1 |
- !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("BabylonViewer",[],t):"object"==typeof exports?exports.BabylonViewer=t():e.BabylonViewer=t()}("undefined"!=typeof self?self:this,function(){return function(e){var t={};function i(r){if(t[r])return t[r].exports;var n=t[r]={i:r,l:!1,exports:{}};return e[r].call(n.exports,n,n.exports,i),n.l=!0,n.exports}return i.m=e,i.c=t,i.d=function(e,t,r){i.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:r})},i.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(t,"a",t),t},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},i.p="",i(i.s=14)}([function(e,t,i){(function(t){var r,n,o,s,a,h,l,c,u,p,f,d,m,g,_,v,y,b,x,T,E,A,P,M,S,C,R,O,I,w,D,L,B,N,F,V,k,U,z,G,W,H,j,X=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},Y=this&&this.__extends||(r=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])},function(e,t){function i(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(i.prototype=t.prototype,new i)});!function(e){var t=function(){function t(){this._defines={},this._currentRank=32,this._maxRank=-1}return t.prototype.unBindMesh=function(){this._mesh=null},t.prototype.addFallback=function(e,t){this._defines[e]||(e<this._currentRank&&(this._currentRank=e),e>this._maxRank&&(this._maxRank=e),this._defines[e]=new Array),this._defines[e].push(t)},t.prototype.addCPUSkinningFallback=function(e,t){this._mesh=t,e<this._currentRank&&(this._currentRank=e),e>this._maxRank&&(this._maxRank=e)},Object.defineProperty(t.prototype,"isMoreFallbacks",{get:function(){return this._currentRank<=this._maxRank},enumerable:!0,configurable:!0}),t.prototype.reduce=function(t){if(this._mesh&&this._mesh.computeBonesUsingShaders&&this._mesh.numBoneInfluencers>0){this._mesh.computeBonesUsingShaders=!1,t=t.replace("#define NUM_BONE_INFLUENCERS "+this._mesh.numBoneInfluencers,"#define NUM_BONE_INFLUENCERS 0"),e.Tools.Log("Falling back to CPU skinning for "+this._mesh.name);for(var i=this._mesh.getScene(),r=0;r<i.meshes.length;r++){var n=i.meshes[r];n.material===this._mesh.material&&n.computeBonesUsingShaders&&n.numBoneInfluencers>0&&(n.computeBonesUsingShaders=!1)}}else{var o=this._defines[this._currentRank];if(o)for(r=0;r<o.length;r++)t=t.replace("#define "+o[r],"");this._currentRank++}return t},t}();e.EffectFallbacks=t;var i=function(){return function(){}}();e.EffectCreationOptions=i;var r=function(){function t(i,r,n,o,s,a,h,l,c,u){void 0===o&&(o=null),void 0===a&&(a=null),void 0===h&&(h=null),void 0===l&&(l=null),void 0===c&&(c=null);var p,f,d=this;if(this.uniqueId=0,this.onCompileObservable=new e.Observable,this.onErrorObservable=new e.Observable,this.onBindObservable=new e.Observable,this._uniformBuffersNames={},this._isReady=!1,this._compilationError="",this.name=i,r.attributes){var m=r;if(this._engine=n,this._attributesNames=m.attributes,this._uniformsNames=m.uniformsNames.concat(m.samplers),this._samplers=m.samplers,this.defines=m.defines,this.onError=m.onError,this.onCompiled=m.onCompiled,this._fallbacks=m.fallbacks,this._indexParameters=m.indexParameters,this._transformFeedbackVaryings=m.transformFeedbackVaryings,m.uniformBuffersNames)for(var g=0;g<m.uniformBuffersNames.length;g++)this._uniformBuffersNames[m.uniformBuffersNames[g]]=g}else this._engine=s,this.defines=a,this._uniformsNames=n.concat(o),this._samplers=o,this._attributesNames=r,this.onError=c,this.onCompiled=l,this._indexParameters=u,this._fallbacks=h;this.uniqueId=t._uniqueIdSeed++,i.vertexElement?(p=document.getElementById(i.vertexElement))||(p=i.vertexElement):p=i.vertex||i,i.fragmentElement?(f=document.getElementById(i.fragmentElement))||(f=i.fragmentElement):f=i.fragment||i,this._loadVertexShader(p,function(e){d._processIncludes(e,function(e){d._processShaderConversion(e,!1,function(e){d._loadFragmentShader(f,function(t){d._processIncludes(t,function(t){d._processShaderConversion(t,!0,function(t){if(i){var r=i.vertexElement||i.vertex||i,n=i.fragmentElement||i.fragment||i;d._vertexSourceCode="#define SHADER_NAME vertex:"+r+"\n"+e,d._fragmentSourceCode="#define SHADER_NAME fragment:"+n+"\n"+t}else d._vertexSourceCode=e,d._fragmentSourceCode=t;d._prepareEffect()})})})})})})}return Object.defineProperty(t.prototype,"key",{get:function(){return this._key},enumerable:!0,configurable:!0}),t.prototype.isReady=function(){return this._isReady},t.prototype.getEngine=function(){return this._engine},t.prototype.getProgram=function(){return this._program},t.prototype.getAttributesNames=function(){return this._attributesNames},t.prototype.getAttributeLocation=function(e){return this._attributes[e]},t.prototype.getAttributeLocationByName=function(e){var t=this._attributesNames.indexOf(e);return this._attributes[t]},t.prototype.getAttributesCount=function(){return this._attributes.length},t.prototype.getUniformIndex=function(e){return this._uniformsNames.indexOf(e)},t.prototype.getUniform=function(e){return this._uniforms[this._uniformsNames.indexOf(e)]},t.prototype.getSamplers=function(){return this._samplers},t.prototype.getCompilationError=function(){return this._compilationError},t.prototype.executeWhenCompiled=function(e){this.isReady()?e(this):this.onCompileObservable.add(function(t){e(t)})},t.prototype._loadVertexShader=function(i,r){var n;if(e.Tools.IsWindowObjectExist()&&i instanceof HTMLElement)return void r(e.Tools.GetDOMTextContent(i));"base64:"!==i.substr(0,7)?t.ShadersStore[i+"VertexShader"]?r(t.ShadersStore[i+"VertexShader"]):(n="."===i[0]||"/"===i[0]||i.indexOf("http")>-1?i:e.Engine.ShadersRepository+i,this._engine._loadFile(n+".vertex.fx",r)):r(window.atob(i.substr(7)))},t.prototype._loadFragmentShader=function(i,r){var n;if(e.Tools.IsWindowObjectExist()&&i instanceof HTMLElement)return void r(e.Tools.GetDOMTextContent(i));"base64:"!==i.substr(0,7)?t.ShadersStore[i+"PixelShader"]?r(t.ShadersStore[i+"PixelShader"]):t.ShadersStore[i+"FragmentShader"]?r(t.ShadersStore[i+"FragmentShader"]):(n="."===i[0]||"/"===i[0]||i.indexOf("http")>-1?i:e.Engine.ShadersRepository+i,this._engine._loadFile(n+".fragment.fx",r)):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 this._engine._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;p<u.length;p+=2){var f=new RegExp(u[p],"g"),d=u[p+1];c=c.replace(f,d)}if(s[4]){var m=s[5];if(-1!==m.indexOf("..")){var g=m.split(".."),_=parseInt(g[0]),v=parseInt(g[1]),y=c.slice(0);c="",isNaN(v)&&(v=this._indexParameters[g[1]]);for(var b=_;b<v;b++)this._engine.supportsUniformBuffers||(y=y.replace(/light\{X\}.(\w*)/g,function(e,t){return t+"{X}"})),c+=y.replace(/\{X\}/g,b.toString())+"\n"}else this._engine.supportsUniformBuffers||(c=c.replace(/light\{X\}.(\w*)/g,function(e,t){return t+"{X}"})),c=c.replace(/\{X\}/g,m)}a=a.replace(s[0],c),s=o.exec(i)}r(a)},t.prototype._processPrecision=function(e){return-1===e.indexOf("precision highp float")?e=this._engine.getCaps().highPrecisionShaderSupported?"precision highp float;\n"+e:"precision mediump float;\n"+e:this._engine.getCaps().highPrecisionShaderSupported||(e=e.replace("precision highp float","precision mediump float")),e},t.prototype._rebuildProgram=function(t,i,r,n){var o=this;this._isReady=!1,this._vertexSourceCodeOverride=t,this._fragmentSourceCodeOverride=i,this.onError=function(e,t){n&&n(t)},this.onCompiled=function(){for(var t=o.getEngine().scenes,i=0;i<t.length;i++)t[i].markAllMaterialsAsDirty(e.Material.TextureDirtyFlag);r&&r(o._program)},this._fallbacks=null,this._prepareEffect()},t.prototype.getSpecificUniformLocations=function(e){return this._engine.getUniforms(this._program,e)},t.prototype._prepareEffect=function(){var t=this._attributesNames,i=this.defines,r=this._fallbacks;this._valueCache={};var n=this._program;try{var o,s=this._engine;if(this._vertexSourceCodeOverride&&this._fragmentSourceCodeOverride?this._program=s.createRawShaderProgram(this._vertexSourceCodeOverride,this._fragmentSourceCodeOverride,void 0,this._transformFeedbackVaryings):this._program=s.createShaderProgram(this._vertexSourceCode,this._fragmentSourceCode,i,void 0,this._transformFeedbackVaryings),this._program.__SPECTOR_rebuildProgram=this._rebuildProgram.bind(this),s.supportsUniformBuffers)for(var a in this._uniformBuffersNames)this.bindUniformBlock(a,this._uniformBuffersNames[a]);for(this._uniforms=s.getUniforms(this._program,this._uniformsNames),this._attributes=s.getAttributes(this._program,t),o=0;o<this._samplers.length;o++){null==this.getUniform(this._samplers[o])&&(this._samplers.splice(o,1),o--)}s.bindSamplers(this),this._compilationError="",this._isReady=!0,this.onCompiled&&this.onCompiled(this),this.onCompileObservable.notifyObservers(this),this.onCompileObservable.clear(),this._fallbacks&&this._fallbacks.unBindMesh(),n&&this.getEngine()._deleteProgram(n)}catch(o){this._compilationError=o.message,e.Tools.Error("Unable to compile effect:"),e.Tools.Error("Uniforms: "+this._uniformsNames.map(function(e){return" "+e})),e.Tools.Error("Attributes: "+t.map(function(e){return" "+e})),this._dumpShadersSource(this._vertexSourceCode,this._fragmentSourceCode,i),e.Tools.Error("Error: "+this._compilationError),n&&(this._program=n,this._isReady=!0,this.onError&&this.onError(this,this._compilationError),this.onErrorObservable.notifyObservers(this)),r&&r.isMoreFallbacks?(e.Tools.Error("Trying next fallback."),this.defines=r.reduce(this.defines),this._prepareEffect()):(this.onError&&this.onError(this,this._compilationError),this.onErrorObservable.notifyObservers(this),this.onErrorObservable.clear(),this._fallbacks&&this._fallbacks.unBindMesh())}},Object.defineProperty(t.prototype,"isSupported",{get:function(){return""===this._compilationError},enumerable:!0,configurable:!0}),t.prototype._bindTexture=function(e,t){this._engine._bindTexture(this._samplers.indexOf(e),t)},t.prototype.setTexture=function(e,t){this._engine.setTexture(this._samplers.indexOf(e),this.getUniform(e),t)},t.prototype.setTextureArray=function(e,t){if(-1===this._samplers.indexOf(e+"Ex"))for(var i=this._samplers.indexOf(e),r=1;r<t.length;r++)this._samplers.splice(i+r,0,e+"Ex");this._engine.setTextureArray(this._samplers.indexOf(e),this.getUniform(e),t)},t.prototype.setTextureFromPostProcess=function(e,t){this._engine.setTextureFromPostProcess(this._samplers.indexOf(e),t)},t.prototype._cacheMatrix=function(e,t){var i=this._valueCache[e],r=t.updateFlag;return(void 0===i||i!==r)&&(this._valueCache[e]=r,!0)},t.prototype._cacheFloat2=function(e,t,i){var r=this._valueCache[e];if(!r)return r=[t,i],this._valueCache[e]=r,!0;var n=!1;return r[0]!==t&&(r[0]=t,n=!0),r[1]!==i&&(r[1]=i,n=!0),n},t.prototype._cacheFloat3=function(e,t,i,r){var n=this._valueCache[e];if(!n)return n=[t,i,r],this._valueCache[e]=n,!0;var o=!1;return n[0]!==t&&(n[0]=t,o=!0),n[1]!==i&&(n[1]=i,o=!0),n[2]!==r&&(n[2]=r,o=!0),o},t.prototype._cacheFloat4=function(e,t,i,r,n){var o=this._valueCache[e];if(!o)return o=[t,i,r,n],this._valueCache[e]=o,!0;var s=!1;return o[0]!==t&&(o[0]=t,s=!0),o[1]!==i&&(o[1]=i,s=!0),o[2]!==r&&(o[2]=r,s=!0),o[3]!==n&&(o[3]=n,s=!0),s},t.prototype.bindUniformBuffer=function(e,i){var r=this._uniformBuffersNames[i];void 0!==r&&t._baseCache[r]!==e&&(t._baseCache[r]=e,this._engine.bindUniformBufferBase(e,r))},t.prototype.bindUniformBlock=function(e,t){this._engine.bindUniformBlock(this._program,e,t)},t.prototype.setInt=function(e,t){var i=this._valueCache[e];return void 0!==i&&i===t?this:(this._valueCache[e]=t,this._engine.setInt(this.getUniform(e),t),this)},t.prototype.setIntArray=function(e,t){return this._valueCache[e]=null,this._engine.setIntArray(this.getUniform(e),t),this},t.prototype.setIntArray2=function(e,t){return this._valueCache[e]=null,this._engine.setIntArray2(this.getUniform(e),t),this},t.prototype.setIntArray3=function(e,t){return this._valueCache[e]=null,this._engine.setIntArray3(this.getUniform(e),t),this},t.prototype.setIntArray4=function(e,t){return this._valueCache[e]=null,this._engine.setIntArray4(this.getUniform(e),t),this},t.prototype.setFloatArray=function(e,t){return this._valueCache[e]=null,this._engine.setFloatArray(this.getUniform(e),t),this},t.prototype.setFloatArray2=function(e,t){return this._valueCache[e]=null,this._engine.setFloatArray2(this.getUniform(e),t),this},t.prototype.setFloatArray3=function(e,t){return this._valueCache[e]=null,this._engine.setFloatArray3(this.getUniform(e),t),this},t.prototype.setFloatArray4=function(e,t){return this._valueCache[e]=null,this._engine.setFloatArray4(this.getUniform(e),t),this},t.prototype.setArray=function(e,t){return this._valueCache[e]=null,this._engine.setArray(this.getUniform(e),t),this},t.prototype.setArray2=function(e,t){return this._valueCache[e]=null,this._engine.setArray2(this.getUniform(e),t),this},t.prototype.setArray3=function(e,t){return this._valueCache[e]=null,this._engine.setArray3(this.getUniform(e),t),this},t.prototype.setArray4=function(e,t){return this._valueCache[e]=null,this._engine.setArray4(this.getUniform(e),t),this},t.prototype.setMatrices=function(e,t){return t?(this._valueCache[e]=null,this._engine.setMatrices(this.getUniform(e),t),this):this},t.prototype.setMatrix=function(e,t){return this._cacheMatrix(e,t)&&this._engine.setMatrix(this.getUniform(e),t),this},t.prototype.setMatrix3x3=function(e,t){return this._valueCache[e]=null,this._engine.setMatrix3x3(this.getUniform(e),t),this},t.prototype.setMatrix2x2=function(e,t){return this._valueCache[e]=null,this._engine.setMatrix2x2(this.getUniform(e),t),this},t.prototype.setFloat=function(e,t){var i=this._valueCache[e];return void 0!==i&&i===t?this:(this._valueCache[e]=t,this._engine.setFloat(this.getUniform(e),t),this)},t.prototype.setBool=function(e,t){var i=this._valueCache[e];return void 0!==i&&i===t?this:(this._valueCache[e]=t,this._engine.setBool(this.getUniform(e),t?1:0),this)},t.prototype.setVector2=function(e,t){return this._cacheFloat2(e,t.x,t.y)&&this._engine.setFloat2(this.getUniform(e),t.x,t.y),this},t.prototype.setFloat2=function(e,t,i){return this._cacheFloat2(e,t,i)&&this._engine.setFloat2(this.getUniform(e),t,i),this},t.prototype.setVector3=function(e,t){return this._cacheFloat3(e,t.x,t.y,t.z)&&this._engine.setFloat3(this.getUniform(e),t.x,t.y,t.z),this},t.prototype.setFloat3=function(e,t,i,r){return this._cacheFloat3(e,t,i,r)&&this._engine.setFloat3(this.getUniform(e),t,i,r),this},t.prototype.setVector4=function(e,t){return this._cacheFloat4(e,t.x,t.y,t.z,t.w)&&this._engine.setFloat4(this.getUniform(e),t.x,t.y,t.z,t.w),this},t.prototype.setFloat4=function(e,t,i,r,n){return this._cacheFloat4(e,t,i,r,n)&&this._engine.setFloat4(this.getUniform(e),t,i,r,n),this},t.prototype.setColor3=function(e,t){return this._cacheFloat3(e,t.r,t.g,t.b)&&this._engine.setColor3(this.getUniform(e),t),this},t.prototype.setColor4=function(e,t,i){return this._cacheFloat4(e,t.r,t.g,t.b,i)&&this._engine.setColor4(this.getUniform(e),t,i),this},t.ResetCache=function(){t._baseCache={}},t._uniqueIdSeed=0,t._baseCache={},t.ShadersStore={},t.IncludesShadersStore={},t}();e.Effect=r}(us||(us={})),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 Y(t,e),t}(i);e.KeyboardInfoPre=r}(us||(us={})),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 Y(i,t),i}(i);e.PointerInfoPre=r;var n=function(e){function t(t,i,r){var n=e.call(this,t,i)||this;return n.pickInfo=r,n}return Y(t,e),t}(i);e.PointerInfo=n}(us||(us={})),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=397*e^(this.g||0))^(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=397*(e=397*e^(this.g||0))^(this.b||0))^(this.a||0)},t.prototype.clone=function(){return new t(this.r,this.g,this.b,this.a)},t.prototype.copyFrom=function(e){return this.r=e.r,this.g=e.g,this.b=e.b,this.a=e.a,this},t.prototype.copyFromFloats=function(e,t,i,r){return this.r=e,this.g=t,this.b=i,this.a=r,this},t.prototype.set=function(e,t,i,r){return this.copyFromFloats(e,t,i,r)},t.prototype.toHexString=function(){var t=255*this.r|0,i=255*this.g|0,r=255*this.b|0,n=255*this.a|0;return"#"+e.Scalar.ToHex(t)+e.Scalar.ToHex(i)+e.Scalar.ToHex(r)+e.Scalar.ToHex(n)},t.prototype.toLinearSpace=function(){var e=new t;return this.toLinearSpaceToRef(e),e},t.prototype.toLinearSpaceToRef=function(t){return t.r=Math.pow(this.r,e.ToLinearSpace),t.g=Math.pow(this.g,e.ToLinearSpace),t.b=Math.pow(this.b,e.ToLinearSpace),t.a=this.a,this},t.prototype.toGammaSpace=function(){var e=new t;return this.toGammaSpaceToRef(e),e},t.prototype.toGammaSpaceToRef=function(t){return t.r=Math.pow(this.r,e.ToGammaSpace),t.g=Math.pow(this.g,e.ToGammaSpace),t.b=Math.pow(this.b,e.ToGammaSpace),t.a=this.a,this},t.FromHexString=function(e){if("#"!==e.substring(0,1)||9!==e.length)return new t(0,0,0,0);var i=parseInt(e.substring(1,3),16),r=parseInt(e.substring(3,5),16),n=parseInt(e.substring(5,7),16),o=parseInt(e.substring(7,9),16);return t.FromInts(i,r,n,o)},t.Lerp=function(e,i,r){var n=new t(0,0,0,0);return t.LerpToRef(e,i,r,n),n},t.LerpToRef=function(e,t,i,r){r.r=e.r+(t.r-e.r)*i,r.g=e.g+(t.g-e.g)*i,r.b=e.b+(t.b-e.b)*i,r.a=e.a+(t.a-e.a)*i},t.FromArray=function(e,i){return void 0===i&&(i=0),new t(e[i],e[i+1],e[i+2],e[i+3])},t.FromInts=function(e,i,r,n){return new t(e/255,i/255,r/255,n/255)},t.CheckColors4=function(e,t){if(e.length===3*t){for(var i=[],r=0;r<e.length;r+=3){var n=r/3*4;i[n]=e[r],i[n+1]=e[r+1],i[n+2]=e[r+2],i[n+3]=1}return i}return e},t}();e.Color4=i;var r=function(){function t(e,t){this.x=e,this.y=t}return t.prototype.toString=function(){return"{X: "+this.x+" Y:"+this.y+"}"},t.prototype.getClassName=function(){return"Vector2"},t.prototype.getHashCode=function(){var e=this.x||0;return e=397*e^(this.y||0)},t.prototype.toArray=function(e,t){return void 0===t&&(t=0),e[t]=this.x,e[t+1]=this.y,this},t.prototype.asArray=function(){var e=new Array;return this.toArray(e,0),e},t.prototype.copyFrom=function(e){return this.x=e.x,this.y=e.y,this},t.prototype.copyFromFloats=function(e,t){return this.x=e,this.y=t,this},t.prototype.set=function(e,t){return this.copyFromFloats(e,t)},t.prototype.add=function(e){return new t(this.x+e.x,this.y+e.y)},t.prototype.addToRef=function(e,t){return t.x=this.x+e.x,t.y=this.y+e.y,this},t.prototype.addInPlace=function(e){return this.x+=e.x,this.y+=e.y,this},t.prototype.addVector3=function(e){return new t(this.x+e.x,this.y+e.y)},t.prototype.subtract=function(e){return new t(this.x-e.x,this.y-e.y)},t.prototype.subtractToRef=function(e,t){return t.x=this.x-e.x,t.y=this.y-e.y,this},t.prototype.subtractInPlace=function(e){return this.x-=e.x,this.y-=e.y,this},t.prototype.multiplyInPlace=function(e){return this.x*=e.x,this.y*=e.y,this},t.prototype.multiply=function(e){return new t(this.x*e.x,this.y*e.y)},t.prototype.multiplyToRef=function(e,t){return t.x=this.x*e.x,t.y=this.y*e.y,this},t.prototype.multiplyByFloats=function(e,i){return new t(this.x*e,this.y*i)},t.prototype.divide=function(e){return new t(this.x/e.x,this.y/e.y)},t.prototype.divideToRef=function(e,t){return t.x=this.x/e.x,t.y=this.y/e.y,this},t.prototype.divideInPlace=function(e){return this.divideToRef(e,this)},t.prototype.negate=function(){return new t(-this.x,-this.y)},t.prototype.scaleInPlace=function(e){return this.x*=e,this.y*=e,this},t.prototype.scale=function(e){return new t(this.x*e,this.y*e)},t.prototype.equals=function(e){return e&&this.x===e.x&&this.y===e.y},t.prototype.equalsWithEpsilon=function(t,i){return void 0===i&&(i=e.Epsilon),t&&e.Scalar.WithinEpsilon(this.x,t.x,i)&&e.Scalar.WithinEpsilon(this.y,t.y,i)},t.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},t.prototype.lengthSquared=function(){return this.x*this.x+this.y*this.y},t.prototype.normalize=function(){var e=this.length();if(0===e)return this;var t=1/e;return this.x*=t,this.y*=t,this},t.prototype.clone=function(){return new t(this.x,this.y)},t.Zero=function(){return new t(0,0)},t.One=function(){return new t(1,1)},t.FromArray=function(e,i){return void 0===i&&(i=0),new t(e[i],e[i+1])},t.FromArrayToRef=function(e,t,i){i.x=e[t],i.y=e[t+1]},t.CatmullRom=function(e,i,r,n,o){var s=o*o,a=o*s;return new t(.5*(2*i.x+(-e.x+r.x)*o+(2*e.x-5*i.x+4*r.x-n.x)*s+(-e.x+3*i.x-3*r.x+n.x)*a),.5*(2*i.y+(-e.y+r.y)*o+(2*e.y-5*i.y+4*r.y-n.y)*s+(-e.y+3*i.y-3*r.y+n.y)*a))},t.Clamp=function(e,i,r){var n=e.x;n=(n=n>r.x?r.x:n)<i.x?i.x:n;var o=e.y;return new t(n,o=(o=o>r.y?r.y:o)<i.y?i.y:o)},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)},t.Lerp=function(e,i,r){return new t(e.x+(i.x-e.x)*r,e.y+(i.y-e.y)*r)},t.Dot=function(e,t){return e.x*t.x+e.y*t.y},t.Normalize=function(e){var t=e.clone();return t.normalize(),t},t.Minimize=function(e,i){return new t(e.x<i.x?e.x:i.x,e.y<i.y?e.y:i.y)},t.Maximize=function(e,i){return new t(e.x>i.x?e.x:i.x,e.y>i.y?e.y:i.y)},t.Transform=function(e,i){var r=t.Zero();return t.TransformToRef(e,i,r),r},t.TransformToRef=function(e,t,i){var r=e.x*t.m[0]+e.y*t.m[4]+t.m[12],n=e.x*t.m[1]+e.y*t.m[5]+t.m[13];i.x=r,i.y=n},t.PointInTriangle=function(e,t,i,r){var n=.5*(-i.y*r.x+t.y*(-i.x+r.x)+t.x*(i.y-r.y)+i.x*r.y),o=n<0?-1:1,s=(t.y*r.x-t.x*r.y+(r.y-t.y)*e.x+(t.x-r.x)*e.y)*o,a=(t.x*i.y-t.y*i.x+(t.y-i.y)*e.x+(i.x-t.x)*e.y)*o;return s>0&&a>0&&s+a<2*n*o},t.Distance=function(e,i){return Math.sqrt(t.DistanceSquared(e,i))},t.DistanceSquared=function(e,t){var i=e.x-t.x,r=e.y-t.y;return i*i+r*r},t.Center=function(e,t){var i=e.add(t);return i.scaleInPlace(.5),i},t.DistanceOfPointFromSegment=function(e,i,r){var n=t.DistanceSquared(i,r);if(0===n)return t.Distance(e,i);var o=r.subtract(i),s=Math.max(0,Math.min(1,t.Dot(e.subtract(i),o)/n)),a=i.add(o.multiplyByFloats(s,s));return t.Distance(e,a)},t}();e.Vector2=r;var n=function(){function t(e,t,i){this.x=e,this.y=t,this.z=i}return t.prototype.toString=function(){return"{X: "+this.x+" Y:"+this.y+" Z:"+this.z+"}"},t.prototype.getClassName=function(){return"Vector3"},t.prototype.getHashCode=function(){var e=this.x||0;return e=397*(e=397*e^(this.y||0))^(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.divideInPlace=function(e){return this.divideToRef(e,this)},t.prototype.MinimizeInPlace=function(e){return e.x<this.x&&(this.x=e.x),e.y<this.y&&(this.y=e.y),e.z<this.z&&(this.z=e.z),this},t.prototype.MaximizeInPlace=function(e){return e.x>this.x&&(this.x=e.x),e.y>this.y&&(this.y=e.y),e.z>this.z&&(this.z=e.z),this},Object.defineProperty(t.prototype,"isNonUniform",{get:function(){var e=Math.abs(this.x),t=Math.abs(this.y);if(e!==t)return!0;var i=Math.abs(this.z);return e!==i||t!==i},enumerable:!0,configurable:!0}),t.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)},t.prototype.lengthSquared=function(){return this.x*this.x+this.y*this.y+this.z*this.z},t.prototype.normalize=function(){var e=this.length();if(0===e||1===e)return this;var t=1/e;return this.x*=t,this.y*=t,this.z*=t,this},t.prototype.normalizeToNew=function(){var e=new t(0,0,0);return this.normalizeToRef(e),e},t.prototype.normalizeToRef=function(e){var t=this.length();if(0===t||1===t)return e.set(this.x,this.y,this.z),e;var i=1/t;return this.scaleToRef(i,e),e},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)<i.x?i.x:n;var o=e.y;o=(o=o>r.y?r.y:o)<i.y?i.y:o;var s=e.z;return new t(n,o,s=(s=s>r.z?r.z:s)<i.z?i.z:s)},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)},t.Lerp=function(e,i,r){var n=new t(0,0,0);return t.LerpToRef(e,i,r,n),n},t.LerpToRef=function(e,t,i,r){r.x=e.x+(t.x-e.x)*i,r.y=e.y+(t.y-e.y)*i,r.z=e.z+(t.z-e.z)*i},t.Dot=function(e,t){return e.x*t.x+e.y*t.y+e.z*t.z},t.Cross=function(e,i){var r=t.Zero();return t.CrossToRef(e,i,r),r},t.CrossToRef=function(e,t,i){P.Vector3[0].x=e.y*t.z-e.z*t.y,P.Vector3[0].y=e.z*t.x-e.x*t.z,P.Vector3[0].z=e.x*t.y-e.y*t.x,i.copyFrom(P.Vector3[0])},t.Normalize=function(e){var i=t.Zero();return t.NormalizeToRef(e,i),i},t.NormalizeToRef=function(e,t){t.copyFrom(e),t.normalize()},t.Project=function(e,i,r,n){var o=n.width,s=n.height,a=n.x,l=n.y,c=t._viewportMatrixCache?t._viewportMatrixCache:t._viewportMatrixCache=new h;h.FromValuesToRef(o/2,0,0,0,0,-s/2,0,0,0,0,.5,0,a+o/2,s/2+l,.5,1,c);var u=P.Matrix[0];return i.multiplyToRef(r,u),u.multiplyToRef(c,u),t.TransformCoordinates(e,u)},t.UnprojectFromTransform=function(i,r,n,o,s){var a=P.Matrix[0];o.multiplyToRef(s,a),a.invert(),i.x=i.x/r*2-1,i.y=-(i.y/n*2-1);var h=t.TransformCoordinates(i,a),l=i.x*a.m[3]+i.y*a.m[7]+i.z*a.m[11]+a.m[15];return e.Scalar.WithinEpsilon(l,1)&&(h=h.scale(1/l)),h},t.Unproject=function(e,i,r,n,o,s){var a=t.Zero();return t.UnprojectToRef(e,i,r,n,o,s,a),a},t.UnprojectToRef=function(e,i,r,n,o,s,a){t.UnprojectFloatsToRef(e.x,e.y,e.z,i,r,n,o,s,a)},t.UnprojectFloatsToRef=function(i,r,n,o,s,a,h,l,c){var u=P.Matrix[0];a.multiplyToRef(h,u),u.multiplyToRef(l,u),u.invert();var p=P.Vector3[0];p.x=i/o*2-1,p.y=-(r/s*2-1),p.z=2*n-1,t.TransformCoordinatesToRef(p,u,c);var f=p.x*u.m[3]+p.y*u.m[7]+p.z*u.m[11]+u.m[15];e.Scalar.WithinEpsilon(f,1)&&c.scaleInPlace(1/f)},t.Minimize=function(e,t){var i=e.clone();return i.MinimizeInPlace(t),i},t.Maximize=function(e,t){var i=e.clone();return i.MaximizeInPlace(t),i},t.Distance=function(e,i){return Math.sqrt(t.DistanceSquared(e,i))},t.DistanceSquared=function(e,t){var i=e.x-t.x,r=e.y-t.y,n=e.z-t.z;return i*i+r*r+n*n},t.Center=function(e,t){var i=e.add(t);return i.scaleInPlace(.5),i},t.RotationFromAxis=function(e,i,r){var n=t.Zero();return t.RotationFromAxisToRef(e,i,r,n),n},t.RotationFromAxisToRef=function(e,t,i,r){var n=P.Quaternion[0];a.RotationQuaternionFromAxisToRef(e,t,i,n),n.toEulerAnglesToRef(r)},t}();e.Vector3=n;var o=function(){function t(e,t,i,r){this.x=e,this.y=t,this.z=i,this.w=r}return t.prototype.toString=function(){return"{X: "+this.x+" Y:"+this.y+" Z:"+this.z+" W:"+this.w+"}"},t.prototype.getClassName=function(){return"Vector4"},t.prototype.getHashCode=function(){var e=this.x||0;return e=397*(e=397*(e=397*e^(this.y||0))^(this.z||0))^(this.w||0)},t.prototype.asArray=function(){var e=new Array;return this.toArray(e,0),e},t.prototype.toArray=function(e,t){return void 0===t&&(t=0),e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,e[t+3]=this.w,this},t.prototype.addInPlace=function(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this.w+=e.w,this},t.prototype.add=function(e){return new t(this.x+e.x,this.y+e.y,this.z+e.z,this.w+e.w)},t.prototype.addToRef=function(e,t){return t.x=this.x+e.x,t.y=this.y+e.y,t.z=this.z+e.z,t.w=this.w+e.w,this},t.prototype.subtractInPlace=function(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this.w-=e.w,this},t.prototype.subtract=function(e){return new t(this.x-e.x,this.y-e.y,this.z-e.z,this.w-e.w)},t.prototype.subtractToRef=function(e,t){return t.x=this.x-e.x,t.y=this.y-e.y,t.z=this.z-e.z,t.w=this.w-e.w,this},t.prototype.subtractFromFloats=function(e,i,r,n){return new t(this.x-e,this.y-i,this.z-r,this.w-n)},t.prototype.subtractFromFloatsToRef=function(e,t,i,r,n){return n.x=this.x-e,n.y=this.y-t,n.z=this.z-i,n.w=this.w-r,this},t.prototype.negate=function(){return new t(-this.x,-this.y,-this.z,-this.w)},t.prototype.scaleInPlace=function(e){return this.x*=e,this.y*=e,this.z*=e,this.w*=e,this},t.prototype.scale=function(e){return new t(this.x*e,this.y*e,this.z*e,this.w*e)},t.prototype.scaleToRef=function(e,t){return t.x=this.x*e,t.y=this.y*e,t.z=this.z*e,t.w=this.w*e,this},t.prototype.equals=function(e){return e&&this.x===e.x&&this.y===e.y&&this.z===e.z&&this.w===e.w},t.prototype.equalsWithEpsilon=function(t,i){return void 0===i&&(i=e.Epsilon),t&&e.Scalar.WithinEpsilon(this.x,t.x,i)&&e.Scalar.WithinEpsilon(this.y,t.y,i)&&e.Scalar.WithinEpsilon(this.z,t.z,i)&&e.Scalar.WithinEpsilon(this.w,t.w,i)},t.prototype.equalsToFloats=function(e,t,i,r){return this.x===e&&this.y===t&&this.z===i&&this.w===r},t.prototype.multiplyInPlace=function(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this.w*=e.w,this},t.prototype.multiply=function(e){return new t(this.x*e.x,this.y*e.y,this.z*e.z,this.w*e.w)},t.prototype.multiplyToRef=function(e,t){return t.x=this.x*e.x,t.y=this.y*e.y,t.z=this.z*e.z,t.w=this.w*e.w,this},t.prototype.multiplyByFloats=function(e,i,r,n){return new t(this.x*e,this.y*i,this.z*r,this.w*n)},t.prototype.divide=function(e){return new t(this.x/e.x,this.y/e.y,this.z/e.z,this.w/e.w)},t.prototype.divideToRef=function(e,t){return t.x=this.x/e.x,t.y=this.y/e.y,t.z=this.z/e.z,t.w=this.w/e.w,this},t.prototype.divideInPlace=function(e){return this.divideToRef(e,this)},t.prototype.MinimizeInPlace=function(e){return e.x<this.x&&(this.x=e.x),e.y<this.y&&(this.y=e.y),e.z<this.z&&(this.z=e.z),e.w<this.w&&(this.w=e.w),this},t.prototype.MaximizeInPlace=function(e){return e.x>this.x&&(this.x=e.x),e.y>this.y&&(this.y=e.y),e.z>this.z&&(this.z=e.z),e.w>this.w&&(this.w=e.w),this},t.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},t.prototype.lengthSquared=function(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w},t.prototype.normalize=function(){var e=this.length();if(0===e)return this;var t=1/e;return this.x*=t,this.y*=t,this.z*=t,this.w*=t,this},t.prototype.toVector3=function(){return new n(this.x,this.y,this.z)},t.prototype.clone=function(){return new t(this.x,this.y,this.z,this.w)},t.prototype.copyFrom=function(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w,this},t.prototype.copyFromFloats=function(e,t,i,r){return this.x=e,this.y=t,this.z=i,this.w=r,this},t.prototype.set=function(e,t,i,r){return this.copyFromFloats(e,t,i,r)},t.FromArray=function(e,i){return i||(i=0),new t(e[i],e[i+1],e[i+2],e[i+3])},t.FromArrayToRef=function(e,t,i){i.x=e[t],i.y=e[t+1],i.z=e[t+2],i.w=e[t+3]},t.FromFloatArrayToRef=function(e,i,r){t.FromArrayToRef(e,i,r)},t.FromFloatsToRef=function(e,t,i,r,n){n.x=e,n.y=t,n.z=i,n.w=r},t.Zero=function(){return new t(0,0,0,0)},t.One=function(){return new t(1,1,1,1)},t.Normalize=function(e){var i=t.Zero();return t.NormalizeToRef(e,i),i},t.NormalizeToRef=function(e,t){t.copyFrom(e),t.normalize()},t.Minimize=function(e,t){var i=e.clone();return i.MinimizeInPlace(t),i},t.Maximize=function(e,t){var i=e.clone();return i.MaximizeInPlace(t),i},t.Distance=function(e,i){return Math.sqrt(t.DistanceSquared(e,i))},t.DistanceSquared=function(e,t){var i=e.x-t.x,r=e.y-t.y,n=e.z-t.z,o=e.w-t.w;return i*i+r*r+n*n+o*o},t.Center=function(e,t){var i=e.add(t);return i.scaleInPlace(.5),i},t.TransformNormal=function(e,i){var r=t.Zero();return t.TransformNormalToRef(e,i,r),r},t.TransformNormalToRef=function(e,t,i){var r=e.x*t.m[0]+e.y*t.m[4]+e.z*t.m[8],n=e.x*t.m[1]+e.y*t.m[5]+e.z*t.m[9],o=e.x*t.m[2]+e.y*t.m[6]+e.z*t.m[10];i.x=r,i.y=n,i.z=o,i.w=e.w},t.TransformNormalFromFloatsToRef=function(e,t,i,r,n,o){o.x=e*n.m[0]+t*n.m[4]+i*n.m[8],o.y=e*n.m[1]+t*n.m[5]+i*n.m[9],o.z=e*n.m[2]+t*n.m[6]+i*n.m[10],o.w=r},t}();e.Vector4=o;var s=function(){function e(e,t){this.width=e,this.height=t}return e.prototype.toString=function(){return"{W: "+this.width+", H: "+this.height+"}"},e.prototype.getClassName=function(){return"Size"},e.prototype.getHashCode=function(){var e=this.width||0;return e=397*e^(this.height||0)},e.prototype.copyFrom=function(e){this.width=e.width,this.height=e.height},e.prototype.copyFromFloats=function(e,t){return this.width=e,this.height=t,this},e.prototype.set=function(e,t){return this.copyFromFloats(e,t)},e.prototype.multiplyByFloats=function(t,i){return new e(this.width*t,this.height*i)},e.prototype.clone=function(){return new e(this.width,this.height)},e.prototype.equals=function(e){return!!e&&(this.width===e.width&&this.height===e.height)},Object.defineProperty(e.prototype,"surface",{get:function(){return this.width*this.height},enumerable:!0,configurable:!0}),e.Zero=function(){return new e(0,0)},e.prototype.add=function(t){return new e(this.width+t.width,this.height+t.height)},e.prototype.subtract=function(t){return new e(this.width-t.width,this.height-t.height)},e.Lerp=function(t,i,r){return new e(t.width+(i.width-t.width)*r,t.height+(i.height-t.height)*r)},e}();e.Size=s;var a=function(){function e(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 e.prototype.toString=function(){return"{X: "+this.x+" Y:"+this.y+" Z:"+this.z+" W:"+this.w+"}"},e.prototype.getClassName=function(){return"Quaternion"},e.prototype.getHashCode=function(){var e=this.x||0;return e=397*(e=397*(e=397*e^(this.y||0))^(this.z||0))^(this.w||0)},e.prototype.asArray=function(){return[this.x,this.y,this.z,this.w]},e.prototype.equals=function(e){return e&&this.x===e.x&&this.y===e.y&&this.z===e.z&&this.w===e.w},e.prototype.clone=function(){return new e(this.x,this.y,this.z,this.w)},e.prototype.copyFrom=function(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w,this},e.prototype.copyFromFloats=function(e,t,i,r){return this.x=e,this.y=t,this.z=i,this.w=r,this},e.prototype.set=function(e,t,i,r){return this.copyFromFloats(e,t,i,r)},e.prototype.add=function(t){return new e(this.x+t.x,this.y+t.y,this.z+t.z,this.w+t.w)},e.prototype.subtract=function(t){return new e(this.x-t.x,this.y-t.y,this.z-t.z,this.w-t.w)},e.prototype.scale=function(t){return new e(this.x*t,this.y*t,this.z*t,this.w*t)},e.prototype.multiply=function(t){var i=new e(0,0,0,1);return this.multiplyToRef(t,i),i},e.prototype.multiplyToRef=function(e,t){var i=this.x*e.w+this.y*e.z-this.z*e.y+this.w*e.x,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},e.prototype.multiplyInPlace=function(e){return this.multiplyToRef(e,this),this},e.prototype.conjugateToRef=function(e){return e.copyFromFloats(-this.x,-this.y,-this.z,this.w),this},e.prototype.conjugateInPlace=function(){return this.x*=-1,this.y*=-1,this.z*=-1,this},e.prototype.conjugate=function(){return new e(-this.x,-this.y,-this.z,this.w)},e.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},e.prototype.normalize=function(){var e=1/this.length();return this.x*=e,this.y*=e,this.z*=e,this.w*=e,this},e.prototype.toEulerAngles=function(e){void 0===e&&(e="YZX");var t=n.Zero();return this.toEulerAnglesToRef(t,e),t},e.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},e.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},e.prototype.fromRotationMatrix=function(t){return e.FromRotationMatrixToRef(t,this),this},e.FromRotationMatrix=function(t){var i=new e;return e.FromRotationMatrixToRef(t,i),i},e.FromRotationMatrixToRef=function(e,t){var i,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)},e.Zero=function(){return new e(0,0,0,0)},e.Inverse=function(t){return new e(-t.x,-t.y,-t.z,t.w)},e.Identity=function(){return new e(0,0,0,1)},e.IsIdentity=function(e){return e&&0===e.x&&0===e.y&&0===e.z&&1===e.w},e.RotationAxis=function(t,i){return e.RotationAxisToRef(t,i,new e)},e.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},e.FromArray=function(t,i){return i||(i=0),new e(t[i],t[i+1],t[i+2],t[i+3])},e.RotationYawPitchRoll=function(t,i,r){var n=new e;return e.RotationYawPitchRollToRef(t,i,r,n),n},e.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},e.RotationAlphaBetaGamma=function(t,i,r){var n=new e;return e.RotationAlphaBetaGammaToRef(t,i,r,n),n},e.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)},e.RotationQuaternionFromAxis=function(t,i,r,n){var o=new e(0,0,0,0);return e.RotationQuaternionFromAxisToRef(t,i,r,o),o},e.RotationQuaternionFromAxisToRef=function(t,i,r,n){var o=P.Matrix[0];h.FromXYZAxesToRef(t.normalize(),i.normalize(),r.normalize(),o),e.FromRotationMatrixToRef(o,n)},e.Slerp=function(t,i,r){var n=e.Identity();return e.SlerpToRef(t,i,r,n),n},e.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},e.Hermite=function(t,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 e(t.x*h+r.x*l+i.x*c+n.x*u,t.y*h+r.y*l+i.y*c+n.y*u,t.z*h+r.z*l+i.z*c+n.z*u,t.w*h+r.w*l+i.w*c+n.w*u)},e}();e.Quaternion=a;var h=function(){function e(){this._isIdentity=!1,this._isIdentityDirty=!0,this.m=new Float32Array(16),this._markAsUpdated()}return e.prototype._markAsUpdated=function(){this.updateFlag=e._updateFlagSeed++,this._isIdentityDirty=!0},e.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},e.prototype.determinant=function(){var e=this.m[10]*this.m[15]-this.m[11]*this.m[14],t=this.m[9]*this.m[15]-this.m[11]*this.m[13],i=this.m[9]*this.m[14]-this.m[10]*this.m[13],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)},e.prototype.toArray=function(){return this.m},e.prototype.asArray=function(){return this.toArray()},e.prototype.invert=function(){return this.invertToRef(this),this},e.prototype.reset=function(){for(var e=0;e<16;e++)this.m[e]=0;return this._markAsUpdated(),this},e.prototype.add=function(t){var i=new e;return this.addToRef(t,i),i},e.prototype.addToRef=function(e,t){for(var i=0;i<16;i++)t.m[i]=this.m[i]+e.m[i];return t._markAsUpdated(),this},e.prototype.addToSelf=function(e){for(var t=0;t<16;t++)this.m[t]+=e.m[t];return this._markAsUpdated(),this},e.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,O=s*m-a*d,I=o*g-h*f,w=o*m-a*f,D=o*d-s*f,L=a*p-h*u,B=s*p-h*c,N=s*u-a*c,F=o*p-h*l,V=o*u-a*l,k=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*O)*S,e.m[6]=-(t*C-r*I+n*w)*S,e.m[10]=(t*R-i*I+n*D)*S,e.m[14]=-(t*O-i*w+r*D)*S,e.m[3]=-(i*L-r*B+n*N)*S,e.m[7]=(t*L-r*F+n*V)*S,e.m[11]=-(t*B-i*F+n*k)*S,e.m[15]=(t*N-i*V+r*k)*S,e._markAsUpdated(),this},e.prototype.setTranslationFromFloats=function(e,t,i){return this.m[12]=e,this.m[13]=t,this.m[14]=i,this._markAsUpdated(),this},e.prototype.setTranslation=function(e){return this.m[12]=e.x,this.m[13]=e.y,this.m[14]=e.z,this._markAsUpdated(),this},e.prototype.getTranslation=function(){return new n(this.m[12],this.m[13],this.m[14])},e.prototype.getTranslationToRef=function(e){return e.x=this.m[12],e.y=this.m[13],e.z=this.m[14],this},e.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},e.prototype.multiply=function(t){var i=new e;return this.multiplyToRef(t,i),i},e.prototype.copyFrom=function(e){for(var t=0;t<16;t++)this.m[t]=e.m[t];return this._markAsUpdated(),this},e.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},e.prototype.multiplyToRef=function(e,t){return this.multiplyToArray(e,t.m,0),t._markAsUpdated(),this},e.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],O=e.m[11],I=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*I,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*O+s*L,t[i+4]=a*y+h*E+l*S+c*I,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*O+c*L,t[i+8]=u*y+p*E+f*S+d*I,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*O+d*L,t[i+12]=m*y+g*E+_*S+v*I,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+_*O+v*L,this},e.prototype.equals=function(e){return e&&this.m[0]===e.m[0]&&this.m[1]===e.m[1]&&this.m[2]===e.m[2]&&this.m[3]===e.m[3]&&this.m[4]===e.m[4]&&this.m[5]===e.m[5]&&this.m[6]===e.m[6]&&this.m[7]===e.m[7]&&this.m[8]===e.m[8]&&this.m[9]===e.m[9]&&this.m[10]===e.m[10]&&this.m[11]===e.m[11]&&this.m[12]===e.m[12]&&this.m[13]===e.m[13]&&this.m[14]===e.m[14]&&this.m[15]===e.m[15]},e.prototype.clone=function(){return e.FromValues(this.m[0],this.m[1],this.m[2],this.m[3],this.m[4],this.m[5],this.m[6],this.m[7],this.m[8],this.m[9],this.m[10],this.m[11],this.m[12],this.m[13],this.m[14],this.m[15])},e.prototype.getClassName=function(){return"Matrix"},e.prototype.getHashCode=function(){for(var e=this.m[0]||0,t=1;t<16;t++)e=397*e^(this.m[t]||0);return e},e.prototype.decompose=function(t,i,r){return r.x=this.m[12],r.y=this.m[13],r.z=this.m[14],t.x=Math.sqrt(this.m[0]*this.m[0]+this.m[1]*this.m[1]+this.m[2]*this.m[2]),t.y=Math.sqrt(this.m[4]*this.m[4]+this.m[5]*this.m[5]+this.m[6]*this.m[6]),t.z=Math.sqrt(this.m[8]*this.m[8]+this.m[9]*this.m[9]+this.m[10]*this.m[10]),this.determinant()<=0&&(t.y*=-1),0===t.x||0===t.y||0===t.z?(i.x=0,i.y=0,i.z=0,i.w=1,!1):(e.FromValuesToRef(this.m[0]/t.x,this.m[1]/t.x,this.m[2]/t.x,0,this.m[4]/t.y,this.m[5]/t.y,this.m[6]/t.y,0,this.m[8]/t.z,this.m[9]/t.z,this.m[10]/t.z,0,0,0,0,1,P.Matrix[0]),a.FromRotationMatrixToRef(P.Matrix[0],i),!0)},e.prototype.getRotationMatrix=function(){var t=e.Identity();return this.getRotationMatrixToRef(t),t},e.prototype.getRotationMatrixToRef=function(t){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 e.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,t),this},e.FromArray=function(t,i){var r=new e;return i||(i=0),e.FromArrayToRef(t,i,r),r},e.FromArrayToRef=function(e,t,i){for(var r=0;r<16;r++)i.m[r]=e[r+t];i._markAsUpdated()},e.FromFloat32ArrayToRefScaled=function(e,t,i,r){for(var n=0;n<16;n++)r.m[n]=e[n+t]*i;r._markAsUpdated()},e.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()},e.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])},e.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},e.prototype.transpose=function(){return e.Transpose(this)},e.prototype.transposeToRef=function(t){return e.TransposeToRef(this,t),this},e.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(e,"IdentityReadOnly",{get:function(){return e._identityReadOnly},enumerable:!0,configurable:!0}),e.FromValues=function(t,i,r,n,o,s,a,h,l,c,u,p,f,d,m,g){var _=new e;return _.m[0]=t,_.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,_},e.Compose=function(t,i,r){var n=e.Identity();return e.ComposeToRef(t,i,r,n),n},e.ComposeToRef=function(t,i,r,n){e.FromValuesToRef(t.x,0,0,0,0,t.y,0,0,0,0,t.z,0,0,0,0,1,P.Matrix[1]),i.toRotationMatrix(P.Matrix[0]),P.Matrix[1].multiplyToRef(P.Matrix[0],n),n.setTranslation(r)},e.Identity=function(){return e.FromValues(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1)},e.IdentityToRef=function(t){e.FromValuesToRef(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,t)},e.Zero=function(){return e.FromValues(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)},e.RotationX=function(t){var i=new e;return e.RotationXToRef(t,i),i},e.Invert=function(t){var i=new e;return t.invertToRef(i),i},e.RotationXToRef=function(e,t){var i=Math.sin(e),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()},e.RotationY=function(t){var i=new e;return e.RotationYToRef(t,i),i},e.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()},e.RotationZ=function(t){var i=new e;return e.RotationZToRef(t,i),i},e.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()},e.RotationAxis=function(t,i){var r=e.Zero();return e.RotationAxisToRef(t,i,r),r},e.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()},e.RotationYawPitchRoll=function(t,i,r){var n=new e;return e.RotationYawPitchRollToRef(t,i,r,n),n},e.RotationYawPitchRollToRef=function(e,t,i,r){a.RotationYawPitchRollToRef(e,t,i,this._tempQuaternion),this._tempQuaternion.toRotationMatrix(r)},e.Scaling=function(t,i,r){var n=e.Zero();return e.ScalingToRef(t,i,r,n),n},e.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()},e.Translation=function(t,i,r){var n=e.Identity();return e.TranslationToRef(t,i,r,n),n},e.TranslationToRef=function(t,i,r,n){e.FromValuesToRef(1,0,0,0,0,1,0,0,0,0,1,0,t,i,r,1,n)},e.Lerp=function(t,i,r){for(var n=e.Zero(),o=0;o<16;o++)n.m[o]=t.m[o]*(1-r)+i.m[o]*r;return n._markAsUpdated(),n},e.DecomposeLerp=function(t,i,r){var o=new n(0,0,0),s=new a,h=new n(0,0,0);t.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 e.Compose(p,f,d)},e.LookAtLH=function(t,i,r){var n=e.Zero();return e.LookAtLHToRef(t,i,r,n),n},e.LookAtLHToRef=function(t,i,r,o){i.subtractToRef(t,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,t),a=-n.Dot(this._yAxis,t),h=-n.Dot(this._zAxis,t);return e.FromValuesToRef(this._xAxis.x,this._yAxis.x,this._zAxis.x,0,this._xAxis.y,this._yAxis.y,this._zAxis.y,0,this._xAxis.z,this._yAxis.z,this._zAxis.z,0,s,a,h,1,o)},e.LookAtRH=function(t,i,r){var n=e.Zero();return e.LookAtRHToRef(t,i,r,n),n},e.LookAtRHToRef=function(t,i,r,o){t.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,t),a=-n.Dot(this._yAxis,t),h=-n.Dot(this._zAxis,t);return e.FromValuesToRef(this._xAxis.x,this._yAxis.x,this._zAxis.x,0,this._xAxis.y,this._yAxis.y,this._zAxis.y,0,this._xAxis.z,this._yAxis.z,this._zAxis.z,0,s,a,h,1,o)},e.OrthoLH=function(t,i,r,n){var o=e.Zero();return e.OrthoLHToRef(t,i,r,n,o),o},e.OrthoLHToRef=function(t,i,r,n,o){var s=2/t,a=2/i,h=2/(n-r),l=-(n+r)/(n-r);e.FromValuesToRef(s,0,0,0,0,a,0,0,0,0,h,0,0,0,l,1,o)},e.OrthoOffCenterLH=function(t,i,r,n,o,s){var a=e.Zero();return e.OrthoOffCenterLHToRef(t,i,r,n,o,s,a),a},e.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.FromValuesToRef(h,0,0,0,0,l,0,0,0,0,c,0,p,f,u,1,a)},e.OrthoOffCenterRH=function(t,i,r,n,o,s){var a=e.Zero();return e.OrthoOffCenterRHToRef(t,i,r,n,o,s,a),a},e.OrthoOffCenterRHToRef=function(t,i,r,n,o,s,a){e.OrthoOffCenterLHToRef(t,i,r,n,o,s,a),a.m[10]*=-1},e.PerspectiveLH=function(t,i,r,n){var o=e.Zero(),s=2*r/t,a=2*r/i,h=(n+r)/(n-r),l=-2*n*r/(n-r);return e.FromValuesToRef(s,0,0,0,0,a,0,0,0,0,h,1,0,0,l,0,o),o},e.PerspectiveFovLH=function(t,i,r,n){var o=e.Zero();return e.PerspectiveFovLHToRef(t,i,r,n,o),o},e.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.FromValuesToRef(c,0,0,0,0,u,0,0,0,0,p,1,0,0,f,0,o)},e.PerspectiveFovRH=function(t,i,r,n){var o=e.Zero();return e.PerspectiveFovRHToRef(t,i,r,n,o),o},e.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.FromValuesToRef(c,0,0,0,0,u,0,0,0,0,p,-1,0,0,f,0,o)},e.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()},e.GetFinalMatrix=function(t,i,r,n,o,s){var a=t.width,h=t.height,l=t.x,c=t.y,u=e.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)},e.GetAsMatrix2x2=function(e){return new Float32Array([e.m[0],e.m[1],e.m[4],e.m[5]])},e.GetAsMatrix3x3=function(e){return new Float32Array([e.m[0],e.m[1],e.m[2],e.m[4],e.m[5],e.m[6],e.m[8],e.m[9],e.m[10]])},e.Transpose=function(t){var i=new e;return e.TransposeToRef(t,i),i},e.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]},e.Reflection=function(t){var i=new e;return e.ReflectionToRef(t,i),i},e.ReflectionToRef=function(e,t){e.normalize();var i=e.normal.x,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()},e.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()},e.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()},e._tempQuaternion=new a,e._xAxis=n.Zero(),e._yAxis=n.Zero(),e._zAxis=n.Zero(),e._updateFlagSeed=0,e._identityReadOnly=e.Identity(),e}();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,p=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=p,(u=e.Space||(e.Space={}))[u.LOCAL=0]="LOCAL",u[u.WORLD=1]="WORLD",u[u.BONE=2]="BONE";var f=function(){function e(){}return e.X=new n(1,0,0),e.Y=new n(0,1,0),e.Z=new n(0,0,1),e}();e.Axis=f;var d,m,g=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=g,(m=d=e.Orientation||(e.Orientation={}))[m.CW=0]="CW",m[m.CCW=1]="CCW";var _=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=_;var v=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=_.BetweenTwoPoints(this.centerPoint,this.startPoint);var h=this.startAngle.degrees(),l=_.BetweenTwoPoints(this.centerPoint,this.midPoint).degrees(),c=_.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=_.FromDegrees(this.orientation===d.CW?h-c:c-h)}}();e.Arc2=v;var y=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 v(s,a,h),c=l.angle.radians()/o;l.orientation===d.CW&&(c*=-1);for(var u=l.startAngle.radians()+c,p=0;p<o;p++){var f=Math.cos(u)*l.radius+l.centerPoint.x,m=Math.sin(u)*l.radius+l.centerPoint.y;this.addLineTo(f,m),u+=c}return this},e.prototype.close=function(){return this.closed=!0,this},e.prototype.length=function(){var e=this._length;if(!this.closed){var t=this._points[this._points.length-1];e+=this._points[0].subtract(t).length()}return e},e.prototype.getPoints=function(){return this._points},e.prototype.getPointAtLengthPosition=function(e){if(e<0||e>1)return r.Zero();for(var t=e*this.length(),i=0,n=0;n<this._points.length;n++){var o=(n+1)%this._points.length,s=this._points[n],a=this._points[o].subtract(s),h=a.length()+i;if(t>=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=y;var b=function(){function t(e,t,i){void 0===t&&(t=null),this.path=e,this._curve=new Array,this._distances=new Array,this._tangents=new Array,this._normals=new Array,this._binormals=new Array;for(var r=0;r<e.length;r++)this._curve[r]=e[r].clone();this._raw=i||!1,this._compute(t)}return t.prototype.getCurve=function(){return this._curve},t.prototype.getTangents=function(){return this._tangents},t.prototype.getNormals=function(){return this._normals},t.prototype.getBinormals=function(){return this._binormals},t.prototype.getDistances=function(){return this._distances},t.prototype.update=function(e,t){void 0===t&&(t=null);for(var i=0;i<e.length;i++)this._curve[i].x=e[i].x,this._curve[i].y=e[i].y,this._curve[i].z=e[i].z;return this._compute(t),this},t.prototype._compute=function(e){var t=this._curve.length;this._tangents[0]=this._getFirstNonNullVector(0),this._raw||this._tangents[0].normalize(),this._tangents[t-1]=this._curve[t-1].subtract(this._curve[t-2]),this._raw||this._tangents[t-1].normalize();var i,r,o,s,a=this._tangents[0],h=this._normalVector(this._curve[0],a,e);this._normals[0]=h,this._raw||this._normals[0].normalize(),this._binormals[0]=n.Cross(a,this._normals[0]),this._raw||this._binormals[0].normalize(),this._distances[0]=0;for(var l=1;l<t;l++)i=this._getLastNonNullVector(l),l<t-1&&(r=this._getFirstNonNullVector(l),this._tangents[l]=i.add(r),this._tangents[l].normalize()),this._distances[l]=this._distances[l-1]+i.length(),o=this._tangents[l],s=this._binormals[l-1],this._normals[l]=n.Cross(s,o),this._raw||this._normals[l].normalize(),this._binormals[l]=n.Cross(o,this._normals[l]),this._raw||this._binormals[l].normalize()},t.prototype._getFirstNonNullVector=function(e){for(var t=1,i=this._curve[e+t].subtract(this._curve[e]);0===i.length()&&e+t+1<this._curve.length;)t++,i=this._curve[e+t].subtract(this._curve[e]);return i},t.prototype._getLastNonNullVector=function(e){for(var t=1,i=this._curve[e].subtract(this._curve[e-t]);0===i.length()&&e>t+1;)t++,i=this._curve[e].subtract(this._curve[e-t]);return i},t.prototype._normalVector=function(t,i,r){var o,s,a=i.length();(0===a&&(a=1),void 0===r||null===r)?(s=e.Scalar.WithinEpsilon(Math.abs(i.y)/a,1,e.Epsilon)?e.Scalar.WithinEpsilon(Math.abs(i.x)/a,1,e.Epsilon)?e.Scalar.WithinEpsilon(Math.abs(i.z)/a,1,e.Epsilon)?n.Zero():new n(0,0,1):new n(1,0,0):new n(0,-1,0),o=n.Cross(i,s)):(o=n.Cross(i,r),n.CrossToRef(o,i,o));return o.normalize(),o},t}();e.Path3D=b;var x=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;h<r.length-3;h++){a=0;for(var l=0;l<i;l++)o.push(n.CatmullRom(r[h],r[h+1],r[h+2],r[h+3],a)),a+=s}return h--,o.push(n.CatmullRom(r[h],r[h+1],r[h+2],r[h+3],a)),new e(o)},e.prototype.getPoints=function(){return this._points},e.prototype.length=function(){return this._length},e.prototype.continue=function(t){for(var i=this._points[this._points.length-1],r=this._points.slice(),n=t.getPoints(),o=1;o<n.length;o++)r.push(n[o].subtract(n[0]).add(i));return new e(r)},e.prototype._computeLength=function(e){for(var t=0,i=1;i<e.length;i++)t+=e[i].subtract(e[i-1]).length();return t},e}();e.Curve3=x;var T=function(){function e(e,t){void 0===e&&(e=n.Zero()),void 0===t&&(t=n.Up()),this.position=e,this.normal=t}return e.prototype.clone=function(){return new e(this.position.clone(),this.normal.clone())},e}();e.PositionNormalVertex=T;var E=function(){function e(e,t,i){void 0===e&&(e=n.Zero()),void 0===t&&(t=n.Up()),void 0===i&&(i=r.Zero()),this.position=e,this.normal=t,this.uv=i}return e.prototype.clone=function(){return new e(this.position.clone(),this.normal.clone(),this.uv.clone())},e}();e.PositionNormalTextureVertex=E;var A=function(){function e(){}return e.Color3=[t.Black(),t.Black(),t.Black()],e.Vector2=[r.Zero(),r.Zero(),r.Zero()],e.Vector3=[n.Zero(),n.Zero(),n.Zero(),n.Zero(),n.Zero(),n.Zero(),n.Zero(),n.Zero(),n.Zero()],e.Vector4=[o.Zero(),o.Zero(),o.Zero()],e.Quaternion=[a.Zero(),a.Zero()],e.Matrix=[h.Zero(),h.Zero(),h.Zero(),h.Zero(),h.Zero(),h.Zero(),h.Zero(),h.Zero()],e}();e.Tmp=A;var P=function(){function e(){}return e.Vector3=[n.Zero()],e.Matrix=[h.Zero(),h.Zero()],e.Quaternion=[a.Zero()],e}()}(us||(us={})),n=us||(us={}),o=function(){function e(){}return e.WithinEpsilon=function(e,t,i){void 0===i&&(i=1.401298e-45);var r=e-t;return-i<=r&&r<=i},e.ToHex=function(e){var t=e.toString(16);return e<=15?("0"+t).toUpperCase():t.toUpperCase()},e.Sign=function(e){return 0===(e=+e)||isNaN(e)?e:e>0?1:-1},e.Clamp=function(e,t,i){return void 0===t&&(t=0),void 0===i&&(i=1),Math.min(i,Math.max(t,e))},e.Log2=function(e){return Math.log(e)*Math.LOG2E},e.Repeat=function(e,t){return e-Math.floor(e/t)*t},e.Normalize=function(e,t,i){return(e-t)/(i-t)},e.Denormalize=function(e,t,i){return e*(i-t)+t},e.DeltaAngle=function(t,i){var r=e.Repeat(i-t,360);return r>180&&(r-=360),r},e.PingPong=function(t,i){var r=e.Repeat(t,2*i);return i-Math.abs(r-i)},e.SmoothStep=function(t,i,r){var n=e.Clamp(r);return i*(n=-2*n*n*n+3*n*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),o=0;return-r<n&&n<r?o=i:(i=t+n,o=e.MoveTowards(t,i,r)),o},e.Lerp=function(e,t,i){return e+(t-e)*i},e.LerpAngle=function(t,i,r){var n=e.Repeat(i-t,360);return n>180&&(n-=360),t+n*e.Clamp(r)},e.InverseLerp=function(t,i,r){return t!=i?e.Clamp((r-t)/(i-t)):0},e.Hermite=function(e,t,i,r,n){var o=n*n,s=n*o;return e*(2*s-3*o+1)+i*(-2*s+3*o)+t*(s-2*o+n)+r*(s-o)},e.RandomRange=function(e,t){return e===t?e:Math.random()*(t-e)+e},e.RangeToPercent=function(e,t,i){return(e-t)/(i-t)},e.PercentToRange=function(e,t,i){return(i-t)*e+t},e.NormalizeRadians=function(t){return t-=e.TwoPi*Math.floor((t+Math.PI)/e.TwoPi)},e.TwoPi=2*Math.PI,e}(),n.Scalar=o,function(e){var t={},i={},r=function(t,i,r){var o=t();e.Tags&&e.Tags.AddTagsTo(o,i.tags);var s=n(o);for(var a in s){var h=s[a],l=i[a],c=h.type;if(void 0!==l&&null!==l)switch(c){case 0:case 6:o[a]=l;break;case 1:o[a]=r||l.isRenderTarget?l:l.clone();break;case 2:case 3:case 4:case 5:case 7:case 10:o[a]=r?l:l.clone()}}return o};function n(e){var r=e.getClassName();if(i[r])return i[r];i[r]={};for(var n=i[r],o=e,s=r;s;){var a=t[s];for(var h in a)n[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 n}function o(e,i){return function(r,n){var o,s=(o=r.getClassName(),t[o]||(t[o]={}),t[o]);s[n]||(s[n]={type:e,sourceName:i})}}e.expandToProperty=function(e,t){return void 0===t&&(t=null),i=e,void 0===(r=t)&&(r=null),function(e,t){var n=r||"_"+t;Object.defineProperty(e,t,{get:function(){return this[n]},set:function(t){this[n]!==t&&(this[n]=t,e[i].apply(this))},enumerable:!0,configurable:!0})};var i,r},e.serialize=function(e){return o(0,e)},e.serializeAsTexture=function(e){return o(1,e)},e.serializeAsColor3=function(e){return o(2,e)},e.serializeAsFresnelParameters=function(e){return o(3,e)},e.serializeAsVector2=function(e){return o(4,e)},e.serializeAsVector3=function(e){return o(5,e)},e.serializeAsMeshReference=function(e){return o(6,e)},e.serializeAsColorCurves=function(e){return o(7,e)},e.serializeAsColor4=function(e){return o(8,e)},e.serializeAsImageProcessingConfiguration=function(e){return o(9,e)},e.serializeAsQuaternion=function(e){return o(10,e)};var s=function(){function t(){}return t.Serialize=function(t,i){i||(i={}),e.Tags&&(i.tags=e.Tags.GetTags(t));var r=n(t);for(var o in r){var s=r[o],a=s.sourceName||o,h=s.type,l=t[o];if(void 0!==l&&null!==l)switch(h){case 0:i[a]=l;break;case 1:i[a]=l.serialize();break;case 2:i[a]=l.asArray();break;case 3:i[a]=l.serialize();break;case 4:case 5:i[a]=l.asArray();break;case 6:i[a]=l.id;break;case 7:i[a]=l.serialize();break;case 8:i[a]=l.asArray();break;case 9:i[a]=l.serialize()}}return i},t.Parse=function(t,i,r,o){void 0===o&&(o=null);var s=t();o||(o=""),e.Tags&&e.Tags.AddTagsTo(s,i.tags);var a=n(s);for(var h in a){var l=a[h],c=i[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:r&&(p[h]=e.Texture.Parse(c,r,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:r&&(p[h]=r.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},t.Clone=function(e,t){return r(e,t,!1)},t.Instanciate=function(e,t){return r(e,t,!0)},t}();e.SerializationHelper=s}(us||(us={})),function(e){var t=function(){function e(e,t,i,r){void 0===t&&(t=!1),this.initalize(e,t,i,r)}return e.prototype.initalize=function(e,t,i,r){return void 0===t&&(t=!1),this.mask=e,this.skipNextObservers=t,this.target=i,this.currentTarget=r,this},e}();e.EventState=t;var i=function(){return function(e,t,i){void 0===i&&(i=null),this.callback=e,this.mask=t,this.scope=i}}();e.Observer=i;var r=function(){function e(){}return e.prototype.dispose=function(){if(this._observers&&this._observables)for(var e=0;e<this._observers.length;e++)this._observables[e].remove(this._observers[e]);this._observers=null,this._observables=null},e.Watch=function(t,i,r,n){void 0===r&&(r=-1),void 0===n&&(n=null);var o=new e;o._observers=new Array,o._observables=t;for(var s=0,a=t;s<a.length;s++){var h=a[s].add(i,r,!1,n);h&&o._observers.push(h)}return o},e}();e.MultiObserver=r;var n=function(){function e(e){this._observers=new Array,this._eventState=new t(0),e&&(this._onObserverAdded=e)}return e.prototype.add=function(e,t,r,n){if(void 0===t&&(t=-1),void 0===r&&(r=!1),void 0===n&&(n=null),!e)return null;var o=new i(e,t,n);return r?this._observers.unshift(o):this._observers.push(o),this._onObserverAdded&&this._onObserverAdded(o),o},e.prototype.remove=function(e){if(!e)return!1;var t=this._observers.indexOf(e);return-1!==t&&(this._observers.splice(t,1),!0)},e.prototype.removeCallback=function(e,t){for(var i=0;i<this._observers.length;i++)if(this._observers[i].callback===e&&(!t||t===this._observers[i].scope))return this._observers.splice(i,1),!0;return!1},e.prototype.notifyObservers=function(e,t,i,r){if(void 0===t&&(t=-1),!this._observers.length)return!0;var n=this._eventState;n.mask=t,n.target=i,n.currentTarget=r,n.skipNextObservers=!1;for(var o=0,s=this._observers;o<s.length;o++){var a=s[o];if(a.mask&t&&(a.scope?a.callback.apply(a.scope,[e,n]):a.callback(e,n)),n.skipNextObservers)return!1}return!0},e.prototype.notifyObserver=function(e,t,i){void 0===i&&(i=-1);var r=this._eventState;r.mask=i,r.skipNextObservers=!1,e.callback(t,r)},e.prototype.hasObservers=function(){return this._observers.length>0},e.prototype.clear=function(){this._observers=new Array,this._onObserverAdded=null},e.prototype.clone=function(){var t=new e;return t._observers=this._observers.slice(0),t},e.prototype.hasSpecificMask=function(e){void 0===e&&(e=-1);for(var t=0,i=this._observers;t<i.length;t++){var r=i[t];if(r.mask&e||r.mask===e)return!0}return!1},e}();e.Observable=n}(us||(us={})),function(e){var t=function(){function e(t){this.length=0,this.data=new Array(t),this._id=e._GlobalId++}return e.prototype.push=function(e){this.data[this.length++]=e,this.length>this.data.length&&(this.data.length*=2)},e.prototype.forEach=function(e){for(var t=0;t<this.length;t++)e(this.data[t])},e.prototype.sort=function(e){this.data.sort(e)},e.prototype.reset=function(){this.length=0},e.prototype.dispose=function(){this.reset(),this.data&&(this.data.length=0,this.data=[])},e.prototype.concat=function(e){if(0!==e.length){this.length+e.length>this.data.length&&(this.data.length=2*(this.length+e.length));for(var t=0;t<e.length;t++)this.data[this.length++]=(e.data||e)[t]}},e.prototype.indexOf=function(e){var t=this.data.indexOf(e);return t>=this.length?-1:t},e.prototype.contains=function(e){return-1!==this.data.indexOf(e)},e._GlobalId=0,e}();e.SmartArray=t;var i=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t._duplicateId=0,t}return Y(t,e),t.prototype.push=function(t){e.prototype.push.call(this,t),t.__smartArrayFlags||(t.__smartArrayFlags={}),t.__smartArrayFlags[this._id]=this._duplicateId},t.prototype.pushNoDuplicate=function(e){return(!e.__smartArrayFlags||e.__smartArrayFlags[this._id]!==this._duplicateId)&&(this.push(e),!0)},t.prototype.reset=function(){e.prototype.reset.call(this),this._duplicateId++},t.prototype.concatWithNoDuplicate=function(e){if(0!==e.length){this.length+e.length>this.data.length&&(this.data.length=2*(this.length+e.length));for(var t=0;t<e.length;t++){var i=(e.data||e)[t];this.pushNoDuplicate(i)}}},t}(t);e.SmartArrayNoDuplicate=i}(us||(us={})),function(e){var t=function(e){function t(i,r){var n=e.call(this,i)||this;return n.request=r,n.name="LoadFileError",t._setPrototypeOf(n,t.prototype),n}return Y(t,e),t._setPrototypeOf=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},t}(Error);e.LoadFileError=t;var i,r=function(){function e(){}return e.ExponentialBackoff=function(e,t){return void 0===e&&(e=3),void 0===t&&(t=500),function(i,r,n){return 0!==r.status||n>=e||-1!==i.indexOf("file:")?-1:Math.pow(2,n)*t}},e}();e.RetryStrategy=r;var n=function(t,i){return t?t instanceof e.Mesh?null:t instanceof e.SubMesh?t.clone(i):t.clone?t.clone():null:null},o=function(){function o(){}return o.Mix=function(e,t,i){return e*(1-i)+t*i},o.Instantiate=function(e){if(o.RegisteredExternalClasses&&o.RegisteredExternalClasses[e])return o.RegisteredExternalClasses[e];for(var t=e.split("."),i=window||this,r=0,n=t.length;r<n;r++)i=i[t[r]];return"function"!=typeof i?null:i},o.SetImmediate=function(e){window.setImmediate?window.setImmediate(e):setTimeout(e,1)},o.IsExponentOfTwo=function(e){var t=1;do{t*=2}while(t<e);return t===e},o.CeilingPOT=function(e){return e--,e|=e>>1,e|=e>>2,e|=e>>4,e|=e>>8,e|=e>>16,++e},o.FloorPOT=function(e){return e|=e>>1,e|=e>>2,e|=e>>4,e|=e>>8,(e|=e>>16)-(e>>1)},o.NearestPOT=function(e){var t=o.CeilingPOT(e),i=o.FloorPOT(e);return t-e>e-i?i:t},o.GetExponentOfTwo=function(t,i,r){var n;switch(void 0===r&&(r=e.Engine.SCALEMODE_NEAREST),r){case e.Engine.SCALEMODE_FLOOR:n=o.FloorPOT(t);break;case e.Engine.SCALEMODE_NEAREST:n=o.NearestPOT(t);break;case e.Engine.SCALEMODE_CEILING:default:n=o.CeilingPOT(t)}return Math.min(n,i)},o.GetFilename=function(e){var t=e.lastIndexOf("/");return t<0?e:e.substring(t+1)},o.GetFolderPath=function(e){var t=e.lastIndexOf("/");return t<0?"":e.substring(0,t+1)},o.GetDOMTextContent=function(e){for(var t="",i=e.firstChild;i;)3===i.nodeType&&(t+=i.textContent),i=i.nextSibling;return t},o.ToDegrees=function(e){return 180*e/Math.PI},o.ToRadians=function(e){return e*Math.PI/180},o.EncodeArrayBufferTobase64=function(e){for(var t,i,r,n,o,s,a,h="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",l="",c=0,u=new Uint8Array(e);c<u.length;)n=(t=u[c++])>>2,o=(3&t)<<4|(i=c<u.length?u[c++]:Number.NaN)>>4,s=(15&i)<<2|(r=c<u.length?u[c++]:Number.NaN)>>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},o.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+n;h++){var l=new e.Vector3(t[3*i[h]],t[3*i[h]+1],t[3*i[h]+2]);s=e.Vector3.Minimize(l,s),a=e.Vector3.Maximize(l,a)}return o&&(s.x-=s.x*o.x+o.y,s.y-=s.y*o.x+o.y,s.z-=s.z*o.x+o.y,a.x+=a.x*o.x+o.y,a.y+=a.y*o.x+o.y,a.z+=a.z*o.x+o.y),{minimum:s,maximum:a}},o.ExtractMinAndMax=function(t,i,r,n,o){void 0===n&&(n=null);var s=new e.Vector3(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),a=new e.Vector3(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE);o||(o=3);for(var h=i;h<i+r;h++){var l=new e.Vector3(t[h*o],t[h*o+1],t[h*o+2]);s=e.Vector3.Minimize(l,s),a=e.Vector3.Maximize(l,a)}return n&&(s.x-=s.x*n.x+n.y,s.y-=s.y*n.x+n.y,s.z-=s.z*n.x+n.y,a.x+=a.x*n.x+n.y,a.y+=a.y*n.x+n.y,a.z+=a.z*n.x+n.y),{minimum:s,maximum:a}},o.Vector2ArrayFeeder=function(t){return function(i){var r=void 0!==t.BYTES_PER_ELEMENT;if(i>=(r?t.length/2:t.length))return null;if(r){var n=t;return new e.Vector2(n[2*i+0],n[2*i+1])}return t[i]}},o.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}},o.MakeArray=function(e,t){return!0===t||void 0!==e&&null!=e?Array.isArray(e)?e:[e]:null},o.GetPointerPrefix=function(){var e="pointer";return!o.IsWindowObjectExist()||window.PointerEvent||navigator.pointerEnabled||(e="mouse"),e},o.QueueNewFrame=function(e,t){return o.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)},o.RequestFullscreen=function(e){var t=e.requestFullscreen||e.msRequestFullscreen||e.webkitRequestFullscreen||e.mozRequestFullScreen;t&&t.call(e)},o.ExitFullscreen=function(){document.exitFullscreen?document.exitFullscreen():document.mozCancelFullScreen?document.mozCancelFullScreen():document.webkitCancelFullScreen?document.webkitCancelFullScreen():document.msCancelFullScreen&&document.msCancelFullScreen()},o.SetCorsBehavior=function(e,t){if((!e||0!==e.indexOf("data:"))&&o.CorsBehavior)if("string"==typeof o.CorsBehavior||o.CorsBehavior instanceof String)t.crossOrigin=o.CorsBehavior;else{var i=o.CorsBehavior(e);i&&(t.crossOrigin=i)}},o.CleanUrl=function(e){return e=e.replace(/#/gm,"%23")},o.LoadImage=function(t,i,r,n){t instanceof ArrayBuffer&&(t=o.EncodeArrayBufferTobase64(t)),t=o.CleanUrl(t),t=o.PreprocessUrl(t);var s=new Image;o.SetCorsBehavior(t,s),s.onload=function(){i(s)},s.onerror=function(e){o.Error("Error while trying to load image: "+t),r&&r("Error while trying to load image: "+t,e)};var a=function(){s.src=t};if("data:"!==t.substr(0,5)&&n&&n.enableTexturesOffline&&e.Database.IsUASupportingBlobStorage)n.openAsync(function(){n&&n.loadImageFromDB(t,s)},a);else{if(-1!==t.indexOf("file:")){var h=decodeURIComponent(t.substring(5).toLowerCase());if(e.FilesInput.FilesToLoad[h]){try{var l;try{l=URL.createObjectURL(e.FilesInput.FilesToLoad[h],{oneTimeOnly:!0})}catch(t){l=URL.createObjectURL(e.FilesInput.FilesToLoad[h])}s.src=l}catch(e){s.src=""}return s}}a()}return s},o.LoadFile=function(i,r,n,s,a,h){if(i=o.CleanUrl(i),-1!==(i=o.PreprocessUrl(i)).indexOf("file:")){var l=decodeURIComponent(i.substring(5).toLowerCase());if(e.FilesInput.FilesToLoad[l])return o.ReadFile(e.FilesInput.FilesToLoad[l],r,n,a)}var c=o.BaseUrl+i,u=!1,p={onCompleteObservable:new e.Observable,abort:function(){return u=!0}},f=function(){var e=new XMLHttpRequest,i=null;p.abort=function(){u=!0,e.readyState!==(XMLHttpRequest.DONE||4)&&e.abort(),null!==i&&(clearTimeout(i),i=null)};var s=function(l){e.open("GET",c,!0),a&&(e.responseType="arraybuffer"),n&&e.addEventListener("progress",n);var f=function(){p.onCompleteObservable.notifyObservers(p)};e.addEventListener("loadend",f);var d=function(){if(!u&&e.readyState===(XMLHttpRequest.DONE||4)){if(e.removeEventListener("readystatechange",d),e.status>=200&&e.status<300||!o.IsWindowObjectExist()&&0===e.status)return void r(a?e.response:e.responseText,e.responseURL);var n=o.DefaultRetryStrategy;if(n){var p=n(c,e,l);if(-1!==p)return e.removeEventListener("loadend",f),e=new XMLHttpRequest,void(i=setTimeout(function(){return s(l+1)},p))}var m=new t("Error status: "+e.status+" "+e.statusText+" - Unable to load "+c,e);if(!h)throw m;h(e,m)}};e.addEventListener("readystatechange",d),e.send()};s(0)};if(s&&s.enableSceneOffline){var d=function(){u||f()};s.openAsync(function(){u||s&&s.loadFileFromDB(i,function(e){u||r(e),p.onCompleteObservable.notifyObservers(p)},n?function(e){u||n(e)}:void 0,d,a)},d)}else f();return p},o.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)},o.ReadFileAsDataURL=function(t,i,r){var n=new FileReader,o={onCompleteObservable:new e.Observable,abort:function(){return n.abort()}};return n.onloadend=function(e){o.onCompleteObservable.notifyObservers(o)},n.onload=function(e){i(e.target.result)},n.onprogress=r,n.readAsDataURL(t),o},o.ReadFile=function(t,i,r,n){var s=new FileReader,a={onCompleteObservable:new e.Observable,abort:function(){return s.abort()}};return s.onloadend=function(e){return a.onCompleteObservable.notifyObservers(a)},s.onerror=function(e){o.Log("Error while reading file: "+t.name),i(JSON.stringify({autoClear:!0,clearColor:[1,0,0],ambientColor:[0,0,0],gravity:[0,-9.807,0],meshes:[],cameras:[],lights:[]}))},s.onload=function(e){i(e.target.result)},r&&(s.onprogress=r),n?s.readAsArrayBuffer(t):s.readAsText(t),a},o.FileAsURL=function(e){var t=new Blob([e]);return(window.URL||window.webkitURL).createObjectURL(t)},o.Format=function(e,t){return void 0===t&&(t=2),e.toFixed(t)},o.CheckExtends=function(e,t,i){e.x<t.x&&(t.x=e.x),e.y<t.y&&(t.y=e.y),e.z<t.z&&(t.z=e.z),e.x>i.x&&(i.x=e.x),e.y>i.y&&(i.y=e.y),e.z>i.z&&(i.z=e.z)},o.DeepCopy=function(e,t,i,r){for(var o in e)if(("_"!==o[0]||r&&-1!==r.indexOf(o))&&(!i||-1===i.indexOf(o))){var s=e[o],a=typeof s;if("function"!==a)if("object"===a)if(s instanceof Array){if(t[o]=[],s.length>0)if("object"==typeof s[0])for(var h=0;h<s.length;h++){var l=n(s[h],t);-1===t[o].indexOf(l)&&t[o].push(l)}else t[o]=s.slice(0)}else t[o]=n(s,t);else t[o]=s}},o.IsEmpty=function(e){for(var t in e)if(e.hasOwnProperty(t))return!1;return!0},o.RegisterTopRootEvents=function(e){for(var t=0;t<e.length;t++){var i=e[t];window.addEventListener(i.name,i.handler,!1);try{window.parent&&window.parent.addEventListener(i.name,i.handler,!1)}catch(e){}}},o.UnregisterTopRootEvents=function(e){for(var t=0;t<e.length;t++){var i=e[t];window.removeEventListener(i.name,i.handler);try{window.parent&&window.parent.removeEventListener(i.name,i.handler)}catch(e){}}},o.DumpFramebuffer=function(e,t,r,n,s,a){void 0===s&&(s="image/png");for(var h=4*e,l=t/2,c=r.readPixels(0,0,e,t),u=0;u<l;u++)for(var p=0;p<h;p++){var f=p+u*h,d=p+(t-u-1)*h,m=c[f];c[f]=c[d],c[d]=m}i||(i=document.createElement("canvas")),i.width=e,i.height=t;var g=i.getContext("2d");if(g){var _=g.createImageData(e,t);_.data.set(c),g.putImageData(_,0,0),o.EncodeScreenshotCanvasData(n,s,a)}},o.EncodeScreenshotCanvasData=function(e,t,r){void 0===t&&(t="image/png");var n=i.toDataURL(t);e?e(n):(i.toBlob||(i.toBlob=function(e,t,i){var r=this;setTimeout(function(){for(var n=atob(r.toDataURL(t,i).split(",")[1]),o=n.length,s=new Uint8Array(o),a=0;a<o;a++)s[a]=n.charCodeAt(a);e(new Blob([s],{type:t||"image/png"}))})}),i.toBlob(function(e){var t=URL.createObjectURL(e);if("download"in document.createElement("a")){var i=window.document.createElement("a");if(i.href=t,r)i.setAttribute("download",r);else{var n=new Date,o=(n.getFullYear()+"-"+(n.getMonth()+1)).slice(-2)+"-"+n.getDate()+"_"+n.getHours()+"-"+("0"+n.getMinutes()).slice(-2);i.setAttribute("download","screenshot_"+o+".png")}window.document.body.appendChild(i),i.addEventListener("click",function(){i.parentElement&&i.parentElement.removeChild(i)}),i.click()}else{var s=window.open("");if(!s)return;var a=s.document.createElement("img");a.onload=function(){URL.revokeObjectURL(t)},a.src=t,s.document.body.appendChild(a)}}))},o.CreateScreenshot=function(e,t,r,n,s){var a,h;if(void 0===s&&(s="image/png"),r.precision)a=Math.round(e.getRenderWidth()*r.precision),h=Math.round(a/e.getAspectRatio(t));else if(r.width&&r.height)a=r.width,h=r.height;else if(r.width&&!r.height)a=r.width,h=Math.round(a/e.getAspectRatio(t));else if(r.height&&!r.width)h=r.height,a=Math.round(h*e.getAspectRatio(t));else{if(isNaN(r))return void o.Error("Invalid 'size' parameter !");h=r,a=r}i||(i=document.createElement("canvas")),i.width=a,i.height=h;var l=i.getContext("2d"),c=e.getRenderWidth()/e.getRenderHeight(),u=a,p=u/c;p>h&&(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),o.EncodeScreenshotCanvasData(n,s)},o.CreateScreenshotUsingRenderTarget=function(t,i,r,n,s,a,h,l){var c,u;if(void 0===s&&(s="image/png"),void 0===a&&(a=1),void 0===h&&(h=!1),r.precision)c=Math.round(t.getRenderWidth()*r.precision),u=Math.round(c/t.getAspectRatio(i)),r={width:c,height:u};else if(r.width&&r.height)c=r.width,u=r.height;else if(r.width&&!r.height)c=r.width,u=Math.round(c/t.getAspectRatio(i)),r={width:c,height:u};else if(r.height&&!r.width)u=r.height,r={width:c=Math.round(u*t.getAspectRatio(i)),height:u};else{if(isNaN(r))return void o.Error("Invalid 'size' parameter !");u=r,c=r}var p=i.getScene(),f=null;p.activeCamera!==i&&(f=p.activeCamera,p.activeCamera=i);var d=new e.RenderTargetTexture("screenShot",r,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(){o.DumpFramebuffer(c,u,t,n,s,l)}),p.incrementRenderId(),p.resetCachedMaterial(),d.render(!0),d.dispose(),f&&(p.activeCamera=f),i.getProjectionMatrix(!0)},o.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.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},o.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(o,"NoneLogLevel",{get:function(){return o._NoneLogLevel},enumerable:!0,configurable:!0}),Object.defineProperty(o,"MessageLogLevel",{get:function(){return o._MessageLogLevel},enumerable:!0,configurable:!0}),Object.defineProperty(o,"WarningLogLevel",{get:function(){return o._WarningLogLevel},enumerable:!0,configurable:!0}),Object.defineProperty(o,"ErrorLogLevel",{get:function(){return o._ErrorLogLevel},enumerable:!0,configurable:!0}),Object.defineProperty(o,"AllLogLevel",{get:function(){return o._MessageLogLevel|o._WarningLogLevel|o._ErrorLogLevel},enumerable:!0,configurable:!0}),o._AddLogEntry=function(e){o._LogCache=e+o._LogCache,o.OnNewCacheEntry&&o.OnNewCacheEntry(e)},o._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},o._LogDisabled=function(e){},o._LogEnabled=function(e){var t=o._FormatMessage(e);console.log("BJS - "+t);var i="<div style='color:white'>"+t+"</div><br>";o._AddLogEntry(i)},o._WarnDisabled=function(e){},o._WarnEnabled=function(e){var t=o._FormatMessage(e);console.warn("BJS - "+t);var i="<div style='color:orange'>"+t+"</div><br>";o._AddLogEntry(i)},o._ErrorDisabled=function(e){},o._ErrorEnabled=function(e){o.errorsCount++;var t=o._FormatMessage(e);console.error("BJS - "+t);var i="<div style='color:red'>"+t+"</div><br>";o._AddLogEntry(i)},Object.defineProperty(o,"LogCache",{get:function(){return o._LogCache},enumerable:!0,configurable:!0}),o.ClearLogCache=function(){o._LogCache="",o.errorsCount=0},Object.defineProperty(o,"LogLevels",{set:function(e){(e&o.MessageLogLevel)===o.MessageLogLevel?o.Log=o._LogEnabled:o.Log=o._LogDisabled,(e&o.WarningLogLevel)===o.WarningLogLevel?o.Warn=o._WarnEnabled:o.Warn=o._WarnDisabled,(e&o.ErrorLogLevel)===o.ErrorLogLevel?o.Error=o._ErrorEnabled:o.Error=o._ErrorDisabled},enumerable:!0,configurable:!0}),o.IsWindowObjectExist=function(){return"undefined"!=typeof window},Object.defineProperty(o,"PerformanceNoneLogLevel",{get:function(){return o._PerformanceNoneLogLevel},enumerable:!0,configurable:!0}),Object.defineProperty(o,"PerformanceUserMarkLogLevel",{get:function(){return o._PerformanceUserMarkLogLevel},enumerable:!0,configurable:!0}),Object.defineProperty(o,"PerformanceConsoleLogLevel",{get:function(){return o._PerformanceConsoleLogLevel},enumerable:!0,configurable:!0}),Object.defineProperty(o,"PerformanceLogLevel",{set:function(e){return(e&o.PerformanceUserMarkLogLevel)===o.PerformanceUserMarkLogLevel?(o.StartPerformanceCounter=o._StartUserMark,void(o.EndPerformanceCounter=o._EndUserMark)):(e&o.PerformanceConsoleLogLevel)===o.PerformanceConsoleLogLevel?(o.StartPerformanceCounter=o._StartPerformanceConsole,void(o.EndPerformanceCounter=o._EndPerformanceConsole)):(o.StartPerformanceCounter=o._StartPerformanceCounterDisabled,void(o.EndPerformanceCounter=o._EndPerformanceCounterDisabled))},enumerable:!0,configurable:!0}),o._StartPerformanceCounterDisabled=function(e,t){},o._EndPerformanceCounterDisabled=function(e,t){},o._StartUserMark=function(e,t){if(void 0===t&&(t=!0),!o._performance){if(!o.IsWindowObjectExist())return;o._performance=window.performance}t&&o._performance.mark&&o._performance.mark(e+"-Begin")},o._EndUserMark=function(e,t){void 0===t&&(t=!0),t&&o._performance.mark&&(o._performance.mark(e+"-End"),o._performance.measure(e,e+"-Begin",e+"-End"))},o._StartPerformanceConsole=function(e,t){void 0===t&&(t=!0),t&&(o._StartUserMark(e,t),console.time&&console.time(e))},o._EndPerformanceConsole=function(e,t){void 0===t&&(t=!0),t&&(o._EndUserMark(e,t),console.time&&console.timeEnd(e))},Object.defineProperty(o,"Now",{get:function(){return o.IsWindowObjectExist()&&window.performance&&window.performance.now?window.performance.now():(new Date).getTime()},enumerable:!0,configurable:!0}),o.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},o.First=function(e,t){for(var i=0,r=e;i<r.length;i++){var n=r[i];if(t(n))return n}return null},o.getFullClassName=function(e,t){void 0===t&&(t=!1);var i=null,r=null;if(!t&&e.getClassName)i=e.getClassName();else{if(e instanceof Object){var n=t?e:Object.getPrototypeOf(e);i=n.constructor.__bjsclassName__,r=n.constructor.__bjsmoduleName__}i||(i=typeof e)}return i?(null!=r?r+".":"")+i:null},o.arrayOrStringFeeder=function(e){return function(t){if(t>=e.length)return null;var i=e.charCodeAt?e.charCodeAt(t):e[t];return i&&i.getHashCode&&(i=i.getHashCode()),"string"==typeof i?o.hashCodeFromStream(o.arrayOrStringFeeder(i)):i}},o.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},o.BaseUrl="",o.DefaultRetryStrategy=r.ExponentialBackoff(),o.CorsBehavior="anonymous",o.UseFallbackTexture=!0,o.RegisteredExternalClasses={},o.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",o.PreprocessUrl=function(e){return e},o._NoneLogLevel=0,o._MessageLogLevel=1,o._WarningLogLevel=2,o._ErrorLogLevel=4,o._LogCache="",o.errorsCount=0,o.Log=o._LogEnabled,o.Warn=o._WarnEnabled,o.Error=o._ErrorEnabled,o._PerformanceNoneLogLevel=0,o._PerformanceUserMarkLogLevel=1,o._PerformanceConsoleLogLevel=2,o.StartPerformanceCounter=o._StartPerformanceCounterDisabled,o.EndPerformanceCounter=o._EndPerformanceCounterDisabled,o}();e.Tools=o;var s=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=o.Now)},e.prototype.endMonitoring=function(t){if(void 0===t&&(t=!0),e.Enabled){t&&this.fetchNewFrame();var i=o.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=o.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=s,e.className=function(e,t){return function(i){i.__bjsclassName__=e,i.__bjsmoduleName__=null!=t?t:null}};var a=function(){function e(e,t,i,r){void 0===r&&(r=0),this.iterations=e,this._fn=t,this._successCallback=i,this.index=r-1,this._done=!1}return e.prototype.executeNext=function(){this._done||(this.index+1<this.iterations?(++this.index,this._fn(this)):this.breakLoop())},e.prototype.breakLoop=function(){this._done=!0,this._successCallback()},e.Run=function(t,i,r,n){void 0===n&&(n=0);var o=new e(t,i,r,n);return o.executeNext(),o},e.SyncAsyncForLoop=function(t,i,r,n,o,s){void 0===s&&(s=0),e.Run(Math.ceil(t/i),function(e){o&&o()?e.breakLoop():setTimeout(function(){for(var n=0;n<i;++n){var s=e.index*i+n;if(s>=t)break;if(r(s),o&&o()){e.breakLoop();break}}e.executeNext()},s)},n)},e}();e.AsyncLoop=a}(us||(us={})),s=us||(us={}),a=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}(),s._AlphaState=a,h=us||(us={}),l=function(){function e(){this._isDepthTestDirty=!1,this._isDepthMaskDirty=!1,this._isDepthFuncDirty=!1,this._isCullFaceDirty=!1,this._isCullDirty=!1,this._isZOffsetDirty=!1,this._isFrontFaceDirty=!1,this.reset()}return Object.defineProperty(e.prototype,"isDirty",{get:function(){return this._isDepthFuncDirty||this._isDepthTestDirty||this._isDepthMaskDirty||this._isCullFaceDirty||this._isCullDirty||this._isZOffsetDirty||this._isFrontFaceDirty},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}),Object.defineProperty(e.prototype,"frontFace",{get:function(){return this._frontFace},set:function(e){this._frontFace!==e&&(this._frontFace=e,this._isFrontFaceDirty=!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._frontFace=null,this._isDepthTestDirty=!0,this._isDepthMaskDirty=!0,this._isDepthFuncDirty=!1,this._isCullFaceDirty=!1,this._isCullDirty=!1,this._isZOffsetDirty=!1,this._isFrontFaceDirty=!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),this._isFrontFaceDirty&&(e.frontFace(this.frontFace),this._isFrontFaceDirty=!1))},e}(),h._DepthCullingState=l,c=us||(us={}),u=function(){function e(){this._isStencilTestDirty=!1,this._isStencilMaskDirty=!1,this._isStencilFuncDirty=!1,this._isStencilOpDirty=!1,this.reset()}return Object.defineProperty(e.prototype,"isDirty",{get:function(){return this._isStencilTestDirty||this._isStencilMaskDirty||this._isStencilFuncDirty||this._isStencilOpDirty},enumerable:!0,configurable:!0}),Object.defineProperty(e.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(e.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(e.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(e.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(e.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(e.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(e.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(e.prototype,"stencilTest",{get:function(){return this._stencilTest},set:function(e){this._stencilTest!==e&&(this._stencilTest=e,this._isStencilTestDirty=!0)},enumerable:!0,configurable:!0}),e.prototype.reset=function(){this._stencilTest=!1,this._stencilMask=255,this._stencilFunc=c.Engine.ALWAYS,this._stencilFuncRef=1,this._stencilFuncMask=255,this._stencilOpStencilFail=c.Engine.KEEP,this._stencilOpDepthFail=c.Engine.KEEP,this._stencilOpStencilDepthPass=c.Engine.REPLACE,this._isStencilTestDirty=!0,this._isStencilMaskDirty=!0,this._isStencilFuncDirty=!0,this._isStencilOpDirty=!0},e.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))},e}(),c._StencilState=u,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){var a;void 0===s&&(s=null);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(){return function(){}}(),s=function(){return function(){}}();e.InstancingAttributeInfo=s;var a=function(){return function(){}}();e.RenderTargetCreationOptions=a;var h=function(){return function(){}}();e.EngineCapabilities=h;var l=function(){function s(t,i,r,n){void 0===n&&(n=!1);var a=this;this.forcePOTTextures=!1,this.isFullscreen=!1,this.isPointerLock=!1,this.cullBackFaces=!0,this.renderEvenInBackground=!0,this.preventCacheWipeBetweenFrames=!1,this.enableOfflineSupport=!1,this.scenes=new Array,this.postProcesses=new Array,this.onResizeObservable=new e.Observable,this.onCanvasBlurObservable=new e.Observable,this.onCanvasFocusObservable=new e.Observable,this.onCanvasPointerOutObservable=new e.Observable,this.onBeforeTextureInitObservable=new e.Observable,this._vrDisplay=void 0,this._vrSupported=!1,this._vrExclusivePointerMode=!1,this.disableUniformBuffers=!1,this._uniformBuffers=new Array,this.onBeginFrameObservable=new e.Observable,this.onEndFrameObservable=new e.Observable,this.onBeforeShaderCompilationObservable=new e.Observable,this.onAfterShaderCompilationObservable=new e.Observable,this._windowIsBackground=!1,this._webGLVersion=1,this._badOS=!1,this._badDesktopOS=!1,this.disableTextureBindingOptimization=!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._textureCollisions=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._DepthCullingState,this._stencilState=new e._StencilState,this._alphaState=new e._AlphaState,this._alphaMode=s.ALPHA_DISABLE,this._internalTexturesCache=new Array,this._boundTexturesCache={},this._boundTexturesStack=new Array,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._nextFreeTextureSlots=new Array,this._maxSimultaneousTextures=0,this._activeRequests=new Array,this._texturesSupported=new Array,this._onVRFullScreenTriggered=function(){if(a._vrDisplay&&a._vrDisplay.isPresenting){a._oldSize=new e.Size(a.getRenderWidth(),a.getRenderHeight()),a._oldHardwareScaleFactor=a.getHardwareScalingLevel();var t=a._vrDisplay.getEyeParameters("left");a.setHardwareScalingLevel(1),a.setSize(2*t.renderWidth,t.renderHeight)}else a.setHardwareScalingLevel(a._oldHardwareScaleFactor),a.setSize(a._oldSize.width,a._oldSize.height)},this._boundUniforms={};var h=null;if(s.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,navigator&&navigator.userAgent)for(var l=navigator.userAgent,c=0,u=s.ExceptionList;c<u.length;c++){var p=u[c],f=p.key,d=p.targets;if(l.indexOf(f)>-1){if(p.capture&&p.captureConstraint){var m=p.capture,g=p.captureConstraint,_=new RegExp(m).exec(l);if(_&&_.length>0)if(parseInt(_[_.length-1])>=g)continue}for(var v=0,y=d;v<y.length;v++){switch(y[v]){case"uniformBuffer":this.disableUniformBuffers=!0;break;case"textureBindingOptimization":this.disableTextureBindingOptimization=!0}}break}}if(!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(){a.onCanvasFocusObservable.notifyObservers(a)},this._onCanvasBlur=function(){a.onCanvasBlurObservable.notifyObservers(a)},h.addEventListener("focus",this._onCanvasFocus),h.addEventListener("blur",this._onCanvasBlur),this._onBlur=function(){a.disablePerformanceMonitorInBackground&&a._performanceMonitor.disable(),a._windowIsBackground=!0},this._onFocus=function(){a.disablePerformanceMonitorInBackground&&a._performanceMonitor.enable(),a._windowIsBackground=!1},this._onCanvasPointerOut=function(){a.onCanvasPointerOutObservable.notifyObservers(a)},window.addEventListener("blur",this._onBlur),window.addEventListener("focus",this._onFocus),h.addEventListener("pointerout",this._onCanvasPointerOut),this._doNotHandleContextLost||(this._onContextLost=function(t){t.preventDefault(),a._contextWasLost=!0,e.Tools.Warn("WebGL context lost."),a.onContextLostObservable.notifyObservers(a)},this._onContextRestored=function(t){setTimeout(function(){a._initGLContext(),a._rebuildEffects(),a._rebuildInternalTextures(),a._rebuildBuffers(),a.wipeCaches(!0),e.Tools.Warn("WebGL context successfully restored."),a.onContextRestoredObservable.notifyObservers(a),a._contextWasLost=!1},0)},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 b=r.limitDeviceRatio||window.devicePixelRatio||1;this._hardwareScalingLevel=n?1/Math.min(b,window.devicePixelRatio||1):1,this.resize(),this._isStencilEnable=!!r.stencil,this._initGLContext(),h&&(this._onFullscreenChange=function(){void 0!==document.fullscreen?a.isFullscreen=document.fullscreen:void 0!==document.mozFullScreen?a.isFullscreen=document.mozFullScreen:void 0!==document.webkitIsFullScreen?a.isFullscreen=document.webkitIsFullScreen:void 0!==document.msIsFullScreen&&(a.isFullscreen=document.msIsFullScreen),a.isFullscreen&&a._pointerLockRequested&&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(){a.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&&!s.audioEngine&&(s.audioEngine=new e.AudioEngine);for(var x=0;x<this._caps.maxVertexAttribs;x++)this._currentBufferPointers[x]=new o;r.autoEnableWebVR&&this.initWebVR(),this._badOS=/iPad/i.test(navigator.userAgent)||/iPhone/i.test(navigator.userAgent),this._badDesktopOS=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),e.Tools.Log("Babylon.js engine (v"+s.Version+") launched"),this.enableOfflineSupport=void 0!==e.Database}}return Object.defineProperty(s,"LastCreatedEngine",{get:function(){return 0===s.Instances.length?null:s.Instances[s.Instances.length-1]},enumerable:!0,configurable:!0}),Object.defineProperty(s,"LastCreatedScene",{get:function(){var e=s.LastCreatedEngine;return e?0===e.scenes.length?null:e.scenes[e.scenes.length-1]:null},enumerable:!0,configurable:!0}),s.MarkAllMaterialsAsDirty=function(e,t){for(var i=0;i<s.Instances.length;i++)for(var r=s.Instances[i],n=0;n<r.scenes.length;n++)r.scenes[n].markAllMaterialsAsDirty(e,t)},Object.defineProperty(s,"NEVER",{get:function(){return s._NEVER},enumerable:!0,configurable:!0}),Object.defineProperty(s,"ALWAYS",{get:function(){return s._ALWAYS},enumerable:!0,configurable:!0}),Object.defineProperty(s,"LESS",{get:function(){return s._LESS},enumerable:!0,configurable:!0}),Object.defineProperty(s,"EQUAL",{get:function(){return s._EQUAL},enumerable:!0,configurable:!0}),Object.defineProperty(s,"LEQUAL",{get:function(){return s._LEQUAL},enumerable:!0,configurable:!0}),Object.defineProperty(s,"GREATER",{get:function(){return s._GREATER},enumerable:!0,configurable:!0}),Object.defineProperty(s,"GEQUAL",{get:function(){return s._GEQUAL},enumerable:!0,configurable:!0}),Object.defineProperty(s,"NOTEQUAL",{get:function(){return s._NOTEQUAL},enumerable:!0,configurable:!0}),Object.defineProperty(s,"KEEP",{get:function(){return s._KEEP},enumerable:!0,configurable:!0}),Object.defineProperty(s,"REPLACE",{get:function(){return s._REPLACE},enumerable:!0,configurable:!0}),Object.defineProperty(s,"INCR",{get:function(){return s._INCR},enumerable:!0,configurable:!0}),Object.defineProperty(s,"DECR",{get:function(){return s._DECR},enumerable:!0,configurable:!0}),Object.defineProperty(s,"INVERT",{get:function(){return s._INVERT},enumerable:!0,configurable:!0}),Object.defineProperty(s,"INCR_WRAP",{get:function(){return s._INCR_WRAP},enumerable:!0,configurable:!0}),Object.defineProperty(s,"DECR_WRAP",{get:function(){return s._DECR_WRAP},enumerable:!0,configurable:!0}),Object.defineProperty(s,"ALPHA_DISABLE",{get:function(){return s._ALPHA_DISABLE},enumerable:!0,configurable:!0}),Object.defineProperty(s,"ALPHA_ONEONE",{get:function(){return s._ALPHA_ONEONE},enumerable:!0,configurable:!0}),Object.defineProperty(s,"ALPHA_ADD",{get:function(){return s._ALPHA_ADD},enumerable:!0,configurable:!0}),Object.defineProperty(s,"ALPHA_COMBINE",{get:function(){return s._ALPHA_COMBINE},enumerable:!0,configurable:!0}),Object.defineProperty(s,"ALPHA_SUBTRACT",{get:function(){return s._ALPHA_SUBTRACT},enumerable:!0,configurable:!0}),Object.defineProperty(s,"ALPHA_MULTIPLY",{get:function(){return s._ALPHA_MULTIPLY},enumerable:!0,configurable:!0}),Object.defineProperty(s,"ALPHA_MAXIMIZED",{get:function(){return s._ALPHA_MAXIMIZED},enumerable:!0,configurable:!0}),Object.defineProperty(s,"ALPHA_PREMULTIPLIED",{get:function(){return s._ALPHA_PREMULTIPLIED},enumerable:!0,configurable:!0}),Object.defineProperty(s,"ALPHA_PREMULTIPLIED_PORTERDUFF",{get:function(){return s._ALPHA_PREMULTIPLIED_PORTERDUFF},enumerable:!0,configurable:!0}),Object.defineProperty(s,"ALPHA_INTERPOLATE",{get:function(){return s._ALPHA_INTERPOLATE},enumerable:!0,configurable:!0}),Object.defineProperty(s,"ALPHA_SCREENMODE",{get:function(){return s._ALPHA_SCREENMODE},enumerable:!0,configurable:!0}),Object.defineProperty(s,"DELAYLOADSTATE_NONE",{get:function(){return s._DELAYLOADSTATE_NONE},enumerable:!0,configurable:!0}),Object.defineProperty(s,"DELAYLOADSTATE_LOADED",{get:function(){return s._DELAYLOADSTATE_LOADED},enumerable:!0,configurable:!0}),Object.defineProperty(s,"DELAYLOADSTATE_LOADING",{get:function(){return s._DELAYLOADSTATE_LOADING},enumerable:!0,configurable:!0}),Object.defineProperty(s,"DELAYLOADSTATE_NOTLOADED",{get:function(){return s._DELAYLOADSTATE_NOTLOADED},enumerable:!0,configurable:!0}),Object.defineProperty(s,"TEXTUREFORMAT_ALPHA",{get:function(){return s._TEXTUREFORMAT_ALPHA},enumerable:!0,configurable:!0}),Object.defineProperty(s,"TEXTUREFORMAT_LUMINANCE",{get:function(){return s._TEXTUREFORMAT_LUMINANCE},enumerable:!0,configurable:!0}),Object.defineProperty(s,"TEXTUREFORMAT_LUMINANCE_ALPHA",{get:function(){return s._TEXTUREFORMAT_LUMINANCE_ALPHA},enumerable:!0,configurable:!0}),Object.defineProperty(s,"TEXTUREFORMAT_RGB",{get:function(){return s._TEXTUREFORMAT_RGB},enumerable:!0,configurable:!0}),Object.defineProperty(s,"TEXTUREFORMAT_RGBA",{get:function(){return s._TEXTUREFORMAT_RGBA},enumerable:!0,configurable:!0}),Object.defineProperty(s,"TEXTURETYPE_UNSIGNED_INT",{get:function(){return s._TEXTURETYPE_UNSIGNED_INT},enumerable:!0,configurable:!0}),Object.defineProperty(s,"TEXTURETYPE_FLOAT",{get:function(){return s._TEXTURETYPE_FLOAT},enumerable:!0,configurable:!0}),Object.defineProperty(s,"TEXTURETYPE_HALF_FLOAT",{get:function(){return s._TEXTURETYPE_HALF_FLOAT},enumerable:!0,configurable:!0}),Object.defineProperty(s,"SCALEMODE_FLOOR",{get:function(){return s._SCALEMODE_FLOOR},enumerable:!0,configurable:!0}),Object.defineProperty(s,"SCALEMODE_NEAREST",{get:function(){return s._SCALEMODE_NEAREST},enumerable:!0,configurable:!0}),Object.defineProperty(s,"SCALEMODE_CEILING",{get:function(){return s._SCALEMODE_CEILING},enumerable:!0,configurable:!0}),Object.defineProperty(s,"Version",{get:function(){return"3.2.0-alpha4"},enumerable:!0,configurable:!0}),Object.defineProperty(s.prototype,"isInVRExclusivePointerMode",{get:function(){return this._vrExclusivePointerMode},enumerable:!0,configurable:!0}),Object.defineProperty(s.prototype,"supportsUniformBuffers",{get:function(){return this.webGLVersion>1&&!this.disableUniformBuffers},enumerable:!0,configurable:!0}),Object.defineProperty(s.prototype,"needPOTTextures",{get:function(){return this._webGLVersion<2||this.forcePOTTextures},enumerable:!0,configurable:!0}),Object.defineProperty(s.prototype,"badOS",{get:function(){return this._badOS},enumerable:!0,configurable:!0}),Object.defineProperty(s.prototype,"badDesktopOS",{get:function(){return this._badDesktopOS},enumerable:!0,configurable:!0}),Object.defineProperty(s.prototype,"performanceMonitor",{get:function(){return this._performanceMonitor},enumerable:!0,configurable:!0}),Object.defineProperty(s.prototype,"texturesSupported",{get:function(){return this._texturesSupported},enumerable:!0,configurable:!0}),Object.defineProperty(s.prototype,"textureFormatInUse",{get:function(){return this._textureFormatInUse},enumerable:!0,configurable:!0}),Object.defineProperty(s.prototype,"currentViewport",{get:function(){return this._cachedViewport},enumerable:!0,configurable:!0}),Object.defineProperty(s.prototype,"emptyTexture",{get:function(){return this._emptyTexture||(this._emptyTexture=this.createRawTexture(new Uint8Array(4),1,1,s.TEXTUREFORMAT_RGBA,!1,!1,e.Texture.NEAREST_SAMPLINGMODE)),this._emptyTexture},enumerable:!0,configurable:!0}),Object.defineProperty(s.prototype,"emptyTexture3D",{get:function(){return this._emptyTexture3D||(this._emptyTexture3D=this.createRawTexture3D(new Uint8Array(4),1,1,1,s.TEXTUREFORMAT_RGBA,!1,!1,e.Texture.NEAREST_SAMPLINGMODE)),this._emptyTexture3D},enumerable:!0,configurable:!0}),Object.defineProperty(s.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,s.TEXTUREFORMAT_RGBA,s.TEXTURETYPE_UNSIGNED_INT,!1,!1,e.Texture.NEAREST_SAMPLINGMODE)}return this._emptyCubeTexture},enumerable:!0,configurable:!0}),s.prototype._rebuildInternalTextures=function(){for(var e=0,t=this._internalTexturesCache.slice();e<t.length;e++){t[e]._rebuild()}},s.prototype._rebuildEffects=function(){for(var t in this._compiledEffects){this._compiledEffects[t]._prepareEffect()}e.Effect.ResetCache()},s.prototype._rebuildBuffers=function(){for(var e=0,t=this.scenes;e<t.length;e++){var i=t[e];i.resetCachedMaterial(),i._rebuildGeometries(),i._rebuildTextures()}for(var r=0,n=this._uniformBuffers;r<n.length;r++){n[r]._rebuild()}},s.prototype._initGLContext=function(){this._caps=new h,this._caps.maxTexturesImageUnits=this._gl.getParameter(this._gl.MAX_TEXTURE_IMAGE_UNITS),this._caps.maxCombinedTexturesImageUnits=this._gl.getParameter(this._gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS),this._caps.maxVertexTextureImageUnits=this._gl.getParameter(this._gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS),this._caps.maxTextureSize=this._gl.getParameter(this._gl.MAX_TEXTURE_SIZE),this._caps.maxCubemapTextureSize=this._gl.getParameter(this._gl.MAX_CUBE_MAP_TEXTURE_SIZE),this._caps.maxRenderTextureSize=this._gl.getParameter(this._gl.MAX_RENDERBUFFER_SIZE),this._caps.maxVertexAttribs=this._gl.getParameter(this._gl.MAX_VERTEX_ATTRIBS),this._caps.maxVaryingVectors=this._gl.getParameter(this._gl.MAX_VARYING_VECTORS),this._caps.maxFragmentUniformVectors=this._gl.getParameter(this._gl.MAX_FRAGMENT_UNIFORM_VECTORS),this._caps.maxVertexUniformVectors=this._gl.getParameter(this._gl.MAX_VERTEX_UNIFORM_VECTORS),this._glVersion=this._gl.getParameter(this._gl.VERSION);var e=this._gl.getExtension("WEBGL_debug_renderer_info");if(null!=e&&(this._glRenderer=this._gl.getParameter(e.UNMASKED_RENDERER_WEBGL),this._glVendor=this._gl.getParameter(e.UNMASKED_VENDOR_WEBGL)),this._glVendor||(this._glVendor="Unknown vendor"),this._glRenderer||(this._glRenderer="Unknown renderer"),this._gl.HALF_FLOAT_OES=36193,34842!==this._gl.RGBA16F&&(this._gl.RGBA16F=34842),34836!==this._gl.RGBA32F&&(this._gl.RGBA32F=34836),35056!==this._gl.DEPTH24_STENCIL8&&(this._gl.DEPTH24_STENCIL8=35056),this._caps.standardDerivatives=this._webGLVersion>1||null!==this._gl.getExtension("OES_standard_derivatives"),this._caps.astc=this._gl.getExtension("WEBGL_compressed_texture_astc")||this._gl.getExtension("WEBKIT_WEBGL_compressed_texture_astc"),this._caps.s3tc=this._gl.getExtension("WEBGL_compressed_texture_s3tc")||this._gl.getExtension("WEBKIT_WEBGL_compressed_texture_s3tc"),this._caps.pvrtc=this._gl.getExtension("WEBGL_compressed_texture_pvrtc")||this._gl.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc"),this._caps.etc1=this._gl.getExtension("WEBGL_compressed_texture_etc1")||this._gl.getExtension("WEBKIT_WEBGL_compressed_texture_etc1"),this._caps.etc2=this._gl.getExtension("WEBGL_compressed_texture_etc")||this._gl.getExtension("WEBKIT_WEBGL_compressed_texture_etc")||this._gl.getExtension("WEBGL_compressed_texture_es3_0"),this._caps.textureAnisotropicFilterExtension=this._gl.getExtension("EXT_texture_filter_anisotropic")||this._gl.getExtension("WEBKIT_EXT_texture_filter_anisotropic")||this._gl.getExtension("MOZ_EXT_texture_filter_anisotropic"),this._caps.maxAnisotropy=this._caps.textureAnisotropicFilterExtension?this._gl.getParameter(this._caps.textureAnisotropicFilterExtension.MAX_TEXTURE_MAX_ANISOTROPY_EXT):0,this._caps.uintIndices=this._webGLVersion>1||null!==this._gl.getExtension("OES_element_index_uint"),this._caps.fragmentDepthSupported=this._webGLVersion>1||null!==this._gl.getExtension("EXT_frag_depth"),this._caps.highPrecisionShaderSupported=!0,this._caps.timerQuery=this._gl.getExtension("EXT_disjoint_timer_query_webgl2")||this._gl.getExtension("EXT_disjoint_timer_query"),this._caps.timerQuery&&(1===this._webGLVersion&&(this._gl.getQuery=this._caps.timerQuery.getQueryEXT.bind(this._caps.timerQuery)),this._caps.canUseTimestampForTimerQuery=this._gl.getQuery(this._caps.timerQuery.TIMESTAMP_EXT,this._caps.timerQuery.QUERY_COUNTER_BITS_EXT)>0),this._caps.colorBufferFloat=this._webGLVersion>1&&this._gl.getExtension("EXT_color_buffer_float"),this._caps.textureFloat=this._webGLVersion>1||this._gl.getExtension("OES_texture_float"),this._caps.textureFloatLinearFiltering=this._caps.textureFloat&&this._gl.getExtension("OES_texture_float_linear"),this._caps.textureFloatRender=this._caps.textureFloat&&this._canRenderToFloatFramebuffer(),this._caps.textureHalfFloat=this._webGLVersion>1||this._gl.getExtension("OES_texture_half_float"),this._caps.textureHalfFloatLinearFiltering=this._webGLVersion>1||this._caps.textureHalfFloat&&this._gl.getExtension("OES_texture_half_float_linear"),this._webGLVersion>1&&(this._gl.HALF_FLOAT_OES=5131),this._caps.textureHalfFloatRender=this._caps.textureHalfFloat&&this._canRenderToHalfFloatFramebuffer(),this._caps.textureLOD=this._webGLVersion>1||this._gl.getExtension("EXT_shader_texture_lod"),this._webGLVersion>1)this._caps.drawBuffersExtension=!0;else{var t=this._gl.getExtension("WEBGL_draw_buffers");if(null!==t){this._caps.drawBuffersExtension=!0,this._gl.drawBuffers=t.drawBuffersWEBGL.bind(t),this._gl.DRAW_FRAMEBUFFER=this._gl.FRAMEBUFFER;for(var i=0;i<16;i++)this._gl["COLOR_ATTACHMENT"+i+"_WEBGL"]=t["COLOR_ATTACHMENT"+i+"_WEBGL"]}else this._caps.drawBuffersExtension=!1}this._webGLVersion>1?this._caps.depthTextureExtension=!0: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),this._maxSimultaneousTextures=this._caps.maxCombinedTexturesImageUnits;for(var s=0;s<this._maxSimultaneousTextures;s++)this._nextFreeTextureSlots.push(s)},Object.defineProperty(s.prototype,"webGLVersion",{get:function(){return this._webGLVersion},enumerable:!0,configurable:!0}),Object.defineProperty(s.prototype,"isStencilEnable",{get:function(){return this._isStencilEnable},enumerable:!0,configurable:!0}),s.prototype._prepareWorkingCanvas=function(){if(!this._workingCanvas){this._workingCanvas=document.createElement("canvas");var e=this._workingCanvas.getContext("2d");e&&(this._workingContext=e)}},s.prototype.resetTextureCache=function(){for(var e in this._boundTexturesCache){var t=this._boundTexturesCache[e];t&&this._removeDesignatedSlot(t),this._boundTexturesCache[e]=null}this._nextFreeTextureSlots=[];for(var i=0;i<this._maxSimultaneousTextures;i++)this._nextFreeTextureSlots.push(i);this._activeChannel=-1},s.prototype.isDeterministicLockStep=function(){return this._deterministicLockstep},s.prototype.getLockstepMaxSteps=function(){return this._lockstepMaxSteps},s.prototype.getGlInfo=function(){return{vendor:this._glVendor,renderer:this._glRenderer,version:this._glVersion}},s.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)},s.prototype.getRenderWidth=function(e){return void 0===e&&(e=!1),!e&&this._currentRenderTarget?this._currentRenderTarget.width:this._gl.drawingBufferWidth},s.prototype.getRenderHeight=function(e){return void 0===e&&(e=!1),!e&&this._currentRenderTarget?this._currentRenderTarget.height:this._gl.drawingBufferHeight},s.prototype.getRenderingCanvas=function(){return this._renderingCanvas},s.prototype.getRenderingCanvasClientRect=function(){return this._renderingCanvas?this._renderingCanvas.getBoundingClientRect():null},s.prototype.setHardwareScalingLevel=function(e){this._hardwareScalingLevel=e,this.resize()},s.prototype.getHardwareScalingLevel=function(){return this._hardwareScalingLevel},s.prototype.getLoadedTexturesCache=function(){return this._internalTexturesCache},s.prototype.getCaps=function(){return this._caps},Object.defineProperty(s.prototype,"drawCalls",{get:function(){return e.Tools.Warn("drawCalls is deprecated. Please use SceneInstrumentation class"),0},enumerable:!0,configurable:!0}),Object.defineProperty(s.prototype,"drawCallsPerfCounter",{get:function(){return e.Tools.Warn("drawCallsPerfCounter is deprecated. Please use SceneInstrumentation class"),null},enumerable:!0,configurable:!0}),s.prototype.getDepthFunction=function(){return this._depthCullingState.depthFunc},s.prototype.setDepthFunction=function(e){this._depthCullingState.depthFunc=e},s.prototype.setDepthFunctionToGreater=function(){this._depthCullingState.depthFunc=this._gl.GREATER},s.prototype.setDepthFunctionToGreaterOrEqual=function(){this._depthCullingState.depthFunc=this._gl.GEQUAL},s.prototype.setDepthFunctionToLess=function(){this._depthCullingState.depthFunc=this._gl.LESS},s.prototype.setDepthFunctionToLessOrEqual=function(){this._depthCullingState.depthFunc=this._gl.LEQUAL},s.prototype.getStencilBuffer=function(){return this._stencilState.stencilTest},s.prototype.setStencilBuffer=function(e){this._stencilState.stencilTest=e},s.prototype.getStencilMask=function(){return this._stencilState.stencilMask},s.prototype.setStencilMask=function(e){this._stencilState.stencilMask=e},s.prototype.getStencilFunction=function(){return this._stencilState.stencilFunc},s.prototype.getStencilFunctionReference=function(){return this._stencilState.stencilFuncRef},s.prototype.getStencilFunctionMask=function(){return this._stencilState.stencilFuncMask},s.prototype.setStencilFunction=function(e){this._stencilState.stencilFunc=e},s.prototype.setStencilFunctionReference=function(e){this._stencilState.stencilFuncRef=e},s.prototype.setStencilFunctionMask=function(e){this._stencilState.stencilFuncMask=e},s.prototype.getStencilOperationFail=function(){return this._stencilState.stencilOpStencilFail},s.prototype.getStencilOperationDepthFail=function(){return this._stencilState.stencilOpDepthFail},s.prototype.getStencilOperationPass=function(){return this._stencilState.stencilOpStencilDepthPass},s.prototype.setStencilOperationFail=function(e){this._stencilState.stencilOpStencilFail=e},s.prototype.setStencilOperationDepthFail=function(e){this._stencilState.stencilOpDepthFail=e},s.prototype.setStencilOperationPass=function(e){this._stencilState.stencilOpStencilDepthPass=e},s.prototype.setDitheringState=function(e){e?this._gl.enable(this._gl.DITHER):this._gl.disable(this._gl.DITHER)},s.prototype.setRasterizerState=function(e){e?this._gl.disable(this._gl.RASTERIZER_DISCARD):this._gl.enable(this._gl.RASTERIZER_DISCARD)},s.prototype.stopRenderLoop=function(e){if(e){var t=this._activeRenderLoops.indexOf(e);t>=0&&this._activeRenderLoops.splice(t,1)}else this._activeRenderLoops=[]},s.prototype._renderLoop=function(){if(!this._contextWasLost){var t=!0;if(!this.renderEvenInBackground&&this._windowIsBackground&&(t=!1),t){this.beginFrame();for(var i=0;i<this._activeRenderLoops.length;i++){(0,this._activeRenderLoops[i])()}this.endFrame()}}if(this._activeRenderLoops.length>0){var r=null;this._vrDisplay&&this._vrDisplay.isPresenting&&(r=this._vrDisplay),this._frameHandler=e.Tools.QueueNewFrame(this._bindedRenderFunction,r)}else this._renderingQueueLaunched=!1},s.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)))},s.prototype.switchFullscreen=function(t){this.isFullscreen?e.Tools.ExitFullscreen():(this._pointerLockRequested=t,this._renderingCanvas&&e.Tools.RequestFullscreen(this._renderingCanvas))},s.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)},s.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)},s.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)},s.prototype.setDirectViewport=function(e,t,i,r){var n=this._cachedViewport;return this._cachedViewport=null,this._gl.viewport(e,t,i,r),n},s.prototype.beginFrame=function(){this.onBeginFrameObservable.notifyObservers(this),this._measureFps()},s.prototype.endFrame=function(){this._badOS&&this.flushFramebuffer(),this._vrDisplay&&this._vrDisplay.isPresenting&&this._vrDisplay.submitFrame(),this.onEndFrameObservable.notifyObservers(this)},s.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)}},s.prototype.setSize=function(e,t){if(this._renderingCanvas&&(this._renderingCanvas.width!==e||this._renderingCanvas.height!==t)){this._renderingCanvas.width=e,this._renderingCanvas.height=t;for(var i=0;i<this.scenes.length;i++)for(var r=this.scenes[i],n=0;n<r.cameras.length;n++){r.cameras[n]._currentRenderId=0}this.onResizeObservable.hasObservers&&this.onResizeObservable.notifyObservers(this)}},s.prototype.isVRDevicePresent=function(){return!!this._vrDisplay},s.prototype.getVRDevice=function(){return this._vrDisplay},s.prototype.initWebVR=function(){var t=this,i=function(){var e={vrDisplay:t._vrDisplay,vrSupported:t._vrSupported};t.onVRDisplayChangedObservable.notifyObservers(e)};return this._onVrDisplayConnect||(this._onVrDisplayConnect=function(e){t._vrDisplay=e.display,i()},this._onVrDisplayDisconnect=function(){t._vrDisplay.cancelAnimationFrame(t._frameHandler),t._vrDisplay=void 0,t._frameHandler=e.Tools.QueueNewFrame(t._bindedRenderFunction),i()},this._onVrDisplayPresentChange=function(){t._vrExclusivePointerMode=t._vrDisplay&&t._vrDisplay.isPresenting},window.addEventListener("vrdisplayconnect",this._onVrDisplayConnect),window.addEventListener("vrdisplaydisconnect",this._onVrDisplayDisconnect),window.addEventListener("vrdisplaypresentchange",this._onVrDisplayPresentChange)),this._getVRDisplays(i),this.onVRDisplayChangedObservable},s.prototype.enableVR=function(){var e=this;if(this._vrDisplay&&!this._vrDisplay.isPresenting){this.onVRRequestPresentStart.notifyObservers(this),this._vrDisplay.requestPresent([{source:this.getRenderingCanvas()}]).then(function(){e.onVRRequestPresentComplete.notifyObservers(!0),e._onVRFullScreenTriggered()}).catch(function(){e.onVRRequestPresentComplete.notifyObservers(!1)})}},s.prototype.disableVR=function(){this._vrDisplay&&this._vrDisplay.isPresenting&&this._vrDisplay.exitPresent().then(this._onVRFullScreenTriggered).catch(this._onVRFullScreenTriggered)},s.prototype._getVRDisplays=function(e){var t=this;navigator.getVRDisplays?navigator.getVRDisplays().then(function(e){return t._vrSupported=!0,t._vrDisplay=e[0]}).then(e).catch(function(i){t._vrSupported=!1,e()}):(this._vrDisplay=void 0,this._vrSupported=!1,e())},s.prototype.bindFramebuffer=function(e,t,i,r,n){this._currentRenderTarget&&this.unBindFramebuffer(this._currentRenderTarget),this._currentRenderTarget=e,this.bindUnboundFramebuffer(e._MSAAFramebuffer?e._MSAAFramebuffer:e._framebuffer);var o=this._gl;e.isCube&&(void 0===t&&(t=0),o.framebufferTexture2D(o.FRAMEBUFFER,o.COLOR_ATTACHMENT0,o.TEXTURE_CUBE_MAP_POSITIVE_X+t,e._webGLTexture,0)),this._cachedViewport&&!n?this.setViewport(this._cachedViewport,i,r):o.viewport(0,0,i||e.width,r||e.height),this.wipeCaches()},s.prototype.bindUnboundFramebuffer=function(e){this._currentFramebuffer!==e&&(this._gl.bindFramebuffer(this._gl.FRAMEBUFFER,e),this._currentFramebuffer=e)},s.prototype.unBindFramebuffer=function(e,t,i){void 0===t&&(t=!1),this._currentRenderTarget=null;var r=this._gl;e._MSAAFramebuffer&&(r.bindFramebuffer(r.READ_FRAMEBUFFER,e._MSAAFramebuffer),r.bindFramebuffer(r.DRAW_FRAMEBUFFER,e._framebuffer),r.blitFramebuffer(0,0,e.width,e.height,0,0,e.width,e.height,r.COLOR_BUFFER_BIT,r.NEAREST)),!e.generateMipMaps||t||e.isCube||(this._bindTextureDirectly(r.TEXTURE_2D,e,!0),r.generateMipmap(r.TEXTURE_2D),this._bindTextureDirectly(r.TEXTURE_2D,null)),i&&(e._MSAAFramebuffer&&this.bindUnboundFramebuffer(e._framebuffer),i()),this.bindUnboundFramebuffer(null)},s.prototype.unBindMultiColorAttachmentFramebuffer=function(e,t,i){void 0===t&&(t=!1),this._currentRenderTarget=null;var r=this._gl;if(e[0]._MSAAFramebuffer){r.bindFramebuffer(r.READ_FRAMEBUFFER,e[0]._MSAAFramebuffer),r.bindFramebuffer(r.DRAW_FRAMEBUFFER,e[0]._framebuffer);var n=e[0]._attachments;n||(n=new Array(e.length),e[0]._attachments=n);for(var o=0;o<e.length;o++){for(var s=e[o],a=0;a<n.length;a++)n[a]=r.NONE;n[o]=r[this.webGLVersion>1?"COLOR_ATTACHMENT"+o:"COLOR_ATTACHMENT"+o+"_WEBGL"],r.readBuffer(n[o]),r.drawBuffers(n),r.blitFramebuffer(0,0,s.width,s.height,0,0,s.width,s.height,r.COLOR_BUFFER_BIT,r.NEAREST)}for(o=0;o<n.length;o++)n[o]=r[this.webGLVersion>1?"COLOR_ATTACHMENT"+o:"COLOR_ATTACHMENT"+o+"_WEBGL"];r.drawBuffers(n)}for(o=0;o<e.length;o++){!(s=e[o]).generateMipMaps||t||s.isCube||(this._bindTextureDirectly(r.TEXTURE_2D,s),r.generateMipmap(r.TEXTURE_2D),this._bindTextureDirectly(r.TEXTURE_2D,null))}i&&(e[0]._MSAAFramebuffer&&this.bindUnboundFramebuffer(e[0]._framebuffer),i()),this.bindUnboundFramebuffer(null)},s.prototype.generateMipMapsForCubemap=function(e){if(e.generateMipMaps){var t=this._gl;this._bindTextureDirectly(t.TEXTURE_CUBE_MAP,e,!0),t.generateMipmap(t.TEXTURE_CUBE_MAP),this._bindTextureDirectly(t.TEXTURE_CUBE_MAP,null)}},s.prototype.flushFramebuffer=function(){this._gl.flush()},s.prototype.restoreDefaultFramebuffer=function(){this._currentRenderTarget?this.unBindFramebuffer(this._currentRenderTarget):this.bindUnboundFramebuffer(null),this._cachedViewport&&this.setViewport(this._cachedViewport),this.wipeCaches()},s.prototype.createUniformBuffer=function(e){var t=this._gl.createBuffer();if(!t)throw new Error("Unable to create uniform buffer");return this.bindUniformBuffer(t),e instanceof Float32Array?this._gl.bufferData(this._gl.UNIFORM_BUFFER,e,this._gl.STATIC_DRAW):this._gl.bufferData(this._gl.UNIFORM_BUFFER,new Float32Array(e),this._gl.STATIC_DRAW),this.bindUniformBuffer(null),t.references=1,t},s.prototype.createDynamicUniformBuffer=function(e){var t=this._gl.createBuffer();if(!t)throw new Error("Unable to create dynamic uniform buffer");return this.bindUniformBuffer(t),e instanceof Float32Array?this._gl.bufferData(this._gl.UNIFORM_BUFFER,e,this._gl.DYNAMIC_DRAW):this._gl.bufferData(this._gl.UNIFORM_BUFFER,new Float32Array(e),this._gl.DYNAMIC_DRAW),this.bindUniformBuffer(null),t.references=1,t},s.prototype.updateUniformBuffer=function(e,t,i,r){this.bindUniformBuffer(e),void 0===i&&(i=0),void 0===r?t instanceof Float32Array?this._gl.bufferSubData(this._gl.UNIFORM_BUFFER,i,t):this._gl.bufferSubData(this._gl.UNIFORM_BUFFER,i,new Float32Array(t)):t instanceof Float32Array?this._gl.bufferSubData(this._gl.UNIFORM_BUFFER,0,t.subarray(i,i+r)):this._gl.bufferSubData(this._gl.UNIFORM_BUFFER,0,new Float32Array(t).subarray(i,i+r)),this.bindUniformBuffer(null)},s.prototype._resetVertexBufferBinding=function(){this.bindArrayBuffer(null),this._cachedVertexBuffers=null},s.prototype.createVertexBuffer=function(e){var t=this._gl.createBuffer();if(!t)throw new Error("Unable to create vertex buffer");return this.bindArrayBuffer(t),e instanceof Float32Array?this._gl.bufferData(this._gl.ARRAY_BUFFER,e,this._gl.STATIC_DRAW):this._gl.bufferData(this._gl.ARRAY_BUFFER,new Float32Array(e),this._gl.STATIC_DRAW),this._resetVertexBufferBinding(),t.references=1,t},s.prototype.createDynamicVertexBuffer=function(e){var t=this._gl.createBuffer();if(!t)throw new Error("Unable to create dynamic vertex buffer");return this.bindArrayBuffer(t),e instanceof Float32Array?this._gl.bufferData(this._gl.ARRAY_BUFFER,e,this._gl.DYNAMIC_DRAW):this._gl.bufferData(this._gl.ARRAY_BUFFER,new Float32Array(e),this._gl.DYNAMIC_DRAW),this._resetVertexBufferBinding(),t.references=1,t},s.prototype.updateDynamicIndexBuffer=function(e,t,i){var r;void 0===i&&(i=0),this._currentBoundBuffer[this._gl.ELEMENT_ARRAY_BUFFER]=null,this.bindIndexBuffer(e),r=t instanceof Uint16Array||t instanceof Uint32Array?t:e.is32Bits?new Uint32Array(t):new Uint16Array(t),this._gl.bufferData(this._gl.ELEMENT_ARRAY_BUFFER,r,this._gl.DYNAMIC_DRAW),this._resetIndexBufferBinding()},s.prototype.updateDynamicVertexBuffer=function(e,t,i,r){this.bindArrayBuffer(e),void 0===i&&(i=0),void 0===r?t instanceof Float32Array?this._gl.bufferSubData(this._gl.ARRAY_BUFFER,i,t):this._gl.bufferSubData(this._gl.ARRAY_BUFFER,i,new Float32Array(t)):t instanceof Float32Array?this._gl.bufferSubData(this._gl.ARRAY_BUFFER,0,t.subarray(i,i+r)):this._gl.bufferSubData(this._gl.ARRAY_BUFFER,0,new Float32Array(t).subarray(i,i+r)),this._resetVertexBufferBinding()},s.prototype._resetIndexBufferBinding=function(){this.bindIndexBuffer(null),this._cachedIndexBuffer=null},s.prototype.createIndexBuffer=function(e,t){var i,r=this._gl.createBuffer();if(!r)throw new Error("Unable to create index buffer");this.bindIndexBuffer(r);var n=!1;if(e instanceof Uint16Array)i=e;else if(this._caps.uintIndices)if(e instanceof Uint32Array)i=e,n=!0;else{for(var o=0;o<e.length;o++)if(e[o]>65535){n=!0;break}i=n?new Uint32Array(e):new Uint16Array(e)}else i=new Uint16Array(e);return this._gl.bufferData(this._gl.ELEMENT_ARRAY_BUFFER,i,t?this._gl.DYNAMIC_DRAW:this._gl.STATIC_DRAW),this._resetIndexBufferBinding(),r.references=1,r.is32Bits=n,r},s.prototype.bindArrayBuffer=function(e){this._vaoRecordInProgress||this._unbindVertexArrayObject(),this.bindBuffer(e,this._gl.ARRAY_BUFFER)},s.prototype.bindUniformBuffer=function(e){this._gl.bindBuffer(this._gl.UNIFORM_BUFFER,e)},s.prototype.bindUniformBufferBase=function(e,t){this._gl.bindBufferBase(this._gl.UNIFORM_BUFFER,t,e)},s.prototype.bindUniformBlock=function(e,t,i){var r=this._gl.getUniformBlockIndex(e,t);this._gl.uniformBlockBinding(e,r,i)},s.prototype.bindIndexBuffer=function(e){this._vaoRecordInProgress||this._unbindVertexArrayObject(),this.bindBuffer(e,this._gl.ELEMENT_ARRAY_BUFFER)},s.prototype.bindBuffer=function(e,t){(this._vaoRecordInProgress||this._currentBoundBuffer[t]!==e)&&(this._gl.bindBuffer(t,e),this._currentBoundBuffer[t]=e)},s.prototype.updateArrayBuffer=function(e){this._gl.bufferSubData(this._gl.ARRAY_BUFFER,0,e)},s.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))},s.prototype._bindIndexBufferWithCache=function(e){null!=e&&this._cachedIndexBuffer!==e&&(this._cachedIndexBuffer=e,this.bindIndexBuffer(e),this._uintIndicesCurrentlySet=e.is32Bits)},s.prototype._bindVertexBuffersAttributes=function(e,t){var i=t.getAttributesNames();this._vaoRecordInProgress||this._unbindVertexArrayObject(),this.unbindAllAttributes();for(var r=0;r<i.length;r++){var n=t.getAttributeLocation(r);if(n>=0){var o=e[i[r]];if(!o)continue;this._gl.enableVertexAttribArray(n),this._vaoRecordInProgress||(this._vertexAttribArraysEnabled[n]=!0);var s=o.getBuffer();s&&(this.vertexAttribPointer(s,n,o.getSize(),this._gl.FLOAT,!1,4*o.getStrideSize(),4*o.getOffset()),o.getIsInstanced()&&(this._gl.vertexAttribDivisor(n,o.getInstanceDivisor()),this._vaoRecordInProgress||(this._currentInstanceLocations.push(n),this._currentInstanceBuffers.push(s))))}}},s.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},s.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)},s.prototype.bindBuffersDirectly=function(e,t,i,r,n){if(this._cachedVertexBuffers!==e||this._cachedEffectForVertexBuffers!==n){this._cachedVertexBuffers=e,this._cachedEffectForVertexBuffers=n;var o=n.getAttributesCount();this._unbindVertexArrayObject(),this.unbindAllAttributes();for(var s=0,a=0;a<o;a++)if(a<i.length){var h=n.getAttributeLocation(a);h>=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)},s.prototype._unbindVertexArrayObject=function(){this._cachedVertexArrayObject&&(this._cachedVertexArrayObject=null,this._gl.bindVertexArray(null))},s.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)},s.prototype.unbindInstanceAttributes=function(){for(var e,t=0,i=this._currentInstanceLocations.length;t<i;t++){var r=this._currentInstanceBuffers[t];e!=r&&r.references&&(e=r,this.bindArrayBuffer(r));var n=this._currentInstanceLocations[t];this._gl.vertexAttribDivisor(n,0)}this._currentInstanceBuffers.length=0,this._currentInstanceLocations.length=0},s.prototype.releaseVertexArrayObject=function(e){this._gl.deleteVertexArray(e)},s.prototype._releaseBuffer=function(e){return e.references--,0===e.references&&(this._gl.deleteBuffer(e),!0)},s.prototype.createInstancesBuffer=function(e){var t=this._gl.createBuffer();if(!t)throw new Error("Unable to create instance buffer");return t.capacity=e,this.bindArrayBuffer(t),this._gl.bufferData(this._gl.ARRAY_BUFFER,e,this._gl.DYNAMIC_DRAW),t},s.prototype.deleteInstancesBuffer=function(e){this._gl.deleteBuffer(e)},s.prototype.updateAndBindInstancesBuffer=function(e,t,i){if(this.bindArrayBuffer(e),t&&this._gl.bufferSubData(this._gl.ARRAY_BUFFER,0,t),void 0!==i[0].index){for(var r=0,n=0;n<i.length;n++){r+=4*(o=i[n]).attributeSize}for(n=0;n<i.length;n++){var o=i[n];this._vertexAttribArraysEnabled[o.index]||(this._gl.enableVertexAttribArray(o.index),this._vertexAttribArraysEnabled[o.index]=!0),this.vertexAttribPointer(e,o.index,o.attributeSize,o.attribyteType||this._gl.FLOAT,o.normalized||!1,r,o.offset),this._gl.vertexAttribDivisor(o.index,1),this._currentInstanceLocations.push(o.index),this._currentInstanceBuffers.push(e)}}else for(var s=0;s<4;s++){var a=i[s];this._vertexAttribArraysEnabled[a]||(this._gl.enableVertexAttribArray(a),this._vertexAttribArraysEnabled[a]=!0),this.vertexAttribPointer(e,a,4,this._gl.FLOAT,!1,64,16*s),this._gl.vertexAttribDivisor(a,1),this._currentInstanceLocations.push(a),this._currentInstanceBuffers.push(e)}},s.prototype.applyStates=function(){this._depthCullingState.apply(this._gl),this._stencilState.apply(this._gl),this._alphaState.apply(this._gl)},s.prototype.draw=function(t,i,r,n){this.drawElementsType(t?e.Material.TriangleFillMode:e.Material.WireFrameFillMode,i,r,n)},s.prototype.drawPointClouds=function(t,i,r){this.drawArraysType(e.Material.PointFillMode,t,i,r)},s.prototype.drawUnIndexed=function(t,i,r,n){this.drawArraysType(t?e.Material.TriangleFillMode:e.Material.WireFrameFillMode,i,r,n)},s.prototype.drawElementsType=function(e,t,i,r){this.applyStates(),this._drawCalls.addCount(1,!1);var n=this.DrawMode(e),o=this._uintIndicesCurrentlySet?this._gl.UNSIGNED_INT:this._gl.UNSIGNED_SHORT,s=this._uintIndicesCurrentlySet?4:2;r?this._gl.drawElementsInstanced(n,i,o,t*s,r):this._gl.drawElements(n,i,o,t*s)},s.prototype.drawArraysType=function(e,t,i,r){this.applyStates(),this._drawCalls.addCount(1,!1);var n=this.DrawMode(e);r?this._gl.drawArraysInstanced(n,t,i,r):this._gl.drawArrays(n,t,i)},s.prototype.DrawMode=function(t){switch(t){case e.Material.TriangleFillMode:return this._gl.TRIANGLES;case e.Material.PointFillMode:return this._gl.POINTS;case e.Material.WireFrameFillMode:return this._gl.LINES;case e.Material.PointListDrawMode:return this._gl.POINTS;case e.Material.LineListDrawMode:return this._gl.LINES;case e.Material.LineLoopDrawMode:return this._gl.LINE_LOOP;case e.Material.LineStripDrawMode:return this._gl.LINE_STRIP;case e.Material.TriangleStripDrawMode:return this._gl.TRIANGLE_STRIP;case e.Material.TriangleFanDrawMode:return this._gl.TRIANGLE_FAN;default:return this._gl.TRIANGLES}},s.prototype._releaseEffect=function(e){this._compiledEffects[e._key]&&(delete this._compiledEffects[e._key],this._deleteProgram(e.getProgram()))},s.prototype._deleteProgram=function(e){e&&(e.__SPECTOR_rebuildProgram=null,e.transformFeedback&&(this.deleteTransformFeedback(e.transformFeedback),e.transformFeedback=null),this._gl.deleteProgram(e))},s.prototype.createEffect=function(t,i,r,n,o,s,a,h,l){var c=(t.vertexElement||t.vertex||t)+"+"+(t.fragmentElement||t.fragment||t)+"@"+(o||i.defines);if(this._compiledEffects[c]){var u=this._compiledEffects[c];return a&&u.isReady()&&a(u),u}var p=new e.Effect(t,i,r,n,this,o,s,a,h,l);return p._key=c,this._compiledEffects[c]=p,p},s.prototype.createEffectForParticles=function(e,t,i,r,n,o,s){return void 0===t&&(t=[]),void 0===i&&(i=[]),void 0===r&&(r=""),this.createEffect({vertex:"particles",fragmentElement:e},["position","color","options"],["view","projection"].concat(t),["diffuseSampler"].concat(i),r,n,o,s)},s.prototype.createRawShaderProgram=function(e,t,r,n){void 0===n&&(n=null),r=r||this._gl;var o=i(r,e,"vertex"),s=i(r,t,"fragment");return this._createShaderProgram(o,s,r,n)},s.prototype.createShaderProgram=function(e,i,r,n,o){void 0===o&&(o=null),n=n||this._gl,this.onBeforeShaderCompilationObservable.notifyObservers(this);var s=this._webGLVersion>1?"#version 300 es\n":"",a=t(n,e,"vertex",r,s),h=t(n,i,"fragment",r,s),l=this._createShaderProgram(a,h,n,o);return this.onAfterShaderCompilationObservable.notifyObservers(this),l},s.prototype._createShaderProgram=function(e,t,i,r){void 0===r&&(r=null);var n=i.createProgram();if(!n)throw new Error("Unable to create program");if(i.attachShader(n,e),i.attachShader(n,t),this.webGLVersion>1&&r){var o=this.createTransformFeedback();this.bindTransformFeedback(o),this.setTranformFeedbackVaryings(n,r),n.transformFeedback=o}if(i.linkProgram(n),this.webGLVersion>1&&r&&this.bindTransformFeedback(null),!i.getProgramParameter(n,i.LINK_STATUS)){i.validateProgram(n);var s=i.getProgramInfoLog(n);if(s)throw new Error(s)}return i.deleteShader(e),i.deleteShader(t),n},s.prototype.getUniforms=function(e,t){for(var i=new Array,r=0;r<t.length;r++)i.push(this._gl.getUniformLocation(e,t[r]));return i},s.prototype.getAttributes=function(e,t){for(var i=[],r=0;r<t.length;r++)try{i.push(this._gl.getAttribLocation(e,t[r]))}catch(e){i.push(-1)}return i},s.prototype.enableEffect=function(e){e&&(this.bindSamplers(e),this._currentEffect=e,e.onBind&&e.onBind(e),e.onBindObservable.notifyObservers(e))},s.prototype.setIntArray=function(e,t){e&&this._gl.uniform1iv(e,t)},s.prototype.setIntArray2=function(e,t){e&&t.length%2==0&&this._gl.uniform2iv(e,t)},s.prototype.setIntArray3=function(e,t){e&&t.length%3==0&&this._gl.uniform3iv(e,t)},s.prototype.setIntArray4=function(e,t){e&&t.length%4==0&&this._gl.uniform4iv(e,t)},s.prototype.setFloatArray=function(e,t){e&&this._gl.uniform1fv(e,t)},s.prototype.setFloatArray2=function(e,t){e&&t.length%2==0&&this._gl.uniform2fv(e,t)},s.prototype.setFloatArray3=function(e,t){e&&t.length%3==0&&this._gl.uniform3fv(e,t)},s.prototype.setFloatArray4=function(e,t){e&&t.length%4==0&&this._gl.uniform4fv(e,t)},s.prototype.setArray=function(e,t){e&&this._gl.uniform1fv(e,t)},s.prototype.setArray2=function(e,t){e&&t.length%2==0&&this._gl.uniform2fv(e,t)},s.prototype.setArray3=function(e,t){e&&t.length%3==0&&this._gl.uniform3fv(e,t)},s.prototype.setArray4=function(e,t){e&&t.length%4==0&&this._gl.uniform4fv(e,t)},s.prototype.setMatrices=function(e,t){e&&this._gl.uniformMatrix4fv(e,!1,t)},s.prototype.setMatrix=function(e,t){e&&this._gl.uniformMatrix4fv(e,!1,t.toArray())},s.prototype.setMatrix3x3=function(e,t){e&&this._gl.uniformMatrix3fv(e,!1,t)},s.prototype.setMatrix2x2=function(e,t){e&&this._gl.uniformMatrix2fv(e,!1,t)},s.prototype.setInt=function(e,t){e&&this._gl.uniform1i(e,t)},s.prototype.setFloat=function(e,t){e&&this._gl.uniform1f(e,t)},s.prototype.setFloat2=function(e,t,i){e&&this._gl.uniform2f(e,t,i)},s.prototype.setFloat3=function(e,t,i,r){e&&this._gl.uniform3f(e,t,i,r)},s.prototype.setBool=function(e,t){e&&this._gl.uniform1i(e,t)},s.prototype.setFloat4=function(e,t,i,r,n){e&&this._gl.uniform4f(e,t,i,r,n)},s.prototype.setColor3=function(e,t){e&&this._gl.uniform3f(e,t.r,t.g,t.b)},s.prototype.setColor4=function(e,t,i){e&&this._gl.uniform4f(e,t.r,t.g,t.b,i)},s.prototype.setState=function(e,t,i,r){void 0===t&&(t=0),void 0===r&&(r=!1),(this._depthCullingState.cull!==e||i)&&(this._depthCullingState.cull=e);var n=this.cullBackFaces?this._gl.BACK:this._gl.FRONT;(this._depthCullingState.cullFace!==n||i)&&(this._depthCullingState.cullFace=n),this.setZOffset(t);var o=r?this._gl.CW:this._gl.CCW;(this._depthCullingState.frontFace!==o||i)&&(this._depthCullingState.frontFace=o)},s.prototype.setZOffset=function(e){this._depthCullingState.zOffset=e},s.prototype.getZOffset=function(){return this._depthCullingState.zOffset},s.prototype.setDepthBuffer=function(e){this._depthCullingState.depthTest=e},s.prototype.getDepthWrite=function(){return this._depthCullingState.depthMask},s.prototype.setDepthWrite=function(e){this._depthCullingState.depthMask=e},s.prototype.setColorWrite=function(e){this._gl.colorMask(e,e,e,e),this._colorWrite=e},s.prototype.getColorWrite=function(){return this._colorWrite},s.prototype.setAlphaConstants=function(e,t,i,r){this._alphaState.setAlphaBlendConstants(e,t,i,r)},s.prototype.setAlphaMode=function(e,t){if(void 0===t&&(t=!1),this._alphaMode!==e){switch(e){case s.ALPHA_DISABLE:this._alphaState.alphaBlend=!1;break;case s.ALPHA_PREMULTIPLIED:this._alphaState.setAlphaBlendFunctionParameters(this._gl.ONE,this._gl.ONE_MINUS_SRC_ALPHA,this._gl.ONE,this._gl.ONE),this._alphaState.alphaBlend=!0;break;case s.ALPHA_PREMULTIPLIED_PORTERDUFF:this._alphaState.setAlphaBlendFunctionParameters(this._gl.ONE,this._gl.ONE_MINUS_SRC_ALPHA,this._gl.ONE,this._gl.ONE_MINUS_SRC_ALPHA),this._alphaState.alphaBlend=!0;break;case s.ALPHA_COMBINE:this._alphaState.setAlphaBlendFunctionParameters(this._gl.SRC_ALPHA,this._gl.ONE_MINUS_SRC_ALPHA,this._gl.ONE,this._gl.ONE),this._alphaState.alphaBlend=!0;break;case s.ALPHA_ONEONE:this._alphaState.setAlphaBlendFunctionParameters(this._gl.ONE,this._gl.ONE,this._gl.ZERO,this._gl.ONE),this._alphaState.alphaBlend=!0;break;case s.ALPHA_ADD:this._alphaState.setAlphaBlendFunctionParameters(this._gl.SRC_ALPHA,this._gl.ONE,this._gl.ZERO,this._gl.ONE),this._alphaState.alphaBlend=!0;break;case s.ALPHA_SUBTRACT:this._alphaState.setAlphaBlendFunctionParameters(this._gl.ZERO,this._gl.ONE_MINUS_SRC_COLOR,this._gl.ONE,this._gl.ONE),this._alphaState.alphaBlend=!0;break;case s.ALPHA_MULTIPLY:this._alphaState.setAlphaBlendFunctionParameters(this._gl.DST_COLOR,this._gl.ZERO,this._gl.ONE,this._gl.ONE),this._alphaState.alphaBlend=!0;break;case s.ALPHA_MAXIMIZED:this._alphaState.setAlphaBlendFunctionParameters(this._gl.SRC_ALPHA,this._gl.ONE_MINUS_SRC_COLOR,this._gl.ONE,this._gl.ONE),this._alphaState.alphaBlend=!0;break;case s.ALPHA_INTERPOLATE:this._alphaState.setAlphaBlendFunctionParameters(this._gl.CONSTANT_COLOR,this._gl.ONE_MINUS_CONSTANT_COLOR,this._gl.CONSTANT_ALPHA,this._gl.ONE_MINUS_CONSTANT_ALPHA),this._alphaState.alphaBlend=!0;break;case s.ALPHA_SCREENMODE:this._alphaState.setAlphaBlendFunctionParameters(this._gl.ONE,this._gl.ONE_MINUS_SRC_COLOR,this._gl.ONE,this._gl.ONE_MINUS_SRC_ALPHA),this._alphaState.alphaBlend=!0}t||this.setDepthWrite(e===s.ALPHA_DISABLE),this._alphaMode=e}},s.prototype.getAlphaMode=function(){return this._alphaMode},s.prototype.setAlphaTesting=function(e){this._alphaTest=e},s.prototype.getAlphaTesting=function(){return!!this._alphaTest},s.prototype.wipeCaches=function(e){this.preventCacheWipeBetweenFrames&&!e||(this._currentEffect=null,e&&(this.resetTextureCache(),this._currentProgram=null,this._stencilState.reset(),this._depthCullingState.reset(),this.setDepthFunctionToLessOrEqual(),this._alphaState.reset()),this._resetVertexBufferBinding(),this._cachedIndexBuffer=null,this._cachedEffectForVertexBuffers=null,this._unbindVertexArrayObject(),this.bindIndexBuffer(null))},s.prototype.setTextureFormatToUse=function(e){for(var t=0,i=this.texturesSupported.length;t<i;t++)for(var r=0,n=e.length;r<n;r++)if(this._texturesSupported[t]===e[r].toLowerCase())return this._textureFormatInUse=this._texturesSupported[t];return this._textureFormatInUse=null,null},s.prototype._createTexture=function(){var e=this._gl.createTexture();if(!e)throw new Error("Unable to create texture");return e},s.prototype.createTexture=function(t,i,r,n,o,s,a,h,l,c){var u=this;void 0===o&&(o=e.Texture.TRILINEAR_SAMPLINGMODE),void 0===s&&(s=null),void 0===a&&(a=null),void 0===h&&(h=null),void 0===l&&(l=null),void 0===c&&(c=null);var p=String(t),f="data:"===p.substr(0,5),d="blob:"===p.substr(0,5),m=f&&-1!==p.indexOf("base64"),g=l||new e.InternalTexture(this,e.InternalTexture.DATASOURCE_URL),_=p.lastIndexOf("."),v=_>0?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.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.TGATools.GetTGAHeader(s);u._prepareWebGLTexture(g,n,a.width,a.height,r,i,!1,function(){return e.TGATools.UploadContent(u._gl,s),!1},o)}:y&&(A=function(t){var s=e.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.DDSTools.UploadDDSLevels(u,u._gl,t,s,a,1),!1},o)}),h?A&&A(h):this._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,!0),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,!0),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},s.prototype._rescaleTexture=function(t,i,r,n,o){var a=this,h=this.createRenderTargetTexture({width:i.width,height:i.height},{generateMipMaps:!1,type:s.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,s.TEXTURETYPE_UNSIGNED_INT)),this._rescalePostProcess.getEffect().executeWhenCompiled(function(){a._rescalePostProcess.onApply=function(e){e._bindTexture("textureSampler",t)};var e=r;e||(e=a.scenes[a.scenes.length-1]),e.postProcessManager.directRender([a._rescalePostProcess],h,!0),a._bindTextureDirectly(a._gl.TEXTURE_2D,i,!0),a._gl.copyTexImage2D(a._gl.TEXTURE_2D,0,n,0,0,i.width,i.height,0),a.unBindFramebuffer(h),a._releaseTexture(h),o&&o()})},s.prototype._getInternalFormat=function(e){var t=this._gl.RGBA;switch(e){case s.TEXTUREFORMAT_ALPHA:t=this._gl.ALPHA;break;case s.TEXTUREFORMAT_LUMINANCE:t=this._gl.LUMINANCE;break;case s.TEXTUREFORMAT_LUMINANCE_ALPHA:t=this._gl.LUMINANCE_ALPHA;break;case s.TEXTUREFORMAT_RGB:t=this._gl.RGB;break;case s.TEXTUREFORMAT_RGBA:t=this._gl.RGBA}return t},s.prototype.updateRawTexture=function(e,t,i,r,n,o){if(void 0===n&&(n=null),void 0===o&&(o=s.TEXTURETYPE_UNSIGNED_INT),e){var a=this._getInternalFormat(i),h=this._getRGBABufferInternalSizedFormat(o),l=this._getWebGLTextureType(o);this._bindTextureDirectly(this._gl.TEXTURE_2D,e,!0),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.type=o,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,h,e.width,e.height,0,a,l,t),e.generateMipMaps&&this._gl.generateMipmap(this._gl.TEXTURE_2D),this._bindTextureDirectly(this._gl.TEXTURE_2D,null),e.isReady=!0}},s.prototype.createRawTexture=function(t,i,n,o,a,h,l,c,u){void 0===c&&(c=null),void 0===u&&(u=s.TEXTURETYPE_UNSIGNED_INT);var p=new e.InternalTexture(this,e.InternalTexture.DATASOURCE_RAW);p.baseWidth=i,p.baseHeight=n,p.width=i,p.height=n,p.format=o,p.generateMipMaps=a,p.samplingMode=l,p.invertY=h,p._compression=c,p.type=u,this._doNotHandleContextLost||(p._bufferView=t),this.updateRawTexture(p,t,o,h,c,u),this._bindTextureDirectly(this._gl.TEXTURE_2D,p,!0);var f=r(l,a,this._gl);return this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_MAG_FILTER,f.mag),this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_MIN_FILTER,f.min),a&&this._gl.generateMipmap(this._gl.TEXTURE_2D),this._bindTextureDirectly(this._gl.TEXTURE_2D,null),this._internalTexturesCache.push(p),p},s.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),o.width=t,o.height=i,o.isReady=!1,o.generateMipMaps=r,o.samplingMode=n,this.updateTextureSamplingMode(n,o),this._internalTexturesCache.push(o),o},s.prototype.updateTextureSamplingMode=function(e,t){var i=r(e,t.generateMipMaps,this._gl);t.isCube?(this._bindTextureDirectly(this._gl.TEXTURE_CUBE_MAP,t,!0),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,!0),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,!0),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},s.prototype.updateDynamicTexture=function(e,t,i,r,n){if(void 0===r&&(r=!1),e){this._bindTextureDirectly(this._gl.TEXTURE_2D,e,!0),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),e.isReady=!0}},s.prototype.updateVideoTexture=function(e,t,i){if(e&&!e._isDisabled){this._bindTextureDirectly(this._gl.TEXTURE_2D,e,!0),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),e.isReady=!0}catch(t){e._isDisabled=!0}}},s.prototype.createRenderTargetTexture=function(t,i){var n=new a;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?s.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=s.TEXTURETYPE_UNSIGNED_INT,n.samplingMode=e.Texture.TRILINEAR_SAMPLINGMODE),(n.type!==s.TEXTURETYPE_FLOAT||this._caps.textureFloatLinearFiltering)&&(n.type!==s.TEXTURETYPE_HALF_FLOAT||this._caps.textureHalfFloatLinearFiltering)||(n.samplingMode=e.Texture.NEAREST_SAMPLINGMODE);var o=this._gl,h=new e.InternalTexture(this,e.InternalTexture.DATASOURCE_RENDERTARGET);this._bindTextureDirectly(o.TEXTURE_2D,h,!0);var l=t.width||t,c=t.height||t,u=r(n.samplingMode,!!n.generateMipMaps,o);n.type!==s.TEXTURETYPE_FLOAT||this._caps.textureFloat||(n.type=s.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,h._webGLTexture,0),h._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),h._framebuffer=p,h.baseWidth=l,h.baseHeight=c,h.width=l,h.height=c,h.isReady=!0,h.samples=1,h.generateMipMaps=!!n.generateMipMaps,h.samplingMode=n.samplingMode,h.type=n.type,h._generateDepthBuffer=n.generateDepthBuffer,h._generateStencilBuffer=!!n.generateStencilBuffer,this._internalTexturesCache.push(h),h},s.prototype.createMultipleRenderTarget=function(t,i){var n=!1,o=!0,a=!1,h=!1,l=1,c=s.TEXTURETYPE_UNSIGNED_INT,u=e.Texture.TRILINEAR_SAMPLINGMODE,p=[],f=[];void 0!==i&&(n=i.generateMipMaps,o=void 0===i.generateDepthBuffer||i.generateDepthBuffer,a=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(a,o,g,_),x=0;x<l;x++){var T=f[x]||u,E=p[x]||c;(E!==s.TEXTURETYPE_FLOAT||this._caps.textureFloatLinearFiltering)&&(E!==s.TEXTURETYPE_HALF_FLOAT||this._caps.textureHalfFloatLinearFiltering)||(T=e.Texture.NEAREST_SAMPLINGMODE);var A=r(T,n,d);E!==s.TEXTURETYPE_FLOAT||this._caps.textureFloat||(E=s.TEXTURETYPE_UNSIGNED_INT,e.Tools.Warn("Float textures are not supported. Render target forced to TEXTURETYPE_UNSIGNED_BYTE type"));var P=new e.InternalTexture(this,e.InternalTexture.DATASOURCE_MULTIRENDERTARGET),M=d[this.webGLVersion>1?"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=a,P._attachments=y,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=a,v.push(S),this._internalTexturesCache.push(S)}return d.drawBuffers(y),d.bindRenderbuffer(d.RENDERBUFFER,null),this.bindUnboundFramebuffer(null),this.resetTextureCache(),v},s.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},s.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._depthStencilBuffer=null),e._MSAAFramebuffer&&(i.deleteFramebuffer(e._MSAAFramebuffer),e._MSAAFramebuffer=null),e._MSAARenderBuffer&&(i.deleteRenderbuffer(e._MSAARenderBuffer),e._MSAARenderBuffer=null),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,this._getRGBAMultiSampleBufferFormat(e.type),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},s.prototype.updateMultipleRenderTargetTextureSampleCount=function(e,t){if(this.webGLVersion<2||!e||0==e.length)return 1;if(e[0].samples===t)return t;var i=this._gl;t=Math.min(t,i.getParameter(i.MAX_SAMPLES)),e[0]._depthStencilBuffer&&(i.deleteRenderbuffer(e[0]._depthStencilBuffer),e[0]._depthStencilBuffer=null),e[0]._MSAAFramebuffer&&(i.deleteFramebuffer(e[0]._MSAAFramebuffer),e[0]._MSAAFramebuffer=null);for(var r=0;r<e.length;r++)e[r]._MSAARenderBuffer&&(i.deleteRenderbuffer(e[r]._MSAARenderBuffer),e[r]._MSAARenderBuffer=null);if(t>1){var n=i.createFramebuffer();if(!n)throw new Error("Unable to create multi sampled framebuffer");this.bindUnboundFramebuffer(n);var o=this._setupFramebufferDepthAttachments(e[0]._generateStencilBuffer,e[0]._generateDepthBuffer,e[0].width,e[0].height,t),s=[];for(r=0;r<e.length;r++){var a=e[r],h=i[this.webGLVersion>1?"COLOR_ATTACHMENT"+r:"COLOR_ATTACHMENT"+r+"_WEBGL"],l=i.createRenderbuffer();if(!l)throw new Error("Unable to create multi sampled framebuffer");i.bindRenderbuffer(i.RENDERBUFFER,l),i.renderbufferStorageMultisample(i.RENDERBUFFER,t,this._getRGBAMultiSampleBufferFormat(a.type),a.width,a.height),i.framebufferRenderbuffer(i.FRAMEBUFFER,h,i.RENDERBUFFER,l),a._MSAAFramebuffer=n,a._MSAARenderBuffer=l,a.samples=t,a._depthStencilBuffer=o,i.bindRenderbuffer(i.RENDERBUFFER,null),s.push(h)}i.drawBuffers(s)}else this.bindUnboundFramebuffer(e[0]._framebuffer);return this.bindUnboundFramebuffer(null),t},s.prototype._uploadDataToTexture=function(e,t,i,r,n,o,s,a){this._gl.texImage2D(e,t,i,r,n,0,o,s,a)},s.prototype._uploadCompressedDataToTexture=function(e,t,i,r,n,o){this._gl.compressedTexImage2D(e,t,i,r,n,0,o)},s.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,!0);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&&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._internalTexturesCache.push(o),o},s.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,_,!0),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.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)},s.prototype.createCubeTexture=function(t,i,r,o,s,a,h,l){var c=this;void 0===s&&(s=null),void 0===a&&(a=null),void 0===l&&(l=null);var u=this._gl,p=new e.InternalTexture(this,e.InternalTexture.DATASOURCE_CUBE);p.isCube=!0,p.url=t,p.generateMipMaps=!o,this._doNotHandleContextLost||(p._extension=l,p._files=r);var f=!1,d=!1,m=t.lastIndexOf("."),g=l||(m>-1?t.substring(m).toLowerCase():"");this._textureFormatInUse?(g=this._textureFormatInUse,t=(m>-1?t.substring(0,m):t)+this._textureFormatInUse,f=!0):d=".dds"===g;var _=function(e,t){a&&e&&a(e.status+" "+e.statusText,t)};if(f)this._loadFile(t,function(t){var i=new e.KhronosTextureContainer(t,6),r=i.numberOfMipmapLevels>1&&!o;c._bindTextureDirectly(u.TEXTURE_CUBE_MAP,p,!0),u.pixelStorei(u.UNPACK_FLIP_Y_WEBGL,1),i.uploadLevels(c._gl,!o),c.setCubeMapTextureParams(u,r),p.width=i.pixelWidth,p.height=i.pixelHeight,p.isReady=!0},void 0,void 0,!0,_);else if(d)r&&6===r.length?this._cascadeLoadFiles(t,i,function(t){for(var i,r=!1,n=0,a=0;a<t.length;a++){var h=t[a];r=((i=e.DDSTools.GetDDSInfo(h)).isRGB||i.isLuminance||i.mipmapCount>1)&&!o,c._bindTextureDirectly(u.TEXTURE_CUBE_MAP,p,!0),u.pixelStorei(u.UNPACK_FLIP_Y_WEBGL,i.isCompressed?1:0),e.DDSTools.UploadDDSLevels(c,c._gl,h,i,r,6,-1,a),o||i.isFourCC||1!==i.mipmapCount||u.generateMipmap(u.TEXTURE_CUBE_MAP),p.width=i.width,p.height=i.height,p.type=i.textureType,n=i.width}c.setCubeMapTextureParams(u,r),p.isReady=!0,s&&s({isDDS:!0,width:n,info:i,imgs:t,texture:p})},r,a):this._loadFile(t,function(t){var i=e.DDSTools.GetDDSInfo(t),r=(i.isRGB||i.isLuminance||i.mipmapCount>1)&&!o;c._bindTextureDirectly(u.TEXTURE_CUBE_MAP,p,!0),u.pixelStorei(u.UNPACK_FLIP_Y_WEBGL,i.isCompressed?1:0),e.DDSTools.UploadDDSLevels(c,c._gl,t,i,r,6),o||i.isFourCC||1!==i.mipmapCount||u.generateMipmap(u.TEXTURE_CUBE_MAP),c.setCubeMapTextureParams(u,r),p.width=i.width,p.height=i.height,p.isReady=!0,p.type=i.textureType,s&&s({isDDS:!0,width:i.width,info:i,data:t,texture:p})},void 0,void 0,!0,_);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=c.needPOTTextures?e.Tools.GetExponentOfTwo(t[0].width,c._caps.maxCubemapTextureSize):t[0].width,r=i;if(c._prepareWorkingCanvas(),c._workingCanvas&&c._workingContext){c._workingCanvas.width=i,c._workingCanvas.height=r;var n=[u.TEXTURE_CUBE_MAP_POSITIVE_X,u.TEXTURE_CUBE_MAP_POSITIVE_Y,u.TEXTURE_CUBE_MAP_POSITIVE_Z,u.TEXTURE_CUBE_MAP_NEGATIVE_X,u.TEXTURE_CUBE_MAP_NEGATIVE_Y,u.TEXTURE_CUBE_MAP_NEGATIVE_Z];c._bindTextureDirectly(u.TEXTURE_CUBE_MAP,p,!0),u.pixelStorei(u.UNPACK_FLIP_Y_WEBGL,0);for(var a=h?c._getInternalFormat(h):c._gl.RGBA,l=0;l<n.length;l++)c._workingContext.drawImage(t[l],0,0,t[l].width,t[l].height,0,0,i,r),u.texImage2D(n[l],0,a,a,u.UNSIGNED_BYTE,c._workingCanvas);o||u.generateMipmap(u.TEXTURE_CUBE_MAP),c.setCubeMapTextureParams(u,!o),p.width=i,p.height=r,p.isReady=!0,h&&(p.format=h),p.onLoadedObservable.notifyObservers(p),p.onLoadedObservable.clear(),s&&s()}},r,a)}return this._internalTexturesCache.push(p),p},s.prototype.setCubeMapTextureParams=function(e,t){e.texParameteri(e.TEXTURE_CUBE_MAP,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_CUBE_MAP,e.TEXTURE_MIN_FILTER,t?e.LINEAR_MIPMAP_LINEAR:e.LINEAR),e.texParameteri(e.TEXTURE_CUBE_MAP,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_CUBE_MAP,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),this._bindTextureDirectly(e.TEXTURE_CUBE_MAP,null)},s.prototype.updateRawCubeTexture=function(t,i,r,n,o,s,a){void 0===s&&(s=null),void 0===a&&(a=0),t._bufferViewArray=i,t.format=r,t.type=n,t.invertY=o,t._compression=s;var h=this._gl,l=this._getWebGLTextureType(n),c=this._getInternalFormat(r),u=this._getRGBABufferInternalSizedFormat(n),p=!1;c===h.RGB&&(c=h.RGBA,p=!0),this._bindTextureDirectly(h.TEXTURE_CUBE_MAP,t,!0),h.pixelStorei(h.UNPACK_FLIP_Y_WEBGL,void 0===o?1:o?1:0),t.width%4!=0&&h.pixelStorei(h.UNPACK_ALIGNMENT,1);for(var f=0;f<6;f++){var d=i[f];s?h.compressedTexImage2D(h.TEXTURE_CUBE_MAP_POSITIVE_X+f,a,this.getCaps().s3tc[s],t.width,t.height,0,d):(p&&(d=this._convertRGBtoRGBATextureData(d,t.width,t.height,n)),h.texImage2D(h.TEXTURE_CUBE_MAP_POSITIVE_X+f,a,u,t.width,t.height,0,c,l,d))}(!this.needPOTTextures||e.Tools.IsExponentOfTwo(t.width)&&e.Tools.IsExponentOfTwo(t.height))&&t.generateMipMaps&&0===a&&this._gl.generateMipmap(this._gl.TEXTURE_CUBE_MAP),this._bindTextureDirectly(this._gl.TEXTURE_CUBE_MAP,null),t.isReady=!0},s.prototype.createRawCubeTexture=function(t,i,n,o,s,a,h,l){void 0===l&&(l=null);var c=this._gl,u=new e.InternalTexture(this,e.InternalTexture.DATASOURCE_CUBERAW);u.isCube=!0,u.generateMipMaps=s,u.format=n,u.type=o,this._doNotHandleContextLost||(u._bufferViewArray=t);var p=this._getWebGLTextureType(o),f=this._getInternalFormat(n);f===c.RGB&&(f=c.RGBA);var d=i,m=d;if(u.width=d,u.height=m,!this.needPOTTextures||e.Tools.IsExponentOfTwo(u.width)&&e.Tools.IsExponentOfTwo(u.height)||(s=!1),t&&this.updateRawCubeTexture(u,t,n,o,a,l),this._bindTextureDirectly(this._gl.TEXTURE_CUBE_MAP,u,!0),t&&s&&this._gl.generateMipmap(this._gl.TEXTURE_CUBE_MAP),p!==c.FLOAT||this._caps.textureFloatLinearFiltering)if(p!==this._gl.HALF_FLOAT_OES||this._caps.textureHalfFloatLinearFiltering){var g=r(h,s,c);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_MAG_FILTER,g.mag),c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_MIN_FILTER,g.min)}else c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_MAG_FILTER,c.NEAREST),c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_MIN_FILTER,c.NEAREST);else c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_MAG_FILTER,c.NEAREST),c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_MIN_FILTER,c.NEAREST);return c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_WRAP_S,c.CLAMP_TO_EDGE),c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_WRAP_T,c.CLAMP_TO_EDGE),this._bindTextureDirectly(c.TEXTURE_CUBE_MAP,null),u},s.prototype.createRawCubeTextureFromUrl=function(t,i,r,n,o,s,a,h,l,c,u,p){var f=this;void 0===l&&(l=null),void 0===c&&(c=null),void 0===u&&(u=e.Texture.TRILINEAR_SAMPLINGMODE),void 0===p&&(p=!1);var d=this._gl,m=this.createRawCubeTexture(null,r,n,o,!s,p,u);i._addPendingData(m),m.url=t,this._internalTexturesCache.push(m);return this._loadFile(t,function(e){!function(e){var t=m.width,r=a(e);if(r){if(h){var c=f._getWebGLTextureType(o),u=f._getInternalFormat(n),g=f._getRGBABufferInternalSizedFormat(o),_=!1;u===d.RGB&&(u=d.RGBA,_=!0),f._bindTextureDirectly(d.TEXTURE_CUBE_MAP,m,!0),d.pixelStorei(d.UNPACK_FLIP_Y_WEBGL,0);for(var v=h(r),y=0;y<v.length;y++)for(var b=t>>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,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},s.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,!0),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),e.isReady=!0},s.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,!0);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},s.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),t&&t._removePendingData(e),e.onLoadedObservable.notifyObservers(e),e.onLoadedObservable.clear()}},s.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;f&&(t._webGLTexture?(this._bindTextureDirectly(f.TEXTURE_2D,t,!0),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)):i&&i._removePendingData(t))},s.prototype._convertRGBtoRGBATextureData=function(e,t,i,r){var n;n=r===s.TEXTURETYPE_FLOAT?new Float32Array(t*i*4):new Uint32Array(t*i*4);for(var o=0;o<t;o++)for(var a=0;a<i;a++){var h=3*(a*t+o),l=4*(a*t+o);n[l+0]=e[h+0],n[l+1]=e[h+1],n[l+2]=e[h+2],n[l+3]=1}return n},s.prototype._releaseFramebufferObjects=function(e){var t=this._gl;e._framebuffer&&(t.deleteFramebuffer(e._framebuffer),e._framebuffer=null),e._depthStencilBuffer&&(t.deleteRenderbuffer(e._depthStencilBuffer),e._depthStencilBuffer=null),e._MSAAFramebuffer&&(t.deleteFramebuffer(e._MSAAFramebuffer),e._MSAAFramebuffer=null),e._MSAARenderBuffer&&(t.deleteRenderbuffer(e._MSAARenderBuffer),e._MSAARenderBuffer=null)},s.prototype._releaseTexture=function(e){var t=this._gl;this._releaseFramebufferObjects(e),t.deleteTexture(e._webGLTexture),this.unbindAllTextures();var i=this._internalTexturesCache.indexOf(e);-1!==i&&this._internalTexturesCache.splice(i,1),e._lodTextureHigh&&e._lodTextureHigh.dispose(),e._lodTextureMid&&e._lodTextureMid.dispose(),e._lodTextureLow&&e._lodTextureLow.dispose()},s.prototype.setProgram=function(e){this._currentProgram!==e&&(this._gl.useProgram(e),this._currentProgram=e)},s.prototype.bindSamplers=function(e){this.setProgram(e.getProgram());for(var t=e.getSamplers(),i=0;i<t.length;i++){var r=e.getUniform(t[i]);r&&(this._boundUniforms[i]=r)}this._currentEffect=null},s.prototype._activateTextureChannel=function(e){this._activeChannel!==e&&e>-1&&(this._gl.activeTexture(this._gl.TEXTURE0+e),this._activeChannel=e)},s.prototype._moveBoundTextureOnTop=function(e){var t=this._boundTexturesStack.indexOf(e);t>-1&&t!==this._boundTexturesStack.length-1&&(this._boundTexturesStack.splice(t,1),this._boundTexturesStack.push(e))},s.prototype._removeDesignatedSlot=function(e){var t=e._designatedSlot;e._designatedSlot=-1;var i=this._boundTexturesStack.indexOf(e);return i>-1&&(this._boundTexturesStack.splice(i,1),t>-1&&(this._boundTexturesCache[t]=null,this._nextFreeTextureSlots.push(t))),t},s.prototype._bindTextureDirectly=function(e,t,i){void 0===i&&(i=!1);var r=this._boundTexturesCache[this._activeChannel],n=t&&t._initialSlot>-1;if(r!==t&&(r&&!this.disableTextureBindingOptimization&&this._removeDesignatedSlot(r),this._gl.bindTexture(e,t?t._webGLTexture:null),this._activeChannel>=0&&(this._boundTexturesCache[this._activeChannel]=t,n&&!this.disableTextureBindingOptimization))){var o=this._nextFreeTextureSlots.indexOf(this._activeChannel);o>-1&&this._nextFreeTextureSlots.splice(o,1),this._boundTexturesStack.push(t)}n&&this._activeChannel>-1&&(t._designatedSlot=this._activeChannel,i||this._bindSamplerUniformToChannel(t._initialSlot,this._activeChannel))},s.prototype._bindTexture=function(e,t){e<0||(t&&(e=this._getCorrectTextureChannel(e,t)),this._activateTextureChannel(e),this._bindTextureDirectly(this._gl.TEXTURE_2D,t))},s.prototype.setTextureFromPostProcess=function(e,t){this._bindTexture(e,t?t._textures.data[t._currentRenderTextureInd]:null)},s.prototype.unbindAllTextures=function(){for(var e=0;e<this._maxSimultaneousTextures;e++)this._activateTextureChannel(e),this._bindTextureDirectly(this._gl.TEXTURE_2D,null),this._bindTextureDirectly(this._gl.TEXTURE_CUBE_MAP,null),this.webGLVersion>1&&this._bindTextureDirectly(this._gl.TEXTURE_3D,null)},s.prototype.setTexture=function(e,t,i){e<0||(t&&(this._boundUniforms[e]=t),this._setTexture(e,i))},s.prototype._getCorrectTextureChannel=function(e,t){if(!t)return-1;if(t._initialSlot=e,this.disableTextureBindingOptimization)e!==t._designatedSlot&&this._textureCollisions.addCount(1,!1);else if(e!==t._designatedSlot)return t._designatedSlot>-1?t._designatedSlot:this._nextFreeTextureSlots.length?this._nextFreeTextureSlots[0]:(this._textureCollisions.addCount(1,!1),this._removeDesignatedSlot(this._boundTexturesStack[0]));return e},s.prototype._bindSamplerUniformToChannel=function(e,t){var i=this._boundUniforms[e];this._gl.uniform1i(i,t)},s.prototype._setTexture=function(t,i,r){if(void 0===r&&(r=!1),!i)return null!=this._boundTexturesCache[t]&&(this._activateTextureChannel(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 n,o=!1;if(i.video)this._activateTextureChannel(t),o=!0,i.update();else if(i.delayLoadState===s.DELAYLOADSTATE_NOTLOADED)return i.delayLoad(),!1;if(n=i.isReady()?i.getInternalTexture():i.isCube?this.emptyCubeTexture:i.is3D?this.emptyTexture3D:this.emptyTexture,r||(t=this._getCorrectTextureChannel(t,n)),this._boundTexturesCache[t]===n)return this._moveBoundTextureOnTop(n),r||this._bindSamplerUniformToChannel(n._initialSlot,t),!1;if(o||this._activateTextureChannel(t),n&&n.is3D){if(this._bindTextureDirectly(this._gl.TEXTURE_3D,n,r),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,r),n._cachedCoordinatesMode!==i.coordinatesMode){n._cachedCoordinatesMode=i.coordinatesMode;var a=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,a),this._gl.texParameteri(this._gl.TEXTURE_CUBE_MAP,this._gl.TEXTURE_WRAP_T,a)}this._setAnisotropicLevel(this._gl.TEXTURE_CUBE_MAP,i)}else{if(this._bindTextureDirectly(this._gl.TEXTURE_2D,n,r),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},s.prototype.setTextureArray=function(e,t,i){if(!(e<0)&&t){this._textureUnits&&this._textureUnits.length===i.length||(this._textureUnits=new Int32Array(i.length));for(var r=0;r<i.length;r++)this._textureUnits[r]=this._getCorrectTextureChannel(e+r,i[r].getInternalTexture());this._gl.uniform1iv(t,this._textureUnits);for(var n=0;n<i.length;n++)this._setTexture(this._textureUnits[n],i[n],!0)}},s.prototype._setAnisotropicLevel=function(t,i){var r=i.getInternalTexture();if(r){var n=this._caps.textureAnisotropicFilterExtension,o=i.anisotropicFilteringLevel;r.samplingMode!==e.Texture.LINEAR_LINEAR_MIPNEAREST&&r.samplingMode!==e.Texture.LINEAR_LINEAR_MIPLINEAR&&r.samplingMode!==e.Texture.LINEAR_LINEAR&&(o=1),n&&r._cachedAnisotropicFilteringLevel!==o&&(this._gl.texParameterf(t,n.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(o,this._caps.maxAnisotropy)),r._cachedAnisotropicFilteringLevel=o)}},s.prototype.readPixels=function(e,t,i,r){var n=new Uint8Array(r*i*4);return this._gl.readPixels(e,t,i,r,this._gl.RGBA,this._gl.UNSIGNED_BYTE,n),n},s.prototype.addExternalData=function(t,i){return this._externalData||(this._externalData=new e.StringDictionary),this._externalData.add(t,i)},s.prototype.getExternalData=function(t){return this._externalData||(this._externalData=new e.StringDictionary),this._externalData.get(t)},s.prototype.getOrAddExternalDataWithFactory=function(t,i){return this._externalData||(this._externalData=new e.StringDictionary),this._externalData.getOrAddWithFactory(t,i)},s.prototype.removeExternalData=function(t){return this._externalData||(this._externalData=new e.StringDictionary),this._externalData.remove(t)},s.prototype.unbindAllAttributes=function(){if(this._mustWipeVertexAttributes){this._mustWipeVertexAttributes=!1;for(var e=0;e<this._caps.maxVertexAttribs;e++)this._gl.disableVertexAttribArray(e),this._vertexAttribArraysEnabled[e]=!1,this._currentBufferPointers[e].active=!1}else{e=0;for(var t=this._vertexAttribArraysEnabled.length;e<t;e++)e>=this._caps.maxVertexAttribs||!this._vertexAttribArraysEnabled[e]||(this._gl.disableVertexAttribArray(e),this._vertexAttribArraysEnabled[e]=!1,this._currentBufferPointers[e].active=!1)}},s.prototype.releaseEffects=function(){for(var e in this._compiledEffects)this._deleteProgram(this._compiledEffects[e]._program);this._compiledEffects={}},s.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();s.audioEngine&&s.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=s.Instances.indexOf(this);t>=0&&s.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();for(var i=0,r=this._activeRequests;i<r.length;i++){r[i].abort()}},s.prototype.displayLoadingUI=function(){if(e.Tools.IsWindowObjectExist()){var t=this.loadingScreen;t&&t.displayLoadingUI()}},s.prototype.hideLoadingUI=function(){if(e.Tools.IsWindowObjectExist()){var t=this.loadingScreen;t&&t.hideLoadingUI()}},Object.defineProperty(s.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(s.prototype,"loadingUIText",{set:function(e){this.loadingScreen.loadingUIText=e},enumerable:!0,configurable:!0}),Object.defineProperty(s.prototype,"loadingUIBackgroundColor",{set:function(e){this.loadingScreen.loadingUIBackgroundColor=e},enumerable:!0,configurable:!0}),s.prototype.attachContextLostEvent=function(e){this._renderingCanvas&&this._renderingCanvas.addEventListener("webglcontextlost",e,!1)},s.prototype.attachContextRestoredEvent=function(e){this._renderingCanvas&&this._renderingCanvas.addEventListener("webglcontextrestored",e,!1)},s.prototype.getVertexShaderSource=function(e){var t=this._gl.getAttachedShaders(e);return t?this._gl.getShaderSource(t[0]):null},s.prototype.getFragmentShaderSource=function(e){var t=this._gl.getAttachedShaders(e);return t?this._gl.getShaderSource(t[1]):null},s.prototype.getError=function(){return this._gl.getError()},s.prototype.getFps=function(){return this._fps},s.prototype.getDeltaTime=function(){return this._deltaTime},s.prototype._measureFps=function(){this._performanceMonitor.sampleFrame(),this._fps=this._performanceMonitor.averageFPS,this._deltaTime=this._performanceMonitor.instantaneousFrameTime||0},s.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},s.prototype._canRenderToFloatFramebuffer=function(){return this._webGLVersion>1?this._caps.colorBufferFloat:this._canRenderToFramebuffer(s.TEXTURETYPE_FLOAT)},s.prototype._canRenderToHalfFloatFramebuffer=function(){return this._webGLVersion>1?this._caps.colorBufferFloat:this._canRenderToFramebuffer(s.TEXTURETYPE_HALF_FLOAT)},s.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=i&&o===t.FRAMEBUFFER_COMPLETE)&&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},s.prototype._getWebGLTextureType=function(e){return e===s.TEXTURETYPE_FLOAT?this._gl.FLOAT:e===s.TEXTURETYPE_HALF_FLOAT?this._gl.HALF_FLOAT_OES:this._gl.UNSIGNED_BYTE},s.prototype._getRGBABufferInternalSizedFormat=function(e){return 1===this._webGLVersion?this._gl.RGBA:e===s.TEXTURETYPE_FLOAT?this._gl.RGBA32F:e===s.TEXTURETYPE_HALF_FLOAT?this._gl.RGBA16F:this._gl.RGBA},s.prototype._getRGBAMultiSampleBufferFormat=function(e){return e===s.TEXTURETYPE_FLOAT?this._gl.RGBA32F:e===s.TEXTURETYPE_HALF_FLOAT?this._gl.RGBA16F:this._gl.RGBA8},s.prototype.createQuery=function(){return this._gl.createQuery()},s.prototype.deleteQuery=function(e){return this._gl.deleteQuery(e),this},s.prototype.isQueryResultAvailable=function(e){return this._gl.getQueryParameter(e,this._gl.QUERY_RESULT_AVAILABLE)},s.prototype.getQueryResult=function(e){return this._gl.getQueryParameter(e,this._gl.QUERY_RESULT)},s.prototype.beginOcclusionQuery=function(e,t){var i=this.getGlAlgorithmType(e);return this._gl.beginQuery(i,t),this},s.prototype.endOcclusionQuery=function(e){var t=this.getGlAlgorithmType(e);return this._gl.endQuery(t),this},s.prototype._createTimeQuery=function(){var e=this._caps.timerQuery;return e.createQueryEXT?e.createQueryEXT():this.createQuery()},s.prototype._deleteTimeQuery=function(e){var t=this._caps.timerQuery;t.deleteQueryEXT?t.deleteQueryEXT(e):this.deleteQuery(e)},s.prototype._getTimeQueryResult=function(e){var t=this._caps.timerQuery;return t.getQueryObjectEXT?t.getQueryObjectEXT(e,t.QUERY_RESULT_EXT):this.getQueryResult(e)},s.prototype._getTimeQueryAvailability=function(e){var t=this._caps.timerQuery;return t.getQueryObjectEXT?t.getQueryObjectEXT(e,t.QUERY_RESULT_AVAILABLE_EXT):this.isQueryResultAvailable(e)},s.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},s.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},s.prototype.getGlAlgorithmType=function(t){return t===e.AbstractMesh.OCCLUSION_ALGORITHM_TYPE_CONSERVATIVE?this._gl.ANY_SAMPLES_PASSED_CONSERVATIVE:this._gl.ANY_SAMPLES_PASSED},s.prototype.createTransformFeedback=function(){return this._gl.createTransformFeedback()},s.prototype.deleteTransformFeedback=function(e){this._gl.deleteTransformFeedback(e)},s.prototype.bindTransformFeedback=function(e){this._gl.bindTransformFeedback(this._gl.TRANSFORM_FEEDBACK,e)},s.prototype.beginTransformFeedback=function(e){void 0===e&&(e=!0),this._gl.beginTransformFeedback(e?this._gl.POINTS:this._gl.TRIANGLES)},s.prototype.endTransformFeedback=function(){this._gl.endTransformFeedback()},s.prototype.setTranformFeedbackVaryings=function(e,t){this._gl.transformFeedbackVaryings(e,t,this._gl.INTERLEAVED_ATTRIBS)},s.prototype.bindTransformFeedbackBuffer=function(e){this._gl.bindBufferBase(this._gl.TRANSFORM_FEEDBACK_BUFFER,0,e)},s.prototype._loadFile=function(t,i,r,n,o,s){var a=this,h=e.Tools.LoadFile(t,i,r,n,o,s);return this._activeRequests.push(h),h.onCompleteObservable.add(function(e){a._activeRequests.splice(a._activeRequests.indexOf(e),1)}),h},s.prototype._partialLoadFile=function(e,t,i,r,n,o){void 0===o&&(o=null);this._loadFile(e,function(e){i[t]=e,i._internalCount++,6===i._internalCount&&n(i)},void 0,void 0,!0,function(e,t){o&&e&&o(e.status+" "+e.statusText,t)})},s.prototype._cascadeLoadFiles=function(e,t,i,r,n){void 0===n&&(n=null);var o=[];o._internalCount=0;for(var s=0;s<6;s++)this._partialLoadFile(r[s],s,o,t,i,n)},s.isSupported=function(){try{var e=document.createElement("canvas");return null!=(e.getContext("webgl")||e.getContext("experimental-webgl"))&&!!window.WebGLRenderingContext}catch(e){return!1}},s.ExceptionList=[{key:"Chrome/63.0",capture:"63\\.0\\.3239\\.(\\d+)",captureConstraint:108,targets:["uniformBuffer"]},{key:"Firefox/58",capture:null,captureConstraint:null,targets:["uniformBuffer"]},{key:"Macintosh",capture:null,captureConstraint:null,targets:["textureBindingOptimization"]}],s.Instances=new Array,s._ALPHA_DISABLE=0,s._ALPHA_ADD=1,s._ALPHA_COMBINE=2,s._ALPHA_SUBTRACT=3,s._ALPHA_MULTIPLY=4,s._ALPHA_MAXIMIZED=5,s._ALPHA_ONEONE=6,s._ALPHA_PREMULTIPLIED=7,s._ALPHA_PREMULTIPLIED_PORTERDUFF=8,s._ALPHA_INTERPOLATE=9,s._ALPHA_SCREENMODE=10,s._DELAYLOADSTATE_NONE=0,s._DELAYLOADSTATE_LOADED=1,s._DELAYLOADSTATE_LOADING=2,s._DELAYLOADSTATE_NOTLOADED=4,s._TEXTUREFORMAT_ALPHA=0,s._TEXTUREFORMAT_LUMINANCE=1,s._TEXTUREFORMAT_LUMINANCE_ALPHA=2,s._TEXTUREFORMAT_RGB=4,s._TEXTUREFORMAT_RGBA=5,s._TEXTURETYPE_UNSIGNED_INT=0,s._TEXTURETYPE_FLOAT=1,s._TEXTURETYPE_HALF_FLOAT=2,s._NEVER=512,s._ALWAYS=519,s._LESS=513,s._EQUAL=514,s._LEQUAL=515,s._GREATER=516,s._GEQUAL=518,s._NOTEQUAL=517,s._KEEP=7680,s._REPLACE=7681,s._INCR=7682,s._DECR=7683,s._INVERT=5386,s._INCR_WRAP=34055,s._DECR_WRAP=34056,s._SCALEMODE_FLOOR=1,s._SCALEMODE_NEAREST=2,s._SCALEMODE_CEILING=3,s.CollisionsEpsilon=.001,s.CodeRepository="src/",s.ShadersRepository="src/Shaders/",s}();e.Engine=l}(us||(us={})),p=us||(us={}),f=function(){function e(e,t){void 0===t&&(t=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 p.Observable,this._behaviors=new Array,this.name=e,this.id=e,this._scene=t||p.Engine.LastCreatedScene,this.uniqueId=this._scene.getUniqueId(),this._initCache()}return Object.defineProperty(e.prototype,"parent",{get:function(){return this._parentNode},set:function(e){if(this._parentNode!==e){if(this._parentNode&&void 0!==this._parentNode._children&&null!==this._parentNode._children){var t=this._parentNode._children.indexOf(this);-1!==t&&this._parentNode._children.splice(t,1)}this._parentNode=e,this._parentNode&&(void 0!==this._parentNode._children&&null!==this._parentNode._children||(this._parentNode._children=new Array),this._parentNode._children.push(this))}},enumerable:!0,configurable:!0}),e.prototype.getClassName=function(){return"Node"},Object.defineProperty(e.prototype,"onDispose",{set:function(e){this._onDisposeObserver&&this.onDisposeObservable.remove(this._onDisposeObserver),this._onDisposeObserver=this.onDisposeObservable.add(e)},enumerable:!0,configurable:!0}),e.prototype.getScene=function(){return this._scene},e.prototype.getEngine=function(){return this._scene.getEngine()},e.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),setTimeout(function(){t._scene.onDataLoadedObservable.remove(i)},0)});else e.attach(this);return this._behaviors.push(e),this},e.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(e.prototype,"behaviors",{get:function(){return this._behaviors},enumerable:!0,configurable:!0}),e.prototype.getBehaviorByName=function(e){for(var t=0,i=this._behaviors;t<i.length;t++){var r=i[t];if(r.name===e)return r}return null},e.prototype.getWorldMatrix=function(){return p.Matrix.Identity()},e.prototype._initCache=function(){this._cache={},this._cache.parent=void 0},e.prototype.updateCache=function(e){!e&&this.isSynchronized()||(this._cache.parent=this.parent,this._updateCache())},e.prototype._updateCache=function(e){},e.prototype._isSynchronized=function(){return!0},e.prototype._markSyncedWithParent=function(){this.parent&&(this._parentRenderId=this.parent._currentRenderId)},e.prototype.isSynchronizedWithParent=function(){return!this.parent||this._parentRenderId===this.parent._currentRenderId&&this.parent.isSynchronized()},e.prototype.isSynchronized=function(e){var t=this.hasNewParent();return t=(t=t||!this.isSynchronizedWithParent())||!this._isSynchronized(),e&&this.updateCache(!0),!t},e.prototype.hasNewParent=function(e){return this._cache.parent!==this.parent&&(e&&(this._cache.parent=this.parent),!0)},e.prototype.isReady=function(){return this._isReady},e.prototype.isEnabled=function(e){return void 0===e&&(e=!0),!1===e?this._isEnabled:!1!==this._isEnabled&&(void 0===this.parent||null===this.parent||this.parent.isEnabled(e))},e.prototype.setEnabled=function(e){this._isEnabled=e},e.prototype.isDescendantOf=function(e){return!!this.parent&&(this.parent===e||this.parent.isDescendantOf(e))},e.prototype._getDescendants=function(e,t,i){if(void 0===t&&(t=!1),this._children)for(var r=0;r<this._children.length;r++){var n=this._children[r];i&&!i(n)||e.push(n),t||n._getDescendants(e,!1,i)}},e.prototype.getDescendants=function(e,t){var i=new Array;return this._getDescendants(i,e,t),i},e.prototype.getChildMeshes=function(e,t){var i=[];return this._getDescendants(i,e,function(e){return(!t||t(e))&&e instanceof p.AbstractMesh}),i},e.prototype.getChildTransformNodes=function(e,t){var i=[];return this._getDescendants(i,e,function(e){return(!t||t(e))&&e instanceof p.TransformNode}),i},e.prototype.getChildren=function(e){return this.getDescendants(!0,e)},e.prototype._setReady=function(e){e!==this._isReady&&(e?(this._isReady=!0,this.onReady&&this.onReady(this)):this._isReady=!1)},e.prototype.getAnimationByName=function(e){for(var t=0;t<this.animations.length;t++){var i=this.animations[t];if(i.name===e)return i}return null},e.prototype.createAnimationRange=function(e,t,i){if(!this._ranges[e]){this._ranges[e]=new p.AnimationRange(e,t,i);for(var r=0,n=this.animations.length;r<n;r++)this.animations[r]&&this.animations[r].createRange(e,t,i)}},e.prototype.deleteAnimationRange=function(e,t){void 0===t&&(t=!0);for(var i=0,r=this.animations.length;i<r;i++)this.animations[i]&&this.animations[i].deleteRange(e,t);this._ranges[e]=null},e.prototype.getAnimationRange=function(e){return this._ranges[e]},e.prototype.beginAnimation=function(e,t,i,r){var n=this.getAnimationRange(e);n&&this._scene.beginAnimation(this,n.from,n.to,t,i,r)},e.prototype.serializeAnimationRanges=function(){var e=[];for(var t in this._ranges){var i=this._ranges[t];if(i){var r={};r.name=t,r.from=i.from,r.to=i.to,e.push(r)}}return e},e.prototype.computeWorldMatrix=function(e){return p.Matrix.Identity()},e.prototype.dispose=function(){this.parent=null,this.onDisposeObservable.notifyObservers(this),this.onDisposeObservable.clear();for(var e=0,t=this._behaviors;e<t.length;e++){t[e].detach()}this._behaviors=[]},e.ParseAnimationRanges=function(e,t,i){if(t.ranges)for(var r=0;r<t.ranges.length;r++){var n=t.ranges[r];e.createAnimationRange(n.name,n.from,n.to)}},X([p.serialize()],e.prototype,"name",void 0),X([p.serialize()],e.prototype,"id",void 0),X([p.serialize()],e.prototype,"uniqueId",void 0),X([p.serialize()],e.prototype,"state",void 0),X([p.serialize()],e.prototype,"metadata",void 0),e}(),p.Node=f,d=us||(us={}),m=function(){function e(e,t){this.minimum=e,this.maximum=t,this._tempRadiusVector=d.Vector3.Zero();var i=d.Vector3.Distance(e,t);this.center=d.Vector3.Lerp(e,t,.5),this.radius=.5*i,this.centerWorld=d.Vector3.Zero(),this._update(d.Matrix.Identity())}return e.prototype._update=function(e){d.Vector3.TransformCoordinatesToRef(this.center,e,this.centerWorld),d.Vector3.TransformNormalFromFloatsToRef(1,1,1,e,this._tempRadiusVector),this.radiusWorld=Math.max(Math.abs(this._tempRadiusVector.x),Math.abs(this._tempRadiusVector.y),Math.abs(this._tempRadiusVector.z))*this.radius},e.prototype.isInFrustum=function(e){for(var t=0;t<6;t++)if(e[t].dotCoordinate(this.centerWorld)<=-this.radiusWorld)return!1;return!0},e.prototype.intersectsPoint=function(e){var t=this.centerWorld.x-e.x,i=this.centerWorld.y-e.y,r=this.centerWorld.z-e.z,n=Math.sqrt(t*t+i*i+r*r);return!(Math.abs(this.radiusWorld-n)<d.Epsilon)},e.Intersects=function(e,t){var i=e.centerWorld.x-t.centerWorld.x,r=e.centerWorld.y-t.centerWorld.y,n=e.centerWorld.z-t.centerWorld.z,o=Math.sqrt(i*i+r*r+n*n);return!(e.radiusWorld+t.radiusWorld<o)},e}(),d.BoundingSphere=m,g=us||(us={}),_=function(){function e(e,t){this.minimum=e,this.maximum=t,this.vectors=new Array,this.vectorsWorld=new Array,this.vectors.push(this.minimum.clone()),this.vectors.push(this.maximum.clone()),this.vectors.push(this.minimum.clone()),this.vectors[2].x=this.maximum.x,this.vectors.push(this.minimum.clone()),this.vectors[3].y=this.maximum.y,this.vectors.push(this.minimum.clone()),this.vectors[4].z=this.maximum.z,this.vectors.push(this.maximum.clone()),this.vectors[5].z=this.minimum.z,this.vectors.push(this.maximum.clone()),this.vectors[6].x=this.minimum.x,this.vectors.push(this.maximum.clone()),this.vectors[7].y=this.minimum.y,this.center=this.maximum.add(this.minimum).scale(.5),this.extendSize=this.maximum.subtract(this.minimum).scale(.5),this.directions=[g.Vector3.Zero(),g.Vector3.Zero(),g.Vector3.Zero()];for(var i=0;i<this.vectors.length;i++)this.vectorsWorld[i]=g.Vector3.Zero();this.minimumWorld=g.Vector3.Zero(),this.maximumWorld=g.Vector3.Zero(),this.centerWorld=g.Vector3.Zero(),this.extendSizeWorld=g.Vector3.Zero(),this._update(g.Matrix.Identity())}return e.prototype.getWorldMatrix=function(){return this._worldMatrix},e.prototype.setWorldMatrix=function(e){return this._worldMatrix.copyFrom(e),this},e.prototype._update=function(e){g.Vector3.FromFloatsToRef(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE,this.minimumWorld),g.Vector3.FromFloatsToRef(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE,this.maximumWorld);for(var t=0;t<this.vectors.length;t++){var i=this.vectorsWorld[t];g.Vector3.TransformCoordinatesToRef(this.vectors[t],e,i),i.x<this.minimumWorld.x&&(this.minimumWorld.x=i.x),i.y<this.minimumWorld.y&&(this.minimumWorld.y=i.y),i.z<this.minimumWorld.z&&(this.minimumWorld.z=i.z),i.x>this.maximumWorld.x&&(this.maximumWorld.x=i.x),i.y>this.maximumWorld.y&&(this.maximumWorld.y=i.y),i.z>this.maximumWorld.z&&(this.maximumWorld.z=i.z)}this.maximumWorld.subtractToRef(this.minimumWorld,this.extendSizeWorld),this.extendSizeWorld.scaleInPlace(.5),this.maximumWorld.addToRef(this.minimumWorld,this.centerWorld),this.centerWorld.scaleInPlace(.5),g.Vector3.FromFloatArrayToRef(e.m,0,this.directions[0]),g.Vector3.FromFloatArrayToRef(e.m,4,this.directions[1]),g.Vector3.FromFloatArrayToRef(e.m,8,this.directions[2]),this._worldMatrix=e},e.prototype.isInFrustum=function(t){return e.IsInFrustum(this.vectorsWorld,t)},e.prototype.isCompletelyInFrustum=function(t){return e.IsCompletelyInFrustum(this.vectorsWorld,t)},e.prototype.intersectsPoint=function(e){var t=-g.Epsilon;return!(this.maximumWorld.x-e.x<t||t>e.x-this.minimumWorld.x)&&(!(this.maximumWorld.y-e.y<t||t>e.y-this.minimumWorld.y)&&!(this.maximumWorld.z-e.z<t||t>e.z-this.minimumWorld.z))},e.prototype.intersectsSphere=function(t){return e.IntersectsSphere(this.minimumWorld,this.maximumWorld,t.centerWorld,t.radiusWorld)},e.prototype.intersectsMinMax=function(e,t){return!(this.maximumWorld.x<e.x||this.minimumWorld.x>t.x)&&(!(this.maximumWorld.y<e.y||this.minimumWorld.y>t.y)&&!(this.maximumWorld.z<e.z||this.minimumWorld.z>t.z))},e.Intersects=function(e,t){return!(e.maximumWorld.x<t.minimumWorld.x||e.minimumWorld.x>t.maximumWorld.x)&&(!(e.maximumWorld.y<t.minimumWorld.y||e.minimumWorld.y>t.maximumWorld.y)&&!(e.maximumWorld.z<t.minimumWorld.z||e.minimumWorld.z>t.maximumWorld.z))},e.IntersectsSphere=function(e,t,i,r){var n=g.Vector3.Clamp(i,e,t);return g.Vector3.DistanceSquared(i,n)<=r*r},e.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},e.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},e}(),g.BoundingBox=_,v=us||(us={}),y=function(e,t){var i=v.Vector3.Dot(t.centerWorld,e),r=Math.abs(v.Vector3.Dot(t.directions[0],e))*t.extendSize.x+Math.abs(v.Vector3.Dot(t.directions[1],e))*t.extendSize.y+Math.abs(v.Vector3.Dot(t.directions[2],e))*t.extendSize.z;return{min:i-r,max:i+r}},b=function(e,t,i){var r,n,o,s,a=y(e,t),h=y(e,i);return r=a.min,n=a.max,o=h.min,s=h.max,!(r>s||o>n)},x=function(){function e(e,t){this.minimum=e,this.maximum=t,this._isLocked=!1,this.boundingBox=new v.BoundingBox(e,t),this.boundingSphere=new v.BoundingSphere(e,t)}return Object.defineProperty(e.prototype,"isLocked",{get:function(){return this._isLocked},set:function(e){this._isLocked=e},enumerable:!0,configurable:!0}),e.prototype.update=function(e){this._isLocked||(this.boundingBox._update(e),this.boundingSphere._update(e))},e.prototype.centerOn=function(e,t){return this.minimum=e.subtract(t),this.maximum=e.add(t),this.boundingBox=new v.BoundingBox(this.minimum,this.maximum),this.boundingSphere=new v.BoundingSphere(this.minimum,this.maximum),this},e.prototype.isInFrustum=function(e){return!!this.boundingSphere.isInFrustum(e)&&this.boundingBox.isInFrustum(e)},Object.defineProperty(e.prototype,"diagonalLength",{get:function(){var e=this.boundingBox;return e.maximumWorld.subtract(e.minimumWorld).length()},enumerable:!0,configurable:!0}),e.prototype.isCompletelyInFrustum=function(e){return this.boundingBox.isCompletelyInFrustum(e)},e.prototype._checkCollision=function(e){return e._canDoCollision(this.boundingSphere.centerWorld,this.boundingSphere.radiusWorld,this.boundingBox.minimumWorld,this.boundingBox.maximumWorld)},e.prototype.intersectsPoint=function(e){return!!this.boundingSphere.centerWorld&&(!!this.boundingSphere.intersectsPoint(e)&&!!this.boundingBox.intersectsPoint(e))},e.prototype.intersects=function(e,t){if(!this.boundingSphere.centerWorld||!e.boundingSphere.centerWorld)return!1;if(!v.BoundingSphere.Intersects(this.boundingSphere,e.boundingSphere))return!1;if(!v.BoundingBox.Intersects(this.boundingBox,e.boundingBox))return!1;if(!t)return!0;var i=this.boundingBox,r=e.boundingBox;return!!b(i.directions[0],i,r)&&(!!b(i.directions[1],i,r)&&(!!b(i.directions[2],i,r)&&(!!b(r.directions[0],i,r)&&(!!b(r.directions[1],i,r)&&(!!b(r.directions[2],i,r)&&(!!b(v.Vector3.Cross(i.directions[0],r.directions[0]),i,r)&&(!!b(v.Vector3.Cross(i.directions[0],r.directions[1]),i,r)&&(!!b(v.Vector3.Cross(i.directions[0],r.directions[2]),i,r)&&(!!b(v.Vector3.Cross(i.directions[1],r.directions[0]),i,r)&&(!!b(v.Vector3.Cross(i.directions[1],r.directions[1]),i,r)&&(!!b(v.Vector3.Cross(i.directions[1],r.directions[2]),i,r)&&(!!b(v.Vector3.Cross(i.directions[2],r.directions[0]),i,r)&&(!!b(v.Vector3.Cross(i.directions[2],r.directions[1]),i,r)&&!!b(v.Vector3.Cross(i.directions[2],r.directions[2]),i,r))))))))))))))},e}(),v.BoundingInfo=x,T=us||(us={}),E=function(e){function t(t,i,r){void 0===i&&(i=null),void 0===r&&(r=!0);var n=e.call(this,t,i)||this;return n._rotation=T.Vector3.Zero(),n._scaling=T.Vector3.One(),n._isDirty=!1,n.billboardMode=T.AbstractMesh.BILLBOARDMODE_NONE,n.scalingDeterminant=1,n.infiniteDistance=!1,n.position=T.Vector3.Zero(),n._localWorld=T.Matrix.Zero(),n._worldMatrix=T.Matrix.Zero(),n._worldMatrixDeterminant=0,n._absolutePosition=T.Vector3.Zero(),n._pivotMatrix=T.Matrix.Identity(),n._postMultiplyPivotMatrix=!1,n._isWorldMatrixFrozen=!1,n.onAfterWorldMatrixUpdateObservable=new T.Observable,n._nonUniformScaling=!1,r&&n.getScene().addTransformNode(n),n}return Y(t,e),Object.defineProperty(t.prototype,"rotation",{get:function(){return this._rotation},set:function(e){this._rotation=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"scaling",{get:function(){return this._scaling},set:function(e){this._scaling=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.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}),t.prototype.getWorldMatrix=function(){return this._currentRenderId!==this.getScene().getRenderId()&&this.computeWorldMatrix(),this._worldMatrix},t.prototype._getWorldMatrixDeterminant=function(){return this._worldMatrixDeterminant},Object.defineProperty(t.prototype,"worldMatrixFromCache",{get:function(){return this._worldMatrix},enumerable:!0,configurable:!0}),t.prototype.updatePoseMatrix=function(e){return this._poseMatrix.copyFrom(e),this},t.prototype.getPoseMatrix=function(){return this._poseMatrix},t.prototype._isSynchronized=function(){return!this._isDirty&&(this.billboardMode===this._cache.billboardMode&&this.billboardMode===T.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)))))))},t.prototype._initCache=function(){e.prototype._initCache.call(this),this._cache.localMatrixUpdated=!1,this._cache.position=T.Vector3.Zero(),this._cache.scaling=T.Vector3.Zero(),this._cache.rotation=T.Vector3.Zero(),this._cache.rotationQuaternion=new T.Quaternion(0,0,0,0),this._cache.billboardMode=-1},t.prototype.markAsDirty=function(e){return"rotation"===e&&(this.rotationQuaternion=null),this._currentRenderId=Number.MAX_VALUE,this._isDirty=!0,this},Object.defineProperty(t.prototype,"absolutePosition",{get:function(){return this._absolutePosition},enumerable:!0,configurable:!0}),t.prototype.setPivotMatrix=function(e,t){return void 0===t&&(t=!1),this._pivotMatrix=e.clone(),this._cache.pivotMatrixUpdated=!0,this._postMultiplyPivotMatrix=t,this._postMultiplyPivotMatrix&&(this._pivotMatrixInverse=T.Matrix.Invert(e)),this},t.prototype.getPivotMatrix=function(){return this._pivotMatrix},t.prototype.freezeWorldMatrix=function(){return this._isWorldMatrixFrozen=!1,this.computeWorldMatrix(!0),this._isWorldMatrixFrozen=!0,this},t.prototype.unfreezeWorldMatrix=function(){return this._isWorldMatrixFrozen=!1,this.computeWorldMatrix(!0),this},Object.defineProperty(t.prototype,"isWorldMatrixFrozen",{get:function(){return this._isWorldMatrixFrozen},enumerable:!0,configurable:!0}),t.prototype.getAbsolutePosition=function(){return this.computeWorldMatrix(),this._absolutePosition},t.prototype.setAbsolutePosition=function(e){if(!e)return this;var t,i,r;if(void 0===e.x){if(arguments.length<3)return this;t=arguments[0],i=arguments[1],r=arguments[2]}else t=e.x,i=e.y,r=e.z;if(this.parent){var n=this.parent.getWorldMatrix().clone();n.invert();var o=new T.Vector3(t,i,r);this.position=T.Vector3.TransformCoordinates(o,n)}else this.position.x=t,this.position.y=i,this.position.z=r;return this},t.prototype.setPositionWithLocalVector=function(e){return this.computeWorldMatrix(),this.position=T.Vector3.TransformNormal(e,this._localWorld),this},t.prototype.getPositionExpressedInLocalSpace=function(){this.computeWorldMatrix();var e=this._localWorld.clone();return e.invert(),T.Vector3.TransformNormal(this.position,e)},t.prototype.locallyTranslate=function(e){return this.computeWorldMatrix(!0),this.position=T.Vector3.TransformCoordinates(e,this._localWorld),this},t.prototype.lookAt=function(e,t,i,r,n){void 0===t&&(t=0),void 0===i&&(i=0),void 0===r&&(r=0),void 0===n&&(n=T.Space.LOCAL);var o=T.AbstractMesh._lookAtVectorCache,s=n===T.Space.LOCAL?this.position:this.getAbsolutePosition();e.subtractToRef(s,o);var a=-Math.atan2(o.z,o.x)-Math.PI/2,h=Math.sqrt(o.x*o.x+o.z*o.z),l=Math.atan2(o.y,h);return this.rotationQuaternion?T.Quaternion.RotationYawPitchRollToRef(a+t,l+i,r,this.rotationQuaternion):(this.rotation.x=l+i,this.rotation.y=a+t,this.rotation.z=r),this},t.prototype.getDirection=function(e){var t=T.Vector3.Zero();return this.getDirectionToRef(e,t),t},t.prototype.getDirectionToRef=function(e,t){return T.Vector3.TransformNormalToRef(e,this.getWorldMatrix(),t),this},t.prototype.setPivotPoint=function(e,t){void 0===t&&(t=T.Space.LOCAL),0==this.getScene().getRenderId()&&this.computeWorldMatrix(!0);var i=this.getWorldMatrix();if(t==T.Space.WORLD){var r=T.Tmp.Matrix[0];i.invertToRef(r),e=T.Vector3.TransformCoordinates(e,r)}return T.Vector3.TransformCoordinatesToRef(e,i,this.position),this._pivotMatrix.m[12]=-e.x,this._pivotMatrix.m[13]=-e.y,this._pivotMatrix.m[14]=-e.z,this._cache.pivotMatrixUpdated=!0,this},t.prototype.getPivotPoint=function(){var e=T.Vector3.Zero();return this.getPivotPointToRef(e),e},t.prototype.getPivotPointToRef=function(e){return e.x=-this._pivotMatrix.m[12],e.y=-this._pivotMatrix.m[13],e.z=-this._pivotMatrix.m[14],this},t.prototype.getAbsolutePivotPoint=function(){var e=T.Vector3.Zero();return this.getAbsolutePivotPointToRef(e),e},t.prototype.getAbsolutePivotPointToRef=function(e){return e.x=this._pivotMatrix.m[12],e.y=this._pivotMatrix.m[13],e.z=this._pivotMatrix.m[14],this.getPivotPointToRef(e),T.Vector3.TransformCoordinatesToRef(e,this.getWorldMatrix(),e),this},t.prototype.setParent=function(e){if(null===e){var t=T.Tmp.Quaternion[0],i=T.Tmp.Vector3[0],r=T.Tmp.Vector3[1];this.parent&&this.parent.computeWorldMatrix&&this.parent.computeWorldMatrix(!0),this.computeWorldMatrix(!0),this.getWorldMatrix().decompose(r,t,i),this.rotationQuaternion?this.rotationQuaternion.copyFrom(t):t.toEulerAnglesToRef(this.rotation),this.scaling.x=r.x,this.scaling.y=r.y,this.scaling.z=r.z,this.position.x=i.x,this.position.y=i.y,this.position.z=i.z}else{t=T.Tmp.Quaternion[0],i=T.Tmp.Vector3[0],r=T.Tmp.Vector3[1];var n=T.Tmp.Matrix[0],o=T.Tmp.Matrix[1];this.computeWorldMatrix(!0),e.computeWorldMatrix(!0),e.getWorldMatrix().invertToRef(o),this.getWorldMatrix().multiplyToRef(o,n),n.decompose(r,t,i),this.rotationQuaternion?this.rotationQuaternion.copyFrom(t):t.toEulerAnglesToRef(this.rotation),this.position.x=i.x,this.position.y=i.y,this.position.z=i.z,this.scaling.x=r.x,this.scaling.y=r.y,this.scaling.z=r.z}return this.parent=e,this},Object.defineProperty(t.prototype,"nonUniformScaling",{get:function(){return this._nonUniformScaling},enumerable:!0,configurable:!0}),t.prototype._updateNonUniformScalingState=function(e){return this._nonUniformScaling!==e&&(this._nonUniformScaling=!0,!0)},t.prototype.attachToBone=function(e,t){return this._transformToBoneReferal=t,this.parent=e,e.getWorldMatrix().determinant()<0&&(this.scalingDeterminant*=-1),this},t.prototype.detachFromBone=function(){return this.parent?(this.parent.getWorldMatrix().determinant()<0&&(this.scalingDeterminant*=-1),this._transformToBoneReferal=null,this.parent=null,this):this},t.prototype.rotate=function(e,t,i){var r;if(e.normalize(),this.rotationQuaternion||(this.rotationQuaternion=T.Quaternion.RotationYawPitchRoll(this.rotation.y,this.rotation.x,this.rotation.z),this.rotation=T.Vector3.Zero()),i&&i!==T.Space.LOCAL){if(this.parent){var n=this.parent.getWorldMatrix().clone();n.invert(),e=T.Vector3.TransformNormal(e,n)}(r=T.Quaternion.RotationAxisToRef(e,t,T.AbstractMesh._rotationAxisCache)).multiplyToRef(this.rotationQuaternion,this.rotationQuaternion)}else r=T.Quaternion.RotationAxisToRef(e,t,T.AbstractMesh._rotationAxisCache),this.rotationQuaternion.multiplyToRef(r,this.rotationQuaternion);return this},t.prototype.rotateAround=function(e,t,i){return t.normalize(),this.rotationQuaternion||(this.rotationQuaternion=T.Quaternion.RotationYawPitchRoll(this.rotation.y,this.rotation.x,this.rotation.z),this.rotation.copyFromFloats(0,0,0)),e.subtractToRef(this.position,T.Tmp.Vector3[0]),T.Matrix.TranslationToRef(T.Tmp.Vector3[0].x,T.Tmp.Vector3[0].y,T.Tmp.Vector3[0].z,T.Tmp.Matrix[0]),T.Tmp.Matrix[0].invertToRef(T.Tmp.Matrix[2]),T.Matrix.RotationAxisToRef(t,i,T.Tmp.Matrix[1]),T.Tmp.Matrix[2].multiplyToRef(T.Tmp.Matrix[1],T.Tmp.Matrix[2]),T.Tmp.Matrix[2].multiplyToRef(T.Tmp.Matrix[0],T.Tmp.Matrix[2]),T.Tmp.Matrix[2].decompose(T.Tmp.Vector3[0],T.Tmp.Quaternion[0],T.Tmp.Vector3[1]),this.position.addInPlace(T.Tmp.Vector3[1]),T.Tmp.Quaternion[0].multiplyToRef(this.rotationQuaternion,this.rotationQuaternion),this},t.prototype.translate=function(e,t,i){var r=e.scale(t);if(i&&i!==T.Space.LOCAL)this.setAbsolutePosition(this.getAbsolutePosition().add(r));else{var n=this.getPositionExpressedInLocalSpace().add(r);this.setPositionWithLocalVector(n)}return this},t.prototype.addRotation=function(e,t,i){var r;this.rotationQuaternion?r=this.rotationQuaternion:(r=T.Tmp.Quaternion[1],T.Quaternion.RotationYawPitchRollToRef(this.rotation.y,this.rotation.x,this.rotation.z,r));var n=T.Tmp.Quaternion[0];return T.Quaternion.RotationYawPitchRollToRef(t,e,i,n),r.multiplyInPlace(n),this.rotationQuaternion||r.toEulerAnglesToRef(this.rotation),this},t.prototype.computeWorldMatrix=function(e){if(this._isWorldMatrixFrozen)return this._worldMatrix;if(!e&&this.isSynchronized(!0))return this._worldMatrix;(this._cache.position.copyFrom(this.position),this._cache.scaling.copyFrom(this.scaling),this._cache.pivotMatrixUpdated=!1,this._cache.billboardMode=this.billboardMode,this._currentRenderId=this.getScene().getRenderId(),this._isDirty=!1,T.Matrix.ScalingToRef(this.scaling.x*this.scalingDeterminant,this.scaling.y*this.scalingDeterminant,this.scaling.z*this.scalingDeterminant,T.Tmp.Matrix[1]),this.rotationQuaternion)&&(this.rotation.length()&&(this.rotationQuaternion.multiplyInPlace(T.Quaternion.RotationYawPitchRoll(this.rotation.y,this.rotation.x,this.rotation.z)),this.rotation.copyFromFloats(0,0,0)));this.rotationQuaternion?(this.rotationQuaternion.toRotationMatrix(T.Tmp.Matrix[0]),this._cache.rotationQuaternion.copyFrom(this.rotationQuaternion)):(T.Matrix.RotationYawPitchRollToRef(this.rotation.y,this.rotation.x,this.rotation.z,T.Tmp.Matrix[0]),this._cache.rotation.copyFrom(this.rotation));var t=this.getScene().activeCamera;if(this.infiniteDistance&&!this.parent&&t){var i=t.getWorldMatrix(),r=new T.Vector3(i.m[12],i.m[13],i.m[14]);T.Matrix.TranslationToRef(this.position.x+r.x,this.position.y+r.y,this.position.z+r.z,T.Tmp.Matrix[2])}else T.Matrix.TranslationToRef(this.position.x,this.position.y,this.position.z,T.Tmp.Matrix[2]);if(this._pivotMatrix.multiplyToRef(T.Tmp.Matrix[1],T.Tmp.Matrix[4]),T.Tmp.Matrix[4].multiplyToRef(T.Tmp.Matrix[0],T.Tmp.Matrix[5]),this.billboardMode!==T.AbstractMesh.BILLBOARDMODE_NONE&&t){if((this.billboardMode&T.AbstractMesh.BILLBOARDMODE_ALL)!==T.AbstractMesh.BILLBOARDMODE_ALL){var n=T.Tmp.Vector3[3];this.parent&&this.parent.getWorldMatrix?this._transformToBoneReferal?(this.parent.getWorldMatrix().multiplyToRef(this._transformToBoneReferal.getWorldMatrix(),T.Tmp.Matrix[6]),T.Vector3.TransformCoordinatesToRef(this.position,T.Tmp.Matrix[6],n)):T.Vector3.TransformCoordinatesToRef(this.position,this.parent.getWorldMatrix(),n):n.copyFrom(this.position),n.subtractInPlace(t.globalPosition);var o=T.Tmp.Vector3[4].copyFromFloats(0,0,0);(this.billboardMode&T.AbstractMesh.BILLBOARDMODE_X)===T.AbstractMesh.BILLBOARDMODE_X&&(o.x=Math.atan2(-n.y,n.z)),(this.billboardMode&T.AbstractMesh.BILLBOARDMODE_Y)===T.AbstractMesh.BILLBOARDMODE_Y&&(o.y=Math.atan2(n.x,n.z)),(this.billboardMode&T.AbstractMesh.BILLBOARDMODE_Z)===T.AbstractMesh.BILLBOARDMODE_Z&&(o.z=Math.atan2(n.y,n.x)),T.Matrix.RotationYawPitchRollToRef(o.y,o.x,o.z,T.Tmp.Matrix[0])}else T.Tmp.Matrix[1].copyFrom(t.getViewMatrix()),T.Tmp.Matrix[1].setTranslationFromFloats(0,0,0),T.Tmp.Matrix[1].invertToRef(T.Tmp.Matrix[0]);T.Tmp.Matrix[1].copyFrom(T.Tmp.Matrix[5]),T.Tmp.Matrix[1].multiplyToRef(T.Tmp.Matrix[0],T.Tmp.Matrix[5])}return T.Tmp.Matrix[5].multiplyToRef(T.Tmp.Matrix[2],this._localWorld),this.parent&&this.parent.getWorldMatrix?(this.billboardMode!==T.AbstractMesh.BILLBOARDMODE_NONE?(this._transformToBoneReferal?(this.parent.getWorldMatrix().multiplyToRef(this._transformToBoneReferal.getWorldMatrix(),T.Tmp.Matrix[6]),T.Tmp.Matrix[5].copyFrom(T.Tmp.Matrix[6])):T.Tmp.Matrix[5].copyFrom(this.parent.getWorldMatrix()),this._localWorld.getTranslationToRef(T.Tmp.Vector3[5]),T.Vector3.TransformCoordinatesToRef(T.Tmp.Vector3[5],T.Tmp.Matrix[5],T.Tmp.Vector3[5]),this._worldMatrix.copyFrom(this._localWorld),this._worldMatrix.setTranslation(T.Tmp.Vector3[5])):this._transformToBoneReferal?(this._localWorld.multiplyToRef(this.parent.getWorldMatrix(),T.Tmp.Matrix[6]),T.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=T.Matrix.Invert(this._worldMatrix)),this._worldMatrixDeterminant=this._worldMatrix.determinant(),this._worldMatrix},t.prototype._afterComputeWorldMatrix=function(){},t.prototype.registerAfterWorldMatrixUpdate=function(e){return this.onAfterWorldMatrixUpdateObservable.add(e),this},t.prototype.unregisterAfterWorldMatrixUpdate=function(e){return this.onAfterWorldMatrixUpdateObservable.removeCallback(e),this},t.prototype.clone=function(e,i,r){var n=this,o=T.SerializationHelper.Clone(function(){return new t(e,n.getScene())},this);if(o.name=e,o.id=e,i&&(o.parent=i),!r)for(var s=this.getDescendants(!0),a=0;a<s.length;a++){var h=s[a];h.clone&&h.clone(e+"."+h.name,o)}return o},t.prototype.serialize=function(e){var t=T.SerializationHelper.Serialize(this,e);return t.type=this.getClassName(),this.parent&&(t.parentId=this.parent.id),T.Tags&&T.Tags.HasTags(this)&&(t.tags=T.Tags.GetTags(this)),t.localMatrix=this.getPivotMatrix().asArray(),t.isEnabled=this.isEnabled(),this.parent&&(t.parentId=this.parent.id),t},t.Parse=function(e,i,r){var n=T.SerializationHelper.Parse(function(){return new t(e.name,i)},e,i,r);return T.Tags&&T.Tags.AddTagsTo(n,e.tags),e.localMatrix?n.setPivotMatrix(T.Matrix.FromArray(e.localMatrix)):e.pivotMatrix&&n.setPivotMatrix(T.Matrix.FromArray(e.pivotMatrix)),n.setEnabled(e.isEnabled),e.parentId&&(n._waitingParentId=e.parentId),n},t.prototype.dispose=function(t){if(this.getScene().stopAnimation(this),this.getScene().removeTransformNode(this),t){var i=this.getChildMeshes(!0);for(o=0;o<i.length;o++){var r=i[o];r.parent=null,r.computeWorldMatrix(!0)}}else for(var n=this.getDescendants(!0),o=0;o<n.length;o++)n[o].dispose();this.onAfterWorldMatrixUpdateObservable.clear(),e.prototype.dispose.call(this)},t.BILLBOARDMODE_NONE=0,t.BILLBOARDMODE_X=1,t.BILLBOARDMODE_Y=2,t.BILLBOARDMODE_Z=4,t.BILLBOARDMODE_ALL=7,t._lookAtVectorCache=new T.Vector3(0,0,0),t._rotationAxisCache=new T.Quaternion,X([T.serializeAsVector3()],t.prototype,"_rotation",void 0),X([T.serializeAsQuaternion()],t.prototype,"_rotationQuaternion",void 0),X([T.serializeAsVector3()],t.prototype,"_scaling",void 0),X([T.serialize()],t.prototype,"billboardMode",void 0),X([T.serialize()],t.prototype,"scalingDeterminant",void 0),X([T.serialize()],t.prototype,"infiniteDistance",void 0),X([T.serializeAsVector3()],t.prototype,"position",void 0),t}(T.Node),T.TransformNode=E,A=us||(us={}),P=function(e){function t(i,r){void 0===r&&(r=null);var n=e.call(this,i,r,!1)||this;return n._facetNb=0,n._partitioningSubdivisions=10,n._partitioningBBoxRatio=1.01,n._facetDataEnabled=!1,n._facetParameters={},n._bbSize=A.Vector3.Zero(),n._subDiv={max:1,X:1,Y:1,Z:1},n._facetDepthSort=!1,n._facetDepthSortEnabled=!1,n.onCollideObservable=new A.Observable,n.onCollisionPositionChangeObservable=new A.Observable,n.onMaterialChangedObservable=new A.Observable,n.definedFacingForward=!0,n.occlusionQueryAlgorithmType=t.OCCLUSION_ALGORITHM_TYPE_CONSERVATIVE,n.occlusionType=t.OCCLUSION_TYPE_NONE,n.occlusionRetryCount=-1,n._occlusionInternalRetryCounter=0,n._isOccluded=!1,n._isOcclusionQueryInProgress=!1,n.visibility=1,n.alphaIndex=Number.MAX_VALUE,n.isVisible=!0,n.isPickable=!0,n.showBoundingBox=!1,n.showSubMeshesBoundingBox=!1,n.isBlocker=!1,n.enablePointerMoveEvents=!1,n.renderingGroupId=0,n._receiveShadows=!1,n.renderOutline=!1,n.outlineColor=A.Color3.Red(),n.outlineWidth=.02,n.renderOverlay=!1,n.overlayColor=A.Color3.Red(),n.overlayAlpha=.5,n._hasVertexAlpha=!1,n._useVertexColors=!0,n._computeBonesUsingShaders=!0,n._numBoneInfluencers=4,n._applyFog=!0,n.useOctreeForRenderingSelection=!0,n.useOctreeForPicking=!0,n.useOctreeForCollisions=!0,n._layerMask=268435455,n.alwaysSelectAsActiveMesh=!1,n.actionManager=null,n.physicsImpostor=null,n._checkCollisions=!1,n._collisionMask=-1,n._collisionGroup=-1,n.ellipsoid=new A.Vector3(.5,1,.5),n.ellipsoidOffset=new A.Vector3(0,0,0),n._oldPositionForCollisions=new A.Vector3(0,0,0),n._diffPositionForCollisions=new A.Vector3(0,0,0),n.edgesWidth=1,n.edgesColor=new A.Color4(1,0,0,1),n._collisionsTransformMatrix=A.Matrix.Zero(),n._collisionsScalingMatrix=A.Matrix.Zero(),n._isDisposed=!1,n._renderId=0,n._intersectionsInProgress=new Array,n._unIndexed=!1,n._lightSources=new Array,n._onCollisionPositionChange=function(e,t,i){void 0===i&&(i=null),n.getScene().workerCollisions&&t.multiplyInPlace(n._collider._radius),t.subtractToRef(n._oldPositionForCollisions,n._diffPositionForCollisions),n._diffPositionForCollisions.length()>A.Engine.CollisionsEpsilon&&n.position.addInPlace(n._diffPositionForCollisions),i&&n.onCollideObservable.notifyObservers(i),n.onCollisionPositionChangeObservable.notifyObservers(n.position)},n.getScene().addMesh(n),n._resyncLightSources(),n}return Y(t,e),Object.defineProperty(t,"BILLBOARDMODE_NONE",{get:function(){return A.TransformNode.BILLBOARDMODE_NONE},enumerable:!0,configurable:!0}),Object.defineProperty(t,"BILLBOARDMODE_X",{get:function(){return A.TransformNode.BILLBOARDMODE_X},enumerable:!0,configurable:!0}),Object.defineProperty(t,"BILLBOARDMODE_Y",{get:function(){return A.TransformNode.BILLBOARDMODE_Y},enumerable:!0,configurable:!0}),Object.defineProperty(t,"BILLBOARDMODE_Z",{get:function(){return A.TransformNode.BILLBOARDMODE_Z},enumerable:!0,configurable:!0}),Object.defineProperty(t,"BILLBOARDMODE_ALL",{get:function(){return A.TransformNode.BILLBOARDMODE_ALL},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"facetNb",{get:function(){return this._facetNb},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"partitioningSubdivisions",{get:function(){return this._partitioningSubdivisions},set:function(e){this._partitioningSubdivisions=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"partitioningBBoxRatio",{get:function(){return this._partitioningBBoxRatio},set:function(e){this._partitioningBBoxRatio=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"mustDepthSortFacets",{get:function(){return this._facetDepthSort},set:function(e){this._facetDepthSort=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"facetDepthSortFrom",{get:function(){return this._facetDepthSortFrom},set:function(e){this._facetDepthSortFrom=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isFacetDataEnabled",{get:function(){return this._facetDataEnabled},enumerable:!0,configurable:!0}),t.prototype._updateNonUniformScalingState=function(t){return!!e.prototype._updateNonUniformScalingState.call(this,t)&&(this._markSubMeshesAsMiscDirty(),!0)},Object.defineProperty(t.prototype,"onCollide",{set:function(e){this._onCollideObserver&&this.onCollideObservable.remove(this._onCollideObserver),this._onCollideObserver=this.onCollideObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"onCollisionPositionChange",{set:function(e){this._onCollisionPositionChangeObserver&&this.onCollisionPositionChangeObservable.remove(this._onCollisionPositionChangeObserver),this._onCollisionPositionChangeObserver=this.onCollisionPositionChangeObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isOccluded",{get:function(){return this._isOccluded},set:function(e){this._isOccluded=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isOcclusionQueryInProgress",{get:function(){return this._isOcclusionQueryInProgress},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"material",{get:function(){return this._material},set:function(e){if(this._material!==e&&(this._material=e,this.onMaterialChangedObservable.hasObservers&&this.onMaterialChangedObservable.notifyObservers(this),this.subMeshes))for(var t=0,i=this.subMeshes;t<i.length;t++){i[t].setEffect(null)}},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"receiveShadows",{get:function(){return this._receiveShadows},set:function(e){this._receiveShadows!==e&&(this._receiveShadows=e,this._markSubMeshesAsLightDirty())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"hasVertexAlpha",{get:function(){return this._hasVertexAlpha},set:function(e){this._hasVertexAlpha!==e&&(this._hasVertexAlpha=e,this._markSubMeshesAsAttributesDirty())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"useVertexColors",{get:function(){return this._useVertexColors},set:function(e){this._useVertexColors!==e&&(this._useVertexColors=e,this._markSubMeshesAsAttributesDirty())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"computeBonesUsingShaders",{get:function(){return this._computeBonesUsingShaders},set:function(e){this._computeBonesUsingShaders!==e&&(this._computeBonesUsingShaders=e,this._markSubMeshesAsAttributesDirty())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"numBoneInfluencers",{get:function(){return this._numBoneInfluencers},set:function(e){this._numBoneInfluencers!==e&&(this._numBoneInfluencers=e,this._markSubMeshesAsAttributesDirty())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"applyFog",{get:function(){return this._applyFog},set:function(e){this._applyFog!==e&&(this._applyFog=e,this._markSubMeshesAsMiscDirty())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"layerMask",{get:function(){return this._layerMask},set:function(e){e!==this._layerMask&&(this._layerMask=e,this._resyncLightSources())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"collisionMask",{get:function(){return this._collisionMask},set:function(e){this._collisionMask=isNaN(e)?-1:e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"collisionGroup",{get:function(){return this._collisionGroup},set:function(e){this._collisionGroup=isNaN(e)?-1:e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"_positions",{get:function(){return null},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"skeleton",{get:function(){return this._skeleton},set:function(e){this._skeleton&&this._skeleton.needInitialSkinMatrix&&this._skeleton._unregisterMeshWithPoseMatrix(this),e&&e.needInitialSkinMatrix&&e._registerMeshWithPoseMatrix(this),this._skeleton=e,this._skeleton||(this._bonesTransformMatrices=null),this._markSubMeshesAsAttributesDirty()},enumerable:!0,configurable:!0}),t.prototype.isDisposed=function(){return this._isDisposed},t.prototype.getClassName=function(){return"AbstractMesh"},t.prototype.toString=function(e){var t="Name: "+this.name+", isInstance: "+(this instanceof A.InstancedMesh?"YES":"NO");return t+=", # of submeshes: "+(this.subMeshes?this.subMeshes.length:0),this._skeleton&&(t+=", skeleton: "+this._skeleton.name),e&&(t+=", billboard mode: "+["NONE","X","Y",null,"Z",null,null,"ALL"][this.billboardMode],t+=", freeze wrld mat: "+(this._isWorldMatrixFrozen||this._waitingFreezeWorldMatrix?"YES":"NO")),t},t.prototype._rebuild=function(){if(this._occlusionQuery&&(this._occlusionQuery=null),this._edgesRenderer&&this._edgesRenderer._rebuild(),this.subMeshes)for(var e=0,t=this.subMeshes;e<t.length;e++){t[e]._rebuild()}},t.prototype._resyncLightSources=function(){this._lightSources.length=0;for(var e=0,t=this.getScene().lights;e<t.length;e++){var i=t[e];i.isEnabled()&&(i.canAffectMesh(this)&&this._lightSources.push(i))}this._markSubMeshesAsLightDirty()},t.prototype._resyncLighSource=function(e){var t=e.isEnabled()&&e.canAffectMesh(this),i=this._lightSources.indexOf(e);if(-1===i){if(!t)return;this._lightSources.push(e)}else{if(t)return;this._lightSources.splice(i,1)}this._markSubMeshesAsLightDirty()},t.prototype._removeLightSource=function(e){var t=this._lightSources.indexOf(e);-1!==t&&this._lightSources.splice(t,1)},t.prototype._markSubMeshesAsDirty=function(e){if(this.subMeshes)for(var t=0,i=this.subMeshes;t<i.length;t++){var r=i[t];r._materialDefines&&e(r._materialDefines)}},t.prototype._markSubMeshesAsLightDirty=function(){this._markSubMeshesAsDirty(function(e){return e.markAsLightDirty()})},t.prototype._markSubMeshesAsAttributesDirty=function(){this._markSubMeshesAsDirty(function(e){return e.markAsAttributesDirty()})},t.prototype._markSubMeshesAsMiscDirty=function(){if(this.subMeshes)for(var e=0,t=this.subMeshes;e<t.length;e++){var i=t[e].getMaterial();i&&i.markAsDirty(A.Material.MiscDirtyFlag)}},Object.defineProperty(t.prototype,"scaling",{get:function(){return this._scaling},set:function(e){this._scaling=e,this.physicsImpostor&&this.physicsImpostor.forceUpdate()},enumerable:!0,configurable:!0}),t.prototype.disableEdgesRendering=function(){return this._edgesRenderer&&(this._edgesRenderer.dispose(),this._edgesRenderer=null),this},t.prototype.enableEdgesRendering=function(e,t){return void 0===e&&(e=.95),void 0===t&&(t=!1),this.disableEdgesRendering(),this._edgesRenderer=new A.EdgesRenderer(this,e,t),this},Object.defineProperty(t.prototype,"isBlocked",{get:function(){return!1},enumerable:!0,configurable:!0}),t.prototype.getLOD=function(e){return this},t.prototype.getTotalVertices=function(){return 0},t.prototype.getIndices=function(){return null},t.prototype.getVerticesData=function(e){return null},t.prototype.setVerticesData=function(e,t,i,r){return this},t.prototype.updateVerticesData=function(e,t,i,r){return this},t.prototype.setIndices=function(e,t){return this},t.prototype.isVerticesDataPresent=function(e){return!1},t.prototype.getBoundingInfo=function(){return this._masterMesh?this._masterMesh.getBoundingInfo():(this._boundingInfo||this._updateBoundingInfo(),this._boundingInfo)},t.prototype.normalizeToUnitCube=function(e){void 0===e&&(e=!0);var t=this.getHierarchyBoundingVectors(e),i=t.max.subtract(t.min),r=Math.max(i.x,i.y,i.z);if(0===r)return this;var n=1/r;return this.scaling.scaleInPlace(n),this},t.prototype.setBoundingInfo=function(e){return this._boundingInfo=e,this},Object.defineProperty(t.prototype,"useBones",{get:function(){return this.skeleton&&this.getScene().skeletonsEnabled&&this.isVerticesDataPresent(A.VertexBuffer.MatricesIndicesKind)&&this.isVerticesDataPresent(A.VertexBuffer.MatricesWeightsKind)},enumerable:!0,configurable:!0}),t.prototype._preActivate=function(){},t.prototype._preActivateForIntermediateRendering=function(e){},t.prototype._activate=function(e){this._renderId=e},t.prototype.getWorldMatrix=function(){return this._masterMesh?this._masterMesh.getWorldMatrix():e.prototype.getWorldMatrix.call(this)},t.prototype._getWorldMatrixDeterminant=function(){return this._masterMesh?this._masterMesh._getWorldMatrixDeterminant():e.prototype._getWorldMatrixDeterminant.call(this)},t.prototype.movePOV=function(e,t,i){return this.position.addInPlace(this.calcMovePOV(e,t,i)),this},t.prototype.calcMovePOV=function(e,t,i){var r=new A.Matrix;(this.rotationQuaternion?this.rotationQuaternion:A.Quaternion.RotationYawPitchRoll(this.rotation.y,this.rotation.x,this.rotation.z)).toRotationMatrix(r);var n=A.Vector3.Zero(),o=this.definedFacingForward?-1:1;return A.Vector3.TransformCoordinatesFromFloatsToRef(e*o,t,i*o,r,n),n},t.prototype.rotatePOV=function(e,t,i){return this.rotation.addInPlace(this.calcRotatePOV(e,t,i)),this},t.prototype.calcRotatePOV=function(e,t,i){var r=this.definedFacingForward?1:-1;return new A.Vector3(e*r,t,i*r)},t.prototype.getHierarchyBoundingVectors=function(e){var t,i;void 0===e&&(e=!0),this.computeWorldMatrix(!0);var r=this.getBoundingInfo();if(this.subMeshes?(t=r.boundingBox.minimumWorld,i=r.boundingBox.maximumWorld):(t=new A.Vector3(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),i=new A.Vector3(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE)),e)for(var n=0,o=this.getDescendants(!1);n<o.length;n++){var s=o[n];if(s.computeWorldMatrix(!0),s.getBoundingInfo&&0!==s.getTotalVertices()){var a=s.getBoundingInfo().boundingBox,h=a.minimumWorld,l=a.maximumWorld;A.Tools.CheckExtends(h,t,i),A.Tools.CheckExtends(l,t,i)}}return{min:t,max:i}},t.prototype._updateBoundingInfo=function(){return this._boundingInfo=this._boundingInfo||new A.BoundingInfo(this.absolutePosition,this.absolutePosition),this._boundingInfo.update(this.worldMatrixFromCache),this._updateSubMeshesBoundingInfo(this.worldMatrixFromCache),this},t.prototype._updateSubMeshesBoundingInfo=function(e){if(!this.subMeshes)return this;for(var t=0;t<this.subMeshes.length;t++){var i=this.subMeshes[t];i.IsGlobal||i.updateBoundingInfo(e)}return this},t.prototype._afterComputeWorldMatrix=function(){this._updateBoundingInfo()},t.prototype.isInFrustum=function(e){return null!==this._boundingInfo&&this._boundingInfo.isInFrustum(e)},t.prototype.isCompletelyInFrustum=function(e){return null!==this._boundingInfo&&this._boundingInfo.isCompletelyInFrustum(e)},t.prototype.intersectsMesh=function(e,t,i){if(void 0===t&&(t=!1),!this._boundingInfo||!e._boundingInfo)return!1;if(this._boundingInfo.intersects(e._boundingInfo,t))return!0;if(i)for(var r=0,n=this.getChildMeshes();r<n.length;r++){if(n[r].intersectsMesh(e,t,!0))return!0}return!1},t.prototype.intersectsPoint=function(e){return!!this._boundingInfo&&this._boundingInfo.intersectsPoint(e)},t.prototype.getPhysicsImpostor=function(){return this.physicsImpostor},t.prototype.getPositionInCameraSpace=function(e){return void 0===e&&(e=null),e||(e=this.getScene().activeCamera),A.Vector3.TransformCoordinates(this.absolutePosition,e.getViewMatrix())},t.prototype.getDistanceToCamera=function(e){return void 0===e&&(e=null),e||(e=this.getScene().activeCamera),this.absolutePosition.subtract(e.position).length()},t.prototype.applyImpulse=function(e,t){return this.physicsImpostor?(this.physicsImpostor.applyImpulse(e,t),this):this},t.prototype.setPhysicsLinkWith=function(e,t,i,r){return this.physicsImpostor&&e.physicsImpostor?(this.physicsImpostor.createJoint(e.physicsImpostor,A.PhysicsJoint.HingeJoint,{mainPivot:t,connectedPivot:i,nativeParams:r}),this):this},Object.defineProperty(t.prototype,"checkCollisions",{get:function(){return this._checkCollisions},set:function(e){this._checkCollisions=e,this.getScene().workerCollisions&&this.getScene().collisionCoordinator.onMeshUpdated(this)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"collider",{get:function(){return this._collider},enumerable:!0,configurable:!0}),t.prototype.moveWithCollisions=function(e){return this.getAbsolutePosition().addToRef(this.ellipsoidOffset,this._oldPositionForCollisions),this._collider||(this._collider=new A.Collider),this._collider._radius=this.ellipsoid,this.getScene().collisionCoordinator.getNewPosition(this._oldPositionForCollisions,e,this._collider,3,this,this._onCollisionPositionChange,this.uniqueId),this},t.prototype.createOrUpdateSubmeshesOctree=function(e,t){void 0===e&&(e=64),void 0===t&&(t=2),this._submeshesOctree||(this._submeshesOctree=new A.Octree(A.Octree.CreationFuncForSubMeshes,e,t)),this.computeWorldMatrix(!0);var i=this.getBoundingInfo().boundingBox;return this._submeshesOctree.update(i.minimumWorld,i.maximumWorld,this.subMeshes),this._submeshesOctree},t.prototype._collideForSubMesh=function(e,t,i){if(this._generatePointsArray(),!this._positions)return this;if(!e._lastColliderWorldVertices||!e._lastColliderTransformMatrix.equals(t)){e._lastColliderTransformMatrix=t.clone(),e._lastColliderWorldVertices=[],e._trianglePlanes=[];for(var r=e.verticesStart,n=e.verticesStart+e.verticesCount,o=r;o<n;o++)e._lastColliderWorldVertices.push(A.Vector3.TransformCoordinates(this._positions[o],t))}return i._collide(e._trianglePlanes,e._lastColliderWorldVertices,this.getIndices(),e.indexStart,e.indexStart+e.indexCount,e.verticesStart,!!e.getMaterial()),i.collisionFound&&(i.collidedMesh=this),this},t.prototype._processCollisionsForSubMeshes=function(e,t){var i,r;if(this._submeshesOctree&&this.useOctreeForCollisions){var n=e._velocityWorldLength+Math.max(e._radius.x,e._radius.y,e._radius.z),o=this._submeshesOctree.intersects(e._basePointWorld,n);r=o.length,i=o.data}else r=(i=this.subMeshes).length;for(var s=0;s<r;s++){var a=i[s];r>1&&!a._checkCollision(e)||this._collideForSubMesh(a,t,e)}return this},t.prototype._checkCollision=function(e){return this._boundingInfo&&this._boundingInfo._checkCollision(e)?(A.Matrix.ScalingToRef(1/e._radius.x,1/e._radius.y,1/e._radius.z,this._collisionsScalingMatrix),this.worldMatrixFromCache.multiplyToRef(this._collisionsScalingMatrix,this._collisionsTransformMatrix),this._processCollisionsForSubMeshes(e,this._collisionsTransformMatrix),this):this},t.prototype._generatePointsArray=function(){return!1},t.prototype.intersects=function(e,t){var i=new A.PickingInfo;if(!(this.subMeshes&&this._boundingInfo&&e.intersectsSphere(this._boundingInfo.boundingSphere)&&e.intersectsBox(this._boundingInfo.boundingBox)))return i;if(!this._generatePointsArray())return i;var r,n,o=null;if(this._submeshesOctree&&this.useOctreeForPicking){var s=A.Ray.Transform(e,this.getWorldMatrix()),a=this._submeshesOctree.intersectsRay(s);n=a.length,r=a.data}else n=(r=this.subMeshes).length;for(var h=0;h<n;h++){var l=r[h];if(!(n>1)||l.canIntersects(e)){var c=l.intersects(e,this._positions,this.getIndices(),t);if(c&&(t||!o||c.distance<o.distance)&&((o=c).subMeshId=h,t))break}}if(o){var u=this.getWorldMatrix(),p=A.Vector3.TransformCoordinates(e.origin,u),f=e.direction.clone();f=f.scale(o.distance);var d=A.Vector3.TransformNormal(f,u),m=p.add(d);return i.hit=!0,i.distance=A.Vector3.Distance(p,m),i.pickedPoint=m,i.pickedMesh=this,i.bu=o.bu||0,i.bv=o.bv||0,i.faceId=o.faceId,i.subMeshId=o.subMeshId,i}return i},t.prototype.clone=function(e,t,i){return null},t.prototype.releaseSubMeshes=function(){if(this.subMeshes)for(;this.subMeshes.length;)this.subMeshes[0].dispose();else this.subMeshes=new Array;return this},t.prototype.dispose=function(t,i){var r=this;for(void 0===i&&(i=!1),void 0!==this.actionManager&&null!==this.actionManager&&(this.actionManager.dispose(),this.actionManager=null),this.skeleton=null,this.physicsImpostor&&this.physicsImpostor.dispose(),s=0;s<this._intersectionsInProgress.length;s++){var n=this._intersectionsInProgress[s],o=n._intersectionsInProgress.indexOf(this);n._intersectionsInProgress.splice(o,1)}this._intersectionsInProgress=[],this.getScene().lights.forEach(function(e){var t=e.includedOnlyMeshes.indexOf(r);-1!==t&&e.includedOnlyMeshes.splice(t,1),-1!==(t=e.excludedMeshes.indexOf(r))&&e.excludedMeshes.splice(t,1);var i=e.getShadowGenerator();if(i){var n=i.getShadowMap();n&&n.renderList&&-1!==(t=n.renderList.indexOf(r))&&n.renderList.splice(t,1)}}),this._edgesRenderer&&(this._edgesRenderer.dispose(),this._edgesRenderer=null),"InstancedMesh"!==this.getClassName()&&this.releaseSubMeshes();var s,a=this.getScene().selectionOctree;void 0!==a&&null!==a&&(-1!==(s=a.dynamicContent.indexOf(this))&&a.dynamicContent.splice(s,1));var h=this.getScene().getEngine();if(this._occlusionQuery&&(this._isOcclusionQueryInProgress=!1,h.deleteQuery(this._occlusionQuery),this._occlusionQuery=null),h.wipeCaches(),this.getScene().removeMesh(this),i&&this.material&&this.material.dispose(!1,!0),!t)for(s=0;s<this.getScene().particleSystems.length;s++)this.getScene().particleSystems[s].emitter===this&&(this.getScene().particleSystems[s].dispose(),s--);this._facetDataEnabled&&this.disableFacetData(),this.onAfterWorldMatrixUpdateObservable.clear(),this.onCollideObservable.clear(),this.onCollisionPositionChangeObservable.clear(),this._isDisposed=!0,e.prototype.dispose.call(this,t)},t.prototype.addChild=function(e){return e.setParent(this),this},t.prototype.removeChild=function(e){return e.setParent(null),this},t.prototype._initFacetData=function(){this._facetNormals||(this._facetNormals=new Array),this._facetPositions||(this._facetPositions=new Array),this._facetPartitioning||(this._facetPartitioning=new Array),this._facetNb=this.getIndices().length/3|0,this._partitioningSubdivisions=this._partitioningSubdivisions?this._partitioningSubdivisions:10,this._partitioningBBoxRatio=this._partitioningBBoxRatio?this._partitioningBBoxRatio:1.01;for(var e=0;e<this._facetNb;e++)this._facetNormals[e]=A.Vector3.Zero(),this._facetPositions[e]=A.Vector3.Zero();return this._facetDataEnabled=!0,this},t.prototype.updateFacetData=function(){this._facetDataEnabled||this._initFacetData();var e=this.getVerticesData(A.VertexBuffer.PositionKind),t=this.getIndices(),i=this.getVerticesData(A.VertexBuffer.NormalKind),r=this.getBoundingInfo();if(this._facetDepthSort&&!this._facetDepthSortEnabled){if(this._facetDepthSortEnabled=!0,t instanceof Uint16Array)this._depthSortedIndices=new Uint16Array(t);else if(t instanceof Uint32Array)this._depthSortedIndices=new Uint32Array(t);else{for(var n=!1,o=0;o<t.length;o++)if(t[o]>65535){n=!0;break}this._depthSortedIndices=n?new Uint32Array(t):new Uint16Array(t)}if(this._facetDepthSortFunction=function(e,t){return t.sqDistance-e.sqDistance},!this._facetDepthSortFrom){var s=this.getScene().activeCamera;this._facetDepthSortFrom=s?s.position:A.Vector3.Zero()}this._depthSortedFacets=[];for(var a=0;a<this._facetNb;a++){var h={ind:3*a,sqDistance:0};this._depthSortedFacets.push(h)}this._invertedMatrix=A.Matrix.Identity(),this._facetDepthSortOrigin=A.Vector3.Zero()}this._bbSize.x=r.maximum.x-r.minimum.x>A.Epsilon?r.maximum.x-r.minimum.x:A.Epsilon,this._bbSize.y=r.maximum.y-r.minimum.y>A.Epsilon?r.maximum.y-r.minimum.y:A.Epsilon,this._bbSize.z=r.maximum.z-r.minimum.z>A.Epsilon?r.maximum.z-r.minimum.z:A.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=r,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),A.Vector3.TransformCoordinatesToRef(this._facetDepthSortFrom,this._invertedMatrix,this._facetDepthSortOrigin),this._facetParameters.distanceTo=this._facetDepthSortOrigin),this._facetParameters.depthSortedFacets=this._depthSortedFacets,A.VertexData.ComputeNormals(e,t,i,this._facetParameters),this._facetDepthSort&&this._facetDepthSortEnabled){this._depthSortedFacets.sort(this._facetDepthSortFunction);var c=this._depthSortedIndices.length/3|0;for(a=0;a<c;a++){var u=this._depthSortedFacets[a].ind;this._depthSortedIndices[3*a]=t[u],this._depthSortedIndices[3*a+1]=t[u+1],this._depthSortedIndices[3*a+2]=t[u+2]}this.updateIndices(this._depthSortedIndices)}return this},t.prototype.getFacetLocalNormals=function(){return this._facetNormals||this.updateFacetData(),this._facetNormals},t.prototype.getFacetLocalPositions=function(){return this._facetPositions||this.updateFacetData(),this._facetPositions},t.prototype.getFacetLocalPartitioning=function(){return this._facetPartitioning||this.updateFacetData(),this._facetPartitioning},t.prototype.getFacetPosition=function(e){var t=A.Vector3.Zero();return this.getFacetPositionToRef(e,t),t},t.prototype.getFacetPositionToRef=function(e,t){var i=this.getFacetLocalPositions()[e],r=this.getWorldMatrix();return A.Vector3.TransformCoordinatesToRef(i,r,t),this},t.prototype.getFacetNormal=function(e){var t=A.Vector3.Zero();return this.getFacetNormalToRef(e,t),t},t.prototype.getFacetNormalToRef=function(e,t){var i=this.getFacetLocalNormals()[e];return A.Vector3.TransformNormalToRef(i,this.getWorldMatrix(),t),this},t.prototype.getFacetsAtLocalCoordinates=function(e,t,i){var r=this.getBoundingInfo(),n=Math.floor((e-r.minimum.x*this._partitioningBBoxRatio)*this._subDiv.X*this._partitioningBBoxRatio/this._bbSize.x),o=Math.floor((t-r.minimum.y*this._partitioningBBoxRatio)*this._subDiv.Y*this._partitioningBBoxRatio/this._bbSize.y),s=Math.floor((i-r.minimum.z*this._partitioningBBoxRatio)*this._subDiv.Z*this._partitioningBBoxRatio/this._bbSize.z);return n<0||n>this._subDiv.max||o<0||o>this._subDiv.max||s<0||s>this._subDiv.max?null:this._facetPartitioning[n+this._subDiv.max*o+this._subDiv.max*this._subDiv.max*s]},t.prototype.getClosestFacetAtCoordinates=function(e,t,i,r,n,o){void 0===n&&(n=!1),void 0===o&&(o=!0);var s=this.getWorldMatrix(),a=A.Tmp.Matrix[5];s.invertToRef(a);var h=A.Tmp.Vector3[8];A.Vector3.TransformCoordinatesFromFloatsToRef(e,t,i,a,h);var l=this.getClosestFacetAtLocalCoordinates(h.x,h.y,h.z,r,n,o);return r&&A.Vector3.TransformCoordinatesFromFloatsToRef(r.x,r.y,r.z,s,r),l},t.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),p=e+y.x*u,f=t+y.y*u,d=i+y.z*u,(T=(a=p-e)*a+(h=f-t)*h+(l=d-i)*l)<x&&(x=T,s=v,r&&(r.x=p,r.y=f,r.z=d)));return s},t.prototype.getFacetDataParameters=function(){return this._facetParameters},t.prototype.disableFacetData=function(){return this._facetDataEnabled&&(this._facetDataEnabled=!1,this._facetPositions=new Array,this._facetNormals=new Array,this._facetPartitioning=new Array,this._facetParameters=null,this._depthSortedIndices=new Uint32Array(0)),this},t.prototype.updateIndices=function(e){return this},t.prototype.createNormals=function(e){var t,i=this.getVerticesData(A.VertexBuffer.PositionKind),r=this.getIndices();t=this.isVerticesDataPresent(A.VertexBuffer.NormalKind)?this.getVerticesData(A.VertexBuffer.NormalKind):[],A.VertexData.ComputeNormals(i,r,t,{useRightHandedSystem:this.getScene().useRightHandedSystem}),this.setVerticesData(A.VertexBuffer.NormalKind,t,e)},t.prototype.alignWithNormal=function(e,t){t||(t=A.Axis.Y);var i=A.Tmp.Vector3[0],r=A.Tmp.Vector3[1];return A.Vector3.CrossToRef(t,e,r),A.Vector3.CrossToRef(e,r,i),this.rotationQuaternion?A.Quaternion.RotationQuaternionFromAxisToRef(i,e,r,this.rotationQuaternion):A.Vector3.RotationFromAxisToRef(i,e,r,this.rotation),this},t.prototype.checkOcclusionQuery=function(){var e=this.getEngine();if(e.webGLVersion<2||this.occlusionType===t.OCCLUSION_TYPE_NONE)this._isOccluded=!1;else{if(this.isOcclusionQueryInProgress&&this._occlusionQuery)if(e.isQueryResultAvailable(this._occlusionQuery)){var i=e.getQueryResult(this._occlusionQuery);this._isOcclusionQueryInProgress=!1,this._occlusionInternalRetryCounter=0,this._isOccluded=1!==i}else{if(this._occlusionInternalRetryCounter++,!(-1!==this.occlusionRetryCount&&this._occlusionInternalRetryCounter>this.occlusionRetryCount))return;this._isOcclusionQueryInProgress=!1,this._occlusionInternalRetryCounter=0,this._isOccluded=this.occlusionType!==t.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}},t.OCCLUSION_TYPE_NONE=0,t.OCCLUSION_TYPE_OPTIMISTIC=1,t.OCCLUSION_TYPE_STRICT=2,t.OCCLUSION_ALGORITHM_TYPE_ACCURATE=0,t.OCCLUSION_ALGORITHM_TYPE_CONSERVATIVE=1,t}(A.TransformNode),A.AbstractMesh=P,M=us||(us={}),S=function(e){function t(i,r){var n=e.call(this,i,r)||this;return n.diffuse=new M.Color3(1,1,1),n.specular=new M.Color3(1,1,1),n.intensity=1,n.range=Number.MAX_VALUE,n._photometricScale=1,n._intensityMode=t.INTENSITYMODE_AUTOMATIC,n._radius=1e-5,n.renderPriority=0,n.shadowEnabled=!0,n._excludeWithLayerMask=0,n._includeOnlyWithLayerMask=0,n._lightmapMode=0,n._excludedMeshesIds=new Array,n._includedOnlyMeshesIds=new Array,n.getScene().addLight(n),n._uniformBuffer=new M.UniformBuffer(n.getScene().getEngine()),n._buildUniformLayout(),n.includedOnlyMeshes=new Array,n.excludedMeshes=new Array,n._resyncMeshes(),n}return Y(t,e),Object.defineProperty(t,"LIGHTMAP_DEFAULT",{get:function(){return t._LIGHTMAP_DEFAULT},enumerable:!0,configurable:!0}),Object.defineProperty(t,"LIGHTMAP_SPECULAR",{get:function(){return t._LIGHTMAP_SPECULAR},enumerable:!0,configurable:!0}),Object.defineProperty(t,"LIGHTMAP_SHADOWSONLY",{get:function(){return t._LIGHTMAP_SHADOWSONLY},enumerable:!0,configurable:!0}),Object.defineProperty(t,"INTENSITYMODE_AUTOMATIC",{get:function(){return t._INTENSITYMODE_AUTOMATIC},enumerable:!0,configurable:!0}),Object.defineProperty(t,"INTENSITYMODE_LUMINOUSPOWER",{get:function(){return t._INTENSITYMODE_LUMINOUSPOWER},enumerable:!0,configurable:!0}),Object.defineProperty(t,"INTENSITYMODE_LUMINOUSINTENSITY",{get:function(){return t._INTENSITYMODE_LUMINOUSINTENSITY},enumerable:!0,configurable:!0}),Object.defineProperty(t,"INTENSITYMODE_ILLUMINANCE",{get:function(){return t._INTENSITYMODE_ILLUMINANCE},enumerable:!0,configurable:!0}),Object.defineProperty(t,"INTENSITYMODE_LUMINANCE",{get:function(){return t._INTENSITYMODE_LUMINANCE},enumerable:!0,configurable:!0}),Object.defineProperty(t,"LIGHTTYPEID_POINTLIGHT",{get:function(){return t._LIGHTTYPEID_POINTLIGHT},enumerable:!0,configurable:!0}),Object.defineProperty(t,"LIGHTTYPEID_DIRECTIONALLIGHT",{get:function(){return t._LIGHTTYPEID_DIRECTIONALLIGHT},enumerable:!0,configurable:!0}),Object.defineProperty(t,"LIGHTTYPEID_SPOTLIGHT",{get:function(){return t._LIGHTTYPEID_SPOTLIGHT},enumerable:!0,configurable:!0}),Object.defineProperty(t,"LIGHTTYPEID_HEMISPHERICLIGHT",{get:function(){return t._LIGHTTYPEID_HEMISPHERICLIGHT},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"intensityMode",{get:function(){return this._intensityMode},set:function(e){this._intensityMode=e,this._computePhotometricScale()},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"radius",{get:function(){return this._radius},set:function(e){this._radius=e,this._computePhotometricScale()},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"includedOnlyMeshes",{get:function(){return this._includedOnlyMeshes},set:function(e){this._includedOnlyMeshes=e,this._hookArrayForIncludedOnly(e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"excludedMeshes",{get:function(){return this._excludedMeshes},set:function(e){this._excludedMeshes=e,this._hookArrayForExcluded(e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"excludeWithLayerMask",{get:function(){return this._excludeWithLayerMask},set:function(e){this._excludeWithLayerMask=e,this._resyncMeshes()},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"includeOnlyWithLayerMask",{get:function(){return this._includeOnlyWithLayerMask},set:function(e){this._includeOnlyWithLayerMask=e,this._resyncMeshes()},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"lightmapMode",{get:function(){return this._lightmapMode},set:function(e){this._lightmapMode!==e&&(this._lightmapMode=e,this._markMeshesAsLightDirty())},enumerable:!0,configurable:!0}),t.prototype._buildUniformLayout=function(){},t.prototype.getClassName=function(){return"Light"},t.prototype.toString=function(e){var t="Name: "+this.name;if(t+=", type: "+["Point","Directional","Spot","Hemispheric"][this.getTypeID()],this.animations)for(var i=0;i<this.animations.length;i++)t+=", animation[0]: "+this.animations[i].toString(e);return t},t.prototype.setEnabled=function(t){e.prototype.setEnabled.call(this,t),this._resyncMeshes()},t.prototype.getShadowGenerator=function(){return this._shadowGenerator},t.prototype.getAbsolutePosition=function(){return M.Vector3.Zero()},t.prototype.transferToEffect=function(e,t){},t.prototype._getWorldMatrix=function(){return M.Matrix.Identity()},t.prototype.canAffectMesh=function(e){return!e||!(this.includedOnlyMeshes&&this.includedOnlyMeshes.length>0&&-1===this.includedOnlyMeshes.indexOf(e))&&(!(this.excludedMeshes&&this.excludedMeshes.length>0&&-1!==this.excludedMeshes.indexOf(e))&&((0===this.includeOnlyWithLayerMask||0!=(this.includeOnlyWithLayerMask&e.layerMask))&&!(0!==this.excludeWithLayerMask&&this.excludeWithLayerMask&e.layerMask)))},t.prototype.getWorldMatrix=function(){this._currentRenderId=this.getScene().getRenderId();var e=this._getWorldMatrix();return this.parent&&this.parent.getWorldMatrix?(this._parentedWorldMatrix||(this._parentedWorldMatrix=M.Matrix.Identity()),e.multiplyToRef(this.parent.getWorldMatrix(),this._parentedWorldMatrix),this._markSyncedWithParent(),this._parentedWorldMatrix):e},t.compareLightsPriority=function(e,t){return e.shadowEnabled!==t.shadowEnabled?(t.shadowEnabled?1:0)-(e.shadowEnabled?1:0):t.renderPriority-e.renderPriority},t.prototype.dispose=function(){this._shadowGenerator&&(this._shadowGenerator.dispose(),this._shadowGenerator=null),this.getScene().stopAnimation(this),this._uniformBuffer.dispose(),this.getScene().removeLight(this),e.prototype.dispose.call(this)},t.prototype.getTypeID=function(){return 0},t.prototype.getScaledIntensity=function(){return this._photometricScale*this.intensity},t.prototype.clone=function(e){var i=t.GetConstructorFromName(this.getTypeID(),e,this.getScene());return i?M.SerializationHelper.Clone(i,this):null},t.prototype.serialize=function(){var e=M.SerializationHelper.Serialize(this);return e.type=this.getTypeID(),this.parent&&(e.parentId=this.parent.id),this.excludedMeshes.length>0&&(e.excludedMeshesIds=[],this.excludedMeshes.forEach(function(t){e.excludedMeshesIds.push(t.id)})),this.includedOnlyMeshes.length>0&&(e.includedOnlyMeshesIds=[],this.includedOnlyMeshes.forEach(function(t){e.includedOnlyMeshesIds.push(t.id)})),M.Animation.AppendSerializedAnimations(this,e),e.ranges=this.serializeAnimationRanges(),e},t.GetConstructorFromName=function(e,t,i){switch(e){case 0:return function(){return new M.PointLight(t,M.Vector3.Zero(),i)};case 1:return function(){return new M.DirectionalLight(t,M.Vector3.Zero(),i)};case 2:return function(){return new M.SpotLight(t,M.Vector3.Zero(),M.Vector3.Zero(),0,0,i)};case 3:return function(){return new M.HemisphericLight(t,M.Vector3.Zero(),i)}}return null},t.Parse=function(e,i){var r=t.GetConstructorFromName(e.type,e.name,i);if(!r)return null;var n=M.SerializationHelper.Parse(r,e,i);if(e.excludedMeshesIds&&(n._excludedMeshesIds=e.excludedMeshesIds),e.includedOnlyMeshesIds&&(n._includedOnlyMeshesIds=e.includedOnlyMeshesIds),e.parentId&&(n._waitingParentId=e.parentId),e.animations){for(var o=0;o<e.animations.length;o++){var s=e.animations[o];n.animations.push(M.Animation.Parse(s))}M.Node.ParseAnimationRanges(n,e,i)}return e.autoAnimate&&i.beginAnimation(n,e.autoAnimateFrom,e.autoAnimateTo,e.autoAnimateLoop,e.autoAnimateSpeed||1),n},t.prototype._hookArrayForExcluded=function(e){var t=this,i=e.push;e.push=function(){for(var r=[],n=0;n<arguments.length;n++)r[n]=arguments[n];for(var o=i.apply(e,r),s=0,a=r;s<a.length;s++){a[s]._resyncLighSource(t)}return o};var r=e.splice;e.splice=function(i,n){for(var o=r.apply(e,[i,n]),s=0,a=o;s<a.length;s++){a[s]._resyncLighSource(t)}return o};for(var n=0,o=e;n<o.length;n++){o[n]._resyncLighSource(this)}},t.prototype._hookArrayForIncludedOnly=function(e){var t=this,i=e.push;e.push=function(){for(var r=[],n=0;n<arguments.length;n++)r[n]=arguments[n];var o=i.apply(e,r);return t._resyncMeshes(),o};var r=e.splice;e.splice=function(i,n){var o=r.apply(e,[i,n]);return t._resyncMeshes(),o},this._resyncMeshes()},t.prototype._resyncMeshes=function(){for(var e=0,t=this.getScene().meshes;e<t.length;e++){t[e]._resyncLighSource(this)}},t.prototype._markMeshesAsLightDirty=function(){for(var e=0,t=this.getScene().meshes;e<t.length;e++){var i=t[e];-1!==i._lightSources.indexOf(this)&&i._markSubMeshesAsLightDirty()}},t.prototype._computePhotometricScale=function(){this._photometricScale=this._getPhotometricScale(),this.getScene().resetCachedMaterial()},t.prototype._getPhotometricScale=function(){var e=0,i=this.getTypeID(),r=this.intensityMode;switch(r===t.INTENSITYMODE_AUTOMATIC&&(r=i===t.LIGHTTYPEID_DIRECTIONALLIGHT?t.INTENSITYMODE_ILLUMINANCE:t.INTENSITYMODE_LUMINOUSINTENSITY),i){case t.LIGHTTYPEID_POINTLIGHT:case t.LIGHTTYPEID_SPOTLIGHT:switch(r){case t.INTENSITYMODE_LUMINOUSPOWER:e=1/(4*Math.PI);break;case t.INTENSITYMODE_LUMINOUSINTENSITY:e=1;break;case t.INTENSITYMODE_LUMINANCE:e=this.radius*this.radius}break;case t.LIGHTTYPEID_DIRECTIONALLIGHT:switch(r){case t.INTENSITYMODE_ILLUMINANCE:e=1;break;case t.INTENSITYMODE_LUMINANCE:var n=this.radius;n=Math.max(n,.001),e=2*Math.PI*(1-Math.cos(n))}break;case t.LIGHTTYPEID_HEMISPHERICLIGHT:e=1}return e},t.prototype._reorderLightsInScene=function(){var e=this.getScene();0!=this._renderPriority&&(e.requireLightSorting=!0),this.getScene().sortLightsByPriority()},t._LIGHTMAP_DEFAULT=0,t._LIGHTMAP_SPECULAR=1,t._LIGHTMAP_SHADOWSONLY=2,t._INTENSITYMODE_AUTOMATIC=0,t._INTENSITYMODE_LUMINOUSPOWER=1,t._INTENSITYMODE_LUMINOUSINTENSITY=2,t._INTENSITYMODE_ILLUMINANCE=3,t._INTENSITYMODE_LUMINANCE=4,t._LIGHTTYPEID_POINTLIGHT=0,t._LIGHTTYPEID_DIRECTIONALLIGHT=1,t._LIGHTTYPEID_SPOTLIGHT=2,t._LIGHTTYPEID_HEMISPHERICLIGHT=3,X([M.serializeAsColor3()],t.prototype,"diffuse",void 0),X([M.serializeAsColor3()],t.prototype,"specular",void 0),X([M.serialize()],t.prototype,"intensity",void 0),X([M.serialize()],t.prototype,"range",void 0),X([M.serialize()],t.prototype,"intensityMode",null),X([M.serialize()],t.prototype,"radius",null),X([M.serialize()],t.prototype,"_renderPriority",void 0),X([M.expandToProperty("_reorderLightsInScene")],t.prototype,"renderPriority",void 0),X([M.serialize()],t.prototype,"shadowEnabled",void 0),X([M.serialize("excludeWithLayerMask")],t.prototype,"_excludeWithLayerMask",void 0),X([M.serialize("includeOnlyWithLayerMask")],t.prototype,"_includeOnlyWithLayerMask",void 0),X([M.serialize("lightmapMode")],t.prototype,"_lightmapMode",void 0),t}(M.Node),M.Light=S,C=us||(us={}),R=function(e){function t(i,r,n){var o=e.call(this,i,n)||this;return o.upVector=C.Vector3.Up(),o.orthoLeft=null,o.orthoRight=null,o.orthoBottom=null,o.orthoTop=null,o.fov=.8,o.minZ=1,o.maxZ=1e4,o.inertia=.9,o.mode=t.PERSPECTIVE_CAMERA,o.isIntermediate=!1,o.viewport=new C.Viewport(0,0,1,1),o.layerMask=268435455,o.fovMode=t.FOVMODE_VERTICAL_FIXED,o.cameraRigMode=t.RIG_MODE_NONE,o._rigCameras=new Array,o._webvrViewMatrix=C.Matrix.Identity(),o._skipRendering=!1,o.customRenderTargets=new Array,o.onViewMatrixChangedObservable=new C.Observable,o.onProjectionMatrixChangedObservable=new C.Observable,o.onAfterCheckInputsObservable=new C.Observable,o.onRestoreStateObservable=new C.Observable,o._computedViewMatrix=C.Matrix.Identity(),o._projectionMatrix=new C.Matrix,o._doNotComputeProjectionMatrix=!1,o._postProcesses=new Array,o._transformMatrix=C.Matrix.Zero(),o._activeMeshes=new C.SmartArray(256),o._globalPosition=C.Vector3.Zero(),o._refreshFrustumPlanes=!0,o.getScene().addCamera(o),o.getScene().activeCamera||(o.getScene().activeCamera=o),o.position=r,o}return Y(t,e),Object.defineProperty(t,"PERSPECTIVE_CAMERA",{get:function(){return t._PERSPECTIVE_CAMERA},enumerable:!0,configurable:!0}),Object.defineProperty(t,"ORTHOGRAPHIC_CAMERA",{get:function(){return t._ORTHOGRAPHIC_CAMERA},enumerable:!0,configurable:!0}),Object.defineProperty(t,"FOVMODE_VERTICAL_FIXED",{get:function(){return t._FOVMODE_VERTICAL_FIXED},enumerable:!0,configurable:!0}),Object.defineProperty(t,"FOVMODE_HORIZONTAL_FIXED",{get:function(){return t._FOVMODE_HORIZONTAL_FIXED},enumerable:!0,configurable:!0}),Object.defineProperty(t,"RIG_MODE_NONE",{get:function(){return t._RIG_MODE_NONE},enumerable:!0,configurable:!0}),Object.defineProperty(t,"RIG_MODE_STEREOSCOPIC_ANAGLYPH",{get:function(){return t._RIG_MODE_STEREOSCOPIC_ANAGLYPH},enumerable:!0,configurable:!0}),Object.defineProperty(t,"RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL",{get:function(){return t._RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL},enumerable:!0,configurable:!0}),Object.defineProperty(t,"RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED",{get:function(){return t._RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED},enumerable:!0,configurable:!0}),Object.defineProperty(t,"RIG_MODE_STEREOSCOPIC_OVERUNDER",{get:function(){return t._RIG_MODE_STEREOSCOPIC_OVERUNDER},enumerable:!0,configurable:!0}),Object.defineProperty(t,"RIG_MODE_VR",{get:function(){return t._RIG_MODE_VR},enumerable:!0,configurable:!0}),Object.defineProperty(t,"RIG_MODE_WEBVR",{get:function(){return t._RIG_MODE_WEBVR},enumerable:!0,configurable:!0}),t.prototype.storeState=function(){return this._stateStored=!0,this._storedFov=this.fov,this},t.prototype._restoreStateValues=function(){return!!this._stateStored&&(this.fov=this._storedFov,!0)},t.prototype.restoreState=function(){return!!this._restoreStateValues()&&(this.onRestoreStateObservable.notifyObservers(this),!0)},t.prototype.getClassName=function(){return"Camera"},t.prototype.toString=function(e){var t="Name: "+this.name;if(t+=", type: "+this.getClassName(),this.animations)for(var i=0;i<this.animations.length;i++)t+=", animation[0]: "+this.animations[i].toString(e);return t},Object.defineProperty(t.prototype,"globalPosition",{get:function(){return this._globalPosition},enumerable:!0,configurable:!0}),t.prototype.getActiveMeshes=function(){return this._activeMeshes},t.prototype.isActiveMesh=function(e){return-1!==this._activeMeshes.indexOf(e)},t.prototype._initCache=function(){e.prototype._initCache.call(this),this._cache.position=new C.Vector3(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),this._cache.upVector=new C.Vector3(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),this._cache.mode=void 0,this._cache.minZ=void 0,this._cache.maxZ=void 0,this._cache.fov=void 0,this._cache.fovMode=void 0,this._cache.aspectRatio=void 0,this._cache.orthoLeft=void 0,this._cache.orthoRight=void 0,this._cache.orthoBottom=void 0,this._cache.orthoTop=void 0,this._cache.renderWidth=void 0,this._cache.renderHeight=void 0},t.prototype._updateCache=function(t){t||e.prototype._updateCache.call(this),this._cache.position.copyFrom(this.position),this._cache.upVector.copyFrom(this.upVector)},t.prototype._isSynchronized=function(){return this._isSynchronizedViewMatrix()&&this._isSynchronizedProjectionMatrix()},t.prototype._isSynchronizedViewMatrix=function(){return!!e.prototype._isSynchronized.call(this)&&(this._cache.position.equals(this.position)&&this._cache.upVector.equals(this.upVector)&&this.isSynchronizedWithParent())},t.prototype._isSynchronizedProjectionMatrix=function(){var e=this._cache.mode===this.mode&&this._cache.minZ===this.minZ&&this._cache.maxZ===this.maxZ;if(!e)return!1;var i=this.getEngine();return e=this.mode===t.PERSPECTIVE_CAMERA?this._cache.fov===this.fov&&this._cache.fovMode===this.fovMode&&this._cache.aspectRatio===i.getAspectRatio(this):this._cache.orthoLeft===this.orthoLeft&&this._cache.orthoRight===this.orthoRight&&this._cache.orthoBottom===this.orthoBottom&&this._cache.orthoTop===this.orthoTop&&this._cache.renderWidth===i.getRenderWidth()&&this._cache.renderHeight===i.getRenderHeight()},t.prototype.attachControl=function(e,t){},t.prototype.detachControl=function(e){},t.prototype.update=function(){this._checkInputs(),this.cameraRigMode!==t.RIG_MODE_NONE&&this._updateRigCameras()},t.prototype._checkInputs=function(){this.onAfterCheckInputsObservable.notifyObservers(this)},Object.defineProperty(t.prototype,"rigCameras",{get:function(){return this._rigCameras},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rigPostProcess",{get:function(){return this._rigPostProcess},enumerable:!0,configurable:!0}),t.prototype._cascadePostProcessesToRigCams=function(){this._postProcesses.length>0&&this._postProcesses[0].markTextureDirty();for(var e=0,t=this._rigCameras.length;e<t;e++){var i=this._rigCameras[e],r=i._rigPostProcess;if(r)r instanceof C.PassPostProcess&&(i.isIntermediate=0===this._postProcesses.length),i._postProcesses=this._postProcesses.slice(0).concat(r),r.markTextureDirty();else i._postProcesses=this._postProcesses.slice(0)}},t.prototype.attachPostProcess=function(e,t){return void 0===t&&(t=null),!e.isReusable()&&this._postProcesses.indexOf(e)>-1?(C.Tools.Error("You're trying to reuse a post process not defined as reusable."),0):(null==t||t<0?this._postProcesses.push(e):this._postProcesses.splice(t,0,e),this._cascadePostProcessesToRigCams(),this._postProcesses.indexOf(e))},t.prototype.detachPostProcess=function(e){var t=this._postProcesses.indexOf(e);-1!==t&&this._postProcesses.splice(t,1),this._cascadePostProcessesToRigCams()},t.prototype.getWorldMatrix=function(){return this._worldMatrix||(this._worldMatrix=C.Matrix.Identity()),this.getViewMatrix().invertToRef(this._worldMatrix),this._worldMatrix},t.prototype._getViewMatrix=function(){return C.Matrix.Identity()},t.prototype.getViewMatrix=function(e){return!e&&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=C.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)},t.prototype.freezeProjectionMatrix=function(e){this._doNotComputeProjectionMatrix=!0,void 0!==e&&(this._projectionMatrix=e)},t.prototype.unfreezeProjectionMatrix=function(){this._doNotComputeProjectionMatrix=!1},t.prototype.getProjectionMatrix=function(e){if(this._doNotComputeProjectionMatrix||!e&&this._isSynchronizedProjectionMatrix())return this._projectionMatrix;this._cache.mode=this.mode,this._cache.minZ=this.minZ,this._cache.maxZ=this.maxZ,this._refreshFrustumPlanes=!0;var i=this.getEngine(),r=this.getScene();if(this.mode===t.PERSPECTIVE_CAMERA)this._cache.fov=this.fov,this._cache.fovMode=this.fovMode,this._cache.aspectRatio=i.getAspectRatio(this),this.minZ<=0&&(this.minZ=.1),r.useRightHandedSystem?C.Matrix.PerspectiveFovRHToRef(this.fov,i.getAspectRatio(this),this.minZ,this.maxZ,this._projectionMatrix,this.fovMode===t.FOVMODE_VERTICAL_FIXED):C.Matrix.PerspectiveFovLHToRef(this.fov,i.getAspectRatio(this),this.minZ,this.maxZ,this._projectionMatrix,this.fovMode===t.FOVMODE_VERTICAL_FIXED);else{var n=i.getRenderWidth()/2,o=i.getRenderHeight()/2;r.useRightHandedSystem?C.Matrix.OrthoOffCenterRHToRef(this.orthoLeft||-n,this.orthoRight||n,this.orthoBottom||-o,this.orthoTop||o,this.minZ,this.maxZ,this._projectionMatrix):C.Matrix.OrthoOffCenterLHToRef(this.orthoLeft||-n,this.orthoRight||n,this.orthoBottom||-o,this.orthoTop||o,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=i.getRenderWidth(),this._cache.renderHeight=i.getRenderHeight()}return this.onProjectionMatrixChangedObservable.notifyObservers(this),this._projectionMatrix},t.prototype.getTranformationMatrix=function(){return this._computedViewMatrix.multiplyToRef(this._projectionMatrix,this._transformMatrix),this._transformMatrix},t.prototype.updateFrustumPlanes=function(){this._refreshFrustumPlanes&&(this.getTranformationMatrix(),this._frustumPlanes?C.Frustum.GetPlanesToRef(this._transformMatrix,this._frustumPlanes):this._frustumPlanes=C.Frustum.GetPlanes(this._transformMatrix),this._refreshFrustumPlanes=!1)},t.prototype.isInFrustum=function(e){return this.updateFrustumPlanes(),e.isInFrustum(this._frustumPlanes)},t.prototype.isCompletelyInFrustum=function(e){return this.updateFrustumPlanes(),e.isCompletelyInFrustum(this._frustumPlanes)},t.prototype.getForwardRay=function(e,t,i){void 0===e&&(e=100),t||(t=this.getWorldMatrix()),i||(i=this.position);var r=new C.Vector3(0,0,1),n=C.Vector3.TransformNormal(r,t),o=C.Vector3.Normalize(n);return new C.Ray(i,o,e)},t.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 i=this._rigCameras.pop();i&&i.dispose()}if(this._rigPostProcess)this._rigPostProcess.dispose(this),this._rigPostProcess=null,this._postProcesses=[];else if(this.cameraRigMode!==t.RIG_MODE_NONE)this._rigPostProcess=null,this._postProcesses=[];else for(var r=this._postProcesses.length;--r>=0;)this._postProcesses[r].dispose(this);for(r=this.customRenderTargets.length;--r>=0;)this.customRenderTargets[r].dispose();this.customRenderTargets=[],this._activeMeshes.dispose(),e.prototype.dispose.call(this)},Object.defineProperty(t.prototype,"leftCamera",{get:function(){return this._rigCameras.length<1?null:this._rigCameras[0]},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rightCamera",{get:function(){return this._rigCameras.length<2?null:this._rigCameras[1]},enumerable:!0,configurable:!0}),t.prototype.getLeftTarget=function(){return this._rigCameras.length<1?null:this._rigCameras[0].getTarget()},t.prototype.getRightTarget=function(){return this._rigCameras.length<2?null:this._rigCameras[1].getTarget()},t.prototype.setCameraRigMode=function(e,i){if(this.cameraRigMode!==e){for(;this._rigCameras.length>0;){var r=this._rigCameras.pop();r&&r.dispose()}if(this.cameraRigMode=e,this._cameraRigParams={},this._cameraRigParams.interaxialDistance=i.interaxialDistance||.0637,this._cameraRigParams.stereoHalfAngle=C.Tools.ToRadians(this._cameraRigParams.interaxialDistance/.0637),this.cameraRigMode!==t.RIG_MODE_NONE){var n=this.createRigCamera(this.name+"_L",0),o=this.createRigCamera(this.name+"_R",1);n&&o&&(this._rigCameras.push(n),this._rigCameras.push(o))}switch(this.cameraRigMode){case t.RIG_MODE_STEREOSCOPIC_ANAGLYPH:this._rigCameras[0]._rigPostProcess=new C.PassPostProcess(this.name+"_passthru",1,this._rigCameras[0]),this._rigCameras[1]._rigPostProcess=new C.AnaglyphPostProcess(this.name+"_anaglyph",1,this._rigCameras);break;case t.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL:case t.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED:case t.RIG_MODE_STEREOSCOPIC_OVERUNDER:var s=this.cameraRigMode===t.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL||this.cameraRigMode===t.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED;this._rigCameras[0]._rigPostProcess=new C.PassPostProcess(this.name+"_passthru",1,this._rigCameras[0]),this._rigCameras[1]._rigPostProcess=new C.StereoscopicInterlacePostProcess(this.name+"_stereoInterlace",this._rigCameras,s);break;case t.RIG_MODE_VR:var a=i.vrCameraMetrics||C.VRCameraMetrics.GetDefault();this._rigCameras[0]._cameraRigParams.vrMetrics=a,this._rigCameras[0].viewport=new C.Viewport(0,0,.5,1),this._rigCameras[0]._cameraRigParams.vrWorkMatrix=new C.Matrix,this._rigCameras[0]._cameraRigParams.vrHMatrix=a.leftHMatrix,this._rigCameras[0]._cameraRigParams.vrPreViewMatrix=a.leftPreViewMatrix,this._rigCameras[0].getProjectionMatrix=this._rigCameras[0]._getVRProjectionMatrix,this._rigCameras[1]._cameraRigParams.vrMetrics=a,this._rigCameras[1].viewport=new C.Viewport(.5,0,.5,1),this._rigCameras[1]._cameraRigParams.vrWorkMatrix=new C.Matrix,this._rigCameras[1]._cameraRigParams.vrHMatrix=a.rightHMatrix,this._rigCameras[1]._cameraRigParams.vrPreViewMatrix=a.rightPreViewMatrix,this._rigCameras[1].getProjectionMatrix=this._rigCameras[1]._getVRProjectionMatrix,a.compensateDistortion&&(this._rigCameras[0]._rigPostProcess=new C.VRDistortionCorrectionPostProcess("VR_Distort_Compensation_Left",this._rigCameras[0],!1,a),this._rigCameras[1]._rigPostProcess=new C.VRDistortionCorrectionPostProcess("VR_Distort_Compensation_Right",this._rigCameras[1],!0,a));break;case t.RIG_MODE_WEBVR:if(i.vrDisplay){var h=i.vrDisplay.getEyeParameters("left"),l=i.vrDisplay.getEyeParameters("right");this._rigCameras[0].viewport=new C.Viewport(0,0,.5,1),this._rigCameras[0].setCameraRigParameter("left",!0),this._rigCameras[0].setCameraRigParameter("specs",i.specs),this._rigCameras[0].setCameraRigParameter("eyeParameters",h),this._rigCameras[0].setCameraRigParameter("frameData",i.frameData),this._rigCameras[0].setCameraRigParameter("parentCamera",i.parentCamera),this._rigCameras[0]._cameraRigParams.vrWorkMatrix=new C.Matrix,this._rigCameras[0].getProjectionMatrix=this._getWebVRProjectionMatrix,this._rigCameras[0].parent=this,this._rigCameras[0]._getViewMatrix=this._getWebVRViewMatrix,this._rigCameras[1].viewport=new C.Viewport(.5,0,.5,1),this._rigCameras[1].setCameraRigParameter("eyeParameters",l),this._rigCameras[1].setCameraRigParameter("specs",i.specs),this._rigCameras[1].setCameraRigParameter("frameData",i.frameData),this._rigCameras[1].setCameraRigParameter("parentCamera",i.parentCamera),this._rigCameras[1]._cameraRigParams.vrWorkMatrix=new C.Matrix,this._rigCameras[1].getProjectionMatrix=this._getWebVRProjectionMatrix,this._rigCameras[1].parent=this,this._rigCameras[1]._getViewMatrix=this._getWebVRViewMatrix,t.UseAlternateWebVRRendering&&(this._rigCameras[1]._skipRendering=!0,this._rigCameras[0]._alternateCamera=this._rigCameras[1])}}this._cascadePostProcessesToRigCams(),this.update()}},t.prototype._getVRProjectionMatrix=function(){return C.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},t.prototype._updateCameraRotationMatrix=function(){},t.prototype._updateWebVRCameraRotationMatrix=function(){},t.prototype._getWebVRProjectionMatrix=function(){return C.Matrix.Identity()},t.prototype._getWebVRViewMatrix=function(){return C.Matrix.Identity()},t.prototype.setCameraRigParameter=function(e,t){this._cameraRigParams||(this._cameraRigParams={}),this._cameraRigParams[e]=t,"interaxialDistance"===e&&(this._cameraRigParams.stereoHalfAngle=C.Tools.ToRadians(t/.0637))},t.prototype.createRigCamera=function(e,t){return null},t.prototype._updateRigCameras=function(){for(var e=0;e<this._rigCameras.length;e++)this._rigCameras[e].minZ=this.minZ,this._rigCameras[e].maxZ=this.maxZ,this._rigCameras[e].fov=this.fov;this.cameraRigMode===t.RIG_MODE_STEREOSCOPIC_ANAGLYPH&&(this._rigCameras[0].viewport=this._rigCameras[1].viewport=this.viewport)},t.prototype._setupInputs=function(){},t.prototype.serialize=function(){var e=C.SerializationHelper.Serialize(this);return e.type=this.getClassName(),this.parent&&(e.parentId=this.parent.id),this.inputs&&this.inputs.serialize(e),C.Animation.AppendSerializedAnimations(this,e),e.ranges=this.serializeAnimationRanges(),e},t.prototype.clone=function(e){return C.SerializationHelper.Clone(t.GetConstructorFromName(this.getClassName(),e,this.getScene(),this.interaxialDistance,this.isStereoscopicSideBySide),this)},t.prototype.getDirection=function(e){var t=C.Vector3.Zero();return this.getDirectionToRef(e,t),t},t.prototype.getDirectionToRef=function(e,t){C.Vector3.TransformNormalToRef(e,this.getWorldMatrix(),t)},t.GetConstructorFromName=function(e,t,i,r,n){switch(void 0===r&&(r=0),void 0===n&&(n=!0),e){case"ArcRotateCamera":return function(){return new C.ArcRotateCamera(t,0,0,1,C.Vector3.Zero(),i)};case"DeviceOrientationCamera":return function(){return new C.DeviceOrientationCamera(t,C.Vector3.Zero(),i)};case"FollowCamera":return function(){return new C.FollowCamera(t,C.Vector3.Zero(),i)};case"ArcFollowCamera":return function(){return new C.ArcFollowCamera(t,0,0,1,null,i)};case"GamepadCamera":return function(){return new C.GamepadCamera(t,C.Vector3.Zero(),i)};case"TouchCamera":return function(){return new C.TouchCamera(t,C.Vector3.Zero(),i)};case"VirtualJoysticksCamera":return function(){return new C.VirtualJoysticksCamera(t,C.Vector3.Zero(),i)};case"WebVRFreeCamera":case"WebVRGamepadCamera":return function(){return new C.WebVRFreeCamera(t,C.Vector3.Zero(),i)};case"VRDeviceOrientationFreeCamera":return function(){return new C.VRDeviceOrientationFreeCamera(t,C.Vector3.Zero(),i)};case"VRDeviceOrientationGamepadCamera":return function(){return new C.VRDeviceOrientationGamepadCamera(t,C.Vector3.Zero(),i)};case"AnaglyphArcRotateCamera":return function(){return new C.AnaglyphArcRotateCamera(t,0,0,1,C.Vector3.Zero(),r,i)};case"AnaglyphFreeCamera":return function(){return new C.AnaglyphFreeCamera(t,C.Vector3.Zero(),r,i)};case"AnaglyphGamepadCamera":return function(){return new C.AnaglyphGamepadCamera(t,C.Vector3.Zero(),r,i)};case"AnaglyphUniversalCamera":return function(){return new C.AnaglyphUniversalCamera(t,C.Vector3.Zero(),r,i)};case"StereoscopicArcRotateCamera":return function(){return new C.StereoscopicArcRotateCamera(t,0,0,1,C.Vector3.Zero(),r,n,i)};case"StereoscopicFreeCamera":return function(){return new C.StereoscopicFreeCamera(t,C.Vector3.Zero(),r,n,i)};case"StereoscopicGamepadCamera":return function(){return new C.StereoscopicGamepadCamera(t,C.Vector3.Zero(),r,n,i)};case"StereoscopicUniversalCamera":return function(){return new C.StereoscopicUniversalCamera(t,C.Vector3.Zero(),r,n,i)};case"FreeCamera":default:return function(){return new C.UniversalCamera(t,C.Vector3.Zero(),i)}}},t.prototype.computeWorldMatrix=function(){return this.getWorldMatrix()},t.Parse=function(e,i){var r=e.type,n=t.GetConstructorFromName(r,e.name,i,e.interaxial_distance,e.isStereoscopicSideBySide),o=C.SerializationHelper.Parse(n,e,i);if(e.parentId&&(o._waitingParentId=e.parentId),o.inputs&&(o.inputs.parse(e),o._setupInputs()),o.setPosition&&(o.position.copyFromFloats(0,0,0),o.setPosition(C.Vector3.FromArray(e.position))),e.target&&o.setTarget&&o.setTarget(C.Vector3.FromArray(e.target)),e.cameraRigMode){var s=e.interaxial_distance?{interaxialDistance:e.interaxial_distance}:{};o.setCameraRigMode(e.cameraRigMode,s)}if(e.animations){for(var a=0;a<e.animations.length;a++){var h=e.animations[a];o.animations.push(C.Animation.Parse(h))}C.Node.ParseAnimationRanges(o,e,i)}return e.autoAnimate&&i.beginAnimation(o,e.autoAnimateFrom,e.autoAnimateTo,e.autoAnimateLoop,e.autoAnimateSpeed||1),o},t._PERSPECTIVE_CAMERA=0,t._ORTHOGRAPHIC_CAMERA=1,t._FOVMODE_VERTICAL_FIXED=0,t._FOVMODE_HORIZONTAL_FIXED=1,t._RIG_MODE_NONE=0,t._RIG_MODE_STEREOSCOPIC_ANAGLYPH=10,t._RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL=11,t._RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED=12,t._RIG_MODE_STEREOSCOPIC_OVERUNDER=13,t._RIG_MODE_VR=20,t._RIG_MODE_WEBVR=21,t.ForceAttachControlToAlwaysPreventDefault=!1,t.UseAlternateWebVRRendering=!1,X([C.serializeAsVector3()],t.prototype,"position",void 0),X([C.serializeAsVector3()],t.prototype,"upVector",void 0),X([C.serialize()],t.prototype,"orthoLeft",void 0),X([C.serialize()],t.prototype,"orthoRight",void 0),X([C.serialize()],t.prototype,"orthoBottom",void 0),X([C.serialize()],t.prototype,"orthoTop",void 0),X([C.serialize()],t.prototype,"fov",void 0),X([C.serialize()],t.prototype,"minZ",void 0),X([C.serialize()],t.prototype,"maxZ",void 0),X([C.serialize()],t.prototype,"inertia",void 0),X([C.serialize()],t.prototype,"mode",void 0),X([C.serialize()],t.prototype,"layerMask",void 0),X([C.serialize()],t.prototype,"fovMode",void 0),X([C.serialize()],t.prototype,"cameraRigMode",void 0),X([C.serialize()],t.prototype,"interaxialDistance",void 0),X([C.serialize()],t.prototype,"isStereoscopicSideBySide",void 0),t}(C.Node),C.Camera=R,O=us||(us={}),I=function(){function e(t){this._renderingGroups=new Array,this._autoClearDepthStencil={},this._customOpaqueSortCompareFn={},this._customAlphaTestSortCompareFn={},this._customTransparentSortCompareFn={},this._renderinGroupInfo=null,this._scene=t;for(var i=e.MIN_RENDERINGGROUPS;i<e.MAX_RENDERINGGROUPS;i++)this._autoClearDepthStencil[i]={autoClear:!0,depth:!0,stencil:!0}}return e.prototype._clearDepthStencilBuffer=function(e,t){void 0===e&&(e=!0),void 0===t&&(t=!0),this._depthStencilBufferAlreadyCleaned||(this._scene.getEngine().clear(null,!1,e,t),this._depthStencilBufferAlreadyCleaned=!0)},e.prototype.render=function(t,i,r,n){var o=this._scene.onRenderingGroupObservable.hasObservers()?this._scene.onRenderingGroupObservable:null,s=null;if(o&&(this._renderinGroupInfo||(this._renderinGroupInfo=new O.RenderingGroupInfo),(s=this._renderinGroupInfo).scene=this._scene,s.camera=this._scene.activeCamera),n)for(var a=0;a<this._scene.spriteManagers.length;a++){var h=this._scene.spriteManagers[a];this.dispatchSprites(h)}for(a=e.MIN_RENDERINGGROUPS;a<e.MAX_RENDERINGGROUPS;a++){this._depthStencilBufferAlreadyCleaned=a===e.MIN_RENDERINGGROUPS;var l=this._renderingGroups[a];if(l||o){var c=0;if(o&&s&&(c=Math.pow(2,a),s.renderStage=O.RenderingGroupInfo.STAGE_PRECLEAR,s.renderingGroupId=a,o.notifyObservers(s,c)),e.AUTOCLEAR){var u=this._autoClearDepthStencil[a];u&&u.autoClear&&this._clearDepthStencilBuffer(u.depth,u.stencil)}o&&s&&(s.renderStage=O.RenderingGroupInfo.STAGE_PREOPAQUE,o.notifyObservers(s,c),s.renderStage=O.RenderingGroupInfo.STAGE_PRETRANSPARENT,o.notifyObservers(s,c)),l&&l.render(t,n,r,i),o&&s&&(s.renderStage=O.RenderingGroupInfo.STAGE_POSTTRANSPARENT,o.notifyObservers(s,c))}}},e.prototype.reset=function(){for(var t=e.MIN_RENDERINGGROUPS;t<e.MAX_RENDERINGGROUPS;t++){var i=this._renderingGroups[t];i&&i.prepare()}},e.prototype.dispose=function(){for(var t=e.MIN_RENDERINGGROUPS;t<e.MAX_RENDERINGGROUPS;t++){var i=this._renderingGroups[t];i&&i.dispose()}this._renderingGroups.length=0},e.prototype._prepareRenderingGroup=function(e){void 0===this._renderingGroups[e]&&(this._renderingGroups[e]=new O.RenderingGroup(e,this._scene,this._customOpaqueSortCompareFn[e],this._customAlphaTestSortCompareFn[e],this._customTransparentSortCompareFn[e]))},e.prototype.dispatchSprites=function(e){var t=e.renderingGroupId||0;this._prepareRenderingGroup(t),this._renderingGroups[t].dispatchSprites(e)},e.prototype.dispatchParticles=function(e){var t=e.renderingGroupId||0;this._prepareRenderingGroup(t),this._renderingGroups[t].dispatchParticles(e)},e.prototype.dispatch=function(e,t,i){void 0===t&&(t=e.getMesh());var r=t.renderingGroupId||0;this._prepareRenderingGroup(r),this._renderingGroups[r].dispatch(e,t,i)},e.prototype.setRenderingOrder=function(e,t,i,r){if(void 0===t&&(t=null),void 0===i&&(i=null),void 0===r&&(r=null),this._customOpaqueSortCompareFn[e]=t,this._customAlphaTestSortCompareFn[e]=i,this._customTransparentSortCompareFn[e]=r,this._renderingGroups[e]){var n=this._renderingGroups[e];n.opaqueSortCompareFn=this._customOpaqueSortCompareFn[e],n.alphaTestSortCompareFn=this._customAlphaTestSortCompareFn[e],n.transparentSortCompareFn=this._customTransparentSortCompareFn[e]}},e.prototype.setRenderingAutoClearDepthStencil=function(e,t,i,r){void 0===i&&(i=!0),void 0===r&&(r=!0),this._autoClearDepthStencil[e]={autoClear:t,depth:i,stencil:r}},e.MAX_RENDERINGGROUPS=4,e.MIN_RENDERINGGROUPS=0,e.AUTOCLEAR=!0,e}(),O.RenderingManager=I,w=us||(us={}),D=function(){function e(e,t,i,r,n){void 0===i&&(i=null),void 0===r&&(r=null),void 0===n&&(n=null),this.index=e,this._opaqueSubMeshes=new w.SmartArray(256),this._transparentSubMeshes=new w.SmartArray(256),this._alphaTestSubMeshes=new w.SmartArray(256),this._depthOnlySubMeshes=new w.SmartArray(256),this._particleSystems=new w.SmartArray(256),this._spriteManagers=new w.SmartArray(256),this._edgesRenderers=new w.SmartArray(16),this._scene=t,this.opaqueSortCompareFn=i,this.alphaTestSortCompareFn=r,this.transparentSortCompareFn=n}return Object.defineProperty(e.prototype,"opaqueSortCompareFn",{set:function(t){this._opaqueSortCompareFn=t,this._renderOpaque=t?this.renderOpaqueSorted:e.renderUnsorted},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"alphaTestSortCompareFn",{set:function(t){this._alphaTestSortCompareFn=t,this._renderAlphaTest=t?this.renderAlphaTestSorted:e.renderUnsorted},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"transparentSortCompareFn",{set:function(t){this._transparentSortCompareFn=t||e.defaultTransparentSortCompare,this._renderTransparent=this.renderTransparentSorted},enumerable:!0,configurable:!0}),e.prototype.render=function(e,t,i,r){if(e)e(this._opaqueSubMeshes,this._alphaTestSubMeshes,this._transparentSubMeshes,this._depthOnlySubMeshes);else{var n=this._scene.getEngine();0!==this._depthOnlySubMeshes.length&&(n.setAlphaTesting(!0),n.setColorWrite(!1),this._renderAlphaTest(this._depthOnlySubMeshes),n.setAlphaTesting(!1),n.setColorWrite(!0)),0!==this._opaqueSubMeshes.length&&this._renderOpaque(this._opaqueSubMeshes),0!==this._alphaTestSubMeshes.length&&(n.setAlphaTesting(!0),this._renderAlphaTest(this._alphaTestSubMeshes),n.setAlphaTesting(!1));var o=n.getStencilBuffer();n.setStencilBuffer(!1),t&&this._renderSprites(),i&&this._renderParticles(r),this.onBeforeTransparentRendering&&this.onBeforeTransparentRendering(),0!==this._transparentSubMeshes.length&&(this._renderTransparent(this._transparentSubMeshes),n.setAlphaMode(w.Engine.ALPHA_DISABLE)),n.setStencilBuffer(!1);for(var s=0;s<this._edgesRenderers.length;s++)this._edgesRenderers.data[s].render();n.setStencilBuffer(o)}},e.prototype.renderOpaqueSorted=function(t){return e.renderSorted(t,this._opaqueSortCompareFn,this._scene.activeCamera,!1)},e.prototype.renderAlphaTestSorted=function(t){return e.renderSorted(t,this._alphaTestSortCompareFn,this._scene.activeCamera,!1)},e.prototype.renderTransparentSorted=function(t){return e.renderSorted(t,this._transparentSortCompareFn,this._scene.activeCamera,!0)},e.renderSorted=function(e,t,i,r){for(var n,o=0,s=i?i.globalPosition:w.Vector3.Zero();o<e.length;o++)(n=e.data[o])._alphaIndex=n.getMesh().alphaIndex,n._distanceToCamera=n.getBoundingInfo().boundingSphere.centerWorld.subtract(s).length();var a=e.data.slice(0,e.length);for(t&&a.sort(t),o=0;o<a.length;o++){if(n=a[o],r){var h=n.getMaterial();if(h&&h.needDepthPrePass){var l=h.getScene().getEngine();l.setColorWrite(!1),l.setAlphaTesting(!0),l.setAlphaMode(w.Engine.ALPHA_DISABLE),n.render(!1),l.setAlphaTesting(!1),l.setColorWrite(!0)}}n.render(r)}},e.renderUnsorted=function(e){for(var t=0;t<e.length;t++){e.data[t].render(!1)}},e.defaultTransparentSortCompare=function(t,i){return t._alphaIndex>i._alphaIndex?1:t._alphaIndex<i._alphaIndex?-1:e.backToFrontSortCompare(t,i)},e.backToFrontSortCompare=function(e,t){return e._distanceToCamera<t._distanceToCamera?1:e._distanceToCamera>t._distanceToCamera?-1:0},e.frontToBackSortCompare=function(e,t){return e._distanceToCamera<t._distanceToCamera?-1:e._distanceToCamera>t._distanceToCamera?1:0},e.prototype.prepare=function(){this._opaqueSubMeshes.reset(),this._transparentSubMeshes.reset(),this._alphaTestSubMeshes.reset(),this._depthOnlySubMeshes.reset(),this._particleSystems.reset(),this._spriteManagers.reset(),this._edgesRenderers.reset()},e.prototype.dispose=function(){this._opaqueSubMeshes.dispose(),this._transparentSubMeshes.dispose(),this._alphaTestSubMeshes.dispose(),this._depthOnlySubMeshes.dispose(),this._particleSystems.dispose(),this._spriteManagers.dispose(),this._edgesRenderers.dispose()},e.prototype.dispatch=function(e,t,i){void 0===t&&(t=e.getMesh()),void 0===i&&(i=e.getMaterial()),null!==i&&void 0!==i&&(i.needAlphaBlendingForMesh(t)?this._transparentSubMeshes.push(e):i.needAlphaTesting()?(i.needDepthPrePass&&this._depthOnlySubMeshes.push(e),this._alphaTestSubMeshes.push(e)):(i.needDepthPrePass&&this._depthOnlySubMeshes.push(e),this._opaqueSubMeshes.push(e)),null!==t._edgesRenderer&&void 0!==t._edgesRenderer&&this._edgesRenderers.push(t._edgesRenderer))},e.prototype.dispatchSprites=function(e){this._spriteManagers.push(e)},e.prototype.dispatchParticles=function(e){this._particleSystems.push(e)},e.prototype._renderParticles=function(e){if(0!==this._particleSystems.length){var t=this._scene.activeCamera;this._scene.onBeforeParticlesRenderingObservable.notifyObservers(this._scene);for(var i=0;i<this._scene._activeParticleSystems.length;i++){var r=this._scene._activeParticleSystems.data[i];if(0!==(t&&t.layerMask&r.layerMask)){var n=r.emitter;n.position&&e&&-1===e.indexOf(n)||this._scene._activeParticles.addCount(r.render(),!1)}}this._scene.onAfterParticlesRenderingObservable.notifyObservers(this._scene)}},e.prototype._renderSprites=function(){if(this._scene.spritesEnabled&&0!==this._spriteManagers.length){var e=this._scene.activeCamera;this._scene.onBeforeSpritesRenderingObservable.notifyObservers(this._scene);for(var t=0;t<this._spriteManagers.length;t++){var i=this._spriteManagers.data[t];0!==(e&&e.layerMask&i.layerMask)&&i.render()}this._scene.onAfterSpritesRenderingObservable.notifyObservers(this._scene)}},e}(),w.RenderingGroup=D,function(e){var t=function(){function e(){this._singleClick=!1,this._doubleClick=!1,this._hasSwiped=!1,this._ignore=!1}return Object.defineProperty(e.prototype,"singleClick",{get:function(){return this._singleClick},set:function(e){this._singleClick=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"doubleClick",{get:function(){return this._doubleClick},set:function(e){this._doubleClick=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"hasSwiped",{get:function(){return this._hasSwiped},set:function(e){this._hasSwiped=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"ignore",{get:function(){return this._ignore},set:function(e){this._ignore=e},enumerable:!0,configurable:!0}),e}(),i=function(){function e(){}return e.STAGE_PRECLEAR=1,e.STAGE_PREOPAQUE=2,e.STAGE_PRETRANSPARENT=3,e.STAGE_POSTTRANSPARENT=4,e}();e.RenderingGroupInfo=i;var r=function(){function i(t){this.autoClear=!0,this.autoClearDepthAndStencil=!0,this.clearColor=new e.Color4(.2,.2,.3,1),this.ambientColor=new e.Color3(0,0,0),this.forceWireframe=!1,this._forcePointsCloud=!1,this.forceShowBoundingBoxes=!1,this.animationsEnabled=!0,this.useConstantAnimationDeltaTime=!1,this.constantlyUpdateMeshUnderPointer=!1,this.hoverCursor="pointer",this.defaultCursor="",this.preventDefaultOnPointerDown=!0,this.metadata=null,this.onDisposeObservable=new e.Observable,this.onBeforeRenderObservable=new e.Observable,this.onAfterRenderObservable=new e.Observable,this.onBeforeAnimationsObservable=new e.Observable,this.onAfterAnimationsObservable=new e.Observable,this.onBeforeDrawPhaseObservable=new e.Observable,this.onAfterDrawPhaseObservable=new e.Observable,this.onBeforePhysicsObservable=new e.Observable,this.onAfterPhysicsObservable=new e.Observable,this.onReadyObservable=new e.Observable,this.onBeforeCameraRenderObservable=new e.Observable,this.onAfterCameraRenderObservable=new e.Observable,this.onBeforeActiveMeshesEvaluationObservable=new e.Observable,this.onAfterActiveMeshesEvaluationObservable=new e.Observable,this.onBeforeParticlesRenderingObservable=new e.Observable,this.onAfterParticlesRenderingObservable=new e.Observable,this.onBeforeSpritesRenderingObservable=new e.Observable,this.onAfterSpritesRenderingObservable=new e.Observable,this.onDataLoadedObservable=new e.Observable,this.onNewCameraAddedObservable=new e.Observable,this.onCameraRemovedObservable=new e.Observable,this.onNewLightAddedObservable=new e.Observable,this.onLightRemovedObservable=new e.Observable,this.onNewGeometryAddedObservable=new e.Observable,this.onGeometryRemovedObservable=new e.Observable,this.onNewTransformNodeAddedObservable=new e.Observable,this.onTransformNodeRemovedObservable=new e.Observable,this.onNewMeshAddedObservable=new e.Observable,this.onMeshRemovedObservable=new e.Observable,this.OnBeforeRenderTargetsRenderObservable=new e.Observable,this.OnAfterRenderTargetsRenderObservable=new e.Observable,this.onBeforeStepObservable=new e.Observable,this.onAfterStepObservable=new e.Observable,this.onRenderingGroupObservable=new e.Observable,this.animations=[],this.onPrePointerObservable=new e.Observable,this.onPointerObservable=new e.Observable,this._meshPickProceed=!1,this._currentPickResult=null,this._previousPickResult=null,this._totalPointersPressed=0,this._doubleClickOccured=!1,this.cameraToUseForPointers=null,this._startingPointerPosition=new e.Vector2(0,0),this._previousStartingPointerPosition=new e.Vector2(0,0),this._startingPointerTime=0,this._previousStartingPointerTime=0,this._timeAccumulator=0,this._currentStepId=0,this._currentInternalStep=0,this.onPreKeyboardObservable=new e.Observable,this.onKeyboardObservable=new e.Observable,this._useRightHandedSystem=!1,this._fogEnabled=!0,this._fogMode=i.FOGMODE_NONE,this.fogColor=new e.Color3(.2,.2,.3),this.fogDensity=.1,this.fogStart=0,this.fogEnd=1e3,this._shadowsEnabled=!0,this._lightsEnabled=!0,this.lights=new Array,this.cameras=new Array,this.activeCameras=new Array,this.transformNodes=new Array,this.meshes=new Array,this.animationGroups=new Array,this._geometries=new Array,this.materials=new Array,this.multiMaterials=new Array,this._texturesEnabled=!0,this.textures=new Array,this.particlesEnabled=!0,this.particleSystems=new Array,this.spritesEnabled=!0,this.spriteManagers=new Array,this.layers=new Array,this.highlightLayers=new Array,this._skeletonsEnabled=!0,this.skeletons=new Array,this.morphTargetManagers=new Array,this.lensFlaresEnabled=!0,this.lensFlareSystems=new Array,this.collisionsEnabled=!0,this.gravity=new e.Vector3(0,-9.807,0),this.postProcesses=new Array,this.postProcessesEnabled=!0,this.renderTargetsEnabled=!0,this.dumpNextRenderTargets=!1,this.customRenderTargets=new Array,this.importedMeshesFiles=new Array,this.probesEnabled=!0,this.reflectionProbes=new Array,this._actionManagers=new Array,this._meshesForIntersections=new e.SmartArrayNoDuplicate(256),this.proceduralTexturesEnabled=!0,this._proceduralTextures=new Array,this.soundTracks=new Array,this._audioEnabled=!0,this._headphone=!1,this._totalVertices=new e.PerfCounter,this._activeIndices=new e.PerfCounter,this._activeParticles=new e.PerfCounter,this._activeBones=new e.PerfCounter,this._animationTime=0,this.animationTimeScale=1,this._renderId=0,this._executeWhenReadyTimeoutId=-1,this._intermediateRendering=!1,this._viewUpdateFlag=-1,this._projectionUpdateFlag=-1,this._alternateViewUpdateFlag=-1,this._alternateProjectionUpdateFlag=-1,this._toBeDisposed=new e.SmartArray(256),this._activeRequests=new Array,this._pendingData=new Array,this._isDisposed=!1,this.dispatchAllSubMeshesOfActiveMeshes=!1,this._activeMeshes=new e.SmartArray(256),this._processedMaterials=new e.SmartArray(256),this._renderTargets=new e.SmartArrayNoDuplicate(256),this._activeParticleSystems=new e.SmartArray(256),this._activeSkeletons=new e.SmartArrayNoDuplicate(32),this._softwareSkinnedMeshes=new e.SmartArrayNoDuplicate(32),this._activeAnimatables=new Array,this._transformMatrix=e.Matrix.Zero(),this._useAlternateCameraConfiguration=!1,this._alternateRendering=!1,this.requireLightSorting=!1,this._activeMeshesFrozen=!1,this._tempPickingRay=e.Ray?e.Ray.Zero():null,this._engine=t||e.Engine.LastCreatedEngine,this._engine.scenes.push(this),this._uid=null,this._renderingManager=new e.RenderingManager(this),this.postProcessManager=new e.PostProcessManager(this),e.OutlineRenderer&&(this._outlineRenderer=new e.OutlineRenderer(this)),e.Tools.IsWindowObjectExist()&&this.attachControl(),e.SimplificationQueue&&(this.simplificationQueue=new e.SimplificationQueue),this.workerCollisions=!1,this._createUbo(),this._imageProcessingConfiguration=new e.ImageProcessingConfiguration}return Object.defineProperty(i,"FOGMODE_NONE",{get:function(){return i._FOGMODE_NONE},enumerable:!0,configurable:!0}),Object.defineProperty(i,"FOGMODE_EXP",{get:function(){return i._FOGMODE_EXP},enumerable:!0,configurable:!0}),Object.defineProperty(i,"FOGMODE_EXP2",{get:function(){return i._FOGMODE_EXP2},enumerable:!0,configurable:!0}),Object.defineProperty(i,"FOGMODE_LINEAR",{get:function(){return i._FOGMODE_LINEAR},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"environmentTexture",{get:function(){return this._environmentTexture},set:function(t){this._environmentTexture!==t&&(this._environmentTexture=t,this.markAllMaterialsAsDirty(e.Material.TextureDirtyFlag))},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"imageProcessingConfiguration",{get:function(){return this._imageProcessingConfiguration},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"forcePointsCloud",{get:function(){return this._forcePointsCloud},set:function(t){this._forcePointsCloud!==t&&(this._forcePointsCloud=t,this.markAllMaterialsAsDirty(e.Material.MiscDirtyFlag))},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"onDispose",{set:function(e){this._onDisposeObserver&&this.onDisposeObservable.remove(this._onDisposeObserver),this._onDisposeObserver=this.onDisposeObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"beforeRender",{set:function(e){this._onBeforeRenderObserver&&this.onBeforeRenderObservable.remove(this._onBeforeRenderObserver),e&&(this._onBeforeRenderObserver=this.onBeforeRenderObservable.add(e))},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"afterRender",{set:function(e){this._onAfterRenderObserver&&this.onAfterRenderObservable.remove(this._onAfterRenderObserver),e&&(this._onAfterRenderObserver=this.onAfterRenderObservable.add(e))},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"beforeCameraRender",{set:function(e){this._onBeforeCameraRenderObserver&&this.onBeforeCameraRenderObservable.remove(this._onBeforeCameraRenderObserver),this._onBeforeCameraRenderObserver=this.onBeforeCameraRenderObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"afterCameraRender",{set:function(e){this._onAfterCameraRenderObserver&&this.onAfterCameraRenderObservable.remove(this._onAfterCameraRenderObserver),this._onAfterCameraRenderObserver=this.onAfterCameraRenderObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"gamepadManager",{get:function(){return this._gamepadManager||(this._gamepadManager=new e.GamepadManager(this)),this._gamepadManager},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"unTranslatedPointer",{get:function(){return new e.Vector2(this._unTranslatedPointerX,this._unTranslatedPointerY)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"useRightHandedSystem",{get:function(){return this._useRightHandedSystem},set:function(t){this._useRightHandedSystem!==t&&(this._useRightHandedSystem=t,this.markAllMaterialsAsDirty(e.Material.MiscDirtyFlag))},enumerable:!0,configurable:!0}),i.prototype.setStepId=function(e){this._currentStepId=e},i.prototype.getStepId=function(){return this._currentStepId},i.prototype.getInternalStep=function(){return this._currentInternalStep},Object.defineProperty(i.prototype,"fogEnabled",{get:function(){return this._fogEnabled},set:function(t){this._fogEnabled!==t&&(this._fogEnabled=t,this.markAllMaterialsAsDirty(e.Material.MiscDirtyFlag))},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"fogMode",{get:function(){return this._fogMode},set:function(t){this._fogMode!==t&&(this._fogMode=t,this.markAllMaterialsAsDirty(e.Material.MiscDirtyFlag))},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"shadowsEnabled",{get:function(){return this._shadowsEnabled},set:function(t){this._shadowsEnabled!==t&&(this._shadowsEnabled=t,this.markAllMaterialsAsDirty(e.Material.LightDirtyFlag))},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"lightsEnabled",{get:function(){return this._lightsEnabled},set:function(t){this._lightsEnabled!==t&&(this._lightsEnabled=t,this.markAllMaterialsAsDirty(e.Material.LightDirtyFlag))},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"defaultMaterial",{get:function(){return this._defaultMaterial||(this._defaultMaterial=new e.StandardMaterial("default material",this)),this._defaultMaterial},set:function(e){this._defaultMaterial=e},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"texturesEnabled",{get:function(){return this._texturesEnabled},set:function(t){this._texturesEnabled!==t&&(this._texturesEnabled=t,this.markAllMaterialsAsDirty(e.Material.TextureDirtyFlag))},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"skeletonsEnabled",{get:function(){return this._skeletonsEnabled},set:function(t){this._skeletonsEnabled!==t&&(this._skeletonsEnabled=t,this.markAllMaterialsAsDirty(e.Material.AttributesDirtyFlag))},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"postProcessRenderPipelineManager",{get:function(){return this._postProcessRenderPipelineManager||(this._postProcessRenderPipelineManager=new e.PostProcessRenderPipelineManager),this._postProcessRenderPipelineManager},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"mainSoundTrack",{get:function(){return this._mainSoundTrack||(this._mainSoundTrack=new e.SoundTrack(this,{mainTrack:!0})),this._mainSoundTrack},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"_isAlternateRenderingEnabled",{get:function(){return this._alternateRendering},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"frustumPlanes",{get:function(){return this._frustumPlanes},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"debugLayer",{get:function(){return this._debugLayer||(this._debugLayer=new e.DebugLayer(this)),this._debugLayer},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"workerCollisions",{get:function(){return this._workerCollisions},set:function(t){e.CollisionCoordinatorLegacy&&(t=t&&!!Worker,this._workerCollisions=t,this.collisionCoordinator&&this.collisionCoordinator.destroy(),this.collisionCoordinator=t?new e.CollisionCoordinatorWorker:new e.CollisionCoordinatorLegacy,this.collisionCoordinator.init(this))},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"selectionOctree",{get:function(){return this._selectionOctree},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"meshUnderPointer",{get:function(){return this._pointerOverMesh},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"pointerX",{get:function(){return this._pointerX},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"pointerY",{get:function(){return this._pointerY},enumerable:!0,configurable:!0}),i.prototype.getCachedMaterial=function(){return this._cachedMaterial},i.prototype.getCachedEffect=function(){return this._cachedEffect},i.prototype.getCachedVisibility=function(){return this._cachedVisibility},i.prototype.isCachedMaterialInvalid=function(e,t,i){return void 0===i&&(i=1),this._cachedEffect!==t||this._cachedMaterial!==e||this._cachedVisibility!==i},i.prototype.getBoundingBoxRenderer=function(){return this._boundingBoxRenderer||(this._boundingBoxRenderer=new e.BoundingBoxRenderer(this)),this._boundingBoxRenderer},i.prototype.getOutlineRenderer=function(){return this._outlineRenderer},i.prototype.getEngine=function(){return this._engine},i.prototype.getTotalVertices=function(){return this._totalVertices.current},Object.defineProperty(i.prototype,"totalVerticesPerfCounter",{get:function(){return this._totalVertices},enumerable:!0,configurable:!0}),i.prototype.getActiveIndices=function(){return this._activeIndices.current},Object.defineProperty(i.prototype,"totalActiveIndicesPerfCounter",{get:function(){return this._activeIndices},enumerable:!0,configurable:!0}),i.prototype.getActiveParticles=function(){return this._activeParticles.current},Object.defineProperty(i.prototype,"activeParticlesPerfCounter",{get:function(){return this._activeParticles},enumerable:!0,configurable:!0}),i.prototype.getActiveBones=function(){return this._activeBones.current},Object.defineProperty(i.prototype,"activeBonesPerfCounter",{get:function(){return this._activeBones},enumerable:!0,configurable:!0}),i.prototype.getInterFramePerfCounter=function(){return e.Tools.Warn("getInterFramePerfCounter is deprecated. Please use SceneInstrumentation class"),0},Object.defineProperty(i.prototype,"interFramePerfCounter",{get:function(){return e.Tools.Warn("interFramePerfCounter is deprecated. Please use SceneInstrumentation class"),null},enumerable:!0,configurable:!0}),i.prototype.getLastFrameDuration=function(){return e.Tools.Warn("getLastFrameDuration is deprecated. Please use SceneInstrumentation class"),0},Object.defineProperty(i.prototype,"lastFramePerfCounter",{get:function(){return e.Tools.Warn("lastFramePerfCounter is deprecated. Please use SceneInstrumentation class"),null},enumerable:!0,configurable:!0}),i.prototype.getEvaluateActiveMeshesDuration=function(){return e.Tools.Warn("getEvaluateActiveMeshesDuration is deprecated. Please use SceneInstrumentation class"),0},Object.defineProperty(i.prototype,"evaluateActiveMeshesDurationPerfCounter",{get:function(){return e.Tools.Warn("evaluateActiveMeshesDurationPerfCounter is deprecated. Please use SceneInstrumentation class"),null},enumerable:!0,configurable:!0}),i.prototype.getActiveMeshes=function(){return this._activeMeshes},i.prototype.getRenderTargetsDuration=function(){return e.Tools.Warn("getRenderTargetsDuration is deprecated. Please use SceneInstrumentation class"),0},i.prototype.getRenderDuration=function(){return e.Tools.Warn("getRenderDuration is deprecated. Please use SceneInstrumentation class"),0},Object.defineProperty(i.prototype,"renderDurationPerfCounter",{get:function(){return e.Tools.Warn("renderDurationPerfCounter is deprecated. Please use SceneInstrumentation class"),null},enumerable:!0,configurable:!0}),i.prototype.getParticlesDuration=function(){return e.Tools.Warn("getParticlesDuration is deprecated. Please use SceneInstrumentation class"),0},Object.defineProperty(i.prototype,"particlesDurationPerfCounter",{get:function(){return e.Tools.Warn("particlesDurationPerfCounter is deprecated. Please use SceneInstrumentation class"),null},enumerable:!0,configurable:!0}),i.prototype.getSpritesDuration=function(){return e.Tools.Warn("getSpritesDuration is deprecated. Please use SceneInstrumentation class"),0},Object.defineProperty(i.prototype,"spriteDuractionPerfCounter",{get:function(){return e.Tools.Warn("spriteDuractionPerfCounter is deprecated. Please use SceneInstrumentation class"),null},enumerable:!0,configurable:!0}),i.prototype.getAnimationRatio=function(){return this._animationRatio},i.prototype.getRenderId=function(){return this._renderId},i.prototype.incrementRenderId=function(){this._renderId++},i.prototype._updatePointerPosition=function(e){var t=this._engine.getRenderingCanvasClientRect();t&&(this._pointerX=e.clientX-t.left,this._pointerY=e.clientY-t.top,this._unTranslatedPointerX=this._pointerX,this._unTranslatedPointerY=this._pointerY)},i.prototype._createUbo=function(){this._sceneUbo=new e.UniformBuffer(this._engine,void 0,!0),this._sceneUbo.addUniform("viewProjection",16),this._sceneUbo.addUniform("view",16)},i.prototype._createAlternateUbo=function(){this._alternateSceneUbo=new e.UniformBuffer(this._engine,void 0,!0),this._alternateSceneUbo.addUniform("viewProjection",16),this._alternateSceneUbo.addUniform("view",16)},i.prototype.simulatePointerMove=function(e){var t=new PointerEvent("pointermove");return this._processPointerMove(e,t)},i.prototype._processPointerMove=function(t,i){var r=this._engine.getRenderingCanvas();if(!r)return this;if(t&&t.hit&&t.pickedMesh?(this.setPointerOverSprite(null),this.setPointerOverMesh(t.pickedMesh),this._pointerOverMesh&&this._pointerOverMesh.actionManager&&this._pointerOverMesh.actionManager.hasPointerTriggers?this._pointerOverMesh.actionManager.hoverCursor?r.style.cursor=this._pointerOverMesh.actionManager.hoverCursor:r.style.cursor=this.hoverCursor:r.style.cursor=this.defaultCursor):(this.setPointerOverMesh(null),(t=this.pickSprite(this._unTranslatedPointerX,this._unTranslatedPointerY,this._spritePredicate,!1,this.cameraToUseForPointers||void 0))&&t.hit&&t.pickedSprite?(this.setPointerOverSprite(t.pickedSprite),this._pointerOverSprite&&this._pointerOverSprite.actionManager&&this._pointerOverSprite.actionManager.hoverCursor?r.style.cursor=this._pointerOverSprite.actionManager.hoverCursor:r.style.cursor=this.hoverCursor):(this.setPointerOverSprite(null),r.style.cursor=this.defaultCursor)),t&&(this.onPointerMove&&this.onPointerMove(i,t),this.onPointerObservable.hasObservers())){var n="mousewheel"===i.type||"DOMMouseScroll"===i.type?e.PointerEventTypes.POINTERWHEEL:e.PointerEventTypes.POINTERMOVE,o=new e.PointerInfo(n,i,t);this.onPointerObservable.notifyObservers(o,n)}return this},i.prototype.simulatePointerDown=function(e){var t=new PointerEvent("pointerdown");return this._processPointerDown(e,t)},i.prototype._processPointerDown=function(t,r){var n=this;if(t&&t.hit&&t.pickedMesh){this._pickedDownMesh=t.pickedMesh;var o=t.pickedMesh.actionManager;if(o){if(o.hasPickTriggers)switch(o.processTrigger(e.ActionManager.OnPickDownTrigger,e.ActionEvent.CreateNew(t.pickedMesh,r)),r.button){case 0:o.processTrigger(e.ActionManager.OnLeftPickTrigger,e.ActionEvent.CreateNew(t.pickedMesh,r));break;case 1:o.processTrigger(e.ActionManager.OnCenterPickTrigger,e.ActionEvent.CreateNew(t.pickedMesh,r));break;case 2:o.processTrigger(e.ActionManager.OnRightPickTrigger,e.ActionEvent.CreateNew(t.pickedMesh,r))}o.hasSpecificTrigger(e.ActionManager.OnLongPressTrigger)&&window.setTimeout(function(){var t=n.pick(n._unTranslatedPointerX,n._unTranslatedPointerY,function(t){return t.isPickable&&t.isVisible&&t.isReady()&&t.actionManager&&t.actionManager.hasSpecificTrigger(e.ActionManager.OnLongPressTrigger)&&t==n._pickedDownMesh},!1,n.cameraToUseForPointers);t&&t.hit&&t.pickedMesh&&o&&0!==n._totalPointersPressed&&(new Date).getTime()-n._startingPointerTime>i.LongPressDelay&&Math.abs(n._startingPointerPosition.x-n._pointerX)<i.DragMovementThreshold&&Math.abs(n._startingPointerPosition.y-n._pointerY)<i.DragMovementThreshold&&(n._startingPointerTime=0,o.processTrigger(e.ActionManager.OnLongPressTrigger,e.ActionEvent.CreateNew(t.pickedMesh,r)))},i.LongPressDelay)}}if(t&&(this.onPointerDown&&this.onPointerDown(r,t),this.onPointerObservable.hasObservers())){var s=e.PointerEventTypes.POINTERDOWN,a=new e.PointerInfo(s,r,t);this.onPointerObservable.notifyObservers(a,s)}return this},i.prototype.simulatePointerUp=function(e){var i=new PointerEvent("pointerup"),r=new t;return r.singleClick=!0,r.ignore=!0,this._processPointerUp(e,i,r)},i.prototype._processPointerUp=function(t,i,r){if(t&&t&&t.pickedMesh){if(this._pickedUpMesh=t.pickedMesh,this._pickedDownMesh===this._pickedUpMesh&&(this.onPointerPick&&this.onPointerPick(i,t),r.singleClick&&!r.ignore&&this.onPointerObservable.hasObservers())){var n=e.PointerEventTypes.POINTERPICK,o=new e.PointerInfo(n,i,t);this.onPointerObservable.notifyObservers(o,n)}t.pickedMesh.actionManager&&(r.ignore&&t.pickedMesh.actionManager.processTrigger(e.ActionManager.OnPickUpTrigger,e.ActionEvent.CreateNew(t.pickedMesh,i)),r.hasSwiped||r.ignore||!r.singleClick||t.pickedMesh.actionManager.processTrigger(e.ActionManager.OnPickTrigger,e.ActionEvent.CreateNew(t.pickedMesh,i)),r.doubleClick&&!r.ignore&&t.pickedMesh.actionManager.hasSpecificTrigger(e.ActionManager.OnDoublePickTrigger)&&t.pickedMesh.actionManager.processTrigger(e.ActionManager.OnDoublePickTrigger,e.ActionEvent.CreateNew(t.pickedMesh,i)))}if(this._pickedDownMesh&&this._pickedDownMesh.actionManager&&this._pickedDownMesh.actionManager.hasSpecificTrigger(e.ActionManager.OnPickOutTrigger)&&this._pickedDownMesh!==this._pickedUpMesh&&this._pickedDownMesh.actionManager.processTrigger(e.ActionManager.OnPickOutTrigger,e.ActionEvent.CreateNew(this._pickedDownMesh,i)),this.onPointerUp&&this.onPointerUp(i,t),this.onPointerObservable.hasObservers())if(r.ignore){n=e.PointerEventTypes.POINTERUP,o=new e.PointerInfo(n,i,t);this.onPointerObservable.notifyObservers(o,n)}else if(!r.hasSwiped){if(r.singleClick&&this.onPointerObservable.hasSpecificMask(e.PointerEventTypes.POINTERTAP)){var n=e.PointerEventTypes.POINTERTAP,o=new e.PointerInfo(n,i,t);this.onPointerObservable.notifyObservers(o,n)}if(r.doubleClick&&this.onPointerObservable.hasSpecificMask(e.PointerEventTypes.POINTERDOUBLETAP)){n=e.PointerEventTypes.POINTERDOUBLETAP,o=new e.PointerInfo(n,i,t);this.onPointerObservable.notifyObservers(o,n)}}return this},i.prototype.attachControl=function(r,n,o){var s=this;void 0===r&&(r=!0),void 0===n&&(n=!0),void 0===o&&(o=!0),this._initActionManager=function(e,t){if(!s._meshPickProceed){var i=s.pick(s._unTranslatedPointerX,s._unTranslatedPointerY,s.pointerDownPredicate,!1,s.cameraToUseForPointers);s._currentPickResult=i,i&&(e=i.hit&&i.pickedMesh?i.pickedMesh.actionManager:null),s._meshPickProceed=!0}return e},this._delayedSimpleClick=function(e,t,r){((new Date).getTime()-s._previousStartingPointerTime>i.DoubleClickDelay&&!s._doubleClickOccured||e!==s._previousButtonPressed)&&(s._doubleClickOccured=!1,t.singleClick=!0,t.ignore=!1,r(t,s._currentPickResult))},this._initClickEvent=function(r,n,o,a){var 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._previousStartingPointerTime<i.DoubleClickDelay&&!s._doubleClickOccured?!h.hasSwiped&&Math.abs(s._previousStartingPointerPosition.x-s._startingPointerPosition.x)<i.DragMovementThreshold&&Math.abs(s._previousStartingPointerPosition.y-s._startingPointerPosition.y)<i.DragMovementThreshold?(s._previousStartingPointerTime=0,s._doubleClickOccured=!0,h.doubleClick=!0,h.ignore=!1,i.ExclusiveDoubleClickMode&&s._previousDelayedSimpleClickTimeout&&clearTimeout(s._previousDelayedSimpleClickTimeout),s._previousDelayedSimpleClickTimeout=s._delayedSimpleClickTimeout,a(h,s._currentPickResult)):(s._doubleClickOccured=!1,s._previousStartingPointerTime=s._startingPointerTime,s._previousStartingPointerPosition.x=s._startingPointerPosition.x,s._previousStartingPointerPosition.y=s._startingPointerPosition.y,s._previousButtonPressed=u,i.ExclusiveDoubleClickMode?(s._previousDelayedSimpleClickTimeout&&clearTimeout(s._previousDelayedSimpleClickTimeout),s._previousDelayedSimpleClickTimeout=s._delayedSimpleClickTimeout,a(h,s._previousPickResult)):a(h,s._currentPickResult)):(s._doubleClickOccured=!1,s._previousStartingPointerTime=s._startingPointerTime,s._previousStartingPointerPosition.x=s._startingPointerPosition.x,s._previousStartingPointerPosition.y=s._startingPointerPosition.y,s._previousButtonPressed=u))}}h.ignore=!0,a(h,s._currentPickResult)},this._spritePredicate=function(e){return e.isPickable&&e.actionManager&&e.actionManager.hasPointerTriggers},this._onPointerMove=function(t){if(s._updatePointerPosition(t),s.onPrePointerObservable.hasObservers()){var i="mousewheel"===t.type||"DOMMouseScroll"===t.type?e.PointerEventTypes.POINTERWHEEL:e.PointerEventTypes.POINTERMOVE,r=new e.PointerInfoPre(i,t,s._unTranslatedPointerX,s._unTranslatedPointerY);if(s.onPrePointerObservable.notifyObservers(r,i),r.skipOnPointerObservable)return}if(s.cameraToUseForPointers||s.activeCamera){s.pointerMovePredicate||(s.pointerMovePredicate=function(e){return e.isPickable&&e.isVisible&&e.isReady()&&e.isEnabled()&&(e.enablePointerMoveEvents||s.constantlyUpdateMeshUnderPointer||null!==e.actionManager&&void 0!==e.actionManager)});var n=s.pick(s._unTranslatedPointerX,s._unTranslatedPointerY,s.pointerMovePredicate,!1,s.cameraToUseForPointers);s._processPointerMove(n,t)}},this._onPointerDown=function(t){if(s._totalPointersPressed++,s._pickedDownMesh=null,s._meshPickProceed=!1,s._updatePointerPosition(t),s.preventDefaultOnPointerDown&&l&&(t.preventDefault(),l.focus()),s.onPrePointerObservable.hasObservers()){var i=e.PointerEventTypes.POINTERDOWN,r=new e.PointerInfoPre(i,t,s._unTranslatedPointerX,s._unTranslatedPointerY);if(s.onPrePointerObservable.notifyObservers(r,i),r.skipOnPointerObservable)return}if(s.cameraToUseForPointers||s.activeCamera){s._startingPointerPosition.x=s._pointerX,s._startingPointerPosition.y=s._pointerY,s._startingPointerTime=(new Date).getTime(),s.pointerDownPredicate||(s.pointerDownPredicate=function(e){return e.isPickable&&e.isVisible&&e.isReady()&&e.isEnabled()}),s._pickedDownMesh=null;var n=s.pick(s._unTranslatedPointerX,s._unTranslatedPointerY,s.pointerDownPredicate,!1,s.cameraToUseForPointers);if(s._processPointerDown(n,t),s._pickedDownSprite=null,s.spriteManagers.length>0&&(n=s.pickSprite(s._unTranslatedPointerX,s._unTranslatedPointerY,s._spritePredicate,!1,s.cameraToUseForPointers||void 0))&&n.hit&&n.pickedSprite&&n.pickedSprite.actionManager){switch(s._pickedDownSprite=n.pickedSprite,t.button){case 0:n.pickedSprite.actionManager.processTrigger(e.ActionManager.OnLeftPickTrigger,e.ActionEvent.CreateNewFromSprite(n.pickedSprite,s,t));break;case 1:n.pickedSprite.actionManager.processTrigger(e.ActionManager.OnCenterPickTrigger,e.ActionEvent.CreateNewFromSprite(n.pickedSprite,s,t));break;case 2:n.pickedSprite.actionManager.processTrigger(e.ActionManager.OnRightPickTrigger,e.ActionEvent.CreateNewFromSprite(n.pickedSprite,s,t))}n.pickedSprite.actionManager&&n.pickedSprite.actionManager.processTrigger(e.ActionManager.OnPickDownTrigger,e.ActionEvent.CreateNewFromSprite(n.pickedSprite,s,t))}}},this._onPointerUp=function(t){0!==s._totalPointersPressed&&(s._totalPointersPressed--,s._pickedUpMesh=null,s._meshPickProceed=!1,s._updatePointerPosition(t),s._initClickEvent(s.onPrePointerObservable,s.onPointerObservable,t,function(r,n){if(s.onPrePointerObservable.hasObservers())if(r.ignore){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)<i.DragMovementThreshold&&Math.abs(s._startingPointerPosition.y-s._pointerY)<i.DragMovementThreshold&&h.pickedSprite.actionManager.processTrigger(e.ActionManager.OnPickTrigger,e.ActionEvent.CreateNewFromSprite(h.pickedSprite,s,t))),s._pickedDownSprite&&s._pickedDownSprite.actionManager&&s._pickedDownSprite!==h.pickedSprite&&s._pickedDownSprite.actionManager.processTrigger(e.ActionManager.OnPickOutTrigger,e.ActionEvent.CreateNewFromSprite(s._pickedDownSprite,s,t)))}s._previousPickResult=s._currentPickResult}}))},this._onKeyDown=function(t){var i=e.KeyboardEventTypes.KEYDOWN;if(s.onPreKeyboardObservable.hasObservers()){var r=new e.KeyboardInfoPre(i,t);if(s.onPreKeyboardObservable.notifyObservers(r,i),r.skipOnPointerObservable)return}if(s.onKeyboardObservable.hasObservers()){r=new e.KeyboardInfo(i,t);s.onKeyboardObservable.notifyObservers(r,i)}s.actionManager&&s.actionManager.processTrigger(e.ActionManager.OnKeyDownTrigger,e.ActionEvent.CreateNewFromScene(s,t))},this._onKeyUp=function(t){var i=e.KeyboardEventTypes.KEYUP;if(s.onPreKeyboardObservable.hasObservers()){var r=new e.KeyboardInfoPre(i,t);if(s.onPreKeyboardObservable.notifyObservers(r,i),r.skipOnPointerObservable)return}if(s.onKeyboardObservable.hasObservers()){r=new e.KeyboardInfo(i,t);s.onKeyboardObservable.notifyObservers(r,i)}s.actionManager&&s.actionManager.processTrigger(e.ActionManager.OnKeyUpTrigger,e.ActionEvent.CreateNewFromScene(s,t))};var a=this.getEngine();this._onCanvasFocusObserver=a.onCanvasFocusObservable.add(function(){l&&(l.addEventListener("keydown",s._onKeyDown,!1),l.addEventListener("keyup",s._onKeyUp,!1))}),this._onCanvasBlurObserver=a.onCanvasBlurObservable.add(function(){l&&(l.removeEventListener("keydown",s._onKeyDown),l.removeEventListener("keyup",s._onKeyUp))});var h=e.Tools.GetPointerPrefix(),l=this._engine.getRenderingCanvas();l&&(o&&(l.addEventListener(h+"move",this._onPointerMove,!1),l.addEventListener("mousewheel",this._onPointerMove,!1),l.addEventListener("DOMMouseScroll",this._onPointerMove,!1)),n&&l.addEventListener(h+"down",this._onPointerDown,!1),r&&window.addEventListener(h+"up",this._onPointerUp,!1),l.tabIndex=1)},i.prototype.detachControl=function(){var t=this.getEngine(),i=e.Tools.GetPointerPrefix(),r=t.getRenderingCanvas();r&&(r.removeEventListener(i+"move",this._onPointerMove),r.removeEventListener(i+"down",this._onPointerDown),window.removeEventListener(i+"up",this._onPointerUp),this._onCanvasBlurObserver&&t.onCanvasBlurObservable.remove(this._onCanvasBlurObserver),this._onCanvasFocusObserver&&t.onCanvasFocusObservable.remove(this._onCanvasFocusObserver),r.removeEventListener("mousewheel",this._onPointerMove),r.removeEventListener("DOMMouseScroll",this._onPointerMove),r.removeEventListener("keydown",this._onKeyDown),r.removeEventListener("keyup",this._onKeyUp),this.onKeyboardObservable.clear(),this.onPreKeyboardObservable.clear(),this.onPointerObservable.clear(),this.onPrePointerObservable.clear())},i.prototype.isReady=function(){if(this._isDisposed)return!1;if(this._pendingData.length>0)return!1;var t,i=this.getEngine();for(t=0;t<this._geometries.length;t++){if(this._geometries[t].delayLoadState===e.Engine.DELAYLOADSTATE_LOADING)return!1}for(t=0;t<this.meshes.length;t++){var r=this.meshes[t];if(r.isEnabled()&&(r.subMeshes&&0!==r.subMeshes.length)){if(!r.isReady())return!1;for(var n="InstancedMesh"===r.getClassName()||i.getCaps().instancedArrays&&r.instances.length>0,o=0,s=this.highlightLayers;o<s.length;o++){var a=s[o];if(a.hasMesh(r))for(var h=0,l=r.subMeshes;h<l.length;h++){var c=l[h];if(!a.isReady(c,n))return!1}}}}return!0},i.prototype.resetCachedMaterial=function(){this._cachedMaterial=null,this._cachedEffect=null,this._cachedVisibility=null},i.prototype.registerBeforeRender=function(e){this.onBeforeRenderObservable.add(e)},i.prototype.unregisterBeforeRender=function(e){this.onBeforeRenderObservable.removeCallback(e)},i.prototype.registerAfterRender=function(e){this.onAfterRenderObservable.add(e)},i.prototype.unregisterAfterRender=function(e){this.onAfterRenderObservable.removeCallback(e)},i.prototype._executeOnceBeforeRender=function(e){var t=this,i=function(){e(),setTimeout(function(){t.unregisterBeforeRender(i)})};this.registerBeforeRender(i)},i.prototype.executeOnceBeforeRender=function(e,t){var i=this;void 0!==t?setTimeout(function(){i._executeOnceBeforeRender(e)},t):this._executeOnceBeforeRender(e)},i.prototype._addPendingData=function(e){this._pendingData.push(e)},i.prototype._removePendingData=function(e){var t=this.isLoading,i=this._pendingData.indexOf(e);-1!==i&&this._pendingData.splice(i,1),t&&!this.isLoading&&this.onDataLoadedObservable.notifyObservers(this)},i.prototype.getWaitingItemsCount=function(){return this._pendingData.length},Object.defineProperty(i.prototype,"isLoading",{get:function(){return this._pendingData.length>0},enumerable:!0,configurable:!0}),i.prototype.executeWhenReady=function(e){var t=this;this.onReadyObservable.add(e),-1===this._executeWhenReadyTimeoutId&&(this._executeWhenReadyTimeoutId=setTimeout(function(){t._checkIsReady()},150))},i.prototype._checkIsReady=function(){var e=this;if(this.isReady())return this.onReadyObservable.notifyObservers(this),this.onReadyObservable.clear(),void(this._executeWhenReadyTimeoutId=-1);this._executeWhenReadyTimeoutId=setTimeout(function(){e._checkIsReady()},150)},i.prototype.beginAnimation=function(t,i,r,n,o,s,a){if(void 0===o&&(o=1),i>r&&o>0&&(o*=-1),this.stopAnimation(t),a||(a=new e.Animatable(this,t,i,r,n,o,s)),t.animations&&a.appendAnimations(t,t.animations),t.getAnimatables)for(var h=t.getAnimatables(),l=0;l<h.length;l++)this.beginAnimation(h[l],i,r,n,o,s,a);return a.reset(),a},i.prototype.beginDirectAnimation=function(t,i,r,n,o,s,a){return void 0===s&&(s=1),new e.Animatable(this,t,r,n,o,s,a,i)},i.prototype.beginDirectHierarchyAnimation=function(e,t,i,r,n,o,s,a){for(var h=[],l=0,c=e.getDescendants(t);l<c.length;l++){var u=c[l];h.push(this.beginDirectAnimation(u,i,r,n,o,s,a))}return h},i.prototype.getAnimatableByTarget=function(e){for(var t=0;t<this._activeAnimatables.length;t++)if(this._activeAnimatables[t].target===e)return this._activeAnimatables[t];return null},Object.defineProperty(i.prototype,"animatables",{get:function(){return this._activeAnimatables},enumerable:!0,configurable:!0}),i.prototype.stopAnimation=function(e,t){var i=this.getAnimatableByTarget(e);i&&i.stop(t)},i.prototype.stopAllAnimations=function(){if(this._activeAnimatables){for(var e=0;e<this._activeAnimatables.length;e++)this._activeAnimatables[e].stop();this._activeAnimatables=[]}},i.prototype._animate=function(){if(this.animationsEnabled&&0!==this._activeAnimatables.length){var t=e.Tools.Now;if(!this._animationTimeLast){if(this._pendingData.length>0)return;this._animationTimeLast=t}var i=this.useConstantAnimationDeltaTime?16:(t-this._animationTimeLast)*this.animationTimeScale;this._animationTime+=i,this._animationTimeLast=t;for(var r=0;r<this._activeAnimatables.length;r++)this._activeAnimatables[r]._animate(this._animationTime)}},i.prototype._switchToAlternateCameraConfiguration=function(e){this._useAlternateCameraConfiguration=e},i.prototype.getViewMatrix=function(){return this._useAlternateCameraConfiguration?this._alternateViewMatrix:this._viewMatrix},i.prototype.getProjectionMatrix=function(){return this._useAlternateCameraConfiguration?this._alternateProjectionMatrix:this._projectionMatrix},i.prototype.getTransformMatrix=function(){return this._useAlternateCameraConfiguration?this._alternateTransformMatrix:this._transformMatrix},i.prototype.setTransformMatrix=function(t,i){if(this._viewUpdateFlag!==t.updateFlag||this._projectionUpdateFlag!==i.updateFlag){if(this._viewUpdateFlag=t.updateFlag,this._projectionUpdateFlag=i.updateFlag,this._viewMatrix=t,this._projectionMatrix=i,this._viewMatrix.multiplyToRef(this._projectionMatrix,this._transformMatrix),this._frustumPlanes?e.Frustum.GetPlanesToRef(this._transformMatrix,this._frustumPlanes):this._frustumPlanes=e.Frustum.GetPlanes(this._transformMatrix),this.activeCamera&&this.activeCamera._alternateCamera){var r=this.activeCamera._alternateCamera;r.getViewMatrix().multiplyToRef(r.getProjectionMatrix(),e.Tmp.Matrix[0]),e.Frustum.GetRightPlaneToRef(e.Tmp.Matrix[0],this._frustumPlanes[3])}this._sceneUbo.useUbo&&(this._sceneUbo.updateMatrix("viewProjection",this._transformMatrix),this._sceneUbo.updateMatrix("view",this._viewMatrix),this._sceneUbo.update())}},i.prototype._setAlternateTransformMatrix=function(t,i){this._alternateViewUpdateFlag===t.updateFlag&&this._alternateProjectionUpdateFlag===i.updateFlag||(this._alternateViewUpdateFlag=t.updateFlag,this._alternateProjectionUpdateFlag=i.updateFlag,this._alternateViewMatrix=t,this._alternateProjectionMatrix=i,this._alternateTransformMatrix||(this._alternateTransformMatrix=e.Matrix.Zero()),this._alternateViewMatrix.multiplyToRef(this._alternateProjectionMatrix,this._alternateTransformMatrix),this._alternateSceneUbo||this._createAlternateUbo(),this._alternateSceneUbo.useUbo&&(this._alternateSceneUbo.updateMatrix("viewProjection",this._alternateTransformMatrix),this._alternateSceneUbo.updateMatrix("view",this._alternateViewMatrix),this._alternateSceneUbo.update()))},i.prototype.getSceneUniformBuffer=function(){return this._useAlternateCameraConfiguration?this._alternateSceneUbo:this._sceneUbo},i.prototype.getUniqueId=function(){var e=i._uniqueIdCounter;return i._uniqueIdCounter++,e},i.prototype.addMesh=function(e){this.meshes.push(e),this.collisionCoordinator&&this.collisionCoordinator.onMeshAdded(e),e._resyncLightSources(),this.onNewMeshAddedObservable.notifyObservers(e)},i.prototype.removeMesh=function(e){var t=this.meshes.indexOf(e);return-1!==t&&this.meshes.splice(t,1),this.onMeshRemovedObservable.notifyObservers(e),t},i.prototype.addTransformNode=function(e){this.transformNodes.push(e),this.onNewTransformNodeAddedObservable.notifyObservers(e)},i.prototype.removeTransformNode=function(e){var t=this.transformNodes.indexOf(e);return-1!==t&&this.transformNodes.splice(t,1),this.onTransformNodeRemovedObservable.notifyObservers(e),t},i.prototype.removeSkeleton=function(e){var t=this.skeletons.indexOf(e);return-1!==t&&this.skeletons.splice(t,1),t},i.prototype.removeMorphTargetManager=function(e){var t=this.morphTargetManagers.indexOf(e);return-1!==t&&this.morphTargetManagers.splice(t,1),t},i.prototype.removeLight=function(e){var t=this.lights.indexOf(e);if(-1!==t){for(var i=0,r=this.meshes;i<r.length;i++){r[i]._removeLightSource(e)}this.lights.splice(t,1),this.sortLightsByPriority()}return this.onLightRemovedObservable.notifyObservers(e),t},i.prototype.removeCamera=function(e){var t=this.cameras.indexOf(e);-1!==t&&this.cameras.splice(t,1);var i=this.activeCameras.indexOf(e);return-1!==i&&this.activeCameras.splice(i,1),this.activeCamera===e&&(this.cameras.length>0?this.activeCamera=this.cameras[0]:this.activeCamera=null),this.onCameraRemovedObservable.notifyObservers(e),t},i.prototype.removeParticleSystem=function(e){var t=this.particleSystems.indexOf(e);return-1!==t&&this.particleSystems.splice(t,1),t},i.prototype.removeAnimation=function(e){var t=this.animations.indexOf(e);return-1!==t&&this.animations.splice(t,1),t},i.prototype.removeMultiMaterial=function(e){var t=this.multiMaterials.indexOf(e);return-1!==t&&this.multiMaterials.splice(t,1),t},i.prototype.removeMaterial=function(e){var t=this.materials.indexOf(e);return-1!==t&&this.materials.splice(t,1),t},i.prototype.removeLensFlareSystem=function(e){var t=this.lensFlareSystems.indexOf(e);return-1!==t&&this.lensFlareSystems.splice(t,1),t},i.prototype.removeActionManager=function(e){var t=this._actionManagers.indexOf(e);return-1!==t&&this._actionManagers.splice(t,1),t},i.prototype.addLight=function(e){this.lights.push(e),this.sortLightsByPriority();for(var t=0,i=this.meshes;t<i.length;t++){var r=i[t];-1===r._lightSources.indexOf(e)&&(r._lightSources.push(e),r._resyncLightSources())}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.addSkeleton=function(e){this.skeletons.push(e)},i.prototype.addParticleSystem=function(e){this.particleSystems.push(e)},i.prototype.addAnimation=function(e){this.animations.push(e)},i.prototype.addMultiMaterial=function(e){this.multiMaterials.push(e)},i.prototype.addMaterial=function(e){this.materials.push(e)},i.prototype.addMorphTargetManager=function(e){this.morphTargetManagers.push(e)},i.prototype.addGeometry=function(e){this._geometries.push(e)},i.prototype.addLensFlareSystem=function(e){this.lensFlareSystems.push(e)},i.prototype.addActionManager=function(e){this._actionManagers.push(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.getAnimationGroupByName=function(e){for(var t=0;t<this.animationGroups.length;t++)if(this.animationGroups[t].name===e)return this.animationGroups[t];return null},i.prototype.getMaterialByID=function(e){for(var t=0;t<this.materials.length;t++)if(this.materials[t].id===e)return this.materials[t];return null},i.prototype.getMaterialByName=function(e){for(var t=0;t<this.materials.length;t++)if(this.materials[t].name===e)return this.materials[t];return null},i.prototype.getLensFlareSystemByName=function(e){for(var t=0;t<this.lensFlareSystems.length;t++)if(this.lensFlareSystems[t].name===e)return this.lensFlareSystems[t];return null},i.prototype.getLensFlareSystemByID=function(e){for(var t=0;t<this.lensFlareSystems.length;t++)if(this.lensFlareSystems[t].id===e)return this.lensFlareSystems[t];return null},i.prototype.getCameraByID=function(e){for(var t=0;t<this.cameras.length;t++)if(this.cameras[t].id===e)return this.cameras[t];return null},i.prototype.getCameraByUniqueID=function(e){for(var t=0;t<this.cameras.length;t++)if(this.cameras[t].uniqueId===e)return this.cameras[t];return null},i.prototype.getCameraByName=function(e){for(var t=0;t<this.cameras.length;t++)if(this.cameras[t].name===e)return this.cameras[t];return null},i.prototype.getBoneByID=function(e){for(var t=0;t<this.skeletons.length;t++)for(var i=this.skeletons[t],r=0;r<i.bones.length;r++)if(i.bones[r].id===e)return i.bones[r];return null},i.prototype.getBoneByName=function(e){for(var t=0;t<this.skeletons.length;t++)for(var i=this.skeletons[t],r=0;r<i.bones.length;r++)if(i.bones[r].name===e)return i.bones[r];return null},i.prototype.getLightByName=function(e){for(var t=0;t<this.lights.length;t++)if(this.lights[t].name===e)return this.lights[t];return null},i.prototype.getLightByID=function(e){for(var t=0;t<this.lights.length;t++)if(this.lights[t].id===e)return this.lights[t];return null},i.prototype.getLightByUniqueID=function(e){for(var t=0;t<this.lights.length;t++)if(this.lights[t].uniqueId===e)return this.lights[t];return null},i.prototype.getParticleSystemByID=function(e){for(var t=0;t<this.particleSystems.length;t++)if(this.particleSystems[t].id===e)return this.particleSystems[t];return null},i.prototype.getGeometryByID=function(e){for(var t=0;t<this._geometries.length;t++)if(this._geometries[t].id===e)return this._geometries[t];return null},i.prototype.pushGeometry=function(e,t){return!(!t&&this.getGeometryByID(e.id))&&(this._geometries.push(e),this.collisionCoordinator&&this.collisionCoordinator.onGeometryAdded(e),this.onNewGeometryAddedObservable.notifyObservers(e),!0)},i.prototype.removeGeometry=function(e){var t=this._geometries.indexOf(e);return t>-1&&(this._geometries.splice(t,1),this.collisionCoordinator&&this.collisionCoordinator.onGeometryDeleted(e),this.onGeometryRemovedObservable.notifyObservers(e),!0)},i.prototype.getGeometries=function(){return this._geometries},i.prototype.getMeshByID=function(e){for(var t=0;t<this.meshes.length;t++)if(this.meshes[t].id===e)return this.meshes[t];return null},i.prototype.getMeshesByID=function(e){return this.meshes.filter(function(t){return t.id===e})},i.prototype.getTransformNodeByID=function(e){for(var t=0;t<this.transformNodes.length;t++)if(this.transformNodes[t].id===e)return this.transformNodes[t];return null},i.prototype.getTransformNodesByID=function(e){return this.transformNodes.filter(function(t){return t.id===e})},i.prototype.getMeshByUniqueID=function(e){for(var t=0;t<this.meshes.length;t++)if(this.meshes[t].uniqueId===e)return this.meshes[t];return null},i.prototype.getLastMeshByID=function(e){for(var t=this.meshes.length-1;t>=0;t--)if(this.meshes[t].id===e)return this.meshes[t];return null},i.prototype.getLastEntryByID=function(e){var t;for(t=this.meshes.length-1;t>=0;t--)if(this.meshes[t].id===e)return this.meshes[t];for(t=this.transformNodes.length-1;t>=0;t--)if(this.transformNodes[t].id===e)return this.transformNodes[t];for(t=this.cameras.length-1;t>=0;t--)if(this.cameras[t].id===e)return this.cameras[t];for(t=this.lights.length-1;t>=0;t--)if(this.lights[t].id===e)return this.lights[t];return null},i.prototype.getNodeByID=function(e){var t=this.getMeshByID(e);if(t)return t;var i=this.getLightByID(e);if(i)return i;var r=this.getCameraByID(e);return r||this.getBoneByID(e)},i.prototype.getNodeByName=function(e){var t=this.getMeshByName(e);if(t)return t;var i=this.getLightByName(e);if(i)return i;var r=this.getCameraByName(e);return r||this.getBoneByName(e)},i.prototype.getMeshByName=function(e){for(var t=0;t<this.meshes.length;t++)if(this.meshes[t].name===e)return this.meshes[t];return null},i.prototype.getTransformNodeByName=function(e){for(var t=0;t<this.transformNodes.length;t++)if(this.transformNodes[t].name===e)return this.transformNodes[t];return null},i.prototype.getSoundByName=function(t){var i;if(e.AudioEngine){for(i=0;i<this.mainSoundTrack.soundCollection.length;i++)if(this.mainSoundTrack.soundCollection[i].name===t)return this.mainSoundTrack.soundCollection[i];for(var r=0;r<this.soundTracks.length;r++)for(i=0;i<this.soundTracks[r].soundCollection.length;i++)if(this.soundTracks[r].soundCollection[i].name===t)return this.soundTracks[r].soundCollection[i]}return null},i.prototype.getLastSkeletonByID=function(e){for(var t=this.skeletons.length-1;t>=0;t--)if(this.skeletons[t].id===e)return this.skeletons[t];return null},i.prototype.getSkeletonById=function(e){for(var t=0;t<this.skeletons.length;t++)if(this.skeletons[t].id===e)return this.skeletons[t];return null},i.prototype.getSkeletonByName=function(e){for(var t=0;t<this.skeletons.length;t++)if(this.skeletons[t].name===e)return this.skeletons[t];return null},i.prototype.getMorphTargetManagerById=function(e){for(var t=0;t<this.morphTargetManagers.length;t++)if(this.morphTargetManagers[t].uniqueId===e)return this.morphTargetManagers[t];return null},i.prototype.isActiveMesh=function(e){return-1!==this._activeMeshes.indexOf(e)},i.prototype.getHighlightLayerByName=function(e){for(var t=0;t<this.highlightLayers.length;t++)if(this.highlightLayers[t].name===e)return this.highlightLayers[t];return null},Object.defineProperty(i.prototype,"uid",{get:function(){return this._uid||(this._uid=e.Tools.RandomId()),this._uid},enumerable:!0,configurable:!0}),i.prototype.addExternalData=function(t,i){return this._externalData||(this._externalData=new e.StringDictionary),this._externalData.add(t,i)},i.prototype.getExternalData=function(e){return this._externalData?this._externalData.get(e):null},i.prototype.getOrAddExternalDataWithFactory=function(t,i){return this._externalData||(this._externalData=new e.StringDictionary),this._externalData.getOrAddWithFactory(t,i)},i.prototype.removeExternalData=function(e){return this._externalData.remove(e)},i.prototype._evaluateSubMesh=function(e,t){if(this.dispatchAllSubMeshesOfActiveMeshes||t.alwaysSelectAsActiveMesh||1===t.subMeshes.length||e.isInFrustum(this._frustumPlanes)){if(t.showSubMeshesBoundingBox){var i=e.getBoundingInfo();null!==i&&void 0!==i&&this.getBoundingBoxRenderer().renderList.push(i.boundingBox)}var r=e.getMaterial();null!==r&&void 0!==r&&(void 0!==r.getRenderTargetTextures&&-1===this._processedMaterials.indexOf(r)&&(this._processedMaterials.push(r),this._renderTargets.concatWithNoDuplicate(r.getRenderTargetTextures())),this._activeIndices.addCount(e.indexCount,!1),this._renderingManager.dispatch(e,t,r))}},i.prototype._isInIntermediateRendering=function(){return this._intermediateRendering},i.prototype.setActiveMeshCandidateProvider=function(e){this._activeMeshCandidateProvider=e},i.prototype.getActiveMeshCandidateProvider=function(){return this._activeMeshCandidateProvider},i.prototype.freezeActiveMeshes=function(){return this._evaluateActiveMeshes(),this._activeMeshesFrozen=!0,this},i.prototype.unfreezeActiveMeshes=function(){return this._activeMeshesFrozen=!1,this},i.prototype._evaluateActiveMeshes=function(){if((!this._activeMeshesFrozen||!this._activeMeshes.length)&&this.activeCamera){var t,i;this.onBeforeActiveMeshesEvaluationObservable.notifyObservers(this),this.activeCamera._activeMeshes.reset(),this._activeMeshes.reset(),this._renderingManager.reset(),this._processedMaterials.reset(),this._activeParticleSystems.reset(),this._activeSkeletons.reset(),this._softwareSkinnedMeshes.reset(),this._boundingBoxRenderer&&this._boundingBoxRenderer.reset();var r=!0;if(void 0!==this._activeMeshCandidateProvider)t=this._activeMeshCandidateProvider.getMeshes(this),r=!1===this._activeMeshCandidateProvider.checksIsEnabled,i=void 0!==t?t.length:0;else if(void 0!==this._selectionOctree){var n=this._selectionOctree.select(this._frustumPlanes);t=n.data,i=n.length}else i=this.meshes.length,t=this.meshes;for(var o,s,a=0;a<i;a++)(o=t[a]).isBlocked||(this._totalVertices.addCount(o.getTotalVertices(),!1),!o.isReady()||r&&!o.isEnabled()||(o.computeWorldMatrix(),o.actionManager&&o.actionManager.hasSpecificTriggers([e.ActionManager.OnIntersectionEnterTrigger,e.ActionManager.OnIntersectionExitTrigger])&&this._meshesForIntersections.pushNoDuplicate(o),void 0!==(s=o.getLOD(this.activeCamera))&&null!==s&&(o._preActivate(),(o.alwaysSelectAsActiveMesh||o.isVisible&&o.visibility>0&&0!=(o.layerMask&this.activeCamera.layerMask)&&o.isInFrustum(this._frustumPlanes))&&(this._activeMeshes.push(o),this.activeCamera._activeMeshes.push(o),o._activate(this._renderId),s!==o&&s._activate(this._renderId),this._activeMesh(o,s)))));if(this.onAfterActiveMeshesEvaluationObservable.notifyObservers(this),this.particlesEnabled){this.onBeforeParticlesRenderingObservable.notifyObservers(this);for(var h=0;h<this.particleSystems.length;h++){var l=this.particleSystems[h];if(l.isStarted()&&l.emitter){var c=l.emitter;c.position&&!c.isEnabled()||(this._activeParticleSystems.push(l),l.animate(),this._renderingManager.dispatchParticles(l))}}this.onAfterParticlesRenderingObservable.notifyObservers(this)}}},i.prototype._activeMesh=function(e,t){if(this.skeletonsEnabled&&null!==t.skeleton&&void 0!==t.skeleton&&(this._activeSkeletons.pushNoDuplicate(t.skeleton)&&t.skeleton.prepare(),t.computeBonesUsingShaders||this._softwareSkinnedMeshes.pushNoDuplicate(t)),e.showBoundingBox||this.forceShowBoundingBoxes){var i=e.getBoundingInfo();this.getBoundingBoxRenderer().renderList.push(i.boundingBox)}if(void 0!==t&&null!==t&&void 0!==t.subMeshes&&null!==t.subMeshes&&t.subMeshes.length>0){var r,n;if(t.useOctreeForRenderingSelection&&void 0!==t._submeshesOctree&&null!==t._submeshesOctree){var o=t._submeshesOctree.select(this._frustumPlanes);r=o.length,n=o.data}else r=(n=t.subMeshes).length;for(var s,a=0;a<r;a++)s=n[a],this._evaluateSubMesh(s,t)}},i.prototype.updateTransformMatrix=function(e){this.activeCamera&&this.setTransformMatrix(this.activeCamera.getViewMatrix(),this.activeCamera.getProjectionMatrix(e))},i.prototype.updateAlternateTransformMatrix=function(e){this._setAlternateTransformMatrix(e.getViewMatrix(),e.getProjectionMatrix())},i.prototype._renderForCamera=function(t){if(!t||!t._skipRendering){var i=this._engine;if(this.activeCamera=t,!this.activeCamera)throw new Error("Active camera not set");e.Tools.StartPerformanceCounter("Rendering camera "+this.activeCamera.name),i.setViewport(this.activeCamera.viewport),this.resetCachedMaterial(),this._renderId++,this.activeCamera.update(),this.updateTransformMatrix(),t._alternateCamera&&(this.updateAlternateTransformMatrix(t._alternateCamera),this._alternateRendering=!0),this.onBeforeCameraRenderObservable.notifyObservers(this.activeCamera),this._evaluateActiveMeshes();for(var r=0;r<this._softwareSkinnedMeshes.length;r++){var n=this._softwareSkinnedMeshes.data[r];n.applySkeleton(n.skeleton)}this.OnBeforeRenderTargetsRenderObservable.notifyObservers(this);var o=!1;if(t.customRenderTargets&&t.customRenderTargets.length>0&&this._renderTargets.concatWithNoDuplicate(t.customRenderTargets),this.renderTargetsEnabled&&this._renderTargets.length>0){this._intermediateRendering=!0,e.Tools.StartPerformanceCounter("Render targets",this._renderTargets.length>0);for(var s=0;s<this._renderTargets.length;s++){if((f=this._renderTargets.data[s])._shouldRender()){this._renderId++;var a=f.activeCamera&&f.activeCamera!==this.activeCamera;f.render(a,this.dumpNextRenderTargets)}}e.Tools.EndPerformanceCounter("Render targets",this._renderTargets.length>0),this._intermediateRendering=!1,this._renderId++,o=!0}var h,l,c=this._engine.getStencilBuffer(),u=!1;if(this.renderTargetsEnabled&&this.highlightLayers&&this.highlightLayers.length>0){this._intermediateRendering=!0;for(var p=0;p<this.highlightLayers.length;p++){var f,d=this.highlightLayers[p];if(d.shouldRender()&&(!d.camera||d.camera.cameraRigMode===e.Camera.RIG_MODE_NONE&&t===d.camera||d.camera.cameraRigMode!==e.Camera.RIG_MODE_NONE&&d.camera._rigCameras.indexOf(t)>-1))u=!0,(f=d._mainTexture)._shouldRender()&&(this._renderId++,f.render(!1,!1),o=!0)}this._intermediateRendering=!1,this._renderId++}if(o&&i.restoreDefaultFramebuffer(),this.OnAfterRenderTargetsRenderObservable.notifyObservers(this),this.postProcessManager._prepareFrame(),this.layers.length){for(i.setDepthBuffer(!1),h=0;h<this.layers.length;h++)(l=this.layers[h]).isBackground&&0!=(l.layerMask&this.activeCamera.layerMask)&&l.render();i.setDepthBuffer(!0)}if(u&&this._engine.setStencilBuffer(!0),this.onBeforeDrawPhaseObservable.notifyObservers(this),this._renderingManager.render(null,null,!0,!0),this.onAfterDrawPhaseObservable.notifyObservers(this),u&&this._engine.setStencilBuffer(c),this._boundingBoxRenderer&&this._boundingBoxRenderer.render(),this.lensFlaresEnabled){e.Tools.StartPerformanceCounter("Lens flares",this.lensFlareSystems.length>0);for(var m=0;m<this.lensFlareSystems.length;m++){var g=this.lensFlareSystems[m];0!=(t.layerMask&g.layerMask)&&g.render()}e.Tools.EndPerformanceCounter("Lens flares",this.lensFlareSystems.length>0)}if(this.layers.length){for(i.setDepthBuffer(!1),h=0;h<this.layers.length;h++)(l=this.layers[h]).isBackground||0==(l.layerMask&this.activeCamera.layerMask)||l.render();i.setDepthBuffer(!0)}if(u){i.setDepthBuffer(!1);for(p=0;p<this.highlightLayers.length;p++)this.highlightLayers[p].shouldRender()&&this.highlightLayers[p].render();i.setDepthBuffer(!0)}this.postProcessManager._finalizeFrame(t.isIntermediate),this._renderTargets.reset(),this._alternateRendering=!1,this.onAfterCameraRenderObservable.notifyObservers(this.activeCamera),e.Tools.EndPerformanceCounter("Rendering camera "+this.activeCamera.name)}},i.prototype._processSubCameras=function(t){if(t.cameraRigMode!==e.Camera.RIG_MODE_NONE){this.activeCamera&&this.activeCamera.update();for(var i=0;i<t._rigCameras.length;i++)this._renderForCamera(t._rigCameras[i]);this.activeCamera=t,this.setTransformMatrix(this.activeCamera.getViewMatrix(),this.activeCamera.getProjectionMatrix())}else this._renderForCamera(t)},i.prototype._checkIntersections=function(){for(var t=0;t<this._meshesForIntersections.length;t++){var i=this._meshesForIntersections.data[t];if(i.actionManager)for(var r=0;r<i.actionManager.actions.length;r++){var n=i.actionManager.actions[r];if(n.trigger===e.ActionManager.OnIntersectionEnterTrigger||n.trigger===e.ActionManager.OnIntersectionExitTrigger){var o=n.getTriggerParameter(),s=o instanceof e.AbstractMesh?o:o.mesh,a=s.intersectsMesh(i,o.usePreciseIntersection),h=i._intersectionsInProgress.indexOf(s);a&&-1===h?n.trigger===e.ActionManager.OnIntersectionEnterTrigger?(n._executeCurrent(e.ActionEvent.CreateNew(i,void 0,s)),i._intersectionsInProgress.push(s)):n.trigger===e.ActionManager.OnIntersectionExitTrigger&&i._intersectionsInProgress.push(s):!a&&h>-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=1e3*this._physicsEngine.getTimeStep());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(r/1e3),this.onAfterPhysicsObservable.notifyObservers(this)),this.onAfterStepObservable.notifyObservers(this),this._currentStepId++,n++,t-=r}while(t>0&&n<s);this._timeAccumulator=t<0?0:t}else{t=this.useConstantAnimationDeltaTime?16:Math.max(i.MinDeltaTime,Math.min(this._engine.getDeltaTime(),i.MaxDeltaTime));this._animationRatio=.06*t,this._animate(),this.onAfterAnimationsObservable.notifyObservers(this),this._physicsEngine&&(this.onBeforePhysicsObservable.notifyObservers(this),this._physicsEngine._step(t/1e3),this.onAfterPhysicsObservable.notifyObservers(this))}this._gamepadManager&&this._gamepadManager._isMonitoring&&this._gamepadManager._checkGamepadsStatus(),this.onBeforeRenderObservable.notifyObservers(this),this.OnBeforeRenderTargetsRenderObservable.notifyObservers(this);var a=this.getEngine(),h=this.activeCamera;if(this.renderTargetsEnabled){e.Tools.StartPerformanceCounter("Custom render targets",this.customRenderTargets.length>0),this._intermediateRendering=!0;for(var l=0;l<this.customRenderTargets.length;l++){var c=this.customRenderTargets[l];if(c._shouldRender()){if(this._renderId++,this.activeCamera=c.activeCamera||this.activeCamera,!this.activeCamera)throw new Error("Active camera not set");a.setViewport(this.activeCamera.viewport),this.updateTransformMatrix(),c.render(h!==this.activeCamera,this.dumpNextRenderTargets)}}e.Tools.EndPerformanceCounter("Custom render targets",this.customRenderTargets.length>0),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;u<this._proceduralTextures.length;u++){var p=this._proceduralTextures[u];p._shouldRender()&&p.render()}e.Tools.EndPerformanceCounter("Procedural textures",this._proceduralTextures.length>0)}if((this.autoClearDepthAndStencil||this.autoClear)&&this._engine.clear(this.clearColor,this.autoClear||this.forceWireframe||this.forcePointsCloud,this.autoClearDepthAndStencil,this.autoClearDepthAndStencil),this.shadowsEnabled)for(var f=0;f<this.lights.length;f++){var d=this.lights[f],m=d.getShadowGenerator();if(d.isEnabled()&&d.shadowEnabled&&m){var g=m.getShadowMap();-1!==this.textures.indexOf(g)&&this._renderTargets.push(g)}}if(this._depthRenderer&&this._renderTargets.push(this._depthRenderer.getDepthMap()),this._geometryBufferRenderer&&this._renderTargets.push(this._geometryBufferRenderer.getGBuffer()),this._postProcessRenderPipelineManager&&this._postProcessRenderPipelineManager.update(),this.activeCameras.length>0)for(var _=0;_<this.activeCameras.length;_++)_>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;v<this._toBeDisposed.length;v++){var y=this._toBeDisposed.data[v];y&&y.dispose(),this._toBeDisposed[v]=null}this._toBeDisposed.reset(),this.dumpNextRenderTargets&&(this.dumpNextRenderTargets=!1),this._activeBones.addCount(0,!0),this._activeIndices.addCount(0,!0),this._activeParticles.addCount(0,!0)}},i.prototype._updateAudioParameters=function(){if(this.audioEnabled&&this._mainSoundTrack&&(0!==this._mainSoundTrack.soundCollection.length||1!==this.soundTracks.length)){var t,i=e.Engine.audioEngine;if((t=this.activeCameras.length>0?this.activeCameras[0]:this.activeCamera)&&i.canUseWebAudio&&i.audioContext){i.audioContext.listener.setPosition(t.position.x,t.position.y,t.position.z),t.rigCameras&&t.rigCameras.length>0&&(t=t.rigCameras[0]);var r,n=e.Matrix.Invert(t.getViewMatrix()),o=e.Vector3.TransformNormal(new e.Vector3(0,0,-1),n);for(o.normalize(),isNaN(o.x)||isNaN(o.y)||isNaN(o.z)||i.audioContext.listener.setOrientation(o.x,o.y,o.z,0,1,0),r=0;r<this.mainSoundTrack.soundCollection.length;r++){var s=this.mainSoundTrack.soundCollection[r];s.useCustomAttenuation&&s.updateDistanceFromListener()}for(r=0;r<this.soundTracks.length;r++)for(var a=0;a<this.soundTracks[r].soundCollection.length;a++)(s=this.soundTracks[r].soundCollection[a]).useCustomAttenuation&&s.updateDistanceFromListener()}}},Object.defineProperty(i.prototype,"audioEnabled",{get:function(){return this._audioEnabled},set:function(t){this._audioEnabled=t,e.AudioEngine&&(this._audioEnabled?this._enableAudio():this._disableAudio())},enumerable:!0,configurable:!0}),i.prototype._disableAudio=function(){var e;for(e=0;e<this.mainSoundTrack.soundCollection.length;e++)this.mainSoundTrack.soundCollection[e].pause();for(e=0;e<this.soundTracks.length;e++)for(var t=0;t<this.soundTracks[e].soundCollection.length;t++)this.soundTracks[e].soundCollection[t].pause()},i.prototype._enableAudio=function(){var e;for(e=0;e<this.mainSoundTrack.soundCollection.length;e++)this.mainSoundTrack.soundCollection[e].isPaused&&this.mainSoundTrack.soundCollection[e].play();for(e=0;e<this.soundTracks.length;e++)for(var t=0;t<this.soundTracks[e].soundCollection.length;t++)this.soundTracks[e].soundCollection[t].isPaused&&this.soundTracks[e].soundCollection[t].play()},Object.defineProperty(i.prototype,"headphone",{get:function(){return this._headphone},set:function(t){this._headphone=t,e.AudioEngine&&(this._headphone?this._switchAudioModeForHeadphones():this._switchAudioModeForNormalSpeakers())},enumerable:!0,configurable:!0}),i.prototype._switchAudioModeForHeadphones=function(){this.mainSoundTrack.switchPanningModelToHRTF();for(var e=0;e<this.soundTracks.length;e++)this.soundTracks[e].switchPanningModelToHRTF()},i.prototype._switchAudioModeForNormalSpeakers=function(){this.mainSoundTrack.switchPanningModelToEqualPower();for(var e=0;e<this.soundTracks.length;e++)this.soundTracks[e].switchPanningModelToEqualPower()},i.prototype.enableDepthRenderer=function(){return this._depthRenderer?this._depthRenderer:(this._depthRenderer=new e.DepthRenderer(this),this._depthRenderer)},i.prototype.disableDepthRenderer=function(){this._depthRenderer&&(this._depthRenderer.dispose(),this._depthRenderer=null)},i.prototype.enableGeometryBufferRenderer=function(t){return void 0===t&&(t=1),this._geometryBufferRenderer?this._geometryBufferRenderer:(this._geometryBufferRenderer=new e.GeometryBufferRenderer(this,t),this._geometryBufferRenderer.isSupported||(this._geometryBufferRenderer=null),this._geometryBufferRenderer)},i.prototype.disableGeometryBufferRenderer=function(){this._geometryBufferRenderer&&(this._geometryBufferRenderer.dispose(),this._geometryBufferRenderer=null)},i.prototype.freezeMaterials=function(){for(var e=0;e<this.materials.length;e++)this.materials[e].freeze()},i.prototype.unfreezeMaterials=function(){for(var e=0;e<this.materials.length;e++)this.materials[e].unfreeze()},i.prototype.dispose=function(){this.beforeRender=null,this.afterRender=null,this.skeletons=[],this.morphTargetManagers=[],this.importedMeshesFiles=new Array,this.stopAllAnimations(),this.resetCachedMaterial(),this._depthRenderer&&this._depthRenderer.dispose(),this._gamepadManager&&(this._gamepadManager.dispose(),this._gamepadManager=null),this.activeCamera&&(this.activeCamera._activeMeshes.dispose(),this.activeCamera=null),this._activeMeshes.dispose(),this._renderingManager.dispose(),this._processedMaterials.dispose(),this._activeParticleSystems.dispose(),this._activeSkeletons.dispose(),this._softwareSkinnedMeshes.dispose(),this._renderTargets.dispose(),this._boundingBoxRenderer&&this._boundingBoxRenderer.dispose(),this._meshesForIntersections.dispose(),this._toBeDisposed.dispose();for(var t=0,i=this._activeRequests;t<i.length;t++){i[t].abort()}this._debugLayer&&this._debugLayer.hide(),this.onDisposeObservable.notifyObservers(this),this.onDisposeObservable.clear(),this.onBeforeRenderObservable.clear(),this.onAfterRenderObservable.clear(),this.OnBeforeRenderTargetsRenderObservable.clear(),this.OnAfterRenderTargetsRenderObservable.clear(),this.onAfterStepObservable.clear(),this.onBeforeStepObservable.clear(),this.onBeforeActiveMeshesEvaluationObservable.clear(),this.onAfterActiveMeshesEvaluationObservable.clear(),this.onBeforeParticlesRenderingObservable.clear(),this.onAfterParticlesRenderingObservable.clear(),this.onBeforeSpritesRenderingObservable.clear(),this.onAfterSpritesRenderingObservable.clear(),this.onBeforeDrawPhaseObservable.clear(),this.onAfterDrawPhaseObservable.clear(),this.onBeforePhysicsObservable.clear(),this.onAfterPhysicsObservable.clear(),this.onBeforeAnimationsObservable.clear(),this.onAfterAnimationsObservable.clear(),this.onDataLoadedObservable.clear(),this.detachControl(),e.AudioEngine&&this.disposeSounds(),this.VRHelper&&this.VRHelper.dispose();var r,n=this._engine.getRenderingCanvas();if(n)for(r=0;r<this.cameras.length;r++)this.cameras[r].detachControl(n);for(;this.animationGroups.length;)this.animationGroups[0].dispose();for(;this.lights.length;)this.lights[0].dispose();for(;this.meshes.length;)this.meshes[0].dispose(!0);for(;this.transformNodes.length;)this.removeTransformNode(this.transformNodes[0]);for(;this.cameras.length;)this.cameras[0].dispose();for(this.defaultMaterial&&this.defaultMaterial.dispose();this.multiMaterials.length;)this.multiMaterials[0].dispose();for(;this.materials.length;)this.materials[0].dispose();for(;this.particleSystems.length;)this.particleSystems[0].dispose();for(;this.spriteManagers.length;)this.spriteManagers[0].dispose();for(;this.postProcesses.length;)this.postProcesses[0].dispose();for(;this.layers.length;)this.layers[0].dispose();for(;this.highlightLayers.length;)this.highlightLayers[0].dispose();for(;this.textures.length;)this.textures[0].dispose();this._sceneUbo.dispose(),this._alternateSceneUbo&&this._alternateSceneUbo.dispose(),this.postProcessManager.dispose(),this._postProcessRenderPipelineManager&&this._postProcessRenderPipelineManager.dispose(),this._physicsEngine&&this.disablePhysicsEngine(),(r=this._engine.scenes.indexOf(this))>-1&&this._engine.scenes.splice(r,1),this._engine.wipeCaches(!0),this._isDisposed=!0},Object.defineProperty(i.prototype,"isDisposed",{get:function(){return this._isDisposed},enumerable:!0,configurable:!0}),i.prototype.disposeSounds=function(){if(this._mainSoundTrack){this.mainSoundTrack.dispose();for(var e=0;e<this.soundTracks.length;e++)this.soundTracks[e].dispose()}},i.prototype.getWorldExtends=function(){for(var t=new e.Vector3(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),i=new e.Vector3(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE),r=0;r<this.meshes.length;r++){var n=this.meshes[r];if(n.subMeshes&&0!==n.subMeshes.length&&!n.infiniteDistance){n.computeWorldMatrix(!0);var o=n.getBoundingInfo(),s=o.boundingBox.minimumWorld,a=o.boundingBox.maximumWorld;e.Tools.CheckExtends(s,t,i),e.Tools.CheckExtends(a,t,i)}}return{min:t,max:i}},i.prototype.createOrUpdateSelectionOctree=function(t,i){void 0===t&&(t=64),void 0===i&&(i=2),this._selectionOctree||(this._selectionOctree=new e.Octree(e.Octree.CreationFuncForMeshes,t,i));var r=this.getWorldExtends();return this._selectionOctree.update(r.min,r.max,this.meshes),this._selectionOctree},i.prototype.createPickingRay=function(t,i,r,n,o){void 0===o&&(o=!1);var s=e.Ray.Zero();return this.createPickingRayToRef(t,i,r,s,n,o),s},i.prototype.createPickingRayToRef=function(t,i,r,n,o,s){void 0===s&&(s=!1);var a=this._engine;if(!o){if(!this.activeCamera)throw new Error("Active camera not set");o=this.activeCamera}var h=o.viewport.toGlobal(a.getRenderWidth(),a.getRenderHeight());return t=t/this._engine.getHardwareScalingLevel()-h.x,i=i/this._engine.getHardwareScalingLevel()-(this._engine.getRenderHeight()-h.y-h.height),n.update(t,i,h.width,h.height,r||e.Matrix.Identity(),s?e.Matrix.Identity():o.getViewMatrix(),o.getProjectionMatrix()),this},i.prototype.createPickingRayInCameraSpace=function(t,i,r){var n=e.Ray.Zero();return this.createPickingRayInCameraSpaceToRef(t,i,n,r),n},i.prototype.createPickingRayInCameraSpaceToRef=function(t,i,r,n){if(!e.PickingInfo)return this;var o=this._engine;if(!n){if(!this.activeCamera)throw new Error("Active camera not set");n=this.activeCamera}var s=n.viewport.toGlobal(o.getRenderWidth(),o.getRenderHeight()),a=e.Matrix.Identity();return t=t/this._engine.getHardwareScalingLevel()-s.x,i=i/this._engine.getHardwareScalingLevel()-(this._engine.getRenderHeight()-s.y-s.height),r.update(t,i,s.width,s.height,a,a,n.getProjectionMatrix()),this},i.prototype._internalPick=function(t,i,r){if(!e.PickingInfo)return null;for(var n=null,o=0;o<this.meshes.length;o++){var s=this.meshes[o];if(i){if(!i(s))continue}else if(!s.isEnabled()||!s.isVisible||!s.isPickable)continue;var a=t(s.getWorldMatrix()),h=s.intersects(a,r);if(h&&h.hit&&((r||null==n||!(h.distance>=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;n<this.meshes.length;n++){var o=this.meshes[n];if(i){if(!i(o))continue}else if(!o.isEnabled()||!o.isVisible||!o.isPickable)continue;var s=t(o.getWorldMatrix()),a=o.intersects(s,!1);a&&a.hit&&r.push(a)}return r},i.prototype._internalPickSprites=function(t,i,r,n){if(!e.PickingInfo)return null;var o=null;if(!n){if(!this.activeCamera)return null;n=this.activeCamera}if(this.spriteManagers.length>0)for(var s=0;s<this.spriteManagers.length;s++){var a=this.spriteManagers[s];if(a.isPickable){var h=a.intersects(t,n,i,r);if(h&&h.hit&&(r||null==o||!(h.distance>=o.distance))&&(o=h,r))break}}return o||new e.PickingInfo},i.prototype.pick=function(t,i,r,n,o){var s=this;return e.PickingInfo?this._internalPick(function(e){return s.createPickingRayToRef(t,i,e,s._tempPickingRay,o||null),s._tempPickingRay},r,n):null},i.prototype.pickSprite=function(e,t,i,r,n){return this.createPickingRayInCameraSpaceToRef(e,t,this._tempPickingRay,n),this._internalPickSprites(this._tempPickingRay,i,r,n)},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<t.length;e++){t[e]._rebuild()}for(var i=0,r=this.meshes;i<r.length;i++){r[i]._rebuild()}this.postProcessManager&&this.postProcessManager._rebuild();for(var n=0,o=this.layers;n<o.length;n++){o[n]._rebuild()}for(var s=0,a=this.highlightLayers;s<a.length;s++){a[s]._rebuild()}this._boundingBoxRenderer&&this._boundingBoxRenderer._rebuild();for(var h=0,l=this.particleSystems;h<l.length;h++){l[h].rebuild()}this._postProcessRenderPipelineManager&&this._postProcessRenderPipelineManager._rebuild()},i.prototype._rebuildTextures=function(){for(var t=0,i=this.textures;t<i.length;t++){i[t]._rebuild()}this.markAllMaterialsAsDirty(e.Material.TextureDirtyFlag)},i.prototype.createDefaultCameraOrLight=function(t,i,r){if(void 0===t&&(t=!1),void 0===i&&(i=!1),void 0===r&&(r=!1),i&&(this.activeCamera&&(this.activeCamera.dispose(),this.activeCamera=null),this.lights))for(var n=0;n<this.lights.length;n++)this.lights[n].dispose();if(0===this.lights.length&&new e.HemisphericLight("default light",e.Vector3.Up(),this),!this.activeCamera){var o,s=this.getWorldExtends(),a=s.max.subtract(s.min),h=s.min.add(a.scale(.5)),l=1.5*a.length();if(t){var c=new e.ArcRotateCamera("default camera",-Math.PI/2,Math.PI/2,l,h,this);c.lowerRadiusLimit=.01*l,c.wheelPrecision=100/l,o=c}else{var u=new e.FreeCamera("default camera",new e.Vector3(h.x,h.y,-l),this);u.setTarget(h),o=u}o.minZ=.01*l,o.maxZ=1e3*l,o.speed=.2*l,this.activeCamera=o;var p=this.getEngine().getRenderingCanvas();r&&p&&o.attachControl(p)}},i.prototype.createDefaultSkybox=function(t,i,r,n){if(void 0===i&&(i=!1),void 0===r&&(r=1e3),void 0===n&&(n=0),t&&(this.environmentTexture=t),!this.environmentTexture)return e.Tools.Warn("Can not create default skybox without environment texture."),null;var o=e.Mesh.CreateBox("hdrSkyBox",r,this);if(i){var s=new e.PBRMaterial("skyBox",this);s.backFaceCulling=!1,s.reflectionTexture=this.environmentTexture.clone(),s.reflectionTexture&&(s.reflectionTexture.coordinatesMode=e.Texture.SKYBOX_MODE),s.microSurface=1-n,s.disableLighting=!0,s.twoSidedLighting=!0,o.infiniteDistance=!0,o.material=s}else{var a=new e.StandardMaterial("skyBox",this);a.backFaceCulling=!1,a.reflectionTexture=this.environmentTexture.clone(),a.reflectionTexture&&(a.reflectionTexture.coordinatesMode=e.Texture.SKYBOX_MODE),a.disableLighting=!0,o.infiniteDistance=!0,o.material=a}return o},i.prototype.createDefaultEnvironment=function(t){return e.EnvironmentHelper?new e.EnvironmentHelper(t,this):null},i.prototype.createDefaultVRExperience=function(t){return void 0===t&&(t={}),new e.VRExperienceHelper(this,t)},i.prototype._getByTags=function(t,i,r){if(void 0===i)return t;var n=[];r=r||function(e){};for(var o in t){var s=t[o];e.Tags&&e.Tags.MatchesQuery(s,i)&&(n.push(s),r(s))}return n},i.prototype.getMeshesByTags=function(e,t){return this._getByTags(this.meshes,e,t)},i.prototype.getCamerasByTags=function(e,t){return this._getByTags(this.cameras,e,t)},i.prototype.getLightsByTags=function(e,t){return this._getByTags(this.lights,e,t)},i.prototype.getMaterialByTags=function(e,t){return this._getByTags(this.materials,e,t).concat(this._getByTags(this.multiMaterials,e,t))},i.prototype.setRenderingOrder=function(e,t,i,r){void 0===t&&(t=null),void 0===i&&(i=null),void 0===r&&(r=null),this._renderingManager.setRenderingOrder(e,t,i,r)},i.prototype.setRenderingAutoClearDepthStencil=function(e,t,i,r){void 0===i&&(i=!0),void 0===r&&(r=!0),this._renderingManager.setRenderingAutoClearDepthStencil(e,t,i,r)},i.prototype.markAllMaterialsAsDirty=function(e,t){for(var i=0,r=this.materials;i<r.length;i++){var n=r[i];t&&!t(n)||n.markAsDirty(e)}},i.prototype._loadFile=function(t,i,r,n,o,s){var a=this,h=e.Tools.LoadFile(t,i,r,n?this.database:void 0,o,s);return this._activeRequests.push(h),h.onCompleteObservable.add(function(e){a._activeRequests.splice(a._activeRequests.indexOf(e),1)}),h},i._FOGMODE_NONE=0,i._FOGMODE_EXP=1,i._FOGMODE_EXP2=2,i._FOGMODE_LINEAR=3,i._uniqueIdCounter=0,i.MinDeltaTime=1,i.MaxDeltaTime=1e3,i.DragMovementThreshold=10,i.LongPressDelay=500,i.DoubleClickDelay=300,i.ExclusiveDoubleClickMode=!1,i}();e.Scene=r}(us||(us={})),L=us||(us={}),B=function(){function e(e){this.cameras=new Array,this.lights=new Array,this.meshes=new Array,this.skeletons=new Array,this.particleSystems=new Array,this.animations=new Array,this.multiMaterials=new Array,this.materials=new Array,this.morphTargetManagers=new Array,this.geometries=new Array,this.transformNodes=new Array,this.lensFlareSystems=new Array,this.shadowGenerators=new Array,this.actionManagers=new Array,this.sounds=new Array,this.scene=e}return e.prototype.addAllToScene=function(){var e=this;this.cameras.forEach(function(t){e.scene.addCamera(t)}),this.lights.forEach(function(t){e.scene.addLight(t)}),this.meshes.forEach(function(t){e.scene.addMesh(t)}),this.skeletons.forEach(function(t){e.scene.addSkeleton(t)}),this.particleSystems.forEach(function(t){e.scene.addParticleSystem(t)}),this.animations.forEach(function(t){e.scene.addAnimation(t)}),this.multiMaterials.forEach(function(t){e.scene.addMultiMaterial(t)}),this.materials.forEach(function(t){e.scene.addMaterial(t)}),this.morphTargetManagers.forEach(function(t){e.scene.addMorphTargetManager(t)}),this.geometries.forEach(function(t){e.scene.addGeometry(t)}),this.transformNodes.forEach(function(t){e.scene.addTransformNode(t)}),this.lensFlareSystems.forEach(function(t){e.scene.addLensFlareSystem(t)}),this.actionManagers.forEach(function(t){e.scene.addActionManager(t)}),this.sounds.forEach(function(t){t.play(),t.autoplay=!0,e.scene.mainSoundTrack.AddSound(t)})},e.prototype.removeAllFromScene=function(){var e=this;this.cameras.forEach(function(t){e.scene.removeCamera(t)}),this.lights.forEach(function(t){e.scene.removeLight(t)}),this.meshes.forEach(function(t){e.scene.removeMesh(t)}),this.skeletons.forEach(function(t){e.scene.removeSkeleton(t)}),this.particleSystems.forEach(function(t){e.scene.removeParticleSystem(t)}),this.animations.forEach(function(t){e.scene.removeAnimation(t)}),this.multiMaterials.forEach(function(t){e.scene.removeMultiMaterial(t)}),this.materials.forEach(function(t){e.scene.removeMaterial(t)}),this.morphTargetManagers.forEach(function(t){e.scene.removeMorphTargetManager(t)}),this.geometries.forEach(function(t){e.scene.removeGeometry(t)}),this.transformNodes.forEach(function(t){e.scene.removeTransformNode(t)}),this.lensFlareSystems.forEach(function(t){e.scene.removeLensFlareSystem(t)}),this.actionManagers.forEach(function(t){e.scene.removeActionManager(t)}),this.sounds.forEach(function(t){t.stop(),t.autoplay=!1,e.scene.mainSoundTrack.RemoveSound(t)})},e}(),L.AssetContainer=B,N=us||(us={}),F=function(){function e(e,t,i,r,n,o){void 0===o&&(o=!1),e instanceof N.Mesh?this._engine=e.getScene().getEngine():this._engine=e,this._updatable=i,this._data=t,this._strideSize=r,n||this.create(),this._instanced=o,this._instanceDivisor=o?1:0}return e.prototype.createVertexBuffer=function(e,t,i,r){return new N.VertexBuffer(this._engine,this,e,this._updatable,!0,r||this._strideSize,this._instanced,t,i)},e.prototype.isUpdatable=function(){return this._updatable},e.prototype.getData=function(){return this._data},e.prototype.getBuffer=function(){return this._buffer},e.prototype.getStrideSize=function(){return this._strideSize},e.prototype.getIsInstanced=function(){return this._instanced},Object.defineProperty(e.prototype,"instanceDivisor",{get:function(){return this._instanceDivisor},set:function(e){this._instanceDivisor=e,this._instanced=0!=e},enumerable:!0,configurable:!0}),e.prototype.create=function(e){void 0===e&&(e=null),!e&&this._buffer||(e=e||this._data)&&(this._buffer?this._updatable&&(this._engine.updateDynamicVertexBuffer(this._buffer,e),this._data=e):this._updatable?(this._buffer=this._engine.createDynamicVertexBuffer(e),this._data=e):this._buffer=this._engine.createVertexBuffer(e))},e.prototype._rebuild=function(){this._buffer=null,this.create(this._data)},e.prototype.update=function(e){this.create(e)},e.prototype.updateDirectly=function(e,t,i){this._buffer&&this._updatable&&(this._engine.updateDynamicVertexBuffer(this._buffer,e,t,i?i*this.getStrideSize():void 0),this._data=null)},e.prototype.dispose=function(){this._buffer&&this._engine._releaseBuffer(this._buffer)&&(this._buffer=null)},e}(),N.Buffer=F,V=us||(us={}),k=function(){function e(t,i,r,n,o,s,a,h,l){if(!s)switch(r){case e.PositionKind:case e.NormalKind:s=3;break;case e.UVKind:case e.UV2Kind:case e.UV3Kind:case e.UV4Kind:case e.UV5Kind:case e.UV6Kind:s=2;break;case e.TangentKind:case e.ColorKind:s=4;break;case e.MatricesIndicesKind:case e.MatricesIndicesExtraKind:s=4;break;case e.MatricesWeightsKind:case e.MatricesWeightsExtraKind:default:s=4}i instanceof V.Buffer?(s||(s=i.getStrideSize()),this._buffer=i,this._ownsBuffer=!1):(this._buffer=new V.Buffer(t,i,n,s,o,a),this._ownsBuffer=!0),this._stride=s,this._offset=h||0,this._size=l||s,this._kind=r}return e.prototype._rebuild=function(){this._buffer&&this._buffer._rebuild()},e.prototype.getKind=function(){return this._kind},e.prototype.isUpdatable=function(){return this._buffer.isUpdatable()},e.prototype.getData=function(){return this._buffer.getData()},e.prototype.getBuffer=function(){return this._buffer.getBuffer()},e.prototype.getStrideSize=function(){return this._stride},e.prototype.getOffset=function(){return this._offset},e.prototype.getSize=function(){return this._size},e.prototype.getIsInstanced=function(){return this._buffer.getIsInstanced()},e.prototype.getInstanceDivisor=function(){return this._buffer.instanceDivisor},e.prototype.create=function(e){return this._buffer.create(e)},e.prototype.update=function(e){return this._buffer.update(e)},e.prototype.updateDirectly=function(e,t){return this._buffer.updateDirectly(e,t)},e.prototype.dispose=function(){this._ownsBuffer&&this._buffer.dispose()},Object.defineProperty(e,"PositionKind",{get:function(){return e._PositionKind},enumerable:!0,configurable:!0}),Object.defineProperty(e,"NormalKind",{get:function(){return e._NormalKind},enumerable:!0,configurable:!0}),Object.defineProperty(e,"TangentKind",{get:function(){return e._TangentKind},enumerable:!0,configurable:!0}),Object.defineProperty(e,"UVKind",{get:function(){return e._UVKind},enumerable:!0,configurable:!0}),Object.defineProperty(e,"UV2Kind",{get:function(){return e._UV2Kind},enumerable:!0,configurable:!0}),Object.defineProperty(e,"UV3Kind",{get:function(){return e._UV3Kind},enumerable:!0,configurable:!0}),Object.defineProperty(e,"UV4Kind",{get:function(){return e._UV4Kind},enumerable:!0,configurable:!0}),Object.defineProperty(e,"UV5Kind",{get:function(){return e._UV5Kind},enumerable:!0,configurable:!0}),Object.defineProperty(e,"UV6Kind",{get:function(){return e._UV6Kind},enumerable:!0,configurable:!0}),Object.defineProperty(e,"ColorKind",{get:function(){return e._ColorKind},enumerable:!0,configurable:!0}),Object.defineProperty(e,"MatricesIndicesKind",{get:function(){return e._MatricesIndicesKind},enumerable:!0,configurable:!0}),Object.defineProperty(e,"MatricesWeightsKind",{get:function(){return e._MatricesWeightsKind},enumerable:!0,configurable:!0}),Object.defineProperty(e,"MatricesIndicesExtraKind",{get:function(){return e._MatricesIndicesExtraKind},enumerable:!0,configurable:!0}),Object.defineProperty(e,"MatricesWeightsExtraKind",{get:function(){return e._MatricesWeightsExtraKind},enumerable:!0,configurable:!0}),e._PositionKind="position",e._NormalKind="normal",e._TangentKind="tangent",e._UVKind="uv",e._UV2Kind="uv2",e._UV3Kind="uv3",e._UV4Kind="uv4",e._UV5Kind="uv5",e._UV6Kind="uv6",e._ColorKind="color",e._MatricesIndicesKind="matricesIndices",e._MatricesWeightsKind="matricesWeights",e._MatricesIndicesExtraKind="matricesIndicesExtra",e._MatricesWeightsExtraKind="matricesWeightsExtra",e}(),V.VertexBuffer=k,U=us||(us={}),z=function(){function e(t,i){this.onLoadedObservable=new U.Observable,this._initialSlot=-1,this._designatedSlot=-1,this._dataSource=e.DATASOURCE_UNKNOWN,this._references=1,this._engine=t,this._dataSource=i,this._webGLTexture=t._createTexture()}return Object.defineProperty(e.prototype,"dataSource",{get:function(){return this._dataSource},enumerable:!0,configurable:!0}),e.prototype.incrementReferences=function(){this._references++},e.prototype.updateSize=function(e,t,i){void 0===i&&(i=1),this.width=e,this.height=t,this.depth=i,this.baseWidth=e,this.baseHeight=t,this.baseDepth=i,this._size=e*t*i},e.prototype._rebuild=function(){var t,i=this;switch(this.isReady=!1,this._cachedCoordinatesMode=null,this._cachedWrapU=null,this._cachedWrapV=null,this._cachedAnisotropicFilteringLevel=null,this._dataSource){case e.DATASOURCE_TEMP:return;case e.DATASOURCE_URL:return void(t=this._engine.createTexture(this.url,!this.generateMipMaps,this.invertY,null,this.samplingMode,function(){i.isReady=!0},null,this._buffer,void 0,this.format))._swapAndDie(this);case e.DATASOURCE_RAW:return(t=this._engine.createRawTexture(this._bufferView,this.baseWidth,this.baseHeight,this.format,this.generateMipMaps,this.invertY,this.samplingMode,this._compression))._swapAndDie(this),void(this.isReady=!0);case e.DATASOURCE_RAW3D:return(t=this._engine.createRawTexture3D(this._bufferView,this.baseWidth,this.baseHeight,this.baseDepth,this.format,this.generateMipMaps,this.invertY,this.samplingMode,this._compression))._swapAndDie(this),void(this.isReady=!0);case e.DATASOURCE_DYNAMIC:return void(t=this._engine.createDynamicTexture(this.baseWidth,this.baseHeight,this.generateMipMaps,this.samplingMode))._swapAndDie(this);case e.DATASOURCE_RENDERTARGET:var r=new U.RenderTargetCreationOptions;if(r.generateDepthBuffer=this._generateDepthBuffer,r.generateMipMaps=this.generateMipMaps,r.generateStencilBuffer=this._generateStencilBuffer,r.samplingMode=this.samplingMode,r.type=this.type,this.isCube)t=this._engine.createRenderTargetCubeTexture(this.width,r);else{var n={width:this.width,height:this.height};t=this._engine.createRenderTargetTexture(n,r)}return t._swapAndDie(this),void(this.isReady=!0);case e.DATASOURCE_CUBE:return void(t=this._engine.createCubeTexture(this.url,null,this._files,!this.generateMipMaps,function(){i.isReady=!0},null,this.format,this._extension))._swapAndDie(this);case e.DATASOURCE_CUBERAW:return(t=this._engine.createRawCubeTexture(this._bufferViewArray,this.width,this.format,this.type,this.generateMipMaps,this.invertY,this.samplingMode,this._compression))._swapAndDie(this),void(this.isReady=!0);case e.DATASOURCE_CUBEPREFILTERED:return void(t=this._engine.createPrefilteredCubeTexture(this.url,null,this._lodGenerationScale,this._lodGenerationOffset,function(e){e&&e._swapAndDie(i),i.isReady=!0},null,this.format,this._extension))}},e.prototype._swapAndDie=function(e){e._webGLTexture=this._webGLTexture,this._framebuffer&&(e._framebuffer=this._framebuffer),this._depthStencilBuffer&&(e._depthStencilBuffer=this._depthStencilBuffer),this._lodTextureHigh&&(e._lodTextureHigh&&e._lodTextureHigh.dispose(),e._lodTextureHigh=this._lodTextureHigh),this._lodTextureMid&&(e._lodTextureMid&&e._lodTextureMid.dispose(),e._lodTextureMid=this._lodTextureMid),this._lodTextureLow&&(e._lodTextureLow&&e._lodTextureLow.dispose(),e._lodTextureLow=this._lodTextureLow);var t=this._engine.getLoadedTexturesCache(),i=t.indexOf(this);-1!==i&&t.splice(i,1)},e.prototype.dispose=function(){this._webGLTexture&&(this._references--,0===this._references&&(this._engine._releaseTexture(this),this._webGLTexture=null))},e.DATASOURCE_UNKNOWN=0,e.DATASOURCE_URL=1,e.DATASOURCE_TEMP=2,e.DATASOURCE_RAW=3,e.DATASOURCE_DYNAMIC=4,e.DATASOURCE_RENDERTARGET=5,e.DATASOURCE_MULTIRENDERTARGET=6,e.DATASOURCE_CUBE=7,e.DATASOURCE_CUBERAW=8,e.DATASOURCE_CUBEPREFILTERED=9,e.DATASOURCE_RAW3D=10,e}(),U.InternalTexture=z,G=us||(us={}),W=function(){function e(t){this._hasAlpha=!1,this.getAlphaFromRGB=!1,this.level=1,this.coordinatesIndex=0,this._coordinatesMode=G.Texture.EXPLICIT_MODE,this.wrapU=G.Texture.WRAP_ADDRESSMODE,this.wrapV=G.Texture.WRAP_ADDRESSMODE,this.wrapR=G.Texture.WRAP_ADDRESSMODE,this.anisotropicFilteringLevel=e.DEFAULT_ANISOTROPIC_FILTERING_LEVEL,this.isCube=!1,this.is3D=!1,this.gammaSpace=!0,this.invertZ=!1,this.lodLevelInAlpha=!1,this.lodGenerationOffset=0,this.lodGenerationScale=.8,this.isRenderTarget=!1,this.animations=new Array,this.onDisposeObservable=new G.Observable,this.delayLoadState=G.Engine.DELAYLOADSTATE_NONE,this._scene=t||G.Engine.LastCreatedScene,this._scene&&this._scene.textures.push(this),this._uid=null}return Object.defineProperty(e.prototype,"hasAlpha",{get:function(){return this._hasAlpha},set:function(e){this._hasAlpha!==e&&(this._hasAlpha=e,this._scene&&this._scene.markAllMaterialsAsDirty(G.Material.TextureDirtyFlag))},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"coordinatesMode",{get:function(){return this._coordinatesMode},set:function(e){this._coordinatesMode!==e&&(this._coordinatesMode=e,this._scene&&this._scene.markAllMaterialsAsDirty(G.Material.TextureDirtyFlag))},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"uid",{get:function(){return this._uid||(this._uid=G.Tools.RandomId()),this._uid},enumerable:!0,configurable:!0}),e.prototype.toString=function(){return this.name},e.prototype.getClassName=function(){return"BaseTexture"},Object.defineProperty(e.prototype,"onDispose",{set:function(e){this._onDisposeObserver&&this.onDisposeObservable.remove(this._onDisposeObserver),this._onDisposeObserver=this.onDisposeObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isBlocking",{get:function(){return!0},enumerable:!0,configurable:!0}),e.prototype.getScene=function(){return this._scene},e.prototype.getTextureMatrix=function(){return G.Matrix.IdentityReadOnly},e.prototype.getReflectionTextureMatrix=function(){return G.Matrix.IdentityReadOnly},e.prototype.getInternalTexture=function(){return this._texture},e.prototype.isReadyOrNotBlocking=function(){return!this.isBlocking||this.isReady()},e.prototype.isReady=function(){return this.delayLoadState===G.Engine.DELAYLOADSTATE_NOTLOADED?(this.delayLoad(),!1):!!this._texture&&this._texture.isReady},e.prototype.getSize=function(){return this._texture&&this._texture.width?new G.Size(this._texture.width,this._texture.height):this._texture&&this._texture._size?new G.Size(this._texture._size,this._texture._size):G.Size.Zero()},e.prototype.getBaseSize=function(){return this.isReady()&&this._texture?this._texture._size?new G.Size(this._texture._size,this._texture._size):new G.Size(this._texture.baseWidth,this._texture.baseHeight):G.Size.Zero()},e.prototype.scale=function(e){},Object.defineProperty(e.prototype,"canRescale",{get:function(){return!1},enumerable:!0,configurable:!0}),e.prototype._getFromCache=function(e,t,i){if(!this._scene)return null;for(var r=this._scene.getEngine().getLoadedTexturesCache(),n=0;n<r.length;n++){var o=r[n];if(o.url===e&&o.generateMipMaps===!t&&(!i||i===o.samplingMode))return o.incrementReferences(),o}return null},e.prototype._rebuild=function(){},e.prototype.delayLoad=function(){},e.prototype.clone=function(){return null},Object.defineProperty(e.prototype,"textureType",{get:function(){return this._texture&&void 0!==this._texture.type?this._texture.type:G.Engine.TEXTURETYPE_UNSIGNED_INT},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"textureFormat",{get:function(){return this._texture&&void 0!==this._texture.format?this._texture.format:G.Engine.TEXTUREFORMAT_RGBA},enumerable:!0,configurable:!0}),e.prototype.readPixels=function(e){if(void 0===e&&(e=0),!this._texture)return null;var t=this.getSize(),i=this.getScene();if(!i)return null;var r=i.getEngine();return this._texture.isCube?r._readTexturePixels(this._texture,t.width,t.height,e):r._readTexturePixels(this._texture,t.width,t.height,-1)},e.prototype.releaseInternalTexture=function(){this._texture&&(this._texture.dispose(),this._texture=null)},Object.defineProperty(e.prototype,"sphericalPolynomial",{get:function(){return this._texture&&G.CubeMapToSphericalPolynomialTools&&this.isReady()?(this._texture._sphericalPolynomial||(this._texture._sphericalPolynomial=G.CubeMapToSphericalPolynomialTools.ConvertCubeMapTextureToSphericalPolynomial(this)),this._texture._sphericalPolynomial):null},set:function(e){this._texture&&(this._texture._sphericalPolynomial=e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"_lodTextureHigh",{get:function(){return this._texture?this._texture._lodTextureHigh:null},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"_lodTextureMid",{get:function(){return this._texture?this._texture._lodTextureMid:null},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"_lodTextureLow",{get:function(){return this._texture?this._texture._lodTextureLow:null},enumerable:!0,configurable:!0}),e.prototype.dispose=function(){if(this._scene){this._scene.stopAnimation(this),this._scene._removePendingData(this);var e=this._scene.textures.indexOf(this);e>=0&&this._scene.textures.splice(e,1),void 0!==this._texture&&(this.releaseInternalTexture(),this.onDisposeObservable.notifyObservers(this),this.onDisposeObservable.clear())}},e.prototype.serialize=function(){if(!this.name)return null;var e=G.SerializationHelper.Serialize(this);return G.Animation.AppendSerializedAnimations(this,e),e},e.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;s<e.length;s++)o();else t()},e.DEFAULT_ANISOTROPIC_FILTERING_LEVEL=4,X([G.serialize()],e.prototype,"name",void 0),X([G.serialize("hasAlpha")],e.prototype,"_hasAlpha",void 0),X([G.serialize()],e.prototype,"getAlphaFromRGB",void 0),X([G.serialize()],e.prototype,"level",void 0),X([G.serialize()],e.prototype,"coordinatesIndex",void 0),X([G.serialize("coordinatesMode")],e.prototype,"_coordinatesMode",void 0),X([G.serialize()],e.prototype,"wrapU",void 0),X([G.serialize()],e.prototype,"wrapV",void 0),X([G.serialize()],e.prototype,"wrapR",void 0),X([G.serialize()],e.prototype,"anisotropicFilteringLevel",void 0),X([G.serialize()],e.prototype,"isCube",void 0),X([G.serialize()],e.prototype,"is3D",void 0),X([G.serialize()],e.prototype,"gammaSpace",void 0),X([G.serialize()],e.prototype,"invertZ",void 0),X([G.serialize()],e.prototype,"lodLevelInAlpha",void 0),X([G.serialize()],e.prototype,"lodGenerationOffset",void 0),X([G.serialize()],e.prototype,"lodGenerationScale",void 0),X([G.serialize()],e.prototype,"isRenderTarget",void 0),e}(),G.BaseTexture=W,H=us||(us={}),j=function(e){function t(i,r,n,o,s,a,h,l,c,u){void 0===n&&(n=!1),void 0===o&&(o=!0),void 0===s&&(s=t.TRILINEAR_SAMPLINGMODE),void 0===a&&(a=null),void 0===h&&(h=null),void 0===l&&(l=null),void 0===c&&(c=!1);var p=e.call(this,r)||this;if(p.uOffset=0,p.vOffset=0,p.uScale=1,p.vScale=1,p.uAng=0,p.vAng=0,p.wAng=0,p._isBlocking=!0,p.name=i||"",p.url=i,p._noMipmap=n,p._invertY=o,p._samplingMode=s,p._buffer=l,p._deleteBuffer=c,u&&(p._format=u),!(r=p.getScene()))return p;r.getEngine().onBeforeTextureInitObservable.notifyObservers(p);var f=function(){p._onLoadObservable&&p._onLoadObservable.hasObservers()&&p.onLoadObservable.notifyObservers(p),a&&a(),!p.isBlocking&&r&&r.resetCachedMaterial()};return p.url?(p._texture=p._getFromCache(p.url,n,s),p._texture?p._texture.isReady?H.Tools.SetImmediate(function(){return f()}):p._texture.onLoadedObservable.add(f):r.useDelayedTextureLoading?(p.delayLoadState=H.Engine.DELAYLOADSTATE_NOTLOADED,p._delayedOnLoad=f,p._delayedOnError=h):(p._texture=r.getEngine().createTexture(p.url,n,o,r,p._samplingMode,f,h,p._buffer,void 0,p._format),c&&delete p._buffer),p):(p._delayedOnLoad=f,p._delayedOnError=h,p)}return Y(t,e),Object.defineProperty(t.prototype,"noMipmap",{get:function(){return this._noMipmap},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isBlocking",{get:function(){return this._isBlocking},set:function(e){this._isBlocking=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"samplingMode",{get:function(){return this._samplingMode},enumerable:!0,configurable:!0}),t.prototype.updateURL=function(e){this.url=e,this.delayLoadState=H.Engine.DELAYLOADSTATE_NOTLOADED,this.delayLoad()},t.prototype.delayLoad=function(){var e=this;if(this.delayLoadState===H.Engine.DELAYLOADSTATE_NOTLOADED){var t=this.getScene();t&&(this.delayLoadState=H.Engine.DELAYLOADSTATE_LOADED,this._texture=this._getFromCache(this.url,this._noMipmap,this._samplingMode),this._texture?this._texture.isReady?H.Tools.SetImmediate(function(){e._delayedOnLoad&&e._delayedOnLoad()}):this._delayedOnLoad&&this._texture.onLoadedObservable.add(this._delayedOnLoad):(this._texture=t.getEngine().createTexture(this.url,this._noMipmap,this._invertY,t,this._samplingMode,this._delayedOnLoad,this._delayedOnError,this._buffer,null,this._format),this._deleteBuffer&&delete this._buffer))}},t.prototype.updateSamplingMode=function(e){if(this._texture){var t=this.getScene();t&&(this._samplingMode=e,t.getEngine().updateTextureSamplingMode(e,this._texture))}},t.prototype._prepareRowForTextureGeneration=function(e,t,i,r){e*=this.uScale,t*=this.vScale,e-=.5*this.uScale,t-=.5*this.vScale,i-=.5,H.Vector3.TransformCoordinatesFromFloatsToRef(e,t,i,this._rowGenerationMatrix,r),r.x+=.5*this.uScale+this.uOffset,r.y+=.5*this.vScale+this.vOffset,r.z+=.5},t.prototype.getTextureMatrix=function(){var e=this;if(this.uOffset===this._cachedUOffset&&this.vOffset===this._cachedVOffset&&this.uScale===this._cachedUScale&&this.vScale===this._cachedVScale&&this.uAng===this._cachedUAng&&this.vAng===this._cachedVAng&&this.wAng===this._cachedWAng)return this._cachedTextureMatrix;this._cachedUOffset=this.uOffset,this._cachedVOffset=this.vOffset,this._cachedUScale=this.uScale,this._cachedVScale=this.vScale,this._cachedUAng=this.uAng,this._cachedVAng=this.vAng,this._cachedWAng=this.wAng,this._cachedTextureMatrix||(this._cachedTextureMatrix=H.Matrix.Zero(),this._rowGenerationMatrix=new H.Matrix,this._t0=H.Vector3.Zero(),this._t1=H.Vector3.Zero(),this._t2=H.Vector3.Zero()),H.Matrix.RotationYawPitchRollToRef(this.vAng,this.uAng,this.wAng,this._rowGenerationMatrix),this._prepareRowForTextureGeneration(0,0,0,this._t0),this._prepareRowForTextureGeneration(1,0,0,this._t1),this._prepareRowForTextureGeneration(0,1,0,this._t2),this._t1.subtractInPlace(this._t0),this._t2.subtractInPlace(this._t0),H.Matrix.IdentityToRef(this._cachedTextureMatrix),this._cachedTextureMatrix.m[0]=this._t1.x,this._cachedTextureMatrix.m[1]=this._t1.y,this._cachedTextureMatrix.m[2]=this._t1.z,this._cachedTextureMatrix.m[4]=this._t2.x,this._cachedTextureMatrix.m[5]=this._t2.y,this._cachedTextureMatrix.m[6]=this._t2.z,this._cachedTextureMatrix.m[8]=this._t0.x,this._cachedTextureMatrix.m[9]=this._t0.y,this._cachedTextureMatrix.m[10]=this._t0.z;var t=this.getScene();return t?(t.markAllMaterialsAsDirty(H.Material.TextureDirtyFlag,function(t){return t.hasTexture(e)}),this._cachedTextureMatrix):this._cachedTextureMatrix},t.prototype.getReflectionTextureMatrix=function(){var e=this,i=this.getScene();if(!i)return this._cachedTextureMatrix;if(this.uOffset===this._cachedUOffset&&this.vOffset===this._cachedVOffset&&this.uScale===this._cachedUScale&&this.vScale===this._cachedVScale&&this.coordinatesMode===this._cachedCoordinatesMode){if(this.coordinatesMode!==t.PROJECTION_MODE)return this._cachedTextureMatrix;if(this._cachedProjectionMatrixId===i.getProjectionMatrix().updateFlag)return this._cachedTextureMatrix}switch(this._cachedTextureMatrix||(this._cachedTextureMatrix=H.Matrix.Zero()),this._projectionModeMatrix||(this._projectionModeMatrix=H.Matrix.Zero()),this._cachedUOffset=this.uOffset,this._cachedVOffset=this.vOffset,this._cachedUScale=this.uScale,this._cachedVScale=this.vScale,this._cachedCoordinatesMode=this.coordinatesMode,this.coordinatesMode){case t.PLANAR_MODE:H.Matrix.IdentityToRef(this._cachedTextureMatrix),this._cachedTextureMatrix[0]=this.uScale,this._cachedTextureMatrix[5]=this.vScale,this._cachedTextureMatrix[12]=this.uOffset,this._cachedTextureMatrix[13]=this.vOffset;break;case t.PROJECTION_MODE:H.Matrix.IdentityToRef(this._projectionModeMatrix),this._projectionModeMatrix.m[0]=.5,this._projectionModeMatrix.m[5]=-.5,this._projectionModeMatrix.m[10]=0,this._projectionModeMatrix.m[12]=.5,this._projectionModeMatrix.m[13]=.5,this._projectionModeMatrix.m[14]=1,this._projectionModeMatrix.m[15]=1;var r=i.getProjectionMatrix();this._cachedProjectionMatrixId=r.updateFlag,r.multiplyToRef(this._projectionModeMatrix,this._cachedTextureMatrix);break;default:H.Matrix.IdentityToRef(this._cachedTextureMatrix)}return i.markAllMaterialsAsDirty(H.Material.TextureDirtyFlag,function(t){return-1!==t.getActiveTextures().indexOf(e)}),this._cachedTextureMatrix},t.prototype.clone=function(){var e=this;return H.SerializationHelper.Clone(function(){return new t(e._texture?e._texture.url:null,e.getScene(),e._noMipmap,e._invertY,e._samplingMode)},this)},Object.defineProperty(t.prototype,"onLoadObservable",{get:function(){return this._onLoadObservable||(this._onLoadObservable=new H.Observable),this._onLoadObservable},enumerable:!0,configurable:!0}),t.prototype.serialize=function(){var t=e.prototype.serialize.call(this);return"string"==typeof this._buffer&&"data:"===this._buffer.substr(0,5)&&(t.base64String=this._buffer,t.name=t.name.replace("data:","")),t},t.prototype.getClassName=function(){return"Texture"},t.prototype.dispose=function(){e.prototype.dispose.call(this),this.onLoadObservable&&(this.onLoadObservable.clear(),this._onLoadObservable=null),this._delayedOnLoad=null,this._delayedOnError=null},t.CreateFromBase64String=function(e,i,r,n,o,s,a,h,l){return void 0===s&&(s=t.TRILINEAR_SAMPLINGMODE),void 0===a&&(a=null),void 0===h&&(h=null),void 0===l&&(l=H.Engine.TEXTUREFORMAT_RGBA),new t("data:"+i,r,n,o,s,a,h,e,!1,l)},t.Parse=function(e,i,r){if(e.customType){var n=H.Tools.Instantiate(e.customType).Parse(e,i,r);return e.samplingMode&&n.updateSamplingMode&&n._samplingMode&&n._samplingMode!==e.samplingMode&&n.updateSamplingMode(e.samplingMode),n}if(e.isCube)return H.CubeTexture.Parse(e,i,r);if(!e.name&&!e.isRenderTarget)return null;var o=H.SerializationHelper.Parse(function(){var n=!0;if(e.noMipmap&&(n=!1),e.mirrorPlane){var o=new H.MirrorTexture(e.name,e.renderTargetSize,i,n);return o._waitingRenderList=e.renderList,o.mirrorPlane=H.Plane.FromArray(e.mirrorPlane),o}if(e.isRenderTarget){var s=new H.RenderTargetTexture(e.name,e.renderTargetSize,i,n);return s._waitingRenderList=e.renderList,s}return e.base64String?t.CreateFromBase64String(e.base64String,e.name,i,!n):new t(r+e.name,i,!n)},e,i);if(e.samplingMode){var s=e.samplingMode;o._samplingMode!==s&&o.updateSamplingMode(s)}if(e.animations)for(var a=0;a<e.animations.length;a++){var h=e.animations[a];o.animations.push(H.Animation.Parse(h))}return o},t.LoadFromDataString=function(e,i,r,n,o,s,a,h,l,c){return void 0===n&&(n=!1),void 0===o&&(o=!1),void 0===s&&(s=!0),void 0===a&&(a=t.TRILINEAR_SAMPLINGMODE),void 0===h&&(h=null),void 0===l&&(l=null),void 0===c&&(c=H.Engine.TEXTUREFORMAT_RGBA),"data:"!==e.substr(0,5)&&(e="data:"+e),new t(e,r,o,s,a,h,l,i,n,c)},t.NEAREST_SAMPLINGMODE=1,t.NEAREST_NEAREST_MIPLINEAR=1,t.BILINEAR_SAMPLINGMODE=2,t.LINEAR_LINEAR_MIPNEAREST=2,t.TRILINEAR_SAMPLINGMODE=3,t.LINEAR_LINEAR_MIPLINEAR=3,t.NEAREST_NEAREST_MIPNEAREST=4,t.NEAREST_LINEAR_MIPNEAREST=5,t.NEAREST_LINEAR_MIPLINEAR=6,t.NEAREST_LINEAR=7,t.NEAREST_NEAREST=8,t.LINEAR_NEAREST_MIPNEAREST=9,t.LINEAR_NEAREST_MIPLINEAR=10,t.LINEAR_LINEAR=11,t.LINEAR_NEAREST=12,t.EXPLICIT_MODE=0,t.SPHERICAL_MODE=1,t.PLANAR_MODE=2,t.CUBIC_MODE=3,t.PROJECTION_MODE=4,t.SKYBOX_MODE=5,t.INVCUBIC_MODE=6,t.EQUIRECTANGULAR_MODE=7,t.FIXED_EQUIRECTANGULAR_MODE=8,t.FIXED_EQUIRECTANGULAR_MIRRORED_MODE=9,t.CLAMP_ADDRESSMODE=0,t.WRAP_ADDRESSMODE=1,t.MIRROR_ADDRESSMODE=2,X([H.serialize()],t.prototype,"url",void 0),X([H.serialize()],t.prototype,"uOffset",void 0),X([H.serialize()],t.prototype,"vOffset",void 0),X([H.serialize()],t.prototype,"uScale",void 0),X([H.serialize()],t.prototype,"vScale",void 0),X([H.serialize()],t.prototype,"uAng",void 0),X([H.serialize()],t.prototype,"vAng",void 0),X([H.serialize()],t.prototype,"wAng",void 0),X([H.serialize()],t.prototype,"isBlocking",null),t}(H.BaseTexture),H.Texture=j,function(e){var t=function(){return function(){this.mustReturn=!1,this.visibleInstances=new Array,this.renderSelf=new Array}}();e._InstancesBatch=t;var i=function(i){function r(n,o,s,a,h,l){void 0===o&&(o=null),void 0===s&&(s=null),void 0===a&&(a=null),void 0===l&&(l=!0);var c=i.call(this,n,o)||this;if(c.onBeforeRenderObservable=new e.Observable,c.onAfterRenderObservable=new e.Observable,c.onBeforeDrawObservable=new e.Observable,c.delayLoadState=e.Engine.DELAYLOADSTATE_NONE,c.instances=new Array,c._LODLevels=new Array,c._visibleInstances={},c._renderIdForInstances=new Array,c._batchCache=new t,c._instancesBufferSize=2048,c._originalBuilderSideOrientation=r._DEFAULTSIDE,c.overrideMaterialSideOrientation=null,c._areNormalsFrozen=!1,c._source=null,o=c.getScene(),a){var u;if(c._source=a,a._geometry&&a._geometry.applyToMesh(c),e.Tools.DeepCopy(a,c,["name","material","skeleton","instances","parent","uniqueId","source","metadata"],["_poseMatrix","_source"]),a.metadata&&a.metadata.clone?c.metadata=a.metadata.clone():c.metadata=a.metadata,e.Tags&&e.Tags.HasTags(a)&&e.Tags.AddTagsTo(c,e.Tags.GetTags(a,!0)),c.parent=a.parent,c.setPivotMatrix(a.getPivotMatrix()),c.id=n+"."+a.id,c.material=a.material,!h)for(var p=a.getDescendants(!0),f=0;f<p.length;f++){var d=p[f];d.clone&&d.clone(n+"."+d.name,c)}var m=c.getScene().getPhysicsEngine();if(l&&m){var g=m.getImpostorForPhysicsObject(a);g&&(c.physicsImpostor=g.clone(c))}for(u=0;u<o.particleSystems.length;u++){var _=o.particleSystems[u];_.emitter===a&&_.clone(_.name,c)}c.computeWorldMatrix(!0)}return null!==s&&(c.parent=s),c}return Y(r,i),Object.defineProperty(r,"FRONTSIDE",{get:function(){return r._FRONTSIDE},enumerable:!0,configurable:!0}),Object.defineProperty(r,"BACKSIDE",{get:function(){return r._BACKSIDE},enumerable:!0,configurable:!0}),Object.defineProperty(r,"DOUBLESIDE",{get:function(){return r._DOUBLESIDE},enumerable:!0,configurable:!0}),Object.defineProperty(r,"DEFAULTSIDE",{get:function(){return r._DEFAULTSIDE},enumerable:!0,configurable:!0}),Object.defineProperty(r,"NO_CAP",{get:function(){return r._NO_CAP},enumerable:!0,configurable:!0}),Object.defineProperty(r,"CAP_START",{get:function(){return r._CAP_START},enumerable:!0,configurable:!0}),Object.defineProperty(r,"CAP_END",{get:function(){return r._CAP_END},enumerable:!0,configurable:!0}),Object.defineProperty(r,"CAP_ALL",{get:function(){return r._CAP_ALL},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"onBeforeDraw",{set:function(e){this._onBeforeDrawObserver&&this.onBeforeDrawObservable.remove(this._onBeforeDrawObserver),this._onBeforeDrawObserver=this.onBeforeDrawObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"morphTargetManager",{get:function(){return this._morphTargetManager},set:function(e){this._morphTargetManager!==e&&(this._morphTargetManager=e,this._syncGeometryWithMorphTargetManager())},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"source",{get:function(){return this._source},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"isUnIndexed",{get:function(){return this._unIndexed},set:function(e){this._unIndexed!==e&&(this._unIndexed=e,this._markSubMeshesAsAttributesDirty())},enumerable:!0,configurable:!0}),r.prototype.getClassName=function(){return"Mesh"},r.prototype.toString=function(t){var r=i.prototype.toString.call(this,t);if(r+=", n vertices: "+this.getTotalVertices(),r+=", parent: "+(this._waitingParentId?this._waitingParentId:this.parent?this.parent.name:"NONE"),this.animations)for(var n=0;n<this.animations.length;n++)r+=", animation[0]: "+this.animations[n].toString(t);if(t)if(this._geometry){var o=this.getIndices(),s=this.getVerticesData(e.VertexBuffer.PositionKind);s&&o&&(r+=", flat shading: "+(s.length/3===o.length?"YES":"NO"))}else r+=", flat shading: UNKNOWN";return r},Object.defineProperty(r.prototype,"hasLODLevels",{get:function(){return this._LODLevels.length>0},enumerable:!0,configurable:!0}),r.prototype._sortLODLevels=function(){this._LODLevels.sort(function(e,t){return e.distance<t.distance?1:e.distance>t.distance?-1:0})},r.prototype.addLODLevel=function(t,i){if(i&&i._masterMesh)return e.Tools.Warn("You cannot use a mesh as LOD level twice"),this;var r=new e.MeshLODLevel(t,i);return this._LODLevels.push(r),i&&(i._masterMesh=this),this._sortLODLevels(),this},r.prototype.getLODLevelAtDistance=function(e){for(var t=0;t<this._LODLevels.length;t++){var i=this._LODLevels[t];if(i.distance===e)return i.mesh}return null},r.prototype.removeLODLevel=function(e){for(var t=0;t<this._LODLevels.length;t++)this._LODLevels[t].mesh===e&&(this._LODLevels.splice(t,1),e&&(e._masterMesh=null));return this._sortLODLevels(),this},r.prototype.getLOD=function(e,t){if(!this._LODLevels||0===this._LODLevels.length)return this;var i;t?i=t:i=this.getBoundingInfo().boundingSphere;var r=i.centerWorld.subtract(e.globalPosition).length();if(this._LODLevels[this._LODLevels.length-1].distance>r)return this.onLODLevelSelection&&this.onLODLevelSelection(r,this,this._LODLevels[this._LODLevels.length-1].mesh),this;for(var n=0;n<this._LODLevels.length;n++){var o=this._LODLevels[n];if(o.distance<r)return o.mesh&&(o.mesh._preActivate(),o.mesh._updateSubMeshesBoundingInfo(this.worldMatrixFromCache)),this.onLODLevelSelection&&this.onLODLevelSelection(r,this,o.mesh),o.mesh}return this.onLODLevelSelection&&this.onLODLevelSelection(r,this,this),this},Object.defineProperty(r.prototype,"geometry",{get:function(){return this._geometry},enumerable:!0,configurable:!0}),r.prototype.getTotalVertices=function(){return null===this._geometry||void 0===this._geometry?0:this._geometry.getTotalVertices()},r.prototype.getVerticesData=function(e,t,i){return this._geometry?this._geometry.getVerticesData(e,t,i):null},r.prototype.getVertexBuffer=function(e){return this._geometry?this._geometry.getVertexBuffer(e):null},r.prototype.isVerticesDataPresent=function(e){return this._geometry?this._geometry.isVerticesDataPresent(e):!!this._delayInfo&&-1!==this._delayInfo.indexOf(e)},r.prototype.isVertexBufferUpdatable=function(e){return this._geometry?this._geometry.isVertexBufferUpdatable(e):!!this._delayInfo&&-1!==this._delayInfo.indexOf(e)},r.prototype.getVerticesDataKinds=function(){if(!this._geometry){var e=new Array;return this._delayInfo&&this._delayInfo.forEach(function(t,i,r){e.push(t)}),e}return this._geometry.getVerticesDataKinds()},r.prototype.getTotalIndices=function(){return this._geometry?this._geometry.getTotalIndices():0},r.prototype.getIndices=function(e){return this._geometry?this._geometry.getIndices(e):[]},Object.defineProperty(r.prototype,"isBlocked",{get:function(){return null!==this._masterMesh&&void 0!==this._masterMesh},enumerable:!0,configurable:!0}),r.prototype.isReady=function(t){if(void 0===t&&(t=!1),this.delayLoadState===e.Engine.DELAYLOADSTATE_LOADING)return!1;if(!i.prototype.isReady.call(this))return!1;if(!this.subMeshes||0===this.subMeshes.length)return!0;var r=this.getEngine(),n=this.getScene(),o=t||r.getCaps().instancedArrays&&this.instances.length>0;this.computeWorldMatrix();var s=this.material||n.defaultMaterial;if(s){var a=r.getAlphaTesting();if(s.storeEffectOnSubMeshes)for(var h=0,l=this.subMeshes;h<l.length;h++){var c=(g=l[h]).getMaterial();if(c&&(r.setAlphaTesting(c.needAlphaTesting()&&!c.needAlphaBlendingForMesh(this)),!c.isReadyForSubMesh(this,g,o)))return r.setAlphaTesting(a),!1}else if(r.setAlphaTesting(s.needAlphaTesting()&&!s.needAlphaBlendingForMesh(this)),!s.isReady(this,o))return r.setAlphaTesting(a),!1;r.setAlphaTesting(a)}for(var u=0,p=this._lightSources;u<p.length;u++){var f=p[u].getShadowGenerator();if(f)for(var d=0,m=this.subMeshes;d<m.length;d++){var g=m[d];if(!f.isReady(g,o))return!1}}for(var _=0,v=this._LODLevels;_<v.length;_++){var y=v[_];if(y.mesh&&!y.mesh.isReady(o))return!1}return!0},Object.defineProperty(r.prototype,"areNormalsFrozen",{get:function(){return this._areNormalsFrozen},enumerable:!0,configurable:!0}),r.prototype.freezeNormals=function(){return this._areNormalsFrozen=!0,this},r.prototype.unfreezeNormals=function(){return this._areNormalsFrozen=!1,this},Object.defineProperty(r.prototype,"overridenInstanceCount",{set:function(e){this._overridenInstanceCount=e},enumerable:!0,configurable:!0}),r.prototype._preActivate=function(){var e=this.getScene().getRenderId();return this._preActivateId===e?this:(this._preActivateId=e,this._visibleInstances=null,this)},r.prototype._preActivateForIntermediateRendering=function(e){return this._visibleInstances&&(this._visibleInstances.intermediateDefaultRenderId=e),this},r.prototype._registerInstanceForRenderId=function(e,t){return this._visibleInstances||(this._visibleInstances={},this._visibleInstances.defaultRenderId=t,this._visibleInstances.selfDefaultRenderId=this._renderId),this._visibleInstances[t]||(this._visibleInstances[t]=new Array),this._visibleInstances[t].push(e),this},r.prototype.refreshBoundingInfo=function(){return this._refreshBoundingInfo(!1)},r.prototype._refreshBoundingInfo=function(t){if(this._boundingInfo&&this._boundingInfo.isLocked)return this;var i=this._getPositionData(t);if(i){var r=e.Tools.ExtractMinAndMax(i,0,this.getTotalVertices());this._boundingInfo=new e.BoundingInfo(r.minimum,r.maximum)}if(this.subMeshes)for(var n=0;n<this.subMeshes.length;n++)this.subMeshes[n].refreshBoundingInfo();return this._updateBoundingInfo(),this},r.prototype._getPositionData=function(t){var i=this.getVerticesData(e.VertexBuffer.PositionKind);if(i&&t&&this.skeleton){i=i.slice();var r=this.getVerticesData(e.VertexBuffer.MatricesIndicesKind),n=this.getVerticesData(e.VertexBuffer.MatricesWeightsKind);if(n&&r)for(var o=this.numBoneInfluencers>4,s=o?this.getVerticesData(e.VertexBuffer.MatricesIndicesExtraKind):null,a=o?this.getVerticesData(e.VertexBuffer.MatricesWeightsExtraKind):null,h=this.skeleton.getTransformMatrices(this),l=e.Tmp.Vector3[0],c=e.Tmp.Matrix[0],u=e.Tmp.Matrix[1],p=0,f=0;f<i.length;f+=3,p+=4){var d,m;for(c.reset(),d=0;d<4&&!((m=n[p+d])<=0);d++)e.Matrix.FromFloat32ArrayToRefScaled(h,16*r[p+d],m,u),c.addToSelf(u);if(o)for(d=0;d<4&&!((m=a[p+d])<=0);d++)e.Matrix.FromFloat32ArrayToRefScaled(h,16*s[p+d],m,u),c.addToSelf(u);e.Vector3.TransformCoordinatesFromFloatsToRef(i[f],i[f+1],i[f+2],c,l),l.toArray(i,f)}}return i},r.prototype._createGlobalSubMesh=function(t){var i=this.getTotalVertices();if(!i||!this.getIndices())return null;if(this.subMeshes&&this.subMeshes.length>0){var r=this.getIndices();if(!r)return null;var n=r.length,o=!1;if(t)o=!0;else for(var s=0,a=this.subMeshes;s<a.length;s++){var h=a[s];if(h.indexStart+h.indexCount>=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<t&&!(n>=i);o++)e.SubMesh.CreateFromIndices(0,n,Math.min(r,i-n),this),n+=r;this.synchronizeInstances()}},r.prototype.setVerticesData=function(t,i,r,n){if(void 0===r&&(r=!1),this._geometry)this._geometry.setVerticesData(t,i,r,n);else{var o=new e.VertexData;o.set(i,t);var s=this.getScene();new e.Geometry(e.Geometry.RandomId(),s,o,r,this)}return this},r.prototype.markVerticesDataAsUpdatable=function(e,t){void 0===t&&(t=!0);var i=this.getVertexBuffer(e);i&&i.isUpdatable()!==t&&this.setVerticesData(e,this.getVerticesData(e),t)},r.prototype.setVerticesBuffer=function(t){return this._geometry||(this._geometry=e.Geometry.CreateGeometryForMesh(this)),this._geometry.setVerticesBuffer(t),this},r.prototype.updateVerticesData=function(e,t,i,r){return this._geometry?(r?(this.makeGeometryUnique(),this.updateVerticesData(e,t,i,!1)):this._geometry.updateVerticesData(e,t,i),this):this},r.prototype.updateMeshPositions=function(t,i){void 0===i&&(i=!0);var r=this.getVerticesData(e.VertexBuffer.PositionKind);if(!r)return this;if(t(r),this.updateVerticesData(e.VertexBuffer.PositionKind,r,!1,!1),i){var n=this.getIndices(),o=this.getVerticesData(e.VertexBuffer.NormalKind);if(!o)return this;e.VertexData.ComputeNormals(r,n,o),this.updateVerticesData(e.VertexBuffer.NormalKind,o,!1,!1)}return this},r.prototype.makeGeometryUnique=function(){if(!this._geometry)return this;var t=this._geometry,i=this._geometry.copy(e.Geometry.RandomId());return t.releaseForMesh(this,!0),i.applyToMesh(this),this},r.prototype.setIndices=function(t,i,r){if(void 0===i&&(i=null),void 0===r&&(r=!1),this._geometry)this._geometry.setIndices(t,i,r);else{var n=new e.VertexData;n.indices=t;var o=this.getScene();new e.Geometry(e.Geometry.RandomId(),o,n,r,this)}return this},r.prototype.updateIndices=function(e,t){return this._geometry?(this._geometry.updateIndices(e,t),this):this},r.prototype.toLeftHanded=function(){return this._geometry?(this._geometry.toLeftHanded(),this):this},r.prototype._bind=function(t,i,r){if(!this._geometry)return this;var n,o=this.getScene().getEngine();if(this._unIndexed)n=null;else switch(r){case e.Material.PointFillMode:n=null;break;case e.Material.WireFrameFillMode:n=t.getLinesIndexBuffer(this.getIndices(),o);break;default:case e.Material.TriangleFillMode:n=this._unIndexed?null:this._geometry.getIndexBuffer()}return this._geometry._bind(i,n),this},r.prototype._draw=function(t,i,r,n){if(void 0===n&&(n=!1),!this._geometry||!this._geometry.getVertexBuffers()||!this._geometry.getIndexBuffer())return this;this.onBeforeDrawObservable.notifyObservers(this);var o=this.getScene(),s=o.getEngine();if(this._unIndexed||i==e.Material.PointFillMode?s.drawArraysType(i,t.verticesStart,t.verticesCount,r):i==e.Material.WireFrameFillMode?s.drawElementsType(i,0,t.linesIndexCount,r):s.drawElementsType(i,t.indexStart,t.indexCount,r),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<a;)this._instancesBufferSize*=2;this._instancesData&&h==this._instancesBufferSize||(this._instancesData=new Float32Array(this._instancesBufferSize/4));var c=0,u=0,p=this.getWorldMatrix();if(r.renderSelf[t._id]&&(p.copyToArray(this._instancesData,c),c+=16,u++),s)for(var f=0;f<s.length;f++){s[f].getWorldMatrix().copyToArray(this._instancesData,c),c+=16,u++}return l&&h==this._instancesBufferSize?l.updateDirectly(this._instancesData,0,u):(l&&l.dispose(),l=new e.Buffer(o,this._instancesData,!0,16,!1,!0),this._instancesBuffer=l,this.setVerticesBuffer(l.createVertexBuffer("world0",0,4)),this.setVerticesBuffer(l.createVertexBuffer("world1",4,4)),this.setVerticesBuffer(l.createVertexBuffer("world2",8,4)),this.setVerticesBuffer(l.createVertexBuffer("world3",12,4))),this._bind(t,n,i),this._draw(t,i,u),o.unbindInstanceAttributes(),this},r.prototype._processRendering=function(e,t,i,r,n,o,s){var a=this.getScene().getEngine();if(n)this._renderWithInstances(e,i,r,t,a);else{r.renderSelf[e._id]&&(o&&o(!1,this.getWorldMatrix(),s),this._draw(e,i,this._overridenInstanceCount));var h=r.visibleInstances[e._id];if(h)for(var l=0;l<h.length;l++){var c=h[l].getWorldMatrix();o&&o(!0,c,s),this._draw(e,i)}}return this},r.prototype.render=function(t,i){if(this.checkOcclusionQuery(),this._isOccluded)return this;var r=this.getScene(),n=this._getInstancesRenderList(t._id);if(n.mustReturn)return this;if(!this._geometry||!this._geometry.getVertexBuffers()||!this._geometry.getIndexBuffer())return this;this.onBeforeRenderObservable.notifyObservers(this);var o=r.getEngine(),s=o.getCaps().instancedArrays&&null!==n.visibleInstances[t._id]&&void 0!==n.visibleInstances[t._id],a=t.getMaterial();if(!a)return this;if(this._effectiveMaterial=a,this._effectiveMaterial.storeEffectOnSubMeshes){if(!this._effectiveMaterial.isReadyForSubMesh(this,t,s))return this}else if(!this._effectiveMaterial.isReady(this,s))return this;i&&o.setAlphaMode(this._effectiveMaterial.alphaMode);var h,l=o.getDepthWrite();if(this.renderOutline&&(o.setDepthWrite(!1),r.getOutlineRenderer().render(t,n),o.setDepthWrite(l)),!(h=this._effectiveMaterial.storeEffectOnSubMeshes?t.effect:this._effectiveMaterial.getEffect()))return this;var c=this.overrideMaterialSideOrientation;null==c&&(c=this._effectiveMaterial.sideOrientation,this._getWorldMatrixDeterminant()<0&&(c=c===e.Material.ClockWiseSideOrientation?e.Material.CounterClockWiseSideOrientation:e.Material.ClockWiseSideOrientation));var u=this._effectiveMaterial._preBind(h,c);this._effectiveMaterial.forceDepthWrite&&o.setDepthWrite(!0);var p=r.forcePointsCloud?e.Material.PointFillMode:r.forceWireframe?e.Material.WireFrameFillMode:this._effectiveMaterial.fillMode;s||this._bind(t,h,p);var f=this.getWorldMatrix();if(this._effectiveMaterial.storeEffectOnSubMeshes?this._effectiveMaterial.bindForSubMesh(f,this,t):this._effectiveMaterial.bind(f,this),!this._effectiveMaterial.backFaceCulling&&this._effectiveMaterial.separateCullingPass&&(o.setState(!0,this._effectiveMaterial.zOffset,!1,!u),this._processRendering(t,h,p,n,s,this._onBeforeDraw,this._effectiveMaterial),o.setState(!0,this._effectiveMaterial.zOffset,!1,u)),this._processRendering(t,h,p,n,s,this._onBeforeDraw,this._effectiveMaterial),this._effectiveMaterial.unbind(),this.renderOutline&&l&&(o.setDepthWrite(!0),o.setColorWrite(!1),r.getOutlineRenderer().render(t,n),o.setColorWrite(!0)),this.renderOverlay){var d=o.getAlphaMode();o.setAlphaMode(e.Engine.ALPHA_COMBINE),r.getOutlineRenderer().render(t,n,!0),o.setAlphaMode(d)}return this.onAfterRenderObservable.notifyObservers(this),this},r.prototype._onBeforeDraw=function(e,t,i){e&&i&&i.bindOnlyWorldMatrix(t)},r.prototype.getEmittedParticleSystems=function(){for(var e=new Array,t=0;t<this.getScene().particleSystems.length;t++){var i=this.getScene().particleSystems[t];i.emitter===this&&e.push(i)}return e},r.prototype.getHierarchyEmittedParticleSystems=function(){var e=new Array,t=this.getDescendants();t.push(this);for(var i=0;i<this.getScene().particleSystems.length;i++){var r=this.getScene().particleSystems[i],n=r.emitter;n.position&&-1!==t.indexOf(n)&&e.push(r)}return e},r.prototype._checkDelayState=function(){var t=this.getScene();return this._geometry?this._geometry.load(t):this.delayLoadState===e.Engine.DELAYLOADSTATE_NOTLOADED&&(this.delayLoadState=e.Engine.DELAYLOADSTATE_LOADING,this._queueLoad(t)),this},r.prototype._queueLoad=function(t){var i=this;t._addPendingData(this);var r=-1!==this.delayLoadingFile.indexOf(".babylonbinarymeshdata");return e.Tools.LoadFile(this.delayLoadingFile,function(r){r instanceof ArrayBuffer?i._delayLoadingFunction(r,i):i._delayLoadingFunction(JSON.parse(r),i),i.instances.forEach(function(e){e._syncSubMeshes()}),i.delayLoadState=e.Engine.DELAYLOADSTATE_LOADED,t._removePendingData(i)},function(){},t.database,r),this},r.prototype.isInFrustum=function(t){return this.delayLoadState!==e.Engine.DELAYLOADSTATE_LOADING&&(!!i.prototype.isInFrustum.call(this,t)&&(this._checkDelayState(),!0))},r.prototype.setMaterialByID=function(e){var t,i=this.getScene().materials;for(t=i.length-1;t>-1;t--)if(i[t].id===e)return this.material=i[t],this;var r=this.getScene().multiMaterials;for(t=r.length-1;t>-1;t--)if(r[t].id===e)return this.material=r[t],this;return this},r.prototype.getAnimatables=function(){var e=new Array;return this.material&&e.push(this.material),this.skeleton&&e.push(this.skeleton),e},r.prototype.bakeTransformIntoVertices=function(t){if(!this.isVerticesDataPresent(e.VertexBuffer.PositionKind))return this;var i=this.subMeshes.splice(0);this._resetPointsArrayCache();var r,n=this.getVerticesData(e.VertexBuffer.PositionKind),o=new Array;for(r=0;r<n.length;r+=3)e.Vector3.TransformCoordinates(e.Vector3.FromArray(n,r),t).toArray(o,r);if(this.setVerticesData(e.VertexBuffer.PositionKind,o,this.getVertexBuffer(e.VertexBuffer.PositionKind).isUpdatable()),!this.isVerticesDataPresent(e.VertexBuffer.NormalKind))return this;for(n=this.getVerticesData(e.VertexBuffer.NormalKind),o=[],r=0;r<n.length;r+=3)e.Vector3.TransformNormal(e.Vector3.FromArray(n,r),t).normalize().toArray(o,r);return this.setVerticesData(e.VertexBuffer.NormalKind,o,this.getVertexBuffer(e.VertexBuffer.NormalKind).isUpdatable()),t.m[0]*t.m[5]*t.m[10]<0&&this.flipFaces(),this.releaseSubMeshes(),this.subMeshes=i,this},r.prototype.bakeCurrentTransformIntoVertices=function(){return this.bakeTransformIntoVertices(this.computeWorldMatrix(!0)),this.scaling.copyFromFloats(1,1,1),this.position.copyFromFloats(0,0,0),this.rotation.copyFromFloats(0,0,0),this.rotationQuaternion&&(this.rotationQuaternion=e.Quaternion.Identity()),this._worldMatrix=e.Matrix.Identity(),this},Object.defineProperty(r.prototype,"_positions",{get:function(){return this._geometry?this._geometry._positions:null},enumerable:!0,configurable:!0}),r.prototype._resetPointsArrayCache=function(){return this._geometry&&this._geometry._resetPointsArrayCache(),this},r.prototype._generatePointsArray=function(){return!!this._geometry&&this._geometry._generatePointsArray()},r.prototype.clone=function(e,t,i,n){return void 0===n&&(n=!0),new r(e,this.getScene(),t,this,i,n)},r.prototype.dispose=function(e,t){var r=this;for(void 0===t&&(t=!1),this.morphTargetManager=null,this._geometry&&this._geometry.releaseForMesh(this,!0),this.getScene().meshes.forEach(function(e){var t=e;t._source&&t._source===r&&(t._source=null)}),this._source=null,this._instancesBuffer&&(this._instancesBuffer.dispose(),this._instancesBuffer=null);this.instances.length;)this.instances[0].dispose();for(var n=this.getScene().highlightLayers,o=0;o<n.length;o++){var s=n[o];s&&(s.removeMesh(this),s.removeExcludedMesh(this))}i.prototype.dispose.call(this,e,t)},r.prototype.applyDisplacementMap=function(t,i,r,n,o,s){var a=this,h=this.getScene();return e.Tools.LoadImage(t,function(e){var t=document.createElement("canvas"),h=t.getContext("2d"),l=e.width,c=e.height;t.width=l,t.height=c,h.drawImage(e,0,0);var u=h.getImageData(0,0,l,c).data;a.applyDisplacementMapFromBuffer(u,l,c,i,r,o,s),n&&n(a)},function(){},h.database),this},r.prototype.applyDisplacementMapFromBuffer=function(t,i,r,n,o,s,a){if(!this.isVerticesDataPresent(e.VertexBuffer.PositionKind)||!this.isVerticesDataPresent(e.VertexBuffer.NormalKind)||!this.isVerticesDataPresent(e.VertexBuffer.UVKind))return e.Tools.Warn("Cannot call applyDisplacementMap: Given mesh is not complete. Position, Normal or UV are missing"),this;var h=this.getVerticesData(e.VertexBuffer.PositionKind),l=this.getVerticesData(e.VertexBuffer.NormalKind),c=this.getVerticesData(e.VertexBuffer.UVKind),u=e.Vector3.Zero(),p=e.Vector3.Zero(),f=e.Vector2.Zero();s=s||e.Vector2.Zero(),a=a||new e.Vector2(1,1);for(var d=0;d<h.length;d+=3){e.Vector3.FromArrayToRef(h,d,u),e.Vector3.FromArrayToRef(l,d,p),e.Vector2.FromArrayToRef(c,d/3*2,f);var m=4*((Math.abs(f.x*a.x+s.x)*i%i|0)+(Math.abs(f.y*a.y+s.y)*r%r|0)*i),g=.3*(t[m]/255)+.59*(t[m+1]/255)+.11*(t[m+2]/255);p.normalize(),p.scaleInPlace(n+(o-n)*g),(u=u.add(p)).toArray(h,d)}return e.VertexData.ComputeNormals(h,this.getIndices(),l),this.updateVerticesData(e.VertexBuffer.PositionKind,h),this.updateVerticesData(e.VertexBuffer.NormalKind,l),this},r.prototype.convertToFlatShadedMesh=function(){var t,i,r=this.getVerticesDataKinds(),n={},o={},s={},a=!1;for(t=0;t<r.length;t++){i=r[t];var h=this.getVertexBuffer(i);i!==e.VertexBuffer.NormalKind?(n[i]=h,o[i]=n[i].getData(),s[i]=[]):(a=h.isUpdatable(),r.splice(t,1),t--)}var l,c=this.subMeshes.slice(0),u=this.getIndices(),p=this.getTotalIndices();for(l=0;l<p;l++){var f=u[l];for(t=0;t<r.length;t++)for(var d=n[i=r[t]].getStrideSize(),m=0;m<d;m++)s[i].push(o[i][f*d+m])}var g=[],_=s[e.VertexBuffer.PositionKind];for(l=0;l<p;l+=3){u[l]=l,u[l+1]=l+1,u[l+2]=l+2;for(var v=e.Vector3.FromArray(_,3*l),y=e.Vector3.FromArray(_,3*(l+1)),b=e.Vector3.FromArray(_,3*(l+2)),x=v.subtract(y),T=b.subtract(y),E=e.Vector3.Normalize(e.Vector3.Cross(x,T)),A=0;A<3;A++)g.push(E.x),g.push(E.y),g.push(E.z)}for(this.setIndices(u),this.setVerticesData(e.VertexBuffer.NormalKind,g,a),t=0;t<r.length;t++)i=r[t],this.setVerticesData(i,s[i],n[i].isUpdatable());this.releaseSubMeshes();for(var P=0;P<c.length;P++){var M=c[P];e.SubMesh.AddToMesh(M.materialIndex,M.indexStart,M.indexCount,M.indexStart,M.indexCount,this)}return this.synchronizeInstances(),this},r.prototype.convertToUnIndexedMesh=function(){var t,i,r=this.getVerticesDataKinds(),n={},o={},s={};for(t=0;t<r.length;t++){i=r[t];var a=this.getVertexBuffer(i);n[i]=a,o[i]=n[i].getData(),s[i]=[]}var h,l=this.subMeshes.slice(0),c=this.getIndices(),u=this.getTotalIndices();for(h=0;h<u;h++){var p=c[h];for(t=0;t<r.length;t++)for(var f=n[i=r[t]].getStrideSize(),d=0;d<f;d++)s[i].push(o[i][p*f+d])}for(h=0;h<u;h+=3)c[h]=h,c[h+1]=h+1,c[h+2]=h+2;for(this.setIndices(c),t=0;t<r.length;t++)i=r[t],this.setVerticesData(i,s[i],n[i].isUpdatable());this.releaseSubMeshes();for(var m=0;m<l.length;m++){var g=l[m];e.SubMesh.AddToMesh(g.materialIndex,g.indexStart,g.indexCount,g.indexStart,g.indexCount,this)}return this._unIndexed=!0,this.synchronizeInstances(),this},r.prototype.flipFaces=function(t){void 0===t&&(t=!1);var i,r,n=e.VertexData.ExtractFromMesh(this);if(t&&this.isVerticesDataPresent(e.VertexBuffer.NormalKind)&&n.normals)for(i=0;i<n.normals.length;i++)n.normals[i]*=-1;if(n.indices)for(i=0;i<n.indices.length;i+=3)r=n.indices[i+1],n.indices[i+1]=n.indices[i+2],n.indices[i+2]=r;return n.applyToMesh(this),this},r.prototype.createInstance=function(t){return new e.InstancedMesh(t,this)},r.prototype.synchronizeInstances=function(){for(var e=0;e<this.instances.length;e++){this.instances[e]._syncSubMeshes()}return this},r.prototype.simplify=function(t,i,r,n){return void 0===i&&(i=!0),void 0===r&&(r=e.SimplificationType.QUADRATIC),this.getScene().simplificationQueue.addTask({settings:t,parallelProcessing:i,mesh:this,simplificationType:r,successCallback:n}),this},r.prototype.optimizeIndices=function(t){var i=this,r=this.getIndices(),n=this.getVerticesData(e.VertexBuffer.PositionKind);if(!n||!r)return this;for(var o=new Array,s=0;s<n.length;s+=3)o.push(e.Vector3.FromArray(n,s));var a=new Array;return e.AsyncLoop.SyncAsyncForLoop(o.length,40,function(e){for(var t=o.length-1-e,i=o[t],r=0;r<t;++r){var n=o[r];if(i.equals(n)){a[t]=r;break}}},function(){for(var e=0;e<r.length;++e)r[e]=a[r[e]]||r[e];var n=i.subMeshes.slice(0);i.setIndices(r),i.subMeshes=n,t&&t(i)}),this},r.prototype.serialize=function(t){t.name=this.name,t.id=this.id,t.type=this.getClassName(),e.Tags&&e.Tags.HasTags(this)&&(t.tags=e.Tags.GetTags(this)),t.position=this.position.asArray(),this.rotationQuaternion?t.rotationQuaternion=this.rotationQuaternion.asArray():this.rotation&&(t.rotation=this.rotation.asArray()),t.scaling=this.scaling.asArray(),t.localMatrix=this.getPivotMatrix().asArray(),t.isEnabled=this.isEnabled(!1),t.isVisible=this.isVisible,t.infiniteDistance=this.infiniteDistance,t.pickable=this.isPickable,t.receiveShadows=this.receiveShadows,t.billboardMode=this.billboardMode,t.visibility=this.visibility,t.checkCollisions=this.checkCollisions,t.isBlocker=this.isBlocker,this.parent&&(t.parentId=this.parent.id),t.isUnIndexed=this.isUnIndexed;var i=this._geometry;if(i){var r=i.id;t.geometryId=r,t.subMeshes=[];for(var n=0;n<this.subMeshes.length;n++){var o=this.subMeshes[n];t.subMeshes.push({materialIndex:o.materialIndex,verticesStart:o.verticesStart,verticesCount:o.verticesCount,indexStart:o.indexStart,indexCount:o.indexCount})}}this.material?t.materialId=this.material.id:this.material=null,this.morphTargetManager&&(t.morphTargetManagerId=this.morphTargetManager.uniqueId),this.skeleton&&(t.skeletonId=this.skeleton.id);var s=this.getPhysicsImpostor();s&&(t.physicsMass=s.getParam("mass"),t.physicsFriction=s.getParam("friction"),t.physicsRestitution=s.getParam("mass"),t.physicsImpostor=s.type),this.metadata&&(t.metadata=this.metadata),t.instances=[];for(var a=0;a<this.instances.length;a++){var h=this.instances[a],l={name:h.name,id:h.id,position:h.position.asArray(),scaling:h.scaling.asArray()};h.rotationQuaternion?l.rotationQuaternion=h.rotationQuaternion.asArray():h.rotation&&(l.rotation=h.rotation.asArray()),t.instances.push(l),e.Animation.AppendSerializedAnimations(h,l),l.ranges=h.serializeAnimationRanges()}e.Animation.AppendSerializedAnimations(this,t),t.ranges=this.serializeAnimationRanges(),t.layerMask=this.layerMask,t.alphaIndex=this.alphaIndex,t.hasVertexAlpha=this.hasVertexAlpha,t.overlayAlpha=this.overlayAlpha,t.overlayColor=this.overlayColor.asArray(),t.renderOverlay=this.renderOverlay,t.applyFog=this.applyFog,this.actionManager&&(t.actions=this.actionManager.serialize(this.name))},r.prototype._syncGeometryWithMorphTargetManager=function(){if(this.geometry){this._markSubMeshesAsAttributesDirty();var t=this._morphTargetManager;if(t&&t.vertexCount){if(t.vertexCount!==this.getTotalVertices())return e.Tools.Error("Mesh is incompatible with morph targets. Targets and mesh must all have the same vertices count."),void(this.morphTargetManager=null);for(var i=0;i<t.numInfluencers;i++){var r=t.getActiveTarget(i),n=r.getPositions();if(!n)return void e.Tools.Error("Invalid morph target. Target must have positions.");this.geometry.setVerticesData(e.VertexBuffer.PositionKind+i,n,!1,3);var o=r.getNormals();o&&this.geometry.setVerticesData(e.VertexBuffer.NormalKind+i,o,!1,3);var s=r.getTangents();s&&this.geometry.setVerticesData(e.VertexBuffer.TangentKind+i,s,!1,3)}}else for(i=0;this.geometry.isVerticesDataPresent(e.VertexBuffer.PositionKind+i);)this.geometry.removeVerticesData(e.VertexBuffer.PositionKind+i),this.geometry.isVerticesDataPresent(e.VertexBuffer.NormalKind+i)&&this.geometry.removeVerticesData(e.VertexBuffer.NormalKind+i),this.geometry.isVerticesDataPresent(e.VertexBuffer.TangentKind+i)&&this.geometry.removeVerticesData(e.VertexBuffer.TangentKind+i),i++}},r.Parse=function(t,i,n){var o;if((o=t.type&&"GroundMesh"===t.type?e.GroundMesh.Parse(t,i):new r(t.name,i)).id=t.id,e.Tags&&e.Tags.AddTagsTo(o,t.tags),o.position=e.Vector3.FromArray(t.position),void 0!==t.metadata&&(o.metadata=t.metadata),t.rotationQuaternion?o.rotationQuaternion=e.Quaternion.FromArray(t.rotationQuaternion):t.rotation&&(o.rotation=e.Vector3.FromArray(t.rotation)),o.scaling=e.Vector3.FromArray(t.scaling),t.localMatrix?o.setPivotMatrix(e.Matrix.FromArray(t.localMatrix)):t.pivotMatrix&&o.setPivotMatrix(e.Matrix.FromArray(t.pivotMatrix)),o.setEnabled(t.isEnabled),o.isVisible=t.isVisible,o.infiniteDistance=t.infiniteDistance,o.showBoundingBox=t.showBoundingBox,o.showSubMeshesBoundingBox=t.showSubMeshesBoundingBox,void 0!==t.applyFog&&(o.applyFog=t.applyFog),void 0!==t.pickable&&(o.isPickable=t.pickable),void 0!==t.alphaIndex&&(o.alphaIndex=t.alphaIndex),o.receiveShadows=t.receiveShadows,o.billboardMode=t.billboardMode,void 0!==t.visibility&&(o.visibility=t.visibility),o.checkCollisions=t.checkCollisions,void 0!==t.isBlocker&&(o.isBlocker=t.isBlocker),o._shouldGenerateFlatShading=t.useFlatShading,t.freezeWorldMatrix&&(o._waitingFreezeWorldMatrix=t.freezeWorldMatrix),t.parentId&&(o._waitingParentId=t.parentId),void 0!==t.actions&&(o._waitingActions=t.actions),void 0!==t.overlayAlpha&&(o.overlayAlpha=t.overlayAlpha),void 0!==t.overlayColor&&(o.overlayColor=e.Color3.FromArray(t.overlayColor)),void 0!==t.renderOverlay&&(o.renderOverlay=t.renderOverlay),o.isUnIndexed=!!t.isUnIndexed,o.hasVertexAlpha=t.hasVertexAlpha,t.delayLoadingFile?(o.delayLoadState=e.Engine.DELAYLOADSTATE_NOTLOADED,o.delayLoadingFile=n+t.delayLoadingFile,o._boundingInfo=new e.BoundingInfo(e.Vector3.FromArray(t.boundingBoxMinimum),e.Vector3.FromArray(t.boundingBoxMaximum)),t._binaryInfo&&(o._binaryInfo=t._binaryInfo),o._delayInfo=[],t.hasUVs&&o._delayInfo.push(e.VertexBuffer.UVKind),t.hasUVs2&&o._delayInfo.push(e.VertexBuffer.UV2Kind),t.hasUVs3&&o._delayInfo.push(e.VertexBuffer.UV3Kind),t.hasUVs4&&o._delayInfo.push(e.VertexBuffer.UV4Kind),t.hasUVs5&&o._delayInfo.push(e.VertexBuffer.UV5Kind),t.hasUVs6&&o._delayInfo.push(e.VertexBuffer.UV6Kind),t.hasColors&&o._delayInfo.push(e.VertexBuffer.ColorKind),t.hasMatricesIndices&&o._delayInfo.push(e.VertexBuffer.MatricesIndicesKind),t.hasMatricesWeights&&o._delayInfo.push(e.VertexBuffer.MatricesWeightsKind),o._delayLoadingFunction=e.Geometry.ImportGeometry,e.SceneLoader.ForceFullSceneLoadingForIncremental&&o._checkDelayState()):e.Geometry.ImportGeometry(t,o),t.materialId?o.setMaterialByID(t.materialId):o.material=null,t.morphTargetManagerId>-1&&(o.morphTargetManager=i.getMorphTargetManagerById(t.morphTargetManagerId)),t.skeletonId>-1&&(o.skeleton=i.getLastSkeletonByID(t.skeletonId),t.numBoneInfluencers&&(o.numBoneInfluencers=t.numBoneInfluencers)),t.animations){for(var s=0;s<t.animations.length;s++){var a=t.animations[s];o.animations.push(e.Animation.Parse(a))}e.Node.ParseAnimationRanges(o,t,i)}if(t.autoAnimate&&i.beginAnimation(o,t.autoAnimateFrom,t.autoAnimateTo,t.autoAnimateLoop,t.autoAnimateSpeed||1),t.layerMask&&!isNaN(t.layerMask)?o.layerMask=Math.abs(parseInt(t.layerMask)):o.layerMask=268435455,t.physicsImpostor&&(o.physicsImpostor=new e.PhysicsImpostor(o,t.physicsImpostor,{mass:t.physicsMass,friction:t.physicsFriction,restitution:t.physicsRestitution},i)),t.instances)for(var h=0;h<t.instances.length;h++){var l=t.instances[h],c=o.createInstance(l.name);if(l.id&&(c.id=l.id),e.Tags&&e.Tags.AddTagsTo(c,l.tags),c.position=e.Vector3.FromArray(l.position),l.parentId&&(c._waitingParentId=l.parentId),l.rotationQuaternion?c.rotationQuaternion=e.Quaternion.FromArray(l.rotationQuaternion):l.rotation&&(c.rotation=e.Vector3.FromArray(l.rotation)),c.scaling=e.Vector3.FromArray(l.scaling),c.checkCollisions=o.checkCollisions,t.animations){for(s=0;s<t.animations.length;s++)a=t.animations[s],c.animations.push(e.Animation.Parse(a));e.Node.ParseAnimationRanges(c,t,i)}}return o},r.CreateRibbon=function(t,i,r,n,o,s,a,h,l){return void 0===r&&(r=!1),void 0===a&&(a=!1),e.MeshBuilder.CreateRibbon(t,{pathArray:i,closeArray:r,closePath:n,offset:o,updatable:a,sideOrientation:h,instance:l},s)},r.CreateDisc=function(t,i,r,n,o,s){void 0===n&&(n=null);var a={radius:i,tessellation:r,sideOrientation:s,updatable:o};return e.MeshBuilder.CreateDisc(t,a,n)},r.CreateBox=function(t,i,r,n,o){void 0===r&&(r=null);var s={size:i,sideOrientation:o,updatable:n};return e.MeshBuilder.CreateBox(t,s,r)},r.CreateSphere=function(t,i,r,n,o,s){var a={segments:i,diameterX:r,diameterY:r,diameterZ:r,sideOrientation:s,updatable:o};return e.MeshBuilder.CreateSphere(t,a,n)},r.CreateCylinder=function(t,i,n,o,s,a,h,l,c){void 0!==h&&h instanceof e.Scene||(void 0!==h&&(c=l||r.DEFAULTSIDE,l=h),h=a,a=1);var u={height:i,diameterTop:n,diameterBottom:o,tessellation:s,subdivisions:a,sideOrientation:c,updatable:l};return e.MeshBuilder.CreateCylinder(t,u,h)},r.CreateTorus=function(t,i,r,n,o,s,a){var h={diameter:i,thickness:r,tessellation:n,sideOrientation:a,updatable:s};return e.MeshBuilder.CreateTorus(t,h,o)},r.CreateTorusKnot=function(t,i,r,n,o,s,a,h,l,c){var u={radius:i,tube:r,radialSegments:n,tubularSegments:o,p:s,q:a,sideOrientation:c,updatable:l};return e.MeshBuilder.CreateTorusKnot(t,u,h)},r.CreateLines=function(t,i,r,n,o){void 0===r&&(r=null),void 0===n&&(n=!1),void 0===o&&(o=null);var s={points:i,updatable:n,instance:o};return e.MeshBuilder.CreateLines(t,s,r)},r.CreateDashedLines=function(t,i,r,n,o,s,a,h){void 0===s&&(s=null);var l={points:i,dashSize:r,gapSize:n,dashNb:o,updatable:a,instance:h};return e.MeshBuilder.CreateDashedLines(t,l,s)},r.CreatePolygon=function(t,i,r,n,o,s){var a={shape:i,holes:n,updatable:o,sideOrientation:s};return e.MeshBuilder.CreatePolygon(t,a,r)},r.ExtrudePolygon=function(t,i,r,n,o,s,a){var h={shape:i,holes:o,depth:r,updatable:s,sideOrientation:a};return e.MeshBuilder.ExtrudePolygon(t,h,n)},r.ExtrudeShape=function(t,i,n,o,s,a,h,l,c,u){void 0===h&&(h=null);var p={shape:i,path:n,scale:o,rotation:s,cap:0===a?0:a||r.NO_CAP,sideOrientation:c,instance:u,updatable:l};return e.MeshBuilder.ExtrudeShape(t,p,h)},r.ExtrudeShapeCustom=function(t,i,n,o,s,a,h,l,c,u,p,f){var d={shape:i,path:n,scaleFunction:o,rotationFunction:s,ribbonCloseArray:a,ribbonClosePath:h,cap:0===l?0:l||r.NO_CAP,sideOrientation:p,instance:f,updatable:u};return e.MeshBuilder.ExtrudeShapeCustom(t,d,c)},r.CreateLathe=function(t,i,r,n,o,s,a){var h={shape:i,radius:r,tessellation:n,sideOrientation:a,updatable:s};return e.MeshBuilder.CreateLathe(t,h,o)},r.CreatePlane=function(t,i,r,n,o){var s={size:i,width:i,height:i,sideOrientation:o,updatable:n};return e.MeshBuilder.CreatePlane(t,s,r)},r.CreateGround=function(t,i,r,n,o,s){var a={width:i,height:r,subdivisions:n,updatable:s};return e.MeshBuilder.CreateGround(t,a,o)},r.CreateTiledGround=function(t,i,r,n,o,s,a,h,l){var c={xmin:i,zmin:r,xmax:n,zmax:o,subdivisions:s,precision:a,updatable:l};return e.MeshBuilder.CreateTiledGround(t,c,h)},r.CreateGroundFromHeightMap=function(t,i,r,n,o,s,a,h,l,c){var u={width:r,height:n,subdivisions:o,minHeight:s,maxHeight:a,updatable:l,onReady:c};return e.MeshBuilder.CreateGroundFromHeightMap(t,i,u,h)},r.CreateTube=function(t,i,r,n,o,s,a,h,l,c){var u={path:i,radius:r,tessellation:n,radiusFunction:o,arc:1,cap:s,updatable:h,sideOrientation:l,instance:c};return e.MeshBuilder.CreateTube(t,u,a)},r.CreatePolyhedron=function(t,i,r){return e.MeshBuilder.CreatePolyhedron(t,i,r)},r.CreateIcoSphere=function(t,i,r){return e.MeshBuilder.CreateIcoSphere(t,i,r)},r.CreateDecal=function(t,i,r,n,o,s){var a={position:r,normal:n,size:o,angle:s};return e.MeshBuilder.CreateDecal(t,i,a)},r.prototype.setPositionsForCPUSkinning=function(){if(!this._sourcePositions){var t=this.getVerticesData(e.VertexBuffer.PositionKind);if(!t)return this._sourcePositions;this._sourcePositions=new Float32Array(t),this.isVertexBufferUpdatable(e.VertexBuffer.PositionKind)||this.setVerticesData(e.VertexBuffer.PositionKind,t,!0)}return this._sourcePositions},r.prototype.setNormalsForCPUSkinning=function(){if(!this._sourceNormals){var t=this.getVerticesData(e.VertexBuffer.NormalKind);if(!t)return this._sourceNormals;this._sourceNormals=new Float32Array(t),this.isVertexBufferUpdatable(e.VertexBuffer.NormalKind)||this.setVerticesData(e.VertexBuffer.NormalKind,t,!0)}return this._sourceNormals},r.prototype.applySkeleton=function(t){if(!this.geometry)return this;if(this.geometry._softwareSkinningRenderId==this.getScene().getRenderId())return this;if(this.geometry._softwareSkinningRenderId=this.getScene().getRenderId(),!this.isVerticesDataPresent(e.VertexBuffer.PositionKind))return this;if(!this.isVerticesDataPresent(e.VertexBuffer.NormalKind))return this;if(!this.isVerticesDataPresent(e.VertexBuffer.MatricesIndicesKind))return this;if(!this.isVerticesDataPresent(e.VertexBuffer.MatricesWeightsKind))return this;if(!this._sourcePositions){var i=this.subMeshes.slice();this.setPositionsForCPUSkinning(),this.subMeshes=i}this._sourceNormals||this.setNormalsForCPUSkinning();var r=this.getVerticesData(e.VertexBuffer.PositionKind);if(!r)return this;r instanceof Float32Array||(r=new Float32Array(r));var n=this.getVerticesData(e.VertexBuffer.NormalKind);if(!n)return this;n instanceof Float32Array||(n=new Float32Array(n));var o=this.getVerticesData(e.VertexBuffer.MatricesIndicesKind),s=this.getVerticesData(e.VertexBuffer.MatricesWeightsKind);if(!s||!o)return this;for(var a,h=this.numBoneInfluencers>4,l=h?this.getVerticesData(e.VertexBuffer.MatricesIndicesExtraKind):null,c=h?this.getVerticesData(e.VertexBuffer.MatricesWeightsExtraKind):null,u=t.getTransformMatrices(this),p=e.Vector3.Zero(),f=new e.Matrix,d=new e.Matrix,m=0,g=0;g<r.length;g+=3,m+=4){var _;for(a=0;a<4&&(_=s[m+a])>0;a++)e.Matrix.FromFloat32ArrayToRefScaled(u,16*o[m+a],_,d),f.addToSelf(d);if(h)for(a=0;a<4&&(_=c[m+a])>0;a++)e.Matrix.FromFloat32ArrayToRefScaled(u,16*l[m+a],_,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?r.MinMax(t):t;return e.Vector3.Center(i.min,i.max)},r.MergeMeshes=function(t,i,n,o,s){var a;if(void 0===i&&(i=!0),!n){var h=0;for(a=0;a<t.length;a++)if(t[a]&&(h+=t[a].getTotalVertices())>65536)return e.Tools.Warn("Cannot merge meshes because resulting mesh will have more than 65536 vertices. Please use allow32BitsIndices = true to use 32 bits indices"),null}var l,c=null,u=new Array,p=null;for(a=0;a<t.length;a++)t[a]&&(t[a].computeWorldMatrix(!0),(l=e.VertexData.ExtractFromMesh(t[a],!0)).transform(t[a].getWorldMatrix()),c?c.merge(l):(c=l,p=t[a]),s&&u.push(t[a].getTotalIndices()));if(p=p,o||(o=new r(p.name+"_merged",p.getScene())),c.applyToMesh(o),o.material=p.material,o.checkCollisions=p.checkCollisions,i)for(a=0;a<t.length;a++)t[a]&&t[a].dispose();if(s){o.releaseSubMeshes(),a=0;for(var f=0;a<u.length;)e.SubMesh.CreateFromIndices(0,f,u[a],o),f+=u[a],a++}return o},r._FRONTSIDE=0,r._BACKSIDE=1,r._DOUBLESIDE=2,r._DEFAULTSIDE=0,r._NO_CAP=0,r._CAP_START=1,r._CAP_END=2,r._CAP_ALL=3,r}(e.AbstractMesh);e.Mesh=i}(us||(us={})),function(e){var t=function(){function e(){}return Object.defineProperty(e.prototype,"effect",{get:function(){return this._materialEffect},enumerable:!0,configurable:!0}),e.prototype.setEffect=function(e,t){void 0===t&&(t=null),this._materialEffect!==e?(this._materialDefines=t,this._materialEffect=e):e||(this._materialDefines=null)},e}();e.BaseSubMesh=t;var i=function(t){function i(e,i,r,n,o,s,a,h){void 0===h&&(h=!0);var l=t.call(this)||this;return l.materialIndex=e,l.verticesStart=i,l.verticesCount=r,l.indexStart=n,l.indexCount=o,l._renderId=0,l._mesh=s,l._renderingMesh=a||s,s.subMeshes.push(l),l._trianglePlanes=[],l._id=s.subMeshes.length-1,h&&(l.refreshBoundingInfo(),s.computeWorldMatrix(!0)),l}return Y(i,t),i.AddToMesh=function(e,t,r,n,o,s,a,h){return void 0===h&&(h=!0),new i(e,t,r,n,o,s,a,h)},Object.defineProperty(i.prototype,"IsGlobal",{get:function(){return 0===this.verticesStart&&this.verticesCount==this._mesh.getTotalVertices()},enumerable:!0,configurable:!0}),i.prototype.getBoundingInfo=function(){return this.IsGlobal?this._mesh.getBoundingInfo():this._boundingInfo},i.prototype.setBoundingInfo=function(e){return this._boundingInfo=e,this},i.prototype.getMesh=function(){return this._mesh},i.prototype.getRenderingMesh=function(){return this._renderingMesh},i.prototype.getMaterial=function(){var e=this._renderingMesh.material;if(null===e||void 0===e)return this._mesh.getScene().defaultMaterial;if(e.getSubMaterial){var t=e.getSubMaterial(this.materialIndex);return this._currentMaterial!==t&&(this._currentMaterial=t,this._materialDefines=null),t}return e},i.prototype.refreshBoundingInfo=function(){if(this._lastColliderWorldVertices=null,this.IsGlobal||!this._renderingMesh||!this._renderingMesh.geometry)return this;var t=this._renderingMesh.getVerticesData(e.VertexBuffer.PositionKind);if(!t)return this._boundingInfo=this._mesh.getBoundingInfo(),this;var i,r=this._renderingMesh.getIndices();if(0===this.indexStart&&this.indexCount===r.length){var n=this._renderingMesh.getBoundingInfo();i={minimum:n.minimum.clone(),maximum:n.maximum.clone()}}else i=e.Tools.ExtractMinAndMaxIndexed(t,r,this.indexStart,this.indexCount,this._renderingMesh.geometry.boundingBias);return this._boundingInfo=new e.BoundingInfo(i.minimum,i.maximum),this},i.prototype._checkCollision=function(e){return this._renderingMesh.getBoundingInfo()._checkCollision(e)},i.prototype.updateBoundingInfo=function(e){var t=this.getBoundingInfo();return t||(this.refreshBoundingInfo(),t=this.getBoundingInfo()),t.update(e),this},i.prototype.isInFrustum=function(e){var t=this.getBoundingInfo();return!!t&&t.isInFrustum(e)},i.prototype.isCompletelyInFrustum=function(e){var t=this.getBoundingInfo();return!!t&&t.isCompletelyInFrustum(e)},i.prototype.render=function(e){return this._renderingMesh.render(this,e),this},i.prototype.getLinesIndexBuffer=function(e,t){if(!this._linesIndexBuffer){for(var i=[],r=this.indexStart;r<this.indexStart+this.indexCount;r+=3)i.push(e[r],e[r+1],e[r+1],e[r+2],e[r+2],e[r]);this._linesIndexBuffer=t.createIndexBuffer(i),this.linesIndexCount=i.length}return this._linesIndexBuffer},i.prototype.canIntersects=function(e){var t=this.getBoundingInfo();return!!t&&e.intersectsBox(t.boundingBox)},i.prototype.intersects=function(t,i,r,n){var o=null;if(e.LinesMesh&&this._mesh instanceof e.LinesMesh)for(var s=this._mesh,a=this.indexStart;a<this.indexStart+this.indexCount;a+=2){var h=i[r[a]],l=i[r[a+1]],c=t.intersectionSegment(h,l,s.intersectionThreshold);if(!(c<0)&&((n||!o||c<o.distance)&&(o=new e.IntersectionInfo(null,null,c),n)))break}else for(a=this.indexStart;a<this.indexStart+this.indexCount;a+=3){h=i[r[a]],l=i[r[a+1]];var u=i[r[a+2]],p=t.intersectsTriangle(h,l,u);if(p){if(p.distance<0)continue;if((n||!o||p.distance<o.distance)&&((o=p).faceId=a/3,n))break}}return o},i.prototype._rebuild=function(){this._linesIndexBuffer&&(this._linesIndexBuffer=null)},i.prototype.clone=function(t,r){var n=new i(this.materialIndex,this.verticesStart,this.verticesCount,this.indexStart,this.indexCount,t,r,!1);if(!this.IsGlobal){var o=this.getBoundingInfo();if(!o)return n;n._boundingInfo=new e.BoundingInfo(o.minimum,o.maximum)}return n},i.prototype.dispose=function(){this._linesIndexBuffer&&(this._mesh.getScene().getEngine()._releaseBuffer(this._linesIndexBuffer),this._linesIndexBuffer=null);var e=this._mesh.subMeshes.indexOf(this);this._mesh.subMeshes.splice(e,1)},i.CreateFromIndices=function(e,t,r,n,o){for(var s=Number.MAX_VALUE,a=-Number.MAX_VALUE,h=(o=o||n).getIndices(),l=t;l<t+r;l++){var c=h[l];c<s&&(s=c),c>a&&(a=c)}return new i(e,s,a-s+1,t,r,n,o)},i}(t);e.SubMesh=i}(us||(us={}));var K,Q,Z,q,J,$,ee,te,ie,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,Oe,Ie,we,De,Le,Be,Ne,Fe,Ve,ke,Ue,ze,Ge,We,He,je,Xe,Ye,Ke,Qe,Ze,qe,Je,$e,et,tt,it,rt,nt,ot,st,at,ht,lt,ct,ut,pt,ft,dt,mt,gt,_t,vt,yt,bt,xt,Tt,Et,At,Pt,Mt,St,Ct,Rt,Ot,It,wt,Dt,Lt,Bt,Nt,Ft,Vt,kt,Ut,zt,Gt,Wt,Ht,jt,Xt,Yt,Kt,Qt,Zt,qt,Jt,$t,ei,ti,ii,ri,ni,oi,si,ai,hi,li,ci,ui=this&&this.__assign||Object.assign||function(e){for(var t,i=1,r=arguments.length;i<r;i++){t=arguments[i];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e};!function(e){var t=function(){function e(){this._isDirty=!0,this._areLightsDirty=!0,this._areAttributesDirty=!0,this._areTexturesDirty=!0,this._areFresnelDirty=!0,this._areMiscDirty=!0,this._areImageProcessingDirty=!0,this._normals=!1,this._uvs=!1,this._needNormals=!1,this._needUVs=!1}return Object.defineProperty(e.prototype,"isDirty",{get:function(){return this._isDirty},enumerable:!0,configurable:!0}),e.prototype.markAsProcessed=function(){this._isDirty=!1,this._areAttributesDirty=!1,this._areTexturesDirty=!1,this._areFresnelDirty=!1,this._areLightsDirty=!1,this._areMiscDirty=!1,this._areImageProcessingDirty=!1},e.prototype.markAsUnprocessed=function(){this._isDirty=!0},e.prototype.markAllAsDirty=function(){this._areTexturesDirty=!0,this._areAttributesDirty=!0,this._areLightsDirty=!0,this._areFresnelDirty=!0,this._areMiscDirty=!0,this._areImageProcessingDirty=!0,this._isDirty=!0},e.prototype.markAsImageProcessingDirty=function(){this._areImageProcessingDirty=!0,this._isDirty=!0},e.prototype.markAsLightDirty=function(){this._areLightsDirty=!0,this._isDirty=!0},e.prototype.markAsAttributesDirty=function(){this._areAttributesDirty=!0,this._isDirty=!0},e.prototype.markAsTexturesDirty=function(){this._areTexturesDirty=!0,this._isDirty=!0},e.prototype.markAsFresnelDirty=function(){this._areFresnelDirty=!0,this._isDirty=!0},e.prototype.markAsMiscDirty=function(){this._areMiscDirty=!0,this._isDirty=!0},e.prototype.rebuild=function(){this._keys&&delete this._keys,this._keys=[];for(var e=0,t=Object.keys(this);e<t.length;e++){var i=t[e];"_"!==i[0]&&this._keys.push(i)}},e.prototype.isEqual=function(e){if(this._keys.length!==e._keys.length)return!1;for(var t=0;t<this._keys.length;t++){var i=this._keys[t];if(this[i]!==e[i])return!1}return!0},e.prototype.cloneTo=function(e){this._keys.length!==e._keys.length&&(e._keys=this._keys.slice(0));for(var t=0;t<this._keys.length;t++){var i=this._keys[t];e[i]=this[i]}},e.prototype.reset=function(){for(var e=0;e<this._keys.length;e++){var t=this._keys[e];"number"==typeof this[t]?this[t]=0:this[t]=!1}},e.prototype.toString=function(){for(var e="",t=0;t<this._keys.length;t++){var i=this._keys[t],r=this[i];"number"==typeof r?e+="#define "+i+" "+this[i]+"\n":r&&(e+="#define "+i+"\n")}return e},e}();e.MaterialDefines=t;var i=function(){function t(i,r,n){this.checkReadyOnEveryCall=!1,this.checkReadyOnlyOnce=!1,this.state="",this.alpha=1,this._backFaceCulling=!0,this.doNotSerialize=!1,this.storeEffectOnSubMeshes=!1,this.onDisposeObservable=new e.Observable,this.onBindObservable=new e.Observable,this.onUnBindObservable=new e.Observable,this._alphaMode=e.Engine.ALPHA_COMBINE,this._needDepthPrePass=!1,this.disableDepthWrite=!1,this.forceDepthWrite=!1,this.separateCullingPass=!1,this._fogEnabled=!0,this.pointSize=1,this.zOffset=0,this._wasPreviouslyReady=!1,this._fillMode=t.TriangleFillMode,this.name=i,this.id=i||e.Tools.RandomId(),this._scene=r||e.Engine.LastCreatedScene,this._scene.useRightHandedSystem?this.sideOrientation=t.ClockWiseSideOrientation:this.sideOrientation=t.CounterClockWiseSideOrientation,this._uniformBuffer=new e.UniformBuffer(this._scene.getEngine()),this._useUBO=this.getScene().getEngine().supportsUniformBuffers,n||this._scene.materials.push(this)}return Object.defineProperty(t,"TriangleFillMode",{get:function(){return t._TriangleFillMode},enumerable:!0,configurable:!0}),Object.defineProperty(t,"WireFrameFillMode",{get:function(){return t._WireFrameFillMode},enumerable:!0,configurable:!0}),Object.defineProperty(t,"PointFillMode",{get:function(){return t._PointFillMode},enumerable:!0,configurable:!0}),Object.defineProperty(t,"PointListDrawMode",{get:function(){return t._PointListDrawMode},enumerable:!0,configurable:!0}),Object.defineProperty(t,"LineListDrawMode",{get:function(){return t._LineListDrawMode},enumerable:!0,configurable:!0}),Object.defineProperty(t,"LineLoopDrawMode",{get:function(){return t._LineLoopDrawMode},enumerable:!0,configurable:!0}),Object.defineProperty(t,"LineStripDrawMode",{get:function(){return t._LineStripDrawMode},enumerable:!0,configurable:!0}),Object.defineProperty(t,"TriangleStripDrawMode",{get:function(){return t._TriangleStripDrawMode},enumerable:!0,configurable:!0}),Object.defineProperty(t,"TriangleFanDrawMode",{get:function(){return t._TriangleFanDrawMode},enumerable:!0,configurable:!0}),Object.defineProperty(t,"ClockWiseSideOrientation",{get:function(){return t._ClockWiseSideOrientation},enumerable:!0,configurable:!0}),Object.defineProperty(t,"CounterClockWiseSideOrientation",{get:function(){return t._CounterClockWiseSideOrientation},enumerable:!0,configurable:!0}),Object.defineProperty(t,"TextureDirtyFlag",{get:function(){return t._TextureDirtyFlag},enumerable:!0,configurable:!0}),Object.defineProperty(t,"LightDirtyFlag",{get:function(){return t._LightDirtyFlag},enumerable:!0,configurable:!0}),Object.defineProperty(t,"FresnelDirtyFlag",{get:function(){return t._FresnelDirtyFlag},enumerable:!0,configurable:!0}),Object.defineProperty(t,"AttributesDirtyFlag",{get:function(){return t._AttributesDirtyFlag},enumerable:!0,configurable:!0}),Object.defineProperty(t,"MiscDirtyFlag",{get:function(){return t._MiscDirtyFlag},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"backFaceCulling",{get:function(){return this._backFaceCulling},set:function(e){this._backFaceCulling!==e&&(this._backFaceCulling=e,this.markAsDirty(t.TextureDirtyFlag))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"onDispose",{set:function(e){this._onDisposeObserver&&this.onDisposeObservable.remove(this._onDisposeObserver),this._onDisposeObserver=this.onDisposeObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"onBind",{set:function(e){this._onBindObserver&&this.onBindObservable.remove(this._onBindObserver),this._onBindObserver=this.onBindObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"alphaMode",{get:function(){return this._alphaMode},set:function(e){this._alphaMode!==e&&(this._alphaMode=e,this.markAsDirty(t.TextureDirtyFlag))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"needDepthPrePass",{get:function(){return this._needDepthPrePass},set:function(e){this._needDepthPrePass!==e&&(this._needDepthPrePass=e,this._needDepthPrePass&&(this.checkReadyOnEveryCall=!0))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"fogEnabled",{get:function(){return this._fogEnabled},set:function(e){this._fogEnabled!==e&&(this._fogEnabled=e,this.markAsDirty(t.MiscDirtyFlag))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"wireframe",{get:function(){return this._fillMode===t.WireFrameFillMode},set:function(e){this._fillMode=e?t.WireFrameFillMode:t.TriangleFillMode},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"pointsCloud",{get:function(){return this._fillMode===t.PointFillMode},set:function(e){this._fillMode=e?t.PointFillMode:t.TriangleFillMode},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"fillMode",{get:function(){return this._fillMode},set:function(e){this._fillMode!==e&&(this._fillMode=e,this.markAsDirty(t.MiscDirtyFlag))},enumerable:!0,configurable:!0}),t.prototype.toString=function(e){return"Name: "+this.name},t.prototype.getClassName=function(){return"Material"},Object.defineProperty(t.prototype,"isFrozen",{get:function(){return this.checkReadyOnlyOnce},enumerable:!0,configurable:!0}),t.prototype.freeze=function(){this.checkReadyOnlyOnce=!0},t.prototype.unfreeze=function(){this.checkReadyOnlyOnce=!1},t.prototype.isReady=function(e,t){return!0},t.prototype.isReadyForSubMesh=function(e,t,i){return!1},t.prototype.getEffect=function(){return this._effect},t.prototype.getScene=function(){return this._scene},t.prototype.needAlphaBlending=function(){return this.alpha<1},t.prototype.needAlphaBlendingForMesh=function(e){return this.needAlphaBlending()||e.visibility<1||e.hasVertexAlpha},t.prototype.needAlphaTesting=function(){return!1},t.prototype.getAlphaTestTexture=function(){return null},t.prototype.markDirty=function(){this._wasPreviouslyReady=!1},t.prototype._preBind=function(e,i){void 0===i&&(i=null);var r=this._scene.getEngine(),n=(null==i?this.sideOrientation:i)===t.ClockWiseSideOrientation;return r.enableEffect(e||this._effect),r.setState(this.backFaceCulling,this.zOffset,!1,n),n},t.prototype.bind=function(e,t){},t.prototype.bindForSubMesh=function(e,t,i){},t.prototype.bindOnlyWorldMatrix=function(e){},t.prototype.bindSceneUniformBuffer=function(e,t){t.bindToEffect(e,"Scene")},t.prototype.bindView=function(e){this._useUBO?this.bindSceneUniformBuffer(e,this.getScene().getSceneUniformBuffer()):e.setMatrix("view",this.getScene().getViewMatrix())},t.prototype.bindViewProjection=function(e){this._useUBO?this.bindSceneUniformBuffer(e,this.getScene().getSceneUniformBuffer()):e.setMatrix("viewProjection",this.getScene().getTransformMatrix())},t.prototype._afterBind=function(e){if(this._scene._cachedMaterial=this,this._scene._cachedVisibility=e?e.visibility:1,e&&this.onBindObservable.notifyObservers(e),this.disableDepthWrite){var t=this._scene.getEngine();this._cachedDepthWriteState=t.getDepthWrite(),t.setDepthWrite(!1)}},t.prototype.unbind=function(){(this.onUnBindObservable.notifyObservers(this),this.disableDepthWrite)&&this._scene.getEngine().setDepthWrite(this._cachedDepthWriteState)},t.prototype.getActiveTextures=function(){return[]},t.prototype.hasTexture=function(e){return!1},t.prototype.clone=function(e){return null},t.prototype.getBindedMeshes=function(){for(var e=new Array,t=0;t<this._scene.meshes.length;t++){var i=this._scene.meshes[t];i.material===this&&e.push(i)}return e},t.prototype.forceCompilation=function(t,i,r){var n=this,o=ui({alphaTest:null,clipPlane:!1},r),s=new e.BaseSubMesh,a=this.getScene(),h=a.getEngine(),l=function(){if(n._scene&&n._scene.getEngine()){s._materialDefines&&(s._materialDefines._renderId=-1);var c=h.getAlphaTesting(),u=a.clipPlane;h.setAlphaTesting(o.alphaTest||!n.needAlphaBlendingForMesh(t)&&n.needAlphaTesting()),o.clipPlane&&(a.clipPlane=new e.Plane(0,0,0,1)),n.storeEffectOnSubMeshes?n.isReadyForSubMesh(t,s)?i&&i(n):setTimeout(l,16):n.isReady(t)?i&&i(n):setTimeout(l,16),h.setAlphaTesting(c),r&&r.clipPlane&&(a.clipPlane=u)}};l()},t.prototype.markAsDirty=function(e){e&t.TextureDirtyFlag&&this._markAllSubMeshesAsTexturesDirty(),e&t.LightDirtyFlag&&this._markAllSubMeshesAsLightsDirty(),e&t.FresnelDirtyFlag&&this._markAllSubMeshesAsFresnelDirty(),e&t.AttributesDirtyFlag&&this._markAllSubMeshesAsAttributesDirty(),e&t.MiscDirtyFlag&&this._markAllSubMeshesAsMiscDirty(),this.getScene().resetCachedMaterial()},t.prototype._markAllSubMeshesAsDirty=function(e){for(var t=0,i=this.getScene().meshes;t<i.length;t++){var r=i[t];if(r.subMeshes)for(var n=0,o=r.subMeshes;n<o.length;n++){var s=o[n];s.getMaterial()===this&&(s._materialDefines&&e(s._materialDefines))}}},t.prototype._markAllSubMeshesAsImageProcessingDirty=function(){this._markAllSubMeshesAsDirty(function(e){return e.markAsImageProcessingDirty()})},t.prototype._markAllSubMeshesAsTexturesDirty=function(){this._markAllSubMeshesAsDirty(function(e){return e.markAsTexturesDirty()})},t.prototype._markAllSubMeshesAsFresnelDirty=function(){this._markAllSubMeshesAsDirty(function(e){return e.markAsFresnelDirty()})},t.prototype._markAllSubMeshesAsLightsDirty=function(){this._markAllSubMeshesAsDirty(function(e){return e.markAsLightDirty()})},t.prototype._markAllSubMeshesAsAttributesDirty=function(){this._markAllSubMeshesAsDirty(function(e){return e.markAsAttributesDirty()})},t.prototype._markAllSubMeshesAsMiscDirty=function(){this._markAllSubMeshesAsDirty(function(e){return e.markAsMiscDirty()})},t.prototype.dispose=function(e,t){this.getScene().stopAnimation(this);var i=this._scene.materials.indexOf(this);for(i>=0&&this._scene.materials.splice(i,1),i=0;i<this._scene.meshes.length;i++){var r=this._scene.meshes[i];if(r.material===this&&(r.material=null,r.geometry)){var n=r.geometry;if(this.storeEffectOnSubMeshes)for(var o=0,s=r.subMeshes;o<s.length;o++){var a=s[o];n._releaseVertexArrayObject(a._materialEffect),e&&a._materialEffect&&this._scene.getEngine()._releaseEffect(a._materialEffect)}else n._releaseVertexArrayObject(this._effect)}}this._uniformBuffer.dispose(),e&&this._effect&&(this.storeEffectOnSubMeshes||this._scene.getEngine()._releaseEffect(this._effect),this._effect=null),this.onDisposeObservable.notifyObservers(this),this.onDisposeObservable.clear(),this.onBindObservable.clear(),this.onUnBindObservable.clear()},t.prototype.serialize=function(){return e.SerializationHelper.Serialize(this)},t.ParseMultiMaterial=function(t,i){var r=new e.MultiMaterial(t.name,i);r.id=t.id,e.Tags&&e.Tags.AddTagsTo(r,t.tags);for(var n=0;n<t.materials.length;n++){var o=t.materials[n];o?r.subMaterials.push(i.getMaterialByID(o)):r.subMaterials.push(null)}return r},t.Parse=function(t,i,r){return t.customType?"BABYLON.PBRMaterial"!==t.customType||!t.overloadedAlbedo||(t.customType="BABYLON.LegacyPBRMaterial",e.LegacyPBRMaterial)?e.Tools.Instantiate(t.customType).Parse(t,i,r):void e.Tools.Error("Your scene is trying to load a legacy version of the PBRMaterial, please, include it from the materials library."):e.StandardMaterial.Parse(t,i,r)},t._TriangleFillMode=0,t._WireFrameFillMode=1,t._PointFillMode=2,t._PointListDrawMode=3,t._LineListDrawMode=4,t._LineLoopDrawMode=5,t._LineStripDrawMode=6,t._TriangleStripDrawMode=7,t._TriangleFanDrawMode=8,t._ClockWiseSideOrientation=0,t._CounterClockWiseSideOrientation=1,t._TextureDirtyFlag=1,t._LightDirtyFlag=2,t._FresnelDirtyFlag=4,t._AttributesDirtyFlag=8,t._MiscDirtyFlag=16,X([e.serialize()],t.prototype,"id",void 0),X([e.serialize()],t.prototype,"name",void 0),X([e.serialize()],t.prototype,"checkReadyOnEveryCall",void 0),X([e.serialize()],t.prototype,"checkReadyOnlyOnce",void 0),X([e.serialize()],t.prototype,"state",void 0),X([e.serialize()],t.prototype,"alpha",void 0),X([e.serialize("backFaceCulling")],t.prototype,"_backFaceCulling",void 0),X([e.serialize()],t.prototype,"sideOrientation",void 0),X([e.serialize("alphaMode")],t.prototype,"_alphaMode",void 0),X([e.serialize()],t.prototype,"_needDepthPrePass",void 0),X([e.serialize()],t.prototype,"disableDepthWrite",void 0),X([e.serialize()],t.prototype,"forceDepthWrite",void 0),X([e.serialize()],t.prototype,"separateCullingPass",void 0),X([e.serialize("fogEnabled")],t.prototype,"_fogEnabled",void 0),X([e.serialize()],t.prototype,"pointSize",void 0),X([e.serialize()],t.prototype,"zOffset",void 0),X([e.serialize()],t.prototype,"wireframe",null),X([e.serialize()],t.prototype,"pointsCloud",null),X([e.serialize()],t.prototype,"fillMode",null),t}();e.Material=i}(us||(us={})),K=us||(us={}),Q=function(){function e(e,t,i){this._engine=e,this._noUBO=!e.supportsUniformBuffers,this._dynamic=i,this._data=t||[],this._uniformLocations={},this._uniformSizes={},this._uniformLocationPointer=0,this._needSync=!1,this._noUBO?(this.updateMatrix3x3=this._updateMatrix3x3ForEffect,this.updateMatrix2x2=this._updateMatrix2x2ForEffect,this.updateFloat=this._updateFloatForEffect,this.updateFloat2=this._updateFloat2ForEffect,this.updateFloat3=this._updateFloat3ForEffect,this.updateFloat4=this._updateFloat4ForEffect,this.updateMatrix=this._updateMatrixForEffect,this.updateVector3=this._updateVector3ForEffect,this.updateVector4=this._updateVector4ForEffect,this.updateColor3=this._updateColor3ForEffect,this.updateColor4=this._updateColor4ForEffect):(this._engine._uniformBuffers.push(this),this.updateMatrix3x3=this._updateMatrix3x3ForUniform,this.updateMatrix2x2=this._updateMatrix2x2ForUniform,this.updateFloat=this._updateFloatForUniform,this.updateFloat2=this._updateFloat2ForUniform,this.updateFloat3=this._updateFloat3ForUniform,this.updateFloat4=this._updateFloat4ForUniform,this.updateMatrix=this._updateMatrixForUniform,this.updateVector3=this._updateVector3ForUniform,this.updateVector4=this._updateVector4ForUniform,this.updateColor3=this._updateColor3ForUniform,this.updateColor4=this._updateColor4ForUniform)}return Object.defineProperty(e.prototype,"useUbo",{get:function(){return!this._noUBO},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isSync",{get:function(){return!this._needSync},enumerable:!0,configurable:!0}),e.prototype.isDynamic=function(){return void 0!==this._dynamic},e.prototype.getData=function(){return this._bufferData},e.prototype.getBuffer=function(){return this._buffer},e.prototype._fillAlignment=function(e){var t;if(t=e<=2?e:4,this._uniformLocationPointer%t!=0){var i=this._uniformLocationPointer;this._uniformLocationPointer+=t-this._uniformLocationPointer%t;for(var r=this._uniformLocationPointer-i,n=0;n<r;n++)this._data.push(0)}},e.prototype.addUniform=function(e,t){if(!this._noUBO&&void 0===this._uniformLocations[e]){var i;if(t instanceof Array)t=(i=t).length;else{t=t,i=[];for(var r=0;r<t;r++)i.push(0)}this._fillAlignment(t),this._uniformSizes[e]=t,this._uniformLocations[e]=this._uniformLocationPointer,this._uniformLocationPointer+=t;for(r=0;r<t;r++)this._data.push(i[r]);this._needSync=!0}},e.prototype.addMatrix=function(e,t){this.addUniform(e,Array.prototype.slice.call(t.toArray()))},e.prototype.addFloat2=function(e,t,i){var r=[t,i];this.addUniform(e,r)},e.prototype.addFloat3=function(e,t,i,r){var n=[t,i,r];this.addUniform(e,n)},e.prototype.addColor3=function(e,t){var i=new Array;t.toArray(i),this.addUniform(e,i)},e.prototype.addColor4=function(e,t,i){var r=new Array;t.toArray(r),r.push(i),this.addUniform(e,r)},e.prototype.addVector3=function(e,t){var i=new Array;t.toArray(i),this.addUniform(e,i)},e.prototype.addMatrix3x3=function(e){this.addUniform(e,12)},e.prototype.addMatrix2x2=function(e){this.addUniform(e,8)},e.prototype.create=function(){this._noUBO||this._buffer||(this._fillAlignment(4),this._bufferData=new Float32Array(this._data),this._rebuild(),this._needSync=!0)},e.prototype._rebuild=function(){this._noUBO||(this._dynamic?this._buffer=this._engine.createDynamicUniformBuffer(this._bufferData):this._buffer=this._engine.createUniformBuffer(this._bufferData))},e.prototype.update=function(){this._buffer?(this._dynamic||this._needSync)&&(this._engine.updateUniformBuffer(this._buffer,this._bufferData),this._needSync=!1):this.create()},e.prototype.updateUniform=function(e,t,i){var r=this._uniformLocations[e];if(void 0===r){if(this._buffer)return void K.Tools.Error("Cannot add an uniform after UBO has been created.");this.addUniform(e,i),r=this._uniformLocations[e]}if(this._buffer||this.create(),this._dynamic)for(o=0;o<i;o++)this._bufferData[r+o]=t[o];else{for(var n=!1,o=0;o<i;o++)this._bufferData[r+o]!==t[o]&&(n=!0,this._bufferData[r+o]=t[o]);this._needSync=this._needSync||n}},e.prototype._updateMatrix3x3ForUniform=function(t,i){for(var r=0;r<3;r++)e._tempBuffer[4*r]=i[3*r],e._tempBuffer[4*r+1]=i[3*r+1],e._tempBuffer[4*r+2]=i[3*r+2],e._tempBuffer[4*r+3]=0;this.updateUniform(t,e._tempBuffer,12)},e.prototype._updateMatrix3x3ForEffect=function(e,t){this._currentEffect.setMatrix3x3(e,t)},e.prototype._updateMatrix2x2ForEffect=function(e,t){this._currentEffect.setMatrix2x2(e,t)},e.prototype._updateMatrix2x2ForUniform=function(t,i){for(var r=0;r<2;r++)e._tempBuffer[4*r]=i[2*r],e._tempBuffer[4*r+1]=i[2*r+1],e._tempBuffer[4*r+2]=0,e._tempBuffer[4*r+3]=0;this.updateUniform(t,e._tempBuffer,8)},e.prototype._updateFloatForEffect=function(e,t){this._currentEffect.setFloat(e,t)},e.prototype._updateFloatForUniform=function(t,i){e._tempBuffer[0]=i,this.updateUniform(t,e._tempBuffer,1)},e.prototype._updateFloat2ForEffect=function(e,t,i,r){void 0===r&&(r=""),this._currentEffect.setFloat2(e+r,t,i)},e.prototype._updateFloat2ForUniform=function(t,i,r,n){void 0===n&&(n=""),e._tempBuffer[0]=i,e._tempBuffer[1]=r,this.updateUniform(t,e._tempBuffer,2)},e.prototype._updateFloat3ForEffect=function(e,t,i,r,n){void 0===n&&(n=""),this._currentEffect.setFloat3(e+n,t,i,r)},e.prototype._updateFloat3ForUniform=function(t,i,r,n,o){void 0===o&&(o=""),e._tempBuffer[0]=i,e._tempBuffer[1]=r,e._tempBuffer[2]=n,this.updateUniform(t,e._tempBuffer,3)},e.prototype._updateFloat4ForEffect=function(e,t,i,r,n,o){void 0===o&&(o=""),this._currentEffect.setFloat4(e+o,t,i,r,n)},e.prototype._updateFloat4ForUniform=function(t,i,r,n,o,s){void 0===s&&(s=""),e._tempBuffer[0]=i,e._tempBuffer[1]=r,e._tempBuffer[2]=n,e._tempBuffer[3]=o,this.updateUniform(t,e._tempBuffer,4)},e.prototype._updateMatrixForEffect=function(e,t){this._currentEffect.setMatrix(e,t)},e.prototype._updateMatrixForUniform=function(e,t){this.updateUniform(e,t.toArray(),16)},e.prototype._updateVector3ForEffect=function(e,t){this._currentEffect.setVector3(e,t)},e.prototype._updateVector3ForUniform=function(t,i){i.toArray(e._tempBuffer),this.updateUniform(t,e._tempBuffer,3)},e.prototype._updateVector4ForEffect=function(e,t){this._currentEffect.setVector4(e,t)},e.prototype._updateVector4ForUniform=function(t,i){i.toArray(e._tempBuffer),this.updateUniform(t,e._tempBuffer,4)},e.prototype._updateColor3ForEffect=function(e,t,i){void 0===i&&(i=""),this._currentEffect.setColor3(e+i,t)},e.prototype._updateColor3ForUniform=function(t,i,r){void 0===r&&(r=""),i.toArray(e._tempBuffer),this.updateUniform(t,e._tempBuffer,3)},e.prototype._updateColor4ForEffect=function(e,t,i,r){void 0===r&&(r=""),this._currentEffect.setColor4(e+r,t,i)},e.prototype._updateColor4ForUniform=function(t,i,r,n){void 0===n&&(n=""),i.toArray(e._tempBuffer),e._tempBuffer[3]=r,this.updateUniform(t,e._tempBuffer,4)},e.prototype.setTexture=function(e,t){this._currentEffect.setTexture(e,t)},e.prototype.updateUniformDirectly=function(e,t){this.updateUniform(e,t,t.length),this.update()},e.prototype.bindToEffect=function(e,t){this._currentEffect=e,!this._noUBO&&this._buffer&&e.bindUniformBuffer(this._buffer,t)},e.prototype.dispose=function(){if(!this._noUBO){var e=this._engine._uniformBuffers.indexOf(this);-1!==e&&this._engine._uniformBuffers.splice(e,1),this._buffer&&this._engine._releaseBuffer(this._buffer)&&(this._buffer=null)}},e._MAX_UNIFORM_SIZE=256,e._tempBuffer=new Float32Array(e._MAX_UNIFORM_SIZE),e}(),K.UniformBuffer=Q,Z=us||(us={}),q=function(){function e(){}return e.prototype.set=function(e,t){switch(t){case Z.VertexBuffer.PositionKind:this.positions=e;break;case Z.VertexBuffer.NormalKind:this.normals=e;break;case Z.VertexBuffer.TangentKind:this.tangents=e;break;case Z.VertexBuffer.UVKind:this.uvs=e;break;case Z.VertexBuffer.UV2Kind:this.uvs2=e;break;case Z.VertexBuffer.UV3Kind:this.uvs3=e;break;case Z.VertexBuffer.UV4Kind:this.uvs4=e;break;case Z.VertexBuffer.UV5Kind:this.uvs5=e;break;case Z.VertexBuffer.UV6Kind:this.uvs6=e;break;case Z.VertexBuffer.ColorKind:this.colors=e;break;case Z.VertexBuffer.MatricesIndicesKind:this.matricesIndices=e;break;case Z.VertexBuffer.MatricesWeightsKind:this.matricesWeights=e;break;case Z.VertexBuffer.MatricesIndicesExtraKind:this.matricesIndicesExtra=e;break;case Z.VertexBuffer.MatricesWeightsExtraKind:this.matricesWeightsExtra=e}},e.prototype.applyToMesh=function(e,t){return this._applyTo(e,t),this},e.prototype.applyToGeometry=function(e,t){return this._applyTo(e,t),this},e.prototype.updateMesh=function(e,t,i){return this._update(e),this},e.prototype.updateGeometry=function(e,t,i){return this._update(e),this},e.prototype._applyTo=function(e,t){return void 0===t&&(t=!1),this.positions&&e.setVerticesData(Z.VertexBuffer.PositionKind,this.positions,t),this.normals&&e.setVerticesData(Z.VertexBuffer.NormalKind,this.normals,t),this.tangents&&e.setVerticesData(Z.VertexBuffer.TangentKind,this.tangents,t),this.uvs&&e.setVerticesData(Z.VertexBuffer.UVKind,this.uvs,t),this.uvs2&&e.setVerticesData(Z.VertexBuffer.UV2Kind,this.uvs2,t),this.uvs3&&e.setVerticesData(Z.VertexBuffer.UV3Kind,this.uvs3,t),this.uvs4&&e.setVerticesData(Z.VertexBuffer.UV4Kind,this.uvs4,t),this.uvs5&&e.setVerticesData(Z.VertexBuffer.UV5Kind,this.uvs5,t),this.uvs6&&e.setVerticesData(Z.VertexBuffer.UV6Kind,this.uvs6,t),this.colors&&e.setVerticesData(Z.VertexBuffer.ColorKind,this.colors,t),this.matricesIndices&&e.setVerticesData(Z.VertexBuffer.MatricesIndicesKind,this.matricesIndices,t),this.matricesWeights&&e.setVerticesData(Z.VertexBuffer.MatricesWeightsKind,this.matricesWeights,t),this.matricesIndicesExtra&&e.setVerticesData(Z.VertexBuffer.MatricesIndicesExtraKind,this.matricesIndicesExtra,t),this.matricesWeightsExtra&&e.setVerticesData(Z.VertexBuffer.MatricesWeightsExtraKind,this.matricesWeightsExtra,t),this.indices&&e.setIndices(this.indices,null,t),this},e.prototype._update=function(e,t,i){return this.positions&&e.updateVerticesData(Z.VertexBuffer.PositionKind,this.positions,t,i),this.normals&&e.updateVerticesData(Z.VertexBuffer.NormalKind,this.normals,t,i),this.tangents&&e.updateVerticesData(Z.VertexBuffer.TangentKind,this.tangents,t,i),this.uvs&&e.updateVerticesData(Z.VertexBuffer.UVKind,this.uvs,t,i),this.uvs2&&e.updateVerticesData(Z.VertexBuffer.UV2Kind,this.uvs2,t,i),this.uvs3&&e.updateVerticesData(Z.VertexBuffer.UV3Kind,this.uvs3,t,i),this.uvs4&&e.updateVerticesData(Z.VertexBuffer.UV4Kind,this.uvs4,t,i),this.uvs5&&e.updateVerticesData(Z.VertexBuffer.UV5Kind,this.uvs5,t,i),this.uvs6&&e.updateVerticesData(Z.VertexBuffer.UV6Kind,this.uvs6,t,i),this.colors&&e.updateVerticesData(Z.VertexBuffer.ColorKind,this.colors,t,i),this.matricesIndices&&e.updateVerticesData(Z.VertexBuffer.MatricesIndicesKind,this.matricesIndices,t,i),this.matricesWeights&&e.updateVerticesData(Z.VertexBuffer.MatricesWeightsKind,this.matricesWeights,t,i),this.matricesIndicesExtra&&e.updateVerticesData(Z.VertexBuffer.MatricesIndicesExtraKind,this.matricesIndicesExtra,t,i),this.matricesWeightsExtra&&e.updateVerticesData(Z.VertexBuffer.MatricesWeightsExtraKind,this.matricesWeightsExtra,t,i),this.indices&&e.setIndices(this.indices,null),this},e.prototype.transform=function(e){var t,i=Z.Vector3.Zero();if(this.positions){var r=Z.Vector3.Zero();for(t=0;t<this.positions.length;t+=3)Z.Vector3.FromArrayToRef(this.positions,t,r),Z.Vector3.TransformCoordinatesToRef(r,e,i),this.positions[t]=i.x,this.positions[t+1]=i.y,this.positions[t+2]=i.z}if(this.normals){var n=Z.Vector3.Zero();for(t=0;t<this.normals.length;t+=3)Z.Vector3.FromArrayToRef(this.normals,t,n),Z.Vector3.TransformNormalToRef(n,e,i),this.normals[t]=i.x,this.normals[t+1]=i.y,this.normals[t+2]=i.z}if(this.tangents){var o=Z.Vector4.Zero(),s=Z.Vector4.Zero();for(t=0;t<this.tangents.length;t+=4)Z.Vector4.FromArrayToRef(this.tangents,t,o),Z.Vector4.TransformNormalToRef(o,e,s),this.tangents[t]=s.x,this.tangents[t+1]=s.y,this.tangents[t+2]=s.z,this.tangents[t+3]=s.w}return this},e.prototype.merge=function(e,t){if(t=t||{},e.indices){this.indices||(this.indices=[]);for(var i=this.positions?this.positions.length/3:0,r=0;r<e.indices.length;r++)this.indices.push(e.indices[r]+i)}if(this.positions=this._mergeElement(this.positions,e.positions),!this.positions)return this;var n=this.positions.length/3;return this.normals=this._mergeElement(this.normals,e.normals,3*n),this.tangents=this._mergeElement(this.tangents,e.tangents,n*(t.tangentLength||4)),this.uvs=this._mergeElement(this.uvs,e.uvs,2*n),this.uvs2=this._mergeElement(this.uvs2,e.uvs2,2*n),this.uvs3=this._mergeElement(this.uvs3,e.uvs3,2*n),this.uvs4=this._mergeElement(this.uvs4,e.uvs4,2*n),this.uvs5=this._mergeElement(this.uvs5,e.uvs5,2*n),this.uvs6=this._mergeElement(this.uvs6,e.uvs6,2*n),this.colors=this._mergeElement(this.colors,e.colors,4*n,1),this.matricesIndices=this._mergeElement(this.matricesIndices,e.matricesIndices,4*n),this.matricesWeights=this._mergeElement(this.matricesWeights,e.matricesWeights,4*n),this.matricesIndicesExtra=this._mergeElement(this.matricesIndicesExtra,e.matricesIndicesExtra,4*n),this.matricesWeightsExtra=this._mergeElement(this.matricesWeightsExtra,e.matricesWeightsExtra,4*n),this},e.prototype._mergeElement=function(e,t,i,r){if(void 0===i&&(i=0),void 0===r&&(r=0),!t&&!e)return null;var n;if(!t)return(n=new Float32Array(e.length)).fill(r),this._mergeElement(e,n,i);if(!e)return 0===i||i===t.length?t:((n=new Float32Array(i-t.length)).fill(r),this._mergeElement(n,t,i));var o=t.length+e.length,s=e instanceof Float32Array,a=t instanceof Float32Array;if(s){var h=new Float32Array(o);return h.set(e),h.set(t,e.length),h}if(a){var l=e.slice(0),c=0;for(o=t.length;c<o;c++)l.push(t[c]);return l}return e.concat(t)},e.prototype.serialize=function(){var e=this.serialize();return this.positions&&(e.positions=this.positions),this.normals&&(e.normals=this.normals),this.tangents&&(e.tangents=this.tangents),this.uvs&&(e.uvs=this.uvs),this.uvs2&&(e.uvs2=this.uvs2),this.uvs3&&(e.uvs3=this.uvs3),this.uvs4&&(e.uvs4=this.uvs4),this.uvs5&&(e.uvs5=this.uvs5),this.uvs6&&(e.uvs6=this.uvs6),this.colors&&(e.colors=this.colors),this.matricesIndices&&(e.matricesIndices=this.matricesIndices,e.matricesIndices._isExpanded=!0),this.matricesWeights&&(e.matricesWeights=this.matricesWeights),this.matricesIndicesExtra&&(e.matricesIndicesExtra=this.matricesIndicesExtra,e.matricesIndicesExtra._isExpanded=!0),this.matricesWeightsExtra&&(e.matricesWeightsExtra=this.matricesWeightsExtra),e.indices=this.indices,e},e.ExtractFromMesh=function(t,i,r){return e._ExtractFrom(t,i,r)},e.ExtractFromGeometry=function(t,i,r){return e._ExtractFrom(t,i,r)},e._ExtractFrom=function(t,i,r){var n=new e;return t.isVerticesDataPresent(Z.VertexBuffer.PositionKind)&&(n.positions=t.getVerticesData(Z.VertexBuffer.PositionKind,i,r)),t.isVerticesDataPresent(Z.VertexBuffer.NormalKind)&&(n.normals=t.getVerticesData(Z.VertexBuffer.NormalKind,i,r)),t.isVerticesDataPresent(Z.VertexBuffer.TangentKind)&&(n.tangents=t.getVerticesData(Z.VertexBuffer.TangentKind,i,r)),t.isVerticesDataPresent(Z.VertexBuffer.UVKind)&&(n.uvs=t.getVerticesData(Z.VertexBuffer.UVKind,i,r)),t.isVerticesDataPresent(Z.VertexBuffer.UV2Kind)&&(n.uvs2=t.getVerticesData(Z.VertexBuffer.UV2Kind,i,r)),t.isVerticesDataPresent(Z.VertexBuffer.UV3Kind)&&(n.uvs3=t.getVerticesData(Z.VertexBuffer.UV3Kind,i,r)),t.isVerticesDataPresent(Z.VertexBuffer.UV4Kind)&&(n.uvs4=t.getVerticesData(Z.VertexBuffer.UV4Kind,i,r)),t.isVerticesDataPresent(Z.VertexBuffer.UV5Kind)&&(n.uvs5=t.getVerticesData(Z.VertexBuffer.UV5Kind,i,r)),t.isVerticesDataPresent(Z.VertexBuffer.UV6Kind)&&(n.uvs6=t.getVerticesData(Z.VertexBuffer.UV6Kind,i,r)),t.isVerticesDataPresent(Z.VertexBuffer.ColorKind)&&(n.colors=t.getVerticesData(Z.VertexBuffer.ColorKind,i,r)),t.isVerticesDataPresent(Z.VertexBuffer.MatricesIndicesKind)&&(n.matricesIndices=t.getVerticesData(Z.VertexBuffer.MatricesIndicesKind,i,r)),t.isVerticesDataPresent(Z.VertexBuffer.MatricesWeightsKind)&&(n.matricesWeights=t.getVerticesData(Z.VertexBuffer.MatricesWeightsKind,i,r)),t.isVerticesDataPresent(Z.VertexBuffer.MatricesIndicesExtraKind)&&(n.matricesIndicesExtra=t.getVerticesData(Z.VertexBuffer.MatricesIndicesExtraKind,i,r)),t.isVerticesDataPresent(Z.VertexBuffer.MatricesWeightsExtraKind)&&(n.matricesWeightsExtra=t.getVerticesData(Z.VertexBuffer.MatricesWeightsExtraKind,i,r)),n.indices=t.getIndices(i),n},e.CreateRibbon=function(t){var i=t.pathArray,r=t.closeArray||!1,n=t.closePath||!1,o=t.invertUV||!1,s=Math.floor(i[0].length/2),a=t.offset||s;a=a>s?s:Math.floor(a);var h,l,c,u,p=0===t.sideOrientation?0:t.sideOrientation||Z.Mesh.DEFAULTSIDE,f=t.uvs,d=t.colors,m=[],g=[],_=[],v=[],y=[],b=[],x=[],T=[],E=[],A=[];if(i.length<2){var P=[],M=[];for(c=0;c<i[0].length-a;c++)P.push(i[0][c]),M.push(i[0][c+a]);i=[P,M]}var S,C,R,O,I,w=0,D=n?1:0;for(h=i[0].length,l=0;l<i.length;l++){for(x[l]=0,y[l]=[0],h=h<(C=(S=i[l]).length)?h:C,u=0;u<C;)m.push(S[u].x,S[u].y,S[u].z),u>0&&(R=S[u].subtract(S[u-1]).length()+x[l],y[l].push(R),x[l]=R),u++;n&&(u--,m.push(S[0].x,S[0].y,S[0].z),R=S[u].subtract(S[0]).length()+x[l],y[l].push(R),x[l]=R),E[l]=C+D,A[l]=w,w+=C+D}var L,B,N=null,F=null;for(c=0;c<h+D;c++){for(T[c]=0,b[c]=[0],l=0;l<i.length-1;l++)O=i[l],I=i[l+1],c===h?(N=O[0],F=I[0]):(N=O[c],F=I[c]),R=F.subtract(N).length()+T[c],b[c].push(R),T[c]=R;r&&F&&N&&(O=i[l],I=i[0],c===h&&(F=I[0]),R=F.subtract(N).length()+T[c],T[c]=R)}if(f)for(l=0;l<f.length;l++)v.push(f[l].x,f[l].y);else for(l=0;l<i.length;l++)for(c=0;c<h+D;c++)L=0!=x[l]?y[l][c]/x[l]:0,B=0!=T[c]?b[c][l]/T[c]:0,o?v.push(B,L):v.push(L,B);for(var V=0,k=E[l=0]-1,U=E[l+1]-1,z=k<U?k:U,G=A[1]-A[0],W=r?E.length:E.length-1;V<=z&&l<W;)g.push(V,V+G,V+1),g.push(V+G+1,V+1,V+G),(V+=1)===z&&(++l===E.length-1?(G=A[0]-A[l],k=E[l]-1,U=E[0]-1):(G=A[l+1]-A[l],k=E[l]-1,U=E[l+1]-1),V=A[l],z=k<U?k+V:U+V);if(e.ComputeNormals(m,g,_),n){var H=0,j=0;for(l=0;l<i.length;l++)H=3*A[l],j=l+1<i.length?3*(A[l+1]-1):_.length-3,_[H]=.5*(_[H]+_[j]),_[H+1]=.5*(_[H+1]+_[j+1]),_[H+2]=.5*(_[H+2]+_[j+2]),_[j]=_[H],_[j+1]=_[H+1],_[j+2]=_[H+2]}e._ComputeSides(p,m,g,_,v,t.frontUVs,t.backUVs);var X=null;if(d){X=new Float32Array(4*d.length);for(var Y=0;Y<d.length;Y++)X[4*Y]=d[Y].r,X[4*Y+1]=d[Y].g,X[4*Y+2]=d[Y].b,X[4*Y+3]=d[Y].a}var K=new e,Q=new Float32Array(m),q=new Float32Array(_),J=new Float32Array(v);return K.indices=g,K.positions=Q,K.normals=q,K.uvs=J,X&&K.set(X,Z.VertexBuffer.ColorKind),n&&(K._idx=A),K},e.CreateBox=function(t){for(var i=[new Z.Vector3(0,0,1),new Z.Vector3(0,0,-1),new Z.Vector3(1,0,0),new Z.Vector3(-1,0,0),new Z.Vector3(0,1,0),new Z.Vector3(0,-1,0)],r=[],n=[],o=[],s=[],a=t.width||t.size||1,h=t.height||t.size||1,l=t.depth||t.size||1,c=0===t.sideOrientation?0:t.sideOrientation||Z.Mesh.DEFAULTSIDE,u=t.faceUV||new Array(6),p=t.faceColors,f=[],d=0;d<6;d++)void 0===u[d]&&(u[d]=new Z.Vector4(0,0,1,1)),p&&void 0===p[d]&&(p[d]=new Z.Color4(1,1,1,1));for(var m=new Z.Vector3(a/2,h/2,l/2),g=0;g<i.length;g++){var _=i[g],v=new Z.Vector3(_.y,_.z,_.x),y=Z.Vector3.Cross(_,v),b=n.length/3;r.push(b),r.push(b+1),r.push(b+2),r.push(b),r.push(b+2),r.push(b+3);var x=_.subtract(v).subtract(y).multiply(m);n.push(x.x,x.y,x.z),o.push(_.x,_.y,_.z),s.push(u[g].z,u[g].w),p&&f.push(p[g].r,p[g].g,p[g].b,p[g].a),x=_.subtract(v).add(y).multiply(m),n.push(x.x,x.y,x.z),o.push(_.x,_.y,_.z),s.push(u[g].x,u[g].w),p&&f.push(p[g].r,p[g].g,p[g].b,p[g].a),x=_.add(v).add(y).multiply(m),n.push(x.x,x.y,x.z),o.push(_.x,_.y,_.z),s.push(u[g].x,u[g].y),p&&f.push(p[g].r,p[g].g,p[g].b,p[g].a),x=_.add(v).subtract(y).multiply(m),n.push(x.x,x.y,x.z),o.push(_.x,_.y,_.z),s.push(u[g].z,u[g].y),p&&f.push(p[g].r,p[g].g,p[g].b,p[g].a)}e._ComputeSides(c,n,r,o,s,t.frontUVs,t.backUVs);var T=new e;if(T.indices=r,T.positions=n,T.normals=o,T.uvs=s,p){var E=c===Z.Mesh.DOUBLESIDE?f.concat(f):f;T.colors=E}return T},e.CreateSphere=function(t){for(var i=t.segments||32,r=t.diameterX||t.diameter||1,n=t.diameterY||t.diameter||1,o=t.diameterZ||t.diameter||1,s=t.arc&&(t.arc<=0||t.arc>1)?1:t.arc||1,a=t.slice&&t.slice<=0?1:t.slice||1,h=0===t.sideOrientation?0:t.sideOrientation||Z.Mesh.DEFAULTSIDE,l=new Z.Vector3(r/2,n/2,o/2),c=2+i,u=2*c,p=[],f=[],d=[],m=[],g=0;g<=c;g++){for(var _=g/c,v=_*Math.PI*a,y=0;y<=u;y++){var b=y/u,x=b*Math.PI*2*s,T=Z.Matrix.RotationZ(-v),E=Z.Matrix.RotationY(x),A=Z.Vector3.TransformCoordinates(Z.Vector3.Up(),T),P=Z.Vector3.TransformCoordinates(A,E),M=P.multiply(l),S=P.divide(l).normalize();f.push(M.x,M.y,M.z),d.push(S.x,S.y,S.z),m.push(b,_)}if(g>0)for(var C=f.length/3,R=C-2*(u+1);R+u+2<C;R++)p.push(R),p.push(R+1),p.push(R+u+1),p.push(R+u+1),p.push(R+1),p.push(R+u+2)}e._ComputeSides(h,f,p,d,m,t.frontUVs,t.backUVs);var O=new e;return O.indices=p,O.positions=f,O.normals=d,O.uvs=m,O},e.CreateCylinder=function(t){var i,r=t.height||2,n=0===t.diameterTop?0:t.diameterTop||t.diameter||1,o=0===t.diameterBottom?0:t.diameterBottom||t.diameter||1,s=t.tessellation||24,a=t.subdivisions||1,h=!!t.hasRings,l=!!t.enclose,c=t.arc&&(t.arc<=0||t.arc>1)?1:t.arc||1,u=0===t.sideOrientation?0:t.sideOrientation||Z.Mesh.DEFAULTSIDE,p=t.faceUV||new Array(3),f=t.faceColors,d=2+(1+(1!==c&&l?2:0))*(h?a:1);for(i=0;i<d;i++)f&&void 0===f[i]&&(f[i]=new Z.Color4(1,1,1,1));for(i=0;i<d;i++)p&&void 0===p[i]&&(p[i]=new Z.Vector4(0,0,1,1));var m,g,_,v,y,b,x=new Array,T=new Array,E=new Array,A=new Array,P=new Array,M=2*Math.PI*c/s,S=(o-n)/2/r,C=Z.Vector3.Zero(),R=Z.Vector3.Zero(),O=Z.Vector3.Zero(),I=Z.Vector3.Zero(),w=Z.Vector3.Zero(),D=Z.Axis.Y,L=1,B=1,N=0,F=0;for(v=0;v<=a;v++)for(_=((g=v/a)*(n-o)+o)/2,L=h&&0!==v&&v!==a?2:1,b=0;b<L;b++){for(h&&(B+=b),l&&(B+=2*b),y=0;y<=s;y++)m=y*M,C.x=Math.cos(-m)*_,C.y=-r/2+g*r,C.z=Math.sin(-m)*_,0===n&&v===a?(R.x=E[E.length-3*(s+1)],R.y=E[E.length-3*(s+1)+1],R.z=E[E.length-3*(s+1)+2]):(R.x=C.x,R.z=C.z,R.y=Math.sqrt(R.x*R.x+R.z*R.z)*S,R.normalize()),0===y&&(O.copyFrom(C),I.copyFrom(R)),T.push(C.x,C.y,C.z),E.push(R.x,R.y,R.z),F=h?N!==B?p[B].y:p[B].w:p[B].y+(p[B].w-p[B].y)*g,A.push(p[B].x+(p[B].z-p[B].x)*y/s,F),f&&P.push(f[B].r,f[B].g,f[B].b,f[B].a);1!==c&&l&&(T.push(C.x,C.y,C.z),T.push(0,C.y,0),T.push(0,C.y,0),T.push(O.x,O.y,O.z),Z.Vector3.CrossToRef(D,R,w),w.normalize(),E.push(w.x,w.y,w.z,w.x,w.y,w.z),Z.Vector3.CrossToRef(I,D,w),w.normalize(),E.push(w.x,w.y,w.z,w.x,w.y,w.z),F=h?N!==B?p[B+1].y:p[B+1].w:p[B+1].y+(p[B+1].w-p[B+1].y)*g,A.push(p[B+1].x,F),A.push(p[B+1].z,F),F=h?N!==B?p[B+2].y:p[B+2].w:p[B+2].y+(p[B+2].w-p[B+2].y)*g,A.push(p[B+2].x,F),A.push(p[B+2].z,F),f&&(P.push(f[B+1].r,f[B+1].g,f[B+1].b,f[B+1].a),P.push(f[B+1].r,f[B+1].g,f[B+1].b,f[B+1].a),P.push(f[B+2].r,f[B+2].g,f[B+2].b,f[B+2].a),P.push(f[B+2].r,f[B+2].g,f[B+2].b,f[B+2].a))),N!==B&&(N=B)}var V=1!==c&&l?s+4:s;for(v=0,B=0;B<a;B++){var k=0,U=0,z=0,G=0;for(y=0;y<s;y++)k=v*(V+1)+y,U=(v+1)*(V+1)+y,z=v*(V+1)+(y+1),G=(v+1)*(V+1)+(y+1),x.push(k,U,z),x.push(G,z,U);1!==c&&l&&(x.push(k+2,U+2,z+2),x.push(G+2,z+2,U+2),x.push(k+4,U+4,z+4),x.push(G+4,z+4,U+4)),v=h?v+2:v+1}var W=function(e){var t=e?n/2:o/2;if(0!==t){var i,a,h,l=e?p[d-1]:p[0],u=null;f&&(u=e?f[d-1]:f[0]);var m=T.length/3,g=e?r/2:-r/2,_=new Z.Vector3(0,g,0);T.push(_.x,_.y,_.z),E.push(0,e?1:-1,0),A.push(l.x+.5*(l.z-l.x),l.y+.5*(l.w-l.y)),u&&P.push(u.r,u.g,u.b,u.a);var v=new Z.Vector2(.5,.5);for(h=0;h<=s;h++){i=2*Math.PI*h*c/s;var y=Math.cos(-i),b=Math.sin(-i);a=new Z.Vector3(y*t,g,b*t);var M=new Z.Vector2(y*v.x+.5,b*v.y+.5);T.push(a.x,a.y,a.z),E.push(0,e?1:-1,0),A.push(l.x+(l.z-l.x)*M.x,l.y+(l.w-l.y)*M.y),u&&P.push(u.r,u.g,u.b,u.a)}for(h=0;h<s;h++)e?(x.push(m),x.push(m+(h+2)),x.push(m+(h+1))):(x.push(m),x.push(m+(h+1)),x.push(m+(h+2)))}};W(!1),W(!0),e._ComputeSides(u,T,x,E,A,t.frontUVs,t.backUVs);var H=new e;return H.indices=x,H.positions=T,H.normals=E,H.uvs=A,f&&(H.colors=P),H},e.CreateTorus=function(t){for(var i=[],r=[],n=[],o=[],s=t.diameter||1,a=t.thickness||.5,h=t.tessellation||16,l=0===t.sideOrientation?0:t.sideOrientation||Z.Mesh.DEFAULTSIDE,c=h+1,u=0;u<=h;u++)for(var p=u/h,f=u*Math.PI*2/h-Math.PI/2,d=Z.Matrix.Translation(s/2,0,0).multiply(Z.Matrix.RotationY(f)),m=0;m<=h;m++){var g=1-m/h,_=m*Math.PI*2/h+Math.PI,v=Math.cos(_),y=Math.sin(_),b=new Z.Vector3(v,y,0),x=b.scale(a/2),T=new Z.Vector2(p,g);x=Z.Vector3.TransformCoordinates(x,d),b=Z.Vector3.TransformNormal(b,d),r.push(x.x,x.y,x.z),n.push(b.x,b.y,b.z),o.push(T.x,T.y);var E=(u+1)%c,A=(m+1)%c;i.push(u*c+m),i.push(u*c+A),i.push(E*c+m),i.push(u*c+A),i.push(E*c+A),i.push(E*c+m)}e._ComputeSides(l,r,i,n,o,t.frontUVs,t.backUVs);var P=new e;return P.indices=i,P.positions=r,P.normals=n,P.uvs=o,P},e.CreateLineSystem=function(t){for(var i=[],r=[],n=t.lines,o=t.colors,s=[],a=0,h=0;h<n.length;h++)for(var l=n[h],c=0;c<l.length;c++){if(r.push(l[c].x,l[c].y,l[c].z),o){var u=o[h];s.push(u[c].r,u[c].g,u[c].b,u[c].a)}c>0&&(i.push(a-1),i.push(a)),a++}var p=new e;return p.indices=i,p.positions=r,o&&(p.colors=s),p},e.CreateDashedLines=function(t){var i,r,n=t.dashSize||3,o=t.gapSize||1,s=t.dashNb||200,a=t.points,h=new Array,l=new Array,c=Z.Vector3.Zero(),u=0,p=0,f=0,d=0,m=0;for(m=0;m<a.length-1;m++)a[m+1].subtractToRef(a[m],c),u+=c.length();for(r=n*(i=u/s)/(n+o),m=0;m<a.length-1;m++){a[m+1].subtractToRef(a[m],c),p=Math.floor(c.length()/i),c.normalize();for(var g=0;g<p;g++)f=i*g,h.push(a[m].x+f*c.x,a[m].y+f*c.y,a[m].z+f*c.z),h.push(a[m].x+(f+r)*c.x,a[m].y+(f+r)*c.y,a[m].z+(f+r)*c.z),l.push(d,d+1),d+=2}var _=new e;return _.positions=h,_.indices=l,_},e.CreateGround=function(t){var i,r,n=[],o=[],s=[],a=[],h=t.width||1,l=t.height||1,c=t.subdivisionsX||t.subdivisions||1,u=t.subdivisionsY||t.subdivisions||1;for(i=0;i<=u;i++)for(r=0;r<=c;r++){var p=new Z.Vector3(r*h/c-h/2,0,(u-i)*l/u-l/2),f=new Z.Vector3(0,1,0);o.push(p.x,p.y,p.z),s.push(f.x,f.y,f.z),a.push(r/c,1-i/u)}for(i=0;i<u;i++)for(r=0;r<c;r++)n.push(r+1+(i+1)*(c+1)),n.push(r+1+i*(c+1)),n.push(r+i*(c+1)),n.push(r+(i+1)*(c+1)),n.push(r+1+(i+1)*(c+1)),n.push(r+i*(c+1));var d=new e;return d.indices=n,d.positions=o,d.normals=s,d.uvs=a,d},e.CreateTiledGround=function(t){var i,r,n,o,s=void 0!==t.xmin&&null!==t.xmin?t.xmin:-1,a=void 0!==t.zmin&&null!==t.zmin?t.zmin:-1,h=void 0!==t.xmax&&null!==t.xmax?t.xmax:1,l=void 0!==t.zmax&&null!==t.zmax?t.zmax:1,c=t.subdivisions||{w:1,h:1},u=t.precision||{w:1,h:1},p=new Array,f=new Array,d=new Array,m=new Array;c.h=c.h<1?1:c.h,c.w=c.w<1?1:c.w,u.w=u.w<1?1:u.w,u.h=u.h<1?1:u.h;var g=(h-s)/c.w,_=(l-a)/c.h;function v(e,t,n,o){var s=f.length/3,a=u.w+1;for(i=0;i<u.h;i++)for(r=0;r<u.w;r++){var h=[s+r+i*a,s+(r+1)+i*a,s+(r+1)+(i+1)*a,s+r+(i+1)*a];p.push(h[1]),p.push(h[2]),p.push(h[3]),p.push(h[0]),p.push(h[1]),p.push(h[3])}var l=Z.Vector3.Zero(),c=new Z.Vector3(0,1,0);for(i=0;i<=u.h;i++)for(l.z=i*(o-t)/u.h+t,r=0;r<=u.w;r++)l.x=r*(n-e)/u.w+e,l.y=0,f.push(l.x,l.y,l.z),d.push(c.x,c.y,c.z),m.push(r/u.w,i/u.h)}for(n=0;n<c.h;n++)for(o=0;o<c.w;o++)v(s+o*g,a+n*_,s+(o+1)*g,a+(n+1)*_);var y=new e;return y.indices=p,y.positions=f,y.normals=d,y.uvs=m,y},e.CreateGroundFromHeightMap=function(t){var i,r,n=[],o=[],s=[],a=[],h=t.colorFilter||new Z.Color3(.3,.59,.11);for(i=0;i<=t.subdivisions;i++)for(r=0;r<=t.subdivisions;r++){var l=new Z.Vector3(r*t.width/t.subdivisions-t.width/2,0,(t.subdivisions-i)*t.height/t.subdivisions-t.height/2),c=4*(((l.x+t.width/2)/t.width*(t.bufferWidth-1)|0)+((1-(l.z+t.height/2)/t.height)*(t.bufferHeight-1)|0)*t.bufferWidth),u=t.buffer[c]/255,p=t.buffer[c+1]/255,f=t.buffer[c+2]/255,d=u*h.r+p*h.g+f*h.b;l.y=t.minHeight+(t.maxHeight-t.minHeight)*d,o.push(l.x,l.y,l.z),s.push(0,0,0),a.push(r/t.subdivisions,1-i/t.subdivisions)}for(i=0;i<t.subdivisions;i++)for(r=0;r<t.subdivisions;r++)n.push(r+1+(i+1)*(t.subdivisions+1)),n.push(r+1+i*(t.subdivisions+1)),n.push(r+i*(t.subdivisions+1)),n.push(r+(i+1)*(t.subdivisions+1)),n.push(r+1+(i+1)*(t.subdivisions+1)),n.push(r+i*(t.subdivisions+1));e.ComputeNormals(o,n,s);var m=new e;return m.indices=n,m.positions=o,m.normals=s,m.uvs=a,m},e.CreatePlane=function(t){var i=[],r=[],n=[],o=[],s=t.width||t.size||1,a=t.height||t.size||1,h=0===t.sideOrientation?0:t.sideOrientation||Z.Mesh.DEFAULTSIDE,l=s/2,c=a/2;r.push(-l,-c,0),n.push(0,0,-1),o.push(0,0),r.push(l,-c,0),n.push(0,0,-1),o.push(1,0),r.push(l,c,0),n.push(0,0,-1),o.push(1,1),r.push(-l,c,0),n.push(0,0,-1),o.push(0,1),i.push(0),i.push(1),i.push(2),i.push(0),i.push(2),i.push(3),e._ComputeSides(h,r,i,n,o,t.frontUVs,t.backUVs);var u=new e;return u.indices=i,u.positions=r,u.normals=n,u.uvs=o,u},e.CreateDisc=function(t){var i=new Array,r=new Array,n=new Array,o=new Array,s=t.radius||.5,a=t.tessellation||64,h=t.arc&&(t.arc<=0||t.arc>1)?1:t.arc||1,l=0===t.sideOrientation?0:t.sideOrientation||Z.Mesh.DEFAULTSIDE;i.push(0,0,0),o.push(.5,.5);for(var c=2*Math.PI*h,u=c/a,p=0;p<c;p+=u){var f=Math.cos(p),d=Math.sin(p),m=(f+1)/2,g=(1-d)/2;i.push(s*f,s*d,0),o.push(m,g)}1===h&&(i.push(i[3],i[4],i[5]),o.push(o[2],o[3]));for(var _=i.length/3,v=1;v<_-1;v++)r.push(v+1,0,v);e.ComputeNormals(i,r,n),e._ComputeSides(l,i,r,n,o,t.frontUVs,t.backUVs);var y=new e;return y.indices=r,y.positions=i,y.normals=n,y.uvs=o,y},e.CreatePolygon=function(t,i,r,n,o,s){for(var a=r||new Array(3),h=n,l=[],c=0;c<3;c++)void 0===a[c]&&(a[c]=new Z.Vector4(0,0,1,1)),h&&void 0===h[c]&&(h[c]=new Z.Color4(1,1,1,1));for(var u=t.getVerticesData(Z.VertexBuffer.PositionKind),p=t.getVerticesData(Z.VertexBuffer.NormalKind),f=t.getVerticesData(Z.VertexBuffer.UVKind),d=t.getIndices(),m=0,g=0,_=0;_<p.length;_+=3)Math.abs(p[_+1])<.001&&(g=1),Math.abs(p[_+1]-1)<.001&&(g=0),Math.abs(p[_+1]+1)<.001&&(g=2),f[2*(m=_/3)]=(1-f[2*m])*a[g].x+f[2*m]*a[g].z,f[2*m+1]=(1-f[2*m+1])*a[g].y+f[2*m+1]*a[g].w,h&&l.push(h[g].r,h[g].g,h[g].b,h[g].a);e._ComputeSides(i,u,d,p,f,o,s);var v=new e;if(v.indices=d,v.positions=u,v.normals=p,v.uvs=f,h){var y=i===Z.Mesh.DOUBLESIDE?l.concat(l):l;v.colors=y}return v},e.CreateIcoSphere=function(t){var i,r=t.sideOrientation||Z.Mesh.DEFAULTSIDE,n=t.radius||1,o=void 0===t.flat||t.flat,s=t.subdivisions||4,a=t.radiusX||n,h=t.radiusY||n,l=t.radiusZ||n,c=(1+Math.sqrt(5))/2,u=[-1,c,-0,1,c,0,-1,-c,0,1,-c,0,0,-1,-c,0,1,-c,0,-1,c,0,1,c,c,0,1,c,0,-1,-c,0,1,-c,0,-1],p=[0,11,5,0,5,1,0,1,7,0,7,10,12,22,23,1,5,20,5,11,4,23,22,13,22,18,6,7,1,8,14,21,4,14,4,2,16,13,6,15,6,19,3,8,9,4,21,5,13,17,23,6,13,22,19,6,18,9,8,1],f=[0,1,2,3,4,5,6,7,8,9,10,11,0,2,3,3,3,4,7,8,9,9,10,11],d=[5,1,3,1,6,4,0,0,5,3,4,2,2,2,4,0,2,0,1,1,6,0,6,2,0,4,3,3,4,4,3,1,4,2,4,4,0,2,1,1,2,2,3,3,1,3,2,4],m=[0,0,0,0,1,0,0,1,1,0,0,0,1,1,0,0,1,1,1,0],g=new Array,_=new Array,v=new Array,y=new Array,b=0,x=new Array(3),T=new Array(3);for(i=0;i<3;i++)x[i]=Z.Vector3.Zero(),T[i]=Z.Vector2.Zero();for(var E=0;E<20;E++){for(i=0;i<3;i++){var A=p[3*E+i];x[i].copyFromFloats(u[3*f[A]],u[3*f[A]+1],u[3*f[A]+2]),x[i].normalize().scaleInPlace(n),T[i].copyFromFloats(d[2*A]*(138/1024)+60/1024+m[E]*(-40/1024),d[2*A+1]*(239/1024)+26/1024+m[E]*(20/1024))}for(var P=function(e,t,i,r){var n,c=Z.Vector3.Lerp(x[0],x[2],t/s),u=Z.Vector3.Lerp(x[1],x[2],t/s),p=s===t?x[2]:Z.Vector3.Lerp(c,u,e/(s-t));if(p.normalize(),o){var f=Z.Vector3.Lerp(x[0],x[2],r/s),d=Z.Vector3.Lerp(x[1],x[2],r/s);n=Z.Vector3.Lerp(f,d,i/(s-r))}else n=new Z.Vector3(p.x,p.y,p.z);n.x/=a,n.y/=h,n.z/=l,n.normalize();var m=Z.Vector2.Lerp(T[0],T[2],t/s),E=Z.Vector2.Lerp(T[1],T[2],t/s),A=s===t?T[2]:Z.Vector2.Lerp(m,E,e/(s-t));_.push(p.x*a,p.y*h,p.z*l),v.push(n.x,n.y,n.z),y.push(A.x,A.y),g.push(b),b++},M=0;M<s;M++)for(var S=0;S+M<s;S++)P(S,M,S+1/3,M+1/3),P(S+1,M,S+1/3,M+1/3),P(S,M+1,S+1/3,M+1/3),S+M+1<s&&(P(S+1,M,S+2/3,M+2/3),P(S+1,M+1,S+2/3,M+2/3),P(S,M+1,S+2/3,M+2/3))}e._ComputeSides(r,_,g,v,y,t.frontUVs,t.backUVs);var C=new e;return C.indices=g,C.positions=_,C.normals=v,C.uvs=y,C},e.CreatePolyhedron=function(t){var i=[];i[0]={vertex:[[0,0,1.732051],[1.632993,0,-.5773503],[-.8164966,1.414214,-.5773503],[-.8164966,-1.414214,-.5773503]],face:[[0,1,2],[0,2,3],[0,3,1],[1,3,2]]},i[1]={vertex:[[0,0,1.414214],[1.414214,0,0],[0,1.414214,0],[-1.414214,0,0],[0,-1.414214,0],[0,0,-1.414214]],face:[[0,1,2],[0,2,3],[0,3,4],[0,4,1],[1,4,5],[1,5,2],[2,5,3],[3,5,4]]},i[2]={vertex:[[0,0,1.070466],[.7136442,0,.7978784],[-.3568221,.618034,.7978784],[-.3568221,-.618034,.7978784],[.7978784,.618034,.3568221],[.7978784,-.618034,.3568221],[-.9341724,.381966,.3568221],[.1362939,1,.3568221],[.1362939,-1,.3568221],[-.9341724,-.381966,.3568221],[.9341724,.381966,-.3568221],[.9341724,-.381966,-.3568221],[-.7978784,.618034,-.3568221],[-.1362939,1,-.3568221],[-.1362939,-1,-.3568221],[-.7978784,-.618034,-.3568221],[.3568221,.618034,-.7978784],[.3568221,-.618034,-.7978784],[-.7136442,0,-.7978784],[0,0,-1.070466]],face:[[0,1,4,7,2],[0,2,6,9,3],[0,3,8,5,1],[1,5,11,10,4],[2,7,13,12,6],[3,9,15,14,8],[4,10,16,13,7],[5,8,14,17,11],[6,12,18,15,9],[10,11,17,19,16],[12,13,16,19,18],[14,15,18,19,17]]},i[3]={vertex:[[0,0,1.175571],[1.051462,0,.5257311],[.3249197,1,.5257311],[-.8506508,.618034,.5257311],[-.8506508,-.618034,.5257311],[.3249197,-1,.5257311],[.8506508,.618034,-.5257311],[.8506508,-.618034,-.5257311],[-.3249197,1,-.5257311],[-1.051462,0,-.5257311],[-.3249197,-1,-.5257311],[0,0,-1.175571]],face:[[0,1,2],[0,2,3],[0,3,4],[0,4,5],[0,5,1],[1,5,7],[1,7,6],[1,6,2],[2,6,8],[2,8,3],[3,8,9],[3,9,4],[4,9,10],[4,10,5],[5,10,7],[6,7,11],[6,11,8],[7,10,11],[8,11,9],[9,11,10]]},i[4]={vertex:[[0,0,1.070722],[.7148135,0,.7971752],[-.104682,.7071068,.7971752],[-.6841528,.2071068,.7971752],[-.104682,-.7071068,.7971752],[.6101315,.7071068,.5236279],[1.04156,.2071068,.1367736],[.6101315,-.7071068,.5236279],[-.3574067,1,.1367736],[-.7888348,-.5,.5236279],[-.9368776,.5,.1367736],[-.3574067,-1,.1367736],[.3574067,1,-.1367736],[.9368776,-.5,-.1367736],[.7888348,.5,-.5236279],[.3574067,-1,-.1367736],[-.6101315,.7071068,-.5236279],[-1.04156,-.2071068,-.1367736],[-.6101315,-.7071068,-.5236279],[.104682,.7071068,-.7971752],[.6841528,-.2071068,-.7971752],[.104682,-.7071068,-.7971752],[-.7148135,0,-.7971752],[0,0,-1.070722]],face:[[0,2,3],[1,6,5],[4,9,11],[7,15,13],[8,16,10],[12,14,19],[17,22,18],[20,21,23],[0,1,5,2],[0,3,9,4],[0,4,7,1],[1,7,13,6],[2,5,12,8],[2,8,10,3],[3,10,17,9],[4,11,15,7],[5,6,14,12],[6,13,20,14],[8,12,19,16],[9,17,18,11],[10,16,22,17],[11,18,21,15],[13,15,21,20],[14,20,23,19],[16,19,23,22],[18,22,23,21]]},i[5]={vertex:[[0,0,1.322876],[1.309307,0,.1889822],[-.9819805,.8660254,.1889822],[.1636634,-1.299038,.1889822],[.3273268,.8660254,-.9449112],[-.8183171,-.4330127,-.9449112]],face:[[0,3,1],[2,4,5],[0,1,4,2],[0,2,5,3],[1,3,5,4]]},i[6]={vertex:[[0,0,1.159953],[1.013464,0,.5642542],[-.3501431,.9510565,.5642542],[-.7715208,-.6571639,.5642542],[.6633206,.9510565,-.03144481],[.8682979,-.6571639,-.3996071],[-1.121664,.2938926,-.03144481],[-.2348831,-1.063314,-.3996071],[.5181548,.2938926,-.9953061],[-.5850262,-.112257,-.9953061]],face:[[0,1,4,2],[0,2,6,3],[1,5,8,4],[3,6,9,7],[5,7,9,8],[0,3,7,5,1],[2,4,8,9,6]]},i[7]={vertex:[[0,0,1.118034],[.8944272,0,.6708204],[-.2236068,.8660254,.6708204],[-.7826238,-.4330127,.6708204],[.6708204,.8660254,.2236068],[1.006231,-.4330127,-.2236068],[-1.006231,.4330127,.2236068],[-.6708204,-.8660254,-.2236068],[.7826238,.4330127,-.6708204],[.2236068,-.8660254,-.6708204],[-.8944272,0,-.6708204],[0,0,-1.118034]],face:[[0,1,4,2],[0,2,6,3],[1,5,8,4],[3,6,10,7],[5,9,11,8],[7,10,11,9],[0,3,7,9,5,1],[2,4,8,11,10,6]]},i[8]={vertex:[[-.729665,.670121,.319155],[-.655235,-.29213,-.754096],[-.093922,-.607123,.537818],[.702196,.595691,.485187],[.776626,-.36656,-.588064]],face:[[1,4,2],[0,1,2],[3,0,2],[4,3,2],[4,1,0,3]]},i[9]={vertex:[[-.868849,-.100041,.61257],[-.329458,.976099,.28078],[-.26629,-.013796,-.477654],[-.13392,-1.034115,.229829],[.738834,.707117,-.307018],[.859683,-.535264,-.338508]],face:[[3,0,2],[5,3,2],[4,5,2],[1,4,2],[0,1,2],[0,3,5,4,1]]},i[10]={vertex:[[-.610389,.243975,.531213],[-.187812,-.48795,-.664016],[-.187812,.9759,-.664016],[.187812,-.9759,.664016],[.798201,.243975,.132803]],face:[[1,3,0],[3,4,0],[3,1,4],[0,2,1],[0,4,2],[2,4,1]]},i[11]={vertex:[[-1.028778,.392027,-.048786],[-.640503,-.646161,.621837],[-.125162,-.395663,-.540059],[.004683,.888447,-.651988],[.125161,.395663,.540059],[.632925,-.791376,.433102],[1.031672,.157063,-.354165]],face:[[3,2,0],[2,1,0],[2,5,1],[0,4,3],[0,1,4],[4,1,5],[2,3,6],[3,4,6],[5,2,6],[4,5,6]]},i[12]={vertex:[[-.669867,.334933,-.529576],[-.669867,.334933,.529577],[-.4043,1.212901,0],[-.334933,-.669867,-.529576],[-.334933,-.669867,.529577],[.334933,.669867,-.529576],[.334933,.669867,.529577],[.4043,-1.212901,0],[.669867,-.334933,-.529576],[.669867,-.334933,.529577]],face:[[8,9,7],[6,5,2],[3,8,7],[5,0,2],[4,3,7],[0,1,2],[9,4,7],[1,6,2],[9,8,5,6],[8,3,0,5],[3,4,1,0],[4,9,6,1]]},i[13]={vertex:[[-.931836,.219976,-.264632],[-.636706,.318353,.692816],[-.613483,-.735083,-.264632],[-.326545,.979634,0],[-.318353,-.636706,.692816],[-.159176,.477529,-.856368],[.159176,-.477529,-.856368],[.318353,.636706,.692816],[.326545,-.979634,0],[.613482,.735082,-.264632],[.636706,-.318353,.692816],[.931835,-.219977,-.264632]],face:[[11,10,8],[7,9,3],[6,11,8],[9,5,3],[2,6,8],[5,0,3],[4,2,8],[0,1,3],[10,4,8],[1,7,3],[10,11,9,7],[11,6,5,9],[6,2,0,5],[2,4,1,0],[4,10,7,1]]},i[14]={vertex:[[-.93465,.300459,-.271185],[-.838689,-.260219,-.516017],[-.711319,.717591,.128359],[-.710334,-.156922,.080946],[-.599799,.556003,-.725148],[-.503838,-.004675,-.969981],[-.487004,.26021,.48049],[-.460089,-.750282,-.512622],[-.376468,.973135,-.325605],[-.331735,-.646985,.084342],[-.254001,.831847,.530001],[-.125239,-.494738,-.966586],[.029622,.027949,.730817],[.056536,-.982543,-.262295],[.08085,1.087391,.076037],[.125583,-.532729,.485984],[.262625,.599586,.780328],[.391387,-.726999,-.716259],[.513854,-.868287,.139347],[.597475,.85513,.326364],[.641224,.109523,.783723],[.737185,-.451155,.538891],[.848705,-.612742,-.314616],[.976075,.365067,.32976],[1.072036,-.19561,.084927]],face:[[15,18,21],[12,20,16],[6,10,2],[3,0,1],[9,7,13],[2,8,4,0],[0,4,5,1],[1,5,11,7],[7,11,17,13],[13,17,22,18],[18,22,24,21],[21,24,23,20],[20,23,19,16],[16,19,14,10],[10,14,8,2],[15,9,13,18],[12,15,21,20],[6,12,16,10],[3,6,2,0],[9,3,1,7],[9,15,12,6,3],[22,17,11,5,4,8,14,19,23,24]]};var r,n,o,s,a,h,l=t.type&&(t.type<0||t.type>=i.length)?0:t.type||0,c=t.size,u=t.sizeX||c||1,p=t.sizeY||c||1,f=t.sizeZ||c||1,d=t.custom||i[l],m=d.face.length,g=t.faceUV||new Array(m),_=t.faceColors,v=void 0===t.flat||t.flat,y=0===t.sideOrientation?0:t.sideOrientation||Z.Mesh.DEFAULTSIDE,b=new Array,x=new Array,T=new Array,E=new Array,A=new Array,P=0,M=0,S=new Array,C=0,R=0;if(v)for(R=0;R<m;R++)_&&void 0===_[R]&&(_[R]=new Z.Color4(1,1,1,1)),g&&void 0===g[R]&&(g[R]=new Z.Vector4(0,0,1,1));if(v)for(R=0;R<m;R++){var O=d.face[R].length;for(o=2*Math.PI/O,s=.5*Math.tan(o/2),a=.5,C=0;C<O;C++)b.push(d.vertex[d.face[R][C]][0]*u,d.vertex[d.face[R][C]][1]*p,d.vertex[d.face[R][C]][2]*f),S.push(P),P++,r=g[R].x+(g[R].z-g[R].x)*(.5+s),n=g[R].y+(g[R].w-g[R].y)*(a-.5),E.push(r,n),h=s*Math.cos(o)-a*Math.sin(o),a=s*Math.sin(o)+a*Math.cos(o),s=h,_&&A.push(_[R].r,_[R].g,_[R].b,_[R].a);for(C=0;C<O-2;C++)x.push(S[0+M],S[C+2+M],S[C+1+M]);M+=O}else{for(C=0;C<d.vertex.length;C++)b.push(d.vertex[C][0]*u,d.vertex[C][1]*p,d.vertex[C][2]*f),E.push(0,0);for(R=0;R<m;R++)for(C=0;C<d.face[R].length-2;C++)x.push(d.face[R][0],d.face[R][C+2],d.face[R][C+1])}e.ComputeNormals(b,x,T),e._ComputeSides(y,b,x,T,E,t.frontUVs,t.backUVs);var I=new e;return I.positions=b,I.indices=x,I.normals=T,I.uvs=E,_&&v&&(I.colors=A),I},e.CreateTorusKnot=function(t){var i,r,n=new Array,o=new Array,s=new Array,a=new Array,h=t.radius||2,l=t.tube||.5,c=t.radialSegments||32,u=t.tubularSegments||32,p=t.p||2,f=t.q||3,d=0===t.sideOrientation?0:t.sideOrientation||Z.Mesh.DEFAULTSIDE,m=function(e){var t=Math.cos(e),i=Math.sin(e),r=f/p*e,n=Math.cos(r),o=h*(2+n)*.5*t,s=h*(2+n)*i*.5,a=h*Math.sin(r)*.5;return new Z.Vector3(o,s,a)};for(i=0;i<=c;i++){var g=i%c/c*2*p*Math.PI,_=m(g),v=m(g+.01),y=v.subtract(_),b=v.add(_),x=Z.Vector3.Cross(y,b);for(b=Z.Vector3.Cross(x,y),x.normalize(),b.normalize(),r=0;r<u;r++){var T=r%u/u*2*Math.PI,E=-l*Math.cos(T),A=l*Math.sin(T);o.push(_.x+E*b.x+A*x.x),o.push(_.y+E*b.y+A*x.y),o.push(_.z+E*b.z+A*x.z),a.push(i/c),a.push(r/u)}}for(i=0;i<c;i++)for(r=0;r<u;r++){var P=(r+1)%u,M=i*u+r,S=(i+1)*u+r,C=(i+1)*u+P,R=i*u+P;n.push(R),n.push(S),n.push(M),n.push(R),n.push(C),n.push(S)}e.ComputeNormals(o,n,s),e._ComputeSides(d,o,n,s,a,t.frontUVs,t.backUVs);var O=new e;return O.indices=n,O.positions=o,O.normals=s,O.uvs=a,O},e.ComputeNormals=function(e,t,i,r){var n=0,o=0,s=0,a=0,h=0,l=0,c=0,u=0,p=0,f=0,d=0,m=0,g=0,_=0,v=0,y=0,b=0,x=0,T=0,E=0,A=!1,P=!1,M=!1,S=!1,C=1,R=0,O=null;if(r&&(A=!!r.facetNormals,P=!!r.facetPositions,M=!!r.facetPartitioning,C=!0===r.useRightHandedSystem?-1:1,R=r.ratio||0,S=!!r.depthSort,O=r.distanceTo,S)){void 0===O&&(O=Z.Vector3.Zero());var I=r.depthSortedFacets}var w=0,D=0,L=0,B=0;if(M&&r&&r.bbSize){var N=0,F=0,V=0,k=0,U=0,z=0,G=0,W=0,H=0,j=0,X=0,Y=0,K=0,Q=0,q=0,J=0,$=r.bbSize.x>r.bbSize.y?r.bbSize.x:r.bbSize.y;$=$>r.bbSize.z?$:r.bbSize.z,w=r.subDiv.X*R/r.bbSize.x,D=r.subDiv.Y*R/r.bbSize.y,L=r.subDiv.Z*R/r.bbSize.z,B=r.subDiv.max*r.subDiv.max,r.facetPartitioning.length=0}for(n=0;n<e.length;n++)i[n]=0;var ee=t.length/3|0;for(n=0;n<ee;n++){if(g=(m=3*t[3*n])+1,_=m+2,y=(v=3*t[3*n+1])+1,b=v+2,T=(x=3*t[3*n+2])+1,E=x+2,o=e[m]-e[v],s=e[g]-e[y],a=e[_]-e[b],h=e[x]-e[v],l=e[T]-e[y],u=C*(s*(c=e[E]-e[b])-a*l),p=C*(a*h-o*c),f=C*(o*l-s*h),u/=d=0===(d=Math.sqrt(u*u+p*p+f*f))?1:d,p/=d,f/=d,A&&r&&(r.facetNormals[n].x=u,r.facetNormals[n].y=p,r.facetNormals[n].z=f),P&&r&&(r.facetPositions[n].x=(e[m]+e[v]+e[x])/3,r.facetPositions[n].y=(e[g]+e[y]+e[T])/3,r.facetPositions[n].z=(e[_]+e[b]+e[E])/3),M&&r&&(N=Math.floor((r.facetPositions[n].x-r.bInfo.minimum.x*R)*w),F=Math.floor((r.facetPositions[n].y-r.bInfo.minimum.y*R)*D),V=Math.floor((r.facetPositions[n].z-r.bInfo.minimum.z*R)*L),k=Math.floor((e[m]-r.bInfo.minimum.x*R)*w),U=Math.floor((e[g]-r.bInfo.minimum.y*R)*D),z=Math.floor((e[_]-r.bInfo.minimum.z*R)*L),G=Math.floor((e[v]-r.bInfo.minimum.x*R)*w),W=Math.floor((e[y]-r.bInfo.minimum.y*R)*D),H=Math.floor((e[b]-r.bInfo.minimum.z*R)*L),j=Math.floor((e[x]-r.bInfo.minimum.x*R)*w),X=Math.floor((e[T]-r.bInfo.minimum.y*R)*D),Y=Math.floor((e[E]-r.bInfo.minimum.z*R)*L),Q=k+r.subDiv.max*U+B*z,q=G+r.subDiv.max*W+B*H,J=j+r.subDiv.max*X+B*Y,K=N+r.subDiv.max*F+B*V,r.facetPartitioning[K]=r.facetPartitioning[K]?r.facetPartitioning[K]:new Array,r.facetPartitioning[Q]=r.facetPartitioning[Q]?r.facetPartitioning[Q]:new Array,r.facetPartitioning[q]=r.facetPartitioning[q]?r.facetPartitioning[q]:new Array,r.facetPartitioning[J]=r.facetPartitioning[J]?r.facetPartitioning[J]:new Array,r.facetPartitioning[Q].push(n),q!=Q&&r.facetPartitioning[q].push(n),J!=q&&J!=Q&&r.facetPartitioning[J].push(n),K!=Q&&K!=q&&K!=J&&r.facetPartitioning[K].push(n)),S&&r&&r.facetPositions){var te=I[n];te.ind=3*n,te.sqDistance=Z.Vector3.DistanceSquared(r.facetPositions[n],O)}i[m]+=u,i[g]+=p,i[_]+=f,i[v]+=u,i[y]+=p,i[b]+=f,i[x]+=u,i[T]+=p,i[E]+=f}for(n=0;n<i.length/3;n++)u=i[3*n],p=i[3*n+1],f=i[3*n+2],u/=d=0===(d=Math.sqrt(u*u+p*p+f*f))?1:d,p/=d,f/=d,i[3*n]=u,i[3*n+1]=p,i[3*n+2]=f},e._ComputeSides=function(e,t,i,r,n,o,s){var a,h,l=i.length,c=r.length;switch(e=e||Z.Mesh.DEFAULTSIDE){case Z.Mesh.FRONTSIDE:break;case Z.Mesh.BACKSIDE:var u;for(a=0;a<l;a+=3)u=i[a],i[a]=i[a+2],i[a+2]=u;for(h=0;h<c;h++)r[h]=-r[h];break;case Z.Mesh.DOUBLESIDE:for(var p=t.length,f=p/3,d=0;d<p;d++)t[p+d]=t[d];for(a=0;a<l;a+=3)i[a+l]=i[a+2]+f,i[a+1+l]=i[a+1]+f,i[a+2+l]=i[a]+f;for(h=0;h<c;h++)r[c+h]=-r[h];var m=n.length,g=0;for(g=0;g<m;g++)n[g+m]=n[g];for(o=o||new Z.Vector4(0,0,1,1),s=s||new Z.Vector4(0,0,1,1),g=0,a=0;a<m/2;a++)n[g]=o.x+(o.z-o.x)*n[g],n[g+1]=o.y+(o.w-o.y)*n[g+1],n[g+m]=s.x+(s.z-s.x)*n[g+m],n[g+m+1]=s.y+(s.w-s.y)*n[g+m+1],g+=2}},e.ImportVertexData=function(t,i){var r=new e,n=t.positions;n&&r.set(n,Z.VertexBuffer.PositionKind);var o=t.normals;o&&r.set(o,Z.VertexBuffer.NormalKind);var s=t.tangents;s&&r.set(s,Z.VertexBuffer.TangentKind);var a=t.uvs;a&&r.set(a,Z.VertexBuffer.UVKind);var h=t.uv2s;h&&r.set(h,Z.VertexBuffer.UV2Kind);var l=t.uv3s;l&&r.set(l,Z.VertexBuffer.UV3Kind);var c=t.uv4s;c&&r.set(c,Z.VertexBuffer.UV4Kind);var u=t.uv5s;u&&r.set(u,Z.VertexBuffer.UV5Kind);var p=t.uv6s;p&&r.set(p,Z.VertexBuffer.UV6Kind);var f=t.colors;f&&r.set(Z.Color4.CheckColors4(f,n.length/3),Z.VertexBuffer.ColorKind);var d=t.matricesIndices;d&&r.set(d,Z.VertexBuffer.MatricesIndicesKind);var m=t.matricesWeights;m&&r.set(m,Z.VertexBuffer.MatricesWeightsKind);var g=t.indices;g&&(r.indices=g),i.setAllVerticesData(r,t.updatable)},e}(),Z.VertexData=q,function(e){var t=function(){function t(t,i,r,n,o){void 0===n&&(n=!1),void 0===o&&(o=null),this.delayLoadState=e.Engine.DELAYLOADSTATE_NONE,this._totalVertices=0,this._isDisposed=!1,this._indexBufferIsUpdatable=!1,this.id=t,this._engine=i.getEngine(),this._meshes=[],this._scene=i,this._vertexBuffers={},this._indices=[],this._updatable=n,r?this.setAllVerticesData(r,n):(this._totalVertices=0,this._indices=[]),this._engine.getCaps().vertexArrayObject&&(this._vertexArrayObjects={}),o&&("LinesMesh"===o.getClassName()&&(this.boundingBias=new e.Vector2(0,o.intersectionThreshold),this.updateExtend()),this.applyToMesh(o),o.computeWorldMatrix(!0))}return Object.defineProperty(t.prototype,"boundingBias",{get:function(){return this._boundingBias},set:function(e){this._boundingBias&&this._boundingBias.equals(e)||(this._boundingBias=e.clone(),this.updateBoundingInfo(!0,null))},enumerable:!0,configurable:!0}),t.CreateGeometryForMesh=function(e){var i=new t(t.RandomId(),e.getScene());return i.applyToMesh(e),i},Object.defineProperty(t.prototype,"extend",{get:function(){return this._extend},enumerable:!0,configurable:!0}),t.prototype.getScene=function(){return this._scene},t.prototype.getEngine=function(){return this._engine},t.prototype.isReady=function(){return this.delayLoadState===e.Engine.DELAYLOADSTATE_LOADED||this.delayLoadState===e.Engine.DELAYLOADSTATE_NONE},Object.defineProperty(t.prototype,"doNotSerialize",{get:function(){for(var e=0;e<this._meshes.length;e++)if(!this._meshes[e].doNotSerialize)return!1;return!0},enumerable:!0,configurable:!0}),t.prototype._rebuild=function(){this._vertexArrayObjects&&(this._vertexArrayObjects={}),0!==this._meshes.length&&this._indices&&(this._indexBuffer=this._engine.createIndexBuffer(this._indices));for(var e in this._vertexBuffers){this._vertexBuffers[e]._rebuild()}},t.prototype.setAllVerticesData=function(e,t){e.applyToGeometry(this,t),this.notifyUpdate()},t.prototype.setVerticesData=function(t,i,r,n){void 0===r&&(r=!1);var o=new e.VertexBuffer(this._engine,i,t,r,0===this._meshes.length,n);this.setVerticesBuffer(o)},t.prototype.removeVerticesData=function(e){this._vertexBuffers[e]&&(this._vertexBuffers[e].dispose(),delete this._vertexBuffers[e])},t.prototype.setVerticesBuffer=function(t){var i=t.getKind();if(this._vertexBuffers[i]&&this._vertexBuffers[i].dispose(),this._vertexBuffers[i]=t,i===e.VertexBuffer.PositionKind){var r=t.getData(),n=t.getStrideSize();this._totalVertices=r.length/n,this.updateExtend(r,n),this._resetPointsArrayCache();for(var o=this._meshes,s=o.length,a=0;a<s;a++){var h=o[a];h._boundingInfo=new e.BoundingInfo(this._extend.minimum,this._extend.maximum),h._createGlobalSubMesh(!1),h.computeWorldMatrix(!0)}}this.notifyUpdate(i),this._vertexArrayObjects&&(this._disposeVertexArrayObjects(),this._vertexArrayObjects={})},t.prototype.updateVerticesDataDirectly=function(e,t,i){var r=this.getVertexBuffer(e);r&&(r.updateDirectly(t,i),this.notifyUpdate(e))},t.prototype.updateVerticesData=function(t,i,r){void 0===r&&(r=!1);var n=this.getVertexBuffer(t);if(n){if(n.update(i),t===e.VertexBuffer.PositionKind){var o=n.getStrideSize();this._totalVertices=i.length/o,this.updateBoundingInfo(r,i)}this.notifyUpdate(t)}},t.prototype.updateBoundingInfo=function(t,i){t&&this.updateExtend(i);var r=this._meshes,n=r.length;this._resetPointsArrayCache();for(var o=0;o<n;o++){var s=r[o];if(t){s._boundingInfo=new e.BoundingInfo(this._extend.minimum,this._extend.maximum);for(var a=0;a<s.subMeshes.length;a++){s.subMeshes[a].refreshBoundingInfo()}}}},t.prototype._bind=function(e,t){if(e){void 0===t&&(t=this._indexBuffer);var i=this.getVertexBuffers();i&&(t==this._indexBuffer&&this._vertexArrayObjects?(this._vertexArrayObjects[e.key]||(this._vertexArrayObjects[e.key]=this._engine.recordVertexArrayObject(i,t,e)),this._engine.bindVertexArrayObject(this._vertexArrayObjects[e.key],t)):this._engine.bindBuffers(i,t,e))}},t.prototype.getTotalVertices=function(){return this.isReady()?this._totalVertices:0},t.prototype.getVerticesData=function(e,t,i){var r=this.getVertexBuffer(e);if(!r)return null;var n=r.getData();if(i||t&&1!==this._meshes.length){for(var o=n.length,s=[],a=0;a<o;a++)s.push(n[a]);return s}return n},t.prototype.isVertexBufferUpdatable=function(e){var t=this._vertexBuffers[e];return!!t&&t.isUpdatable()},t.prototype.getVertexBuffer=function(e){return this.isReady()?this._vertexBuffers[e]:null},t.prototype.getVertexBuffers=function(){return this.isReady()?this._vertexBuffers:null},t.prototype.isVerticesDataPresent=function(e){return this._vertexBuffers?void 0!==this._vertexBuffers[e]:!!this._delayInfo&&-1!==this._delayInfo.indexOf(e)},t.prototype.getVerticesDataKinds=function(){var e,t=[];if(!this._vertexBuffers&&this._delayInfo)for(e in this._delayInfo)t.push(e);else for(e in this._vertexBuffers)t.push(e);return t},t.prototype.updateIndices=function(e,t){this._indexBuffer&&(this._indexBufferIsUpdatable?this._engine.updateDynamicIndexBuffer(this._indexBuffer,e,t):this.setIndices(e,null,!0))},t.prototype.setIndices=function(e,t,i){void 0===t&&(t=null),void 0===i&&(i=!1),this._indexBuffer&&this._engine._releaseBuffer(this._indexBuffer),this._disposeVertexArrayObjects(),this._indices=e,this._indexBufferIsUpdatable=i,0!==this._meshes.length&&this._indices&&(this._indexBuffer=this._engine.createIndexBuffer(this._indices,i)),void 0!=t&&(this._totalVertices=t);for(var r=this._meshes,n=r.length,o=0;o<n;o++)r[o]._createGlobalSubMesh(!0);this.notifyUpdate()},t.prototype.getTotalIndices=function(){return this.isReady()?this._indices.length:0},t.prototype.getIndices=function(e){if(!this.isReady())return null;var t=this._indices;if(e&&1!==this._meshes.length){for(var i=t.length,r=[],n=0;n<i;n++)r.push(t[n]);return r}return t},t.prototype.getIndexBuffer=function(){return this.isReady()?this._indexBuffer:null},t.prototype._releaseVertexArrayObject=function(e){void 0===e&&(e=null),e&&this._vertexArrayObjects&&this._vertexArrayObjects[e.key]&&(this._engine.releaseVertexArrayObject(this._vertexArrayObjects[e.key]),delete this._vertexArrayObjects[e.key])},t.prototype.releaseForMesh=function(e,t){var i=this._meshes,r=i.indexOf(e);-1!==r&&(i.splice(r,1),e._geometry=null,0===i.length&&t&&this.dispose())},t.prototype.applyToMesh=function(e){if(e._geometry!==this){var t=e._geometry;t&&t.releaseForMesh(e);var i=this._meshes;e._geometry=this,this._scene.pushGeometry(this),i.push(e),this.isReady()?this._applyToMesh(e):e._boundingInfo=this._boundingInfo}},t.prototype.updateExtend=function(t,i){void 0===t&&(t=null),t||(t=this._vertexBuffers[e.VertexBuffer.PositionKind].getData()),this._extend=e.Tools.ExtractMinAndMax(t,0,this._totalVertices,this.boundingBias,i)},t.prototype._applyToMesh=function(t){var i=this._meshes.length;for(var r in this._vertexBuffers){1===i&&this._vertexBuffers[r].create();var n=this._vertexBuffers[r].getBuffer();n&&(n.references=i),r===e.VertexBuffer.PositionKind&&(this._extend||this.updateExtend(this._vertexBuffers[r].getData()),t._boundingInfo=new e.BoundingInfo(this._extend.minimum,this._extend.maximum),t._createGlobalSubMesh(!1),t._updateBoundingInfo())}1===i&&this._indices&&this._indices.length>0&&(this._indexBuffer=this._engine.createIndexBuffer(this._indices)),this._indexBuffer&&(this._indexBuffer.references=i)},t.prototype.notifyUpdate=function(e){this.onGeometryUpdated&&this.onGeometryUpdated(this,e);for(var t=0,i=this._meshes;t<i.length;t++){i[t]._markSubMeshesAsAttributesDirty()}},t.prototype.load=function(t,i){this.delayLoadState!==e.Engine.DELAYLOADSTATE_LOADING&&(this.isReady()?i&&i():(this.delayLoadState=e.Engine.DELAYLOADSTATE_LOADING,this._queueLoad(t,i)))},t.prototype._queueLoad=function(t,i){var r=this;this.delayLoadingFile&&(t._addPendingData(this),t._loadFile(this.delayLoadingFile,function(n){if(r._delayLoadingFunction){r._delayLoadingFunction(JSON.parse(n),r),r.delayLoadState=e.Engine.DELAYLOADSTATE_LOADED,r._delayInfo=[],t._removePendingData(r);for(var o=r._meshes,s=o.length,a=0;a<s;a++)r._applyToMesh(o[a]);i&&i()}},void 0,!0))},t.prototype.toLeftHanded=function(){var t=this.getIndices(!1);if(null!=t&&t.length>0){for(var i=0;i<t.length;i+=3){var r=t[i+0];t[i+0]=t[i+2],t[i+2]=r}this.setIndices(t)}var n=this.getVerticesData(e.VertexBuffer.PositionKind,!1);if(null!=n&&n.length>0){for(i=0;i<n.length;i+=3)n[i+2]=-n[i+2];this.setVerticesData(e.VertexBuffer.PositionKind,n,!1)}var o=this.getVerticesData(e.VertexBuffer.NormalKind,!1);if(null!=o&&o.length>0){for(i=0;i<o.length;i+=3)o[i+2]=-o[i+2];this.setVerticesData(e.VertexBuffer.NormalKind,o,!1)}},t.prototype._resetPointsArrayCache=function(){this._positions=null},t.prototype._generatePointsArray=function(){if(this._positions)return!0;this._positions=[];var t=this.getVerticesData(e.VertexBuffer.PositionKind);if(!t)return!1;for(var i=0;i<t.length;i+=3)this._positions.push(e.Vector3.FromArray(t,i));return!0},t.prototype.isDisposed=function(){return this._isDisposed},t.prototype._disposeVertexArrayObjects=function(){if(this._vertexArrayObjects){for(var e in this._vertexArrayObjects)this._engine.releaseVertexArrayObject(this._vertexArrayObjects[e]);this._vertexArrayObjects={}}},t.prototype.dispose=function(){var t,i=this._meshes,r=i.length;for(t=0;t<r;t++)this.releaseForMesh(i[t]);this._meshes=[],this._disposeVertexArrayObjects();for(var n in this._vertexBuffers)this._vertexBuffers[n].dispose();this._vertexBuffers={},this._totalVertices=0,this._indexBuffer&&this._engine._releaseBuffer(this._indexBuffer),this._indexBuffer=null,this._indices=[],this.delayLoadState=e.Engine.DELAYLOADSTATE_NONE,this.delayLoadingFile=null,this._delayLoadingFunction=null,this._delayInfo=[],this._boundingInfo=null,this._scene.removeGeometry(this),this._isDisposed=!0},t.prototype.copy=function(i){var r=new e.VertexData;r.indices=[];var n=this.getIndices();if(n)for(var o=0;o<n.length;o++)r.indices.push(n[o]);var s,a=!1,h=!1;for(s in this._vertexBuffers){var l=this.getVerticesData(s);if(l instanceof Float32Array?r.set(new Float32Array(l),s):r.set(l.slice(0),s),!h){var c=this.getVertexBuffer(s);c&&(h=!(a=c.isUpdatable()))}}var u=new t(i,this._scene,r,a);u.delayLoadState=this.delayLoadState,u.delayLoadingFile=this.delayLoadingFile,u._delayLoadingFunction=this._delayLoadingFunction;for(s in this._delayInfo)u._delayInfo=u._delayInfo||[],u._delayInfo.push(s);return u._boundingInfo=new e.BoundingInfo(this._extend.minimum,this._extend.maximum),u},t.prototype.serialize=function(){var t={};return t.id=this.id,t.updatable=this._updatable,e.Tags&&e.Tags.HasTags(this)&&(t.tags=e.Tags.GetTags(this)),t},t.prototype.toNumberArray=function(e){return Array.isArray(e)?e:Array.prototype.slice.call(e)},t.prototype.serializeVerticeData=function(){var t=this.serialize();return this.isVerticesDataPresent(e.VertexBuffer.PositionKind)&&(t.positions=this.toNumberArray(this.getVerticesData(e.VertexBuffer.PositionKind)),this.isVertexBufferUpdatable(e.VertexBuffer.PositionKind)&&(t.positions._updatable=!0)),this.isVerticesDataPresent(e.VertexBuffer.NormalKind)&&(t.normals=this.toNumberArray(this.getVerticesData(e.VertexBuffer.NormalKind)),this.isVertexBufferUpdatable(e.VertexBuffer.NormalKind)&&(t.normals._updatable=!0)),this.isVerticesDataPresent(e.VertexBuffer.UVKind)&&(t.uvs=this.toNumberArray(this.getVerticesData(e.VertexBuffer.UVKind)),this.isVertexBufferUpdatable(e.VertexBuffer.UVKind)&&(t.uvs._updatable=!0)),this.isVerticesDataPresent(e.VertexBuffer.UV2Kind)&&(t.uv2s=this.toNumberArray(this.getVerticesData(e.VertexBuffer.UV2Kind)),this.isVertexBufferUpdatable(e.VertexBuffer.UV2Kind)&&(t.uv2s._updatable=!0)),this.isVerticesDataPresent(e.VertexBuffer.UV3Kind)&&(t.uv3s=this.toNumberArray(this.getVerticesData(e.VertexBuffer.UV3Kind)),this.isVertexBufferUpdatable(e.VertexBuffer.UV3Kind)&&(t.uv3s._updatable=!0)),this.isVerticesDataPresent(e.VertexBuffer.UV4Kind)&&(t.uv4s=this.toNumberArray(this.getVerticesData(e.VertexBuffer.UV4Kind)),this.isVertexBufferUpdatable(e.VertexBuffer.UV4Kind)&&(t.uv4s._updatable=!0)),this.isVerticesDataPresent(e.VertexBuffer.UV5Kind)&&(t.uv5s=this.toNumberArray(this.getVerticesData(e.VertexBuffer.UV5Kind)),this.isVertexBufferUpdatable(e.VertexBuffer.UV5Kind)&&(t.uv5s._updatable=!0)),this.isVerticesDataPresent(e.VertexBuffer.UV6Kind)&&(t.uv6s=this.toNumberArray(this.getVerticesData(e.VertexBuffer.UV6Kind)),this.isVertexBufferUpdatable(e.VertexBuffer.UV6Kind)&&(t.uv6s._updatable=!0)),this.isVerticesDataPresent(e.VertexBuffer.ColorKind)&&(t.colors=this.toNumberArray(this.getVerticesData(e.VertexBuffer.ColorKind)),this.isVertexBufferUpdatable(e.VertexBuffer.ColorKind)&&(t.colors._updatable=!0)),this.isVerticesDataPresent(e.VertexBuffer.MatricesIndicesKind)&&(t.matricesIndices=this.toNumberArray(this.getVerticesData(e.VertexBuffer.MatricesIndicesKind)),t.matricesIndices._isExpanded=!0,this.isVertexBufferUpdatable(e.VertexBuffer.MatricesIndicesKind)&&(t.matricesIndices._updatable=!0)),this.isVerticesDataPresent(e.VertexBuffer.MatricesWeightsKind)&&(t.matricesWeights=this.toNumberArray(this.getVerticesData(e.VertexBuffer.MatricesWeightsKind)),this.isVertexBufferUpdatable(e.VertexBuffer.MatricesWeightsKind)&&(t.matricesWeights._updatable=!0)),t.indices=this.toNumberArray(this.getIndices()),t},t.ExtractFromMesh=function(e,t){var i=e._geometry;return i?i.copy(t):null},t.RandomId=function(){return e.Tools.RandomId()},t.ImportGeometry=function(i,r){var n=r.getScene(),o=i.geometryId;if(o){var s=n.getGeometryByID(o);s&&s.applyToMesh(r)}else if(i instanceof ArrayBuffer){var a=r._binaryInfo;if(a.positionsAttrDesc&&a.positionsAttrDesc.count>0){var 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(var x=0;x<a.subMeshesAttrDesc.count;x++){var T=b[5*x+0],E=b[5*x+1],A=b[5*x+2],P=b[5*x+3],M=b[5*x+4];e.SubMesh.AddToMesh(T,E,A,P,M,r)}}}else if(i.positions&&i.normals&&i.indices){if(r.setVerticesData(e.VertexBuffer.PositionKind,i.positions,i.positions._updatable),r.setVerticesData(e.VertexBuffer.NormalKind,i.normals,i.normals._updatable),i.uvs&&r.setVerticesData(e.VertexBuffer.UVKind,i.uvs,i.uvs._updatable),i.uvs2&&r.setVerticesData(e.VertexBuffer.UV2Kind,i.uvs2,i.uvs2._updatable),i.uvs3&&r.setVerticesData(e.VertexBuffer.UV3Kind,i.uvs3,i.uvs3._updatable),i.uvs4&&r.setVerticesData(e.VertexBuffer.UV4Kind,i.uvs4,i.uvs4._updatable),i.uvs5&&r.setVerticesData(e.VertexBuffer.UV5Kind,i.uvs5,i.uvs5._updatable),i.uvs6&&r.setVerticesData(e.VertexBuffer.UV6Kind,i.uvs6,i.uvs6._updatable),i.colors&&r.setVerticesData(e.VertexBuffer.ColorKind,e.Color4.CheckColors4(i.colors,i.positions.length/3),i.colors._updatable),i.matricesIndices)if(i.matricesIndices._isExpanded)delete i.matricesIndices._isExpanded,r.setVerticesData(e.VertexBuffer.MatricesIndicesKind,i.matricesIndices,i.matricesIndices._updatable);else{var S=[];for(x=0;x<i.matricesIndices.length;x++){var C=i.matricesIndices[x];S.push(255&C),S.push((65280&C)>>8),S.push((16711680&C)>>16),S.push(C>>24)}r.setVerticesData(e.VertexBuffer.MatricesIndicesKind,S,i.matricesIndices._updatable)}if(i.matricesIndicesExtra)if(i.matricesIndicesExtra._isExpanded)delete i.matricesIndices._isExpanded,r.setVerticesData(e.VertexBuffer.MatricesIndicesExtraKind,i.matricesIndicesExtra,i.matricesIndicesExtra._updatable);else{for(S=[],x=0;x<i.matricesIndicesExtra.length;x++){C=i.matricesIndicesExtra[x];S.push(255&C),S.push((65280&C)>>8),S.push((16711680&C)>>16),S.push(C>>24)}r.setVerticesData(e.VertexBuffer.MatricesIndicesExtraKind,S,i.matricesIndicesExtra._updatable)}i.matricesWeights&&(t._CleanMatricesWeights(i,r),r.setVerticesData(e.VertexBuffer.MatricesWeightsKind,i.matricesWeights,i.matricesWeights._updatable)),i.matricesWeightsExtra&&r.setVerticesData(e.VertexBuffer.MatricesWeightsExtraKind,i.matricesWeightsExtra,i.matricesWeights._updatable),r.setIndices(i.indices,null)}if(i.subMeshes){r.subMeshes=[];for(var R=0;R<i.subMeshes.length;R++){var O=i.subMeshes[R];e.SubMesh.AddToMesh(O.materialIndex,O.verticesStart,O.verticesCount,O.indexStart,O.indexCount,r)}}r._shouldGenerateFlatShading&&(r.convertToFlatShadedMesh(),delete r._shouldGenerateFlatShading),r.computeWorldMatrix(!0);var I=n.selectionOctree;void 0!==I&&null!==I&&I.addMesh(r)},t._CleanMatricesWeights=function(t,i){if(e.SceneLoader.CleanBoneMatrixWeights){var r=0;if(t.skeletonId>-1){var n=i.getScene().getLastSkeletonByID(t.skeletonId);if(n){r=n.bones.length;for(var o=i.getVerticesData(e.VertexBuffer.MatricesIndicesKind),s=i.getVerticesData(e.VertexBuffer.MatricesIndicesExtraKind),a=t.matricesWeights,h=t.matricesWeightsExtra,l=t.numBoneInfluencer,c=a.length,u=0;u<c;u+=4){for(var p=0,f=-1,d=0;d<4;d++){p+=m=a[u+d],m<.001&&f<0&&(f=d)}if(h)for(d=0;d<4;d++){var m;p+=m=h[u+d],m<.001&&f<0&&(f=d+4)}if((f<0||f>l-1)&&(f=l-1),p>.001){var g=1/p;for(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;var i=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 Y(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);e._PrimitiveGeometry=i;var r=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 Y(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}(i);e.RibbonGeometry=r;var n=function(t){function i(i,r,n,o,s,a){void 0===s&&(s=null),void 0===a&&(a=e.Mesh.DEFAULTSIDE);var h=t.call(this,i,r,o,s)||this;return h.size=n,h.side=a,h}return Y(i,t),i.prototype._regenerateVertexData=function(){return e.VertexData.CreateBox({size:this.size,sideOrientation:this.side})},i.prototype.copy=function(e){return new i(e,this.getScene(),this.size,this.canBeRegenerated(),void 0,this.side)},i.prototype.serialize=function(){var e=t.prototype.serialize.call(this);return e.size=this.size,e},i.Parse=function(t,r){if(r.getGeometryByID(t.id))return null;var n=new i(t.id,r,t.size,t.canBeRegenerated,null);return e.Tags&&e.Tags.AddTagsTo(n,t.tags),r.pushGeometry(n,!0),n},i}(i);e.BoxGeometry=n;var o=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.segments=n,l.diameter=o,l.side=h,l}return Y(i,t),i.prototype._regenerateVertexData=function(){return e.VertexData.CreateSphere({segments:this.segments,diameter:this.diameter,sideOrientation:this.side})},i.prototype.copy=function(e){return new i(e,this.getScene(),this.segments,this.diameter,this.canBeRegenerated(),null,this.side)},i.prototype.serialize=function(){var e=t.prototype.serialize.call(this);return e.segments=this.segments,e.diameter=this.diameter,e},i.Parse=function(t,r){if(r.getGeometryByID(t.id))return null;var n=new i(t.id,r,t.segments,t.diameter,t.canBeRegenerated,null);return e.Tags&&e.Tags.AddTagsTo(n,t.tags),r.pushGeometry(n,!0),n},i}(i);e.SphereGeometry=o;var s=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 Y(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}(i);e.DiscGeometry=s;var a=function(t){function i(i,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=t.call(this,i,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 Y(i,t),i.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})},i.prototype.copy=function(e){return new i(e,this.getScene(),this.height,this.diameterTop,this.diameterBottom,this.tessellation,this.subdivisions,this.canBeRegenerated(),null,this.side)},i.prototype.serialize=function(){var e=t.prototype.serialize.call(this);return e.height=this.height,e.diameterTop=this.diameterTop,e.diameterBottom=this.diameterBottom,e.tessellation=this.tessellation,e},i.Parse=function(t,r){if(r.getGeometryByID(t.id))return null;var n=new i(t.id,r,t.height,t.diameterTop,t.diameterBottom,t.tessellation,t.subdivisions,t.canBeRegenerated,null);return e.Tags&&e.Tags.AddTagsTo(n,t.tags),r.pushGeometry(n,!0),n},i}(i);e.CylinderGeometry=a;var h=function(t){function i(i,r,n,o,s,a,h,l){void 0===h&&(h=null),void 0===l&&(l=e.Mesh.DEFAULTSIDE);var c=t.call(this,i,r,a,h)||this;return c.diameter=n,c.thickness=o,c.tessellation=s,c.side=l,c}return Y(i,t),i.prototype._regenerateVertexData=function(){return e.VertexData.CreateTorus({diameter:this.diameter,thickness:this.thickness,tessellation:this.tessellation,sideOrientation:this.side})},i.prototype.copy=function(e){return new i(e,this.getScene(),this.diameter,this.thickness,this.tessellation,this.canBeRegenerated(),null,this.side)},i.prototype.serialize=function(){var e=t.prototype.serialize.call(this);return e.diameter=this.diameter,e.thickness=this.thickness,e.tessellation=this.tessellation,e},i.Parse=function(t,r){if(r.getGeometryByID(t.id))return null;var n=new i(t.id,r,t.diameter,t.thickness,t.tessellation,t.canBeRegenerated,null);return e.Tags&&e.Tags.AddTagsTo(n,t.tags),r.pushGeometry(n,!0),n},i}(i);e.TorusGeometry=h;var l=function(t){function i(e,i,r,n,o,s,a){void 0===a&&(a=null);var h=t.call(this,e,i,s,a)||this;return h.width=r,h.height=n,h.subdivisions=o,h}return Y(i,t),i.prototype._regenerateVertexData=function(){return e.VertexData.CreateGround({width:this.width,height:this.height,subdivisions:this.subdivisions})},i.prototype.copy=function(e){return new i(e,this.getScene(),this.width,this.height,this.subdivisions,this.canBeRegenerated(),null)},i.prototype.serialize=function(){var e=t.prototype.serialize.call(this);return e.width=this.width,e.height=this.height,e.subdivisions=this.subdivisions,e},i.Parse=function(t,r){if(r.getGeometryByID(t.id))return null;var n=new i(t.id,r,t.width,t.height,t.subdivisions,t.canBeRegenerated,null);return e.Tags&&e.Tags.AddTagsTo(n,t.tags),r.pushGeometry(n,!0),n},i}(i);e.GroundGeometry=l;var c=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 Y(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}(i);e.TiledGroundGeometry=c;var u=function(t){function i(i,r,n,o,s,a){void 0===s&&(s=null),void 0===a&&(a=e.Mesh.DEFAULTSIDE);var h=t.call(this,i,r,o,s)||this;return h.size=n,h.side=a,h}return Y(i,t),i.prototype._regenerateVertexData=function(){return e.VertexData.CreatePlane({size:this.size,sideOrientation:this.side})},i.prototype.copy=function(e){return new i(e,this.getScene(),this.size,this.canBeRegenerated(),null,this.side)},i.prototype.serialize=function(){var e=t.prototype.serialize.call(this);return e.size=this.size,e},i.Parse=function(t,r){if(r.getGeometryByID(t.id))return null;var n=new i(t.id,r,t.size,t.canBeRegenerated,null);return e.Tags&&e.Tags.AddTagsTo(n,t.tags),r.pushGeometry(n,!0),n},i}(i);e.PlaneGeometry=u;var p=function(t){function i(i,r,n,o,s,a,h,l,c,u,p){void 0===u&&(u=null),void 0===p&&(p=e.Mesh.DEFAULTSIDE);var f=t.call(this,i,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 Y(i,t),i.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})},i.prototype.copy=function(e){return new i(e,this.getScene(),this.radius,this.tube,this.radialSegments,this.tubularSegments,this.p,this.q,this.canBeRegenerated(),null,this.side)},i.prototype.serialize=function(){var e=t.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},i.Parse=function(t,r){if(r.getGeometryByID(t.id))return null;var n=new i(t.id,r,t.radius,t.tube,t.radialSegments,t.tubularSegments,t.p,t.q,t.canBeRegenerated,null);return e.Tags&&e.Tags.AddTagsTo(n,t.tags),r.pushGeometry(n,!0),n},i}(i);e.TorusKnotGeometry=p}(us||(us={})),J=us||(us={}),$=function(){function e(e){this._vertexBuffers={},this._scene=e}return e.prototype._prepareBuffers=function(){if(!this._vertexBuffers[J.VertexBuffer.PositionKind]){var e=[];e.push(1,1),e.push(-1,1),e.push(-1,-1),e.push(1,-1),this._vertexBuffers[J.VertexBuffer.PositionKind]=new J.VertexBuffer(this._scene.getEngine(),e,J.VertexBuffer.PositionKind,!1,!1,2),this._buildIndexBuffer()}},e.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)},e.prototype._rebuild=function(){var e=this._vertexBuffers[J.VertexBuffer.PositionKind];e&&(e._rebuild(),this._buildIndexBuffer())},e.prototype._prepareFrame=function(e,t){void 0===e&&(e=null),void 0===t&&(t=null);var i=this._scene.activeCamera;return!!i&&(!(!(t=t||i._postProcesses)||0===t.length||!this._scene.postProcessesEnabled)&&(t[0].activate(i,e,null!==t&&void 0!==t),!0))},e.prototype.directRender=function(e,t,i){void 0===t&&(t=null),void 0===i&&(i=!1);for(var r=this._scene.getEngine(),n=0;n<e.length;n++){n<e.length-1?e[n+1].activate(this._scene.activeCamera,t):t?r.bindFramebuffer(t,0,void 0,void 0,i):r.restoreDefaultFramebuffer();var o=e[n],s=o.apply();s&&(o.onBeforeRenderObservable.notifyObservers(s),this._prepareBuffers(),r.bindBuffers(this._vertexBuffers,this._indexBuffer,s),r.drawElementsType(J.Material.TriangleFillMode,0,6),o.onAfterRenderObservable.notifyObservers(s))}r.setDepthBuffer(!0),r.setDepthWrite(!0)},e.prototype._finalizeFrame=function(e,t,i,r,n){void 0===n&&(n=!1);var o=this._scene.activeCamera;if(o&&0!==(r=r||o._postProcesses).length&&this._scene.postProcessesEnabled){for(var s=this._scene.getEngine(),a=0,h=r.length;a<h&&(a<h-1?r[a+1].activate(o,t):t?s.bindFramebuffer(t,i,void 0,void 0,n):s.restoreDefaultFramebuffer(),!e);a++){var l=r[a],c=l.apply();c&&(l.onBeforeRenderObservable.notifyObservers(c),this._prepareBuffers(),s.bindBuffers(this._vertexBuffers,this._indexBuffer,c),s.drawElementsType(J.Material.TriangleFillMode,0,6),l.onAfterRenderObservable.notifyObservers(c))}s.setDepthBuffer(!0),s.setDepthWrite(!0),s.setAlphaMode(J.Engine.ALPHA_DISABLE)}},e.prototype.dispose=function(){var e=this._vertexBuffers[J.VertexBuffer.PositionKind];e&&(e.dispose(),this._vertexBuffers[J.VertexBuffer.PositionKind]=null),this._indexBuffer&&(this._scene.getEngine()._releaseBuffer(this._indexBuffer),this._indexBuffer=null)},e}(),J.PostProcessManager=$,function(e){var t=function(){function t(e){void 0===e&&(e=30),this._enabled=!0,this._rollingFrameTime=new i(e)}return t.prototype.sampleFrame=function(t){if(void 0===t&&(t=e.Tools.Now),this._enabled){if(null!=this._lastFrameTimeMs){var i=t-this._lastFrameTimeMs;this._rollingFrameTime.add(i)}this._lastFrameTimeMs=t}},Object.defineProperty(t.prototype,"averageFrameTime",{get:function(){return this._rollingFrameTime.average},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"averageFrameTimeVariance",{get:function(){return this._rollingFrameTime.variance},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"instantaneousFrameTime",{get:function(){return this._rollingFrameTime.history(0)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"averageFPS",{get:function(){return 1e3/this._rollingFrameTime.average},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"instantaneousFPS",{get:function(){var e=this._rollingFrameTime.history(0);return 0===e?0:1e3/e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isSaturated",{get:function(){return this._rollingFrameTime.isSaturated()},enumerable:!0,configurable:!0}),t.prototype.enable=function(){this._enabled=!0},t.prototype.disable=function(){this._enabled=!1,this._lastFrameTimeMs=null},Object.defineProperty(t.prototype,"isEnabled",{get:function(){return this._enabled},enumerable:!0,configurable:!0}),t.prototype.reset=function(){this._lastFrameTimeMs=null,this._rollingFrameTime.reset()},t}();e.PerformanceMonitor=t;var i=function(){function e(e){this._samples=new Array(e),this.reset()}return e.prototype.add=function(e){var t;if(this.isSaturated()){var i=this._samples[this._pos];t=i-this.average,this.average-=t/(this._sampleCount-1),this._m2-=t*(i-this.average)}else this._sampleCount++;t=e-this.average,this.average+=t/this._sampleCount,this._m2+=t*(e-this.average),this.variance=this._m2/(this._sampleCount-1),this._samples[this._pos]=e,this._pos++,this._pos%=this._samples.length},e.prototype.history=function(e){if(e>=this._sampleCount||e>=this._samples.length)return 0;var t=this._wrapPosition(this._pos-1);return this._samples[this._wrapPosition(t-e)]},e.prototype.isSaturated=function(){return this._sampleCount>=this._samples.length},e.prototype.reset=function(){this.average=0,this.variance=0,this._sampleCount=0,this._pos=0,this._m2=0},e.prototype._wrapPosition=function(e){var t=this._samples.length;return(e%t+t)%t},e}();e.RollingAverage=i}(us||(us={})),ee=us||(us={}),te=function(){function e(){this.colorCurves=new ee.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 ee.Color4(0,0,0,0),this.vignetteCameraFov=.5,this._vignetteBlendMode=e.VIGNETTEMODE_MULTIPLY,this._vignetteEnabled=!1,this._applyByPostProcess=!1,this._isEnabled=!0,this.onUpdateParameters=new ee.Observable}return Object.defineProperty(e.prototype,"colorCurvesEnabled",{get:function(){return this._colorCurvesEnabled},set:function(e){this._colorCurvesEnabled!==e&&(this._colorCurvesEnabled=e,this._updateParameters())},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"colorGradingEnabled",{get:function(){return this._colorGradingEnabled},set:function(e){this._colorGradingEnabled!==e&&(this._colorGradingEnabled=e,this._updateParameters())},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"colorGradingWithGreenDepth",{get:function(){return this._colorGradingWithGreenDepth},set:function(e){this._colorGradingWithGreenDepth!==e&&(this._colorGradingWithGreenDepth=e,this._updateParameters())},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"colorGradingBGR",{get:function(){return this._colorGradingBGR},set:function(e){this._colorGradingBGR!==e&&(this._colorGradingBGR=e,this._updateParameters())},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"exposure",{get:function(){return this._exposure},set:function(e){this._exposure!==e&&(this._exposure=e,this._updateParameters())},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"toneMappingEnabled",{get:function(){return this._toneMappingEnabled},set:function(e){this._toneMappingEnabled!==e&&(this._toneMappingEnabled=e,this._updateParameters())},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"contrast",{get:function(){return this._contrast},set:function(e){this._contrast!==e&&(this._contrast=e,this._updateParameters())},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"vignetteBlendMode",{get:function(){return this._vignetteBlendMode},set:function(e){this._vignetteBlendMode!==e&&(this._vignetteBlendMode=e,this._updateParameters())},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"vignetteEnabled",{get:function(){return this._vignetteEnabled},set:function(e){this._vignetteEnabled!==e&&(this._vignetteEnabled=e,this._updateParameters())},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"applyByPostProcess",{get:function(){return this._applyByPostProcess},set:function(e){this._applyByPostProcess!==e&&(this._applyByPostProcess=e,this._updateParameters())},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isEnabled",{get:function(){return this._isEnabled},set:function(e){this._isEnabled!==e&&(this._isEnabled=e,this._updateParameters())},enumerable:!0,configurable:!0}),e.prototype._updateParameters=function(){this.onUpdateParameters.notifyObservers(this)},e.prototype.getClassName=function(){return"ImageProcessingConfiguration"},e.PrepareUniforms=function(e,t){t.EXPOSURE&&e.push("exposureLinear"),t.CONTRAST&&e.push("contrast"),t.COLORGRADING&&e.push("colorTransformSettings"),t.VIGNETTE&&(e.push("vInverseScreenSize"),e.push("vignetteSettings1"),e.push("vignetteSettings2")),t.COLORCURVES&&ee.ColorCurves.PrepareUniforms(e)},e.PrepareSamplers=function(e,t){t.COLORGRADING&&e.push("txColorTransform")},e.prototype.prepareDefines=function(t,i){if(void 0===i&&(i=!1),i!==this.applyByPostProcess||!this._isEnabled)return t.VIGNETTE=!1,t.TONEMAPPING=!1,t.CONTRAST=!1,t.EXPOSURE=!1,t.COLORCURVES=!1,t.COLORGRADING=!1,t.COLORGRADING3D=!1,t.IMAGEPROCESSING=!1,void(t.IMAGEPROCESSINGPOSTPROCESS=this.applyByPostProcess&&this._isEnabled);t.VIGNETTE=this.vignetteEnabled,t.VIGNETTEBLENDMODEMULTIPLY=this.vignetteBlendMode===e._VIGNETTEMODE_MULTIPLY,t.VIGNETTEBLENDMODEOPAQUE=!t.VIGNETTEBLENDMODEMULTIPLY,t.TONEMAPPING=this.toneMappingEnabled,t.CONTRAST=1!==this.contrast,t.EXPOSURE=1!==this.exposure,t.COLORCURVES=this.colorCurvesEnabled&&!!this.colorCurves,t.COLORGRADING=this.colorGradingEnabled&&!!this.colorGradingTexture,t.COLORGRADING?t.COLORGRADING3D=this.colorGradingTexture.is3D:t.COLORGRADING3D=!1,t.SAMPLER3DGREENDEPTH=this.colorGradingWithGreenDepth,t.SAMPLER3DBGRMAP=this.colorGradingBGR,t.IMAGEPROCESSINGPOSTPROCESS=this.applyByPostProcess,t.IMAGEPROCESSING=t.VIGNETTE||t.TONEMAPPING||t.CONTRAST||t.EXPOSURE||t.COLORCURVES||t.COLORGRADING},e.prototype.isReady=function(){return!this.colorGradingEnabled||!this.colorGradingTexture||this.colorGradingTexture.isReady()},e.prototype.bind=function(e,t){if(void 0===t&&(t=1),this._colorCurvesEnabled&&this.colorCurves&&ee.ColorCurves.Bind(this.colorCurves,e),this._vignetteEnabled){var i=1/e.getEngine().getRenderWidth(),r=1/e.getEngine().getRenderHeight();e.setFloat2("vInverseScreenSize",i,r);var n=Math.tan(.5*this.vignetteCameraFov),o=n*t,s=Math.sqrt(o*n);o=ee.Tools.Mix(o,s,this.vignetteStretch),n=ee.Tools.Mix(n,s,this.vignetteStretch),e.setFloat4("vignetteSettings1",o,n,-o*this.vignetteCentreX,-n*this.vignetteCentreY);var a=-2*this.vignetteWeight;e.setFloat4("vignetteSettings2",this.vignetteColor.r,this.vignetteColor.g,this.vignetteColor.b,a)}if(e.setFloat("exposureLinear",this.exposure),e.setFloat("contrast",this.contrast),this.colorGradingTexture){e.setTexture("txColorTransform",this.colorGradingTexture);var h=this.colorGradingTexture.getSize().height;e.setFloat4("colorTransformSettings",(h-1)/h,.5/h,h,this.colorGradingTexture.level)}},e.prototype.clone=function(){return ee.SerializationHelper.Clone(function(){return new e},this)},e.prototype.serialize=function(){return ee.SerializationHelper.Serialize(this)},e.Parse=function(t){return ee.SerializationHelper.Parse(function(){return new e},t,null,null)},Object.defineProperty(e,"VIGNETTEMODE_MULTIPLY",{get:function(){return this._VIGNETTEMODE_MULTIPLY},enumerable:!0,configurable:!0}),Object.defineProperty(e,"VIGNETTEMODE_OPAQUE",{get:function(){return this._VIGNETTEMODE_OPAQUE},enumerable:!0,configurable:!0}),e._VIGNETTEMODE_MULTIPLY=0,e._VIGNETTEMODE_OPAQUE=1,X([ee.serializeAsColorCurves()],e.prototype,"colorCurves",void 0),X([ee.serialize()],e.prototype,"_colorCurvesEnabled",void 0),X([ee.serializeAsTexture()],e.prototype,"colorGradingTexture",void 0),X([ee.serialize()],e.prototype,"_colorGradingEnabled",void 0),X([ee.serialize()],e.prototype,"_colorGradingWithGreenDepth",void 0),X([ee.serialize()],e.prototype,"_colorGradingBGR",void 0),X([ee.serialize()],e.prototype,"_exposure",void 0),X([ee.serialize()],e.prototype,"_toneMappingEnabled",void 0),X([ee.serialize()],e.prototype,"_contrast",void 0),X([ee.serialize()],e.prototype,"vignetteStretch",void 0),X([ee.serialize()],e.prototype,"vignetteCentreX",void 0),X([ee.serialize()],e.prototype,"vignetteCentreY",void 0),X([ee.serialize()],e.prototype,"vignetteWeight",void 0),X([ee.serializeAsColor4()],e.prototype,"vignetteColor",void 0),X([ee.serialize()],e.prototype,"vignetteCameraFov",void 0),X([ee.serialize()],e.prototype,"_vignetteBlendMode",void 0),X([ee.serialize()],e.prototype,"_vignetteEnabled",void 0),X([ee.serialize()],e.prototype,"_applyByPostProcess",void 0),X([ee.serialize()],e.prototype,"_isEnabled",void 0),e}(),ee.ImageProcessingConfiguration=te,ie=us||(us={}),re=function(e){function t(t,i){var r=e.call(this,i)||this;return t?(r._engine=i.getEngine(),r._textureMatrix=ie.Matrix.Identity(),r.name=t,r.url=t,r.hasAlpha=!1,r.isCube=!1,r.is3D=r._engine.webGLVersion>1,r.wrapU=ie.Texture.CLAMP_ADDRESSMODE,r.wrapV=ie.Texture.CLAMP_ADDRESSMODE,r.wrapR=ie.Texture.CLAMP_ADDRESSMODE,r.anisotropicFilteringLevel=1,r._texture=r._getFromCache(t,!0),r._texture||(i.useDelayedTextureLoading?r.delayLoadState=ie.Engine.DELAYLOADSTATE_NOTLOADED:r.loadTexture()),r):r}return Y(t,e),t.prototype.getTextureMatrix=function(){return this._textureMatrix},t.prototype.load3dlTexture=function(){var e,i=this._engine;e=1===i.webGLVersion?i.createRawTexture(null,1,1,ie.Engine.TEXTUREFORMAT_RGBA,!1,!1,ie.Texture.BILINEAR_SAMPLINGMODE):i.createRawTexture3D(null,1,1,1,ie.Engine.TEXTUREFORMAT_RGBA,!1,!1,ie.Texture.BILINEAR_SAMPLINGMODE),this._texture=e;var r=function(r){if("string"==typeof r){for(var n,o=null,s=null,a=r.split("\n"),h=0,l=0,c=0,u=0,p=0,f=0;f<a.length;f++)if(n=a[f],t._noneEmptyLineRegex.test(n)&&0!==n.indexOf("#")){var d=n.split(" ");if(0!==h){if(0!=h){var m=Math.max(parseInt(d[0]),0),g=Math.max(parseInt(d[1]),0),_=Math.max(parseInt(d[2]),0);p=Math.max(m,p),p=Math.max(g,p),p=Math.max(_,p);var v=4*(l+u*h+c*h*h);s&&(s[v+0]=m,s[v+1]=g,s[v+2]=_),++u%h==0&&(u=0,++c%h==0&&(l++,c=0))}}else h=d.length,o=new Uint8Array(h*h*h*4),s=new Float32Array(h*h*h*4)}if(s&&o)for(f=0;f<s.length;f++)if(f>0&&(f+1)%4==0)o[f]=255;else{var y=s[f];o[f]=y/p*255}e.is3D?(e.updateSize(h,h,h),i.updateRawTexture3D(e,o,ie.Engine.TEXTUREFORMAT_RGBA,!1)):(e.updateSize(h*h,h),i.updateRawTexture(e,o,ie.Engine.TEXTUREFORMAT_RGBA,!1))}},n=this.getScene();return n?n._loadFile(this.url,r):this._engine._loadFile(this.url,r),this._texture},t.prototype.loadTexture=function(){this.url&&this.url.toLocaleLowerCase().indexOf(".3dl")==this.url.length-4&&this.load3dlTexture()},t.prototype.clone=function(){var e=new t(this.url,this.getScene());return e.level=this.level,e},t.prototype.delayLoad=function(){this.delayLoadState===ie.Engine.DELAYLOADSTATE_NOTLOADED&&(this.delayLoadState=ie.Engine.DELAYLOADSTATE_LOADED,this._texture=this._getFromCache(this.url,!0),this._texture||this.loadTexture())},t.Parse=function(e,i,r){var n=null;return e.name&&!e.isRenderTarget&&((n=new t(e.name,i)).name=e.name,n.level=e.level),n},t.prototype.serialize=function(){if(!this.name)return null;var e={};return e.name=this.name,e.level=this.level,e.customType="BABYLON.ColorGradingTexture",e},t._noneEmptyLineRegex=/\S+/,t}(ie.BaseTexture),ie.ColorGradingTexture=re,ne=us||(us={}),oe=function(){function e(){this._dirty=!0,this._tempColor=new ne.Color4(0,0,0,0),this._globalCurve=new ne.Color4(0,0,0,0),this._highlightsCurve=new ne.Color4(0,0,0,0),this._midtonesCurve=new ne.Color4(0,0,0,0),this._shadowsCurve=new ne.Color4(0,0,0,0),this._positiveCurve=new ne.Color4(0,0,0,0),this._negativeCurve=new ne.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(e.prototype,"globalHue",{get:function(){return this._globalHue},set:function(e){this._globalHue=e,this._dirty=!0},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"globalDensity",{get:function(){return this._globalDensity},set:function(e){this._globalDensity=e,this._dirty=!0},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"globalSaturation",{get:function(){return this._globalSaturation},set:function(e){this._globalSaturation=e,this._dirty=!0},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"highlightsHue",{get:function(){return this._highlightsHue},set:function(e){this._highlightsHue=e,this._dirty=!0},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"highlightsDensity",{get:function(){return this._highlightsDensity},set:function(e){this._highlightsDensity=e,this._dirty=!0},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"highlightsSaturation",{get:function(){return this._highlightsSaturation},set:function(e){this._highlightsSaturation=e,this._dirty=!0},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"highlightsExposure",{get:function(){return this._highlightsExposure},set:function(e){this._highlightsExposure=e,this._dirty=!0},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"midtonesHue",{get:function(){return this._midtonesHue},set:function(e){this._midtonesHue=e,this._dirty=!0},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"midtonesDensity",{get:function(){return this._midtonesDensity},set:function(e){this._midtonesDensity=e,this._dirty=!0},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"midtonesSaturation",{get:function(){return this._midtonesSaturation},set:function(e){this._midtonesSaturation=e,this._dirty=!0},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"midtonesExposure",{get:function(){return this._midtonesExposure},set:function(e){this._midtonesExposure=e,this._dirty=!0},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"shadowsHue",{get:function(){return this._shadowsHue},set:function(e){this._shadowsHue=e,this._dirty=!0},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"shadowsDensity",{get:function(){return this._shadowsDensity},set:function(e){this._shadowsDensity=e,this._dirty=!0},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"shadowsSaturation",{get:function(){return this._shadowsSaturation},set:function(e){this._shadowsSaturation=e,this._dirty=!0},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"shadowsExposure",{get:function(){return this._shadowsExposure},set:function(e){this._shadowsExposure=e,this._dirty=!0},enumerable:!0,configurable:!0}),e.prototype.getClassName=function(){return"ColorCurves"},e.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))},e.PrepareUniforms=function(e){e.push("vCameraColorCurveNeutral","vCameraColorCurvePositive","vCameraColorCurveNegative")},e.prototype.getColorGradingDataToRef=function(t,i,r,n,o){null!=t&&(t=e.clamp(t,0,360),i=e.clamp(i,-100,100),r=e.clamp(r,-100,100),n=e.clamp(n,-100,100),i=e.applyColorGradingSliderNonlinear(i),i*=.5,n=e.applyColorGradingSliderNonlinear(n),i<0&&(i*=-1,t=(t+180)%360),e.fromHSBToRef(t,i,50+.25*n,o),o.scaleToRef(2,o),o.a=1+.01*r)},e.applyColorGradingSliderNonlinear=function(e){e/=100;var t=Math.abs(e);return t=Math.pow(t,2),e<0&&(t*=-1),t*=100},e.fromHSBToRef=function(t,i,r,n){var o=e.clamp(t,0,360),s=e.clamp(i/100,0,1),a=e.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},e.clamp=function(e,t,i){return Math.min(Math.max(e,t),i)},e.prototype.clone=function(){return ne.SerializationHelper.Clone(function(){return new e},this)},e.prototype.serialize=function(){return ne.SerializationHelper.Serialize(this)},e.Parse=function(t){return ne.SerializationHelper.Parse(function(){return new e},t,null,null)},X([ne.serialize()],e.prototype,"_globalHue",void 0),X([ne.serialize()],e.prototype,"_globalDensity",void 0),X([ne.serialize()],e.prototype,"_globalSaturation",void 0),X([ne.serialize()],e.prototype,"_globalExposure",void 0),X([ne.serialize()],e.prototype,"_highlightsHue",void 0),X([ne.serialize()],e.prototype,"_highlightsDensity",void 0),X([ne.serialize()],e.prototype,"_highlightsSaturation",void 0),X([ne.serialize()],e.prototype,"_highlightsExposure",void 0),X([ne.serialize()],e.prototype,"_midtonesHue",void 0),X([ne.serialize()],e.prototype,"_midtonesDensity",void 0),X([ne.serialize()],e.prototype,"_midtonesSaturation",void 0),X([ne.serialize()],e.prototype,"_midtonesExposure",void 0),e}(),ne.ColorCurves=oe,se=us||(us={}),ae=function(){function e(){}return e.BindEyePosition=function(e,t){t._forcedViewPosition?e.setVector3("vEyePosition",t._forcedViewPosition):e.setVector3("vEyePosition",t._mirroredCameraPosition?t._mirroredCameraPosition:t.activeCamera.globalPosition)},e.PrepareDefinesForMergedUV=function(e,t,i){t._needUVs=!0,t[i]=!0,e.getTextureMatrix().isIdentity(!0)?(t[i+"DIRECTUV"]=e.coordinatesIndex+1,0===e.coordinatesIndex?t.MAINUV1=!0:t.MAINUV2=!0):t[i+"DIRECTUV"]=0},e.BindTextureMatrix=function(e,t,i){var r=e.getTextureMatrix();r.isIdentity(!0)||t.updateMatrix(i+"Matrix",r)},e.PrepareDefinesForMisc=function(e,t,i,r,n,o){o._areMiscDirty&&(o.LOGARITHMICDEPTH=i,o.POINTSIZE=r||t.forcePointsCloud,o.FOG=t.fogEnabled&&e.applyFog&&t.fogMode!==se.Scene.FOGMODE_NONE&&n,o.NONUNIFORMSCALING=e.nonUniformScaling)},e.PrepareDefinesForFrameBoundValues=function(e,t,i,r,n){void 0===n&&(n=!1);var o=!1;i.CLIPPLANE!==(void 0!==e.clipPlane&&null!==e.clipPlane)&&(i.CLIPPLANE=!i.CLIPPLANE,o=!0),i.ALPHATEST!==(t.getAlphaTesting()||n)&&(i.ALPHATEST=!i.ALPHATEST,o=!0),i.DEPTHPREPASS!==!t.getColorWrite()&&(i.DEPTHPREPASS=!i.DEPTHPREPASS,o=!0),i.INSTANCES!==r&&(i.INSTANCES=r,o=!0),o&&i.markAsUnprocessed()},e.PrepareDefinesForAttributes=function(e,t,i,r,n,o){if(void 0===n&&(n=!1),void 0===o&&(o=!0),!t._areAttributesDirty&&t._needNormals===t._normals&&t._needUVs===t._uvs)return!1;if(t._normals=t._needNormals,t._uvs=t._needUVs,t.NORMAL=t._needNormals&&e.isVerticesDataPresent(se.VertexBuffer.NormalKind),t._needNormals&&e.isVerticesDataPresent(se.VertexBuffer.TangentKind)&&(t.TANGENT=!0),t._needUVs?(t.UV1=e.isVerticesDataPresent(se.VertexBuffer.UVKind),t.UV2=e.isVerticesDataPresent(se.VertexBuffer.UV2Kind)):(t.UV1=!1,t.UV2=!1),i){var s=e.useVertexColors&&e.isVerticesDataPresent(se.VertexBuffer.ColorKind);t.VERTEXCOLOR=s,t.VERTEXALPHA=e.hasVertexAlpha&&s&&o}if(r&&(e.useBones&&e.computeBonesUsingShaders&&e.skeleton?(t.NUM_BONE_INFLUENCERS=e.numBoneInfluencers,t.BonesPerMesh=e.skeleton.bones.length+1):(t.NUM_BONE_INFLUENCERS=0,t.BonesPerMesh=0)),n){var a=e.morphTargetManager;a?(t.MORPHTARGETS_TANGENT=a.supportsTangents&&t.TANGENT,t.MORPHTARGETS_NORMAL=a.supportsNormals&&t.NORMAL,t.MORPHTARGETS=a.numInfluencers>0,t.NUM_MORPH_INFLUENCERS=a.numInfluencers):(t.MORPHTARGETS_TANGENT=!1,t.MORPHTARGETS_NORMAL=!1,t.MORPHTARGETS=!1,t.NUM_MORPH_INFLUENCERS=0)}return!0},e.PrepareDefinesForLights=function(e,t,i,r,n,o){if(void 0===n&&(n=4),void 0===o&&(o=!1),!i._areLightsDirty)return i._needNormals;var s=0,a=!1,h=!1,l=!1,c=!1,u=!1;if(e.lightsEnabled&&!o)for(var p=0,f=t._lightSources;p<f.length;p++){var d=f[p];if(a=!0,void 0===i["LIGHT"+s]&&(h=!0),i["LIGHT"+s]=!0,i["SPOTLIGHT"+s]=!1,i["HEMILIGHT"+s]=!1,i["POINTLIGHT"+s]=!1,i["DIRLIGHT"+s]=!1,i[d.getTypeID()===se.Light.LIGHTTYPEID_SPOTLIGHT?"SPOTLIGHT"+s:d.getTypeID()===se.Light.LIGHTTYPEID_HEMISPHERICLIGHT?"HEMILIGHT"+s:d.getTypeID()===se.Light.LIGHTTYPEID_POINTLIGHT?"POINTLIGHT"+s:"DIRLIGHT"+s]=!0,r&&!d.specular.equalsFloats(0,0,0)&&(u=!0),i["SHADOW"+s]=!1,i["SHADOWPCF"+s]=!1,i["SHADOWESM"+s]=!1,i["SHADOWCUBE"+s]=!1,t&&t.receiveShadows&&e.shadowsEnabled&&d.shadowEnabled){var m=d.getShadowGenerator();m&&(c=!0,m.prepareDefines(i,s))}if(d.lightmapMode!=se.Light.LIGHTMAP_DEFAULT?(l=!0,i["LIGHTMAPEXCLUDED"+s]=!0,i["LIGHTMAPNOSPECULAR"+s]=d.lightmapMode==se.Light.LIGHTMAP_SHADOWSONLY):(i["LIGHTMAPEXCLUDED"+s]=!1,i["LIGHTMAPNOSPECULAR"+s]=!1),++s===n)break}i.SPECULARTERM=u,i.SHADOWS=c;for(var g=s;g<n;g++)void 0!==i["LIGHT"+g]&&(i["LIGHT"+g]=!1,i["HEMILIGHT"+s]=!1,i["POINTLIGHT"+s]=!1,i["DIRLIGHT"+s]=!1,i["SPOTLIGHT"+s]=!1,i["SHADOW"+s]=!1);var _=e.getEngine().getCaps();return void 0===i.SHADOWFLOAT&&(h=!0),i.SHADOWFLOAT=c&&(_.textureFloatRender&&_.textureFloatLinearFiltering||_.textureHalfFloatRender&&_.textureHalfFloatLinearFiltering),i.LIGHTMAPEXCLUDED=l,h&&i.rebuild(),a},e.PrepareUniformsAndSamplersList=function(e,t,i,r){var n;void 0===r&&(r=4);var o=null;if(e.uniformsNames){var s=e;n=s.uniformsNames,o=s.uniformBuffersNames,t=s.samplers,i=s.defines,r=s.maxSimultaneousLights}else n=e,t||(t=[]);for(var a=0;a<r&&i["LIGHT"+a];a++)n.push("vLightData"+a,"vLightDiffuse"+a,"vLightSpecular"+a,"vLightDirection"+a,"vLightGround"+a,"lightMatrix"+a,"shadowsInfo"+a,"depthValues"+a),o&&o.push("Light"+a),t.push("shadowSampler"+a);i.NUM_MORPH_INFLUENCERS&&n.push("morphTargetInfluences")},e.HandleFallbacksForShadows=function(e,t,i,r){void 0===i&&(i=4),void 0===r&&(r=0);for(var n=0,o=0;o<i&&e["LIGHT"+o];o++)o>0&&(n=r+o,t.addFallback(n,"LIGHT"+o)),e.SHADOWS||(e["SHADOW"+o]&&t.addFallback(r,"SHADOW"+o),e["SHADOWPCF"+o]&&t.addFallback(r,"SHADOWPCF"+o),e["SHADOWESM"+o]&&t.addFallback(r,"SHADOWESM"+o));return n++},e.PrepareAttributesForMorphTargets=function(e,t,i){var r=i.NUM_MORPH_INFLUENCERS;if(r>0&&se.Engine.LastCreatedEngine)for(var n=se.Engine.LastCreatedEngine.getCaps().maxVertexAttribs,o=t.morphTargetManager,s=o&&o.supportsNormals&&i.NORMAL,a=o&&o.supportsTangents&&i.TANGENT,h=0;h<r;h++)e.push(se.VertexBuffer.PositionKind+h),s&&e.push(se.VertexBuffer.NormalKind+h),a&&e.push(se.VertexBuffer.TangentKind+h),e.length>n&&se.Tools.Error("Cannot add more vertex attributes for mesh "+t.name)},e.PrepareAttributesForBones=function(e,t,i,r){i.NUM_BONE_INFLUENCERS>0&&(r.addCPUSkinningFallback(0,t),e.push(se.VertexBuffer.MatricesIndicesKind),e.push(se.VertexBuffer.MatricesWeightsKind),i.NUM_BONE_INFLUENCERS>4&&(e.push(se.VertexBuffer.MatricesIndicesExtraKind),e.push(se.VertexBuffer.MatricesWeightsExtraKind)))},e.PrepareAttributesForInstances=function(e,t){t.INSTANCES&&(e.push("world0"),e.push("world1"),e.push("world2"),e.push("world3"))},e.BindLightShadow=function(e,t,i,r,n){if(e.shadowEnabled&&i.receiveShadows){var o=e.getShadowGenerator();o&&o.bindShadowLight(r,n)}},e.BindLightProperties=function(e,t,i){e.transferToEffect(t,i+"")},e.BindLights=function(t,i,r,n,o,s){void 0===o&&(o=4),void 0===s&&(s=!1);for(var a=Math.min(i._lightSources.length,o),h=0;h<a;h++){var l=i._lightSources[h],c=h.toString(),u=l.getScaledIntensity();l._uniformBuffer.bindToEffect(r,"Light"+h),e.BindLightProperties(l,r,h),l.diffuse.scaleToRef(u,se.Tmp.Color3[0]),l._uniformBuffer.updateColor4("vLightDiffuse",se.Tmp.Color3[0],s?l.radius:l.range,c),n.SPECULARTERM&&(l.specular.scaleToRef(u,se.Tmp.Color3[1]),l._uniformBuffer.updateColor3("vLightSpecular",se.Tmp.Color3[1],c)),t.shadowsEnabled&&this.BindLightShadow(l,t,i,c,r),l._uniformBuffer.update()}},e.BindFogParameters=function(e,t,i){e.fogEnabled&&t.applyFog&&e.fogMode!==se.Scene.FOGMODE_NONE&&(i.setFloat4("vFogInfos",e.fogMode,e.fogStart,e.fogEnd,e.fogDensity),i.setColor3("vFogColor",e.fogColor))},e.BindBonesParameters=function(e,t){if(e&&e.useBones&&e.computeBonesUsingShaders&&e.skeleton){var i=e.skeleton.getTransformMatrices(e);i&&t&&t.setMatrices("mBones",i)}},e.BindMorphTargetParameters=function(e,t){var i=e.morphTargetManager;e&&i&&t.setFloatArray("morphTargetInfluences",i.influences)},e.BindLogDepth=function(e,t,i){e.LOGARITHMICDEPTH&&t.setFloat("logarithmicDepthConstant",2/(Math.log(i.activeCamera.maxZ+1)/Math.LN2))},e.BindClipPlane=function(e,t){if(t.clipPlane){var i=t.clipPlane;e.setFloat4("vClipPlane",i.normal.x,i.normal.y,i.normal.z,i.d)}},e}(),se.MaterialHelper=ae,he=us||(us={}),le=function(e){function t(t,i){var r=e.call(this,t,i)||this;return r.storeEffectOnSubMeshes=!0,r}return Y(t,e),t.prototype.getEffect=function(){return this._activeEffect},t.prototype.isReady=function(e,t){return!!e&&(!e.subMeshes||0===e.subMeshes.length||this.isReadyForSubMesh(e,e.subMeshes[0],t))},t.prototype.bindOnlyWorldMatrix=function(e){this._activeEffect.setMatrix("world",e)},t.prototype.bind=function(e,t){t&&this.bindForSubMesh(e,t,t.subMeshes[0])},t.prototype._afterBind=function(t,i){void 0===i&&(i=null),e.prototype._afterBind.call(this,t),this.getScene()._cachedEffect=i},t.prototype._mustRebind=function(e,t,i){return void 0===i&&(i=1),e.isCachedMaterialInvalid(this,t,i)},t}(he.Material),he.PushMaterial=le,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 Y(t,e),t.prototype.setReflectionMode=function(e){for(var t=0,i=["REFLECTIONMAP_CUBIC","REFLECTIONMAP_EXPLICIT","REFLECTIONMAP_PLANAR","REFLECTIONMAP_PROJECTION","REFLECTIONMAP_PROJECTION","REFLECTIONMAP_SKYBOX","REFLECTIONMAP_SPHERICAL","REFLECTIONMAP_EQUIRECTANGULAR","REFLECTIONMAP_EQUIRECTANGULAR_FIXED","REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED"];t<i.length;t++){var r=i[t];this[r]=r===e}},t}(e.MaterialDefines);e.StandardMaterialDefines=t;var i=function(i){function r(t,n){var o=i.call(this,t,n)||this;return o.ambientColor=new e.Color3(0,0,0),o.diffuseColor=new e.Color3(1,1,1),o.specularColor=new e.Color3(1,1,1),o.emissiveColor=new e.Color3(0,0,0),o.specularPower=64,o._useAlphaFromDiffuseTexture=!1,o._useEmissiveAsIllumination=!1,o._linkEmissiveWithDiffuse=!1,o._useSpecularOverAlpha=!1,o._useReflectionOverAlpha=!1,o._disableLighting=!1,o._useParallax=!1,o._useParallaxOcclusion=!1,o.parallaxScaleBias=.05,o._roughness=0,o.indexOfRefraction=.98,o.invertRefractionY=!0,o._useLightmapAsShadowmap=!1,o._useReflectionFresnelFromSpecular=!1,o._useGlossinessFromSpecularMapAlpha=!1,o._maxSimultaneousLights=4,o._invertNormalMapX=!1,o._invertNormalMapY=!1,o._twoSidedLighting=!1,o._renderTargets=new e.SmartArray(16),o._worldViewProjectionMatrix=e.Matrix.Zero(),o._globalAmbientColor=new e.Color3(0,0,0),o._attachImageProcessingConfiguration(null),o.getRenderTargetTextures=function(){return o._renderTargets.reset(),r.ReflectionTextureEnabled&&o._reflectionTexture&&o._reflectionTexture.isRenderTarget&&o._renderTargets.push(o._reflectionTexture),r.RefractionTextureEnabled&&o._refractionTexture&&o._refractionTexture.isRenderTarget&&o._renderTargets.push(o._refractionTexture),o._renderTargets},o}return Y(r,i),Object.defineProperty(r.prototype,"imageProcessingConfiguration",{get:function(){return this._imageProcessingConfiguration},set:function(e){this._attachImageProcessingConfiguration(e),this._markAllSubMeshesAsTexturesDirty()},enumerable:!0,configurable:!0}),r.prototype._attachImageProcessingConfiguration=function(e){var t=this;e!==this._imageProcessingConfiguration&&(this._imageProcessingConfiguration&&this._imageProcessingObserver&&this._imageProcessingConfiguration.onUpdateParameters.remove(this._imageProcessingObserver),this._imageProcessingConfiguration=e||this.getScene().imageProcessingConfiguration,this._imageProcessingObserver=this._imageProcessingConfiguration.onUpdateParameters.add(function(e){t._markAllSubMeshesAsImageProcessingDirty()}))},Object.defineProperty(r.prototype,"cameraColorCurvesEnabled",{get:function(){return this.imageProcessingConfiguration.colorCurvesEnabled},set:function(e){this.imageProcessingConfiguration.colorCurvesEnabled=e},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"cameraColorGradingEnabled",{get:function(){return this.imageProcessingConfiguration.colorGradingEnabled},set:function(e){this.imageProcessingConfiguration.colorGradingEnabled=e},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"cameraToneMappingEnabled",{get:function(){return this._imageProcessingConfiguration.toneMappingEnabled},set:function(e){this._imageProcessingConfiguration.toneMappingEnabled=e},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"cameraExposure",{get:function(){return this._imageProcessingConfiguration.exposure},set:function(e){this._imageProcessingConfiguration.exposure=e},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"cameraContrast",{get:function(){return this._imageProcessingConfiguration.contrast},set:function(e){this._imageProcessingConfiguration.contrast=e},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"cameraColorGradingTexture",{get:function(){return this._imageProcessingConfiguration.colorGradingTexture},set:function(e){this._imageProcessingConfiguration.colorGradingTexture=e},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"cameraColorCurves",{get:function(){return this._imageProcessingConfiguration.colorCurves},set:function(e){this._imageProcessingConfiguration.colorCurves=e},enumerable:!0,configurable:!0}),r.prototype.getClassName=function(){return"StandardMaterial"},Object.defineProperty(r.prototype,"useLogarithmicDepth",{get:function(){return this._useLogarithmicDepth},set:function(e){this._useLogarithmicDepth=e&&this.getScene().getEngine().getCaps().fragmentDepthSupported,this._markAllSubMeshesAsMiscDirty()},enumerable:!0,configurable:!0}),r.prototype.needAlphaBlending=function(){return this.alpha<1||null!=this._opacityTexture||this._shouldUseAlphaFromDiffuseTexture()||this._opacityFresnelParameters&&this._opacityFresnelParameters.isEnabled},r.prototype.needAlphaTesting=function(){return null!=this._diffuseTexture&&this._diffuseTexture.hasAlpha},r.prototype._shouldUseAlphaFromDiffuseTexture=function(){return null!=this._diffuseTexture&&this._diffuseTexture.hasAlpha&&this._useAlphaFromDiffuseTexture},r.prototype.getAlphaTestTexture=function(){return this._diffuseTexture},r.prototype.isReadyForSubMesh=function(i,n,o){if(void 0===o&&(o=!1),n.effect&&this.isFrozen&&this._wasPreviouslyReady&&n.effect)return!0;n._materialDefines||(n._materialDefines=new t);var s=this.getScene(),a=n._materialDefines;if(!this.checkReadyOnEveryCall&&n.effect&&a._renderId===s.getRenderId())return!0;var h=s.getEngine();if(a._needNormals=e.MaterialHelper.PrepareDefinesForLights(s,i,a,!0,this._maxSimultaneousLights,this._disableLighting),a._areTexturesDirty){if(a._needUVs=!1,a.MAINUV1=!1,a.MAINUV2=!1,s.texturesEnabled){if(this._diffuseTexture&&r.DiffuseTextureEnabled){if(!this._diffuseTexture.isReadyOrNotBlocking())return!1;e.MaterialHelper.PrepareDefinesForMergedUV(this._diffuseTexture,a,"DIFFUSE")}else a.DIFFUSE=!1;if(this._ambientTexture&&r.AmbientTextureEnabled){if(!this._ambientTexture.isReadyOrNotBlocking())return!1;e.MaterialHelper.PrepareDefinesForMergedUV(this._ambientTexture,a,"AMBIENT")}else a.AMBIENT=!1;if(this._opacityTexture&&r.OpacityTextureEnabled){if(!this._opacityTexture.isReadyOrNotBlocking())return!1;e.MaterialHelper.PrepareDefinesForMergedUV(this._opacityTexture,a,"OPACITY"),a.OPACITYRGB=this._opacityTexture.getAlphaFromRGB}else a.OPACITY=!1;if(this._reflectionTexture&&r.ReflectionTextureEnabled){if(!this._reflectionTexture.isReadyOrNotBlocking())return!1;switch(a._needNormals=!0,a.REFLECTION=!0,a.ROUGHNESS=this._roughness>0,a.REFLECTIONOVERALPHA=this._useReflectionOverAlpha,a.INVERTCUBICMAP=this._reflectionTexture.coordinatesMode===e.Texture.INVCUBIC_MODE,a.REFLECTIONMAP_3D=this._reflectionTexture.isCube,this._reflectionTexture.coordinatesMode){case e.Texture.CUBIC_MODE:case e.Texture.INVCUBIC_MODE:a.setReflectionMode("REFLECTIONMAP_CUBIC");break;case e.Texture.EXPLICIT_MODE:a.setReflectionMode("REFLECTIONMAP_EXPLICIT");break;case e.Texture.PLANAR_MODE:a.setReflectionMode("REFLECTIONMAP_PLANAR");break;case e.Texture.PROJECTION_MODE:a.setReflectionMode("REFLECTIONMAP_PROJECTION");break;case e.Texture.SKYBOX_MODE:a.setReflectionMode("REFLECTIONMAP_SKYBOX");break;case e.Texture.SPHERICAL_MODE:a.setReflectionMode("REFLECTIONMAP_SPHERICAL");break;case e.Texture.EQUIRECTANGULAR_MODE:a.setReflectionMode("REFLECTIONMAP_EQUIRECTANGULAR");break;case e.Texture.FIXED_EQUIRECTANGULAR_MODE:a.setReflectionMode("REFLECTIONMAP_EQUIRECTANGULAR_FIXED");break;case e.Texture.FIXED_EQUIRECTANGULAR_MIRRORED_MODE:a.setReflectionMode("REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED")}}else a.REFLECTION=!1;if(this._emissiveTexture&&r.EmissiveTextureEnabled){if(!this._emissiveTexture.isReadyOrNotBlocking())return!1;e.MaterialHelper.PrepareDefinesForMergedUV(this._emissiveTexture,a,"EMISSIVE")}else a.EMISSIVE=!1;if(this._lightmapTexture&&r.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&&r.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&&r.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&&r.RefractionTextureEnabled){if(!this._refractionTexture.isReadyOrNotBlocking())return!1;a._needUVs=!0,a.REFRACTION=!0,a.REFRACTIONMAP_3D=this._refractionTexture.isCube}else a.REFRACTION=!1;a.TWOSIDEDLIGHTING=!this._backFaceCulling&&this._twoSidedLighting}else a.DIFFUSE=!1,a.AMBIENT=!1,a.OPACITY=!1,a.REFLECTION=!1,a.EMISSIVE=!1,a.LIGHTMAP=!1,a.BUMP=!1,a.REFRACTION=!1;a.ALPHAFROMDIFFUSE=this._shouldUseAlphaFromDiffuseTexture(),a.EMISSIVEASILLUMINATION=this._useEmissiveAsIllumination,a.LINKEMISSIVEWITHDIFFUSE=this._linkEmissiveWithDiffuse,a.SPECULAROVERALPHA=this._useSpecularOverAlpha,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&&(r.FresnelEnabled?(this._diffuseFresnelParameters||this._opacityFresnelParameters||this._emissiveFresnelParameters||this._refractionFresnelParameters||this._reflectionFresnelParameters)&&(a.DIFFUSEFRESNEL=this._diffuseFresnelParameters&&this._diffuseFresnelParameters.isEnabled,a.OPACITYFRESNEL=this._opacityFresnelParameters&&this._opacityFresnelParameters.isEnabled,a.REFLECTIONFRESNEL=this._reflectionFresnelParameters&&this._reflectionFresnelParameters.isEnabled,a.REFLECTIONFRESNELFROMSPECULAR=this._useReflectionFresnelFromSpecular,a.REFRACTIONFRESNEL=this._refractionFresnelParameters&&this._refractionFresnelParameters.isEnabled,a.EMISSIVEFRESNEL=this._emissiveFresnelParameters&&this._emissiveFresnelParameters.isEnabled,a._needNormals=!0,a.FRESNEL=!0):a.FRESNEL=!1),e.MaterialHelper.PrepareDefinesForMisc(i,s,this._useLogarithmicDepth,this.pointsCloud,this.fogEnabled,a),e.MaterialHelper.PrepareDefinesForAttributes(i,a,!0,!0,!0),e.MaterialHelper.PrepareDefinesForFrameBoundValues(s,h,a,o),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();n.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!(!n.effect||!n.effect.isReady())&&(a._renderId=s.getRenderId(),this._wasPreviouslyReady=!0,!0)},r.prototype.buildUniformLayout=function(){this._uniformBuffer.addUniform("diffuseLeftColor",4),this._uniformBuffer.addUniform("diffuseRightColor",4),this._uniformBuffer.addUniform("opacityParts",4),this._uniformBuffer.addUniform("reflectionLeftColor",4),this._uniformBuffer.addUniform("reflectionRightColor",4),this._uniformBuffer.addUniform("refractionLeftColor",4),this._uniformBuffer.addUniform("refractionRightColor",4),this._uniformBuffer.addUniform("emissiveLeftColor",4),this._uniformBuffer.addUniform("emissiveRightColor",4),this._uniformBuffer.addUniform("vDiffuseInfos",2),this._uniformBuffer.addUniform("vAmbientInfos",2),this._uniformBuffer.addUniform("vOpacityInfos",2),this._uniformBuffer.addUniform("vReflectionInfos",2),this._uniformBuffer.addUniform("vEmissiveInfos",2),this._uniformBuffer.addUniform("vLightmapInfos",2),this._uniformBuffer.addUniform("vSpecularInfos",2),this._uniformBuffer.addUniform("vBumpInfos",3),this._uniformBuffer.addUniform("diffuseMatrix",16),this._uniformBuffer.addUniform("ambientMatrix",16),this._uniformBuffer.addUniform("opacityMatrix",16),this._uniformBuffer.addUniform("reflectionMatrix",16),this._uniformBuffer.addUniform("emissiveMatrix",16),this._uniformBuffer.addUniform("lightmapMatrix",16),this._uniformBuffer.addUniform("specularMatrix",16),this._uniformBuffer.addUniform("bumpMatrix",16),this._uniformBuffer.addUniform("vTangentSpaceParams",2),this._uniformBuffer.addUniform("refractionMatrix",16),this._uniformBuffer.addUniform("vRefractionInfos",4),this._uniformBuffer.addUniform("vSpecularColor",4),this._uniformBuffer.addUniform("vEmissiveColor",3),this._uniformBuffer.addUniform("vDiffuseColor",4),this._uniformBuffer.addUniform("pointSize",1),this._uniformBuffer.create()},r.prototype.unbind=function(){this._activeEffect&&(this._reflectionTexture&&this._reflectionTexture.isRenderTarget&&this._activeEffect.setTexture("reflection2DSampler",null),this._refractionTexture&&this._refractionTexture.isRenderTarget&&this._activeEffect.setTexture("refraction2DSampler",null)),i.prototype.unbind.call(this)},r.prototype.bindForSubMesh=function(t,i,n){var o=this.getScene(),s=n._materialDefines;if(s){var a=n.effect;if(a){this._activeEffect=a,this.bindOnlyWorldMatrix(t);var h=this._mustRebind(o,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(r.FresnelEnabled&&s.FRESNEL&&(this.diffuseFresnelParameters&&this.diffuseFresnelParameters.isEnabled&&(this._uniformBuffer.updateColor4("diffuseLeftColor",this.diffuseFresnelParameters.leftColor,this.diffuseFresnelParameters.power),this._uniformBuffer.updateColor4("diffuseRightColor",this.diffuseFresnelParameters.rightColor,this.diffuseFresnelParameters.bias)),this.opacityFresnelParameters&&this.opacityFresnelParameters.isEnabled&&this._uniformBuffer.updateColor4("opacityParts",new e.Color3(this.opacityFresnelParameters.leftColor.toLuminance(),this.opacityFresnelParameters.rightColor.toLuminance(),this.opacityFresnelParameters.bias),this.opacityFresnelParameters.power),this.reflectionFresnelParameters&&this.reflectionFresnelParameters.isEnabled&&(this._uniformBuffer.updateColor4("reflectionLeftColor",this.reflectionFresnelParameters.leftColor,this.reflectionFresnelParameters.power),this._uniformBuffer.updateColor4("reflectionRightColor",this.reflectionFresnelParameters.rightColor,this.reflectionFresnelParameters.bias)),this.refractionFresnelParameters&&this.refractionFresnelParameters.isEnabled&&(this._uniformBuffer.updateColor4("refractionLeftColor",this.refractionFresnelParameters.leftColor,this.refractionFresnelParameters.power),this._uniformBuffer.updateColor4("refractionRightColor",this.refractionFresnelParameters.rightColor,this.refractionFresnelParameters.bias)),this.emissiveFresnelParameters&&this.emissiveFresnelParameters.isEnabled&&(this._uniformBuffer.updateColor4("emissiveLeftColor",this.emissiveFresnelParameters.leftColor,this.emissiveFresnelParameters.power),this._uniformBuffer.updateColor4("emissiveRightColor",this.emissiveFresnelParameters.rightColor,this.emissiveFresnelParameters.bias))),o.texturesEnabled&&(this._diffuseTexture&&r.DiffuseTextureEnabled&&(this._uniformBuffer.updateFloat2("vDiffuseInfos",this._diffuseTexture.coordinatesIndex,this._diffuseTexture.level),e.MaterialHelper.BindTextureMatrix(this._diffuseTexture,this._uniformBuffer,"diffuse")),this._ambientTexture&&r.AmbientTextureEnabled&&(this._uniformBuffer.updateFloat2("vAmbientInfos",this._ambientTexture.coordinatesIndex,this._ambientTexture.level),e.MaterialHelper.BindTextureMatrix(this._ambientTexture,this._uniformBuffer,"ambient")),this._opacityTexture&&r.OpacityTextureEnabled&&(this._uniformBuffer.updateFloat2("vOpacityInfos",this._opacityTexture.coordinatesIndex,this._opacityTexture.level),e.MaterialHelper.BindTextureMatrix(this._opacityTexture,this._uniformBuffer,"opacity")),this._reflectionTexture&&r.ReflectionTextureEnabled&&(this._uniformBuffer.updateFloat2("vReflectionInfos",this._reflectionTexture.level,this.roughness),this._uniformBuffer.updateMatrix("reflectionMatrix",this._reflectionTexture.getReflectionTextureMatrix())),this._emissiveTexture&&r.EmissiveTextureEnabled&&(this._uniformBuffer.updateFloat2("vEmissiveInfos",this._emissiveTexture.coordinatesIndex,this._emissiveTexture.level),e.MaterialHelper.BindTextureMatrix(this._emissiveTexture,this._uniformBuffer,"emissive")),this._lightmapTexture&&r.LightmapTextureEnabled&&(this._uniformBuffer.updateFloat2("vLightmapInfos",this._lightmapTexture.coordinatesIndex,this._lightmapTexture.level),e.MaterialHelper.BindTextureMatrix(this._lightmapTexture,this._uniformBuffer,"lightmap")),this._specularTexture&&r.SpecularTextureEnabled&&(this._uniformBuffer.updateFloat2("vSpecularInfos",this._specularTexture.coordinatesIndex,this._specularTexture.level),e.MaterialHelper.BindTextureMatrix(this._specularTexture,this._uniformBuffer,"specular")),this._bumpTexture&&o.getEngine().getCaps().standardDerivatives&&r.BumpTextureEnabled&&(this._uniformBuffer.updateFloat3("vBumpInfos",this._bumpTexture.coordinatesIndex,1/this._bumpTexture.level,this.parallaxScaleBias),e.MaterialHelper.BindTextureMatrix(this._bumpTexture,this._uniformBuffer,"bump"),o._mirroredCameraPosition?this._uniformBuffer.updateFloat2("vTangentSpaceParams",this._invertNormalMapX?1:-1,this._invertNormalMapY?1:-1):this._uniformBuffer.updateFloat2("vTangentSpaceParams",this._invertNormalMapX?-1:1,this._invertNormalMapY?-1:1)),this._refractionTexture&&r.RefractionTextureEnabled)){var l=1;this._refractionTexture.isCube||(this._uniformBuffer.updateMatrix("refractionMatrix",this._refractionTexture.getReflectionTextureMatrix()),this._refractionTexture.depth&&(l=this._refractionTexture.depth)),this._uniformBuffer.updateFloat4("vRefractionInfos",this._refractionTexture.level,this.indexOfRefraction,l,this.invertRefractionY?-1:1)}this.pointsCloud&&this._uniformBuffer.updateFloat("pointSize",this.pointSize),s.SPECULARTERM&&this._uniformBuffer.updateColor4("vSpecularColor",this.specularColor,this.specularPower),this._uniformBuffer.updateColor3("vEmissiveColor",this.emissiveColor),this._uniformBuffer.updateColor4("vDiffuseColor",this.diffuseColor,this.alpha*i.visibility)}if(o.texturesEnabled&&(this._diffuseTexture&&r.DiffuseTextureEnabled&&a.setTexture("diffuseSampler",this._diffuseTexture),this._ambientTexture&&r.AmbientTextureEnabled&&a.setTexture("ambientSampler",this._ambientTexture),this._opacityTexture&&r.OpacityTextureEnabled&&a.setTexture("opacitySampler",this._opacityTexture),this._reflectionTexture&&r.ReflectionTextureEnabled&&(this._reflectionTexture.isCube?a.setTexture("reflectionCubeSampler",this._reflectionTexture):a.setTexture("reflection2DSampler",this._reflectionTexture)),this._emissiveTexture&&r.EmissiveTextureEnabled&&a.setTexture("emissiveSampler",this._emissiveTexture),this._lightmapTexture&&r.LightmapTextureEnabled&&a.setTexture("lightmapSampler",this._lightmapTexture),this._specularTexture&&r.SpecularTextureEnabled&&a.setTexture("specularSampler",this._specularTexture),this._bumpTexture&&o.getEngine().getCaps().standardDerivatives&&r.BumpTextureEnabled&&a.setTexture("bumpSampler",this._bumpTexture),this._refractionTexture&&r.RefractionTextureEnabled)){l=1;this._refractionTexture.isCube?a.setTexture("refractionCubeSampler",this._refractionTexture):a.setTexture("refraction2DSampler",this._refractionTexture)}e.MaterialHelper.BindClipPlane(a,o),o.ambientColor.multiplyToRef(this.ambientColor,this._globalAmbientColor),e.MaterialHelper.BindEyePosition(a,o),a.setColor3("vAmbientColor",this._globalAmbientColor)}!h&&this.isFrozen||(o.lightsEnabled&&!this._disableLighting&&e.MaterialHelper.BindLights(o,i,a,s,this._maxSimultaneousLights),(o.fogEnabled&&i.applyFog&&o.fogMode!==e.Scene.FOGMODE_NONE||this._reflectionTexture||this._refractionTexture)&&this.bindView(a),e.MaterialHelper.BindFogParameters(o,i,a),s.NUM_MORPH_INFLUENCERS&&e.MaterialHelper.BindMorphTargetParameters(i,a),e.MaterialHelper.BindLogDepth(s,a,o),this._imageProcessingConfiguration.applyByPostProcess||this._imageProcessingConfiguration.bind(this._activeEffect)),this._uniformBuffer.update(),this._afterBind(i,this._activeEffect)}}},r.prototype.getAnimatables=function(){var e=[];return this._diffuseTexture&&this._diffuseTexture.animations&&this._diffuseTexture.animations.length>0&&e.push(this._diffuseTexture),this._ambientTexture&&this._ambientTexture.animations&&this._ambientTexture.animations.length>0&&e.push(this._ambientTexture),this._opacityTexture&&this._opacityTexture.animations&&this._opacityTexture.animations.length>0&&e.push(this._opacityTexture),this._reflectionTexture&&this._reflectionTexture.animations&&this._reflectionTexture.animations.length>0&&e.push(this._reflectionTexture),this._emissiveTexture&&this._emissiveTexture.animations&&this._emissiveTexture.animations.length>0&&e.push(this._emissiveTexture),this._specularTexture&&this._specularTexture.animations&&this._specularTexture.animations.length>0&&e.push(this._specularTexture),this._bumpTexture&&this._bumpTexture.animations&&this._bumpTexture.animations.length>0&&e.push(this._bumpTexture),this._lightmapTexture&&this._lightmapTexture.animations&&this._lightmapTexture.animations.length>0&&e.push(this._lightmapTexture),this._refractionTexture&&this._refractionTexture.animations&&this._refractionTexture.animations.length>0&&e.push(this._refractionTexture),e},r.prototype.getActiveTextures=function(){var e=i.prototype.getActiveTextures.call(this);return this._diffuseTexture&&e.push(this._diffuseTexture),this._ambientTexture&&e.push(this._ambientTexture),this._opacityTexture&&e.push(this._opacityTexture),this._reflectionTexture&&e.push(this._reflectionTexture),this._emissiveTexture&&e.push(this._emissiveTexture),this._specularTexture&&e.push(this._specularTexture),this._bumpTexture&&e.push(this._bumpTexture),this._lightmapTexture&&e.push(this._lightmapTexture),this._refractionTexture&&e.push(this._refractionTexture),e},r.prototype.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))))))))},r.prototype.dispose=function(e,t){t&&(this._diffuseTexture&&this._diffuseTexture.dispose(),this._ambientTexture&&this._ambientTexture.dispose(),this._opacityTexture&&this._opacityTexture.dispose(),this._reflectionTexture&&this._reflectionTexture.dispose(),this._emissiveTexture&&this._emissiveTexture.dispose(),this._specularTexture&&this._specularTexture.dispose(),this._bumpTexture&&this._bumpTexture.dispose(),this._lightmapTexture&&this._lightmapTexture.dispose(),this._refractionTexture&&this._refractionTexture.dispose()),this._imageProcessingConfiguration&&this._imageProcessingObserver&&this._imageProcessingConfiguration.onUpdateParameters.remove(this._imageProcessingObserver),i.prototype.dispose.call(this,e,t)},r.prototype.clone=function(t){var i=this,n=e.SerializationHelper.Clone(function(){return new r(t,i.getScene())},this);return n.name=t,n.id=t,n},r.prototype.serialize=function(){return e.SerializationHelper.Serialize(this)},r.Parse=function(t,i,n){return e.SerializationHelper.Parse(function(){return new r(t.name,i)},t,i,n)},Object.defineProperty(r,"DiffuseTextureEnabled",{get:function(){return r._DiffuseTextureEnabled},set:function(t){r._DiffuseTextureEnabled!==t&&(r._DiffuseTextureEnabled=t,e.Engine.MarkAllMaterialsAsDirty(e.Material.TextureDirtyFlag))},enumerable:!0,configurable:!0}),Object.defineProperty(r,"AmbientTextureEnabled",{get:function(){return r._AmbientTextureEnabled},set:function(t){r._AmbientTextureEnabled!==t&&(r._AmbientTextureEnabled=t,e.Engine.MarkAllMaterialsAsDirty(e.Material.TextureDirtyFlag))},enumerable:!0,configurable:!0}),Object.defineProperty(r,"OpacityTextureEnabled",{get:function(){return r._OpacityTextureEnabled},set:function(t){r._OpacityTextureEnabled!==t&&(r._OpacityTextureEnabled=t,e.Engine.MarkAllMaterialsAsDirty(e.Material.TextureDirtyFlag))},enumerable:!0,configurable:!0}),Object.defineProperty(r,"ReflectionTextureEnabled",{get:function(){return r._ReflectionTextureEnabled},set:function(t){r._ReflectionTextureEnabled!==t&&(r._ReflectionTextureEnabled=t,e.Engine.MarkAllMaterialsAsDirty(e.Material.TextureDirtyFlag))},enumerable:!0,configurable:!0}),Object.defineProperty(r,"EmissiveTextureEnabled",{get:function(){return r._EmissiveTextureEnabled},set:function(t){r._EmissiveTextureEnabled!==t&&(r._EmissiveTextureEnabled=t,e.Engine.MarkAllMaterialsAsDirty(e.Material.TextureDirtyFlag))},enumerable:!0,configurable:!0}),Object.defineProperty(r,"SpecularTextureEnabled",{get:function(){return r._SpecularTextureEnabled},set:function(t){r._SpecularTextureEnabled!==t&&(r._SpecularTextureEnabled=t,e.Engine.MarkAllMaterialsAsDirty(e.Material.TextureDirtyFlag))},enumerable:!0,configurable:!0}),Object.defineProperty(r,"BumpTextureEnabled",{get:function(){return r._BumpTextureEnabled},set:function(t){r._BumpTextureEnabled!==t&&(r._BumpTextureEnabled=t,e.Engine.MarkAllMaterialsAsDirty(e.Material.TextureDirtyFlag))},enumerable:!0,configurable:!0}),Object.defineProperty(r,"LightmapTextureEnabled",{get:function(){return r._LightmapTextureEnabled},set:function(t){r._LightmapTextureEnabled!==t&&(r._LightmapTextureEnabled=t,e.Engine.MarkAllMaterialsAsDirty(e.Material.TextureDirtyFlag))},enumerable:!0,configurable:!0}),Object.defineProperty(r,"RefractionTextureEnabled",{get:function(){return r._RefractionTextureEnabled},set:function(t){r._RefractionTextureEnabled!==t&&(r._RefractionTextureEnabled=t,e.Engine.MarkAllMaterialsAsDirty(e.Material.TextureDirtyFlag))},enumerable:!0,configurable:!0}),Object.defineProperty(r,"ColorGradingTextureEnabled",{get:function(){return r._ColorGradingTextureEnabled},set:function(t){r._ColorGradingTextureEnabled!==t&&(r._ColorGradingTextureEnabled=t,e.Engine.MarkAllMaterialsAsDirty(e.Material.TextureDirtyFlag))},enumerable:!0,configurable:!0}),Object.defineProperty(r,"FresnelEnabled",{get:function(){return r._FresnelEnabled},set:function(t){r._FresnelEnabled!==t&&(r._FresnelEnabled=t,e.Engine.MarkAllMaterialsAsDirty(e.Material.FresnelDirtyFlag))},enumerable:!0,configurable:!0}),r._DiffuseTextureEnabled=!0,r._AmbientTextureEnabled=!0,r._OpacityTextureEnabled=!0,r._ReflectionTextureEnabled=!0,r._EmissiveTextureEnabled=!0,r._SpecularTextureEnabled=!0,r._BumpTextureEnabled=!0,r._LightmapTextureEnabled=!0,r._RefractionTextureEnabled=!0,r._ColorGradingTextureEnabled=!0,r._FresnelEnabled=!0,X([e.serializeAsTexture("diffuseTexture")],r.prototype,"_diffuseTexture",void 0),X([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"diffuseTexture",void 0),X([e.serializeAsTexture("ambientTexture")],r.prototype,"_ambientTexture",void 0),X([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"ambientTexture",void 0),X([e.serializeAsTexture("opacityTexture")],r.prototype,"_opacityTexture",void 0),X([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"opacityTexture",void 0),X([e.serializeAsTexture("reflectionTexture")],r.prototype,"_reflectionTexture",void 0),X([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"reflectionTexture",void 0),X([e.serializeAsTexture("emissiveTexture")],r.prototype,"_emissiveTexture",void 0),X([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"emissiveTexture",void 0),X([e.serializeAsTexture("specularTexture")],r.prototype,"_specularTexture",void 0),X([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"specularTexture",void 0),X([e.serializeAsTexture("bumpTexture")],r.prototype,"_bumpTexture",void 0),X([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"bumpTexture",void 0),X([e.serializeAsTexture("lightmapTexture")],r.prototype,"_lightmapTexture",void 0),X([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"lightmapTexture",void 0),X([e.serializeAsTexture("refractionTexture")],r.prototype,"_refractionTexture",void 0),X([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"refractionTexture",void 0),X([e.serializeAsColor3("ambient")],r.prototype,"ambientColor",void 0),X([e.serializeAsColor3("diffuse")],r.prototype,"diffuseColor",void 0),X([e.serializeAsColor3("specular")],r.prototype,"specularColor",void 0),X([e.serializeAsColor3("emissive")],r.prototype,"emissiveColor",void 0),X([e.serialize()],r.prototype,"specularPower",void 0),X([e.serialize("useAlphaFromDiffuseTexture")],r.prototype,"_useAlphaFromDiffuseTexture",void 0),X([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"useAlphaFromDiffuseTexture",void 0),X([e.serialize("useEmissiveAsIllumination")],r.prototype,"_useEmissiveAsIllumination",void 0),X([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"useEmissiveAsIllumination",void 0),X([e.serialize("linkEmissiveWithDiffuse")],r.prototype,"_linkEmissiveWithDiffuse",void 0),X([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"linkEmissiveWithDiffuse",void 0),X([e.serialize("useSpecularOverAlpha")],r.prototype,"_useSpecularOverAlpha",void 0),X([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"useSpecularOverAlpha",void 0),X([e.serialize("useReflectionOverAlpha")],r.prototype,"_useReflectionOverAlpha",void 0),X([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"useReflectionOverAlpha",void 0),X([e.serialize("disableLighting")],r.prototype,"_disableLighting",void 0),X([e.expandToProperty("_markAllSubMeshesAsLightsDirty")],r.prototype,"disableLighting",void 0),X([e.serialize("useParallax")],r.prototype,"_useParallax",void 0),X([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"useParallax",void 0),X([e.serialize("useParallaxOcclusion")],r.prototype,"_useParallaxOcclusion",void 0),X([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"useParallaxOcclusion",void 0),X([e.serialize()],r.prototype,"parallaxScaleBias",void 0),X([e.serialize("roughness")],r.prototype,"_roughness",void 0),X([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"roughness",void 0),X([e.serialize()],r.prototype,"indexOfRefraction",void 0),X([e.serialize()],r.prototype,"invertRefractionY",void 0),X([e.serialize("useLightmapAsShadowmap")],r.prototype,"_useLightmapAsShadowmap",void 0),X([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"useLightmapAsShadowmap",void 0),X([e.serializeAsFresnelParameters("diffuseFresnelParameters")],r.prototype,"_diffuseFresnelParameters",void 0),X([e.expandToProperty("_markAllSubMeshesAsFresnelDirty")],r.prototype,"diffuseFresnelParameters",void 0),X([e.serializeAsFresnelParameters("opacityFresnelParameters")],r.prototype,"_opacityFresnelParameters",void 0),X([e.expandToProperty("_markAllSubMeshesAsFresnelDirty")],r.prototype,"opacityFresnelParameters",void 0),X([e.serializeAsFresnelParameters("reflectionFresnelParameters")],r.prototype,"_reflectionFresnelParameters",void 0),X([e.expandToProperty("_markAllSubMeshesAsFresnelDirty")],r.prototype,"reflectionFresnelParameters",void 0),X([e.serializeAsFresnelParameters("refractionFresnelParameters")],r.prototype,"_refractionFresnelParameters",void 0),X([e.expandToProperty("_markAllSubMeshesAsFresnelDirty")],r.prototype,"refractionFresnelParameters",void 0),X([e.serializeAsFresnelParameters("emissiveFresnelParameters")],r.prototype,"_emissiveFresnelParameters",void 0),X([e.expandToProperty("_markAllSubMeshesAsFresnelDirty")],r.prototype,"emissiveFresnelParameters",void 0),X([e.serialize("useReflectionFresnelFromSpecular")],r.prototype,"_useReflectionFresnelFromSpecular",void 0),X([e.expandToProperty("_markAllSubMeshesAsFresnelDirty")],r.prototype,"useReflectionFresnelFromSpecular",void 0),X([e.serialize("useGlossinessFromSpecularMapAlpha")],r.prototype,"_useGlossinessFromSpecularMapAlpha",void 0),X([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"useGlossinessFromSpecularMapAlpha",void 0),X([e.serialize("maxSimultaneousLights")],r.prototype,"_maxSimultaneousLights",void 0),X([e.expandToProperty("_markAllSubMeshesAsLightsDirty")],r.prototype,"maxSimultaneousLights",void 0),X([e.serialize("invertNormalMapX")],r.prototype,"_invertNormalMapX",void 0),X([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"invertNormalMapX",void 0),X([e.serialize("invertNormalMapY")],r.prototype,"_invertNormalMapY",void 0),X([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"invertNormalMapY",void 0),X([e.serialize("twoSidedLighting")],r.prototype,"_twoSidedLighting",void 0),X([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"twoSidedLighting",void 0),X([e.serialize()],r.prototype,"useLogarithmicDepth",null),r}(e.PushMaterial);e.StandardMaterial=i}(us||(us={})),ce=us||(us={}),ue=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.LINEARALPHAFRESNEL=!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 Y(t,e),t.prototype.reset=function(){e.prototype.reset.call(this),this.ALPHATESTVALUE=.5,this.PBR=!0},t}(ce.MaterialDefines),pe=function(e){function t(t,i){var r=e.call(this,t,i)||this;return r._directIntensity=1,r._emissiveIntensity=1,r._environmentIntensity=1,r._specularIntensity=1,r._lightingInfos=new ce.Vector4(r._directIntensity,r._emissiveIntensity,r._environmentIntensity,r._specularIntensity),r._disableBumpMap=!1,r._ambientTextureStrength=1,r._ambientColor=new ce.Color3(0,0,0),r._albedoColor=new ce.Color3(1,1,1),r._reflectivityColor=new ce.Color3(1,1,1),r._reflectionColor=new ce.Color3(1,1,1),r._emissiveColor=new ce.Color3(0,0,0),r._microSurface=.9,r._indexOfRefraction=.66,r._invertRefractionY=!1,r._linkRefractionWithTransparency=!1,r._useLightmapAsShadowmap=!1,r._useHorizonOcclusion=!0,r._useRadianceOcclusion=!0,r._useAlphaFromAlbedoTexture=!1,r._useSpecularOverAlpha=!0,r._useMicroSurfaceFromReflectivityMapAlpha=!1,r._useRoughnessFromMetallicTextureAlpha=!0,r._useRoughnessFromMetallicTextureGreen=!1,r._useMetallnessFromMetallicTextureBlue=!1,r._useAmbientOcclusionFromMetallicTextureRed=!1,r._useAmbientInGrayScale=!1,r._useAutoMicroSurfaceFromReflectivityMap=!1,r._usePhysicalLightFalloff=!0,r._useRadianceOverAlpha=!0,r._useParallax=!1,r._useParallaxOcclusion=!1,r._parallaxScaleBias=.05,r._disableLighting=!1,r._maxSimultaneousLights=4,r._invertNormalMapX=!1,r._invertNormalMapY=!1,r._twoSidedLighting=!1,r._alphaCutOff=.4,r._forceAlphaTest=!1,r._useAlphaFresnel=!1,r._useLinearAlphaFresnel=!1,r._transparencyMode=null,r._environmentBRDFTexture=null,r._forceIrradianceInFragment=!1,r._forceNormalForward=!1,r._forceMetallicWorkflow=!1,r._renderTargets=new ce.SmartArray(16),r._globalAmbientColor=new ce.Color3(0,0,0),r._attachImageProcessingConfiguration(null),r.getRenderTargetTextures=function(){return r._renderTargets.reset(),ce.StandardMaterial.ReflectionTextureEnabled&&r._reflectionTexture&&r._reflectionTexture.isRenderTarget&&r._renderTargets.push(r._reflectionTexture),ce.StandardMaterial.RefractionTextureEnabled&&r._refractionTexture&&r._refractionTexture.isRenderTarget&&r._renderTargets.push(r._refractionTexture),r._renderTargets},r._environmentBRDFTexture=ce.TextureTools.GetEnvironmentBRDFTexture(i),r}return Y(t,e),t.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()}))},t.prototype.getClassName=function(){return"PBRBaseMaterial"},Object.defineProperty(t.prototype,"useLogarithmicDepth",{get:function(){return this._useLogarithmicDepth},set:function(e){this._useLogarithmicDepth=e&&this.getScene().getEngine().getCaps().fragmentDepthSupported},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"transparencyMode",{get:function(){return this._transparencyMode},set:function(e){this._transparencyMode!==e&&(this._transparencyMode=e,this._forceAlphaTest=e===ce.PBRMaterial.PBRMATERIAL_ALPHATESTANDBLEND,this._markAllSubMeshesAsTexturesDirty())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"_disableAlphaBlending",{get:function(){return this._linkRefractionWithTransparency||this._transparencyMode===ce.PBRMaterial.PBRMATERIAL_OPAQUE||this._transparencyMode===ce.PBRMaterial.PBRMATERIAL_ALPHATEST},enumerable:!0,configurable:!0}),t.prototype.needAlphaBlending=function(){return!this._disableAlphaBlending&&(this.alpha<1||null!=this._opacityTexture||this._shouldUseAlphaFromAlbedoTexture())},t.prototype.needAlphaBlendingForMesh=function(t){return!this._disableAlphaBlending&&e.prototype.needAlphaBlendingForMesh.call(this,t)},t.prototype.needAlphaTesting=function(){return!!this._forceAlphaTest||!this._linkRefractionWithTransparency&&(null!=this._albedoTexture&&this._albedoTexture.hasAlpha&&(null==this._transparencyMode||this._transparencyMode===ce.PBRMaterial.PBRMATERIAL_ALPHATEST))},t.prototype._shouldUseAlphaFromAlbedoTexture=function(){return null!=this._albedoTexture&&this._albedoTexture.hasAlpha&&this._useAlphaFromAlbedoTexture&&this._transparencyMode!==ce.PBRMaterial.PBRMATERIAL_OPAQUE},t.prototype.getAlphaTestTexture=function(){return this._albedoTexture},t.prototype.isReadyForSubMesh=function(e,t,i){var r=this;if(t.effect&&this.isFrozen&&this._wasPreviouslyReady)return!0;t._materialDefines||(t._materialDefines=new ue);var n=this.getScene(),o=t._materialDefines;if(!this.checkReadyOnEveryCall&&t.effect&&o._renderId===n.getRenderId())return!0;var s=n.getEngine();if(ce.MaterialHelper.PrepareDefinesForLights(n,e,o,!0,this._maxSimultaneousLights,this._disableLighting),o._needNormals=!0,o._areTexturesDirty){if(o._needUVs=!1,n.texturesEnabled){if(n.getEngine().getCaps().textureLOD&&(o.LODBASEDMICROSFURACE=!0),this._albedoTexture&&ce.StandardMaterial.DiffuseTextureEnabled){if(!this._albedoTexture.isReadyOrNotBlocking())return!1;ce.MaterialHelper.PrepareDefinesForMergedUV(this._albedoTexture,o,"ALBEDO")}else o.ALBEDO=!1;if(this._ambientTexture&&ce.StandardMaterial.AmbientTextureEnabled){if(!this._ambientTexture.isReadyOrNotBlocking())return!1;ce.MaterialHelper.PrepareDefinesForMergedUV(this._ambientTexture,o,"AMBIENT"),o.AMBIENTINGRAYSCALE=this._useAmbientInGrayScale}else o.AMBIENT=!1;if(this._opacityTexture&&ce.StandardMaterial.OpacityTextureEnabled){if(!this._opacityTexture.isReadyOrNotBlocking())return!1;ce.MaterialHelper.PrepareDefinesForMergedUV(this._opacityTexture,o,"OPACITY"),o.OPACITYRGB=this._opacityTexture.getAlphaFromRGB}else o.OPACITY=!1;var a=this._getReflectionTexture();if(a&&ce.StandardMaterial.ReflectionTextureEnabled){if(!a.isReadyOrNotBlocking())return!1;switch(o.REFLECTION=!0,o.GAMMAREFLECTION=a.gammaSpace,o.REFLECTIONMAP_OPPOSITEZ=this.getScene().useRightHandedSystem?!a.invertZ:a.invertZ,o.LODINREFLECTIONALPHA=a.lodLevelInAlpha,a.coordinatesMode===ce.Texture.INVCUBIC_MODE&&(o.INVERTCUBICMAP=!0),o.REFLECTIONMAP_3D=a.isCube,a.coordinatesMode){case ce.Texture.CUBIC_MODE:case ce.Texture.INVCUBIC_MODE:o.REFLECTIONMAP_CUBIC=!0;break;case ce.Texture.EXPLICIT_MODE:o.REFLECTIONMAP_EXPLICIT=!0;break;case ce.Texture.PLANAR_MODE:o.REFLECTIONMAP_PLANAR=!0;break;case ce.Texture.PROJECTION_MODE:o.REFLECTIONMAP_PROJECTION=!0;break;case ce.Texture.SKYBOX_MODE:o.REFLECTIONMAP_SKYBOX=!0;break;case ce.Texture.SPHERICAL_MODE:o.REFLECTIONMAP_SPHERICAL=!0;break;case ce.Texture.EQUIRECTANGULAR_MODE:o.REFLECTIONMAP_EQUIRECTANGULAR=!0;break;case ce.Texture.FIXED_EQUIRECTANGULAR_MODE:o.REFLECTIONMAP_EQUIRECTANGULAR_FIXED=!0;break;case ce.Texture.FIXED_EQUIRECTANGULAR_MIRRORED_MODE:o.REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED=!0}a.coordinatesMode!==ce.Texture.SKYBOX_MODE&&a.sphericalPolynomial&&(o.USESPHERICALFROMREFLECTIONMAP=!0,this._forceIrradianceInFragment||n.getEngine().getCaps().maxVaryingVectors<=8?o.USESPHERICALINVERTEX=!1:o.USESPHERICALINVERTEX=!0)}else o.REFLECTION=!1,o.REFLECTIONMAP_3D=!1,o.REFLECTIONMAP_SPHERICAL=!1,o.REFLECTIONMAP_PLANAR=!1,o.REFLECTIONMAP_CUBIC=!1,o.REFLECTIONMAP_PROJECTION=!1,o.REFLECTIONMAP_SKYBOX=!1,o.REFLECTIONMAP_EXPLICIT=!1,o.REFLECTIONMAP_EQUIRECTANGULAR=!1,o.REFLECTIONMAP_EQUIRECTANGULAR_FIXED=!1,o.REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED=!1,o.INVERTCUBICMAP=!1,o.USESPHERICALFROMREFLECTIONMAP=!1,o.USESPHERICALINVERTEX=!1,o.REFLECTIONMAP_OPPOSITEZ=!1,o.LODINREFLECTIONALPHA=!1,o.GAMMAREFLECTION=!1;if(this._lightmapTexture&&ce.StandardMaterial.LightmapTextureEnabled){if(!this._lightmapTexture.isReadyOrNotBlocking())return!1;ce.MaterialHelper.PrepareDefinesForMergedUV(this._lightmapTexture,o,"LIGHTMAP"),o.USELIGHTMAPASSHADOWMAP=this._useLightmapAsShadowmap}else o.LIGHTMAP=!1;if(this._emissiveTexture&&ce.StandardMaterial.EmissiveTextureEnabled){if(!this._emissiveTexture.isReadyOrNotBlocking())return!1;ce.MaterialHelper.PrepareDefinesForMergedUV(this._emissiveTexture,o,"EMISSIVE")}else o.EMISSIVE=!1;if(ce.StandardMaterial.SpecularTextureEnabled){if(this._metallicTexture){if(!this._metallicTexture.isReadyOrNotBlocking())return!1;ce.MaterialHelper.PrepareDefinesForMergedUV(this._metallicTexture,o,"REFLECTIVITY"),o.METALLICWORKFLOW=!0,o.ROUGHNESSSTOREINMETALMAPALPHA=this._useRoughnessFromMetallicTextureAlpha,o.ROUGHNESSSTOREINMETALMAPGREEN=!this._useRoughnessFromMetallicTextureAlpha&&this._useRoughnessFromMetallicTextureGreen,o.METALLNESSSTOREINMETALMAPBLUE=this._useMetallnessFromMetallicTextureBlue,o.AOSTOREINMETALMAPRED=this._useAmbientOcclusionFromMetallicTextureRed}else if(this._reflectivityTexture){if(!this._reflectivityTexture.isReadyOrNotBlocking())return!1;o.METALLICWORKFLOW=!1,ce.MaterialHelper.PrepareDefinesForMergedUV(this._reflectivityTexture,o,"REFLECTIVITY"),o.MICROSURFACEFROMREFLECTIVITYMAP=this._useMicroSurfaceFromReflectivityMapAlpha,o.MICROSURFACEAUTOMATIC=this._useAutoMicroSurfaceFromReflectivityMap}else o.METALLICWORKFLOW=!1,o.REFLECTIVITY=!1;if(this._microSurfaceTexture){if(!this._microSurfaceTexture.isReadyOrNotBlocking())return!1;ce.MaterialHelper.PrepareDefinesForMergedUV(this._microSurfaceTexture,o,"MICROSURFACEMAP")}else o.MICROSURFACEMAP=!1}else o.REFLECTIVITY=!1,o.MICROSURFACEMAP=!1;if(n.getEngine().getCaps().standardDerivatives&&this._bumpTexture&&ce.StandardMaterial.BumpTextureEnabled&&!this._disableBumpMap){if(!this._bumpTexture.isReady())return!1;ce.MaterialHelper.PrepareDefinesForMergedUV(this._bumpTexture,o,"BUMP"),this._useParallax&&this._albedoTexture&&ce.StandardMaterial.DiffuseTextureEnabled?(o.PARALLAX=!0,o.PARALLAXOCCLUSION=!!this._useParallaxOcclusion):o.PARALLAX=!1}else o.BUMP=!1;var h=this._getRefractionTexture();if(h&&ce.StandardMaterial.RefractionTextureEnabled){if(!h.isReadyOrNotBlocking())return!1;o.REFRACTION=!0,o.REFRACTIONMAP_3D=h.isCube,o.GAMMAREFRACTION=h.gammaSpace,o.REFRACTIONMAP_OPPOSITEZ=h.invertZ,o.LODINREFRACTIONALPHA=h.lodLevelInAlpha,this._linkRefractionWithTransparency&&(o.LINKREFRACTIONTOTRANSPARENCY=!0)}else o.REFRACTION=!1;if(this._environmentBRDFTexture&&ce.StandardMaterial.ReflectionTextureEnabled){if(!this._environmentBRDFTexture.isReady())return!1;o.ENVIRONMENTBRDF=!0}else o.ENVIRONMENTBRDF=!1;this._shouldUseAlphaFromAlbedoTexture()?o.ALPHAFROMALBEDO=!0:o.ALPHAFROMALBEDO=!1}o.SPECULAROVERALPHA=this._useSpecularOverAlpha,o.USEPHYSICALLIGHTFALLOFF=this._usePhysicalLightFalloff,o.RADIANCEOVERALPHA=this._useRadianceOverAlpha,this._forceMetallicWorkflow||void 0!==this._metallic&&null!==this._metallic||void 0!==this._roughness&&null!==this._roughness?o.METALLICWORKFLOW=!0:o.METALLICWORKFLOW=!1,!this.backFaceCulling&&this._twoSidedLighting?o.TWOSIDEDLIGHTING=!0:o.TWOSIDEDLIGHTING=!1,o.ALPHATESTVALUE=this._alphaCutOff,o.PREMULTIPLYALPHA=this.alphaMode===ce.Engine.ALPHA_PREMULTIPLIED||this.alphaMode===ce.Engine.ALPHA_PREMULTIPLIED_PORTERDUFF,o.ALPHABLEND=this.needAlphaBlendingForMesh(e),o.ALPHAFRESNEL=this._useAlphaFresnel||this._useLinearAlphaFresnel,o.LINEARALPHAFRESNEL=this._useLinearAlphaFresnel}if(o._areImageProcessingDirty){if(!this._imageProcessingConfiguration.isReady())return!1;this._imageProcessingConfiguration.prepareDefines(o)}if(o.FORCENORMALFORWARD=this._forceNormalForward,o.RADIANCEOCCLUSION=this._useRadianceOcclusion,o.HORIZONOCCLUSION=this._useHorizonOcclusion,ce.MaterialHelper.PrepareDefinesForMisc(e,n,this._useLogarithmicDepth,this.pointsCloud,this.fogEnabled,o),ce.MaterialHelper.PrepareDefinesForFrameBoundValues(n,s,o,!!i,this._forceAlphaTest),ce.MaterialHelper.PrepareDefinesForAttributes(e,o,!0,!0,!0,this._transparencyMode!==ce.PBRMaterial.PBRMATERIAL_OPAQUE)&&e){var l=null;if(e instanceof ce.InstancedMesh?l=e.sourceMesh:e instanceof ce.Mesh&&(l=e),l)if(l.isVerticesDataPresent(ce.VertexBuffer.NormalKind)){var c=l.getVertexBuffer(ce.VertexBuffer.NormalKind),u=c.getData(),p=c.getOffset(),f=c.getStrideSize(),d=p+t.indexStart*f;if(0===u[d]&&0===u[d+1]&&0===u[d+2]&&(o.NORMAL=!1),l.isVerticesDataPresent(ce.VertexBuffer.TangentKind)){var m=l.getVertexBuffer(ce.VertexBuffer.TangentKind),g=m.getData(),_=m.getOffset(),v=m.getStrideSize(),y=_+t.indexStart*v;0===g[y]&&0===g[y+1]&&0===g[y+2]&&(o.TANGENT=!1)}}else n.getEngine().getCaps().standardDerivatives||(l.createNormals(!0),ce.Tools.Warn("PBRMaterial: Normals have been created for the mesh: "+l.name))}if(o.isDirty){o.markAsProcessed(),n.resetCachedMaterial();var b=new ce.EffectFallbacks,x=0;o.USESPHERICALINVERTEX&&b.addFallback(x++,"USESPHERICALINVERTEX"),o.FOG&&b.addFallback(x,"FOG"),o.POINTSIZE&&b.addFallback(x,"POINTSIZE"),o.LOGARITHMICDEPTH&&b.addFallback(x,"LOGARITHMICDEPTH"),o.PARALLAX&&b.addFallback(x,"PARALLAX"),o.PARALLAXOCCLUSION&&b.addFallback(x++,"PARALLAXOCCLUSION"),o.ENVIRONMENTBRDF&&b.addFallback(x++,"ENVIRONMENTBRDF"),o.TANGENT&&b.addFallback(x++,"TANGENT"),o.BUMP&&b.addFallback(x++,"BUMP"),x=ce.MaterialHelper.HandleFallbacksForShadows(o,b,this._maxSimultaneousLights,x++),o.SPECULARTERM&&b.addFallback(x++,"SPECULARTERM"),o.USESPHERICALFROMREFLECTIONMAP&&b.addFallback(x++,"USESPHERICALFROMREFLECTIONMAP"),o.LIGHTMAP&&b.addFallback(x++,"LIGHTMAP"),o.NORMAL&&b.addFallback(x++,"NORMAL"),o.AMBIENT&&b.addFallback(x++,"AMBIENT"),o.EMISSIVE&&b.addFallback(x++,"EMISSIVE"),o.VERTEXCOLOR&&b.addFallback(x++,"VERTEXCOLOR"),o.NUM_BONE_INFLUENCERS>0&&b.addCPUSkinningFallback(x++,e),o.MORPHTARGETS&&b.addFallback(x++,"MORPHTARGETS");var T=[ce.VertexBuffer.PositionKind];o.NORMAL&&T.push(ce.VertexBuffer.NormalKind),o.TANGENT&&T.push(ce.VertexBuffer.TangentKind),o.UV1&&T.push(ce.VertexBuffer.UVKind),o.UV2&&T.push(ce.VertexBuffer.UV2Kind),o.VERTEXCOLOR&&T.push(ce.VertexBuffer.ColorKind),ce.MaterialHelper.PrepareAttributesForBones(T,e,o,b),ce.MaterialHelper.PrepareAttributesForInstances(T,o),ce.MaterialHelper.PrepareAttributesForMorphTargets(T,e,o);var E=["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"],A=["albedoSampler","reflectivitySampler","ambientSampler","emissiveSampler","bumpSampler","lightmapSampler","opacitySampler","refractionSampler","refractionSamplerLow","refractionSamplerHigh","reflectionSampler","reflectionSamplerLow","reflectionSamplerHigh","microSurfaceSampler","environmentBrdfSampler"],P=["Material","Scene"];ce.ImageProcessingConfiguration.PrepareUniforms(E,o),ce.ImageProcessingConfiguration.PrepareSamplers(A,o),ce.MaterialHelper.PrepareUniformsAndSamplersList({uniformsNames:E,uniformBuffersNames:P,samplers:A,defines:o,maxSimultaneousLights:this._maxSimultaneousLights});var M=o.toString();t.setEffect(n.getEngine().createEffect("pbr",{attributes:T,uniformsNames:E,uniformBuffersNames:P,samplers:A,defines:M,fallbacks:b,onCompiled:function(e){r.onCompiled&&r.onCompiled(e),r.bindSceneUniformBuffer(e,n.getSceneUniformBuffer())},onError:this.onError,indexParameters:{maxSimultaneousLights:this._maxSimultaneousLights,maxSimultaneousMorphTargets:o.NUM_MORPH_INFLUENCERS}},s),o),this.buildUniformLayout()}return!(!t.effect||!t.effect.isReady())&&(o._renderId=n.getRenderId(),this._wasPreviouslyReady=!0,!0)},t.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()},t.prototype.unbind=function(){this._reflectionTexture&&this._reflectionTexture.isRenderTarget&&this._uniformBuffer.setTexture("reflectionSampler",null),this._refractionTexture&&this._refractionTexture.isRenderTarget&&this._uniformBuffer.setTexture("refractionSampler",null),e.prototype.unbind.call(this)},t.prototype.bindOnlyWorldMatrix=function(e){this._activeEffect.setMatrix("world",e)},t.prototype.bindForSubMesh=function(e,t,i){var r=this.getScene(),n=i._materialDefines;if(n){var o=i.effect;if(o){this._activeEffect=o,this.bindOnlyWorldMatrix(e);var s=this._mustRebind(r,o,t.visibility);ce.MaterialHelper.BindBonesParameters(t,this._activeEffect);var a=null;if(s){this._uniformBuffer.bindToEffect(o,"Material"),this.bindViewProjection(o),a=this._getReflectionTexture();var h=this._getRefractionTexture();if(!this._uniformBuffer.useUbo||!this.isFrozen||!this._uniformBuffer.isSync){if(r.texturesEnabled){if(this._albedoTexture&&ce.StandardMaterial.DiffuseTextureEnabled&&(this._uniformBuffer.updateFloat2("vAlbedoInfos",this._albedoTexture.coordinatesIndex,this._albedoTexture.level),ce.MaterialHelper.BindTextureMatrix(this._albedoTexture,this._uniformBuffer,"albedo")),this._ambientTexture&&ce.StandardMaterial.AmbientTextureEnabled&&(this._uniformBuffer.updateFloat3("vAmbientInfos",this._ambientTexture.coordinatesIndex,this._ambientTexture.level,this._ambientTextureStrength),ce.MaterialHelper.BindTextureMatrix(this._ambientTexture,this._uniformBuffer,"ambient")),this._opacityTexture&&ce.StandardMaterial.OpacityTextureEnabled&&(this._uniformBuffer.updateFloat2("vOpacityInfos",this._opacityTexture.coordinatesIndex,this._opacityTexture.level),ce.MaterialHelper.BindTextureMatrix(this._opacityTexture,this._uniformBuffer,"opacity")),a&&ce.StandardMaterial.ReflectionTextureEnabled){this._uniformBuffer.updateMatrix("reflectionMatrix",a.getReflectionTextureMatrix()),this._uniformBuffer.updateFloat2("vReflectionInfos",a.level,0);var l=a.sphericalPolynomial;n.USESPHERICALFROMREFLECTIONMAP&&l&&(this._activeEffect.setFloat3("vSphericalX",l.x.x,l.x.y,l.x.z),this._activeEffect.setFloat3("vSphericalY",l.y.x,l.y.y,l.y.z),this._activeEffect.setFloat3("vSphericalZ",l.z.x,l.z.y,l.z.z),this._activeEffect.setFloat3("vSphericalXX_ZZ",l.xx.x-l.zz.x,l.xx.y-l.zz.y,l.xx.z-l.zz.z),this._activeEffect.setFloat3("vSphericalYY_ZZ",l.yy.x-l.zz.x,l.yy.y-l.zz.y,l.yy.z-l.zz.z),this._activeEffect.setFloat3("vSphericalZZ",l.zz.x,l.zz.y,l.zz.z),this._activeEffect.setFloat3("vSphericalXY",l.xy.x,l.xy.y,l.xy.z),this._activeEffect.setFloat3("vSphericalYZ",l.yz.x,l.yz.y,l.yz.z),this._activeEffect.setFloat3("vSphericalZX",l.zx.x,l.zx.y,l.zx.z)),this._uniformBuffer.updateFloat3("vReflectionMicrosurfaceInfos",a.getSize().width,a.lodGenerationScale,a.lodGenerationOffset)}if(this._emissiveTexture&&ce.StandardMaterial.EmissiveTextureEnabled&&(this._uniformBuffer.updateFloat2("vEmissiveInfos",this._emissiveTexture.coordinatesIndex,this._emissiveTexture.level),ce.MaterialHelper.BindTextureMatrix(this._emissiveTexture,this._uniformBuffer,"emissive")),this._lightmapTexture&&ce.StandardMaterial.LightmapTextureEnabled&&(this._uniformBuffer.updateFloat2("vLightmapInfos",this._lightmapTexture.coordinatesIndex,this._lightmapTexture.level),ce.MaterialHelper.BindTextureMatrix(this._lightmapTexture,this._uniformBuffer,"lightmap")),ce.StandardMaterial.SpecularTextureEnabled&&(this._metallicTexture?(this._uniformBuffer.updateFloat3("vReflectivityInfos",this._metallicTexture.coordinatesIndex,this._metallicTexture.level,this._ambientTextureStrength),ce.MaterialHelper.BindTextureMatrix(this._metallicTexture,this._uniformBuffer,"reflectivity")):this._reflectivityTexture&&(this._uniformBuffer.updateFloat3("vReflectivityInfos",this._reflectivityTexture.coordinatesIndex,this._reflectivityTexture.level,1),ce.MaterialHelper.BindTextureMatrix(this._reflectivityTexture,this._uniformBuffer,"reflectivity")),this._microSurfaceTexture&&(this._uniformBuffer.updateFloat2("vMicroSurfaceSamplerInfos",this._microSurfaceTexture.coordinatesIndex,this._microSurfaceTexture.level),ce.MaterialHelper.BindTextureMatrix(this._microSurfaceTexture,this._uniformBuffer,"microSurfaceSampler"))),this._bumpTexture&&r.getEngine().getCaps().standardDerivatives&&ce.StandardMaterial.BumpTextureEnabled&&!this._disableBumpMap&&(this._uniformBuffer.updateFloat3("vBumpInfos",this._bumpTexture.coordinatesIndex,this._bumpTexture.level,this._parallaxScaleBias),ce.MaterialHelper.BindTextureMatrix(this._bumpTexture,this._uniformBuffer,"bump"),r._mirroredCameraPosition?this._uniformBuffer.updateFloat2("vTangentSpaceParams",this._invertNormalMapX?1:-1,this._invertNormalMapY?1:-1):this._uniformBuffer.updateFloat2("vTangentSpaceParams",this._invertNormalMapX?-1:1,this._invertNormalMapY?-1:1)),h&&ce.StandardMaterial.RefractionTextureEnabled){this._uniformBuffer.updateMatrix("refractionMatrix",h.getReflectionTextureMatrix());var c=1;h.isCube||h.depth&&(c=h.depth),this._uniformBuffer.updateFloat4("vRefractionInfos",h.level,this._indexOfRefraction,c,this._invertRefractionY?-1:1),this._uniformBuffer.updateFloat3("vRefractionMicrosurfaceInfos",h.getSize().width,h.lodGenerationScale,h.lodGenerationOffset)}}this.pointsCloud&&this._uniformBuffer.updateFloat("pointSize",this.pointSize),n.METALLICWORKFLOW?(ce.PBRMaterial._scaledReflectivity.r=void 0===this._metallic||null===this._metallic?1:this._metallic,ce.PBRMaterial._scaledReflectivity.g=void 0===this._roughness||null===this._roughness?1:this._roughness,this._uniformBuffer.updateColor4("vReflectivityColor",ce.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*t.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)}r.texturesEnabled&&(this._albedoTexture&&ce.StandardMaterial.DiffuseTextureEnabled&&this._uniformBuffer.setTexture("albedoSampler",this._albedoTexture),this._ambientTexture&&ce.StandardMaterial.AmbientTextureEnabled&&this._uniformBuffer.setTexture("ambientSampler",this._ambientTexture),this._opacityTexture&&ce.StandardMaterial.OpacityTextureEnabled&&this._uniformBuffer.setTexture("opacitySampler",this._opacityTexture),a&&ce.StandardMaterial.ReflectionTextureEnabled&&(n.LODBASEDMICROSFURACE?this._uniformBuffer.setTexture("reflectionSampler",a):(this._uniformBuffer.setTexture("reflectionSampler",a._lodTextureMid||a),this._uniformBuffer.setTexture("reflectionSamplerLow",a._lodTextureLow||a),this._uniformBuffer.setTexture("reflectionSamplerHigh",a._lodTextureHigh||a))),n.ENVIRONMENTBRDF&&this._uniformBuffer.setTexture("environmentBrdfSampler",this._environmentBRDFTexture),h&&ce.StandardMaterial.RefractionTextureEnabled&&(n.LODBASEDMICROSFURACE?this._uniformBuffer.setTexture("refractionSampler",h):(this._uniformBuffer.setTexture("refractionSampler",h._lodTextureMid||h),this._uniformBuffer.setTexture("refractionSamplerLow",h._lodTextureLow||h),this._uniformBuffer.setTexture("refractionSamplerHigh",h._lodTextureHigh||h))),this._emissiveTexture&&ce.StandardMaterial.EmissiveTextureEnabled&&this._uniformBuffer.setTexture("emissiveSampler",this._emissiveTexture),this._lightmapTexture&&ce.StandardMaterial.LightmapTextureEnabled&&this._uniformBuffer.setTexture("lightmapSampler",this._lightmapTexture),ce.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&&r.getEngine().getCaps().standardDerivatives&&ce.StandardMaterial.BumpTextureEnabled&&!this._disableBumpMap&&this._uniformBuffer.setTexture("bumpSampler",this._bumpTexture)),ce.MaterialHelper.BindClipPlane(this._activeEffect,r),r.ambientColor.multiplyToRef(this._ambientColor,this._globalAmbientColor);var u=r._forcedViewPosition?r._forcedViewPosition:r._mirroredCameraPosition?r._mirroredCameraPosition:r.activeCamera.globalPosition,p=r.useRightHandedSystem===(null!=r._mirroredCameraPosition);o.setFloat4("vEyePosition",u.x,u.y,u.z,p?-1:1),o.setColor3("vAmbientColor",this._globalAmbientColor)}!s&&this.isFrozen||(r.lightsEnabled&&!this._disableLighting&&ce.MaterialHelper.BindLights(r,t,this._activeEffect,n,this._maxSimultaneousLights,this._usePhysicalLightFalloff),(r.fogEnabled&&t.applyFog&&r.fogMode!==ce.Scene.FOGMODE_NONE||a)&&this.bindView(o),ce.MaterialHelper.BindFogParameters(r,t,this._activeEffect),n.NUM_MORPH_INFLUENCERS&&ce.MaterialHelper.BindMorphTargetParameters(t,this._activeEffect),this._imageProcessingConfiguration.bind(this._activeEffect),ce.MaterialHelper.BindLogDepth(n,this._activeEffect,r)),this._uniformBuffer.update(),this._afterBind(t)}}},t.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},t.prototype._getReflectionTexture=function(){return this._reflectionTexture?this._reflectionTexture:this.getScene().environmentTexture},t.prototype._getRefractionTexture=function(){return this._refractionTexture?this._refractionTexture:this._linkRefractionWithTransparency?this.getScene().environmentTexture:null},t.prototype.dispose=function(t,i){i&&(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),e.prototype.dispose.call(this,t,i)},t._scaledReflectivity=new ce.Color3,X([ce.serializeAsImageProcessingConfiguration()],t.prototype,"_imageProcessingConfiguration",void 0),X([ce.serialize()],t.prototype,"useLogarithmicDepth",null),X([ce.serialize()],t.prototype,"transparencyMode",null),t}(ce.PushMaterial),ce.PBRBaseMaterial=pe,fe=us||(us={}),de=function(e){function t(t,i){var r=e.call(this,t,i)||this;return r.maxSimultaneousLights=4,r.disableLighting=!1,r.invertNormalMapX=!1,r.invertNormalMapY=!1,r.emissiveColor=new fe.Color3(0,0,0),r.occlusionStrength=1,r.useLightmapAsShadowmap=!1,r._useAlphaFromAlbedoTexture=!0,r._useAmbientInGrayScale=!0,r}return Y(t,e),Object.defineProperty(t.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}),t.prototype.getActiveTextures=function(){var t=e.prototype.getActiveTextures.call(this);return this.environmentTexture&&t.push(this.environmentTexture),this.normalTexture&&t.push(this.normalTexture),this.emissiveTexture&&t.push(this.emissiveTexture),this.occlusionTexture&&t.push(this.occlusionTexture),this.lightmapTexture&&t.push(this.lightmapTexture),t},t.prototype.hasTexture=function(t){return!!e.prototype.hasTexture.call(this,t)||this.lightmapTexture===t},t.prototype.getClassName=function(){return"PBRBaseSimpleMaterial"},X([fe.serialize(),fe.expandToProperty("_markAllSubMeshesAsLightsDirty")],t.prototype,"maxSimultaneousLights",void 0),X([fe.serialize(),fe.expandToProperty("_markAllSubMeshesAsLightsDirty")],t.prototype,"disableLighting",void 0),X([fe.serializeAsTexture(),fe.expandToProperty("_markAllSubMeshesAsTexturesDirty","_reflectionTexture")],t.prototype,"environmentTexture",void 0),X([fe.serialize(),fe.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"invertNormalMapX",void 0),X([fe.serialize(),fe.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"invertNormalMapY",void 0),X([fe.serializeAsTexture(),fe.expandToProperty("_markAllSubMeshesAsTexturesDirty","_bumpTexture")],t.prototype,"normalTexture",void 0),X([fe.serializeAsColor3("emissive"),fe.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"emissiveColor",void 0),X([fe.serializeAsTexture(),fe.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"emissiveTexture",void 0),X([fe.serialize(),fe.expandToProperty("_markAllSubMeshesAsTexturesDirty","_ambientTextureStrength")],t.prototype,"occlusionStrength",void 0),X([fe.serializeAsTexture(),fe.expandToProperty("_markAllSubMeshesAsTexturesDirty","_ambientTexture")],t.prototype,"occlusionTexture",void 0),X([fe.serialize(),fe.expandToProperty("_markAllSubMeshesAsTexturesDirty","_alphaCutOff")],t.prototype,"alphaCutOff",void 0),X([fe.serialize()],t.prototype,"doubleSided",null),X([fe.serializeAsTexture(),fe.expandToProperty("_markAllSubMeshesAsTexturesDirty",null)],t.prototype,"lightmapTexture",void 0),X([fe.serialize(),fe.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"useLightmapAsShadowmap",void 0),t}(fe.PBRBaseMaterial),fe.PBRBaseSimpleMaterial=de,me=us||(us={}),ge=function(e){function t(t,i){var r=e.call(this,t,i)||this;return r.directIntensity=1,r.emissiveIntensity=1,r.environmentIntensity=1,r.specularIntensity=1,r.disableBumpMap=!1,r.ambientTextureStrength=1,r.ambientColor=new me.Color3(0,0,0),r.albedoColor=new me.Color3(1,1,1),r.reflectivityColor=new me.Color3(1,1,1),r.reflectionColor=new me.Color3(1,1,1),r.emissiveColor=new me.Color3(0,0,0),r.microSurface=1,r.indexOfRefraction=.66,r.invertRefractionY=!1,r.linkRefractionWithTransparency=!1,r.useLightmapAsShadowmap=!1,r.useAlphaFromAlbedoTexture=!1,r.forceAlphaTest=!1,r.alphaCutOff=.4,r.useSpecularOverAlpha=!0,r.useMicroSurfaceFromReflectivityMapAlpha=!1,r.useRoughnessFromMetallicTextureAlpha=!0,r.useRoughnessFromMetallicTextureGreen=!1,r.useMetallnessFromMetallicTextureBlue=!1,r.useAmbientOcclusionFromMetallicTextureRed=!1,r.useAmbientInGrayScale=!1,r.useAutoMicroSurfaceFromReflectivityMap=!1,r.usePhysicalLightFalloff=!0,r.useRadianceOverAlpha=!0,r.useParallax=!1,r.useParallaxOcclusion=!1,r.parallaxScaleBias=.05,r.disableLighting=!1,r.forceIrradianceInFragment=!1,r.maxSimultaneousLights=4,r.invertNormalMapX=!1,r.invertNormalMapY=!1,r.twoSidedLighting=!1,r.useAlphaFresnel=!1,r.useLinearAlphaFresnel=!1,r.environmentBRDFTexture=null,r.forceNormalForward=!1,r.useHorizonOcclusion=!0,r.useRadianceOcclusion=!0,r._environmentBRDFTexture=me.TextureTools.GetEnvironmentBRDFTexture(i),r}return Y(t,e),Object.defineProperty(t,"PBRMATERIAL_OPAQUE",{get:function(){return this._PBRMATERIAL_OPAQUE},enumerable:!0,configurable:!0}),Object.defineProperty(t,"PBRMATERIAL_ALPHATEST",{get:function(){return this._PBRMATERIAL_ALPHATEST},enumerable:!0,configurable:!0}),Object.defineProperty(t,"PBRMATERIAL_ALPHABLEND",{get:function(){return this._PBRMATERIAL_ALPHABLEND},enumerable:!0,configurable:!0}),Object.defineProperty(t,"PBRMATERIAL_ALPHATESTANDBLEND",{get:function(){return this._PBRMATERIAL_ALPHATESTANDBLEND},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"imageProcessingConfiguration",{get:function(){return this._imageProcessingConfiguration},set:function(e){this._attachImageProcessingConfiguration(e),this._markAllSubMeshesAsTexturesDirty()},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"cameraColorCurvesEnabled",{get:function(){return this.imageProcessingConfiguration.colorCurvesEnabled},set:function(e){this.imageProcessingConfiguration.colorCurvesEnabled=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"cameraColorGradingEnabled",{get:function(){return this.imageProcessingConfiguration.colorGradingEnabled},set:function(e){this.imageProcessingConfiguration.colorGradingEnabled=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"cameraToneMappingEnabled",{get:function(){return this._imageProcessingConfiguration.toneMappingEnabled},set:function(e){this._imageProcessingConfiguration.toneMappingEnabled=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"cameraExposure",{get:function(){return this._imageProcessingConfiguration.exposure},set:function(e){this._imageProcessingConfiguration.exposure=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"cameraContrast",{get:function(){return this._imageProcessingConfiguration.contrast},set:function(e){this._imageProcessingConfiguration.contrast=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"cameraColorGradingTexture",{get:function(){return this._imageProcessingConfiguration.colorGradingTexture},set:function(e){this._imageProcessingConfiguration.colorGradingTexture=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"cameraColorCurves",{get:function(){return this._imageProcessingConfiguration.colorCurves},set:function(e){this._imageProcessingConfiguration.colorCurves=e},enumerable:!0,configurable:!0}),t.prototype.getClassName=function(){return"PBRMaterial"},t.prototype.getActiveTextures=function(){var t=e.prototype.getActiveTextures.call(this);return this._albedoTexture&&t.push(this._albedoTexture),this._ambientTexture&&t.push(this._ambientTexture),this._opacityTexture&&t.push(this._opacityTexture),this._reflectionTexture&&t.push(this._reflectionTexture),this._emissiveTexture&&t.push(this._emissiveTexture),this._reflectivityTexture&&t.push(this._reflectivityTexture),this._metallicTexture&&t.push(this._metallicTexture),this._microSurfaceTexture&&t.push(this._microSurfaceTexture),this._bumpTexture&&t.push(this._bumpTexture),this._lightmapTexture&&t.push(this._lightmapTexture),this._refractionTexture&&t.push(this._refractionTexture),t},t.prototype.hasTexture=function(t){return!!e.prototype.hasTexture.call(this,t)||(this._albedoTexture===t||(this._ambientTexture===t||(this._opacityTexture===t||(this._reflectionTexture===t||(this._reflectivityTexture===t||(this._metallicTexture===t||(this._microSurfaceTexture===t||(this._bumpTexture===t||(this._lightmapTexture===t||this._refractionTexture===t)))))))))},t.prototype.clone=function(e){var i=this,r=me.SerializationHelper.Clone(function(){return new t(e,i.getScene())},this);return r.id=e,r.name=e,r},t.prototype.serialize=function(){var e=me.SerializationHelper.Serialize(this);return e.customType="BABYLON.PBRMaterial",e},t.Parse=function(e,i,r){return me.SerializationHelper.Parse(function(){return new t(e.name,i)},e,i,r)},t._PBRMATERIAL_OPAQUE=0,t._PBRMATERIAL_ALPHATEST=1,t._PBRMATERIAL_ALPHABLEND=2,t._PBRMATERIAL_ALPHATESTANDBLEND=3,X([me.serialize(),me.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"directIntensity",void 0),X([me.serialize(),me.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"emissiveIntensity",void 0),X([me.serialize(),me.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"environmentIntensity",void 0),X([me.serialize(),me.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"specularIntensity",void 0),X([me.serialize(),me.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"disableBumpMap",void 0),X([me.serializeAsTexture(),me.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"albedoTexture",void 0),X([me.serializeAsTexture(),me.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"ambientTexture",void 0),X([me.serialize(),me.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"ambientTextureStrength",void 0),X([me.serializeAsTexture(),me.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"opacityTexture",void 0),X([me.serializeAsTexture(),me.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"reflectionTexture",void 0),X([me.serializeAsTexture(),me.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"emissiveTexture",void 0),X([me.serializeAsTexture(),me.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"reflectivityTexture",void 0),X([me.serializeAsTexture(),me.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"metallicTexture",void 0),X([me.serialize(),me.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"metallic",void 0),X([me.serialize(),me.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"roughness",void 0),X([me.serializeAsTexture(),me.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"microSurfaceTexture",void 0),X([me.serializeAsTexture(),me.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"bumpTexture",void 0),X([me.serializeAsTexture(),me.expandToProperty("_markAllSubMeshesAsTexturesDirty",null)],t.prototype,"lightmapTexture",void 0),X([me.serializeAsTexture(),me.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"refractionTexture",void 0),X([me.serializeAsColor3("ambient"),me.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"ambientColor",void 0),X([me.serializeAsColor3("albedo"),me.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"albedoColor",void 0),X([me.serializeAsColor3("reflectivity"),me.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"reflectivityColor",void 0),X([me.serializeAsColor3("reflection"),me.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"reflectionColor",void 0),X([me.serializeAsColor3("emissive"),me.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"emissiveColor",void 0),X([me.serialize(),me.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"microSurface",void 0),X([me.serialize(),me.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"indexOfRefraction",void 0),X([me.serialize(),me.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"invertRefractionY",void 0),X([me.serialize(),me.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"linkRefractionWithTransparency",void 0),X([me.serialize(),me.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"useLightmapAsShadowmap",void 0),X([me.serialize(),me.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"useAlphaFromAlbedoTexture",void 0),X([me.serialize(),me.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"forceAlphaTest",void 0),X([me.serialize(),me.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"alphaCutOff",void 0),X([me.serialize(),me.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"useSpecularOverAlpha",void 0),X([me.serialize(),me.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"useMicroSurfaceFromReflectivityMapAlpha",void 0),X([me.serialize(),me.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"useRoughnessFromMetallicTextureAlpha",void 0),X([me.serialize(),me.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"useRoughnessFromMetallicTextureGreen",void 0),X([me.serialize(),me.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"useMetallnessFromMetallicTextureBlue",void 0),X([me.serialize(),me.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"useAmbientOcclusionFromMetallicTextureRed",void 0),X([me.serialize(),me.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"useAmbientInGrayScale",void 0),X([me.serialize(),me.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"useAutoMicroSurfaceFromReflectivityMap",void 0),X([me.serialize(),me.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"usePhysicalLightFalloff",void 0),X([me.serialize(),me.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"useRadianceOverAlpha",void 0),X([me.serialize(),me.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"useParallax",void 0),X([me.serialize(),me.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"useParallaxOcclusion",void 0),X([me.serialize(),me.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"parallaxScaleBias",void 0),X([me.serialize(),me.expandToProperty("_markAllSubMeshesAsLightsDirty")],t.prototype,"disableLighting",void 0),X([me.serialize(),me.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"forceIrradianceInFragment",void 0),X([me.serialize(),me.expandToProperty("_markAllSubMeshesAsLightsDirty")],t.prototype,"maxSimultaneousLights",void 0),X([me.serialize(),me.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"invertNormalMapX",void 0),X([me.serialize(),me.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"invertNormalMapY",void 0),X([me.serialize(),me.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"twoSidedLighting",void 0),X([me.serialize(),me.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"useAlphaFresnel",void 0),X([me.serialize(),me.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"useLinearAlphaFresnel",void 0),X([me.serializeAsTexture(),me.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"environmentBRDFTexture",void 0),X([me.serialize(),me.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"forceNormalForward",void 0),X([me.serialize(),me.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"useHorizonOcclusion",void 0),X([me.serialize(),me.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"useRadianceOcclusion",void 0),t}(me.PBRBaseMaterial),me.PBRMaterial=ge,_e=us||(us={}),ve=function(e){function t(t,i){var r=e.call(this,t,i)||this;return r._useRoughnessFromMetallicTextureAlpha=!1,r._useRoughnessFromMetallicTextureGreen=!0,r._useMetallnessFromMetallicTextureBlue=!0,r._forceMetallicWorkflow=!0,r}return Y(t,e),t.prototype.getClassName=function(){return"PBRMetallicRoughnessMaterial"},t.prototype.getActiveTextures=function(){var t=e.prototype.getActiveTextures.call(this);return this.baseTexture&&t.push(this.baseTexture),this.metallicRoughnessTexture&&t.push(this.metallicRoughnessTexture),t},t.prototype.hasTexture=function(t){return!!e.prototype.hasTexture.call(this,t)||(this.baseTexture===t||this.metallicRoughnessTexture===t)},t.prototype.clone=function(e){var i=this,r=_e.SerializationHelper.Clone(function(){return new t(e,i.getScene())},this);return r.id=e,r.name=e,r},t.prototype.serialize=function(){var e=_e.SerializationHelper.Serialize(this);return e.customType="BABYLON.PBRMetallicRoughnessMaterial",e},t.Parse=function(e,i,r){return _e.SerializationHelper.Parse(function(){return new t(e.name,i)},e,i,r)},X([_e.serializeAsColor3(),_e.expandToProperty("_markAllSubMeshesAsTexturesDirty","_albedoColor")],t.prototype,"baseColor",void 0),X([_e.serializeAsTexture(),_e.expandToProperty("_markAllSubMeshesAsTexturesDirty","_albedoTexture")],t.prototype,"baseTexture",void 0),X([_e.serialize(),_e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"metallic",void 0),X([_e.serialize(),_e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"roughness",void 0),X([_e.serializeAsTexture(),_e.expandToProperty("_markAllSubMeshesAsTexturesDirty","_metallicTexture")],t.prototype,"metallicRoughnessTexture",void 0),t}(_e.PBRBaseSimpleMaterial),_e.PBRMetallicRoughnessMaterial=ve,ye=us||(us={}),be=function(e){function t(t,i){var r=e.call(this,t,i)||this;return r._useMicroSurfaceFromReflectivityMapAlpha=!0,r}return Y(t,e),t.prototype.getClassName=function(){return"PBRSpecularGlossinessMaterial"},t.prototype.getActiveTextures=function(){var t=e.prototype.getActiveTextures.call(this);return this.diffuseTexture&&t.push(this.diffuseTexture),this.specularGlossinessTexture&&t.push(this.specularGlossinessTexture),t},t.prototype.hasTexture=function(t){return!!e.prototype.hasTexture.call(this,t)||(this.diffuseTexture===t||this.specularGlossinessTexture===t)},t.prototype.clone=function(e){var i=this,r=ye.SerializationHelper.Clone(function(){return new t(e,i.getScene())},this);return r.id=e,r.name=e,r},t.prototype.serialize=function(){var e=ye.SerializationHelper.Serialize(this);return e.customType="BABYLON.PBRSpecularGlossinessMaterial",e},t.Parse=function(e,i,r){return ye.SerializationHelper.Parse(function(){return new t(e.name,i)},e,i,r)},X([ye.serializeAsColor3("diffuse"),ye.expandToProperty("_markAllSubMeshesAsTexturesDirty","_albedoColor")],t.prototype,"diffuseColor",void 0),X([ye.serializeAsTexture(),ye.expandToProperty("_markAllSubMeshesAsTexturesDirty","_albedoTexture")],t.prototype,"diffuseTexture",void 0),X([ye.serializeAsColor3("specular"),ye.expandToProperty("_markAllSubMeshesAsTexturesDirty","_reflectivityColor")],t.prototype,"specularColor",void 0),X([ye.serialize(),ye.expandToProperty("_markAllSubMeshesAsTexturesDirty","_microSurface")],t.prototype,"glossiness",void 0),X([ye.serializeAsTexture(),ye.expandToProperty("_markAllSubMeshesAsTexturesDirty","_reflectivityTexture")],t.prototype,"specularGlossinessTexture",void 0),t}(ye.PBRBaseSimpleMaterial),ye.PBRSpecularGlossinessMaterial=be,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;if(s=e.CameraInputTypes[this.attached[r].getClassName()]){o=e.SerializationHelper.Parse(function(){return new s},t,null);this.remove(this.attached[r]),this.add(o)}}},t}();e.CameraInputsManager=t}(us||(us={})),xe=us||(us={}),Te=function(e){function t(t,i,r){var n=e.call(this,t,i,r)||this;return n.cameraDirection=new xe.Vector3(0,0,0),n.cameraRotation=new xe.Vector2(0,0),n.rotation=new xe.Vector3(0,0,0),n.speed=2,n.noRotationConstraint=!1,n.lockedTarget=null,n._currentTarget=xe.Vector3.Zero(),n._viewMatrix=xe.Matrix.Zero(),n._camMatrix=xe.Matrix.Zero(),n._cameraTransformMatrix=xe.Matrix.Zero(),n._cameraRotationMatrix=xe.Matrix.Zero(),n._referencePoint=new xe.Vector3(0,0,1),n._currentUpVector=new xe.Vector3(0,1,0),n._transformedReferencePoint=xe.Vector3.Zero(),n._lookAtTemp=xe.Matrix.Zero(),n._tempMatrix=xe.Matrix.Zero(),n}return Y(t,e),t.prototype.getFrontPosition=function(e){this.getWorldMatrix();var t=this.getTarget().subtract(this.position);return t.normalize(),t.scaleInPlace(e),this.globalPosition.add(t)},t.prototype._getLockedTargetPosition=function(){return this.lockedTarget?(this.lockedTarget.absolutePosition&&this.lockedTarget.computeWorldMatrix(),this.lockedTarget.absolutePosition||this.lockedTarget):null},t.prototype.storeState=function(){return this._storedPosition=this.position.clone(),this._storedRotation=this.rotation.clone(),this.rotationQuaternion&&(this._storedRotationQuaternion=this.rotationQuaternion.clone()),e.prototype.storeState.call(this)},t.prototype._restoreStateValues=function(){return!!e.prototype._restoreStateValues.call(this)&&(this.position=this._storedPosition.clone(),this.rotation=this._storedRotation.clone(),this.rotationQuaternion&&(this.rotationQuaternion=this._storedRotationQuaternion.clone()),this.cameraDirection.copyFromFloats(0,0,0),this.cameraRotation.copyFromFloats(0,0),!0)},t.prototype._initCache=function(){e.prototype._initCache.call(this),this._cache.lockedTarget=new xe.Vector3(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),this._cache.rotation=new xe.Vector3(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),this._cache.rotationQuaternion=new xe.Quaternion(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE)},t.prototype._updateCache=function(t){t||e.prototype._updateCache.call(this);var i=this._getLockedTargetPosition();i?this._cache.lockedTarget?this._cache.lockedTarget.copyFrom(i):this._cache.lockedTarget=i.clone():this._cache.lockedTarget=null,this._cache.rotation.copyFrom(this.rotation),this.rotationQuaternion&&this._cache.rotationQuaternion.copyFrom(this.rotationQuaternion)},t.prototype._isSynchronizedViewMatrix=function(){if(!e.prototype._isSynchronizedViewMatrix.call(this))return!1;var t=this._getLockedTargetPosition();return(this._cache.lockedTarget?this._cache.lockedTarget.equals(t):!t)&&(this.rotationQuaternion?this.rotationQuaternion.equals(this._cache.rotationQuaternion):this._cache.rotation.equals(this.rotation))},t.prototype._computeLocalCameraSpeed=function(){var e=this.getEngine();return this.speed*Math.sqrt(e.getDeltaTime()/(100*e.getFps()))},t.prototype.setTarget=function(e){this.upVector.normalize(),xe.Matrix.LookAtLHToRef(this.position,e,this.upVector,this._camMatrix),this._camMatrix.invert(),this.rotation.x=Math.atan(this._camMatrix.m[6]/this._camMatrix.m[10]);var t=e.subtract(this.position);t.x>=0?this.rotation.y=-Math.atan(t.z/t.x)+Math.PI/2:this.rotation.y=-Math.atan(t.z/t.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&&xe.Quaternion.RotationYawPitchRollToRef(this.rotation.y,this.rotation.x,this.rotation.z,this.rotationQuaternion)},t.prototype.getTarget=function(){return this._currentTarget},t.prototype._decideIfNeedsToMove=function(){return Math.abs(this.cameraDirection.x)>0||Math.abs(this.cameraDirection.y)>0||Math.abs(this.cameraDirection.z)>0},t.prototype._updatePosition=function(){if(this.parent)return this.parent.getWorldMatrix().invertToRef(xe.Tmp.Matrix[0]),xe.Vector3.TransformNormalToRef(this.cameraDirection,xe.Tmp.Matrix[0],xe.Tmp.Vector3[0]),void this.position.addInPlace(xe.Tmp.Vector3[0]);this.position.addInPlace(this.cameraDirection)},t.prototype._checkInputs=function(){var t=this._decideIfNeedsToMove(),i=Math.abs(this.cameraRotation.x)>0||Math.abs(this.cameraRotation.y)>0;if(t&&this._updatePosition(),i){if(this.rotation.x+=this.cameraRotation.x,this.rotation.y+=this.cameraRotation.y,this.rotationQuaternion)this.rotation.lengthSquared()&&xe.Quaternion.RotationYawPitchRollToRef(this.rotation.y,this.rotation.x,this.rotation.z,this.rotationQuaternion);if(!this.noRotationConstraint){var r=Math.PI/2*.95;this.rotation.x>r&&(this.rotation.x=r),this.rotation.x<-r&&(this.rotation.x=-r)}}t&&(Math.abs(this.cameraDirection.x)<this.speed*xe.Epsilon&&(this.cameraDirection.x=0),Math.abs(this.cameraDirection.y)<this.speed*xe.Epsilon&&(this.cameraDirection.y=0),Math.abs(this.cameraDirection.z)<this.speed*xe.Epsilon&&(this.cameraDirection.z=0),this.cameraDirection.scaleInPlace(this.inertia)),i&&(Math.abs(this.cameraRotation.x)<this.speed*xe.Epsilon&&(this.cameraRotation.x=0),Math.abs(this.cameraRotation.y)<this.speed*xe.Epsilon&&(this.cameraRotation.y=0),this.cameraRotation.scaleInPlace(this.inertia)),e.prototype._checkInputs.call(this)},t.prototype._updateCameraRotationMatrix=function(){this.rotationQuaternion?this.rotationQuaternion.toRotationMatrix(this._cameraRotationMatrix):xe.Matrix.RotationYawPitchRollToRef(this.rotation.y,this.rotation.x,this.rotation.z,this._cameraRotationMatrix),xe.Vector3.TransformNormalToRef(this.upVector,this._cameraRotationMatrix,this._currentUpVector)},t.prototype._getViewMatrix=function(){return this.lockedTarget&&this.setTarget(this._getLockedTargetPosition()),this._updateCameraRotationMatrix(),xe.Vector3.TransformCoordinatesToRef(this._referencePoint,this._cameraRotationMatrix,this._transformedReferencePoint),this.position.addToRef(this._transformedReferencePoint,this._currentTarget),this.getScene().useRightHandedSystem?xe.Matrix.LookAtRHToRef(this.position,this._currentTarget,this._currentUpVector,this._viewMatrix):xe.Matrix.LookAtLHToRef(this.position,this._currentTarget,this._currentUpVector,this._viewMatrix),this._viewMatrix},t.prototype.createRigCamera=function(e,i){if(this.cameraRigMode!==xe.Camera.RIG_MODE_NONE){var r=new t(e,this.position.clone(),this.getScene());return this.cameraRigMode!==xe.Camera.RIG_MODE_VR&&this.cameraRigMode!==xe.Camera.RIG_MODE_WEBVR||(this.rotationQuaternion||(this.rotationQuaternion=new xe.Quaternion),r._cameraRigParams={},r.rotationQuaternion=new xe.Quaternion),r}return null},t.prototype._updateRigCameras=function(){var t=this._rigCameras[0],i=this._rigCameras[1];switch(this.cameraRigMode){case xe.Camera.RIG_MODE_STEREOSCOPIC_ANAGLYPH:case xe.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL:case xe.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED:case xe.Camera.RIG_MODE_STEREOSCOPIC_OVERUNDER:var r=this.cameraRigMode===xe.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED?1:-1,n=this.cameraRigMode===xe.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED?-1:1;this._getRigCamPosition(this._cameraRigParams.stereoHalfAngle*r,t.position),this._getRigCamPosition(this._cameraRigParams.stereoHalfAngle*n,i.position),t.setTarget(this.getTarget()),i.setTarget(this.getTarget());break;case xe.Camera.RIG_MODE_VR:t.rotationQuaternion?(t.rotationQuaternion.copyFrom(this.rotationQuaternion),i.rotationQuaternion.copyFrom(this.rotationQuaternion)):(t.rotation.copyFrom(this.rotation),i.rotation.copyFrom(this.rotation)),t.position.copyFrom(this.position),i.position.copyFrom(this.position)}e.prototype._updateRigCameras.call(this)},t.prototype._getRigCamPosition=function(e,t){this._rigCamTransformMatrix||(this._rigCamTransformMatrix=new xe.Matrix);var i=this.getTarget();xe.Matrix.Translation(-i.x,-i.y,-i.z).multiplyToRef(xe.Matrix.RotationY(e),this._rigCamTransformMatrix),this._rigCamTransformMatrix=this._rigCamTransformMatrix.multiply(xe.Matrix.Translation(i.x,i.y,i.z)),xe.Vector3.TransformCoordinatesToRef(this.position,this._rigCamTransformMatrix,t)},t.prototype.getClassName=function(){return"TargetCamera"},X([xe.serializeAsVector3()],t.prototype,"rotation",void 0),X([xe.serialize()],t.prototype,"speed",void 0),X([xe.serializeAsMeshReference("lockedTargetId")],t.prototype,"lockedTarget",void 0),t}(xe.Camera),xe.TargetCamera=Te,Ee=us||(us={}),Ae=function(){function e(e){void 0===e&&(e=!0),this.touchEnabled=e,this.buttons=[0,1,2],this.angularSensibility=2e3,this.previousPosition=null}return e.prototype.attachControl=function(e,t){var i=this,r=this.camera.getEngine();this._pointerInput||(this._pointerInput=function(n,o){var s=n.event;if(!r.isInVRExclusivePointerMode&&(i.touchEnabled||"touch"!==s.pointerType)&&(n.type===Ee.PointerEventTypes.POINTERMOVE||-1!==i.buttons.indexOf(s.button))){var a=s.srcElement||s.target;if(n.type===Ee.PointerEventTypes.POINTERDOWN&&a){try{a.setPointerCapture(s.pointerId)}catch(e){}i.previousPosition={x:s.clientX,y:s.clientY},t||(s.preventDefault(),e.focus())}else if(n.type===Ee.PointerEventTypes.POINTERUP&&a){try{a.releasePointerCapture(s.pointerId)}catch(e){}i.previousPosition=null,t||s.preventDefault()}else if(n.type===Ee.PointerEventTypes.POINTERMOVE){if(!i.previousPosition||r.isPointerLock)return;var h=s.clientX-i.previousPosition.x,l=s.clientY-i.previousPosition.y;i.camera.getScene().useRightHandedSystem?i.camera.cameraRotation.y-=h/i.angularSensibility:i.camera.cameraRotation.y+=h/i.angularSensibility,i.camera.cameraRotation.x+=l/i.angularSensibility,i.previousPosition={x:s.clientX,y:s.clientY},t||s.preventDefault()}}}),this._onMouseMove=function(e){if(r.isPointerLock&&!r.isInVRExclusivePointerMode){var n=e.movementX||e.mozMovementX||e.webkitMovementX||e.msMovementX||0,o=e.movementY||e.mozMovementY||e.webkitMovementY||e.msMovementY||0;i.camera.getScene().useRightHandedSystem?i.camera.cameraRotation.y-=n/i.angularSensibility:i.camera.cameraRotation.y+=n/i.angularSensibility,i.camera.cameraRotation.x+=o/i.angularSensibility,i.previousPosition=null,t||e.preventDefault()}},this._observer=this.camera.getScene().onPointerObservable.add(this._pointerInput,Ee.PointerEventTypes.POINTERDOWN|Ee.PointerEventTypes.POINTERUP|Ee.PointerEventTypes.POINTERMOVE),e.addEventListener("mousemove",this._onMouseMove,!1)},e.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)},e.prototype.getClassName=function(){return"FreeCameraMouseInput"},e.prototype.getSimpleName=function(){return"mouse"},X([Ee.serialize()],e.prototype,"buttons",void 0),X([Ee.serialize()],e.prototype,"angularSensibility",void 0),e}(),Ee.FreeCameraMouseInput=Ae,Ee.CameraInputTypes.FreeCameraMouseInput=Ae,Pe=us||(us={}),Me=function(){function e(){this._keys=new Array,this.keysUp=[38],this.keysDown=[40],this.keysLeft=[37],this.keysRight=[39]}return e.prototype.attachControl=function(e,t){var i=this;this._onCanvasBlurObserver||(this._scene=this.camera.getScene(),this._engine=this._scene.getEngine(),this._onCanvasBlurObserver=this._engine.onCanvasBlurObservable.add(function(){i._keys=[]}),this._onKeyboardObserver=this._scene.onKeyboardObservable.add(function(e){var r,n=e.event;e.type===Pe.KeyboardEventTypes.KEYDOWN?-1===i.keysUp.indexOf(n.keyCode)&&-1===i.keysDown.indexOf(n.keyCode)&&-1===i.keysLeft.indexOf(n.keyCode)&&-1===i.keysRight.indexOf(n.keyCode)||(-1===(r=i._keys.indexOf(n.keyCode))&&i._keys.push(n.keyCode),t||n.preventDefault()):-1===i.keysUp.indexOf(n.keyCode)&&-1===i.keysDown.indexOf(n.keyCode)&&-1===i.keysLeft.indexOf(n.keyCode)&&-1===i.keysRight.indexOf(n.keyCode)||((r=i._keys.indexOf(n.keyCode))>=0&&i._keys.splice(r,1),t||n.preventDefault())}))},e.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=[]},e.prototype.checkInputs=function(){if(this._onKeyboardObserver)for(var e=this.camera,t=0;t<this._keys.length;t++){var i=this._keys[t],r=e._computeLocalCameraSpeed();-1!==this.keysLeft.indexOf(i)?e._localDirection.copyFromFloats(-r,0,0):-1!==this.keysUp.indexOf(i)?e._localDirection.copyFromFloats(0,0,r):-1!==this.keysRight.indexOf(i)?e._localDirection.copyFromFloats(r,0,0):-1!==this.keysDown.indexOf(i)&&e._localDirection.copyFromFloats(0,0,-r),e.getScene().useRightHandedSystem&&(e._localDirection.z*=-1),e.getViewMatrix().invertToRef(e._cameraTransformMatrix),Pe.Vector3.TransformNormalToRef(e._localDirection,e._cameraTransformMatrix,e._transformedDirection),e.cameraDirection.addInPlace(e._transformedDirection)}},e.prototype.getClassName=function(){return"FreeCameraKeyboardMoveInput"},e.prototype._onLostFocus=function(e){this._keys=[]},e.prototype.getSimpleName=function(){return"keyboard"},X([Pe.serialize()],e.prototype,"keysUp",void 0),X([Pe.serialize()],e.prototype,"keysDown",void 0),X([Pe.serialize()],e.prototype,"keysLeft",void 0),X([Pe.serialize()],e.prototype,"keysRight",void 0),e}(),Pe.FreeCameraKeyboardMoveInput=Me,Pe.CameraInputTypes.FreeCameraKeyboardMoveInput=Me,Se=us||(us={}),Ce=function(e){function t(t){return e.call(this,t)||this}return Y(t,e),t.prototype.addKeyboard=function(){return this.add(new Se.FreeCameraKeyboardMoveInput),this},t.prototype.addMouse=function(e){return void 0===e&&(e=!0),this.add(new Se.FreeCameraMouseInput(e)),this},t.prototype.addGamepad=function(){return this.add(new Se.FreeCameraGamepadInput),this},t.prototype.addDeviceOrientation=function(){return this.add(new Se.FreeCameraDeviceOrientationInput),this},t.prototype.addTouch=function(){return this.add(new Se.FreeCameraTouchInput),this},t.prototype.addVirtualJoystick=function(){return this.add(new Se.FreeCameraVirtualJoystickInput),this},t}(Se.CameraInputsManager),Se.FreeCameraInputsManager=Ce,Re=us||(us={}),Oe=function(e){function t(t,i,r){var n=e.call(this,t,i,r)||this;return n.ellipsoid=new Re.Vector3(.5,1,.5),n.ellipsoidOffset=new Re.Vector3(0,0,0),n.checkCollisions=!1,n.applyGravity=!1,n._needMoveForGravity=!1,n._oldPosition=Re.Vector3.Zero(),n._diffPosition=Re.Vector3.Zero(),n._newPosition=Re.Vector3.Zero(),n._collisionMask=-1,n._onCollisionPositionChange=function(e,t,i){void 0===i&&(i=null),n.getScene().workerCollisions&&t.multiplyInPlace(n._collider._radius);var r;r=t,n._newPosition.copyFrom(r),n._newPosition.subtractToRef(n._oldPosition,n._diffPosition),n._diffPosition.length()>Re.Engine.CollisionsEpsilon&&(n.position.addInPlace(n._diffPosition),n.onCollide&&i&&n.onCollide(i))},n.inputs=new Re.FreeCameraInputsManager(n),n.inputs.addKeyboard().addMouse(),n}return Y(t,e),Object.defineProperty(t.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(t.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(t.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(t.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(t.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}),t.prototype.attachControl=function(e,t){this.inputs.attachElement(e,t)},t.prototype.detachControl=function(e){this.inputs.detachElement(e),this.cameraDirection=new Re.Vector3(0,0,0),this.cameraRotation=new Re.Vector2(0,0)},Object.defineProperty(t.prototype,"collisionMask",{get:function(){return this._collisionMask},set:function(e){this._collisionMask=isNaN(e)?-1:e},enumerable:!0,configurable:!0}),t.prototype._collideWithWorld=function(e){(this.parent?Re.Vector3.TransformCoordinates(this.position,this.parent.getWorldMatrix()):this.position).subtractFromFloatsToRef(0,this.ellipsoid.y,0,this._oldPosition),this._oldPosition.addInPlace(this.ellipsoidOffset),this._collider||(this._collider=new Re.Collider),this._collider._radius=this.ellipsoid,this._collider.collisionMask=this._collisionMask;var t=e;this.applyGravity&&(t=e.add(this.getScene().gravity)),this.getScene().collisionCoordinator.getNewPosition(this._oldPosition,t,this._collider,3,null,this._onCollisionPositionChange,this.uniqueId)},t.prototype._checkInputs=function(){this._localDirection||(this._localDirection=Re.Vector3.Zero(),this._transformedDirection=Re.Vector3.Zero()),this.inputs.checkInputs(),e.prototype._checkInputs.call(this)},t.prototype._decideIfNeedsToMove=function(){return this._needMoveForGravity||Math.abs(this.cameraDirection.x)>0||Math.abs(this.cameraDirection.y)>0||Math.abs(this.cameraDirection.z)>0},t.prototype._updatePosition=function(){this.checkCollisions&&this.getScene().collisionsEnabled?this._collideWithWorld(this.cameraDirection):e.prototype._updatePosition.call(this)},t.prototype.dispose=function(){this.inputs.clear(),e.prototype.dispose.call(this)},t.prototype.getClassName=function(){return"FreeCamera"},X([Re.serializeAsVector3()],t.prototype,"ellipsoid",void 0),X([Re.serializeAsVector3()],t.prototype,"ellipsoidOffset",void 0),X([Re.serialize()],t.prototype,"checkCollisions",void 0),X([Re.serialize()],t.prototype,"applyGravity",void 0),t}(Re.TargetCamera),Re.FreeCamera=Oe,Ie=us||(us={}),we=function(){function e(){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 e.prototype.attachControl=function(e,t){var i=this;this._onCanvasBlurObserver||(this._scene=this.camera.getScene(),this._engine=this._scene.getEngine(),this._onCanvasBlurObserver=this._engine.onCanvasBlurObservable.add(function(){i._keys=[]}),this._onKeyboardObserver=this._scene.onKeyboardObservable.add(function(e){var r,n=e.event;e.type===Ie.KeyboardEventTypes.KEYDOWN?(i._ctrlPressed=n.ctrlKey,i._altPressed=n.altKey,(-1!==i.keysUp.indexOf(n.keyCode)||-1!==i.keysDown.indexOf(n.keyCode)||-1!==i.keysLeft.indexOf(n.keyCode)||-1!==i.keysRight.indexOf(n.keyCode)||-1!==i.keysReset.indexOf(n.keyCode))&&(-1===(r=i._keys.indexOf(n.keyCode))&&i._keys.push(n.keyCode),n.preventDefault&&(t||n.preventDefault()))):-1===i.keysUp.indexOf(n.keyCode)&&-1===i.keysDown.indexOf(n.keyCode)&&-1===i.keysLeft.indexOf(n.keyCode)&&-1===i.keysRight.indexOf(n.keyCode)&&-1===i.keysReset.indexOf(n.keyCode)||((r=i._keys.indexOf(n.keyCode))>=0&&i._keys.splice(r,1),n.preventDefault&&(t||n.preventDefault()))}))},e.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=[]},e.prototype.checkInputs=function(){if(this._onKeyboardObserver)for(var e=this.camera,t=0;t<this._keys.length;t++){var i=this._keys[t];-1!==this.keysLeft.indexOf(i)?this._ctrlPressed&&this.camera._useCtrlForPanning?e.inertialPanningX-=1/this.panningSensibility:e.inertialAlphaOffset-=.01:-1!==this.keysUp.indexOf(i)?this._ctrlPressed&&this.camera._useCtrlForPanning?e.inertialPanningY+=1/this.panningSensibility:this._altPressed&&this.useAltToZoom?e.inertialRadiusOffset+=1/this.zoomingSensibility:e.inertialBetaOffset-=.01:-1!==this.keysRight.indexOf(i)?this._ctrlPressed&&this.camera._useCtrlForPanning?e.inertialPanningX+=1/this.panningSensibility:e.inertialAlphaOffset+=.01:-1!==this.keysDown.indexOf(i)?this._ctrlPressed&&this.camera._useCtrlForPanning?e.inertialPanningY-=1/this.panningSensibility:this._altPressed&&this.useAltToZoom?e.inertialRadiusOffset-=1/this.zoomingSensibility:e.inertialBetaOffset+=.01:-1!==this.keysReset.indexOf(i)&&e.restoreState()}},e.prototype.getClassName=function(){return"ArcRotateCameraKeyboardMoveInput"},e.prototype.getSimpleName=function(){return"keyboard"},X([Ie.serialize()],e.prototype,"keysUp",void 0),X([Ie.serialize()],e.prototype,"keysDown",void 0),X([Ie.serialize()],e.prototype,"keysLeft",void 0),X([Ie.serialize()],e.prototype,"keysRight",void 0),X([Ie.serialize()],e.prototype,"keysReset",void 0),X([Ie.serialize()],e.prototype,"panningSensibility",void 0),X([Ie.serialize()],e.prototype,"zoomingSensibility",void 0),X([Ie.serialize()],e.prototype,"useAltToZoom",void 0),e}(),Ie.ArcRotateCameraKeyboardMoveInput=we,Ie.CameraInputTypes.ArcRotateCameraKeyboardMoveInput=we,De=us||(us={}),Le=function(){function e(){this.wheelPrecision=3,this.wheelDeltaPercentage=0}return e.prototype.attachControl=function(e,t){var i=this;this._wheel=function(e,r){if(e.type===De.PointerEventTypes.POINTERWHEEL){var n=e.event,o=0;n.wheelDelta?o=i.wheelDeltaPercentage?.01*n.wheelDelta*i.camera.radius*i.wheelDeltaPercentage:n.wheelDelta/(40*i.wheelPrecision):n.detail&&(o=-n.detail/i.wheelPrecision),o&&(i.camera.inertialRadiusOffset+=o),n.preventDefault&&(t||n.preventDefault())}},this._observer=this.camera.getScene().onPointerObservable.add(this._wheel,De.PointerEventTypes.POINTERWHEEL)},e.prototype.detachControl=function(e){this._observer&&e&&(this.camera.getScene().onPointerObservable.remove(this._observer),this._observer=null,this._wheel=null)},e.prototype.getClassName=function(){return"ArcRotateCameraMouseWheelInput"},e.prototype.getSimpleName=function(){return"mousewheel"},X([De.serialize()],e.prototype,"wheelPrecision",void 0),X([De.serialize()],e.prototype,"wheelDeltaPercentage",void 0),e}(),De.ArcRotateCameraMouseWheelInput=Le,De.CameraInputTypes.ArcRotateCameraMouseWheelInput=Le,Be=us||(us={}),Ne=function(){function e(){this.buttons=[0,1,2],this.angularSensibilityX=1e3,this.angularSensibilityY=1e3,this.pinchPrecision=12,this.pinchDeltaPercentage=0,this.panningSensibility=1e3,this.multiTouchPanning=!0,this.multiTouchPanAndZoom=!0,this._isPanClick=!1,this.pinchInwards=!0}return e.prototype.attachControl=function(e,t){var i,r=this,n=this.camera.getEngine(),o=null,s=null,a=0,h=0,l=0,c={x:0,y:0,isPaning:!1,isPinching:!1};this._pointerInput=function(u,p){var f=u.event,d="touch"===u.event.pointerType;if(!n.isInVRExclusivePointerMode&&(u.type===Be.PointerEventTypes.POINTERMOVE||-1!==r.buttons.indexOf(f.button))){var m=f.srcElement||f.target;if(u.type===Be.PointerEventTypes.POINTERDOWN&&m){try{m.setPointerCapture(f.pointerId)}catch(e){}r._isPanClick=f.button===r.camera._panningMouseButton,i={x:f.clientX,y:f.clientY,pointerId:f.pointerId,type:f.pointerType},null===o?o=i:null===s&&(s=i),t||(f.preventDefault(),e.focus())}else if(u.type===Be.PointerEventTypes.POINTERDOUBLETAP)r.camera.restoreState();else if(u.type===Be.PointerEventTypes.POINTERUP&&m){try{m.releasePointerCapture(f.pointerId)}catch(e){}i=null,a=0,c.isPaning=!1,c.isPinching=!1,l=0,h=0,d||(s=null),n.badOS?o=s=null:s&&o&&o.pointerId==f.pointerId?(o=s,s=null,i={x:o.x,y:o.y,pointerId:o.pointerId,type:f.pointerType}):o&&s&&s.pointerId==f.pointerId?(s=null,i={x:o.x,y:o.y,pointerId:o.pointerId,type:f.pointerType}):o=s=null,t||f.preventDefault()}else if(u.type===Be.PointerEventTypes.POINTERMOVE)if(t||f.preventDefault(),o&&null===s&&i){if(0!==r.panningSensibility&&(f.ctrlKey&&r.camera._useCtrlForPanning||r._isPanClick))r.camera.inertialPanningX+=-(f.clientX-i.x)/r.panningSensibility,r.camera.inertialPanningY+=(f.clientY-i.y)/r.panningSensibility;else{var g=f.clientX-i.x,_=f.clientY-i.y;r.camera.inertialAlphaOffset-=g/r.angularSensibilityX,r.camera.inertialBetaOffset-=_/r.angularSensibilityY}i.x=f.clientX,i.y=f.clientY}else if(o&&s){var v=o.pointerId===f.pointerId?o:s;v.x=f.clientX,v.y=f.clientY;var y=r.pinchInwards?1:-1,b=o.x-s.x,x=o.y-s.y,T=b*b+x*x,E=Math.sqrt(T);if(0===a)return h=E,a=T,c.x=(o.x+s.x)/2,void(c.y=(o.y+s.y)/2);if(r.multiTouchPanAndZoom){if(r.pinchDeltaPercentage?r.camera.inertialRadiusOffset+=.001*(T-a)*r.camera.radius*r.pinchDeltaPercentage:r.camera.inertialRadiusOffset+=(T-a)/(r.pinchPrecision*((r.angularSensibilityX+r.angularSensibilityY)/2)*y),0!==r.panningSensibility){var A=(o.x+s.x)/2,P=(o.y+s.y)/2,M=A-c.x,S=P-c.y;c.x=A,c.y=P,r.camera.inertialPanningX+=-M/r.panningSensibility,r.camera.inertialPanningY+=S/r.panningSensibility}}else{if(l++,c.isPinching||l<20&&Math.abs(E-h)>r.camera.pinchToPanMaxDistance)r.pinchDeltaPercentage?r.camera.inertialRadiusOffset+=.001*(T-a)*r.camera.radius*r.pinchDeltaPercentage:r.camera.inertialRadiusOffset+=(T-a)/(r.pinchPrecision*((r.angularSensibilityX+r.angularSensibilityY)/2)*y),c.isPaning=!1,c.isPinching=!0;else if(i&&i.pointerId===v.pointerId&&0!==r.panningSensibility&&r.multiTouchPanning){if(!c.isPaning)return c.isPaning=!0,c.isPinching=!1,c.x=v.x,void(c.y=v.y);r.camera.inertialPanningX+=-(v.x-c.x)/r.panningSensibility,r.camera.inertialPanningY+=(v.y-c.y)/r.panningSensibility}i&&i.pointerId===f.pointerId&&(c.x=v.x,c.y=v.y)}a=T}}},this._observer=this.camera.getScene().onPointerObservable.add(this._pointerInput,Be.PointerEventTypes.POINTERDOWN|Be.PointerEventTypes.POINTERUP|Be.PointerEventTypes.POINTERMOVE|Be.PointerEventTypes._POINTERDOUBLETAP),this._onContextMenu=function(e){e.preventDefault()},this.camera._useCtrlForPanning||e.addEventListener("contextmenu",this._onContextMenu,!1),this._onLostFocus=function(){o=s=null,a=0,c.isPaning=!1,c.isPinching=!1,l=0,i=null,h=0},this._onMouseMove=function(e){if(n.isPointerLock){var i=e.movementX||e.mozMovementX||e.webkitMovementX||e.msMovementX||0,o=e.movementY||e.mozMovementY||e.webkitMovementY||e.msMovementY||0;r.camera.inertialAlphaOffset-=i/r.angularSensibilityX,r.camera.inertialBetaOffset-=o/r.angularSensibilityY,t||e.preventDefault()}},this._onGestureStart=function(t){void 0!==window.MSGesture&&(r._MSGestureHandler||(r._MSGestureHandler=new MSGesture,r._MSGestureHandler.target=e),r._MSGestureHandler.addPointer(t.pointerId))},this._onGesture=function(e){r.camera.radius*=e.scale,e.preventDefault&&(t||(e.stopPropagation(),e.preventDefault()))},e.addEventListener("mousemove",this._onMouseMove,!1),e.addEventListener("MSPointerDown",this._onGestureStart,!1),e.addEventListener("MSGestureChange",this._onGesture,!1),Be.Tools.RegisterTopRootEvents([{name:"blur",handler:this._onLostFocus}])},e.prototype.detachControl=function(e){this._onLostFocus&&Be.Tools.UnregisterTopRootEvents([{name:"blur",handler:this._onLostFocus}]),e&&this._observer&&(this.camera.getScene().onPointerObservable.remove(this._observer),this._observer=null,this._onContextMenu&&e.removeEventListener("contextmenu",this._onContextMenu),this._onMouseMove&&e.removeEventListener("mousemove",this._onMouseMove),this._onGestureStart&&e.removeEventListener("MSPointerDown",this._onGestureStart),this._onGesture&&e.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)},e.prototype.getClassName=function(){return"ArcRotateCameraPointersInput"},e.prototype.getSimpleName=function(){return"pointers"},X([Be.serialize()],e.prototype,"buttons",void 0),X([Be.serialize()],e.prototype,"angularSensibilityX",void 0),X([Be.serialize()],e.prototype,"angularSensibilityY",void 0),X([Be.serialize()],e.prototype,"pinchPrecision",void 0),X([Be.serialize()],e.prototype,"pinchDeltaPercentage",void 0),X([Be.serialize()],e.prototype,"panningSensibility",void 0),X([Be.serialize()],e.prototype,"multiTouchPanning",void 0),X([Be.serialize()],e.prototype,"multiTouchPanAndZoom",void 0),e}(),Be.ArcRotateCameraPointersInput=Ne,Be.CameraInputTypes.ArcRotateCameraPointersInput=Ne,Fe=us||(us={}),Ve=function(e){function t(t){return e.call(this,t)||this}return Y(t,e),t.prototype.addMouseWheel=function(){return this.add(new Fe.ArcRotateCameraMouseWheelInput),this},t.prototype.addPointers=function(){return this.add(new Fe.ArcRotateCameraPointersInput),this},t.prototype.addKeyboard=function(){return this.add(new Fe.ArcRotateCameraKeyboardMoveInput),this},t.prototype.addGamepad=function(){return this.add(new Fe.ArcRotateCameraGamepadInput),this},t.prototype.addVRDeviceOrientation=function(){return this.add(new Fe.ArcRotateCameraVRDeviceOrientationInput),this},t}(Fe.CameraInputsManager),Fe.ArcRotateCameraInputsManager=Ve,ke=us||(us={}),Ue=function(e){function t(t,i,r,n,o,s){var a=e.call(this,t,ke.Vector3.Zero(),s)||this;return a.inertialAlphaOffset=0,a.inertialBetaOffset=0,a.inertialRadiusOffset=0,a.lowerAlphaLimit=null,a.upperAlphaLimit=null,a.lowerBetaLimit=.01,a.upperBetaLimit=Math.PI,a.lowerRadiusLimit=null,a.upperRadiusLimit=null,a.inertialPanningX=0,a.inertialPanningY=0,a.pinchToPanMaxDistance=20,a.panningDistanceLimit=null,a.panningOriginTarget=ke.Vector3.Zero(),a.panningInertia=.9,a.zoomOnFactor=1,a.targetScreenOffset=ke.Vector2.Zero(),a.allowUpsideDown=!0,a._viewMatrix=new ke.Matrix,a.panningAxis=new ke.Vector3(1,1,0),a.onMeshTargetChangedObservable=new ke.Observable,a.checkCollisions=!1,a.collisionRadius=new ke.Vector3(.5,.5,.5),a._previousPosition=ke.Vector3.Zero(),a._collisionVelocity=ke.Vector3.Zero(),a._newPosition=ke.Vector3.Zero(),a._onCollisionPositionChange=function(e,t,i){void 0===i&&(i=null),a.getScene().workerCollisions&&a.checkCollisions&&t.multiplyInPlace(a._collider._radius),i?(a.setPosition(t),a.onCollide&&a.onCollide(i)):a._previousPosition.copyFrom(a.position);var r=Math.cos(a.alpha),n=Math.sin(a.alpha),o=Math.cos(a.beta),s=Math.sin(a.beta);0===s&&(s=1e-4);var h=a._getTargetPosition();h.addToRef(new ke.Vector3(a.radius*r*s,a.radius*o,a.radius*n*s),a._newPosition),a.position.copyFrom(a._newPosition);var l=a.upVector;a.allowUpsideDown&&a.beta<0&&(l=(l=l.clone()).negate()),ke.Matrix.LookAtLHToRef(a.position,h,l,a._viewMatrix),a._viewMatrix.m[12]+=a.targetScreenOffset.x,a._viewMatrix.m[13]+=a.targetScreenOffset.y,a._collisionTriggered=!1},a._target=ke.Vector3.Zero(),o&&a.setTarget(o),a.alpha=i,a.beta=r,a.radius=n,a.getViewMatrix(),a.inputs=new ke.ArcRotateCameraInputsManager(a),a.inputs.addKeyboard().addMouseWheel().addPointers(),a}return Y(t,e),Object.defineProperty(t.prototype,"target",{get:function(){return this._target},set:function(e){this.setTarget(e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.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(t.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(t.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(t.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(t.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(t.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(t.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(t.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(t.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(t.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(t.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(t.prototype,"bouncingBehavior",{get:function(){return this._bouncingBehavior},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"useBouncingBehavior",{get:function(){return null!=this._bouncingBehavior},set:function(e){e!==this.useBouncingBehavior&&(e?(this._bouncingBehavior=new ke.BouncingBehavior,this.addBehavior(this._bouncingBehavior)):this._bouncingBehavior&&(this.removeBehavior(this._bouncingBehavior),this._bouncingBehavior=null))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"framingBehavior",{get:function(){return this._framingBehavior},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"useFramingBehavior",{get:function(){return null!=this._framingBehavior},set:function(e){e!==this.useFramingBehavior&&(e?(this._framingBehavior=new ke.FramingBehavior,this.addBehavior(this._framingBehavior)):this._framingBehavior&&(this.removeBehavior(this._framingBehavior),this._framingBehavior=null))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"autoRotationBehavior",{get:function(){return this._autoRotationBehavior},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"useAutoRotationBehavior",{get:function(){return null!=this._autoRotationBehavior},set:function(e){e!==this.useAutoRotationBehavior&&(e?(this._autoRotationBehavior=new ke.AutoRotationBehavior,this.addBehavior(this._autoRotationBehavior)):this._autoRotationBehavior&&(this.removeBehavior(this._autoRotationBehavior),this._autoRotationBehavior=null))},enumerable:!0,configurable:!0}),t.prototype._initCache=function(){e.prototype._initCache.call(this),this._cache._target=new ke.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=ke.Vector2.Zero()},t.prototype._updateCache=function(t){t||e.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)},t.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},t.prototype.storeState=function(){return this._storedAlpha=this.alpha,this._storedBeta=this.beta,this._storedRadius=this.radius,this._storedTarget=this._getTargetPosition().clone(),e.prototype.storeState.call(this)},t.prototype._restoreStateValues=function(){return!!e.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)},t.prototype._isSynchronizedViewMatrix=function(){return!!e.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))},t.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}},t.prototype.detachControl=function(e){this.inputs.detachElement(e),this._reset&&this._reset()},t.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)<ke.Epsilon&&(this.inertialAlphaOffset=0),Math.abs(this.inertialBetaOffset)<ke.Epsilon&&(this.inertialBetaOffset=0),Math.abs(this.inertialRadiusOffset)<this.speed*ke.Epsilon&&(this.inertialRadiusOffset=0)),0!==this.inertialPanningX||0!==this.inertialPanningY){if(this._localDirection||(this._localDirection=ke.Vector3.Zero(),this._transformedDirection=ke.Vector3.Zero()),this._localDirection.copyFromFloats(this.inertialPanningX,this.inertialPanningY,this.inertialPanningY),this._localDirection.multiplyInPlace(this.panningAxis),this._viewMatrix.invertToRef(this._cameraTransformMatrix),ke.Vector3.TransformNormalToRef(this._localDirection,this._cameraTransformMatrix,this._transformedDirection),this.panningAxis.y||(this._transformedDirection.y=0),!this._targetHost)if(this.panningDistanceLimit)this._transformedDirection.addInPlace(this._target),ke.Vector3.DistanceSquared(this._transformedDirection,this.panningOriginTarget)<=this.panningDistanceLimit*this.panningDistanceLimit&&this._target.copyFrom(this._transformedDirection);else this._target.addInPlace(this._transformedDirection);this.inertialPanningX*=this.panningInertia,this.inertialPanningY*=this.panningInertia,Math.abs(this.inertialPanningX)<this.speed*ke.Epsilon&&(this.inertialPanningX=0),Math.abs(this.inertialPanningY)<this.speed*ke.Epsilon&&(this.inertialPanningY=0)}this._checkLimits(),e.prototype._checkInputs.call(this)}},t.prototype._checkLimits=function(){null===this.lowerBetaLimit||void 0===this.lowerBetaLimit?this.allowUpsideDown&&this.beta>Math.PI&&(this.beta=this.beta-2*Math.PI):this.beta<this.lowerBetaLimit&&(this.beta=this.lowerBetaLimit),null===this.upperBetaLimit||void 0===this.upperBetaLimit?this.allowUpsideDown&&this.beta<-Math.PI&&(this.beta=this.beta+2*Math.PI):this.beta>this.upperBetaLimit&&(this.beta=this.upperBetaLimit),this.lowerAlphaLimit&&this.alpha<this.lowerAlphaLimit&&(this.alpha=this.lowerAlphaLimit),this.upperAlphaLimit&&this.alpha>this.upperAlphaLimit&&(this.alpha=this.upperAlphaLimit),this.lowerRadiusLimit&&this.radius<this.lowerRadiusLimit&&(this.radius=this.lowerRadiusLimit),this.upperRadiusLimit&&this.radius>this.upperRadiusLimit&&(this.radius=this.upperRadiusLimit)},t.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()},t.prototype.setPosition=function(e){this.position.equals(e)||(this.position.copyFrom(e),this.rebuildAnglesAndRadius())},t.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()},t.prototype._getViewMatrix=function(){var e=Math.cos(this.alpha),t=Math.sin(this.alpha),i=Math.cos(this.beta),r=Math.sin(this.beta);0===r&&(r=1e-4);var n=this._getTargetPosition();if(n.addToRef(new ke.Vector3(this.radius*e*r,this.radius*i,this.radius*t*r),this._newPosition),this.getScene().collisionsEnabled&&this.checkCollisions)this._collider||(this._collider=new ke.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 o=this.upVector;this.allowUpsideDown&&r<0&&(o=(o=o.clone()).negate()),this.getScene().useRightHandedSystem?ke.Matrix.LookAtRHToRef(this.position,n,o,this._viewMatrix):ke.Matrix.LookAtLHToRef(this.position,n,o,this._viewMatrix),this._viewMatrix.m[12]+=this.targetScreenOffset.x,this._viewMatrix.m[13]+=this.targetScreenOffset.y}return this._currentTarget=n,this._viewMatrix},t.prototype.zoomOn=function(e,t){void 0===t&&(t=!1),e=e||this.getScene().meshes;var i=ke.Mesh.MinMax(e),r=ke.Vector3.Distance(i.min,i.max);this.radius=r*this.zoomOnFactor,this.focusOn({min:i.min,max:i.max,distance:r},t)},t.prototype.focusOn=function(e,t){var i,r;if(void 0===t&&(t=!1),void 0===e.min){var n=e||this.getScene().meshes;i=ke.Mesh.MinMax(n),r=ke.Vector3.Distance(i.min,i.max)}else{i=e,r=e.distance}this._target=ke.Mesh.Center(i),t||(this.maxZ=2*r)},t.prototype.createRigCamera=function(e,i){var r=0;switch(this.cameraRigMode){case ke.Camera.RIG_MODE_STEREOSCOPIC_ANAGLYPH:case ke.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL:case ke.Camera.RIG_MODE_STEREOSCOPIC_OVERUNDER:case ke.Camera.RIG_MODE_VR:r=this._cameraRigParams.stereoHalfAngle*(0===i?1:-1);break;case ke.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED:r=this._cameraRigParams.stereoHalfAngle*(0===i?-1:1)}var n=new t(e,this.alpha+r,this.beta,this.radius,this._target,this.getScene());return n._cameraRigParams={},n},t.prototype._updateRigCameras=function(){var t=this._rigCameras[0],i=this._rigCameras[1];switch(t.beta=i.beta=this.beta,t.radius=i.radius=this.radius,this.cameraRigMode){case ke.Camera.RIG_MODE_STEREOSCOPIC_ANAGLYPH:case ke.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL:case ke.Camera.RIG_MODE_STEREOSCOPIC_OVERUNDER:case ke.Camera.RIG_MODE_VR:t.alpha=this.alpha-this._cameraRigParams.stereoHalfAngle,i.alpha=this.alpha+this._cameraRigParams.stereoHalfAngle;break;case ke.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED:t.alpha=this.alpha+this._cameraRigParams.stereoHalfAngle,i.alpha=this.alpha-this._cameraRigParams.stereoHalfAngle}e.prototype._updateRigCameras.call(this)},t.prototype.dispose=function(){this.inputs.clear(),e.prototype.dispose.call(this)},t.prototype.getClassName=function(){return"ArcRotateCamera"},X([ke.serialize()],t.prototype,"alpha",void 0),X([ke.serialize()],t.prototype,"beta",void 0),X([ke.serialize()],t.prototype,"radius",void 0),X([ke.serializeAsVector3("target")],t.prototype,"_target",void 0),X([ke.serialize()],t.prototype,"inertialAlphaOffset",void 0),X([ke.serialize()],t.prototype,"inertialBetaOffset",void 0),X([ke.serialize()],t.prototype,"inertialRadiusOffset",void 0),X([ke.serialize()],t.prototype,"lowerAlphaLimit",void 0),X([ke.serialize()],t.prototype,"upperAlphaLimit",void 0),X([ke.serialize()],t.prototype,"lowerBetaLimit",void 0),X([ke.serialize()],t.prototype,"upperBetaLimit",void 0),X([ke.serialize()],t.prototype,"lowerRadiusLimit",void 0),X([ke.serialize()],t.prototype,"upperRadiusLimit",void 0),X([ke.serialize()],t.prototype,"inertialPanningX",void 0),X([ke.serialize()],t.prototype,"inertialPanningY",void 0),X([ke.serialize()],t.prototype,"pinchToPanMaxDistance",void 0),X([ke.serialize()],t.prototype,"panningDistanceLimit",void 0),X([ke.serializeAsVector3()],t.prototype,"panningOriginTarget",void 0),X([ke.serialize()],t.prototype,"panningInertia",void 0),X([ke.serialize()],t.prototype,"zoomOnFactor",void 0),X([ke.serialize()],t.prototype,"allowUpsideDown",void 0),t}(ke.TargetCamera),ke.ArcRotateCamera=Ue,ze=us||(us={}),Ge=function(e){function t(t,i,r){var n=e.call(this,t,r)||this;return n.groundColor=new ze.Color3(0,0,0),n.direction=i||ze.Vector3.Up(),n}return Y(t,e),t.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()},t.prototype.getClassName=function(){return"HemisphericLight"},t.prototype.setDirectionToTarget=function(e){return this.direction=ze.Vector3.Normalize(e.subtract(ze.Vector3.Zero())),this.direction},t.prototype.getShadowGenerator=function(){return null},t.prototype.transferToEffect=function(e,t){var i=ze.Vector3.Normalize(this.direction);return this._uniformBuffer.updateFloat4("vLightData",i.x,i.y,i.z,0,t),this._uniformBuffer.updateColor3("vLightGround",this.groundColor.scale(this.intensity),t),this},t.prototype._getWorldMatrix=function(){return this._worldMatrix||(this._worldMatrix=ze.Matrix.Identity()),this._worldMatrix},t.prototype.getTypeID=function(){return ze.Light.LIGHTTYPEID_HEMISPHERICLIGHT},X([ze.serializeAsColor3()],t.prototype,"groundColor",void 0),X([ze.serializeAsVector3()],t.prototype,"direction",void 0),t}(ze.Light),ze.HemisphericLight=Ge,We=us||(us={}),He=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t._needProjectionMatrixCompute=!0,t}return Y(t,e),Object.defineProperty(t.prototype,"direction",{get:function(){return this._direction},set:function(e){this._direction=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"shadowMinZ",{get:function(){return this._shadowMinZ},set:function(e){this._shadowMinZ=e,this.forceProjectionMatrixCompute()},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"shadowMaxZ",{get:function(){return this._shadowMaxZ},set:function(e){this._shadowMaxZ=e,this.forceProjectionMatrixCompute()},enumerable:!0,configurable:!0}),t.prototype.computeTransformedInformation=function(){return!(!this.parent||!this.parent.getWorldMatrix)&&(this.transformedPosition||(this.transformedPosition=We.Vector3.Zero()),We.Vector3.TransformCoordinatesToRef(this.position,this.parent.getWorldMatrix(),this.transformedPosition),this.direction&&(this.transformedDirection||(this.transformedDirection=We.Vector3.Zero()),We.Vector3.TransformNormalToRef(this.direction,this.parent.getWorldMatrix(),this.transformedDirection)),!0)},t.prototype.getDepthScale=function(){return 50},t.prototype.getShadowDirection=function(e){return this.transformedDirection?this.transformedDirection:this.direction},t.prototype.getAbsolutePosition=function(){return this.transformedPosition?this.transformedPosition:this.position},t.prototype.setDirectionToTarget=function(e){return this.direction=We.Vector3.Normalize(e.subtract(this.position)),this.direction},t.prototype.getRotation=function(){this.direction.normalize();var e=We.Vector3.Cross(this.direction,We.Axis.Y),t=We.Vector3.Cross(e,this.direction);return We.Vector3.RotationFromAxis(e,t,this.direction)},t.prototype.needCube=function(){return!1},t.prototype.needProjectionMatrixCompute=function(){return this._needProjectionMatrixCompute},t.prototype.forceProjectionMatrixCompute=function(){this._needProjectionMatrixCompute=!0},t.prototype._getWorldMatrix=function(){return this._worldMatrix||(this._worldMatrix=We.Matrix.Identity()),We.Matrix.TranslationToRef(this.position.x,this.position.y,this.position.z,this._worldMatrix),this._worldMatrix},t.prototype.getDepthMinZ=function(e){return void 0!==this.shadowMinZ?this.shadowMinZ:e.minZ},t.prototype.getDepthMaxZ=function(e){return void 0!==this.shadowMaxZ?this.shadowMaxZ:e.maxZ},t.prototype.setShadowProjectionMatrix=function(e,t,i){return this.customProjectionMatrixBuilder?this.customProjectionMatrixBuilder(t,i,e):this._setDefaultShadowProjectionMatrix(e,t,i),this},X([We.serializeAsVector3()],t.prototype,"position",void 0),X([We.serializeAsVector3()],t.prototype,"direction",null),X([We.serialize()],t.prototype,"shadowMinZ",null),X([We.serialize()],t.prototype,"shadowMaxZ",null),t}(We.Light),We.ShadowLight=He,je=us||(us={}),Xe=function(e){function t(t,i,r){var n=e.call(this,t,r)||this;return n._shadowAngle=Math.PI/2,n.position=i,n}return Y(t,e),Object.defineProperty(t.prototype,"shadowAngle",{get:function(){return this._shadowAngle},set:function(e){this._shadowAngle=e,this.forceProjectionMatrixCompute()},enumerable:!0,configurable:!0}),Object.defineProperty(t.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}),t.prototype.getClassName=function(){return"PointLight"},t.prototype.getTypeID=function(){return je.Light.LIGHTTYPEID_POINTLIGHT},t.prototype.needCube=function(){return!this.direction},t.prototype.getShadowDirection=function(t){if(this.direction)return e.prototype.getShadowDirection.call(this,t);switch(t){case 0:return new je.Vector3(1,0,0);case 1:return new je.Vector3(-1,0,0);case 2:return new je.Vector3(0,-1,0);case 3:return new je.Vector3(0,1,0);case 4:return new je.Vector3(0,0,1);case 5:return new je.Vector3(0,0,-1)}return je.Vector3.Zero()},t.prototype._setDefaultShadowProjectionMatrix=function(e,t,i){var r=this.getScene().activeCamera;r&&je.Matrix.PerspectiveFovLHToRef(this.shadowAngle,1,this.getDepthMinZ(r),this.getDepthMaxZ(r),e)},t.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()},t.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)},X([je.serialize()],t.prototype,"shadowAngle",null),t}(je.ShadowLight),je.PointLight=Xe,Ye=us||(us={}),Ke=function(e){function t(t,i,r){var n=e.call(this,t,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 Y(t,e),Object.defineProperty(t.prototype,"shadowFrustumSize",{get:function(){return this._shadowFrustumSize},set:function(e){this._shadowFrustumSize=e,this.forceProjectionMatrixCompute()},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"shadowOrthoScale",{get:function(){return this._shadowOrthoScale},set:function(e){this._shadowOrthoScale=e,this.forceProjectionMatrixCompute()},enumerable:!0,configurable:!0}),t.prototype.getClassName=function(){return"DirectionalLight"},t.prototype.getTypeID=function(){return Ye.Light.LIGHTTYPEID_DIRECTIONALLIGHT},t.prototype._setDefaultShadowProjectionMatrix=function(e,t,i){this.shadowFrustumSize>0?this._setDefaultFixedFrustumShadowProjectionMatrix(e,t):this._setDefaultAutoExtendShadowProjectionMatrix(e,t,i)},t.prototype._setDefaultFixedFrustumShadowProjectionMatrix=function(e,t){var i=this.getScene().activeCamera;i&&Ye.Matrix.OrthoLHToRef(this.shadowFrustumSize,this.shadowFrustumSize,void 0!==this.shadowMinZ?this.shadowMinZ:i.minZ,void 0!==this.shadowMaxZ?this.shadowMaxZ:i.maxZ,e)},t.prototype._setDefaultAutoExtendShadowProjectionMatrix=function(e,t,i){var r=this.getScene().activeCamera;if(r){if(this.autoUpdateExtends||this._orthoLeft===Number.MAX_VALUE){var n=Ye.Vector3.Zero();this._orthoLeft=Number.MAX_VALUE,this._orthoRight=Number.MIN_VALUE,this._orthoTop=Number.MIN_VALUE,this._orthoBottom=Number.MAX_VALUE;for(var o=0;o<i.length;o++){var s=i[o];if(s)for(var a=s.getBoundingInfo().boundingBox,h=0;h<a.vectorsWorld.length;h++)Ye.Vector3.TransformCoordinatesToRef(a.vectorsWorld[h],t,n),n.x<this._orthoLeft&&(this._orthoLeft=n.x),n.y<this._orthoBottom&&(this._orthoBottom=n.y),n.x>this._orthoRight&&(this._orthoRight=n.x),n.y>this._orthoTop&&(this._orthoTop=n.y)}}var l=this._orthoRight-this._orthoLeft,c=this._orthoTop-this._orthoBottom;Ye.Matrix.OrthoOffCenterLHToRef(this._orthoLeft-l*this.shadowOrthoScale,this._orthoRight+l*this.shadowOrthoScale,this._orthoBottom-c*this.shadowOrthoScale,this._orthoTop+c*this.shadowOrthoScale,void 0!==this.shadowMinZ?this.shadowMinZ:r.minZ,void 0!==this.shadowMaxZ?this.shadowMaxZ:r.maxZ,e)}},t.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()},t.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)},t.prototype.getDepthMinZ=function(e){return 1},t.prototype.getDepthMaxZ=function(e){return 1},X([Ye.serialize()],t.prototype,"shadowFrustumSize",null),X([Ye.serialize()],t.prototype,"shadowOrthoScale",null),X([Ye.serialize()],t.prototype,"autoUpdateExtends",void 0),t}(Ye.ShadowLight),Ye.DirectionalLight=Ke,Qe=us||(us={}),Ze=function(e){function t(t,i,r,n,o,s){var a=e.call(this,t,s)||this;return a.position=i,a.direction=r,a.angle=n,a.exponent=o,a}return Y(t,e),Object.defineProperty(t.prototype,"angle",{get:function(){return this._angle},set:function(e){this._angle=e,this.forceProjectionMatrixCompute()},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"shadowAngleScale",{get:function(){return this._shadowAngleScale},set:function(e){this._shadowAngleScale=e,this.forceProjectionMatrixCompute()},enumerable:!0,configurable:!0}),t.prototype.getClassName=function(){return"SpotLight"},t.prototype.getTypeID=function(){return Qe.Light.LIGHTTYPEID_SPOTLIGHT},t.prototype._setDefaultShadowProjectionMatrix=function(e,t,i){var r=this.getScene().activeCamera;if(r){this._shadowAngleScale=this._shadowAngleScale||1;var n=this._shadowAngleScale*this._angle;Qe.Matrix.PerspectiveFovLHToRef(n,1,this.getDepthMinZ(r),this.getDepthMaxZ(r),e)}},t.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()},t.prototype.transferToEffect=function(e,t){var i;return this.computeTransformedInformation()?(this._uniformBuffer.updateFloat4("vLightData",this.transformedPosition.x,this.transformedPosition.y,this.transformedPosition.z,this.exponent,t),i=Qe.Vector3.Normalize(this.transformedDirection)):(this._uniformBuffer.updateFloat4("vLightData",this.position.x,this.position.y,this.position.z,this.exponent,t),i=Qe.Vector3.Normalize(this.direction)),this._uniformBuffer.updateFloat4("vLightDirection",i.x,i.y,i.z,Math.cos(.5*this.angle),t),this},X([Qe.serialize()],t.prototype,"angle",null),X([Qe.serialize()],t.prototype,"shadowAngleScale",null),X([Qe.serialize()],t.prototype,"exponent",void 0),t}(Qe.ShadowLight),Qe.SpotLight=Ze,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,n=function(){function t(e){this.path=e,this._onchange=new Array,this.value=0,this.animations=new Array}return t.prototype.getPoint=function(){var t=this.path.getPointAtLengthPosition(this.value);return new e.Vector3(t.x,0,t.y)},t.prototype.moveAhead=function(e){return void 0===e&&(e=.002),this.move(e),this},t.prototype.moveBack=function(e){return void 0===e&&(e=.002),this.move(-e),this},t.prototype.move=function(e){if(Math.abs(e)>1)throw"step size should be less than 1.";return this.value+=e,this.ensureLimits(),this.raiseOnChange(),this},t.prototype.ensureLimits=function(){for(;this.value>1;)this.value-=1;for(;this.value<0;)this.value+=1;return this},t.prototype.raiseOnChange=function(){var e=this;return this._onchange.forEach(function(t){return t(e)}),this},t.prototype.onchange=function(e){return this._onchange.push(e),this},t}();e.PathCursor=n,(r=e.AnimationKeyInterpolation||(e.AnimationKeyInterpolation={}))[r.STEP=1]="STEP";var o=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(e,t,r,n){var o=new i(e+"Animation",e,r,t,i.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.CreateAndStartHierarchyAnimation=function(e,t,r,n,o,s,a,h,l,c,u){var p=i._PrepareAnimation(e,n,o,s,a,h,l,c);return p?t.getScene().beginDirectHierarchyAnimation(t,r,[p],0,s,1===p.loopMode,1,u):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<t.length;e++){if(!t[e].isStopped)return!0}return!1},enumerable:!0,configurable:!0}),i.prototype.toString=function(e){var t="Name: "+this.name+", property: "+this.targetProperty;if(t+=", datatype: "+["Float","Vector3","Quaternion","Matrix","Color3","Vector2"][this.dataType],t+=", nKeys: "+(this._keys?this._keys.length:"none"),t+=", nRanges: "+(this._ranges?Object.keys(this._ranges).length:"none"),e){t+=", Ranges: {";var i=!0;for(var r in this._ranges)i&&(t+=", ",i=!1),t+=r;t+="}"}return t},i.prototype.addEvent=function(e){this._events.push(e)},i.prototype.removeEvents=function(e){for(var t=0;t<this._events.length;t++)this._events[t].frame===e&&(this._events.splice(t,1),t--)},i.prototype.getEvents=function(){return this._events},i.prototype.createRange=function(e,i,r){this._ranges[e]||(this._ranges[e]=new t(e,i,r))},i.prototype.deleteRange=function(e,t){void 0===t&&(t=!0);var i=this._ranges[e];if(i){if(t)for(var r=i.from,n=i.to,o=this._keys.length-1;o>=0;o--)this._keys[o].frame>=r&&this._keys[o].frame<=n&&this._keys.splice(o,1);this._ranges[e]=null}},i.prototype.getRange=function(e){return this._ranges[e]},i.prototype.getKeys=function(){return this._keys},i.prototype.getHighestFrame=function(){for(var e=0,t=0,i=this._keys.length;t<i;t++)e<this._keys[t].frame&&(e=this._keys[t].frame);return e},i.prototype.getEasingFunction=function(){return this._easingFunction},i.prototype.setEasingFunction=function(e){this._easingFunction=e},i.prototype.floatInterpolateFunction=function(t,i,r){return e.Scalar.Lerp(t,i,r)},i.prototype.floatInterpolateFunctionWithTangents=function(t,i,r,n,o){return e.Scalar.Hermite(t,i,r,n,o)},i.prototype.quaternionInterpolateFunction=function(t,i,r){return e.Quaternion.Slerp(t,i,r)},i.prototype.quaternionInterpolateFunctionWithTangents=function(t,i,r,n,o){return e.Quaternion.Hermite(t,i,r,n,o).normalize()},i.prototype.vector3InterpolateFunction=function(t,i,r){return e.Vector3.Lerp(t,i,r)},i.prototype.vector3InterpolateFunctionWithTangents=function(t,i,r,n,o){return e.Vector3.Hermite(t,i,r,n,o)},i.prototype.vector2InterpolateFunction=function(t,i,r){return e.Vector2.Lerp(t,i,r)},i.prototype.vector2InterpolateFunctionWithTangents=function(t,i,r,n,o){return e.Vector2.Hermite(t,i,r,n,o)},i.prototype.sizeInterpolateFunction=function(t,i,r){return e.Size.Lerp(t,i,r)},i.prototype.color3InterpolateFunction=function(t,i,r){return e.Color3.Lerp(t,i,r)},i.prototype.matrixInterpolateFunction=function(t,i,r){return e.Matrix.Lerp(t,i,r)},i.prototype.clone=function(){var e=new i(this.name,this.targetPropertyPath.join("."),this.framePerSecond,this.dataType,this.loopMode);if(e.enableBlending=this.enableBlending,e.blendingSpeed=this.blendingSpeed,this._keys&&e.setKeys(this._keys),this._ranges){e._ranges={};for(var t in this._ranges){var r=this._ranges[t];r&&(e._ranges[t]=r.clone())}}return e},i.prototype.setKeys=function(e){this._keys=e.slice(0)},i.prototype.serialize=function(){var e={};e.name=this.name,e.property=this.targetProperty,e.framePerSecond=this.framePerSecond,e.dataType=this.dataType,e.loopBehavior=this.loopMode,e.enableBlending=this.enableBlending,e.blendingSpeed=this.blendingSpeed;var t=this.dataType;e.keys=[];for(var r=this.getKeys(),n=0;n<r.length;n++){var o=r[n],s={};switch(s.frame=o.frame,t){case i.ANIMATIONTYPE_FLOAT:s.values=[o.value];break;case i.ANIMATIONTYPE_QUATERNION:case i.ANIMATIONTYPE_MATRIX:case i.ANIMATIONTYPE_VECTOR3:case i.ANIMATIONTYPE_COLOR3:s.values=o.value.asArray()}e.keys.push(s)}e.ranges=[];for(var a in this._ranges){var h=this._ranges[a];if(h){var l={};l.name=a,l.from=h.from,l.to=h.to,e.ranges.push(l)}}return e},Object.defineProperty(i,"ANIMATIONTYPE_FLOAT",{get:function(){return i._ANIMATIONTYPE_FLOAT},enumerable:!0,configurable:!0}),Object.defineProperty(i,"ANIMATIONTYPE_VECTOR3",{get:function(){return i._ANIMATIONTYPE_VECTOR3},enumerable:!0,configurable:!0}),Object.defineProperty(i,"ANIMATIONTYPE_VECTOR2",{get:function(){return i._ANIMATIONTYPE_VECTOR2},enumerable:!0,configurable:!0}),Object.defineProperty(i,"ANIMATIONTYPE_SIZE",{get:function(){return i._ANIMATIONTYPE_SIZE},enumerable:!0,configurable:!0}),Object.defineProperty(i,"ANIMATIONTYPE_QUATERNION",{get:function(){return i._ANIMATIONTYPE_QUATERNION},enumerable:!0,configurable:!0}),Object.defineProperty(i,"ANIMATIONTYPE_MATRIX",{get:function(){return i._ANIMATIONTYPE_MATRIX},enumerable:!0,configurable:!0}),Object.defineProperty(i,"ANIMATIONTYPE_COLOR3",{get:function(){return i._ANIMATIONTYPE_COLOR3},enumerable:!0,configurable:!0}),Object.defineProperty(i,"ANIMATIONLOOPMODE_RELATIVE",{get:function(){return i._ANIMATIONLOOPMODE_RELATIVE},enumerable:!0,configurable:!0}),Object.defineProperty(i,"ANIMATIONLOOPMODE_CYCLE",{get:function(){return i._ANIMATIONLOOPMODE_CYCLE},enumerable:!0,configurable:!0}),Object.defineProperty(i,"ANIMATIONLOOPMODE_CONSTANT",{get:function(){return i._ANIMATIONLOOPMODE_CONSTANT},enumerable:!0,configurable:!0}),i.Parse=function(t){var r,n,o=new i(t.name,t.property,t.framePerSecond,t.dataType,t.loopBehavior),s=t.dataType,a=[];for(t.enableBlending&&(o.enableBlending=t.enableBlending),t.blendingSpeed&&(o.blendingSpeed=t.blendingSpeed),n=0;n<t.keys.length;n++){var h,l,c=t.keys[n];switch(s){case i.ANIMATIONTYPE_FLOAT:r=c.values[0],c.values.length>=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<t.ranges.length;n++)r=t.ranges[n],o.createRange(r.name,r.from,r.to);return o},i.AppendSerializedAnimations=function(e,t){if(e.animations){t.animations=[];for(var i=0;i<e.animations.length;i++){var r=e.animations[i];t.animations.push(r.serialize())}}},i.AllowMatricesInterpolation=!1,i._ANIMATIONTYPE_FLOAT=0,i._ANIMATIONTYPE_VECTOR3=1,i._ANIMATIONTYPE_QUATERNION=2,i._ANIMATIONTYPE_MATRIX=3,i._ANIMATIONTYPE_COLOR3=4,i._ANIMATIONTYPE_VECTOR2=5,i._ANIMATIONTYPE_SIZE=6,i._ANIMATIONLOOPMODE_RELATIVE=0,i._ANIMATIONLOOPMODE_CYCLE=1,i._ANIMATIONLOOPMODE_CONSTANT=2,i}();e.Animation=o}(us||(us={})),function(e){var t=function(){return function(){}}();e.TargetedAnimation=t;var i=function(){function t(t,i){void 0===i&&(i=null),this.name=t,this._targetedAnimations=new Array,this._animatables=new Array,this._from=Number.MAX_VALUE,this._to=Number.MIN_VALUE,this._speedRatio=1,this.onAnimationEndObservable=new e.Observable,this._scene=i||e.Engine.LastCreatedScene,this._scene.animationGroups.push(this)}return Object.defineProperty(t.prototype,"isStarted",{get:function(){return this._isStarted},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"speedRatio",{get:function(){return this._speedRatio},set:function(e){if(this._speedRatio!==e){this._speedRatio=e;for(var t=0;t<this._animatables.length;t++){this._animatables[t].speedRatio=this._speedRatio}}},enumerable:!0,configurable:!0}),t.prototype.addTargetedAnimation=function(e,t){var i={animation:e,target:t},r=e.getKeys();return this._from>r[0].frame&&(this._from=r[0].frame),this._to<r[r.length-1].frame&&(this._to=r[r.length-1].frame),this._targetedAnimations.push(i),i},t.prototype.normalize=function(e,t){e=Math.min(e,this._from),t=Math.min(t,this._to);for(var i=0;i<this._targetedAnimations.length;i++){var r=this._targetedAnimations[i].animation.getKeys(),n=r[0],o=r[r.length-1];if(n.frame>e){var s={frame:e,value:n.value,inTangent:n.inTangent,outTangent:n.outTangent};r.splice(0,0,s)}if(o.frame<t){s={frame:t,value:o.value,inTangent:n.outTangent,outTangent:n.outTangent};r.push(s)}}return this},t.prototype.start=function(e,t){var i=this;if(void 0===e&&(e=!1),void 0===t&&(t=1),this._isStarted||0===this._targetedAnimations.length)return this;for(var r=function(){var r=n._targetedAnimations[o];n._animatables.push(n._scene.beginDirectAnimation(r.target,[r.animation],n._from,n._to,e,t,function(){i.onAnimationEndObservable.notifyObservers(r)}))},n=this,o=0;o<this._targetedAnimations.length;o++)r();return this._speedRatio=t,this._isStarted=!0,this},t.prototype.pause=function(){if(!this._isStarted)return this;for(var e=0;e<this._animatables.length;e++){this._animatables[e].pause()}return this},t.prototype.play=function(e){if(this.isStarted){if(void 0!==e)for(var t=0;t<this._animatables.length;t++){this._animatables[t].loopAnimation=e}this.restart()}else this.start(e,this._speedRatio);return this},t.prototype.reset=function(){if(!this._isStarted)return this;for(var e=0;e<this._animatables.length;e++){this._animatables[e].reset()}return this},t.prototype.restart=function(){if(!this._isStarted)return this;for(var e=0;e<this._animatables.length;e++){this._animatables[e].restart()}return this},t.prototype.stop=function(){if(!this._isStarted)return this;for(var e=0;e<this._animatables.length;e++){this._animatables[e].stop()}return this._isStarted=!1,this},t.prototype.dispose=function(){this._targetedAnimations=[],this._animatables=[];var e=this._scene.animationGroups.indexOf(this);e>-1&&this._scene.animationGroups.splice(e,1)},t}();e.AnimationGroup=i}(us||(us={})),qe=us||(us={}),Je=function(){function e(e,t){this._offsetsCache={},this._highLimitsCache={},this._stopped=!1,this._blendingFactor=0,this._ratioOffset=0,this._animation=t,this._target=e,t._runtimeAnimations.push(this)}return Object.defineProperty(e.prototype,"animation",{get:function(){return this._animation},enumerable:!0,configurable:!0}),e.prototype.reset=function(){this._offsetsCache={},this._highLimitsCache={},this.currentFrame=0,this._blendingFactor=0,this._originalBlendValue=null},e.prototype.isStopped=function(){return this._stopped},e.prototype.dispose=function(){var e=this._animation.runtimeAnimations.indexOf(this);e>-1&&this._animation.runtimeAnimations.splice(e,1)},e.prototype._getKeyValue=function(e){return"function"==typeof e?e():e},e.prototype._interpolate=function(e,t,i,r,n){if(i===qe.Animation.ANIMATIONLOOPMODE_CONSTANT&&t>0)return n.clone?n.clone():n;this.currentFrame=e;var o=this._animation.getKeys(),s=Math.max(0,Math.min(o.length-1,Math.floor(o.length*(e-o[0].frame)/(o[o.length-1].frame-o[0].frame))-1));if(o[s].frame>=e)for(;s-1>=0&&o[s].frame>=e;)s--;for(var a=s;a<o.length;a++){var h=o[a+1];if(h.frame>=e){var l=o[a],c=this._getKeyValue(l.value);if(l.interpolation===qe.AnimationKeyInterpolation.STEP)return c;var u=this._getKeyValue(h.value),p=void 0!==l.outTangent&&void 0!==h.inTangent,f=h.frame-l.frame,d=(e-l.frame)/f,m=this._animation.getEasingFunction();switch(null!=m&&(d=m.ease(d)),this._animation.dataType){case qe.Animation.ANIMATIONTYPE_FLOAT:var g=p?this._animation.floatInterpolateFunctionWithTangents(c,l.outTangent*f,u,h.inTangent*f,d):this._animation.floatInterpolateFunction(c,u,d);switch(i){case qe.Animation.ANIMATIONLOOPMODE_CYCLE:case qe.Animation.ANIMATIONLOOPMODE_CONSTANT:return g;case qe.Animation.ANIMATIONLOOPMODE_RELATIVE:return r*t+g}break;case qe.Animation.ANIMATIONTYPE_QUATERNION:var _=p?this._animation.quaternionInterpolateFunctionWithTangents(c,l.outTangent.scale(f),u,h.inTangent.scale(f),d):this._animation.quaternionInterpolateFunction(c,u,d);switch(i){case qe.Animation.ANIMATIONLOOPMODE_CYCLE:case qe.Animation.ANIMATIONLOOPMODE_CONSTANT:return _;case qe.Animation.ANIMATIONLOOPMODE_RELATIVE:return _.add(r.scale(t))}return _;case qe.Animation.ANIMATIONTYPE_VECTOR3:var v=p?this._animation.vector3InterpolateFunctionWithTangents(c,l.outTangent.scale(f),u,h.inTangent.scale(f),d):this._animation.vector3InterpolateFunction(c,u,d);switch(i){case qe.Animation.ANIMATIONLOOPMODE_CYCLE:case qe.Animation.ANIMATIONLOOPMODE_CONSTANT:return v;case qe.Animation.ANIMATIONLOOPMODE_RELATIVE:return v.add(r.scale(t))}case qe.Animation.ANIMATIONTYPE_VECTOR2:var y=p?this._animation.vector2InterpolateFunctionWithTangents(c,l.outTangent.scale(f),u,h.inTangent.scale(f),d):this._animation.vector2InterpolateFunction(c,u,d);switch(i){case qe.Animation.ANIMATIONLOOPMODE_CYCLE:case qe.Animation.ANIMATIONLOOPMODE_CONSTANT:return y;case qe.Animation.ANIMATIONLOOPMODE_RELATIVE:return y.add(r.scale(t))}case qe.Animation.ANIMATIONTYPE_SIZE:switch(i){case qe.Animation.ANIMATIONLOOPMODE_CYCLE:case qe.Animation.ANIMATIONLOOPMODE_CONSTANT:return this._animation.sizeInterpolateFunction(c,u,d);case qe.Animation.ANIMATIONLOOPMODE_RELATIVE:return this._animation.sizeInterpolateFunction(c,u,d).add(r.scale(t))}case qe.Animation.ANIMATIONTYPE_COLOR3:switch(i){case qe.Animation.ANIMATIONLOOPMODE_CYCLE:case qe.Animation.ANIMATIONLOOPMODE_CONSTANT:return this._animation.color3InterpolateFunction(c,u,d);case qe.Animation.ANIMATIONLOOPMODE_RELATIVE:return this._animation.color3InterpolateFunction(c,u,d).add(r.scale(t))}case qe.Animation.ANIMATIONTYPE_MATRIX:switch(i){case qe.Animation.ANIMATIONLOOPMODE_CYCLE:case qe.Animation.ANIMATIONLOOPMODE_CONSTANT:if(qe.Animation.AllowMatricesInterpolation)return this._animation.matrixInterpolateFunction(c,u,d);case qe.Animation.ANIMATIONLOOPMODE_RELATIVE:return c}}break}}return this._getKeyValue(o[o.length-1].value)},e.prototype.setValue=function(e,t){var i,r;void 0===t&&(t=!1);var n=this._animation.targetPropertyPath;if(n.length>1){for(var o=this._target[n[0]],s=1;s<n.length-1;s++)o=o[n[s]];i=n[n.length-1],r=o}else i=n[0],r=this._target;this._animation.enableBlending&&this._blendingFactor<=1?(this._originalBlendValue||(r[i].clone?this._originalBlendValue=r[i].clone():this._originalBlendValue=r[i]),this._originalBlendValue.prototype?this._originalBlendValue.prototype.Lerp?r[i]=this._originalBlendValue.construtor.prototype.Lerp(e,this._originalBlendValue,this._blendingFactor):r[i]=e:this._originalBlendValue.m?r[i]=qe.Matrix.Lerp(this._originalBlendValue,e,this._blendingFactor):r[i]=this._originalBlendValue*(1-this._blendingFactor)+this._blendingFactor*e,this._blendingFactor+=this._animation.blendingSpeed):r[i]=e,this._target.markAsDirty&&this._target.markAsDirty(this._animation.targetProperty)},e.prototype.goToFrame=function(e){var t=this._animation.getKeys();e<t[0].frame?e=t[0].frame:e>t[t.length-1].frame&&(e=t[t.length-1].frame);var i=this._interpolate(e,0,this._animation.loopMode);this.setValue(i)},e.prototype._prepareForSpeedRatioChange=function(e){var t=this._previousDelay*(this._animation.framePerSecond*e)/1e3;this._ratioOffset=this._previousRatio-t},e.prototype.animate=function(e,t,i,r,n,o){void 0===o&&(o=!1);var s=this._animation.targetPropertyPath;if(!s||s.length<1)return this._stopped=!0,!1;var a=!0,h=this._animation.getKeys();if(0!==h[0].frame){var l={frame:0,value:h[0].value};h.splice(0,0,l)}(t<h[0].frame||t>h[h.length-1].frame)&&(t=h[0].frame),(i<h[0].frame||i>h[h.length-1].frame)&&(i=h[h.length-1].frame),t===i&&(t>h[0].frame?t--:i<h[h.length-1].frame&&i++);var c,u=i-t,p=e*(this._animation.framePerSecond*n)/1e3+this._ratioOffset,f=0;if(this._previousDelay=e,this._previousRatio=p,(i>t&&p>u||t>i&&p<u)&&!r)a=!1,f=this._getKeyValue(h[h.length-1].value);else if(this._animation.loopMode!==qe.Animation.ANIMATIONLOOPMODE_CYCLE){var d=i.toString()+t.toString();if(!this._offsetsCache[d]){var m=this._interpolate(t,0,qe.Animation.ANIMATIONLOOPMODE_CYCLE),g=this._interpolate(i,0,qe.Animation.ANIMATIONLOOPMODE_CYCLE);switch(this._animation.dataType){case qe.Animation.ANIMATIONTYPE_FLOAT:this._offsetsCache[d]=g-m;break;case qe.Animation.ANIMATIONTYPE_QUATERNION:this._offsetsCache[d]=g.subtract(m);break;case qe.Animation.ANIMATIONTYPE_VECTOR3:this._offsetsCache[d]=g.subtract(m);case qe.Animation.ANIMATIONTYPE_VECTOR2:this._offsetsCache[d]=g.subtract(m);case qe.Animation.ANIMATIONTYPE_SIZE:this._offsetsCache[d]=g.subtract(m);case qe.Animation.ANIMATIONTYPE_COLOR3:this._offsetsCache[d]=g.subtract(m)}this._highLimitsCache[d]=g}f=this._highLimitsCache[d],c=this._offsetsCache[d]}if(void 0===c)switch(this._animation.dataType){case qe.Animation.ANIMATIONTYPE_FLOAT:c=0;break;case qe.Animation.ANIMATIONTYPE_QUATERNION:c=new qe.Quaternion(0,0,0,0);break;case qe.Animation.ANIMATIONTYPE_VECTOR3:c=qe.Vector3.Zero();break;case qe.Animation.ANIMATIONTYPE_VECTOR2:c=qe.Vector2.Zero();break;case qe.Animation.ANIMATIONTYPE_SIZE:c=qe.Size.Zero();break;case qe.Animation.ANIMATIONTYPE_COLOR3:c=qe.Color3.Black()}var _=p/u>>0,v=a?t+p%u:i,y=this._interpolate(v,_,this._animation.loopMode,c,f);this.setValue(y);for(var b=this._animation.getEvents(),x=0;x<b.length;x++)if(u>0&&v>=b[x].frame&&b[x].frame>=t||u<0&&v<=b[x].frame&&b[x].frame<=t){var T=b[x];T.isDone||(T.onlyOnce&&(b.splice(x,1),x--),T.isDone=!0,T.action())}else b[x].isDone&&!b[x].onlyOnce&&(b[x].isDone=!1);return a||(this._stopped=!0),a},e}(),qe.RuntimeAnimation=Je,$e=us||(us={}),et=function(){function e(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(e.prototype,"speedRatio",{get:function(){return this._speedRatio},set:function(e){for(var t=0;t<this._runtimeAnimations.length;t++){this._runtimeAnimations[t]._prepareForSpeedRatioChange(e)}this._speedRatio=e},enumerable:!0,configurable:!0}),e.prototype.getAnimations=function(){return this._runtimeAnimations},e.prototype.appendAnimations=function(e,t){for(var i=0;i<t.length;i++){var r=t[i];this._runtimeAnimations.push(new $e.RuntimeAnimation(e,r))}},e.prototype.getAnimationByTargetProperty=function(e){for(var t=this._runtimeAnimations,i=0;i<t.length;i++)if(t[i].animation.targetProperty===e)return t[i].animation;return null},e.prototype.getRuntimeAnimationByTargetProperty=function(e){for(var t=this._runtimeAnimations,i=0;i<t.length;i++)if(t[i].animation.targetProperty===e)return t[i];return null},e.prototype.reset=function(){for(var e=this._runtimeAnimations,t=0;t<e.length;t++)e[t].reset();for(t=0;t<e.length;t++){e[t].animate(0,this.fromFrame,this.toFrame,!1,this._speedRatio)}this._localDelayOffset=null,this._pausedDelay=null},e.prototype.enableBlending=function(e){for(var t=this._runtimeAnimations,i=0;i<t.length;i++)t[i].animation.enableBlending=!0,t[i].animation.blendingSpeed=e},e.prototype.disableBlending=function(){for(var e=this._runtimeAnimations,t=0;t<e.length;t++)e[t].animation.enableBlending=!1},e.prototype.goToFrame=function(e){var t=this._runtimeAnimations;if(t[0]){var i=t[0].animation.framePerSecond,r=1e3*(e-t[0].currentFrame)/i;null===this._localDelayOffset&&(this._localDelayOffset=0),this._localDelayOffset-=r}for(var n=0;n<t.length;n++)t[n].goToFrame(e)},e.prototype.pause=function(){this._paused||(this._paused=!0)},e.prototype.restart=function(){this._paused=!1},e.prototype.stop=function(e){if(e){var t=this._scene._activeAnimatables.indexOf(this);if(t>-1){for(var i=(r=this._runtimeAnimations).length-1;i>=0;i--)"string"==typeof e&&r[i].animation.name!=e||(r[i].dispose(),r.splice(i,1));0==r.length&&(this._scene._activeAnimatables.splice(t,1),this.onAnimationEnd&&this.onAnimationEnd())}}else{if((i=this._scene._activeAnimatables.indexOf(this))>-1){this._scene._activeAnimatables.splice(i,1);var r=this._runtimeAnimations;for(i=0;i<r.length;i++)r[i].dispose();this.onAnimationEnd&&this.onAnimationEnd()}}},e.prototype._animate=function(e){if(this._paused)return this.animationStarted=!1,null===this._pausedDelay&&(this._pausedDelay=e),!0;null===this._localDelayOffset?this._localDelayOffset=e:null!==this._pausedDelay&&(this._localDelayOffset+=e-this._pausedDelay,this._pausedDelay=null);var t,i=!1,r=this._runtimeAnimations;for(t=0;t<r.length;t++){var n=r[t].animate(e-this._localDelayOffset,this.fromFrame,this.toFrame,this.loopAnimation,this._speedRatio);i=i||n}if(this.animationStarted=i,!i)for(t=this._scene._activeAnimatables.indexOf(this),this._scene._activeAnimatables.splice(t,1),t=0;t<r.length;t++)r[t].dispose();return!i&&this.onAnimationEnd&&(this.onAnimationEnd(),this.onAnimationEnd=null),i},e}(),$e.Animatable=et,function(e){var t=function(){function e(){this._easingMode=e.EASINGMODE_EASEIN}return Object.defineProperty(e,"EASINGMODE_EASEIN",{get:function(){return e._EASINGMODE_EASEIN},enumerable:!0,configurable:!0}),Object.defineProperty(e,"EASINGMODE_EASEOUT",{get:function(){return e._EASINGMODE_EASEOUT},enumerable:!0,configurable:!0}),Object.defineProperty(e,"EASINGMODE_EASEINOUT",{get:function(){return e._EASINGMODE_EASEINOUT},enumerable:!0,configurable:!0}),e.prototype.setEasingMode=function(e){var t=Math.min(Math.max(e,0),2);this._easingMode=t},e.prototype.getEasingMode=function(){return this._easingMode},e.prototype.easeInCore=function(e){throw new Error("You must implement this method")},e.prototype.ease=function(t){switch(this._easingMode){case e.EASINGMODE_EASEIN:return this.easeInCore(t);case e.EASINGMODE_EASEOUT:return 1-this.easeInCore(1-t)}return t>=.5?.5*(1-this.easeInCore(2*(1-t)))+.5:.5*this.easeInCore(2*t)},e._EASINGMODE_EASEIN=0,e._EASINGMODE_EASEOUT=1,e._EASINGMODE_EASEINOUT=2,e}();e.EasingFunction=t;var i=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return Y(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 Y(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 n=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 Y(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=n;var o=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return Y(t,e),t.prototype.easeInCore=function(e){return e*e*e},t}(t);e.CubicEase=o;var s=function(e){function t(t,i){void 0===t&&(t=3),void 0===i&&(i=3);var r=e.call(this)||this;return r.oscillations=t,r.springiness=i,r}return Y(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=s;var a=function(e){function t(t){void 0===t&&(t=2);var i=e.call(this)||this;return i.exponent=t,i}return Y(t,e),t.prototype.easeInCore=function(e){return this.exponent<=0?e:(Math.exp(this.exponent*e)-1)/(Math.exp(this.exponent)-1)},t}(t);e.ExponentialEase=a;var h=function(e){function t(t){void 0===t&&(t=2);var i=e.call(this)||this;return i.power=t,i}return Y(t,e),t.prototype.easeInCore=function(e){var t=Math.max(0,this.power);return Math.pow(e,t)},t}(t);e.PowerEase=h;var l=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return Y(t,e),t.prototype.easeInCore=function(e){return e*e},t}(t);e.QuadraticEase=l;var c=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return Y(t,e),t.prototype.easeInCore=function(e){return e*e*e*e},t}(t);e.QuarticEase=c;var u=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return Y(t,e),t.prototype.easeInCore=function(e){return e*e*e*e*e},t}(t);e.QuinticEase=u;var p=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return Y(t,e),t.prototype.easeInCore=function(e){return 1-Math.sin(1.5707963267948966*(1-e))},t}(t);e.SineEase=p;var f=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 Y(i,t),i.prototype.easeInCore=function(t){return e.BezierCurve.interpolate(t,this.x1,this.y1,this.x2,this.y2)},i}(t);e.BezierCurveEase=f}(us||(us={})),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 Y(i,t),Object.defineProperty(i,"IsEqual",{get:function(){return i._IsEqual},enumerable:!0,configurable:!0}),Object.defineProperty(i,"IsDifferent",{get:function(){return i._IsDifferent},enumerable:!0,configurable:!0}),Object.defineProperty(i,"IsGreater",{get:function(){return i._IsGreater},enumerable:!0,configurable:!0}),Object.defineProperty(i,"IsLesser",{get:function(){return i._IsLesser},enumerable:!0,configurable:!0}),i.prototype.isValid=function(){switch(this.operator){case i.IsGreater:return this._effectiveTarget[this._property]>this.value;case i.IsLesser:return this._effectiveTarget[this._property]<this.value;case i.IsEqual:case i.IsDifferent:var e;return e=this.value.equals?this.value.equals(this._effectiveTarget[this._property]):this.value===this._effectiveTarget[this._property],this.operator===i.IsEqual?e:!e}return!1},i.prototype.serialize=function(){return this._serialize({name:"ValueCondition",properties:[e.Action._GetTargetProperty(this._target),{name:"propertyPath",value:this.propertyPath},{name:"value",value:e.Action._SerializeValueAsString(this.value)},{name:"operator",value:i.GetOperatorName(this.operator)}]})},i.GetOperatorName=function(e){switch(e){case i._IsEqual:return"IsEqual";case i._IsDifferent:return"IsDifferent";case i._IsGreater:return"IsGreater";case i._IsLesser:return"IsLesser";default:return""}},i._IsEqual=0,i._IsDifferent=1,i._IsGreater=2,i._IsLesser=3,i}(t);e.ValueCondition=i;var r=function(e){function t(t,i){var r=e.call(this,t)||this;return r.predicate=i,r}return Y(t,e),t.prototype.isValid=function(){return this.predicate()},t}(t);e.PredicateCondition=r;var n=function(t){function i(e,i,r){var n=t.call(this,e)||this;return n.value=r,n._target=i,n}return Y(i,t),i.prototype.isValid=function(){return this._target.state===this.value},i.prototype.serialize=function(){return this._serialize({name:"StateCondition",properties:[e.Action._GetTargetProperty(this._target),{name:"value",value:this.value}]})},i}(t);e.StateCondition=n}(us||(us={})),tt=us||(us={}),it=function(){function e(e,t){this.triggerOptions=e,this.onBeforeExecuteObservable=new tt.Observable,e.parameter?(this.trigger=e.trigger,this._triggerParameter=e.parameter):this.trigger=e,this._nextActiveAction=this,this._condition=t}return e.prototype._prepare=function(){},e.prototype.getTriggerParameter=function(){return this._triggerParameter},e.prototype._executeCurrent=function(e){if(this._nextActiveAction._condition){var t=this._nextActiveAction._condition,i=this._actionManager.getScene().getRenderId();if(t._evaluationId===i){if(!t._currentResult)return}else{if(t._evaluationId=i,!t.isValid())return void(t._currentResult=!1);t._currentResult=!0}}this.onBeforeExecuteObservable.notifyObservers(this),this._nextActiveAction.execute(e),this.skipToNextActiveAction()},e.prototype.execute=function(e){},e.prototype.skipToNextActiveAction=function(){this._nextActiveAction._child?(this._nextActiveAction._child._actionManager||(this._nextActiveAction._child._actionManager=this._actionManager),this._nextActiveAction=this._nextActiveAction._child):this._nextActiveAction=this},e.prototype.then=function(e){return this._child=e,e._actionManager=this._actionManager,e._prepare(),e},e.prototype._getProperty=function(e){return this._actionManager._getProperty(e)},e.prototype._getEffectiveTarget=function(e,t){return this._actionManager._getEffectiveTarget(e,t)},e.prototype.serialize=function(e){},e.prototype._serialize=function(e,t){var i={type:1,children:[],name:e.name,properties:e.properties||[]};if(this._child&&this._child.serialize(i),this._condition){var r=this._condition.serialize();return r.children.push(i),t&&t.children.push(r),r}return t&&t.children.push(i),i},e._SerializeValueAsString=function(e){return"number"==typeof e?e.toString():"boolean"==typeof e?e?"true":"false":e instanceof tt.Vector2?e.x+", "+e.y:e instanceof tt.Vector3?e.x+", "+e.y+", "+e.z:e instanceof tt.Color3?e.r+", "+e.g+", "+e.b:e instanceof tt.Color4?e.r+", "+e.g+", "+e.b+", "+e.a:e},e._GetTargetProperty=function(e){return{name:"target",targetType:e instanceof tt.Mesh?"MeshProperties":e instanceof tt.Light?"LightProperties":e instanceof tt.Camera?"CameraProperties":"SceneProperties",value:e instanceof tt.Scene?"Scene":e.name}},e}(),tt.Action=it,function(e){var t=function(){function e(e,t,i,r,n,o){this.source=e,this.pointerX=t,this.pointerY=i,this.meshUnderPointer=r,this.sourceEvent=n,this.additionalData=o}return e.CreateNew=function(t,i,r){var n=t.getScene();return new e(t,n.pointerX,n.pointerY,n.meshUnderPointer,i,r)},e.CreateNewFromSprite=function(t,i,r,n){return new e(t,i.pointerX,i.pointerY,i.meshUnderPointer,r,n)},e.CreateNewFromScene=function(t,i){return new e(null,t.pointerX,t.pointerY,t.meshUnderPointer,i)},e.CreateNewFromPrimitive=function(t,i,r,n){return new e(t,i.x,i.y,null,r,n)},e}();e.ActionEvent=t;var i=function(){function t(e){this.actions=new Array,this.hoverCursor="",this._scene=e,e._actionManagers.push(this)}return Object.defineProperty(t,"NothingTrigger",{get:function(){return t._NothingTrigger},enumerable:!0,configurable:!0}),Object.defineProperty(t,"OnPickTrigger",{get:function(){return t._OnPickTrigger},enumerable:!0,configurable:!0}),Object.defineProperty(t,"OnLeftPickTrigger",{get:function(){return t._OnLeftPickTrigger},enumerable:!0,configurable:!0}),Object.defineProperty(t,"OnRightPickTrigger",{get:function(){return t._OnRightPickTrigger},enumerable:!0,configurable:!0}),Object.defineProperty(t,"OnCenterPickTrigger",{get:function(){return t._OnCenterPickTrigger},enumerable:!0,configurable:!0}),Object.defineProperty(t,"OnPickDownTrigger",{get:function(){return t._OnPickDownTrigger},enumerable:!0,configurable:!0}),Object.defineProperty(t,"OnDoublePickTrigger",{get:function(){return t._OnDoublePickTrigger},enumerable:!0,configurable:!0}),Object.defineProperty(t,"OnPickUpTrigger",{get:function(){return t._OnPickUpTrigger},enumerable:!0,configurable:!0}),Object.defineProperty(t,"OnPickOutTrigger",{get:function(){return t._OnPickOutTrigger},enumerable:!0,configurable:!0}),Object.defineProperty(t,"OnLongPressTrigger",{get:function(){return t._OnLongPressTrigger},enumerable:!0,configurable:!0}),Object.defineProperty(t,"OnPointerOverTrigger",{get:function(){return t._OnPointerOverTrigger},enumerable:!0,configurable:!0}),Object.defineProperty(t,"OnPointerOutTrigger",{get:function(){return t._OnPointerOutTrigger},enumerable:!0,configurable:!0}),Object.defineProperty(t,"OnEveryFrameTrigger",{get:function(){return t._OnEveryFrameTrigger},enumerable:!0,configurable:!0}),Object.defineProperty(t,"OnIntersectionEnterTrigger",{get:function(){return t._OnIntersectionEnterTrigger},enumerable:!0,configurable:!0}),Object.defineProperty(t,"OnIntersectionExitTrigger",{get:function(){return t._OnIntersectionExitTrigger},enumerable:!0,configurable:!0}),Object.defineProperty(t,"OnKeyDownTrigger",{get:function(){return t._OnKeyDownTrigger},enumerable:!0,configurable:!0}),Object.defineProperty(t,"OnKeyUpTrigger",{get:function(){return t._OnKeyUpTrigger},enumerable:!0,configurable:!0}),t.prototype.dispose=function(){for(var e=this._scene._actionManagers.indexOf(this),i=0;i<this.actions.length;i++){var r=this.actions[i];t.Triggers[r.trigger]--,0===t.Triggers[r.trigger]&&delete t.Triggers[r.trigger]}e>-1&&this._scene._actionManagers.splice(e,1)},t.prototype.getScene=function(){return this._scene},t.prototype.hasSpecificTriggers=function(e){for(var t=0;t<this.actions.length;t++){var i=this.actions[t];if(e.indexOf(i.trigger)>-1)return!0}return!1},t.prototype.hasSpecificTrigger=function(e){for(var t=0;t<this.actions.length;t++){if(this.actions[t].trigger===e)return!0}return!1},Object.defineProperty(t.prototype,"hasPointerTriggers",{get:function(){for(var e=0;e<this.actions.length;e++){var i=this.actions[e];if(i.trigger>=t._OnPickTrigger&&i.trigger<=t._OnPointerOutTrigger)return!0}return!1},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"hasPickTriggers",{get:function(){for(var e=0;e<this.actions.length;e++){var i=this.actions[e];if(i.trigger>=t._OnPickTrigger&&i.trigger<=t._OnPickUpTrigger)return!0}return!1},enumerable:!0,configurable:!0}),Object.defineProperty(t,"HasTriggers",{get:function(){for(var e in t.Triggers)if(t.Triggers.hasOwnProperty(e))return!0;return!1},enumerable:!0,configurable:!0}),Object.defineProperty(t,"HasPickTriggers",{get:function(){for(var e in t.Triggers)if(t.Triggers.hasOwnProperty(e)){var i=parseInt(e);if(i>=t._OnPickTrigger&&i<=t._OnPickUpTrigger)return!0}return!1},enumerable:!0,configurable:!0}),t.HasSpecificTrigger=function(e){for(var i in t.Triggers){if(t.Triggers.hasOwnProperty(i))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;r<this.actions.length;r++){var n=this.actions[r];if(n.trigger===e){if(i&&(e===t.OnKeyUpTrigger||e===t.OnKeyDownTrigger)){var o=n.getTriggerParameter();if(o&&o!==i.sourceEvent.keyCode){if(!o.toLowerCase)continue;var s=o.toLowerCase();if(s!==i.sourceEvent.key){var a=i.sourceEvent.charCode?i.sourceEvent.charCode:i.sourceEvent.keyCode;if(String.fromCharCode(a).toLowerCase()!==s)continue}}}n._executeCurrent(i)}}},t.prototype._getEffectiveTarget=function(e,t){for(var i=t.split("."),r=0;r<i.length-1;r++)e=e[i[r]];return e},t.prototype._getProperty=function(e){var t=e.split(".");return t[t.length-1]},t.prototype.serialize=function(i){for(var r={children:new Array,name:i,type:3,properties:new Array},n=0;n<this.actions.length;n++){var o={type:0,children:new Array,name:t.GetTriggerName(this.actions[n].trigger),properties:new Array},s=this.actions[n].triggerOptions;if(s&&"number"!=typeof s)if(s.parameter instanceof e.Node)o.properties.push(e.Action._GetTargetProperty(s.parameter));else{var a={};e.Tools.DeepCopy(s.parameter,a,["mesh"]),s.parameter.mesh&&(a._meshId=s.parameter.mesh.id),o.properties.push({name:"parameter",targetType:null,value:a})}this.actions[n].serialize(o),r.children.push(o)}return r},t.Parse=function(i,r,n){var o=new t(n);null===r?n.actionManager=o:r.actionManager=o;for(var s=function(t,i,r,n){if(null===n){var o=parseFloat(i);return"true"===i||"false"===i?"true"===i:isNaN(o)?i:o}for(var s=n.split("."),a=i.split(","),h=0;h<s.length;h++)r=r[s[h]];if("boolean"==typeof r)return"true"===a[0];if("string"==typeof r)return a[0];var l=new Array;for(h=0;h<a.length;h++)l.push(parseFloat(a[h]));return r instanceof e.Vector3?e.Vector3.FromArray(l):r instanceof e.Vector4?e.Vector4.FromArray(l):r instanceof e.Color3?e.Color3.FromArray(l):r instanceof e.Color4?e.Color4.FromArray(l):parseFloat(a[0])},a=function(i,r,h,l,c){if(void 0===c&&(c=null),!i.detached){var u=new Array,p=null,f=null,d=i.combine&&i.combine.length>0;if(2===i.type?u.push(o):u.push(r),d){for(var m=new Array,g=0;g<i.combine.length;g++)a(i.combine[g],t.NothingTrigger,h,l,m);u.push(m)}else for(var _=0;_<i.properties.length;_++){var v=i.properties[_].value,y=i.properties[_].name,b=i.properties[_].targetType;"target"===y?v=p=null!==b&&"SceneProperties"===b?n:n.getNodeByName(v):"parent"===y?v=n.getNodeByName(v):"sound"===y?v=n.getSoundByName(v):"propertyPath"!==y?v=2===i.type&&"operator"===y?e.ValueCondition[v]:s(0,v,p,"value"===y?f:null):f=v,u.push(v)}if(null===c?u.push(h):u.push(null),"InterpolateValueAction"===i.name){var x=u[u.length-2];u[u.length-1]=x,u[u.length-2]=h}var T,E,A,P=(T=i.name,E=u,(A=Object.create(e.Tools.Instantiate("BABYLON."+T).prototype)).constructor.apply(A,E),A);if(P instanceof e.Condition&&null!==h){var M=new e.DoNothingAction(r,h);l?l.then(M):o.registerAction(M),l=M}null===c?P instanceof e.Condition?(h=P,P=l):(h=null,l?l.then(P):o.registerAction(P)):c.push(P);for(_=0;_<i.children.length;_++)a(i.children[_],r,h,P,null)}},h=0;h<i.children.length;h++){var l,c=i.children[h];if(c.properties.length>0){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<c.children.length;f++)c.detached||a(c.children[f],l,null,null)}},t.GetTriggerName=function(e){switch(e){case 0:return"NothingTrigger";case 1:return"OnPickTrigger";case 2:return"OnLeftPickTrigger";case 3:return"OnRightPickTrigger";case 4:return"OnCenterPickTrigger";case 5:return"OnPickDownTrigger";case 6:return"OnPickUpTrigger";case 7:return"OnLongPressTrigger";case 8:return"OnPointerOverTrigger";case 9:return"OnPointerOutTrigger";case 10:return"OnEveryFrameTrigger";case 11:return"OnIntersectionEnterTrigger";case 12:return"OnIntersectionExitTrigger";case 13:return"OnKeyDownTrigger";case 14:return"OnKeyUpTrigger";case 15:return"OnPickOutTrigger";default:return""}},t._NothingTrigger=0,t._OnPickTrigger=1,t._OnLeftPickTrigger=2,t._OnRightPickTrigger=3,t._OnCenterPickTrigger=4,t._OnPickDownTrigger=5,t._OnDoublePickTrigger=6,t._OnPickUpTrigger=7,t._OnLongPressTrigger=8,t._OnPointerOverTrigger=9,t._OnPointerOutTrigger=10,t._OnEveryFrameTrigger=11,t._OnIntersectionEnterTrigger=12,t._OnIntersectionExitTrigger=13,t._OnKeyDownTrigger=14,t._OnKeyUpTrigger=15,t._OnPickOutTrigger=16,t.Triggers={},t}();e.ActionManager=i}(us||(us={})),rt=us||(us={}),nt=function(e){function t(t,i,r,n,o,s,a,h){void 0===o&&(o=1e3);var l=e.call(this,t,s)||this;return l.propertyPath=r,l.value=n,l.duration=o,l.stopOtherAnimations=a,l.onInterpolationDone=h,l.onInterpolationDoneObservable=new rt.Observable,l._target=l._effectiveTarget=i,l}return Y(t,e),t.prototype._prepare=function(){this._effectiveTarget=this._getEffectiveTarget(this._effectiveTarget,this.propertyPath),this._property=this._getProperty(this.propertyPath)},t.prototype.execute=function(){var e,t=this,i=this._actionManager.getScene(),r=[{frame:0,value:this._effectiveTarget[this._property]},{frame:100,value:this.value}];if("number"==typeof this.value)e=rt.Animation.ANIMATIONTYPE_FLOAT;else if(this.value instanceof rt.Color3)e=rt.Animation.ANIMATIONTYPE_COLOR3;else if(this.value instanceof rt.Vector3)e=rt.Animation.ANIMATIONTYPE_VECTOR3;else if(this.value instanceof rt.Matrix)e=rt.Animation.ANIMATIONTYPE_MATRIX;else{if(!(this.value instanceof rt.Quaternion))return void rt.Tools.Warn("InterpolateValueAction: Unsupported type ("+typeof this.value+")");e=rt.Animation.ANIMATIONTYPE_QUATERNION}var n=new rt.Animation("InterpolateValueAction",this._property,1e3/this.duration*100,e,rt.Animation.ANIMATIONLOOPMODE_CONSTANT);n.setKeys(r),this.stopOtherAnimations&&i.stopAnimation(this._effectiveTarget);i.beginDirectAnimation(this._effectiveTarget,[n],0,100,!1,1,function(){t.onInterpolationDoneObservable.notifyObservers(t),t.onInterpolationDone&&t.onInterpolationDone()})},t.prototype.serialize=function(t){return e.prototype._serialize.call(this,{name:"InterpolateValueAction",properties:[rt.Action._GetTargetProperty(this._target),{name:"propertyPath",value:this.propertyPath},{name:"value",value:rt.Action._SerializeValueAsString(this.value)},{name:"duration",value:rt.Action._SerializeValueAsString(this.duration)},{name:"stopOtherAnimations",value:rt.Action._SerializeValueAsString(this.stopOtherAnimations)||!1}]},t)},t}(rt.Action),rt.InterpolateValueAction=nt,function(e){var t=function(t){function i(e,i,r,n){var o=t.call(this,e,n)||this;return o.propertyPath=r,o._target=o._effectiveTarget=i,o}return Y(i,t),i.prototype._prepare=function(){this._effectiveTarget=this._getEffectiveTarget(this._effectiveTarget,this.propertyPath),this._property=this._getProperty(this.propertyPath)},i.prototype.execute=function(){this._effectiveTarget[this._property]=!this._effectiveTarget[this._property]},i.prototype.serialize=function(i){return t.prototype._serialize.call(this,{name:"SwitchBooleanAction",properties:[e.Action._GetTargetProperty(this._target),{name:"propertyPath",value:this.propertyPath}]},i)},i}(e.Action);e.SwitchBooleanAction=t;var i=function(t){function i(e,i,r,n){var o=t.call(this,e,n)||this;return o.value=r,o._target=i,o}return Y(i,t),i.prototype.execute=function(){this._target.state=this.value},i.prototype.serialize=function(i){return t.prototype._serialize.call(this,{name:"SetStateAction",properties:[e.Action._GetTargetProperty(this._target),{name:"value",value:this.value}]},i)},i}(e.Action);e.SetStateAction=i;var r=function(t){function i(e,i,r,n,o){var s=t.call(this,e,o)||this;return s.propertyPath=r,s.value=n,s._target=s._effectiveTarget=i,s}return Y(i,t),i.prototype._prepare=function(){this._effectiveTarget=this._getEffectiveTarget(this._effectiveTarget,this.propertyPath),this._property=this._getProperty(this.propertyPath)},i.prototype.execute=function(){this._effectiveTarget[this._property]=this.value,this._target.markAsDirty&&this._target.markAsDirty(this._property)},i.prototype.serialize=function(i){return t.prototype._serialize.call(this,{name:"SetValueAction",properties:[e.Action._GetTargetProperty(this._target),{name:"propertyPath",value:this.propertyPath},{name:"value",value:e.Action._SerializeValueAsString(this.value)}]},i)},i}(e.Action);e.SetValueAction=r;var n=function(t){function i(e,i,r,n,o){var s=t.call(this,e,o)||this;return s.propertyPath=r,s.value=n,s._target=s._effectiveTarget=i,s}return Y(i,t),i.prototype._prepare=function(){this._effectiveTarget=this._getEffectiveTarget(this._effectiveTarget,this.propertyPath),this._property=this._getProperty(this.propertyPath),"number"!=typeof this._effectiveTarget[this._property]&&e.Tools.Warn("Warning: IncrementValueAction can only be used with number values")},i.prototype.execute=function(){this._effectiveTarget[this._property]+=this.value,this._target.markAsDirty&&this._target.markAsDirty(this._property)},i.prototype.serialize=function(i){return t.prototype._serialize.call(this,{name:"IncrementValueAction",properties:[e.Action._GetTargetProperty(this._target),{name:"propertyPath",value:this.propertyPath},{name:"value",value:e.Action._SerializeValueAsString(this.value)}]},i)},i}(e.Action);e.IncrementValueAction=n;var o=function(t){function i(e,i,r,n,o,s){var a=t.call(this,e,s)||this;return a.from=r,a.to=n,a.loop=o,a._target=i,a}return Y(i,t),i.prototype._prepare=function(){},i.prototype.execute=function(){this._actionManager.getScene().beginAnimation(this._target,this.from,this.to,this.loop)},i.prototype.serialize=function(i){return t.prototype._serialize.call(this,{name:"PlayAnimationAction",properties:[e.Action._GetTargetProperty(this._target),{name:"from",value:String(this.from)},{name:"to",value:String(this.to)},{name:"loop",value:e.Action._SerializeValueAsString(this.loop)||!1}]},i)},i}(e.Action);e.PlayAnimationAction=o;var s=function(t){function i(e,i,r){var n=t.call(this,e,r)||this;return n._target=i,n}return Y(i,t),i.prototype._prepare=function(){},i.prototype.execute=function(){this._actionManager.getScene().stopAnimation(this._target)},i.prototype.serialize=function(i){return t.prototype._serialize.call(this,{name:"StopAnimationAction",properties:[e.Action._GetTargetProperty(this._target)]},i)},i}(e.Action);e.StopAnimationAction=s;var a=function(t){function i(i,r){return void 0===i&&(i=e.ActionManager.NothingTrigger),t.call(this,i,r)||this}return Y(i,t),i.prototype.execute=function(){},i.prototype.serialize=function(e){return t.prototype._serialize.call(this,{name:"DoNothingAction",properties:[]},e)},i}(e.Action);e.DoNothingAction=a;var h=function(e){function t(t,i,r){var n=e.call(this,t,r)||this;return n.children=i,n}return Y(t,e),t.prototype._prepare=function(){for(var e=0;e<this.children.length;e++)this.children[e]._actionManager=this._actionManager,this.children[e]._prepare()},t.prototype.execute=function(e){for(var t=0;t<this.children.length;t++)this.children[t].execute(e)},t.prototype.serialize=function(t){for(var i=e.prototype._serialize.call(this,{name:"CombineAction",properties:[],combine:[]},t),r=0;r<this.children.length;r++)i.combine.push(this.children[r].serialize(null));return i},t}(e.Action);e.CombineAction=h;var l=function(e){function t(t,i,r){var n=e.call(this,t,r)||this;return n.func=i,n}return Y(t,e),t.prototype.execute=function(e){this.func(e)},t}(e.Action);e.ExecuteCodeAction=l;var c=function(t){function i(e,i,r,n){var o=t.call(this,e,n)||this;return o._target=i,o._parent=r,o}return Y(i,t),i.prototype._prepare=function(){},i.prototype.execute=function(){if(this._target.parent!==this._parent){var t=this._parent.getWorldMatrix().clone();t.invert(),this._target.position=e.Vector3.TransformCoordinates(this._target.position,t),this._target.parent=this._parent}},i.prototype.serialize=function(i){return t.prototype._serialize.call(this,{name:"SetParentAction",properties:[e.Action._GetTargetProperty(this._target),e.Action._GetTargetProperty(this._parent)]},i)},i}(e.Action);e.SetParentAction=c;var u=function(e){function t(t,i,r){var n=e.call(this,t,r)||this;return n._sound=i,n}return Y(t,e),t.prototype._prepare=function(){},t.prototype.execute=function(){void 0!==this._sound&&this._sound.play()},t.prototype.serialize=function(t){return e.prototype._serialize.call(this,{name:"PlaySoundAction",properties:[{name:"sound",value:this._sound.name}]},t)},t}(e.Action);e.PlaySoundAction=u;var p=function(e){function t(t,i,r){var n=e.call(this,t,r)||this;return n._sound=i,n}return Y(t,e),t.prototype._prepare=function(){},t.prototype.execute=function(){void 0!==this._sound&&this._sound.stop()},t.prototype.serialize=function(t){return e.prototype._serialize.call(this,{name:"StopSoundAction",properties:[{name:"sound",value:this._sound.name}]},t)},t}(e.Action);e.StopSoundAction=p}(us||(us={})),ot=us||(us={}),st=function(){function e(e,t,i,r,n,o,s){if(void 0===o&&(o=.01),void 0===s&&(s=ot.Texture.TRILINEAR_SAMPLINGMODE),this.name=e,this.sprites=new Array,this.renderingGroupId=0,this.layerMask=268435455,this.fogEnabled=!0,this.isPickable=!1,this.onDisposeObservable=new ot.Observable,this._vertexBuffers={},this._capacity=i,this._spriteTexture=new ot.Texture(t,n,!0,!1,s),this._spriteTexture.wrapU=ot.Texture.CLAMP_ADDRESSMODE,this._spriteTexture.wrapV=ot.Texture.CLAMP_ADDRESSMODE,r.width&&r.height)this.cellWidth=r.width,this.cellHeight=r.height;else{if(void 0===r)return;this.cellWidth=r,this.cellHeight=r}this._epsilon=o,this._scene=n,this._scene.spriteManagers.push(this);for(var a=[],h=0,l=0;l<i;l++)a.push(h),a.push(h+1),a.push(h+2),a.push(h),a.push(h+2),a.push(h+3),h+=4;this._indexBuffer=n.getEngine().createIndexBuffer(a),this._vertexData=new Float32Array(16*i*4),this._buffer=new ot.Buffer(n.getEngine(),this._vertexData,!0,16);var c=this._buffer.createVertexBuffer(ot.VertexBuffer.PositionKind,0,4),u=this._buffer.createVertexBuffer("options",4,4),p=this._buffer.createVertexBuffer("cellInfo",8,4),f=this._buffer.createVertexBuffer(ot.VertexBuffer.ColorKind,12,4);this._vertexBuffers[ot.VertexBuffer.PositionKind]=c,this._vertexBuffers.options=u,this._vertexBuffers.cellInfo=p,this._vertexBuffers[ot.VertexBuffer.ColorKind]=f,this._effectBase=this._scene.getEngine().createEffect("sprites",[ot.VertexBuffer.PositionKind,"options","cellInfo",ot.VertexBuffer.ColorKind],["view","projection","textureInfos","alphaTest"],["diffuseSampler"],""),this._effectFog=this._scene.getEngine().createEffect("sprites",[ot.VertexBuffer.PositionKind,"options","cellInfo",ot.VertexBuffer.ColorKind],["view","projection","textureInfos","alphaTest","vFogInfos","vFogColor"],["diffuseSampler"],"#define FOG")}return Object.defineProperty(e.prototype,"onDispose",{set:function(e){this._onDisposeObserver&&this.onDisposeObservable.remove(this._onDisposeObserver),this._onDisposeObserver=this.onDisposeObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"texture",{get:function(){return this._spriteTexture},set:function(e){this._spriteTexture=e},enumerable:!0,configurable:!0}),e.prototype._appendSpriteVertex=function(e,t,i,r,n){var o=16*e;0===i?i=this._epsilon:1===i&&(i=1-this._epsilon),0===r?r=this._epsilon:1===r&&(r=1-this._epsilon),this._vertexData[o]=t.position.x,this._vertexData[o+1]=t.position.y,this._vertexData[o+2]=t.position.z,this._vertexData[o+3]=t.angle,this._vertexData[o+4]=t.width,this._vertexData[o+5]=t.height,this._vertexData[o+6]=i,this._vertexData[o+7]=r,this._vertexData[o+8]=t.invertU?1:0,this._vertexData[o+9]=t.invertV?1:0;var s=t.cellIndex/n>>0;this._vertexData[o+10]=t.cellIndex-s*n,this._vertexData[o+11]=s,this._vertexData[o+12]=t.color.r,this._vertexData[o+13]=t.color.g,this._vertexData[o+14]=t.color.b,this._vertexData[o+15]=t.color.a},e.prototype.intersects=function(e,t,i,r){for(var n=Math.min(this._capacity,this.sprites.length),o=ot.Vector3.Zero(),s=ot.Vector3.Zero(),a=Number.MAX_VALUE,h=null,l=ot.Vector3.Zero(),c=t.getViewMatrix(),u=0;u<n;u++){var p=this.sprites[u];if(p){if(i){if(!i(p))continue}else if(!p.isPickable)continue;if(ot.Vector3.TransformCoordinatesToRef(p.position,c,l),o.copyFromFloats(l.x-p.width/2,l.y-p.height/2,l.z),s.copyFromFloats(l.x+p.width/2,l.y+p.height/2,l.z),e.intersectsBoxMinMax(o,s)){var f=ot.Vector3.Distance(l,e.origin);if(a>f&&(a=f,h=p,r))break}}}if(h){var d=new ot.PickingInfo;return d.hit=!0,d.pickedSprite=h,d.distance=a,d}return null},e.prototype.render=function(){if(this._effectBase.isReady()&&this._effectFog.isReady()&&this._spriteTexture&&this._spriteTexture.isReady()){for(var e=this._scene.getEngine(),t=this._spriteTexture.getBaseSize(),i=e.getDeltaTime(),r=Math.min(this._capacity,this.sprites.length),n=t.width/this.cellWidth,o=0,s=0;s<r;s++){var a=this.sprites[s];a&&(a._animate(i),this._appendSpriteVertex(o++,a,0,0,n),this._appendSpriteVertex(o++,a,1,0,n),this._appendSpriteVertex(o++,a,1,1,n),this._appendSpriteVertex(o++,a,0,1,n))}this._buffer.update(this._vertexData);var h=this._effectBase;this._scene.fogEnabled&&this._scene.fogMode!==ot.Scene.FOGMODE_NONE&&this.fogEnabled&&(h=this._effectFog),e.enableEffect(h);var l=this._scene.getViewMatrix();h.setTexture("diffuseSampler",this._spriteTexture),h.setMatrix("view",l),h.setMatrix("projection",this._scene.getProjectionMatrix()),h.setFloat2("textureInfos",this.cellWidth/t.width,this.cellHeight/t.height),this._scene.fogEnabled&&this._scene.fogMode!==ot.Scene.FOGMODE_NONE&&this.fogEnabled&&(h.setFloat4("vFogInfos",this._scene.fogMode,this._scene.fogStart,this._scene.fogEnd,this._scene.fogDensity),h.setColor3("vFogColor",this._scene.fogColor)),e.bindBuffers(this._vertexBuffers,this._indexBuffer,h),e.setDepthFunctionToLessOrEqual(),h.setBool("alphaTest",!0),e.setColorWrite(!1),e.drawElementsType(ot.Material.TriangleFillMode,0,6*r),e.setColorWrite(!0),h.setBool("alphaTest",!1),e.setAlphaMode(ot.Engine.ALPHA_COMBINE),e.drawElementsType(ot.Material.TriangleFillMode,0,6*r),e.setAlphaMode(ot.Engine.ALPHA_DISABLE)}},e.prototype.dispose=function(){this._buffer&&(this._buffer.dispose(),this._buffer=null),this._indexBuffer&&(this._scene.getEngine()._releaseBuffer(this._indexBuffer),this._indexBuffer=null),this._spriteTexture&&(this._spriteTexture.dispose(),this._spriteTexture=null);var e=this._scene.spriteManagers.indexOf(this);this._scene.spriteManagers.splice(e,1),this.onDisposeObservable.notifyObservers(this),this.onDisposeObservable.clear()},e}(),ot.SpriteManager=st,at=us||(us={}),ht=function(){function e(e,t){this.name=e,this.color=new at.Color4(1,1,1,1),this.width=1,this.height=1,this.angle=0,this.cellIndex=0,this.invertU=0,this.invertV=0,this.animations=new Array,this.isPickable=!1,this._animationStarted=!1,this._loopAnimation=!1,this._fromIndex=0,this._toIndex=0,this._delay=0,this._direction=1,this._time=0,this._manager=t,this._manager.sprites.push(this),this.position=at.Vector3.Zero()}return Object.defineProperty(e.prototype,"size",{get:function(){return this.width},set:function(e){this.width=e,this.height=e},enumerable:!0,configurable:!0}),e.prototype.playAnimation=function(e,t,i,r,n){this._fromIndex=e,this._toIndex=t,this._loopAnimation=i,this._delay=r,this._animationStarted=!0,this._direction=e<t?1:-1,this.cellIndex=e,this._time=0,this._onAnimationEnd=n},e.prototype.stopAnimation=function(){this._animationStarted=!1},e.prototype._animate=function(e){this._animationStarted&&(this._time+=e,this._time>this._delay&&(this._time=this._time%this._delay,this.cellIndex+=this._direction,this.cellIndex>this._toIndex&&(this._loopAnimation?this.cellIndex=this._fromIndex:(this.cellIndex=this._toIndex,this._animationStarted=!1,this._onAnimationEnd&&this._onAnimationEnd(),this.disposeWhenFinishedAnimating&&this.dispose()))))},e.prototype.dispose=function(){for(var e=0;e<this._manager.sprites.length;e++)this._manager.sprites[e]==this&&this._manager.sprites.splice(e,1)},e}(),at.Sprite=ht,function(e){var t=function(){return function(e,t,i){this.bu=e,this.bv=t,this.distance=i,this.faceId=0,this.subMeshId=0}}();e.IntersectionInfo=t;var i=function(){function t(){this.hit=!1,this.distance=0,this.pickedPoint=null,this.pickedMesh=null,this.bu=0,this.bv=0,this.faceId=-1,this.subMeshId=0,this.pickedSprite=null}return t.prototype.getNormal=function(t,i){if(void 0===t&&(t=!1),void 0===i&&(i=!0),!this.pickedMesh||!this.pickedMesh.isVerticesDataPresent(e.VertexBuffer.NormalKind))return null;var r,n=this.pickedMesh.getIndices();if(!n)return null;if(i){var o=this.pickedMesh.getVerticesData(e.VertexBuffer.NormalKind),s=e.Vector3.FromArray(o,3*n[3*this.faceId]),a=e.Vector3.FromArray(o,3*n[3*this.faceId+1]),h=e.Vector3.FromArray(o,3*n[3*this.faceId+2]);s=s.scale(this.bu),a=a.scale(this.bv),h=h.scale(1-this.bu-this.bv),r=new e.Vector3(s.x+a.x+h.x,s.y+a.y+h.y,s.z+a.z+h.z)}else{var l=this.pickedMesh.getVerticesData(e.VertexBuffer.PositionKind),c=e.Vector3.FromArray(l,3*n[3*this.faceId]),u=e.Vector3.FromArray(l,3*n[3*this.faceId+1]),p=e.Vector3.FromArray(l,3*n[3*this.faceId+2]),f=c.subtract(u),d=p.subtract(u);r=e.Vector3.Cross(f,d)}return t&&(r=e.Vector3.TransformNormal(r,this.pickedMesh.getWorldMatrix())),e.Vector3.Normalize(r)},t.prototype.getTextureCoordinates=function(){if(!this.pickedMesh||!this.pickedMesh.isVerticesDataPresent(e.VertexBuffer.UVKind))return null;var t=this.pickedMesh.getIndices();if(!t)return null;var i=this.pickedMesh.getVerticesData(e.VertexBuffer.UVKind);if(!i)return null;var r=e.Vector2.FromArray(i,2*t[3*this.faceId]),n=e.Vector2.FromArray(i,2*t[3*this.faceId+1]),o=e.Vector2.FromArray(i,2*t[3*this.faceId+2]);return r=r.scale(1-this.bu-this.bv),n=n.scale(this.bu),o=o.scale(this.bv),new e.Vector2(r.x+n.x+o.x,r.y+n.y+o.y)},t}();e.PickingInfo=i}(us||(us={})),lt=us||(us={}),ct=function(){function e(e,t,i){void 0===i&&(i=Number.MAX_VALUE),this.origin=e,this.direction=t,this.length=i}return e.prototype.intersectsBoxMinMax=function(e,t){var i,r,n,o,s=0,a=Number.MAX_VALUE;if(Math.abs(this.direction.x)<1e-7){if(this.origin.x<e.x||this.origin.x>t.x)return!1}else if(i=1/this.direction.x,r=(e.x-this.origin.x)*i,(n=(t.x-this.origin.x)*i)===-1/0&&(n=1/0),r>n&&(o=r,r=n,n=o),(s=Math.max(r,s))>(a=Math.min(n,a)))return!1;if(Math.abs(this.direction.y)<1e-7){if(this.origin.y<e.y||this.origin.y>t.y)return!1}else if(i=1/this.direction.y,r=(e.y-this.origin.y)*i,(n=(t.y-this.origin.y)*i)===-1/0&&(n=1/0),r>n&&(o=r,r=n,n=o),(s=Math.max(r,s))>(a=Math.min(n,a)))return!1;if(Math.abs(this.direction.z)<1e-7){if(this.origin.z<e.z||this.origin.z>t.z)return!1}else if(i=1/this.direction.z,r=(e.z-this.origin.z)*i,(n=(t.z-this.origin.z)*i)===-1/0&&(n=1/0),r>n&&(o=r,r=n,n=o),(s=Math.max(r,s))>(a=Math.min(n,a)))return!1;return!0},e.prototype.intersectsBox=function(e){return this.intersectsBoxMinMax(e.minimum,e.maximum)},e.prototype.intersectsSphere=function(e){var t=e.center.x-this.origin.x,i=e.center.y-this.origin.y,r=e.center.z-this.origin.z,n=t*t+i*i+r*r,o=e.radius*e.radius;if(n<=o)return!0;var s=t*this.direction.x+i*this.direction.y+r*this.direction.z;return!(s<0)&&n-s*s<=o},e.prototype.intersectsTriangle=function(e,t,i){this._edge1||(this._edge1=lt.Vector3.Zero(),this._edge2=lt.Vector3.Zero(),this._pvec=lt.Vector3.Zero(),this._tvec=lt.Vector3.Zero(),this._qvec=lt.Vector3.Zero()),t.subtractToRef(e,this._edge1),i.subtractToRef(e,this._edge2),lt.Vector3.CrossToRef(this.direction,this._edge2,this._pvec);var r=lt.Vector3.Dot(this._edge1,this._pvec);if(0===r)return null;var n=1/r;this.origin.subtractToRef(e,this._tvec);var o=lt.Vector3.Dot(this._tvec,this._pvec)*n;if(o<0||o>1)return null;lt.Vector3.CrossToRef(this._tvec,this._edge1,this._qvec);var s=lt.Vector3.Dot(this.direction,this._qvec)*n;if(s<0||o+s>1)return null;var a=lt.Vector3.Dot(this._edge2,this._qvec)*n;return a>this.length?null:new lt.IntersectionInfo(o,s,a)},e.prototype.intersectsPlane=function(e){var t,i=lt.Vector3.Dot(e.normal,this.direction);if(Math.abs(i)<9.99999997475243e-7)return null;var r=lt.Vector3.Dot(e.normal,this.origin);return(t=(-e.d-r)/i)<0?t<-9.99999997475243e-7?null:0:t},e.prototype.intersectsMesh=function(t,i){var r=lt.Tmp.Matrix[0];return t.getWorldMatrix().invertToRef(r),this._tmpRay?e.TransformToRef(this,r,this._tmpRay):this._tmpRay=e.Transform(this,r),t.intersects(this._tmpRay,i)},e.prototype.intersectsMeshes=function(e,t,i){i?i.length=0:i=[];for(var r=0;r<e.length;r++){var n=this.intersectsMesh(e[r],t);n.hit&&i.push(n)}return i.sort(this._comparePickingInfo),i},e.prototype._comparePickingInfo=function(e,t){return e.distance<t.distance?-1:e.distance>t.distance?1:0},e.prototype.intersectionSegment=function(t,i,r){var n,o,s,a,h=this.origin.add(this.direction.multiplyByFloats(e.rayl,e.rayl,e.rayl)),l=i.subtract(t),c=h.subtract(this.origin),u=t.subtract(this.origin),p=lt.Vector3.Dot(l,l),f=lt.Vector3.Dot(l,c),d=lt.Vector3.Dot(c,c),m=lt.Vector3.Dot(l,u),g=lt.Vector3.Dot(c,u),_=p*d-f*f,v=_,y=_;_<e.smallnum?(o=0,v=1,a=g,y=d):(a=p*g-f*m,(o=f*g-d*m)<0?(o=0,a=g,y=d):o>v&&(o=v,a=g+f,y=d)),a<0?(a=0,-m<0?o=0:-m>p?o=v:(o=-m,v=p)):a>y&&(a=y,-m+f<0?o=0:-m+f>p?o=v:(o=-m+f,v=p)),n=Math.abs(o)<e.smallnum?0:o/v,s=Math.abs(a)<e.smallnum?0:a/y;var b=c.multiplyByFloats(s,s,s),x=u.add(l.multiplyByFloats(n,n,n)).subtract(b);return s>0&&s<=this.length&&x.lengthSquared()<r*r?b.length():-1},e.prototype.update=function(e,t,i,r,n,o,s){return lt.Vector3.UnprojectFloatsToRef(e,t,0,i,r,n,o,s,this.origin),lt.Vector3.UnprojectFloatsToRef(e,t,1,i,r,n,o,s,lt.Tmp.Vector3[0]),lt.Tmp.Vector3[0].subtractToRef(this.origin,this.direction),this.direction.normalize(),this},e.Zero=function(){return new e(lt.Vector3.Zero(),lt.Vector3.Zero())},e.CreateNew=function(t,i,r,n,o,s,a){return e.Zero().update(t,i,r,n,o,s,a)},e.CreateNewFromTo=function(t,i,r){void 0===r&&(r=lt.Matrix.Identity());var n=i.subtract(t),o=Math.sqrt(n.x*n.x+n.y*n.y+n.z*n.z);return n.normalize(),e.Transform(new e(t,n,o),r)},e.Transform=function(t,i){var r=new e(new lt.Vector3(0,0,0),new lt.Vector3(0,0,0));return e.TransformToRef(t,i,r),r},e.TransformToRef=function(e,t,i){lt.Vector3.TransformCoordinatesToRef(e.origin,t,i.origin),lt.Vector3.TransformNormalToRef(e.direction,t,i.direction),i.length=e.length;var r=i.direction,n=r.length();if(0!==n&&1!==n){var o=1/n;r.x*=o,r.y*=o,r.z*=o,i.length*=n}},e.smallnum=1e-8,e.rayl=1e9,e}(),lt.Ray=ct,ut=us||(us={}),pt={root:0,found:!1},ft=function(e,t,i,r){pt.root=0,pt.found=!1;var n=t*t-4*e*i;if(n<0)return pt;var o=Math.sqrt(n),s=(-t-o)/(2*e),a=(-t+o)/(2*e);if(s>a){var h=a;a=s,s=h}return s>0&&s<r?(pt.root=s,pt.found=!0,pt):a>0&&a<r?(pt.root=a,pt.found=!0,pt):pt},dt=function(){function e(){this._collisionPoint=ut.Vector3.Zero(),this._planeIntersectionPoint=ut.Vector3.Zero(),this._tempVector=ut.Vector3.Zero(),this._tempVector2=ut.Vector3.Zero(),this._tempVector3=ut.Vector3.Zero(),this._tempVector4=ut.Vector3.Zero(),this._edge=ut.Vector3.Zero(),this._baseToVertex=ut.Vector3.Zero(),this._destinationPoint=ut.Vector3.Zero(),this._slidePlaneNormal=ut.Vector3.Zero(),this._displacementVector=ut.Vector3.Zero(),this._radius=ut.Vector3.One(),this._retry=0,this._basePointWorld=ut.Vector3.Zero(),this._velocityWorld=ut.Vector3.Zero(),this._normalizedVelocity=ut.Vector3.Zero(),this._collisionMask=-1}return Object.defineProperty(e.prototype,"collisionMask",{get:function(){return this._collisionMask},set:function(e){this._collisionMask=isNaN(e)?-1:e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"slidePlaneNormal",{get:function(){return this._slidePlaneNormal},enumerable:!0,configurable:!0}),e.prototype._initialize=function(e,t,i){this._velocity=t,ut.Vector3.NormalizeToRef(t,this._normalizedVelocity),this._basePoint=e,e.multiplyToRef(this._radius,this._basePointWorld),t.multiplyToRef(this._radius,this._velocityWorld),this._velocityWorldLength=this._velocityWorld.length(),this._epsilon=i,this.collisionFound=!1},e.prototype._checkPointInTriangle=function(e,t,i,r,n){t.subtractToRef(e,this._tempVector),i.subtractToRef(e,this._tempVector2),ut.Vector3.CrossToRef(this._tempVector,this._tempVector2,this._tempVector4);var o=ut.Vector3.Dot(this._tempVector4,n);return!(o<0)&&(r.subtractToRef(e,this._tempVector3),ut.Vector3.CrossToRef(this._tempVector2,this._tempVector3,this._tempVector4),!((o=ut.Vector3.Dot(this._tempVector4,n))<0)&&(ut.Vector3.CrossToRef(this._tempVector3,this._tempVector,this._tempVector4),(o=ut.Vector3.Dot(this._tempVector4,n))>=0))},e.prototype._canDoCollision=function(e,t,i,r){var n,o,s,a,h=ut.Vector3.Distance(this._basePointWorld,e),l=Math.max(this._radius.x,this._radius.y,this._radius.z);return!(h>this._velocityWorldLength+l+t)&&(n=i,o=r,s=this._basePointWorld,a=this._velocityWorldLength+l,!(n.x>s.x+a||s.x-a>o.x||n.y>s.y+a||s.y-a>o.y||n.z>s.z+a||s.z-a>o.z))},e.prototype._testTriangle=function(e,t,i,r,n,o){var s,a=!1;t||(t=[]),t[e]||(t[e]=new ut.Plane(0,0,0,0),t[e].copyFromPoints(i,r,n));var h=t[e];if(o||h.isFrontFacingTo(this._normalizedVelocity,0)){var l=h.signedDistanceTo(this._basePoint),c=ut.Vector3.Dot(h.normal,this._velocity);if(0==c){if(Math.abs(l)>=1)return;a=!0,s=0}else{var u=(1-l)/c;if((s=(-1-l)/c)>u){var p=u;u=s,s=p}if(s>1||u<0)return;s<0&&(s=0),s>1&&(s=1)}this._collisionPoint.copyFromFloats(0,0,0);var f=!1,d=1;if(a||(this._basePoint.subtractToRef(h.normal,this._planeIntersectionPoint),this._velocity.scaleToRef(s,this._tempVector),this._planeIntersectionPoint.addInPlace(this._tempVector),this._checkPointInTriangle(this._planeIntersectionPoint,i,r,n,h.normal)&&(f=!0,d=s,this._collisionPoint.copyFrom(this._planeIntersectionPoint))),!f){var m=this._velocity.lengthSquared(),g=m;this._basePoint.subtractToRef(i,this._tempVector);var _=2*ut.Vector3.Dot(this._velocity,this._tempVector),v=this._tempVector.lengthSquared()-1,y=ft(g,_,v,d);y.found&&(d=y.root,f=!0,this._collisionPoint.copyFrom(i)),this._basePoint.subtractToRef(r,this._tempVector),_=2*ut.Vector3.Dot(this._velocity,this._tempVector),v=this._tempVector.lengthSquared()-1,(y=ft(g,_,v,d)).found&&(d=y.root,f=!0,this._collisionPoint.copyFrom(r)),this._basePoint.subtractToRef(n,this._tempVector),_=2*ut.Vector3.Dot(this._velocity,this._tempVector),v=this._tempVector.lengthSquared()-1,(y=ft(g,_,v,d)).found&&(d=y.root,f=!0,this._collisionPoint.copyFrom(n)),r.subtractToRef(i,this._edge),i.subtractToRef(this._basePoint,this._baseToVertex);var b=this._edge.lengthSquared(),x=ut.Vector3.Dot(this._edge,this._velocity),T=ut.Vector3.Dot(this._edge,this._baseToVertex);if(g=b*-m+x*x,_=b*(2*ut.Vector3.Dot(this._velocity,this._baseToVertex))-2*x*T,v=b*(1-this._baseToVertex.lengthSquared())+T*T,(y=ft(g,_,v,d)).found){var E=(x*y.root-T)/b;E>=0&&E<=1&&(d=y.root,f=!0,this._edge.scaleInPlace(E),i.addToRef(this._edge,this._collisionPoint))}n.subtractToRef(r,this._edge),r.subtractToRef(this._basePoint,this._baseToVertex),b=this._edge.lengthSquared(),x=ut.Vector3.Dot(this._edge,this._velocity),T=ut.Vector3.Dot(this._edge,this._baseToVertex),g=b*-m+x*x,_=b*(2*ut.Vector3.Dot(this._velocity,this._baseToVertex))-2*x*T,v=b*(1-this._baseToVertex.lengthSquared())+T*T,(y=ft(g,_,v,d)).found&&(E=(x*y.root-T)/b)>=0&&E<=1&&(d=y.root,f=!0,this._edge.scaleInPlace(E),r.addToRef(this._edge,this._collisionPoint)),i.subtractToRef(n,this._edge),n.subtractToRef(this._basePoint,this._baseToVertex),b=this._edge.lengthSquared(),x=ut.Vector3.Dot(this._edge,this._velocity),T=ut.Vector3.Dot(this._edge,this._baseToVertex),g=b*-m+x*x,_=b*(2*ut.Vector3.Dot(this._velocity,this._baseToVertex))-2*x*T,v=b*(1-this._baseToVertex.lengthSquared())+T*T,(y=ft(g,_,v,d)).found&&(E=(x*y.root-T)/b)>=0&&E<=1&&(d=y.root,f=!0,this._edge.scaleInPlace(E),n.addToRef(this._edge,this._collisionPoint))}if(f){var A=d*this._velocity.length();(!this.collisionFound||A<this._nearestDistance)&&(this.intersectionPoint?this.intersectionPoint.copyFrom(this._collisionPoint):this.intersectionPoint=this._collisionPoint.clone(),this._nearestDistance=A,this.collisionFound=!0)}}},e.prototype._collide=function(e,t,i,r,n,o,s){for(var a=r;a<n;a+=3){var h=t[i[a]-o],l=t[i[a+1]-o],c=t[i[a+2]-o];this._testTriangle(a,e,c,l,h,s)}},e.prototype._getResponse=function(e,t){e.addToRef(t,this._destinationPoint),t.scaleInPlace(this._nearestDistance/t.length()),this._basePoint.addToRef(t,e),e.subtractToRef(this.intersectionPoint,this._slidePlaneNormal),this._slidePlaneNormal.normalize(),this._slidePlaneNormal.scaleToRef(this._epsilon,this._displacementVector),e.addInPlace(this._displacementVector),this.intersectionPoint.addInPlace(this._displacementVector),this._slidePlaneNormal.scaleInPlace(ut.Plane.SignedDistanceToPlaneFromPositionAndNormal(this.intersectionPoint,this._slidePlaneNormal,this._destinationPoint)),this._destinationPoint.subtractInPlace(this._slidePlaneNormal),this._destinationPoint.subtractToRef(this.intersectionPoint,t)},e}(),ut.Collider=dt,function(e){var t,i,r,n;e.CollisionWorker="",(i=t=e.WorkerTaskType||(e.WorkerTaskType={}))[i.INIT=0]="INIT",i[i.UPDATE=1]="UPDATE",i[i.COLLIDE=2]="COLLIDE",(n=r=e.WorkerReplyType||(e.WorkerReplyType={}))[n.SUCCESS=0]="SUCCESS",n[n.UNKNOWN_ERROR=1]="UNKNOWN_ERROR";var o=function(){function i(){var n=this;this._scaledPosition=e.Vector3.Zero(),this._scaledVelocity=e.Vector3.Zero(),this.onMeshUpdated=function(e){n._addUpdateMeshesList[e.uniqueId]=i.SerializeMesh(e)},this.onGeometryUpdated=function(e){n._addUpdateGeometriesList[e.id]=i.SerializeGeometry(e)},this._afterRender=function(){if(n._init&&!(0==n._toRemoveGeometryArray.length&&0==n._toRemoveMeshesArray.length&&0==Object.keys(n._addUpdateGeometriesList).length&&0==Object.keys(n._addUpdateMeshesList).length||n._runningUpdated>4)){++n._runningUpdated;var e={updatedMeshes:n._addUpdateMeshesList,updatedGeometries:n._addUpdateGeometriesList,removedGeometries:n._toRemoveGeometryArray,removedMeshes:n._toRemoveMeshesArray},i={payload:e,taskType:t.UPDATE},r=[];for(var o in e.updatedGeometries)e.updatedGeometries.hasOwnProperty(o)&&(r.push(i.payload.updatedGeometries[o].indices.buffer),r.push(i.payload.updatedGeometries[o].normals.buffer),r.push(i.payload.updatedGeometries[o].positions.buffer));n._worker.postMessage(i,r),n._addUpdateMeshesList={},n._addUpdateGeometriesList={},n._toRemoveGeometryArray=[],n._toRemoveMeshesArray=[]}},this._onMessageFromWorker=function(i){var o=i.data;if(o.error==r.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 i.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)}},i.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)},i.prototype.destroy=function(){this._scene.unregisterAfterRender(this._afterRender),this._worker.terminate()},i.prototype.onMeshAdded=function(e){e.registerAfterWorldMatrixUpdate(this.onMeshUpdated),this.onMeshUpdated(e)},i.prototype.onMeshRemoved=function(e){this._toRemoveMeshesArray.push(e.uniqueId)},i.prototype.onGeometryAdded=function(e){e.onGeometryUpdated=this.onGeometryUpdated,this.onGeometryUpdated(e)},i.prototype.onGeometryDeleted=function(e){this._toRemoveGeometryArray.push(e.id)},i.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;r=(n=t.sourceMesh.geometry)?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}},i.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()||[])}},i}();e.CollisionCoordinatorWorker=o;var s=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<this._scene.meshes.length;l++){var c=this._scene.meshes[l];c.isEnabled()&&c.checkCollisions&&c.subMeshes&&c!==s&&0!=(h&c.collisionGroup)&&c._checkCollision(r)}r.collisionFound?(0===i.x&&0===i.y&&0===i.z||r._getResponse(t,i),i.length()<=a?o.copyFrom(t):(r._retry++,this._collideWithWorld(t,i,r,n,o,s))):t.addToRef(i,o)}},t}();e.CollisionCoordinatorLegacy=s}(us||(us={})),mt=us||(us={}),gt=function(){function e(e){this.particleSystem=e,this.position=mt.Vector3.Zero(),this.direction=mt.Vector3.Zero(),this.color=new mt.Color4(0,0,0,0),this.colorStep=new mt.Color4(0,0,0,0),this.lifeTime=1,this.age=0,this.size=0,this.angle=0,this.angularSpeed=0,this._currentFrameCounter=0,this.cellIndex=0,this.particleSystem.isAnimationSheetEnabled&&(this.cellIndex=this.particleSystem.startSpriteCellID,0==this.particleSystem.spriteCellChangeSpeed?this.updateCellIndex=this.updateCellIndexWithSpeedCalculated:this.updateCellIndex=this.updateCellIndexWithCustomSpeed)}return e.prototype.updateCellIndexWithSpeedCalculated=function(e){var t=(this.lifeTime-this.age)/e/(this.particleSystem.endSpriteCellID+1-this.cellIndex);this._currentFrameCounter+=e,this._currentFrameCounter>=t*e&&(this._currentFrameCounter=0,this.cellIndex++,this.cellIndex>this.particleSystem.endSpriteCellID&&(this.cellIndex=this.particleSystem.endSpriteCellID))},e.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++},e.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},e}(),mt.Particle=gt,_t=us||(us={}),vt=function(){function e(t,i,r,n,o,s){void 0===n&&(n=null),void 0===o&&(o=!1),void 0===s&&(s=.01);var a=this;this.name=t,this._isAnimationSheetEnabled=o,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 _t.Observable,this.onAnimationEnd=null,this.blendMode=e.BLENDMODE_ONEONE,this.forceDepthWrite=!1,this.gravity=_t.Vector3.Zero(),this.direction1=new _t.Vector3(0,1,0),this.direction2=new _t.Vector3(0,1,0),this.minEmitBox=new _t.Vector3(-.5,-.5,-.5),this.maxEmitBox=new _t.Vector3(.5,.5,.5),this.color1=new _t.Color4(1,1,1,1),this.color2=new _t.Color4(1,1,1,1),this.colorDead=new _t.Color4(0,0,0,1),this.textureMask=new _t.Color4(1,1,1,1),this.particles=new Array,this._stockParticles=new Array,this._newPartsExcess=0,this._vertexBuffers={},this._scaledColorStep=new _t.Color4(0,0,0,0),this._colorDiff=new _t.Color4(0,0,0,0),this._scaledDirection=_t.Vector3.Zero(),this._scaledGravity=_t.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=t,this._capacity=i,this._epsilon=s,o&&(this._vertexBufferSize=12),this._scene=r||_t.Engine.LastCreatedScene,this._customEffect=n,r.particleSystems.push(this),this._createIndexBuffer(),this._vertexData=new Float32Array(i*this._vertexBufferSize*4),this._vertexBuffer=new _t.Buffer(r.getEngine(),this._vertexData,!0,this._vertexBufferSize);var h=this._vertexBuffer.createVertexBuffer(_t.VertexBuffer.PositionKind,0,3),l=this._vertexBuffer.createVertexBuffer(_t.VertexBuffer.ColorKind,3,4),c=this._vertexBuffer.createVertexBuffer("options",7,4);if(this._isAnimationSheetEnabled){var u=this._vertexBuffer.createVertexBuffer("cellIndex",11,1);this._vertexBuffers.cellIndex=u}this._vertexBuffers[_t.VertexBuffer.PositionKind]=h,this._vertexBuffers[_t.VertexBuffer.ColorKind]=l,this._vertexBuffers.options=c,this.particleEmitterType=new _t.BoxParticleEmitter(this),this.updateFunction=function(e){for(var t=0;t<e.length;t++){var i=e[t];i.age+=a._scaledUpdateSpeed,i.age>=i.lifeTime?(a.recycleParticle(i),t--):(i.colorStep.scaleToRef(a._scaledUpdateSpeed,a._scaledColorStep),i.color.addInPlace(a._scaledColorStep),i.color.a<0&&(i.color.a=0),i.angle+=i.angularSpeed*a._scaledUpdateSpeed,i.direction.scaleToRef(a._scaledUpdateSpeed,a._scaledDirection),i.position.addInPlace(a._scaledDirection),a.gravity.scaleToRef(a._scaledUpdateSpeed,a._scaledGravity),i.direction.addInPlace(a._scaledGravity),a._isAnimationSheetEnabled&&i.updateCellIndex(a._scaledUpdateSpeed))}}}return Object.defineProperty(e.prototype,"onDispose",{set:function(e){this._onDisposeObserver&&this.onDisposeObservable.remove(this._onDisposeObserver),this._onDisposeObserver=this.onDisposeObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isAnimationSheetEnabled",{get:function(){return this._isAnimationSheetEnabled},enumerable:!0,configurable:!0}),e.prototype._createIndexBuffer=function(){for(var e=[],t=0,i=0;i<this._capacity;i++)e.push(t),e.push(t+1),e.push(t+2),e.push(t),e.push(t+2),e.push(t+3),t+=4;this._indexBuffer=this._scene.getEngine().createIndexBuffer(e)},e.prototype.recycleParticle=function(e){var t=this.particles.pop();t!==e&&(t.copyTo(e),this._stockParticles.push(t))},e.prototype.getCapacity=function(){return this._capacity},e.prototype.isAlive=function(){return this._alive},e.prototype.isStarted=function(){return this._started},e.prototype.start=function(){this._started=!0,this._stopped=!1,this._actualFrame=0},e.prototype.stop=function(){this._stopped=!0},e.prototype._appendParticleVertex=function(e,t,i,r){var n=e*this._vertexBufferSize;this._vertexData[n]=t.position.x,this._vertexData[n+1]=t.position.y,this._vertexData[n+2]=t.position.z,this._vertexData[n+3]=t.color.r,this._vertexData[n+4]=t.color.g,this._vertexData[n+5]=t.color.b,this._vertexData[n+6]=t.color.a,this._vertexData[n+7]=t.angle,this._vertexData[n+8]=t.size,this._vertexData[n+9]=i,this._vertexData[n+10]=r},e.prototype._appendParticleVertexWithAnimation=function(e,t,i,r){0===i?i=this._epsilon:1===i&&(i=1-this._epsilon),0===r?r=this._epsilon:1===r&&(r=1-this._epsilon);var n=e*this._vertexBufferSize;this._vertexData[n]=t.position.x,this._vertexData[n+1]=t.position.y,this._vertexData[n+2]=t.position.z,this._vertexData[n+3]=t.color.r,this._vertexData[n+4]=t.color.g,this._vertexData[n+5]=t.color.b,this._vertexData[n+6]=t.color.a,this._vertexData[n+7]=t.angle,this._vertexData[n+8]=t.size,this._vertexData[n+9]=i,this._vertexData[n+10]=r,this._vertexData[n+11]=t.cellIndex},e.prototype._update=function(t){var i,r;if(this._alive=this.particles.length>0,this.updateFunction(this.particles),this.emitter.position){i=this.emitter.getWorldMatrix()}else{var n=this.emitter;i=_t.Matrix.Translation(n.x,n.y,n.z)}for(var o=0;o<t&&this.particles.length!==this._capacity;o++){0!==this._stockParticles.length?((r=this._stockParticles.pop()).age=0,r.cellIndex=this.startSpriteCellID):r=new _t.Particle(this),this.particles.push(r);var s=e.randomNumber(this.minEmitPower,this.maxEmitPower);this.startDirectionFunction?this.startDirectionFunction(s,i,r.direction,r):this.particleEmitterType.startDirectionFunction(s,i,r.direction,r),this.startPositionFunction?this.startPositionFunction(i,r.position,r):this.particleEmitterType.startPositionFunction(i,r.position,r),r.lifeTime=e.randomNumber(this.minLifeTime,this.maxLifeTime),r.size=e.randomNumber(this.minSize,this.maxSize),r.angularSpeed=e.randomNumber(this.minAngularSpeed,this.maxAngularSpeed);var a=e.randomNumber(0,1);_t.Color4.LerpToRef(this.color1,this.color2,a,r.color),this.colorDead.subtractToRef(r.color,this._colorDiff),this._colorDiff.scaleToRef(1/r.lifeTime,r.colorStep)}},e.prototype._getEffect=function(){if(this._customEffect)return this._customEffect;var e=[];this._scene.clipPlane&&e.push("#define CLIPPLANE"),this._isAnimationSheetEnabled&&e.push("#define ANIMATESHEET");var t,i,r=e.join("\n");this._cachedDefines!==r&&(this._cachedDefines=r,this._isAnimationSheetEnabled?(t=[_t.VertexBuffer.PositionKind,_t.VertexBuffer.ColorKind,"options","cellIndex"],i=["invView","view","projection","particlesInfos","vClipPlane","textureMask"]):(t=[_t.VertexBuffer.PositionKind,_t.VertexBuffer.ColorKind,"options"],i=["invView","view","projection","vClipPlane","textureMask"]),this._effect=this._scene.getEngine().createEffect("particles",t,i,["diffuseSampler"],r));return this._effect},e.prototype.animate=function(){if(this._started){var e=this._getEffect();if(this.emitter&&e.isReady()&&this.particleTexture&&this.particleTexture.isReady()&&this._currentRenderId!==this._scene.getRenderId()){var t;this._currentRenderId=this._scene.getRenderId(),this._scaledUpdateSpeed=this.updateSpeed*this._scene.getAnimationRatio(),this.manualEmitCount>-1?(t=this.manualEmitCount,this._newPartsExcess=0,this.manualEmitCount=0):(t=this.emitRate*this._scaledUpdateSpeed>>0,this._newPartsExcess+=this.emitRate*this._scaledUpdateSpeed-t),this._newPartsExcess>1&&(t+=this._newPartsExcess>>0,this._newPartsExcess-=this._newPartsExcess>>0),this._alive=!1,this._stopped?t=0:(this._actualFrame+=this._scaledUpdateSpeed,this.targetStopDuration&&this._actualFrame>=this.targetStopDuration&&this.stop()),this._update(t),this._stopped&&(this._alive||(this._started=!1,this.onAnimationEnd&&this.onAnimationEnd(),this.disposeOnStop&&this._scene._toBeDisposed.push(this))),this._isAnimationSheetEnabled?this.appendParticleVertexes=this.appenedParticleVertexesWithSheet:this.appendParticleVertexes=this.appenedParticleVertexesNoSheet;for(var i=0,r=0;r<this.particles.length;r++){var n=this.particles[r];this.appendParticleVertexes(i,n),i+=4}this._vertexBuffer&&this._vertexBuffer.update(this._vertexData)}}},e.prototype.appenedParticleVertexesWithSheet=function(e,t){this._appendParticleVertexWithAnimation(e++,t,0,0),this._appendParticleVertexWithAnimation(e++,t,1,0),this._appendParticleVertexWithAnimation(e++,t,1,1),this._appendParticleVertexWithAnimation(e++,t,0,1)},e.prototype.appenedParticleVertexesNoSheet=function(e,t){this._appendParticleVertex(e++,t,0,0),this._appendParticleVertex(e++,t,1,0),this._appendParticleVertex(e++,t,1,1),this._appendParticleVertex(e++,t,0,1)},e.prototype.rebuild=function(){this._createIndexBuffer(),this._vertexBuffer&&this._vertexBuffer._rebuild()},e.prototype.render=function(){var t=this._getEffect();if(!(this.emitter&&t.isReady()&&this.particleTexture&&this.particleTexture.isReady()&&this.particles.length))return 0;var i=this._scene.getEngine();i.enableEffect(t),i.setState(!1);var r=this._scene.getViewMatrix();if(t.setTexture("diffuseSampler",this.particleTexture),t.setMatrix("view",r),t.setMatrix("projection",this._scene.getProjectionMatrix()),this._isAnimationSheetEnabled){var n=this.particleTexture.getBaseSize();t.setFloat3("particlesInfos",this.spriteCellWidth/n.width,this.spriteCellHeight/n.height,n.width/this.spriteCellWidth)}if(t.setFloat4("textureMask",this.textureMask.r,this.textureMask.g,this.textureMask.b,this.textureMask.a),this._scene.clipPlane){var o=this._scene.clipPlane,s=r.clone();s.invert(),t.setMatrix("invView",s),t.setFloat4("vClipPlane",o.normal.x,o.normal.y,o.normal.z,o.d)}return i.bindBuffers(this._vertexBuffers,this._indexBuffer,t),this.blendMode===e.BLENDMODE_ONEONE?i.setAlphaMode(_t.Engine.ALPHA_ONEONE):i.setAlphaMode(_t.Engine.ALPHA_COMBINE),this.forceDepthWrite&&i.setDepthWrite(!0),i.drawElementsType(_t.Material.TriangleFillMode,0,6*this.particles.length),i.setAlphaMode(_t.Engine.ALPHA_DISABLE),this.particles.length},e.prototype.dispose=function(){this._vertexBuffer&&(this._vertexBuffer.dispose(),this._vertexBuffer=null),this._indexBuffer&&(this._scene.getEngine()._releaseBuffer(this._indexBuffer),this._indexBuffer=null),this.particleTexture&&(this.particleTexture.dispose(),this.particleTexture=null);var e=this._scene.particleSystems.indexOf(this);e>-1&&this._scene.particleSystems.splice(e,1),this.onDisposeObservable.notifyObservers(this),this.onDisposeObservable.clear()},e.prototype.createSphereEmitter=function(e){void 0===e&&(e=1);var t=new _t.SphereParticleEmitter(e);return this.particleEmitterType=t,t},e.prototype.createDirectedSphereEmitter=function(e,t,i){void 0===e&&(e=1),void 0===t&&(t=new _t.Vector3(0,1,0)),void 0===i&&(i=new _t.Vector3(0,1,0));var r=new _t.SphereDirectedParticleEmitter(e,t,i);return this.particleEmitterType=r,r},e.prototype.createConeEmitter=function(e,t){void 0===e&&(e=1),void 0===t&&(t=Math.PI/4);var i=new _t.ConeParticleEmitter(e,t);return this.particleEmitterType=i,i},e.prototype.createBoxEmitter=function(e,t,i,r){var n=new _t.BoxParticleEmitter(this);return this.direction1=e,this.direction2=t,this.minEmitBox=i,this.maxEmitBox=r,this.particleEmitterType=n,n},e.randomNumber=function(e,t){return e===t?e:Math.random()*(t-e)+e},e.prototype.clone=function(t,i){var r=null,n=null;if(null!=this.customShader){var o=(n=this.customShader).shaderOptions.defines.length>0?n.shaderOptions.defines.join("\n"):"";r=this._scene.getEngine().createEffectForParticles(n.shaderPath.fragmentElement,n.shaderOptions.uniforms,n.shaderOptions.samplers,o)}var s=new e(t,this._capacity,this._scene,r);return s.customShader=n,_t.Tools.DeepCopy(this,s,["particles","customShader"]),void 0===i&&(i=this.emitter),s.emitter=i,this.particleTexture&&(s.particleTexture=new _t.Texture(this.particleTexture.url,this._scene)),this.preventAutoStart||s.start(),s},e.prototype.serialize=function(){var e={};if(e.name=this.name,e.id=this.id,this.emitter.position){var t=this.emitter;e.emitterId=t.id}else{var i=this.emitter;e.emitter=i.asArray()}return e.capacity=this.getCapacity(),this.particleTexture&&(e.textureName=this.particleTexture.name),_t.Animation.AppendSerializedAnimations(this,e),e.minAngularSpeed=this.minAngularSpeed,e.maxAngularSpeed=this.maxAngularSpeed,e.minSize=this.minSize,e.maxSize=this.maxSize,e.minEmitPower=this.minEmitPower,e.maxEmitPower=this.maxEmitPower,e.minLifeTime=this.minLifeTime,e.maxLifeTime=this.maxLifeTime,e.emitRate=this.emitRate,e.minEmitBox=this.minEmitBox.asArray(),e.maxEmitBox=this.maxEmitBox.asArray(),e.gravity=this.gravity.asArray(),e.direction1=this.direction1.asArray(),e.direction2=this.direction2.asArray(),e.color1=this.color1.asArray(),e.color2=this.color2.asArray(),e.colorDead=this.colorDead.asArray(),e.updateSpeed=this.updateSpeed,e.targetStopDuration=this.targetStopDuration,e.textureMask=this.textureMask.asArray(),e.blendMode=this.blendMode,e.customShader=this.customShader,e.preventAutoStart=this.preventAutoStart,e.startSpriteCellID=this.startSpriteCellID,e.endSpriteCellID=this.endSpriteCellID,e.spriteCellLoop=this.spriteCellLoop,e.spriteCellChangeSpeed=this.spriteCellChangeSpeed,e.spriteCellWidth=this.spriteCellWidth,e.spriteCellHeight=this.spriteCellHeight,e.isAnimationSheetEnabled=this._isAnimationSheetEnabled,e},e.Parse=function(t,i,r){var n=t.name,o=null,s=null;if(t.customShader){var a=(s=t.customShader).shaderOptions.defines.length>0?s.shaderOptions.defines.join("\n"):"";o=i.getEngine().createEffectForParticles(s.shaderPath.fragmentElement,s.shaderOptions.uniforms,s.shaderOptions.samplers,a)}var h=new e(n,t.capacity,i,o,t.isAnimationSheetEnabled);if(h.customShader=s,t.id&&(h.id=t.id),t.preventAutoStart&&(h.preventAutoStart=t.preventAutoStart),t.textureName&&(h.particleTexture=new _t.Texture(r+t.textureName,i),h.particleTexture.name=t.textureName),t.emitterId?h.emitter=i.getLastMeshByID(t.emitterId):h.emitter=_t.Vector3.FromArray(t.emitter),t.animations)for(var l=0;l<t.animations.length;l++){var c=t.animations[l];h.animations.push(_t.Animation.Parse(c))}return t.autoAnimate&&i.beginAnimation(h,t.autoAnimateFrom,t.autoAnimateTo,t.autoAnimateLoop,t.autoAnimateSpeed||1),h.minAngularSpeed=t.minAngularSpeed,h.maxAngularSpeed=t.maxAngularSpeed,h.minSize=t.minSize,h.maxSize=t.maxSize,h.minLifeTime=t.minLifeTime,h.maxLifeTime=t.maxLifeTime,h.minEmitPower=t.minEmitPower,h.maxEmitPower=t.maxEmitPower,h.emitRate=t.emitRate,h.minEmitBox=_t.Vector3.FromArray(t.minEmitBox),h.maxEmitBox=_t.Vector3.FromArray(t.maxEmitBox),h.gravity=_t.Vector3.FromArray(t.gravity),h.direction1=_t.Vector3.FromArray(t.direction1),h.direction2=_t.Vector3.FromArray(t.direction2),h.color1=_t.Color4.FromArray(t.color1),h.color2=_t.Color4.FromArray(t.color2),h.colorDead=_t.Color4.FromArray(t.colorDead),h.updateSpeed=t.updateSpeed,h.targetStopDuration=t.targetStopDuration,h.textureMask=_t.Color4.FromArray(t.textureMask),h.blendMode=t.blendMode,h.startSpriteCellID=t.startSpriteCellID,h.endSpriteCellID=t.endSpriteCellID,h.spriteCellLoop=t.spriteCellLoop,h.spriteCellChangeSpeed=t.spriteCellChangeSpeed,h.spriteCellWidth=t.spriteCellWidth,h.spriteCellHeight=t.spriteCellHeight,h.preventAutoStart||h.start(),h},e.BLENDMODE_ONEONE=0,e.BLENDMODE_STANDARD=1,e}(),_t.ParticleSystem=vt,yt=us||(us={}),bt=function(){function e(e){this._particleSystem=e}return Object.defineProperty(e.prototype,"direction1",{get:function(){return this._particleSystem.direction1},set:function(e){this._particleSystem.direction1=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"direction2",{get:function(){return this._particleSystem.direction2},set:function(e){this._particleSystem.direction2=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"minEmitBox",{get:function(){return this._particleSystem.minEmitBox},set:function(e){this._particleSystem.minEmitBox=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"maxEmitBox",{get:function(){return this._particleSystem.maxEmitBox},set:function(e){this._particleSystem.maxEmitBox=e},enumerable:!0,configurable:!0}),e.prototype.startDirectionFunction=function(e,t,i,r){var n=yt.ParticleSystem.randomNumber(this.direction1.x,this.direction2.x),o=yt.ParticleSystem.randomNumber(this.direction1.y,this.direction2.y),s=yt.ParticleSystem.randomNumber(this.direction1.z,this.direction2.z);yt.Vector3.TransformNormalFromFloatsToRef(n*e,o*e,s*e,t,i)},e.prototype.startPositionFunction=function(e,t,i){var r=yt.ParticleSystem.randomNumber(this.minEmitBox.x,this.maxEmitBox.x),n=yt.ParticleSystem.randomNumber(this.minEmitBox.y,this.maxEmitBox.y),o=yt.ParticleSystem.randomNumber(this.minEmitBox.z,this.maxEmitBox.z);yt.Vector3.TransformCoordinatesFromFloatsToRef(r,n,o,e,t)},e}(),yt.BoxParticleEmitter=bt,xt=us||(us={}),Tt=function(){function e(e,t){this.radius=e,this.angle=t}return e.prototype.startDirectionFunction=function(e,t,i,r){if(0===this.angle)xt.Vector3.TransformNormalFromFloatsToRef(0,e,0,t,i);else{var n=xt.ParticleSystem.randomNumber(0,2*Math.PI),o=xt.ParticleSystem.randomNumber(0,this.angle),s=Math.cos(n)*Math.sin(o),a=Math.cos(o),h=Math.sin(n)*Math.sin(o);xt.Vector3.TransformNormalFromFloatsToRef(s*e,a*e,h*e,t,i)}},e.prototype.startPositionFunction=function(e,t,i){var r=xt.ParticleSystem.randomNumber(0,2*Math.PI),n=xt.ParticleSystem.randomNumber(0,this.radius),o=n*Math.sin(r),s=n*Math.cos(r);xt.Vector3.TransformCoordinatesFromFloatsToRef(o,0,s,e,t)},e}(),xt.ConeParticleEmitter=Tt,function(e){var t=function(){function t(e){this.radius=e}return t.prototype.startDirectionFunction=function(t,i,r,n){var o=n.position.subtract(i.getTranslation());e.Vector3.TransformNormalFromFloatsToRef(o.x*t,o.y*t,o.z*t,i,r)},t.prototype.startPositionFunction=function(t,i,r){var n=e.ParticleSystem.randomNumber(0,2*Math.PI),o=e.ParticleSystem.randomNumber(0,Math.PI),s=this.radius*Math.cos(n)*Math.sin(o),a=this.radius*Math.cos(o),h=this.radius*Math.sin(n)*Math.sin(o);e.Vector3.TransformCoordinatesFromFloatsToRef(s,a,h,t,i)},t}();e.SphereParticleEmitter=t;var i=function(t){function i(e,i,r){var n=t.call(this,e)||this;return n.direction1=i,n.direction2=r,n}return Y(i,t),i.prototype.startDirectionFunction=function(t,i,r,n){var o=e.ParticleSystem.randomNumber(this.direction1.x,this.direction2.x),s=e.ParticleSystem.randomNumber(this.direction1.y,this.direction2.y),a=e.ParticleSystem.randomNumber(this.direction1.z,this.direction2.z);e.Vector3.TransformNormalFromFloatsToRef(o*t,s*t,a*t,i,r)},i}(t);e.SphereDirectedParticleEmitter=i}(us||(us={})),Et=us||(us={}),At=function(){function e(e,t,i){this.name=e,this.emitter=null,this.renderingGroupId=0,this.layerMask=268435455,this._updateVertexBuffers={},this._renderVertexBuffers={},this._currentRenderId=-1,this._started=!0,this.onDisposeObservable=new Et.Observable,this.id=e,this._scene=i||Et.Engine.LastCreatedScene,this._capacity=t,this._engine=this._scene.getEngine(),this._scene.particleSystems.push(this),this._renderEffect=new Et.Effect("gpuRenderParticles",["position","age","life","velocity"],[],[],this._scene.getEngine());this._updateEffect=new Et.Effect("gpuUpdateParticles",{attributes:["position","age","life","velocity"],uniformsNames:[],uniformBuffersNames:[],samplers:[],defines:"",fallbacks:null,onCompiled:null,onError:null,indexParameters:null,maxSimultaneousLights:0,transformFeedbackVaryings:["outPosition","outAge","outLife","outVelocity"]},this._scene.getEngine())}return e.prototype.isStarted=function(){return this._started},e.prototype.start=function(){this._started=!0},e.prototype.stop=function(){this._started=!1},e.prototype.animate=function(){},e.prototype._initialize=function(){if(!this._renderVAO){for(var e=new Array,t=0;t<this._capacity;t++){e.push(0),e.push(0),e.push(0);var i=1+10*Math.random();e.push(i+1),e.push(i),e.push(0),e.push(0),e.push(0)}this._updateBuffer=new Et.Buffer(this._scene.getEngine(),e,!1,0),this._updateVertexBuffers.position=this._updateBuffer.createVertexBuffer("position",0,3,3),this._updateVertexBuffers.age=this._updateBuffer.createVertexBuffer("age",3,1,1),this._updateVertexBuffers.life=this._updateBuffer.createVertexBuffer("life",4,1,1),this._updateVertexBuffers.velocity=this._updateBuffer.createVertexBuffer("velocity",5,3,3),this._updateVAO=this._engine.recordVertexArrayObject(this._updateVertexBuffers,null,this._updateEffect),this._engine.bindArrayBuffer(null),this._renderBuffer=new Et.Buffer(this._scene.getEngine(),e,!1,0),this._renderVertexBuffers.position=this._renderBuffer.createVertexBuffer("position",0,3,3),this._renderVertexBuffers.age=this._renderBuffer.createVertexBuffer("age",3,1,1),this._renderVertexBuffers.life=this._renderBuffer.createVertexBuffer("life",4,1,1),this._renderVertexBuffers.velocity=this._renderBuffer.createVertexBuffer("velocity",5,3,3),this._renderVAO=this._engine.recordVertexArrayObject(this._renderVertexBuffers,null,this._renderEffect),this._engine.bindArrayBuffer(null),this._sourceVAO=this._updateVAO,this._targetVAO=this._renderVAO,this._sourceBuffer=this._updateBuffer,this._targetBuffer=this._renderBuffer}},e.prototype.render=function(){if(!this.emitter||!this._updateEffect.isReady()||!this._renderEffect.isReady())return 0;if(this._initialize(),this._currentRenderId===this._scene.getRenderId())return 0;this._currentRenderId=this._scene.getRenderId(),this._engine.enableEffect(this._updateEffect),this._engine.setState(!1),this._engine.bindVertexArrayObject(this._sourceVAO,null),this._engine.bindTransformFeedbackBuffer(this._targetBuffer.getBuffer()),this._engine.setRasterizerState(!1),this._engine.beginTransformFeedback(),this._engine.drawArraysType(Et.Material.PointListDrawMode,0,this._capacity),this._engine.endTransformFeedback(),this._engine.setRasterizerState(!0),this._engine.bindTransformFeedbackBuffer(null),this._engine.enableEffect(this._renderEffect),this._engine.bindVertexArrayObject(this._targetVAO,null),this._engine.drawArraysType(Et.Material.PointListDrawMode,0,this._capacity);var e=this._sourceVAO;this._sourceVAO=this._targetVAO,this._targetVAO=e;var t=this._sourceBuffer;return this._sourceBuffer=this._targetBuffer,this._targetBuffer=t,0},e.prototype.rebuild=function(){},e.prototype.dispose=function(){var e=this._scene.particleSystems.indexOf(this);e>-1&&this._scene.particleSystems.splice(e,1),this.onDisposeObservable.notifyObservers(this),this.onDisposeObservable.clear()},e.prototype.clone=function(e,t){return null},e.prototype.serialize=function(){},e}(),Et.GPUParticleSystem=At,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}(us||(us={})),Pt=us||(us={}),Mt=function(){function e(e,t,i){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 Pt.SolidParticle(0,0,0,null,0,0,this),this._color=new Pt.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=Pt.Vector3.Zero(),this._cam_axisY=Pt.Vector3.Zero(),this._cam_axisX=Pt.Vector3.Zero(),this._axisZ=Pt.Axis.Z,this._camDir=Pt.Vector3.Zero(),this._camInvertedPosition=Pt.Vector3.Zero(),this._rotMatrix=new Pt.Matrix,this._invertMatrix=new Pt.Matrix,this._rotated=Pt.Vector3.Zero(),this._quaternion=new Pt.Quaternion,this._vertex=Pt.Vector3.Zero(),this._normal=Pt.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=Pt.Tmp.Vector3[0],this._maximum=Pt.Tmp.Vector3[1],this._minBbox=Pt.Tmp.Vector3[4],this._maxBbox=Pt.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=e,this._scene=t||Pt.Engine.LastCreatedScene,this._camera=t.activeCamera,this._pickable=!!i&&i.isPickable,this._depthSort=!!i&&i.enableDepthSort,this._particlesIntersect=!!i&&i.particleIntersection,this._bSphereOnly=!!i&&i.boundingSphereOnly,this._bSphereRadiusFactor=i&&i.bSphereRadiusFactor?i.bSphereRadiusFactor:1,i&&i.updatable?this._updatable=i.updatable:this._updatable=!0,this._pickable&&(this.pickedParticles=[]),this._depthSort&&(this.depthSortedParticles=[])}return e.prototype.buildMesh=function(){if(0===this.nbParticles){var e=Pt.MeshBuilder.CreateDisc("",{radius:1,tessellation:3},this._scene);this.addShape(e,1),e.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&&Pt.VertexData.ComputeNormals(this._positions32,this._indices32,this._normals),this._normals32=new Float32Array(this._normals),this._fixedNormal32=new Float32Array(this._normals),this._mustUnrotateFixedNormals&&this._unrotateFixedNormals();var t=new Pt.VertexData;t.indices=this._depthSort?this._indices:this._indices32,t.set(this._positions32,Pt.VertexBuffer.PositionKind),t.set(this._normals32,Pt.VertexBuffer.NormalKind),this._uvs32&&t.set(this._uvs32,Pt.VertexBuffer.UVKind),this._colors32&&t.set(this._colors32,Pt.VertexBuffer.ColorKind);var i=new Pt.Mesh(this.name,this._scene);return t.applyToMesh(i,this._updatable),this.mesh=i,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),i},e.prototype.digest=function(e,t){var i=t&&t.facetNb||1,r=t&&t.number||0,n=t&&t.delta||0,o=e.getVerticesData(Pt.VertexBuffer.PositionKind),s=e.getIndices(),a=e.getVerticesData(Pt.VertexBuffer.UVKind),h=e.getVerticesData(Pt.VertexBuffer.ColorKind),l=e.getVerticesData(Pt.VertexBuffer.NormalKind),c=0,u=s.length/3;r?(r=r>u?u:r,i=Math.round(u/r),n=0):i=i>u?u:i;for(var p=[],f=[],d=[],m=[],g=Pt.Tmp.Vector3[0],_=i;c<u;){c>u-(i=_+Math.floor((1+n)*Math.random()))&&(i=u-c),p.length=0,f.length=0,d.length=0,m.length=0;for(var v=0,y=3*c;y<3*(c+i);y++){f.push(v);var b=s[y];p.push(o[3*b],o[3*b+1],o[3*b+2]),a&&d.push(a[2*b],a[2*b+1]),h&&m.push(h[4*b],h[4*b+1],h[4*b+2],h[4*b+3]),v++}var x,T,E=this.nbParticles,A=this._posToShape(p),P=this._uvsToShapeUV(d);for(x=0;x<A.length;x++)g.addInPlace(A[x]);for(g.scaleInPlace(1/A.length),x=0;x<A.length;x++)A[x].subtractInPlace(g);this._particlesIntersect&&(T=new Pt.BoundingInfo(g,g));var M=new Pt.ModelShape(this._shapeCounter,A,3*i,P,null,null),S=this._positions.length,C=this._indices.length;this._meshBuilder(this._index,A,this._positions,f,this._indices,d,this._uvs,m,this._colors,l,this._normals,E,0,null),this._addParticle(E,S,C,M,this._shapeCounter,0,T),this.particles[this.nbParticles].position.addInPlace(g),this._index+=A.length,E++,this.nbParticles++,this._shapeCounter++,c+=i}return this},e.prototype._unrotateFixedNormals=function(){for(var e=0,t=0,i=0;i<this.particles.length;i++){this._particle=this.particles[i],this._shape=this._particle._model._shape,this._particle.rotationQuaternion?this._quaternion.copyFrom(this._particle.rotationQuaternion):(this._yaw=this._particle.rotation.y,this._pitch=this._particle.rotation.x,this._roll=this._particle.rotation.z,this._quaternionRotationYPR()),this._quaternionToRotationMatrix(),this._rotMatrix.invertToRef(this._invertMatrix);for(var r=0;r<this._shape.length;r++)t=e+3*r,Pt.Vector3.TransformNormalFromFloatsToRef(this._normals32[t],this._normals32[t+1],this._normals32[t+2],this._invertMatrix,this._normal),this._fixedNormal32[t]=this._normal.x,this._fixedNormal32[t+1]=this._normal.y,this._fixedNormal32[t+2]=this._normal.z;e=t+3}},e.prototype._resetCopy=function(){this._copy.position.x=0,this._copy.position.y=0,this._copy.position.z=0,this._copy.rotation.x=0,this._copy.rotation.y=0,this._copy.rotation.z=0,this._copy.rotationQuaternion=null,this._copy.scaling.x=1,this._copy.scaling.y=1,this._copy.scaling.z=1,this._copy.uvs.x=0,this._copy.uvs.y=0,this._copy.uvs.z=1,this._copy.uvs.w=1,this._copy.color=null},e.prototype._meshBuilder=function(e,t,i,r,n,o,s,a,h,l,c,u,p,f){var d,m=0,g=0,_=0;for(this._resetCopy(),f&&f.positionFunction&&(f.positionFunction(this._copy,u,p),this._mustUnrotateFixedNormals=!0),this._copy.rotationQuaternion?this._quaternion.copyFrom(this._copy.rotationQuaternion):(this._yaw=this._copy.rotation.y,this._pitch=this._copy.rotation.x,this._roll=this._copy.rotation.z,this._quaternionRotationYPR()),this._quaternionToRotationMatrix(),d=0;d<t.length;d++)this._vertex.x=t[d].x,this._vertex.y=t[d].y,this._vertex.z=t[d].z,f&&f.vertexFunction&&f.vertexFunction(this._copy,this._vertex,d),this._vertex.x*=this._copy.scaling.x,this._vertex.y*=this._copy.scaling.y,this._vertex.z*=this._copy.scaling.z,this._vertex.x+=this._copy.pivot.x,this._vertex.y+=this._copy.pivot.y,this._vertex.z+=this._copy.pivot.z,Pt.Vector3.TransformCoordinatesToRef(this._vertex,this._rotMatrix,this._rotated),i.push(this._copy.position.x+this._rotated.x,this._copy.position.y+this._rotated.y,this._copy.position.z+this._rotated.z),o&&(s.push((this._copy.uvs.z-this._copy.uvs.x)*o[m]+this._copy.uvs.x,(this._copy.uvs.w-this._copy.uvs.y)*o[m+1]+this._copy.uvs.y),m+=2),this._copy.color?this._color=this._copy.color:a&&void 0!==a[g]?(this._color.r=a[g],this._color.g=a[g+1],this._color.b=a[g+2],this._color.a=a[g+3]):(this._color.r=1,this._color.g=1,this._color.b=1,this._color.a=1),h.push(this._color.r,this._color.g,this._color.b,this._color.a),g+=4,!this.recomputeNormals&&l&&(this._normal.x=l[_],this._normal.y=l[_+1],this._normal.z=l[_+2],Pt.Vector3.TransformNormalToRef(this._normal,this._rotMatrix,this._normal),c.push(this._normal.x,this._normal.y,this._normal.z),_+=3);for(d=0;d<r.length;d++){var v=e+r[d];n.push(v),v>65535&&(this._needs32Bits=!0)}if(this._pickable){var y=r.length/3;for(d=0;d<y;d++)this.pickedParticles.push({idx:u,faceId:d})}return this._depthSort&&this.depthSortedParticles.push(new Pt.DepthSortedParticle),this._copy},e.prototype._posToShape=function(e){for(var t=[],i=0;i<e.length;i+=3)t.push(new Pt.Vector3(e[i],e[i+1],e[i+2]));return t},e.prototype._uvsToShapeUV=function(e){var t=[];if(e)for(var i=0;i<e.length;i++)t.push(e[i]);return t},e.prototype._addParticle=function(e,t,i,r,n,o,s){void 0===s&&(s=null);var a=new Pt.SolidParticle(e,t,i,r,n,o,this,s);return this.particles.push(a),a},e.prototype.addShape=function(e,t,i){var r,n=e.getVerticesData(Pt.VertexBuffer.PositionKind),o=e.getIndices(),s=e.getVerticesData(Pt.VertexBuffer.UVKind),a=e.getVerticesData(Pt.VertexBuffer.ColorKind),h=e.getVerticesData(Pt.VertexBuffer.NormalKind);this._particlesIntersect&&(r=e.getBoundingInfo());for(var l,c,u=this._posToShape(n),p=this._uvsToShapeUV(s),f=i?i.positionFunction:null,d=i?i.vertexFunction:null,m=new Pt.ModelShape(this._shapeCounter,u,o.length,p,f,d),g=this.nbParticles,_=0;_<t;_++){var v=this._positions.length,y=this._indices.length;c=this._meshBuilder(this._index,u,this._positions,o,this._indices,s,this._uvs,a,this._colors,h,this._normals,g,_,i),this._updatable&&((l=this._addParticle(g,v,y,m,this._shapeCounter,_,r)).position.copyFrom(c.position),l.rotation.copyFrom(c.rotation),c.rotationQuaternion&&l.rotationQuaternion&&l.rotationQuaternion.copyFrom(c.rotationQuaternion),c.color&&l.color&&l.color.copyFrom(c.color),l.scaling.copyFrom(c.scaling),l.uvs.copyFrom(c.uvs)),this._index+=u.length,g++}return this.nbParticles+=t,this._shapeCounter++,this._shapeCounter-1},e.prototype._rebuildParticle=function(e){this._resetCopy(),e._model._positionFunction&&e._model._positionFunction(this._copy,e.idx,e.idxInShape),this._copy.rotationQuaternion?this._quaternion.copyFrom(this._copy.rotationQuaternion):(this._yaw=this._copy.rotation.y,this._pitch=this._copy.rotation.x,this._roll=this._copy.rotation.z,this._quaternionRotationYPR()),this._quaternionToRotationMatrix(),this._shape=e._model._shape;for(var t=0;t<this._shape.length;t++)this._vertex.x=this._shape[t].x,this._vertex.y=this._shape[t].y,this._vertex.z=this._shape[t].z,e._model._vertexFunction&&e._model._vertexFunction(this._copy,this._vertex,t),this._vertex.x*=this._copy.scaling.x,this._vertex.y*=this._copy.scaling.y,this._vertex.z*=this._copy.scaling.z,this._vertex.x+=this._copy.pivot.x,this._vertex.y+=this._copy.pivot.y,this._vertex.z+=this._copy.pivot.z,Pt.Vector3.TransformCoordinatesToRef(this._vertex,this._rotMatrix,this._rotated),this._positions32[e._pos+3*t]=this._copy.position.x+this._rotated.x,this._positions32[e._pos+3*t+1]=this._copy.position.y+this._rotated.y,this._positions32[e._pos+3*t+2]=this._copy.position.z+this._rotated.z;e.position.x=0,e.position.y=0,e.position.z=0,e.rotation.x=0,e.rotation.y=0,e.rotation.z=0,e.rotationQuaternion=null,e.scaling.x=1,e.scaling.y=1,e.scaling.z=1},e.prototype.rebuildMesh=function(){for(var e=0;e<this.particles.length;e++)this._rebuildParticle(this.particles[e]);return this.mesh.updateVerticesData(Pt.VertexBuffer.PositionKind,this._positions32,!1,!1),this},e.prototype.setParticles=function(e,t,i){if(void 0===e&&(e=0),void 0===t&&(t=this.nbParticles-1),void 0===i&&(i=!0),!this._updatable)return this;if(this.beforeUpdateParticles(e,t,i),this._cam_axisX.x=1,this._cam_axisX.y=0,this._cam_axisX.z=0,this._cam_axisY.x=0,this._cam_axisY.y=1,this._cam_axisY.z=0,this._cam_axisZ.x=0,this._cam_axisZ.y=0,this._cam_axisZ.z=1,(this.billboard||this._depthSort)&&(this.mesh.computeWorldMatrix(!0),this.mesh._worldMatrix.invertToRef(this._invertMatrix)),this.billboard){this._camera.getDirectionToRef(this._axisZ,this._camDir),Pt.Vector3.TransformNormalToRef(this._camDir,this._invertMatrix,this._cam_axisZ),this._cam_axisZ.normalize();var r=this._camera.getViewMatrix(!0);Pt.Vector3.TransformNormalFromFloatsToRef(r.m[1],r.m[5],r.m[9],this._invertMatrix,this._cam_axisY),Pt.Vector3.CrossToRef(this._cam_axisY,this._cam_axisZ,this._cam_axisX),this._cam_axisY.normalize(),this._cam_axisX.normalize()}this._depthSort&&Pt.Vector3.TransformCoordinatesToRef(this._camera.globalPosition,this._invertMatrix,this._camInvertedPosition),Pt.Matrix.IdentityToRef(this._rotMatrix);var n=0,o=0,s=0,a=0,h=0,l=0,c=0;this.mesh.isFacetDataEnabled&&(this._computeBoundingBox=!0),t=t>=this.nbParticles?this.nbParticles-1:t,this._computeBoundingBox&&(0==e&&t==this.nbParticles-1?(Pt.Vector3.FromFloatsToRef(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE,this._minimum),Pt.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 u=(o=this.particles[e]._pos)/3|0;a=4*u,l=2*u;for(var p=e;p<=t;p++){if(this._particle=this.particles[p],this._shape=this._particle._model._shape,this._shapeUV=this._particle._model._shapeUV,this.updateParticle(this._particle),this._depthSort&&this._depthSortParticles){var f=this.depthSortedParticles[p];f.ind=this._particle._ind,f.indicesLength=this._particle._model._indicesLength,f.sqDistance=Pt.Vector3.DistanceSquared(this._particle.position,this._camInvertedPosition)}if(!this._particle.alive||this._particle._stillInvisible&&!this._particle.isVisible)o+=3*(c=this._shape.length),a+=4*c,l+=2*c;else{if(this._particle.isVisible)for(this._particle._stillInvisible=!1,this.billboard&&(this._particle.rotation.x=0,this._particle.rotation.y=0),(this._computeParticleRotation||this.billboard)&&(this._particle.rotationQuaternion?this._quaternion.copyFrom(this._particle.rotationQuaternion):(this._yaw=this._particle.rotation.y,this._pitch=this._particle.rotation.x,this._roll=this._particle.rotation.z,this._quaternionRotationYPR()),this._quaternionToRotationMatrix()),c=0;c<this._shape.length;c++)n=o+3*c,s=a+4*c,h=l+2*c,this._vertex.x=this._shape[c].x,this._vertex.y=this._shape[c].y,this._vertex.z=this._shape[c].z,this._computeParticleVertex&&this.updateParticleVertex(this._particle,this._vertex,c),this._vertex.x*=this._particle.scaling.x,this._vertex.y*=this._particle.scaling.y,this._vertex.z*=this._particle.scaling.z,this._vertex.x+=this._particle.pivot.x,this._vertex.y+=this._particle.pivot.y,this._vertex.z+=this._particle.pivot.z,this._rotated.x=this._vertex.x*this._rotMatrix.m[0]+this._vertex.y*this._rotMatrix.m[4]+this._vertex.z*this._rotMatrix.m[8],this._rotated.y=this._vertex.x*this._rotMatrix.m[1]+this._vertex.y*this._rotMatrix.m[5]+this._vertex.z*this._rotMatrix.m[9],this._rotated.z=this._vertex.x*this._rotMatrix.m[2]+this._vertex.y*this._rotMatrix.m[6]+this._vertex.z*this._rotMatrix.m[10],this._positions32[n]=this._particle.position.x+this._cam_axisX.x*this._rotated.x+this._cam_axisY.x*this._rotated.y+this._cam_axisZ.x*this._rotated.z,this._positions32[n+1]=this._particle.position.y+this._cam_axisX.y*this._rotated.x+this._cam_axisY.y*this._rotated.y+this._cam_axisZ.y*this._rotated.z,this._positions32[n+2]=this._particle.position.z+this._cam_axisX.z*this._rotated.x+this._cam_axisY.z*this._rotated.y+this._cam_axisZ.z*this._rotated.z,this._computeBoundingBox&&(this._positions32[n]<this._minimum.x&&(this._minimum.x=this._positions32[n]),this._positions32[n]>this._maximum.x&&(this._maximum.x=this._positions32[n]),this._positions32[n+1]<this._minimum.y&&(this._minimum.y=this._positions32[n+1]),this._positions32[n+1]>this._maximum.y&&(this._maximum.y=this._positions32[n+1]),this._positions32[n+2]<this._minimum.z&&(this._minimum.z=this._positions32[n+2]),this._positions32[n+2]>this._maximum.z&&(this._maximum.z=this._positions32[n+2])),this._computeParticleVertex||(this._normal.x=this._fixedNormal32[n],this._normal.y=this._fixedNormal32[n+1],this._normal.z=this._fixedNormal32[n+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[n]=this._cam_axisX.x*this._rotated.x+this._cam_axisY.x*this._rotated.y+this._cam_axisZ.x*this._rotated.z,this._normals32[n+1]=this._cam_axisX.y*this._rotated.x+this._cam_axisY.y*this._rotated.y+this._cam_axisZ.y*this._rotated.z,this._normals32[n+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[s]=this._particle.color.r,this._colors32[s+1]=this._particle.color.g,this._colors32[s+2]=this._particle.color.b,this._colors32[s+3]=this._particle.color.a),this._computeParticleTexture&&(this._uvs32[h]=this._shapeUV[2*c]*(this._particle.uvs.z-this._particle.uvs.x)+this._particle.uvs.x,this._uvs32[h+1]=this._shapeUV[2*c+1]*(this._particle.uvs.w-this._particle.uvs.y)+this._particle.uvs.y);else for(this._particle._stillInvisible=!0,c=0;c<this._shape.length;c++)n=o+3*c,s=a+4*c,h=l+2*c,this._positions32[n]=0,this._positions32[n+1]=0,this._positions32[n+2]=0,this._normals32[n]=0,this._normals32[n+1]=0,this._normals32[n+2]=0,this._computeParticleColor&&this._particle.color&&(this._colors32[s]=this._particle.color.r,this._colors32[s+1]=this._particle.color.g,this._colors32[s+2]=this._particle.color.b,this._colors32[s+3]=this._particle.color.a),this._computeParticleTexture&&(this._uvs32[h]=this._shapeUV[2*c]*(this._particle.uvs.z-this._particle.uvs.x)+this._particle.uvs.x,this._uvs32[h+1]=this._shapeUV[2*c+1]*(this._particle.uvs.w-this._particle.uvs.y)+this._particle.uvs.y);if(this._particlesIntersect){var d=this._particle._boundingInfo,m=d.boundingBox,g=d.boundingSphere;if(!this._bSphereOnly){for(var _=0;_<m.vectors.length;_++)this._vertex.x=this._particle._modelBoundingInfo.boundingBox.vectors[_].x*this._particle.scaling.x,this._vertex.y=this._particle._modelBoundingInfo.boundingBox.vectors[_].y*this._particle.scaling.y,this._vertex.z=this._particle._modelBoundingInfo.boundingBox.vectors[_].z*this._particle.scaling.z,this._rotated.x=this._vertex.x*this._rotMatrix.m[0]+this._vertex.y*this._rotMatrix.m[4]+this._vertex.z*this._rotMatrix.m[8],this._rotated.y=this._vertex.x*this._rotMatrix.m[1]+this._vertex.y*this._rotMatrix.m[5]+this._vertex.z*this._rotMatrix.m[9],this._rotated.z=this._vertex.x*this._rotMatrix.m[2]+this._vertex.y*this._rotMatrix.m[6]+this._vertex.z*this._rotMatrix.m[10],m.vectors[_].x=this._particle.position.x+this._cam_axisX.x*this._rotated.x+this._cam_axisY.x*this._rotated.y+this._cam_axisZ.x*this._rotated.z,m.vectors[_].y=this._particle.position.y+this._cam_axisX.y*this._rotated.x+this._cam_axisY.y*this._rotated.y+this._cam_axisZ.y*this._rotated.z,m.vectors[_].z=this._particle.position.z+this._cam_axisX.z*this._rotated.x+this._cam_axisY.z*this._rotated.y+this._cam_axisZ.z*this._rotated.z;m._update(this.mesh._worldMatrix)}this._minBbox.x=this._particle._modelBoundingInfo.minimum.x*this._particle.scaling.x,this._minBbox.y=this._particle._modelBoundingInfo.minimum.y*this._particle.scaling.y,this._minBbox.z=this._particle._modelBoundingInfo.minimum.z*this._particle.scaling.z,this._maxBbox.x=this._particle._modelBoundingInfo.maximum.x*this._particle.scaling.x,this._maxBbox.y=this._particle._modelBoundingInfo.maximum.y*this._particle.scaling.y,this._maxBbox.z=this._particle._modelBoundingInfo.maximum.z*this._particle.scaling.z,g.center.x=this._particle.position.x+.5*(this._minBbox.x+this._maxBbox.x),g.center.y=this._particle.position.y+.5*(this._minBbox.y+this._maxBbox.y),g.center.z=this._particle.position.z+.5*(this._minBbox.z+this._maxBbox.z),g.radius=.5*this._bSphereRadiusFactor*Math.sqrt((this._maxBbox.x-this._minBbox.x)*(this._maxBbox.x-this._minBbox.x)+(this._maxBbox.y-this._minBbox.y)*(this._maxBbox.y-this._minBbox.y)+(this._maxBbox.z-this._minBbox.z)*(this._maxBbox.z-this._minBbox.z)),g._update(this.mesh._worldMatrix)}o=n+3,a=s+4,l=h+2}}if(i){if(this._computeParticleColor&&this.mesh.updateVerticesData(Pt.VertexBuffer.ColorKind,this._colors32,!1,!1),this._computeParticleTexture&&this.mesh.updateVerticesData(Pt.VertexBuffer.UVKind,this._uvs32,!1,!1),this.mesh.updateVerticesData(Pt.VertexBuffer.PositionKind,this._positions32,!1,!1),!this.mesh.areNormalsFrozen||this.mesh.isFacetDataEnabled){if(this._computeParticleVertex||this.mesh.isFacetDataEnabled){var v=this.mesh.isFacetDataEnabled?this.mesh.getFacetDataParameters():null;Pt.VertexData.ComputeNormals(this._positions32,this._indices32,this._normals32,v);for(var y=0;y<this._normals32.length;y++)this._fixedNormal32[y]=this._normals32[y]}this.mesh.areNormalsFrozen||this.mesh.updateVerticesData(Pt.VertexBuffer.NormalKind,this._normals32,!1,!1)}if(this._depthSort&&this._depthSortParticles){this.depthSortedParticles.sort(this._depthSortFunction);var b=this.depthSortedParticles.length,x=0,T=0,E=0,A=0;for(x=0;x<b;x++){T=this.depthSortedParticles[x].indicesLength,E=this.depthSortedParticles[x].ind;for(y=0;y<T;y++)this._indices32[A]=this._indices[E+y],A++}this.mesh.updateIndices(this._indices32)}}return this._computeBoundingBox&&(this.mesh._boundingInfo=new Pt.BoundingInfo(this._minimum,this._maximum),this.mesh._boundingInfo.update(this.mesh._worldMatrix)),this.afterUpdateParticles(e,t,i),this},e.prototype._quaternionRotationYPR=function(){this._halfroll=.5*this._roll,this._halfpitch=.5*this._pitch,this._halfyaw=.5*this._yaw,this._sinRoll=Math.sin(this._halfroll),this._cosRoll=Math.cos(this._halfroll),this._sinPitch=Math.sin(this._halfpitch),this._cosPitch=Math.cos(this._halfpitch),this._sinYaw=Math.sin(this._halfyaw),this._cosYaw=Math.cos(this._halfyaw),this._quaternion.x=this._cosYaw*this._sinPitch*this._cosRoll+this._sinYaw*this._cosPitch*this._sinRoll,this._quaternion.y=this._sinYaw*this._cosPitch*this._cosRoll-this._cosYaw*this._sinPitch*this._sinRoll,this._quaternion.z=this._cosYaw*this._cosPitch*this._sinRoll-this._sinYaw*this._sinPitch*this._cosRoll,this._quaternion.w=this._cosYaw*this._cosPitch*this._cosRoll+this._sinYaw*this._sinPitch*this._sinRoll},e.prototype._quaternionToRotationMatrix=function(){this._rotMatrix.m[0]=1-2*(this._quaternion.y*this._quaternion.y+this._quaternion.z*this._quaternion.z),this._rotMatrix.m[1]=2*(this._quaternion.x*this._quaternion.y+this._quaternion.z*this._quaternion.w),this._rotMatrix.m[2]=2*(this._quaternion.z*this._quaternion.x-this._quaternion.y*this._quaternion.w),this._rotMatrix.m[3]=0,this._rotMatrix.m[4]=2*(this._quaternion.x*this._quaternion.y-this._quaternion.z*this._quaternion.w),this._rotMatrix.m[5]=1-2*(this._quaternion.z*this._quaternion.z+this._quaternion.x*this._quaternion.x),this._rotMatrix.m[6]=2*(this._quaternion.y*this._quaternion.z+this._quaternion.x*this._quaternion.w),this._rotMatrix.m[7]=0,this._rotMatrix.m[8]=2*(this._quaternion.z*this._quaternion.x+this._quaternion.y*this._quaternion.w),this._rotMatrix.m[9]=2*(this._quaternion.y*this._quaternion.z-this._quaternion.x*this._quaternion.w),this._rotMatrix.m[10]=1-2*(this._quaternion.y*this._quaternion.y+this._quaternion.x*this._quaternion.x),this._rotMatrix.m[11]=0,this._rotMatrix.m[12]=0,this._rotMatrix.m[13]=0,this._rotMatrix.m[14]=0,this._rotMatrix.m[15]=1},e.prototype.dispose=function(){this.mesh.dispose(),this.vars=null,this._positions=null,this._indices=null,this._normals=null,this._uvs=null,this._colors=null,this._indices32=null,this._positions32=null,this._normals32=null,this._fixedNormal32=null,this._uvs32=null,this._colors32=null,this.pickedParticles=null},e.prototype.refreshVisibleSize=function(){return this._isVisibilityBoxLocked||this.mesh.refreshBoundingInfo(),this},e.prototype.setVisibilityBox=function(e){var t=e/2;this.mesh._boundingInfo=new Pt.BoundingInfo(new Pt.Vector3(-t,-t,-t),new Pt.Vector3(t,t,t))},Object.defineProperty(e.prototype,"isAlwaysVisible",{get:function(){return this._alwaysVisible},set:function(e){this._alwaysVisible=e,this.mesh.alwaysSelectAsActiveMesh=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isVisibilityBoxLocked",{get:function(){return this._isVisibilityBoxLocked},set:function(e){this._isVisibilityBoxLocked=e,this.mesh.getBoundingInfo().isLocked=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"computeParticleRotation",{get:function(){return this._computeParticleRotation},set:function(e){this._computeParticleRotation=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"computeParticleColor",{get:function(){return this._computeParticleColor},set:function(e){this._computeParticleColor=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"computeParticleTexture",{get:function(){return this._computeParticleTexture},set:function(e){this._computeParticleTexture=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"computeParticleVertex",{get:function(){return this._computeParticleVertex},set:function(e){this._computeParticleVertex=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"computeBoundingBox",{get:function(){return this._computeBoundingBox},set:function(e){this._computeBoundingBox=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"depthSortParticles",{get:function(){return this._depthSortParticles},set:function(e){this._depthSortParticles=e},enumerable:!0,configurable:!0}),e.prototype.initParticles=function(){},e.prototype.recycleParticle=function(e){return e},e.prototype.updateParticle=function(e){return e},e.prototype.updateParticleVertex=function(e,t,i){return t},e.prototype.beforeUpdateParticles=function(e,t,i){},e.prototype.afterUpdateParticles=function(e,t,i){},e}(),Pt.SolidParticleSystem=Mt,St=us||(us={}),Ct=function(e){function t(t,i,r,n){var o=e.call(this,t,i)||this;return o._textures={},o._textureArrays={},o._floats={},o._ints={},o._floatsArrays={},o._colors3={},o._colors3Arrays={},o._colors4={},o._vectors2={},o._vectors3={},o._vectors4={},o._matrices={},o._matrices3x3={},o._matrices2x2={},o._vectors2Arrays={},o._vectors3Arrays={},o._cachedWorldViewMatrix=new St.Matrix,o._shaderPath=r,n.needAlphaBlending=n.needAlphaBlending||!1,n.needAlphaTesting=n.needAlphaTesting||!1,n.attributes=n.attributes||["position","normal","uv"],n.uniforms=n.uniforms||["worldViewProjection"],n.uniformBuffers=n.uniformBuffers||[],n.samplers=n.samplers||[],n.defines=n.defines||[],o._options=n,o}return Y(t,e),t.prototype.getClassName=function(){return"ShaderMaterial"},t.prototype.needAlphaBlending=function(){return this._options.needAlphaBlending},t.prototype.needAlphaTesting=function(){return this._options.needAlphaTesting},t.prototype._checkUniform=function(e){-1===this._options.uniforms.indexOf(e)&&this._options.uniforms.push(e)},t.prototype.setTexture=function(e,t){return-1===this._options.samplers.indexOf(e)&&this._options.samplers.push(e),this._textures[e]=t,this},t.prototype.setTextureArray=function(e,t){return-1===this._options.samplers.indexOf(e)&&this._options.samplers.push(e),this._checkUniform(e),this._textureArrays[e]=t,this},t.prototype.setFloat=function(e,t){return this._checkUniform(e),this._floats[e]=t,this},t.prototype.setInt=function(e,t){return this._checkUniform(e),this._ints[e]=t,this},t.prototype.setFloats=function(e,t){return this._checkUniform(e),this._floatsArrays[e]=t,this},t.prototype.setColor3=function(e,t){return this._checkUniform(e),this._colors3[e]=t,this},t.prototype.setColor3Array=function(e,t){return this._checkUniform(e),this._colors3Arrays[e]=t.reduce(function(e,t){return t.toArray(e,e.length),e},[]),this},t.prototype.setColor4=function(e,t){return this._checkUniform(e),this._colors4[e]=t,this},t.prototype.setVector2=function(e,t){return this._checkUniform(e),this._vectors2[e]=t,this},t.prototype.setVector3=function(e,t){return this._checkUniform(e),this._vectors3[e]=t,this},t.prototype.setVector4=function(e,t){return this._checkUniform(e),this._vectors4[e]=t,this},t.prototype.setMatrix=function(e,t){return this._checkUniform(e),this._matrices[e]=t,this},t.prototype.setMatrix3x3=function(e,t){return this._checkUniform(e),this._matrices3x3[e]=t,this},t.prototype.setMatrix2x2=function(e,t){return this._checkUniform(e),this._matrices2x2[e]=t,this},t.prototype.setArray2=function(e,t){return this._checkUniform(e),this._vectors2Arrays[e]=t,this},t.prototype.setArray3=function(e,t){return this._checkUniform(e),this._vectors3Arrays[e]=t,this},t.prototype._checkCache=function(e,t,i){return!t||(this._effect&&this._effect.defines.indexOf("#define INSTANCES"),!1)},t.prototype.isReady=function(e,t){var i=this.getScene(),r=i.getEngine();if(!this.checkReadyOnEveryCall&&this._renderId===i.getRenderId()&&this._checkCache(i,e,t))return!0;var n=[],o=[],s=new St.EffectFallbacks;t&&n.push("#define INSTANCES");for(var a=0;a<this._options.defines.length;a++)n.push(this._options.defines[a]);for(a=0;a<this._options.attributes.length;a++)o.push(this._options.attributes[a]);e&&e.isVerticesDataPresent(St.VertexBuffer.ColorKind)&&(o.push(St.VertexBuffer.ColorKind),n.push("#define VERTEXCOLOR")),e&&e.useBones&&e.computeBonesUsingShaders&&e.skeleton?(o.push(St.VertexBuffer.MatricesIndicesKind),o.push(St.VertexBuffer.MatricesWeightsKind),e.numBoneInfluencers>4&&(o.push(St.VertexBuffer.MatricesIndicesExtraKind),o.push(St.VertexBuffer.MatricesWeightsExtraKind)),n.push("#define NUM_BONE_INFLUENCERS "+e.numBoneInfluencers),n.push("#define BonesPerMesh "+(e.skeleton.bones.length+1)),s.addCPUSkinningFallback(0,e),-1===this._options.uniforms.indexOf("mBones")&&this._options.uniforms.push("mBones")):n.push("#define NUM_BONE_INFLUENCERS 0");for(var h in this._textures)if(!this._textures[h].isReady())return!1;r.getAlphaTesting()&&n.push("#define ALPHATEST");var l=this._effect,c=n.join("\n");return this._effect=r.createEffect(this._shaderPath,{attributes:o,uniformsNames:this._options.uniforms,uniformBuffersNames:this._options.uniformBuffers,samplers:this._options.samplers,defines:c,fallbacks:s,onCompiled:this.onCompiled,onError:this.onError},r),!!this._effect.isReady()&&(l!==this._effect&&i.resetCachedMaterial(),this._renderId=i.getRenderId(),!0)},t.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())))},t.prototype.bind=function(e,t){if(this.bindOnlyWorldMatrix(e),this._effect&&this.getScene().getCachedMaterial()!==this){var i;-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()),St.MaterialHelper.BindBonesParameters(t,this._effect);for(i in this._textures)this._effect.setTexture(i,this._textures[i]);for(i in this._textureArrays)this._effect.setTextureArray(i,this._textureArrays[i]);for(i in this._ints)this._effect.setInt(i,this._ints[i]);for(i in this._floats)this._effect.setFloat(i,this._floats[i]);for(i in this._floatsArrays)this._effect.setArray(i,this._floatsArrays[i]);for(i in this._colors3)this._effect.setColor3(i,this._colors3[i]);for(i in this._colors3Arrays)this._effect.setArray3(i,this._colors3Arrays[i]);for(i in this._colors4){var r=this._colors4[i];this._effect.setFloat4(i,r.r,r.g,r.b,r.a)}for(i in this._vectors2)this._effect.setVector2(i,this._vectors2[i]);for(i in this._vectors3)this._effect.setVector3(i,this._vectors3[i]);for(i in this._vectors4)this._effect.setVector4(i,this._vectors4[i]);for(i in this._matrices)this._effect.setMatrix(i,this._matrices[i]);for(i in this._matrices3x3)this._effect.setMatrix3x3(i,this._matrices3x3[i]);for(i in this._matrices2x2)this._effect.setMatrix2x2(i,this._matrices2x2[i]);for(i in this._vectors2Arrays)this._effect.setArray2(i,this._vectors2Arrays[i]);for(i in this._vectors3Arrays)this._effect.setArray3(i,this._vectors3Arrays[i])}this._afterBind(t)},t.prototype.getActiveTextures=function(){var t=e.prototype.getActiveTextures.call(this);for(var i in this._textures)t.push(this._textures[i]);for(var i in this._textureArrays)for(var r=this._textureArrays[i],n=0;n<r.length;n++)t.push(r[n]);return t},t.prototype.hasTexture=function(t){if(e.prototype.hasTexture.call(this,t))return!0;for(var i in this._textures)if(this._textures[i]===t)return!0;for(var i in this._textureArrays)for(var r=this._textureArrays[i],n=0;n<r.length;n++)if(r[n]===t)return!0;return!1},t.prototype.clone=function(e){return new t(e,this.getScene(),this._shaderPath,this._options)},t.prototype.dispose=function(t,i){if(i){var r;for(r in this._textures)this._textures[r].dispose();for(r in this._textureArrays)for(var n=this._textureArrays[r],o=0;o<n.length;o++)n[o].dispose()}this._textures={},e.prototype.dispose.call(this,t,i)},t.prototype.serialize=function(){var e,t=St.SerializationHelper.Serialize(this);t.customType="BABYLON.ShaderMaterial",t.options=this._options,t.shaderPath=this._shaderPath,t.textures={};for(e in this._textures)t.textures[e]=this._textures[e].serialize();t.textureArrays={};for(e in this._textureArrays){t.textureArrays[e]=[];for(var i=this._textureArrays[e],r=0;r<i.length;r++)t.textureArrays[e].push(i[r].serialize())}t.floats={};for(e in this._floats)t.floats[e]=this._floats[e];t.FloatArrays={};for(e in this._floatsArrays)t.FloatArrays[e]=this._floatsArrays[e];t.colors3={};for(e in this._colors3)t.colors3[e]=this._colors3[e].asArray();t.colors3Arrays={};for(e in this._colors3Arrays)t.colors3Arrays[e]=this._colors3Arrays[e];t.colors4={};for(e in this._colors4)t.colors4[e]=this._colors4[e].asArray();t.vectors2={};for(e in this._vectors2)t.vectors2[e]=this._vectors2[e].asArray();t.vectors3={};for(e in this._vectors3)t.vectors3[e]=this._vectors3[e].asArray();t.vectors4={};for(e in this._vectors4)t.vectors4[e]=this._vectors4[e].asArray();t.matrices={};for(e in this._matrices)t.matrices[e]=this._matrices[e].asArray();t.matrices3x3={};for(e in this._matrices3x3)t.matrices3x3[e]=this._matrices3x3[e];t.matrices2x2={};for(e in this._matrices2x2)t.matrices2x2[e]=this._matrices2x2[e];t.vectors2Arrays={};for(e in this._vectors2Arrays)t.vectors2Arrays[e]=this._vectors2Arrays[e];t.vectors3Arrays={};for(e in this._vectors3Arrays)t.vectors3Arrays[e]=this._vectors3Arrays[e];return t},t.Parse=function(e,i,r){var n,o=St.SerializationHelper.Parse(function(){return new t(e.name,i,e.shaderPath,e.options)},e,i,r);for(n in e.textures)o.setTexture(n,St.Texture.Parse(e.textures[n],i,r));for(n in e.textureArrays){for(var s=e.textureArrays[n],a=new Array,h=0;h<s.length;h++)a.push(St.Texture.Parse(s[h],i,r));o.setTextureArray(n,a)}for(n in e.floats)o.setFloat(n,e.floats[n]);for(n in e.floatsArrays)o.setFloats(n,e.floatsArrays[n]);for(n in e.colors3)o.setColor3(n,St.Color3.FromArray(e.colors3[n]));for(n in e.colors3Arrays){var l=e.colors3Arrays[n].reduce(function(e,t,i){return i%3==0?e.push([t]):e[e.length-1].push(t),e},[]).map(function(e){return St.Color3.FromArray(e)});o.setColor3Array(n,l)}for(n in e.colors4)o.setColor4(n,St.Color4.FromArray(e.colors4[n]));for(n in e.vectors2)o.setVector2(n,St.Vector2.FromArray(e.vectors2[n]));for(n in e.vectors3)o.setVector3(n,St.Vector3.FromArray(e.vectors3[n]));for(n in e.vectors4)o.setVector4(n,St.Vector4.FromArray(e.vectors4[n]));for(n in e.matrices)o.setMatrix(n,St.Matrix.FromArray(e.matrices[n]));for(n in e.matrices3x3)o.setMatrix3x3(n,e.matrices3x3[n]);for(n in e.matrices2x2)o.setMatrix2x2(n,e.matrices2x2[n]);for(n in e.vectors2Arrays)o.setArray2(n,e.vectors2Arrays[n]);for(n in e.vectors3Arrays)o.setArray3(n,e.vectors3Arrays[n]);return o},t}(St.Material),St.ShaderMaterial=Ct,Rt=us||(us={}),Ot=function(e){function t(t,i){var r=e.call(this,t,i)||this;return r.generateOctree=!1,r}return Y(t,e),t.prototype.getClassName=function(){return"GroundMesh"},Object.defineProperty(t.prototype,"subdivisions",{get:function(){return Math.min(this._subdivisionsX,this._subdivisionsY)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"subdivisionsX",{get:function(){return this._subdivisionsX},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"subdivisionsY",{get:function(){return this._subdivisionsY},enumerable:!0,configurable:!0}),t.prototype.optimize=function(e,t){void 0===t&&(t=32),this._subdivisionsX=e,this._subdivisionsY=e,this.subdivide(e),this.createOrUpdateSubmeshesOctree(t)},t.prototype.getHeightAtCoordinates=function(e,t){var i=this.getWorldMatrix(),r=Rt.Tmp.Matrix[5];i.invertToRef(r);var n=Rt.Tmp.Vector3[8];if(Rt.Vector3.TransformCoordinatesFromFloatsToRef(e,0,t,r,n),e=n.x,t=n.z,e<this._minX||e>this._maxX||t<this._minZ||t>this._maxZ)return this.position.y;this._heightQuads&&0!=this._heightQuads.length||(this._initHeightQuads(),this._computeHeightQuads());var o=this._getFacetAt(e,t),s=-(o.x*e+o.z*t+o.w)/o.y;return Rt.Vector3.TransformCoordinatesFromFloatsToRef(0,s,0,i,n),n.y},t.prototype.getNormalAtCoordinates=function(e,t){var i=new Rt.Vector3(0,1,0);return this.getNormalAtCoordinatesToRef(e,t,i),i},t.prototype.getNormalAtCoordinatesToRef=function(e,t,i){var r=this.getWorldMatrix(),n=Rt.Tmp.Matrix[5];r.invertToRef(n);var o=Rt.Tmp.Vector3[8];if(Rt.Vector3.TransformCoordinatesFromFloatsToRef(e,0,t,n,o),e=o.x,t=o.z,e<this._minX||e>this._maxX||t<this._minZ||t>this._maxZ)return this;this._heightQuads&&0!=this._heightQuads.length||(this._initHeightQuads(),this._computeHeightQuads());var s=this._getFacetAt(e,t);return Rt.Vector3.TransformNormalFromFloatsToRef(s.x,s.y,s.z,r,i),this},t.prototype.updateCoordinateHeights=function(){return this._heightQuads&&0!=this._heightQuads.length||this._initHeightQuads(),this._computeHeightQuads(),this},t.prototype._getFacetAt=function(e,t){var i=Math.floor((e+this._maxX)*this._subdivisionsX/this._width),r=Math.floor(-(t+this._maxZ)*this._subdivisionsY/this._height+this._subdivisionsY),n=this._heightQuads[r*this._subdivisionsX+i];return t<n.slope.x*e+n.slope.y?n.facet1:n.facet2},t.prototype._initHeightQuads=function(){var e=this._subdivisionsX,t=this._subdivisionsY;this._heightQuads=new Array;for(var i=0;i<t;i++)for(var r=0;r<e;r++){var n={slope:Rt.Vector2.Zero(),facet1:new Rt.Vector4(0,0,0,0),facet2:new Rt.Vector4(0,0,0,0)};this._heightQuads[i*e+r]=n}return this},t.prototype._computeHeightQuads=function(){var e=this.getVerticesData(Rt.VertexBuffer.PositionKind);if(!e)return this;for(var t=Rt.Tmp.Vector3[3],i=Rt.Tmp.Vector3[2],r=Rt.Tmp.Vector3[1],n=Rt.Tmp.Vector3[0],o=Rt.Tmp.Vector3[4],s=Rt.Tmp.Vector3[5],a=Rt.Tmp.Vector3[6],h=Rt.Tmp.Vector3[7],l=Rt.Tmp.Vector3[8],c=0,u=0,p=0,f=0,d=0,m=0,g=0,_=this._subdivisionsX,v=this._subdivisionsY,y=0;y<v;y++)for(var b=0;b<_;b++){c=3*b,u=y*(_+1)*3,p=(y+1)*(_+1)*3,t.x=e[u+c],t.y=e[u+c+1],t.z=e[u+c+2],i.x=e[u+c+3],i.y=e[u+c+4],i.z=e[u+c+5],r.x=e[p+c],r.y=e[p+c+1],r.z=e[p+c+2],n.x=e[p+c+3],n.y=e[p+c+4],n.z=e[p+c+5],f=(n.z-t.z)/(n.x-t.x),d=t.z-f*t.x,i.subtractToRef(t,o),r.subtractToRef(t,s),n.subtractToRef(t,a),Rt.Vector3.CrossToRef(a,s,h),Rt.Vector3.CrossToRef(o,a,l),h.normalize(),l.normalize(),m=-(h.x*t.x+h.y*t.y+h.z*t.z),g=-(l.x*i.x+l.y*i.y+l.z*i.z);var x=this._heightQuads[y*_+b];x.slope.copyFromFloats(f,d),x.facet1.copyFromFloats(h.x,h.y,h.z,m),x.facet2.copyFromFloats(l.x,l.y,l.z,g)}return this},t.prototype.serialize=function(t){e.prototype.serialize.call(this,t),t.subdivisionsX=this._subdivisionsX,t.subdivisionsY=this._subdivisionsY,t.minX=this._minX,t.maxX=this._maxX,t.minZ=this._minZ,t.maxZ=this._maxZ,t.width=this._width,t.height=this._height},t.Parse=function(e,i){var r=new t(e.name,i);return r._subdivisionsX=e.subdivisionsX||1,r._subdivisionsY=e.subdivisionsY||1,r._minX=e.minX,r._maxX=e.maxX,r._minZ=e.minZ,r._maxZ=e.maxZ,r._width=e.width,r._height=e.height,r},t}(Rt.Mesh),Rt.GroundMesh=Ot,It=us||(us={}),wt=function(e){function t(t,i){var r=e.call(this,t,i.getScene())||this;return i.instances.push(r),r._sourceMesh=i,r.position.copyFrom(i.position),r.rotation.copyFrom(i.rotation),r.scaling.copyFrom(i.scaling),i.rotationQuaternion&&(r.rotationQuaternion=i.rotationQuaternion.clone()),r.infiniteDistance=i.infiniteDistance,r.setPivotMatrix(i.getPivotMatrix()),r.refreshBoundingInfo(),r._syncSubMeshes(),r}return Y(t,e),t.prototype.getClassName=function(){return"InstancedMesh"},Object.defineProperty(t.prototype,"receiveShadows",{get:function(){return this._sourceMesh.receiveShadows},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"material",{get:function(){return this._sourceMesh.material},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"visibility",{get:function(){return this._sourceMesh.visibility},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"skeleton",{get:function(){return this._sourceMesh.skeleton},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"renderingGroupId",{get:function(){return this._sourceMesh.renderingGroupId},enumerable:!0,configurable:!0}),t.prototype.getTotalVertices=function(){return this._sourceMesh.getTotalVertices()},Object.defineProperty(t.prototype,"sourceMesh",{get:function(){return this._sourceMesh},enumerable:!0,configurable:!0}),t.prototype.isReady=function(){return this._sourceMesh.isReady(!0)},t.prototype.getVerticesData=function(e,t){return this._sourceMesh.getVerticesData(e,t)},t.prototype.setVerticesData=function(e,t,i,r){return this.sourceMesh&&this.sourceMesh.setVerticesData(e,t,i,r),this.sourceMesh},t.prototype.updateVerticesData=function(e,t,i,r){return this.sourceMesh&&this.sourceMesh.updateVerticesData(e,t,i,r),this.sourceMesh},t.prototype.setIndices=function(e,t){return void 0===t&&(t=null),this.sourceMesh&&this.sourceMesh.setIndices(e,t),this.sourceMesh},t.prototype.isVerticesDataPresent=function(e){return this._sourceMesh.isVerticesDataPresent(e)},t.prototype.getIndices=function(){return this._sourceMesh.getIndices()},Object.defineProperty(t.prototype,"_positions",{get:function(){return this._sourceMesh._positions},enumerable:!0,configurable:!0}),t.prototype.refreshBoundingInfo=function(){var e=this._sourceMesh.getBoundingInfo();return this._boundingInfo=new It.BoundingInfo(e.minimum.clone(),e.maximum.clone()),this._updateBoundingInfo(),this},t.prototype._preActivate=function(){return this._currentLOD&&this._currentLOD._preActivate(),this},t.prototype._activate=function(e){return this._currentLOD&&this._currentLOD._registerInstanceForRenderId(this,e),this},t.prototype.getLOD=function(e){if(!e)return this;var t=this.getBoundingInfo();return this._currentLOD=this.sourceMesh.getLOD(e,t.boundingSphere),this._currentLOD===this.sourceMesh?this:this._currentLOD},t.prototype._syncSubMeshes=function(){if(this.releaseSubMeshes(),this._sourceMesh.subMeshes)for(var e=0;e<this._sourceMesh.subMeshes.length;e++)this._sourceMesh.subMeshes[e].clone(this,this._sourceMesh);return this},t.prototype._generatePointsArray=function(){return this._sourceMesh._generatePointsArray()},t.prototype.clone=function(e,t,i){var r=this._sourceMesh.createInstance(e);if(It.Tools.DeepCopy(this,r,["name","subMeshes","uniqueId"],[]),this.refreshBoundingInfo(),t&&(r.parent=t),!i)for(var n=0;n<this.getScene().meshes.length;n++){var o=this.getScene().meshes[n];o.parent===this&&o.clone(o.name,r)}return r.computeWorldMatrix(!0),r},t.prototype.dispose=function(t){var i=this._sourceMesh.instances.indexOf(this);this._sourceMesh.instances.splice(i,1),e.prototype.dispose.call(this,t)},t}(It.AbstractMesh),It.InstancedMesh=wt,Dt=us||(us={}),Lt=function(e){function t(t,i,r,n,o,s,a){void 0===i&&(i=null),void 0===r&&(r=null);var h=e.call(this,t,i,r,n,o)||this;h.useVertexColor=s,h.useVertexAlpha=a,h.color=new Dt.Color3(1,1,1),h.alpha=1,n&&(h.color=n.color.clone(),h.alpha=n.alpha,h.useVertexColor=n.useVertexColor,h.useVertexAlpha=n.useVertexAlpha),h._intersectionThreshold=.1;var l={attributes:[Dt.VertexBuffer.PositionKind],uniforms:["world","viewProjection"],needAlphaBlending:!0,defines:[]};return!1===a&&(l.needAlphaBlending=!1),s?(l.defines.push("#define VERTEXCOLOR"),l.attributes.push(Dt.VertexBuffer.ColorKind)):l.uniforms.push("color"),h._colorShader=new Dt.ShaderMaterial("colorShader",h.getScene(),"color",l),h}return Y(t,e),Object.defineProperty(t.prototype,"intersectionThreshold",{get:function(){return this._intersectionThreshold},set:function(e){this._intersectionThreshold!==e&&(this._intersectionThreshold=e,this.geometry&&(this.geometry.boundingBias=new Dt.Vector2(0,e)))},enumerable:!0,configurable:!0}),t.prototype.getClassName=function(){return"LinesMesh"},Object.defineProperty(t.prototype,"material",{get:function(){return this._colorShader},set:function(e){},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"checkCollisions",{get:function(){return!1},enumerable:!0,configurable:!0}),t.prototype.createInstance=function(e){throw new Error("LinesMeshes do not support createInstance.")},t.prototype._bind=function(e,t,i){return this._geometry?(this._geometry._bind(this._colorShader.getEffect()),this.useVertexColor||this._colorShader.setColor4("color",this.color.toColor4(this.alpha)),this):this},t.prototype._draw=function(e,t,i){return this._geometry&&this._geometry.getVertexBuffers()&&this._geometry.getIndexBuffer()?(this.getScene().getEngine().drawElementsType(Dt.Material.LineListDrawMode,e.indexStart,e.indexCount),this):this},t.prototype.dispose=function(t){this._colorShader.dispose(),e.prototype.dispose.call(this,t)},t.prototype.clone=function(e,i,r){return new t(e,this.getScene(),i,this,r)},t}(Dt.Mesh),Dt.LinesMesh=Lt,Bt=us||(us={}),Nt=function(){function e(){}return e.updateSideOrientation=function(e){return e==Bt.Mesh.DOUBLESIDE?Bt.Mesh.DOUBLESIDE:void 0===e||null===e?Bt.Mesh.FRONTSIDE:e},e.CreateBox=function(t,i,r){void 0===r&&(r=null);var n=new Bt.Mesh(t,r);return i.sideOrientation=e.updateSideOrientation(i.sideOrientation),n._originalBuilderSideOrientation=i.sideOrientation,Bt.VertexData.CreateBox(i).applyToMesh(n,i.updatable),n},e.CreateSphere=function(t,i,r){var n=new Bt.Mesh(t,r);return i.sideOrientation=e.updateSideOrientation(i.sideOrientation),n._originalBuilderSideOrientation=i.sideOrientation,Bt.VertexData.CreateSphere(i).applyToMesh(n,i.updatable),n},e.CreateDisc=function(t,i,r){void 0===r&&(r=null);var n=new Bt.Mesh(t,r);return i.sideOrientation=e.updateSideOrientation(i.sideOrientation),n._originalBuilderSideOrientation=i.sideOrientation,Bt.VertexData.CreateDisc(i).applyToMesh(n,i.updatable),n},e.CreateIcoSphere=function(t,i,r){var n=new Bt.Mesh(t,r);return i.sideOrientation=e.updateSideOrientation(i.sideOrientation),n._originalBuilderSideOrientation=i.sideOrientation,Bt.VertexData.CreateIcoSphere(i).applyToMesh(n,i.updatable),n},e.CreateRibbon=function(t,i,r){void 0===r&&(r=null);var n=i.pathArray,o=i.closeArray,s=i.closePath,a=e.updateSideOrientation(i.sideOrientation),h=i.instance,l=i.updatable;if(h){Bt.Vector3.FromFloatsToRef(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE,Bt.Tmp.Vector3[0]),Bt.Vector3.FromFloatsToRef(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE,Bt.Tmp.Vector3[1]);var c=h.getVerticesData(Bt.VertexBuffer.PositionKind);if(function(e){for(var t=n[0].length,i=0,r=h._originalBuilderSideOrientation===Bt.Mesh.DOUBLESIDE?2:1,o=1;o<=r;o++)for(var s=0;s<n.length;s++){var a=n[s],l=a.length;t=t<l?t:l;for(var c=0;c<t;)e[i]=a[c].x,e[i+1]=a[c].y,e[i+2]=a[c].z,a[c].x<Bt.Tmp.Vector3[0].x&&(Bt.Tmp.Vector3[0].x=a[c].x),a[c].x>Bt.Tmp.Vector3[1].x&&(Bt.Tmp.Vector3[1].x=a[c].x),a[c].y<Bt.Tmp.Vector3[0].y&&(Bt.Tmp.Vector3[0].y=a[c].y),a[c].y>Bt.Tmp.Vector3[1].y&&(Bt.Tmp.Vector3[1].y=a[c].y),a[c].z<Bt.Tmp.Vector3[0].z&&(Bt.Tmp.Vector3[0].z=a[c].z),a[c].z>Bt.Tmp.Vector3[1].z&&(Bt.Tmp.Vector3[1].z=a[c].z),c++,i+=3;h._closePath&&(e[i]=a[0].x,e[i+1]=a[0].y,e[i+2]=a[0].z,i+=3)}}(c),h._boundingInfo=new Bt.BoundingInfo(Bt.Tmp.Vector3[0],Bt.Tmp.Vector3[1]),h._boundingInfo.update(h._worldMatrix),h.updateVerticesData(Bt.VertexBuffer.PositionKind,c,!1,!1),i.colors){for(var u=h.getVerticesData(Bt.VertexBuffer.ColorKind),p=0;p<i.colors.length;p++)u[4*p]=i.colors[p].r,u[4*p+1]=i.colors[p].g,u[4*p+2]=i.colors[p].b,u[4*p+3]=i.colors[p].a;h.updateVerticesData(Bt.VertexBuffer.ColorKind,u,!1,!1)}if(i.uvs){for(var f=h.getVerticesData(Bt.VertexBuffer.UVKind),d=0;d<i.uvs.length;d++)f[2*d]=i.uvs[d].x,f[2*d+1]=i.uvs[d].y;h.updateVerticesData(Bt.VertexBuffer.UVKind,f,!1,!1)}if(!h.areNormalsFrozen||h.isFacetDataEnabled){var m=h.getIndices(),g=h.getVerticesData(Bt.VertexBuffer.NormalKind),_=h.isFacetDataEnabled?h.getFacetDataParameters():null;if(Bt.VertexData.ComputeNormals(c,m,g,_),h._closePath)for(var v=0,y=0,b=0;b<n.length;b++)v=3*h._idx[b],y=b+1<n.length?3*(h._idx[b+1]-1):g.length-3,g[v]=.5*(g[v]+g[y]),g[v+1]=.5*(g[v+1]+g[y+1]),g[v+2]=.5*(g[v+2]+g[y+2]),g[y]=g[v],g[y+1]=g[v+1],g[y+2]=g[v+2];h.areNormalsFrozen||h.updateVerticesData(Bt.VertexBuffer.NormalKind,g,!1,!1)}return h}var x=new Bt.Mesh(t,r);x._originalBuilderSideOrientation=a;var T=Bt.VertexData.CreateRibbon(i);return s&&(x._idx=T._idx),x._closePath=s,x._closeArray=o,T.applyToMesh(x,l),x},e.CreateCylinder=function(t,i,r){var n=new Bt.Mesh(t,r);return i.sideOrientation=e.updateSideOrientation(i.sideOrientation),n._originalBuilderSideOrientation=i.sideOrientation,Bt.VertexData.CreateCylinder(i).applyToMesh(n,i.updatable),n},e.CreateTorus=function(t,i,r){var n=new Bt.Mesh(t,r);return i.sideOrientation=e.updateSideOrientation(i.sideOrientation),n._originalBuilderSideOrientation=i.sideOrientation,Bt.VertexData.CreateTorus(i).applyToMesh(n,i.updatable),n},e.CreateTorusKnot=function(t,i,r){var n=new Bt.Mesh(t,r);return i.sideOrientation=e.updateSideOrientation(i.sideOrientation),n._originalBuilderSideOrientation=i.sideOrientation,Bt.VertexData.CreateTorusKnot(i).applyToMesh(n,i.updatable),n},e.CreateLineSystem=function(e,t,i){var r=t.instance,n=t.lines,o=t.colors;if(r){var s,a,h=r.getVerticesData(Bt.VertexBuffer.PositionKind);o&&(s=r.getVerticesData(Bt.VertexBuffer.ColorKind));for(var l=0,c=0,u=0;u<n.length;u++)for(var p=n[u],f=0;f<p.length;f++)h[l]=p[f].x,h[l+1]=p[f].y,h[l+2]=p[f].z,o&&s&&(a=o[u],s[c]=a[f].r,s[c+1]=a[f].g,s[c+2]=a[f].b,s[c+3]=a[f].a,c+=4),l+=3;return r.updateVerticesData(Bt.VertexBuffer.PositionKind,h,!1,!1),o&&s&&r.updateVerticesData(Bt.VertexBuffer.ColorKind,s,!1,!1),r}var d=!!o,m=new Bt.LinesMesh(e,i,null,void 0,void 0,d,t.useVertexAlpha);return Bt.VertexData.CreateLineSystem(t).applyToMesh(m,t.updatable),m},e.CreateLines=function(t,i,r){void 0===r&&(r=null);var n=i.colors?[i.colors]:null;return e.CreateLineSystem(t,{lines:[i.points],updatable:i.updatable,instance:i.instance,colors:n,useVertexAlpha:i.useVertexAlpha},r)},e.CreateDashedLines=function(e,t,i){void 0===i&&(i=null);var r=t.points,n=t.instance,o=t.gapSize||1,s=t.dashSize||3;if(n){return n.updateMeshPositions(function(e){var t,i,o=Bt.Vector3.Zero(),s=e.length/6,a=0,h=0,l=0,c=0,u=0,p=0;for(u=0;u<r.length-1;u++)r[u+1].subtractToRef(r[u],o),a+=o.length();for(t=a/s,i=n.dashSize*t/(n.dashSize+n.gapSize),u=0;u<r.length-1;u++)for(r[u+1].subtractToRef(r[u],o),h=Math.floor(o.length()/t),o.normalize(),p=0;p<h&&c<e.length;)l=t*p,e[c]=r[u].x+l*o.x,e[c+1]=r[u].y+l*o.y,e[c+2]=r[u].z+l*o.z,e[c+3]=r[u].x+(l+i)*o.x,e[c+4]=r[u].y+(l+i)*o.y,e[c+5]=r[u].z+(l+i)*o.z,c+=6,p++;for(;c<e.length;)e[c]=r[u].x,e[c+1]=r[u].y,e[c+2]=r[u].z,c+=3},!1),n}var a=new Bt.LinesMesh(e,i);return Bt.VertexData.CreateDashedLines(t).applyToMesh(a,t.updatable),a.dashSize=s,a.gapSize=o,a},e.ExtrudeShape=function(t,i,r){void 0===r&&(r=null);var n=i.path,o=i.shape,s=i.scale||1,a=i.rotation||0,h=0===i.cap?0:i.cap||Bt.Mesh.NO_CAP,l=i.updatable,c=e.updateSideOrientation(i.sideOrientation),u=i.instance||null,p=i.invertUV||!1;return e._ExtrudeShapeGeneric(t,o,n,s,a,null,null,!1,!1,h,!1,r,!!l,c,u,p,i.frontUVs||null,i.backUVs||null)},e.ExtrudeShapeCustom=function(t,i,r){var n=i.path,o=i.shape,s=i.scaleFunction||function(){return 1},a=i.rotationFunction||function(){return 0},h=i.ribbonCloseArray||!1,l=i.ribbonClosePath||!1,c=0===i.cap?0:i.cap||Bt.Mesh.NO_CAP,u=i.updatable,p=e.updateSideOrientation(i.sideOrientation),f=i.instance,d=i.invertUV||!1;return e._ExtrudeShapeGeneric(t,o,n,null,null,s,a,h,l,c,!0,r,!!u,p,f||null,d,i.frontUVs||null,i.backUVs||null)},e.CreateLathe=function(t,i,r){var n,o=i.arc?i.arc<=0||i.arc>1?1:i.arc:1,s=void 0===i.closed||i.closed,a=i.shape,h=i.radius||1,l=i.tessellation||64,c=i.updatable,u=e.updateSideOrientation(i.sideOrientation),p=i.cap||Bt.Mesh.NO_CAP,f=2*Math.PI,d=new Array,m=i.invertUV||!1,g=0,_=0,v=f/l*o,y=new Array;for(g=0;g<=l;g++){y=[];for(p!=Bt.Mesh.CAP_START&&p!=Bt.Mesh.CAP_ALL||(y.push(new Bt.Vector3(0,a[0].y,0)),y.push(new Bt.Vector3(Math.cos(g*v)*a[0].x*h,a[0].y,Math.sin(g*v)*a[0].x*h))),_=0;_<a.length;_++)n=new Bt.Vector3(Math.cos(g*v)*a[_].x*h,a[_].y,Math.sin(g*v)*a[_].x*h),y.push(n);p!=Bt.Mesh.CAP_END&&p!=Bt.Mesh.CAP_ALL||(y.push(new Bt.Vector3(Math.cos(g*v)*a[a.length-1].x*h,a[a.length-1].y,Math.sin(g*v)*a[a.length-1].x*h)),y.push(new Bt.Vector3(0,a[a.length-1].y,0))),d.push(y)}return e.CreateRibbon(t,{pathArray:d,closeArray:s,sideOrientation:u,updatable:c,invertUV:m,frontUVs:i.frontUVs,backUVs:i.backUVs},r)},e.CreatePlane=function(t,i,r){var n=new Bt.Mesh(t,r);if(i.sideOrientation=e.updateSideOrientation(i.sideOrientation),n._originalBuilderSideOrientation=i.sideOrientation,Bt.VertexData.CreatePlane(i).applyToMesh(n,i.updatable),i.sourcePlane){n.translate(i.sourcePlane.normal,i.sourcePlane.d);var o=Math.acos(Bt.Vector3.Dot(i.sourcePlane.normal,Bt.Axis.Z)),s=Bt.Vector3.Cross(Bt.Axis.Z,i.sourcePlane.normal);n.rotate(s,o)}return n},e.CreateGround=function(e,t,i){var r=new Bt.GroundMesh(e,i);return r._setReady(!1),r._subdivisionsX=t.subdivisionsX||t.subdivisions||1,r._subdivisionsY=t.subdivisionsY||t.subdivisions||1,r._width=t.width||1,r._height=t.height||1,r._maxX=r._width/2,r._maxZ=r._height/2,r._minX=-r._maxX,r._minZ=-r._maxZ,Bt.VertexData.CreateGround(t).applyToMesh(r,t.updatable),r._setReady(!0),r},e.CreateTiledGround=function(e,t,i){var r=new Bt.Mesh(e,i);return Bt.VertexData.CreateTiledGround(t).applyToMesh(r,t.updatable),r},e.CreateGroundFromHeightMap=function(e,t,i,r){var n=i.width||10,o=i.height||10,s=i.subdivisions||1,a=i.minHeight||0,h=i.maxHeight||1,l=i.colorFilter||new Bt.Color3(.3,.59,.11),c=i.updatable,u=i.onReady,p=new Bt.GroundMesh(e,r);p._subdivisionsX=s,p._subdivisionsY=s,p._width=n,p._height=o,p._maxX=p._width/2,p._maxZ=p._height/2,p._minX=-p._maxX,p._minZ=-p._maxZ,p._setReady(!1);return Bt.Tools.LoadImage(t,function(e){var t=document.createElement("canvas"),i=t.getContext("2d");if(!i)throw new Error("Unable to get 2d context for CreateGroundFromHeightMap");if(!r.isDisposed){var f=e.width,d=e.height;t.width=f,t.height=d,i.drawImage(e,0,0);var m=i.getImageData(0,0,f,d).data;Bt.VertexData.CreateGroundFromHeightMap({width:n,height:o,subdivisions:s,minHeight:a,maxHeight:h,colorFilter:l,buffer:m,bufferWidth:f,bufferHeight:d}).applyToMesh(p,c),p._setReady(!0),u&&u(p)}},function(){},r.database),p},e.CreatePolygon=function(t,i,r){i.sideOrientation=e.updateSideOrientation(i.sideOrientation);for(var n=i.shape,o=i.holes||[],s=i.depth||0,a=[],h=[],l=0;l<n.length;l++)a[l]=new Bt.Vector2(n[l].x,n[l].z);a[0].equalsWithEpsilon(a[a.length-1],1e-8)&&a.pop();for(var c=new Bt.PolygonMeshBuilder(t,a,r),u=0;u<o.length;u++){h=[];for(var p=0;p<o[u].length;p++)h.push(new Bt.Vector2(o[u][p].x,o[u][p].z));c.addHole(h)}var f=c.build(i.updatable,s);return f._originalBuilderSideOrientation=i.sideOrientation,Bt.VertexData.CreatePolygon(f,i.sideOrientation,i.faceUV,i.faceColors,i.frontUVs,i.backUVs).applyToMesh(f,i.updatable),f},e.ExtrudePolygon=function(t,i,r){return e.CreatePolygon(t,i,r)},e.CreateTube=function(t,i,r){var n=i.path,o=i.instance,s=1;o&&(s=o.radius),void 0!==i.radius&&(s=i.radius);var a=i.tessellation||64,h=i.radiusFunction||null,l=i.cap||Bt.Mesh.NO_CAP,c=i.invertUV||!1,u=i.updatable,p=e.updateSideOrientation(i.sideOrientation);i.arc=i.arc&&(i.arc<=0||i.arc>1)?1:i.arc||1;var f,d,m=function(e,t,i,r,n,o,s,a){for(var h,l,c,u,p=t.getTangents(),f=t.getNormals(),d=t.getDistances(),m=2*Math.PI/n*a,g=o||function(){return r},_=Bt.Tmp.Matrix[0],v=s===Bt.Mesh._NO_CAP||s===Bt.Mesh.CAP_END?0:2,y=0;y<e.length;y++){l=g(y,d[y]),h=Array(),c=f[y];for(var b=0;b<n;b++)Bt.Matrix.RotationAxisToRef(p[y],m*b,_),u=h[b]?h[b]:Bt.Vector3.Zero(),Bt.Vector3.TransformCoordinatesToRef(c,_,u),u.scaleInPlace(l).addInPlace(e[y]),h[b]=u;i[v]=h,v++}var x=function(t,i){for(var r=Array(),n=0;n<t;n++)r.push(e[i]);return r};switch(s){case Bt.Mesh.NO_CAP:break;case Bt.Mesh.CAP_START:i[0]=x(n,0),i[1]=i[2].slice(0);break;case Bt.Mesh.CAP_END:i[v]=i[v-1].slice(0),i[v+1]=x(n,e.length-1);break;case Bt.Mesh.CAP_ALL:i[0]=x(n,0),i[1]=i[2].slice(0),i[v]=i[v-1].slice(0),i[v+1]=x(n,e.length-1)}return i};if(o){var g=i.arc||o.arc;return d=m(n,f=o.path3D.update(n),o.pathArray,s,o.tessellation,h,o.cap,g),(o=e.CreateRibbon("",{pathArray:d,instance:o})).path3D=f,o.pathArray=d,o.arc=g,o.radius=s,o}d=m(n,f=new Bt.Path3D(n),new Array,s,a,h,l=l<0||l>3?0:l,i.arc);var _=e.CreateRibbon(t,{pathArray:d,closePath:!0,closeArray:!1,updatable:u,sideOrientation:p,invertUV:c,frontUVs:i.frontUVs,backUVs:i.backUVs},r);return _.pathArray=d,_.path3D=f,_.tessellation=a,_.cap=l,_.arc=i.arc,_.radius=s,_},e.CreatePolyhedron=function(t,i,r){var n=new Bt.Mesh(t,r);return i.sideOrientation=e.updateSideOrientation(i.sideOrientation),n._originalBuilderSideOrientation=i.sideOrientation,Bt.VertexData.CreatePolyhedron(i).applyToMesh(n,i.updatable),n},e.CreateDecal=function(e,t,i){var r=t.getIndices(),n=t.getVerticesData(Bt.VertexBuffer.PositionKind),o=t.getVerticesData(Bt.VertexBuffer.NormalKind),s=i.position||Bt.Vector3.Zero(),a=i.normal||Bt.Vector3.Up(),h=i.size||Bt.Vector3.One(),l=i.angle||0;if(!a){var c=new Bt.Vector3(0,0,1),u=t.getScene().activeCamera,p=Bt.Vector3.TransformCoordinates(c,u.getWorldMatrix());a=u.globalPosition.subtract(p)}var f=-Math.atan2(a.z,a.x)-Math.PI/2,d=Math.sqrt(a.x*a.x+a.z*a.z),m=Math.atan2(a.y,d),g=Bt.Matrix.RotationYawPitchRoll(f,m,l).multiply(Bt.Matrix.Translation(s.x,s.y,s.z)),_=Bt.Matrix.Invert(g),v=t.getWorldMatrix().multiply(_),y=new Bt.VertexData;y.indices=[],y.positions=[],y.normals=[],y.uvs=[];for(var b=0,x=function(e){var t=new Bt.PositionNormalVertex;if(!r||!n||!o)return t;var i=r[e];return t.position=new Bt.Vector3(n[3*i],n[3*i+1],n[3*i+2]),t.position=Bt.Vector3.TransformCoordinates(t.position,v),t.normal=new Bt.Vector3(o[3*i],o[3*i+1],o[3*i+2]),t.normal=Bt.Vector3.TransformNormal(t.normal,v),t},T=function(e,t){if(0===e.length)return e;for(var i=.5*Math.abs(Bt.Vector3.Dot(h,t)),r=function(e,r){var n=Bt.Vector3.GetClipFactor(e.position,r.position,t,i);return new Bt.PositionNormalVertex(Bt.Vector3.Lerp(e.position,r.position,n),Bt.Vector3.Lerp(e.normal,r.normal,n))},n=new Array,o=0;o<e.length;o+=3){var s,a,l,c=null,u=null,p=null,f=null,d=Bt.Vector3.Dot(e[o].position,t)-i;switch(a=Bt.Vector3.Dot(e[o+1].position,t)-i>0,l=Bt.Vector3.Dot(e[o+2].position,t)-i>0,((s=d>0)?1:0)+(a?1:0)+(l?1:0)){case 0:n.push(e[o]),n.push(e[o+1]),n.push(e[o+2]);break;case 1:if(s&&(c=e[o+1],u=e[o+2],p=r(e[o],c),f=r(e[o],u)),a){c=e[o],u=e[o+2],p=r(e[o+1],c),f=r(e[o+1],u),n.push(p),n.push(u.clone()),n.push(c.clone()),n.push(u.clone()),n.push(p.clone()),n.push(f);break}l&&(c=e[o],u=e[o+1],p=r(e[o+2],c),f=r(e[o+2],u)),c&&u&&p&&f&&(n.push(c.clone()),n.push(u.clone()),n.push(p),n.push(f),n.push(p.clone()),n.push(u.clone()));break;case 2:s||(u=r(c=e[o].clone(),e[o+1]),p=r(c,e[o+2]),n.push(c),n.push(u),n.push(p)),a||(u=r(c=e[o+1].clone(),e[o+2]),p=r(c,e[o]),n.push(c),n.push(u),n.push(p)),l||(u=r(c=e[o+2].clone(),e[o]),p=r(c,e[o+1]),n.push(c),n.push(u),n.push(p))}}return n},E=0;E<r.length;E+=3){var A=new Array;if(A.push(x(E)),A.push(x(E+1)),A.push(x(E+2)),0!==(A=T(A=T(A=T(A=T(A=T(A=T(A,new Bt.Vector3(1,0,0)),new Bt.Vector3(-1,0,0)),new Bt.Vector3(0,1,0)),new Bt.Vector3(0,-1,0)),new Bt.Vector3(0,0,1)),new Bt.Vector3(0,0,-1))).length)for(var P=0;P<A.length;P++){var M=A[P];y.indices.push(b),M.position.toArray(y.positions,3*b),M.normal.toArray(y.normals,3*b),y.uvs.push(.5+M.position.x/h.x),y.uvs.push(.5+M.position.y/h.y),b++}}var S=new Bt.Mesh(e,t.getScene());return y.applyToMesh(S),S.position=s.clone(),S.rotation=new Bt.Vector3(m,f,l),S},e._ExtrudeShapeGeneric=function(t,i,r,n,o,s,a,h,l,c,u,p,f,d,m,g,_,v){var y,b,x=function(e,t,i,r,n,o,s,a,h,l){for(var c=i.getTangents(),u=i.getNormals(),p=i.getBinormals(),f=i.getDistances(),d=0,m=l&&a?a:function(){return null!==o?o:0},g=l&&s?s:function(){return null!==n?n:1},_=h===Bt.Mesh.NO_CAP||h===Bt.Mesh.CAP_END?0:2,v=Bt.Tmp.Matrix[0],y=0;y<t.length;y++){for(var b=new Array,x=m(y,f[y]),T=g(y,f[y]),E=0;E<e.length;E++){Bt.Matrix.RotationAxisToRef(c[y],d,v);var A=c[y].scale(e[E].z).add(u[y].scale(e[E].x)).add(p[y].scale(e[E].y)),P=b[E]?b[E]:Bt.Vector3.Zero();Bt.Vector3.TransformCoordinatesToRef(A,v,P),P.scaleInPlace(T).addInPlace(t[y]),b[E]=P}r[_]=b,d+=x,_++}var M=function(e){var t,i=Array(),r=Bt.Vector3.Zero();for(t=0;t<e.length;t++)r.addInPlace(e[t]);for(r.scaleInPlace(1/e.length),t=0;t<e.length;t++)i.push(r);return i};switch(h){case Bt.Mesh.NO_CAP:break;case Bt.Mesh.CAP_START:r[0]=M(r[2]),r[1]=r[2];break;case Bt.Mesh.CAP_END:r[_]=r[_-1],r[_+1]=M(r[_-1]);break;case Bt.Mesh.CAP_ALL:r[0]=M(r[2]),r[1]=r[2],r[_]=r[_-1],r[_+1]=M(r[_-1])}return r};if(m)return y=m.path3D.update(r),b=x(i,r,m.path3D,m.pathArray,n,o,s,a,m.cap,u),m=Bt.Mesh.CreateRibbon("",b,!1,!1,0,p||void 0,!1,0,m);b=x(i,r,y=new Bt.Path3D(r),new Array,n,o,s,a,c=c<0||c>3?0:c,u);var T=e.CreateRibbon(t,{pathArray:b,closeArray:h,closePath:l,updatable:f,sideOrientation:d,invertUV:g,frontUVs:_||void 0,backUVs:v||void 0},p);return T.pathArray=b,T.path3D=y,T.cap=c,T},e}(),Bt.MeshBuilder=Nt,Ft=us||(us={}),Vt=function(){function e(){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(e.prototype,"audioContext",{get:function(){return this._audioContextInitialized||this._initializeAudioContext(),this._audioContext},enumerable:!0,configurable:!0}),e.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)},e.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(e){this.canUseWebAudio=!1,Ft.Tools.Error("Web Audio: "+e.message)}},e.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},e.prototype.getGlobalVolume=function(){return this.canUseWebAudio&&this._audioContextInitialized?this.masterGain.gain.value:-1},e.prototype.setGlobalVolume=function(e){this.canUseWebAudio&&this._audioContextInitialized&&(this.masterGain.gain.value=e)},e.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))},e}(),Ft.AudioEngine=Vt,kt=us||(us={}),Ut=function(){function e(e,t,i,r,n){void 0===r&&(r=null);var o=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=kt.Vector3.Zero(),this._localDirection=new kt.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=e,this._scene=i,this._readyToPlayCallback=r,this._customAttenuationFunction=function(e,t,i,r,n){return t<i?e*(1-t/i):0},n&&(this.autoplay=n.autoplay||!1,this.loop=n.loop||!1,void 0!==n.volume&&(this._volume=n.volume),this.spatialSound=n.spatialSound||!1,this.maxDistance=n.maxDistance||100,this.useCustomAttenuation=n.useCustomAttenuation||!1,this.rolloffFactor=n.rolloffFactor||1,this.refDistance=n.refDistance||1,this.distanceModel=n.distanceModel||"linear",this._playbackRate=n.playbackRate||1,this._streaming=n.streaming||!1),kt.Engine.audioEngine.canUseWebAudio&&kt.Engine.audioEngine.audioContext){this._soundGain=kt.Engine.audioEngine.audioContext.createGain(),this._soundGain.gain.value=this._volume,this._inputAudioNode=this._soundGain,this._ouputAudioNode=this._soundGain,this.spatialSound&&this._createSpatialParameters(),this._scene.mainSoundTrack.AddSound(this);var s=!0;if(t){"string"==typeof t&&(this._urlType="String"),Array.isArray(t)&&(this._urlType="Array"),t instanceof ArrayBuffer&&(this._urlType="ArrayBuffer");var a=[],h=!1;switch(this._urlType){case"ArrayBuffer":t.byteLength>0&&(h=!0,this._soundLoaded(t));break;case"String":a.push(t);case"Array":0===a.length&&(a=t);for(var l=0;l<a.length;l++){var c=a[l];if(-1!==c.indexOf(".mp3",c.length-4)&&kt.Engine.audioEngine.isMP3supported&&(h=!0),-1!==c.indexOf(".ogg",c.length-4)&&kt.Engine.audioEngine.isOGGsupported&&(h=!0),-1!==c.indexOf(".wav",c.length-4)&&(h=!0),-1!==c.indexOf("blob:")&&(h=!0),h){this._streaming?(this._htmlAudioElement=new Audio(c),this._htmlAudioElement.controls=!1,this._htmlAudioElement.loop=this.loop,kt.Tools.SetCorsBehavior(c,this._htmlAudioElement),this._htmlAudioElement.preload="auto",this._htmlAudioElement.addEventListener("canplaythrough",function(){o._isReadyToPlay=!0,o.autoplay&&o.play(),o._readyToPlayCallback&&o._readyToPlayCallback()}),document.body.appendChild(this._htmlAudioElement)):this._scene._loadFile(c,function(e){o._soundLoaded(e)},void 0,!0,!0);break}}break;default:s=!1}s?h||(this._isReadyToPlay=!0,this._readyToPlayCallback&&window.setTimeout(function(){o._readyToPlayCallback&&o._readyToPlayCallback()},1e3)):kt.Tools.Error("Parameter must be a URL to the sound, an Array of URLs (.mp3 & .ogg) or an ArrayBuffer of the sound.")}}else this._scene.mainSoundTrack.AddSound(this),kt.Engine.audioEngine.WarnedWebAudioUnsupported||(kt.Tools.Error("Web Audio is not supported by your browser."),kt.Engine.audioEngine.WarnedWebAudioUnsupported=!0),this._readyToPlayCallback&&window.setTimeout(function(){o._readyToPlayCallback&&o._readyToPlayCallback()},1e3)}return e.prototype.dispose=function(){kt.Engine.audioEngine.canUseWebAudio&&this._isReadyToPlay&&(this.isPlaying&&this.stop(),this._isReadyToPlay=!1,-1===this.soundTrackId?this._scene.mainSoundTrack.RemoveSound(this):this._scene.soundTracks[this.soundTrackId].RemoveSound(this),this._soundGain&&(this._soundGain.disconnect(),this._soundGain=null),this._soundPanner&&(this._soundPanner.disconnect(),this._soundPanner=null),this._soundSource&&(this._soundSource.disconnect(),this._soundSource=null),this._audioBuffer=null,this._htmlAudioElement&&(this._htmlAudioElement.pause(),this._htmlAudioElement.src="",document.body.removeChild(this._htmlAudioElement)),this._connectedMesh&&this._registerFunc&&(this._connectedMesh.unregisterAfterWorldMatrixUpdate(this._registerFunc),this._connectedMesh=null))},e.prototype.isReady=function(){return this._isReadyToPlay},e.prototype._soundLoaded=function(e){var t=this;kt.Engine.audioEngine.audioContext&&kt.Engine.audioEngine.audioContext.decodeAudioData(e,function(e){t._audioBuffer=e,t._isReadyToPlay=!0,t.autoplay&&t.play(),t._readyToPlayCallback&&t._readyToPlayCallback()},function(e){kt.Tools.Error("Error while decoding audio data for: "+t.name+" / Error: "+e)})},e.prototype.setAudioBuffer=function(e){kt.Engine.audioEngine.canUseWebAudio&&(this._audioBuffer=e,this._isReadyToPlay=!0)},e.prototype.updateOptions=function(e){e&&(this.loop=e.loop||this.loop,this.maxDistance=e.maxDistance||this.maxDistance,this.useCustomAttenuation=e.useCustomAttenuation||this.useCustomAttenuation,this.rolloffFactor=e.rolloffFactor||this.rolloffFactor,this.refDistance=e.refDistance||this.refDistance,this.distanceModel=e.distanceModel||this.distanceModel,this._playbackRate=e.playbackRate||this._playbackRate,this._updateSpatialParameters(),this.isPlaying&&(this._streaming?this._htmlAudioElement.playbackRate=this._playbackRate:this._soundSource&&(this._soundSource.playbackRate.value=this._playbackRate)))},e.prototype._createSpatialParameters=function(){kt.Engine.audioEngine.canUseWebAudio&&kt.Engine.audioEngine.audioContext&&(this._scene.headphone&&(this._panningModel="HRTF"),this._soundPanner=kt.Engine.audioEngine.audioContext.createPanner(),this._updateSpatialParameters(),this._soundPanner.connect(this._ouputAudioNode),this._inputAudioNode=this._soundPanner)},e.prototype._updateSpatialParameters=function(){this.spatialSound&&this._soundPanner&&(this.useCustomAttenuation?(this._soundPanner.distanceModel="linear",this._soundPanner.maxDistance=Number.MAX_VALUE,this._soundPanner.refDistance=1,this._soundPanner.rolloffFactor=1,this._soundPanner.panningModel=this._panningModel):(this._soundPanner.distanceModel=this.distanceModel,this._soundPanner.maxDistance=this.maxDistance,this._soundPanner.refDistance=this.refDistance,this._soundPanner.rolloffFactor=this.rolloffFactor,this._soundPanner.panningModel=this._panningModel))},e.prototype.switchPanningModelToHRTF=function(){this._panningModel="HRTF",this._switchPanningModel()},e.prototype.switchPanningModelToEqualPower=function(){this._panningModel="equalpower",this._switchPanningModel()},e.prototype._switchPanningModel=function(){kt.Engine.audioEngine.canUseWebAudio&&this.spatialSound&&this._soundPanner&&(this._soundPanner.panningModel=this._panningModel)},e.prototype.connectToSoundTrackAudioNode=function(e){kt.Engine.audioEngine.canUseWebAudio&&(this._isOutputConnected&&this._ouputAudioNode.disconnect(),this._ouputAudioNode.connect(e),this._isOutputConnected=!0)},e.prototype.setDirectionalCone=function(e,t,i){t<e?kt.Tools.Error("setDirectionalCone(): outer angle of the cone must be superior or equal to the inner angle."):(this._coneInnerAngle=e,this._coneOuterAngle=t,this._coneOuterGain=i,this._isDirectional=!0,this.isPlaying&&this.loop&&(this.stop(),this.play()))},e.prototype.setPosition=function(e){this._position=e,kt.Engine.audioEngine.canUseWebAudio&&this.spatialSound&&this._soundPanner&&this._soundPanner.setPosition(this._position.x,this._position.y,this._position.z)},e.prototype.setLocalDirectionToMesh=function(e){this._localDirection=e,kt.Engine.audioEngine.canUseWebAudio&&this._connectedMesh&&this.isPlaying&&this._updateDirection()},e.prototype._updateDirection=function(){if(this._connectedMesh&&this._soundPanner){var e=this._connectedMesh.getWorldMatrix(),t=kt.Vector3.TransformNormal(this._localDirection,e);t.normalize(),this._soundPanner.setOrientation(t.x,t.y,t.z)}},e.prototype.updateDistanceFromListener=function(){if(kt.Engine.audioEngine.canUseWebAudio&&this._connectedMesh&&this.useCustomAttenuation&&this._soundGain&&this._scene.activeCamera){var e=this._connectedMesh.getDistanceToCamera(this._scene.activeCamera);this._soundGain.gain.value=this._customAttenuationFunction(this._volume,e,this.maxDistance,this.refDistance,this.rolloffFactor)}},e.prototype.setAttenuationFunction=function(e){this._customAttenuationFunction=e},e.prototype.play=function(e,t){var i=this;if(this._isReadyToPlay&&this._scene.audioEnabled&&kt.Engine.audioEngine.audioContext)try{this._startOffset<0&&(e=-this._startOffset,this._startOffset=0);var r=e?kt.Engine.audioEngine.audioContext.currentTime+e:kt.Engine.audioEngine.audioContext.currentTime;this._soundSource&&this._streamingSource||this.spatialSound&&this._soundPanner&&(this._soundPanner.setPosition(this._position.x,this._position.y,this._position.z),this._isDirectional&&(this._soundPanner.coneInnerAngle=this._coneInnerAngle,this._soundPanner.coneOuterAngle=this._coneOuterAngle,this._soundPanner.coneOuterGain=this._coneOuterGain,this._connectedMesh?this._updateDirection():this._soundPanner.setOrientation(this._localDirection.x,this._localDirection.y,this._localDirection.z))),this._streaming?(this._streamingSource||(this._streamingSource=kt.Engine.audioEngine.audioContext.createMediaElementSource(this._htmlAudioElement),this._htmlAudioElement.onended=function(){i._onended()},this._htmlAudioElement.playbackRate=this._playbackRate),this._streamingSource.disconnect(),this._streamingSource.connect(this._inputAudioNode),this._htmlAudioElement.play()):(this._soundSource=kt.Engine.audioEngine.audioContext.createBufferSource(),this._soundSource.buffer=this._audioBuffer,this._soundSource.connect(this._inputAudioNode),this._soundSource.loop=this.loop,this._soundSource.playbackRate.value=this._playbackRate,this._soundSource.onended=function(){i._onended()},this._soundSource.buffer&&this._soundSource.start(r,this.isPaused?this._startOffset%this._soundSource.buffer.duration:t||0)),this._startTime=r,this.isPlaying=!0,this.isPaused=!1}catch(e){kt.Tools.Error("Error while trying to play audio: "+this.name+", "+e.message)}},e.prototype._onended=function(){this.isPlaying=!1,this.onended&&this.onended()},e.prototype.stop=function(e){if(this.isPlaying){if(this._streaming)this._htmlAudioElement.pause(),this._htmlAudioElement.currentTime>0&&(this._htmlAudioElement.currentTime=0);else if(kt.Engine.audioEngine.audioContext&&this._soundSource){var t=e?kt.Engine.audioEngine.audioContext.currentTime+e:kt.Engine.audioEngine.audioContext.currentTime;this._soundSource.stop(t),this._soundSource.onended=function(){},this.isPaused||(this._startOffset=0)}this.isPlaying=!1}},e.prototype.pause=function(){this.isPlaying&&(this.isPaused=!0,this._streaming?this._htmlAudioElement.pause():kt.Engine.audioEngine.audioContext&&(this.stop(0),this._startOffset+=kt.Engine.audioEngine.audioContext.currentTime-this._startTime))},e.prototype.setVolume=function(e,t){kt.Engine.audioEngine.canUseWebAudio&&this._soundGain&&(t&&kt.Engine.audioEngine.audioContext?(this._soundGain.gain.cancelScheduledValues(kt.Engine.audioEngine.audioContext.currentTime),this._soundGain.gain.setValueAtTime(this._soundGain.gain.value,kt.Engine.audioEngine.audioContext.currentTime),this._soundGain.gain.linearRampToValueAtTime(e,kt.Engine.audioEngine.audioContext.currentTime+t)):this._soundGain.gain.value=e),this._volume=e},e.prototype.setPlaybackRate=function(e){this._playbackRate=e,this.isPlaying&&(this._streaming?this._htmlAudioElement.playbackRate=this._playbackRate:this._soundSource&&(this._soundSource.playbackRate.value=this._playbackRate))},e.prototype.getVolume=function(){return this._volume},e.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)},e.prototype.detachFromMesh=function(){this._connectedMesh&&this._registerFunc&&(this._connectedMesh.unregisterAfterWorldMatrixUpdate(this._registerFunc),this._registerFunc=null,this._connectedMesh=null)},e.prototype._onRegisterAfterWorldMatrixUpdate=function(e){if(e.getBoundingInfo){var t=e.getBoundingInfo();this.setPosition(t.boundingSphere.centerWorld),kt.Engine.audioEngine.canUseWebAudio&&this._isDirectional&&this.isPlaying&&this._updateDirection()}},e.prototype.clone=function(){var t=this;if(this._streaming)return null;var i=function(){t._isReadyToPlay?(n._audioBuffer=t.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 e(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},e.prototype.getAudioBuffer=function(){return this._audioBuffer},e.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},e.Parse=function(t,i,r,n){var o,s=t.name;o=t.url?r+t.url:r+s;var a,h={autoplay:t.autoplay,loop:t.loop,volume:t.volume,spatialSound:t.spatialSound,maxDistance:t.maxDistance,rolloffFactor:t.rolloffFactor,refDistance:t.refDistance,distanceModel:t.distanceModel,playbackRate:t.playbackRate};if(n){var l=function(){n._isReadyToPlay?(a._audioBuffer=n.getAudioBuffer(),a._isReadyToPlay=!0,a.autoplay&&a.play()):window.setTimeout(l,300)};a=new e(s,new ArrayBuffer(0),i,null,h),l()}else a=new e(s,o,i,function(){i._removePendingData(a)},h),i._addPendingData(a);if(t.position){var c=kt.Vector3.FromArray(t.position);a.setPosition(c)}if(t.isDirectional&&(a.setDirectionalCone(t.coneInnerAngle||360,t.coneOuterAngle||360,t.coneOuterGain||0),t.localDirectionToMesh)){var u=kt.Vector3.FromArray(t.localDirectionToMesh);a.setLocalDirectionToMesh(u)}if(t.connectedMeshId){var p=i.getMeshByID(t.connectedMeshId);p&&a.attachToMesh(p)}return a},e}(),kt.Sound=Ut,zt=us||(us={}),Gt=function(){function e(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 e.prototype._initializeSoundTrackAudioGraph=function(){zt.Engine.audioEngine.canUseWebAudio&&zt.Engine.audioEngine.audioContext&&(this._outputAudioNode=zt.Engine.audioEngine.audioContext.createGain(),this._outputAudioNode.connect(zt.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)},e.prototype.dispose=function(){if(zt.Engine.audioEngine.canUseWebAudio){for(this._connectedAnalyser&&this._connectedAnalyser.stopDebugCanvas();this.soundCollection.length;)this.soundCollection[0].dispose();this._outputAudioNode&&this._outputAudioNode.disconnect(),this._outputAudioNode=null}},e.prototype.AddSound=function(e){this._isInitialized||this._initializeSoundTrackAudioGraph(),zt.Engine.audioEngine.canUseWebAudio&&this._outputAudioNode&&e.connectToSoundTrackAudioNode(this._outputAudioNode),e.soundTrackId&&(-1===e.soundTrackId?this._scene.mainSoundTrack.RemoveSound(e):this._scene.soundTracks[e.soundTrackId].RemoveSound(e)),this.soundCollection.push(e),e.soundTrackId=this.id},e.prototype.RemoveSound=function(e){var t=this.soundCollection.indexOf(e);-1!==t&&this.soundCollection.splice(t,1)},e.prototype.setVolume=function(e){zt.Engine.audioEngine.canUseWebAudio&&this._outputAudioNode&&(this._outputAudioNode.gain.value=e)},e.prototype.switchPanningModelToHRTF=function(){if(zt.Engine.audioEngine.canUseWebAudio)for(var e=0;e<this.soundCollection.length;e++)this.soundCollection[e].switchPanningModelToHRTF()},e.prototype.switchPanningModelToEqualPower=function(){if(zt.Engine.audioEngine.canUseWebAudio)for(var e=0;e<this.soundCollection.length;e++)this.soundCollection[e].switchPanningModelToEqualPower()},e.prototype.connectToAnalyser=function(e){this._connectedAnalyser&&this._connectedAnalyser.stopDebugCanvas(),this._connectedAnalyser=e,zt.Engine.audioEngine.canUseWebAudio&&this._outputAudioNode&&(this._outputAudioNode.disconnect(),this._connectedAnalyser.connectAudioNodes(this._outputAudioNode,zt.Engine.audioEngine.masterGain))},e}(),zt.SoundTrack=Gt,Wt=us||(us={}),Ht=function(){function e(e){this.SMOOTHING=.75,this.FFT_SIZE=512,this.BARGRAPHAMPLITUDE=256,this.DEBUGCANVASPOS={x:20,y:20},this.DEBUGCANVASSIZE={width:320,height:200},this._scene=e,this._audioEngine=Wt.Engine.audioEngine,this._audioEngine.canUseWebAudio&&this._audioEngine.audioContext&&(this._webAudioAnalyser=this._audioEngine.audioContext.createAnalyser(),this._webAudioAnalyser.minDecibels=-140,this._webAudioAnalyser.maxDecibels=0,this._byteFreqs=new Uint8Array(this._webAudioAnalyser.frequencyBinCount),this._byteTime=new Uint8Array(this._webAudioAnalyser.frequencyBinCount),this._floatFreqs=new Float32Array(this._webAudioAnalyser.frequencyBinCount))}return e.prototype.getFrequencyBinCount=function(){return this._audioEngine.canUseWebAudio?this._webAudioAnalyser.frequencyBinCount:0},e.prototype.getByteFrequencyData=function(){return this._audioEngine.canUseWebAudio&&(this._webAudioAnalyser.smoothingTimeConstant=this.SMOOTHING,this._webAudioAnalyser.fftSize=this.FFT_SIZE,this._webAudioAnalyser.getByteFrequencyData(this._byteFreqs)),this._byteFreqs},e.prototype.getByteTimeDomainData=function(){return this._audioEngine.canUseWebAudio&&(this._webAudioAnalyser.smoothingTimeConstant=this.SMOOTHING,this._webAudioAnalyser.fftSize=this.FFT_SIZE,this._webAudioAnalyser.getByteTimeDomainData(this._byteTime)),this._byteTime},e.prototype.getFloatFrequencyData=function(){return this._audioEngine.canUseWebAudio&&(this._webAudioAnalyser.smoothingTimeConstant=this.SMOOTHING,this._webAudioAnalyser.fftSize=this.FFT_SIZE,this._webAudioAnalyser.getFloatFrequencyData(this._floatFreqs)),this._floatFreqs},e.prototype.drawDebugCanvas=function(){var e=this;if(this._audioEngine.canUseWebAudio&&(this._debugCanvas||(this._debugCanvas=document.createElement("canvas"),this._debugCanvas.width=this.DEBUGCANVASSIZE.width,this._debugCanvas.height=this.DEBUGCANVASSIZE.height,this._debugCanvas.style.position="absolute",this._debugCanvas.style.top=this.DEBUGCANVASPOS.y+"px",this._debugCanvas.style.left=this.DEBUGCANVASPOS.x+"px",this._debugCanvasContext=this._debugCanvas.getContext("2d"),document.body.appendChild(this._debugCanvas),this._registerFunc=function(){e.drawDebugCanvas()},this._scene.registerBeforeRender(this._registerFunc)),this._registerFunc&&this._debugCanvasContext)){var t=this.getByteFrequencyData();this._debugCanvasContext.fillStyle="rgb(0, 0, 0)",this._debugCanvasContext.fillRect(0,0,this.DEBUGCANVASSIZE.width,this.DEBUGCANVASSIZE.height);for(var i=0;i<this.getFrequencyBinCount();i++){var r=t[i]/this.BARGRAPHAMPLITUDE,n=this.DEBUGCANVASSIZE.height*r,o=this.DEBUGCANVASSIZE.height-n-1,s=this.DEBUGCANVASSIZE.width/this.getFrequencyBinCount(),a=i/this.getFrequencyBinCount()*360;this._debugCanvasContext.fillStyle="hsl("+a+", 100%, 50%)",this._debugCanvasContext.fillRect(i*s,o,s,n)}}},e.prototype.stopDebugCanvas=function(){this._debugCanvas&&(this._registerFunc&&(this._scene.unregisterBeforeRender(this._registerFunc),this._registerFunc=null),document.body.removeChild(this._debugCanvas),this._debugCanvas=null,this._debugCanvasContext=null)},e.prototype.connectAudioNodes=function(e,t){this._audioEngine.canUseWebAudio&&(e.connect(this._webAudioAnalyser),this._webAudioAnalyser.connect(t))},e.prototype.dispose=function(){this._audioEngine.canUseWebAudio&&this._webAudioAnalyser.disconnect()},e}(),Wt.Analyser=Ht,jt=us||(us={}),Xt=function(e){function t(t,i,r,n,o,s,a,h,l,c){void 0===r&&(r=null),void 0===n&&(n=!1),void 0===o&&(o=null),void 0===s&&(s=null),void 0===a&&(a=null),void 0===h&&(h=jt.Engine.TEXTUREFORMAT_RGBA),void 0===l&&(l=!1),void 0===c&&(c=null);var u=e.call(this,i)||this;if(u.coordinatesMode=jt.Texture.CUBIC_MODE,u.name=t,u.url=t,u._noMipmap=n,u.hasAlpha=!1,u._format=h,u._prefiltered=l,u.isCube=!0,u._textureMatrix=jt.Matrix.Identity(),l&&(u.gammaSpace=!1),!t&&!o)return u;u._texture=u._getFromCache(t,n);var p=t.lastIndexOf("."),f=c||(p>-1?t.substring(p).toLowerCase():"");if(!o&&(".dds"===f||r||(r=["_px.jpg","_py.jpg","_pz.jpg","_nx.jpg","_ny.jpg","_nz.jpg"]),o=[],r))for(var d=0;d<r.length;d++)o.push(t+r[d]);return u._files=o,u._texture?s&&(u._texture.isReady?jt.Tools.SetImmediate(function(){return s()}):u._texture.onLoadedObservable.add(s)):i.useDelayedTextureLoading?u.delayLoadState=jt.Engine.DELAYLOADSTATE_NOTLOADED:u._texture=l?i.getEngine().createPrefilteredCubeTexture(t,i,u.lodGenerationScale,u.lodGenerationOffset,s,a,h,c):i.getEngine().createCubeTexture(t,i,o,n,s,a,u._format,c),u}return Y(t,e),t.CreateFromImages=function(e,i,r){return new t("",i,null,r,e)},t.CreateFromPrefilteredData=function(e,i,r){return void 0===r&&(r=null),new t(e,i,null,!1,null,null,null,void 0,!0,r)},t.prototype.delayLoad=function(){if(this.delayLoadState===jt.Engine.DELAYLOADSTATE_NOTLOADED){var e=this.getScene();e&&(this.delayLoadState=jt.Engine.DELAYLOADSTATE_LOADED,this._texture=this._getFromCache(this.url,this._noMipmap),this._texture||(this._prefiltered?this._texture=e.getEngine().createPrefilteredCubeTexture(this.url,e,this.lodGenerationScale,this.lodGenerationOffset,void 0,void 0,this._format):this._texture=e.getEngine().createCubeTexture(this.url,e,this._files,this._noMipmap,void 0,void 0,this._format)))}},t.prototype.getReflectionTextureMatrix=function(){return this._textureMatrix},t.prototype.setReflectionTextureMatrix=function(e){this._textureMatrix=e},t.Parse=function(e,i,r){var n=jt.SerializationHelper.Parse(function(){return new t(r+e.name,i,e.extensions)},e,i);if(e.animations)for(var o=0;o<e.animations.length;o++){var s=e.animations[o];n.animations.push(jt.Animation.Parse(s))}return n},t.prototype.clone=function(){var e=this;return jt.SerializationHelper.Clone(function(){var i=e.getScene();return i?new t(e.url,i,e._extensions,e._noMipmap,e._files):e},this)},t}(jt.BaseTexture),jt.CubeTexture=Xt,Yt=us||(us={}),Kt=function(e){function t(t,i,r,n,o,s,a,h,l,c,u){void 0===o&&(o=!0),void 0===s&&(s=Yt.Engine.TEXTURETYPE_UNSIGNED_INT),void 0===a&&(a=!1),void 0===h&&(h=Yt.Texture.TRILINEAR_SAMPLINGMODE),void 0===l&&(l=!0),void 0===c&&(c=!1),void 0===u&&(u=!1);var p=e.call(this,null,r,!n)||this;return p.isCube=a,p.renderList=new Array,p.renderParticles=!0,p.renderSprites=!1,p.coordinatesMode=Yt.Texture.PROJECTION_MODE,p.ignoreCameraViewport=!1,p.onBeforeBindObservable=new Yt.Observable,p.onAfterUnbindObservable=new Yt.Observable,p.onBeforeRenderObservable=new Yt.Observable,p.onAfterRenderObservable=new Yt.Observable,p.onClearObservable=new Yt.Observable,p._currentRefreshId=-1,p._refreshRate=1,p._samples=1,(r=p.getScene())?(p._engine=r.getEngine(),p.name=t,p.isRenderTarget=!0,p._initialSizeParameter=i,p._processSizeParameter(i),p._resizeObserver=p.getScene().getEngine().onResizeObservable.add(function(){}),p._generateMipMaps=!!n,p._doNotChangeAspectRatio=o,p._renderingManager=new Yt.RenderingManager(r),u?p:(p._renderTargetOptions={generateMipMaps:n,type:s,samplingMode:h,generateDepthBuffer:l,generateStencilBuffer:c},h===Yt.Texture.NEAREST_SAMPLINGMODE&&(p.wrapU=Yt.Texture.CLAMP_ADDRESSMODE,p.wrapV=Yt.Texture.CLAMP_ADDRESSMODE),a?(p._texture=r.getEngine().createRenderTargetCubeTexture(p.getRenderSize(),p._renderTargetOptions),p.coordinatesMode=Yt.Texture.INVCUBIC_MODE,p._textureMatrix=Yt.Matrix.Identity()):p._texture=r.getEngine().createRenderTargetTexture(p._size,p._renderTargetOptions),p)):p}return Y(t,e),Object.defineProperty(t,"REFRESHRATE_RENDER_ONCE",{get:function(){return t._REFRESHRATE_RENDER_ONCE},enumerable:!0,configurable:!0}),Object.defineProperty(t,"REFRESHRATE_RENDER_ONEVERYFRAME",{get:function(){return t._REFRESHRATE_RENDER_ONEVERYFRAME},enumerable:!0,configurable:!0}),Object.defineProperty(t,"REFRESHRATE_RENDER_ONEVERYTWOFRAMES",{get:function(){return t._REFRESHRATE_RENDER_ONEVERYTWOFRAMES},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"onAfterUnbind",{set:function(e){this._onAfterUnbindObserver&&this.onAfterUnbindObservable.remove(this._onAfterUnbindObserver),this._onAfterUnbindObserver=this.onAfterUnbindObservable.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,"onClear",{set:function(e){this._onClearObserver&&this.onClearObservable.remove(this._onClearObserver),this._onClearObserver=this.onClearObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"renderTargetOptions",{get:function(){return this._renderTargetOptions},enumerable:!0,configurable:!0}),t.prototype._onRatioRescale=function(){this._sizeRatio&&this.resize(this._initialSizeParameter)},t.prototype._processSizeParameter=function(e){e.ratio?(this._sizeRatio=e.ratio,this._size={width:this._bestReflectionRenderTargetDimension(this._engine.getRenderWidth(),this._sizeRatio),height:this._bestReflectionRenderTargetDimension(this._engine.getRenderHeight(),this._sizeRatio)}):this._size=e},Object.defineProperty(t.prototype,"samples",{get:function(){return this._samples},set:function(e){if(this._samples!==e){var t=this.getScene();t&&(this._samples=t.getEngine().updateRenderTargetTextureSampleCount(this._texture,e))}},enumerable:!0,configurable:!0}),t.prototype.resetRefreshCounter=function(){this._currentRefreshId=-1},Object.defineProperty(t.prototype,"refreshRate",{get:function(){return this._refreshRate},set:function(e){this._refreshRate=e,this.resetRefreshCounter()},enumerable:!0,configurable:!0}),t.prototype.addPostProcess=function(e){if(!this._postProcessManager){var t=this.getScene();if(!t)return;this._postProcessManager=new Yt.PostProcessManager(t),this._postProcesses=new Array}this._postProcesses.push(e),this._postProcesses[0].autoClear=!1},t.prototype.clearPostProcesses=function(e){if(this._postProcesses){if(e)for(var t=0,i=this._postProcesses;t<i.length;t++){i[t].dispose()}this._postProcesses=[]}},t.prototype.removePostProcess=function(e){if(this._postProcesses){var t=this._postProcesses.indexOf(e);-1!==t&&(this._postProcesses.splice(t,1),this._postProcesses.length>0&&(this._postProcesses[0].autoClear=!1))}},t.prototype._shouldRender=function(){return-1===this._currentRefreshId?(this._currentRefreshId=1,!0):this.refreshRate===this._currentRefreshId?(this._currentRefreshId=1,!0):(this._currentRefreshId++,!1)},t.prototype.getRenderSize=function(){return this._size.width?this._size.width:this._size},t.prototype.getRenderWidth=function(){return this._size.width?this._size.width:this._size},t.prototype.getRenderHeight=function(){return this._size.width?this._size.height:this._size},Object.defineProperty(t.prototype,"canRescale",{get:function(){return!0},enumerable:!0,configurable:!0}),t.prototype.scale=function(e){var t=this.getRenderSize()*e;this.resize(t)},t.prototype.getReflectionTextureMatrix=function(){return this.isCube?this._textureMatrix:e.prototype.getReflectionTextureMatrix.call(this)},t.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))},t.prototype.render=function(e,t){if(void 0===e&&(e=!1),void 0===t&&(t=!1),a=this.getScene()){var i,r=a.getEngine();if(void 0!==this.useCameraPostProcesses&&(e=this.useCameraPostProcesses),this._waitingRenderList){this.renderList=[];for(var n=0;n<this._waitingRenderList.length;n++){var o=this._waitingRenderList[n],s=a.getMeshByID(o);s&&this.renderList.push(s)}delete this._waitingRenderList}if(this.renderListPredicate){var a;if(this.renderList?this.renderList.splice(0):this.renderList=[],!(a=this.getScene()))return;var h=a.meshes;for(n=0;n<h.length;n++){var l=h[n];this.renderListPredicate(l)&&this.renderList.push(l)}}this.onBeforeBindObservable.notifyObservers(this),this.activeCamera?(i=this.activeCamera,r.setViewport(this.activeCamera.viewport,this.getRenderWidth(),this.getRenderHeight()),this.activeCamera!==a.activeCamera&&a.setTransformMatrix(this.activeCamera.getViewMatrix(),this.activeCamera.getProjectionMatrix(!0))):(i=a.activeCamera)&&r.setViewport(i.viewport,this.getRenderWidth(),this.getRenderHeight()),this._renderingManager.reset();for(var c=this.renderList?this.renderList:a.getActiveMeshes().data,u=this.renderList?this.renderList.length:a.getActiveMeshes().length,p=a.getRenderId(),f=0;f<u;f++){if(l=c[f]){if(!l.isReady()){this.resetRefreshCounter();continue}l._preActivateForIntermediateRendering(p);var d=void 0;if(d=!(this.renderList||!i)&&0==(l.layerMask&i.layerMask),l.isEnabled()&&l.isVisible&&l.subMeshes&&!d){l._activate(p);for(var m=0;m<l.subMeshes.length;m++){var g=l.subMeshes[m];a._activeIndices.addCount(g.indexCount,!1),this._renderingManager.dispatch(g,l)}}}}for(var _=0;_<a.particleSystems.length;_++){var v=a.particleSystems[_],y=v.emitter;v.isStarted()&&y&&y.position&&y.isEnabled()&&(c.indexOf(y)>=0&&this._renderingManager.dispatchParticles(v))}if(this.isCube)for(var b=0;b<6;b++)this.renderToTarget(b,c,u,e,t),a.incrementRenderId(),a.resetCachedMaterial();else this.renderToTarget(0,c,u,e,t);this.onAfterUnbindObservable.notifyObservers(this),a.activeCamera&&(this.activeCamera&&this.activeCamera!==a.activeCamera&&a.setTransformMatrix(a.activeCamera.getViewMatrix(),a.activeCamera.getProjectionMatrix(!0)),r.setViewport(a.activeCamera.viewport)),a.resetCachedMaterial()}},t.prototype._bestReflectionRenderTargetDimension=function(e,t){var i=e*t,r=Yt.Tools.NearestPOT(i+16384/(128+i));return Math.min(Yt.Tools.FloorPOT(e),r)},t.prototype.unbindFrameBuffer=function(e,t){var i=this;this._texture&&e.unBindFramebuffer(this._texture,this.isCube,function(){i.onAfterRenderObservable.notifyObservers(t)})},t.prototype.renderToTarget=function(e,t,i,r,n){var o=this.getScene();if(o){var s=o.getEngine();this._texture&&(this._postProcessManager?this._postProcessManager._prepareFrame(this._texture,this._postProcesses):r&&o.postProcessManager._prepareFrame(this._texture)||this._texture&&s.bindFramebuffer(this._texture,this.isCube?e:void 0,void 0,void 0,this.ignoreCameraViewport),this.onBeforeRenderObservable.notifyObservers(e),this.onClearObservable.hasObservers()?this.onClearObservable.notifyObservers(s):s.clear(this.clearColor||o.clearColor,!0,!0,!0),this._doNotChangeAspectRatio||o.updateTransformMatrix(!0),this._renderingManager.render(this.customRenderFunction,t,this.renderParticles,this.renderSprites),this._postProcessManager?this._postProcessManager._finalizeFrame(!1,this._texture,e,this._postProcesses,this.ignoreCameraViewport):r&&o.postProcessManager._finalizeFrame(!1,this._texture,e),this._doNotChangeAspectRatio||o.updateTransformMatrix(!0),n&&Yt.Tools.DumpFramebuffer(this.getRenderWidth(),this.getRenderHeight(),s),this.isCube&&5!==e?this.onAfterRenderObservable.notifyObservers(e):(this.isCube&&5===e&&s.generateMipMapsForCubemap(this._texture),this.unbindFrameBuffer(s,e)))}},t.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)},t.prototype.setRenderingAutoClearDepthStencil=function(e,t){this._renderingManager.setRenderingAutoClearDepthStencil(e,t)},t.prototype.clone=function(){var e=this.getSize(),i=new t(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 i.hasAlpha=this.hasAlpha,i.level=this.level,i.coordinatesMode=this.coordinatesMode,this.renderList&&(i.renderList=this.renderList.slice(0)),i},t.prototype.serialize=function(){if(!this.name)return null;var t=e.prototype.serialize.call(this);if(t.renderTargetSize=this.getRenderSize(),t.renderList=[],this.renderList)for(var i=0;i<this.renderList.length;i++)t.renderList.push(this.renderList[i].id);return t},t.prototype.disposeFramebufferObjects=function(){var e=this.getInternalTexture(),t=this.getScene();e&&t&&t.getEngine()._releaseFramebufferObjects(e)},t.prototype.dispose=function(){this._postProcessManager&&(this._postProcessManager.dispose(),this._postProcessManager=null),this.clearPostProcesses(!0),this._resizeObserver&&(this.getScene().getEngine().onResizeObservable.remove(this._resizeObserver),this._resizeObserver=null),this.renderList=null;var t=this.getScene();if(t){var i=t.customRenderTargets.indexOf(this);i>=0&&t.customRenderTargets.splice(i,1);for(var r=0,n=t.cameras;r<n.length;r++){var o=n[r];(i=o.customRenderTargets.indexOf(this))>=0&&o.customRenderTargets.splice(i,1)}e.prototype.dispose.call(this)}},t.prototype._rebuild=function(){this.refreshRate===t.REFRESHRATE_RENDER_ONCE&&(this.refreshRate=t.REFRESHRATE_RENDER_ONCE),this._postProcessManager&&this._postProcessManager._rebuild()},t._REFRESHRATE_RENDER_ONCE=0,t._REFRESHRATE_RENDER_ONEVERYFRAME=1,t._REFRESHRATE_RENDER_ONEVERYTWOFRAMES=2,t}(Yt.Texture),Yt.RenderTargetTexture=Kt,Qt=us||(us={}),Zt=function(e){function t(t,i,r,n,o){var s=this,a=!(!o||!o.generateMipMaps)&&o.generateMipMaps,h=!(!o||!o.generateDepthTexture)&&o.generateDepthTexture,l=!o||void 0===o.doNotChangeAspectRatio||o.doNotChangeAspectRatio;if((s=e.call(this,t,i,n,a,l)||this)._engine=n.getEngine(),s.isSupported){for(var c=[],u=[],p=0;p<r;p++)o&&o.types&&void 0!==o.types[p]?c.push(o.types[p]):c.push(o&&o.defaultType?o.defaultType:Qt.Engine.TEXTURETYPE_UNSIGNED_INT),o&&o.samplingModes&&void 0!==o.samplingModes[p]?u.push(o.samplingModes[p]):u.push(Qt.Texture.BILINEAR_SAMPLINGMODE);var f=!o||void 0===o.generateDepthBuffer||o.generateDepthBuffer,d=!(!o||void 0===o.generateStencilBuffer)&&o.generateStencilBuffer;return s._size=i,s._multiRenderTargetOptions={samplingModes:u,generateMipMaps:a,generateDepthBuffer:f,generateStencilBuffer:d,generateDepthTexture:h,types:c,textureCount:r},s._createInternalTextures(),s._createTextures(),s}s.dispose()}return Y(t,e),Object.defineProperty(t.prototype,"isSupported",{get:function(){return this._engine.webGLVersion>1||this._engine.getCaps().drawBuffersExtension},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"textures",{get:function(){return this._textures},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"depthTexture",{get:function(){return this._textures[this._textures.length-1]},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"wrapU",{set:function(e){if(this._textures)for(var t=0;t<this._textures.length;t++)this._textures[t].wrapU=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"wrapV",{set:function(e){if(this._textures)for(var t=0;t<this._textures.length;t++)this._textures[t].wrapV=e},enumerable:!0,configurable:!0}),t.prototype._rebuild=function(){this.releaseInternalTextures(),this._createInternalTextures();for(var e=0;e<this._internalTextures.length;e++){this._textures[e]._texture=this._internalTextures[e]}this._texture=this._internalTextures[0]},t.prototype._createInternalTextures=function(){this._internalTextures=this._engine.createMultipleRenderTarget(this._size,this._multiRenderTargetOptions)},t.prototype._createTextures=function(){this._textures=[];for(var e=0;e<this._internalTextures.length;e++){var t=new Qt.Texture(null,this.getScene());t._texture=this._internalTextures[e],this._textures.push(t)}this._texture=this._internalTextures[0]},Object.defineProperty(t.prototype,"samples",{get:function(){return this._samples},set:function(e){this._samples!==e&&(this._samples=this._engine.updateMultipleRenderTargetTextureSampleCount(this._internalTextures,e))},enumerable:!0,configurable:!0}),t.prototype.resize=function(e){this.releaseInternalTextures(),this._internalTextures=this._engine.createMultipleRenderTarget(e,this._multiRenderTargetOptions),this._createInternalTextures()},t.prototype.unbindFrameBuffer=function(e,t){var i=this;e.unBindMultiColorAttachmentFramebuffer(this._internalTextures,this.isCube,function(){i.onAfterRenderObservable.notifyObservers(t)})},t.prototype.dispose=function(){this.releaseInternalTextures(),e.prototype.dispose.call(this)},t.prototype.releaseInternalTextures=function(){if(this._internalTextures)for(var e=this._internalTextures.length-1;e>=0;e--)void 0!==this._internalTextures[e]&&(this._internalTextures[e].dispose(),this._internalTextures.splice(e,1))},t}(Qt.RenderTargetTexture),Qt.MultiRenderTarget=Zt,qt=us||(us={}),Jt=function(e){function t(t,i,r,n,o,s,a){void 0===o&&(o=qt.Engine.TEXTURETYPE_UNSIGNED_INT),void 0===s&&(s=qt.Texture.BILINEAR_SAMPLINGMODE),void 0===a&&(a=!0);var h=e.call(this,t,i,r,n,!0,o,!1,s,a)||this;return h.mirrorPlane=new qt.Plane(0,1,0,1),h._transformMatrix=qt.Matrix.Zero(),h._mirrorMatrix=qt.Matrix.Zero(),h._adaptiveBlurKernel=0,h._blurKernelX=0,h._blurKernelY=0,h._blurRatio=1,h.ignoreCameraViewport=!0,h.onBeforeRenderObservable.add(function(){qt.Matrix.ReflectionToRef(h.mirrorPlane,h._mirrorMatrix),h._savedViewMatrix=r.getViewMatrix(),h._mirrorMatrix.multiplyToRef(h._savedViewMatrix,h._transformMatrix),r.setTransformMatrix(h._transformMatrix,r.getProjectionMatrix()),r.clipPlane=h.mirrorPlane,r.getEngine().cullBackFaces=!1,r._mirroredCameraPosition=qt.Vector3.TransformCoordinates(r.activeCamera.globalPosition,h._mirrorMatrix)}),h.onAfterRenderObservable.add(function(){r.setTransformMatrix(h._savedViewMatrix,r.getProjectionMatrix()),r.getEngine().cullBackFaces=!0,r._mirroredCameraPosition=null,delete r.clipPlane}),h}return Y(t,e),Object.defineProperty(t.prototype,"blurRatio",{get:function(){return this._blurRatio},set:function(e){this._blurRatio!==e&&(this._blurRatio=e,this._preparePostProcesses())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"adaptiveBlurKernel",{set:function(e){this._adaptiveBlurKernel=e,this._autoComputeBlurKernel()},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"blurKernel",{set:function(e){this.blurKernelX=e,this.blurKernelY=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"blurKernelX",{get:function(){return this._blurKernelX},set:function(e){this._blurKernelX!==e&&(this._blurKernelX=e,this._preparePostProcesses())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"blurKernelY",{get:function(){return this._blurKernelY},set:function(e){this._blurKernelY!==e&&(this._blurKernelY=e,this._preparePostProcesses())},enumerable:!0,configurable:!0}),t.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},t.prototype._onRatioRescale=function(){this._sizeRatio&&(this.resize(this._initialSizeParameter),this._adaptiveBlurKernel||this._preparePostProcesses()),this._adaptiveBlurKernel&&this._autoComputeBlurKernel()},t.prototype._preparePostProcesses=function(){if(this.clearPostProcesses(!0),this._blurKernelX&&this._blurKernelY){var e=this.getScene().getEngine(),t=e.getCaps().textureFloatRender?qt.Engine.TEXTURETYPE_FLOAT:qt.Engine.TEXTURETYPE_HALF_FLOAT;this._blurX=new qt.BlurPostProcess("horizontal blur",new qt.Vector2(1,0),this._blurKernelX,this._blurRatio,null,qt.Texture.BILINEAR_SAMPLINGMODE,e,!1,t),this._blurX.autoClear=!1,1===this._blurRatio&&this.samples<2&&this._texture?this._blurX.outputTexture=this._texture:this._blurX.alwaysForcePOT=!0,this._blurY=new qt.BlurPostProcess("vertical blur",new qt.Vector2(0,1),this._blurKernelY,this._blurRatio,null,qt.Texture.BILINEAR_SAMPLINGMODE,e,!1,t),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)},t.prototype.clone=function(){var e=this.getScene();if(!e)return this;var i=this.getSize(),r=new t(this.name,i.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},t.prototype.serialize=function(){if(!this.name)return null;var t=e.prototype.serialize.call(this);return t.mirrorPlane=this.mirrorPlane.asArray(),t},t}(qt.RenderTargetTexture),qt.MirrorTexture=Jt,$t=us||(us={}),ei=function(e){function t(t,i,r,n){var o=e.call(this,t,i,r,n,!0)||this;return o.refractionPlane=new $t.Plane(0,1,0,1),o.depth=2,o.onBeforeRenderObservable.add(function(){r.clipPlane=o.refractionPlane}),o.onAfterRenderObservable.add(function(){delete r.clipPlane}),o}return Y(t,e),t.prototype.clone=function(){var e=this.getScene();if(!e)return this;var i=this.getSize(),r=new t(this.name,i.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},t.prototype.serialize=function(){if(!this.name)return null;var t=e.prototype.serialize.call(this);return t.mirrorPlane=this.refractionPlane.asArray(),t.depth=this.depth,t},t}($t.RenderTargetTexture),$t.RefractionTexture=ei,ti=us||(us={}),ii=function(e){function t(t,i,r,n,o,s){void 0===r&&(r=null),void 0===o&&(o=ti.Texture.TRILINEAR_SAMPLINGMODE),void 0===s&&(s=ti.Engine.TEXTUREFORMAT_RGBA);var a=e.call(this,null,r,!n,void 0,o,void 0,void 0,void 0,void 0,s)||this;a.name=t,a._engine=a.getScene().getEngine(),a.wrapU=ti.Texture.CLAMP_ADDRESSMODE,a.wrapV=ti.Texture.CLAMP_ADDRESSMODE,a._generateMipMaps=n,i.getContext?(a._canvas=i,a._texture=a._engine.createDynamicTexture(i.width,i.height,n,o)):(a._canvas=document.createElement("canvas"),i.width?a._texture=a._engine.createDynamicTexture(i.width,i.height,n,o):a._texture=a._engine.createDynamicTexture(i,i,n,o));var h=a.getSize();return a._canvas.width=h.width,a._canvas.height=h.height,a._context=a._canvas.getContext("2d"),a}return Y(t,e),Object.defineProperty(t.prototype,"canRescale",{get:function(){return!0},enumerable:!0,configurable:!0}),t.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)},t.prototype.scale=function(e){var t=this.getSize();t.width*=e,t.height*=e,this._recreate(t)},t.prototype.scaleTo=function(e,t){var i=this.getSize();i.width=e,i.height=t,this._recreate(i)},t.prototype.getContext=function(){return this._context},t.prototype.clear=function(){var e=this.getSize();this._context.fillRect(0,0,e.width,e.height)},t.prototype.update=function(e){this._engine.updateDynamicTexture(this._texture,this._canvas,void 0===e||e,void 0,this._format||void 0)},t.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)},t.prototype.clone=function(){var e=this.getScene();if(!e)return this;var i=this.getSize(),r=new t(this.name,i,e,this._generateMipMaps);return r.hasAlpha=this.hasAlpha,r.level=this.level,r.wrapU=this.wrapU,r.wrapV=this.wrapV,r},t.prototype._rebuild=function(){this.update()},t}(ti.Texture),ti.DynamicTexture=ii,ri=us||(us={}),ni=function(e){function t(t,i,r,n,o,s){void 0===n&&(n=!1),void 0===o&&(o=!1),void 0===s&&(s=ri.Texture.TRILINEAR_SAMPLINGMODE);var a=e.call(this,null,r,!n,o)||this;a._autoLaunch=!0;var h=null;return a.name=t,i instanceof HTMLVideoElement?a.video=i:(h=i,a.video=document.createElement("video"),a.video.autoplay=!1,a.video.loop=!0,ri.Tools.SetCorsBehavior(h,a.video)),a._engine=a.getScene().getEngine(),a._generateMipMaps=n,a._samplingMode=s,!a._engine.needPOTTextures||ri.Tools.IsExponentOfTwo(a.video.videoWidth)&&ri.Tools.IsExponentOfTwo(a.video.videoHeight)?(a.wrapU=ri.Texture.WRAP_ADDRESSMODE,a.wrapV=ri.Texture.WRAP_ADDRESSMODE):(a.wrapU=ri.Texture.CLAMP_ADDRESSMODE,a.wrapV=ri.Texture.CLAMP_ADDRESSMODE,a._generateMipMaps=!1),h?(a.video.addEventListener("canplay",function(){void 0===a._texture&&a._createTexture()}),h.forEach(function(e){var t=document.createElement("source");t.src=e,a.video.appendChild(t)})):a._createTexture(),a._lastUpdate=ri.Tools.Now,a}return Y(t,e),t.prototype.__setTextureReady=function(){this._texture&&(this._texture.isReady=!0)},t.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)},t.prototype._rebuild=function(){this.update()},t.prototype.update=function(){var e=ri.Tools.Now;return!(e-this._lastUpdate<15||this.video.readyState!==this.video.HAVE_ENOUGH_DATA)&&(this._lastUpdate=e,this._engine.updateVideoTexture(this._texture,this.video,this._invertY),!0)},t.prototype.dispose=function(){e.prototype.dispose.call(this),this.video.removeEventListener("playing",this._setTextureReady)},t.CreateFromWebCam=function(e,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 t("video",o,e,!0,!0))},function(e){ri.Tools.Error(e.name)})},t}(ri.Texture),ri.VideoTexture=ni,oi=us||(us={}),si=function(e){function t(t,i,r,n,o,s,a,h,l){void 0===s&&(s=!0),void 0===a&&(a=!1),void 0===h&&(h=oi.Texture.TRILINEAR_SAMPLINGMODE),void 0===l&&(l=oi.Engine.TEXTURETYPE_UNSIGNED_INT);var c=e.call(this,null,o,!s,a)||this;return c.format=n,c._engine=o.getEngine(),c._texture=o.getEngine().createRawTexture(t,i,r,n,s,a,h,null,l),c.wrapU=oi.Texture.CLAMP_ADDRESSMODE,c.wrapV=oi.Texture.CLAMP_ADDRESSMODE,c}return Y(t,e),t.prototype.update=function(e){this._engine.updateRawTexture(this._texture,e,this._texture.format,this._texture.invertY,void 0,this._texture.type)},t.CreateLuminanceTexture=function(e,i,r,n,o,s,a){return void 0===o&&(o=!0),void 0===s&&(s=!1),void 0===a&&(a=oi.Texture.TRILINEAR_SAMPLINGMODE),new t(e,i,r,oi.Engine.TEXTUREFORMAT_LUMINANCE,n,o,s,a)},t.CreateLuminanceAlphaTexture=function(e,i,r,n,o,s,a){return void 0===o&&(o=!0),void 0===s&&(s=!1),void 0===a&&(a=oi.Texture.TRILINEAR_SAMPLINGMODE),new t(e,i,r,oi.Engine.TEXTUREFORMAT_LUMINANCE_ALPHA,n,o,s,a)},t.CreateAlphaTexture=function(e,i,r,n,o,s,a){return void 0===o&&(o=!0),void 0===s&&(s=!1),void 0===a&&(a=oi.Texture.TRILINEAR_SAMPLINGMODE),new t(e,i,r,oi.Engine.TEXTUREFORMAT_ALPHA,n,o,s,a)},t.CreateRGBTexture=function(e,i,r,n,o,s,a,h){return void 0===o&&(o=!0),void 0===s&&(s=!1),void 0===a&&(a=oi.Texture.TRILINEAR_SAMPLINGMODE),void 0===h&&(h=oi.Engine.TEXTURETYPE_UNSIGNED_INT),new t(e,i,r,oi.Engine.TEXTUREFORMAT_RGB,n,o,s,a,h)},t.CreateRGBATexture=function(e,i,r,n,o,s,a,h){return void 0===o&&(o=!0),void 0===s&&(s=!1),void 0===a&&(a=oi.Texture.TRILINEAR_SAMPLINGMODE),void 0===h&&(h=oi.Engine.TEXTURETYPE_UNSIGNED_INT),new t(e,i,r,oi.Engine.TEXTUREFORMAT_RGBA,n,o,s,a,h)},t}(oi.Texture),oi.RawTexture=si,ai=us||(us={}),hi=function(){function e(e,t,i,r,n,o,s,a,h,l,c,u,p,f){void 0===s&&(s=ai.Texture.NEAREST_SAMPLINGMODE),void 0===l&&(l=null),void 0===c&&(c=ai.Engine.TEXTURETYPE_UNSIGNED_INT),void 0===u&&(u="postprocess"),void 0===f&&(f=!1),this.name=e,this.width=-1,this.height=-1,this.autoClear=!0,this.alphaMode=ai.Engine.ALPHA_DISABLE,this.animations=new Array,this.enablePixelPerfectMode=!1,this.scaleMode=ai.Engine.SCALEMODE_FLOOR,this.alwaysForcePOT=!1,this.samples=1,this.adaptScaleToCurrentViewport=!1,this._reusable=!1,this._textures=new ai.SmartArray(2),this._currentRenderTextureInd=0,this._scaleRatio=new ai.Vector2(1,1),this._texelSize=ai.Vector2.Zero(),this.onActivateObservable=new ai.Observable,this.onSizeChangedObservable=new ai.Observable,this.onApplyObservable=new ai.Observable,this.onBeforeRenderObservable=new ai.Observable,this.onAfterRenderObservable=new ai.Observable,null!=o?(this._camera=o,this._scene=o.getScene(),o.attachPostProcess(this),this._engine=this._scene.getEngine(),this._scene.postProcesses.push(this)):a&&(this._engine=a,this._engine.postProcesses.push(this)),this._options=n,this.renderTargetSamplingMode=s||ai.Texture.NEAREST_SAMPLINGMODE,this._reusable=h||!1,this._textureType=c,this._samplers=r||[],this._samplers.push("textureSampler"),this._fragmentUrl=t,this._vertexUrl=u,this._parameters=i||[],this._parameters.push("scale"),this._indexParameters=p,f||this.updateEffect(l)}return Object.defineProperty(e.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(e.prototype,"onSizeChanged",{set:function(e){this._onSizeChangedObserver&&this.onSizeChangedObservable.remove(this._onSizeChangedObserver),this._onSizeChangedObserver=this.onSizeChangedObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"onApply",{set:function(e){this._onApplyObserver&&this.onApplyObservable.remove(this._onApplyObserver),this._onApplyObserver=this.onApplyObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"onBeforeRender",{set:function(e){this._onBeforeRenderObserver&&this.onBeforeRenderObservable.remove(this._onBeforeRenderObserver),this._onBeforeRenderObserver=this.onBeforeRenderObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"onAfterRender",{set:function(e){this._onAfterRenderObserver&&this.onAfterRenderObservable.remove(this._onAfterRenderObserver),this._onAfterRenderObserver=this.onAfterRenderObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"outputTexture",{get:function(){return this._textures.data[this._currentRenderTextureInd]},set:function(e){this._forcedOutputTexture=e},enumerable:!0,configurable:!0}),e.prototype.getCamera=function(){return this._camera},Object.defineProperty(e.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}),e.prototype.getEngine=function(){return this._engine},e.prototype.getEffect=function(){return this._effect},e.prototype.shareOutputWith=function(e){return this._disposeTextures(),this._shareOutputWithPostProcess=e,this},e.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)},e.prototype.isReusable=function(){return this._reusable},e.prototype.markTextureDirty=function(){this.width=-1},e.prototype.activate=function(e,t,i){var r=this;void 0===t&&(t=null);var n,o=(e=e||this._camera).getScene(),s=o.getEngine(),a=s.getCaps().maxTextureSize,h=(t?t.width:this._engine.getRenderWidth(!0))*this._options|0,l=(t?t.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===ai.Texture.TRILINEAR_SAMPLINGMODE||this.alwaysForcePOT)&&(this._options.width||(c=s.needPOTTextures?ai.Tools.GetExponentOfTwo(c,a,this.scaleMode):c),this._options.height||(u=s.needPOTTextures?ai.Tools.GetExponentOfTwo(u,a,this.scaleMode):u)),this.width!==c||this.height!==u){if(this._textures.length>0){for(var f=0;f<this._textures.length;f++)this._engine._releaseTexture(this._textures.data[f]);this._textures.reset()}this.width=c,this.height=u;var d={width:this.width,height:this.height},m={generateMipMaps:!1,generateDepthBuffer:i||0===e._postProcesses.indexOf(this),generateStencilBuffer:(i||0===e._postProcesses.indexOf(this))&&this._engine.isStencilEnable,samplingMode:this.renderTargetSamplingMode,type:this._textureType};this._textures.push(this._engine.createRenderTargetTexture(d,m)),this._reusable&&this._textures.push(this._engine.createRenderTargetTexture(d,m)),this._texelSize.copyFromFloats(1/this.width,1/this.height),this.onSizeChangedObservable.notifyObservers(this)}this._textures.forEach(function(e){e.samples!==r.samples&&r._engine.updateRenderTargetTextureSampleCount(e,r.samples)})}this._shareOutputWithPostProcess?n=this._shareOutputWithPostProcess.outputTexture:this._forcedOutputTexture?(n=this._forcedOutputTexture,this.width=this._forcedOutputTexture.width,this.height=this._forcedOutputTexture.height):n=this.outputTexture,this.enablePixelPerfectMode?(this._scaleRatio.copyFromFloats(h/c,l/u),this._engine.bindFramebuffer(n,0,h,l,!0)):(this._scaleRatio.copyFromFloats(1,1),this._engine.bindFramebuffer(n,0,void 0,void 0,!0)),this.onActivateObservable.notifyObservers(e),this.autoClear&&this.alphaMode===ai.Engine.ALPHA_DISABLE&&this._engine.clear(this.clearColor?this.clearColor:o.clearColor,!0,!0,!0),this._reusable&&(this._currentRenderTextureInd=(this._currentRenderTextureInd+1)%2)},Object.defineProperty(e.prototype,"isSupported",{get:function(){return this._effect.isSupported},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"aspectRatio",{get:function(){return this._shareOutputWithPostProcess?this._shareOutputWithPostProcess.aspectRatio:this._forcedOutputTexture?this._forcedOutputTexture.width/this._forcedOutputTexture.height:this.width/this.height},enumerable:!0,configurable:!0}),e.prototype.isReady=function(){return this._effect&&this._effect.isReady()},e.prototype.apply=function(){return this._effect&&this._effect.isReady()?(this._engine.enableEffect(this._effect),this._engine.setState(!1),this._engine.setDepthBuffer(!1),this._engine.setDepthWrite(!1),this._engine.setAlphaMode(this.alphaMode),this.alphaConstants&&this.getEngine().setAlphaConstants(this.alphaConstants.r,this.alphaConstants.g,this.alphaConstants.b,this.alphaConstants.a),e=this._shareOutputWithPostProcess?this._shareOutputWithPostProcess.outputTexture:this._forcedOutputTexture?this._forcedOutputTexture:this.outputTexture,this._effect._bindTexture("textureSampler",e),this._effect.setVector2("scale",this._scaleRatio),this.onApplyObservable.notifyObservers(this._effect),this._effect):null;var e},e.prototype._disposeTextures=function(){if(!this._shareOutputWithPostProcess&&!this._forcedOutputTexture){if(this._textures.length>0)for(var e=0;e<this._textures.length;e++)this._engine._releaseTexture(this._textures.data[e]);this._textures.dispose()}},e.prototype.dispose=function(e){if(e=e||this._camera,this._disposeTextures(),this._scene){var t=this._scene.postProcesses.indexOf(this);-1!==t&&this._scene.postProcesses.splice(t,1)}else{var i=this._engine.postProcesses.indexOf(this);-1!==i&&this._engine.postProcesses.splice(i,1)}e&&(e.detachPostProcess(this),0===e._postProcesses.indexOf(this)&&e._postProcesses.length>0&&this._camera._postProcesses[0].markTextureDirty(),this.onActivateObservable.clear(),this.onAfterRenderObservable.clear(),this.onApplyObservable.clear(),this.onBeforeRenderObservable.clear(),this.onSizeChangedObservable.clear())},e}(),ai.PostProcess=hi,li=us||(us={}),ci=function(e){function t(t,i,r,n,o,s,a){return void 0===r&&(r=null),void 0===a&&(a=li.Engine.TEXTURETYPE_UNSIGNED_INT),e.call(this,t,"pass",null,null,i,r,n,o,s,void 0,a)||this}return Y(t,e),t}(li.PostProcess),li.PassPostProcess=ci;var pi,fi,di,mi,gi,_i,vi,yi,bi,xi,Ti,Ei,Ai,Pi,Mi,Si,Ci,Ri,Oi,Ii,wi,Di,Li,Bi,Ni,Fi,Vi,ki,Ui,zi,Gi,Wi,Hi,ji,Xi,Yi,Ki,Qi,Zi,qi,Ji,$i,er,tr,ir,rr,nr,or,sr,ar,hr,lr,cr,ur,pr,fr,dr,mr,gr,_r,vr,yr,br,xr,Tr,Er,Ar,Pr,Mr,Sr,Cr,Rr,Or,Ir,wr,Dr,Lr,Br,Nr,Fr,Vr,kr,Ur,zr,Gr,Wr,Hr,jr,Xr,Yr,Kr,Qr,Zr,qr,Jr,$r,en,tn,rn,nn,on,sn,an,hn,ln,cn,un,pn,fn,dn,mn,gn,_n,vn,yn,bn,xn,Tn,En,An,Pn,Mn,Sn,Cn,Rn,On,In,wn,Dn,Ln,Bn,Nn,Fn,Vn,kn,Un,zn,Gn,Wn,Hn,jn,Xn,Yn,Kn,Qn,Zn,qn,Jn,$n,eo,to,io,ro,no,oo,so,ao,ho,lo,co,uo,po,fo,mo,go,_o,vo,yo,bo,xo,To,Eo,Ao,Po,Mo,So,Co,Ro,Oo,Io,wo,Do,Lo,Bo,No,Fo,Vo,ko,Uo,zo,Go,Wo,Ho,jo,Xo,Yo,Ko,Qo,Zo,qo,Jo,$o,es,ts,is,rs,ns,os,ss,as,hs,ls,cs;ui=this&&this.__assign||Object.assign||function(e){for(var t,i=1,r=arguments.length;i<r;i++){t=arguments[i];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e};pi=us||(us={}),fi=function(){function e(t,i,r){this._bias=5e-5,this._blurBoxOffset=1,this._blurScale=2,this._blurKernel=1,this._useKernelBlur=!1,this._filter=e.FILTER_NONE,this._darkness=0,this._transparencyShadow=!1,this.frustumEdgeFalloff=0,this.forceBackFacesOnly=!1,this._lightDirection=pi.Vector3.Zero(),this._viewMatrix=pi.Matrix.Zero(),this._projectionMatrix=pi.Matrix.Zero(),this._transformMatrix=pi.Matrix.Zero(),this._currentFaceIndex=0,this._currentFaceIndexCache=0,this._defaultTextureMatrix=pi.Matrix.Identity(),this._mapSize=t,this._light=i,this._scene=i.getScene(),i._shadowGenerator=this;var n=this._scene.getEngine().getCaps();r?n.textureFloatRender&&n.textureFloatLinearFiltering?this._textureType=pi.Engine.TEXTURETYPE_FLOAT:n.textureHalfFloatRender&&n.textureHalfFloatLinearFiltering?this._textureType=pi.Engine.TEXTURETYPE_HALF_FLOAT:this._textureType=pi.Engine.TEXTURETYPE_UNSIGNED_INT:n.textureHalfFloatRender&&n.textureHalfFloatLinearFiltering?this._textureType=pi.Engine.TEXTURETYPE_HALF_FLOAT:n.textureFloatRender&&n.textureFloatLinearFiltering?this._textureType=pi.Engine.TEXTURETYPE_FLOAT:this._textureType=pi.Engine.TEXTURETYPE_UNSIGNED_INT,this._initializeGenerator()}return Object.defineProperty(e,"FILTER_NONE",{get:function(){return e._FILTER_NONE},enumerable:!0,configurable:!0}),Object.defineProperty(e,"FILTER_POISSONSAMPLING",{get:function(){return e._FILTER_POISSONSAMPLING},enumerable:!0,configurable:!0}),Object.defineProperty(e,"FILTER_EXPONENTIALSHADOWMAP",{get:function(){return e._FILTER_EXPONENTIALSHADOWMAP},enumerable:!0,configurable:!0}),Object.defineProperty(e,"FILTER_BLUREXPONENTIALSHADOWMAP",{get:function(){return e._FILTER_BLUREXPONENTIALSHADOWMAP},enumerable:!0,configurable:!0}),Object.defineProperty(e,"FILTER_CLOSEEXPONENTIALSHADOWMAP",{get:function(){return e._FILTER_CLOSEEXPONENTIALSHADOWMAP},enumerable:!0,configurable:!0}),Object.defineProperty(e,"FILTER_BLURCLOSEEXPONENTIALSHADOWMAP",{get:function(){return e._FILTER_BLURCLOSEEXPONENTIALSHADOWMAP},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bias",{get:function(){return this._bias},set:function(e){this._bias=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"blurBoxOffset",{get:function(){return this._blurBoxOffset},set:function(e){this._blurBoxOffset!==e&&(this._blurBoxOffset=e,this._disposeBlurPostProcesses())},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"blurScale",{get:function(){return this._blurScale},set:function(e){this._blurScale!==e&&(this._blurScale=e,this._disposeBlurPostProcesses())},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"blurKernel",{get:function(){return this._blurKernel},set:function(e){this._blurKernel!==e&&(this._blurKernel=e,this._disposeBlurPostProcesses())},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"useKernelBlur",{get:function(){return this._useKernelBlur},set:function(e){this._useKernelBlur!==e&&(this._useKernelBlur=e,this._disposeBlurPostProcesses())},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"depthScale",{get:function(){return void 0!==this._depthScale?this._depthScale:this._light.getDepthScale()},set:function(e){this._depthScale=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"filter",{get:function(){return this._filter},set:function(t){if(this._light.needCube()){if(t===e.FILTER_BLUREXPONENTIALSHADOWMAP)return void(this.useExponentialShadowMap=!0);if(t===e.FILTER_BLURCLOSEEXPONENTIALSHADOWMAP)return void(this.useCloseExponentialShadowMap=!0)}this._filter!==t&&(this._filter=t,this._disposeBlurPostProcesses(),this._applyFilterValues(),this._light._markMeshesAsLightDirty())},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"usePoissonSampling",{get:function(){return this.filter===e.FILTER_POISSONSAMPLING},set:function(t){(t||this.filter===e.FILTER_POISSONSAMPLING)&&(this.filter=t?e.FILTER_POISSONSAMPLING:e.FILTER_NONE)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"useVarianceShadowMap",{get:function(){return pi.Tools.Warn("VSM are now replaced by ESM. Please use useExponentialShadowMap instead."),this.useExponentialShadowMap},set:function(e){pi.Tools.Warn("VSM are now replaced by ESM. Please use useExponentialShadowMap instead."),this.useExponentialShadowMap=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"useBlurVarianceShadowMap",{get:function(){return pi.Tools.Warn("VSM are now replaced by ESM. Please use useBlurExponentialShadowMap instead."),this.useBlurExponentialShadowMap},set:function(e){pi.Tools.Warn("VSM are now replaced by ESM. Please use useBlurExponentialShadowMap instead."),this.useBlurExponentialShadowMap=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"useExponentialShadowMap",{get:function(){return this.filter===e.FILTER_EXPONENTIALSHADOWMAP},set:function(t){(t||this.filter===e.FILTER_EXPONENTIALSHADOWMAP)&&(this.filter=t?e.FILTER_EXPONENTIALSHADOWMAP:e.FILTER_NONE)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"useBlurExponentialShadowMap",{get:function(){return this.filter===e.FILTER_BLUREXPONENTIALSHADOWMAP},set:function(t){(t||this.filter===e.FILTER_BLUREXPONENTIALSHADOWMAP)&&(this.filter=t?e.FILTER_BLUREXPONENTIALSHADOWMAP:e.FILTER_NONE)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"useCloseExponentialShadowMap",{get:function(){return this.filter===e.FILTER_CLOSEEXPONENTIALSHADOWMAP},set:function(t){(t||this.filter===e.FILTER_CLOSEEXPONENTIALSHADOWMAP)&&(this.filter=t?e.FILTER_CLOSEEXPONENTIALSHADOWMAP:e.FILTER_NONE)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"useBlurCloseExponentialShadowMap",{get:function(){return this.filter===e.FILTER_BLURCLOSEEXPONENTIALSHADOWMAP},set:function(t){(t||this.filter===e.FILTER_BLURCLOSEEXPONENTIALSHADOWMAP)&&(this.filter=t?e.FILTER_BLURCLOSEEXPONENTIALSHADOWMAP:e.FILTER_NONE)},enumerable:!0,configurable:!0}),e.prototype.getDarkness=function(){return this._darkness},e.prototype.setDarkness=function(e){return this._darkness=e>=1?1:e<=0?0:e,this},e.prototype.setTransparencyShadow=function(e){return this._transparencyShadow=e,this},e.prototype.getShadowMap=function(){return this._shadowMap},e.prototype.getShadowMapForRendering=function(){return this._shadowMap2?this._shadowMap2:this._shadowMap},e.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},e.prototype.removeShadowCaster=function(e,t){if(void 0===t&&(t=!0),!this._shadowMap||!this._shadowMap.renderList)return this;var i=this._shadowMap.renderList.indexOf(e);if(-1!==i&&this._shadowMap.renderList.splice(i,1),t)for(var r=0,n=e.getChildren();r<n.length;r++){var o=n[r];this.removeShadowCaster(o)}return this},e.prototype.getLight=function(){return this._light},e.prototype._initializeGenerator=function(){this._light._markMeshesAsLightDirty(),this._initializeShadowMap()},e.prototype._initializeShadowMap=function(){var e=this;this._shadowMap=new pi.RenderTargetTexture(this._light.name+"_shadowMap",this._mapSize,this._scene,!1,!0,this._textureType,this._light.needCube()),this._shadowMap.wrapU=pi.Texture.CLAMP_ADDRESSMODE,this._shadowMap.wrapV=pi.Texture.CLAMP_ADDRESSMODE,this._shadowMap.anisotropicFilteringLevel=1,this._shadowMap.updateSamplingMode(pi.Texture.BILINEAR_SAMPLINGMODE),this._shadowMap.renderParticles=!1,this._shadowMap.ignoreCameraViewport=!0,this._shadowMap.onBeforeRenderObservable.add(function(t){e._currentFaceIndex=t}),this._shadowMap.customRenderFunction=this._renderForShadowMap.bind(this),this._shadowMap.onAfterUnbindObservable.add(function(){if(e.useBlurExponentialShadowMap||e.useBlurCloseExponentialShadowMap){var t=e.getShadowMapForRendering();t&&e._scene.postProcessManager.directRender(e._blurPostProcesses,t.getInternalTexture(),!0)}}),this._shadowMap.onClearObservable.add(function(t){e.useExponentialShadowMap||e.useBlurExponentialShadowMap?t.clear(new pi.Color4(0,0,0,0),!0,!0,!0):t.clear(new pi.Color4(1,1,1,1),!0,!0,!0)})},e.prototype._initializeBlurRTTAndPostProcesses=function(){var e=this,t=this._scene.getEngine(),i=this._mapSize/this.blurScale;this.useKernelBlur&&1===this.blurScale||(this._shadowMap2=new pi.RenderTargetTexture(this._light.name+"_shadowMap2",i,this._scene,!1,!0,this._textureType),this._shadowMap2.wrapU=pi.Texture.CLAMP_ADDRESSMODE,this._shadowMap2.wrapV=pi.Texture.CLAMP_ADDRESSMODE,this._shadowMap2.updateSamplingMode(pi.Texture.BILINEAR_SAMPLINGMODE)),this.useKernelBlur?(this._kernelBlurXPostprocess=new pi.BlurPostProcess(this._light.name+"KernelBlurX",new pi.Vector2(1,0),this.blurKernel,1,null,pi.Texture.BILINEAR_SAMPLINGMODE,t,!1,this._textureType),this._kernelBlurXPostprocess.width=i,this._kernelBlurXPostprocess.height=i,this._kernelBlurXPostprocess.onApplyObservable.add(function(t){t.setTexture("textureSampler",e._shadowMap)}),this._kernelBlurYPostprocess=new pi.BlurPostProcess(this._light.name+"KernelBlurY",new pi.Vector2(0,1),this.blurKernel,1,null,pi.Texture.BILINEAR_SAMPLINGMODE,t,!1,this._textureType),this._kernelBlurXPostprocess.autoClear=!1,this._kernelBlurYPostprocess.autoClear=!1,this._textureType===pi.Engine.TEXTURETYPE_UNSIGNED_INT&&(this._kernelBlurXPostprocess.packedFloat=!0,this._kernelBlurYPostprocess.packedFloat=!0),this._blurPostProcesses=[this._kernelBlurXPostprocess,this._kernelBlurYPostprocess]):(this._boxBlurPostprocess=new pi.PostProcess(this._light.name+"DepthBoxBlur","depthBoxBlur",["screenSize","boxOffset"],[],1,null,pi.Texture.BILINEAR_SAMPLINGMODE,t,!1,"#define OFFSET "+this._blurBoxOffset,this._textureType),this._boxBlurPostprocess.onApplyObservable.add(function(t){t.setFloat2("screenSize",i,i),t.setTexture("textureSampler",e._shadowMap)}),this._boxBlurPostprocess.autoClear=!1,this._blurPostProcesses=[this._boxBlurPostprocess])},e.prototype._renderForShadowMap=function(e,t,i,r){var n,o=this._scene.getEngine();if(r.length){for(o.setColorWrite(!1),n=0;n<r.length;n++)this._renderSubMeshForShadowMap(r.data[n]);o.setColorWrite(!0)}for(n=0;n<e.length;n++)this._renderSubMeshForShadowMap(e.data[n]);for(n=0;n<t.length;n++)this._renderSubMeshForShadowMap(t.data[n]);if(this._transparencyShadow)for(n=0;n<i.length;n++)this._renderSubMeshForShadowMap(i.data[n])},e.prototype._renderSubMeshForShadowMap=function(e){var t=this,i=e.getRenderingMesh(),r=this._scene,n=r.getEngine(),o=e.getMaterial();if(o){n.setState(o.backFaceCulling);var s=i._getInstancesRenderList(e._id);if(!s.mustReturn){var a=n.getCaps().instancedArrays&&null!==s.visibleInstances[e._id]&&void 0!==s.visibleInstances[e._id];if(this.isReady(e,a)){if(n.enableEffect(this._effect),i._bind(e,this._effect,pi.Material.TriangleFillMode),this._effect.setFloat2("biasAndScale",this.bias,this.depthScale),this._effect.setMatrix("viewProjection",this.getTransformMatrix()),this._effect.setVector3("lightPosition",this.getLight().position),r.activeCamera&&this._effect.setFloat2("depthValues",this.getLight().getDepthMinZ(r.activeCamera),this.getLight().getDepthMinZ(r.activeCamera)+this.getLight().getDepthMaxZ(r.activeCamera)),o&&o.needAlphaTesting()){var h=o.getAlphaTestTexture();h&&(this._effect.setTexture("diffuseSampler",h),this._effect.setMatrix("diffuseMatrix",h.getTextureMatrix()||this._defaultTextureMatrix))}i.useBones&&i.computeBonesUsingShaders&&this._effect.setMatrices("mBones",i.skeleton.getTransformMatrices(i)),this.forceBackFacesOnly&&n.setState(!0,0,!1,!0),i._processRendering(e,this._effect,pi.Material.TriangleFillMode,s,a,function(e,i){return t._effect.setMatrix("world",i)}),this.forceBackFacesOnly&&n.setState(!0,0,!1,!1)}else this._shadowMap&&this._shadowMap.resetRefreshCounter()}}},e.prototype._applyFilterValues=function(){this._shadowMap&&(this.filter===e.FILTER_NONE?this._shadowMap.updateSamplingMode(pi.Texture.NEAREST_SAMPLINGMODE):this._shadowMap.updateSamplingMode(pi.Texture.BILINEAR_SAMPLINGMODE))},e.prototype.forceCompilation=function(e,t){var i=this,r=ui({useInstances:!1},t),n=this.getShadowMap();if(n){var o=n.renderList;if(o){for(var s=new Array,a=0,h=o;a<h.length;a++){var l=h[a];s.push.apply(s,l.subMeshes)}if(0!==s.length){var c=0,u=function(){if(i._scene&&i._scene.getEngine()){for(;i.isReady(s[c],r.useInstances);)if(++c>=s.length)return void(e&&e(i));setTimeout(u,16)}};u()}else e&&e(this)}else e&&e(this)}else e&&e(this)},e.prototype.isReady=function(e,t){var i=[];this._textureType!==pi.Engine.TEXTURETYPE_UNSIGNED_INT&&i.push("#define FLOAT"),(this.useExponentialShadowMap||this.useBlurExponentialShadowMap)&&i.push("#define ESM");var r=[pi.VertexBuffer.PositionKind],n=e.getMesh(),o=e.getMaterial();if(o&&o.needAlphaTesting()){var s=o.getAlphaTestTexture();s&&(i.push("#define ALPHATEST"),n.isVerticesDataPresent(pi.VertexBuffer.UVKind)&&(r.push(pi.VertexBuffer.UVKind),i.push("#define UV1")),n.isVerticesDataPresent(pi.VertexBuffer.UV2Kind)&&1===s.coordinatesIndex&&(r.push(pi.VertexBuffer.UV2Kind),i.push("#define UV2")))}n.useBones&&n.computeBonesUsingShaders?(r.push(pi.VertexBuffer.MatricesIndicesKind),r.push(pi.VertexBuffer.MatricesWeightsKind),n.numBoneInfluencers>4&&(r.push(pi.VertexBuffer.MatricesIndicesExtraKind),r.push(pi.VertexBuffer.MatricesWeightsExtraKind)),i.push("#define NUM_BONE_INFLUENCERS "+n.numBoneInfluencers),i.push("#define BonesPerMesh "+(n.skeleton.bones.length+1))):i.push("#define NUM_BONE_INFLUENCERS 0"),t&&(i.push("#define INSTANCES"),r.push("world0"),r.push("world1"),r.push("world2"),r.push("world3"));var a=i.join("\n");return this._cachedDefines!==a&&(this._cachedDefines=a,this._effect=this._scene.getEngine().createEffect("shadowMap",r,["world","mBones","viewProjection","diffuseMatrix","lightPosition","depthValues","biasAndScale"],["diffuseSampler"],a)),!!this._effect.isReady()&&((this.useBlurExponentialShadowMap||this.useBlurCloseExponentialShadowMap)&&(this._blurPostProcesses&&this._blurPostProcesses.length||this._initializeBlurRTTAndPostProcesses()),!(this._kernelBlurXPostprocess&&!this._kernelBlurXPostprocess.isReady())&&(!(this._kernelBlurYPostprocess&&!this._kernelBlurYPostprocess.isReady())&&!(this._boxBlurPostprocess&&!this._boxBlurPostprocess.isReady())))},e.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))},e.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))}}},e.prototype.getTransformMatrix=function(){var e=this._scene;if(this._currentRenderID===e.getRenderId()&&this._currentFaceIndexCache===this._currentFaceIndex)return this._transformMatrix;this._currentRenderID=e.getRenderId(),this._currentFaceIndexCache=this._currentFaceIndex;var t=this._light.position;if(this._light.computeTransformedInformation()&&(t=this._light.transformedPosition),pi.Vector3.NormalizeToRef(this._light.getShadowDirection(this._currentFaceIndex),this._lightDirection),1===Math.abs(pi.Vector3.Dot(this._lightDirection,pi.Vector3.Up()))&&(this._lightDirection.z=1e-13),this._light.needProjectionMatrixCompute()||!this._cachedPosition||!this._cachedDirection||!t.equals(this._cachedPosition)||!this._lightDirection.equals(this._cachedDirection)){this._cachedPosition=t.clone(),this._cachedDirection=this._lightDirection.clone(),pi.Matrix.LookAtLHToRef(t,t.add(this._lightDirection),pi.Vector3.Up(),this._viewMatrix);var i=this.getShadowMap();if(i){var r=i.renderList;r&&this._light.setShadowProjectionMatrix(this._projectionMatrix,this._viewMatrix,r)}this._viewMatrix.multiplyToRef(this._projectionMatrix,this._transformMatrix)}return this._transformMatrix},e.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}},e.prototype._disposeBlurPostProcesses=function(){this._shadowMap2&&(this._shadowMap2.dispose(),this._shadowMap2=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=[]},e.prototype._disposeRTTandPostProcesses=function(){this._shadowMap&&(this._shadowMap.dispose(),this._shadowMap=null),this._disposeBlurPostProcesses()},e.prototype.dispose=function(){this._disposeRTTandPostProcesses(),this._light&&(this._light._shadowGenerator=null,this._light._markMeshesAsLightDirty())},e.prototype.serialize=function(){var e={},t=this.getShadowMap();if(!t)return e;if(e.lightId=this._light.id,e.mapSize=t.getRenderSize(),e.useExponentialShadowMap=this.useExponentialShadowMap,e.useBlurExponentialShadowMap=this.useBlurExponentialShadowMap,e.useCloseExponentialShadowMap=this.useBlurExponentialShadowMap,e.useBlurCloseExponentialShadowMap=this.useBlurExponentialShadowMap,e.usePoissonSampling=this.usePoissonSampling,e.forceBackFacesOnly=this.forceBackFacesOnly,e.depthScale=this.depthScale,e.darkness=this.getDarkness(),e.blurBoxOffset=this.blurBoxOffset,e.blurKernel=this.blurKernel,e.blurScale=this.blurScale,e.useKernelBlur=this.useKernelBlur,e.transparencyShadow=this._transparencyShadow,e.renderList=[],t.renderList)for(var i=0;i<t.renderList.length;i++){var r=t.renderList[i];e.renderList.push(r.id)}return e},e.Parse=function(t,i){for(var r=i.getLightByID(t.lightId),n=new e(t.mapSize,r),o=n.getShadowMap(),s=0;s<t.renderList.length;s++){i.getMeshesByID(t.renderList[s]).forEach(function(e){o&&(o.renderList||(o.renderList=[]),o.renderList.push(e))})}return t.usePoissonSampling?n.usePoissonSampling=!0:t.useExponentialShadowMap?n.useExponentialShadowMap=!0:t.useBlurExponentialShadowMap?n.useBlurExponentialShadowMap=!0:t.useCloseExponentialShadowMap?n.useCloseExponentialShadowMap=!0:t.useBlurCloseExponentialShadowMap?n.useBlurCloseExponentialShadowMap=!0:t.useVarianceShadowMap?n.useExponentialShadowMap=!0:t.useBlurVarianceShadowMap&&(n.useBlurExponentialShadowMap=!0),t.depthScale&&(n.depthScale=t.depthScale),t.blurScale&&(n.blurScale=t.blurScale),t.blurBoxOffset&&(n.blurBoxOffset=t.blurBoxOffset),t.useKernelBlur&&(n.useKernelBlur=t.useKernelBlur),t.blurKernel&&(n.blurKernel=t.blurKernel),void 0!==t.bias&&(n.bias=t.bias),t.darkness&&n.setDarkness(t.darkness),t.transparencyShadow&&n.setTransparencyShadow(!0),n.forceBackFacesOnly=t.forceBackFacesOnly,n},e._FILTER_NONE=0,e._FILTER_EXPONENTIALSHADOWMAP=1,e._FILTER_POISSONSAMPLING=2,e._FILTER_BLUREXPONENTIALSHADOWMAP=3,e._FILTER_CLOSEEXPONENTIALSHADOWMAP=4,e._FILTER_BLURCLOSEEXPONENTIALSHADOWMAP=5,e}(),pi.ShadowGenerator=fi,di=us||(us={}),mi=function(){function e(e,t,i){void 0===t&&(t=""),void 0===i&&(i="black");var r=this;this._renderingCanvas=e,this._loadingText=t,this._loadingDivBackgroundColor=i,this._resizeLoadingUI=function(){var e=r._renderingCanvas.getBoundingClientRect(),t=window.getComputedStyle(r._renderingCanvas).position;r._loadingDiv&&(r._loadingDiv.style.position="fixed"===t?"fixed":"absolute",r._loadingDiv.style.left=e.left+"px",r._loadingDiv.style.top=e.top+"px",r._loadingDiv.style.width=e.width+"px",r._loadingDiv.style.height=e.height+"px")}}return e.prototype.displayLoadingUI=function(){if(!this._loadingDiv){this._loadingDiv=document.createElement("div"),this._loadingDiv.id="babylonjsLoadingDiv",this._loadingDiv.style.opacity="0",this._loadingDiv.style.transition="opacity 1.5s ease",this._loadingDiv.style.pointerEvents="none",this._loadingTextDiv=document.createElement("div"),this._loadingTextDiv.style.position="absolute",this._loadingTextDiv.style.left="0",this._loadingTextDiv.style.top="50%",this._loadingTextDiv.style.marginTop="80px",this._loadingTextDiv.style.width="100%",this._loadingTextDiv.style.height="20px",this._loadingTextDiv.style.fontFamily="Arial",this._loadingTextDiv.style.fontSize="14px",this._loadingTextDiv.style.color="white",this._loadingTextDiv.style.textAlign="center",this._loadingTextDiv.innerHTML="Loading",this._loadingDiv.appendChild(this._loadingTextDiv),this._loadingTextDiv.innerHTML=this._loadingText;var e=document.createElement("style");e.type="text/css";e.innerHTML="@-webkit-keyframes spin1 { 0% { -webkit-transform: rotate(0deg);}\n 100% { -webkit-transform: rotate(360deg);}\n } @keyframes spin1 { 0% { transform: rotate(0deg);}\n 100% { transform: rotate(360deg);}\n }",document.getElementsByTagName("head")[0].appendChild(e);var t=new Image;t.src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHgAAAB4CAYAAAA5ZDbSAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAZdEVYdFNvZnR3YXJlAHBhaW50Lm5ldCA0LjAuMTZEaa/1AAAYq0lEQVR4Xu2dCZRcVZnHScAJUZSwjSOIbAJmEAZwQCCMoAInYRGIg8AwegQx7AFzUBBmzAFlE4EAwxz2GRk2w7AnAURZBiEOZgyEQDAQAjmEJqTpNd3V1V3Vmd+/6utKV7/1vnpVXd2p/zn3vOV+27vfu/fd/W3QQAPrBZqbm7fJZrN79vf3T+/r67uf4wO9vb37WXQDIwWtra0Tenp6voQTv5XP56/BkfcR3iLk1g6B7hEeI+zP5V+ZiAbqBZ2dnZ8lV+6Gg87CobfhpOc4byf0FjwYE9DneBkWcXrM2tmzNzTxDdQKJPyETCazI46YgiMuI9zJuXJltuChFIHsP/PSfIfTjU19A2mira1tcxy3ey6XO5vEnkV4kes11XBmENDVj97XOT2O03FmWgMuoNLzGRJva8IUnPkzjjcT/kLoKCZzfQB7XiX8M2G8md7AUJgzJ+Z6e88gZ1xGuj3HsY17PcVkrG9gp7CUF/F8PUvxqdZDrFq1ahNVfKjwTCYxZuDE2wjKlc2WViMePM+HPNsFPOdf22OPblD5OZQHvphnV65cjTMzxaQY3eA5V9OO/hmnm1lSjE7woFsQbiXki4++foHnXkW4mLC1JUl947333tsMY3emqfB9jtPJlXN5U0+bOXPmWCPxgOccSy4+AfqPio+9/oFnbyatbqVE28GSZfjQ1NT0KQzaHMcdyPfyaNoE12HcvdxT29K3Fkv8A2vWrPmcifAFZNtD91yRY+SBZ+9UsMtEgD+jTpeenp6JXI6xpKkuUDqRcA6Kr0Wpens+InQTnIpV6Fdi+BQT64ulS5eOIzefD62na7CeoGcnLCM8ykt5OWlzcPv772/BS/w3nP+K+xU11+DvQe5dcrQlTfWAwbNMb8XA8AyGX80xtLlA6TAJuteMbVhhia1v5VMcr+LWMeoZ4xiYw7q6urbhHbgG+paCkIRQehHu4pO3O5fVydEomF5Ulx548JfVD2wqfKE2I3R3ob/f2GoC1DWhdz7HG3i5j2pvb9+Z24m6HvVZQtYsZFWcowlzePEP4jJdR/OQhxTVpAs9NMXxmZxuZKo8IG4s+v8R2tUFphSBTBWzH+OAFwn/gS3TuN55xYoVqfc6dXd3fwHZ1xFaTX0iyGbwjJqXXAammxP00EXx6UMGEx7ram7+vKnzBZ/87Xiwp40tEdDTgYwlHG/CmadSjO7L+XiialOZAej7POFG2VK0Khngl6Pn8/LL0YEtlFh4n8oDAqvaAYH8tzH2iNDm1IIFn8Ax50G7xtgCAU07CfAG4RHOz+vLZL7e0dGxlYlKHaj8BHo25xgrsfV5wrYH4KmouxV+ZZDnCUdwmXxMGgFvFUVWD+jQuOot6rI0tb4gcfaG9v+MrcAn+wj38gL8C7cObmlp2ZRjOkWYD6ypuAf6zjFHLSJ0c/6YQ813DM/yZXgehreiVgP8cvSfsOeExYsXuzs6n8v9j8mqBRZQmdjXVPuira1NHSpn8UDf4Xu0vd2uCtDzacJOlDDf5ng94X8JTWarB8R1EK7ju7udiYgEz/v3pLFKm4oHUHhh3iZdfshpaEYpA4pvKLLXBujLYKRq71XLhUHg27z12rW9B6L/QhLrWWxRH7nzeDK8awi/5HRTEx0K6MZQ694LHk0DqrgfADkreIYz1q5c+UlTEQzesIuMryrggYQWjNL3RGO7p2tuFMeqjaOidgzyCz1yJMTJ6L6d66WEVCcHIO/dQkI75Chs2g97Hoc3jRz9Lge1ED5l4r0gckqRPB0gTw34t1B+h3IqxZkmrn2SULUa7ezZszdE5xfR9130Xsm5ilrnHrmkQOcKvrkncxqrIiY6wlewbw7BOUfDo/b84zzvj9C7J7eCS0NrUiRKCPjUE7ScMBdlF/B2HqBi0ERXBcuXL99YnQz9fX2ah3Up4UnsWGEmDRuUhoTn+Z5PfvbZZ2N/fuCZRJgnfhNVBu73EZoIKt7l0L2UBsYeDZg016nb5EUCWuXQewinUtTuyq2aTStF14a8SD+VDQVj6hDYxjuXf4Hjl83sSMCmTp8j4FtoMuRQ5dAZcii3kk/0s2bBhxIcBxjxUlib1hWInEDO/6qKV+y4geO5HAMntEE/pq+nZyo0ywsG1SmwL4Orf+0yqGCfmvR73LAn9lAeBjQTEhkA+1h49a08iRflcq4H5iuXFU9cz4lqihC/LXS/NZa6Bc+pz5gql5ub6VXD2tZWTSPeyS7XgeLhXrMnEhj6MSHSwaIhFGZH8oA/JzzFeexvJbRN2HW03moT6cEChx6w4QY2rurn85JWrxsiCy0FwjcIqos8w7GZNPulkawDEbFHlaBtjzODEDrVztuKXMmADPWA3RaljyJeNdKq98ilAez8iJdyGqfO31V4NoV/EvyaCqR54V2EshE5Lqcb+TrkstkTLD4WKB4PNNZQ8P05HAelMXNSPWChC8JsYvwthJo0jSoF6fIqjjqe08Aat+LIkd+AVjn09zxbZFqK3tjXAUbXUaWDjTUSyN4J45YZX2Igo4cEOVfFson2ALIxSjR0jog5YNgpfNHM90BxIjDyWIB8Z2NfB01HISJ20wPaw4w1FlavXq1v8aPGXhFw9JNRFTDItifU/RwwpfmKxYsDK180kU4x0lhAXvOSJUs+bezlIDL2N4xi4GpjK4MGCuzUA+SPxzn3m4iKgKyV2DCV08DeMWg0B+zHHOt2DpjS3Mz1BfFOM25C5ZH4LxldJBB0g7GVARkaXgv8VsKqZtIMPpN9RUnJgRzU5Wfp22vifcG3+2vQvmdsdQXsX2pm+oKX+GYjjQXkPWqsXshpRhcJ0RpbGShSHiSuheP37ZYHsGusVHOrU1lMxkO9od4eE+8LlSzQqfetpnPAooBN/2Um+gISp89MkF8K4G3RrMJYoOhbYGxlQEGhSOGogfoLwipExGtUZVVBYIVAluaAaUpuWA+YujlPF22Ra/iBLYEOsV6tV4w0FiitfmLsXiBMU0NiAVrfsp77Zd8MHPgbDoHtva6uLs1jiv1piAKy5tCG+4KJ9wVO/p6RDzvy+b5rzSwP9Okh/WKPERiCWzfk4K8bUSTiOljAyCdx5DZG4gE8W5Dov+NYUfsV/j50fUC4dmXIQDh0qQ6PVgJsOcLM8oA410Ggvo6Ojr81di+g2TKuQOiyJOKWxlpCJpM5zUjKAL3awTsamQfEbYhjtDGKa5tPsyn/wAuiURftlBO56h6aunEwCMxxvV1d+2Fr7Jce2vAu5LUtLeoGi/19gtbToCaR97BoD6BvUs+WkXqgbw6OuhC6wH5l4rRGaCFOvYnjYbyxnpcsCvDVhYOxo6+zszNwSNHVTtJEmSiwzlMAQmNPwIPW42Dds2hfEK/5WJo0Fth+5VNxFHSlkoTzFRh/N3wnq0OGWxXtdoO8enFwaI4jsyidYgNZTxhrMEjEJ4w+En65ESWRXZ7Q4K/COqDAPlhka87WedB8KawmngTIHREOJs5pMiRp+p/GGgxL1FiA9hxjK6G1tVVdhJGAV15+cPXq1f7dahVC20Wg4miCp0uTe3Xh4Hwu93rY1B7SR/t7xQbP5R1FGgpy8IlKe+MJhZ9Aa7u5jPm+pGLX2BMDOZ+hDXgQiXIJ5xoXHZg96anEEFcvOTi0SMUXS4w0FijSTzTWYEA3hkTSEtDI2qw6RoytDLA6jctCvzKqJ8oPFOO7kAhnYe9cZGiWiZ/N9ezguWaSL4h3TUfvKJIfoN0I4sjigYSdZyxlcDVMgEczEY41ER6oZFBOh2Yqegf2zYoziFC3DuZZrjSTPLDtMlxaNPmPP/54W2OPxksrVozP5fLPGr8vEOpbxJCr3jQSJyDvGRNRhv7iHh8vE5LMpKznHBz4zSTOaXwe+mXGGh9tbWvVQf+iyfCAON/ZlTj4v43ECfB94Le4CuMrWVpTtw7O9fZOM5M8oD7xVSOLBdLuNWN1g7bgJUF8+4qpBjf7Te9M6hD4tBDc0289Wh2MHbuaSR7gsHOMLBaQ9W/G6o5MJrNDPu9dcYdQ33Yc95I6OFV5hnp2cGCliDingX5KU+9MShd0dmqta/k8J4zwnV2JsuuNxAnI83VwNpO52kiSoC4djA255cuXBzYPycGzjTQWkPdNY00OfRcQVLafRnd39ySLLsG1i20AyPZ3cDb7AyNJgnp1cOhUHUhcFiL045v9jTUa8Gjlm29fsQQhb3DzJLUEhC+oiK7EISPOwapoEh+7JQJti5YfGXs0YNC62ouC1h9lsrlToClsjc/RM7uSe0kd3EmlzTO/Kqk8Q106mM/Yw2aOB9jnOg6sWTHxJ9FraSJMy6nGz7RbZUDYmN7e3BnQ5Gisez7u3J9c0JwA6Pb0aCFvNObgwKk6NoU59uJwaJ8y1viAT4vCtEFXYO8SFQGtCZpllyXQtNqL+4lmZ/BN/5qJKQFZozEHe9JtAGSaw4wsFnie4JmUQcjleh8yZq0Fnmq3y0D02IzPMgnonYqYIfA4pC+TcXrgIahLB+PEb5s5HrjaR0b7kbHGB0pK7TDO1/T39x1lUZGAPlUH0xTbz+KSoC4dDDx2DQCHzTCaWOB5zjbW+KCSpW0IS0BIJmy6zWCk7WDuxZ4r5oO6dHB7e/sBZo4H2OfUsYOv9jHW+ECJdkAtA/c6MpmMd+XaEKj7km9M4F5TEfBzSKovDLKG1cHobw+b6EDa3WOksYBPAhevBUJMxl8GJTRhFyMLBKSJFn5ls9nvmogS0DfaHOzb3h8AcUuNNBLQNiWa0gRv4MwMMyBwCqxAfCIH82JdYSJKQN+ocjA5NHD2I/e1aj/23iPyhbG6A+bAgXsZoUEII/UAkkQORu71JqIE7o22HBw4VaelpWU74mPPDc/39d1trO5Qb4vJ8QXxbwat06WofcTInMCzeToAtN4VXUn/l1AXDkan9tDSfmL6C81BZooHxDkN9CMveLFZFFAWWZtDwVta3G0sJcAbe3bmYEiniShBXabcL+wflQDD5mD0yKlvk0b/Tk33AG5F7idG+/ibRe54oEl1nLG6A+ZYe1jyAIuG/u2LB3MazxwAfL5vJFGJinxQUwcju6c/n3+FNPm5JhJyy2k/sQTp5nm+2HBJCGi1X1WpwzuBoQXAN+IcjDz8mdePKi/WhH1uxd7GcCjIVBcWpUYDfZ0VbclEJSr2akMBhVrdX6j+Jx3DpSh7vKB8CIiqKwcrcXGqdr05k3RKbU9ryTQVkUB3aHMrEshw7kGCXiv8xxG0h6Uzent6Fpn6MhA17A6GT/3yTxNO1coJbgWur3JFf1fXNuTes5AZe18xXobFHJKv04JZc3O7CtIcgGL9KW03u3QCfL4D4b292dhrpoYgsYOhEz4kaOuHqXKqiagYiN9QnUlyKgX84JUYsQFP9GKzMFRSe8XJb9upE9Dn62CK/KQT75wdTLz+NXgPNdrDuYzeUd0ByN4Wp07n+EdCRZuTY1/ymZQDwIjQye9pA32xdw6IiUgHc639mN8kzCLRjkxzQRzitUpkZ8LZBP1CILUd55EVvdgsCrzJl5i8mgCja+Zgjst4Pq3DUnMmtSWqyNIuQruRU3+CbO08n+pvBAZAjf1IU5kcGJc0YRMBfVV3MPd2RN4+YbvYukI/3sSpe+LUmbw0ryG/6ts1oSLeYrMw6C0xeaFAGc+Wq3hbfeRk582b55lrzf3UHJwWkD0Wp+6BQ3+BfXEXw6UCdHX4TVB0BoJi9Y1Cp59XbUWN8HW7lRjLli3zbINE+1hNiCRI1cGakIhT99ani/A6z1z1nDoUqNQfbO40kyqDfrCBwMg3E5rsCy+8sFlHR8dEnFzRTq/I8hQ9NFFOtGhXVOxgFeUqfknUK7Ctpjl1ANKJ/vmUkvrdwRZmWjpA4J9MTyja2toKY8TQa/ufxP/Whdd5c5cQJHIwfBsTvkKiaqd6/fRyOHKqavdL0H+V2sxmWvrQCAeKItfmQlNyDG/8SVwnetMHyxmA7lm0K2I7GFrlVBW/V6FPP9GqeU4V0Kt2+O2yhctUN6AJBEWD9ngMnessJxh5AfCoQe+8q+xQOYLuWbQrQh2MXP1XYh8S9DKC2sI1z6kCatW3/RCZ6Vj9fNPMqx2wQVNJQlcNEl/mGG5pv48bi7HxMVSOoHsW7QqPg5GlvnJtk6/B9+HMqYUfaXE6rampqWy4dVhgi8FfLprnBXEex+i/wCSkNiSNDSpUxxt7Ccj2nQQYAwUHc9yE3HEotuifDklnfFYMdGNC/lWCxotDf4PvB/jHZTs71c+f2n+ryqCPPcb5/pKdGrTvbH2MUjH4ByOLBDpON9YSFi5cuI1FOwFbbyTox5T6y+iwFL8CqvWvwVtolWgSv/N4sXbl5ZP3r8hRLT50d56KgYJDCYXVhYOhtqqReKDdZuGJtSQSOk8f67x581SspvH3lpoBe9Vefbg/lzveaXmnAf6tEDMNGRp3LnV3ch29o10lQIf+bOKZc+XnmMGARF2EK4vUwQiSw33n7ZlqDWwcaK9Ob29vd26vwj+OT8m3kKFxdd9tlILSJ1Wo8Y8RZT/YiKOY4le5P3SGZJAc7telg7FroL16Jc/n/a1cBBCxsSblwT8LOfofcCh4AQ4x1uoCXZtgVKnYDXLMUECnPSQD29VBcrhfVw7GHrVXb6WylGg0SvUZcrr+YPYuwWVfaE9ltmpA2Q6EQq2UY+yigzf2oqCH4v4MIysD94fdwdig9uqDnB4T5/d+gwHPGNVFcOopyJiPLOfmGTwa0Ek8qS8RKDKORLFWH95utwbDd94SRqqN/Cv4PDXbTFfXfUZWBvRUPJCRBJiIqfnnccy0Dz74wHkWoypY2D4ZGU8gK+kKjQKQ8RcTW1uQI2fmc7nH7LIMFEW+sw6xdyN4CgvNByNIDjp+ZyRVhzlV7dVLaZc7t1cRoW0w9of/No6ptbuRdZupqC3QPZY33HchMkbJiRPssgyaHkN82XaJXPtOJuN+JRuixQI6Cu1VXiZtJehcFGpeNPyXI6cqPWTIvsxU1R7o912akevre4OHfTHot3fEfRbD3y8+Qu0djO5Ce5UXNGl7dTt4z0RGqnOuhgLZgmcPk2FHrrd3jgwkAVQ58e1ioxjcHeMLPWQcq+5gZKm9+hJHjXo5z4xQBQsxxyDjEfir+nNq5GfQo/nYh6f9e4NUgGEFx3DEzvw1nPrOhSJ+kh6GUBUHw6//Kmls96dJ2qv6FxNF9z8g405kVLVXDfkaiFAd4JIkttYUGFpyDOf91Ch/YVEe8DA/gORpuywDfLNMjBOQt4qEupbTPTX4YeJig+/qrnoxkfMeIdH2UHGBfP0H6kFepElc1rY5lBQYXZbzuO7BWYH7b3V3d/+TX1FEG/JSExEJdOi7qsnrx3DuNM8Zdg2NqnN/BjK0EXlVhxORr56wP6Lv/DT+X1FzYLynaOWe2s1TjCQW4An9t6Jk4hBVdH6YpB9YNXoS+SRk/JaQZHd5J2CnesLuyGaze3KZ2hTemoNcpO+uB3pAQuzvC7SeJSfc0258Wo97aX9PT+TmMEMB73jsO0wJzXnVx4llL7pe5kWaFtSqGHHgu6rpPr5jsdx+hyI59G+hA4C25GDO1V69mbf/77h0+lZpzZX44B+Ye1X1cWKz92pKrYlcjtzc6gfN+ufhApd/ErcwTvuTRNI0m4c4Tg77u6gfbCHdTuQcrRFaRKiFU7Xl1O/RqX9RObevRxR43gmEBYUn9wEJIMeF/jk0yVKTta2tE0jg43kx1OatWifEYKDrHYKGDnfkMrU1xHUPaoh7k8i+030EvoV3c6i4aTCoc/9+9NVkFgh6BmZFaig08he3oxYkwBEkQGCzg7gfG6kzaDvuSyLfgIyqt1cF6SAspoS4iJf3c9xaf3JrGEgUzZcOGgvO4agzjTQUkI9V5z4851MuLhBvUUp1gR7tjXEHL+shXFZnduNIBomi6T73FVLLByQePu4N3CxMbVxyzfeQUTYZrdpA3yvoPVf/1jdTGggC6aXx0ieLSecFcWoj72vkhU4IcswU7gVORksb6FHnufbouJ4Xbv+gf1g0EADav9uSeO9YenpA3IfURFVZ0gqEms1rRg0qCzM4TuYy1T061jt0dXXpX0xJ96FMDXIqQXtJ3tSfze6OaY0KU1ogfTUgUJMK0lBIL06dS/F/LJeRe0k2kAAk7BgSWN2GVW/aCOjRuPCbBHVGBG6J3ECKIN3VlfjroguqA+RrMsFvCNqisf5mRox2qPlB4s8vuiMdIE/fVjVvLlRnhKlqYLig7QIpOiva40PAqR2E22neJFrN10AVgWMOIDgPuMOjmRFa+HVaR0fHliaugXoEOe80nBWrZg2dZkZoYffuaW5u1kCVkadmbT70AGdqJodWOhxHqP2eFg1UDvsLatnSFq41M+KKnp6eXbhsdB2OdGiCeX8+/2ecqgnmk/VXNYtqYLSAnNposzpjgw3+H/belpVa8J7TAAAAAElFTkSuQmCC",t.style.position="absolute",t.style.left="50%",t.style.top="50%",t.style.marginLeft="-60px",t.style.marginTop="-60px",t.style.animation="spin1 2s infinite ease-in-out",t.style.webkitAnimation="spin1 2s infinite ease-in-out",t.style.transformOrigin="50% 50%",t.style.webkitTransformOrigin="50% 50%",this._loadingDiv.appendChild(t),this._resizeLoadingUI(),window.addEventListener("resize",this._resizeLoadingUI),this._loadingDiv.style.backgroundColor=this._loadingDivBackgroundColor,document.body.appendChild(this._loadingDiv),this._loadingDiv.style.opacity="1"}},e.prototype.hideLoadingUI=function(){var e=this;if(this._loadingDiv){this._loadingDiv.style.opacity="0",this._loadingDiv.addEventListener("transitionend",function(){e._loadingDiv&&(document.body.removeChild(e._loadingDiv),window.removeEventListener("resize",e._resizeLoadingUI),e._loadingDiv=null)})}},Object.defineProperty(e.prototype,"loadingUIText",{set:function(e){this._loadingText=e,this._loadingTextDiv&&(this._loadingTextDiv.innerHTML=this._loadingText)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"loadingUIBackgroundColor",{get:function(){return this._loadingDivBackgroundColor},set:function(e){this._loadingDivBackgroundColor=e,this._loadingDiv&&(this._loadingDiv.style.backgroundColor=this._loadingDivBackgroundColor)},enumerable:!0,configurable:!0}),e}(),di.DefaultLoadingScreen=mi,function(e){var t=function(){function e(e,t,i){this.lengthComputable=e,this.loaded=t,this.total=i}return e.FromProgressEvent=function(t){return new e(t.lengthComputable,t.loaded,t.total)},e}();e.SceneLoaderProgressEvent=t;var i=function(){function i(){}return Object.defineProperty(i,"NO_LOGGING",{get:function(){return 0},enumerable:!0,configurable:!0}),Object.defineProperty(i,"MINIMAL_LOGGING",{get:function(){return 1},enumerable:!0,configurable:!0}),Object.defineProperty(i,"SUMMARY_LOGGING",{get:function(){return 2},enumerable:!0,configurable:!0}),Object.defineProperty(i,"DETAILED_LOGGING",{get:function(){return 3},enumerable:!0,configurable:!0}),Object.defineProperty(i,"ForceFullSceneLoadingForIncremental",{get:function(){return i._ForceFullSceneLoadingForIncremental},set:function(e){i._ForceFullSceneLoadingForIncremental=e},enumerable:!0,configurable:!0}),Object.defineProperty(i,"ShowLoadingScreen",{get:function(){return i._ShowLoadingScreen},set:function(e){i._ShowLoadingScreen=e},enumerable:!0,configurable:!0}),Object.defineProperty(i,"loggingLevel",{get:function(){return i._loggingLevel},set:function(e){i._loggingLevel=e},enumerable:!0,configurable:!0}),Object.defineProperty(i,"CleanBoneMatrixWeights",{get:function(){return i._CleanBoneMatrixWeights},set:function(e){i._CleanBoneMatrixWeights=e},enumerable:!0,configurable:!0}),i._getDefaultPlugin=function(){return i._registeredPlugins[".babylon"]},i._getPluginForExtension=function(t){var r=i._registeredPlugins[t];return r||(e.Tools.Warn("Unable to find a plugin to load "+t+" files. Trying to use .babylon default plugin."),i._getDefaultPlugin())},i._getPluginForDirectLoad=function(e){for(var t in i._registeredPlugins){var r=i._registeredPlugins[t].plugin;if(r.canDirectLoad&&r.canDirectLoad(e))return i._registeredPlugins[t]}return i._getDefaultPlugin()},i._getPluginForFilename=function(e){e.name&&(e=e.name);var t=e.indexOf("?");-1!==t&&(e=e.substring(0,t));var r=e.lastIndexOf("."),n=e.substring(r,e.length).toLowerCase();return i._getPluginForExtension(n)},i._getDirectLoad=function(e){return e.substr&&"data:"===e.substr(0,5)?e.substr(5):null},i._loadData=function(r,n,o,s,a,h,l,c){var u,p=i._getDirectLoad(n),f=c?i._getPluginForExtension(c):p?i._getPluginForDirectLoad(n):i._getPluginForFilename(n);u=f.plugin.createPlugin?f.plugin.createPlugin():f.plugin;var d,m=f.isBinary;i.OnPluginActivatedObservable.notifyObservers(u);var g=function(e,t){o.isDisposed?h("Scene has been disposed"):(o.database=d,s(u,e,t))},_=null,v=!1,y=u.onDisposeObservable;y&&y.add(function(){v=!0,_&&(_.abort(),_=null),l()});var b=function(){if(!v){var i=r+n;_=e.Tools.LoadFile(i,g,a?function(e){a(t.FromProgressEvent(e))}:void 0,d,m,function(e,t){h("Failed to load scene."+(t?"":" "+t.message),t)})}};if(p)return g(p),u;if(-1===r.indexOf("file:"))o.getEngine().enableOfflineSupport?d=new e.Database(r+n,b):b();else{var x=n;x.name?_=e.Tools.ReadFile(x,g,a,m):e.FilesInput.FilesToLoad[n]?_=e.Tools.ReadFile(e.FilesInput.FilesToLoad[n],g,a,m):h("Unable to find file named "+n)}return u},i.GetPluginForExtension=function(e){return i._getPluginForExtension(e).plugin},i.IsPluginForExtensionAvailable=function(e){return!!i._registeredPlugins[e]},i.RegisterPlugin=function(e){if("string"==typeof e.extensions){var t=e.extensions;i._registeredPlugins[t.toLowerCase()]={plugin:e,isBinary:!1}}else{var r=e.extensions;Object.keys(r).forEach(function(t){i._registeredPlugins[t.toLowerCase()]={plugin:e,isBinary:r[t].isBinary}})}},i.ImportMesh=function(t,r,n,o,s,a,h,l){if(void 0===s&&(s=null),void 0===a&&(a=null),void 0===h&&(h=null),void 0===l&&(l=null),n.substr&&"/"===n.substr(0,1))return e.Tools.Error("Wrong sceneFilename parameter"),null;var c={};o._addPendingData(c);var u=function(){o._removePendingData(c)},p=function(t,i){var s="Unable to import meshes from "+r+n+": "+t;h?h(o,s,i):e.Tools.Error(s),u()},f=a?function(e){try{a(e)}catch(e){p("Error in onProgress callback",e)}}:void 0,d=function(e,t,i){if(o.importedMeshesFiles.push(r+n),s)try{s(e,t,i)}catch(e){p("Error in onSuccess callback",e)}o._removePendingData(c)};return i._loadData(r,n,o,function(e,i,n){if(e.rewriteRootURL&&(r=e.rewriteRootURL(r,n)),e.importMesh){var s=e,a=new Array,h=new Array,l=new Array;if(!s.importMesh(t,o,i,r,a,h,l,p))return;o.loadingPluginName=e.name,d(a,h,l)}else{e.importMeshAsync(t,o,i,r,function(t,i,r){o.loadingPluginName=e.name,d(t,i,r)},f,p)}},f,p,u,l)},i.Load=function(t,r,n,o,s,a,h){return void 0===o&&(o=null),void 0===s&&(s=null),void 0===a&&(a=null),void 0===h&&(h=null),i.Append(t,r,new e.Scene(n),o,s,a,h)},i.Append=function(t,r,n,o,s,a,h){if(void 0===o&&(o=null),void 0===s&&(s=null),void 0===a&&(a=null),void 0===h&&(h=null),r.substr&&"/"===r.substr(0,1))return e.Tools.Error("Wrong sceneFilename parameter"),null;i.ShowLoadingScreen&&n.getEngine().displayLoadingUI();var l={};n._addPendingData(l);var c=function(){n._removePendingData(l),n.getEngine().hideLoadingUI()},u=function(i,o){var s="Unable to load from "+t+r+(i?": "+i:"");a?a(n,s,o):e.Tools.Error(s),c()},p=s?function(e){try{s(e)}catch(e){u("Error in onProgress callback",e)}}:void 0,f=function(){if(o)try{o(n)}catch(e){u("Error in onSuccess callback",e)}n._removePendingData(l)};return i._loadData(t,r,n,function(e,r,o){if(e.load){if(!e.load(n,r,t,u))return;n.loadingPluginName=e.name,f()}else{e.loadAsync(n,r,t,function(){n.loadingPluginName=e.name,f()},p,u)}i.ShowLoadingScreen&&n.executeWhenReady(function(){n.getEngine().hideLoadingUI()})},p,u,c,h)},i.LoadAssetContainer=function(t,r,n,o,s,a,h){if(void 0===o&&(o=null),void 0===s&&(s=null),void 0===a&&(a=null),void 0===h&&(h=null),r.substr&&"/"===r.substr(0,1))return e.Tools.Error("Wrong sceneFilename parameter"),null;var l={};n._addPendingData(l);var c=function(){n._removePendingData(l)},u=function(i,o){var s="Unable to load assets from "+t+r+(i?": "+i:"");a?a(n,s,o):e.Tools.Error(s),c()},p=s?function(e){try{s(e)}catch(e){u("Error in onProgress callback",e)}}:void 0,f=function(e){if(o)try{o(e)}catch(e){u("Error in onSuccess callback",e)}n._removePendingData(l)};return i._loadData(t,r,n,function(e,r,o){if(e.loadAssets){var s=e.loadAssets(n,r,t,u);if(!s)return;n.loadingPluginName=e.name,f(s)}else if(e.loadAssetsAsync){e.loadAssetsAsync(n,r,t,function(t){t&&(n.loadingPluginName=e.name,f(t))},p,u)}else u("LoadAssetContainer is not supported by this plugin. Plugin did not provide a loadAssets or loadAssetsAsync method.");i.ShowLoadingScreen&&n.executeWhenReady(function(){n.getEngine().hideLoadingUI()})},p,u,c,h)},i._ForceFullSceneLoadingForIncremental=!1,i._ShowLoadingScreen=!0,i._CleanBoneMatrixWeights=!1,i._loggingLevel=i.NO_LOGGING,i.OnPluginActivatedObservable=new e.Observable,i._registeredPlugins={},i}();e.SceneLoader=i}(us||(us={})),gi=us||(us={}),_i=function(e,t,i,r){for(var n=0,o=t.materials.length;n<o;n++){var s=t.materials[n];if(s.id===e)return gi.Material.Parse(s,i,r)}return null},vi=function(e,t,i){for(var r in t)if(e.name===t[r])return i.push(e.id),!0;return!(!e.parentId||-1===i.indexOf(e.parentId))&&(i.push(e.id),!0)},yi=function(e,t){return e+" of "+(t?t.file+" from "+t.name+" version: "+t.version+", exporter version: "+t.exporter_version:"unknown")},bi=function(e,t,i,r,n){void 0===n&&(n=!1);var o=new gi.AssetContainer(e),s="importScene has failed JSON parse";try{var a=JSON.parse(t);s="";var h,l,c=gi.SceneLoader.loggingLevel===gi.SceneLoader.DETAILED_LOGGING;if(void 0!==a.lights&&null!==a.lights)for(h=0,l=a.lights.length;h<l;h++){var u=a.lights[h],p=gi.Light.Parse(u,e);p&&(o.lights.push(p),s+=0===h?"\n\tLights:":"",s+="\n\t\t"+p.toString(c))}if(void 0!==a.animations&&null!==a.animations)for(h=0,l=a.animations.length;h<l;h++){var f=a.animations[h],d=gi.Animation.Parse(f);e.animations.push(d),o.animations.push(d),s+=0===h?"\n\tAnimations:":"",s+="\n\t\t"+d.toString(c)}if(void 0!==a.materials&&null!==a.materials)for(h=0,l=a.materials.length;h<l;h++){var m=a.materials[h],g=gi.Material.Parse(m,e,i);o.materials.push(g),s+=0===h?"\n\tMaterials:":"",s+="\n\t\t"+g.toString(c)}if(void 0!==a.multiMaterials&&null!==a.multiMaterials)for(h=0,l=a.multiMaterials.length;h<l;h++){var _=a.multiMaterials[h],v=gi.Material.ParseMultiMaterial(_,e);o.multiMaterials.push(v),s+=0===h?"\n\tMultiMaterials:":"",s+="\n\t\t"+v.toString(c)}if(void 0!==a.morphTargetManagers&&null!==a.morphTargetManagers)for(var y=0,b=a.morphTargetManagers;y<b.length;y++){var x=b[y];o.morphTargetManagers.push(gi.MorphTargetManager.Parse(x,e))}if(void 0!==a.skeletons&&null!==a.skeletons)for(h=0,l=a.skeletons.length;h<l;h++){var T=a.skeletons[h],E=gi.Skeleton.Parse(T,e);o.skeletons.push(E),s+=0===h?"\n\tSkeletons:":"",s+="\n\t\t"+E.toString(c)}var A=a.geometries;if(void 0!==A&&null!==A){var P=new Array,M=A.boxes;if(void 0!==M&&null!==M)for(h=0,l=M.length;h<l;h++){var S=M[h];P.push(gi.BoxGeometry.Parse(S,e))}var C=A.spheres;if(void 0!==C&&null!==C)for(h=0,l=C.length;h<l;h++){var R=C[h];P.push(gi.SphereGeometry.Parse(R,e))}var O=A.cylinders;if(void 0!==O&&null!==O)for(h=0,l=O.length;h<l;h++){var I=O[h];P.push(gi.CylinderGeometry.Parse(I,e))}var w=A.toruses;if(void 0!==w&&null!==w)for(h=0,l=w.length;h<l;h++){var D=w[h];P.push(gi.TorusGeometry.Parse(D,e))}var L=A.grounds;if(void 0!==L&&null!==L)for(h=0,l=L.length;h<l;h++){var B=L[h];P.push(gi.GroundGeometry.Parse(B,e))}var N=A.planes;if(void 0!==N&&null!==N)for(h=0,l=N.length;h<l;h++){var F=N[h];P.push(gi.PlaneGeometry.Parse(F,e))}var V=A.torusKnots;if(void 0!==V&&null!==V)for(h=0,l=V.length;h<l;h++){var k=V[h];P.push(gi.TorusKnotGeometry.Parse(k,e))}var U=A.vertexData;if(void 0!==U&&null!==U)for(h=0,l=U.length;h<l;h++){var z=U[h];P.push(gi.Geometry.Parse(z,e,i))}P.forEach(function(e){e&&o.geometries.push(e)})}if(void 0!==a.transformNodes&&null!==a.transformNodes)for(h=0,l=a.transformNodes.length;h<l;h++){var G=a.transformNodes[h],W=gi.TransformNode.Parse(G,e,i);o.transformNodes.push(W)}if(void 0!==a.meshes&&null!==a.meshes)for(h=0,l=a.meshes.length;h<l;h++){var H=a.meshes[h],j=gi.Mesh.Parse(H,e,i);o.meshes.push(j),s+=0===h?"\n\tMeshes:":"",s+="\n\t\t"+j.toString(c)}if(void 0!==a.cameras&&null!==a.cameras)for(h=0,l=a.cameras.length;h<l;h++){var X=a.cameras[h],Y=gi.Camera.Parse(X,e);o.cameras.push(Y),s+=0===h?"\n\tCameras:":"",s+="\n\t\t"+Y.toString(c)}for(h=0,l=e.cameras.length;h<l;h++){(Y=e.cameras[h])._waitingParentId&&(Y.parent=e.getLastEntryByID(Y._waitingParentId),Y._waitingParentId=null)}for(h=0,l=e.lights.length;h<l;h++){var K=e.lights[h];K&&K._waitingParentId&&(K.parent=e.getLastEntryByID(K._waitingParentId),K._waitingParentId=null)}var Q,Z=[];if(gi.AudioEngine&&void 0!==a.sounds&&null!==a.sounds)for(h=0,l=a.sounds.length;h<l;h++){var q=a.sounds[h];gi.Engine.audioEngine.canUseWebAudio?(q.url||(q.url=q.name),Z[q.url]?o.sounds.push(gi.Sound.Parse(q,e,i,Z[q.url])):(Q=gi.Sound.Parse(q,e,i),Z[q.url]=Q,o.sounds.push(Q))):o.sounds.push(new gi.Sound(q.name,null,e))}for(Z=[],h=0,l=e.transformNodes.length;h<l;h++){var J=e.transformNodes[h];J._waitingParentId&&(J.parent=e.getLastEntryByID(J._waitingParentId),J._waitingParentId=null)}for(h=0,l=e.meshes.length;h<l;h++){(j=e.meshes[h])._waitingParentId&&(j.parent=e.getLastEntryByID(j._waitingParentId),j._waitingParentId=null),j._waitingActions&&(gi.ActionManager.Parse(j._waitingActions,j,e),j._waitingActions=null)}for(h=0,l=e.meshes.length;h<l;h++){var $=e.meshes[h];$._waitingFreezeWorldMatrix?($.freezeWorldMatrix(),$._waitingFreezeWorldMatrix=null):$.computeWorldMatrix(!0)}if(void 0!==a.particleSystems&&null!==a.particleSystems)for(h=0,l=a.particleSystems.length;h<l;h++){var ee=a.particleSystems[h],te=gi.ParticleSystem.Parse(ee,e,i);o.particleSystems.push(te)}if(void 0!==a.lensFlareSystems&&null!==a.lensFlareSystems)for(h=0,l=a.lensFlareSystems.length;h<l;h++){var ie=a.lensFlareSystems[h],re=gi.LensFlareSystem.Parse(ie,e,i);o.lensFlareSystems.push(re)}if(void 0!==a.shadowGenerators&&null!==a.shadowGenerators)for(h=0,l=a.shadowGenerators.length;h<l;h++){var ne=a.shadowGenerators[h],oe=gi.ShadowGenerator.Parse(ne,e);o.shadowGenerators.push(oe)}for(h=0,l=e.lights.length;h<l;h++){var se=e.lights[h];if(se._excludedMeshesIds.length>0){for(var ae=0;ae<se._excludedMeshesIds.length;ae++){var he=e.getMeshByID(se._excludedMeshesIds[ae]);he&&se.excludedMeshes.push(he)}se._excludedMeshesIds=[]}if(se._includedOnlyMeshesIds.length>0){for(var le=0;le<se._includedOnlyMeshesIds.length;le++){var ce=e.getMeshByID(se._includedOnlyMeshesIds[le]);ce&&se.includedOnlyMeshes.push(ce)}se._includedOnlyMeshesIds=[]}}return void 0!==a.actions&&null!==a.actions&&gi.ActionManager.Parse(a.actions,null,e),n||o.removeAllFromScene(),o}catch(e){var ue=yi("loadAssts",a?a.producer:"Unknown")+s;if(!r)throw gi.Tools.Log(ue),e;r(ue,e)}finally{null!==s&&gi.SceneLoader.loggingLevel!==gi.SceneLoader.NO_LOGGING&&gi.Tools.Log(yi("loadAssts",a?a.producer:"Unknown")+(gi.SceneLoader.loggingLevel!==gi.SceneLoader.MINIMAL_LOGGING?s:""))}return null},gi.SceneLoader.RegisterPlugin({name:"babylon.js",extensions:".babylon",canDirectLoad:function(e){return-1!==e.indexOf("babylon")},importMesh:function(e,t,i,r,n,o,s,a){var h="importMesh has failed JSON parse";try{var l=JSON.parse(i);h="";var c=gi.SceneLoader.loggingLevel===gi.SceneLoader.DETAILED_LOGGING;e?Array.isArray(e)||(e=[e]):e=null;var u=new Array;if(void 0!==l.meshes&&null!==l.meshes){var p,f,d,m=[],g=[];for(p=0,f=l.meshes.length;p<f;p++){var _=l.meshes[p];if(null===e||vi(_,e,u)){if(null!==e&&delete e[e.indexOf(_.name)],void 0!==_.geometryId&&null!==_.geometryId&&void 0!==l.geometries&&null!==l.geometries){var v=!1;["boxes","spheres","cylinders","toruses","grounds","planes","torusKnots","vertexData"].forEach(function(e){!0!==v&&l.geometries[e]&&Array.isArray(l.geometries[e])&&l.geometries[e].forEach(function(i){if(i.id===_.geometryId){switch(e){case"boxes":gi.BoxGeometry.Parse(i,t);break;case"spheres":gi.SphereGeometry.Parse(i,t);break;case"cylinders":gi.CylinderGeometry.Parse(i,t);break;case"toruses":gi.TorusGeometry.Parse(i,t);break;case"grounds":gi.GroundGeometry.Parse(i,t);break;case"planes":gi.PlaneGeometry.Parse(i,t);break;case"torusKnots":gi.TorusKnotGeometry.Parse(i,t);break;case"vertexData":gi.Geometry.Parse(i,t,r)}v=!0}})}),!1===v&&gi.Tools.Warn("Geometry not found for mesh "+_.id)}if(_.materialId){var y=-1!==g.indexOf(_.materialId);if(!1===y&&void 0!==l.multiMaterials&&null!==l.multiMaterials)for(var b=0,x=l.multiMaterials.length;b<x;b++){var T=l.multiMaterials[b];if(T.id===_.materialId){for(var E=0,A=T.materials.length;E<A;E++){var P,M=T.materials[E];g.push(M),h+="\n\tMaterial "+(P=_i(M,l,t,r)).toString(c)}g.push(T.id),y=!0,h+="\n\tMulti-Material "+gi.Material.ParseMultiMaterial(T,t).toString(c);break}}!1===y&&(g.push(_.materialId),(P=_i(_.materialId,l,t,r))?h+="\n\tMaterial "+P.toString(c):gi.Tools.Warn("Material not found for mesh "+_.id))}if(_.skeletonId>-1&&void 0!==l.skeletons&&null!==l.skeletons&&!1==m.indexOf(_.skeletonId)>-1)for(var S=0,C=l.skeletons.length;S<C;S++){var R=l.skeletons[S];if(R.id===_.skeletonId){var O=gi.Skeleton.Parse(R,t);s.push(O),m.push(R.id),h+="\n\tSkeleton "+O.toString(c)}}var I=gi.Mesh.Parse(_,t,r);n.push(I),h+="\n\tMesh "+I.toString(c)}}for(p=0,f=t.meshes.length;p<f;p++)(d=t.meshes[p])._waitingParentId&&(d.parent=t.getLastEntryByID(d._waitingParentId),d._waitingParentId=null);for(p=0,f=t.meshes.length;p<f;p++)(d=t.meshes[p])._waitingFreezeWorldMatrix?(d.freezeWorldMatrix(),d._waitingFreezeWorldMatrix=null):d.computeWorldMatrix(!0)}if(void 0!==l.particleSystems&&null!==l.particleSystems)for(p=0,f=l.particleSystems.length;p<f;p++){var w=l.particleSystems[p];-1!==u.indexOf(w.emitterId)&&o.push(gi.ParticleSystem.Parse(w,t,r))}return!0}catch(e){var D=yi("importMesh",l?l.producer:"Unknown")+h;if(!a)throw gi.Tools.Log(D),e;a(D,e)}finally{null!==h&&gi.SceneLoader.loggingLevel!==gi.SceneLoader.NO_LOGGING&&gi.Tools.Log(yi("importMesh",l?l.producer:"Unknown")+(gi.SceneLoader.loggingLevel!==gi.SceneLoader.MINIMAL_LOGGING?h:""))}return!1},load:function(e,t,i,r){var n="importScene has failed JSON parse";try{var o=JSON.parse(t);if(n="",void 0!==o.useDelayedTextureLoading&&null!==o.useDelayedTextureLoading&&(e.useDelayedTextureLoading=o.useDelayedTextureLoading&&!gi.SceneLoader.ForceFullSceneLoadingForIncremental),void 0!==o.autoClear&&null!==o.autoClear&&(e.autoClear=o.autoClear),void 0!==o.clearColor&&null!==o.clearColor&&(e.clearColor=gi.Color4.FromArray(o.clearColor)),void 0!==o.ambientColor&&null!==o.ambientColor&&(e.ambientColor=gi.Color3.FromArray(o.ambientColor)),void 0!==o.gravity&&null!==o.gravity&&(e.gravity=gi.Vector3.FromArray(o.gravity)),o.fogMode&&0!==o.fogMode)switch(e.fogMode=o.fogMode,e.fogColor=gi.Color3.FromArray(o.fogColor),e.fogStart=o.fogStart,e.fogEnd=o.fogEnd,e.fogDensity=o.fogDensity,n+="\tFog mode for scene: ",e.fogMode){case 1:n+="exp\n";break;case 2:n+="exp2\n";break;case 3:n+="linear\n"}if(o.physicsEnabled){var s;"cannon"===o.physicsEngine?s=new gi.CannonJSPlugin:"oimo"===o.physicsEngine&&(s=new gi.OimoJSPlugin),n="\tPhysics engine "+(o.physicsEngine?o.physicsEngine:"oimo")+" enabled\n";var a=o.physicsGravity?gi.Vector3.FromArray(o.physicsGravity):null;e.enablePhysics(a,s)}if(void 0!==o.metadata&&null!==o.metadata&&(e.metadata=o.metadata),void 0!==o.collisionsEnabled&&null!==o.collisionsEnabled&&(e.collisionsEnabled=o.collisionsEnabled),e.workerCollisions=!!o.workerCollisions,!bi(e,t,i,onerror,!0))return!1;if(o.autoAnimate&&e.beginAnimation(e,o.autoAnimateFrom,o.autoAnimateTo,o.autoAnimateLoop,o.autoAnimateSpeed||1),void 0!==o.activeCameraID&&null!==o.activeCameraID&&e.setActiveCameraByID(o.activeCameraID),void 0!==o.environmentTexture&&null!==o.environmentTexture&&(e.environmentTexture=gi.CubeTexture.CreateFromPrefilteredData(i+o.environmentTexture,e),!0===o.createDefaultSkybox)){var h=void 0!==e.activeCamera&&null!==e.activeCamera?(e.activeCamera.maxZ-e.activeCamera.minZ)/2:1e3,l=o.skyboxBlurLevel||0;e.createDefaultSkybox(void 0,!0,h,l)}return!0}catch(e){var c=yi("importScene",o?o.producer:"Unknown")+n;if(!r)throw gi.Tools.Log(c),e;r(c,e)}finally{null!==n&&gi.SceneLoader.loggingLevel!==gi.SceneLoader.NO_LOGGING&&gi.Tools.Log(yi("importScene",o?o.producer:"Unknown")+(gi.SceneLoader.loggingLevel!==gi.SceneLoader.MINIMAL_LOGGING?n:""))}return!1},loadAssets:function(e,t,i,r){return bi(e,t,i,onerror)}}),xi=us||(us={}),Ti=function(){function e(e,t,i,r,n,o,s,a,h){this.onProcessFileCallback=function(){return!0},this._engine=e,this._currentScene=t,this._sceneLoadedCallback=i,this._progressCallback=r,this._additionalRenderLoopLogicCallback=n,this._textureLoadingCallback=o,this._startingProcessingFilesCallback=s,this._onReloadCallback=a,this._errorCallback=h}return e.prototype.monitorElementForDragNDrop=function(e){var t=this;e&&(this._elementToMonitor=e,this._dragEnterHandler=function(e){t.drag(e)},this._dragOverHandler=function(e){t.drag(e)},this._dropHandler=function(e){t.drop(e)},this._elementToMonitor.addEventListener("dragenter",this._dragEnterHandler,!1),this._elementToMonitor.addEventListener("dragover",this._dragOverHandler,!1),this._elementToMonitor.addEventListener("drop",this._dropHandler,!1))},e.prototype.dispose=function(){this._elementToMonitor&&(this._elementToMonitor.removeEventListener("dragenter",this._dragEnterHandler),this._elementToMonitor.removeEventListener("dragover",this._dragOverHandler),this._elementToMonitor.removeEventListener("drop",this._dropHandler))},e.prototype.renderFunction=function(){if(this._additionalRenderLoopLogicCallback&&this._additionalRenderLoopLogicCallback(),this._currentScene){if(this._textureLoadingCallback){var e=this._currentScene.getWaitingItemsCount();e>0&&this._textureLoadingCallback(e)}this._currentScene.render()}},e.prototype.drag=function(e){e.stopPropagation(),e.preventDefault()},e.prototype.drop=function(e){e.stopPropagation(),e.preventDefault(),this.loadFiles(e)},e.prototype._traverseFolder=function(e,t,i,r){var n=this,o=e.createReader(),s=e.fullPath.replace(/^\//,"").replace(/(.+?)\/?$/,"$1/");o.readEntries(function(e){i.count+=e.length;for(var o=0,a=e;o<a.length;o++){var h=a[o];h.isFile?h.file(function(e){e.correctName=s+e.name,t.push(e),0==--i.count&&r()}):h.isDirectory&&n._traverseFolder(h,t,i,r)}--i.count&&r()})},e.prototype._processFiles=function(t){for(var i=0;i<t.length;i++){var r=t[i].correctName.toLowerCase(),n=r.split(".").pop();this.onProcessFileCallback(t[i],r,n)&&("babylon"!==n&&"stl"!==n&&"obj"!==n&&"gltf"!==n&&"glb"!==n||-1!==r.indexOf(".binary.babylon")||-1!==r.indexOf(".incremental.babylon")?e.FilesToLoad[r]=t[i]:this._sceneFileToLoad=t[i])}},e.prototype.loadFiles=function(e){var t=this;if(this._startingProcessingFilesCallback&&this._startingProcessingFilesCallback(),e&&e.dataTransfer&&e.dataTransfer.files&&(this._filesToLoad=e.dataTransfer.files),e&&e.target&&e.target.files&&(this._filesToLoad=e.target.files),this._filesToLoad&&this._filesToLoad.length>0){for(var i=new Array,r=[],n=e.dataTransfer?e.dataTransfer.items:null,o=0;o<this._filesToLoad.length;o++){var s=this._filesToLoad[o],a=s.name.toLowerCase(),h=void 0;if(s.correctName=a,n){var l=n[o];l.getAsEntry?h=l.getAsEntry():l.webkitGetAsEntry&&(h=l.webkitGetAsEntry())}h&&h.isDirectory?r.push(h):i.push(s)}if(0===r.length)this._processFiles(i),this._processReload();else for(var c={count:r.length},u=0,p=r;u<p.length;u++){var f=p[u];this._traverseFolder(f,i,c,function(){t._processFiles(i),0===c.count&&t._processReload()})}}},e.prototype._processReload=function(){this._onReloadCallback?this._onReloadCallback(this._sceneFileToLoad):this.reload()},e.prototype.reload=function(){var e=this;this._sceneFileToLoad?(this._currentScene&&(xi.Tools.errorsCount>0&&xi.Tools.ClearLogCache(),this._engine.stopRenderLoop(),this._currentScene.dispose()),xi.SceneLoader.Load("file:",this._sceneFileToLoad,this._engine,function(t){e._currentScene=t,e._sceneLoadedCallback&&e._sceneLoadedCallback(e._sceneFileToLoad,e._currentScene),e._currentScene.executeWhenReady(function(){e._engine.runRenderLoop(function(){e.renderFunction()})})},function(t){e._progressCallback&&e._progressCallback(t)},function(t,i){e._currentScene=t,e._errorCallback&&e._errorCallback(e._sceneFileToLoad,e._currentScene,i)})):xi.Tools.Error("Please provide a valid .babylon file.")},e.FilesToLoad={},e}(),xi.FilesInput=Ti,Ei=us||(us={}),Ai=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}(),Ei.StringDictionary=Ai,Pi=us||(us={}),Mi=function(){function e(){}return e.EnableFor=function(t){t._tags=t._tags||{},t.hasTags=function(){return e.HasTags(t)},t.addTags=function(i){return e.AddTagsTo(t,i)},t.removeTags=function(i){return e.RemoveTagsFrom(t,i)},t.matchesTagsQuery=function(i){return e.MatchesQuery(t,i)}},e.DisableFor=function(e){delete e._tags,delete e.hasTags,delete e.addTags,delete e.removeTags,delete e.matchesTagsQuery},e.HasTags=function(e){return!!e._tags&&!Pi.Tools.IsEmpty(e._tags)},e.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},e.AddTagsTo=function(t,i){i&&("string"==typeof i&&i.split(" ").forEach(function(i,r,n){e._AddTagTo(t,i)}))},e._AddTagTo=function(t,i){""!==(i=i.trim())&&"true"!==i&&"false"!==i&&(i.match(/[\s]/)||i.match(/^([!]|([|]|[&]){2})/)||(e.EnableFor(t),t._tags[i]=!0))},e.RemoveTagsFrom=function(t,i){if(e.HasTags(t)){var r=i.split(" ");for(var n in r)e._RemoveTagFrom(t,r[n])}},e._RemoveTagFrom=function(e,t){delete e._tags[t]},e.MatchesQuery=function(t,i){return void 0===i||(""===i?e.HasTags(t):Pi.AndOrNotEvaluator.Eval(i,function(i){return e.HasTags(t)&&t._tags[i]}))},e}(),Pi.Tags=Mi,Si=us||(us={}),Ci=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){var r;i=i||function(e){return"true"===e};var 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;h<a.length;++h){var l=e._SimplifyNegation(a[h].trim());if(!(r="true"!==l&&"false"!==l?"!"===l[0]?!i(l.substring(1)):i(l):"true"===l)){s="false";break}}if(r||"true"===s){r=!0;break}r="true"!==s&&"false"!==s?"!"===s[0]?!i(s.substring(1)):i(s):"true"===s}return r?"true":"false"},e._SimplifyNegation=function(e){return"!true"===(e=(e=e.replace(/^[\s!]+/,function(e){return(e=e.replace(/[\s]/g,function(){return""})).length%2?"!":""})).trim())?e="false":"!false"===e&&(e="true"),e},e}(),Si.AndOrNotEvaluator=Ci,Ri=us||(us={}),Oi=function(){function e(t,i){this.idbFactory=window.indexedDB||window.mozIndexedDB||window.webkitIndexedDB||window.msIndexedDB,this.callbackManifestChecked=i,this.currentSceneUrl=e.ReturnFullUrlLocation(t),this.db=null,this._enableSceneOffline=!1,this._enableTexturesOffline=!1,this.manifestVersionFound=0,this.mustUpdateRessources=!1,this.hasReachedQuota=!1,e.IDBStorageEnabled?this.checkManifestFile():this.callbackManifestChecked(!0)}return Object.defineProperty(e.prototype,"enableSceneOffline",{get:function(){return this._enableSceneOffline},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"enableTexturesOffline",{get:function(){return this._enableTexturesOffline},enumerable:!0,configurable:!0}),e.prototype.checkManifestFile=function(){var e=this,t=function(){e._enableSceneOffline=!1,e._enableTexturesOffline=!1,e.callbackManifestChecked(!1)},i=!1,r=this.currentSceneUrl+".manifest",n=new XMLHttpRequest;navigator.onLine&&(i=!0,r=r+(null==r.match(/\?/)?"?":"&")+(new Date).getTime()),n.open("GET",r,!0),n.addEventListener("load",function(){if(200===n.status||Ri.Tools.ValidateXHRData(n,1))try{var i=JSON.parse(n.response);e._enableSceneOffline=i.enableSceneOffline,e._enableTexturesOffline=i.enableTexturesOffline,i.version&&!isNaN(parseInt(i.version))&&(e.manifestVersionFound=i.version),e.callbackManifestChecked&&e.callbackManifestChecked(!0)}catch(e){t()}else t()},!1),n.addEventListener("error",function(r){if(i){i=!1;var o=e.currentSceneUrl+".manifest";n.open("GET",o,!0),n.send()}else t()},!1);try{n.send()}catch(e){Ri.Tools.Error("Error on XHR send request."),this.callbackManifestChecked(!1)}},e.prototype.openAsync=function(e,t){var i=this,r=function(){i.isSupported=!1,t&&t()};if(this.idbFactory&&(this._enableSceneOffline||this._enableTexturesOffline))if(this.db)e&&e();else{this.hasReachedQuota=!1,this.isSupported=!0;var n=this.idbFactory.open("babylonjs",1);n.onerror=function(e){r()},n.onblocked=function(e){Ri.Tools.Error("IDB request blocked. Please reload the page."),r()},n.onsuccess=function(t){i.db=n.result,e()},n.onupgradeneeded=function(e){if(i.db=e.target.result,i.db)try{i.db.createObjectStore("scenes",{keyPath:"sceneUrl"}),i.db.createObjectStore("versions",{keyPath:"sceneUrl"}),i.db.createObjectStore("textures",{keyPath:"textureUrl"})}catch(e){Ri.Tools.Error("Error while creating object stores. Exception: "+e.message),r()}}}else this.isSupported=!1,t&&t()},e.prototype.loadImageFromDB=function(t,i){var r=this,n=e.ReturnFullUrlLocation(t),o=function(){r.hasReachedQuota||null===r.db?i.src=t:r._saveImageIntoDBAsync(n,i)};this.mustUpdateRessources?o():this._loadImageFromDBAsync(n,i,o)},e.prototype._loadImageFromDBAsync=function(e,t,i){if(this.isSupported&&null!==this.db){var r,n=this.db.transaction(["textures"]);n.onabort=function(i){t.src=e},n.oncomplete=function(n){var o;if(r){var s=window.URL||window.webkitURL;o=s.createObjectURL(r.data,{oneTimeOnly:!0}),t.onerror=function(){Ri.Tools.Error("Error loading image from blob URL: "+o+" switching back to web url: "+e),t.src=e},t.src=o}else i()};var o=n.objectStore("textures").get(e);o.onsuccess=function(e){r=e.target.result},o.onerror=function(i){Ri.Tools.Error("Error loading texture "+e+" from DB."),t.src=e}}else Ri.Tools.Error("Error: IndexedDB not supported by your browser or BabylonJS Database is not open."),t.src=e},e.prototype._saveImageIntoDBAsync=function(t,i){var r=this;if(this.isSupported){var n=function(){var e;if(o){var t=window.URL||window.webkitURL;try{e=t.createObjectURL(o,{oneTimeOnly:!0})}catch(i){e=t.createObjectURL(o)}}e&&(i.src=e)};if(e.IsUASupportingBlobStorage){var o,s=new XMLHttpRequest;s.open("GET",t,!0),s.responseType="blob",s.addEventListener("load",function(){if(200===s.status&&r.db){o=s.response;var a=r.db.transaction(["textures"],"readwrite");a.onabort=function(e){try{var t=(e.srcElement||e.target).error;t&&"QuotaExceededError"===t.name&&(r.hasReachedQuota=!0)}catch(e){}n()},a.oncomplete=function(e){n()};var h={textureUrl:t,data:o};try{var l=a.objectStore("textures").put(h);l.onsuccess=function(e){},l.onerror=function(e){n()}}catch(r){25===r.code&&(e.IsUASupportingBlobStorage=!1),i.src=t}}else i.src=t},!1),s.addEventListener("error",function(e){Ri.Tools.Error("Error in XHR request in BABYLON.Database."),i.src=t},!1),s.send()}else i.src=t}else Ri.Tools.Error("Error: IndexedDB not supported by your browser or BabylonJS Database is not open."),i.src=t},e.prototype._checkVersionFromDB=function(e,t){var i=this;this._loadVersionFromDBAsync(e,t,function(){i._saveVersionIntoDBAsync(e,t)})},e.prototype._loadVersionFromDBAsync=function(e,t,i){var r,n=this;if(this.isSupported&&this.db)try{var o=this.db.transaction(["versions"]);o.oncomplete=function(e){r?n.manifestVersionFound>r.data?(n.mustUpdateRessources=!0,i()):t(r.data):(n.mustUpdateRessources=!0,i())},o.onabort=function(e){t(-1)};var s=o.objectStore("versions").get(e);s.onsuccess=function(e){r=e.target.result},s.onerror=function(i){Ri.Tools.Error("Error loading version for scene "+e+" from DB."),t(-1)}}catch(e){Ri.Tools.Error("Error while accessing 'versions' object store (READ OP). Exception: "+e.message),t(-1)}else Ri.Tools.Error("Error: IndexedDB not supported by your browser or BabylonJS Database is not open."),t(-1)},e.prototype._saveVersionIntoDBAsync=function(e,t){var i=this;if(this.isSupported&&!this.hasReachedQuota&&this.db)try{var r=this.db.transaction(["versions"],"readwrite");r.onabort=function(e){try{var r=e.srcElement.error;r&&"QuotaExceededError"===r.name&&(i.hasReachedQuota=!0)}catch(e){}t(-1)},r.oncomplete=function(e){t(i.manifestVersionFound)};var n={sceneUrl:e,data:this.manifestVersionFound},o=r.objectStore("versions").put(n);o.onsuccess=function(e){},o.onerror=function(e){Ri.Tools.Error("Error in DB add version request in BABYLON.Database.")}}catch(e){Ri.Tools.Error("Error while accessing 'versions' object store (WRITE OP). Exception: "+e.message),t(-1)}else t(-1)},e.prototype.loadFileFromDB=function(t,i,r,n,o){var s=this,a=e.ReturnFullUrlLocation(t),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()})},e.prototype._loadFileFromDBAsync=function(e,t,i,r){if(this.isSupported&&this.db){var n,o;n=-1!==e.indexOf(".babylon")?"scenes":"textures";var s=this.db.transaction([n]);s.oncomplete=function(e){o?t(o.data):i()},s.onabort=function(e){i()};var a=s.objectStore(n).get(e);a.onsuccess=function(e){o=e.target.result},a.onerror=function(t){Ri.Tools.Error("Error loading file "+e+" from DB."),i()}}else Ri.Tools.Error("Error: IndexedDB not supported by your browser or BabylonJS Database is not open."),t()},e.prototype._saveFileIntoDBAsync=function(e,t,i,r){var n=this;if(this.isSupported){var o;o=-1!==e.indexOf(".babylon")?"scenes":"textures";var s,a=new XMLHttpRequest;a.open("GET",e,!0),r&&(a.responseType="arraybuffer"),i&&(a.onprogress=i),a.addEventListener("load",function(){if(200===a.status||Ri.Tools.ValidateXHRData(a,r?6:1))if(s=r?a.response:a.responseText,!n.hasReachedQuota&&n.db){var i,h=n.db.transaction([o],"readwrite");h.onabort=function(e){try{var i=e.srcElement.error;i&&"QuotaExceededError"===i.name&&(n.hasReachedQuota=!0)}catch(e){}t(s)},h.oncomplete=function(e){t(s)},i="scenes"===o?{sceneUrl:e,data:s,version:n.manifestVersionFound}:{textureUrl:e,data:s};try{var l=h.objectStore(o).put(i);l.onsuccess=function(e){},l.onerror=function(e){Ri.Tools.Error("Error in DB add file request in BABYLON.Database.")}}catch(e){t(s)}}else t(s);else t()},!1),a.addEventListener("error",function(e){Ri.Tools.Error("error on XHR request."),t()},!1),a.send()}else Ri.Tools.Error("Error: IndexedDB not supported by your browser or BabylonJS Database is not open."),t()},e.IsUASupportingBlobStorage=!0,e.IDBStorageEnabled=!0,e.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))},e.ReturnFullUrlLocation=function(t){return-1===t.indexOf("http:/")&&-1===t.indexOf("https:/")?e.parseURL(window.location.href)+t:t},e}(),Ri.Database=Oi,Ii=us||(us={}),wi=function(){function e(){this._isEnabled=!0,this.leftColor=Ii.Color3.White(),this.rightColor=Ii.Color3.Black(),this.bias=0,this.power=1}return Object.defineProperty(e.prototype,"isEnabled",{get:function(){return this._isEnabled},set:function(e){this._isEnabled!==e&&(this._isEnabled=e,Ii.Engine.MarkAllMaterialsAsDirty(Ii.Material.FresnelDirtyFlag))},enumerable:!0,configurable:!0}),e.prototype.clone=function(){var t=new e;return Ii.Tools.DeepCopy(this,t),t},e.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},e.Parse=function(t){var i=new e;return i.isEnabled=t.isEnabled,i.leftColor=Ii.Color3.FromArray(t.leftColor),i.rightColor=Ii.Color3.FromArray(t.rightColor),i.bias=t.bias,i.power=t.power||1,i},e}(),Ii.FresnelParameters=wi,Di=us||(us={}),Li=function(e){function t(t,i){var r=e.call(this,t,i,!0)||this;return i.multiMaterials.push(r),r.subMaterials=new Array,r.storeEffectOnSubMeshes=!0,r}return Y(t,e),Object.defineProperty(t.prototype,"subMaterials",{get:function(){return this._subMaterials},set:function(e){this._subMaterials=e,this._hookArray(e)},enumerable:!0,configurable:!0}),t.prototype._hookArray=function(e){var t=this,i=e.push;e.push=function(){for(var r=[],n=0;n<arguments.length;n++)r[n]=arguments[n];var o=i.apply(e,r);return t._markAllSubMeshesAsTexturesDirty(),o};var r=e.splice;e.splice=function(i,n){var o=r.apply(e,[i,n]);return t._markAllSubMeshesAsTexturesDirty(),o}},t.prototype.getSubMaterial=function(e){return e<0||e>=this.subMaterials.length?this.getScene().defaultMaterial:this.subMaterials[e]},t.prototype.getActiveTextures=function(){return(t=e.prototype.getActiveTextures.call(this)).concat.apply(t,this.subMaterials.map(function(e){return e?e.getActiveTextures():[]}));var t},t.prototype.getClassName=function(){return"MultiMaterial"},t.prototype.isReadyForSubMesh=function(e,t,i){for(var r=0;r<this.subMaterials.length;r++){var n=this.subMaterials[r];if(n){if(n.storeEffectOnSubMeshes){if(!n.isReadyForSubMesh(e,t,i))return!1;continue}if(!n.isReady(e))return!1}}return!0},t.prototype.clone=function(e,i){for(var r=new t(e,this.getScene()),n=0;n<this.subMaterials.length;n++){var o=null,s=this.subMaterials[n];o=i&&s?s.clone(e+"-"+s.name):this.subMaterials[n],r.subMaterials.push(o)}return r},t.prototype.serialize=function(){var e={};e.name=this.name,e.id=this.id,Di.Tags&&(e.tags=Di.Tags.GetTags(this)),e.materials=[];for(var t=0;t<this.subMaterials.length;t++){var i=this.subMaterials[t];i?e.materials.push(i.id):e.materials.push(null)}return e},t.prototype.dispose=function(t,i){var r=this.getScene();if(r){var n=r.multiMaterials.indexOf(this);n>=0&&r.multiMaterials.splice(n,1),e.prototype.dispose.call(this,t,i)}},t}(Di.Material),Di.MultiMaterial=Li,Bi=us||(us={}),Ni=function(){function e(){this._offsetX=null,this._offsetY=null,this._pointerPressed=new Array,this.touchAngularSensibility=2e5,this.touchMoveSensibility=250}return e.prototype.attachControl=function(e,t){var i=this,r=null;void 0===this._pointerInput&&(this._onLostFocus=function(e){i._offsetX=null,i._offsetY=null},this._pointerInput=function(e,n){var o=e.event;if("mouse"!==o.pointerType)if(e.type===Bi.PointerEventTypes.POINTERDOWN){if(t||o.preventDefault(),i._pointerPressed.push(o.pointerId),1!==i._pointerPressed.length)return;r={x:o.clientX,y:o.clientY}}else if(e.type===Bi.PointerEventTypes.POINTERUP){if(t||o.preventDefault(),-1===(s=i._pointerPressed.indexOf(o.pointerId)))return;if(i._pointerPressed.splice(s,1),0!=s)return;r=null,i._offsetX=null,i._offsetY=null}else if(e.type===Bi.PointerEventTypes.POINTERMOVE){if(t||o.preventDefault(),!r)return;var s;if(0!=(s=i._pointerPressed.indexOf(o.pointerId)))return;i._offsetX=o.clientX-r.x,i._offsetY=-(o.clientY-r.y)}}),this._observer=this.camera.getScene().onPointerObservable.add(this._pointerInput,Bi.PointerEventTypes.POINTERDOWN|Bi.PointerEventTypes.POINTERUP|Bi.PointerEventTypes.POINTERMOVE),this._onLostFocus&&e.addEventListener("blur",this._onLostFocus)},e.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)},e.prototype.checkInputs=function(){if(this._offsetX&&this._offsetY){var e=this.camera;if(e.cameraRotation.y+=this._offsetX/this.touchAngularSensibility,this._pointerPressed.length>1)e.cameraRotation.x+=-this._offsetY/this.touchAngularSensibility;else{var t=e._computeLocalCameraSpeed(),i=new Bi.Vector3(0,0,t*this._offsetY/this.touchMoveSensibility);Bi.Matrix.RotationYawPitchRollToRef(e.rotation.y,e.rotation.x,0,e._cameraRotationMatrix),e.cameraDirection.addInPlace(Bi.Vector3.TransformCoordinates(i,e._cameraRotationMatrix))}}},e.prototype.getClassName=function(){return"FreeCameraTouchInput"},e.prototype.getSimpleName=function(){return"touch"},X([Bi.serialize()],e.prototype,"touchAngularSensibility",void 0),X([Bi.serialize()],e.prototype,"touchMoveSensibility",void 0),e}(),Bi.FreeCameraTouchInput=Ni,Bi.CameraInputTypes.FreeCameraTouchInput=Ni,Fi=us||(us={}),Vi=function(e){function t(t,i,r){var n=e.call(this,t,i,r)||this;return n.inputs.addTouch(),n._setupInputs(),n}return Y(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}(Fi.FreeCamera),Fi.TouchCamera=Vi,ki=us||(us={}),Ui=function(e){function t(t,i,r,n,o,s,a){void 0===o&&(o=null),void 0===s&&(s=!0),void 0===a&&(a=!1);var h=e.call(this,null,n,!s)||this;h.isCube=a,h.isEnabled=!0,h._currentRefreshId=-1,h._refreshRate=1,h._vertexBuffers={},h._uniforms=new Array,h._samplers=new Array,h._textures={},h._floats={},h._floatsArrays={},h._colors3={},h._colors4={},h._vectors2={},h._vectors3={},h._matrices={},h._fallbackTextureUsed=!1,n._proceduralTextures.push(h),h._engine=n.getEngine(),h.name=t,h.isRenderTarget=!0,h._size=i,h._generateMipMaps=s,h.setFragment(r),h._fallbackTexture=o,a?(h._texture=h._engine.createRenderTargetCubeTexture(i,{generateMipMaps:s}),h.setFloat("face",0)):h._texture=h._engine.createRenderTargetTexture(i,s);var l=[];return l.push(1,1),l.push(-1,1),l.push(-1,-1),l.push(1,-1),h._vertexBuffers[ki.VertexBuffer.PositionKind]=new ki.VertexBuffer(h._engine,l,ki.VertexBuffer.PositionKind,!1,!1,2),h._createIndexBuffer(),h}return Y(t,e),t.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)},t.prototype._rebuild=function(){var e=this._vertexBuffers[ki.VertexBuffer.PositionKind];e&&e._rebuild(),this._createIndexBuffer(),this.refreshRate===ki.RenderTargetTexture.REFRESHRATE_RENDER_ONCE&&(this.refreshRate=ki.RenderTargetTexture.REFRESHRATE_RENDER_ONCE)},t.prototype.reset=function(){void 0!==this._effect&&this._engine._releaseEffect(this._effect)},t.prototype.isReady=function(){var e,t=this,i=this._engine;return!!this._fragment&&(!!this._fallbackTextureUsed||(e=void 0!==this._fragment.fragmentElement?{vertex:"procedural",fragmentElement:this._fragment.fragmentElement}:{vertex:"procedural",fragment:this._fragment},this._effect=i.createEffect(e,[ki.VertexBuffer.PositionKind],this._uniforms,this._samplers,"",void 0,void 0,function(){t.releaseInternalTexture(),t._fallbackTexture&&(t._texture=t._fallbackTexture._texture,t._texture&&t._texture.incrementReferences()),t._fallbackTextureUsed=!0}),this._effect.isReady()))},t.prototype.resetRefreshCounter=function(){this._currentRefreshId=-1},t.prototype.setFragment=function(e){this._fragment=e},Object.defineProperty(t.prototype,"refreshRate",{get:function(){return this._refreshRate},set:function(e){this._refreshRate=e,this.resetRefreshCounter()},enumerable:!0,configurable:!0}),t.prototype._shouldRender=function(){return!!(this.isEnabled&&this.isReady()&&this._texture)&&(!this._fallbackTextureUsed&&(-1===this._currentRefreshId?(this._currentRefreshId=1,!0):this.refreshRate===this._currentRefreshId?(this._currentRefreshId=1,!0):(this._currentRefreshId++,!1)))},t.prototype.getRenderSize=function(){return this._size},t.prototype.resize=function(e,t){this._fallbackTextureUsed||(this.releaseInternalTexture(),this._texture=this._engine.createRenderTargetTexture(e,t))},t.prototype._checkUniform=function(e){-1===this._uniforms.indexOf(e)&&this._uniforms.push(e)},t.prototype.setTexture=function(e,t){return-1===this._samplers.indexOf(e)&&this._samplers.push(e),this._textures[e]=t,this},t.prototype.setFloat=function(e,t){return this._checkUniform(e),this._floats[e]=t,this},t.prototype.setFloats=function(e,t){return this._checkUniform(e),this._floatsArrays[e]=t,this},t.prototype.setColor3=function(e,t){return this._checkUniform(e),this._colors3[e]=t,this},t.prototype.setColor4=function(e,t){return this._checkUniform(e),this._colors4[e]=t,this},t.prototype.setVector2=function(e,t){return this._checkUniform(e),this._vectors2[e]=t,this},t.prototype.setVector3=function(e,t){return this._checkUniform(e),this._vectors3[e]=t,this},t.prototype.setMatrix=function(e,t){return this._checkUniform(e),this._matrices[e]=t,this},t.prototype.render=function(e){var t=this.getScene();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.drawElementsType(ki.Material.TriangleFillMode,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.drawElementsType(ki.Material.TriangleFillMode,0,6);i.unBindFramebuffer(this._texture,this.isCube),this.onGenerated&&this.onGenerated()}}},t.prototype.clone=function(){var e=this.getSize(),i=new t(this.name,e.width,this._fragment,this.getScene(),this._fallbackTexture,this._generateMipMaps);return i.hasAlpha=this.hasAlpha,i.level=this.level,i.coordinatesMode=this.coordinatesMode,i},t.prototype.dispose=function(){var t=this.getScene();if(t){var i=t._proceduralTextures.indexOf(this);i>=0&&t._proceduralTextures.splice(i,1);var r=this._vertexBuffers[ki.VertexBuffer.PositionKind];r&&(r.dispose(),this._vertexBuffers[ki.VertexBuffer.PositionKind]=null),this._indexBuffer&&this._engine._releaseBuffer(this._indexBuffer)&&(this._indexBuffer=null),e.prototype.dispose.call(this)}},t}(ki.Texture),ki.ProceduralTexture=Ui,zi=us||(us={}),Gi=function(e){function t(t,i,r,n,o,s){var a=e.call(this,t,r,null,n,o,s)||this;return a._animate=!0,a._time=0,a._texturePath=i,a.loadJson(i),a.refreshRate=1,a}return Y(t,e),t.prototype.loadJson=function(e){var t=this,i=function(){zi.Tools.Log("No config file found in "+e+" trying to use ShadersStore or DOM element");try{t.setFragment(t._texturePath)}catch(e){zi.Tools.Error("No json or ShaderStore or DOM element found for CustomProceduralTexture")}},r=e+"/config.json",n=new XMLHttpRequest;n.open("GET",r,!0),n.addEventListener("load",function(){if(200===n.status||zi.Tools.ValidateXHRData(n,1))try{t._config=JSON.parse(n.response),t.updateShaderUniforms(),t.updateTextures(),t.setFragment(t._texturePath+"/custom"),t._animate=t._config.animate,t.refreshRate=t._config.refreshrate}catch(e){i()}else i()},!1),n.addEventListener("error",function(){i()},!1);try{n.send()}catch(e){zi.Tools.Error("CustomProceduralTexture: Error on XHR send request.")}},t.prototype.isReady=function(){if(!e.prototype.isReady.call(this))return!1;for(var t in this._textures){if(!this._textures[t].isReady())return!1}return!0},t.prototype.render=function(t){var i=this.getScene();this._animate&&i&&(this._time+=.03*i.getAnimationRatio(),this.updateShaderUniforms()),e.prototype.render.call(this,t)},t.prototype.updateTextures=function(){for(var e=0;e<this._config.sampler2Ds.length;e++)this.setTexture(this._config.sampler2Ds[e].sample2Dname,new zi.Texture(this._texturePath+"/"+this._config.sampler2Ds[e].textureRelativeUrl,this.getScene()))},t.prototype.updateShaderUniforms=function(){if(this._config)for(var e=0;e<this._config.uniforms.length;e++){var t=this._config.uniforms[e];switch(t.type){case"float":this.setFloat(t.name,t.value);break;case"color3":this.setColor3(t.name,new zi.Color3(t.r,t.g,t.b));break;case"color4":this.setColor4(t.name,new zi.Color4(t.r,t.g,t.b,t.a));break;case"vector2":this.setVector2(t.name,new zi.Vector2(t.x,t.y));break;case"vector3":this.setVector3(t.name,new zi.Vector3(t.x,t.y,t.z))}}this.setFloat("time",this._time)},Object.defineProperty(t.prototype,"animate",{get:function(){return this._animate},set:function(e){this._animate=e},enumerable:!0,configurable:!0}),t}(zi.ProceduralTexture),zi.CustomProceduralTexture=Gi,Wi=us||(us={}),Hi=function(){function e(){this.gamepadAngularSensibility=200,this.gamepadMoveSensibility=40,this._cameraTransform=Wi.Matrix.Identity(),this._deltaTransform=Wi.Vector3.Zero(),this._vector3=Wi.Vector3.Zero(),this._vector2=Wi.Vector2.Zero()}return e.prototype.attachControl=function(e,t){var i=this,r=this.camera.getScene().gamepadManager;this._onGamepadConnectedObserver=r.onGamepadConnectedObservable.add(function(e){e.type!==Wi.Gamepad.POSE_ENABLED&&(i.gamepad&&e.type!==Wi.Gamepad.XBOX||(i.gamepad=e))}),this._onGamepadDisconnectedObserver=r.onGamepadDisconnectedObservable.add(function(e){i.gamepad===e&&(i.gamepad=null)}),this.gamepad=r.getGamepadByType(Wi.Gamepad.XBOX)},e.prototype.detachControl=function(e){this.camera.getScene().gamepadManager.onGamepadConnectedObservable.remove(this._onGamepadConnectedObserver),this.camera.getScene().gamepadManager.onGamepadDisconnectedObservable.remove(this._onGamepadDisconnectedObserver),this.gamepad=null},e.prototype.checkInputs=function(){if(this.gamepad&&this.gamepad.leftStick){var e=this.camera,t=this.gamepad.leftStick,i=t.x/this.gamepadMoveSensibility,r=t.y/this.gamepadMoveSensibility;t.x=Math.abs(i)>.005?0+i:0,t.y=Math.abs(r)>.005?0+r:0;var n=this.gamepad.rightStick;if(n){var o=n.x/this.gamepadAngularSensibility,s=n.y/this.gamepadAngularSensibility;n.x=Math.abs(o)>.001?0+o:0,n.y=Math.abs(s)>.001?0+s:0}else n={x:0,y:0};e.rotationQuaternion?e.rotationQuaternion.toRotationMatrix(this._cameraTransform):Wi.Matrix.RotationYawPitchRollToRef(e.rotation.y,e.rotation.x,0,this._cameraTransform);var a=50*e._computeLocalCameraSpeed();this._vector3.copyFromFloats(t.x*a,0,-t.y*a),Wi.Vector3.TransformCoordinatesToRef(this._vector3,this._cameraTransform,this._deltaTransform),e.cameraDirection.addInPlace(this._deltaTransform),this._vector2.copyFromFloats(n.y,n.x),e.cameraRotation.addInPlace(this._vector2)}},e.prototype.getClassName=function(){return"FreeCameraGamepadInput"},e.prototype.getSimpleName=function(){return"gamepad"},X([Wi.serialize()],e.prototype,"gamepadAngularSensibility",void 0),X([Wi.serialize()],e.prototype,"gamepadMoveSensibility",void 0),e}(),Wi.FreeCameraGamepadInput=Hi,Wi.CameraInputTypes.FreeCameraGamepadInput=Hi,ji=us||(us={}),Xi=function(){function e(){this.gamepadRotationSensibility=80,this.gamepadMoveSensibility=40}return e.prototype.attachControl=function(e,t){var i=this,r=this.camera.getScene().gamepadManager;this._onGamepadConnectedObserver=r.onGamepadConnectedObservable.add(function(e){e.type!==ji.Gamepad.POSE_ENABLED&&(i.gamepad&&e.type!==ji.Gamepad.XBOX||(i.gamepad=e))}),this._onGamepadDisconnectedObserver=r.onGamepadDisconnectedObservable.add(function(e){i.gamepad===e&&(i.gamepad=null)}),this.gamepad=r.getGamepadByType(ji.Gamepad.XBOX)},e.prototype.detachControl=function(e){this.camera.getScene().gamepadManager.onGamepadConnectedObservable.remove(this._onGamepadConnectedObserver),this.camera.getScene().gamepadManager.onGamepadDisconnectedObservable.remove(this._onGamepadDisconnectedObserver),this.gamepad=null},e.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)}}},e.prototype.getClassName=function(){return"ArcRotateCameraGamepadInput"},e.prototype.getSimpleName=function(){return"gamepad"},X([ji.serialize()],e.prototype,"gamepadRotationSensibility",void 0),X([ji.serialize()],e.prototype,"gamepadMoveSensibility",void 0),e}(),ji.ArcRotateCameraGamepadInput=Xi,ji.CameraInputTypes.ArcRotateCameraGamepadInput=Xi,Yi=us||(us={}),Ki=function(){function e(e){var t=this;this._scene=e,this._babylonGamepads=[],this._oneGamepadConnected=!1,this._isMonitoring=!1,this.onGamepadDisconnectedObservable=new Yi.Observable,Yi.Tools.IsWindowObjectExist()?(this._gamepadEventSupported="GamepadEvent"in window,this._gamepadSupport=navigator.getGamepads||navigator.webkitGetGamepads||navigator.msGetGamepads||navigator.webkitGamepads):this._gamepadEventSupported=!1,this.onGamepadConnectedObservable=new Yi.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,r=e.gamepad;r.index in t._babylonGamepads&&t._babylonGamepads[r.index].isConnected||(t._babylonGamepads[r.index]?((i=t._babylonGamepads[r.index]).browserGamepad=r,i._isConnected=!0):i=t._addNewGamepad(r),t.onGamepadConnectedObservable.notifyObservers(i),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(e.prototype,"gamepads",{get:function(){return this._babylonGamepads},enumerable:!0,configurable:!0}),e.prototype.getGamepadByType=function(e){void 0===e&&(e=Yi.Gamepad.XBOX);for(var t=0,i=this._babylonGamepads;t<i.length;t++){var r=i[t];if(r&&r.type===e)return r}return null},e.prototype.dispose=function(){this._gamepadEventSupported&&(this._onGamepadConnectedEvent&&window.removeEventListener("gamepadconnected",this._onGamepadConnectedEvent),this._onGamepadDisconnectedEvent&&window.removeEventListener("gamepaddisconnected",this._onGamepadDisconnectedEvent),this._onGamepadConnectedEvent=null,this._onGamepadDisconnectedEvent=null),this._babylonGamepads.forEach(function(e){e.dispose()}),this.onGamepadConnectedObservable.clear(),this.onGamepadDisconnectedObservable.clear(),this._oneGamepadConnected=!1,this._stopMonitoringGamepads(),this._babylonGamepads=[]},e.prototype._addNewGamepad=function(e){var t;this._oneGamepadConnected||(this._oneGamepadConnected=!0);var i=-1!==e.id.search("Xbox One");return t=i||-1!==e.id.search("Xbox 360")||-1!==e.id.search("xinput")?new Yi.Xbox360Pad(e.id,e.index,e,i):e.pose?Yi.PoseEnabledControllerHelper.InitiateController(e):new Yi.GenericPad(e.id,e.index,e),this._babylonGamepads[t.index]=t,t},e.prototype._startMonitoringGamepads=function(){this._isMonitoring||(this._isMonitoring=!0,this._scene||this._checkGamepadsStatus())},e.prototype._stopMonitoringGamepads=function(){this._isMonitoring=!1},e.prototype._checkGamepadsStatus=function(){var e=this;this._updateGamepadObjects();for(var t in this._babylonGamepads){var i=this._babylonGamepads[t];i&&i.isConnected&&i.update()}this._isMonitoring&&!this._scene&&Yi.Tools.QueueNewFrame(function(){e._checkGamepadsStatus()})},e.prototype._updateGamepadObjects=function(){for(var e=navigator.getGamepads?navigator.getGamepads():navigator.webkitGetGamepads?navigator.webkitGetGamepads():[],t=0;t<e.length;t++)if(e[t])if(this._babylonGamepads[e[t].index])this._babylonGamepads[t].browserGamepad=e[t],this._babylonGamepads[t].isConnected||(this._babylonGamepads[t]._isConnected=!0,this.onGamepadConnectedObservable.notifyObservers(this._babylonGamepads[t]));else{var i=this._addNewGamepad(e[t]);this.onGamepadConnectedObservable.notifyObservers(i)}},e}(),Yi.GamepadManager=Ki,function(e){var t=function(){return function(e,t){this.x=e,this.y=t}}();e.StickValues=t;var i=function(){function e(t,i,r,n,o,s,a){void 0===n&&(n=0),void 0===o&&(o=1),void 0===s&&(s=2),void 0===a&&(a=3),this.id=t,this.index=i,this.browserGamepad=r,this._isConnected=!0,this._invertLeftStickY=!1,this.type=e.GAMEPAD,this._leftStickAxisX=n,this._leftStickAxisY=o,this._rightStickAxisX=s,this._rightStickAxisY=a,this.browserGamepad.axes.length>=2&&(this._leftStick={x:this.browserGamepad.axes[this._leftStickAxisX],y:this.browserGamepad.axes[this._leftStickAxisY]}),this.browserGamepad.axes.length>=4&&(this._rightStick={x:this.browserGamepad.axes[this._rightStickAxisX],y:this.browserGamepad.axes[this._rightStickAxisY]})}return Object.defineProperty(e.prototype,"isConnected",{get:function(){return this._isConnected},enumerable:!0,configurable:!0}),e.prototype.onleftstickchanged=function(e){this._onleftstickchanged=e},e.prototype.onrightstickchanged=function(e){this._onrightstickchanged=e},Object.defineProperty(e.prototype,"leftStick",{get:function(){return this._leftStick},set:function(e){!this._onleftstickchanged||this._leftStick.x===e.x&&this._leftStick.y===e.y||this._onleftstickchanged(e),this._leftStick=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rightStick",{get:function(){return this._rightStick},set:function(e){!this._onrightstickchanged||this._rightStick.x===e.x&&this._rightStick.y===e.y||this._onrightstickchanged(e),this._rightStick=e},enumerable:!0,configurable:!0}),e.prototype.update=function(){this._leftStick&&(this.leftStick={x:this.browserGamepad.axes[this._leftStickAxisX],y:this.browserGamepad.axes[this._leftStickAxisY]},this._invertLeftStickY&&(this.leftStick.y*=-1)),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 Y(r,t),r.prototype.onbuttondown=function(e){this._onbuttondown=e},r.prototype.onbuttonup=function(e){this._onbuttonup=e},r.prototype._setButtonValue=function(e,t,i){return e!==t&&(1===e&&(this._onbuttondown&&this._onbuttondown(i),this.onButtonDownObservable.notifyObservers(i)),0===e&&(this._onbuttonup&&this._onbuttonup(i),this.onButtonUpObservable.notifyObservers(i))),e},r.prototype.update=function(){t.prototype.update.call(this);for(var e=0;e<this._buttons.length;e++)this._buttons[e]=this._setButtonValue(this.browserGamepad.buttons[e].value,this._buttons[e],e)},r.prototype.dispose=function(){t.prototype.dispose.call(this),this.onButtonDownObservable.clear(),this.onButtonUpObservable.clear()},r}(i);e.GenericPad=r}(us||(us={})),function(e){var t,i,r,n;(i=t=e.Xbox360Button||(e.Xbox360Button={}))[i.A=0]="A",i[i.B=1]="B",i[i.X=2]="X",i[i.Y=3]="Y",i[i.Start=4]="Start",i[i.Back=5]="Back",i[i.LB=6]="LB",i[i.RB=7]="RB",i[i.LeftStick=8]="LeftStick",i[i.RightStick=9]="RightStick",(n=r=e.Xbox360Dpad||(e.Xbox360Dpad={}))[n.Up=0]="Up",n[n.Down=1]="Down",n[n.Left=2]="Left",n[n.Right=3]="Right";var o=function(i){function n(t,r,n,o){void 0===o&&(o=!1);var s=i.call(this,t,r,n,0,1,2,3)||this;return s._leftTrigger=0,s._rightTrigger=0,s.onButtonDownObservable=new e.Observable,s.onButtonUpObservable=new e.Observable,s.onPadDownObservable=new e.Observable,s.onPadUpObservable=new e.Observable,s._buttonA=0,s._buttonB=0,s._buttonX=0,s._buttonY=0,s._buttonBack=0,s._buttonStart=0,s._buttonLB=0,s._buttonRB=0,s._buttonLeftStick=0,s._buttonRightStick=0,s._dPadUp=0,s._dPadDown=0,s._dPadLeft=0,s._dPadRight=0,s._isXboxOnePad=!1,s.type=e.Gamepad.XBOX,s._isXboxOnePad=o,s}return Y(n,i),n.prototype.onlefttriggerchanged=function(e){this._onlefttriggerchanged=e},n.prototype.onrighttriggerchanged=function(e){this._onrighttriggerchanged=e},Object.defineProperty(n.prototype,"leftTrigger",{get:function(){return this._leftTrigger},set:function(e){this._onlefttriggerchanged&&this._leftTrigger!==e&&this._onlefttriggerchanged(e),this._leftTrigger=e},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"rightTrigger",{get:function(){return this._rightTrigger},set:function(e){this._onrighttriggerchanged&&this._rightTrigger!==e&&this._onrighttriggerchanged(e),this._rightTrigger=e},enumerable:!0,configurable:!0}),n.prototype.onbuttondown=function(e){this._onbuttondown=e},n.prototype.onbuttonup=function(e){this._onbuttonup=e},n.prototype.ondpaddown=function(e){this._ondpaddown=e},n.prototype.ondpadup=function(e){this._ondpadup=e},n.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},n.prototype._setDPadValue=function(e,t,i){return e!==t&&(1===e&&(this._ondpaddown&&this._ondpaddown(i),this.onPadDownObservable.notifyObservers(i)),0===e&&(this._ondpadup&&this._ondpadup(i),this.onPadUpObservable.notifyObservers(i))),e},Object.defineProperty(n.prototype,"buttonA",{get:function(){return this._buttonA},set:function(e){this._buttonA=this._setButtonValue(e,this._buttonA,t.A)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"buttonB",{get:function(){return this._buttonB},set:function(e){this._buttonB=this._setButtonValue(e,this._buttonB,t.B)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"buttonX",{get:function(){return this._buttonX},set:function(e){this._buttonX=this._setButtonValue(e,this._buttonX,t.X)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"buttonY",{get:function(){return this._buttonY},set:function(e){this._buttonY=this._setButtonValue(e,this._buttonY,t.Y)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"buttonStart",{get:function(){return this._buttonStart},set:function(e){this._buttonStart=this._setButtonValue(e,this._buttonStart,t.Start)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"buttonBack",{get:function(){return this._buttonBack},set:function(e){this._buttonBack=this._setButtonValue(e,this._buttonBack,t.Back)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"buttonLB",{get:function(){return this._buttonLB},set:function(e){this._buttonLB=this._setButtonValue(e,this._buttonLB,t.LB)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"buttonRB",{get:function(){return this._buttonRB},set:function(e){this._buttonRB=this._setButtonValue(e,this._buttonRB,t.RB)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"buttonLeftStick",{get:function(){return this._buttonLeftStick},set:function(e){this._buttonLeftStick=this._setButtonValue(e,this._buttonLeftStick,t.LeftStick)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"buttonRightStick",{get:function(){return this._buttonRightStick},set:function(e){this._buttonRightStick=this._setButtonValue(e,this._buttonRightStick,t.RightStick)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"dPadUp",{get:function(){return this._dPadUp},set:function(e){this._dPadUp=this._setDPadValue(e,this._dPadUp,r.Up)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"dPadDown",{get:function(){return this._dPadDown},set:function(e){this._dPadDown=this._setDPadValue(e,this._dPadDown,r.Down)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"dPadLeft",{get:function(){return this._dPadLeft},set:function(e){this._dPadLeft=this._setDPadValue(e,this._dPadLeft,r.Left)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"dPadRight",{get:function(){return this._dPadRight},set:function(e){this._dPadRight=this._setDPadValue(e,this._dPadRight,r.Right)},enumerable:!0,configurable:!0}),n.prototype.update=function(){i.prototype.update.call(this),this._isXboxOnePad?(this.buttonA=this.browserGamepad.buttons[0].value,this.buttonB=this.browserGamepad.buttons[1].value,this.buttonX=this.browserGamepad.buttons[2].value,this.buttonY=this.browserGamepad.buttons[3].value,this.buttonLB=this.browserGamepad.buttons[4].value,this.buttonRB=this.browserGamepad.buttons[5].value,this.leftTrigger=this.browserGamepad.axes[2],this.rightTrigger=this.browserGamepad.axes[5],this.buttonBack=this.browserGamepad.buttons[9].value,this.buttonStart=this.browserGamepad.buttons[8].value,this.buttonLeftStick=this.browserGamepad.buttons[6].value,this.buttonRightStick=this.browserGamepad.buttons[7].value,this.dPadUp=this.browserGamepad.buttons[11].value,this.dPadDown=this.browserGamepad.buttons[12].value,this.dPadLeft=this.browserGamepad.buttons[13].value,this.dPadRight=this.browserGamepad.buttons[14].value):(this.buttonA=this.browserGamepad.buttons[0].value,this.buttonB=this.browserGamepad.buttons[1].value,this.buttonX=this.browserGamepad.buttons[2].value,this.buttonY=this.browserGamepad.buttons[3].value,this.buttonLB=this.browserGamepad.buttons[4].value,this.buttonRB=this.browserGamepad.buttons[5].value,this.leftTrigger=this.browserGamepad.buttons[6].value,this.rightTrigger=this.browserGamepad.buttons[7].value,this.buttonBack=this.browserGamepad.buttons[8].value,this.buttonStart=this.browserGamepad.buttons[9].value,this.buttonLeftStick=this.browserGamepad.buttons[10].value,this.buttonRightStick=this.browserGamepad.buttons[11].value,this.dPadUp=this.browserGamepad.buttons[12].value,this.dPadDown=this.browserGamepad.buttons[13].value,this.dPadLeft=this.browserGamepad.buttons[14].value,this.dPadRight=this.browserGamepad.buttons[15].value)},n.prototype.dispose=function(){i.prototype.dispose.call(this),this.onButtonDownObservable.clear(),this.onButtonUpObservable.clear(),this.onPadDownObservable.clear(),this.onPadUpObservable.clear()},n}(e.Gamepad);e.Xbox360Pad=o}(us||(us={})),function(e){var t,i;(i=t=e.PoseEnabledControllerType||(e.PoseEnabledControllerType={}))[i.VIVE=0]="VIVE",i[i.OCULUS=1]="OCULUS",i[i.WINDOWS=2]="WINDOWS",i[i.GEAR_VR=3]="GEAR_VR",i[i.GENERIC=4]="GENERIC";var r=function(){function t(){}return t.InitiateController=function(t){return-1!==t.id.indexOf("Oculus Touch")?new e.OculusTouchController(t):0===t.id.indexOf(e.WindowsMotionController.GAMEPAD_ID_PREFIX)?new e.WindowsMotionController(t):-1!==t.id.toLowerCase().indexOf("openvr")?new e.ViveController(t):0===t.id.indexOf(e.GearVRController.GAMEPAD_ID_PREFIX)?new e.GearVRController(t):new e.GenericController(t)},t}();e.PoseEnabledControllerHelper=r;var n=function(i){function r(r){var n=i.call(this,r.id,r.index,r)||this;return n._deviceRoomPosition=e.Vector3.Zero(),n._deviceRoomRotationQuaternion=new e.Quaternion,n.devicePosition=e.Vector3.Zero(),n.deviceRotationQuaternion=new e.Quaternion,n.deviceScaleFactor=1,n._leftHandSystemQuaternion=new e.Quaternion,n._deviceToWorld=e.Matrix.Identity(),n._workingMatrix=e.Matrix.Identity(),n.type=e.Gamepad.POSE_ENABLED,n.controllerType=t.GENERIC,n.position=e.Vector3.Zero(),n.rotationQuaternion=new e.Quaternion,n._calculatedPosition=e.Vector3.Zero(),n._calculatedRotation=new e.Quaternion,e.Quaternion.RotationYawPitchRollToRef(Math.PI,0,0,n._leftHandSystemQuaternion),n}return Y(r,i),r.prototype.update=function(){i.prototype.update.call(this);var t=this.browserGamepad.pose;this.updateFromDevice(t),e.Vector3.TransformCoordinatesToRef(this._calculatedPosition,this._deviceToWorld,this.devicePosition),this._deviceToWorld.getRotationMatrixToRef(this._workingMatrix),e.Quaternion.FromRotationMatrixToRef(this._workingMatrix,this.deviceRotationQuaternion),this.deviceRotationQuaternion.multiplyInPlace(this._calculatedRotation),this._mesh&&(this._mesh.position.copyFrom(this.devicePosition),this._mesh.rotationQuaternion&&this._mesh.rotationQuaternion.copyFrom(this.deviceRotationQuaternion))},r.prototype.updateFromDevice=function(e){if(e){this.rawPose=e,e.position&&(this._deviceRoomPosition.copyFromFloats(e.position[0],e.position[1],-e.position[2]),this._mesh&&this._mesh.getScene().useRightHandedSystem&&(this._deviceRoomPosition.z*=-1),this._deviceRoomPosition.scaleToRef(this.deviceScaleFactor,this._calculatedPosition),this._calculatedPosition.addInPlace(this.position));var t=this.rawPose;e.orientation&&t.orientation&&(this._deviceRoomRotationQuaternion.copyFromFloats(t.orientation[0],t.orientation[1],-t.orientation[2],-t.orientation[3]),this._mesh&&(this._mesh.getScene().useRightHandedSystem?(this._deviceRoomRotationQuaternion.z*=-1,this._deviceRoomRotationQuaternion.w*=-1):this._deviceRoomRotationQuaternion.multiplyToRef(this._leftHandSystemQuaternion,this._deviceRoomRotationQuaternion)),this._deviceRoomRotationQuaternion.multiplyToRef(this.rotationQuaternion,this._calculatedRotation))}},r.prototype.attachToMesh=function(t){this._mesh&&(this._mesh.parent=null),this._mesh=t,this._poseControlledCamera&&(this._mesh.parent=this._poseControlledCamera),this._mesh.rotationQuaternion||(this._mesh.rotationQuaternion=new e.Quaternion)},r.prototype.attachToPoseControlledCamera=function(e){this._poseControlledCamera=e,this._mesh&&(this._mesh.parent=this._poseControlledCamera)},r.prototype.dispose=function(){this._mesh&&this._mesh.dispose(),this._mesh=null,i.prototype.dispose.call(this)},Object.defineProperty(r.prototype,"mesh",{get:function(){return this._mesh},enumerable:!0,configurable:!0}),r.prototype.getForwardRay=function(t){if(void 0===t&&(t=100),!this.mesh)return new e.Ray(e.Vector3.Zero(),new e.Vector3(0,0,1),t);var i=this.mesh.getWorldMatrix(),r=i.getTranslation(),n=new e.Vector3(0,0,-1),o=e.Vector3.TransformNormal(n,i),s=e.Vector3.Normalize(o);return new e.Ray(r,s,t)},r}(e.Gamepad);e.PoseEnabledController=n}(us||(us={})),Qi=us||(us={}),Zi=function(e){function t(t){var i=e.call(this,t)||this;return i.onTriggerStateChangedObservable=new Qi.Observable,i.onMainButtonStateChangedObservable=new Qi.Observable,i.onSecondaryButtonStateChangedObservable=new Qi.Observable,i.onPadStateChangedObservable=new Qi.Observable,i.onPadValuesChangedObservable=new Qi.Observable,i.pad={x:0,y:0},i._changes={pressChanged:!1,touchChanged:!1,valueChanged:!1,changed:!1},i._buttons=new Array(t.buttons.length),i.hand=t.hand,i}return Y(t,e),t.prototype.onButtonStateChange=function(e){this._onButtonStateChange=e},Object.defineProperty(t.prototype,"defaultModel",{get:function(){return this._defaultModel},enumerable:!0,configurable:!0}),t.prototype.update=function(){e.prototype.update.call(this);for(var t=0;t<this._buttons.length;t++)this._setButtonValue(this.browserGamepad.buttons[t],this._buttons[t],t);this.leftStick.x===this.pad.x&&this.leftStick.y===this.pad.y||(this.pad.x=this.leftStick.x,this.pad.y=this.leftStick.y,this.onPadValuesChangedObservable.notifyObservers(this.pad))},t.prototype._setButtonValue=function(e,t,i){e||(e={pressed:!1,touched:!1,value:0}),t?(this._checkChanges(e,t),this._changes.changed&&(this._onButtonStateChange&&this._onButtonStateChange(this.index,i,e),this.handleButtonChange(i,e,this._changes)),this._buttons[i].pressed=e.pressed,this._buttons[i].touched=e.touched,this._buttons[i].value=e.value<1e-8?0:e.value):this._buttons[i]={pressed:e.pressed,touched:e.touched,value:e.value}},t.prototype._checkChanges=function(e,t){return this._changes.pressChanged=e.pressed!==t.pressed,this._changes.touchChanged=e.touched!==t.touched,this._changes.valueChanged=e.value!==t.value,this._changes.changed=this._changes.pressChanged||this._changes.touchChanged||this._changes.valueChanged,this._changes},t.prototype.dispose=function(){e.prototype.dispose.call(this),this.onTriggerStateChangedObservable.clear(),this.onMainButtonStateChangedObservable.clear(),this.onSecondaryButtonStateChangedObservable.clear(),this.onPadStateChangedObservable.clear(),this.onPadValuesChangedObservable.clear()},t}(Qi.PoseEnabledController),Qi.WebVRController=Zi,qi=us||(us={}),Ji=function(e){function t(t){var i=e.call(this,t)||this;return i.onSecondaryTriggerStateChangedObservable=new qi.Observable,i.onThumbRestChangedObservable=new qi.Observable,i.controllerType=qi.PoseEnabledControllerType.OCULUS,i}return Y(t,e),t.prototype.initControllerMesh=function(e,i){var r,n=this;r="left"===this.hand?t.MODEL_LEFT_FILENAME:t.MODEL_RIGHT_FILENAME,qi.SceneLoader.ImportMesh("",t.MODEL_BASE_URL,r,e,function(e){n._defaultModel=e[1],n.attachToMesh(n._defaultModel),i&&i(n._defaultModel)})},Object.defineProperty(t.prototype,"onAButtonStateChangedObservable",{get:function(){if("right"===this.hand)return this.onMainButtonStateChangedObservable;throw new Error("No A button on left hand")},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"onBButtonStateChangedObservable",{get:function(){if("right"===this.hand)return this.onSecondaryButtonStateChangedObservable;throw new Error("No B button on left hand")},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"onXButtonStateChangedObservable",{get:function(){if("left"===this.hand)return this.onMainButtonStateChangedObservable;throw new Error("No X button on right hand")},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"onYButtonStateChangedObservable",{get:function(){if("left"===this.hand)return this.onSecondaryButtonStateChangedObservable;throw new Error("No Y button on right hand")},enumerable:!0,configurable:!0}),t.prototype.handleButtonChange=function(e,t,i){var r=t,n="right"===this.hand?-1:1;switch(e){case 0:return void this.onPadStateChangedObservable.notifyObservers(r);case 1:return this._defaultModel&&(this._defaultModel.getChildren()[3].rotation.x=.2*-r.value,this._defaultModel.getChildren()[3].position.y=.005*-r.value,this._defaultModel.getChildren()[3].position.z=.005*-r.value),void this.onTriggerStateChangedObservable.notifyObservers(r);case 2:return this._defaultModel&&(this._defaultModel.getChildren()[4].position.x=n*r.value*.0035),void this.onSecondaryTriggerStateChangedObservable.notifyObservers(r);case 3:return this._defaultModel&&(r.pressed?this._defaultModel.getChildren()[1].position.y=-.001:this._defaultModel.getChildren()[1].position.y=0),void this.onMainButtonStateChangedObservable.notifyObservers(r);case 4:return this._defaultModel&&(r.pressed?this._defaultModel.getChildren()[2].position.y=-.001:this._defaultModel.getChildren()[2].position.y=0),void this.onSecondaryButtonStateChangedObservable.notifyObservers(r);case 5:return void this.onThumbRestChangedObservable.notifyObservers(r)}},t.MODEL_BASE_URL="https://controllers.babylonjs.com/oculus/",t.MODEL_LEFT_FILENAME="left.babylon",t.MODEL_RIGHT_FILENAME="right.babylon",t}(qi.WebVRController),qi.OculusTouchController=Ji,$i=us||(us={}),er=function(e){function t(t){var i=e.call(this,t)||this;return i.controllerType=$i.PoseEnabledControllerType.VIVE,i._invertLeftStickY=!0,i}return Y(t,e),t.prototype.initControllerMesh=function(e,i){var r=this;$i.SceneLoader.ImportMesh("",t.MODEL_BASE_URL,t.MODEL_FILENAME,e,function(e){r._defaultModel=e[1],r.attachToMesh(r._defaultModel),i&&i(r._defaultModel)})},Object.defineProperty(t.prototype,"onLeftButtonStateChangedObservable",{get:function(){return this.onMainButtonStateChangedObservable},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"onRightButtonStateChangedObservable",{get:function(){return this.onMainButtonStateChangedObservable},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"onMenuButtonStateChangedObservable",{get:function(){return this.onSecondaryButtonStateChangedObservable},enumerable:!0,configurable:!0}),t.prototype.handleButtonChange=function(e,t,i){var r=t;switch(e){case 0:return void this.onPadStateChangedObservable.notifyObservers(r);case 1:return this._defaultModel&&(this._defaultModel.getChildren()[6].rotation.x=.15*-r.value),void this.onTriggerStateChangedObservable.notifyObservers(r);case 2:return void this.onMainButtonStateChangedObservable.notifyObservers(r);case 3:return this._defaultModel&&(r.pressed?this._defaultModel.getChildren()[2].position.y=-.001:this._defaultModel.getChildren()[2].position.y=0),void this.onSecondaryButtonStateChangedObservable.notifyObservers(r)}},t.MODEL_BASE_URL="https://controllers.babylonjs.com/vive/",t.MODEL_FILENAME="wand.babylon",t}($i.WebVRController),$i.ViveController=er,tr=us||(us={}),ir=function(e){function t(t){return e.call(this,t)||this}return Y(t,e),t.prototype.initControllerMesh=function(e,i){var r=this;tr.SceneLoader.ImportMesh("",t.MODEL_BASE_URL,t.MODEL_FILENAME,e,function(e){r._defaultModel=e[1],r.attachToMesh(r._defaultModel),i&&i(r._defaultModel)})},t.prototype.handleButtonChange=function(e,t,i){console.log("Button id: "+e+"state: "),console.dir(t)},t.MODEL_BASE_URL="https://controllers.babylonjs.com/generic/",t.MODEL_FILENAME="generic.babylon",t}(tr.WebVRController),tr.GenericController=ir,rr=us||(us={}),nr=function(){return function(){this.buttonMeshes={},this.axisMeshes={}}}(),or=function(e){function t(t){var i=e.call(this,t)||this;return i._mapping={buttons:["thumbstick","trigger","grip","menu","trackpad"],buttonMeshNames:{trigger:"SELECT",menu:"MENU",grip:"GRASP",thumbstick:"THUMBSTICK_PRESS",trackpad:"TOUCHPAD_PRESS"},buttonObservableNames:{trigger:"onTriggerStateChangedObservable",menu:"onSecondaryButtonStateChangedObservable",grip:"onMainButtonStateChangedObservable",thumbstick:"onPadStateChangedObservable",trackpad:"onTrackpadChangedObservable"},axisMeshNames:["THUMBSTICK_X","THUMBSTICK_Y","TOUCHPAD_TOUCH_X","TOUCHPAD_TOUCH_Y"],pointingPoseMeshName:"POINTING_POSE"},i.onTrackpadChangedObservable=new rr.Observable,i.onTrackpadValuesChangedObservable=new rr.Observable,i.trackpad={x:0,y:0},i.controllerType=rr.PoseEnabledControllerType.WINDOWS,i._loadedMeshInfo=null,i}return Y(t,e),Object.defineProperty(t.prototype,"onTriggerButtonStateChangedObservable",{get:function(){return this.onTriggerStateChangedObservable},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"onMenuButtonStateChangedObservable",{get:function(){return this.onSecondaryButtonStateChangedObservable},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"onGripButtonStateChangedObservable",{get:function(){return this.onMainButtonStateChangedObservable},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"onThumbstickButtonStateChangedObservable",{get:function(){return this.onPadStateChangedObservable},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"onTouchpadButtonStateChangedObservable",{get:function(){return this.onTrackpadChangedObservable},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"onTouchpadValuesChangedObservable",{get:function(){return this.onTrackpadValuesChangedObservable},enumerable:!0,configurable:!0}),t.prototype.update=function(){if(e.prototype.update.call(this),this._loadedMeshInfo&&this.browserGamepad.axes){this.browserGamepad.axes[2]==this.trackpad.x&&this.browserGamepad.axes[3]==this.trackpad.y||(this.trackpad.x=this.browserGamepad.axes[2],this.trackpad.y=this.browserGamepad.axes[3],this.onTrackpadValuesChangedObservable.notifyObservers(this.trackpad));for(var t=0;t<this._mapping.axisMeshNames.length;t++)this.lerpAxisTransform(t,this.browserGamepad.axes[t])}},t.prototype.handleButtonChange=function(e,t,i){var r=this._mapping.buttons[e];if(r){var n=this[this._mapping.buttonObservableNames[r]];n&&n.notifyObservers(t),this.lerpButtonTransform(r,t.value)}},t.prototype.lerpButtonTransform=function(e,t){if(this._loadedMeshInfo){var i=this._loadedMeshInfo.buttonMeshes[e];i.unpressed.rotationQuaternion&&i.pressed.rotationQuaternion&&i.value.rotationQuaternion&&(rr.Quaternion.SlerpToRef(i.unpressed.rotationQuaternion,i.pressed.rotationQuaternion,t,i.value.rotationQuaternion),rr.Vector3.LerpToRef(i.unpressed.position,i.pressed.position,t,i.value.position))}},t.prototype.lerpAxisTransform=function(e,t){if(this._loadedMeshInfo){var i=this._loadedMeshInfo.axisMeshes[e];if(i&&i.min.rotationQuaternion&&i.max.rotationQuaternion&&i.value.rotationQuaternion){var r=.5*t+.5;rr.Quaternion.SlerpToRef(i.min.rotationQuaternion,i.max.rotationQuaternion,r,i.value.rotationQuaternion),rr.Vector3.LerpToRef(i.min.position,i.max.position,r,i.value.position)}}},t.prototype.initControllerMesh=function(e,i,r){var n,o,s=this;if(void 0===r&&(r=!1),rr.SceneLoader.IsPluginForExtensionAvailable(".glb")){var a="default";if(this.id&&!r){var h=this.id.match(t.GAMEPAD_ID_PATTERN);a=h&&h[0]||a}o="left"===this.hand?t.MODEL_LEFT_FILENAME:t.MODEL_RIGHT_FILENAME,n=t.MODEL_BASE_URL+a+"/"}else rr.Tools.Warn("You need to reference GLTF loader to load Windows Motion Controllers model. Falling back to generic models"),n=rr.GenericController.MODEL_BASE_URL,o=rr.GenericController.MODEL_FILENAME;rr.SceneLoader.ImportMesh("",n,o,e,function(t){s._loadedMeshInfo=s.processModel(e,t),s._loadedMeshInfo&&(s._defaultModel=s._loadedMeshInfo.rootNode,s.attachToMesh(s._defaultModel),i&&i(s._defaultModel))},null,function(e,t){rr.Tools.Log(t),rr.Tools.Warn("Failed to retrieve controller model from the remote server: "+n+o),r||s.initControllerMesh(e,i,!0)})},t.prototype.processModel=function(e,t){for(var i=null,r=new rr.Mesh(this.id+" "+this.hand,e),n=null,o=0;o<t.length;o++){var s=t[o];if(!s.parent){s.isPickable=!1,n=s;break}}return n?(n.setParent(r),i=this.createMeshInfo(r)):rr.Tools.Warn("Could not find root node in model file."),i},t.prototype.createMeshInfo=function(e){var t,i=new nr;for(i.rootNode=e,i.buttonMeshes={},i.axisMeshes={},t=0;t<this._mapping.buttons.length;t++){var r=this._mapping.buttonMeshNames[this._mapping.buttons[t]];if(r){var n=l(e,r);if(n){var o={index:t,value:c(n,"VALUE"),pressed:c(n,"PRESSED"),unpressed:c(n,"UNPRESSED")};o.value&&o.pressed&&o.unpressed?i.buttonMeshes[this._mapping.buttons[t]]=o:rr.Tools.Warn("Missing button submesh under mesh with name: "+r+"(VALUE: "+!!o.value+", PRESSED: "+!!o.pressed+", UNPRESSED:"+!!o.unpressed+")")}else rr.Tools.Warn("Missing button mesh with name: "+r)}else rr.Tools.Log("Skipping unknown button at index: "+t+" with mapped name: "+this._mapping.buttons[t])}for(t=0;t<this._mapping.axisMeshNames.length;t++){var s=this._mapping.axisMeshNames[t];if(s){var a=l(e,s);if(a){var h={index:t,value:c(a,"VALUE"),min:c(a,"MIN"),max:c(a,"MAX")};h.value&&h.min&&h.max?i.axisMeshes[t]=h:rr.Tools.Warn("Missing axis submesh under mesh with name: "+s+"(VALUE: "+!!h.value+", MIN: "+!!h.min+", MAX:"+!!h.max+")")}else rr.Tools.Warn("Missing axis mesh with name: "+s)}else rr.Tools.Log("Skipping unknown axis at index: "+t)}return i.pointingPoseNode=l(e,this._mapping.pointingPoseMeshName),i.pointingPoseNode||rr.Tools.Warn("Missing pointing pose mesh with name: "+this._mapping.pointingPoseMeshName),i;function l(e,t){return e.getChildMeshes(!1,function(e){return e.name===t})[0]}function c(e,t){return e.getChildMeshes(!0,function(e){return e.name==t})[0]}},t.prototype.getForwardRay=function(t){if(void 0===t&&(t=100),!this._loadedMeshInfo||!this._loadedMeshInfo.pointingPoseNode)return e.prototype.getForwardRay.call(this,t);var i=this._loadedMeshInfo.pointingPoseNode.getWorldMatrix(),r=i.getTranslation(),n=new rr.Vector3(0,0,-1),o=rr.Vector3.TransformNormal(n,i),s=rr.Vector3.Normalize(o);return new rr.Ray(r,s,t)},t.prototype.dispose=function(){e.prototype.dispose.call(this),this.onTrackpadChangedObservable.clear()},t.MODEL_BASE_URL="https://controllers.babylonjs.com/microsoft/",t.MODEL_LEFT_FILENAME="left.glb",t.MODEL_RIGHT_FILENAME="right.glb",t.GAMEPAD_ID_PREFIX="Spatial Controller (Spatial Interaction Source) ",t.GAMEPAD_ID_PATTERN=/([0-9a-zA-Z]+-[0-9a-zA-Z]+)$/,t}(rr.WebVRController),rr.WindowsMotionController=or,sr=us||(us={}),ar=function(e){function t(t){var i=e.call(this,t)||this;return i._buttonIndexToObservableNameMap=["onTrackpadChangedObservable","onTriggerStateChangedObservable"],i.controllerType=sr.PoseEnabledControllerType.GEAR_VR,i}return Y(t,e),t.prototype.initControllerMesh=function(e,i){var r=this;sr.SceneLoader.ImportMesh("",t.MODEL_BASE_URL,t.MODEL_FILENAME,e,function(e){r._defaultModel=e[1],r.attachToMesh(r._defaultModel),i&&i(r._defaultModel)})},t.prototype.handleButtonChange=function(e,t,i){if(e<this._buttonIndexToObservableNameMap.length){var r=this[this._buttonIndexToObservableNameMap[e]];r&&r.notifyObservers(t)}},t.MODEL_BASE_URL="https://controllers.babylonjs.com/generic/",t.MODEL_FILENAME="generic.babylon",t.GAMEPAD_ID_PREFIX="Gear VR",t}(sr.WebVRController),sr.GearVRController=ar,function(e){var t=function(t){function i(e,i,r,n){void 0===n&&(n=null);var o=t.call(this,e,i,r)||this;return o.radius=12,o.rotationOffset=0,o.heightOffset=4,o.cameraAcceleration=.05,o.maxCameraSpeed=20,o.lockedTarget=n,o}return Y(i,t),i.prototype.getRadians=function(e){return e*Math.PI/180},i.prototype.follow=function(t){if(t){var i;if(t.rotationQuaternion){var r=new e.Matrix;t.rotationQuaternion.toRotationMatrix(r),i=Math.atan2(r.m[8],r.m[10])}else i=t.rotation.y;var n=this.getRadians(this.rotationOffset)+i,o=t.getAbsolutePosition(),s=o.x+Math.sin(n)*this.radius,a=o.z+Math.cos(n)*this.radius,h=s-this.position.x,l=o.y+this.heightOffset-this.position.y,c=a-this.position.z,u=h*this.cameraAcceleration*2,p=l*this.cameraAcceleration,f=c*this.cameraAcceleration*2;(u>this.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"},X([e.serialize()],i.prototype,"radius",void 0),X([e.serialize()],i.prototype,"rotationOffset",void 0),X([e.serialize()],i.prototype,"heightOffset",void 0),X([e.serialize()],i.prototype,"cameraAcceleration",void 0),X([e.serialize()],i.prototype,"maxCameraSpeed",void 0),X([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 Y(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}(us||(us={})),hr=us||(us={}),lr=function(e){function t(t,i,r){var n=e.call(this,t,i,r)||this;return n.inputs.addGamepad(),n}return Y(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}(hr.TouchCamera),hr.UniversalCamera=lr,cr=us||(us={}),ur=function(e){function t(t,i,r){return e.call(this,t,i,r)||this}return Y(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}(cr.UniversalCamera),cr.GamepadCamera=ur,pr=us||(us={}),fr=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}(),pr.PostProcessRenderPipelineManager=fr,dr=us||(us={}),mr=function(){function e(e,t,i,r,n,o){this._refCount=0,this._name=t,this._renderTexture=new dr.RenderTargetTexture(t,i,e),this.setRenderList(r),this._renderTexture.onBeforeRenderObservable.add(n),this._renderTexture.onAfterRenderObservable.add(o),this._scene=e,this._renderList=r}return e.prototype._incRefCount=function(){return 0===this._refCount&&this._scene.customRenderTargets.push(this._renderTexture),++this._refCount},e.prototype._decRefCount=function(){return this._refCount--,this._refCount<=0&&this._scene.customRenderTargets.splice(this._scene.customRenderTargets.indexOf(this._renderTexture),1),this._refCount},e.prototype._update=function(){this.setRenderList(this._renderList)},e.prototype.setRenderList=function(e){this._renderTexture.renderList=e},e.prototype.getRenderTexture=function(){return this._renderTexture},e}(),dr.PostProcessRenderPass=mr,gr=us||(us={}),_r=function(){function e(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(e.prototype,"isSupported",{get:function(){for(var e in this._postProcesses)if(!this._postProcesses[e].isSupported)return!1;return!0},enumerable:!0,configurable:!0}),e.prototype._update=function(){for(var e in this._renderPasses)this._renderPasses[e]._update()},e.prototype.addPass=function(e){this._renderPasses[e._name]=e,this._linkParameters()},e.prototype.removePass=function(e){delete this._renderPasses[e._name],this._linkParameters()},e.prototype.addRenderEffectAsPass=function(e){this._renderEffectAsPasses[e._name]=e,this._linkParameters()},e.prototype.getPass=function(e){for(var t in this._renderPasses)if(t===e)return this._renderPasses[e];return null},e.prototype.emptyPasses=function(){this._renderPasses={},this._linkParameters()},e.prototype._attachCameras=function(e){var t,i=gr.Tools.MakeArray(e||this._cameras);if(i){for(var r=0;r<i.length;r++){var n=i[r],o=n.name;t=this._singleInstance?0:o,this._postProcesses[t]=this._postProcesses[t]||this._getPostProcess();var s=n.attachPostProcess(this._postProcesses[t]);this._indicesForCamera[o]||(this._indicesForCamera[o]=[]),this._indicesForCamera[o].push(s),this._cameras[o]||(this._cameras[o]=n);for(var a in this._renderPasses)this._renderPasses[a]._incRefCount()}this._linkParameters()}},e.prototype._detachCameras=function(e){var t=gr.Tools.MakeArray(e||this._cameras);if(t)for(var i=0;i<t.length;i++){var r=t[i],n=r.name;r.detachPostProcess(this._postProcesses[this._singleInstance?0:n]),this._cameras[n]&&(this._cameras[n]=null);for(var o in this._renderPasses)this._renderPasses[o]._decRefCount()}},e.prototype._enable=function(e){var t=gr.Tools.MakeArray(e||this._cameras);if(t)for(var i=0;i<t.length;i++){for(var r=t[i],n=r.name,o=0;o<this._indicesForCamera[n].length;o++)void 0===r._postProcesses[this._indicesForCamera[n][o]]&&e[i].attachPostProcess(this._postProcesses[this._singleInstance?0:n],this._indicesForCamera[n][o]);for(var s in this._renderPasses)this._renderPasses[s]._incRefCount()}},e.prototype._disable=function(e){var t=gr.Tools.MakeArray(e||this._cameras);if(t)for(var i=0;i<t.length;i++){var r=t[i],n=r.Name;r.detachPostProcess(this._postProcesses[this._singleInstance?0:n]);for(var o in this._renderPasses)this._renderPasses[o]._decRefCount()}},e.prototype.getPostProcess=function(e){return this._singleInstance?this._postProcesses[0]:e?this._postProcesses[e.name]:null},e.prototype._linkParameters=function(){var e=this;for(var t in this._postProcesses)this.applyParameters&&this.applyParameters(this._postProcesses[t]),this._postProcesses[t].onBeforeRenderObservable.add(function(t){e._linkTextures(t)})},e.prototype._linkTextures=function(e){for(var t in this._renderPasses)e.setTexture(t,this._renderPasses[t].getRenderTexture());for(var i in this._renderEffectAsPasses)e.setTextureFromPostProcess(i+"Sampler",this._renderEffectAsPasses[i].getPostProcess())},e}(),gr.PostProcessRenderEffect=_r,vr=us||(us={}),yr=function(){function e(e,t){this._engine=e,this._name=t,this._renderEffects={},this._renderEffectsForIsolatedPass=new Array,this._cameras=[]}return e.prototype.getClassName=function(){return"PostProcessRenderPipeline"},Object.defineProperty(e.prototype,"isSupported",{get:function(){for(var e in this._renderEffects)if(this._renderEffects.hasOwnProperty(e)&&!this._renderEffects[e].isSupported)return!1;return!0},enumerable:!0,configurable:!0}),e.prototype.addEffect=function(e){this._renderEffects[e._name]=e},e.prototype._rebuild=function(){},e.prototype._enableEffect=function(e,t){var i=this._renderEffects[e];i&&i._enable(vr.Tools.MakeArray(t||this._cameras))},e.prototype._disableEffect=function(e,t){var i=this._renderEffects[e];i&&i._disable(vr.Tools.MakeArray(t||this._cameras))},e.prototype._attachCameras=function(e,t){var i=vr.Tools.MakeArray(e||this._cameras);if(i){var r,n=[];for(r=0;r<i.length;r++){var o=i[r],s=o.name;-1===this._cameras.indexOf(o)?this._cameras[s]=o:t&&n.push(r)}for(r=0;r<n.length;r++)e.splice(n[r],1);for(var a in this._renderEffects)this._renderEffects.hasOwnProperty(a)&&this._renderEffects[a]._attachCameras(i)}},e.prototype._detachCameras=function(e){var t=vr.Tools.MakeArray(e||this._cameras);if(t){for(var i in this._renderEffects)this._renderEffects.hasOwnProperty(i)&&this._renderEffects[i]._detachCameras(t);for(var r=0;r<t.length;r++)this._cameras.splice(this._cameras.indexOf(t[r]),1)}},e.prototype._enableDisplayOnlyPass=function(t,i){var r=this,n=vr.Tools.MakeArray(i||this._cameras);if(n){var o,s=null;for(o in this._renderEffects)if(this._renderEffects.hasOwnProperty(o)&&null!=(s=this._renderEffects[o].getPass(t)))break;if(null!==s){for(o in this._renderEffects)this._renderEffects.hasOwnProperty(o)&&this._renderEffects[o]._disable(n);s._name=e.PASS_SAMPLER_NAME;for(var a=0;a<n.length;a++){var h=n[a],l=h.name;this._renderEffectsForIsolatedPass[l]=this._renderEffectsForIsolatedPass[l]||new vr.PostProcessRenderEffect(this._engine,e.PASS_EFFECT_NAME,function(){return new vr.DisplayPassPostProcess(e.PASS_EFFECT_NAME,1,null,void 0,r._engine,!0)}),this._renderEffectsForIsolatedPass[l].emptyPasses(),this._renderEffectsForIsolatedPass[l].addPass(s),this._renderEffectsForIsolatedPass[l]._attachCameras(h)}}}},e.prototype._disableDisplayOnlyPass=function(t){var i=this,r=vr.Tools.MakeArray(t||this._cameras);if(r){for(var n=0;n<r.length;n++){var o=r[n],s=o.name;this._renderEffectsForIsolatedPass[s]=this._renderEffectsForIsolatedPass[s]||new vr.PostProcessRenderEffect(this._engine,e.PASS_EFFECT_NAME,function(){return new vr.DisplayPassPostProcess(e.PASS_EFFECT_NAME,1,null,void 0,i._engine,!0)}),this._renderEffectsForIsolatedPass[s]._disable(o)}for(var a in this._renderEffects)this._renderEffects.hasOwnProperty(a)&&this._renderEffects[a]._enable(r)}},e.prototype._update=function(){for(var e in this._renderEffects)this._renderEffects.hasOwnProperty(e)&&this._renderEffects[e]._update();for(var t=0;t<this._cameras.length;t++){var i=this._cameras[t].name;this._renderEffectsForIsolatedPass[i]&&this._renderEffectsForIsolatedPass[i]._update()}},e.prototype._reset=function(){this._renderEffects={},this._renderEffectsForIsolatedPass=new Array},e.prototype.dispose=function(){},e.PASS_EFFECT_NAME="passEffect",e.PASS_SAMPLER_NAME="passSampler",X([vr.serialize()],e.prototype,"_name",void 0),e}(),vr.PostProcessRenderPipeline=yr,br=us||(us={}),xr=function(){function e(e,t){void 0===t&&(t=br.Engine.TEXTURETYPE_FLOAT);var i=this;this._scene=e;var r=e.getEngine();this._depthMap=new br.RenderTargetTexture("depthMap",{width:r.getRenderWidth(),height:r.getRenderHeight()},this._scene,!1,!0,t),this._depthMap.wrapU=br.Texture.CLAMP_ADDRESSMODE,this._depthMap.wrapV=br.Texture.CLAMP_ADDRESSMODE,this._depthMap.refreshRate=1,this._depthMap.renderParticles=!1,this._depthMap.renderList=null,this._depthMap.onClearObservable.add(function(e){e.clear(new br.Color4(1,1,1,1),!0,!0,!0)});var n=function(e){var t=e.getRenderingMesh(),r=i._scene,n=r.getEngine(),o=e.getMaterial();if(o){n.setState(o.backFaceCulling,0,!1,r.useRightHandedSystem);var s=t._getInstancesRenderList(e._id);if(!s.mustReturn){var a=n.getCaps().instancedArrays&&null!==s.visibleInstances[e._id];if(i.isReady(e,a)&&r.activeCamera){if(n.enableEffect(i._effect),t._bind(e,i._effect,br.Material.TriangleFillMode),i._effect.setMatrix("viewProjection",r.getTransformMatrix()),i._effect.setFloat2("depthValues",r.activeCamera.minZ,r.activeCamera.minZ+r.activeCamera.maxZ),o&&o.needAlphaTesting()){var h=o.getAlphaTestTexture();h&&(i._effect.setTexture("diffuseSampler",h),i._effect.setMatrix("diffuseMatrix",h.getTextureMatrix()))}t.useBones&&t.computeBonesUsingShaders&&t.skeleton&&i._effect.setMatrices("mBones",t.skeleton.getTransformMatrices(t)),t._processRendering(e,i._effect,br.Material.TriangleFillMode,s,a,function(e,t){return i._effect.setMatrix("world",t)})}}}};this._depthMap.customRenderFunction=function(e,t,i,o){var s;if(o.length){for(r.setColorWrite(!1),s=0;s<o.length;s++)n(o.data[s]);r.setColorWrite(!0)}for(s=0;s<e.length;s++)n(e.data[s]);for(s=0;s<t.length;s++)n(t.data[s])}}return e.prototype.isReady=function(e,t){var i=e.getMaterial();if(i.disableDepthWrite)return!1;var r=[],n=[br.VertexBuffer.PositionKind],o=e.getMesh();i&&i.needAlphaTesting()&&(r.push("#define ALPHATEST"),o.isVerticesDataPresent(br.VertexBuffer.UVKind)&&(n.push(br.VertexBuffer.UVKind),r.push("#define UV1")),o.isVerticesDataPresent(br.VertexBuffer.UV2Kind)&&(n.push(br.VertexBuffer.UV2Kind),r.push("#define UV2"))),o.useBones&&o.computeBonesUsingShaders?(n.push(br.VertexBuffer.MatricesIndicesKind),n.push(br.VertexBuffer.MatricesWeightsKind),o.numBoneInfluencers>4&&(n.push(br.VertexBuffer.MatricesIndicesExtraKind),n.push(br.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"),t&&(r.push("#define INSTANCES"),n.push("world0"),n.push("world1"),n.push("world2"),n.push("world3"));var s=r.join("\n");return this._cachedDefines!==s&&(this._cachedDefines=s,this._effect=this._scene.getEngine().createEffect("depth",n,["world","mBones","viewProjection","diffuseMatrix","depthValues"],["diffuseSampler"],s)),this._effect.isReady()},e.prototype.getDepthMap=function(){return this._depthMap},e.prototype.dispose=function(){this._depthMap.dispose()},e}(),br.DepthRenderer=xr,Tr=us||(us={}),Er=function(e){function t(t,i,r,n){var o=e.call(this,i.getEngine(),t)||this;o.SSAOOriginalSceneColorEffect="SSAOOriginalSceneColorEffect",o.SSAORenderEffect="SSAORenderEffect",o.SSAOBlurHRenderEffect="SSAOBlurHRenderEffect",o.SSAOBlurVRenderEffect="SSAOBlurVRenderEffect",o.SSAOCombineRenderEffect="SSAOCombineRenderEffect",o.totalStrength=1,o.radius=1e-4,o.area=.0075,o.fallOff=1e-6,o.base=.5,o._firstUpdate=!0,o._scene=i,o._createRandomTexture(),o._depthTexture=i.enableDepthRenderer().getDepthMap();var s=r.ssaoRatio||r,a=r.combineRatio||r;return o._originalColorPostProcess=new Tr.PassPostProcess("SSAOOriginalSceneColor",a,null,Tr.Texture.BILINEAR_SAMPLINGMODE,i.getEngine(),!1),o._createSSAOPostProcess(s),o._createBlurPostProcess(s),o._createSSAOCombinePostProcess(a),o.addEffect(new Tr.PostProcessRenderEffect(i.getEngine(),o.SSAOOriginalSceneColorEffect,function(){return o._originalColorPostProcess},!0)),o.addEffect(new Tr.PostProcessRenderEffect(i.getEngine(),o.SSAORenderEffect,function(){return o._ssaoPostProcess},!0)),o.addEffect(new Tr.PostProcessRenderEffect(i.getEngine(),o.SSAOBlurHRenderEffect,function(){return o._blurHPostProcess},!0)),o.addEffect(new Tr.PostProcessRenderEffect(i.getEngine(),o.SSAOBlurVRenderEffect,function(){return o._blurVPostProcess},!0)),o.addEffect(new Tr.PostProcessRenderEffect(i.getEngine(),o.SSAOCombineRenderEffect,function(){return o._ssaoCombinePostProcess},!0)),i.postProcessRenderPipelineManager.addPipeline(o),n&&i.postProcessRenderPipelineManager.attachCamerasToRenderPipeline(t,n),o}return Y(t,e),t.prototype.dispose=function(t){void 0===t&&(t=!1);for(var i=0;i<this._scene.cameras.length;i++){var r=this._scene.cameras[i];this._originalColorPostProcess.dispose(r),this._ssaoPostProcess.dispose(r),this._blurHPostProcess.dispose(r),this._blurVPostProcess.dispose(r),this._ssaoCombinePostProcess.dispose(r)}this._randomTexture.dispose(),t&&this._scene.disableDepthRenderer(),this._scene.postProcessRenderPipelineManager.detachCamerasFromRenderPipeline(this._name,this._scene.cameras),e.prototype.dispose.call(this)},t.prototype._createBlurPostProcess=function(e){var t=this;this._blurHPostProcess=new Tr.BlurPostProcess("BlurH",new Tr.Vector2(1,0),16,e,null,Tr.Texture.BILINEAR_SAMPLINGMODE,this._scene.getEngine(),!1,Tr.Engine.TEXTURETYPE_UNSIGNED_INT),this._blurVPostProcess=new Tr.BlurPostProcess("BlurV",new Tr.Vector2(0,1),16,e,null,Tr.Texture.BILINEAR_SAMPLINGMODE,this._scene.getEngine(),!1,Tr.Engine.TEXTURETYPE_UNSIGNED_INT),this._blurHPostProcess.onActivateObservable.add(function(){var e=t._blurHPostProcess.width/t._scene.getEngine().getRenderWidth();t._blurHPostProcess.kernel=16*e}),this._blurVPostProcess.onActivateObservable.add(function(){var e=t._blurVPostProcess.height/t._scene.getEngine().getRenderHeight();t._blurVPostProcess.kernel=16*e})},t.prototype._rebuild=function(){this._firstUpdate=!0,e.prototype._rebuild.call(this)},t.prototype._createSSAOPostProcess=function(e){var t=this,i=[.5381,.1856,-.4319,.1379,.2486,.443,.3371,.5679,-.0057,-.6999,-.0451,-.0019,.0689,-.1598,-.8547,.056,.0069,-.1843,-.0146,.1402,.0762,.01,-.1924,-.0344,-.3577,-.5301,-.4358,-.3169,.1063,.0158,.0103,-.5869,.0046,-.0897,-.494,.3287,.7119,-.0154,-.0918,-.0533,.0596,-.5411,.0352,-.0631,.546,-.4776,.2847,-.0271];this._ssaoPostProcess=new Tr.PostProcess("ssao","ssao",["sampleSphere","samplesFactor","randTextureTiles","totalStrength","radius","area","fallOff","base","range","viewport"],["randomSampler"],e,null,Tr.Texture.BILINEAR_SAMPLINGMODE,this._scene.getEngine(),!1,"#define SAMPLES 16\n#define SSAO"),this._ssaoPostProcess.onApply=function(e){t._firstUpdate&&(e.setArray3("sampleSphere",i),e.setFloat("samplesFactor",1/16),e.setFloat("randTextureTiles",4)),e.setFloat("totalStrength",t.totalStrength),e.setFloat("radius",t.radius),e.setFloat("area",t.area),e.setFloat("fallOff",t.fallOff),e.setFloat("base",t.base),e.setTexture("textureSampler",t._depthTexture),e.setTexture("randomSampler",t._randomTexture)}},t.prototype._createSSAOCombinePostProcess=function(e){var t=this;this._ssaoCombinePostProcess=new Tr.PostProcess("ssaoCombine","ssaoCombine",[],["originalColor"],e,null,Tr.Texture.BILINEAR_SAMPLINGMODE,this._scene.getEngine(),!1),this._ssaoCombinePostProcess.onApply=function(e){e.setTextureFromPostProcess("originalColor",t._originalColorPostProcess)}},t.prototype._createRandomTexture=function(){this._randomTexture=new Tr.DynamicTexture("SSAORandomTexture",512,this._scene,!1,Tr.Texture.TRILINEAR_SAMPLINGMODE),this._randomTexture.wrapU=Tr.Texture.WRAP_ADDRESSMODE,this._randomTexture.wrapV=Tr.Texture.WRAP_ADDRESSMODE;for(var e=this._randomTexture.getContext(),t=function(e,t){return Math.random()*(t-e)+e},i=Tr.Vector3.Zero(),r=0;r<512;r++)for(var n=0;n<512;n++)i.x=Math.floor(255*t(-1,1)),i.y=Math.floor(255*t(-1,1)),i.z=Math.floor(255*t(-1,1)),e.fillStyle="rgb("+i.x+", "+i.y+", "+i.z+")",e.fillRect(r,n,1,1);this._randomTexture.update(!1)},X([Tr.serialize()],t.prototype,"totalStrength",void 0),X([Tr.serialize()],t.prototype,"radius",void 0),X([Tr.serialize()],t.prototype,"area",void 0),X([Tr.serialize()],t.prototype,"fallOff",void 0),X([Tr.serialize()],t.prototype,"base",void 0),t}(Tr.PostProcessRenderPipeline),Tr.SSAORenderingPipeline=Er,Ar=us||(us={}),Pr=function(e){function t(t,i,r,n){var o=e.call(this,i.getEngine(),t)||this;if(o.SSAOOriginalSceneColorEffect="SSAOOriginalSceneColorEffect",o.SSAORenderEffect="SSAORenderEffect",o.SSAOBlurHRenderEffect="SSAOBlurHRenderEffect",o.SSAOBlurVRenderEffect="SSAOBlurVRenderEffect",o.SSAOCombineRenderEffect="SSAOCombineRenderEffect",o.totalStrength=1,o.maxZ=100,o.minZAspect=.2,o._samples=8,o._expensiveBlur=!0,o.radius=2,o.base=.1,o._firstUpdate=!0,o._scene=i,!o.isSupported)return Ar.Tools.Error("SSAO 2 needs WebGL 2 support."),o;var s=r.ssaoRatio||r,a=r.blurRatio||r,h=i.enableGeometryBufferRenderer();return o._createRandomTexture(),o._depthTexture=h.getGBuffer().textures[0],o._normalTexture=h.getGBuffer().textures[1],o._originalColorPostProcess=new Ar.PassPostProcess("SSAOOriginalSceneColor",1,null,Ar.Texture.BILINEAR_SAMPLINGMODE,i.getEngine(),!1),o._createSSAOPostProcess(1),o._createBlurPostProcess(s,a),o._createSSAOCombinePostProcess(a),o.addEffect(new Ar.PostProcessRenderEffect(i.getEngine(),o.SSAOOriginalSceneColorEffect,function(){return o._originalColorPostProcess},!0)),o.addEffect(new Ar.PostProcessRenderEffect(i.getEngine(),o.SSAORenderEffect,function(){return o._ssaoPostProcess},!0)),o.addEffect(new Ar.PostProcessRenderEffect(i.getEngine(),o.SSAOBlurHRenderEffect,function(){return o._blurHPostProcess},!0)),o.addEffect(new Ar.PostProcessRenderEffect(i.getEngine(),o.SSAOBlurVRenderEffect,function(){return o._blurVPostProcess},!0)),o.addEffect(new Ar.PostProcessRenderEffect(i.getEngine(),o.SSAOCombineRenderEffect,function(){return o._ssaoCombinePostProcess},!0)),i.postProcessRenderPipelineManager.addPipeline(o),n&&i.postProcessRenderPipelineManager.attachCamerasToRenderPipeline(t,n),o}return Y(t,e),Object.defineProperty(t.prototype,"samples",{get:function(){return this._samples},set:function(e){this._ssaoPostProcess.updateEffect("#define SAMPLES "+e+"\n#define SSAO"),this._samples=e,this._sampleSphere=this._generateHemisphere(),this._firstUpdate=!0},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"expensiveBlur",{get:function(){return this._expensiveBlur},set:function(e){this._blurHPostProcess.updateEffect("#define BILATERAL_BLUR\n#define BILATERAL_BLUR_H\n#define SAMPLES 16\n#define EXPENSIVE "+(e?"1":"0")+"\n",null,["textureSampler","depthSampler"]),this._blurVPostProcess.updateEffect("#define BILATERAL_BLUR\n#define SAMPLES 16\n#define EXPENSIVE "+(e?"1":"0")+"\n",null,["textureSampler","depthSampler"]),this._expensiveBlur=e,this._firstUpdate=!0},enumerable:!0,configurable:!0}),Object.defineProperty(t,"IsSupported",{get:function(){var e=Ar.Engine.LastCreatedEngine;return!!e&&e.getCaps().drawBuffersExtension},enumerable:!0,configurable:!0}),t.prototype.dispose=function(t){void 0===t&&(t=!1);for(var i=0;i<this._scene.cameras.length;i++){var r=this._scene.cameras[i];this._originalColorPostProcess.dispose(r),this._ssaoPostProcess.dispose(r),this._blurHPostProcess.dispose(r),this._blurVPostProcess.dispose(r),this._ssaoCombinePostProcess.dispose(r)}this._randomTexture.dispose(),t&&this._scene.disableGeometryBufferRenderer(),this._scene.postProcessRenderPipelineManager.detachCamerasFromRenderPipeline(this._name,this._scene.cameras),e.prototype.dispose.call(this)},t.prototype._createBlurPostProcess=function(e,t){var i=this;this._samplerOffsets=[];for(var r=this.expensiveBlur,n=-8;n<8;n++)this._samplerOffsets.push(2*n+.5);this._blurHPostProcess=new Ar.PostProcess("BlurH","ssao2",["outSize","samplerOffsets","near","far","radius"],["depthSampler"],e,null,Ar.Texture.TRILINEAR_SAMPLINGMODE,this._scene.getEngine(),!1,"#define BILATERAL_BLUR\n#define BILATERAL_BLUR_H\n#define SAMPLES 16\n#define EXPENSIVE "+(r?"1":"0")+"\n"),this._blurHPostProcess.onApply=function(e){i._scene.activeCamera&&(e.setFloat("outSize",i._ssaoCombinePostProcess.width>0?i._ssaoCombinePostProcess.width:i._originalColorPostProcess.width),e.setFloat("near",i._scene.activeCamera.minZ),e.setFloat("far",i._scene.activeCamera.maxZ),e.setFloat("radius",i.radius),e.setTexture("depthSampler",i._depthTexture),i._firstUpdate&&e.setArray("samplerOffsets",i._samplerOffsets))},this._blurVPostProcess=new Ar.PostProcess("BlurV","ssao2",["outSize","samplerOffsets","near","far","radius"],["depthSampler"],t,null,Ar.Texture.TRILINEAR_SAMPLINGMODE,this._scene.getEngine(),!1,"#define BILATERAL_BLUR\n#define BILATERAL_BLUR_V\n#define SAMPLES 16\n#define EXPENSIVE "+(r?"1":"0")+"\n"),this._blurVPostProcess.onApply=function(e){i._scene.activeCamera&&(e.setFloat("outSize",i._ssaoCombinePostProcess.height>0?i._ssaoCombinePostProcess.height:i._originalColorPostProcess.height),e.setFloat("near",i._scene.activeCamera.minZ),e.setFloat("far",i._scene.activeCamera.maxZ),e.setFloat("radius",i.radius),e.setTexture("depthSampler",i._depthTexture),i._firstUpdate&&(e.setArray("samplerOffsets",i._samplerOffsets),i._firstUpdate=!1))}},t.prototype._rebuild=function(){this._firstUpdate=!0,e.prototype._rebuild.call(this)},t.prototype._generateHemisphere=function(){for(var e,t,i=this.samples,r=[],n=function(e,t){return Math.random()*(t-e)+e},o=0;o<i;)(e=new Ar.Vector3(n(-1,1),n(-1,1),n(.3,1))).normalize(),t=o/i,t=Ar.Scalar.Lerp(.1,1,t*t),e.scaleInPlace(t),r.push(e.x,e.y,e.z),o++;return r},t.prototype._createSSAOPostProcess=function(e){var t=this,i=this.samples;this._sampleSphere=this._generateHemisphere(),this._ssaoPostProcess=new Ar.PostProcess("ssao2","ssao2",["sampleSphere","samplesFactor","randTextureTiles","totalStrength","radius","base","range","projection","near","far","texelSize","xViewport","yViewport","maxZ","minZAspect"],["randomSampler","normalSampler"],e,null,Ar.Texture.BILINEAR_SAMPLINGMODE,this._scene.getEngine(),!1,"#define SAMPLES "+i+"\n#define SSAO"),this._ssaoPostProcess.onApply=function(e){t._firstUpdate&&(e.setArray3("sampleSphere",t._sampleSphere),e.setFloat("randTextureTiles",4)),t._scene.activeCamera&&(e.setFloat("samplesFactor",1/t.samples),e.setFloat("totalStrength",t.totalStrength),e.setFloat2("texelSize",1/t._ssaoPostProcess.width,1/t._ssaoPostProcess.height),e.setFloat("radius",t.radius),e.setFloat("maxZ",t.maxZ),e.setFloat("minZAspect",t.minZAspect),e.setFloat("base",t.base),e.setFloat("near",t._scene.activeCamera.minZ),e.setFloat("far",t._scene.activeCamera.maxZ),e.setFloat("xViewport",Math.tan(t._scene.activeCamera.fov/2)*t._scene.getEngine().getAspectRatio(t._scene.activeCamera,!0)),e.setFloat("yViewport",Math.tan(t._scene.activeCamera.fov/2)),e.setMatrix("projection",t._scene.getProjectionMatrix()),e.setTexture("textureSampler",t._depthTexture),e.setTexture("normalSampler",t._normalTexture),e.setTexture("randomSampler",t._randomTexture))}},t.prototype._createSSAOCombinePostProcess=function(e){var t=this;this._ssaoCombinePostProcess=new Ar.PostProcess("ssaoCombine","ssaoCombine",[],["originalColor"],e,null,Ar.Texture.BILINEAR_SAMPLINGMODE,this._scene.getEngine(),!1),this._ssaoCombinePostProcess.onApply=function(e){e.setTextureFromPostProcess("originalColor",t._originalColorPostProcess)}},t.prototype._createRandomTexture=function(){this._randomTexture=new Ar.DynamicTexture("SSAORandomTexture",512,this._scene,!1,Ar.Texture.TRILINEAR_SAMPLINGMODE),this._randomTexture.wrapU=Ar.Texture.WRAP_ADDRESSMODE,this._randomTexture.wrapV=Ar.Texture.WRAP_ADDRESSMODE;for(var e=this._randomTexture.getContext(),t=function(e,t){return Math.random()*(t-e)+e},i=Ar.Vector3.Zero(),r=0;r<512;r++)for(var n=0;n<512;n++)i.x=t(0,1),i.y=t(0,1),i.z=0,i.normalize(),i.scaleInPlace(255),i.x=Math.floor(i.x),i.y=Math.floor(i.y),e.fillStyle="rgb("+i.x+", "+i.y+", "+i.z+")",e.fillRect(r,n,1,1);this._randomTexture.update(!1)},X([Ar.serialize()],t.prototype,"totalStrength",void 0),X([Ar.serialize()],t.prototype,"maxZ",void 0),X([Ar.serialize()],t.prototype,"minZAspect",void 0),X([Ar.serialize("samples")],t.prototype,"_samples",void 0),X([Ar.serialize("expensiveBlur")],t.prototype,"_expensiveBlur",void 0),X([Ar.serialize()],t.prototype,"radius",void 0),X([Ar.serialize()],t.prototype,"base",void 0),t}(Ar.PostProcessRenderPipeline),Ar.SSAO2RenderingPipeline=Pr,Mr=us||(us={}),Sr=function(e){function t(t,i,r,n,o){void 0===n&&(n=1);var s=e.call(this,r.getEngine(),t)||this;return s.LensChromaticAberrationEffect="LensChromaticAberrationEffect",s.HighlightsEnhancingEffect="HighlightsEnhancingEffect",s.LensDepthOfFieldEffect="LensDepthOfFieldEffect",s._scene=r,s._depthTexture=r.enableDepthRenderer().getDepthMap(),i.grain_texture?s._grainTexture=i.grain_texture:s._createGrainTexture(),s._edgeBlur=i.edge_blur?i.edge_blur:0,s._grainAmount=i.grain_amount?i.grain_amount:0,s._chromaticAberration=i.chromatic_aberration?i.chromatic_aberration:0,s._distortion=i.distortion?i.distortion:0,s._highlightsGain=void 0!==i.dof_gain?i.dof_gain:-1,s._highlightsThreshold=i.dof_threshold?i.dof_threshold:1,s._dofDistance=void 0!==i.dof_focus_distance?i.dof_focus_distance:-1,s._dofAperture=i.dof_aperture?i.dof_aperture:1,s._dofDarken=i.dof_darken?i.dof_darken:0,s._dofPentagon=void 0===i.dof_pentagon||i.dof_pentagon,s._blurNoise=void 0===i.blur_noise||i.blur_noise,s._createChromaticAberrationPostProcess(n),s._createHighlightsPostProcess(n),s._createDepthOfFieldPostProcess(n/4),s.addEffect(new Mr.PostProcessRenderEffect(r.getEngine(),s.LensChromaticAberrationEffect,function(){return s._chromaticAberrationPostProcess},!0)),s.addEffect(new Mr.PostProcessRenderEffect(r.getEngine(),s.HighlightsEnhancingEffect,function(){return s._highlightsPostProcess},!0)),s.addEffect(new Mr.PostProcessRenderEffect(r.getEngine(),s.LensDepthOfFieldEffect,function(){return s._depthOfFieldPostProcess},!0)),-1===s._highlightsGain&&s._disableEffect(s.HighlightsEnhancingEffect,null),r.postProcessRenderPipelineManager.addPipeline(s),o&&r.postProcessRenderPipelineManager.attachCamerasToRenderPipeline(t,o),s}return Y(t,e),t.prototype.setEdgeBlur=function(e){this._edgeBlur=e},t.prototype.disableEdgeBlur=function(){this._edgeBlur=0},t.prototype.setGrainAmount=function(e){this._grainAmount=e},t.prototype.disableGrain=function(){this._grainAmount=0},t.prototype.setChromaticAberration=function(e){this._chromaticAberration=e},t.prototype.disableChromaticAberration=function(){this._chromaticAberration=0},t.prototype.setEdgeDistortion=function(e){this._distortion=e},t.prototype.disableEdgeDistortion=function(){this._distortion=0},t.prototype.setFocusDistance=function(e){this._dofDistance=e},t.prototype.disableDepthOfField=function(){this._dofDistance=-1},t.prototype.setAperture=function(e){this._dofAperture=e},t.prototype.setDarkenOutOfFocus=function(e){this._dofDarken=e},t.prototype.enablePentagonBokeh=function(){this._highlightsPostProcess.updateEffect("#define PENTAGON\n")},t.prototype.disablePentagonBokeh=function(){this._highlightsPostProcess.updateEffect()},t.prototype.enableNoiseBlur=function(){this._blurNoise=!0},t.prototype.disableNoiseBlur=function(){this._blurNoise=!1},t.prototype.setHighlightsGain=function(e){this._highlightsGain=e},t.prototype.setHighlightsThreshold=function(e){-1===this._highlightsGain&&(this._highlightsGain=1),this._highlightsThreshold=e},t.prototype.disableHighlights=function(){this._highlightsGain=-1},t.prototype.dispose=function(e){void 0===e&&(e=!1),this._scene.postProcessRenderPipelineManager.detachCamerasFromRenderPipeline(this._name,this._scene.cameras),this._chromaticAberrationPostProcess=null,this._highlightsPostProcess=null,this._depthOfFieldPostProcess=null,this._grainTexture.dispose(),e&&this._scene.disableDepthRenderer()},t.prototype._createChromaticAberrationPostProcess=function(e){var t=this;this._chromaticAberrationPostProcess=new Mr.PostProcess("LensChromaticAberration","chromaticAberration",["chromatic_aberration","screen_width","screen_height"],[],e,null,Mr.Texture.TRILINEAR_SAMPLINGMODE,this._scene.getEngine(),!1),this._chromaticAberrationPostProcess.onApply=function(e){e.setFloat("chromatic_aberration",t._chromaticAberration),e.setFloat("screen_width",t._scene.getEngine().getRenderWidth()),e.setFloat("screen_height",t._scene.getEngine().getRenderHeight())}},t.prototype._createHighlightsPostProcess=function(e){var t=this;this._highlightsPostProcess=new Mr.PostProcess("LensHighlights","lensHighlights",["gain","threshold","screen_width","screen_height"],[],e,null,Mr.Texture.TRILINEAR_SAMPLINGMODE,this._scene.getEngine(),!1,this._dofPentagon?"#define PENTAGON\n":""),this._highlightsPostProcess.onApply=function(e){e.setFloat("gain",t._highlightsGain),e.setFloat("threshold",t._highlightsThreshold),e.setTextureFromPostProcess("textureSampler",t._chromaticAberrationPostProcess),e.setFloat("screen_width",t._scene.getEngine().getRenderWidth()),e.setFloat("screen_height",t._scene.getEngine().getRenderHeight())}},t.prototype._createDepthOfFieldPostProcess=function(e){var t=this;this._depthOfFieldPostProcess=new Mr.PostProcess("LensDepthOfField","depthOfField",["grain_amount","blur_noise","screen_width","screen_height","distortion","dof_enabled","screen_distance","aperture","darken","edge_blur","highlights","near","far"],["depthSampler","grainSampler","highlightsSampler"],e,null,Mr.Texture.TRILINEAR_SAMPLINGMODE,this._scene.getEngine(),!1),this._depthOfFieldPostProcess.onApply=function(e){e.setTexture("depthSampler",t._depthTexture),e.setTexture("grainSampler",t._grainTexture),e.setTextureFromPostProcess("textureSampler",t._highlightsPostProcess),e.setTextureFromPostProcess("highlightsSampler",t._depthOfFieldPostProcess),e.setFloat("grain_amount",t._grainAmount),e.setBool("blur_noise",t._blurNoise),e.setFloat("screen_width",t._scene.getEngine().getRenderWidth()),e.setFloat("screen_height",t._scene.getEngine().getRenderHeight()),e.setFloat("distortion",t._distortion),e.setBool("dof_enabled",-1!==t._dofDistance),e.setFloat("screen_distance",1/(.1-1/t._dofDistance)),e.setFloat("aperture",t._dofAperture),e.setFloat("darken",t._dofDarken),e.setFloat("edge_blur",t._edgeBlur),e.setBool("highlights",-1!==t._highlightsGain),t._scene.activeCamera&&(e.setFloat("near",t._scene.activeCamera.minZ),e.setFloat("far",t._scene.activeCamera.maxZ))}},t.prototype._createGrainTexture=function(){this._grainTexture=new Mr.DynamicTexture("LensNoiseTexture",512,this._scene,!1,Mr.Texture.BILINEAR_SAMPLINGMODE),this._grainTexture.wrapU=Mr.Texture.WRAP_ADDRESSMODE,this._grainTexture.wrapV=Mr.Texture.WRAP_ADDRESSMODE;for(var e,t,i,r=this._grainTexture.getContext(),n=0;n<512;n++)for(var o=0;o<512;o++)e=Math.floor(255*(t=.42,i=.58,Math.random()*(i-t)+t)),r.fillStyle="rgb("+e+", "+e+", "+e+")",r.fillRect(n,o,1,1);this._grainTexture.update(!1)},t}(Mr.PostProcessRenderPipeline),Mr.LensRenderingPipeline=Sr,Cr=us||(us={}),Rr=function(e){function t(t,i,r,n,o){void 0===n&&(n=null);var s=e.call(this,i.getEngine(),t)||this;return s.downSampleX4PostProcess=null,s.brightPassPostProcess=null,s.blurHPostProcesses=[],s.blurVPostProcesses=[],s.textureAdderPostProcess=null,s.volumetricLightPostProcess=null,s.volumetricLightSmoothXPostProcess=null,s.volumetricLightSmoothYPostProcess=null,s.volumetricLightMergePostProces=null,s.volumetricLightFinalPostProcess=null,s.luminancePostProcess=null,s.luminanceDownSamplePostProcesses=[],s.hdrPostProcess=null,s.textureAdderFinalPostProcess=null,s.lensFlareFinalPostProcess=null,s.hdrFinalPostProcess=null,s.lensFlarePostProcess=null,s.lensFlareComposePostProcess=null,s.motionBlurPostProcess=null,s.depthOfFieldPostProcess=null,s.brightThreshold=1,s.blurWidth=512,s.horizontalBlur=!1,s.exposure=1,s.lensTexture=null,s.volumetricLightCoefficient=.2,s.volumetricLightPower=4,s.volumetricLightBlurScale=64,s.sourceLight=null,s.hdrMinimumLuminance=1,s.hdrDecreaseRate=.5,s.hdrIncreaseRate=.5,s.lensColorTexture=null,s.lensFlareStrength=20,s.lensFlareGhostDispersal=1.4,s.lensFlareHaloWidth=.7,s.lensFlareDistortionStrength=16,s.lensStarTexture=null,s.lensFlareDirtTexture=null,s.depthOfFieldDistance=10,s.depthOfFieldBlurWidth=64,s.motionStrength=1,s.animations=[],s._currentDepthOfFieldSource=null,s._hdrCurrentLuminance=1,s._bloomEnabled=!0,s._depthOfFieldEnabled=!1,s._vlsEnabled=!1,s._lensFlareEnabled=!1,s._hdrEnabled=!1,s._motionBlurEnabled=!1,s._motionBlurSamples=64,s._volumetricLightStepsCount=50,s._cameras=o||[],s._scene=i,s._basePostProcess=n,s._ratio=r,s._floatTextureType=i.getEngine().getCaps().textureFloatRender?Cr.Engine.TEXTURETYPE_FLOAT:Cr.Engine.TEXTURETYPE_HALF_FLOAT,i.postProcessRenderPipelineManager.addPipeline(s),s._buildPipeline(),s}return Y(t,e),Object.defineProperty(t.prototype,"BloomEnabled",{get:function(){return this._bloomEnabled},set:function(e){this._bloomEnabled!==e&&(this._bloomEnabled=e,this._buildPipeline())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"DepthOfFieldEnabled",{get:function(){return this._depthOfFieldEnabled},set:function(e){this._depthOfFieldEnabled!==e&&(this._depthOfFieldEnabled=e,this._buildPipeline())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"LensFlareEnabled",{get:function(){return this._lensFlareEnabled},set:function(e){this._lensFlareEnabled!==e&&(this._lensFlareEnabled=e,this._buildPipeline())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"HDREnabled",{get:function(){return this._hdrEnabled},set:function(e){this._hdrEnabled!==e&&(this._hdrEnabled=e,this._buildPipeline())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"VLSEnabled",{get:function(){return this._vlsEnabled},set:function(e){if(this._vlsEnabled!==e){if(e)if(!this._scene.enableGeometryBufferRenderer())return void Cr.Tools.Warn("Geometry renderer is not supported, cannot create volumetric lights in Standard Rendering Pipeline");this._vlsEnabled=e,this._buildPipeline()}},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"MotionBlurEnabled",{get:function(){return this._motionBlurEnabled},set:function(e){this._motionBlurEnabled!==e&&(this._motionBlurEnabled=e,this._buildPipeline())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"volumetricLightStepsCount",{get:function(){return this._volumetricLightStepsCount},set:function(e){this.volumetricLightPostProcess&&this.volumetricLightPostProcess.updateEffect("#define VLS\n#define NB_STEPS "+e.toFixed(1)),this._volumetricLightStepsCount=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"motionBlurSamples",{get:function(){return this._motionBlurSamples},set:function(e){this.motionBlurPostProcess&&this.motionBlurPostProcess.updateEffect("#define MOTION_BLUR\n#define MAX_MOTION_SAMPLES "+e.toFixed(1)),this._motionBlurSamples=e},enumerable:!0,configurable:!0}),t.prototype._buildPipeline=function(){var e=this,t=this._ratio,i=this._scene;this._disposePostProcesses(),this._reset(),this._basePostProcess?this.originalPostProcess=this._basePostProcess:(this.originalPostProcess=new Cr.PostProcess("HDRPass","standard",[],[],t,null,Cr.Texture.BILINEAR_SAMPLINGMODE,i.getEngine(),!1,"#define PASS_POST_PROCESS",this._floatTextureType),this.originalPostProcess.onApply=function(t){e._currentDepthOfFieldSource=e.originalPostProcess}),this.addEffect(new Cr.PostProcessRenderEffect(i.getEngine(),"HDRPassPostProcess",function(){return e.originalPostProcess},!0)),this._currentDepthOfFieldSource=this.originalPostProcess,this._vlsEnabled&&(this._createVolumetricLightPostProcess(i,t),this.volumetricLightFinalPostProcess=new Cr.PostProcess("HDRVLSFinal","standard",[],[],t,null,Cr.Texture.BILINEAR_SAMPLINGMODE,i.getEngine(),!1,"#define PASS_POST_PROCESS",Cr.Engine.TEXTURETYPE_UNSIGNED_INT),this.addEffect(new Cr.PostProcessRenderEffect(i.getEngine(),"HDRVLSFinal",function(){return e.volumetricLightFinalPostProcess},!0))),this._bloomEnabled&&(this._createDownSampleX4PostProcess(i,t/2),this._createBrightPassPostProcess(i,t/2),this._createBlurPostProcesses(i,t/4,1),this._createTextureAdderPostProcess(i,t),this.textureAdderFinalPostProcess=new Cr.PostProcess("HDRDepthOfFieldSource","standard",[],[],t,null,Cr.Texture.BILINEAR_SAMPLINGMODE,i.getEngine(),!1,"#define PASS_POST_PROCESS",Cr.Engine.TEXTURETYPE_UNSIGNED_INT),this.addEffect(new Cr.PostProcessRenderEffect(i.getEngine(),"HDRBaseDepthOfFieldSource",function(){return e.textureAdderFinalPostProcess},!0))),this._lensFlareEnabled&&(this._createLensFlarePostProcess(i,t),this.lensFlareFinalPostProcess=new Cr.PostProcess("HDRPostLensFlareDepthOfFieldSource","standard",[],[],t,null,Cr.Texture.BILINEAR_SAMPLINGMODE,i.getEngine(),!1,"#define PASS_POST_PROCESS",Cr.Engine.TEXTURETYPE_UNSIGNED_INT),this.addEffect(new Cr.PostProcessRenderEffect(i.getEngine(),"HDRPostLensFlareDepthOfFieldSource",function(){return e.lensFlareFinalPostProcess},!0))),this._hdrEnabled&&(this._createLuminancePostProcesses(i,this._floatTextureType),this._createHdrPostProcess(i,t),this.hdrFinalPostProcess=new Cr.PostProcess("HDRPostHDReDepthOfFieldSource","standard",[],[],t,null,Cr.Texture.BILINEAR_SAMPLINGMODE,i.getEngine(),!1,"#define PASS_POST_PROCESS",Cr.Engine.TEXTURETYPE_UNSIGNED_INT),this.addEffect(new Cr.PostProcessRenderEffect(i.getEngine(),"HDRPostHDReDepthOfFieldSource",function(){return e.hdrFinalPostProcess},!0))),this._depthOfFieldEnabled&&(this._createBlurPostProcesses(i,t/2,3,"depthOfFieldBlurWidth"),this._createDepthOfFieldPostProcess(i,t)),this._motionBlurEnabled&&this._createMotionBlurPostProcess(i,t),null!==this._cameras&&this._scene.postProcessRenderPipelineManager.attachCamerasToRenderPipeline(this._name,this._cameras)},t.prototype._createDownSampleX4PostProcess=function(e,t){var i=this,r=new Array(32);this.downSampleX4PostProcess=new Cr.PostProcess("HDRDownSampleX4","standard",["dsOffsets"],[],t,null,Cr.Texture.BILINEAR_SAMPLINGMODE,e.getEngine(),!1,"#define DOWN_SAMPLE_X4",Cr.Engine.TEXTURETYPE_UNSIGNED_INT),this.downSampleX4PostProcess.onApply=function(e){for(var t=0,n=i.downSampleX4PostProcess.width,o=i.downSampleX4PostProcess.height,s=-2;s<2;s++)for(var a=-2;a<2;a++)r[t]=(s+.5)*(1/n),r[t+1]=(a+.5)*(1/o),t+=2;e.setArray2("dsOffsets",r)},this.addEffect(new Cr.PostProcessRenderEffect(e.getEngine(),"HDRDownSampleX4",function(){return i.downSampleX4PostProcess},!0))},t.prototype._createBrightPassPostProcess=function(e,t){var i=this,r=new Array(8);this.brightPassPostProcess=new Cr.PostProcess("HDRBrightPass","standard",["dsOffsets","brightThreshold"],[],t,null,Cr.Texture.BILINEAR_SAMPLINGMODE,e.getEngine(),!1,"#define BRIGHT_PASS",Cr.Engine.TEXTURETYPE_UNSIGNED_INT),this.brightPassPostProcess.onApply=function(e){var t=1/i.brightPassPostProcess.width,n=1/i.brightPassPostProcess.height;r[0]=-.5*t,r[1]=.5*n,r[2]=.5*t,r[3]=.5*n,r[4]=-.5*t,r[5]=-.5*n,r[6]=.5*t,r[7]=-.5*n,e.setArray2("dsOffsets",r),e.setFloat("brightThreshold",i.brightThreshold)},this.addEffect(new Cr.PostProcessRenderEffect(e.getEngine(),"HDRBrightPass",function(){return i.brightPassPostProcess},!0))},t.prototype._createBlurPostProcesses=function(e,t,i,r){var n=this;void 0===r&&(r="blurWidth");var o=e.getEngine(),s=new Cr.BlurPostProcess("HDRBlurH_"+i,new Cr.Vector2(1,0),this[r],t,null,Cr.Texture.BILINEAR_SAMPLINGMODE,e.getEngine(),!1,Cr.Engine.TEXTURETYPE_UNSIGNED_INT),a=new Cr.BlurPostProcess("HDRBlurV_"+i,new Cr.Vector2(0,1),this[r],t,null,Cr.Texture.BILINEAR_SAMPLINGMODE,e.getEngine(),!1,Cr.Engine.TEXTURETYPE_UNSIGNED_INT);s.onActivateObservable.add(function(){var e=s.width/o.getRenderWidth();s.kernel=n[r]*e}),a.onActivateObservable.add(function(){var e=a.height/o.getRenderHeight();a.kernel=n.horizontalBlur?64*e:n[r]*e}),this.addEffect(new Cr.PostProcessRenderEffect(e.getEngine(),"HDRBlurH"+i,function(){return s},!0)),this.addEffect(new Cr.PostProcessRenderEffect(e.getEngine(),"HDRBlurV"+i,function(){return a},!0)),this.blurHPostProcesses.push(s),this.blurVPostProcesses.push(a)},t.prototype._createTextureAdderPostProcess=function(e,t){var i=this;this.textureAdderPostProcess=new Cr.PostProcess("HDRTextureAdder","standard",["exposure"],["otherSampler","lensSampler"],t,null,Cr.Texture.BILINEAR_SAMPLINGMODE,e.getEngine(),!1,"#define TEXTURE_ADDER",Cr.Engine.TEXTURETYPE_UNSIGNED_INT),this.textureAdderPostProcess.onApply=function(e){e.setTextureFromPostProcess("otherSampler",i._vlsEnabled?i._currentDepthOfFieldSource:i.originalPostProcess),e.setTexture("lensSampler",i.lensTexture),e.setFloat("exposure",i.exposure),i._currentDepthOfFieldSource=i.textureAdderFinalPostProcess},this.addEffect(new Cr.PostProcessRenderEffect(e.getEngine(),"HDRTextureAdder",function(){return i.textureAdderPostProcess},!0))},t.prototype._createVolumetricLightPostProcess=function(e,t){var i=this,r=e.enableGeometryBufferRenderer();r.enablePosition=!0;var n=r.getGBuffer();this.volumetricLightPostProcess=new Cr.PostProcess("HDRVLS","standard",["shadowViewProjection","cameraPosition","sunDirection","sunColor","scatteringCoefficient","scatteringPower","depthValues"],["shadowMapSampler","positionSampler"],t/8,null,Cr.Texture.BILINEAR_SAMPLINGMODE,e.getEngine(),!1,"#define VLS\n#define NB_STEPS "+this._volumetricLightStepsCount.toFixed(1));var o=Cr.Vector2.Zero();this.volumetricLightPostProcess.onApply=function(e){if(i.sourceLight&&i.sourceLight.getShadowGenerator()&&i._scene.activeCamera){var t=i.sourceLight.getShadowGenerator();e.setTexture("shadowMapSampler",t.getShadowMap()),e.setTexture("positionSampler",n.textures[2]),e.setColor3("sunColor",i.sourceLight.diffuse),e.setVector3("sunDirection",i.sourceLight.getShadowDirection()),e.setVector3("cameraPosition",i._scene.activeCamera.globalPosition),e.setMatrix("shadowViewProjection",t.getTransformMatrix()),e.setFloat("scatteringCoefficient",i.volumetricLightCoefficient),e.setFloat("scatteringPower",i.volumetricLightPower),o.x=t.getLight().getDepthMinZ(i._scene.activeCamera),o.y=t.getLight().getDepthMaxZ(i._scene.activeCamera),e.setVector2("depthValues",o)}},this.addEffect(new Cr.PostProcessRenderEffect(e.getEngine(),"HDRVLS",function(){return i.volumetricLightPostProcess},!0)),this._createBlurPostProcesses(e,t/4,0,"volumetricLightBlurScale"),this.volumetricLightMergePostProces=new Cr.PostProcess("HDRVLSMerge","standard",[],["originalSampler"],t,null,Cr.Texture.BILINEAR_SAMPLINGMODE,e.getEngine(),!1,"#define VLSMERGE"),this.volumetricLightMergePostProces.onApply=function(e){e.setTextureFromPostProcess("originalSampler",i.originalPostProcess),i._currentDepthOfFieldSource=i.volumetricLightFinalPostProcess},this.addEffect(new Cr.PostProcessRenderEffect(e.getEngine(),"HDRVLSMerge",function(){return i.volumetricLightMergePostProces},!0))},t.prototype._createLuminancePostProcesses=function(e,i){var r=this,n=Math.pow(3,t.LuminanceSteps);this.luminancePostProcess=new Cr.PostProcess("HDRLuminance","standard",["lumOffsets"],[],{width:n,height:n},null,Cr.Texture.BILINEAR_SAMPLINGMODE,e.getEngine(),!1,"#define LUMINANCE",i);var o=[];this.luminancePostProcess.onApply=function(e){var t=1/r.luminancePostProcess.width,i=1/r.luminancePostProcess.height;o[0]=-.5*t,o[1]=.5*i,o[2]=.5*t,o[3]=.5*i,o[4]=-.5*t,o[5]=-.5*i,o[6]=.5*t,o[7]=-.5*i,e.setArray2("lumOffsets",o)},this.addEffect(new Cr.PostProcessRenderEffect(e.getEngine(),"HDRLuminance",function(){return r.luminancePostProcess},!0));for(var s=t.LuminanceSteps-1;s>=0;s--){n=Math.pow(3,s);var a="#define LUMINANCE_DOWN_SAMPLE\n";0===s&&(a+="#define FINAL_DOWN_SAMPLER");var h=new Cr.PostProcess("HDRLuminanceDownSample"+s,"standard",["dsOffsets","halfDestPixelSize"],[],{width:n,height:n},null,Cr.Texture.BILINEAR_SAMPLINGMODE,e.getEngine(),!1,a,i);this.luminanceDownSamplePostProcesses.push(h)}var l=this.luminancePostProcess;this.luminanceDownSamplePostProcesses.forEach(function(t,i){var n=new Array(18);t.onApply=function(e){if(l){for(var o=0,s=-1;s<2;s++)for(var a=-1;a<2;a++)n[o]=s/l.width,n[o+1]=a/l.height,o+=2;e.setArray2("dsOffsets",n),e.setFloat("halfDestPixelSize",.5/l.width),l=i===r.luminanceDownSamplePostProcesses.length-1?r.luminancePostProcess:t}},i===r.luminanceDownSamplePostProcesses.length-1&&(t.onAfterRender=function(t){var i=e.getEngine().readPixels(0,0,1,1),n=new Cr.Vector4(1/16581375,1/65025,1/255,1);r._hdrCurrentLuminance=(i[0]*n.x+i[1]*n.y+i[2]*n.z+i[3]*n.w)/100}),r.addEffect(new Cr.PostProcessRenderEffect(e.getEngine(),"HDRLuminanceDownSample"+i,function(){return t},!0))})},t.prototype._createHdrPostProcess=function(e,t){var i=this;this.hdrPostProcess=new Cr.PostProcess("HDR","standard",["averageLuminance"],["textureAdderSampler"],t,null,Cr.Texture.BILINEAR_SAMPLINGMODE,e.getEngine(),!1,"#define HDR",Cr.Engine.TEXTURETYPE_UNSIGNED_INT);var r=1,n=0,o=0;this.hdrPostProcess.onApply=function(t){if(t.setTextureFromPostProcess("textureAdderSampler",i._currentDepthOfFieldSource),n+=e.getEngine().getDeltaTime(),r<0)r=i._hdrCurrentLuminance;else{var s=(o-n)/1e3;i._hdrCurrentLuminance<r+i.hdrDecreaseRate*s?r+=i.hdrDecreaseRate*s:i._hdrCurrentLuminance>r-i.hdrIncreaseRate*s?r-=i.hdrIncreaseRate*s:r=i._hdrCurrentLuminance}r=Cr.Scalar.Clamp(r,i.hdrMinimumLuminance,1e20),t.setFloat("averageLuminance",r),o=n,i._currentDepthOfFieldSource=i.hdrFinalPostProcess},this.addEffect(new Cr.PostProcessRenderEffect(e.getEngine(),"HDR",function(){return i.hdrPostProcess},!0))},t.prototype._createLensFlarePostProcess=function(e,t){var i=this;this.lensFlarePostProcess=new Cr.PostProcess("HDRLensFlare","standard",["strength","ghostDispersal","haloWidth","resolution","distortionStrength"],["lensColorSampler"],t/2,null,Cr.Texture.BILINEAR_SAMPLINGMODE,e.getEngine(),!1,"#define LENS_FLARE",Cr.Engine.TEXTURETYPE_UNSIGNED_INT),this.addEffect(new Cr.PostProcessRenderEffect(e.getEngine(),"HDRLensFlare",function(){return i.lensFlarePostProcess},!0)),this._createBlurPostProcesses(e,t/4,2),this.lensFlareComposePostProcess=new Cr.PostProcess("HDRLensFlareCompose","standard",["lensStarMatrix"],["otherSampler","lensDirtSampler","lensStarSampler"],t,null,Cr.Texture.BILINEAR_SAMPLINGMODE,e.getEngine(),!1,"#define LENS_FLARE_COMPOSE",Cr.Engine.TEXTURETYPE_UNSIGNED_INT),this.addEffect(new Cr.PostProcessRenderEffect(e.getEngine(),"HDRLensFlareCompose",function(){return i.lensFlareComposePostProcess},!0));var r=new Cr.Vector2(0,0);this.lensFlarePostProcess.onApply=function(e){e.setTextureFromPostProcess("textureSampler",i._bloomEnabled?i.blurHPostProcesses[0]:i.originalPostProcess),e.setTexture("lensColorSampler",i.lensColorTexture),e.setFloat("strength",i.lensFlareStrength),e.setFloat("ghostDispersal",i.lensFlareGhostDispersal),e.setFloat("haloWidth",i.lensFlareHaloWidth),r.x=i.lensFlarePostProcess.width,r.y=i.lensFlarePostProcess.height,e.setVector2("resolution",r),e.setFloat("distortionStrength",i.lensFlareDistortionStrength)};var n=Cr.Matrix.FromValues(2,0,-1,0,0,2,-1,0,0,0,1,0,0,0,0,1),o=Cr.Matrix.FromValues(.5,0,.5,0,0,.5,.5,0,0,0,1,0,0,0,0,1);this.lensFlareComposePostProcess.onApply=function(e){if(i._scene.activeCamera){e.setTextureFromPostProcess("otherSampler",i._currentDepthOfFieldSource),e.setTexture("lensDirtSampler",i.lensFlareDirtTexture),e.setTexture("lensStarSampler",i.lensStarTexture);var t=i._scene.activeCamera.getViewMatrix().getRow(0),r=i._scene.activeCamera.getViewMatrix().getRow(2),s=Cr.Vector3.Dot(t.toVector3(),new Cr.Vector3(1,0,0))+Cr.Vector3.Dot(r.toVector3(),new Cr.Vector3(0,0,1));s*=4;var a=Cr.Matrix.FromValues(.5*Math.cos(s),-Math.sin(s),0,0,Math.sin(s),.5*Math.cos(s),0,0,0,0,1,0,0,0,0,1),h=o.multiply(a).multiply(n);e.setMatrix("lensStarMatrix",h),i._currentDepthOfFieldSource=i.lensFlareFinalPostProcess}}},t.prototype._createDepthOfFieldPostProcess=function(e,t){var i=this;this.depthOfFieldPostProcess=new Cr.PostProcess("HDRDepthOfField","standard",["distance"],["otherSampler","depthSampler"],t,null,Cr.Texture.BILINEAR_SAMPLINGMODE,e.getEngine(),!1,"#define DEPTH_OF_FIELD",Cr.Engine.TEXTURETYPE_UNSIGNED_INT),this.depthOfFieldPostProcess.onApply=function(e){e.setTextureFromPostProcess("otherSampler",i._currentDepthOfFieldSource),e.setTexture("depthSampler",i._getDepthTexture()),e.setFloat("distance",i.depthOfFieldDistance)},this.addEffect(new Cr.PostProcessRenderEffect(e.getEngine(),"HDRDepthOfField",function(){return i.depthOfFieldPostProcess},!0))},t.prototype._createMotionBlurPostProcess=function(e,t){var i=this;this.motionBlurPostProcess=new Cr.PostProcess("HDRMotionBlur","standard",["inverseViewProjection","prevViewProjection","screenSize","motionScale","motionStrength"],["depthSampler"],t,null,Cr.Texture.BILINEAR_SAMPLINGMODE,e.getEngine(),!1,"#define MOTION_BLUR\n#define MAX_MOTION_SAMPLES "+this.motionBlurSamples.toFixed(1),Cr.Engine.TEXTURETYPE_UNSIGNED_INT);var r=0,n=Cr.Matrix.Identity(),o=Cr.Matrix.Identity(),s=Cr.Matrix.Identity(),a=Cr.Vector2.Zero();this.motionBlurPostProcess.onApply=function(t){(s=e.getProjectionMatrix().multiply(e.getViewMatrix())).invertToRef(o),t.setMatrix("inverseViewProjection",o),t.setMatrix("prevViewProjection",n),n=s,a.x=i.motionBlurPostProcess.width,a.y=i.motionBlurPostProcess.height,t.setVector2("screenSize",a),r=e.getEngine().getFps()/60,t.setFloat("motionScale",r),t.setFloat("motionStrength",i.motionStrength),t.setTexture("depthSampler",i._getDepthTexture())},this.addEffect(new Cr.PostProcessRenderEffect(e.getEngine(),"HDRMotionBlur",function(){return i.motionBlurPostProcess},!0))},t.prototype._getDepthTexture=function(){return this._scene.getEngine().getCaps().drawBuffersExtension?this._scene.enableGeometryBufferRenderer().getGBuffer().textures[0]:this._scene.enableDepthRenderer().getDepthMap()},t.prototype._disposePostProcesses=function(){for(var e=0;e<this._cameras.length;e++){var t=this._cameras[e];this.originalPostProcess&&this.originalPostProcess.dispose(t),this.downSampleX4PostProcess&&this.downSampleX4PostProcess.dispose(t),this.brightPassPostProcess&&this.brightPassPostProcess.dispose(t),this.textureAdderPostProcess&&this.textureAdderPostProcess.dispose(t),this.textureAdderFinalPostProcess&&this.textureAdderFinalPostProcess.dispose(t),this.volumetricLightPostProcess&&this.volumetricLightPostProcess.dispose(t),this.volumetricLightSmoothXPostProcess&&this.volumetricLightSmoothXPostProcess.dispose(t),this.volumetricLightSmoothYPostProcess&&this.volumetricLightSmoothYPostProcess.dispose(t),this.volumetricLightMergePostProces&&this.volumetricLightMergePostProces.dispose(t),this.volumetricLightFinalPostProcess&&this.volumetricLightFinalPostProcess.dispose(t),this.lensFlarePostProcess&&this.lensFlarePostProcess.dispose(t),this.lensFlareComposePostProcess&&this.lensFlareComposePostProcess.dispose(t);for(var i=0;i<this.luminanceDownSamplePostProcesses.length;i++)this.luminanceDownSamplePostProcesses[i].dispose(t);this.luminancePostProcess&&this.luminancePostProcess.dispose(t),this.hdrPostProcess&&this.hdrPostProcess.dispose(t),this.hdrFinalPostProcess&&this.hdrFinalPostProcess.dispose(t),this.depthOfFieldPostProcess&&this.depthOfFieldPostProcess.dispose(t),this.motionBlurPostProcess&&this.motionBlurPostProcess.dispose(t);for(i=0;i<this.blurHPostProcesses.length;i++)this.blurHPostProcesses[i].dispose(t);for(i=0;i<this.blurVPostProcesses.length;i++)this.blurVPostProcesses[i].dispose(t)}this.originalPostProcess=null,this.downSampleX4PostProcess=null,this.brightPassPostProcess=null,this.textureAdderPostProcess=null,this.textureAdderFinalPostProcess=null,this.volumetricLightPostProcess=null,this.volumetricLightSmoothXPostProcess=null,this.volumetricLightSmoothYPostProcess=null,this.volumetricLightMergePostProces=null,this.volumetricLightFinalPostProcess=null,this.lensFlarePostProcess=null,this.lensFlareComposePostProcess=null,this.luminancePostProcess=null,this.hdrPostProcess=null,this.hdrFinalPostProcess=null,this.depthOfFieldPostProcess=null,this.motionBlurPostProcess=null,this.luminanceDownSamplePostProcesses=[],this.blurHPostProcesses=[],this.blurVPostProcesses=[]},t.prototype.dispose=function(){this._disposePostProcesses(),this._scene.postProcessRenderPipelineManager.detachCamerasFromRenderPipeline(this._name,this._cameras),e.prototype.dispose.call(this)},t.prototype.serialize=function(){var e=Cr.SerializationHelper.Serialize(this);return e.customType="StandardRenderingPipeline",e},t.Parse=function(e,i,r){return Cr.SerializationHelper.Parse(function(){return new t(e._name,i,e._ratio)},e,i,r)},t.LuminanceSteps=6,X([Cr.serialize()],t.prototype,"brightThreshold",void 0),X([Cr.serialize()],t.prototype,"blurWidth",void 0),X([Cr.serialize()],t.prototype,"horizontalBlur",void 0),X([Cr.serialize()],t.prototype,"exposure",void 0),X([Cr.serializeAsTexture("lensTexture")],t.prototype,"lensTexture",void 0),X([Cr.serialize()],t.prototype,"volumetricLightCoefficient",void 0),X([Cr.serialize()],t.prototype,"volumetricLightPower",void 0),X([Cr.serialize()],t.prototype,"volumetricLightBlurScale",void 0),X([Cr.serialize()],t.prototype,"hdrMinimumLuminance",void 0),X([Cr.serialize()],t.prototype,"hdrDecreaseRate",void 0),X([Cr.serialize()],t.prototype,"hdrIncreaseRate",void 0),X([Cr.serializeAsTexture("lensColorTexture")],t.prototype,"lensColorTexture",void 0),X([Cr.serialize()],t.prototype,"lensFlareStrength",void 0),X([Cr.serialize()],t.prototype,"lensFlareGhostDispersal",void 0),X([Cr.serialize()],t.prototype,"lensFlareHaloWidth",void 0),X([Cr.serialize()],t.prototype,"lensFlareDistortionStrength",void 0),X([Cr.serializeAsTexture("lensStarTexture")],t.prototype,"lensStarTexture",void 0),X([Cr.serializeAsTexture("lensFlareDirtTexture")],t.prototype,"lensFlareDirtTexture",void 0),X([Cr.serialize()],t.prototype,"depthOfFieldDistance",void 0),X([Cr.serialize()],t.prototype,"depthOfFieldBlurWidth",void 0),X([Cr.serialize()],t.prototype,"motionStrength",void 0),X([Cr.serialize()],t.prototype,"_ratio",void 0),X([Cr.serialize()],t.prototype,"BloomEnabled",null),X([Cr.serialize()],t.prototype,"DepthOfFieldEnabled",null),X([Cr.serialize()],t.prototype,"LensFlareEnabled",null),X([Cr.serialize()],t.prototype,"HDREnabled",null),X([Cr.serialize()],t.prototype,"VLSEnabled",null),X([Cr.serialize()],t.prototype,"MotionBlurEnabled",null),X([Cr.serialize()],t.prototype,"volumetricLightStepsCount",null),X([Cr.serialize()],t.prototype,"motionBlurSamples",null),t}(Cr.PostProcessRenderPipeline),Cr.StandardRenderingPipeline=Rr,Or=us||(us={}),Ir=function(e){function t(t,i,r,n,o,s,a){void 0===r&&(r=null),void 0===a&&(a=Or.Engine.TEXTURETYPE_UNSIGNED_INT);var h=e.call(this,t,"fxaa",["texelSize"],null,i,r,n||Or.Texture.BILINEAR_SAMPLINGMODE,o,s,null,a,"fxaa")||this;return h.onApplyObservable.add(function(e){var t=h.texelSize;e.setFloat2("texelSize",t.x,t.y)}),h}return Y(t,e),t}(Or.PostProcess),Or.FxaaPostProcess=Ir,wr=us||(us={}),Dr=function(e){function t(t,i,r,n,o){void 0===o&&(o=!0);var s=e.call(this,r.getEngine(),t)||this;s.PassPostProcessId="PassPostProcessEffect",s.HighLightsPostProcessId="HighLightsPostProcessEffect",s.BlurXPostProcessId="BlurXPostProcessEffect",s.BlurYPostProcessId="BlurYPostProcessEffect",s.CopyBackPostProcessId="CopyBackPostProcessEffect",s.ImageProcessingPostProcessId="ImageProcessingPostProcessEffect",s.FxaaPostProcessId="FxaaPostProcessEffect",s.FinalMergePostProcessId="FinalMergePostProcessEffect",s.animations=[],s._bloomEnabled=!1,s._fxaaEnabled=!1,s._imageProcessingEnabled=!0,s._bloomScale=.6,s._buildAllowed=!0,s.bloomKernel=64,s._bloomWeight=.15,s._cameras=n||[],s._buildAllowed=o,s._scene=r;var a=s._scene.getEngine().getCaps();return s._hdr=i&&(a.textureHalfFloatRender||a.textureFloatRender),s._hdr?a.textureHalfFloatRender?s._defaultPipelineTextureType=wr.Engine.TEXTURETYPE_HALF_FLOAT:a.textureFloatRender&&(s._defaultPipelineTextureType=wr.Engine.TEXTURETYPE_FLOAT):s._defaultPipelineTextureType=wr.Engine.TEXTURETYPE_UNSIGNED_INT,r.postProcessRenderPipelineManager.addPipeline(s),s._buildPipeline(),s}return Y(t,e),Object.defineProperty(t.prototype,"bloomWeight",{get:function(){return this._bloomWeight},set:function(e){this._bloomWeight!==e&&(this._bloomWeight=e,this._hdr&&this.copyBack&&(this.copyBack.alphaConstants=new wr.Color4(e,e,e,e)))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"bloomScale",{get:function(){return this._bloomScale},set:function(e){this._bloomScale!==e&&(this._bloomScale=e,this._buildPipeline())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"bloomEnabled",{get:function(){return this._bloomEnabled},set:function(e){this._bloomEnabled!==e&&(this._bloomEnabled=e,this._buildPipeline())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"fxaaEnabled",{get:function(){return this._fxaaEnabled},set:function(e){this._fxaaEnabled!==e&&(this._fxaaEnabled=e,this._buildPipeline())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"imageProcessingEnabled",{get:function(){return this._imageProcessingEnabled},set:function(e){this._imageProcessingEnabled!==e&&(this._imageProcessingEnabled=e,this._buildPipeline())},enumerable:!0,configurable:!0}),t.prototype.prepare=function(){var e=this._buildAllowed;this._buildAllowed=!0,this._buildPipeline(),this._buildAllowed=e},t.prototype._buildPipeline=function(){var e=this;if(this._buildAllowed){var t=this._scene.getEngine();if(this._disposePostProcesses(),this._reset(),this.bloomEnabled){if(this.pass=new wr.PassPostProcess("sceneRenderTarget",1,null,wr.Texture.BILINEAR_SAMPLINGMODE,t,!1,this._defaultPipelineTextureType),this.addEffect(new wr.PostProcessRenderEffect(t,this.PassPostProcessId,function(){return e.pass},!0)),this._hdr||(this.highlights=new wr.HighlightsPostProcess("highlights",this.bloomScale,null,wr.Texture.BILINEAR_SAMPLINGMODE,t,!1,this._defaultPipelineTextureType),this.addEffect(new wr.PostProcessRenderEffect(t,this.HighLightsPostProcessId,function(){return e.highlights},!0)),this.highlights.autoClear=!1,this.highlights.alwaysForcePOT=!0),this.blurX=new wr.BlurPostProcess("horizontal blur",new wr.Vector2(1,0),10,this.bloomScale,null,wr.Texture.BILINEAR_SAMPLINGMODE,t,!1,this._defaultPipelineTextureType),this.addEffect(new wr.PostProcessRenderEffect(t,this.BlurXPostProcessId,function(){return e.blurX},!0)),this.blurX.alwaysForcePOT=!0,this.blurX.autoClear=!1,this.blurX.onActivateObservable.add(function(){var i=e.blurX.width/t.getRenderWidth(!0);e.blurX.kernel=e.bloomKernel*i}),this.blurY=new wr.BlurPostProcess("vertical blur",new wr.Vector2(0,1),10,this.bloomScale,null,wr.Texture.BILINEAR_SAMPLINGMODE,t,!1,this._defaultPipelineTextureType),this.addEffect(new wr.PostProcessRenderEffect(t,this.BlurYPostProcessId,function(){return e.blurY},!0)),this.blurY.alwaysForcePOT=!0,this.blurY.autoClear=!1,this.blurY.onActivateObservable.add(function(){var i=e.blurY.height/t.getRenderHeight(!0);e.blurY.kernel=e.bloomKernel*i}),this.copyBack=new wr.PassPostProcess("bloomBlendBlit",this.bloomScale,null,wr.Texture.BILINEAR_SAMPLINGMODE,t,!1,this._defaultPipelineTextureType),this.addEffect(new wr.PostProcessRenderEffect(t,this.CopyBackPostProcessId,function(){return e.copyBack},!0)),this.copyBack.alwaysForcePOT=!0,this._hdr){this.copyBack.alphaMode=wr.Engine.ALPHA_INTERPOLATE;var i=this.bloomWeight;this.copyBack.alphaConstants=new wr.Color4(i,i,i,i)}else this.copyBack.alphaMode=wr.Engine.ALPHA_SCREENMODE;this.copyBack.autoClear=!1}this._imageProcessingEnabled&&(this.imageProcessing=new wr.ImageProcessingPostProcess("imageProcessing",1,null,wr.Texture.BILINEAR_SAMPLINGMODE,t,!1,this._defaultPipelineTextureType),this._hdr?this.addEffect(new wr.PostProcessRenderEffect(t,this.ImageProcessingPostProcessId,function(){return e.imageProcessing},!0)):this._scene.imageProcessingConfiguration.applyByPostProcess=!1),this.fxaaEnabled?(this.fxaa=new wr.FxaaPostProcess("fxaa",1,null,wr.Texture.BILINEAR_SAMPLINGMODE,t,!1,this._defaultPipelineTextureType),this.addEffect(new wr.PostProcessRenderEffect(t,this.FxaaPostProcessId,function(){return e.fxaa},!0)),this.fxaa.autoClear=!(this.bloomEnabled||this._hdr&&this.imageProcessing)):this._hdr&&this.imageProcessing?this.finalMerge=this.imageProcessing:(this.finalMerge=new wr.PassPostProcess("finalMerge",1,null,wr.Texture.BILINEAR_SAMPLINGMODE,t,!1,this._defaultPipelineTextureType),this.addEffect(new wr.PostProcessRenderEffect(t,this.FinalMergePostProcessId,function(){return e.finalMerge},!0)),this.finalMerge.autoClear=!(this.bloomEnabled||this._hdr&&this.imageProcessing)),this.bloomEnabled&&(this._hdr?(this.copyBack.shareOutputWith(this.blurX),this.imageProcessing?(this.imageProcessing.shareOutputWith(this.pass),this.imageProcessing.autoClear=!1):this.fxaa?this.fxaa.shareOutputWith(this.pass):this.finalMerge.shareOutputWith(this.pass)):this.fxaa?this.fxaa.shareOutputWith(this.pass):this.finalMerge.shareOutputWith(this.pass)),null!==this._cameras&&this._scene.postProcessRenderPipelineManager.attachCamerasToRenderPipeline(this._name,this._cameras)}},t.prototype._disposePostProcesses=function(){for(var e=0;e<this._cameras.length;e++){var t=this._cameras[e];this.pass&&this.pass.dispose(t),this.highlights&&this.highlights.dispose(t),this.blurX&&this.blurX.dispose(t),this.blurY&&this.blurY.dispose(t),this.copyBack&&this.copyBack.dispose(t),this.imageProcessing&&this.imageProcessing.dispose(t),this.fxaa&&this.fxaa.dispose(t),this.finalMerge&&this.finalMerge.dispose(t)}this.pass=null,this.highlights=null,this.blurX=null,this.blurY=null,this.copyBack=null,this.imageProcessing=null,this.fxaa=null,this.finalMerge=null},t.prototype.dispose=function(){this._disposePostProcesses(),this._scene.postProcessRenderPipelineManager.detachCamerasFromRenderPipeline(this._name,this._cameras),e.prototype.dispose.call(this)},t.prototype.serialize=function(){var e=wr.SerializationHelper.Serialize(this);return e.customType="DefaultRenderingPipeline",e},t.Parse=function(e,i,r){return wr.SerializationHelper.Parse(function(){return new t(e._name,e._name._hdr,i)},e,i,r)},X([wr.serialize()],t.prototype,"bloomKernel",void 0),X([wr.serialize()],t.prototype,"_bloomWeight",void 0),X([wr.serialize()],t.prototype,"_hdr",void 0),X([wr.serialize()],t.prototype,"bloomWeight",null),X([wr.serialize()],t.prototype,"bloomScale",null),X([wr.serialize()],t.prototype,"bloomEnabled",null),X([wr.serialize()],t.prototype,"fxaaEnabled",null),X([wr.serialize()],t.prototype,"imageProcessingEnabled",null),t}(wr.PostProcessRenderPipeline),wr.DefaultRenderingPipeline=Dr,Lr=us||(us={}),Br=function(){function e(e,t){void 0===t&&(t=1),this._enablePosition=!1,this._scene=e,this._ratio=t,this._createRenderTargets()}return Object.defineProperty(e.prototype,"renderList",{set:function(e){this._multiRenderTarget.renderList=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isSupported",{get:function(){return this._multiRenderTarget.isSupported},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"enablePosition",{get:function(){return this._enablePosition},set:function(e){this._enablePosition=e,this.dispose(),this._createRenderTargets()},enumerable:!0,configurable:!0}),e.prototype.isReady=function(e,t){var i=e.getMaterial();if(i&&i.disableDepthWrite)return!1;var r=[],n=[Lr.VertexBuffer.PositionKind,Lr.VertexBuffer.NormalKind],o=e.getMesh();i&&i.needAlphaTesting()&&(r.push("#define ALPHATEST"),o.isVerticesDataPresent(Lr.VertexBuffer.UVKind)&&(n.push(Lr.VertexBuffer.UVKind),r.push("#define UV1")),o.isVerticesDataPresent(Lr.VertexBuffer.UV2Kind)&&(n.push(Lr.VertexBuffer.UV2Kind),r.push("#define UV2"))),this._enablePosition&&r.push("#define POSITION"),o.useBones&&o.computeBonesUsingShaders?(n.push(Lr.VertexBuffer.MatricesIndicesKind),n.push(Lr.VertexBuffer.MatricesWeightsKind),o.numBoneInfluencers>4&&(n.push(Lr.VertexBuffer.MatricesIndicesExtraKind),n.push(Lr.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"),t&&(r.push("#define INSTANCES"),n.push("world0"),n.push("world1"),n.push("world2"),n.push("world3"));var s=r.join("\n");return this._cachedDefines!==s&&(this._cachedDefines=s,this._effect=this._scene.getEngine().createEffect("geometry",n,["world","mBones","viewProjection","diffuseMatrix","view"],["diffuseSampler"],s,void 0,void 0,void 0,{buffersCount:this._enablePosition?3:2})),this._effect.isReady()},e.prototype.getGBuffer=function(){return this._multiRenderTarget},Object.defineProperty(e.prototype,"samples",{get:function(){return this._multiRenderTarget.samples},set:function(e){this._multiRenderTarget.samples=e},enumerable:!0,configurable:!0}),e.prototype.dispose=function(){this.getGBuffer().dispose()},e.prototype._createRenderTargets=function(){var e=this,t=this._scene.getEngine(),i=this._enablePosition?3:2;if(this._multiRenderTarget=new Lr.MultiRenderTarget("gBuffer",{width:t.getRenderWidth()*this._ratio,height:t.getRenderHeight()*this._ratio},i,this._scene,{generateMipMaps:!1,generateDepthTexture:!0,defaultType:Lr.Engine.TEXTURETYPE_FLOAT}),this.isSupported){this._multiRenderTarget.wrapU=Lr.Texture.CLAMP_ADDRESSMODE,this._multiRenderTarget.wrapV=Lr.Texture.CLAMP_ADDRESSMODE,this._multiRenderTarget.refreshRate=1,this._multiRenderTarget.renderParticles=!1,this._multiRenderTarget.renderList=null,this._multiRenderTarget.onClearObservable.add(function(e){e.clear(new Lr.Color4(0,0,0,1),!0,!0,!0)});var r=function(t){var i=t.getRenderingMesh(),r=e._scene,n=r.getEngine(),o=t.getMaterial();if(o){n.setState(o.backFaceCulling,0,!1,r.useRightHandedSystem);var s=i._getInstancesRenderList(t._id);if(!s.mustReturn){var a=n.getCaps().instancedArrays&&null!==s.visibleInstances[t._id];if(e.isReady(t,a)){if(n.enableEffect(e._effect),i._bind(t,e._effect,Lr.Material.TriangleFillMode),e._effect.setMatrix("viewProjection",r.getTransformMatrix()),e._effect.setMatrix("view",r.getViewMatrix()),o&&o.needAlphaTesting()){var h=o.getAlphaTestTexture();h&&(e._effect.setTexture("diffuseSampler",h),e._effect.setMatrix("diffuseMatrix",h.getTextureMatrix()))}i.useBones&&i.computeBonesUsingShaders&&i.skeleton&&e._effect.setMatrices("mBones",i.skeleton.getTransformMatrices(i)),i._processRendering(t,e._effect,Lr.Material.TriangleFillMode,s,a,function(t,i){return e._effect.setMatrix("world",i)})}}}};this._multiRenderTarget.customRenderFunction=function(e,i,n,o){var s;if(o.length){for(t.setColorWrite(!1),s=0;s<o.length;s++)r(o.data[s]);t.setColorWrite(!0)}for(s=0;s<e.length;s++)r(e.data[s]);for(s=0;s<i.length;s++)r(i.data[s])}}},e}(),Lr.GeometryBufferRenderer=Br,Nr=us||(us={}),Fr=function(e){function t(t,i,r,n,o,s,a,h,l,c){var u=e.call(this,t,"refraction",["baseColor","depth","colorLevel"],["refractionSampler"],s,a,h,l,c)||this;return u.color=r,u.depth=n,u.colorLevel=o,u.onActivateObservable.add(function(e){u._refRexture=u._refRexture||new Nr.Texture(i,e.getScene())}),u.onApplyObservable.add(function(e){e.setColor3("baseColor",u.color),e.setFloat("depth",u.depth),e.setFloat("colorLevel",u.colorLevel),e.setTexture("refractionSampler",u._refRexture)}),u}return Y(t,e),t.prototype.dispose=function(t){this._refRexture&&this._refRexture.dispose(),e.prototype.dispose.call(this,t)},t}(Nr.PostProcess),Nr.RefractionPostProcess=Fr,Vr=us||(us={}),kr=function(e){function t(t,i,r,n,o,s){var a=e.call(this,t,"blackAndWhite",["degree"],null,i,r,n,o,s)||this;return a.degree=1,a.onApplyObservable.add(function(e){e.setFloat("degree",a.degree)}),a}return Y(t,e),t}(Vr.PostProcess),Vr.BlackAndWhitePostProcess=kr,Ur=us||(us={}),zr=function(e){function t(t,i,r,n,o,s,a){var h=e.call(this,t,"convolution",["kernel","screenSize"],null,r,n,o,s,a)||this;return h.kernel=i,h.onApply=function(e){e.setFloat2("screenSize",h.width,h.height),e.setArray("kernel",h.kernel)},h}return Y(t,e),t.EdgeDetect0Kernel=[1,0,-1,0,0,0,-1,0,1],t.EdgeDetect1Kernel=[0,1,0,1,-4,1,0,1,0],t.EdgeDetect2Kernel=[-1,-1,-1,-1,8,-1,-1,-1,-1],t.SharpenKernel=[0,-1,0,-1,5,-1,0,-1,0],t.EmbossKernel=[-2,-1,0,-1,1,1,0,1,2],t.GaussianKernel=[0,1,0,1,1,1,0,1,0],t}(Ur.PostProcess),Ur.ConvolutionPostProcess=zr,Gr=us||(us={}),Wr=function(e){function t(t,i,r,n,o,s,a){var h=e.call(this,t,"filter",["kernelMatrix"],null,r,n,o,s,a)||this;return h.kernelMatrix=i,h.onApply=function(e){e.setMatrix("kernelMatrix",h.kernelMatrix)},h}return Y(t,e),t}(Gr.PostProcess),Gr.FilterPostProcess=Wr,Hr=us||(us={}),jr=function(e){function t(i,r,n,o,s,a,h,l,c){void 0===s&&(s=100),void 0===a&&(a=Hr.Texture.BILINEAR_SAMPLINGMODE);var u=e.call(this,i,"volumetricLightScattering",["decay","exposure","weight","meshPositionOnScreen","density"],["lightScatteringSampler"],r.postProcessRatio||r,n,a,h,l,"#define NUM_SAMPLES "+s)||this;return u._screenCoordinates=Hr.Vector2.Zero(),u.customMeshPosition=Hr.Vector3.Zero(),u.useCustomMeshPosition=!1,u.invert=!0,u.excludedMeshes=new Array,u.exposure=.3,u.decay=.96815,u.weight=.58767,u.density=.926,h=(c=null===n?c:n.getScene()).getEngine(),u._viewPort=new Hr.Viewport(0,0,1,1).toGlobal(h.getRenderWidth(),h.getRenderHeight()),u.mesh=null!==o?o:t.CreateDefaultMesh("VolumetricLightScatteringMesh",c),u._createPass(c,r.passRatio||r),u.onActivate=function(e){u.isSupported||u.dispose(e),u.onActivate=null},u.onApplyObservable.add(function(e){u._updateMeshScreenCoordinates(c),e.setTexture("lightScatteringSampler",u._volumetricLightScatteringRTT),e.setFloat("exposure",u.exposure),e.setFloat("decay",u.decay),e.setFloat("weight",u.weight),e.setFloat("density",u.density),e.setVector2("meshPositionOnScreen",u._screenCoordinates)}),u}return Y(t,e),Object.defineProperty(t.prototype,"useDiffuseColor",{get:function(){return Hr.Tools.Warn("VolumetricLightScatteringPostProcess.useDiffuseColor is no longer used, use the mesh material directly instead"),!1},set:function(e){Hr.Tools.Warn("VolumetricLightScatteringPostProcess.useDiffuseColor is no longer used, use the mesh material directly instead")},enumerable:!0,configurable:!0}),t.prototype.getClassName=function(){return"VolumetricLightScatteringPostProcess"},t.prototype._isReady=function(e,t){var i=e.getMesh();if(i===this.mesh&&i.material)return i.material.isReady(i);var r=[],n=[Hr.VertexBuffer.PositionKind],o=e.getMaterial();o&&(o.needAlphaTesting()&&r.push("#define ALPHATEST"),i.isVerticesDataPresent(Hr.VertexBuffer.UVKind)&&(n.push(Hr.VertexBuffer.UVKind),r.push("#define UV1")),i.isVerticesDataPresent(Hr.VertexBuffer.UV2Kind)&&(n.push(Hr.VertexBuffer.UV2Kind),r.push("#define UV2"))),i.useBones&&i.computeBonesUsingShaders?(n.push(Hr.VertexBuffer.MatricesIndicesKind),n.push(Hr.VertexBuffer.MatricesWeightsKind),r.push("#define NUM_BONE_INFLUENCERS "+i.numBoneInfluencers),r.push("#define BonesPerMesh "+(i.skeleton?i.skeleton.bones.length+1:0))):r.push("#define NUM_BONE_INFLUENCERS 0"),t&&(r.push("#define INSTANCES"),n.push("world0"),n.push("world1"),n.push("world2"),n.push("world3"));var s=r.join("\n");return this._cachedDefines!==s&&(this._cachedDefines=s,this._volumetricLightScatteringPass=i.getScene().getEngine().createEffect({vertexElement:"depth",fragmentElement:"volumetricLightScatteringPass"},n,["world","mBones","viewProjection","diffuseMatrix"],["diffuseSampler"],s)),this._volumetricLightScatteringPass.isReady()},t.prototype.setCustomMeshPosition=function(e){this.customMeshPosition=e},t.prototype.getCustomMeshPosition=function(){return this.customMeshPosition},t.prototype.dispose=function(t){var i=t.getScene().customRenderTargets.indexOf(this._volumetricLightScatteringRTT);-1!==i&&t.getScene().customRenderTargets.splice(i,1),this._volumetricLightScatteringRTT.dispose(),e.prototype.dispose.call(this,t)},t.prototype.getPass=function(){return this._volumetricLightScatteringRTT},t.prototype._meshExcluded=function(e){return this.excludedMeshes.length>0&&-1!==this.excludedMeshes.indexOf(e)},t.prototype._createPass=function(e,t){var i=this,r=e.getEngine();this._volumetricLightScatteringRTT=new Hr.RenderTargetTexture("volumetricLightScatteringMap",{width:r.getRenderWidth()*t,height:r.getRenderHeight()*t},e,!1,!0,Hr.Engine.TEXTURETYPE_UNSIGNED_INT),this._volumetricLightScatteringRTT.wrapU=Hr.Texture.CLAMP_ADDRESSMODE,this._volumetricLightScatteringRTT.wrapV=Hr.Texture.CLAMP_ADDRESSMODE,this._volumetricLightScatteringRTT.renderList=null,this._volumetricLightScatteringRTT.renderParticles=!1;var n=this.getCamera();n?n.customRenderTargets.push(this._volumetricLightScatteringRTT):e.customRenderTargets.push(this._volumetricLightScatteringRTT);var o,s=function(e){var t=e.getRenderingMesh();if(!i._meshExcluded(t)){var r=e.getMaterial();if(r){var n=t.getScene(),o=n.getEngine();o.setState(r.backFaceCulling);var s=t._getInstancesRenderList(e._id);if(!s.mustReturn){var a=o.getCaps().instancedArrays&&null!==s.visibleInstances[e._id];if(i._isReady(e,a)){var h=i._volumetricLightScatteringPass;if(t===i.mesh&&(h=e.effect?e.effect:r.getEffect()),o.enableEffect(h),t._bind(e,h,Hr.Material.TriangleFillMode),t===i.mesh)r.bind(t.getWorldMatrix(),t);else{if(i._volumetricLightScatteringPass.setMatrix("viewProjection",n.getTransformMatrix()),r&&r.needAlphaTesting()){var l=r.getAlphaTestTexture();i._volumetricLightScatteringPass.setTexture("diffuseSampler",l),l&&i._volumetricLightScatteringPass.setMatrix("diffuseMatrix",l.getTextureMatrix())}t.useBones&&t.computeBonesUsingShaders&&t.skeleton&&i._volumetricLightScatteringPass.setMatrices("mBones",t.skeleton.getTransformMatrices(t))}t._processRendering(e,i._volumetricLightScatteringPass,Hr.Material.TriangleFillMode,s,a,function(e,t){return h.setMatrix("world",t)})}}}}},a=new Hr.Color4(0,0,0,1);this._volumetricLightScatteringRTT.onBeforeRenderObservable.add(function(){o=e.clearColor,e.clearColor=a}),this._volumetricLightScatteringRTT.onAfterRenderObservable.add(function(){e.clearColor=o}),this._volumetricLightScatteringRTT.customRenderFunction=function(t,i,r,n){var o,a=e.getEngine();if(n.length){for(a.setColorWrite(!1),o=0;o<n.length;o++)s(n.data[o]);a.setColorWrite(!0)}for(o=0;o<t.length;o++)s(t.data[o]);for(a.setAlphaTesting(!0),o=0;o<i.length;o++)s(i.data[o]);if(a.setAlphaTesting(!1),r.length){for(o=0;o<r.length;o++){var h=r.data[o],l=h.getBoundingInfo();l&&e.activeCamera&&(h._alphaIndex=h.getMesh().alphaIndex,h._distanceToCamera=l.boundingSphere.centerWorld.subtract(e.activeCamera.position).length())}var c=r.data.slice(0,r.length);for(c.sort(function(e,t){return e._alphaIndex>t._alphaIndex?1:e._alphaIndex<t._alphaIndex?-1:e._distanceToCamera<t._distanceToCamera?1:e._distanceToCamera>t._distanceToCamera?-1:0}),a.setAlphaMode(Hr.Engine.ALPHA_COMBINE),o=0;o<c.length;o++)s(c[o]);a.setAlphaMode(Hr.Engine.ALPHA_DISABLE)}}},t.prototype._updateMeshScreenCoordinates=function(e){var t,i=e.getTransformMatrix();t=this.useCustomMeshPosition?this.customMeshPosition:this.attachedNode?this.attachedNode.position:this.mesh.parent?this.mesh.getAbsolutePosition():this.mesh.position;var r=Hr.Vector3.Project(t,Hr.Matrix.Identity(),i,this._viewPort);this._screenCoordinates.x=r.x/this._viewPort.width,this._screenCoordinates.y=r.y/this._viewPort.height,this.invert&&(this._screenCoordinates.y=1-this._screenCoordinates.y)},t.CreateDefaultMesh=function(e,t){var i=Hr.Mesh.CreatePlane(e,1,t);i.billboardMode=Hr.AbstractMesh.BILLBOARDMODE_ALL;var r=new Hr.StandardMaterial(e+"Material",t);return r.emissiveColor=new Hr.Color3(1,1,1),i.material=r,i},X([Hr.serializeAsVector3()],t.prototype,"customMeshPosition",void 0),X([Hr.serialize()],t.prototype,"useCustomMeshPosition",void 0),X([Hr.serialize()],t.prototype,"invert",void 0),X([Hr.serializeAsMeshReference()],t.prototype,"mesh",void 0),X([Hr.serialize()],t.prototype,"excludedMeshes",void 0),X([Hr.serialize()],t.prototype,"exposure",void 0),X([Hr.serialize()],t.prototype,"decay",void 0),X([Hr.serialize()],t.prototype,"weight",void 0),X([Hr.serialize()],t.prototype,"density",void 0),t}(Hr.PostProcess),Hr.VolumetricLightScatteringPostProcess=jr,Xr=us||(us={}),Yr=function(e){function t(t,i,r,n,o,s,a){var h=e.call(this,t,"colorCorrection",null,["colorTable"],r,n,o,s,a)||this;return h._colorTableTexture=new Xr.Texture(i,n.getScene(),!0,!1,Xr.Texture.TRILINEAR_SAMPLINGMODE),h._colorTableTexture.anisotropicFilteringLevel=1,h._colorTableTexture.wrapU=Xr.Texture.CLAMP_ADDRESSMODE,h._colorTableTexture.wrapV=Xr.Texture.CLAMP_ADDRESSMODE,h.onApply=function(e){e.setTexture("colorTable",h._colorTableTexture)},h}return Y(t,e),t}(Xr.PostProcess),Xr.ColorCorrectionPostProcess=Yr,function(e){var t,i;(i=t=e.TonemappingOperator||(e.TonemappingOperator={}))[i.Hable=0]="Hable",i[i.Reinhard=1]="Reinhard",i[i.HejiDawson=2]="HejiDawson",i[i.Photographic=3]="Photographic";var r=function(i){function r(r,n,o,s,a,h,l){void 0===a&&(a=e.Texture.BILINEAR_SAMPLINGMODE),void 0===l&&(l=e.Engine.TEXTURETYPE_UNSIGNED_INT);var c=i.call(this,r,"tonemap",["_ExposureAdjustment"],null,1,s,a,h,!0,null,l)||this;c._operator=n,c.exposureAdjustment=o;var u="#define ";return c._operator===t.Hable?u+="HABLE_TONEMAPPING":c._operator===t.Reinhard?u+="REINHARD_TONEMAPPING":c._operator===t.HejiDawson?u+="OPTIMIZED_HEJIDAWSON_TONEMAPPING":c._operator===t.Photographic&&(u+="PHOTOGRAPHIC_TONEMAPPING"),c.updateEffect(u),c.onApply=function(e){e.setFloat("_ExposureAdjustment",c.exposureAdjustment)},c}return Y(r,i),r}(e.PostProcess);e.TonemapPostProcess=r}(us||(us={})),Kr=us||(us={}),Qr=function(e){function t(t,i,r,n,o,s){return e.call(this,t,"displayPass",["passSampler"],["passSampler"],i,r,n,o,s)||this}return Y(t,e),t}(Kr.PostProcess),Kr.DisplayPassPostProcess=Qr,Zr=us||(us={}),qr=function(e){function t(t,i,r,n,o,s,a){return void 0===a&&(a=Zr.Engine.TEXTURETYPE_UNSIGNED_INT),e.call(this,t,"highlights",null,null,i,r,n,o,s,null,a)||this}return Y(t,e),t}(Zr.PostProcess),Zr.HighlightsPostProcess=qr,Jr=us||(us={}),$r=function(e){function t(t,i,r,n,o,s,a,h){void 0===r&&(r=null),void 0===a&&(a=Jr.Engine.TEXTURETYPE_UNSIGNED_INT);var l=e.call(this,t,"imageProcessing",[],[],i,r,n,o,s,null,a,"postprocess",null,!0)||this;return l._fromLinearSpace=!0,l._defines={IMAGEPROCESSING:!1,VIGNETTE:!1,VIGNETTEBLENDMODEMULTIPLY:!1,VIGNETTEBLENDMODEOPAQUE:!1,TONEMAPPING:!1,CONTRAST:!1,COLORCURVES:!1,COLORGRADING:!1,COLORGRADING3D:!1,FROMLINEARSPACE:!1,SAMPLER3DGREENDEPTH:!1,SAMPLER3DBGRMAP:!1,IMAGEPROCESSINGPOSTPROCESS:!1,EXPOSURE:!1},h?(h.applyByPostProcess=!0,l._attachImageProcessingConfiguration(h,!0),l.fromLinearSpace=!1):(l._attachImageProcessingConfiguration(null,!0),l.imageProcessingConfiguration.applyByPostProcess=!0),l.onApply=function(e){l.imageProcessingConfiguration.bind(e,l.aspectRatio)},l}return Y(t,e),Object.defineProperty(t.prototype,"imageProcessingConfiguration",{get:function(){return this._imageProcessingConfiguration},set:function(e){this._attachImageProcessingConfiguration(e)},enumerable:!0,configurable:!0}),t.prototype._attachImageProcessingConfiguration=function(e,t){var i=this;if(void 0===t&&(t=!1),e!==this._imageProcessingConfiguration){if(this._imageProcessingConfiguration&&this._imageProcessingObserver&&this._imageProcessingConfiguration.onUpdateParameters.remove(this._imageProcessingObserver),e)this._imageProcessingConfiguration=e;else{var r=null,n=this.getEngine(),o=this.getCamera();if(o)r=o.getScene();else if(n&&n.scenes){var s=n.scenes;r=s[s.length-1]}else r=Jr.Engine.LastCreatedScene;this._imageProcessingConfiguration=r.imageProcessingConfiguration}this._imageProcessingObserver=this._imageProcessingConfiguration.onUpdateParameters.add(function(e){i._updateParameters()}),t||this._updateParameters()}},Object.defineProperty(t.prototype,"colorCurves",{get:function(){return this.imageProcessingConfiguration.colorCurves},set:function(e){this.imageProcessingConfiguration.colorCurves=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"colorCurvesEnabled",{get:function(){return this.imageProcessingConfiguration.colorCurvesEnabled},set:function(e){this.imageProcessingConfiguration.colorCurvesEnabled=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"colorGradingTexture",{get:function(){return this.imageProcessingConfiguration.colorGradingTexture},set:function(e){this.imageProcessingConfiguration.colorGradingTexture=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"colorGradingEnabled",{get:function(){return this.imageProcessingConfiguration.colorGradingEnabled},set:function(e){this.imageProcessingConfiguration.colorGradingEnabled=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"exposure",{get:function(){return this.imageProcessingConfiguration.exposure},set:function(e){this.imageProcessingConfiguration.exposure=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"toneMappingEnabled",{get:function(){return this._imageProcessingConfiguration.toneMappingEnabled},set:function(e){this._imageProcessingConfiguration.toneMappingEnabled=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"contrast",{get:function(){return this.imageProcessingConfiguration.contrast},set:function(e){this.imageProcessingConfiguration.contrast=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"vignetteStretch",{get:function(){return this.imageProcessingConfiguration.vignetteStretch},set:function(e){this.imageProcessingConfiguration.vignetteStretch=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"vignetteCentreX",{get:function(){return this.imageProcessingConfiguration.vignetteCentreX},set:function(e){this.imageProcessingConfiguration.vignetteCentreX=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"vignetteCentreY",{get:function(){return this.imageProcessingConfiguration.vignetteCentreY},set:function(e){this.imageProcessingConfiguration.vignetteCentreY=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"vignetteWeight",{get:function(){return this.imageProcessingConfiguration.vignetteWeight},set:function(e){this.imageProcessingConfiguration.vignetteWeight=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"vignetteColor",{get:function(){return this.imageProcessingConfiguration.vignetteColor},set:function(e){this.imageProcessingConfiguration.vignetteColor=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"vignetteCameraFov",{get:function(){return this.imageProcessingConfiguration.vignetteCameraFov},set:function(e){this.imageProcessingConfiguration.vignetteCameraFov=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"vignetteBlendMode",{get:function(){return this.imageProcessingConfiguration.vignetteBlendMode},set:function(e){this.imageProcessingConfiguration.vignetteBlendMode=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"vignetteEnabled",{get:function(){return this.imageProcessingConfiguration.vignetteEnabled},set:function(e){this.imageProcessingConfiguration.vignetteEnabled=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"fromLinearSpace",{get:function(){return this._fromLinearSpace},set:function(e){this._fromLinearSpace!==e&&(this._fromLinearSpace=e,this._updateParameters())},enumerable:!0,configurable:!0}),t.prototype.getClassName=function(){return"ImageProcessingPostProcess"},t.prototype._updateParameters=function(){this._defines.FROMLINEARSPACE=this._fromLinearSpace,this.imageProcessingConfiguration.prepareDefines(this._defines,!0);var e="";for(var t in this._defines)this._defines[t]&&(e+="#define "+t+";\r\n");var i=["textureSampler"];Jr.ImageProcessingConfiguration.PrepareSamplers(i,this._defines);var r=["scale"];Jr.ImageProcessingConfiguration.PrepareUniforms(r,this._defines),this.updateEffect(e,r,i)},t.prototype.dispose=function(t){e.prototype.dispose.call(this,t),this._imageProcessingConfiguration&&this._imageProcessingObserver&&this._imageProcessingConfiguration.onUpdateParameters.remove(this._imageProcessingObserver),this.imageProcessingConfiguration.applyByPostProcess=!1},X([Jr.serialize()],t.prototype,"_fromLinearSpace",void 0),t}(Jr.PostProcess),Jr.ImageProcessingPostProcess=$r,en=us||(us={}),tn=function(e){function t(t,i,r,n,o,s,a,h,l){void 0===s&&(s=en.Texture.BILINEAR_SAMPLINGMODE),void 0===l&&(l=en.Engine.TEXTURETYPE_UNSIGNED_INT);var c=e.call(this,t,"kernelBlur",["delta","direction"],null,n,o,s,a,h,null,l,"kernelBlur",{varyingCount:0,depCount:0},!0)||this;return c.direction=i,c._packedFloat=!1,c.onApplyObservable.add(function(e){e.setFloat2("delta",1/c.width*c.direction.x,1/c.height*c.direction.y)}),c.kernel=r,c}return Y(t,e),Object.defineProperty(t.prototype,"kernel",{get:function(){return this._idealKernel},set:function(e){this._idealKernel!==e&&(e=Math.max(e,1),this._idealKernel=e,this._kernel=this._nearestBestKernel(e),this._updateParameters())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"packedFloat",{get:function(){return this._packedFloat},set:function(e){this._packedFloat!==e&&(this._packedFloat=e,this._updateParameters())},enumerable:!0,configurable:!0}),t.prototype._updateParameters=function(){for(var e=this._kernel,t=(e-1)/2,i=[],r=[],n=0,o=0;o<e;o++){var s=o/(e-1),a=this._gaussianWeight(2*s-1);i[o]=o-t,r[o]=a,n+=a}for(o=0;o<r.length;o++)r[o]/=n;var h=[],l=[],c=[];for(o=0;o<=t;o+=2){var u=Math.min(o+1,Math.floor(t));if(o===u)c.push({o:i[o],w:r[o]});else{var p=u===t,f=r[o]+r[u]*(p?.5:1),d=i[o]+1/(1+r[o]/r[u]);0===d?(c.push({o:i[o],w:r[o]}),c.push({o:i[o+1],w:r[o+1]})):(c.push({o:d,w:f}),c.push({o:-d,w:f}))}}for(o=0;o<c.length;o++)l[o]=c[o].o,h[o]=c[o].w;i=l,r=h;var m=this.getEngine().getCaps().maxVaryingVectors,g=Math.max(m,0)-1,_=Math.min(i.length,g),v="";for(o=0;o<_;o++)v+="#define KERNEL_OFFSET"+o+" "+this._glslFloat(i[o])+"\r\n",v+="#define KERNEL_WEIGHT"+o+" "+this._glslFloat(r[o])+"\r\n";var y=0;for(o=g;o<i.length;o++)v+="#define KERNEL_DEP_OFFSET"+y+" "+this._glslFloat(i[o])+"\r\n",v+="#define KERNEL_DEP_WEIGHT"+y+" "+this._glslFloat(r[o])+"\r\n",y++;this.packedFloat&&(v+="#define PACKEDFLOAT 1"),this.updateEffect(v,null,null,{varyingCount:_,depCount:y})},t.prototype._nearestBestKernel=function(e){for(var t=Math.round(e),i=0,r=[t,t-1,t+1,t-2,t+2];i<r.length;i++){var n=r[i];if(n%2!=0&&Math.floor(n/2)%2==0&&n>0)return Math.max(n,3)}return Math.max(t,3)},t.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)},t.prototype._glslFloat=function(e,t){return void 0===t&&(t=8),e.toFixed(t).replace(/0+$/,"")},t}(en.PostProcess),en.BlurPostProcess=tn,rn=us||(us={}),nn=function(e){function t(t,i,r,n,o,s,a){void 0===r&&(r=null),void 0===n&&(n=null),void 0===o&&(o=null),void 0===s&&(s=null),void 0===a&&(a=null);var h=e.call(this,t,i.getScene())||this;return h.name=t,h.children=new Array,h.animations=new Array,h._index=null,h._worldTransform=new rn.Matrix,h._absoluteTransform=new rn.Matrix,h._invertedAbsoluteTransform=new rn.Matrix,h._scaleMatrix=rn.Matrix.Identity(),h._scaleVector=rn.Vector3.One(),h._negateScaleChildren=rn.Vector3.One(),h._scalingDeterminant=1,h._skeleton=i,h._localMatrix=n||rn.Matrix.Identity(),h._restPose=o||h._localMatrix.clone(),h._baseMatrix=s||h._localMatrix.clone(),h._index=a,i.bones.push(h),h.setParent(r,!1),h._updateDifferenceMatrix(),h}return Y(t,e),Object.defineProperty(t.prototype,"_matrix",{get:function(){return this._localMatrix},set:function(e){this._localMatrix?this._localMatrix.copyFrom(e):this._localMatrix=e},enumerable:!0,configurable:!0}),t.prototype.getSkeleton=function(){return this._skeleton},t.prototype.getParent=function(){return this._parent},t.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()}},t.prototype.getLocalMatrix=function(){return this._localMatrix},t.prototype.getBaseMatrix=function(){return this._baseMatrix},t.prototype.getRestPose=function(){return this._restPose},t.prototype.returnToRest=function(){this.updateMatrix(this._restPose.clone())},t.prototype.getWorldMatrix=function(){return this._worldTransform},t.prototype.getInvertedAbsoluteTransform=function(){return this._invertedAbsoluteTransform},t.prototype.getAbsoluteTransform=function(){return this._absoluteTransform},Object.defineProperty(t.prototype,"position",{get:function(){return this.getPosition()},set:function(e){this.setPosition(e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotation",{get:function(){return this.getRotation()},set:function(e){this.setRotation(e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotationQuaternion",{get:function(){return this.getRotationQuaternion()},set:function(e){this.setRotationQuaternion(e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"scaling",{get:function(){return this.getScale()},set:function(e){this.setScale(e.x,e.y,e.z)},enumerable:!0,configurable:!0}),t.prototype.updateMatrix=function(e,t){void 0===t&&(t=!0),this._baseMatrix=e.clone(),this._localMatrix=e.clone(),this._skeleton._markAsDirty(),t&&this._updateDifferenceMatrix()},t.prototype._updateDifferenceMatrix=function(e){e||(e=this._baseMatrix),this._parent?e.multiplyToRef(this._parent._absoluteTransform,this._absoluteTransform):this._absoluteTransform.copyFrom(e),this._absoluteTransform.invertToRef(this._invertedAbsoluteTransform);for(var t=0;t<this.children.length;t++)this.children[t]._updateDifferenceMatrix();this._scalingDeterminant=this._absoluteTransform.determinant()<0?-1:1},t.prototype.markAsDirty=function(){this._currentRenderId++,this._skeleton._markAsDirty()},t.prototype.copyAnimationRange=function(e,t,i,r,n){void 0===r&&(r=!1),void 0===n&&(n=null),0===this.animations.length&&(this.animations.push(new rn.Animation(this.name,"_matrix",e.animations[0].framePerSecond,rn.Animation.ANIMATIONTYPE_MATRIX,0)),this.animations[0].setKeys([]));var o=e.animations[0].getRange(t);if(!o)return!1;for(var s,a,h,l=o.from,c=o.to,u=e.animations[0].getKeys(),p=e.length,f=e.getParent(),d=this.getParent(),m=r&&f&&p&&this.length&&p!==this.length,g=m&&d&&f?d.length/f.length:1,_=r&&!d&&n&&(1!==n.x||1!==n.y||1!==n.z),v=this.animations[0].getKeys(),y=0,b=u.length;y<b;y++)(s=u[y]).frame>=l&&s.frame<=c&&(r?(h=s.value.clone(),m?(a=h.getTranslation(),h.setTranslation(a.scaleInPlace(g))):_&&n?(a=h.getTranslation(),h.setTranslation(a.multiplyInPlace(n))):h=s.value):h=s.value,v.push({frame:s.frame+i,value:h}));return this.animations[0].createRange(t,l+i,c+i),!0},t.prototype.translate=function(e,i,r){void 0===i&&(i=rn.Space.LOCAL);var n=this.getLocalMatrix();if(i==rn.Space.LOCAL)n.m[12]+=e.x,n.m[13]+=e.y,n.m[14]+=e.z;else{var o=null;r&&(o=r.getWorldMatrix()),this._skeleton.computeAbsoluteTransforms();var s=t._tmpMats[0],a=t._tmpVecs[0];this._parent&&(r&&o?(s.copyFrom(this._parent.getAbsoluteTransform()),s.multiplyToRef(o,s)):s.copyFrom(this._parent.getAbsoluteTransform())),s.m[12]=0,s.m[13]=0,s.m[14]=0,s.invert(),rn.Vector3.TransformCoordinatesToRef(e,s,a),n.m[12]+=a.x,n.m[13]+=a.y,n.m[14]+=a.z}this.markAsDirty()},t.prototype.setPosition=function(e,i,r){void 0===i&&(i=rn.Space.LOCAL);var n=this.getLocalMatrix();if(i==rn.Space.LOCAL)n.m[12]=e.x,n.m[13]=e.y,n.m[14]=e.z;else{var o=null;r&&(o=r.getWorldMatrix()),this._skeleton.computeAbsoluteTransforms();var s=t._tmpMats[0],a=t._tmpVecs[0];this._parent&&(r&&o?(s.copyFrom(this._parent.getAbsoluteTransform()),s.multiplyToRef(o,s)):s.copyFrom(this._parent.getAbsoluteTransform())),s.invert(),rn.Vector3.TransformCoordinatesToRef(e,s,a),n.m[12]=a.x,n.m[13]=a.y,n.m[14]=a.z}this.markAsDirty()},t.prototype.setAbsolutePosition=function(e,t){this.setPosition(e,rn.Space.WORLD,t)},t.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)},t.prototype.scale=function(e,i,r,n){void 0===n&&(n=!1);var o=this.getLocalMatrix(),s=t._tmpMats[0];s.copyFrom(o);var a=t._tmpMats[1];a.copyFrom(s),a.invert();var h=t._tmpMats[2];rn.Matrix.FromValuesToRef(e,0,0,0,0,i,0,0,0,0,r,0,0,0,0,1,h),this._scaleMatrix.multiplyToRef(h,this._scaleMatrix),this._scaleVector.x*=e,this._scaleVector.y*=i,this._scaleVector.z*=r,o.multiplyToRef(a,o),o.multiplyToRef(h,o),o.multiplyToRef(s,o);var l=this.getParent();l?o.multiplyToRef(l.getAbsoluteTransform(),this.getAbsoluteTransform()):this.getAbsoluteTransform().copyFrom(o);var c=this.children.length;h.invert();for(var u=0;u<c;u++){var p=this.children[u],f=p.getLocalMatrix();f.multiplyToRef(h,f);var d=p.getLocalMatrix();d.m[12]*=e,d.m[13]*=i,d.m[14]*=r}if(this.computeAbsoluteTransforms(),n)for(u=0;u<c;u++)this.children[u].scale(e,i,r,n);this.markAsDirty()},t.prototype.setYawPitchRoll=function(e,i,r,n,o){void 0===n&&(n=rn.Space.LOCAL);var s=t._tmpMats[0];rn.Matrix.RotationYawPitchRollToRef(e,i,r,s);var a=t._tmpMats[1];this._getNegativeRotationToRef(a,n,o),a.multiplyToRef(s,s),this._rotateWithMatrix(s,n,o)},t.prototype.rotate=function(e,i,r,n){void 0===r&&(r=rn.Space.LOCAL);var o=t._tmpMats[0];o.m[12]=0,o.m[13]=0,o.m[14]=0,rn.Matrix.RotationAxisToRef(e,i,o),this._rotateWithMatrix(o,r,n)},t.prototype.setAxisAngle=function(e,i,r,n){void 0===r&&(r=rn.Space.LOCAL);var o=t._tmpMats[0];rn.Matrix.RotationAxisToRef(e,i,o);var s=t._tmpMats[1];this._getNegativeRotationToRef(s,r,n),s.multiplyToRef(o,o),this._rotateWithMatrix(o,r,n)},t.prototype.setRotation=function(e,t,i){void 0===t&&(t=rn.Space.LOCAL),this.setYawPitchRoll(e.y,e.x,e.z,t,i)},t.prototype.setRotationQuaternion=function(e,i,r){void 0===i&&(i=rn.Space.LOCAL);var n=t._tmpMats[0];this._getNegativeRotationToRef(n,i,r);var o=t._tmpMats[1];rn.Matrix.FromQuaternionToRef(e,o),n.multiplyToRef(o,o),this._rotateWithMatrix(o,i,r)},t.prototype.setRotationMatrix=function(e,i,r){void 0===i&&(i=rn.Space.LOCAL);var n=t._tmpMats[0];this._getNegativeRotationToRef(n,i,r);var o=t._tmpMats[1];o.copyFrom(e),n.multiplyToRef(e,o),this._rotateWithMatrix(o,i,r)},t.prototype._rotateWithMatrix=function(e,i,r){void 0===i&&(i=rn.Space.LOCAL);var n=this.getLocalMatrix(),o=n.m[12],s=n.m[13],a=n.m[14],h=this.getParent(),l=t._tmpMats[3],c=t._tmpMats[4];h?(i==rn.Space.WORLD?r?(l.copyFrom(r.getWorldMatrix()),h.getAbsoluteTransform().multiplyToRef(l,l)):l.copyFrom(h.getAbsoluteTransform()):l=h._scaleMatrix,c.copyFrom(l),c.invert(),n.multiplyToRef(l,n),n.multiplyToRef(e,n),n.multiplyToRef(c,n)):i==rn.Space.WORLD&&r?(l.copyFrom(r.getWorldMatrix()),c.copyFrom(l),c.invert(),n.multiplyToRef(l,n),n.multiplyToRef(e,n),n.multiplyToRef(c,n)):n.multiplyToRef(e,n),n.m[12]=o,n.m[13]=s,n.m[14]=a,this.computeAbsoluteTransforms(),this.markAsDirty()},t.prototype._getNegativeRotationToRef=function(e,i,r){if(void 0===i&&(i=rn.Space.LOCAL),i==rn.Space.WORLD){if((o=t._tmpMats[2]).copyFrom(this._scaleMatrix),e.copyFrom(this.getAbsoluteTransform()),r){e.multiplyToRef(r.getWorldMatrix(),e);var n=t._tmpMats[3];rn.Matrix.ScalingToRef(r.scaling.x,r.scaling.y,r.scaling.z,n),o.multiplyToRef(n,o)}e.invert(),o.m[0]*=this._scalingDeterminant,e.multiplyToRef(o,e)}else{var o;if(e.copyFrom(this.getLocalMatrix()),e.invert(),(o=t._tmpMats[2]).copyFrom(this._scaleMatrix),this._parent){var s=t._tmpMats[3];s.copyFrom(this._parent._scaleMatrix),s.invert(),s.multiplyToRef(e,e)}else o.m[0]*=this._scalingDeterminant;e.multiplyToRef(o,e)}},t.prototype.getScale=function(){return this._scaleVector.clone()},t.prototype.getScaleToRef=function(e){e.copyFrom(this._scaleVector)},t.prototype.getPosition=function(e,t){void 0===e&&(e=rn.Space.LOCAL),void 0===t&&(t=null);var i=rn.Vector3.Zero();return this.getPositionToRef(e,t,i),i},t.prototype.getPositionToRef=function(e,i,r){if(void 0===e&&(e=rn.Space.LOCAL),e==rn.Space.LOCAL){var n=this.getLocalMatrix();r.x=n.m[12],r.y=n.m[13],r.z=n.m[14]}else{var o=null;i&&(o=i.getWorldMatrix()),this._skeleton.computeAbsoluteTransforms();var s=t._tmpMats[0];i&&o?(s.copyFrom(this.getAbsoluteTransform()),s.multiplyToRef(o,s)):s=this.getAbsoluteTransform(),r.x=s.m[12],r.y=s.m[13],r.z=s.m[14]}},t.prototype.getAbsolutePosition=function(e){void 0===e&&(e=null);var t=rn.Vector3.Zero();return this.getPositionToRef(rn.Space.WORLD,e,t),t},t.prototype.getAbsolutePositionToRef=function(e,t){this.getPositionToRef(rn.Space.WORLD,e,t)},t.prototype.computeAbsoluteTransforms=function(){if(this._parent)this._localMatrix.multiplyToRef(this._parent._absoluteTransform,this._absoluteTransform);else{this._absoluteTransform.copyFrom(this._localMatrix);var e=this._skeleton.getPoseMatrix();e&&this._absoluteTransform.multiplyToRef(e,this._absoluteTransform)}for(var t=this.children,i=t.length,r=0;r<i;r++)t[r].computeAbsoluteTransforms()},t.prototype._syncScaleVector=function(){var e=this.getLocalMatrix(),t=e.m[0]*e.m[0]+e.m[1]*e.m[1]+e.m[2]*e.m[2],i=e.m[4]*e.m[4]+e.m[5]*e.m[5]+e.m[6]*e.m[6],r=e.m[8]*e.m[8]+e.m[9]*e.m[9]+e.m[10]*e.m[10],n=e.m[0]*e.m[1]*e.m[2]*e.m[3]<0?-1:1,o=e.m[4]*e.m[5]*e.m[6]*e.m[7]<0?-1:1,s=e.m[8]*e.m[9]*e.m[10]*e.m[11]<0?-1:1;this._scaleVector.x=n*Math.sqrt(t),this._scaleVector.y=o*Math.sqrt(i),this._scaleVector.z=s*Math.sqrt(r),this._parent&&(this._scaleVector.x/=this._parent._negateScaleChildren.x,this._scaleVector.y/=this._parent._negateScaleChildren.y,this._scaleVector.z/=this._parent._negateScaleChildren.z),rn.Matrix.FromValuesToRef(this._scaleVector.x,0,0,0,0,this._scaleVector.y,0,0,0,0,this._scaleVector.z,0,0,0,0,1,this._scaleMatrix)},t.prototype.getDirection=function(e,t){void 0===t&&(t=null);var i=rn.Vector3.Zero();return this.getDirectionToRef(e,t,i),i},t.prototype.getDirectionToRef=function(e,i,r){void 0===i&&(i=null);var n=null;i&&(n=i.getWorldMatrix()),this._skeleton.computeAbsoluteTransforms();var o=t._tmpMats[0];o.copyFrom(this.getAbsoluteTransform()),i&&n&&o.multiplyToRef(n,o),rn.Vector3.TransformNormalToRef(e,o,r),r.normalize()},t.prototype.getRotation=function(e,t){void 0===e&&(e=rn.Space.LOCAL),void 0===t&&(t=null);var i=rn.Vector3.Zero();return this.getRotationToRef(e,t,i),i},t.prototype.getRotationToRef=function(e,i,r){void 0===e&&(e=rn.Space.LOCAL),void 0===i&&(i=null);var n=t._tmpQuat;this.getRotationQuaternionToRef(e,i,n),n.toEulerAnglesToRef(r)},t.prototype.getRotationQuaternion=function(e,t){void 0===e&&(e=rn.Space.LOCAL),void 0===t&&(t=null);var i=rn.Quaternion.Identity();return this.getRotationQuaternionToRef(e,t,i),i},t.prototype.getRotationQuaternionToRef=function(e,i,r){if(void 0===e&&(e=rn.Space.LOCAL),void 0===i&&(i=null),e==rn.Space.LOCAL)this.getLocalMatrix().decompose(t._tmpVecs[0],r,t._tmpVecs[1]);else{var n=t._tmpMats[0],o=this.getAbsoluteTransform();i?o.multiplyToRef(i.getWorldMatrix(),n):n.copyFrom(o),n.m[0]*=this._scalingDeterminant,n.m[1]*=this._scalingDeterminant,n.m[2]*=this._scalingDeterminant,n.decompose(t._tmpVecs[0],r,t._tmpVecs[1])}},t.prototype.getRotationMatrix=function(e,t){void 0===e&&(e=rn.Space.LOCAL);var i=rn.Matrix.Identity();return this.getRotationMatrixToRef(e,t,i),i},t.prototype.getRotationMatrixToRef=function(e,i,r){if(void 0===e&&(e=rn.Space.LOCAL),e==rn.Space.LOCAL)this.getLocalMatrix().getRotationMatrixToRef(r);else{var n=t._tmpMats[0],o=this.getAbsoluteTransform();i?o.multiplyToRef(i.getWorldMatrix(),n):n.copyFrom(o),n.m[0]*=this._scalingDeterminant,n.m[1]*=this._scalingDeterminant,n.m[2]*=this._scalingDeterminant,n.getRotationMatrixToRef(r)}},t.prototype.getAbsolutePositionFromLocal=function(e,t){void 0===t&&(t=null);var i=rn.Vector3.Zero();return this.getAbsolutePositionFromLocalToRef(e,t,i),i},t.prototype.getAbsolutePositionFromLocalToRef=function(e,i,r){void 0===i&&(i=null);var n=null;i&&(n=i.getWorldMatrix()),this._skeleton.computeAbsoluteTransforms();var o=t._tmpMats[0];i&&n?(o.copyFrom(this.getAbsoluteTransform()),o.multiplyToRef(n,o)):o=this.getAbsoluteTransform(),rn.Vector3.TransformCoordinatesToRef(e,o,r)},t.prototype.getLocalPositionFromAbsolute=function(e,t){void 0===t&&(t=null);var i=rn.Vector3.Zero();return this.getLocalPositionFromAbsoluteToRef(e,t,i),i},t.prototype.getLocalPositionFromAbsoluteToRef=function(e,i,r){void 0===i&&(i=null);var n=null;i&&(n=i.getWorldMatrix()),this._skeleton.computeAbsoluteTransforms();var o=t._tmpMats[0];o.copyFrom(this.getAbsoluteTransform()),i&&n&&o.multiplyToRef(n,o),o.invert(),rn.Vector3.TransformCoordinatesToRef(e,o,r)},t._tmpVecs=[rn.Vector3.Zero(),rn.Vector3.Zero()],t._tmpQuat=rn.Quaternion.Identity(),t._tmpMats=[rn.Matrix.Identity(),rn.Matrix.Identity(),rn.Matrix.Identity(),rn.Matrix.Identity(),rn.Matrix.Identity()],t}(rn.Node),rn.Bone=nn,on=us||(us={}),sn=function(){function e(e,t,i){if(this.targetPosition=on.Vector3.Zero(),this.poleTargetPosition=on.Vector3.Zero(),this.poleTargetLocalOffset=on.Vector3.Zero(),this.poleAngle=0,this.slerpAmount=1,this._bone1Quat=on.Quaternion.Identity(),this._bone1Mat=on.Matrix.Identity(),this._bone2Ang=Math.PI,this._maxAngle=Math.PI,this._rightHandedSystem=!1,this._bendAxis=on.Vector3.Right(),this._slerping=!1,this._adjustRoll=0,this._bone2=t,this._bone1=t.getParent(),this._bone1){this.mesh=e;var r=t.getPosition();if(t.getAbsoluteTransform().determinant()>0&&(this._rightHandedSystem=!0,this._bendAxis.x=0,this._bendAxis.y=0,this._bendAxis.z=-1,r.x>r.y&&r.x>r.z&&(this._adjustRoll=.5*Math.PI,this._bendAxis.z=1)),this._bone1.length){var n=this._bone1.getScale(),o=this._bone2.getScale();this._bone1Length=this._bone1.length*n.y*this.mesh.scaling.y,this._bone2Length=this._bone2.length*o.y*this.mesh.scaling.y}else if(this._bone1.children[0]){e.computeWorldMatrix(!0);var s=this._bone2.children[0].getAbsolutePosition(e),a=this._bone2.getAbsolutePosition(e),h=this._bone1.getAbsolutePosition(e);this._bone1Length=on.Vector3.Distance(s,a),this._bone2Length=on.Vector3.Distance(a,h)}this._bone1.getRotationMatrixToRef(on.Space.WORLD,e,this._bone1Mat),this.maxAngle=Math.PI,i&&(i.targetMesh&&(this.targetMesh=i.targetMesh,this.targetMesh.computeWorldMatrix(!0)),i.poleTargetMesh?(this.poleTargetMesh=i.poleTargetMesh,this.poleTargetMesh.computeWorldMatrix(!0)):i.poleTargetBone?this.poleTargetBone=i.poleTargetBone:this._bone1.getParent()&&(this.poleTargetBone=this._bone1.getParent()),i.poleTargetLocalOffset&&this.poleTargetLocalOffset.copyFrom(i.poleTargetLocalOffset),i.poleAngle&&(this.poleAngle=i.poleAngle),i.bendAxis&&this._bendAxis.copyFrom(i.bendAxis),i.maxAngle&&(this.maxAngle=i.maxAngle),i.slerpAmount&&(this.slerpAmount=i.slerpAmount))}}return Object.defineProperty(e.prototype,"maxAngle",{get:function(){return this._maxAngle},set:function(e){this._setMaxAngle(e)},enumerable:!0,configurable:!0}),e.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))},e.prototype.update=function(){var t=this._bone1;if(t){var i=this.targetPosition,r=this.poleTargetPosition,n=e._tmpMats[0],o=e._tmpMats[1];this.targetMesh&&i.copyFrom(this.targetMesh.getAbsolutePosition()),this.poleTargetBone?this.poleTargetBone.getAbsolutePositionFromLocalToRef(this.poleTargetLocalOffset,this.mesh,r):this.poleTargetMesh&&on.Vector3.TransformCoordinatesToRef(this.poleTargetLocalOffset,this.poleTargetMesh.getWorldMatrix(),r);var s=e._tmpVecs[0],a=e._tmpVecs[1],h=e._tmpVecs[2],l=e._tmpVecs[3],c=e._tmpVecs[4],u=e._tmpQuat;t.getAbsolutePositionToRef(this.mesh,s),r.subtractToRef(s,c),0==c.x&&0==c.y&&0==c.z?c.y=1:c.normalize(),i.subtractToRef(s,l),l.normalize(),on.Vector3.CrossToRef(l,c,a),a.normalize(),on.Vector3.CrossToRef(l,a,h),h.normalize(),on.Matrix.FromXYZAxesToRef(h,l,a,n);var p=this._bone1Length,f=this._bone2Length,d=on.Vector3.Distance(s,i);this._maxReach>0&&(d=Math.min(this._maxReach,d));var m=(f*f+d*d-p*p)/(2*f*d),g=(d*d+p*p-f*f)/(2*d*p);m>1&&(m=1),g>1&&(g=1),m<-1&&(m=-1),g<-1&&(g=-1);var _=Math.acos(m),v=Math.acos(g),y=-_-v;if(this._rightHandedSystem)on.Matrix.RotationYawPitchRollToRef(0,0,this._adjustRoll,o),o.multiplyToRef(n,n),on.Matrix.RotationAxisToRef(this._bendAxis,v,o),o.multiplyToRef(n,n);else{var b=e._tmpVecs[5];b.copyFrom(this._bendAxis),b.x*=-1,on.Matrix.RotationAxisToRef(b,-v,o),o.multiplyToRef(n,n)}this.poleAngle&&(on.Matrix.RotationAxisToRef(l,this.poleAngle,o),n.multiplyToRef(o,n)),this._bone1&&(this.slerpAmount<1?(this._slerping||on.Quaternion.FromRotationMatrixToRef(this._bone1Mat,this._bone1Quat),on.Quaternion.FromRotationMatrixToRef(n,u),on.Quaternion.SlerpToRef(this._bone1Quat,u,this.slerpAmount,this._bone1Quat),y=this._bone2Ang*(1-this.slerpAmount)+y*this.slerpAmount,this._bone1.setRotationQuaternion(this._bone1Quat,on.Space.WORLD,this.mesh),this._slerping=!0):(this._bone1.setRotationMatrix(n,on.Space.WORLD,this.mesh),this._bone1Mat.copyFrom(n),this._slerping=!1)),this._bone2.setAxisAngle(this._bendAxis,y,on.Space.LOCAL),this._bone2Ang=y}},e._tmpVecs=[on.Vector3.Zero(),on.Vector3.Zero(),on.Vector3.Zero(),on.Vector3.Zero(),on.Vector3.Zero(),on.Vector3.Zero()],e._tmpQuat=on.Quaternion.Identity(),e._tmpMats=[on.Matrix.Identity(),on.Matrix.Identity()],e}(),on.BoneIKController=sn,an=us||(us={}),hn=function(){function e(e,t,i,r){if(this.upAxis=an.Vector3.Up(),this.upAxisSpace=an.Space.LOCAL,this.adjustYaw=0,this.adjustPitch=0,this.adjustRoll=0,this.slerpAmount=1,this._boneQuat=an.Quaternion.Identity(),this._slerping=!1,this._firstFrameSkipped=!1,this._fowardAxis=an.Vector3.Forward(),this.mesh=e,this.bone=t,this.target=i,r&&(r.adjustYaw&&(this.adjustYaw=r.adjustYaw),r.adjustPitch&&(this.adjustPitch=r.adjustPitch),r.adjustRoll&&(this.adjustRoll=r.adjustRoll),null!=r.maxYaw?this.maxYaw=r.maxYaw:this.maxYaw=Math.PI,null!=r.minYaw?this.minYaw=r.minYaw:this.minYaw=-Math.PI,null!=r.maxPitch?this.maxPitch=r.maxPitch:this.maxPitch=Math.PI,null!=r.minPitch?this.minPitch=r.minPitch:this.minPitch=-Math.PI,null!=r.slerpAmount&&(this.slerpAmount=r.slerpAmount),null!=r.upAxis&&(this.upAxis=r.upAxis),null!=r.upAxisSpace&&(this.upAxisSpace=r.upAxisSpace),null!=r.yawAxis||null!=r.pitchAxis)){var n=an.Axis.Y,o=an.Axis.X;null!=r.yawAxis&&(n=r.yawAxis.clone()).normalize(),null!=r.pitchAxis&&(o=r.pitchAxis.clone()).normalize();var s=an.Vector3.Cross(o,n);this._transformYawPitch=an.Matrix.Identity(),an.Matrix.FromXYZAxesToRef(o,n,s,this._transformYawPitch),this._transformYawPitchInv=this._transformYawPitch.clone(),this._transformYawPitch.invert()}t.getParent()||this.upAxisSpace!=an.Space.BONE||(this.upAxisSpace=an.Space.LOCAL)}return Object.defineProperty(e.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(e.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(e.prototype,"minPitch",{get:function(){return this._minPitch},set:function(e){this._minPitch=e,this._minPitchTan=Math.tan(e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"maxPitch",{get:function(){return this._maxPitch},set:function(e){this._maxPitch=e,this._maxPitchTan=Math.tan(e)},enumerable:!0,configurable:!0}),e.prototype.update=function(){if(this.slerpAmount<1&&!this._firstFrameSkipped)this._firstFrameSkipped=!0;else{var t=this.bone,i=e._tmpVecs[0];t.getAbsolutePositionToRef(this.mesh,i);var r=this.target,n=e._tmpMats[0],o=e._tmpMats[1],s=this.mesh,a=t.getParent(),h=e._tmpVecs[1];h.copyFrom(this.upAxis),this.upAxisSpace==an.Space.BONE&&a?(this._transformYawPitch&&an.Vector3.TransformCoordinatesToRef(h,this._transformYawPitchInv,h),a.getDirectionToRef(h,this.mesh,h)):this.upAxisSpace==an.Space.LOCAL&&(s.getDirectionToRef(h,h),1==s.scaling.x&&1==s.scaling.y&&1==s.scaling.z||h.normalize());var l=!1,c=!1;if(this._maxYaw==Math.PI&&this._minYaw==-Math.PI||(l=!0),this._maxPitch==Math.PI&&this._minPitch==-Math.PI||(c=!0),l||c){var u=e._tmpMats[2],p=e._tmpMats[3];if(this.upAxisSpace==an.Space.BONE&&1==h.y&&a)a.getRotationMatrixToRef(an.Space.WORLD,this.mesh,u);else if(this.upAxisSpace!=an.Space.LOCAL||1!=h.y||a){(d=e._tmpVecs[2]).copyFrom(this._fowardAxis),this._transformYawPitch&&an.Vector3.TransformCoordinatesToRef(d,this._transformYawPitchInv,d),a?a.getDirectionToRef(d,this.mesh,d):s.getDirectionToRef(d,d);var f=an.Vector3.Cross(h,d);f.normalize();var d=an.Vector3.Cross(f,h);an.Matrix.FromXYZAxesToRef(f,h,d,u)}else u.copyFrom(s.getWorldMatrix());u.invertToRef(p);var m=null;if(c){var g=e._tmpVecs[3];r.subtractToRef(i,g),an.Vector3.TransformCoordinatesToRef(g,p,g),m=Math.sqrt(g.x*g.x+g.z*g.z);var _=Math.atan2(g.y,m),v=_;_>this._maxPitch?(g.y=this._maxPitchTan*m,v=this._maxPitch):_<this._minPitch&&(g.y=this._minPitchTan*m,v=this._minPitch),_!=v&&(an.Vector3.TransformCoordinatesToRef(g,u,g),g.addInPlace(i),r=g)}if(l){g=e._tmpVecs[4];r.subtractToRef(i,g),an.Vector3.TransformCoordinatesToRef(g,p,g);var y=Math.atan2(g.x,g.z),b=y;if((y>this._maxYaw||y<this._minYaw)&&(null==m&&(m=Math.sqrt(g.x*g.x+g.z*g.z)),this._yawRange>Math.PI?this._isAngleBetween(y,this._maxYaw,this._midYawConstraint)?(g.z=this._maxYawCos*m,g.x=this._maxYawSin*m,b=this._maxYaw):this._isAngleBetween(y,this._midYawConstraint,this._minYaw)&&(g.z=this._minYawCos*m,g.x=this._minYawSin*m,b=this._minYaw):y>this._maxYaw?(g.z=this._maxYawCos*m,g.x=this._maxYawSin*m,b=this._maxYaw):y<this._minYaw&&(g.z=this._minYawCos*m,g.x=this._minYawSin*m,b=this._minYaw)),this._slerping&&this._yawRange>Math.PI){var x=e._tmpVecs[8];x.copyFrom(an.Axis.Z),this._transformYawPitch&&an.Vector3.TransformCoordinatesToRef(x,this._transformYawPitchInv,x);var T=e._tmpMats[4];this._boneQuat.toRotationMatrix(T),this.mesh.getWorldMatrix().multiplyToRef(T,T),an.Vector3.TransformCoordinatesToRef(x,T,x),an.Vector3.TransformCoordinatesToRef(x,p,x);var E=Math.atan2(x.x,x.z);if(this._getAngleBetween(E,y)>this._getAngleBetween(E,this._midYawConstraint)){null==m&&(m=Math.sqrt(g.x*g.x+g.z*g.z));var A=this._getAngleBetween(E,this._maxYaw);this._getAngleBetween(E,this._minYaw)<A?(b=E+.75*Math.PI,g.z=Math.cos(b)*m,g.x=Math.sin(b)*m):(b=E-.75*Math.PI,g.z=Math.cos(b)*m,g.x=Math.sin(b)*m)}}y!=b&&(an.Vector3.TransformCoordinatesToRef(g,u,g),g.addInPlace(i),r=g)}}var P=e._tmpVecs[5],M=e._tmpVecs[6],S=e._tmpVecs[7],C=e._tmpQuat;r.subtractToRef(i,P),P.normalize(),an.Vector3.CrossToRef(h,P,M),M.normalize(),an.Vector3.CrossToRef(P,M,S),S.normalize(),an.Matrix.FromXYZAxesToRef(M,S,P,n),0===M.x&&0===M.y&&0===M.z||0===S.x&&0===S.y&&0===S.z||0===P.x&&0===P.y&&0===P.z||((this.adjustYaw||this.adjustPitch||this.adjustRoll)&&(an.Matrix.RotationYawPitchRollToRef(this.adjustYaw,this.adjustPitch,this.adjustRoll,o),o.multiplyToRef(n,n)),this.slerpAmount<1?(this._slerping||this.bone.getRotationQuaternionToRef(an.Space.WORLD,this.mesh,this._boneQuat),this._transformYawPitch&&this._transformYawPitch.multiplyToRef(n,n),an.Quaternion.FromRotationMatrixToRef(n,C),an.Quaternion.SlerpToRef(this._boneQuat,C,this.slerpAmount,this._boneQuat),this.bone.setRotationQuaternion(this._boneQuat,an.Space.WORLD,this.mesh),this._slerping=!0):(this._transformYawPitch&&this._transformYawPitch.multiplyToRef(n,n),this.bone.setRotationMatrix(n,an.Space.WORLD,this.mesh),this._slerping=!1))}},e.prototype._getAngleDiff=function(e,t){var i=t-e;return(i%=2*Math.PI)>Math.PI?i-=2*Math.PI:i<-Math.PI&&(i+=2*Math.PI),i},e.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},e.prototype._isAngleBetween=function(e,t,i){if(e=(e%=2*Math.PI)<0?e+2*Math.PI:e,(t=(t%=2*Math.PI)<0?t+2*Math.PI:t)<(i=(i%=2*Math.PI)<0?i+2*Math.PI:i)){if(e>t&&e<i)return!0}else if(e>i&&e<t)return!0;return!1},e._tmpVecs=[an.Vector3.Zero(),an.Vector3.Zero(),an.Vector3.Zero(),an.Vector3.Zero(),an.Vector3.Zero(),an.Vector3.Zero(),an.Vector3.Zero(),an.Vector3.Zero(),an.Vector3.Zero(),an.Vector3.Zero()],e._tmpQuat=an.Quaternion.Identity(),e._tmpMats=[an.Matrix.Identity(),an.Matrix.Identity(),an.Matrix.Identity(),an.Matrix.Identity(),an.Matrix.Identity()],e}(),an.BoneLookController=hn,ln=us||(us={}),cn=function(){function e(e,t,i){this.name=e,this.id=t,this.bones=new Array,this.needInitialSkinMatrix=!1,this._isDirty=!0,this._meshesWithPoseMatrix=new Array,this._identity=ln.Matrix.Identity(),this._ranges={},this._lastAbsoluteTransformsUpdateId=-1,this.onBeforeComputeObservable=new ln.Observable,this.bones=[],this._scene=i||ln.Engine.LastCreatedScene,i.skeletons.push(this),this._isDirty=!0}return e.prototype.getTransformMatrices=function(e){return this.needInitialSkinMatrix&&e._bonesTransformMatrices?e._bonesTransformMatrices:(this._transformMatrices||this.prepare(),this._transformMatrices)},e.prototype.getScene=function(){return this._scene},e.prototype.toString=function(e){var t="Name: "+this.name+", nBones: "+this.bones.length;if(t+=", nAnimationRanges: "+(this._ranges?Object.keys(this._ranges).length:"none"),e){t+=", Ranges: {";var i=!0;for(var r in this._ranges)i&&(t+=", ",i=!1),t+=r;t+="}"}return t},e.prototype.getBoneIndexByName=function(e){for(var t=0,i=this.bones.length;t<i;t++)if(this.bones[t].name===e)return t;return-1},e.prototype.createAnimationRange=function(e,t,i){if(!this._ranges[e]){this._ranges[e]=new ln.AnimationRange(e,t,i);for(var r=0,n=this.bones.length;r<n;r++)this.bones[r].animations[0]&&this.bones[r].animations[0].createRange(e,t,i)}},e.prototype.deleteAnimationRange=function(e,t){void 0===t&&(t=!0);for(var i=0,r=this.bones.length;i<r;i++)this.bones[i].animations[0]&&this.bones[i].animations[0].deleteRange(e,t);this._ranges[e]=null},e.prototype.getAnimationRange=function(e){return this._ranges[e]},e.prototype.getAnimationRanges=function(){var e,t=[],i=0;for(e in this._ranges)t[i]=this._ranges[e],i++;return t},e.prototype.copyAnimationRange=function(e,t,i){if(void 0===i&&(i=!1),this._ranges[t]||!e.getAnimationRange(t))return!1;var r,n,o=!0,s=this._getHighestAnimationFrame()+1,a={},h=e.bones;for(n=0,r=h.length;n<r;n++)a[h[n].name]=h[n];this.bones.length!==h.length&&(ln.Tools.Warn("copyAnimationRange: this rig has "+this.bones.length+" bones, while source as "+h.length),o=!1);var l=i&&this.dimensionsAtRest&&e.dimensionsAtRest?this.dimensionsAtRest.divide(e.dimensionsAtRest):null;for(n=0,r=this.bones.length;n<r;n++){var c=this.bones[n].name,u=a[c];u?o=o&&this.bones[n].copyAnimationRange(u,t,s,i,l):(ln.Tools.Warn("copyAnimationRange: not same rig, missing source bone "+c),o=!1)}var p=e.getAnimationRange(t);return p&&(this._ranges[t]=new ln.AnimationRange(t,p.from+s,p.to+s)),o},e.prototype.returnToRest=function(){for(var e=0;e<this.bones.length;e++)this.bones[e].returnToRest()},e.prototype._getHighestAnimationFrame=function(){for(var e=0,t=0,i=this.bones.length;t<i;t++)if(this.bones[t].animations[0]){var r=this.bones[t].animations[0].getHighestFrame();e<r&&(e=r)}return e},e.prototype.beginAnimation=function(e,t,i,r){var n=this.getAnimationRange(e);return n?this._scene.beginAnimation(this,n.from,n.to,t,i,r):null},e.prototype._markAsDirty=function(){this._isDirty=!0},e.prototype._registerMeshWithPoseMatrix=function(e){this._meshesWithPoseMatrix.push(e)},e.prototype._unregisterMeshWithPoseMatrix=function(e){var t=this._meshesWithPoseMatrix.indexOf(e);t>-1&&this._meshesWithPoseMatrix.splice(t,1)},e.prototype._computeTransformMatrices=function(e,t){this.onBeforeComputeObservable.notifyObservers(this);for(var i=0;i<this.bones.length;i++){var r=this.bones[i],n=r.getParent();if(n?r.getLocalMatrix().multiplyToRef(n.getWorldMatrix(),r.getWorldMatrix()):t?r.getLocalMatrix().multiplyToRef(t,r.getWorldMatrix()):r.getWorldMatrix().copyFrom(r.getLocalMatrix()),-1!==r._index){var o=null===r._index?i:r._index;r.getInvertedAbsoluteTransform().multiplyToArray(r.getWorldMatrix(),e,16*o)}}this._identity.copyToArray(e,16*this.bones.length)},e.prototype.prepare=function(){if(this._isDirty){if(this.needInitialSkinMatrix)for(var e=0;e<this._meshesWithPoseMatrix.length;e++){var t=this._meshesWithPoseMatrix[e],i=t.getPoseMatrix();if(t._bonesTransformMatrices&&t._bonesTransformMatrices.length===16*(this.bones.length+1)||(t._bonesTransformMatrices=new Float32Array(16*(this.bones.length+1))),this._synchronizedWithMesh!==t){this._synchronizedWithMesh=t;for(var r=0;r<this.bones.length;r++){var n=this.bones[r];if(!n.getParent())n.getBaseMatrix().multiplyToRef(i,ln.Tmp.Matrix[1]),n._updateDifferenceMatrix(ln.Tmp.Matrix[1])}}this._computeTransformMatrices(t._bonesTransformMatrices,i)}else this._transformMatrices&&this._transformMatrices.length===16*(this.bones.length+1)||(this._transformMatrices=new Float32Array(16*(this.bones.length+1))),this._computeTransformMatrices(this._transformMatrices,null);this._isDirty=!1,this._scene._activeBones.addCount(this.bones.length,!1)}},e.prototype.getAnimatables=function(){if(!this._animatables||this._animatables.length!==this.bones.length){this._animatables=[];for(var e=0;e<this.bones.length;e++)this._animatables.push(this.bones[e])}return this._animatables},e.prototype.clone=function(t,i){var r=new e(t,i||t,this._scene);r.needInitialSkinMatrix=this.needInitialSkinMatrix;for(var n=0;n<this.bones.length;n++){var o=this.bones[n],s=null,a=o.getParent();if(a){var h=this.bones.indexOf(a);s=r.bones[h]}var l=new ln.Bone(o.name,r,s,o.getBaseMatrix().clone(),o.getRestPose().clone());ln.Tools.DeepCopy(o.animations,l.animations)}if(this._ranges){r._ranges={};for(var c in this._ranges){var u=this._ranges[c];u&&(r._ranges[c]=u.clone())}}return this._isDirty=!0,r},e.prototype.enableBlending=function(e){void 0===e&&(e=.01),this.bones.forEach(function(t){t.animations.forEach(function(t){t.enableBlending=!0,t.blendingSpeed=e})})},e.prototype.dispose=function(){this._meshesWithPoseMatrix=[],this.getScene().stopAnimation(this),this.getScene().removeSkeleton(this)},e.prototype.serialize=function(){var e={};e.name=this.name,e.id=this.id,e.dimensionsAtRest=this.dimensionsAtRest,e.bones=[],e.needInitialSkinMatrix=this.needInitialSkinMatrix;for(var t=0;t<this.bones.length;t++){var i=this.bones[t],r=i.getParent(),n={parentBoneIndex:r?this.bones.indexOf(r):-1,name:i.name,matrix:i.getBaseMatrix().toArray(),rest:i.getRestPose().toArray()};e.bones.push(n),i.length&&(n.length=i.length),i.animations&&i.animations.length>0&&(n.animation=i.animations[0].serialize()),e.ranges=[];for(var o in this._ranges){var s=this._ranges[o];if(s){var a={};a.name=o,a.from=s.from,a.to=s.to,e.ranges.push(a)}}}return e},e.Parse=function(t,i){var r,n=new e(t.name,t.id,i);for(t.dimensionsAtRest&&(n.dimensionsAtRest=ln.Vector3.FromArray(t.dimensionsAtRest)),n.needInitialSkinMatrix=t.needInitialSkinMatrix,r=0;r<t.bones.length;r++){var o=t.bones[r],s=null;o.parentBoneIndex>-1&&(s=n.bones[o.parentBoneIndex]);var a=o.rest?ln.Matrix.FromArray(o.rest):null,h=new ln.Bone(o.name,n,s,ln.Matrix.FromArray(o.matrix),a);o.length&&(h.length=o.length),o.animation&&h.animations.push(ln.Animation.Parse(o.animation))}if(t.ranges)for(r=0;r<t.ranges.length;r++){var l=t.ranges[r];n.createAnimationRange(l.name,l.from,l.to)}return n},e.prototype.computeAbsoluteTransforms=function(e){void 0===e&&(e=!1);var t=this._scene.getRenderId();(this._lastAbsoluteTransformsUpdateId!=t||e)&&(this.bones[0].computeAbsoluteTransforms(),this._lastAbsoluteTransformsUpdateId=t)},e.prototype.getPoseMatrix=function(){var e=null;return this._meshesWithPoseMatrix.length>0&&(e=this._meshesWithPoseMatrix[0].getPoseMatrix()),e},e.prototype.sortBones=function(){for(var e=new Array,t=new Array(this.bones.length),i=0;i<this.bones.length;i++)this._sortBones(i,e,t);this.bones=e},e.prototype._sortBones=function(e,t,i){if(!i[e]){i[e]=!0;var r=this.bones[e];void 0===r._index&&(r._index=e);var n=r.getParent();n&&this._sortBones(this.bones.indexOf(n),t,i),t.push(r)}},e}(),ln.Skeleton=cn,function(e){var t=function(){function t(){this.x=e.Vector3.Zero(),this.y=e.Vector3.Zero(),this.z=e.Vector3.Zero(),this.xx=e.Vector3.Zero(),this.yy=e.Vector3.Zero(),this.zz=e.Vector3.Zero(),this.xy=e.Vector3.Zero(),this.yz=e.Vector3.Zero(),this.zx=e.Vector3.Zero()}return t.prototype.addAmbient=function(t){var i=new e.Vector3(t.r,t.g,t.b);this.xx=this.xx.add(i),this.yy=this.yy.add(i),this.zz=this.zz.add(i)},t.getSphericalPolynomialFromHarmonics=function(e){var i=new t;return i.x=e.L11.scale(1.02333),i.y=e.L1_1.scale(1.02333),i.z=e.L10.scale(1.02333),i.xx=e.L00.scale(.886277).subtract(e.L20.scale(.247708)).add(e.L22.scale(.429043)),i.yy=e.L00.scale(.886277).subtract(e.L20.scale(.247708)).subtract(e.L22.scale(.429043)),i.zz=e.L00.scale(.886277).add(e.L20.scale(.495417)),i.yz=e.L2_1.scale(.858086),i.zx=e.L21.scale(.858086),i.xy=e.L2_2.scale(.858086),i.scale(1/Math.PI),i},t.prototype.scale=function(e){this.x=this.x.scale(e),this.y=this.y.scale(e),this.z=this.z.scale(e),this.xx=this.xx.scale(e),this.yy=this.yy.scale(e),this.zz=this.zz.scale(e),this.yz=this.yz.scale(e),this.zx=this.zx.scale(e),this.xy=this.xy.scale(e)},t}();e.SphericalPolynomial=t;var i=function(){function t(){this.L00=e.Vector3.Zero(),this.L1_1=e.Vector3.Zero(),this.L10=e.Vector3.Zero(),this.L11=e.Vector3.Zero(),this.L2_2=e.Vector3.Zero(),this.L2_1=e.Vector3.Zero(),this.L20=e.Vector3.Zero(),this.L21=e.Vector3.Zero(),this.L22=e.Vector3.Zero()}return t.prototype.addLight=function(t,i,r){var n=new e.Vector3(i.r,i.g,i.b).scale(r);this.L00=this.L00.add(n.scale(.282095)),this.L1_1=this.L1_1.add(n.scale(.488603*t.y)),this.L10=this.L10.add(n.scale(.488603*t.z)),this.L11=this.L11.add(n.scale(.488603*t.x)),this.L2_2=this.L2_2.add(n.scale(1.092548*t.x*t.y)),this.L2_1=this.L2_1.add(n.scale(1.092548*t.y*t.z)),this.L21=this.L21.add(n.scale(1.092548*t.x*t.z)),this.L20=this.L20.add(n.scale(.315392*(3*t.z*t.z-1))),this.L22=this.L22.add(n.scale(.546274*(t.x*t.x-t.y*t.y)))},t.prototype.scale=function(e){this.L00=this.L00.scale(e),this.L1_1=this.L1_1.scale(e),this.L10=this.L10.scale(e),this.L11=this.L11.scale(e),this.L2_2=this.L2_2.scale(e),this.L2_1=this.L2_1.scale(e),this.L20=this.L20.scale(e),this.L21=this.L21.scale(e),this.L22=this.L22.scale(e)},t.prototype.convertIncidentRadianceToIrradiance=function(){this.L00=this.L00.scale(3.141593),this.L1_1=this.L1_1.scale(2.094395),this.L10=this.L10.scale(2.094395),this.L11=this.L11.scale(2.094395),this.L2_2=this.L2_2.scale(.785398),this.L2_1=this.L2_1.scale(.785398),this.L20=this.L20.scale(.785398),this.L21=this.L21.scale(.785398),this.L22=this.L22.scale(.785398)},t.prototype.convertIrradianceToLambertianRadiance=function(){this.scale(1/Math.PI)},t.getsphericalHarmonicsFromPolynomial=function(e){var i=new t;return i.L00=e.xx.scale(.376127).add(e.yy.scale(.376127)).add(e.zz.scale(.376126)),i.L1_1=e.y.scale(.977204),i.L10=e.z.scale(.977204),i.L11=e.x.scale(.977204),i.L2_2=e.xy.scale(1.16538),i.L2_1=e.yz.scale(1.16538),i.L20=e.zz.scale(1.34567).subtract(e.xx.scale(.672834)).subtract(e.yy.scale(.672834)),i.L21=e.zx.scale(1.16538),i.L22=e.xx.scale(1.16538).subtract(e.yy.scale(1.16538)),i.scale(Math.PI),i},t}();e.SphericalHarmonics=i}(us||(us={})),un=us||(us={}),pn=function(){return function(e,t,i,r){this.name=e,this.worldAxisForNormal=t,this.worldAxisForFileX=i,this.worldAxisForFileY=r}}(),fn=function(){function e(){}return e.ConvertCubeMapTextureToSphericalPolynomial=function(e){if(!e.isCube)return null;var t,i,r=e.getSize().width,n=e.readPixels(0),o=e.readPixels(1);e.isRenderTarget?(t=e.readPixels(3),i=e.readPixels(2)):(t=e.readPixels(2),i=e.readPixels(3));var s=e.readPixels(4),a=e.readPixels(5),h=e.gammaSpace,l=un.Engine.TEXTUREFORMAT_RGBA,c=un.Engine.TEXTURETYPE_UNSIGNED_INT;e.textureType&&e.textureType!==un.Engine.TEXTURETYPE_UNSIGNED_INT&&(c=un.Engine.TEXTURETYPE_FLOAT);var u={size:r,right:n,left:o,up:t,down:i,front:s,back:a,format:l,type:c,gammaSpace:h};return this.ConvertCubeMapToSphericalPolynomial(u)},e.ConvertCubeMapToSphericalPolynomial=function(e){for(var t=new un.SphericalHarmonics,i=0,r=2/e.size,n=r,o=.5*r-1,s=0;s<6;s++)for(var a=this.FileFaces[s],h=e[a.name],l=o,c=e.format===un.Engine.TEXTUREFORMAT_RGBA?4:3,u=0;u<e.size;u++){for(var p=o,f=0;f<e.size;f++){var d=a.worldAxisForFileX.scale(p).add(a.worldAxisForFileY.scale(l)).add(a.worldAxisForNormal);d.normalize();var m=Math.pow(1+p*p+l*l,-1.5),g=h[u*e.size*c+f*c+0],_=h[u*e.size*c+f*c+1],v=h[u*e.size*c+f*c+2];e.type===un.Engine.TEXTURETYPE_UNSIGNED_INT&&(g/=255,_/=255,v/=255),e.gammaSpace&&(g=Math.pow(un.Scalar.Clamp(g),un.ToLinearSpace),_=Math.pow(un.Scalar.Clamp(_),un.ToLinearSpace),v=Math.pow(un.Scalar.Clamp(v),un.ToLinearSpace));var y=new un.Color3(g,_,v);t.addLight(d,y,m),i+=m,p+=r}l+=n}var b=6*(4*Math.PI)/6/i;return t.scale(b),t.convertIncidentRadianceToIrradiance(),t.convertIrradianceToLambertianRadiance(),un.SphericalPolynomial.getSphericalPolynomialFromHarmonics(t)},e.FileFaces=[new pn("right",new un.Vector3(1,0,0),new un.Vector3(0,0,-1),new un.Vector3(0,-1,0)),new pn("left",new un.Vector3(-1,0,0),new un.Vector3(0,0,1),new un.Vector3(0,-1,0)),new pn("up",new un.Vector3(0,1,0),new un.Vector3(1,0,0),new un.Vector3(0,0,1)),new pn("down",new un.Vector3(0,-1,0),new un.Vector3(1,0,0),new un.Vector3(0,0,-1)),new pn("front",new un.Vector3(0,0,1),new un.Vector3(1,0,0),new un.Vector3(0,-1,0)),new pn("back",new un.Vector3(0,0,-1),new un.Vector3(-1,0,0),new un.Vector3(0,-1,0))],e}(),un.CubeMapToSphericalPolynomialTools=fn,dn=us||(us={}),mn=function(){function e(){}return e.ConvertPanoramaToCubemap=function(e,t,i,r){if(!e)throw"ConvertPanoramaToCubemap: input cannot be null";if(e.length!=t*i*3)throw"ConvertPanoramaToCubemap: input size is wrong";return{front:this.CreateCubemapTexture(r,this.FACE_FRONT,e,t,i),back:this.CreateCubemapTexture(r,this.FACE_BACK,e,t,i),left:this.CreateCubemapTexture(r,this.FACE_LEFT,e,t,i),right:this.CreateCubemapTexture(r,this.FACE_RIGHT,e,t,i),up:this.CreateCubemapTexture(r,this.FACE_UP,e,t,i),down:this.CreateCubemapTexture(r,this.FACE_DOWN,e,t,i),size:r,type:dn.Engine.TEXTURETYPE_FLOAT,format:dn.Engine.TEXTUREFORMAT_RGB,gammaSpace:!1}},e.CreateCubemapTexture=function(e,t,i,r,n){for(var o=new ArrayBuffer(e*e*4*3),s=new Float32Array(o),a=t[1].subtract(t[0]).scale(1/e),h=t[3].subtract(t[2]).scale(1/e),l=1/e,c=0,u=0;u<e;u++){for(var p=t[0],f=t[2],d=0;d<e;d++){var m=f.subtract(p).scale(c).add(p);m.normalize();var g=this.CalcProjectionSpherical(m,i,r,n);s[u*e*3+3*d+0]=g.r,s[u*e*3+3*d+1]=g.g,s[u*e*3+3*d+2]=g.b,p=p.add(a),f=f.add(h)}c+=l}return s},e.CalcProjectionSpherical=function(e,t,i,r){for(var n=Math.atan2(e.z,e.x),o=Math.acos(e.y);n<-Math.PI;)n+=2*Math.PI;for(;n>Math.PI;)n-=2*Math.PI;var s=n/Math.PI,a=o/Math.PI;s=.5*s+.5;var 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]}},e.FACE_FRONT=[new dn.Vector3(-1,-1,-1),new dn.Vector3(1,-1,-1),new dn.Vector3(-1,1,-1),new dn.Vector3(1,1,-1)],e.FACE_BACK=[new dn.Vector3(1,-1,1),new dn.Vector3(-1,-1,1),new dn.Vector3(1,1,1),new dn.Vector3(-1,1,1)],e.FACE_RIGHT=[new dn.Vector3(1,-1,-1),new dn.Vector3(1,-1,1),new dn.Vector3(1,1,-1),new dn.Vector3(1,1,1)],e.FACE_LEFT=[new dn.Vector3(-1,-1,1),new dn.Vector3(-1,-1,-1),new dn.Vector3(-1,1,1),new dn.Vector3(-1,1,-1)],e.FACE_DOWN=[new dn.Vector3(-1,1,-1),new dn.Vector3(1,1,-1),new dn.Vector3(-1,1,1),new dn.Vector3(1,1,1)],e.FACE_UP=[new dn.Vector3(-1,-1,1),new dn.Vector3(1,-1,1),new dn.Vector3(-1,-1,-1),new dn.Vector3(1,-1,-1)],e}(),dn.PanoramaToCubeMapTools=mn,gn=us||(us={}),_n=function(){function e(){}return e.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)},e.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)},e.readStringLine=function(e,t){for(var i="",r="",n=t;n<e.length-t&&"\n"!=(r=String.fromCharCode(e[n]));n++)i+=r;return i},e.RGBE_ReadHeader=function(e){var t,i,r=this.readStringLine(e,0);if("#"!=r[0]||"?"!=r[1])throw"Bad HDR Format.";var n=!1,o=!1,s=0;do{s+=r.length+1,"FORMAT=32-bit_rle_rgbe"==(r=this.readStringLine(e,s))?o=!0:0==r.length&&(n=!0)}while(!n);if(!o)throw"HDR Bad header format, unsupported FORMAT";s+=r.length+1,r=this.readStringLine(e,s);var a=/^\-Y (.*) \+X (.*)$/g.exec(r);if(!a||a.length<3)throw"HDR Bad header format, no size";if(i=parseInt(a[2]),t=parseInt(a[1]),i<8||i>32767)throw"HDR Bad header format, unsupported size";return{height:t,width:i,dataPosition:s+=r.length+1}},e.GetCubeMapTextureData=function(e,t){var i=new Uint8Array(e),r=this.RGBE_ReadHeader(i),n=this.RGBE_ReadPixels_RLE(i,r);return gn.PanoramaToCubeMapTools.ConvertPanoramaToCubemap(n,r.width,r.height,t)},e.RGBE_ReadPixels=function(e,t){return this.RGBE_ReadPixels_RLE(e,t)},e.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;c<u;)if(i=e[l++],r=e[l++],i>128){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;_++)d[c++]=e[l++]}for(p=0;p<h;p++)i=d[p],r=d[p+h],n=d[p+2*h],o=d[p+3*h],this.Rgbe2float(g,i,r,n,o,(t.height-a)*h*3+3*p);a--}return g},e}(),gn.HDRTools=_n,vn=us||(us={}),yn=function(e){function t(t,i,r,n,o,s,a,h,l){void 0===n&&(n=!1),void 0===o&&(o=!0),void 0===s&&(s=!1),void 0===a&&(a=!1),void 0===h&&(h=null),void 0===l&&(l=null);var c=e.call(this,i)||this;if(c._useInGammaSpace=!1,c._generateHarmonics=!0,c._isBABYLONPreprocessed=!1,c._onLoad=null,c._onError=null,c.coordinatesMode=vn.Texture.CUBIC_MODE,c.isPMREM=!1,c._isBlocking=!0,!t)return c;c.name=t,c.url=t,c.hasAlpha=!1,c.isCube=!0,c._textureMatrix=vn.Matrix.Identity(),c._onLoad=h,c._onError=l,c.gammaSpace=!1;var u=i.getEngine().getCaps();return r?(c._isBABYLONPreprocessed=!1,c._noMipmap=n,c._size=r,c._useInGammaSpace=s,c._usePMREMGenerator=a&&u.textureLOD&&u.textureFloat&&!c._useInGammaSpace):(c._isBABYLONPreprocessed=!0,c._noMipmap=!1,c._useInGammaSpace=!1,c._usePMREMGenerator=u.textureLOD&&u.textureFloat&&!c._useInGammaSpace),c.isPMREM=c._usePMREMGenerator,c._texture=c._getFromCache(t,c._noMipmap),c._texture||(i.useDelayedTextureLoading?c.delayLoadState=vn.Engine.DELAYLOADSTATE_NOTLOADED:c.loadTexture()),c}return Y(t,e),Object.defineProperty(t.prototype,"isBlocking",{get:function(){return this._isBlocking},set:function(e){this._isBlocking=e},enumerable:!0,configurable:!0}),t.prototype.loadBabylonTexture=function(){var e=this,t=0,i=null,r=this.getScene(),n=!this._useInGammaSpace&&r&&r.getEngine().getCaps().textureFloat?function(r){var n=new Array;if(!i)return n;for(var o=30,s=0;s<t;s++){n.push([]);for(var a=3*Math.pow(e._size>>s,2),h=0;h<6;h++){var l=i.subarray(o,o+a);n[s].push(l),o+=a}}return n}:null;r&&(this._texture=r.getEngine().createRawCubeTextureFromUrl(this.url,r,this._size,vn.Engine.TEXTUREFORMAT_RGB,r.getEngine().getCaps().textureFloat?vn.Engine.TEXTURETYPE_FLOAT:vn.Engine.TEXTURETYPE_UNSIGNED_INT,this._noMipmap,function(r){var o=e.getScene();if(!o)return null;var s=new Int32Array(r);i=new Float32Array(r);var a=s[0];if(e._size=s[1],!e._texture)return null;e._texture.updateSize(e._size,e._size);var h=new vn.SphericalPolynomial;h.x.copyFromFloats(i[2],i[3],i[4]),h.y.copyFromFloats(i[5],i[6],i[7]),h.z.copyFromFloats(i[8],i[9],i[10]),h.xx.copyFromFloats(i[11],i[12],i[13]),h.yy.copyFromFloats(i[14],i[15],i[16]),h.zz.copyFromFloats(i[17],i[18],i[19]),h.xy.copyFromFloats(i[20],i[21],i[22]),h.yz.copyFromFloats(i[23],i[24],i[25]),h.zx.copyFromFloats(i[26],i[27],i[28]),e.sphericalPolynomial=h,t=s[29];for(var l=30,c=[],u=3*Math.pow(e._size,2),p=0;p<6;p++)c.push(i.subarray(l,l+u)),l+=u;for(var f=[],d=null,m=0;m<6;m++){var g=null;if(1===a&&(g=c[[0,2,4,1,3,5][m]]),!n&&g){if(!o.getEngine().getCaps().textureFloat){var _=new ArrayBuffer(u);d=new Uint8Array(_)}for(var v=0;v<e._size*e._size;v++)if(e._useInGammaSpace&&(g[3*v+0]=Math.pow(g[3*v+0],vn.ToGammaSpace),g[3*v+1]=Math.pow(g[3*v+1],vn.ToGammaSpace),g[3*v+2]=Math.pow(g[3*v+2],vn.ToGammaSpace)),d){var y=Math.max(255*g[3*v+0],0),b=Math.max(255*g[3*v+1],0),x=Math.max(255*g[3*v+2],0),T=Math.max(Math.max(y,b),x);if(T>255){var E=255/T;y*=E,b*=E,x*=E}d[3*v+0]=y,d[3*v+1]=b,d[3*v+2]=x}}d?f.push(d):f.push(g)}return f},n,this._onLoad,this._onError))},t.prototype.loadHDRTexture=function(){var e=this,i=this.getScene();i&&(this._texture=i.getEngine().createRawCubeTextureFromUrl(this.url,i,this._size,vn.Engine.TEXTUREFORMAT_RGB,i.getEngine().getCaps().textureFloat?vn.Engine.TEXTURETYPE_FLOAT:vn.Engine.TEXTURETYPE_UNSIGNED_INT,this._noMipmap,function(i){var r=e.getScene();if(!r)return null;var n=vn.HDRTools.GetCubeMapTextureData(i,e._size);if(e._generateHarmonics){var o=vn.CubeMapToSphericalPolynomialTools.ConvertCubeMapToSphericalPolynomial(n);e.sphericalPolynomial=o}for(var s=[],a=null,h=0;h<6;h++){if(!r.getEngine().getCaps().textureFloat){var l=new ArrayBuffer(e._size*e._size*3);a=new Uint8Array(l)}var c=n[t._facesMapping[h]];if(e._useInGammaSpace||a)for(var u=0;u<e._size*e._size;u++)if(e._useInGammaSpace&&(c[3*u+0]=Math.pow(c[3*u+0],vn.ToGammaSpace),c[3*u+1]=Math.pow(c[3*u+1],vn.ToGammaSpace),c[3*u+2]=Math.pow(c[3*u+2],vn.ToGammaSpace)),a){var p=Math.max(255*c[3*u+0],0),f=Math.max(255*c[3*u+1],0),d=Math.max(255*c[3*u+2],0),m=Math.max(Math.max(p,f),d);if(m>255){var g=255/m;p*=g,f*=g,d*=g}a[3*u+0]=p,a[3*u+1]=f,a[3*u+2]=d}a?s.push(a):s.push(c)}return s},null,this._onLoad,this._onError))},t.prototype.loadTexture=function(){this._isBABYLONPreprocessed?this.loadBabylonTexture():this.loadHDRTexture()},t.prototype.clone=function(){var e=this.getScene();if(!e)return this;var i=this._isBABYLONPreprocessed?null:this._size,r=new t(this.url,e,i,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},t.prototype.delayLoad=function(){this.delayLoadState===vn.Engine.DELAYLOADSTATE_NOTLOADED&&(this.delayLoadState=vn.Engine.DELAYLOADSTATE_LOADED,this._texture=this._getFromCache(this.url,this._noMipmap),this._texture||this.loadTexture())},t.prototype.getReflectionTextureMatrix=function(){return this._textureMatrix},t.prototype.setReflectionTextureMatrix=function(e){this._textureMatrix=e},t.Parse=function(e,i,r){var n=null;if(e.name&&!e.isRenderTarget){var o=e.isBABYLONPreprocessed?null:e.size;(n=new t(r+e.name,i,o,e.noMipmap,e.generateHarmonics,e.useInGammaSpace,e.usePMREMGenerator)).name=e.name,n.hasAlpha=e.hasAlpha,n.level=e.level,n.coordinatesMode=e.coordinatesMode,n.isBlocking=e.isBlocking}return n},t.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},t.generateBabylonHDROnDisk=function(e,i,r){void 0===r&&(r=null);t.generateBabylonHDR(e,i,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)},t.generateBabylonHDR=function(e,t,i,r){void 0===r&&(r=null),e&&vn.Tools.IsExponentOfTwo(t)&&vn.Tools.Error("Generation of Babylon HDR is coming back in 3.2.")},t._facesMapping=["right","left","up","down","front","back"],t}(vn.BaseTexture),vn.HDRCubeTexture=yn,function(e){e.earcut=function(e,t,o){o=o||2;var s=t&&t.length,a=s?t[0]*o:e.length,h=i(e,0,a,o,!0),u=new Array;if(!h)return u;var f,d,m,g,_=0,v=0,y=0;if(s&&(h=function(e,t,n,o){var s,a,h,u,f,d=[];for(s=0,a=t.length;s<a;s++)h=t[s]*o,u=s<a-1?t[s+1]*o:e.length,(f=i(e,h,u,o,!1))===f.next&&(f.steiner=!0),d.push(p(f));for(d.sort(l),s=0;s<d.length;s++)c(d[s],n),n=r(n,n.next);return n}(e,t,h,o)),e.length>80*o){_=f=e[0],v=d=e[1];for(var b=o;b<a;b+=o)m=e[b],g=e[b+1],m<_&&(_=m),g<v&&(v=g),m>f&&(f=m),g>d&&(d=g);y=Math.max(f-_,d-v)}return n(h,u,o,_,v,y,0),u};var t=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}}();function i(e,t,i,r,n){var o,s=null;if(n===x(e,t,i,r)>0)for(o=t;o<i;o+=r)s=y(o,e[o],e[o+1],s);else for(o=i-r;o>=t;o-=r)s=y(o,e[o],e[o+1],s);return s&&m(s,s.next)&&(b(s),s=s.next),s}function r(e,t){if(!e)return e;t||(t=e);var i,r=e;do{if(i=!1,r.steiner||!m(r,r.next)&&0!==d(r.prev,r,r.next))r=r.next;else{if(b(r),(r=t=r.prev)===r.next)return;i=!0}}while(i||r!==t);return t}function n(e,t,i,l,c,p,f){if(e){!f&&p&&function(e,t,i,r){var n=e;do{null===n.z&&(n.z=u(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;t<l&&(a++,r=r.nextZ);t++);for(h=l;a>0||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,l,c,p);for(var d,m,g=e;e.prev!==e.next;)if(d=e.prev,m=e.next,p?s(e,l,c,p):o(e))t.push(d.i/i),t.push(e.i/i),t.push(m.i/i),b(e),e=m.next,g=m.next;else if((e=m)===g){f?1===f?n(e=a(e,t,i),t,i,l,c,p,2):2===f&&h(e,t,i,l,c,p):n(r(e,void 0),t,i,l,c,p,1);break}}}function o(e){var t=e.prev,i=e,r=e.next;if(d(t,i,r)>=0)return!1;for(var n=e.next.next;n!==e.prev;){if(f(t.x,t.y,i.x,i.y,r.x,r.y,n.x,n.y)&&d(n.prev,n,n.next)>=0)return!1;n=n.next}return!0}function s(e,t,i,r){var n=e.prev,o=e,s=e.next;if(d(n,o,s)>=0)return!1;for(var a=n.x<o.x?n.x<s.x?n.x:s.x:o.x<s.x?o.x:s.x,h=n.y<o.y?n.y<s.y?n.y:s.y:o.y<s.y?o.y:s.y,l=n.x>o.x?n.x>s.x?n.x:s.x:o.x>s.x?o.x:s.x,c=n.y>o.y?n.y>s.y?n.y:s.y:o.y>s.y?o.y:s.y,p=u(a,h,t,i,r),m=u(l,c,t,i,r),g=e.nextZ;g&&g.z<=m;){if(g!==e.prev&&g!==e.next&&f(n.x,n.y,o.x,o.y,s.x,s.y,g.x,g.y)&&d(g.prev,g,g.next)>=0)return!1;g=g.nextZ}for(g=e.prevZ;g&&g.z>=p;){if(g!==e.prev&&g!==e.next&&f(n.x,n.y,o.x,o.y,s.x,s.y,g.x,g.y)&&d(g.prev,g,g.next)>=0)return!1;g=g.prevZ}return!0}function a(e,t,i){var r=e;do{var n=r.prev,o=r.next.next;!m(n,o)&&g(n,r,r.next,o)&&_(n,o)&&_(o,n)&&(t.push(n.i/i),t.push(r.i/i),t.push(o.i/i),b(r),b(r.next),r=e=o),r=r.next}while(r!==e);return r}function h(e,t,i,o,s,a){var h,l,c=e;do{for(var u=c.next.next;u!==c.prev;){if(c.i!==u.i&&(l=u,(h=c).next.i!==l.i&&h.prev.i!==l.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&&g(i,i.next,e,t))return!0;i=i.next}while(i!==e);return!1}(h,l)&&_(h,l)&&_(l,h)&&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}(h,l))){var p=v(c,u);return c=r(c,c.next),p=r(p,p.next),n(c,t,i,o,s,a,void 0),void n(p,t,i,o,s,a,void 0)}u=u.next}c=c.next}while(c!==e)}function l(e,t){return e.x-t.x}function c(e,t){if(t=function(e,t){var i,r=t,n=e.x,o=e.y,s=-1/0;do{if(o<=r.y&&o>=r.next.y){var a=r.x+(o-r.y)*(r.next.x-r.x)/(r.next.y-r.y);if(a<=n&&a>s){if(s=a,a===n){if(o===r.y)return r;if(o===r.next.y)return r.next}i=r.x<r.next.x?r:r.next}}r=r.next}while(r!==t);if(!i)return null;if(n===s)return i.prev;var h,l=i,c=i.x,u=i.y,p=1/0;r=i.next;for(;r!==l;)n>=r.x&&r.x>=c&&f(o<u?n:s,o,c,u,o<u?s:n,o,r.x,r.y)&&((h=Math.abs(o-r.y)/(n-r.x))<p||h===p&&r.x>i.x)&&_(r,e)&&(i=r,p=h),r=r.next;return i}(e,t)){var i=v(t,e);r(i,i.next)}}function u(e,t,i,r,n){return(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=32767*(e-i)/n)|e<<8))|e<<4))|e<<2))|e<<1))|(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=32767*(t-r)/n)|t<<8))|t<<4))|t<<2))|t<<1))<<1}function p(e){var t=e,i=e;do{t.x<i.x&&(i=t),t=t.next}while(t!==e);return i}function f(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 d(e,t,i){return(t.y-e.y)*(i.x-t.x)-(t.x-e.x)*(i.y-t.y)}function m(e,t){return e.x===t.x&&e.y===t.y}function g(e,t,i,r){return!!(m(e,t)&&m(i,r)||m(e,r)&&m(i,t))||d(e,t,i)>0!=d(e,t,r)>0&&d(i,r,e)>0!=d(i,r,t)>0}function _(e,t){return d(e.prev,e,e.next)<0?d(e,t,e.next)>=0&&d(e,e.prev,t)>=0:d(e,t,e.prev)<0||d(e,e.next,t)<0}function v(e,i){var r=new t(e.i,e.x,e.y),n=new t(i.i,i.x,i.y),o=e.next,s=i.prev;return e.next=i,i.prev=e,r.next=o,o.prev=r,n.next=r,r.prev=n,s.next=n,n.prev=s,n}function y(e,i,r,n){var o=new t(e,i,r);return n?(o.next=n.next,o.prev=n,n.next.prev=o,n.next=o):(o.prev=o,o.next=o),o}function b(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 x(e,t,i,r){for(var n=0,o=t,s=i-r;o<i;o+=r)n+=(e[s]-e[o])*(e[o+1]+e[s+1]),s=o;return n}e.deviation=function(e,t,i,r){var n=t&&t.length,o=n?t[0]*i:e.length,s=Math.abs(x(e,0,o,i));if(n)for(var a=0,h=t.length;a<h;a++){var l=t[a]*i,c=a<h-1?t[a+1]*i:e.length;s-=Math.abs(x(e,l,c,i))}var u=0;for(a=0;a<r.length;a+=3){var p=r[a]*i,f=r[a+1]*i,d=r[a+2]*i;u+=Math.abs((e[p]-e[d])*(e[f+1]-e[p+1])-(e[p]-e[f])*(e[d+1]-e[p+1]))}return 0===s&&0===u?0:Math.abs((u-s)/s)},e.flatten=function(e){for(var t=e[0][0].length,i={vertices:new Array,holes:new Array,dimensions:t},r=0,n=0;n<e.length;n++){for(var o=0;o<e[n].length;o++)for(var s=0;s<t;s++)i.vertices.push(e[n][o][s]);n>0&&(r+=e[n-1].length,i.holes.push(r))}return i}}(bn||(bn={})),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 Y(t,e),t}(e.Vector2),i=function(){function i(){this.elements=new Array}return i.prototype.add=function(e){var i=this,r=new Array;return e.forEach(function(e){if(0===r.length||!e.equalsWithEpsilon(r[0])){var n=new t(e,i.elements.length);r.push(n),i.elements.push(n)}}),r},i.prototype.computeBounds=function(){var t=new e.Vector2(this.elements[0].x,this.elements[0].y),i=new e.Vector2(this.elements[0].x,this.elements[0].y);return this.elements.forEach(function(e){e.x<t.x?t.x=e.x:e.x>i.x&&(i.x=e.x),e.y<t.y?t.y=e.y:e.y>i.y&&(i.y=e.y)}),{min:t,max:i,width:i.x-t.x,height:i.y-t.y}},i}(),r=function(){function t(){}return t.Rectangle=function(t,i,r,n){return[new e.Vector2(t,i),new e.Vector2(r,i),new e.Vector2(r,n),new e.Vector2(t,n)]},t.Circle=function(t,i,r,n){void 0===i&&(i=0),void 0===r&&(r=0),void 0===n&&(n=32);for(var o=new Array,s=0,a=2*Math.PI/n,h=0;h<n;h++)o.push(new e.Vector2(i+Math.cos(s)*t,r+Math.sin(s)*t)),s-=a;return o},t.Parse=function(t){var i,r=t.split(/[^-+eE\.\d]+/).map(parseFloat).filter(function(e){return!isNaN(e)}),n=[];for(i=0;i<(2147483646&r.length);i+=2)n.push(new e.Vector2(r[i],r[i+1]));return n},t.StartingAt=function(t,i){return e.Path2.StartingAt(t,i)},t}();e.Polygon=r;var n=function(){function t(t,r,n){var o;this._points=new i,this._outlinepoints=new i,this._holes=new Array,this._epoints=new Array,this._eholes=new Array,this._name=t,this._scene=n,o=r instanceof e.Path2?r.getPoints():r,this._addToepoint(o),this._points.add(o),this._outlinepoints.add(o)}return t.prototype._addToepoint=function(e){for(var t=0,i=e;t<i.length;t++){var r=i[t];this._epoints.push(r.x,r.y)}},t.prototype.addHole=function(e){this._points.add(e);var t=new i;return t.add(e),this._holes.push(t),this._eholes.push(this._epoints.length/2),this._addToepoint(e),this},t.prototype.build=function(t,i){var r=this;void 0===t&&(t=!1),void 0===i&&(i=0);var n=new e.Mesh(this._name,this._scene),o=new Array,s=new Array,a=new Array,h=this._points.computeBounds();this._points.elements.forEach(function(e){o.push(0,1,0),s.push(e.x,0,e.y),a.push((e.x-h.min.x)/h.width,(e.y-h.min.y)/h.height)});for(var l=new Array,c=bn.earcut(this._epoints,this._eholes,2),u=0;u<c.length;u++)l.push(c[u]);if(i>0){var p=s.length/3;this._points.elements.forEach(function(e){o.push(0,-1,0),s.push(e.x,-i,e.y),a.push(1-(e.x-h.min.x)/h.width,1-(e.y-h.min.y)/h.height)});var f=l.length;for(u=0;u<f;u+=3){var d=l[u+0],m=l[u+1],g=l[u+2];l.push(g+p),l.push(m+p),l.push(d+p)}this.addSide(s,o,a,l,h,this._outlinepoints,i,!1),this._holes.forEach(function(e){r.addSide(s,o,a,l,h,e,i,!0)})}return n.setVerticesData(e.VertexBuffer.PositionKind,s,t),n.setVerticesData(e.VertexBuffer.NormalKind,o,t),n.setVerticesData(e.VertexBuffer.UVKind,a,t),n.setIndices(l),n},t.prototype.addSide=function(t,i,r,n,o,s,a,h){for(var l=t.length/3,c=0,u=0;u<s.elements.length;u++){var p,f=s.elements[u];p=u+1>s.elements.length-1?s.elements[0]:s.elements[u+1],t.push(f.x,0,f.y),t.push(f.x,-a,f.y),t.push(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=n}(us||(us={})),xn=us||(us={}),Tn=0,En=function(){function e(e,t,i){this.pos=e,this.normal=t,this.uv=i}return e.prototype.clone=function(){return new e(this.pos.clone(),this.normal.clone(),this.uv.clone())},e.prototype.flip=function(){this.normal=this.normal.scale(-1)},e.prototype.interpolate=function(t,i){return new e(xn.Vector3.Lerp(this.pos,t.pos,i),xn.Vector3.Lerp(this.normal,t.normal,i),xn.Vector2.Lerp(this.uv,t.uv,i))},e}(),An=function(){function e(e,t){this.normal=e,this.w=t}return e.FromPoints=function(t,i,r){var n=r.subtract(t),o=i.subtract(t);if(0===n.lengthSquared()||0===o.lengthSquared())return null;var s=xn.Vector3.Normalize(xn.Vector3.Cross(n,o));return new e(s,xn.Vector3.Dot(s,t))},e.prototype.clone=function(){return new e(this.normal.clone(),this.w)},e.prototype.flip=function(){this.normal.scaleInPlace(-1),this.w=-this.w},e.prototype.splitPolygon=function(t,i,r,n,o){var s,a,h=0,l=[];for(s=0;s<t.vertices.length;s++){var c=(a=xn.Vector3.Dot(this.normal,t.vertices[s].pos)-this.w)<-e.EPSILON?2:a>e.EPSILON?1:0;h|=c,l.push(c)}switch(h){case 0:(xn.Vector3.Dot(this.normal,t.plane.normal)>0?i:r).push(t);break;case 1:n.push(t);break;case 2:o.push(t);break;case 3:var u,p=[],f=[];for(s=0;s<t.vertices.length;s++){var d=(s+1)%t.vertices.length,m=l[s],g=l[d],_=t.vertices[s],v=t.vertices[d];if(2!==m&&p.push(_),1!==m&&f.push(2!==m?_.clone():_),3==(m|g)){a=(this.w-xn.Vector3.Dot(this.normal,_.pos))/xn.Vector3.Dot(this.normal,v.pos.subtract(_.pos));var y=_.interpolate(v,a);p.push(y),f.push(y.clone())}}p.length>=3&&(u=new Pn(p,t.shared)).plane&&n.push(u),f.length>=3&&(u=new Pn(f,t.shared)).plane&&o.push(u)}},e.EPSILON=1e-5,e}(),Pn=function(){function e(e,t){this.vertices=e,this.shared=t,this.plane=An.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}(),Mn=function(){function e(e){this.plane=null,this.front=null,this.back=null,this.polygons=new Array,e&&this.build(e)}return e.prototype.clone=function(){var t=new e;return t.plane=this.plane&&this.plane.clone(),t.front=this.front&&this.front.clone(),t.back=this.back&&this.back.clone(),t.polygons=this.polygons.map(function(e){return e.clone()}),t},e.prototype.invert=function(){for(var e=0;e<this.polygons.length;e++)this.polygons[e].flip();this.plane&&this.plane.flip(),this.front&&this.front.invert(),this.back&&this.back.invert();var t=this.front;this.front=this.back,this.back=t},e.prototype.clipPolygons=function(e){if(!this.plane)return e.slice();for(var t=new Array,i=new Array,r=0;r<e.length;r++)this.plane.splitPolygon(e[r],t,i,t,i);return this.front&&(t=this.front.clipPolygons(t)),i=this.back?this.back.clipPolygons(i):[],t.concat(i)},e.prototype.clipTo=function(e){this.polygons=e.clipPolygons(this.polygons),this.front&&this.front.clipTo(e),this.back&&this.back.clipTo(e)},e.prototype.allPolygons=function(){var e=this.polygons.slice();return this.front&&(e=e.concat(this.front.allPolygons())),this.back&&(e=e.concat(this.back.allPolygons())),e},e.prototype.build=function(t){if(t.length){this.plane||(this.plane=t[0].plane.clone());for(var i=new Array,r=new Array,n=0;n<t.length;n++)this.plane.splitPolygon(t[n],this.polygons,this.polygons,i,r);i.length&&(this.front||(this.front=new e),this.front.build(i)),r.length&&(this.back||(this.back=new e),this.back.build(r))}},e}(),Sn=function(){function e(){this.polygons=new Array}return e.FromMesh=function(t){var i,r,n,o,s,a,h,l,c,u,p=new Array,f=null;if(!(t instanceof xn.Mesh))throw"BABYLON.CSG: Wrong Mesh type, must be BABYLON.Mesh";t.computeWorldMatrix(!0),h=t.getWorldMatrix(),l=t.position.clone(),c=t.rotation.clone(),t.rotationQuaternion&&(f=t.rotationQuaternion.clone()),u=t.scaling.clone();for(var d=t.getIndices(),m=t.getVerticesData(xn.VertexBuffer.PositionKind),g=t.getVerticesData(xn.VertexBuffer.NormalKind),_=t.getVerticesData(xn.VertexBuffer.UVKind),v=t.subMeshes,y=0,b=v.length;y<b;y++)for(var x=v[y].indexStart,T=v[y].indexCount+v[y].indexStart;x<T;x+=3){a=[];for(var E=0;E<3;E++){var A=new xn.Vector3(g[3*d[x+E]],g[3*d[x+E]+1],g[3*d[x+E]+2]);n=new xn.Vector2(_[2*d[x+E]],_[2*d[x+E]+1]);var P=new xn.Vector3(m[3*d[x+E]],m[3*d[x+E]+1],m[3*d[x+E]+2]);o=xn.Vector3.TransformCoordinates(P,h),r=xn.Vector3.TransformNormal(A,h),i=new En(o,r,n),a.push(i)}(s=new Pn(a,{subMeshId:y,meshId:Tn,materialIndex:v[y].materialIndex})).plane&&p.push(s)}var M=e.FromPolygons(p);return M.matrix=h,M.position=l,M.rotation=c,M.scaling=u,M.rotationQuaternion=f,Tn++,M},e.FromPolygons=function(t){var i=new e;return i.polygons=t,i},e.prototype.clone=function(){var t=new e;return t.polygons=this.polygons.map(function(e){return e.clone()}),t.copyTransformAttributes(this),t},e.prototype.union=function(t){var i=new Mn(this.clone().polygons),r=new Mn(t.clone().polygons);return i.clipTo(r),r.clipTo(i),r.invert(),r.clipTo(i),r.invert(),i.build(r.allPolygons()),e.FromPolygons(i.allPolygons()).copyTransformAttributes(this)},e.prototype.unionInPlace=function(e){var t=new Mn(this.polygons),i=new Mn(e.polygons);t.clipTo(i),i.clipTo(t),i.invert(),i.clipTo(t),i.invert(),t.build(i.allPolygons()),this.polygons=t.allPolygons()},e.prototype.subtract=function(t){var i=new Mn(this.clone().polygons),r=new Mn(t.clone().polygons);return i.invert(),i.clipTo(r),r.clipTo(i),r.invert(),r.clipTo(i),r.invert(),i.build(r.allPolygons()),i.invert(),e.FromPolygons(i.allPolygons()).copyTransformAttributes(this)},e.prototype.subtractInPlace=function(e){var t=new Mn(this.polygons),i=new Mn(e.polygons);t.invert(),t.clipTo(i),i.clipTo(t),i.invert(),i.clipTo(t),i.invert(),t.build(i.allPolygons()),t.invert(),this.polygons=t.allPolygons()},e.prototype.intersect=function(t){var i=new Mn(this.clone().polygons),r=new Mn(t.clone().polygons);return i.invert(),r.clipTo(i),r.invert(),i.clipTo(r),r.clipTo(i),i.build(r.allPolygons()),i.invert(),e.FromPolygons(i.allPolygons()).copyTransformAttributes(this)},e.prototype.intersectInPlace=function(e){var t=new Mn(this.polygons),i=new Mn(e.polygons);t.invert(),i.clipTo(t),i.invert(),t.clipTo(i),i.clipTo(t),t.build(i.allPolygons()),t.invert(),this.polygons=t.allPolygons()},e.prototype.inverse=function(){var e=this.clone();return e.inverseInPlace(),e},e.prototype.inverseInPlace=function(){this.polygons.map(function(e){e.flip()})},e.prototype.copyTransformAttributes=function(e){return this.matrix=e.matrix,this.position=e.position,this.rotation=e.rotation,this.scaling=e.scaling,this.rotationQuaternion=e.rotationQuaternion,this},e.prototype.buildMeshGeometry=function(e,t,i){var r=this.matrix.clone();r.invert();var n,o,s,a=new xn.Mesh(e,t),h=[],l=[],c=[],u=[],p=xn.Vector3.Zero(),f=xn.Vector3.Zero(),d=xn.Vector2.Zero(),m=this.polygons,g=[0,0,0],_={},v=0,y={};i&&m.sort(function(e,t){return e.shared.meshId===t.shared.meshId?e.shared.subMeshId-t.shared.subMeshId:e.shared.meshId-t.shared.meshId});for(var b=0,x=m.length;b<x;b++){y[(n=m[b]).shared.meshId]||(y[n.shared.meshId]={}),y[n.shared.meshId][n.shared.subMeshId]||(y[n.shared.meshId][n.shared.subMeshId]={indexStart:1/0,indexEnd:-1/0,materialIndex:n.shared.materialIndex}),s=y[n.shared.meshId][n.shared.subMeshId];for(var T=2,E=n.vertices.length;T<E;T++){g[0]=0,g[1]=T-1,g[2]=T;for(var A=0;A<3;A++){p.copyFrom(n.vertices[g[A]].pos),f.copyFrom(n.vertices[g[A]].normal),d.copyFrom(n.vertices[g[A]].uv);var P=xn.Vector3.TransformCoordinates(p,r),M=xn.Vector3.TransformNormal(f,r);void 0!==(o=_[P.x+","+P.y+","+P.z])&&c[3*o]===M.x&&c[3*o+1]===M.y&&c[3*o+2]===M.z&&u[2*o]===d.x&&u[2*o+1]===d.y||(h.push(P.x,P.y,P.z),u.push(d.x,d.y),c.push(f.x,f.y,f.z),o=_[P.x+","+P.y+","+P.z]=h.length/3-1),l.push(o),s.indexStart=Math.min(v,s.indexStart),s.indexEnd=Math.max(v,s.indexEnd),v++}}}if(a.setVerticesData(xn.VertexBuffer.PositionKind,h),a.setVerticesData(xn.VertexBuffer.NormalKind,c),a.setVerticesData(xn.VertexBuffer.UVKind,u),a.setIndices(l,null),i){var S,C=0;a.subMeshes=new Array;for(var R in y){S=-1;for(var O in y[R])s=y[R][O],xn.SubMesh.CreateFromIndices(s.materialIndex+C,s.indexStart,s.indexEnd-s.indexStart+1,a),S=Math.max(s.materialIndex,S);C+=++S}}return a},e.prototype.toMesh=function(e,t,i,r){var n=this.buildMeshGeometry(e,i,r);return n.material=t,n.position.copyFrom(this.position),n.rotation.copyFrom(this.rotation),this.rotationQuaternion&&(n.rotationQuaternion=this.rotationQuaternion.clone()),n.scaling.copyFrom(this.scaling),n.computeWorldMatrix(!0),n},e}(),xn.CSG=Sn,Cn=us||(us={}),Rn=function(){function e(e,t,i,r,n){this.size=e,this.position=t,this.alphaMode=Cn.Engine.ALPHA_ONEONE,this.color=i||new Cn.Color3(1,1,1),this.texture=r?new Cn.Texture(r,n.getScene(),!0):null,this._system=n,n.lensFlares.push(this)}return e.AddFlare=function(t,i,r,n,o){return new e(t,i,r,n,o)},e.prototype.dispose=function(){this.texture&&this.texture.dispose();var e=this._system.lensFlares.indexOf(this);this._system.lensFlares.splice(e,1)},e}(),Cn.LensFlare=Rn,On=us||(us={}),In=function(){function e(e,t,i){this.name=e,this.lensFlares=new Array,this.borderLimit=300,this.viewportBorder=0,this.layerMask=268435455,this._vertexBuffers={},this._isEnabled=!0,this._scene=i||On.Engine.LastCreatedScene,this._emitter=t,this.id=e,i.lensFlareSystems.push(this),this.meshesSelectionPredicate=function(e){return i.activeCamera&&e.material&&e.isVisible&&e.isEnabled()&&e.isBlocker&&0!=(e.layerMask&i.activeCamera.layerMask)};var r=i.getEngine(),n=[];n.push(1,1),n.push(-1,1),n.push(-1,-1),n.push(1,-1),this._vertexBuffers[On.VertexBuffer.PositionKind]=new On.VertexBuffer(r,n,On.VertexBuffer.PositionKind,!1,!1,2);var o=[];o.push(0),o.push(1),o.push(2),o.push(0),o.push(2),o.push(3),this._indexBuffer=r.createIndexBuffer(o),this._effect=r.createEffect("lensFlare",[On.VertexBuffer.PositionKind],["color","viewportMatrix"],["textureSampler"],"")}return Object.defineProperty(e.prototype,"isEnabled",{get:function(){return this._isEnabled},set:function(e){this._isEnabled=e},enumerable:!0,configurable:!0}),e.prototype.getScene=function(){return this._scene},e.prototype.getEmitter=function(){return this._emitter},e.prototype.setEmitter=function(e){this._emitter=e},e.prototype.getEmitterPosition=function(){return this._emitter.getAbsolutePosition?this._emitter.getAbsolutePosition():this._emitter.position},e.prototype.computeEffectivePosition=function(e){var t=this.getEmitterPosition();return t=On.Vector3.Project(t,On.Matrix.Identity(),this._scene.getTransformMatrix(),e),this._positionX=t.x,this._positionY=t.y,t=On.Vector3.TransformCoordinates(this.getEmitterPosition(),this._scene.getViewMatrix()),this.viewportBorder>0&&(e.x-=this.viewportBorder,e.y-=this.viewportBorder,e.width+=2*this.viewportBorder,e.height+=2*this.viewportBorder,t.x+=this.viewportBorder,t.y+=this.viewportBorder,this._positionX+=this.viewportBorder,this._positionY+=this.viewportBorder),t.z>0&&(this._positionX>e.x&&this._positionX<e.x+e.width&&this._positionY>e.y&&(this._positionY,e.y,e.height),!0)},e.prototype._isVisible=function(){if(!this._isEnabled||!this._scene.activeCamera)return!1;var e=this.getEmitterPosition().subtract(this._scene.activeCamera.globalPosition),t=e.length();e.normalize();var i=new On.Ray(this._scene.activeCamera.globalPosition,e),r=this._scene.pickWithRay(i,this.meshesSelectionPredicate,!0);return!r||!r.hit||r.distance>t},e.prototype.render=function(){if(!this._effect.isReady()||!this._scene.activeCamera)return!1;var e,t,i=this._scene.getEngine(),r=this._scene.activeCamera.viewport.toGlobal(i.getRenderWidth(!0),i.getRenderHeight(!0));if(!this.computeEffectivePosition(r))return!1;if(!this._isVisible())return!1;var n=(e=this._positionX<this.borderLimit+r.x?this.borderLimit+r.x-this._positionX:this._positionX>r.x+r.width-this.borderLimit?this._positionX-r.x-r.width+this.borderLimit:0)>(t=this._positionY<this.borderLimit+r.y?this.borderLimit+r.y-this._positionY:this._positionY>r.y+r.height-this.borderLimit?this._positionY-r.y-r.height+this.borderLimit:0)?e:t;(n-=this.viewportBorder)>this.borderLimit&&(n=this.borderLimit);var o=1-n/this.borderLimit;if(o<0)return!1;o>1&&(o=1),this.viewportBorder>0&&(r.x+=this.viewportBorder,r.y+=this.viewportBorder,r.width-=2*this.viewportBorder,r.height-=2*this.viewportBorder,this._positionX-=this.viewportBorder,this._positionY-=this.viewportBorder);var s=r.x+r.width/2,a=r.y+r.height/2,h=s-this._positionX,l=a-this._positionY;i.enableEffect(this._effect),i.setState(!1),i.setDepthBuffer(!1),i.bindBuffers(this._vertexBuffers,this._indexBuffer,this._effect);for(var c=0;c<this.lensFlares.length;c++){var u=this.lensFlares[c];i.setAlphaMode(u.alphaMode);var p=s-h*u.position,f=a-l*u.position,d=u.size,m=u.size*i.getAspectRatio(this._scene.activeCamera,!0),g=p/(r.width+2*r.x)*2-1,_=1-f/(r.height+2*r.y)*2,v=On.Matrix.FromValues(d/2,0,0,0,0,m/2,0,0,0,0,1,0,g,_,0,1);this._effect.setMatrix("viewportMatrix",v),this._effect.setTexture("textureSampler",u.texture),this._effect.setFloat4("color",u.color.r*o,u.color.g*o,u.color.b*o,1),i.drawElementsType(On.Material.TriangleFillMode,0,6)}return i.setDepthBuffer(!0),i.setAlphaMode(On.Engine.ALPHA_DISABLE),!0},e.prototype.dispose=function(){var e=this._vertexBuffers[On.VertexBuffer.PositionKind];for(e&&(e.dispose(),this._vertexBuffers[On.VertexBuffer.PositionKind]=null),this._indexBuffer&&(this._scene.getEngine()._releaseBuffer(this._indexBuffer),this._indexBuffer=null);this.lensFlares.length;)this.lensFlares[0].dispose();var t=this._scene.lensFlareSystems.indexOf(this);this._scene.lensFlareSystems.splice(t,1)},e.Parse=function(t,i,r){var n=i.getLastEntryByID(t.emitterId),o=t.name||"lensFlareSystem#"+t.emitterId,s=new e(o,n,i);s.id=t.id||o,s.borderLimit=t.borderLimit;for(var a=0;a<t.flares.length;a++){var h=t.flares[a];On.LensFlare.AddFlare(h.size,h.position,On.Color3.FromArray(h.color),h.textureName?r+h.textureName:"",s)}return s},e.prototype.serialize=function(){var e={};e.id=this.id,e.name=this.name,e.emitterId=this.getEmitter().id,e.borderLimit=this.borderLimit,e.flares=[];for(var t=0;t<this.lensFlares.length;t++){var i=this.lensFlares[t];e.flares.push({size:i.size,position:i.position,color:i.color.asArray(),textureName:On.Tools.GetFilename(i.texture?i.texture.name:"")})}return e},e}(),On.LensFlareSystem=In,function(e){var t=function(){function e(e,t){this.type=e,this.jointData=t,t.nativeParams=t.nativeParams||{}}return Object.defineProperty(e.prototype,"physicsJoint",{get:function(){return this._physicsJoint},set:function(e){this._physicsJoint,this._physicsJoint=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"physicsPlugin",{set:function(e){this._physicsPlugin=e},enumerable:!0,configurable:!0}),e.prototype.executeNativeFunction=function(e){e(this._physicsPlugin.world,this._physicsJoint)},e.DistanceJoint=0,e.HingeJoint=1,e.BallAndSocketJoint=2,e.WheelJoint=3,e.SliderJoint=4,e.PrismaticJoint=5,e.UniversalJoint=6,e.Hinge2Joint=e.WheelJoint,e.PointToPointJoint=8,e.SpringJoint=9,e.LockJoint=10,e}();e.PhysicsJoint=t;var i=function(e){function i(i){return e.call(this,t.DistanceJoint,i)||this}return Y(i,e),i.prototype.updateDistance=function(e,t){this._physicsPlugin.updateDistanceJoint(this,e,t)},i}(t);e.DistanceJoint=i;var r=function(e){function t(t,i){return e.call(this,t,i)||this}return Y(t,e),t.prototype.setMotor=function(e,t){this._physicsPlugin.setMotor(this,e||0,t)},t.prototype.setLimit=function(e,t){this._physicsPlugin.setLimit(this,e,t)},t}(t);e.MotorEnabledJoint=r;var n=function(e){function i(i){return e.call(this,t.HingeJoint,i)||this}return Y(i,e),i.prototype.setMotor=function(e,t){this._physicsPlugin.setMotor(this,e||0,t)},i.prototype.setLimit=function(e,t){this._physicsPlugin.setLimit(this,e,t)},i}(r);e.HingeJoint=n;var o=function(e){function i(i){return e.call(this,t.Hinge2Joint,i)||this}return Y(i,e),i.prototype.setMotor=function(e,t,i){void 0===i&&(i=0),this._physicsPlugin.setMotor(this,e||0,t,i)},i.prototype.setLimit=function(e,t,i){void 0===i&&(i=0),this._physicsPlugin.setLimit(this,e,t,i)},i}(r);e.Hinge2Joint=o}(us||(us={})),wn=us||(us={}),Dn=function(){function e(e,t,i,r){void 0===i&&(i={mass:0});var n=this;this.object=e,this.type=t,this._options=i,this._scene=r,this._bodyUpdateRequired=!1,this._onBeforePhysicsStepCallbacks=new Array,this._onAfterPhysicsStepCallbacks=new Array,this._onPhysicsCollideCallbacks=[],this._deltaPosition=wn.Vector3.Zero(),this._isDisposed=!1,this._tmpQuat=new wn.Quaternion,this._tmpQuat2=new wn.Quaternion,this.beforeStep=function(){n._physicsEngine&&(n.object.translate(n._deltaPosition,-1),n._deltaRotationConjugated&&n.object.rotationQuaternion&&n.object.rotationQuaternion.multiplyToRef(n._deltaRotationConjugated,n.object.rotationQuaternion),n.object.computeWorldMatrix(!1),n.object.parent&&n.object.rotationQuaternion?(n.getParentsRotation(),n._tmpQuat.multiplyToRef(n.object.rotationQuaternion,n._tmpQuat)):n._tmpQuat.copyFrom(n.object.rotationQuaternion||new wn.Quaternion),n._options.disableBidirectionalTransformation||n.object.rotationQuaternion&&n._physicsEngine.getPhysicsPlugin().setPhysicsBodyTransformation(n,n.object.getAbsolutePivotPoint(),n._tmpQuat),n._onBeforePhysicsStepCallbacks.forEach(function(e){e(n)}))},this.afterStep=function(){n._physicsEngine&&(n._onAfterPhysicsStepCallbacks.forEach(function(e){e(n)}),n._physicsEngine.getPhysicsPlugin().setTransformationFromPhysicsBody(n),n.object.parent&&n.object.rotationQuaternion&&(n.getParentsRotation(),n._tmpQuat.conjugateInPlace(),n._tmpQuat.multiplyToRef(n.object.rotationQuaternion,n.object.rotationQuaternion)),n.object.setAbsolutePosition(n.object.position),n._deltaRotation&&n.object.rotationQuaternion&&n.object.rotationQuaternion.multiplyToRef(n._deltaRotation,n.object.rotationQuaternion),n.object.translate(n._deltaPosition,1))},this.onCollideEvent=null,this.onCollide=function(e){if((n._onPhysicsCollideCallbacks.length||n.onCollideEvent)&&n._physicsEngine){var t=n._physicsEngine.getImpostorWithPhysicsBody(e.body);t&&(n.onCollideEvent&&n.onCollideEvent(n,t),n._onPhysicsCollideCallbacks.filter(function(e){return-1!==e.otherImpostors.indexOf(t)}).forEach(function(e){e.callback(n,t)}))}},this.object?(!this._scene&&e.getScene&&(this._scene=e.getScene()),this._scene&&(this._physicsEngine=this._scene.getPhysicsEngine(),this._physicsEngine?(this.object.rotationQuaternion||(this.object.rotation?this.object.rotationQuaternion=wn.Quaternion.RotationYawPitchRoll(this.object.rotation.y,this.object.rotation.x,this.object.rotation.z):this.object.rotationQuaternion=new wn.Quaternion),this._options.mass=void 0===i.mass?0:i.mass,this._options.friction=void 0===i.friction?.2:i.friction,this._options.restitution=void 0===i.restitution?.2:i.restitution,this._joints=[],!this.object.parent||this._options.ignoreParent?this._init():this.object.parent.physicsImpostor&&wn.Tools.Warn("You must affect impostors to children before affecting impostor to parent.")):wn.Tools.Error("Physics not enabled. Please use scene.enablePhysics(...) before creating impostors."))):wn.Tools.Error("No object was provided. A physics object is obligatory")}return Object.defineProperty(e.prototype,"isDisposed",{get:function(){return this._isDisposed},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"mass",{get:function(){return this._physicsEngine?this._physicsEngine.getPhysicsPlugin().getBodyMass(this):0},set:function(e){this.setMass(e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"friction",{get:function(){return this._physicsEngine?this._physicsEngine.getPhysicsPlugin().getBodyFriction(this):0},set:function(e){this._physicsEngine&&this._physicsEngine.getPhysicsPlugin().setBodyFriction(this,e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"restitution",{get:function(){return this._physicsEngine?this._physicsEngine.getPhysicsPlugin().getBodyRestitution(this):0},set:function(e){this._physicsEngine&&this._physicsEngine.getPhysicsPlugin().setBodyRestitution(this,e)},enumerable:!0,configurable:!0}),e.prototype._init=function(){this._physicsEngine&&(this._physicsEngine.removeImpostor(this),this.physicsBody=null,this._parent=this._parent||this._getPhysicsParent(),this._isDisposed||this.parent&&!this._options.ignoreParent||this._physicsEngine.addImpostor(this))},e.prototype._getPhysicsParent=function(){return this.object.parent instanceof wn.AbstractMesh?this.object.parent.physicsImpostor:null},e.prototype.isBodyInitRequired=function(){return this._bodyUpdateRequired||!this._physicsBody&&!this._parent},e.prototype.setScalingUpdated=function(e){this.forceUpdate()},e.prototype.forceUpdate=function(){this._init(),this.parent&&!this._options.ignoreParent&&this.parent.forceUpdate()},Object.defineProperty(e.prototype,"physicsBody",{get:function(){return this._parent&&!this._options.ignoreParent?this._parent.physicsBody:this._physicsBody},set:function(e){this._physicsBody&&this._physicsEngine&&this._physicsEngine.getPhysicsPlugin().removePhysicsBody(this),this._physicsBody=e,this.resetUpdateFlags()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"parent",{get:function(){return!this._options.ignoreParent&&this._parent?this._parent:null},set:function(e){this._parent=e},enumerable:!0,configurable:!0}),e.prototype.resetUpdateFlags=function(){this._bodyUpdateRequired=!1},e.prototype.getObjectExtendSize=function(){if(this.object.getBoundingInfo){var t=this.object.rotationQuaternion;this.object.rotationQuaternion=e.IDENTITY_QUATERNION,this.object.computeWorldMatrix&&this.object.computeWorldMatrix(!0);var i=this.object.getBoundingInfo().boundingBox.extendSizeWorld.scale(2);return this.object.rotationQuaternion=t,this.object.computeWorldMatrix&&this.object.computeWorldMatrix(!0),i}return e.DEFAULT_OBJECT_SIZE},e.prototype.getObjectCenter=function(){return this.object.getBoundingInfo?this.object.getBoundingInfo().boundingBox.centerWorld:this.object.position},e.prototype.getParam=function(e){return this._options[e]},e.prototype.setParam=function(e,t){this._options[e]=t,this._bodyUpdateRequired=!0},e.prototype.setMass=function(e){this.getParam("mass")!==e&&this.setParam("mass",e),this._physicsEngine&&this._physicsEngine.getPhysicsPlugin().setBodyMass(this,e)},e.prototype.getLinearVelocity=function(){return this._physicsEngine?this._physicsEngine.getPhysicsPlugin().getLinearVelocity(this):wn.Vector3.Zero()},e.prototype.setLinearVelocity=function(e){this._physicsEngine&&this._physicsEngine.getPhysicsPlugin().setLinearVelocity(this,e)},e.prototype.getAngularVelocity=function(){return this._physicsEngine?this._physicsEngine.getPhysicsPlugin().getAngularVelocity(this):wn.Vector3.Zero()},e.prototype.setAngularVelocity=function(e){this._physicsEngine&&this._physicsEngine.getPhysicsPlugin().setAngularVelocity(this,e)},e.prototype.executeNativeFunction=function(e){this._physicsEngine&&e(this._physicsEngine.getPhysicsPlugin().world,this.physicsBody)},e.prototype.registerBeforePhysicsStep=function(e){this._onBeforePhysicsStepCallbacks.push(e)},e.prototype.unregisterBeforePhysicsStep=function(e){var t=this._onBeforePhysicsStepCallbacks.indexOf(e);t>-1?this._onBeforePhysicsStepCallbacks.splice(t,1):wn.Tools.Warn("Function to remove was not found")},e.prototype.registerAfterPhysicsStep=function(e){this._onAfterPhysicsStepCallbacks.push(e)},e.prototype.unregisterAfterPhysicsStep=function(e){var t=this._onAfterPhysicsStepCallbacks.indexOf(e);t>-1?this._onAfterPhysicsStepCallbacks.splice(t,1):wn.Tools.Warn("Function to remove was not found")},e.prototype.registerOnPhysicsCollide=function(e,t){var i=e instanceof Array?e:[e];this._onPhysicsCollideCallbacks.push({callback:t,otherImpostors:i})},e.prototype.unregisterOnPhysicsCollide=function(e,t){var i=e instanceof Array?e:[e],r=this._onPhysicsCollideCallbacks.indexOf({callback:t,otherImpostors:i});r>-1?this._onPhysicsCollideCallbacks.splice(r,1):wn.Tools.Warn("Function to remove was not found")},e.prototype.getParentsRotation=function(){var e=this.object.parent;for(this._tmpQuat.copyFromFloats(0,0,0,1);e;)e.rotationQuaternion?this._tmpQuat2.copyFrom(e.rotationQuaternion):wn.Quaternion.RotationYawPitchRollToRef(e.rotation.y,e.rotation.x,e.rotation.z,this._tmpQuat2),this._tmpQuat.multiplyToRef(this._tmpQuat2,this._tmpQuat),e=e.parent;return this._tmpQuat},e.prototype.applyForce=function(e,t){return this._physicsEngine&&this._physicsEngine.getPhysicsPlugin().applyForce(this,e,t),this},e.prototype.applyImpulse=function(e,t){return this._physicsEngine&&this._physicsEngine.getPhysicsPlugin().applyImpulse(this,e,t),this},e.prototype.createJoint=function(e,t,i){var r=new wn.PhysicsJoint(t,i);return this.addJoint(e,r),this},e.prototype.addJoint=function(e,t){return this._joints.push({otherImpostor:e,joint:t}),this._physicsEngine&&this._physicsEngine.addJoint(this,e,t),this},e.prototype.sleep=function(){return this._physicsEngine&&this._physicsEngine.getPhysicsPlugin().sleepBody(this),this},e.prototype.wakeUp=function(){return this._physicsEngine&&this._physicsEngine.getPhysicsPlugin().wakeUpBody(this),this},e.prototype.clone=function(t){return t?new e(t,this.type,this._options,this._scene):null},e.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)},e.prototype.setDeltaPosition=function(e){this._deltaPosition.copyFrom(e)},e.prototype.setDeltaRotation=function(e){this._deltaRotation||(this._deltaRotation=new wn.Quaternion),this._deltaRotation.copyFrom(e),this._deltaRotationConjugated=this._deltaRotation.conjugate()},e.prototype.getBoxSizeToRef=function(e){return this._physicsEngine&&this._physicsEngine.getPhysicsPlugin().getBoxSizeToRef(this,e),this},e.prototype.getRadius=function(){return this._physicsEngine?this._physicsEngine.getPhysicsPlugin().getRadius(this):0},e.prototype.syncBoneWithImpostor=function(t,i,r,n,o){var s=e._tmpVecs[0],a=this.object;if(a.rotationQuaternion)if(o){var h=e._tmpQuat;a.rotationQuaternion.multiplyToRef(o,h),t.setRotationQuaternion(h,wn.Space.WORLD,i)}else t.setRotationQuaternion(a.rotationQuaternion,wn.Space.WORLD,i);s.x=0,s.y=0,s.z=0,r&&(s.x=r.x,s.y=r.y,s.z=r.z,t.getDirectionToRef(s,i,s),void 0!==n&&null!==n||(n=r.length()),s.x*=n,s.y*=n,s.z*=n),t.getParent()?(s.addInPlace(a.getAbsolutePosition()),t.setAbsolutePosition(s,i)):(i.setAbsolutePosition(a.getAbsolutePosition()),i.position.x-=s.x,i.position.y-=s.y,i.position.z-=s.z)},e.prototype.syncImpostorWithBone=function(t,i,r,n,o,s){var a=this.object;if(a.rotationQuaternion)if(o){var h=e._tmpQuat;t.getRotationQuaternionToRef(wn.Space.WORLD,i,h),h.multiplyToRef(o,a.rotationQuaternion)}else t.getRotationQuaternionToRef(wn.Space.WORLD,i,a.rotationQuaternion);var l=e._tmpVecs[0],c=e._tmpVecs[1];s||((s=e._tmpVecs[2]).x=0,s.y=1,s.z=0),t.getDirectionToRef(s,i,c),t.getAbsolutePositionToRef(i,l),void 0!==n&&null!==n||!r||(n=r.length()),void 0!==n&&null!==n&&(l.x+=c.x*n,l.y+=c.y*n,l.z+=c.z*n),a.setAbsolutePosition(l)},e.DEFAULT_OBJECT_SIZE=new wn.Vector3(1,1,1),e.IDENTITY_QUATERNION=wn.Quaternion.Identity(),e._tmpVecs=[wn.Vector3.Zero(),wn.Vector3.Zero(),wn.Vector3.Zero()],e._tmpQuat=wn.Quaternion.Identity(),e.NoImpostor=0,e.SphereImpostor=1,e.BoxImpostor=2,e.PlaneImpostor=3,e.MeshImpostor=4,e.CylinderImpostor=7,e.ParticleImpostor=8,e.HeightmapImpostor=9,e}(),wn.PhysicsImpostor=Dn,Ln=us||(us={}),Bn=function(){function e(e,t){if(void 0===t&&(t=new Ln.CannonJSPlugin),this._physicsPlugin=t,this._impostors=[],this._joints=[],!this._physicsPlugin.isSupported())throw new Error("Physics Engine "+this._physicsPlugin.name+" cannot be found. Please make sure it is included.");e=e||new Ln.Vector3(0,-9.807,0),this.setGravity(e),this.setTimeStep()}return e.prototype.setGravity=function(e){this.gravity=e,this._physicsPlugin.setGravity(this.gravity)},e.prototype.setTimeStep=function(e){void 0===e&&(e=1/60),this._physicsPlugin.setTimeStep(e)},e.prototype.getTimeStep=function(){return this._physicsPlugin.getTimeStep()},e.prototype.dispose=function(){this._impostors.forEach(function(e){e.dispose()}),this._physicsPlugin.dispose()},e.prototype.getPhysicsPluginName=function(){return this._physicsPlugin.name},e.prototype.addImpostor=function(e){e.uniqueId=this._impostors.push(e),e.parent||this._physicsPlugin.generatePhysicsBody(e)},e.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)}},e.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)},e.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])},e.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)},e.prototype.getPhysicsPlugin=function(){return this._physicsPlugin},e.prototype.getImpostors=function(){return this._impostors},e.prototype.getImpostorForPhysicsObject=function(e){for(var t=0;t<this._impostors.length;++t)if(this._impostors[t].object===e)return this._impostors[t];return null},e.prototype.getImpostorWithPhysicsBody=function(e){for(var t=0;t<this._impostors.length;++t)if(this._impostors[t].physicsBody===e)return this._impostors[t];return null},e.Epsilon=.001,e}(),Ln.PhysicsEngine=Bn,function(e){var t=function(){function t(t){this._scene=t,this._physicsEngine=this._scene.getPhysicsEngine(),this._physicsEngine||e.Tools.Warn("Physics engine not enabled. Please enable the physics before you can use the methods.")}return t.prototype.applyRadialExplosionImpulse=function(t,r,n,s){if(void 0===s&&(s=o.Constant),!this._physicsEngine)return e.Tools.Warn("Physics engine not enabled. Please enable the physics before you call this method."),null;var a=this._physicsEngine.getImpostors();if(0===a.length)return null;var h=new i(this._scene);return a.forEach(function(e){var i=h.getImpostorForceAndContactPoint(e,t,r,n,s);i&&e.applyImpulse(i.force,i.contactPoint)}),h.dispose(!1),h},t.prototype.applyRadialExplosionForce=function(t,r,n,s){if(void 0===s&&(s=o.Constant),!this._physicsEngine)return e.Tools.Warn("Physics engine not enabled. Please enable the physics before you call the PhysicsHelper."),null;var a=this._physicsEngine.getImpostors();if(0===a.length)return null;var h=new i(this._scene);return a.forEach(function(e){var i=h.getImpostorForceAndContactPoint(e,t,r,n,s);i&&e.applyForce(i.force,i.contactPoint)}),h.dispose(!1),h},t.prototype.gravitationalField=function(t,i,n,s){if(void 0===s&&(s=o.Constant),!this._physicsEngine)return e.Tools.Warn("Physics engine not enabled. Please enable the physics before you call the PhysicsHelper."),null;if(0===this._physicsEngine.getImpostors().length)return null;var a=new r(this,this._scene,t,i,n,s);return a.dispose(!1),a},t.prototype.updraft=function(t,i,r,o,s){if(void 0===s&&(s=a.Center),!this._physicsEngine)return e.Tools.Warn("Physics engine not enabled. Please enable the physics before you call the PhysicsHelper."),null;if(0===this._physicsEngine.getImpostors().length)return null;var h=new n(this._scene,t,i,r,o,s);return h.dispose(!1),h},t.prototype.vortex=function(t,i,r,n){if(!this._physicsEngine)return e.Tools.Warn("Physics engine not enabled. Please enable the physics before you call the PhysicsHelper."),null;if(0===this._physicsEngine.getImpostors().length)return null;var o=new l(this._scene,t,i,r,n);return o.dispose(!1),o},t}();e.PhysicsHelper=t;var i=function(){function t(e){this._sphereOptions={segments:32,diameter:1},this._rays=[],this._dataFetched=!1,this._scene=e}return t.prototype.getData=function(){return this._dataFetched=!0,{sphere:this._sphere,rays:this._rays}},t.prototype.getImpostorForceAndContactPoint=function(t,i,r,n,s){if(0===t.mass)return null;if(!this._intersectsWithSphere(t,i,r))return null;if("Mesh"!==t.object.getClassName())return null;var a=t.object,h=t.getObjectCenter().subtract(i),l=new e.Ray(i,h,r);this._rays.push(l);var c=l.intersectsMesh(a).pickedPoint;if(!c)return null;var u=e.Vector3.Distance(i,c);if(u>r)return null;var p=s===o.Constant?n:n*(1-u/r);return{force:h.multiplyByFloats(p,p,p),contactPoint:c}},t.prototype.dispose=function(e){var t=this;void 0===e&&(e=!0),e?this._sphere.dispose():setTimeout(function(){t._dataFetched||t._sphere.dispose()},0)},t.prototype._prepareSphere=function(){this._sphere||(this._sphere=e.MeshBuilder.CreateSphere("radialExplosionEventSphere",this._sphereOptions,this._scene),this._sphere.isVisible=!1)},t.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)},t}();e.PhysicsRadialExplosionEvent=i;var r=function(){function e(e,t,i,r,n,s){void 0===s&&(s=o.Constant),this._dataFetched=!1,this._physicsHelper=e,this._scene=t,this._origin=i,this._radius=r,this._strength=n,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=r;var n=function(){function t(t,i,r,n,o,s){this._scene=t,this._origin=i,this._radius=r,this._strength=n,this._height=o,this._updraftMode=s,this._originTop=e.Vector3.Zero(),this._originDirection=e.Vector3.Zero(),this._cylinderPosition=e.Vector3.Zero(),this._dataFetched=!1,this._physicsEngine=this._scene.getPhysicsEngine(),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===a.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===a.Perpendicular)var i=this._originDirection;else i=t.subtract(this._originTop);var r=-1*this._strength;return{force:i.multiplyByFloats(r,r,r),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=n;var o,s,a,h,l=function(){function t(t,i,r,n,o){this._scene=t,this._origin=i,this._radius=r,this._strength=n,this._height=o,this._originTop=e.Vector3.Zero(),this._centripetalForceThreshold=.7,this._updraftMultiplier=.02,this._cylinderPosition=e.Vector3.Zero(),this._dataFetched=!1,this._physicsEngine=this._scene.getPhysicsEngine(),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._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(t){if(0===t.mass)return null;if(!this._intersectsWithCylinder(t))return null;if("Mesh"!==t.object.getClassName())return null;var i=t.object,r=t.getObjectCenter(),n=new e.Vector3(this._origin.x,r.y,this._origin.z),o=r.subtract(n),s=new e.Ray(n,o,this._radius).intersectsMesh(i),a=s.pickedPoint;if(!a)return null;var h=s.distance/this._radius,l=e.Vector3.Cross(n,r).normalize(),c=a.normalize();if(h>this._centripetalForceThreshold&&(c=c.negate()),h>this._centripetalForceThreshold)var u=c.x*this._strength/8,p=c.y*this._updraftMultiplier,f=c.z*this._strength/8;else u=(l.x+c.x)/2,p=this._originTop.y*this._updraftMultiplier,f=(l.z+c.z)/2;var d=new e.Vector3(u,p,f);return{force:d=d.multiplyByFloats(this._strength,this._strength,this._strength),contactPoint:r}},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("vortexEventCylinder",{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.PhysicsVortexEvent=l,(s=o=e.PhysicsRadialImpulseFalloff||(e.PhysicsRadialImpulseFalloff={}))[s.Constant=0]="Constant",s[s.Linear=1]="Linear",(h=a=e.PhysicsUpdraftMode||(e.PhysicsUpdraftMode={}))[h.Center=0]="Center",h[h.Perpendicular=1]="Perpendicular"}(us||(us={})),Nn=us||(us={}),Fn=function(){function e(e,t){void 0===e&&(e=!0),void 0===t&&(t=10),this._useDeltaForWorldStep=e,this.name="CannonJSPlugin",this._physicsMaterials=new Array,this._fixedTimeStep=1/60,this.BJSCANNON="undefined"!=typeof CANNON?CANNON:i(15),this._minus90X=new Nn.Quaternion(-.7071067811865475,0,0,.7071067811865475),this._plus90X=new Nn.Quaternion(.7071067811865475,0,0,.7071067811865475),this._tmpPosition=Nn.Vector3.Zero(),this._tmpDeltaPosition=Nn.Vector3.Zero(),this._tmpUnityRotation=new Nn.Quaternion,this.isSupported()?(this._extendNamespace(),this.world=new this.BJSCANNON.World,this.world.broadphase=new this.BJSCANNON.NaiveBroadphase,this.world.solver.iterations=t):Nn.Tools.Error("CannonJS is not available. Please make sure you included the js file.")}return e.prototype.setGravity=function(e){this.world.gravity.copy(e)},e.prototype.setTimeStep=function(e){this._fixedTimeStep=e},e.prototype.getTimeStep=function(){return this._fixedTimeStep},e.prototype.executeStep=function(e,t){this.world.step(this._fixedTimeStep,this._useDeltaForWorldStep?e:0,3)},e.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)},e.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)},e.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)}},e.prototype._processChildMeshes=function(e){var t=this,i=e.object.getChildMeshes?e.object.getChildMeshes(!0):[],r=e.object.rotationQuaternion;if(i.length){var n=function(i,o){if(r&&o.rotationQuaternion){var s=o.getPhysicsImpostor();if(s)if(s.parent!==e){var a=o.getAbsolutePosition().subtract(e.object.getAbsolutePosition()),h=o.rotationQuaternion.multiply(Nn.Quaternion.Inverse(r));s.physicsBody&&(t.removePhysicsBody(s),s.physicsBody=null),s.parent=e,s.resetUpdateFlags(),e.physicsBody.addShape(t._createShape(s),new t.BJSCANNON.Vec3(a.x,a.y,a.z),new t.BJSCANNON.Quaternion(h.x,h.y,h.z,h.w)),e.physicsBody.mass+=s.getParam("mass")}r.multiplyInPlace(o.rotationQuaternion),o.getChildMeshes(!0).filter(function(e){return!!e.physicsImpostor}).forEach(n.bind(t,o.getAbsolutePosition()))}};i.filter(function(e){return!!e.physicsImpostor}).forEach(n.bind(this,e.object.getAbsolutePosition()))}},e.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)},e.prototype.generateJoint=function(e){var t=e.mainImpostor.physicsBody,i=e.connectedImpostor.physicsBody;if(t&&i){var r,n=e.joint.jointData,o={pivotA:n.mainPivot?(new this.BJSCANNON.Vec3).copy(n.mainPivot):null,pivotB:n.connectedPivot?(new this.BJSCANNON.Vec3).copy(n.connectedPivot):null,axisA:n.mainAxis?(new this.BJSCANNON.Vec3).copy(n.mainAxis):null,axisB:n.connectedAxis?(new this.BJSCANNON.Vec3).copy(n.connectedAxis):null,maxForce:n.nativeParams.maxForce,collideConnected:!!n.collision};switch(e.joint.type){case Nn.PhysicsJoint.HingeJoint:case Nn.PhysicsJoint.Hinge2Joint:r=new this.BJSCANNON.HingeConstraint(t,i,o);break;case Nn.PhysicsJoint.DistanceJoint:r=new this.BJSCANNON.DistanceConstraint(t,i,n.maxDistance||2);break;case Nn.PhysicsJoint.SpringJoint:var s=n;r=new this.BJSCANNON.Spring(t,i,{restLength:s.length,stiffness:s.stiffness,damping:s.damping,localAnchorA:o.pivotA,localAnchorB:o.pivotB});break;case Nn.PhysicsJoint.LockJoint:r=new this.BJSCANNON.LockConstraint(t,i,o);break;case Nn.PhysicsJoint.PointToPointJoint:case Nn.PhysicsJoint.BallAndSocketJoint:default:r=new this.BJSCANNON.PointToPointConstraint(t,o.pivotA,i,o.pivotA,o.maxForce)}r.collideConnected=!!n.collision,e.joint.physicsJoint=r,e.joint.type!==Nn.PhysicsJoint.SpringJoint?this.world.addConstraint(r):e.mainImpostor.registerAfterPhysicsStep(function(){r.applyForce()})}},e.prototype.removeJoint=function(e){this.world.removeConstraint(e.joint.physicsJoint)},e.prototype._addMaterial=function(e,t,i){var r,n;for(r=0;r<this._physicsMaterials.length;r++)if((n=this._physicsMaterials[r]).friction===t&&n.restitution===i)return n;var o=new this.BJSCANNON.Material(e);return o.friction=t,o.restitution=i,this._physicsMaterials.push(o),o},e.prototype._checkWithEpsilon=function(e){return e<Nn.PhysicsEngine.Epsilon?Nn.PhysicsEngine.Epsilon:e},e.prototype._createShape=function(e){var t,i=e.object,r=e.getObjectExtendSize();switch(e.type){case Nn.PhysicsImpostor.SphereImpostor:var n=r.x,o=r.y,s=r.z;t=new this.BJSCANNON.Sphere(Math.max(this._checkWithEpsilon(n),this._checkWithEpsilon(o),this._checkWithEpsilon(s))/2);break;case Nn.PhysicsImpostor.CylinderImpostor:t=new this.BJSCANNON.Cylinder(this._checkWithEpsilon(r.x)/2,this._checkWithEpsilon(r.x)/2,this._checkWithEpsilon(r.y),16);break;case Nn.PhysicsImpostor.BoxImpostor:var a=r.scale(.5);t=new this.BJSCANNON.Box(new this.BJSCANNON.Vec3(this._checkWithEpsilon(a.x),this._checkWithEpsilon(a.y),this._checkWithEpsilon(a.z)));break;case Nn.PhysicsImpostor.PlaneImpostor:Nn.Tools.Warn("Attention, PlaneImposter might not behave as you expect. Consider using BoxImposter instead"),t=new this.BJSCANNON.Plane;break;case Nn.PhysicsImpostor.MeshImpostor:var h=i.getVerticesData?i.getVerticesData(Nn.VertexBuffer.PositionKind):[],l=i.getIndices?i.getIndices():[];if(!h)return;var c=i.position.clone(),u=i.rotation&&i.rotation.clone(),p=i.rotationQuaternion&&i.rotationQuaternion.clone();i.position.copyFromFloats(0,0,0),i.rotation&&i.rotation.copyFromFloats(0,0,0),i.rotationQuaternion&&i.rotationQuaternion.copyFrom(e.getParentsRotation()),i.rotationQuaternion&&i.parent&&i.rotationQuaternion.conjugateInPlace();var f,d=i.computeWorldMatrix(!0),m=new Array;for(f=0;f<h.length;f+=3)Nn.Vector3.TransformCoordinates(Nn.Vector3.FromArray(h,f),d).toArray(m,f);Nn.Tools.Warn("MeshImpostor only collides against spheres."),t=new this.BJSCANNON.Trimesh(m,l),i.position.copyFrom(c),u&&i.rotation&&i.rotation.copyFrom(u),p&&i.rotationQuaternion&&i.rotationQuaternion.copyFrom(p);break;case Nn.PhysicsImpostor.HeightmapImpostor:var g=i.position.clone(),_=i.rotation&&i.rotation.clone(),v=i.rotationQuaternion&&i.rotationQuaternion.clone();i.position.copyFromFloats(0,0,0),i.rotation&&i.rotation.copyFromFloats(0,0,0),i.rotationQuaternion&&i.rotationQuaternion.copyFrom(e.getParentsRotation()),i.rotationQuaternion&&i.parent&&i.rotationQuaternion.conjugateInPlace(),i.rotationQuaternion&&i.rotationQuaternion.multiplyInPlace(this._minus90X),t=this._createHeightmap(i),i.position.copyFrom(g),_&&i.rotation&&i.rotation.copyFrom(_),v&&i.rotationQuaternion&&i.rotationQuaternion.copyFrom(v),i.computeWorldMatrix(!0);break;case Nn.PhysicsImpostor.ParticleImpostor:t=new this.BJSCANNON.Particle}return t},e.prototype._createHeightmap=function(e,t){var i,r=e.getVerticesData(Nn.VertexBuffer.PositionKind),n=e.computeWorldMatrix(!0),o=new Array;for(i=0;i<r.length;i+=3)Nn.Vector3.TransformCoordinates(Nn.Vector3.FromArray(r,i),n).toArray(o,i);r=o;for(var s=new Array,a=t||~~(Math.sqrt(r.length/3)-1),h=e.getBoundingInfo(),l=Math.min(h.boundingBox.extendSizeWorld.x,h.boundingBox.extendSizeWorld.y),c=h.boundingBox.extendSizeWorld.z,u=2*l/a,p=0;p<r.length;p+=3){var f=Math.round(r[p+0]/u+a/2),d=Math.round(-1*(r[p+1]/u-a/2)),m=-r[p+2]+c;s[f]||(s[f]=[]),s[f][d]||(s[f][d]=m),s[f][d]=Math.max(m,s[f][d])}for(f=0;f<=a;++f){if(!s[f]){for(var g=1;!s[(f+g)%a];)g++;s[f]=s[(f+g)%a].slice()}for(d=0;d<=a;++d)if(!s[f][d]){var _;for(g=1;void 0===_;)_=s[f][(d+g++)%a];s[f][d]=_}}var v=new this.BJSCANNON.Heightfield(s,{elementSize:u});return v.minY=c,v},e.prototype._updatePhysicsBodyTransformation=function(e){var t=e.object;if(t.computeWorldMatrix&&t.computeWorldMatrix(!0),t.getBoundingInfo()){var i=e.getObjectCenter();this._tmpDeltaPosition.copyFrom(t.getAbsolutePivotPoint().subtract(i)),this._tmpDeltaPosition.divideInPlace(e.object.scaling),this._tmpPosition.copyFrom(i);var r=t.rotationQuaternion;if(r){if(e.type!==Nn.PhysicsImpostor.PlaneImpostor&&e.type!==Nn.PhysicsImpostor.HeightmapImpostor&&e.type!==Nn.PhysicsImpostor.CylinderImpostor||(r=r.multiply(this._minus90X),e.setDeltaRotation(this._plus90X)),e.type===Nn.PhysicsImpostor.HeightmapImpostor){var n=t,o=n.getBoundingInfo(),s=n.rotationQuaternion;n.rotationQuaternion=this._tmpUnityRotation,n.computeWorldMatrix(!0);var a=i.clone(),h=n.getPivotMatrix()||Nn.Matrix.Translation(0,0,0),l=Nn.Matrix.Translation(o.boundingBox.extendSizeWorld.x,0,-o.boundingBox.extendSizeWorld.z);n.setPivotMatrix(l),n.computeWorldMatrix(!0);var c=o.boundingBox.centerWorld.subtract(i).subtract(n.position).negate();this._tmpPosition.copyFromFloats(c.x,c.y-o.boundingBox.extendSizeWorld.y,c.z),this._tmpDeltaPosition.copyFrom(o.boundingBox.centerWorld.subtract(a)),this._tmpDeltaPosition.y+=o.boundingBox.extendSizeWorld.y,n.rotationQuaternion=s,n.setPivotMatrix(h),n.computeWorldMatrix(!0)}else e.type===Nn.PhysicsImpostor.MeshImpostor&&this._tmpDeltaPosition.copyFromFloats(0,0,0);e.setDeltaPosition(this._tmpDeltaPosition),e.physicsBody.position.copy(this._tmpPosition),e.physicsBody.quaternion.copy(r)}}},e.prototype.setTransformationFromPhysicsBody=function(e){e.object.position.copyFrom(e.physicsBody.position),e.object.rotationQuaternion&&e.object.rotationQuaternion.copyFrom(e.physicsBody.quaternion)},e.prototype.setPhysicsBodyTransformation=function(e,t,i){e.physicsBody.position.copy(t),e.physicsBody.quaternion.copy(i)},e.prototype.isSupported=function(){return void 0!==this.BJSCANNON},e.prototype.setLinearVelocity=function(e,t){e.physicsBody.velocity.copy(t)},e.prototype.setAngularVelocity=function(e,t){e.physicsBody.angularVelocity.copy(t)},e.prototype.getLinearVelocity=function(e){var t=e.physicsBody.velocity;return t?new Nn.Vector3(t.x,t.y,t.z):null},e.prototype.getAngularVelocity=function(e){var t=e.physicsBody.angularVelocity;return t?new Nn.Vector3(t.x,t.y,t.z):null},e.prototype.setBodyMass=function(e,t){e.physicsBody.mass=t,e.physicsBody.updateMassProperties()},e.prototype.getBodyMass=function(e){return e.physicsBody.mass},e.prototype.getBodyFriction=function(e){return e.physicsBody.material.friction},e.prototype.setBodyFriction=function(e,t){e.physicsBody.material.friction=t},e.prototype.getBodyRestitution=function(e){return e.physicsBody.material.restitution},e.prototype.setBodyRestitution=function(e,t){e.physicsBody.material.restitution=t},e.prototype.sleepBody=function(e){e.physicsBody.sleep()},e.prototype.wakeUpBody=function(e){e.physicsBody.wakeUp()},e.prototype.updateDistanceJoint=function(e,t,i){e.physicsJoint.distance=t},e.prototype.setMotor=function(e,t,i,r){r||(e.physicsJoint.enableMotor(),e.physicsJoint.setMotorSpeed(t),i&&this.setLimit(e,i))},e.prototype.setLimit=function(e,t,i){e.physicsJoint.motorEquation.maxForce=t,e.physicsJoint.motorEquation.minForce=void 0===i?-t:i},e.prototype.syncMeshWithImpostor=function(e,t){var i=t.physicsBody;e.position.x=i.position.x,e.position.y=i.position.y,e.position.z=i.position.z,e.rotationQuaternion&&(e.rotationQuaternion.x=i.quaternion.x,e.rotationQuaternion.y=i.quaternion.y,e.rotationQuaternion.z=i.quaternion.z,e.rotationQuaternion.w=i.quaternion.w)},e.prototype.getRadius=function(e){return e.physicsBody.shapes[0].boundingSphereRadius},e.prototype.getBoxSizeToRef=function(e,t){var i=e.physicsBody.shapes[0];t.x=2*i.halfExtents.x,t.y=2*i.halfExtents.y,t.z=2*i.halfExtents.z},e.prototype.dispose=function(){},e.prototype._extendNamespace=function(){var e=new this.BJSCANNON.Vec3,t=this.BJSCANNON;this.BJSCANNON.World.prototype.step=function(i,r,n){if(n=n||10,0===(r=r||0))this.internalStep(i),this.time+=i;else{var o=Math.floor((this.time+r)/i)-Math.floor(this.time/i);o=Math.min(o,n)||1;for(var s=performance.now(),a=0;a!==o&&(this.internalStep(i),!(performance.now()-s>1e3*i));a++);this.time+=r;for(var h=this.time%i/i,l=e,c=this.bodies,u=0;u!==c.length;u++){var p=c[u];p.type!==t.Body.STATIC&&p.sleepState!==t.Body.SLEEPING?(p.position.vsub(p.previousPosition,l),l.scale(h,l),p.position.vadd(l,p.interpolatedPosition)):(p.interpolatedPosition.copy(p.position),p.interpolatedQuaternion.copy(p.quaternion))}}}},e}(),Nn.CannonJSPlugin=Fn,Vn=us||(us={}),kn=function(){function e(e){this.name="OimoJSPlugin",this._tmpImpostorsArray=[],this._tmpPositionVector=Vn.Vector3.Zero(),this.BJSOIMO="undefined"!=typeof OIMO?OIMO:i(16),this.world=new this.BJSOIMO.World(1/60,2,e,!0),this.world.worldscale(1),this.world.clear(),this.world.isNoStat=!0}return e.prototype.setGravity=function(e){this.world.gravity.copy(e)},e.prototype.setTimeStep=function(e){this.world.timeStep=e},e.prototype.getTimeStep=function(){return this.world.timeStep},e.prototype.executeStep=function(e,t){var i=this;t.forEach(function(e){e.beforeStep()}),this.world.step(),t.forEach(function(e){e.afterStep(),i._tmpImpostorsArray[e.uniqueId]=e});for(var r=this.world.contacts;null!==r;)if(!r.touching||r.body1.sleeping||r.body2.sleeping){var n=this._tmpImpostorsArray[+r.body1.name],o=this._tmpImpostorsArray[+r.body2.name];n&&o?(n.onCollide({body:o.physicsBody}),o.onCollide({body:n.physicsBody}),r=r.next):r=r.next}else r=r.next},e.prototype.applyImpulse=function(e,t,i){var r=e.physicsBody.massInfo.mass;e.physicsBody.applyImpulse(i.scale(this.BJSOIMO.INV_SCALE),t.scale(this.BJSOIMO.INV_SCALE*r))},e.prototype.applyForce=function(e,t,i){Vn.Tools.Warn("Oimo doesn't support applying force. Using impule instead."),this.applyImpulse(e,t,i)},e.prototype.generatePhysicsBody=function(e){var t=this;if(e.parent)e.physicsBody&&(this.removePhysicsBody(e),e.forceUpdate());else{if(e.isBodyInitRequired()){var i={name:e.uniqueId,config:[e.getParam("mass")||1,e.getParam("friction"),e.getParam("restitution")],size:[],type:[],pos:[],rot:[],move:0!==e.getParam("mass"),world:this.world},r=[e];(o=e.object).getChildMeshes&&o.getChildMeshes().forEach(function(e){e.physicsImpostor&&r.push(e.physicsImpostor)});var n=function(e){return Math.max(e,Vn.PhysicsEngine.Epsilon)};r.forEach(function(r){if(e.object.rotationQuaternion){var o=r.object.rotationQuaternion,s=(new t.BJSOIMO.Euler).setFromQuaternion({x:e.object.rotationQuaternion.x,y:e.object.rotationQuaternion.y,z:e.object.rotationQuaternion.z,s:e.object.rotationQuaternion.w}),a=r.getObjectExtendSize();if(r===e){var h=e.getObjectCenter();e.object.getAbsolutePivotPoint().subtractToRef(h,t._tmpPositionVector),t._tmpPositionVector.divideInPlace(e.object.scaling),i.pos.push(h.x),i.pos.push(h.y),i.pos.push(h.z),i.rot.push(s.x/(t.BJSOIMO.degtorad||t.BJSOIMO.TO_RAD)),i.rot.push(s.y/(t.BJSOIMO.degtorad||t.BJSOIMO.TO_RAD)),i.rot.push(s.z/(t.BJSOIMO.degtorad||t.BJSOIMO.TO_RAD))}else{var l=r.object.getAbsolutePosition().subtract(e.object.getAbsolutePosition());i.pos.push(l.x),i.pos.push(l.y),i.pos.push(l.z),i.rot.push(0),i.rot.push(0),i.rot.push(0)}switch(r.type){case Vn.PhysicsImpostor.ParticleImpostor:Vn.Tools.Warn("No Particle support in this.BJSOIMO.js. using SphereImpostor instead");case Vn.PhysicsImpostor.SphereImpostor:var c=a.x,u=a.y,p=a.z,f=Math.max(n(c),n(u),n(p))/2;i.type.push("sphere"),i.size.push(f),i.size.push(f),i.size.push(f);break;case Vn.PhysicsImpostor.CylinderImpostor:var d=n(a.x)/2,m=n(a.y);i.type.push("cylinder"),i.size.push(d),i.size.push(m),i.size.push(m);break;case Vn.PhysicsImpostor.PlaneImpostor:case Vn.PhysicsImpostor.BoxImpostor:default:d=n(a.x),m=n(a.y);var g=n(a.z);i.type.push("box"),i.size.push(d),i.size.push(m),i.size.push(g)}r.object.rotationQuaternion=o}}),e.physicsBody=new this.BJSOIMO.Body(i).body}else this._tmpPositionVector.copyFromFloats(0,0,0);var o;e.setDeltaPosition(this._tmpPositionVector)}},e.prototype.removePhysicsBody=function(e){this.world.removeRigidBody(e.physicsBody)},e.prototype.generateJoint=function(e){var t=e.mainImpostor.physicsBody,i=e.connectedImpostor.physicsBody;if(t&&i){var r,n=e.joint.jointData,o=n.nativeParams||{},s={body1:t,body2:i,axe1:o.axe1||(n.mainAxis?n.mainAxis.asArray():null),axe2:o.axe2||(n.connectedAxis?n.connectedAxis.asArray():null),pos1:o.pos1||(n.mainPivot?n.mainPivot.asArray():null),pos2:o.pos2||(n.connectedPivot?n.connectedPivot.asArray():null),min:o.min,max:o.max,collision:o.collision||n.collision,spring:o.spring,world:this.world};switch(e.joint.type){case Vn.PhysicsJoint.BallAndSocketJoint:r="jointBall";break;case Vn.PhysicsJoint.SpringJoint:Vn.Tools.Warn("this.BJSOIMO.js doesn't support Spring Constraint. Simulating using DistanceJoint instead");var a=n;s.min=a.length||s.min,s.max=Math.max(s.min,s.max);case Vn.PhysicsJoint.DistanceJoint:r="jointDistance",s.max=n.maxDistance;break;case Vn.PhysicsJoint.PrismaticJoint:r="jointPrisme";break;case Vn.PhysicsJoint.SliderJoint:r="jointSlide";break;case Vn.PhysicsJoint.WheelJoint:r="jointWheel";break;case Vn.PhysicsJoint.HingeJoint:default:r="jointHinge"}s.type=r,e.joint.physicsJoint=new this.BJSOIMO.Link(s).joint}},e.prototype.removeJoint=function(e){try{this.world.removeJoint(e.joint.physicsJoint)}catch(e){Vn.Tools.Warn(e)}},e.prototype.isSupported=function(){return void 0!==this.BJSOIMO},e.prototype.setTransformationFromPhysicsBody=function(e){if(!e.physicsBody.sleeping){if(e.physicsBody.shapes.next){var t=this._getLastShape(e.physicsBody);e.object.position.x=t.position.x*this.BJSOIMO.WORLD_SCALE,e.object.position.y=t.position.y*this.BJSOIMO.WORLD_SCALE,e.object.position.z=t.position.z*this.BJSOIMO.WORLD_SCALE}else e.object.position.copyFrom(e.physicsBody.getPosition());e.object.rotationQuaternion&&(e.object.rotationQuaternion.copyFrom(e.physicsBody.getQuaternion()),e.object.rotationQuaternion.normalize())}},e.prototype.setPhysicsBodyTransformation=function(e,t,i){var r=e.physicsBody;r.position.init(t.x*this.BJSOIMO.INV_SCALE,t.y*this.BJSOIMO.INV_SCALE,t.z*this.BJSOIMO.INV_SCALE),r.orientation.init(i.w,i.x,i.y,i.z),r.syncShapes(),r.awake()},e.prototype._getLastShape=function(e){for(var t=e.shapes;t.next;)t=t.next;return t},e.prototype.setLinearVelocity=function(e,t){e.physicsBody.linearVelocity.init(t.x,t.y,t.z)},e.prototype.setAngularVelocity=function(e,t){e.physicsBody.angularVelocity.init(t.x,t.y,t.z)},e.prototype.getLinearVelocity=function(e){var t=e.physicsBody.linearVelocity;return t?new Vn.Vector3(t.x,t.y,t.z):null},e.prototype.getAngularVelocity=function(e){var t=e.physicsBody.angularVelocity;return t?new Vn.Vector3(t.x,t.y,t.z):null},e.prototype.setBodyMass=function(e,t){var i=0===t;e.physicsBody.shapes.density=i?1:t,e.physicsBody.setupMass(i?2:1)},e.prototype.getBodyMass=function(e){return e.physicsBody.shapes.density},e.prototype.getBodyFriction=function(e){return e.physicsBody.shapes.friction},e.prototype.setBodyFriction=function(e,t){e.physicsBody.shapes.friction=t},e.prototype.getBodyRestitution=function(e){return e.physicsBody.shapes.restitution},e.prototype.setBodyRestitution=function(e,t){e.physicsBody.shapes.restitution=t},e.prototype.sleepBody=function(e){e.physicsBody.sleep()},e.prototype.wakeUpBody=function(e){e.physicsBody.awake()},e.prototype.updateDistanceJoint=function(e,t,i){e.physicsJoint.limitMotor.upperLimit=t,void 0!==i&&(e.physicsJoint.limitMotor.lowerLimit=i)},e.prototype.setMotor=function(e,t,i,r){var n=r?e.physicsJoint.rotationalLimitMotor2:e.physicsJoint.rotationalLimitMotor1||e.physicsJoint.rotationalLimitMotor||e.physicsJoint.limitMotor;n&&n.setMotor(t,i)},e.prototype.setLimit=function(e,t,i,r){var n=r?e.physicsJoint.rotationalLimitMotor2:e.physicsJoint.rotationalLimitMotor1||e.physicsJoint.rotationalLimitMotor||e.physicsJoint.limitMotor;n&&n.setLimit(t,void 0===i?-t:i)},e.prototype.syncMeshWithImpostor=function(e,t){var i=t.physicsBody;e.position.x=i.position.x,e.position.y=i.position.y,e.position.z=i.position.z,e.rotationQuaternion&&(e.rotationQuaternion.x=i.orientation.x,e.rotationQuaternion.y=i.orientation.y,e.rotationQuaternion.z=i.orientation.z,e.rotationQuaternion.w=i.orientation.s)},e.prototype.getRadius=function(e){return e.physicsBody.shapes.radius},e.prototype.getBoxSizeToRef=function(e,t){var i=e.physicsBody.shapes;t.x=2*i.halfWidth,t.y=2*i.halfHeight,t.z=2*i.halfDepth},e.prototype.dispose=function(){this.world.clear()},e}(),Vn.OimoJSPlugin=kn,Un=us||(us={}),zn=function(){function e(){}return e.GetTGAHeader=function(e){var t=0;return{id_length:e[t++],colormap_type:e[t++],image_type:e[t++],colormap_index:e[t++]|e[t++]<<8,colormap_length:e[t++]|e[t++]<<8,colormap_size:e[t++],origin:[e[t++]|e[t++]<<8,e[t++]|e[t++]<<8],width:e[t++]|e[t++]<<8,height:e[t++]|e[t++]<<8,pixel_size:e[t++],flags:e[t++]}},e.UploadContent=function(t,i){if(i.length<19)Un.Tools.Error("Unable to load TGA file - Not enough data to contain header");else{var r=18,n=e.GetTGAHeader(i);if(n.id_length+r>i.length)Un.Tools.Error("Unable to load TGA file - Not enough data");else{r+=n.id_length;var o,s=!1,a=!1,h=!1;switch(n.image_type){case e._TYPE_RLE_INDEXED:s=!0;case e._TYPE_INDEXED:a=!0;break;case e._TYPE_RLE_RGB:s=!0;case e._TYPE_RGB:break;case e._TYPE_RLE_GREY:s=!0;case e._TYPE_GREY:h=!0}var l,c,u,p,f,d,m,g=n.pixel_size>>3,_=n.width*n.height*g;if(a&&(l=i.subarray(r,r+=n.colormap_length*(n.colormap_size>>3))),s){var v,y,b;o=new Uint8Array(_);for(var x=0,T=new Uint8Array(g);r<_&&x<_;)if(y=1+(127&(v=i[r++])),128&v){for(b=0;b<g;++b)T[b]=i[r++];for(b=0;b<y;++b)o.set(T,x+b*g);x+=g*y}else{for(y*=g,b=0;b<y;++b)o[x+b]=i[r++];x+=y}}else o=i.subarray(r,r+=a?n.width*n.height:_);switch((n.flags&e._ORIGIN_MASK)>>e._ORIGIN_SHIFT){default:case e._ORIGIN_UL:c=0,p=1,m=n.width,u=0,f=1,d=n.height;break;case e._ORIGIN_BL:c=0,p=1,m=n.width,u=n.height-1,f=-1,d=-1;break;case e._ORIGIN_UR:c=n.width-1,p=-1,m=-1,u=0,f=1,d=n.height;break;case e._ORIGIN_BR:c=n.width-1,p=-1,m=-1,u=n.height-1,f=-1,d=-1}var E=e["_getImageData"+(h?"Grey":"")+n.pixel_size+"bits"](n,l,o,u,f,d,c,p,m);t.texImage2D(t.TEXTURE_2D,0,t.RGBA,n.width,n.height,0,t.RGBA,t.UNSIGNED_BYTE,E)}}},e._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 _},e._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},e._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},e._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},e._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},e._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},e._TYPE_INDEXED=1,e._TYPE_RGB=2,e._TYPE_GREY=3,e._TYPE_RLE_INDEXED=9,e._TYPE_RLE_RGB=10,e._TYPE_RLE_GREY=11,e._ORIGIN_MASK=48,e._ORIGIN_SHIFT=4,e._ORIGIN_BL=0,e._ORIGIN_BR=1,e._ORIGIN_UL=2,e._ORIGIN_UR=3,e}(),Un.TGATools=zn,function(e){function t(e){return e.charCodeAt(0)+(e.charCodeAt(1)<<8)+(e.charCodeAt(2)<<16)+(e.charCodeAt(3)<<24)}var i=t("DXT1"),r=t("DXT3"),n=t("DXT5"),o=t("DX10"),s=function(){function t(){}return t.GetDDSInfo=function(t){var s=new Int32Array(t,0,31),a=new Int32Array(t,0,35),h=1;131072&s[2]&&(h=Math.max(1,s[7]));var l=s[21],c=l===o?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 o:if(10===c){u=e.Engine.TEXTURETYPE_HALF_FLOAT;break}}return{width:s[4],height:s[3],mipmapCount:h,isFourCC:4==(4&s[20]),isRGB:64==(64&s[20]),isLuminance:131072==(131072&s[20]),isCube:512==(512&s[28]),isCompressed:l===i||l===r||l===n,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?r|=((n|=2048)>>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<i;c++)for(var u=0;u<e;u++){var p=4*(u+c*e);a[l]=t._FromHalfFloat(h[p]),a[l+1]=t._FromHalfFloat(h[p+1]),a[l+2]=t._FromHalfFloat(h[p+2]),t.StoreLODInAlphaChannel?a[l+3]=s:a[l+3]=t._FromHalfFloat(h[p+3]),l+=4}return a},t._GetHalfFloatRGBAArrayBuffer=function(e,i,r,n,o,s){if(t.StoreLODInAlphaChannel){for(var a=new Uint16Array(n),h=new Uint16Array(o,r),l=0,c=0;c<i;c++)for(var u=0;u<e;u++){var p=4*(u+c*e);a[l]=h[p],a[l+1]=h[p+1],a[l+2]=h[p+2],a[l+3]=t._ToHalfFloat(s),l+=4}return a}return new Uint16Array(o,r,n)},t._GetFloatRGBAArrayBuffer=function(e,i,r,n,o,s){if(t.StoreLODInAlphaChannel){for(var a=new Float32Array(n),h=new Float32Array(o,r),l=0,c=0;c<i;c++)for(var u=0;u<e;u++){var p=4*(u+c*e);a[l]=h[p],a[l+1]=h[p+1],a[l+2]=h[p+2],a[l+3]=s,l+=4}return a}return new Float32Array(o,r,n)},t._GetFloatAsUIntRGBAArrayBuffer=function(i,r,n,o,s,a){for(var h=new Uint8Array(o),l=new Float32Array(s,n),c=0,u=0;u<r;u++)for(var p=0;p<i;p++){var f=4*(p+u*i);h[c]=255*e.Scalar.Clamp(l[f]),h[c+1]=255*e.Scalar.Clamp(l[f+1]),h[c+2]=255*e.Scalar.Clamp(l[f+2]),t.StoreLODInAlphaChannel?h[c+3]=a:h[c+3]=255*e.Scalar.Clamp(l[f+3]),c+=4}return h},t._GetHalfFloatAsUIntRGBAArrayBuffer=function(i,r,n,o,s,a){for(var h=new Uint8Array(o),l=new Uint16Array(s,n),c=0,u=0;u<r;u++)for(var p=0;p<i;p++){var f=4*(p+u*i);h[c]=255*e.Scalar.Clamp(t._FromHalfFloat(l[f])),h[c+1]=255*e.Scalar.Clamp(t._FromHalfFloat(l[f+1])),h[c+2]=255*e.Scalar.Clamp(t._FromHalfFloat(l[f+2])),t.StoreLODInAlphaChannel?h[c+3]=a:h[c+3]=255*e.Scalar.Clamp(t._FromHalfFloat(l[f+3])),c+=4}return h},t._GetRGBAArrayBuffer=function(e,t,i,r,n){for(var o=new Uint8Array(r),s=new Uint8Array(n,i),a=0,h=0;h<t;h++)for(var l=0;l<e;l++){var c=4*(l+h*e);o[a]=s[c+2],o[a+1]=s[c+1],o[a+2]=s[c],o[a+3]=s[c+3],a+=4}return o},t._GetRGBArrayBuffer=function(e,t,i,r,n){for(var o=new Uint8Array(r),s=new Uint8Array(n,i),a=0,h=0;h<t;h++)for(var l=0;l<e;l++){var c=3*(l+h*e);o[a]=s[c+2],o[a+1]=s[c+1],o[a+2]=s[c],a+=3}return o},t._GetLuminanceArrayBuffer=function(e,t,i,r,n){for(var o=new Uint8Array(r),s=new Uint8Array(n,i),a=0,h=0;h<t;h++)for(var l=0;l<e;l++){var c=l+h*e;o[a]=s[c],a++}return o},t.UploadDDSLevels=function(s,a,h,l,c,u,p,f){void 0===p&&(p=-1);var d,m,g,_,v,y,b,x=s.getCaps().s3tc,T=new Int32Array(h,0,31),E=0,A=0,P=0,M=1;if(542327876===T[0])if(l.isFourCC||l.isRGB||l.isLuminance)if(!l.isCompressed||x){var S=T[22];_=T[1]+4;var C,R=!1;if(l.isFourCC)switch(d=T[21]){case i:M=8,A=x.COMPRESSED_RGBA_S3TC_DXT1_EXT;break;case r:M=16,A=x.COMPRESSED_RGBA_S3TC_DXT3_EXT;break;case n:M=16,A=x.COMPRESSED_RGBA_S3TC_DXT5_EXT;break;case 113:case 116:R=!0;break;case o:_+=20;var O=!1;switch(l.dxgiFormat){case 10:R=!0,O=!0;break;case 88:l.isRGB=!0,l.isFourCC=!1,S=32,O=!0}if(O)break;default:return void console.error("Unsupported FourCC code:",(C=d,String.fromCharCode(255&C,C>>8&255,C>>16&255,C>>24&255)))}R&&(P=s._getWebGLTextureType(l.textureType),A=s._getRGBABufferInternalSizedFormat(l.textureType)),y=1,131072&T[2]&&!1!==c&&(y=Math.max(1,T[7]));for(var I=0;I<u;I++){var w=1===u?a.TEXTURE_2D:a.TEXTURE_CUBE_MAP_POSITIVE_X+I+(f||0);for(m=T[4],g=T[3],b=0;b<y;++b){if(-1===p||p===b){var D=-1===p?b:0;if(!l.isCompressed&&l.isFourCC){E=m*g*4;var L=null;s.badOS||s.badDesktopOS||!s.getCaps().textureHalfFloat&&!s.getCaps().textureFloat?(128===S?L=t._GetFloatAsUIntRGBAArrayBuffer(m,g,_,E,h,D):64===S&&(L=t._GetHalfFloatAsUIntRGBAArrayBuffer(m,g,_,E,h,D)),l.textureType=e.Engine.TEXTURETYPE_UNSIGNED_INT,P=s._getWebGLTextureType(l.textureType),A=s._getRGBABufferInternalSizedFormat(l.textureType)):128===S?L=t._GetFloatRGBAArrayBuffer(m,g,_,E,h,D):64!==S||s.getCaps().textureHalfFloat?L=t._GetHalfFloatRGBAArrayBuffer(m,g,_,E,h,D):(L=t._GetHalfFloatAsFloatRGBAArrayBuffer(m,g,_,E,h,D),l.textureType=e.Engine.TEXTURETYPE_FLOAT,P=s._getWebGLTextureType(l.textureType),A=s._getRGBABufferInternalSizedFormat(l.textureType)),L&&s._uploadDataToTexture(w,D,A,m,g,a.RGBA,P,L)}else if(l.isRGB)24===S?(E=m*g*3,v=t._GetRGBArrayBuffer(m,g,_,E,h),s._uploadDataToTexture(w,D,a.RGB,m,g,a.RGB,a.UNSIGNED_BYTE,v)):(E=m*g*4,v=t._GetRGBAArrayBuffer(m,g,_,E,h),s._uploadDataToTexture(w,D,a.RGBA,m,g,a.RGBA,a.UNSIGNED_BYTE,v));else if(l.isLuminance){var B=a.getParameter(a.UNPACK_ALIGNMENT),N=m;E=Math.floor((m+B-1)/B)*B*(g-1)+N,v=t._GetLuminanceArrayBuffer(m,g,_,E,h),s._uploadDataToTexture(w,D,a.LUMINANCE,m,g,a.LUMINANCE,a.UNSIGNED_BYTE,v)}else E=Math.max(4,m)/4*Math.max(4,g)/4*M,v=new Uint8Array(h,_,E),s._uploadCompressedDataToTexture(w,D,A,m,g,v)}_+=S?m*g*(S/8):E,m*=.5,g*=.5,m=Math.max(1,m),g=Math.max(1,g)}if(void 0!==f)break}}else e.Tools.Error("Compressed textures are not supported on this platform.");else e.Tools.Error("Unsupported format, must contain a FourCC, RGB or LUMINANCE code");else e.Tools.Error("Invalid magic number in DDS header")},t.StoreLODInAlphaChannel=!1,t}();e.DDSTools=s}(us||(us={})),Gn=us||(us={}),Wn=function(){function e(t,i,r,n){this.arrayBuffer=t;var o=new Uint8Array(this.arrayBuffer,0,12);if(171===o[0]&&75===o[1]&&84===o[2]&&88===o[3]&&32===o[4]&&49===o[5]&&49===o[6]&&187===o[7]&&13===o[8]&&10===o[9]&&26===o[10]&&10===o[11]){var s=new Int32Array(this.arrayBuffer,12,13),a=16909060===s[0];this.glType=a?this.switchEndainness(s[1]):s[1],this.glTypeSize=a?this.switchEndainness(s[2]):s[2],this.glFormat=a?this.switchEndainness(s[3]):s[3],this.glInternalFormat=a?this.switchEndainness(s[4]):s[4],this.glBaseInternalFormat=a?this.switchEndainness(s[5]):s[5],this.pixelWidth=a?this.switchEndainness(s[6]):s[6],this.pixelHeight=a?this.switchEndainness(s[7]):s[7],this.pixelDepth=a?this.switchEndainness(s[8]):s[8],this.numberOfArrayElements=a?this.switchEndainness(s[9]):s[9],this.numberOfFaces=a?this.switchEndainness(s[10]):s[10],this.numberOfMipmapLevels=a?this.switchEndainness(s[11]):s[11],this.bytesOfKeyValueData=a?this.switchEndainness(s[12]):s[12],0===this.glType?(this.numberOfMipmapLevels=Math.max(1,this.numberOfMipmapLevels),0!==this.pixelHeight&&0===this.pixelDepth?0===this.numberOfArrayElements?this.numberOfFaces===i?this.loadType=e.COMPRESSED_2D:Gn.Tools.Error("number of faces expected"+i+", but found "+this.numberOfFaces):Gn.Tools.Error("texture arrays not currently supported"):Gn.Tools.Error("only 2D textures currently supported")):Gn.Tools.Error("only compressed formats currently supported")}else Gn.Tools.Error("texture missing KTX identifier")}return e.prototype.switchEndainness=function(e){return(255&e)<<24|(65280&e)<<8|e>>8&65280|e>>24&255},e.prototype.uploadLevels=function(t,i){switch(this.loadType){case e.COMPRESSED_2D:this._upload2DCompressedLevels(t,i);break;case e.TEX_2D:case e.COMPRESSED_3D:case e.TEX_3D:}},e.prototype._upload2DCompressedLevels=function(t,i){for(var r=e.HEADER_LEN+this.bytesOfKeyValueData,n=this.pixelWidth,o=this.pixelHeight,s=i?this.numberOfMipmapLevels:1,a=0;a<s;a++){for(var h=new Int32Array(this.arrayBuffer,r,1)[0],l=0;l<this.numberOfFaces;l++){var c=1===this.numberOfFaces?t.TEXTURE_2D:t.TEXTURE_CUBE_MAP_POSITIVE_X+l,u=new Uint8Array(this.arrayBuffer,r+4,h);t.compressedTexImage2D(c,a,this.glInternalFormat,n,o,0,u),r+=h+4,r+=3-(h+3)%4}n=Math.max(1,.5*n),o=Math.max(1,.5*o)}},e.HEADER_LEN=64,e.COMPRESSED_2D=0,e.COMPRESSED_3D=1,e.TEX_2D=2,e.TEX_3D=3,e}(),Gn.KhronosTextureContainer=Wn,Hn=us||(us={}),jn=function(){function e(){}return e.AxesViewer=function(){function e(e,t){void 0===t&&(t=1),this._xline=[Hn.Vector3.Zero(),Hn.Vector3.Zero()],this._yline=[Hn.Vector3.Zero(),Hn.Vector3.Zero()],this._zline=[Hn.Vector3.Zero(),Hn.Vector3.Zero()],this.scaleLines=1,this.scaleLines=t,this._xmesh=Hn.Mesh.CreateLines("xline",this._xline,e,!0),this._ymesh=Hn.Mesh.CreateLines("yline",this._yline,e,!0),this._zmesh=Hn.Mesh.CreateLines("zline",this._zline,e,!0),this._xmesh.renderingGroupId=2,this._ymesh.renderingGroupId=2,this._zmesh.renderingGroupId=2,this._xmesh.material.checkReadyOnlyOnce=!0,this._xmesh.color=new Hn.Color3(1,0,0),this._ymesh.material.checkReadyOnlyOnce=!0,this._ymesh.color=new Hn.Color3(0,1,0),this._zmesh.material.checkReadyOnlyOnce=!0,this._zmesh.color=new Hn.Color3(0,0,1),this.scene=e}return e.prototype.update=function(e,t,i,r){var n=this.scaleLines;this._xmesh&&this._xmesh.position.copyFrom(e),this._ymesh&&this._ymesh.position.copyFrom(e),this._zmesh&&this._zmesh.position.copyFrom(e);var o=this._xline[1];o.x=t.x*n,o.y=t.y*n,o.z=t.z*n,Hn.Mesh.CreateLines("",this._xline,null,!1,this._xmesh),(o=this._yline[1]).x=i.x*n,o.y=i.y*n,o.z=i.z*n,Hn.Mesh.CreateLines("",this._yline,null,!1,this._ymesh),(o=this._zline[1]).x=r.x*n,o.y=r.y*n,o.z=r.z*n,Hn.Mesh.CreateLines("",this._zline,null,!1,this._zmesh)},e.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},e}(),e.BoneAxesViewer=function(e){function t(t,i,r,n){void 0===n&&(n=1);var o=e.call(this,t,n)||this;return o.pos=Hn.Vector3.Zero(),o.xaxis=Hn.Vector3.Zero(),o.yaxis=Hn.Vector3.Zero(),o.zaxis=Hn.Vector3.Zero(),o.mesh=r,o.bone=i,o}return Y(t,e),t.prototype.update=function(){if(this.mesh&&this.bone){var t=this.bone;t.getAbsolutePositionToRef(this.mesh,this.pos),t.getDirectionToRef(Hn.Axis.X,this.mesh,this.xaxis),t.getDirectionToRef(Hn.Axis.Y,this.mesh,this.yaxis),t.getDirectionToRef(Hn.Axis.Z,this.mesh,this.zaxis),e.prototype.update.call(this,this.pos,this.xaxis,this.yaxis,this.zaxis)}},t.prototype.dispose=function(){this.mesh&&(this.mesh=null,this.bone=null,e.prototype.dispose.call(this))},t}(e.AxesViewer),e.PhysicsViewer=function(){function e(e){this._impostors=[],this._meshes=[],this._numMeshes=0,this._scene=e||Hn.Engine.LastCreatedScene;var t=this._scene.getPhysicsEngine();t&&(this._physicsEnginePlugin=t.getPhysicsPlugin())}return e.prototype._updateDebugMeshes=function(){for(var e=this._physicsEnginePlugin,t=0;t<this._numMeshes;t++){var i=this._impostors[t];if(i)if(i.isDisposed)this.hideImpostor(this._impostors[t--]);else{var r=this._meshes[t];r&&e&&e.syncMeshWithImpostor(r,i)}}},e.prototype.showImpostor=function(e){if(this._scene){for(var t=0;t<this._numMeshes;t++)if(this._impostors[t]==e)return;var i=this._getDebugMesh(e,this._scene);i&&(this._impostors[this._numMeshes]=e,this._meshes[this._numMeshes]=i,0===this._numMeshes&&(this._renderFunction=this._updateDebugMeshes.bind(this),this._scene.registerBeforeRender(this._renderFunction)),this._numMeshes++)}},e.prototype.hideImpostor=function(e){if(e&&this._scene){for(var t=!1,i=0;i<this._numMeshes;i++)if(this._impostors[i]==e){var r=this._meshes[i];if(!r)continue;this._scene.removeMesh(r),r.dispose(),this._numMeshes--,this._numMeshes>0?(this._meshes[i]=this._meshes[this._numMeshes],this._impostors[i]=this._impostors[this._numMeshes],this._meshes[this._numMeshes]=null,this._impostors[this._numMeshes]=null):(this._meshes[0]=null,this._impostors[0]=null),t=!0;break}t&&0===this._numMeshes&&this._scene.unregisterBeforeRender(this._renderFunction)}},e.prototype._getDebugMaterial=function(e){return this._debugMaterial||(this._debugMaterial=new Hn.StandardMaterial("",e),this._debugMaterial.wireframe=!0),this._debugMaterial},e.prototype._getDebugBoxMesh=function(e){return this._debugBoxMesh||(this._debugBoxMesh=Hn.MeshBuilder.CreateBox("physicsBodyBoxViewMesh",{size:1},e),this._debugBoxMesh.renderingGroupId=1,this._debugBoxMesh.rotationQuaternion=Hn.Quaternion.Identity(),this._debugBoxMesh.material=this._getDebugMaterial(e),e.removeMesh(this._debugBoxMesh)),this._debugBoxMesh.createInstance("physicsBodyBoxViewInstance")},e.prototype._getDebugSphereMesh=function(e){return this._debugSphereMesh||(this._debugSphereMesh=Hn.MeshBuilder.CreateSphere("physicsBodySphereViewMesh",{diameter:1},e),this._debugSphereMesh.renderingGroupId=1,this._debugSphereMesh.rotationQuaternion=Hn.Quaternion.Identity(),this._debugSphereMesh.material=this._getDebugMaterial(e),e.removeMesh(this._debugSphereMesh)),this._debugSphereMesh.createInstance("physicsBodyBoxViewInstance")},e.prototype._getDebugMesh=function(e,t){var i=null;if(e.type==Hn.PhysicsImpostor.BoxImpostor)i=this._getDebugBoxMesh(t),e.getBoxSizeToRef(i.scaling);else if(e.type==Hn.PhysicsImpostor.SphereImpostor){i=this._getDebugSphereMesh(t);var r=e.getRadius();i.scaling.x=2*r,i.scaling.y=2*r,i.scaling.z=2*r}return i},e.prototype.dispose=function(){for(var e=0;e<this._numMeshes;e++)this.hideImpostor(this._impostors[e]);this._debugBoxMesh&&this._debugBoxMesh.dispose(),this._debugSphereMesh&&this._debugSphereMesh.dispose(),this._debugMaterial&&this._debugMaterial.dispose(),this._impostors.length=0,this._scene=null,this._physicsEnginePlugin=null},e}(),e.SkeletonViewer=function(){function e(e,t,i,r,n){void 0===r&&(r=!0),void 0===n&&(n=1),this.skeleton=e,this.mesh=t,this.autoUpdateBonesMatrices=r,this.renderingGroupId=n,this.color=Hn.Color3.White(),this._debugLines=new Array,this._isEnabled=!1,this._scene=i,this.update(),this._renderFunction=this.update.bind(this)}return Object.defineProperty(e.prototype,"isEnabled",{get:function(){return this._isEnabled},set:function(e){this._isEnabled!==e&&(this._isEnabled=e,e?this._scene.registerBeforeRender(this._renderFunction):this._scene.unregisterBeforeRender(this._renderFunction))},enumerable:!0,configurable:!0}),e.prototype._getBonePosition=function(e,t,i,r,n,o){void 0===r&&(r=0),void 0===n&&(n=0),void 0===o&&(o=0);var s=Hn.Tmp.Matrix[0],a=t.getParent();if(s.copyFrom(t.getLocalMatrix()),0!==r||0!==n||0!==o){var h=Hn.Tmp.Matrix[1];Hn.Matrix.IdentityToRef(h),h.m[12]=r,h.m[13]=n,h.m[14]=o,h.multiplyToRef(s,s)}a&&s.multiplyToRef(a.getAbsoluteTransform(),s),s.multiplyToRef(i,s),e.x=s.m[12],e.y=s.m[13],e.z=s.m[14]},e.prototype._getLinesForBonesWithLength=function(e,t){for(var i=e.length,r=this.mesh.position,n=0;n<i;n++){var o=e[n],s=this._debugLines[n];s||(s=[Hn.Vector3.Zero(),Hn.Vector3.Zero()],this._debugLines[n]=s),this._getBonePosition(s[0],o,t),this._getBonePosition(s[1],o,t,0,o.length,0),s[0].subtractInPlace(r),s[1].subtractInPlace(r)}},e.prototype._getLinesForBonesNoLength=function(e,t){for(var i=e.length,r=0,n=this.mesh.position,o=i-1;o>=0;o--){var s=e[o],a=s.getParent();if(a){var h=this._debugLines[r];h||(h=[Hn.Vector3.Zero(),Hn.Vector3.Zero()],this._debugLines[r]=h),s.getAbsolutePositionToRef(this.mesh,h[0]),a.getAbsolutePositionToRef(this.mesh,h[1]),h[0].subtractInPlace(n),h[1].subtractInPlace(n),r++}}},e.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?Hn.MeshBuilder.CreateLineSystem("",{lines:this._debugLines,updatable:!0,instance:this._debugMesh},this._scene):(this._debugMesh=Hn.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},e.prototype.dispose=function(){this._debugMesh&&(this.isEnabled=!1,this._debugMesh.dispose(),this._debugMesh=null)},e}(),e}(),Hn.Debug=jn,Xn=us||(us={}),Yn=function(){function e(e){this.ray=e}return e.CreateAndShow=function(t,i,r){var n=new e(t);return n.show(i,r),n},e.prototype.show=function(e,t){if(!this._renderFunction&&this.ray){var i=this.ray;this._renderFunction=this._render.bind(this),this._scene=e,this._renderPoints=[i.origin,i.origin.add(i.direction.scale(i.length))],this._renderLine=Xn.Mesh.CreateLines("ray",this._renderPoints,e,!0),this._renderFunction&&this._scene.registerBeforeRender(this._renderFunction)}t&&this._renderLine&&this._renderLine.color.copyFrom(t)},e.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=[])},e.prototype._render=function(){var e=this.ray;if(e){var t=this._renderPoints[1],i=Math.min(e.length,1e6);t.copyFrom(e.direction),t.scaleInPlace(i),t.addInPlace(e.origin),Xn.Mesh.CreateLines("ray",this._renderPoints,this._scene,!0,this._renderLine)}},e.prototype.attachToMesh=function(e,t,i,r){this._attachedToMesh=e;var n=this.ray;n&&(n.direction||(n.direction=Xn.Vector3.Zero()),n.origin||(n.origin=Xn.Vector3.Zero()),r&&(n.length=r),i||(i=Xn.Vector3.Zero()),t||(t=new Xn.Vector3(0,0,-1)),this._meshSpaceDirection?(this._meshSpaceDirection.copyFrom(t),this._meshSpaceOrigin.copyFrom(i)):(this._meshSpaceDirection=t.clone(),this._meshSpaceOrigin=i.clone()),this._updateToMeshFunction||(this._updateToMeshFunction=this._updateToMesh.bind(this),this._attachedToMesh.getScene().registerBeforeRender(this._updateToMeshFunction)),this._updateToMesh())},e.prototype.detachFromMesh=function(){this._attachedToMesh&&(this._updateToMeshFunction&&this._attachedToMesh.getScene().unregisterBeforeRender(this._updateToMeshFunction),this._attachedToMesh=null,this._updateToMeshFunction=null)},e.prototype._updateToMesh=function(){var e=this.ray;this._attachedToMesh&&e&&(this._attachedToMesh._isDisposed?this.detachFromMesh():(this._attachedToMesh.getDirectionToRef(this._meshSpaceDirection,e.direction),Xn.Vector3.TransformCoordinatesToRef(this._meshSpaceOrigin,this._attachedToMesh.getWorldMatrix(),e.origin)))},e.prototype.dispose=function(){this.hide(),this.detachFromMesh(),this.ray=null},e}(),Xn.RayHelper=Yn,Kn=us||(us={}),Qn=function(){function e(e){this.BJSINSPECTOR="undefined"!=typeof INSPECTOR?INSPECTOR:void 0,this._scene=e}return e.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))},e.prototype.isVisible=function(){return!!this._inspector},e.prototype.hide=function(){if(this._inspector){try{this._inspector.dispose()}catch(e){}this._inspector=null}},e.prototype.show=function(t){void 0===t&&(t={}),void 0===this.BJSINSPECTOR?Kn.Tools.LoadScript(e.InspectorURL,this._createInspector.bind(this,t)):this._createInspector(t)},e.InspectorURL="https://preview.babylonjs.com/inspector/babylon.inspector.bundle.js",e}(),Kn.DebugLayer=Qn,Zn=us||(us={}),qn=function(){function e(e){this.frontColor=new Zn.Color3(1,1,1),this.backColor=new Zn.Color3(.1,.1,.1),this.showBackLines=!0,this.renderList=new Zn.SmartArray(32),this._vertexBuffers={},this._scene=e}return e.prototype._prepareRessources=function(){if(!this._colorShader){this._colorShader=new Zn.ShaderMaterial("colorShader",this._scene,"color",{attributes:[Zn.VertexBuffer.PositionKind],uniforms:["world","viewProjection","color"]});var e=this._scene.getEngine(),t=Zn.VertexData.CreateBox({size:1});this._vertexBuffers[Zn.VertexBuffer.PositionKind]=new Zn.VertexBuffer(e,t.positions,Zn.VertexBuffer.PositionKind,!1),this._createIndexBuffer()}},e.prototype._createIndexBuffer=function(){var e=this._scene.getEngine();this._indexBuffer=e.createIndexBuffer([0,1,1,2,2,3,3,0,4,5,5,6,6,7,7,4,0,7,1,6,2,5,3,4])},e.prototype._rebuild=function(){var e=this._vertexBuffers[Zn.VertexBuffer.PositionKind];e&&e._rebuild(),this._createIndexBuffer()},e.prototype.reset=function(){this.renderList.reset()},e.prototype.render=function(){if(0!==this.renderList.length&&(this._prepareRessources(),this._colorShader.isReady())){var e=this._scene.getEngine();e.setDepthWrite(!1),this._colorShader._preBind();for(var t=0;t<this.renderList.length;t++){var i=this.renderList.data[t],r=i.minimum,n=i.maximum.subtract(r),o=r.add(n.scale(.5)),s=Zn.Matrix.Scaling(n.x,n.y,n.z).multiply(Zn.Matrix.Translation(o.x,o.y,o.z)).multiply(i.getWorldMatrix());e.bindBuffers(this._vertexBuffers,this._indexBuffer,this._colorShader.getEffect()),this.showBackLines&&(e.setDepthFunctionToGreaterOrEqual(),this._scene.resetCachedMaterial(),this._colorShader.setColor4("color",this.backColor.toColor4()),this._colorShader.bind(s),e.drawElementsType(Zn.Material.LineListDrawMode,0,24)),e.setDepthFunctionToLess(),this._scene.resetCachedMaterial(),this._colorShader.setColor4("color",this.frontColor.toColor4()),this._colorShader.bind(s),e.drawElementsType(Zn.Material.LineListDrawMode,0,24)}this._colorShader.unbind(),e.setDepthFunctionToLessOrEqual(),e.setDepthWrite(!0)}},e.prototype.renderOcclusionBoundingBox=function(e){if(this._prepareRessources(),this._colorShader.isReady()&&e._boundingInfo){var t=this._scene.getEngine();t.setDepthWrite(!1),t.setColorWrite(!1),this._colorShader._preBind();var i=e._boundingInfo.boundingBox,r=i.minimum,n=i.maximum.subtract(r),o=r.add(n.scale(.5)),s=Zn.Matrix.Scaling(n.x,n.y,n.z).multiply(Zn.Matrix.Translation(o.x,o.y,o.z)).multiply(i.getWorldMatrix());t.bindBuffers(this._vertexBuffers,this._indexBuffer,this._colorShader.getEffect()),t.setDepthFunctionToLess(),this._scene.resetCachedMaterial(),this._colorShader.bind(s),t.drawElementsType(Zn.Material.TriangleFillMode,0,24),this._colorShader.unbind(),t.setDepthFunctionToLessOrEqual(),t.setDepthWrite(!0),t.setColorWrite(!0)}},e.prototype.dispose=function(){if(this._colorShader){this.renderList.dispose(),this._colorShader.dispose();var e=this._vertexBuffers[Zn.VertexBuffer.PositionKind];e&&(e.dispose(),this._vertexBuffers[Zn.VertexBuffer.PositionKind]=null),this._scene.getEngine()._releaseBuffer(this._indexBuffer)}},e}(),Zn.BoundingBoxRenderer=qn,Jn=us||(us={}),$n=function(){function e(e,t){void 0===t&&(t=0),this.name=e,this.animations=new Array,this._positions=null,this._normals=null,this._tangents=null,this.onInfluenceChanged=new Jn.Observable,this.influence=t}return Object.defineProperty(e.prototype,"influence",{get:function(){return this._influence},set:function(e){if(this._influence!==e){var t=this._influence;this._influence=e,this.onInfluenceChanged.hasObservers&&this.onInfluenceChanged.notifyObservers(0===t||0===e)}},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"hasPositions",{get:function(){return!!this._positions},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"hasNormals",{get:function(){return!!this._normals},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"hasTangents",{get:function(){return!!this._tangents},enumerable:!0,configurable:!0}),e.prototype.setPositions=function(e){this._positions=e},e.prototype.getPositions=function(){return this._positions},e.prototype.setNormals=function(e){this._normals=e},e.prototype.getNormals=function(){return this._normals},e.prototype.setTangents=function(e){this._tangents=e},e.prototype.getTangents=function(){return this._tangents},e.prototype.serialize=function(){var e={};return e.name=this.name,e.influence=this.influence,e.positions=Array.prototype.slice.call(this.getPositions()),this.hasNormals&&(e.normals=Array.prototype.slice.call(this.getNormals())),this.hasTangents&&(e.tangents=Array.prototype.slice.call(this.getTangents())),Jn.Animation.AppendSerializedAnimations(this,e),e},e.Parse=function(t){var i=new e(t.name,t.influence);if(i.setPositions(t.positions),t.normals&&i.setNormals(t.normals),t.tangents&&i.setTangents(t.tangents),t.animations)for(var r=0;r<t.animations.length;r++){var n=t.animations[r];i.animations.push(Jn.Animation.Parse(n))}return i},e.FromMesh=function(t,i,r){i||(i=t.name);var n=new e(i,r);return n.setPositions(t.getVerticesData(Jn.VertexBuffer.PositionKind)),t.isVerticesDataPresent(Jn.VertexBuffer.NormalKind)&&n.setNormals(t.getVerticesData(Jn.VertexBuffer.NormalKind)),t.isVerticesDataPresent(Jn.VertexBuffer.TangentKind)&&n.setTangents(t.getVerticesData(Jn.VertexBuffer.TangentKind)),n},e}(),Jn.MorphTarget=$n,eo=us||(us={}),to=function(){function e(e){void 0===e&&(e=null),this._targets=new Array,this._targetObservable=new Array,this._activeTargets=new eo.SmartArray(16),this._supportsNormals=!1,this._supportsTangents=!1,this._vertexCount=0,this._uniqueId=0,this._tempInfluences=new Array,e||(e=eo.Engine.LastCreatedScene),this._scene=e,this._scene&&(this._scene.morphTargetManagers.push(this),this._uniqueId=this._scene.getUniqueId())}return Object.defineProperty(e.prototype,"uniqueId",{get:function(){return this._uniqueId},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"vertexCount",{get:function(){return this._vertexCount},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"supportsNormals",{get:function(){return this._supportsNormals},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"supportsTangents",{get:function(){return this._supportsTangents},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"numTargets",{get:function(){return this._targets.length},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"numInfluencers",{get:function(){return this._activeTargets.length},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"influences",{get:function(){return this._influences},enumerable:!0,configurable:!0}),e.prototype.getActiveTarget=function(e){return this._activeTargets.data[e]},e.prototype.getTarget=function(e){return this._targets[e]},e.prototype.addTarget=function(e){var t=this;this._targets.push(e),this._targetObservable.push(e.onInfluenceChanged.add(function(e){t._syncActiveTargets(e)})),this._syncActiveTargets(!0)},e.prototype.removeTarget=function(e){var t=this._targets.indexOf(e);t>=0&&(this._targets.splice(t,1),e.onInfluenceChanged.remove(this._targetObservable.splice(t,1)[0]),this._syncActiveTargets(!0))},e.prototype.serialize=function(){var e={};e.id=this.uniqueId,e.targets=[];for(var t=0,i=this._targets;t<i.length;t++){var r=i[t];e.targets.push(r.serialize())}return e},e.prototype._syncActiveTargets=function(e){var t=0;this._activeTargets.reset(),this._supportsNormals=!0,this._supportsTangents=!0,this._vertexCount=0;for(var i=0,r=this._targets;i<r.length;i++){var n=r[i];this._activeTargets.push(n),this._tempInfluences[t++]=n.influence;var o=n.getPositions();if(o){this._supportsNormals=this._supportsNormals&&n.hasNormals,this._supportsTangents=this._supportsTangents&&n.hasTangents;var s=o.length/3;if(0===this._vertexCount)this._vertexCount=s;else if(this._vertexCount!==s)return void eo.Tools.Error("Incompatible target. Targets must all have the same vertices count.")}}this._influences&&this._influences.length===t||(this._influences=new Float32Array(t));for(var a=0;a<t;a++)this._influences[a]=this._tempInfluences[a];if(e&&this._scene)for(var h=0,l=this._scene.meshes;h<l.length;h++){var c=l[h];c.morphTargetManager===this&&c._syncGeometryWithMorphTargetManager()}},e.Parse=function(t,i){var r=new e(i);r._uniqueId=t.id;for(var n=0,o=t.targets;n<o.length;n++){var s=o[n];r.addTarget(eo.MorphTarget.Parse(s))}return r},e}(),eo.MorphTargetManager=to,io=us||(us={}),ro=function(){function e(e,t,i){void 0===i&&(i=2),this.maxDepth=i,this.dynamicContent=new Array,this._maxBlockCapacity=t||64,this._selectionContent=new io.SmartArrayNoDuplicate(1024),this._creationFunc=e}return e.prototype.update=function(t,i,r){e._CreateBlocks(t,i,r,this._maxBlockCapacity,0,this.maxDepth,this,this._creationFunc)},e.prototype.addMesh=function(e){for(var t=0;t<this.blocks.length;t++){this.blocks[t].addEntry(e)}},e.prototype.select=function(e,t){this._selectionContent.reset();for(var i=0;i<this.blocks.length;i++){this.blocks[i].select(e,this._selectionContent,t)}return t?this._selectionContent.concat(this.dynamicContent):this._selectionContent.concatWithNoDuplicate(this.dynamicContent),this._selectionContent},e.prototype.intersects=function(e,t,i){this._selectionContent.reset();for(var r=0;r<this.blocks.length;r++){this.blocks[r].intersects(e,t,this._selectionContent,i)}return i?this._selectionContent.concat(this.dynamicContent):this._selectionContent.concatWithNoDuplicate(this.dynamicContent),this._selectionContent},e.prototype.intersectsRay=function(e){this._selectionContent.reset();for(var t=0;t<this.blocks.length;t++){this.blocks[t].intersectsRay(e,this._selectionContent)}return this._selectionContent.concatWithNoDuplicate(this.dynamicContent),this._selectionContent},e._CreateBlocks=function(e,t,i,r,n,o,s,a){s.blocks=new Array;for(var h=new io.Vector3((t.x-e.x)/2,(t.y-e.y)/2,(t.z-e.z)/2),l=0;l<2;l++)for(var c=0;c<2;c++)for(var u=0;u<2;u++){var p=e.add(h.multiplyByFloats(l,c,u)),f=e.add(h.multiplyByFloats(l+1,c+1,u+1)),d=new io.OctreeBlock(p,f,r,n+1,o,a);d.addEntries(i),s.blocks.push(d)}},e.CreationFuncForMeshes=function(e,t){var i=e.getBoundingInfo();!e.isBlocked&&i.boundingBox.intersectsMinMax(t.minPoint,t.maxPoint)&&t.entries.push(e)},e.CreationFuncForSubMeshes=function(e,t){e.getBoundingInfo().boundingBox.intersectsMinMax(t.minPoint,t.maxPoint)&&t.entries.push(e)},e}(),io.Octree=ro,no=us||(us={}),oo=function(){function e(e,t,i,r,n,o){this.entries=new Array,this._boundingVectors=new Array,this._capacity=i,this._depth=r,this._maxDepth=n,this._creationFunc=o,this._minPoint=e,this._maxPoint=t,this._boundingVectors.push(e.clone()),this._boundingVectors.push(t.clone()),this._boundingVectors.push(e.clone()),this._boundingVectors[2].x=t.x,this._boundingVectors.push(e.clone()),this._boundingVectors[3].y=t.y,this._boundingVectors.push(e.clone()),this._boundingVectors[4].z=t.z,this._boundingVectors.push(t.clone()),this._boundingVectors[5].z=e.z,this._boundingVectors.push(t.clone()),this._boundingVectors[6].x=e.x,this._boundingVectors.push(t.clone()),this._boundingVectors[7].y=e.y}return Object.defineProperty(e.prototype,"capacity",{get:function(){return this._capacity},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"minPoint",{get:function(){return this._minPoint},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"maxPoint",{get:function(){return this._maxPoint},enumerable:!0,configurable:!0}),e.prototype.addEntry=function(e){if(this.blocks)for(var t=0;t<this.blocks.length;t++){this.blocks[t].addEntry(e)}else this._creationFunc(e,this),this.entries.length>this.capacity&&this._depth<this._maxDepth&&this.createInnerBlocks()},e.prototype.addEntries=function(e){for(var t=0;t<e.length;t++){var i=e[t];this.addEntry(i)}},e.prototype.select=function(e,t,i){if(no.BoundingBox.IsInFrustum(this._boundingVectors,e)){if(this.blocks){for(var r=0;r<this.blocks.length;r++){this.blocks[r].select(e,t,i)}return}i?t.concat(this.entries):t.concatWithNoDuplicate(this.entries)}},e.prototype.intersects=function(e,t,i,r){if(no.BoundingBox.IntersectsSphere(this._minPoint,this._maxPoint,e,t)){if(this.blocks){for(var n=0;n<this.blocks.length;n++){this.blocks[n].intersects(e,t,i,r)}return}r?i.concat(this.entries):i.concatWithNoDuplicate(this.entries)}},e.prototype.intersectsRay=function(e,t){if(e.intersectsBoxMinMax(this._minPoint,this._maxPoint)){if(this.blocks){for(var i=0;i<this.blocks.length;i++){this.blocks[i].intersectsRay(e,t)}return}t.concatWithNoDuplicate(this.entries)}},e.prototype.createInnerBlocks=function(){no.Octree._CreateBlocks(this._minPoint,this._maxPoint,this.entries,this._capacity,this._depth,this._maxDepth,this,this._creationFunc)},e}(),no.OctreeBlock=oo,so=us||(us={}),ao=function(e){function t(t,i,r,n){var o=e.call(this,t,"vrDistortionCorrection",["LensCenter","Scale","ScaleIn","HmdWarpParam"],null,n.postProcessScaleFactor,i,so.Texture.BILINEAR_SAMPLINGMODE)||this;return o._isRightEye=r,o._distortionFactors=n.distortionK,o._postProcessScaleFactor=n.postProcessScaleFactor,o._lensCenterOffset=n.lensCenterOffset,o.adaptScaleToCurrentViewport=!0,o.onSizeChangedObservable.add(function(){o.aspectRatio=.5*o.width/o.height,o._scaleIn=new so.Vector2(2,2/o.aspectRatio),o._scaleFactor=new so.Vector2(1/o._postProcessScaleFactor*.5,1/o._postProcessScaleFactor*.5*o.aspectRatio),o._lensCenter=new so.Vector2(o._isRightEye?.5-.5*o._lensCenterOffset:.5+.5*o._lensCenterOffset,.5)}),o.onApplyObservable.add(function(e){e.setFloat2("LensCenter",o._lensCenter.x,o._lensCenter.y),e.setFloat2("Scale",o._scaleFactor.x,o._scaleFactor.y),e.setFloat2("ScaleIn",o._scaleIn.x,o._scaleIn.y),e.setFloat4("HmdWarpParam",o._distortionFactors[0],o._distortionFactors[1],o._distortionFactors[2],o._distortionFactors[3])}),o}return Y(t,e),t}(so.PostProcess),so.VRDistortionCorrectionPostProcess=ao,ho=us||(us={}),lo=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 Y(t,e),t}(ho.PostProcess),ho.AnaglyphPostProcess=lo,co=us||(us={}),uo=function(e){function t(t,i,r,n,o,s){var a=e.call(this,t,"stereoscopicInterlace",["stepSize"],["camASampler"],1,i[1],n,o,s,r?"#define IS_STEREOSCOPIC_HORIZ 1":void 0)||this;return a._passedProcess=i[0]._rigPostProcess,a._stepSize=new co.Vector2(1/a.width,1/a.height),a.onSizeChangedObservable.add(function(){a._stepSize=new co.Vector2(1/a.width,1/a.height)}),a.onApplyObservable.add(function(e){e.setTextureFromPostProcess("camASampler",a._passedProcess),e.setFloat2("stepSize",a._stepSize.x,a._stepSize.y)}),a}return Y(t,e),t}(co.PostProcess),co.StereoscopicInterlacePostProcess=uo,po=us||(us={}),fo=function(){function e(){var e=this;this._screenOrientationAngle=0,this._screenQuaternion=new po.Quaternion,this._alpha=0,this._beta=0,this._gamma=0,this._orientationChanged=function(){e._screenOrientationAngle=void 0!==window.orientation?+window.orientation:window.screen.orientation&&window.screen.orientation.angle?window.screen.orientation.angle:0,e._screenOrientationAngle=-po.Tools.ToRadians(e._screenOrientationAngle/2),e._screenQuaternion.copyFromFloats(0,Math.sin(e._screenOrientationAngle),0,Math.cos(e._screenOrientationAngle))},this._deviceOrientation=function(t){e._alpha=null!==t.alpha?t.alpha:0,e._beta=null!==t.beta?t.beta:0,e._gamma=null!==t.gamma?t.gamma:0},this._constantTranform=new po.Quaternion(-Math.sqrt(.5),0,0,Math.sqrt(.5)),this._orientationChanged()}return Object.defineProperty(e.prototype,"camera",{get:function(){return this._camera},set:function(e){this._camera=e,null==this._camera||this._camera.rotationQuaternion||(this._camera.rotationQuaternion=new po.Quaternion)},enumerable:!0,configurable:!0}),e.prototype.attachControl=function(e,t){window.addEventListener("orientationchange",this._orientationChanged),window.addEventListener("deviceorientation",this._deviceOrientation),this._orientationChanged()},e.prototype.detachControl=function(e){window.removeEventListener("orientationchange",this._orientationChanged),window.removeEventListener("deviceorientation",this._deviceOrientation)},e.prototype.checkInputs=function(){this._alpha&&(po.Quaternion.RotationYawPitchRollToRef(po.Tools.ToRadians(this._alpha),po.Tools.ToRadians(this._beta),-po.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)},e.prototype.getClassName=function(){return"FreeCameraDeviceOrientationInput"},e.prototype.getSimpleName=function(){return"deviceOrientation"},e}(),po.FreeCameraDeviceOrientationInput=fo,po.CameraInputTypes.FreeCameraDeviceOrientationInput=fo,mo=us||(us={}),go=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}(),mo.ArcRotateCameraVRDeviceOrientationInput=go,mo.CameraInputTypes.ArcRotateCameraVRDeviceOrientationInput=go,_o=us||(us={}),vo=function(){function e(){this.compensateDistortion=!0}return Object.defineProperty(e.prototype,"aspectRatio",{get:function(){return this.hResolution/(2*this.vResolution)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"aspectRatioFov",{get:function(){return 2*Math.atan(this.postProcessScaleFactor*this.vScreenSize/(2*this.eyeToScreenDistance))},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"leftHMatrix",{get:function(){var e=4*(this.hScreenSize/4-this.lensSeparationDistance/2)/this.hScreenSize;return _o.Matrix.Translation(e,0,0)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rightHMatrix",{get:function(){var e=4*(this.hScreenSize/4-this.lensSeparationDistance/2)/this.hScreenSize;return _o.Matrix.Translation(-e,0,0)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"leftPreViewMatrix",{get:function(){return _o.Matrix.Translation(.5*this.interpupillaryDistance,0,0)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rightPreViewMatrix",{get:function(){return _o.Matrix.Translation(-.5*this.interpupillaryDistance,0,0)},enumerable:!0,configurable:!0}),e.GetDefault=function(){var t=new e;return t.hResolution=1280,t.vResolution=800,t.hScreenSize=.149759993,t.vScreenSize=.0935999975,t.vScreenCenter=.0467999987,t.eyeToScreenDistance=.0410000011,t.lensSeparationDistance=.063500002,t.interpupillaryDistance=.064000003,t.distortionK=[1,.219999999,.239999995,0],t.chromaAbCorrection=[.995999992,-.00400000019,1.01400006,0],t.postProcessScaleFactor=1.714605507808412,t.lensCenterOffset=.151976421,t},e}(),_o.VRCameraMetrics=vo,yo=us||(us={}),bo=function(e){function t(t,i,r,n){void 0===n&&(n={});var o=e.call(this,t,i,r)||this;o.webVROptions=n,o._vrDevice=null,o.rawPose=null,o._specsVersion="1.1",o._attached=!1,o._descendants=[],o._deviceRoomPosition=yo.Vector3.Zero(),o._deviceRoomRotationQuaternion=yo.Quaternion.Identity(),o._standingMatrix=null,o.devicePosition=yo.Vector3.Zero(),o.deviceRotationQuaternion=yo.Quaternion.Identity(),o.deviceScaleFactor=1,o._deviceToWorld=yo.Matrix.Identity(),o._worldToDevice=yo.Matrix.Identity(),o.controllers=[],o.onControllersAttachedObservable=new yo.Observable,o.onControllerMeshLoadedObservable=new yo.Observable,o.rigParenting=!0,o._defaultHeight=0,o.deviceDistanceToRoomGround=function(){return o._standingMatrix?(o._standingMatrix.getTranslationToRef(o._workingVector),o._deviceRoomPosition.y+o._workingVector.y):o._defaultHeight},o.useStandingMatrix=function(e){void 0===e&&(e=function(e){}),navigator&&navigator.getVRDisplays?navigator.getVRDisplays().then(function(t){t&&t[0]&&t[0].stageParameters&&t[0].stageParameters.sittingToStandingTransform?(o._standingMatrix=new yo.Matrix,yo.Matrix.FromFloat32ArrayToRefScaled(t[0].stageParameters.sittingToStandingTransform,0,1,o._standingMatrix),o.getScene().useRightHandedSystem||[2,6,8,9,14].forEach(function(e){o._standingMatrix&&(o._standingMatrix.m[e]*=-1)}),e(!0)):e(!1)}):e(!1)},o._workingVector=yo.Vector3.Zero(),o._oneVector=yo.Vector3.One(),o._workingMatrix=yo.Matrix.Identity(),o._cache.position=yo.Vector3.Zero(),n.defaultHeight&&(o._defaultHeight=n.defaultHeight,o.position.y=o._defaultHeight),o.minZ=.1,5===arguments.length&&(o.webVROptions=arguments[4]),void 0==o.webVROptions.trackPosition&&(o.webVROptions.trackPosition=!0),void 0==o.webVROptions.controllerMeshes&&(o.webVROptions.controllerMeshes=!0),void 0==o.webVROptions.defaultLightingOnControllers&&(o.webVROptions.defaultLightingOnControllers=!0),o.rotationQuaternion=new yo.Quaternion,o.webVROptions&&o.webVROptions.positionScale&&(o.deviceScaleFactor=o.webVROptions.positionScale);var s=o.getEngine();return o._onVREnabled=function(e){e&&o.initControllers()},s.onVRRequestPresentComplete.add(o._onVREnabled),s.initWebVR().add(function(e){e.vrDisplay&&o._vrDevice!==e.vrDisplay&&(o._vrDevice=e.vrDisplay,o.setCameraRigMode(yo.Camera.RIG_MODE_WEBVR,{parentCamera:o,vrDisplay:o._vrDevice,frameData:o._frameData,specs:o._specsVersion}),o._attached&&o.getEngine().enableVR())}),"undefined"!=typeof VRFrameData&&(o._frameData=new VRFrameData),r.onBeforeCameraRenderObservable.add(function(e){e.parent===o&&o.rigParenting&&(o._descendants=o.getDescendants(!0,function(e){var t=o.controllers.some(function(t){return t._mesh===e}),i=-1!==o._rigCameras.indexOf(e);return!t&&!i}),o._descendants.forEach(function(t){t.parent=e}))}),r.onAfterCameraRenderObservable.add(function(e){e.parent===o&&o.rigParenting&&o._descendants.forEach(function(e){e.parent=o})}),o}return Y(t,e),t.prototype.dispose=function(){this.getEngine().onVRRequestPresentComplete.removeCallback(this._onVREnabled),e.prototype.dispose.call(this)},t.prototype.getControllerByName=function(e){for(var t=0,i=this.controllers;t<i.length;t++){var r=i[t];if(r.hand===e)return r}return null},Object.defineProperty(t.prototype,"leftController",{get:function(){return this._leftController||(this._leftController=this.getControllerByName("left")),this._leftController},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rightController",{get:function(){return this._rightController||(this._rightController=this.getControllerByName("right")),this._rightController},enumerable:!0,configurable:!0}),t.prototype.getForwardRay=function(t){return void 0===t&&(t=100),this.leftCamera?e.prototype.getForwardRay.call(this,t,this.leftCamera.getWorldMatrix(),this.leftCamera.globalPosition):e.prototype.getForwardRay.call(this,t)},t.prototype._checkInputs=function(){this._vrDevice&&this._vrDevice.isPresenting&&(this._vrDevice.getFrameData(this._frameData),this.updateFromDevice(this._frameData.pose)),e.prototype._checkInputs.call(this)},t.prototype.updateFromDevice=function(e){e&&e.orientation&&(this.rawPose=e,this._deviceRoomRotationQuaternion.copyFromFloats(e.orientation[0],e.orientation[1],-e.orientation[2],-e.orientation[3]),this.getScene().useRightHandedSystem&&(this._deviceRoomRotationQuaternion.z*=-1,this._deviceRoomRotationQuaternion.w*=-1),this.webVROptions.trackPosition&&this.rawPose.position&&(this._deviceRoomPosition.copyFromFloats(this.rawPose.position[0],this.rawPose.position[1],-this.rawPose.position[2]),this.getScene().useRightHandedSystem&&(this._deviceRoomPosition.z*=-1)))},t.prototype.attachControl=function(t,i){e.prototype.attachControl.call(this,t,i),this._attached=!0,i=!yo.Camera.ForceAttachControlToAlwaysPreventDefault&&i,this._vrDevice&&this.getEngine().enableVR()},t.prototype.detachControl=function(t){this.getScene().gamepadManager.onGamepadConnectedObservable.remove(this._onGamepadConnectedObserver),this.getScene().gamepadManager.onGamepadDisconnectedObservable.remove(this._onGamepadDisconnectedObserver),e.prototype.detachControl.call(this,t),this._attached=!1,this.getEngine().disableVR()},t.prototype.getClassName=function(){return"WebVRFreeCamera"},t.prototype.resetToCurrentRotation=function(){this._vrDevice.resetPose()},t.prototype._updateRigCameras=function(){var e=this._rigCameras[0],t=this._rigCameras[1];e.rotationQuaternion.copyFrom(this._deviceRoomRotationQuaternion),t.rotationQuaternion.copyFrom(this._deviceRoomRotationQuaternion),e.position.copyFrom(this._deviceRoomPosition),t.position.copyFrom(this._deviceRoomPosition)},t.prototype._updateCache=function(t){var i=this;this.rotationQuaternion.equals(this._cache.rotationQuaternion)&&this.position.equals(this._cache.position)||(this.updateCacheCalled||(this.updateCacheCalled=!0,this.update()),this.rotationQuaternion.toRotationMatrix(this._workingMatrix),yo.Vector3.TransformCoordinatesToRef(this._deviceRoomPosition,this._workingMatrix,this._workingVector),this.devicePosition.subtractToRef(this._workingVector,this._workingVector),yo.Matrix.ComposeToRef(this._oneVector,this.rotationQuaternion,this._workingVector,this._deviceToWorld),this._deviceToWorld.getTranslationToRef(this._workingVector),this._workingVector.addInPlace(this.position),this._workingVector.subtractInPlace(this._cache.position),this._deviceToWorld.setTranslation(this._workingVector),this._deviceToWorld.invertToRef(this._worldToDevice),this.controllers.forEach(function(e){e._deviceToWorld=i._deviceToWorld,e.update()})),t||e.prototype._updateCache.call(this),this.updateCacheCalled=!1},t.prototype.update=function(){yo.Vector3.TransformCoordinatesToRef(this._deviceRoomPosition,this._deviceToWorld,this.devicePosition),yo.Matrix.FromQuaternionToRef(this._deviceRoomRotationQuaternion,this._workingMatrix),this._workingMatrix.multiplyToRef(this._deviceToWorld,this._workingMatrix),yo.Quaternion.FromRotationMatrixToRef(this._workingMatrix,this.deviceRotationQuaternion),e.prototype.update.call(this)},t.prototype._getViewMatrix=function(){return yo.Matrix.Identity()},t.prototype._getWebVRViewMatrix=function(){var e=this,t=this._cameraRigParams.left?this._cameraRigParams.frameData.leftViewMatrix:this._cameraRigParams.frameData.rightViewMatrix;yo.Matrix.FromArrayToRef(t,0,this._webvrViewMatrix),this.getScene().useRightHandedSystem||[2,6,8,9,14].forEach(function(t){e._webvrViewMatrix.m[t]*=-1}),this._webvrViewMatrix.getRotationMatrixToRef(this._cameraRotationMatrix),yo.Vector3.TransformCoordinatesToRef(this._referencePoint,this._cameraRotationMatrix,this._transformedReferencePoint),this.position.addToRef(this._transformedReferencePoint,this._currentTarget);var i=this._cameraRigParams.parentCamera;return 1!==i.deviceScaleFactor&&(this._webvrViewMatrix.invert(),i.deviceScaleFactor&&(this._webvrViewMatrix.m[12]*=i.deviceScaleFactor,this._webvrViewMatrix.m[13]*=i.deviceScaleFactor,this._webvrViewMatrix.m[14]*=i.deviceScaleFactor),this._webvrViewMatrix.invert()),i._worldToDevice.multiplyToRef(this._webvrViewMatrix,this._webvrViewMatrix),this._webvrViewMatrix},t.prototype._getWebVRProjectionMatrix=function(){var e=this,t=this.parent;t._vrDevice.depthNear=t.minZ,t._vrDevice.depthFar=t.maxZ;var i=this._cameraRigParams.left?this._cameraRigParams.frameData.leftProjectionMatrix:this._cameraRigParams.frameData.rightProjectionMatrix;return yo.Matrix.FromArrayToRef(i,0,this._projectionMatrix),this.getScene().useRightHandedSystem||[8,9,10,11].forEach(function(t){e._projectionMatrix.m[t]*=-1}),this._projectionMatrix},t.prototype.initControllers=function(){var e=this;this.controllers=[];var t=this.getScene().gamepadManager;this._onGamepadDisconnectedObserver=t.onGamepadDisconnectedObservable.add(function(t){if(t.type===yo.Gamepad.POSE_ENABLED){var i=t;i.defaultModel&&i.defaultModel.setEnabled(!1),"right"===i.hand&&(e._rightController=null),"left"===i.hand&&(e._rightController=null);var r=e.controllers.indexOf(i);-1!==r&&e.controllers.splice(r,1)}}),this._onGamepadConnectedObserver=t.onGamepadConnectedObservable.add(function(t){if(t.type===yo.Gamepad.POSE_ENABLED){var i=t;if(i._deviceToWorld=e._deviceToWorld,e.webVROptions.controllerMeshes&&(i.defaultModel?i.defaultModel.setEnabled(!0):i.initControllerMesh(e.getScene(),function(t){if(e.onControllerMeshLoadedObservable.notifyObservers(i),e.webVROptions.defaultLightingOnControllers){e._lightOnControllers||(e._lightOnControllers=new yo.HemisphericLight("vrControllersLight",new yo.Vector3(0,1,0),e.getScene()));var r=function(e,t){var i=e.getChildren();0!==i.length&&i.forEach(function(e){t.includedOnlyMeshes.push(e),r(e,t)})};e._lightOnControllers.includedOnlyMeshes.push(t),r(t,e._lightOnControllers)}})),i.attachToPoseControlledCamera(e),-1===e.controllers.indexOf(i)){e.controllers.push(i);for(var r=!1,n=0;n<e.controllers.length;n++)e.controllers[n].controllerType===yo.PoseEnabledControllerType.VIVE&&(r?e.controllers[n].hand="right":(r=!0,e.controllers[n].hand="left"));e.controllers.length>=2&&e.onControllersAttachedObservable.notifyObservers(e.controllers)}}})},t}(yo.FreeCamera),yo.WebVRFreeCamera=bo,xo=us||(us={}),To=function(e){function t(t,i,r){var n=e.call(this,t,i,r)||this;return n._quaternionCache=new xo.Quaternion,n.inputs.addDeviceOrientation(),n}return Y(t,e),t.prototype.getClassName=function(){return"DeviceOrientationCamera"},t.prototype._checkInputs=function(){e.prototype._checkInputs.call(this),this._quaternionCache.copyFrom(this.rotationQuaternion),this._initialQuaternion&&this._initialQuaternion.multiplyToRef(this.rotationQuaternion,this.rotationQuaternion)},t.prototype.resetToCurrentRotation=function(e){var t=this;void 0===e&&(e=xo.Axis.Y),this.rotationQuaternion&&(this._initialQuaternion||(this._initialQuaternion=new xo.Quaternion),this._initialQuaternion.copyFrom(this._quaternionCache||this.rotationQuaternion),["x","y","z"].forEach(function(i){e[i]?t._initialQuaternion[i]*=-1:t._initialQuaternion[i]=0}),this._initialQuaternion.normalize(),this._initialQuaternion.multiplyToRef(this.rotationQuaternion,this.rotationQuaternion))},t}(xo.FreeCamera),xo.DeviceOrientationCamera=To,function(e){var t=function(t){function i(i,r,n,o,s){void 0===o&&(o=!0),void 0===s&&(s=e.VRCameraMetrics.GetDefault());var a=t.call(this,i,r,n)||this;return s.compensateDistortion=o,a.setCameraRigMode(e.Camera.RIG_MODE_VR,{vrCameraMetrics:s}),a}return Y(i,t),i.prototype.getClassName=function(){return"VRDeviceOrientationFreeCamera"},i}(e.DeviceOrientationCamera);e.VRDeviceOrientationFreeCamera=t;var i=function(t){function i(i,r,n,o,s){void 0===o&&(o=!0),void 0===s&&(s=e.VRCameraMetrics.GetDefault());var a=t.call(this,i,r,n,o,s)||this;return a.inputs.addGamepad(),a}return Y(i,t),i.prototype.getClassName=function(){return"VRDeviceOrientationGamepadCamera"},i}(t);e.VRDeviceOrientationGamepadCamera=i;var r=function(t){function i(i,r,n,o,s,a,h,l){void 0===h&&(h=!0),void 0===l&&(l=e.VRCameraMetrics.GetDefault());var c=t.call(this,i,r,n,o,s,a)||this;return l.compensateDistortion=h,c.setCameraRigMode(e.Camera.RIG_MODE_VR,{vrCameraMetrics:l}),c.inputs.addVRDeviceOrientation(),c}return Y(i,t),i.prototype.getClassName=function(){return"VRDeviceOrientationArcRotateCamera"},i}(e.ArcRotateCamera);e.VRDeviceOrientationArcRotateCamera=r}(us||(us={})),function(e){var t=function(t){function i(i,r,n,o){var s=t.call(this,i,r,o)||this;return s.interaxialDistance=n,s.setCameraRigMode(e.Camera.RIG_MODE_STEREOSCOPIC_ANAGLYPH,{interaxialDistance:n}),s}return Y(i,t),i.prototype.getClassName=function(){return"AnaglyphFreeCamera"},i}(e.FreeCamera);e.AnaglyphFreeCamera=t;var i=function(t){function i(i,r,n,o,s,a,h){var l=t.call(this,i,r,n,o,s,h)||this;return l.interaxialDistance=a,l.setCameraRigMode(e.Camera.RIG_MODE_STEREOSCOPIC_ANAGLYPH,{interaxialDistance:a}),l}return Y(i,t),i.prototype.getClassName=function(){return"AnaglyphArcRotateCamera"},i}(e.ArcRotateCamera);e.AnaglyphArcRotateCamera=i;var r=function(t){function i(i,r,n,o){var s=t.call(this,i,r,o)||this;return s.interaxialDistance=n,s.setCameraRigMode(e.Camera.RIG_MODE_STEREOSCOPIC_ANAGLYPH,{interaxialDistance:n}),s}return Y(i,t),i.prototype.getClassName=function(){return"AnaglyphGamepadCamera"},i}(e.GamepadCamera);e.AnaglyphGamepadCamera=r;var n=function(t){function i(i,r,n,o){var s=t.call(this,i,r,o)||this;return s.interaxialDistance=n,s.setCameraRigMode(e.Camera.RIG_MODE_STEREOSCOPIC_ANAGLYPH,{interaxialDistance:n}),s}return Y(i,t),i.prototype.getClassName=function(){return"AnaglyphUniversalCamera"},i}(e.UniversalCamera);e.AnaglyphUniversalCamera=n;var o=function(t){function i(i,r,n,o,s){var a=t.call(this,i,r,s)||this;return a.interaxialDistance=n,a.isStereoscopicSideBySide=o,a.setCameraRigMode(o?e.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL:e.Camera.RIG_MODE_STEREOSCOPIC_OVERUNDER,{interaxialDistance:n}),a}return Y(i,t),i.prototype.getClassName=function(){return"StereoscopicFreeCamera"},i}(e.FreeCamera);e.StereoscopicFreeCamera=o;var s=function(t){function i(i,r,n,o,s,a,h,l){var c=t.call(this,i,r,n,o,s,l)||this;return c.interaxialDistance=a,c.isStereoscopicSideBySide=h,c.setCameraRigMode(h?e.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL:e.Camera.RIG_MODE_STEREOSCOPIC_OVERUNDER,{interaxialDistance:a}),c}return Y(i,t),i.prototype.getClassName=function(){return"StereoscopicArcRotateCamera"},i}(e.ArcRotateCamera);e.StereoscopicArcRotateCamera=s;var a=function(t){function i(i,r,n,o,s){var a=t.call(this,i,r,s)||this;return a.interaxialDistance=n,a.isStereoscopicSideBySide=o,a.setCameraRigMode(o?e.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL:e.Camera.RIG_MODE_STEREOSCOPIC_OVERUNDER,{interaxialDistance:n}),a}return Y(i,t),i.prototype.getClassName=function(){return"StereoscopicGamepadCamera"},i}(e.GamepadCamera);e.StereoscopicGamepadCamera=a;var h=function(t){function i(i,r,n,o,s){var a=t.call(this,i,r,s)||this;return a.interaxialDistance=n,a.isStereoscopicSideBySide=o,a.setCameraRigMode(o?e.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL:e.Camera.RIG_MODE_STEREOSCOPIC_OVERUNDER,{interaxialDistance:n}),a}return Y(i,t),i.prototype.getClassName=function(){return"StereoscopicUniversalCamera"},i}(e.UniversalCamera);e.StereoscopicUniversalCamera=h}(us||(us={})),Eo=us||(us={}),Ao=function(){function e(e,t){void 0===t&&(t={});var i=this;if(this.webVROptions=t,this._webVRsupported=!1,this._webVRready=!1,this._webVRrequesting=!1,this._webVRpresenting=!1,this._fullscreenVRpresenting=!1,this.onEnteringVRObservable=new Eo.Observable,this.onExitingVRObservable=new Eo.Observable,this.onControllerMeshLoadedObservable=new Eo.Observable,this._useCustomVRButton=!1,this._teleportationRequested=!1,this._teleportationEnabledOnLeftController=!1,this._teleportationEnabledOnRightController=!1,this._interactionsEnabledOnLeftController=!1,this._interactionsEnabledOnRightController=!1,this._leftControllerReady=!1,this._rightControllerReady=!1,this._floorMeshesCollection=[],this._teleportationAllowed=!1,this._rotationAllowed=!0,this._teleportationRequestInitiated=!1,this._teleportationBackRequestInitiated=!1,this.teleportBackwardsVector=new Eo.Vector3(0,-1,-1),this._rotationRightAsked=!1,this._rotationLeftAsked=!1,this._isDefaultTeleportationTarget=!0,this._teleportationFillColor="#444444",this._teleportationBorderColor="#FFFFFF",this._rotationAngle=0,this._haloCenter=new Eo.Vector3(0,0,0),this._padSensibilityUp=.65,this._padSensibilityDown=.35,this.onNewMeshSelected=new Eo.Observable,this.onNewMeshPicked=new Eo.Observable,this.onBeforeCameraTeleport=new Eo.Observable,this.onAfterCameraTeleport=new Eo.Observable,this.onSelectedMeshUnselected=new Eo.Observable,this.teleportationEnabled=!0,this._pointerDownOnMeshAsked=!1,this._isActionableMesh=!1,this._teleportationInitialized=!1,this._interactionsEnabled=!1,this._interactionsRequested=!1,this._displayGaze=!0,this._displayLaserPointer=!0,this._dpadPressed=!0,this._onResize=function(){i.moveButtonToBottomRight(),i._fullscreenVRpresenting&&i._webVRready&&i.exitVR()},this._onFullscreenChange=function(){void 0!==document.fullscreen?i._fullscreenVRpresenting=document.fullscreen:void 0!==document.mozFullScreen?i._fullscreenVRpresenting=document.mozFullScreen:void 0!==document.webkitIsFullScreen?i._fullscreenVRpresenting=document.webkitIsFullScreen:void 0!==document.msIsFullScreen&&(i._fullscreenVRpresenting=document.msIsFullScreen),!i._fullscreenVRpresenting&&i._canvas&&(i.exitVR(),i._useCustomVRButton||(i._btnVR.style.top=i._canvas.offsetTop+i._canvas.offsetHeight-70+"px",i._btnVR.style.left=i._canvas.offsetLeft+i._canvas.offsetWidth-100+"px"))},this.beforeRender=function(){i._castRayAndSelectObject()},this._onNewGamepadConnected=function(e){if(e.type!==Eo.Gamepad.POSE_ENABLED)e.leftStick&&e.onleftstickchanged(function(e){i._teleportationInitialized&&i.teleportationEnabled&&(!i._leftLaserPointer&&!i._rightLaserPointer||i._leftLaserPointer&&!i._leftLaserPointer.isVisible&&i._rightLaserPointer&&!i._rightLaserPointer.isVisible)&&(i._checkTeleportWithRay(e),i._checkTeleportBackwards(e))}),e.rightStick&&e.onrightstickchanged(function(e){i._teleportationInitialized&&i._checkRotate(e)}),e.type===Eo.Gamepad.XBOX&&(e.onbuttondown(function(e){i._interactionsEnabled&&e===Eo.Xbox360Button.A&&i._selectionPointerDown()}),e.onbuttonup(function(e){i._interactionsEnabled&&e===Eo.Xbox360Button.A&&i._selectionPointerUp()}));else{var t=e;i._tryEnableInteractionOnController(t)}},this._tryEnableInteractionOnController=function(e){"left"===e.hand&&(i._leftControllerReady=!0,i._interactionsRequested&&!i._interactionsEnabledOnLeftController&&i._enableInteractionOnController(e),i._teleportationRequested&&!i._teleportationEnabledOnLeftController&&i._enableTeleportationOnController(e)),"right"===e.hand&&(i._rightControllerReady=!0,i._interactionsRequested&&!i._interactionsEnabledOnRightController&&i._enableInteractionOnController(e),i._teleportationRequested&&!i._teleportationEnabledOnRightController&&i._enableTeleportationOnController(e))},this._onNewGamepadDisconnected=function(e){e instanceof Eo.WebVRController&&("left"===e.hand&&(i._interactionsEnabledOnLeftController=!1,i._teleportationEnabledOnLeftController=!1,i._leftControllerReady=!1,i._leftLaserPointer&&i._leftLaserPointer.dispose()),"right"===e.hand&&(i._interactionsEnabledOnRightController=!1,i._teleportationEnabledOnRightController=!1,i._rightControllerReady=!1,i._rightLaserPointer&&i._rightLaserPointer.dispose()))},this._workingVector=Eo.Vector3.Zero(),this._workingQuaternion=Eo.Quaternion.Identity(),this._workingMatrix=Eo.Matrix.Identity(),this._scene=e,this._canvas=e.getEngine().getRenderingCanvas(),void 0===t.createFallbackVRDeviceOrientationFreeCamera&&(t.createFallbackVRDeviceOrientationFreeCamera=!0),void 0===t.createDeviceOrientationCamera&&(t.createDeviceOrientationCamera=!0),void 0===t.defaultHeight&&(t.defaultHeight=1.7),t.useCustomVRButton&&(this._useCustomVRButton=!0,t.customVRButton&&(this._btnVR=t.customVRButton)),t.rayLength&&(this._rayLength=t.rayLength),this._defaultHeight=t.defaultHeight,this._scene.activeCamera?this._position=this._scene.activeCamera.position.clone():this._position=new Eo.Vector3(0,this._defaultHeight,0),t.createDeviceOrientationCamera||!this._scene.activeCamera){if(this._deviceOrientationCamera=new Eo.DeviceOrientationCamera("deviceOrientationVRHelper",this._position.clone(),e),this._scene.activeCamera&&(this._deviceOrientationCamera.minZ=this._scene.activeCamera.minZ,this._deviceOrientationCamera.maxZ=this._scene.activeCamera.maxZ,this._scene.activeCamera instanceof Eo.TargetCamera&&this._scene.activeCamera.rotation)){var r=this._scene.activeCamera;r.rotationQuaternion?this._deviceOrientationCamera.rotationQuaternion.copyFrom(r.rotationQuaternion):this._deviceOrientationCamera.rotationQuaternion.copyFrom(Eo.Quaternion.RotationYawPitchRoll(r.rotation.y,r.rotation.x,r.rotation.z)),this._deviceOrientationCamera.rotation=r.rotation.clone()}this._scene.activeCamera=this._deviceOrientationCamera,this._canvas&&this._scene.activeCamera.attachControl(this._canvas)}else this._existingCamera=this._scene.activeCamera;if(t.createFallbackVRDeviceOrientationFreeCamera&&(this._vrDeviceOrientationCamera=new Eo.VRDeviceOrientationFreeCamera("VRDeviceOrientationVRHelper",this._position,this._scene)),this._webVRCamera=new Eo.WebVRFreeCamera("WebVRHelper",this._position,this._scene,t),this._webVRCamera.useStandingMatrix(),!this._useCustomVRButton){this._btnVR=document.createElement("BUTTON"),this._btnVR.className="babylonVRicon",this._btnVR.id="babylonVRiconbtn",this._btnVR.title="Click to switch to VR";var n=".babylonVRicon { position: absolute; right: 20px; height: 50px; width: 80px; background-color: rgba(51,51,51,0.7); background-image: url(data:image/svg+xml;charset=UTF-8,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20width%3D%222048%22%20height%3D%221152%22%20viewBox%3D%220%200%202048%201152%22%20version%3D%221.1%22%3E%3Cpath%20transform%3D%22rotate%28180%201024%2C576.0000000000001%29%22%20d%3D%22m1109%2C896q17%2C0%2030%2C-12t13%2C-30t-12.5%2C-30.5t-30.5%2C-12.5l-170%2C0q-18%2C0%20-30.5%2C12.5t-12.5%2C30.5t13%2C30t30%2C12l170%2C0zm-85%2C256q59%2C0%20132.5%2C-1.5t154.5%2C-5.5t164.5%2C-11.5t163%2C-20t150%2C-30t124.5%2C-41.5q23%2C-11%2042%2C-24t38%2C-30q27%2C-25%2041%2C-61.5t14%2C-72.5l0%2C-257q0%2C-123%20-47%2C-232t-128%2C-190t-190%2C-128t-232%2C-47l-81%2C0q-37%2C0%20-68.5%2C14t-60.5%2C34.5t-55.5%2C45t-53%2C45t-53%2C34.5t-55.5%2C14t-55.5%2C-14t-53%2C-34.5t-53%2C-45t-55.5%2C-45t-60.5%2C-34.5t-68.5%2C-14l-81%2C0q-123%2C0%20-232%2C47t-190%2C128t-128%2C190t-47%2C232l0%2C257q0%2C68%2038%2C115t97%2C73q54%2C24%20124.5%2C41.5t150%2C30t163%2C20t164.5%2C11.5t154.5%2C5.5t132.5%2C1.5zm939%2C-298q0%2C39%20-24.5%2C67t-58.5%2C42q-54%2C23%20-122%2C39.5t-143.5%2C28t-155.5%2C19t-157%2C11t-148.5%2C5t-129.5%2C1.5q-59%2C0%20-130%2C-1.5t-148%2C-5t-157%2C-11t-155.5%2C-19t-143.5%2C-28t-122%2C-39.5q-34%2C-14%20-58.5%2C-42t-24.5%2C-67l0%2C-257q0%2C-106%2040.5%2C-199t110%2C-162.5t162.5%2C-109.5t199%2C-40l81%2C0q27%2C0%2052%2C14t50%2C34.5t51%2C44.5t55.5%2C44.5t63.5%2C34.5t74%2C14t74%2C-14t63.5%2C-34.5t55.5%2C-44.5t51%2C-44.5t50%2C-34.5t52%2C-14l14%2C0q37%2C0%2070%2C0.5t64.5%2C4.5t63.5%2C12t68%2C23q71%2C30%20128.5%2C78.5t98.5%2C110t63.5%2C133.5t22.5%2C149l0%2C257z%22%20fill%3D%22white%22%20/%3E%3C/svg%3E%0A); background-size: 80%; background-repeat:no-repeat; background-position: center; border: none; outline: none; transition: transform 0.125s ease-out } .babylonVRicon:hover { transform: scale(1.05) } .babylonVRicon:active {background-color: rgba(51,51,51,1) } .babylonVRicon:focus {background-color: rgba(51,51,51,1) }";n+=".babylonVRicon.vrdisplaypresenting { display: none; }";var o=document.createElement("style");o.appendChild(document.createTextNode(n)),document.getElementsByTagName("head")[0].appendChild(o),this.moveButtonToBottomRight()}this._btnVR&&this._btnVR.addEventListener("click",function(){i.isInVRMode?i.exitVR():i.enterVR()}),window.addEventListener("resize",this._onResize),document.addEventListener("fullscreenchange",this._onFullscreenChange,!1),document.addEventListener("mozfullscreenchange",this._onFullscreenChange,!1),document.addEventListener("webkitfullscreenchange",this._onFullscreenChange,!1),document.addEventListener("msfullscreenchange",this._onFullscreenChange,!1),t.createFallbackVRDeviceOrientationFreeCamera?this.displayVRButton():this._scene.getEngine().onVRDisplayChangedObservable.add(function(e){e.vrDisplay&&i.displayVRButton()}),this._onKeyDown=function(e){27===e.keyCode&&i.isInVRMode&&i.exitVR()},document.addEventListener("keydown",this._onKeyDown),this._scene.onPrePointerObservable.add(function(e,t){i.isInVRMode&&(i.exitVR(),i._fullscreenVRpresenting&&i._scene.getEngine().switchFullscreen(!0))},Eo.PointerEventTypes.POINTERDOUBLETAP,!1),this._onVRDisplayChanged=function(e){return i.onVRDisplayChanged(e)},this._onVrDisplayPresentChange=function(){return i.onVrDisplayPresentChange()},this._onVRRequestPresentStart=function(){i._webVRrequesting=!0,i.updateButtonVisibility()},this._onVRRequestPresentComplete=function(e){i._webVRrequesting=!1,i.updateButtonVisibility()},e.getEngine().onVRDisplayChangedObservable.add(this._onVRDisplayChanged),e.getEngine().onVRRequestPresentStart.add(this._onVRRequestPresentStart),e.getEngine().onVRRequestPresentComplete.add(this._onVRRequestPresentComplete),window.addEventListener("vrdisplaypresentchange",this._onVrDisplayPresentChange),e.onDisposeObservable.add(function(){i.dispose()}),this._webVRCamera.onControllerMeshLoadedObservable.add(function(e){return i._onDefaultMeshLoaded(e)}),this._scene.gamepadManager.onGamepadConnectedObservable.add(this._onNewGamepadConnected),this._scene.gamepadManager.onGamepadDisconnectedObservable.add(this._onNewGamepadDisconnected),this.updateButtonVisibility(),this._circleEase=new Eo.CircleEase,this._circleEase.setEasingMode(Eo.EasingFunction.EASINGMODE_EASEINOUT)}return Object.defineProperty(e.prototype,"onEnteringVR",{get:function(){return this.onEnteringVRObservable},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"onExitingVR",{get:function(){return this.onExitingVRObservable},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"onControllerMeshLoaded",{get:function(){return this.onControllerMeshLoadedObservable},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"teleportationTarget",{get:function(){return this._teleportationTarget},set:function(e){e&&(e.name="teleportationTarget",this._isDefaultTeleportationTarget=!1,this._teleportationTarget=e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"displayGaze",{get:function(){return this._displayGaze},set:function(e){this._displayGaze=e,e||(this._gazeTracker.isVisible=!1)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"displayLaserPointer",{get:function(){return this._displayLaserPointer},set:function(e){this._displayLaserPointer=e,e?this._rightLaserPointer?this._rightLaserPointer.isVisible=!0:this._leftLaserPointer&&(this._leftLaserPointer.isVisible=!0):(this._rightLaserPointer&&(this._rightLaserPointer.isVisible=!1),this._leftLaserPointer&&(this._leftLaserPointer.isVisible=!1))},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"deviceOrientationCamera",{get:function(){return this._deviceOrientationCamera},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"currentVRCamera",{get:function(){return this._webVRready?this._webVRCamera:this._scene.activeCamera},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"webVRCamera",{get:function(){return this._webVRCamera},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"vrDeviceOrientationCamera",{get:function(){return this._vrDeviceOrientationCamera},enumerable:!0,configurable:!0}),e.prototype._onDefaultMeshLoaded=function(e){this._tryEnableInteractionOnController(e);try{this.onControllerMeshLoadedObservable.notifyObservers(e)}catch(e){Eo.Tools.Warn("Error in your custom logic onControllerMeshLoaded: "+e)}},Object.defineProperty(e.prototype,"isInVRMode",{get:function(){return this._webVRpresenting||this._fullscreenVRpresenting},enumerable:!0,configurable:!0}),e.prototype.onVrDisplayPresentChange=function(){var e=this._scene.getEngine().getVRDevice();if(e){var t=this._webVRpresenting;this._webVRpresenting=e.isPresenting,t&&!this._webVRpresenting&&this.exitVR()}else Eo.Tools.Warn("Detected VRDisplayPresentChange on an unknown VRDisplay. Did you can enterVR on the vrExperienceHelper?");this.updateButtonVisibility()},e.prototype.onVRDisplayChanged=function(e){this._webVRsupported=e.vrSupported,this._webVRready=!!e.vrDisplay,this._webVRpresenting=e.vrDisplay&&e.vrDisplay.isPresenting,this.updateButtonVisibility()},e.prototype.moveButtonToBottomRight=function(){this._canvas&&!this._useCustomVRButton&&(this._btnVR.style.top=this._canvas.offsetTop+this._canvas.offsetHeight-70+"px",this._btnVR.style.left=this._canvas.offsetLeft+this._canvas.offsetWidth-100+"px")},e.prototype.displayVRButton=function(){this._useCustomVRButton||this._btnVRDisplayed||(document.body.appendChild(this._btnVR),this._btnVRDisplayed=!0)},e.prototype.updateButtonVisibility=function(){this._btnVR&&!this._useCustomVRButton&&(this._btnVR.className="babylonVRicon",this.isInVRMode?this._btnVR.className+=" vrdisplaypresenting":(this._webVRready&&(this._btnVR.className+=" vrdisplayready"),this._webVRsupported&&(this._btnVR.className+=" vrdisplaysupported"),this._webVRrequesting&&(this._btnVR.className+=" vrdisplayrequesting")))},e.prototype.enterVR=function(){if(this.onEnteringVRObservable)try{this.onEnteringVRObservable.notifyObservers(this)}catch(e){Eo.Tools.Warn("Error in your custom logic onEnteringVR: "+e)}this._scene.activeCamera&&(this._position=this._scene.activeCamera.position.clone(),this._existingCamera=this._scene.activeCamera),this._webVRrequesting||(this._webVRready?this._webVRpresenting||(this._webVRCamera.position=this._position,this._scene.activeCamera=this._webVRCamera):this._vrDeviceOrientationCamera&&(this._vrDeviceOrientationCamera.position=this._position,this._scene.activeCamera=this._vrDeviceOrientationCamera,this._scene.getEngine().switchFullscreen(!0),this.updateButtonVisibility()),this._scene.activeCamera&&this._canvas&&this._scene.activeCamera.attachControl(this._canvas),this._interactionsEnabled&&this._scene.registerBeforeRender(this.beforeRender))},e.prototype.exitVR=function(){if(this.onExitingVRObservable)try{this.onExitingVRObservable.notifyObservers(this)}catch(e){Eo.Tools.Warn("Error in your custom logic onExitingVR: "+e)}this._webVRpresenting&&this._scene.getEngine().disableVR(),this._scene.activeCamera&&(this._position=this._scene.activeCamera.position.clone()),this._deviceOrientationCamera?(this._deviceOrientationCamera.position=this._position,this._scene.activeCamera=this._deviceOrientationCamera,this._canvas&&this._scene.activeCamera.attachControl(this._canvas)):this._existingCamera&&(this._existingCamera.position=this._position,this._scene.activeCamera=this._existingCamera),this.updateButtonVisibility(),this._interactionsEnabled&&this._scene.unregisterBeforeRender(this.beforeRender)},Object.defineProperty(e.prototype,"position",{get:function(){return this._position},set:function(e){this._position=e,this._scene.activeCamera&&(this._scene.activeCamera.position=e)},enumerable:!0,configurable:!0}),e.prototype.enableInteractions=function(){var e=this;this._interactionsEnabled||(this._interactionsRequested=!0,this._leftControllerReady&&this._webVRCamera.leftController&&this._enableInteractionOnController(this._webVRCamera.leftController),this._rightControllerReady&&this._webVRCamera.rightController&&this._enableInteractionOnController(this._webVRCamera.rightController),this._createGazeTracker(),this.raySelectionPredicate=function(e){return e.isVisible},this.meshSelectionPredicate=function(e){return!0},this._raySelectionPredicate=function(t){return!!(e._isTeleportationFloor(t)||-1===t.name.indexOf("gazeTracker")&&-1===t.name.indexOf("teleportationTarget")&&-1===t.name.indexOf("torusTeleportation")&&-1===t.name.indexOf("laserPointer"))&&e.raySelectionPredicate(t)},this._interactionsEnabled=!0)},e.prototype._isTeleportationFloor=function(e){for(var t=0;t<this._floorMeshesCollection.length;t++)if(this._floorMeshesCollection[t].id===e.id)return!0;return!(!this._floorMeshName||e.name!==this._floorMeshName)},e.prototype.addFloorMesh=function(e){this._floorMeshesCollection&&(this._floorMeshesCollection.indexOf(e)>-1||this._floorMeshesCollection.push(e))},e.prototype.removeFloorMesh=function(e){if(this._floorMeshesCollection){var t=this._floorMeshesCollection.indexOf(e);-1!==t&&this._floorMeshesCollection.splice(t,1)}},e.prototype.enableTeleportation=function(e){if(void 0===e&&(e={}),!this._teleportationInitialized){this._teleportationRequested=!0,this.enableInteractions(),e.floorMeshName&&(this._floorMeshName=e.floorMeshName),e.floorMeshes&&(this._floorMeshesCollection=e.floorMeshes),this._leftControllerReady&&this._webVRCamera.leftController&&this._enableTeleportationOnController(this._webVRCamera.leftController),this._rightControllerReady&&this._webVRCamera.rightController&&this._enableTeleportationOnController(this._webVRCamera.rightController);var t=new Eo.ImageProcessingConfiguration;t.vignetteColor=new Eo.Color4(0,0,0,0),t.vignetteEnabled=!0,this._postProcessMove=new Eo.ImageProcessingPostProcess("postProcessMove",1,this._webVRCamera,void 0,void 0,void 0,void 0,t),this._webVRCamera.detachPostProcess(this._postProcessMove),this._passProcessMove=new Eo.PassPostProcess("pass",1,this._webVRCamera),this._teleportationInitialized=!0,this._isDefaultTeleportationTarget&&this._createTeleportationCircles()}},e.prototype._enableInteractionOnController=function(e){var t=this,i=e.mesh;if(i){var r=function(e){e.name+=" laserPointer",e.getChildMeshes().forEach(function(e){r(e)})};r(i);for(var n=i.getChildMeshes(),o=0;o<n.length;o++)if(n[o].name&&n[o].name.indexOf("POINTING_POSE")>=0){i=n[o];break}var s=Eo.Mesh.CreateCylinder("laserPointer",1,.004,2e-4,20,1,this._scene,!1),a=new Eo.StandardMaterial("laserPointerMat",this._scene);a.emissiveColor=new Eo.Color3(.7,.7,.7),a.alpha=.6,s.material=a,s.rotation.x=Math.PI/2,s.parent=i,s.position.z=-.5,s.isVisible=!1,"left"===e.hand?(this._leftLaserPointer=s,this._interactionsEnabledOnLeftController=!0,this._rightLaserPointer||(this._leftLaserPointer.isVisible=!0)):(this._rightLaserPointer=s,this._interactionsEnabledOnRightController=!0,this._leftLaserPointer||(this._rightLaserPointer.isVisible=!0)),e.onMainButtonStateChangedObservable.add(function(i){t._displayLaserPointer&&1===i.value&&(s.isVisible=!s.isVisible,"left"===e.hand&&t._rightLaserPointer?t._rightLaserPointer.isVisible=!1:t._leftLaserPointer&&(t._leftLaserPointer.isVisible=!1))}),e.onTriggerStateChangedObservable.add(function(e){t._pointerDownOnMeshAsked?e.value<t._padSensibilityDown&&t._selectionPointerUp():e.value>t._padSensibilityUp&&t._selectionPointerDown()})}},e.prototype._checkTeleportWithRay=function(e,t){void 0===t&&(t=null),this._teleportationRequestInitiated?(null==t||"left"===t.hand&&this._leftLaserPointer&&this._leftLaserPointer.isVisible||"right"===t.hand&&this._rightLaserPointer&&this._rightLaserPointer.isVisible)&&Math.sqrt(e.y*e.y+e.x*e.x)<this._padSensibilityDown&&(this._teleportationAllowed&&(this._teleportationAllowed=!1,this._teleportCamera()),this._teleportationRequestInitiated=!1):e.y<-this._padSensibilityUp&&this._dpadPressed&&(t&&(this._displayLaserPointer&&"left"===t.hand&&this._leftLaserPointer?(this._leftLaserPointer.isVisible=!0,this._rightLaserPointer&&(this._rightLaserPointer.isVisible=!1)):this._displayLaserPointer&&this._rightLaserPointer&&(this._rightLaserPointer.isVisible=!0,this._leftLaserPointer&&(this._leftLaserPointer.isVisible=!1))),this._teleportationRequestInitiated=!0)},e.prototype._selectionPointerDown=function(){this._pointerDownOnMeshAsked=!0,this._currentMeshSelected&&this._currentHit&&this._scene.simulatePointerDown(this._currentHit)},e.prototype._selectionPointerUp=function(){this._currentMeshSelected&&this._currentHit&&this._scene.simulatePointerUp(this._currentHit),this._pointerDownOnMeshAsked=!1},e.prototype._checkRotate=function(e){this._teleportationRequestInitiated||(this._rotationLeftAsked?e.x>-this._padSensibilityDown&&(this._rotationLeftAsked=!1):e.x<-this._padSensibilityUp&&this._dpadPressed&&(this._rotationLeftAsked=!0,this._rotationAllowed&&this._rotateCamera(!1)),this._rotationRightAsked?e.x<this._padSensibilityDown&&(this._rotationRightAsked=!1):e.x>this._padSensibilityUp&&this._dpadPressed&&(this._rotationRightAsked=!0,this._rotationAllowed&&this._rotateCamera(!0)))},e.prototype._checkTeleportBackwards=function(e){if(!this._teleportationRequestInitiated)if(e.y>this._padSensibilityUp&&this._dpadPressed){if(!this._teleportationBackRequestInitiated){if(!this.currentVRCamera)return;var t=Eo.Quaternion.FromRotationMatrix(this.currentVRCamera.getWorldMatrix().getRotationMatrix()),i=this.currentVRCamera.position;this.currentVRCamera.devicePosition&&this.currentVRCamera.deviceRotationQuaternion&&(t=this.currentVRCamera.deviceRotationQuaternion,i=this.currentVRCamera.devicePosition),t.toEulerAnglesToRef(this._workingVector),this._workingVector.z=0,this._workingVector.x=0,Eo.Quaternion.RotationYawPitchRollToRef(this._workingVector.y,this._workingVector.x,this._workingVector.z,this._workingQuaternion),this._workingQuaternion.toRotationMatrix(this._workingMatrix),Eo.Vector3.TransformCoordinatesToRef(this.teleportBackwardsVector,this._workingMatrix,this._workingVector);var r=new Eo.Ray(i,this._workingVector),n=this._scene.pickWithRay(r,this._raySelectionPredicate);n&&n.pickedPoint&&n.pickedMesh&&this._isTeleportationFloor(n.pickedMesh)&&n.distance<5&&this._teleportCamera(n.pickedPoint),this._teleportationBackRequestInitiated=!0}}else this._teleportationBackRequestInitiated=!1},e.prototype._enableTeleportationOnController=function(e){var t=this;e.mesh&&("left"===e.hand?(this._interactionsEnabledOnLeftController||this._enableInteractionOnController(e),this._teleportationEnabledOnLeftController=!0):(this._interactionsEnabledOnRightController||this._enableInteractionOnController(e),this._teleportationEnabledOnRightController=!0),e.controllerType===Eo.PoseEnabledControllerType.VIVE&&(this._dpadPressed=!1,e.onPadStateChangedObservable.add(function(e){t._dpadPressed=e.pressed,t._dpadPressed||(t._rotationLeftAsked=!1,t._rotationRightAsked=!1,t._teleportationBackRequestInitiated=!1)})),e.onPadValuesChangedObservable.add(function(i){t.teleportationEnabled&&(t._checkTeleportBackwards(i),t._checkTeleportWithRay(i,e)),t._checkRotate(i)}))},e.prototype._createGazeTracker=function(){this._gazeTracker=Eo.Mesh.CreateTorus("gazeTracker",.0035,.0025,20,this._scene,!1),this._gazeTracker.bakeCurrentTransformIntoVertices(),this._gazeTracker.isPickable=!1,this._gazeTracker.isVisible=!1;var e=new Eo.StandardMaterial("targetMat",this._scene);e.specularColor=Eo.Color3.Black(),e.emissiveColor=new Eo.Color3(.7,.7,.7),e.backFaceCulling=!1,this._gazeTracker.material=e},e.prototype._createTeleportationCircles=function(){this._teleportationTarget=Eo.Mesh.CreateGround("teleportationTarget",2,2,2,this._scene),this._teleportationTarget.isPickable=!1;var e=new Eo.DynamicTexture("DynamicTexture",512,this._scene,!0);e.hasAlpha=!0;var t=e.getContext();t.beginPath(),t.arc(256,256,200,0,2*Math.PI,!1),t.fillStyle=this._teleportationFillColor,t.fill(),t.lineWidth=10,t.strokeStyle=this._teleportationBorderColor,t.stroke(),t.closePath(),e.update();var i=new Eo.StandardMaterial("TextPlaneMaterial",this._scene);i.diffuseTexture=e,this._teleportationTarget.material=i;var r=Eo.Mesh.CreateTorus("torusTeleportation",.75,.1,25,this._scene,!1);r.isPickable=!1,r.parent=this._teleportationTarget;var n=new Eo.Animation("animationInnerCircle","position.y",30,Eo.Animation.ANIMATIONTYPE_FLOAT,Eo.Animation.ANIMATIONLOOPMODE_CYCLE),o=[];o.push({frame:0,value:0}),o.push({frame:30,value:.4}),o.push({frame:60,value:0}),n.setKeys(o);var s=new Eo.SineEase;s.setEasingMode(Eo.EasingFunction.EASINGMODE_EASEINOUT),n.setEasingFunction(s),r.animations=[],r.animations.push(n),this._scene.beginAnimation(r,0,60,!0),this._hideTeleportationTarget()},e.prototype._displayTeleportationTarget=function(){this._teleportationInitialized&&(this._teleportationTarget.isVisible=!0,this._isDefaultTeleportationTarget&&(this._teleportationTarget.getChildren()[0].isVisible=!0))},e.prototype._hideTeleportationTarget=function(){this._teleportationInitialized&&(this._teleportationTarget.isVisible=!1,this._isDefaultTeleportationTarget&&(this._teleportationTarget.getChildren()[0].isVisible=!1))},e.prototype._rotateCamera=function(e){var t=this;if(this.currentVRCamera instanceof Eo.FreeCamera){e?this._rotationAngle++:this._rotationAngle--,this.currentVRCamera.animations=[];var i=Eo.Quaternion.FromRotationMatrix(Eo.Matrix.RotationY(Math.PI/4*this._rotationAngle)),r=new Eo.Animation("animationRotation","rotationQuaternion",90,Eo.Animation.ANIMATIONTYPE_QUATERNION,Eo.Animation.ANIMATIONLOOPMODE_CONSTANT),n=[];n.push({frame:0,value:this.currentVRCamera.rotationQuaternion}),n.push({frame:6,value:i}),r.setKeys(n),r.setEasingFunction(this._circleEase),this.currentVRCamera.animations.push(r),this._postProcessMove.animations=[];var o=new Eo.Animation("animationPP","vignetteWeight",90,Eo.Animation.ANIMATIONTYPE_FLOAT,Eo.Animation.ANIMATIONLOOPMODE_CONSTANT),s=[];s.push({frame:0,value:0}),s.push({frame:3,value:4}),s.push({frame:6,value:0}),o.setKeys(s),o.setEasingFunction(this._circleEase),this._postProcessMove.animations.push(o);var a=new Eo.Animation("animationPP2","vignetteStretch",90,Eo.Animation.ANIMATIONTYPE_FLOAT,Eo.Animation.ANIMATIONLOOPMODE_CONSTANT),h=[];h.push({frame:0,value:0}),h.push({frame:3,value:10}),h.push({frame:6,value:0}),a.setKeys(h),a.setEasingFunction(this._circleEase),this._postProcessMove.animations.push(a),this._postProcessMove.imageProcessingConfiguration.vignetteWeight=0,this._postProcessMove.imageProcessingConfiguration.vignetteStretch=0,this._webVRCamera.attachPostProcess(this._postProcessMove),this._scene.beginAnimation(this._postProcessMove,0,6,!1,1,function(){t._webVRCamera.detachPostProcess(t._postProcessMove)}),this._scene.beginAnimation(this.currentVRCamera,0,6,!1,1)}},e.prototype._moveTeleportationSelectorTo=function(e){if(e.pickedPoint){this._teleportationAllowed=!0,this._teleportationRequestInitiated?this._displayTeleportationTarget():this._hideTeleportationTarget(),this._haloCenter.copyFrom(e.pickedPoint),this._teleportationTarget.position.copyFrom(e.pickedPoint);var t=e.getNormal(!0,!1);if(t){var i=Eo.Vector3.Cross(Eo.Axis.Y,t),r=Eo.Vector3.Cross(t,i);Eo.Vector3.RotationFromAxisToRef(r,t,i,this._teleportationTarget.rotation)}this._teleportationTarget.position.y+=.1}},e.prototype._teleportCamera=function(e){var t=this;if(void 0===e&&(e=null),this.currentVRCamera instanceof Eo.FreeCamera){e||(e=this._haloCenter),this.webVRCamera.leftCamera?(this._workingVector.copyFrom(this.webVRCamera.leftCamera.globalPosition),this._workingVector.subtractInPlace(this.webVRCamera.position),e.subtractToRef(this._workingVector,this._workingVector)):this._workingVector.copyFrom(e),this.isInVRMode?this._workingVector.y+=this.webVRCamera.deviceDistanceToRoomGround():this._workingVector.y+=this._defaultHeight,this.onBeforeCameraTeleport.notifyObservers(this._workingVector),this.currentVRCamera.animations=[];var i=new Eo.Animation("animationCameraTeleportation","position",90,Eo.Animation.ANIMATIONTYPE_VECTOR3,Eo.Animation.ANIMATIONLOOPMODE_CONSTANT),r=[{frame:0,value:this.currentVRCamera.position},{frame:11,value:this._workingVector}];i.setKeys(r),i.setEasingFunction(this._circleEase),this.currentVRCamera.animations.push(i),this._postProcessMove.animations=[];var n=new Eo.Animation("animationPP","vignetteWeight",90,Eo.Animation.ANIMATIONTYPE_FLOAT,Eo.Animation.ANIMATIONLOOPMODE_CONSTANT),o=[];o.push({frame:0,value:0}),o.push({frame:5,value:8}),o.push({frame:11,value:0}),n.setKeys(o),this._postProcessMove.animations.push(n);var s=new Eo.Animation("animationPP2","vignetteStretch",90,Eo.Animation.ANIMATIONTYPE_FLOAT,Eo.Animation.ANIMATIONLOOPMODE_CONSTANT),a=[];a.push({frame:0,value:0}),a.push({frame:5,value:10}),a.push({frame:11,value:0}),s.setKeys(a),this._postProcessMove.animations.push(s),this._postProcessMove.imageProcessingConfiguration.vignetteWeight=0,this._postProcessMove.imageProcessingConfiguration.vignetteStretch=0,this._webVRCamera.attachPostProcess(this._postProcessMove),this._scene.beginAnimation(this._postProcessMove,0,11,!1,1,function(){t._webVRCamera.detachPostProcess(t._postProcessMove)}),this._scene.beginAnimation(this.currentVRCamera,0,11,!1,1,function(){t.onAfterCameraTeleport.notifyObservers(t._workingVector)})}},e.prototype._castRayAndSelectObject=function(){if(this.currentVRCamera instanceof Eo.FreeCamera){var e;e=this._leftLaserPointer&&this._leftLaserPointer.isVisible&&this.currentVRCamera.leftController?this.currentVRCamera.leftController.getForwardRay(this._rayLength):this._rightLaserPointer&&this._rightLaserPointer.isVisible&&this.currentVRCamera.rightController?this.currentVRCamera.rightController.getForwardRay(this._rayLength):this.currentVRCamera.getForwardRay(this._rayLength);var t=this._scene.pickWithRay(e,this._raySelectionPredicate);if(t&&t.pickedPoint){if(this._displayGaze){var i=1;this._gazeTracker.isVisible=!0,this._isActionableMesh&&(i=3),this._gazeTracker.scaling.x=t.distance*i,this._gazeTracker.scaling.y=t.distance*i,this._gazeTracker.scaling.z=t.distance*i;var r=t.getNormal();if(r){var n=Eo.Vector3.Cross(Eo.Axis.Y,r),o=Eo.Vector3.Cross(r,n);Eo.Vector3.RotationFromAxisToRef(o,r,n,this._gazeTracker.rotation)}this._gazeTracker.position.copyFrom(t.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=t.distance,this._rightLaserPointer.position.z=-t.distance/2),this._leftLaserPointer&&this._leftLaserPointer.isVisible&&(this._leftLaserPointer.scaling.y=t.distance,this._leftLaserPointer.position.z=-t.distance/2)}else this._gazeTracker.isVisible=!1;if(t&&t.pickedMesh){if(this._currentHit=t,this._pointerDownOnMeshAsked&&this._scene.simulatePointerMove(this._currentHit),this._teleportationInitialized&&this._isTeleportationFloor(t.pickedMesh)&&t.pickedPoint)return this._currentMeshSelected&&!this._isTeleportationFloor(this._currentMeshSelected)&&this.onSelectedMeshUnselected.notifyObservers(this._currentMeshSelected),this._currentMeshSelected=null,void this._moveTeleportationSelectorTo(t);if(this._hideTeleportationTarget(),this._teleportationAllowed=!1,t.pickedMesh!==this._currentMeshSelected)if(this.meshSelectionPredicate(t.pickedMesh)){this.onNewMeshPicked.notifyObservers(t),this._currentMeshSelected=t.pickedMesh,t.pickedMesh.isPickable&&t.pickedMesh.actionManager?(this.changeGazeColor(new Eo.Color3(0,0,1)),this.changeLaserColor(new Eo.Color3(.2,.2,1)),this._isActionableMesh=!0):(this.changeGazeColor(new Eo.Color3(.7,.7,.7)),this.changeLaserColor(new Eo.Color3(.7,.7,.7)),this._isActionableMesh=!1);try{this.onNewMeshSelected.notifyObservers(this._currentMeshSelected)}catch(e){Eo.Tools.Warn("Error in your custom logic onNewMeshSelected: "+e)}}else this._currentMeshSelected&&this.onSelectedMeshUnselected.notifyObservers(this._currentMeshSelected),this._currentMeshSelected=null,this.changeGazeColor(new Eo.Color3(.7,.7,.7)),this.changeLaserColor(new Eo.Color3(.7,.7,.7))}else this._currentHit=null,this._currentMeshSelected=null,this._teleportationAllowed=!1,this._hideTeleportationTarget(),this.changeGazeColor(new Eo.Color3(.7,.7,.7)),this.changeLaserColor(new Eo.Color3(.7,.7,.7))}},e.prototype.changeLaserColor=function(e){this._leftLaserPointer&&this._leftLaserPointer.material&&(this._leftLaserPointer.material.emissiveColor=e),this._rightLaserPointer&&this._rightLaserPointer.material&&(this._rightLaserPointer.material.emissiveColor=e)},e.prototype.changeGazeColor=function(e){this._gazeTracker.material&&(this._gazeTracker.material.emissiveColor=e)},e.prototype.dispose=function(){this.isInVRMode&&this.exitVR(),this._passProcessMove&&this._passProcessMove.dispose(),this._postProcessMove&&this._postProcessMove.dispose(),this._webVRCamera&&this._webVRCamera.dispose(),this._vrDeviceOrientationCamera&&this._vrDeviceOrientationCamera.dispose(),!this._useCustomVRButton&&this._btnVR.parentNode&&document.body.removeChild(this._btnVR),this._deviceOrientationCamera&&this._scene.activeCamera!=this._deviceOrientationCamera&&this._deviceOrientationCamera.dispose(),this._gazeTracker&&this._gazeTracker.dispose(),this._teleportationTarget&&this._teleportationTarget.dispose(),this._floorMeshesCollection=[],document.removeEventListener("keydown",this._onKeyDown),window.removeEventListener("vrdisplaypresentchange",this._onVrDisplayPresentChange),window.removeEventListener("resize",this._onResize),document.removeEventListener("fullscreenchange",this._onFullscreenChange),document.removeEventListener("mozfullscreenchange",this._onFullscreenChange),document.removeEventListener("webkitfullscreenchange",this._onFullscreenChange),document.removeEventListener("msfullscreenchange",this._onFullscreenChange),this._scene.getEngine().onVRDisplayChangedObservable.removeCallback(this._onVRDisplayChanged),this._scene.getEngine().onVRRequestPresentStart.removeCallback(this._onVRRequestPresentStart),this._scene.getEngine().onVRRequestPresentComplete.removeCallback(this._onVRRequestPresentComplete),window.removeEventListener("vrdisplaypresentchange",this._onVrDisplayPresentChange),this._scene.gamepadManager.onGamepadConnectedObservable.removeCallback(this._onNewGamepadConnected),this._scene.gamepadManager.onGamepadDisconnectedObservable.removeCallback(this._onNewGamepadDisconnected),this._scene.unregisterBeforeRender(this.beforeRender)},e.prototype.getClassName=function(){return"VRExperienceHelper"},e}(),Eo.VRExperienceHelper=Ao,function(e){var t,i;(i=t=e.JoystickAxis||(e.JoystickAxis={}))[i.X=0]="X",i[i.Y=1]="Y",i[i.Z=2]="Z";var r=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,i.vjCanvasContext.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.clientX<i.halfWidth:e.clientX>i.halfWidth)&&this._joystickPointerID<0?(this._joystickPointerID=e.pointerId,this._joystickPointerStartPos.x=e.clientX,this._joystickPointerStartPos.y=e.clientY,this._joystickPointerPos=this._joystickPointerStartPos.clone(),this._joystickPreviousPointerPos=this._joystickPointerStartPos.clone(),this._deltaJoystickVector.x=0,this._deltaJoystickVector.y=0,this.pressed=!0,this._touches.add(e.pointerId.toString(),e)):i._globalJoystickIndex<2&&this._action&&(this._action(),this._touches.add(e.pointerId.toString(),{x:e.clientX,y:e.clientY,prevX:e.clientX,prevY:e.clientY}))},i.prototype._onPointerMove=function(e){if(this._joystickPointerID==e.pointerId){this._joystickPointerPos.x=e.clientX,this._joystickPointerPos.y=e.clientY,this._deltaJoystickVector=this._joystickPointerPos.clone(),this._deltaJoystickVector=this._deltaJoystickVector.subtract(this._joystickPointerStartPos);var i=(this.reverseLeftRight?-1:1)*this._deltaJoystickVector.x/this._inversedSensibility;switch(this._axisTargetedByLeftAndRight){case t.X:this.deltaPosition.x=Math.min(1,Math.max(-1,i));break;case t.Y:this.deltaPosition.y=Math.min(1,Math.max(-1,i));break;case t.Z:this.deltaPosition.z=Math.min(1,Math.max(-1,i))}var r=(this.reverseUpDown?1:-1)*this._deltaJoystickVector.y/this._inversedSensibility;switch(this._axisTargetedByUpAndDown){case t.X:this.deltaPosition.x=Math.min(1,Math.max(-1,r));break;case t.Y:this.deltaPosition.y=Math.min(1,Math.max(-1,r));break;case t.Z:this.deltaPosition.z=Math.min(1,Math.max(-1,r))}}else{var n=this._touches.get(e.pointerId.toString());n&&(n.x=e.clientX,n.y=e.clientY)}},i.prototype._onPointerUp=function(e){if(this._joystickPointerID==e.pointerId)i.vjCanvasContext.clearRect(this._joystickPointerStartPos.x-64,this._joystickPointerStartPos.y-64,128,128),i.vjCanvasContext.clearRect(this._joystickPreviousPointerPos.x-42,this._joystickPreviousPointerPos.y-42,84,84),this._joystickPointerID=-1,this.pressed=!1;else{var t=this._touches.get(e.pointerId.toString());t&&i.vjCanvasContext.clearRect(t.prevX-44,t.prevY-44,88,88)}this._deltaJoystickVector.x=0,this._deltaJoystickVector.y=0,this._touches.remove(e.pointerId.toString())},i.prototype.setJoystickColor=function(e){this._joystickColor=e},i.prototype.setActionOnTouch=function(e){this._action=e},i.prototype.setAxisForLeftRight=function(e){switch(e){case t.X:case t.Y:case t.Z:this._axisTargetedByLeftAndRight=e;break;default:this._axisTargetedByLeftAndRight=t.X}},i.prototype.setAxisForUpDown=function(e){switch(e){case t.X:case t.Y:case t.Z:this._axisTargetedByUpAndDown=e;break;default:this._axisTargetedByUpAndDown=t.Y}},i.prototype._drawVirtualJoystick=function(){var e=this;this.pressed&&this._touches.forEach(function(t,r){r.pointerId===e._joystickPointerID?(i.vjCanvasContext.clearRect(e._joystickPointerStartPos.x-64,e._joystickPointerStartPos.y-64,128,128),i.vjCanvasContext.clearRect(e._joystickPreviousPointerPos.x-42,e._joystickPreviousPointerPos.y-42,84,84),i.vjCanvasContext.beginPath(),i.vjCanvasContext.lineWidth=6,i.vjCanvasContext.strokeStyle=e._joystickColor,i.vjCanvasContext.arc(e._joystickPointerStartPos.x,e._joystickPointerStartPos.y,40,0,2*Math.PI,!0),i.vjCanvasContext.stroke(),i.vjCanvasContext.closePath(),i.vjCanvasContext.beginPath(),i.vjCanvasContext.strokeStyle=e._joystickColor,i.vjCanvasContext.lineWidth=2,i.vjCanvasContext.arc(e._joystickPointerStartPos.x,e._joystickPointerStartPos.y,60,0,2*Math.PI,!0),i.vjCanvasContext.stroke(),i.vjCanvasContext.closePath(),i.vjCanvasContext.beginPath(),i.vjCanvasContext.strokeStyle=e._joystickColor,i.vjCanvasContext.arc(e._joystickPointerPos.x,e._joystickPointerPos.y,40,0,2*Math.PI,!0),i.vjCanvasContext.stroke(),i.vjCanvasContext.closePath(),e._joystickPreviousPointerPos=e._joystickPointerPos.clone()):(i.vjCanvasContext.clearRect(r.prevX-44,r.prevY-44,88,88),i.vjCanvasContext.beginPath(),i.vjCanvasContext.fillStyle="white",i.vjCanvasContext.beginPath(),i.vjCanvasContext.strokeStyle="red",i.vjCanvasContext.lineWidth=6,i.vjCanvasContext.arc(r.x,r.y,40,0,2*Math.PI,!0),i.vjCanvasContext.stroke(),i.vjCanvasContext.closePath(),r.prevX=r.x,r.prevY=r.y)}),requestAnimationFrame(function(){e._drawVirtualJoystick()})},i.prototype.releaseCanvas=function(){i.vjCanvas&&(i.vjCanvas.removeEventListener("pointerdown",this._onPointerDownHandlerRef),i.vjCanvas.removeEventListener("pointermove",this._onPointerMoveHandlerRef),i.vjCanvas.removeEventListener("pointerup",this._onPointerUpHandlerRef),i.vjCanvas.removeEventListener("pointerout",this._onPointerUpHandlerRef),window.removeEventListener("resize",this._onResize),document.body.removeChild(i.vjCanvas),i.vjCanvas=null)},i._globalJoystickIndex=0,i}();e.VirtualJoystick=r}(us||(us={})),Po=us||(us={}),Mo=function(e){function t(t,i,r){var n=e.call(this,t,i,r)||this;return n.inputs.addVirtualJoystick(),n}return Y(t,e),t.prototype.getClassName=function(){return"VirtualJoysticksCamera"},t}(Po.FreeCamera),Po.VirtualJoysticksCamera=Mo,So=us||(us={}),Co=function(){function e(){}return e.prototype.getLeftJoystick=function(){return this._leftjoystick},e.prototype.getRightJoystick=function(){return this._rightjoystick},e.prototype.checkInputs=function(){if(this._leftjoystick){var e=this.camera,t=50*e._computeLocalCameraSpeed(),i=So.Matrix.RotationYawPitchRoll(e.rotation.y,e.rotation.x,0),r=So.Vector3.TransformCoordinates(new So.Vector3(this._leftjoystick.deltaPosition.x*t,this._leftjoystick.deltaPosition.y*t,this._leftjoystick.deltaPosition.z*t),i);e.cameraDirection=e.cameraDirection.add(r),e.cameraRotation=e.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))}},e.prototype.attachControl=function(e,t){this._leftjoystick=new So.VirtualJoystick(!0),this._leftjoystick.setAxisForUpDown(So.JoystickAxis.Z),this._leftjoystick.setAxisForLeftRight(So.JoystickAxis.X),this._leftjoystick.setJoystickSensibility(.15),this._rightjoystick=new So.VirtualJoystick(!1),this._rightjoystick.setAxisForUpDown(So.JoystickAxis.X),this._rightjoystick.setAxisForLeftRight(So.JoystickAxis.Y),this._rightjoystick.reverseUpDown=!0,this._rightjoystick.setJoystickSensibility(.05),this._rightjoystick.setJoystickColor("yellow")},e.prototype.detachControl=function(e){this._leftjoystick.releaseCanvas(),this._rightjoystick.releaseCanvas()},e.prototype.getClassName=function(){return"FreeCameraVirtualJoystickInput"},e.prototype.getSimpleName=function(){return"virtualJoystick"},e}(),So.FreeCameraVirtualJoystickInput=Co,So.CameraInputTypes.FreeCameraVirtualJoystickInput=Co,function(e){var t=function(){return function(e,t,i){this.quality=e,this.distance=t,this.optimizeMesh=i}}();e.SimplificationSettings=t;var i,r,n=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){var i,n;i=t.settings[e.index],n=function(){e.executeNext()},r.simplify(i,function(e){t.mesh.addLODLevel(i.distance,e),e.isVisible=!0,n()})},function(){t.successCallback&&t.successCallback(),i.executeNext()})}},t.prototype.getSimplifier=function(e){switch(e.simplificationType){case i.QUADRATIC:default:return new l(e.mesh)}},t}();e.SimplificationQueue=n,(r=i=e.SimplificationType||(e.SimplificationType={}))[r.QUADRATIC=0]="QUADRATIC";var o=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=o;var s=function(){function e(e,t){this.position=e,this.id=t,this.isBorder=!0,this.q=new a,this.triangleCount=0,this.triangleStart=0,this.originalOffsets=[]}return e.prototype.updatePosition=function(e){this.position.copyFrom(e)},e}();e.DecimationVertex=s;var a=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=a;var h=function(){return function(e,t){this.vertexId=e,this.triangleId=t}}();e.Reference=h;var l=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){var i,r;a-s<=o?t.breakLoop():(i=t.index,r=function(){t.executeNext()},setTimeout(function(){i%5==0&&n.updateMesh(0===i);for(var t=0;t<n.triangles.length;++t)n.triangles[t].isDirty=!1;var h=1e-9*Math.pow(i+3,n.aggressiveness);e.AsyncLoop.SyncAsyncForLoop(n.triangles.length,n.syncIterations,function(t){var i=~~((n.triangles.length/2+t)%n.triangles.length),r=n.triangles[i];if(r&&!(r.error[3]>h||r.deleted||r.isDirty))for(var o=0;o<3;++o)if(r.error[o]<h){var a=[],l=[],c=r.vertices[o],u=r.vertices[(o+1)%3];if(c.isBorder||u.isBorder)continue;var p=e.Vector3.Zero(),f=e.Vector3.Zero(),d=e.Vector2.Zero(),m=new e.Color4(0,0,0,1);n.calculateError(c,u,p,f,d,m);var g=new Array;if(n.isFlipped(c,u,p,a,r.borderFactor,g))continue;if(n.isFlipped(u,c,p,l,r.borderFactor,g))continue;if(a.indexOf(!0)<0||l.indexOf(!0)<0)continue;var _=new Array;if(g.forEach(function(e){-1===_.indexOf(e)&&(e.deletePending=!0,_.push(e))}),_.length%2!=0)continue;c.q=u.q.add(c.q),c.updatePosition(p);var v=n.references.length;s=n.updateTriangles(c,c,a,s),s=n.updateTriangles(c,u,l,s);var y=n.references.length-v;if(y<=c.triangleCount){if(y)for(var b=0;b<y;b++)n.references[c.triangleStart+b]=n.references[v+b]}else c.triangleStart=v;c.triangleCount=y;break}},r,function(){return a-s<=o})},0))},function(){setTimeout(function(){n.reconstructMesh(i),r()},0)})},t.prototype.initWithMesh=function(t,i,r){var n=this;this.vertices=[],this.triangles=[];var a=this._mesh.getVerticesData(e.VertexBuffer.PositionKind),h=this._mesh.getIndices(),l=this._mesh.subMeshes[t],c=[],u=l.verticesCount;e.AsyncLoop.SyncAsyncForLoop(u,this.syncIterations/4>>0,function(t){if(a){var i=t+l.verticesStart,o=e.Vector3.FromArray(a,3*i),h=function(e){if(r)for(var t=0;t<n.vertices.length;++t)if(n.vertices[t].position.equals(e))return n.vertices[t];return null}(o)||new s(o,n.vertices.length);h.originalOffsets.push(i),h.id===n.vertices.length&&n.vertices.push(h),c.push(h.id)}},function(){e.AsyncLoop.SyncAsyncForLoop(l.indexCount/3,n.syncIterations,function(e){if(h){var t=3*(l.indexStart/3+e),i=h[t+0],r=h[t+1],s=h[t+2],a=n.vertices[c[i-l.verticesStart]],u=n.vertices[c[r-l.verticesStart]],p=n.vertices[c[s-l.verticesStart]],f=new o([a,u,p]);f.originalOffset=t,n.triangles.push(f)}},function(){n.init(i)})})},t.prototype.init=function(t){var i=this;e.AsyncLoop.SyncAsyncForLoop(this.triangles.length,this.syncIterations,function(t){var r=i.triangles[t];r.normal=e.Vector3.Cross(r.vertices[1].position.subtract(r.vertices[0].position),r.vertices[2].position.subtract(r.vertices[0].position)).normalize();for(var n=0;n<3;n++)r.vertices[n].q.addArrayInPlace(a.DataFromNumbers(r.normal.x,r.normal.y,r.normal.z,-e.Vector3.Dot(r.normal,r.vertices[0].position)))},function(){e.AsyncLoop.SyncAsyncForLoop(i.triangles.length,i.syncIterations,function(e){for(var t=i.triangles[e],r=0;r<3;++r)t.error[r]=i.calculateError(t.vertices[r],t.vertices[(r+1)%3]);t.error[3]=Math.min(t.error[0],t.error[1],t.error[2])},function(){t()})})},t.prototype.reconstructMesh=function(t){var i,r,n,o=[];for(i=0;i<this.vertices.length;++i)this.vertices[i].triangleCount=0;for(i=0;i<this.triangles.length;++i)if(!this.triangles[i].deleted){for(r=this.triangles[i],n=0;n<3;++n)r.vertices[n].triangleCount=1;o.push(r)}var s=this._reconstructedMesh.getVerticesData(e.VertexBuffer.PositionKind)||[],a=this._reconstructedMesh.getVerticesData(e.VertexBuffer.NormalKind)||[],h=this._reconstructedMesh.getVerticesData(e.VertexBuffer.UVKind)||[],l=this._reconstructedMesh.getVerticesData(e.VertexBuffer.ColorKind)||[],c=this._mesh.getVerticesData(e.VertexBuffer.NormalKind),u=this._mesh.getVerticesData(e.VertexBuffer.UVKind),p=this._mesh.getVerticesData(e.VertexBuffer.ColorKind),f=0;for(i=0;i<this.vertices.length;++i){var d=this.vertices[i];d.id=f,d.triangleCount&&d.originalOffsets.forEach(function(e){c&&(s.push(d.position.x),s.push(d.position.y),s.push(d.position.z),a.push(c[3*e]),a.push(c[3*e+1]),a.push(c[3*e+2]),u&&u.length?(h.push(u[2*e]),h.push(u[2*e+1])):p&&p.length&&(l.push(p[4*e]),l.push(p[4*e+1]),l.push(p[4*e+2]),l.push(p[4*e+3])),++f)})}var m=this._reconstructedMesh.getTotalIndices(),g=this._reconstructedMesh.getTotalVertices(),_=this._reconstructedMesh.subMeshes;this._reconstructedMesh.subMeshes=[];var v=this._reconstructedMesh.getIndices(),y=this._mesh.getIndices();for(i=0;i<o.length;++i)r=o[i],[0,1,2].forEach(function(e){var t=y[r.originalOffset+e],i=r.vertices[e].originalOffsets.indexOf(t);i<0&&(i=0),v.push(r.vertices[e].id+i+g)});this._reconstructedMesh.setIndices(v),this._reconstructedMesh.setVerticesData(e.VertexBuffer.PositionKind,s),this._reconstructedMesh.setVerticesData(e.VertexBuffer.NormalKind,a),h.length>0&&this._reconstructedMesh.setVerticesData(e.VertexBuffer.UVKind,h),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*o.length,this._reconstructedMesh))},t.prototype.initDecimatedMesh=function(){this._reconstructedMesh=new e.Mesh(this._mesh.name+"Decimated",this._mesh.getScene()),this._reconstructedMesh.material=this._mesh.material,this._reconstructedMesh.parent=this._mesh.parent,this._reconstructedMesh.isVisible=!1,this._reconstructedMesh.renderingGroupId=this._mesh.renderingGroupId},t.prototype.isFlipped=function(t,i,r,n,o,s){for(var a=0;a<t.triangleCount;++a){var h=this.triangles[this.references[t.triangleStart+a].triangleId];if(!h.deleted){var l=this.references[t.triangleStart+a].vertexId,c=h.vertices[(l+1)%3],u=h.vertices[(l+2)%3];if(c!==i&&u!==i){var p=c.position.subtract(r);p=p.normalize();var f=u.position.subtract(r);if(f=f.normalize(),Math.abs(e.Vector3.Dot(p,f))>.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;o<t.triangleCount;++o){var s=this.references[t.triangleStart+o],a=this.triangles[s.triangleId];a.deleted||(i[o]&&a.deletePending?(a.deleted=!0,n++):(a.vertices[s.vertexId]=e,a.isDirty=!0,a.error[0]=this.calculateError(a.vertices[0],a.vertices[1])+a.borderFactor/2,a.error[1]=this.calculateError(a.vertices[1],a.vertices[2])+a.borderFactor/2,a.error[2]=this.calculateError(a.vertices[2],a.vertices[0])+a.borderFactor/2,a.error[3]=Math.min(a.error[0],a.error[1],a.error[2]),this.references.push(s)))}return n},t.prototype.identifyBorder=function(){for(var e=0;e<this.vertices.length;++e){var t,i=[],r=[],n=this.vertices[e];for(t=0;t<n.triangleCount;++t)for(var o=this.triangles[this.references[n.triangleStart+t].triangleId],s=0;s<3;s++){for(var a=0,h=o.vertices[s];a<i.length&&r[a]!==h.id;)++a;a===i.length?(i.push(1),r.push(h.id)):i[a]++}for(t=0;t<i.length;++t)1===i[t]?this.vertices[r[t]].isBorder=!0:this.vertices[r[t]].isBorder=!1}},t.prototype.updateMesh=function(e){var t,i,r,n;if(void 0===e&&(e=!1),!e){var o=[];for(t=0;t<this.triangles.length;++t)this.triangles[t].deleted||o.push(this.triangles[t]);this.triangles=o}for(t=0;t<this.vertices.length;++t)this.vertices[t].triangleCount=0,this.vertices[t].triangleStart=0;for(t=0;t<this.triangles.length;++t)for(i=this.triangles[t],r=0;r<3;++r)(n=i.vertices[r]).triangleCount++;var s=0;for(t=0;t<this.vertices.length;++t)this.vertices[t].triangleStart=s,s+=this.vertices[t].triangleCount,this.vertices[t].triangleCount=0;var a=new Array(3*this.triangles.length);for(t=0;t<this.triangles.length;++t)for(i=this.triangles[t],r=0;r<3;++r)a[(n=i.vertices[r]).triangleStart+n.triangleCount]=new h(r,t),n.triangleCount++;this.references=a,e&&this.identifyBorder()},t.prototype.vertexError=function(e,t){var i=t.x,r=t.y,n=t.z;return e.data[0]*i*i+2*e.data[1]*i*r+2*e.data[2]*i*n+2*e.data[3]*i+e.data[4]*r*r+2*e.data[5]*r*n+2*e.data[6]*r+e.data[7]*n*n+2*e.data[8]*n+e.data[9]},t.prototype.calculateError=function(t,i,r,n,o,s){var a=t.q.add(i.q),h=t.isBorder&&i.isBorder,l=0,c=a.det(0,1,2,1,4,5,2,5,7);if(0===c||h){var u=t.position.add(i.position).divide(new e.Vector3(2,2,2)),p=this.vertexError(a,t.position),f=this.vertexError(a,i.position),d=this.vertexError(a,u);(l=Math.min(p,f,d))===p?r&&r.copyFrom(t.position):l===f?r&&r.copyFrom(i.position):r&&r.copyFrom(u)}else r||(r=e.Vector3.Zero()),r.x=-1/c*a.det(1,2,3,4,5,6,5,7,8),r.y=1/c*a.det(0,2,3,1,5,6,2,7,8),r.z=-1/c*a.det(0,1,3,1,4,6,2,5,8),l=this.vertexError(a,r);return l},t}();e.QuadraticErrorSimplification=l}(us||(us={})),Ro=us||(us={}),Oo=function(){return function(e,t){this.distance=e,this.mesh=t}}(),Ro.MeshLODLevel=Oo,function(e){var t=function(){function e(e){void 0===e&&(e=0),this.priority=e}return e.prototype.getDescription=function(){return""},e.prototype.apply=function(e){return!0},e}();e.SceneOptimization=t;var i=function(e){function t(t,i,r){void 0===t&&(t=0),void 0===i&&(i=1024),void 0===r&&(r=.5);var n=e.call(this,t)||this;return n.priority=t,n.maximumSize=i,n.step=r,n}return Y(t,e),t.prototype.getDescription=function(){return"Reducing render target texture size to "+this.maximumSize},t.prototype.apply=function(e){for(var t=!0,i=0;i<e.textures.length;i++){var r=e.textures[i];if(r.canRescale&&!r.getContext){var n=r.getSize();Math.max(n.width,n.height)>this.maximumSize&&(r.scale(this.step),t=!1)}}return t},t}(t);e.TextureOptimization=i;var r=function(e){function t(t,i,r){void 0===t&&(t=0),void 0===i&&(i=2),void 0===r&&(r=.25);var n=e.call(this,t)||this;return n.priority=t,n.maximumScale=i,n.step=r,n._currentScale=-1,n._directionOffset=1,n}return Y(t,e),t.prototype.getDescription=function(){return"Setting hardware scaling level to "+this._currentScale},t.prototype.apply=function(e){return-1===this._currentScale&&(this._currentScale=e.getEngine().getHardwareScalingLevel(),this._currentScale>this.maximumScale&&(this._directionOffset=-1)),this._currentScale+=this._directionOffset*this.step,e.getEngine().setHardwareScalingLevel(this._currentScale),1===this._directionOffset?this._currentScale>=this.maximumScale:this._currentScale<=this.maximumScale},t}(t);e.HardwareScalingOptimization=r;var n=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return Y(t,e),t.prototype.getDescription=function(){return"Turning shadows off"},t.prototype.apply=function(e){return e.shadowsEnabled=!1,!0},t}(t);e.ShadowsOptimization=n;var o=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return Y(t,e),t.prototype.getDescription=function(){return"Turning post-processes off"},t.prototype.apply=function(e){return e.postProcessesEnabled=!1,!0},t}(t);e.PostProcessesOptimization=o;var s=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return Y(t,e),t.prototype.getDescription=function(){return"Turning lens flares off"},t.prototype.apply=function(e){return e.lensFlaresEnabled=!1,!0},t}(t);e.LensFlaresOptimization=s;var a=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return Y(t,e),t.prototype.getDescription=function(){return this.onGetDescription?this.onGetDescription():"Running user defined callback"},t.prototype.apply=function(e){return!this.onApply||this.onApply(e)},t}(t);e.CustomOptimization=a;var h=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return Y(t,e),t.prototype.getDescription=function(){return"Turning particles off"},t.prototype.apply=function(e){return e.particlesEnabled=!1,!0},t}(t);e.ParticlesOptimization=h;var l=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return Y(t,e),t.prototype.getDescription=function(){return"Turning render targets off"},t.prototype.apply=function(e){return e.renderTargetsEnabled=!1,!0},t}(t);e.RenderTargetsOptimization=l;var c=function(t){function i(){var i=null!==t&&t.apply(this,arguments)||this;return i._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))},i}return Y(i,t),Object.defineProperty(i,"UpdateSelectionTree",{get:function(){return i._UpdateSelectionTree},set:function(e){i._UpdateSelectionTree=e},enumerable:!0,configurable:!0}),i.prototype.getDescription=function(){return"Merging similar meshes together"},i.prototype.apply=function(t,r){for(var n=t.meshes.slice(0),o=n.length,s=0;s<o;s++){var a=new Array,h=n[s];if(this._canBeMerged(h)){a.push(h);for(var l=s+1;l<o;l++){var c=n[l];this._canBeMerged(c)&&(c.material===h.material&&c.checkCollisions===h.checkCollisions&&(a.push(c),o--,n.splice(l,1),l--))}a.length<2||e.Mesh.MergeMeshes(a)}}return void 0!=r?r&&t.createOrUpdateSelectionOctree():i.UpdateSelectionTree&&t.createOrUpdateSelectionOctree(),!0},i._UpdateSelectionTree=!1,i}(t);e.MergeMeshesOptimization=c;var u=function(){function e(e,t){void 0===e&&(e=60),void 0===t&&(t=2e3),this.targetFrameRate=e,this.trackerDuration=t,this.optimizations=new Array}return e.prototype.addOptimization=function(e){return this.optimizations.push(e),this},e.prototype.addCustomOptimization=function(e,t,i){void 0===i&&(i=0);var r=new a(i);return r.onApply=e,r.onGetDescription=t,this.optimizations.push(r),this},e.LowDegradationAllowed=function(t){var r=new e(t),a=0;return r.addOptimization(new c(a)),r.addOptimization(new n(a)),r.addOptimization(new s(a)),a++,r.addOptimization(new o(a)),r.addOptimization(new h(a)),a++,r.addOptimization(new i(a,1024)),r},e.ModerateDegradationAllowed=function(t){var a=new e(t),u=0;return a.addOptimization(new c(u)),a.addOptimization(new n(u)),a.addOptimization(new s(u)),u++,a.addOptimization(new o(u)),a.addOptimization(new h(u)),u++,a.addOptimization(new i(u,512)),u++,a.addOptimization(new l(u)),u++,a.addOptimization(new r(u,2)),a},e.HighDegradationAllowed=function(t){var a=new e(t),u=0;return a.addOptimization(new c(u)),a.addOptimization(new n(u)),a.addOptimization(new s(u)),u++,a.addOptimization(new o(u)),a.addOptimization(new h(u)),u++,a.addOptimization(new i(u,256)),u++,a.addOptimization(new l(u)),u++,a.addOptimization(new r(u,4)),a},e}();e.SceneOptimizerOptions=u;var p=function(){function t(t,i,r){void 0===r&&(r=!0);var n=this;if(this._isRunning=!1,this._currentPriorityLevel=0,this._targetFrameRate=60,this._trackerDuration=2e3,this._currentFrameRate=0,this.onSuccessObservable=new e.Observable,this.onNewOptimizationAppliedObservable=new e.Observable,this.onFailureObservable=new e.Observable,this._options=i||new u,this._options.targetFrameRate&&(this._targetFrameRate=this._options.targetFrameRate),this._options.trackerDuration&&(this._trackerDuration=this._options.trackerDuration),r)for(var o=0,s=0,a=this._options.optimizations;s<a.length;s++){a[s].priority=o++}this._scene=t||e.Engine.LastCreatedScene,this._sceneDisposeObserver=this._scene.onDisposeObservable.add(function(){n._sceneDisposeObserver=null,n.dispose()})}return Object.defineProperty(t.prototype,"currentPriorityLevel",{get:function(){return this._currentPriorityLevel},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"currentFrameRate",{get:function(){return this._currentFrameRate},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"targetFrameRate",{get:function(){return this._targetFrameRate},set:function(e){this._targetFrameRate=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"trackerDuration",{get:function(){return this._trackerDuration},set:function(e){this._trackerDuration=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"optimizations",{get:function(){return this._options.optimizations},enumerable:!0,configurable:!0}),t.prototype.stop=function(){this._isRunning=!1},t.prototype.reset=function(){this._currentPriorityLevel=0},t.prototype.start=function(){var e=this;this._isRunning||(this._isRunning=!0,this._scene.executeWhenReady(function(){setTimeout(function(){e._checkCurrentState()},e._trackerDuration)}))},t.prototype._checkCurrentState=function(){var e=this;if(this._isRunning){var t=this._scene,i=this._options;if(this._currentFrameRate=Math.round(t.getEngine().getFps()),this._currentFrameRate>=this._targetFrameRate)return this._isRunning=!1,void this.onSuccessObservable.notifyObservers(this);for(var r=!0,n=!0,o=0;o<i.optimizations.length;o++){var s=i.optimizations[o];s.priority===this._currentPriorityLevel&&(n=!1,r=r&&s.apply(t),this.onNewOptimizationAppliedObservable.notifyObservers(s))}if(n)return this._isRunning=!1,void this.onFailureObservable.notifyObservers(this);r&&this._currentPriorityLevel++,t.executeWhenReady(function(){setTimeout(function(){e._checkCurrentState()},e._trackerDuration)})}},t.prototype.dispose=function(){this.stop(),this.onSuccessObservable.clear(),this.onFailureObservable.clear(),this.onNewOptimizationAppliedObservable.clear(),this._sceneDisposeObserver&&this._scene.onDisposeObservable.remove(this._sceneDisposeObserver)},t.OptimizeAsync=function(e,i,r,n){var o=new t(e,i||u.ModerateDegradationAllowed(),!1);return r&&o.onSuccessObservable.add(function(){r()}),n&&o.onFailureObservable.add(function(){n()}),o.start(),o},t}();e.SceneOptimizer=p}(us||(us={})),Io=us||(us={}),wo=function(){function e(e){this.zOffset=1,this._scene=e}return e.prototype.render=function(e,t,i){var r=this;void 0===i&&(i=!1);var n=this._scene,o=this._scene.getEngine(),s=o.getCaps().instancedArrays&&null!==t.visibleInstances[e._id]&&void 0!==t.visibleInstances[e._id];if(this.isReady(e,s)){var a=e.getRenderingMesh(),h=e.getMaterial();if(h&&n.activeCamera){if(o.enableEffect(this._effect),h.useLogarithmicDepth&&this._effect.setFloat("logarithmicDepthConstant",2/(Math.log(n.activeCamera.maxZ+1)/Math.LN2)),this._effect.setFloat("offset",i?0:a.outlineWidth),this._effect.setColor4("color",i?a.overlayColor:a.outlineColor,i?a.overlayAlpha:h.alpha),this._effect.setMatrix("viewProjection",n.getTransformMatrix()),a.useBones&&a.computeBonesUsingShaders&&a.skeleton&&this._effect.setMatrices("mBones",a.skeleton.getTransformMatrices(a)),a._bind(e,this._effect,Io.Material.TriangleFillMode),h&&h.needAlphaTesting()){var l=h.getAlphaTestTexture();l&&(this._effect.setTexture("diffuseSampler",l),this._effect.setMatrix("diffuseMatrix",l.getTextureMatrix()))}o.setZOffset(-this.zOffset),a._processRendering(e,this._effect,Io.Material.TriangleFillMode,t,s,function(e,t){r._effect.setMatrix("world",t)}),o.setZOffset(0)}}},e.prototype.isReady=function(e,t){var i=[],r=[Io.VertexBuffer.PositionKind,Io.VertexBuffer.NormalKind],n=e.getMesh(),o=e.getMaterial();o&&(o.needAlphaTesting()&&(i.push("#define ALPHATEST"),n.isVerticesDataPresent(Io.VertexBuffer.UVKind)&&(r.push(Io.VertexBuffer.UVKind),i.push("#define UV1")),n.isVerticesDataPresent(Io.VertexBuffer.UV2Kind)&&(r.push(Io.VertexBuffer.UV2Kind),i.push("#define UV2"))),o.useLogarithmicDepth&&i.push("#define LOGARITHMICDEPTH")),n.useBones&&n.computeBonesUsingShaders?(r.push(Io.VertexBuffer.MatricesIndicesKind),r.push(Io.VertexBuffer.MatricesWeightsKind),n.numBoneInfluencers>4&&(r.push(Io.VertexBuffer.MatricesIndicesExtraKind),r.push(Io.VertexBuffer.MatricesWeightsExtraKind)),i.push("#define NUM_BONE_INFLUENCERS "+n.numBoneInfluencers),i.push("#define BonesPerMesh "+(n.skeleton?n.skeleton.bones.length+1:0))):i.push("#define NUM_BONE_INFLUENCERS 0"),t&&(i.push("#define INSTANCES"),r.push("world0"),r.push("world1"),r.push("world2"),r.push("world3"));var s=i.join("\n");return this._cachedDefines!==s&&(this._cachedDefines=s,this._effect=this._scene.getEngine().createEffect("outline",r,["world","mBones","viewProjection","diffuseMatrix","offset","color","logarithmicDepthConstant"],["diffuseSampler"],s)),this._effect.isReady()},e}(),Io.OutlineRenderer=wo,Do=us||(us={}),Lo=function(){return function(){this.edges=new Array,this.edgesConnectedCount=0}}(),Bo=function(){function e(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 e.prototype._prepareRessources=function(){this._lineShader||(this._lineShader=new Do.ShaderMaterial("lineShader",this._source.getScene(),"line",{attributes:["position","normal"],uniforms:["worldViewProjection","color","width","aspectRatio"]}),this._lineShader.disableDepthWrite=!0,this._lineShader.backFaceCulling=!1)},e.prototype._rebuild=function(){var e=this._buffers[Do.VertexBuffer.PositionKind];e&&e._rebuild(),(e=this._buffers[Do.VertexBuffer.NormalKind])&&e._rebuild();var t=this._source.getScene().getEngine();this._ib=t.createIndexBuffer(this._linesIndices)},e.prototype.dispose=function(){var e=this._buffers[Do.VertexBuffer.PositionKind];e&&(e.dispose(),this._buffers[Do.VertexBuffer.PositionKind]=null),(e=this._buffers[Do.VertexBuffer.NormalKind])&&(e.dispose(),this._buffers[Do.VertexBuffer.NormalKind]=null),this._source.getScene().getEngine()._releaseBuffer(this._ib),this._lineShader.dispose()},e.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},e.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},e.prototype._checkEdge=function(e,t,i,r,n){var o;void 0===t?o=!0:o=Do.Vector3.Dot(i[e],i[t])<this._epsilon;if(o){var s=this._linesPositions.length/3;r.subtract(n).normalize(),this._linesPositions.push(r.x),this._linesPositions.push(r.y),this._linesPositions.push(r.z),this._linesPositions.push(r.x),this._linesPositions.push(r.y),this._linesPositions.push(r.z),this._linesPositions.push(n.x),this._linesPositions.push(n.y),this._linesPositions.push(n.z),this._linesPositions.push(n.x),this._linesPositions.push(n.y),this._linesPositions.push(n.z),this._linesNormals.push(n.x),this._linesNormals.push(n.y),this._linesNormals.push(n.z),this._linesNormals.push(-1),this._linesNormals.push(n.x),this._linesNormals.push(n.y),this._linesNormals.push(n.z),this._linesNormals.push(1),this._linesNormals.push(r.x),this._linesNormals.push(r.y),this._linesNormals.push(r.z),this._linesNormals.push(-1),this._linesNormals.push(r.x),this._linesNormals.push(r.y),this._linesNormals.push(r.z),this._linesNormals.push(1),this._linesIndices.push(s),this._linesIndices.push(s+1),this._linesIndices.push(s+2),this._linesIndices.push(s),this._linesIndices.push(s+2),this._linesIndices.push(s+3)}},e.prototype._generateEdgesLines=function(){var e=this._source.getVerticesData(Do.VertexBuffer.PositionKind),t=this._source.getIndices();if(t&&e){var i,r,n=new Array,o=new Array;for(i=0;i<t.length;i+=3){r=new Lo;var s=t[i],a=t[i+1],h=t[i+2];r.p0=new Do.Vector3(e[3*s],e[3*s+1],e[3*s+2]),r.p1=new Do.Vector3(e[3*a],e[3*a+1],e[3*a+2]),r.p2=new Do.Vector3(e[3*h],e[3*h+1],e[3*h+2]);var l=Do.Vector3.Cross(r.p1.subtract(r.p0),r.p2.subtract(r.p1));l.normalize(),o.push(l),n.push(r)}for(i=0;i<n.length;i++){r=n[i];for(var c=i+1;c<n.length;c++){var u=n[c];if(3===r.edgesConnectedCount)break;if(3!==u.edgesConnectedCount)for(var p=t[3*c],f=t[3*c+1],d=t[3*c+2],m=0;m<3;m++){var g=0;if(void 0===r.edges[m]){switch(m){case 0:g=this._checkVerticesInsteadOfIndices?this._processEdgeForAdjacenciesWithVertices(r.p0,r.p1,u.p0,u.p1,u.p2):this._processEdgeForAdjacencies(t[3*i],t[3*i+1],p,f,d);break;case 1:g=this._checkVerticesInsteadOfIndices?this._processEdgeForAdjacenciesWithVertices(r.p1,r.p2,u.p0,u.p1,u.p2):this._processEdgeForAdjacencies(t[3*i+1],t[3*i+2],p,f,d);break;case 2:g=this._checkVerticesInsteadOfIndices?this._processEdgeForAdjacenciesWithVertices(r.p2,r.p0,u.p0,u.p1,u.p2):this._processEdgeForAdjacencies(t[3*i+2],t[3*i],p,f,d)}if(-1!==g&&(r.edges[m]=c,u.edges[g]=i,r.edgesConnectedCount++,u.edgesConnectedCount++,3===r.edgesConnectedCount))break}}}}for(i=0;i<n.length;i++){var _=n[i];this._checkEdge(i,_.edges[0],o,_.p0,_.p1),this._checkEdge(i,_.edges[1],o,_.p1,_.p2),this._checkEdge(i,_.edges[2],o,_.p2,_.p0)}var v=this._source.getScene().getEngine();this._buffers[Do.VertexBuffer.PositionKind]=new Do.VertexBuffer(v,this._linesPositions,Do.VertexBuffer.PositionKind,!1),this._buffers[Do.VertexBuffer.NormalKind]=new Do.VertexBuffer(v,this._linesNormals,Do.VertexBuffer.NormalKind,!1,!1,4),this._ib=v.createIndexBuffer(this._linesIndices),this._indicesCount=this._linesIndices.length}},e.prototype.render=function(){var e=this._source.getScene();if(this._lineShader.isReady()&&e.activeCamera){var t=e.getEngine();this._lineShader._preBind(),t.bindBuffers(this._buffers,this._ib,this._lineShader.getEffect()),e.resetCachedMaterial(),this._lineShader.setColor4("color",this._source.edgesColor),e.activeCamera.mode===Do.Camera.ORTHOGRAPHIC_CAMERA?this._lineShader.setFloat("width",this._source.edgesWidth/this.edgesWidthScalerForOrthographic):this._lineShader.setFloat("width",this._source.edgesWidth/this.edgesWidthScalerForPerspective),this._lineShader.setFloat("aspectRatio",t.getAspectRatio(e.activeCamera)),this._lineShader.bind(this._source.getWorldMatrix()),t.drawElementsType(Do.Material.TriangleFillMode,0,this._indicesCount),this._lineShader.unbind(),t.setDepthWrite(!0)}},e}(),Do.EdgesRenderer=Bo,No=us||(us={}),Fo=function(e){function t(t,i,r,n,o,s,a,h){void 0===s&&(s=No.Texture.BILINEAR_SAMPLINGMODE);var l=e.call(this,t,"glowBlurPostProcess",["screenSize","direction","blurWidth"],null,n,o,s,a,h)||this;return l.direction=i,l.kernel=r,l.onApplyObservable.add(function(e){e.setFloat2("screenSize",l.width,l.height),e.setVector2("direction",l.direction),e.setFloat("blurWidth",l.kernel)}),l}return Y(t,e),t}(No.PostProcess),Vo=function(){function e(t,i,r){this.name=t,this._vertexBuffers={},this._mainTextureDesiredSize={width:0,height:0},this._meshes={},this._maxSize=0,this._shouldRender=!1,this._instanceGlowingMeshStencilReference=e.glowingMeshStencilReference++,this._excludedMeshes={},this.innerGlow=!0,this.outerGlow=!0,this.isEnabled=!0,this.onDisposeObservable=new No.Observable,this.onBeforeRenderMainTextureObservable=new No.Observable,this.onBeforeBlurObservable=new No.Observable,this.onAfterBlurObservable=new No.Observable,this.onBeforeComposeObservable=new No.Observable,this.onAfterComposeObservable=new No.Observable,this.onSizeChangedObservable=new No.Observable,this._scene=i||No.Engine.LastCreatedScene;var n=i.getEngine();this._engine=n,this._maxSize=this._engine.getCaps().maxTextureSize,this._scene.highlightLayers.push(this),this._engine.isStencilEnable||No.Tools.Warn("Rendering the Highlight Layer requires the stencil to be active on the canvas. var engine = new BABYLON.Engine(canvas, antialias, { stencil: true }"),this._options=r||{mainTextureRatio:.5,blurTextureSizeRatio:.5,blurHorizontalSize:1,blurVerticalSize:1,alphaBlendingMode:No.Engine.ALPHA_COMBINE,camera:null},this._options.mainTextureRatio=this._options.mainTextureRatio||.5,this._options.blurTextureSizeRatio=this._options.blurTextureSizeRatio||1,this._options.blurHorizontalSize=this._options.blurHorizontalSize||1,this._options.blurVerticalSize=this._options.blurVerticalSize||1,this._options.alphaBlendingMode=this._options.alphaBlendingMode||No.Engine.ALPHA_COMBINE;var o=[];o.push(1,1),o.push(-1,1),o.push(-1,-1),o.push(1,-1);var s=new No.VertexBuffer(n,o,No.VertexBuffer.PositionKind,!1,!1,2);this._vertexBuffers[No.VertexBuffer.PositionKind]=s,this._createIndexBuffer(),this._glowMapMergeEffect=n.createEffect("glowMapMerge",[No.VertexBuffer.PositionKind],["offset"],["textureSampler"],""),this.setMainTextureSize(),this.createTextureAndPostProcesses()}return Object.defineProperty(e.prototype,"blurHorizontalSize",{get:function(){return this._horizontalBlurPostprocess.kernel},set:function(e){this._horizontalBlurPostprocess.kernel=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"blurVerticalSize",{get:function(){return this._verticalBlurPostprocess.kernel},set:function(e){this._verticalBlurPostprocess.kernel=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"camera",{get:function(){return this._options.camera},enumerable:!0,configurable:!0}),e.prototype._createIndexBuffer=function(){var e=this._scene.getEngine(),t=[];t.push(0),t.push(1),t.push(2),t.push(0),t.push(2),t.push(3),this._indexBuffer=e.createIndexBuffer(t)},e.prototype._rebuild=function(){var e=this._vertexBuffers[No.VertexBuffer.PositionKind];e&&e._rebuild(),this._createIndexBuffer()},e.prototype.createTextureAndPostProcesses=function(){var t=this,i=this._mainTextureDesiredSize.width*this._options.blurTextureSizeRatio,r=this._mainTextureDesiredSize.height*this._options.blurTextureSizeRatio;i=this._engine.needPOTTextures?No.Tools.GetExponentOfTwo(i,this._maxSize):i,r=this._engine.needPOTTextures?No.Tools.GetExponentOfTwo(r,this._maxSize):r,this._mainTexture=new No.RenderTargetTexture("HighlightLayerMainRTT",{width:this._mainTextureDesiredSize.width,height:this._mainTextureDesiredSize.height},this._scene,!1,!0,No.Engine.TEXTURETYPE_UNSIGNED_INT),this._mainTexture.activeCamera=this._options.camera,this._mainTexture.wrapU=No.Texture.CLAMP_ADDRESSMODE,this._mainTexture.wrapV=No.Texture.CLAMP_ADDRESSMODE,this._mainTexture.anisotropicFilteringLevel=1,this._mainTexture.updateSamplingMode(No.Texture.BILINEAR_SAMPLINGMODE),this._mainTexture.renderParticles=!1,this._mainTexture.renderList=null,this._mainTexture.ignoreCameraViewport=!0,this._blurTexture=new No.RenderTargetTexture("HighlightLayerBlurRTT",{width:i,height:r},this._scene,!1,!0,No.Engine.TEXTURETYPE_UNSIGNED_INT),this._blurTexture.wrapU=No.Texture.CLAMP_ADDRESSMODE,this._blurTexture.wrapV=No.Texture.CLAMP_ADDRESSMODE,this._blurTexture.anisotropicFilteringLevel=16,this._blurTexture.updateSamplingMode(No.Texture.TRILINEAR_SAMPLINGMODE),this._blurTexture.renderParticles=!1,this._blurTexture.ignoreCameraViewport=!0,this._downSamplePostprocess=new No.PassPostProcess("HighlightLayerPPP",this._options.blurTextureSizeRatio,null,No.Texture.BILINEAR_SAMPLINGMODE,this._scene.getEngine()),this._downSamplePostprocess.onApplyObservable.add(function(e){e.setTexture("textureSampler",t._mainTexture)}),this._options.alphaBlendingMode===No.Engine.ALPHA_COMBINE?(this._horizontalBlurPostprocess=new Fo("HighlightLayerHBP",new No.Vector2(1,0),this._options.blurHorizontalSize,1,null,No.Texture.BILINEAR_SAMPLINGMODE,this._scene.getEngine()),this._horizontalBlurPostprocess.onApplyObservable.add(function(e){e.setFloat2("screenSize",i,r)}),this._verticalBlurPostprocess=new Fo("HighlightLayerVBP",new No.Vector2(0,1),this._options.blurVerticalSize,1,null,No.Texture.BILINEAR_SAMPLINGMODE,this._scene.getEngine()),this._verticalBlurPostprocess.onApplyObservable.add(function(e){e.setFloat2("screenSize",i,r)})):(this._horizontalBlurPostprocess=new No.BlurPostProcess("HighlightLayerHBP",new No.Vector2(1,0),this._options.blurHorizontalSize,1,null,No.Texture.BILINEAR_SAMPLINGMODE,this._scene.getEngine()),this._horizontalBlurPostprocess.onApplyObservable.add(function(e){e.setFloat2("screenSize",i,r)}),this._verticalBlurPostprocess=new No.BlurPostProcess("HighlightLayerVBP",new No.Vector2(0,1),this._options.blurVerticalSize,1,null,No.Texture.BILINEAR_SAMPLINGMODE,this._scene.getEngine()),this._verticalBlurPostprocess.onApplyObservable.add(function(e){e.setFloat2("screenSize",i,r)})),this._mainTexture.onAfterUnbindObservable.add(function(){t.onBeforeBlurObservable.notifyObservers(t);var e=t._blurTexture.getInternalTexture();e&&t._scene.postProcessManager.directRender([t._downSamplePostprocess,t._horizontalBlurPostprocess,t._verticalBlurPostprocess],e,!0),t.onAfterBlurObservable.notifyObservers(t)});var n=function(i){if(t._meshes){var r=i.getMaterial(),n=i.getRenderingMesh(),o=t._scene,s=o.getEngine();if(r&&!r.needAlphaBlendingForMesh(n)){s.setState(r.backFaceCulling);var a=n._getInstancesRenderList(i._id);if(!(a.mustReturn||t._excludedMeshes&&t._excludedMeshes[n.uniqueId])){var h=s.getCaps().instancedArrays&&null!==a.visibleInstances[i._id]&&void 0!==a.visibleInstances[i._id],l=t._meshes[n.uniqueId],c=null;if(l&&l.glowEmissiveOnly&&r&&(c=r.emissiveTexture),t._isReady(i,h,c)){if(s.enableEffect(t._glowMapGenerationEffect),n._bind(i,t._glowMapGenerationEffect,No.Material.TriangleFillMode),t._glowMapGenerationEffect.setMatrix("viewProjection",o.getTransformMatrix()),l?t._glowMapGenerationEffect.setFloat4("color",l.color.r,l.color.g,l.color.b,1):t._glowMapGenerationEffect.setFloat4("color",e.neutralColor.r,e.neutralColor.g,e.neutralColor.b,e.neutralColor.a),r&&r.needAlphaTesting()){var u=r.getAlphaTestTexture();if(u){t._glowMapGenerationEffect.setTexture("diffuseSampler",u);var p=u.getTextureMatrix();p&&t._glowMapGenerationEffect.setMatrix("diffuseMatrix",p)}}c&&(t._glowMapGenerationEffect.setTexture("emissiveSampler",c),t._glowMapGenerationEffect.setMatrix("emissiveMatrix",c.getTextureMatrix())),n.useBones&&n.computeBonesUsingShaders&&n.skeleton&&t._glowMapGenerationEffect.setMatrices("mBones",n.skeleton.getTransformMatrices(n)),n._processRendering(i,t._glowMapGenerationEffect,No.Material.TriangleFillMode,a,h,function(e,i){return t._glowMapGenerationEffect.setMatrix("world",i)})}else t._mainTexture.resetRefreshCounter()}}}};this._mainTexture.customRenderFunction=function(e,i,r,o){var s;t.onBeforeRenderMainTextureObservable.notifyObservers(t);var a=t._scene.getEngine();if(o.length){for(a.setColorWrite(!1),s=0;s<o.length;s++)n(o.data[s]);a.setColorWrite(!0)}for(s=0;s<e.length;s++)n(e.data[s]);for(s=0;s<i.length;s++)n(i.data[s]);for(s=0;s<r.length;s++)n(r.data[s])},this._mainTexture.onClearObservable.add(function(t){t.clear(e.neutralColor,!0,!0,!0)})},e.prototype.isReady=function(e,t){var i=e.getMaterial(),r=e.getRenderingMesh();if(!i||!r||!this._meshes)return!1;var n=null,o=this._meshes[r.uniqueId];return o&&o.glowEmissiveOnly&&i&&(n=i.emissiveTexture),this._isReady(e,t,n)},e.prototype._isReady=function(e,t,i){var r=e.getMaterial();if(!r)return!1;if(!r.isReady(e.getMesh(),t))return!1;var n=[],o=[No.VertexBuffer.PositionKind],s=e.getMesh(),a=!1,h=!1;if(r&&r.needAlphaTesting()){var l=r.getAlphaTestTexture();l&&(n.push("#define ALPHATEST"),s.isVerticesDataPresent(No.VertexBuffer.UV2Kind)&&1===l.coordinatesIndex?(n.push("#define DIFFUSEUV2"),h=!0):s.isVerticesDataPresent(No.VertexBuffer.UVKind)&&(n.push("#define DIFFUSEUV1"),a=!0))}i&&(n.push("#define EMISSIVE"),s.isVerticesDataPresent(No.VertexBuffer.UV2Kind)&&1===i.coordinatesIndex?(n.push("#define EMISSIVEUV2"),h=!0):s.isVerticesDataPresent(No.VertexBuffer.UVKind)&&(n.push("#define EMISSIVEUV1"),a=!0)),a&&(o.push(No.VertexBuffer.UVKind),n.push("#define UV1")),h&&(o.push(No.VertexBuffer.UV2Kind),n.push("#define UV2")),s.useBones&&s.computeBonesUsingShaders?(o.push(No.VertexBuffer.MatricesIndicesKind),o.push(No.VertexBuffer.MatricesWeightsKind),s.numBoneInfluencers>4&&(o.push(No.VertexBuffer.MatricesIndicesExtraKind),o.push(No.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"),t&&(n.push("#define INSTANCES"),o.push("world0"),o.push("world1"),o.push("world2"),o.push("world3"));var c=n.join("\n");return this._cachedDefines!==c&&(this._cachedDefines=c,this._glowMapGenerationEffect=this._scene.getEngine().createEffect("glowMapGeneration",o,["world","mBones","viewProjection","diffuseMatrix","color","emissiveMatrix"],["diffuseSampler","emissiveSampler"],c)),this._glowMapGenerationEffect.isReady()},e.prototype.render=function(){var e=this._glowMapMergeEffect;if(e.isReady()&&this._blurTexture.isReady()){var t=this._scene.getEngine();this.onBeforeComposeObservable.notifyObservers(this),t.enableEffect(e),t.setState(!1);var i=t.getStencilBuffer(),r=t.getStencilFunction(),n=t.getStencilMask(),o=t.getStencilOperationPass(),s=t.getStencilOperationFail(),a=t.getStencilOperationDepthFail(),h=t.getAlphaMode();e.setTexture("textureSampler",this._blurTexture),t.bindBuffers(this._vertexBuffers,this._indexBuffer,e),t.setStencilOperationPass(No.Engine.REPLACE),t.setStencilOperationFail(No.Engine.KEEP),t.setStencilOperationDepthFail(No.Engine.KEEP),t.setAlphaMode(this._options.alphaBlendingMode),t.setStencilMask(0),t.setStencilBuffer(!0),t.setStencilFunctionReference(this._instanceGlowingMeshStencilReference),this.outerGlow&&(e.setFloat("offset",0),t.setStencilFunction(No.Engine.NOTEQUAL),t.drawElementsType(No.Material.TriangleFillMode,0,6)),this.innerGlow&&(e.setFloat("offset",1),t.setStencilFunction(No.Engine.EQUAL),t.drawElementsType(No.Material.TriangleFillMode,0,6)),t.setStencilFunction(r),t.setStencilMask(n),t.setAlphaMode(h),t.setStencilBuffer(i),t.setStencilOperationPass(o),t.setStencilOperationFail(s),t.setStencilOperationDepthFail(a),t._stencilState.reset(),this.onAfterComposeObservable.notifyObservers(this);var l=this._mainTexture.getSize();this.setMainTextureSize(),l.width===this._mainTextureDesiredSize.width&&l.height===this._mainTextureDesiredSize.height||(this.onSizeChangedObservable.notifyObservers(this),this.disposeTextureAndPostProcesses(),this.createTextureAndPostProcesses())}},e.prototype.addExcludedMesh=function(e){this._excludedMeshes&&(this._excludedMeshes[e.uniqueId]||(this._excludedMeshes[e.uniqueId]={mesh:e,beforeRender:e.onBeforeRenderObservable.add(function(e){e.getEngine().setStencilBuffer(!1)}),afterRender:e.onAfterRenderObservable.add(function(e){e.getEngine().setStencilBuffer(!0)})}))},e.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}},e.prototype.hasMesh=function(e){return!!this._meshes&&(void 0!==this._meshes[e.uniqueId]&&null!==this._meshes[e.uniqueId])},e.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}},e.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),delete this._meshes[e.uniqueId]),this._shouldRender=!1;for(var i in this._meshes)if(this._meshes[i]){this._shouldRender=!0;break}}},e.prototype.shouldRender=function(){return this.isEnabled&&this._shouldRender},e.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?No.Tools.GetExponentOfTwo(this._mainTextureDesiredSize.width,this._maxSize):this._mainTextureDesiredSize.width,this._mainTextureDesiredSize.height=this._engine.needPOTTextures?No.Tools.GetExponentOfTwo(this._mainTextureDesiredSize.height,this._maxSize):this._mainTextureDesiredSize.height)},e.prototype.defaultStencilReference=function(t){t.getScene().getEngine().setStencilFunctionReference(e.normalMeshStencilReference)},e.prototype.disposeTextureAndPostProcesses=function(){this._blurTexture.dispose(),this._mainTexture.dispose(),this._downSamplePostprocess.dispose(),this._horizontalBlurPostprocess.dispose(),this._verticalBlurPostprocess.dispose()},e.prototype.dispose=function(){var e=this._vertexBuffers[No.VertexBuffer.PositionKind];if(e&&(e.dispose(),this._vertexBuffers[No.VertexBuffer.PositionKind]=null),this._indexBuffer&&(this._scene.getEngine()._releaseBuffer(this._indexBuffer),this._indexBuffer=null),this.disposeTextureAndPostProcesses(),this._meshes){for(var t in this._meshes){(i=this._meshes[t])&&i.mesh&&(i.observerHighlight&&i.mesh.onBeforeRenderObservable.remove(i.observerHighlight),i.observerDefault&&i.mesh.onAfterRenderObservable.remove(i.observerDefault))}this._meshes=null}if(this._excludedMeshes){for(var t in this._excludedMeshes){var i;(i=this._excludedMeshes[t])&&(i.beforeRender&&i.mesh.onBeforeRenderObservable.remove(i.beforeRender),i.afterRender&&i.mesh.onAfterRenderObservable.remove(i.afterRender))}this._excludedMeshes=null}var r=this._scene.highlightLayers.indexOf(this,0);r>-1&&this._scene.highlightLayers.splice(r,1),this.onDisposeObservable.notifyObservers(this),this.onDisposeObservable.clear(),this.onBeforeRenderMainTextureObservable.clear(),this.onBeforeBlurObservable.clear(),this.onBeforeComposeObservable.clear(),this.onAfterComposeObservable.clear(),this.onSizeChangedObservable.clear()},e.neutralColor=new No.Color4(0,0,0,0),e.glowingMeshStencilReference=2,e.normalMeshStencilReference=1,e}(),No.HighlightLayer=Vo,function(e){var t,i;(i=t=e.AssetTaskState||(e.AssetTaskState={}))[i.INIT=0]="INIT",i[i.RUNNING=1]="RUNNING",i[i.DONE=2]="DONE",i[i.ERROR=3]="ERROR";var r=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=r;var n=function(){return function(e,t,i){this.remainingCount=e,this.totalCount=t,this.task=i}}();e.AssetsProgressEvent=n;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 Y(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}(r);e.MeshAssetTask=o;var s=function(e){function t(t,i){var r=e.call(this,t)||this;return r.name=t,r.url=i,r}return Y(t,e),t.prototype.runTask=function(e,t,i){var r=this;e._loadFile(this.url,function(e){r.text=e,t()},void 0,!1,!0,function(e,t){e&&i(e.status+" "+e.statusText,t)})},t}(r);e.TextFileAssetTask=s;var a=function(e){function t(t,i){var r=e.call(this,t)||this;return r.name=t,r.url=i,r}return Y(t,e),t.prototype.runTask=function(e,t,i){var r=this;e._loadFile(this.url,function(e){r.data=e,t()},void 0,!0,!0,function(e,t){e&&i(e.status+" "+e.statusText,t)})},t}(r);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 Y(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}(r);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 Y(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}(r);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 Y(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}(r);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 Y(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}(r);e.HDRCubeTextureAssetTask=u;var p=function(){function t(t){this._isLoading=!1,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 n(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._isLoading=!1,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._isLoading=!1,this.tasks=new Array,this},t.prototype.load=function(){if(this._isLoading)return this;if(this._isLoading=!0,this.waitingTasksCount=this.tasks.length,0===this.waitingTasksCount)return this.onFinish&&this.onFinish(this.tasks),this.onTasksDoneObservable.notifyObservers(this.tasks),this._isLoading=!1,this;this.useDefaultLoadingScreen&&this._scene.getEngine().displayLoadingUI();for(var e=0;e<this.tasks.length;e++){var t=this.tasks[e];this._runTask(t)}return this},t}();e.AssetsManager=p}(us||(us={})),ko=us||(us={}),Uo=[],zo=function(e,t){if(!Uo[e.id]&&!e.doNotSerialize){if(e instanceof ko.BoxGeometry)t.boxes.push(e.serialize());else if(e instanceof ko.SphereGeometry)t.spheres.push(e.serialize());else if(e instanceof ko.CylinderGeometry)t.cylinders.push(e.serialize());else if(e instanceof ko.TorusGeometry)t.toruses.push(e.serialize());else if(e instanceof ko.GroundGeometry)t.grounds.push(e.serialize());else if(e instanceof ko.Plane)t.planes.push(e.serialize());else if(e instanceof ko.TorusKnotGeometry)t.torusKnots.push(e.serialize());else{if(e instanceof ko._PrimitiveGeometry)throw new Error("Unknown primitive type");t.vertexData.push(e.serializeVerticeData())}Uo[e.id]=!0}},Go=function(e,t){var i={},r=e._geometry;return r&&(e.getScene().getGeometryByID(r.id)||zo(r,t.geometries)),e.serialize&&e.serialize(i),i},Wo=function(){function e(){}return e.ClearCache=function(){Uo=[]},e.Serialize=function(t){var i,r,n,o={};if(e.ClearCache(),o.useDelayedTextureLoading=t.useDelayedTextureLoading,o.autoClear=t.autoClear,o.clearColor=t.clearColor.asArray(),o.ambientColor=t.ambientColor.asArray(),o.gravity=t.gravity.asArray(),o.collisionsEnabled=t.collisionsEnabled,o.workerCollisions=t.workerCollisions,t.fogMode&&0!==t.fogMode&&(o.fogMode=t.fogMode,o.fogColor=t.fogColor.asArray(),o.fogStart=t.fogStart,o.fogEnd=t.fogEnd,o.fogDensity=t.fogDensity),t.isPhysicsEnabled()){var s=t.getPhysicsEngine();s&&(o.physicsEnabled=!0,o.physicsGravity=s.gravity.asArray(),o.physicsEngine=s.getPhysicsPluginName())}t.metadata&&(o.metadata=t.metadata),o.morphTargetManagers=[];for(var a=0,h=t.meshes;a<h.length;a++){var l=(d=h[a]).morphTargetManager;l&&o.morphTargetManagers.push(l.serialize())}for(o.lights=[],i=0;i<t.lights.length;i++)(r=t.lights[i]).doNotSerialize||o.lights.push(r.serialize());for(o.cameras=[],i=0;i<t.cameras.length;i++){var c=t.cameras[i];c.doNotSerialize||o.cameras.push(c.serialize())}for(t.activeCamera&&(o.activeCameraID=t.activeCamera.id),ko.Animation.AppendSerializedAnimations(t,o),o.materials=[],o.multiMaterials=[],i=0;i<t.materials.length;i++)(n=t.materials[i]).doNotSerialize||o.materials.push(n.serialize());for(o.multiMaterials=[],i=0;i<t.multiMaterials.length;i++){var u=t.multiMaterials[i];o.multiMaterials.push(u.serialize())}for(t.environmentTexture&&(o.environmentTexture=t.environmentTexture.name),o.skeletons=[],i=0;i<t.skeletons.length;i++)o.skeletons.push(t.skeletons[i].serialize());for(o.transformNodes=[],i=0;i<t.transformNodes.length;i++)o.transformNodes.push(t.transformNodes[i].serialize());o.geometries={},o.geometries.boxes=[],o.geometries.spheres=[],o.geometries.cylinders=[],o.geometries.toruses=[],o.geometries.grounds=[],o.geometries.planes=[],o.geometries.torusKnots=[],o.geometries.vertexData=[],Uo=[];var p=t.getGeometries();for(i=0;i<p.length;i++){var f=p[i];f.isReady()&&zo(f,o.geometries)}for(o.meshes=[],i=0;i<t.meshes.length;i++){var d;if((d=t.meshes[i])instanceof ko.Mesh){var m=d;m.doNotSerialize||m.delayLoadState!==ko.Engine.DELAYLOADSTATE_LOADED&&m.delayLoadState!==ko.Engine.DELAYLOADSTATE_NONE||o.meshes.push(Go(m,o))}}for(o.particleSystems=[],i=0;i<t.particleSystems.length;i++)o.particleSystems.push(t.particleSystems[i].serialize());for(o.lensFlareSystems=[],i=0;i<t.lensFlareSystems.length;i++)o.lensFlareSystems.push(t.lensFlareSystems[i].serialize());for(o.shadowGenerators=[],i=0;i<t.lights.length;i++){var g=(r=t.lights[i]).getShadowGenerator();g&&o.shadowGenerators.push(g.serialize())}for(t.actionManager&&(o.actions=t.actionManager.serialize("scene")),o.sounds=[],i=0;i<t.soundTracks.length;i++)for(var _=t.soundTracks[i],v=0;v<_.soundCollection.length;v++)o.sounds.push(_.soundCollection[v].serialize());return o},e.SerializeMesh=function(t,i,r){void 0===i&&(i=!1),void 0===r&&(r=!1);var n={};if(e.ClearCache(),t=t instanceof Array?t:[t],i||r)for(var o=0;o<t.length;++o)r&&t[o].getDescendants().forEach(function(e){e instanceof ko.Mesh&&t.indexOf(e)<0&&t.push(e)}),i&&t[o].parent&&t.indexOf(t[o].parent)<0&&t.push(t[o].parent);return t.forEach(function(e){!function(e,t){if(e.delayLoadState===ko.Engine.DELAYLOADSTATE_LOADED||e.delayLoadState===ko.Engine.DELAYLOADSTATE_NONE){e.material&&(e.material instanceof ko.StandardMaterial?(t.materials=t.materials||[],t.materials.some(function(t){return t.id===e.material.id})||t.materials.push(e.material.serialize())):e.material instanceof ko.MultiMaterial&&(t.multiMaterials=t.multiMaterials||[],t.multiMaterials.some(function(t){return t.id===e.material.id})||t.multiMaterials.push(e.material.serialize())));var i=e._geometry;i&&(t.geometries||(t.geometries={},t.geometries.boxes=[],t.geometries.spheres=[],t.geometries.cylinders=[],t.geometries.toruses=[],t.geometries.grounds=[],t.geometries.planes=[],t.geometries.torusKnots=[],t.geometries.vertexData=[]),zo(i,t.geometries)),e.skeleton&&(t.skeletons=t.skeletons||[],t.skeletons.push(e.skeleton.serialize())),t.meshes=t.meshes||[],t.meshes.push(Go(e,t))}}(e,n)}),n},e}(),ko.SceneSerializer=Wo,Ho=us||(us={}),jo=function(){function e(e,t,i,r){void 0===r&&(r=!0);var n=this;this.name=e,this._viewMatrix=Ho.Matrix.Identity(),this._target=Ho.Vector3.Zero(),this._add=Ho.Vector3.Zero(),this.invertYAxis=!1,this.position=Ho.Vector3.Zero(),this._scene=i,this._scene.reflectionProbes.push(this),this._renderTargetTexture=new Ho.RenderTargetTexture(e,t,i,r,!0,Ho.Engine.TEXTURETYPE_UNSIGNED_INT,!0),this._renderTargetTexture.onBeforeRenderObservable.add(function(e){switch(e){case 0:n._add.copyFromFloats(1,0,0);break;case 1:n._add.copyFromFloats(-1,0,0);break;case 2:n._add.copyFromFloats(0,n.invertYAxis?1:-1,0);break;case 3:n._add.copyFromFloats(0,n.invertYAxis?-1:1,0);break;case 4:n._add.copyFromFloats(0,0,1);break;case 5:n._add.copyFromFloats(0,0,-1)}n._attachedMesh&&n.position.copyFrom(n._attachedMesh.getAbsolutePosition()),n.position.addToRef(n._add,n._target),Ho.Matrix.LookAtLHToRef(n.position,n._target,Ho.Vector3.Up(),n._viewMatrix),i.setTransformMatrix(n._viewMatrix,n._projectionMatrix),i._forcedViewPosition=n.position}),this._renderTargetTexture.onAfterUnbindObservable.add(function(){i._forcedViewPosition=null,i.updateTransformMatrix(!0)}),i.activeCamera&&(this._projectionMatrix=Ho.Matrix.PerspectiveFovLH(Math.PI/2,1,i.activeCamera.minZ,i.activeCamera.maxZ))}return Object.defineProperty(e.prototype,"samples",{get:function(){return this._renderTargetTexture.samples},set:function(e){this._renderTargetTexture.samples=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"refreshRate",{get:function(){return this._renderTargetTexture.refreshRate},set:function(e){this._renderTargetTexture.refreshRate=e},enumerable:!0,configurable:!0}),e.prototype.getScene=function(){return this._scene},Object.defineProperty(e.prototype,"cubeTexture",{get:function(){return this._renderTargetTexture},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"renderList",{get:function(){return this._renderTargetTexture.renderList},enumerable:!0,configurable:!0}),e.prototype.attachToMesh=function(e){this._attachedMesh=e},e.prototype.setRenderingAutoClearDepthStencil=function(e,t){this._renderTargetTexture.setRenderingAutoClearDepthStencil(e,t)},e.prototype.dispose=function(){var e=this._scene.reflectionProbes.indexOf(this);-1!==e&&this._scene.reflectionProbes.splice(e,1),this._renderTargetTexture&&(this._renderTargetTexture.dispose(),this._renderTargetTexture=null)},e}(),Ho.ReflectionProbe=jo,Xo=us||(us={}),Yo=function(){function e(e,t,i,r,n){this.name=e,this.scale=new Xo.Vector2(1,1),this.offset=new Xo.Vector2(0,0),this.alphaBlendingMode=Xo.Engine.ALPHA_COMBINE,this.layerMask=268435455,this._vertexBuffers={},this.onDisposeObservable=new Xo.Observable,this.onBeforeRenderObservable=new Xo.Observable,this.onAfterRenderObservable=new Xo.Observable,this.texture=t?new Xo.Texture(t,i,!0):null,this.isBackground=void 0===r||r,this.color=void 0===n?new Xo.Color4(1,1,1,1):n,this._scene=i||Xo.Engine.LastCreatedScene,this._scene.layers.push(this);var o=this._scene.getEngine(),s=[];s.push(1,1),s.push(-1,1),s.push(-1,-1),s.push(1,-1);var a=new Xo.VertexBuffer(o,s,Xo.VertexBuffer.PositionKind,!1,!1,2);this._vertexBuffers[Xo.VertexBuffer.PositionKind]=a,this._createIndexBuffer(),this._effect=o.createEffect("layer",[Xo.VertexBuffer.PositionKind],["textureMatrix","color","scale","offset"],["textureSampler"],""),this._alphaTestEffect=o.createEffect("layer",[Xo.VertexBuffer.PositionKind],["textureMatrix","color","scale","offset"],["textureSampler"],"#define ALPHATEST")}return Object.defineProperty(e.prototype,"onDispose",{set:function(e){this._onDisposeObserver&&this.onDisposeObservable.remove(this._onDisposeObserver),this._onDisposeObserver=this.onDisposeObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"onBeforeRender",{set:function(e){this._onBeforeRenderObserver&&this.onBeforeRenderObservable.remove(this._onBeforeRenderObserver),this._onBeforeRenderObserver=this.onBeforeRenderObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"onAfterRender",{set:function(e){this._onAfterRenderObserver&&this.onAfterRenderObservable.remove(this._onAfterRenderObserver),this._onAfterRenderObserver=this.onAfterRenderObservable.add(e)},enumerable:!0,configurable:!0}),e.prototype._createIndexBuffer=function(){var e=this._scene.getEngine(),t=[];t.push(0),t.push(1),t.push(2),t.push(0),t.push(2),t.push(3),this._indexBuffer=e.createIndexBuffer(t)},e.prototype._rebuild=function(){var e=this._vertexBuffers[Xo.VertexBuffer.PositionKind];e&&e._rebuild(),this._createIndexBuffer()},e.prototype.render=function(){var e=this.alphaTest?this._alphaTestEffect:this._effect;if(e.isReady()&&this.texture&&this.texture.isReady()){var t=this._scene.getEngine();this.onBeforeRenderObservable.notifyObservers(this),t.enableEffect(e),t.setState(!1),e.setTexture("textureSampler",this.texture),e.setMatrix("textureMatrix",this.texture.getTextureMatrix()),e.setFloat4("color",this.color.r,this.color.g,this.color.b,this.color.a),e.setVector2("offset",this.offset),e.setVector2("scale",this.scale),t.bindBuffers(this._vertexBuffers,this._indexBuffer,e),this.alphaTest?t.drawElementsType(Xo.Material.TriangleFillMode,0,6):(t.setAlphaMode(this.alphaBlendingMode),t.drawElementsType(Xo.Material.TriangleFillMode,0,6),t.setAlphaMode(Xo.Engine.ALPHA_DISABLE)),this.onAfterRenderObservable.notifyObservers(this)}},e.prototype.dispose=function(){var e=this._vertexBuffers[Xo.VertexBuffer.PositionKind];e&&(e.dispose(),this._vertexBuffers[Xo.VertexBuffer.PositionKind]=null),this._indexBuffer&&(this._scene.getEngine()._releaseBuffer(this._indexBuffer),this._indexBuffer=null),this.texture&&(this.texture.dispose(),this.texture=null);var t=this._scene.layers.indexOf(this);this._scene.layers.splice(t,1),this.onDisposeObservable.notifyObservers(this),this.onDisposeObservable.clear(),this.onAfterRenderObservable.clear(),this.onBeforeRenderObservable.clear()},e}(),Xo.Layer=Yo,Ko=us||(us={}),Qo=function(){function e(){}return e.CreateResizedCopy=function(e,t,i,r){void 0===r&&(r=!0);var n=e.getScene(),o=n.getEngine(),s=new Ko.RenderTargetTexture("resized"+e.name,{width:t,height:i},n,!e.noMipmap,!0,e._texture.type,!1,e._samplingMode,!1);s.wrapU=e.wrapU,s.wrapV=e.wrapV,s.uOffset=e.uOffset,s.vOffset=e.vOffset,s.uScale=e.uScale,s.vScale=e.vScale,s.uAng=e.uAng,s.vAng=e.vAng,s.wAng=e.wAng,s.coordinatesIndex=e.coordinatesIndex,s.level=e.level,s.anisotropicFilteringLevel=e.anisotropicFilteringLevel,s._texture.isReady=!1,e.wrapU=Ko.Texture.CLAMP_ADDRESSMODE,e.wrapV=Ko.Texture.CLAMP_ADDRESSMODE;var a=new Ko.PassPostProcess("pass",1,null,r?Ko.Texture.BILINEAR_SAMPLINGMODE:Ko.Texture.NEAREST_SAMPLINGMODE,o,!1,Ko.Engine.TEXTURETYPE_UNSIGNED_INT);return a.getEffect().executeWhenCompiled(function(){a.onApply=function(t){t.setTexture("textureSampler",e)};var t=s.getInternalTexture();t&&(n.postProcessManager.directRender([a],t),o.unBindFramebuffer(t),s.disposeFramebufferObjects(),a.dispose(),t.isReady=!0)}),s},e.GetEnvironmentBRDFTexture=function(e){if(!e._environmentBRDFTexture){var t=Ko.Texture.CreateFromBase64String(this._environmentBRDFBase64Texture,"EnvironmentBRDFTexture",e,!0,!1,Ko.Texture.BILINEAR_SAMPLINGMODE);t.wrapU=Ko.Texture.CLAMP_ADDRESSMODE,t.wrapV=Ko.Texture.CLAMP_ADDRESSMODE,e._environmentBRDFTexture=t}return e._environmentBRDFTexture},e._environmentBRDFBase64Texture="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQAAAAEACAYAAABccqhmAAAgAElEQVR4Xu19Z7PtTHbW1g3jMMbGmGDAZAMm5xxMLDAU0WSKWOQcCoqccw6eGdtgk4yNbZxnvvAL+Af8Af6AsQl+06ako9X36dXPSi3pnPu+cz/cOntL3S1pq5+w1mrpLs/eud9fvn27rf9evPPwFz+v22S7fGZ/n7/70G79J5/Xv/qzbLP+Pnvvoc/6Tz7jX/15/c62LfeH7fofbpfP3l/ct36Wf+u4+D37+XYb++G26LPsr/zFttnPuh37bm1bt0f7MvtlnOx4uv0H4fty8UUsz77rfn/57u32cgXvDv72eQf0tl0+G38b0Nf9K4Dl704MEfA16KsE8Gw9JgD+DQE8EA0DT2b7GwK4GHnF4a8iguXZt9/vL5/dbisJbEq/uwD5vIK/fbbAv4N9U/8nJIDNCazKvBLBGwdwu62OhajxmQSAx6gqNp5HCg9wPan2nwSNjhLD8ux/3u8vP3y7vbwDAYjtR8AzFyDqLu1Q+YEINnew23rPCYiKb+q/K7o4AVT4tg0t/h4ydJZfkQASQ/d5b9fZ/Z1ENmuPn/cwYCYEELBguKC3nRkCnE0AFOwOKCOAR/sH/L4hgFMpbSWP5dn/uN9ffs7t9mJ5cAHoBLTyszBAFJ/F/xIKdASw5wgaEWDMLySxAk4svf6L+4QAGPiJCziNAPb4f3UZ2dh/m+z7BK4SAPYrxf5FB6ABPgCUAfANAZwKyscc7IEA/vv9/uLzbreXzx9cQCMACAl00m8jAlF7ov6SCMQ8gJsMFFBnCECSg5H6TxJAU3vPAbwhgFfz9AABeOEDBcIbB3AqPzwQwH+731/8sNvt5Ydut5e3B2C/fG9P+jESgGz/RgxG9r9VAwTUUh0goQDafUz+DYnAnSha5l99Z1l/yQVswAZSGIAugNd/9xBgCw9E8aECkHUB22QPHIAVDlQdQAMWAibhBgZAasAVHUAI8Cqg96Tm0bj3VBS9jwd7IIBvuN9ffMHt9vLTbreXy+32QlwAhgMIeuNzKwOqCoB2Aa00KHE+EsIeDuj4H2N+Hf/TfAC6A4nhgQCQDDwiaKDXiq9KgBEJNPArAtCk0AEd2mpAizW3/lYIoANpBPg3BPA+hjs/9eXZV+0E8Bm32wsJA9aEoBCAuAABPiEAC/yDC4gSgRgKRHkAlgsI6v7iEFqJEMgBwb4BGkEfEEDnDlReoAP/SQRgOYIB+IYDMEE/SQBbXoLNr0jhq4qOZc0PHBSf5oKW519xvz//kbfby8+83V68ABfwniIBgwgQ/HoRUMv8w5qAoQqgk4DWQiCw+63eD8k/XAPQgK5s/5a5xzAAqgR6wY9k+ZEMtCOoJABb230hEHMFWQdgAl0Ap/+uc6tKBrrP/n0AuwfiNwTwNKguHHV5/qX3+/M1B/Ddb7cXax7g2e324vaQB3hhkMAW92tHoFb96cVAbimwkgQ0Vv7R+D8iACfuxzKfLvnNlAAjAsBwwP2MwLQAD9sbYJME0AFcg5uBPSAA0x0AobhtcDKDA0j3KYDhk7Hp8uKj9/vzH3C7vfget9uLT9nDgDUZuOYCLBJA8MNKPyGGIftPrL+4gy3eh5p/lwRUYYAs9Fn7tM/E9lvJwCH2DxJ/mPTr4nyyLiDtBgTAGCrgNuPzNuETgN+suEEAFhng9lkCoICMLH7V0isCeEMCxylrefkl9/uzz90J4NNUGLDmAnYXINUBrf5dCCAuQCcCvYVAYPk3G++VAveVfkIAFRLolgbr2F9ifP33pAqAV/fHRF4HcAS7AKlAAEIYFNwITOszs/wMsB6II4BXFZ0QwBsSOEYCDwTw2TsBfPrt9uLlqzCgcwFABI0EVCiANl8Uvq0JWNsi2JPZ/0YKsOiHxftsW4v51ZqAaBWgZf91PsBL/jFHwEqBR1cCiuJ3gAfCmCEA3cf8rmz8AMZHIoA3JDBPAsuHVgL4jNvt+UoCH34ggK0asIYBGArsAB7AD+reQgCl+GwZ8LaNlP3MEEDaSg4ACMGr/+ulwV4JsAEfLH42/vdKgWElAJ4QpBl+LAlKErHwt+oGMgTA2ngE4IUIOH3dGr/hAKT/m/UBdSJYPuVL7vflU26352sScCWAD+0EsCcDVxewKjfmAzAsENVn4EfgdySgnYB81yEAgL4RA8T8mTUASAAYBgylQAkL8K/+zL6rsl8qF6ArAeS7WRGoAB8Sf7isN/VZqTs6jQ5wXlweWfyqpQ8I4I0TmCCAT/3I/b48u92ef9bt9nwNAdZE4FoOFALYXcAGegkDMByAzzQEgJh+cAIs/legH0IA5QTCPADE+7ISkD0TgA/8sBIgLQfOgF/F9kPcr+J8fIYguyCILQRKgV4DNviOzoKqeJS0u4AA3pBAjQSWT//I/b5OmC0MWB3ASgBrGLA+IryvDNxCgRXo+wKhjgwk8bcTwUACsJ09ANRVAALwCxmEoFcrAUsuAJ4M1E8BDuHABAHomJ8RgACrZfQLyT9dBWi2OOEG9NJd/TDQ8HAQuBE97ZhjGKy6o+imnU+4gDckkCeB5cMfud/v6zr9Dz84gOdCAM/3JwQhF9CAD25gBWWz/8wNgMpj3K9Lfy0foMMBVffXyT4r+cceC9bvCcDFP0311QrATPkvWgosYQFLAuoqQEcQuw3v2si25F+M1RkZXLUU+CgBmCBOEsCbvECOBJbP+Oj9fv+u2+3Zp91uz9cy4Kfebs/3ROD6iPD2b10YJCXB+0PyrgsHdtBuRACfBeTN+uM+suJPSEDbfh3/oxPoHgwiC3/06j8Eutj69sAQqj++I0CUfvIpwCEvYCT90O4Pn1XsT5Ve1/+dcp9FBh3woqXBSEJkvjHHEOUPqJPAjUUCeOMGfCJYPvOj9/t7//d2e7YmAlcS2B3A8xcPYcBm/7ULEDIQew+5gS0EIEA31R8Uf6gAoBsgKwBd9ddvBBJAs6XARgLQXQ2o7T8+IETe+9eRACg7rhCMVgCiE8D4O9wOCb2ubOht1/vYd2ubzLlgKbBHEDSnAMfL6durVm8qBPwXWz7rY/f7/X/fbsvL2+3Zqv4QAjzfw4COAMAJbEC3wC8koBJ9lAhgxZ+4hi3Oh/f8dU8EqtV/JhHgWn9cC4CJQZXZp6GAk/1nawMkrrcqAiwPIIA2FwOB2oaAF5UkcX+GADBs0I5gsNbBQqCorJcFJjqWKvhNMjky0Aek7/LZH7vf3/vO2215vruAD91uz/dSYCOAPQzYkoD7vw34sFIQw4LNymNSUKk8Wv0hCYhkoJ74Q6BboO9eDKoWAHXvBiCvAdPZf4nt3QqA924AbfXV8t8uN4Bt2We029WkoErWpSoCSm11TM8AOYA5uRS4RAITIQDDavaYHxCcm5exfM7H7vd3v2N9McDt9uxDD//WKsAG/ue32/M1DEACuO3g1jkBsf57fqCL/7UbIISAio85AAG0VQEYiIC9DJTYfy/+Dx8HlpeDRK8G90IBHQbgWgD2WT8LoOJ7NyeA5JEkAwwxmuqzur5X6y+sBEwDMggrqoBNH7c68Puk/fI9Vwfwvx4e6H724oEA1iSg5AAaAewlweeyLmAnAHQCTfU1CTAH4GyTMt+QDMRFQFEYQB71lXUAOjHYlvTqh4N2xe5yASoh2PpaJUGDBDrLr9cGIDlY1l+vDlQOAQHckYMiA68KMFsGtOy65RCGsMIDT+QqJoD3yUwCy/f+6P3+7koAt50AXrwigM0FrIuEoBrwHMMAUhmQUKAlAwHo7VmAPURo9h/r//ozLv1V7/5v6wGMV4B3rwYPXEBqIZAQwp4TYDE+LQlqtQfw6my/LgsyZaeLg7wVgmDnWQ5AA5ZWCDRx7ECzyn3udgFptFCIgTlyFRMEUCKgA+O/jl2Xz/3o/f7Otz88QvpszQOsLmAPARoBSDVgud02AthdwPZ5BSxUBVr8L3kAVHrvs076KSLQi3/M9QCJ7H/G/rf4n8X41XIgcwHecuBMDgAe+BHA6uQgqnvbF5DB5hwUQM3vQgIWkKOVftH+gAC6cz0RXZ9MjmD5fh/ZCWCd1CsB7CSwhgArAUgIIC5AQoDOCewJwab+CH79WR4C0mQAZT4hEQS9DgfEztNkoEECDfi6FAhZflb6Q1XXqwHDEECpvZX4a0qP1l7bfAS98cQfzQUo9a4mASMC0CsIm6JGK/2i/QkCuFK9PxmIYPm8nQDu795uy3K7LTvwVyJAB7ARwJoAVLkA7QIkJ9A5AQS95Ad2YmgvAJWwQFcBpB38pUuB9wVKbAWgCXwV86Mz2ICKTwUWFgOxMEBicr0eoBwCGBUADfxsDsAiA+zflNay31ZcfnAdAAXgDGkcdAcfZCJYfuCX3O9vf/vtthHAmgcQF7ATwOoAtn9IACsRSDkQ/wqIIUGoXYEQQ/sL5IDJP539776DwodVAGlr5QBgP8sDdApP3gSUXQa8/rZsRaBeHmy+HwDyCI1MUNlZzX9iJSBO9igJGJYCo4RdIqMfJQ4Ztq8C7FXjHuSnQ92XH/yvdwJ4Z68ErOXAlQRW0O9/JRG42v9GBHsuAImAqv+uzDo30C3yAfVHoHeg9xyAp/7wlp+WFCSWv1sOTBb+0EoAZP5DImBrApAUMFHolQG19c+EAkbpjyUEdQ6gm/QEsCzZFxKDlWNwprJVWfBm/1WAvWrcQ0ie7Lz80H91v7/9v263+9sPI2zrAZAEdvXvXMBKBJIIFDcgyUAEvHICg/o7wA/Bvyt35wCc2F9Cg03RvRyAA34N8hD0xsIfXP7bQgDMFSgyYO8GsF4N/hQ5ALak1yUGRQDZZJ5VWXgKEsie8yQuH63b8vn/8oEA3lsJYJ2EQgD73xX4z9bs/74gaHMBQgA7+DsXAJWBBniHCLTtNx2AUnkG/LYNiUCpvX7wp6sIOHF/lwgkNf8UGagwYMgLMBdgLQCyVgOyciCGCs5nz/Jr8EXOQOcQZEbrfjjTU8qaCBseMyx4vxPB8iP+RU8A24Kg9R8Qgaj/av8lDBgcwApQ+QdVgW0bKr3+jsk//AztzBKgtv4K+Kj08rl7JFgt9BnCAIsQcD2AsQAolQj0CAGAqhOFCK5u3cA+84dyIJLCPm6buAgoBa5qDoDF6wzUkZ13iSDKKwTamSKZSf29cuzJUwq7LV/wz18RwH2Nl9dKABLArv6bC5B/+9OBGxmsIIR1AQ3w2gk4RECTfwBulgC0rP96/FYJUOv9SzkAB/xuKTBY/qsTgZ0LILF/s/RW9v81ywEwhbeAwUIH6hRwGp+wEOhqoF49fojqQoPlR/+z+/3t77jd3n3rdru999CzEYAQAYJfXACEAqL8W5lQgA5uoJUK9zxBB3ii9ALiYT2AjvuN72wFILP+XdlP8gLKFeg6f5QM3AC+VlMMZ9ABGuN+VePHWL6tHVD23or3tQPo2iWfBRgShDp0ELcBjmIAbwTWqEzIJvLM6kEDEFcD9erxCzg3my4/9p/e7299x+323lu32+oAtjwAhgE7Cazqv7mAvRLQcgG7A9B5AAwHus87CWBYsIKFfe+eCSBgt2J+7QBQ+VsogOU/9fIPBvLhASEF8AHwlhPQ2wVYFhmo/Wby74QyYLcmQAEbbbue2FcnAb28QTmHQKBwNVCvHv8IESw//h/f7299pyIA7QIE/LsTeIbqL59hPUADvHIBG8jBIWgn0L4rsKMj2Noomz8QgZELsCoAAnh0Caj8lup7ib9tX+ZBoKgUmFkWTGJ8S/UHZa/kAHT+QGaeoeQmMUC/CoAzVYAjYDvSNwPCq8fPnINus/zEfwQE8O7tdt8dwGZjIQQQ9Y9cwAB+RQIC4I4MdvvdLL+O//E7LgLykn6q3Efjf6X8bOUfkoNYcQZ8z/KzBUBYCqT/YQgjBuOBHxPs7JHh7JoAy/IzWz+xEtBKBEYg8fIGw+SeQQQ+CzHZP+oWXWPU/8z9y0/+h/f729/5kAN4791X/6/cpl4SCsDfLRQwHEBLCmJFYH92vssNgBPo7D8qv4CekIHpAjKgx1iffGbKb5UAQwdguIAtz2KsEWj7vIQggNON91lYoIFN2mznYKj9UBmwQgXLLcDstRTdBchEFWAWcLP9MgC9cuzM8aXN8lP//v3+9v/uCUDyAM0FIBFADqAjAsgFiAvYwK3/MfAL8InSd/Yfy37Qpyv3OSTgxf8C5vZXPfF3aB2AA3hJGg5LghMOgCUBo8SgEAyC3Irvh5xAwhW0cT1iQBKYWds/QQLdeVUQcrEjeGoiWH7633sggHfWJOAaAkglYL/wLQyQf3tYsCp9CwmgFIgOgIJ/JwMdBuB3cQTDX4z9wR2whN+WE9idh67761p/F/8bpb8O/OotQCsJDhZfji0qT9p0LsCI83X9H8E9KH8iCSiTrQO29bwAAbvlCipPAw4T/oRKQAVElbaMJ472t7jnqnEjrlt+1t+539/6P4oAxLquawIkF7Bb/40M9hAAHcD2GVzABmBYKSgxfyMGAbROCipl1w6gs/8ZF0Cy/UIOOr7vHAIu9iHP/2v77yX9ROUt29+AHVUCnDJgtvSn8wXsnQGzIUAW3F27qFS4z2CrD07wCogqbR8LtGecUwR4vX/5OX/7FQFsOYC9FCiToBGAEAH83ZwA5AM06BspiPKrNQIt/kcg69iffBegNqVXb/wdQgIMC0DltUuQ+L+Bmz0OrNTdK/91+4JVf15SEPMCYRkwEfc3stBxurMS0AoTMKRocaV8cKw6jpcFsdUn2/8qRT8buGeP55HC8vP+5v3+1v99cADvvfNQBZB4dO24Kv5GAntSUOz/+n1wAis4wAnoMAC/N9svSUKsBABgmwPAbQTwWzsW/2vAI6j14h+1CEjnBYZFQWSxj+sEVFyPjgBBrhf+aOtPY39vRaBVJlQ2vyOGIATQsb6etBguDMSQyAF4IMhUAmZANNNnUNSqBDvtzzif6HSWL/wbuwN4eycA4gDEBQgRYPzfSGC3/BYBdOCHxKBHBAJoAbdWfIz1I9XXsf5g9y0yAJB7iUDPCaC6e2EA2ngMGyIHwAgBldncf4ID0EDXVp1NYmbnrclOtyfDhiPOoCO4CEXB/rOBfOZ4yy/8a7sDAALY1gKAfWMEgOovoNdk0IArKr+7gwH02gWQ2L4t/sEEoLL2IQnoFX96HYC4CIz/jcSgAJSVAtu2RPZ/SPRBHkC7AkYEqceC2fqBfdKaCcHAAeAkpKVBCANcElBVgBQRTC4HngHOTJ+rQo2jhEbP6xf/VU4AmBza7L+EAZgLgGSgxP8dGQDwmQOQbS2xp6oEWAnQn1seIEMCJO4fsv8Q2w/JQU0IJMvPiCCT/NPuQP/noJ0rAFBa23VSr1N/vQhIgxzzB9odMMIAkGvFZPF6JkyIlJeFFl6IcRYYX0ciOOOcll/6l+/3t/7fngPYy4BSCmyT0SGAlgvY4/+BAET10fZjUhAWCg2AV8nBEPQ6D6DJgSUAoQ/G+Dr+T9l/pfg0HxAs/e3WBUhbsihIgHKkHGiGCQHYO/UHomDgdd0BcRkZlYtyAFlgZNtlzqkSJcwc1xr/6FjLL/tLPQG8t+YA3tuXBKPiqISgAB//bjZdkoNE/Rs5EAIYXIAKCwYHYJADlvhalp8RgS4PogNwFN8jgo1A2LoALxRw1gA09TbCAjckQHBZlQEFwEoS0Iv1S3mAYFGPlwOIJn+0v+ocPohEsHzRX9gJYM0BvPvwTyoB2gGsP6iEAowANsBJWAAVgRYeAPCb/WdkAKEAttNJwRbzM+UPQI8K36k9Kf3RagBTe2vhj3o8uAFXLxUGxTdXBrK1AIltTZ2JzUe7Lp/Ralvxvrb5kcWP9nv2fwBzIRF4FRFkx/XcwRljHCGm5Vf++fv9re+63d4xCABVRhOAJoOtRCguQKoCmghwv7L/mBPQwB/KfMQhCEF0ym8RAUkIToUAxrP/gxOwSoDGmn9WCjTzASw3kHQA5poA7Q4g3n+MEMAChiadiopXwHZV26usvB43e/7Lr/pznADakmBdDcB8AFj+5ggcF4AhgAlwwyUM6m+pPgF8U3BS6jOdAAkJ3HUAO5C7ZKBT99/IVDsGhwyY3e8qNfhCERXDa5BrlW/ftaoqe265Ar0U+PIQQCUzqwqYBYfnSK4AcuW8sjmHaMzl1/zZnQDeud3eXRcCrfH/ngNYbyxzAKL8nQNAMiC5gI0gBNz42XIBAnAkBACwqDyWByPlp2BPWP7WD0Crs/5ewq+1JaBnWX8rEajbDiVAlbNpwHRyAJ4D6EqECQcQWfxo/0wI4E3wcPJnUbSLXqH5A26qHaD9kb7ssKaj+nV/ZiSALRG4rwhsJLBfUKt/k3yAJMGwEtCFBGD/PTIY4n6d8ANyaEk/Q/nPUv8h+WeRgXYCVgIwSwbK3osKi4PonEGUC2C2Pngc2LL73Xanlj9bBTg7BIgAFe2vuoxZS14B7wy/DCT8xX/qfn/rrYccwLtrElA7AJkgkrDSJUHJfO/Z/wZ4Kx8g4IXyYKfm0i9QfkoSJK5HghALr51Ce2Jwv0ad9BvAj1WCidKfZf1x3UDnvPQ90HYf7o1WfSQMGbOpU1D3H6oCynpjPE7VfSccpoalMEHNdAxFKkDLgDzTRo5ZaXukz1E34f1Gy2/8kzEB6MUlsjCoCwWMEAAdgOcGTECrnECn+JYTgPyABn0U82vwt7hfJft0rK9DAlHooTSolH94GxBUAnTSL/reAbz6UBADt344SDkIJBIT5E62HgnEAwgFmjq3ChFkAJUFd7Zd9fwsdZ89nnX85Tf/8Z0A1hwAOgDJAxBbuU1usboYCoiCKvWX+L/lAUDlNUG0bD8Bt7dviP9Vf0v9LbV3XQCz/3qbZf2d0h8D+JAPYDb/RAfArL1l92W7Z/OjEICpOZvkw7bES0EisET7M0RxRNkzx78qJGj37rf+MUUA+zoAnQjs1gTAhJNyFy4X7kBtkYHKB0ifDMgrLiADfJMESGa/Cwe0/a+CHsmA5QQ8N6ByAzJZh1IhEobOAegsvwaVDhEKDkCre0cielYbau4SQfIZggyIM0DMtMkc6ywnMHMsduzlt/+R+/2tt2+3d8QBiAtQSUBaEVDxPyYB22cEuiYDQgJtLUFk7539ke1vgAeAR05gC3ekbAclwuaEjEVA3XoAAnLpT6sBCuStrUrIpqsBHhkwcBOVTecFJAteCAFSyk/GzapwBOJofwV0mbEQkNX2p/X9HX9IEcB7eyLw3q8IlPgSbV/LBThEIMreQJkhAeYOIsDrsELV8VmIgHX9ITGo1L+BnxGB5wQY6IvKLzZZCKD7nsj8m+sADjoAVHk9ga19tF1CzSk5GO8T9MCUAdpZbSqEUW17lpNYfucfvN/fBgfwLlQBcEnwdkA9cdGiCjCgGrCpZhACDMSA6wL28dewgKl6GzuI963EXwtf1Nr/wQ0YMb+bCJwAPgKc5gPIPeiImeUC4B5J2zbZnGXBQjI4Mdk2HFNPYqv9MNlJCJByAzPPEezIiUAe7a8ANjPWGYpePc52Db/799/vb7/zKgQQAnhvDwH0cwFWLqBluwkRYJ7AqgoMTiHjApTqR9ZfbLxbCbCUX1wOKQGiO8ASn7XdKgMimL2SoG4nkxGVnqk+OoeBDHR4AN87EmCWnlULBGiBuiNJMFC5RJB8HsACRgYwZ7WpEEY2pNEuYOoYv/f37Q7g3dvtnT3+39YC6BBAv3IK1wVA9p8SAYC5gRDBqz53QDasvag/dQboGMCy0zBA7e/CgoTyszX/VeA35QeH1YGc2Hwr2YchGn5mJNGVd8FdoEOIHEBo9VkeQc3cqFJgEkPhxSBHwoIMCVTAlx1vlggq4y+/7/fe72+tDuDdV2XARgD7isDtd95BpZWjKRUov4Acwa6BT5OEsEjICg1aBUAl8DpwA2kgQeCYbHsjL0zygfKbll9XC5xk3zYGgM1yA0IKERGgI2PJQJ20M13CAQfgWv1kEjBj+Yc2zlqAGdWPgBPtrwI2O16FXMrn8Ad+z04AaxVgTwDiasAtBNgnrK4E6HBgSApichCBBHkBCnQNbmb1iTPoSEXlDXCfTv6x0EAA2OUDtCPA70bMT6sAXjVAlf4sIhieC8BYXy0CYk5gIPKCA8CJGzoAI5QYJqoRzx8NAZ6KCLLgzra7igSWP/i79hzA6gCAAMQFrBMNSUCrFypUm+x78k/cQRffY45AqatOGDJy0CDHkh5dDERielFhWvrTIYHO+icy/jK+qe6sCkCAH70erLsXylXMWv5GFowQrLyACISU6HZ0W+RALX0Qz2ug4NgYUWScRNQ+q6IZ8GbaVMCdHS99jX/4dwIBCAmsoNd5AHAB1sRDArByAV1YgLkBnfRDF6AtPbP4LNY32lkOgMX/tPynSKFzC466Y2JP+mT+mk8BOiVAVP2MA9COgH4nQGcgHxyCAe5uMicqARTcJ+QBIlB5+6O+V4E7c9wMCSx/9HfkCEDyAMPDJiQZ2AABqtZUVwG7s+ZWMlCDO/F9iPFZso9l/IkDaMRgxPqe4g8JQa30yg14pdaM7TddgWHxXcUPVgLqvnqyWw6AqrlT0jPV33AekYJb4IlAdfX+6LwR0BVi8Yhg+WO//X5/e68AyLMAawlwCAEwF2BkpTfgqwlu5QU6G45KrdYNsNi9qwAQMgjBnyEDI77XYGcxfjXut1wAhlfSptsGoNHJPab6XkLwTAeAk1MIidp+mJlRJYCqPxCABwizr0aUDl3I/ogEMsDMjJEZp0oYjECWP/HbSA4ACEDWAbA8gJ6MjADWbYP6i5LqvyRROBBABHgjXEAV14k963s7d0koOkm/s+J+FiaERADqbjkAHKNNrsRCoE7lmYsQ0HjlPm+dgMzKRLmQkkgyBJhR/SPWPwPyTJuriWD5U78FHMB7eyJQ5QDaYiBhXL0mgGWumRNQAO/KbieTASMOL8bvVgUSq2/lAvAaOvDiwiEjs6/BThdZ6bUBJNvfuQN0Z+pzVzI09nXqrT3UMRMAACAASURBVJcKg+J6xKAnLao7Tvruc6ZcyBS6EDpUXUIEvgyAz2oTnQuqe+aYzT386d98v69rALZ1AEIAazVgz/4zBzC8aorlAdS2rkIgC4e8v2TxkOsGMLeA45I6vgZ7ygFg4g8JQhOdl+FPZv+ZnRey0CQhE4PtH1TfCBmkXQd+S+1ZXkCTiQZq0gG4sb6qMHSAKFYQHpsIMoDMtKla/syYy5/9Tb0DWGP/7R8QgOUA2NtnzEw3LhRS6hjlA9CK6/gfS4XU5rOk427p9bg02cfATtS9CwGcSsB6/taTf9Zvx0ItvQ2JgH7WgEYyMMA+5AwmHMBMDsAjAhrPTz5M9H4mggy4M65g+XO/YSeAXf1lLYAsBca/24D7MwKdakBIYOUBxKYyJ0BDAeIOTOW2QI75AgVkXNVH7b+VBFTgDisAQda/gd5LrCrlZpa/WXJrEVBk+cGxNWAkqwDMQWiFNq2/zNKgDOi6A2NFICULRAV8rrSN7HgEzmh/NH4G2MZlDi8qXf78Fz8QgNj/thjIcADtvw9HNcgQwGxIwPIGLHTQVj8BfszWmzkAlZsQwFrlPbcCYOUCjBwKKwl6pUBRWyFhukxY7LmO7414X8f61BVY4YLY9iDBhy6BTX6LPJCoPHtcAXelbQRUD+gZEojGZyCvjrv8hV/fOwArBGBLgnFpcGdJYUJ0gNknxLDNCwm8xKEV6xtqPwt4DWpm92kIQICN7bSNF2Xv/pLfUgNd5wxoCEAA34GbqL0VAmhSuMIBuIqv8wGJRUQWmCzAfNIQwV/8tff7O+9BEhBKgEMiUIUAXjLQinMbAAAcCIruFWMVgBPFX28iLhW2Yvzu+JCo06A21wAQm69XRVJwk+RpaiEQCxeQKEDlaWhgtEWQWEqvt7vhwoQDKAFfjR+5hytdgjf20X1HLH/kIpa//GtUCLATgE4CogOQz628IwzslKx0gosuG1bWnuUGotJhyzUYYUIjBSsnoJKVXZnPCAeYo3EBH1UDDIA38CniiBR/CA1I1r5VEQBUg/1XVt8jjG7iWZUD5WEz5UIK8sRagIhYquQQgfqI/a/aeBYKZMOD5a/86r0MCGsApAqQcQDbgTQBMNuqJ70GE/nuOgMSGjDFj7ZZhNABnxBTIxon459Vfa9yYpUEEfRU5RXounEUkJEgGJlEYNb9O2IQ16hsO07y9nk2ETjzJKG4JIKUSlgQKqyDzgzQM22ic/AcxPLXflXSAew30no8eDsJvBGWyhmJsKojQOAOi3R0yRFtPcvuqxo/tf7qeryYv2T/mZqT0IARgfzmG9Eg6erP8Jvr+4Tk4Sk6IwnWfgA/IxsCPhmfKWuk3ugcqENIgLwC+hl1j4Ac7c+CPDNOd4/++q/ccwCRA1iFHkqAtBrA3ICh/J46Yp7AjM+DHIK27t1aA0YIbKGPIisrw59NAOqSH/0NEKyMCBS4qwnAtNpnk4JGnN8pfKYKoIgiA2R2DEYglW1XE8FZQI6AHu1vv8nf+BUPBNDKgFYOgDkAsHdmQhAnkhP74kNDg72OwgMP0CRuN90GW+CTdCwWoVluQKv3EAYQ1cZjuOpv9JXJNyT49KIgliMwlByVu7kJUFwvPBjcQuaxYSuUOBAGZMjGIxEP1BEQn3z/3/oi4gA0CQD4uxAACMBLCKLNjFSPJd3Q7rtJOWu1oZNcHMgmE+8H5T3P3Xj7OlCzCgEeN+sEVDs8Rpu4Ol9ggd1ScuYWkAQIsDv1lrYqB+BZ/2FfsBqQAe3sbZG6Xwn2aGzr3Ja//cuJA8CnAXfr314SajgBkwBwAs6EAwmwWWFChThY0s8iI297B3DDPYRtCLi3Psb2AdRAHrKvqb9BCEyNtaKXS4OkoqAnomXjKUEo9e/GSjqAs0HvAS8C5WzfaNwKES1/95cZDmAlAbIacPudIRcgi4H0oqBuUirgU6WDSVtJsHnJw8gtZNyGWeJLEJNn61vZzYjzo/3dQ0Ea1DgmUXMWAqTAbil9UOaLynttQj+iAzibCCLQRfstUM+ShJiqqP/y937p7gDuex5gBz5bByD23woDMA9ACeCAG8jkCLTis+8ZUhjCAisZOKvwySw/OoWONFWMrmv4ZsWAqX+wrXMGbLkwnMvgIowEIWuHTsV1CTKz978WeViA88IKDzRnA/Ts8TyCcUng7/+SngC2twFZJLBPljIB4IQ1wgA9waPM+rCfJApN9Tae1beOGZ1LO06CEKj7UbF9A7CVB7AShIa9R3Uf1gOwhF9V6S1iEEQFDqFN3my14IJEYNYRTANNERd+PZMMIsXXp7H8g198v68VgHf2uP9dBX5xAtvbgaUUqEqCg/1HKweAlx9vsLeGIlqxchWojCyqY1RCgXK5jxGHofIsD9B+V92nSAgIxCEkgLEGBU8mAaO4PgoVmEJbOQQG1CzIs+08Msg6kAwRzJBOlgiWf/SLRgewksCq8l0YAKBveQAgBGb/t4vDhJQmAwf4a9dQeZPWnJbiHMfgOYeNlAKlx3BFOxs3L6B+LySS8EUg6rzwuEgQ3luBGugDqx/lCzyCGPbtCBBi05M9Io2OFB4hEXgmGLMgzZDEjIvYruUf/0I7BGgkAJWAbY46SUArGThMyAIZVADH2ppEkiCBir2n5xmpu5ME1I5pUH+LYEnFICKEDpiFEADPSSu0JhQX/MphTBFBIYnI3MRjgLviLs48H9OR/JNf4IcAK9bxPwoV9TerAXgj4T0BOJk9MhAQDZOfACUCNgIy0zbTJpPZpyGAQwTiKug7AYkr0L+N991Vf00gpGyHINbK3yZVMQQwVT2xEMh1BEZ/Nvk1EKsKmgXyGeOeTQQdEf/TL3wggNX2b/H//jqwLRGo1gC0HMCeD9AlQPw+WDqZJEZIoCdaNY6OgOmFAVq5u7ae3Y9AHam7sd8kApUsZHaekclAvrv86eoBcwkZkFvrA1hf1wU4Cu4Btu1T/c8G/hWgrxDEmSFDc0D//OdDCEAqADoPIMnA7a8wrv6LpSEFfJlkoQtAdfKShEmAWlUDN7xgOYYE6DPuBY+Lv0W0HRXdK/cN2X6l0jqcsICubbx2AVeFAK7Sy+zV1YDiasAjgH6MvqZth+vXH6sksfyLn/eKAFaw6yoA5gEE9FYScDsZZfsR8CwhSJNb2Tq5UVLsQO0lE5Pk4bqRiBDU/oEcHFVn9X1T4dFZ6TKhYfWZcltqbm6HsZm6D07QKuGRcqQGgEUKSF5N2QySYPutbZkw4SmJwCIIJIXIYSz/8uf2BEDXAWAosN/w7gUhAHwhge7GY2wGBKFtf5oMGKgcl1Cx/wKwKKQY2hWB3oHbqver7ab6J8t/2L9VbaR6sM8auk4gArlRNbBchQnSaBw5RyV7lRCAgSYCerS/otRZwqiMmSECc7x/9XNUDkCvAyB5AAwDtrlBQgG8KegCOsvolQgrgPKcQKTQSReBhOCquBP3a8LTToXF/vpY8ls2J6AdBFH/rNJfov4YDoL6UzVP5gDc8MBJBFbBnwHrWW08EEcqrvhw+5oNBZZ//bMLBCDqb7kAcAJtUQeyOuQDcGIPnzFeJQClSbJqngBULW3xIzKpkBYe3wGxkISn/u5zASwccLbh5NHhht43ELsFcGeFXwfmA1UAdBsZ9YxU/ej+zDkwJ+RtO5Mkmhh9yc+637cKwJ79lxyAlP/kKcC1IqBzAJgL0K4AQwC0m7hgyAsBrAVEaL0HJU6SQKeiyT6dWictOwsTsqW+9ttosAax/pA3AKJBEqEhQLX+T+J2PG9GEIxEPPC6ag/SNzhOtm/fZo3JABYpfLT/KBFU+leUvxHNR37mSAAC/lYBUDkA76EgIYWOAHASKnXHm4/hwaB8pIxIV8oFFpxlziNws/0diSgF91bwuQQmE7QQ+2fUvwO+pf7KkXRA9db6W6QB1+KCHu1qMgTQE70DoTOG24/Y5qMuIEMOFYBXQ4FM++WjP2MnAFUClGTg5gCEAMhy4M4F7JNou/eZ0qBWELD7qO6D0uNkZXmEwKqb4HXI4wzAa8ejLTYSjb5mfXz8jgCvlP86YrhC/ZH4lfpSFU4SgAfMo88TZFxAlRgyY1aI4Iy2zQF87KfbBLCVAAP199YCaBJAV9AlnAxX0NqwnIBSrHSSziAPa/VeJt/ACMp0AY6l1+CNvofqb6h6NikoJMMUHN2apayZNt3YxRwAPa6Tb2iTXj4cVP2MwkdkUQFz5njsGt1tX/rTHghArwHY7P++DBhdwDanYCWgzgPIfh2TtfUB+6QcJhcBedfGUXoGwAaOyXhdKy4rC1rxPAtlymqfjP0x5h6ArVSdARJdiQa6BWC8t3h8RhQ616AnY+cEigRQdREWUZ1NDBnFz4I5Y+OroMf2y5f9VE4ACH50AS4B7OD28gDtxyEVgW6yOIQwWGlg/Uz8bQLXcBoa/AM56Dq8FcMbCTyx/o3ISF3fsvaMWPRv7JLEPht08nC4TyTDb5UNI1VnwO3coaHQFPBKxa0QwAO/G1LAucwA+2oHkDkny2Vs27/8pygCANUXF9D+h2CdC1CA334rcQf7Z7yxsp8qiFpBOKhPQAiW6jIlN9UdzllAKQBjdtxT9eF8HJLQ5xNae6Lska1nSu+pfyMjb3GOlxwEYrHANwA6sO/abdBxyRiPAf4ZoGf6WOA9y0Es/+YnAwHs4JfsP4v/JSEoTgD/is1veYFZEsB+xAp7gDEX0yRU2asQaHX2wD8QjEEsCDKt0pZqM2LpSqaiiNpteCW7mQSgukc4UTWxsH0Z8EaKT/erRGIW/E/pAo6AOdt35+Pxvwf/t0gA8BKQFfzZMiDmAYakoJ4oUB2gE4UtHDLiYQSa9bnsDEhJj4HfdBYHF/V4Vn8gvh3sh9Rfk60ot7c9Uf+Xc80AkDnCNGng+RrnzCa/RS6Z8zXBJDv0ORnf9bHY96Pbov7LV/ykMQfQrQMgVQABvP67//60BKgXA7UTU9Z/mDgk+TeAndjrBtpCBcEF9Wz23on7j1p9TW74mzaH4jgC/Vtri20uDdakzvIDbTL0y1I9Gx+V8CJHgNeTBfIMEXhjz5LDU5HB8pU/ccwByBOAXQ6AxP9sQVBL5EJGF8uByPYDCehJE1UGAuB7JKD3MadA22iFx9DCiPPpeZAFOZWyH46Jk2cDPiZFRX1IvI7XrMdg2fsOvCRsYGMM25QadgC8KAeQIg5BblAajOL26v5Z4DPrb6m95wKWf/cTxhwAPgJskQAu/aUhAIB5+22J9aelQa0uOuFFQoRBCY2Soc4PNBDBMQVAGJ50amqVI8kYOH4F3FTZsyU9EvuLMs4q/NBP3SNT1Y2FPQyQcs0RYYT7JxYTZQgiAmoE/Ki/8E80DgO+RQYe8Nvx/v2P3wng9updALgAyEoEYrY/ejS4katyBegG2OfOEqpSX7s4K0QohgVUpSft+5VgR7BFsb/nEkxScByD/s31pB2IIOMSIETRE9YLF0wiOGMtwcUu4EoyyIAe79uyEsDwIhAsBSrrT6sAuyJ0i4KU6p9CAkpl9boBNuHT7iCw9vThJBJfe8erKrt2IZZjoWSIcTkLCTwVt6oC6nojwLKYvuoWIsUf1DsZRljn7m3PAPcMBY/GqIK8YU/IHTYs/+HHKQLYAd+tBCQkMIQA7L0AQAxo8bbjI1MXPiOIqMJNOgIEly4HmvsUIaUA7oQ0tD/LuBsAzTqC7XosUnAy/MwBZADtKTl1fjhB2aT19j9RCHAGOWTGyII/Gyos//HHAgEo5c8kAbv4X6m+lRDEmy73EtViSEA5pcFOIVTSMHIEAgTLVuvVceXVeFWwO3F+ByIW5zuxv1ZRRqL6d2TK64E1Y/9dIiDWfVB3veqPEcEThAARcDNgPKtNdC6Dw/lPP+Z+fxcWAOHbgM2FQKDsQ/wP+7TSo+qzsiAqk1apLmGoVUor4kTpcCCDALzZen1EQpbNp+QEjgNdiZWxN8t4pCKQUXeLOChZOFacEoFxTmzsYRIjEZwQAnjjRwCL7Hu0PxofLnVc1IM7gzxGE96vWgkAHwUWF8AWAuGDQOyhIAQ/KwPu+9t5KmVvJwXtMHSgE9BQfU0g7oMy2g4byb9ZMFtkwUCMhNDtJ2VDDVoNLBoSEBLpQBYB18kPpElkv9HM1XRzwFB85gzw2BaArX4uoRRAFYG7up+RQYYgKm5i+aof/RACiPK39wAAEbB3ArSq3v4Bl//qpcAa8Nt3QhAM7N0FE7DTSWc4goEUAAwm8Ky1CNYCG69syWr/BJBWLkArvWflL1H/iDwE2I6dH0hKJkeyYtCRFYCThSdZYLuEwo6hCGwGlE9FBsNx//OP2gkAwwBJBBoVgK4SsE8KyQWwuJ8RAoIdCQJvpMXqVnlQA3z4TpRdjsHA1IEo6hss7JFzQQDQYwaE0AHAUmMrSWgAmJKomuRH7D8DmOVWGMAjgHb7T8oBeORR2XcFOcyMyfps2776C/ocwPr7df8rkEMC23xS/0uQLgVm3IBOAHYni1ldneHVcSMJKdbJEYYOQU7BDR+M8VMZeQZUY1tHVNYxlQJnQgJNKNbk9tzGAFovx0CWDXurDkPF1+MVcgBZhzDbbgaoVWdQsftNaIHcNwLQIYCQgCh9SwaC2jfgQ/lPg92qAnQnokIB6gCUcrlVAqNsZqqco+xMtTM2/FTwVxyBofAsvGGgNe25UxqskgxV+ETIkCaCAgFEzkLmqdXuqZ1ARBam6gMAl6/5kSoEUPYfwa/fBNSeBQBi2MZW7wRox8skBgnYTUfgKLeA11O4KDk3gJ0pWzI00BOYxuhOeU9fhwXWqdg/Io7MfuJKKNhBfRrAJisAFJgH1wF4oPYAF4HxyP6oLwN6xhls/f7Lj7jf5dHf9hdeBNoRgJH5L4UB+2TSpBDmBADsCG5U9izYq+Sg25uKqqsJhnJ64JdrcC13Mfan14tAdDL76MhM0qmOFdh2fRxGJBZQoycKI7BkQZ5tFx0v2h+BPw30BrhXH7bweCOA/eWf+kUgFvjxKcChGqAAbuYADCLQ4N5O14j9I/DjftcGe1UDpn7Ogh2LhCrHfyzw098Hwews/aVkkMzkD8qd7JciggNJQItUjoC0CuAjxMLOMzz3r/3h4ADgLcDM+ktOwKwC4HJg9ZmV/RoXWaGBUv1TiYABO8ofWLHwRDLPBd8JCn8quLMWPeMkiPozK5/dNpBCkAPIgnwWiLP9QqAqBc8of6rN1/3wh4VA8gRg9AxARwI7iFgJUCcAKwlBFg50lQIdDoCbMC1rpYKQrBygW+kUMcjkR+CsxvHus/sReCPQRvsR0A74rPCBnXtK6ZVTsdzgYwK+ovaVthE5zCi/8MnydZ+vQgC1AIiFARveINHnJQMbNlHlAbDbiTj7NBmUiYCoNqsiDBNUT+YjoHaSh3Lz3BDBcivedkaSjvqa8X2ypBe+QEQBVl9vBHrmCCi4H7EKcJban00GFcJYvv6H9UlA+i4AXAuAZT/1WWf/LdXv8G6VAQkxlMHPMsJFJ3CJylugstTaU2FPdT3wZpQ9UZ4LiYvU/TswJ1xDRsWZ88v0a0oIFjtDNt7YEQCPEEc0dnX/AwGQ2P9oDkDCAvld9XdP9dEV4I3tbpaenMZ3V2lIn0yCSlv0wyTh1Nkz9p6ppxVGoFU2VV/UOqn+6NKiMbtzdQgmcgRv1P/hJlXdw/C7/dcfajsAifeFDESU27MB+wa5jzoUaOB3LD4SA4v9NVF4LgAnd3ehgeozAHugHianEx6wCR+FG2YeA294whVQYtjvWQRUMw9BlDIkG7b6j4VmVrusOp9s/y0ncJX6R+POAD4kiI0A4L8BQ+Uf3gfg2H/2MBBTfdP+C7vAzdaPAFfIwLSERHVoIoqUBjNKm3EDGVIwx8kAOFLuaL86hkkkxcU/jDgrSh8CUhG9B6iMzc+0iUB7xO6H4EWszLqBb/ghJARgTwKytwI7OYAhBHBcQDYckOtlTmFYABIA3XILbCEJ3QaE1ampsRItHTbsF+mqqpUryCzZzYA/QzJJN+ICPLFqLwPCI/F/aXy5N4YjiRT6akB7BGmd2/INP/ghBGjJPwL+1QnIfGf2X8CuQ4GGEZXoO9UFEOdwhAxYDiCtXE79ngKh2t7LFWTAHwAbSTEKEby2kaqznEHUJ6XmCUJJjaPUdFbFK4CvtI2IprJ/+caVAHQSkD0ObL0MxCgJbnNNqb7+XlX+KATYLlwdky4NZVaRxY/ZcMGLZwNHkCaXCPwZ1bbOBZXNyS0wkJruSKmll1w9CsrHdACzZOBdYwWwYj7CcAhcijf+8o0/KHYAkgzs/u4Trqm+/g7gKYUDRNG7F4jKhTlAbz+SbgNjdz+g0S5yA0wFO5AQAnHVzwOoZ/vPAn8yMeclKSMlPwOspm1nhO2oeRZEM+0qgH8q9d/O8ZtWAig4AMGQuRDIWQ48JAUBkO3eRcDWuQSi+pETQOBSdpxQ/kjJI7IYljkrVXaBlajpZxbqeGrOQEDzGqA8OoywfvdqHP5+IICznEKFSDJOYhjvm35g0QEkFwIh2Bm4w3AgcAJ6MrV5R+y9BpcmCFQl+oOz8MByE0qNu/EK4UDkJBihWHF7Bvz4m5jAJct+I8Wn+6+I1a8YE0k4+OwBtaLwlbYZwIfjrQQwrP4jK/82+6+2y8q/IQmolR2SiNvvqFUc3x/A9jOwESfAgB6BnxGJFR6E9tWbhJ499ey9FUbIhDT6ejadAjwKMbSVtkgxY7kvAOuZjwFn1fvq0CACeAhucGPycejzzT9gdABYERheCLqDUQhh+0qeC2iYNcBvWf4wMWgQhE7+CdHoC04TAlFy0zkY6+41udAJkyANar8JKVIHEBFEspYfOZLIxofkmSEOr82B+H9WvWcIoALaStuILNj+bdtKAF4JUKu+uQpQx/5AFKj6NBwQeiLOYCCxKEegCELb++GHcCoCA2taYHXU0IrtXTJhjsd5kKcDpziDBEEgQZkkg+MBWVigiYjA/T3gZofjGI4kC+azwTszXgTaqwlgHX/5ls97tRRYVL2tADRCgUH1yYKgDofE4nc4VqDG/EGbE0ZiziMIF/yGYlCHYJEKKzviJLaOEWTbQ5CQpN9AAhcoP5JWGaBA8lmyKYHZI+FgldwMeLNhgncNlX0RWczufyAAWQqcjP2tCgACV+Z+t0RYAUmIpAOxEdtHTmDbTybBsHaAnIMmiuHmatcBk9m8iexcEgrqVgP2c6cxvFL+LMii2HkYJ5Er8H6TaeL4ANj/CKSPofiIowcH8P23COBGnwHQhOBVALxHg1l4kCED0mbIEVjqTIhk+4GT26dJIXAF0yGBQR4U6MR5ZNsNTkIRS0mVsa8ir+o4LnF4ZKvPYXKV3xWK/1o4gG/9/ioJKC8E9dyAAXaM75sDANDp+N8LA7p3CyjF1Y5B3xxKEsZ6AVo5SIDYZHMvGRUlqqLseLCSbzunpBVGMsy6hTA0icAWXf9sIjC45irZyPzKuJUjIH4KxR8cwLd+v50A1PMAmOzTnwXTYvkld7Bth5uM+9uBo3yAodKR8uP4HUEQ5dFtGYEM25QCDwQQqVAEzAgcQdx/JvipC4jICX50Cpxk/wzoorCkAsrM8WbHM0WCEGXU9qr9y0oAWwiglH8LCYz1/w3wqvznqr5BDhqsUwuEqg5BkUwHdgOI2yGsx02tHIHcaGd/pMQIbArMRF7hCGAwFMqAxWwTEdys+sO9zJzfjBuoKPVVba8lgGISsFsApElivyE45wdXADdNhwUdlkm8nnYCCeWXY+l439tecgvG5OxuZqSMjnPoJnwWYJETYUoenWOkaBP9M2C2yDML8my72fg/Am2FLKKxZvZvfb7t+77KAWxOwEj8NXUHp7DNb3QBCvwSAnSCq0MAQhiitugOcCzcbsX71qrAri9OXEY21nMGHUu9GnG4oQVncMg2Z8FPSDEFNMcVHemf6ssIidw3a6wsyM9oVwXhUQLwznkQMVIKbQRAV/45RKDJoAHcIQMhiwjUQwjQscer3hYh0BWBxhhCNCzej/ZZx9FuIsolHLbMFUWfAXIUviAY2ecKOUVjMTIoXH8EmAwhRSA/Cuoj/c255pHot33uQw6A5QFku5cLQGAjMSDmLCcw4BImixUaCDCZkntuwGtPCcABCx6nHBJkVDg7qSuvwEoAcQDIBPi9MTIAKyt59rcKyGWWHCr9IvJ4kv2NAII8gIC1Wwqs1wUAoi0yEABrx82UP+sGziCFDsgkHLDyBN1N80gjqCLg+CkQJOPqdn4BUOhEniENVJtE/2x8TduRa/IAmT1WBMSzxomO8yj7P/65r1YCotIPn0m8j28BFpVvwGdkoCRf2/gOd1k3MNgImIEEyBZZYEKJugVrHYEoi3EsTSzu5HEIZCCFyuQPnMIl4If7kgVMtt0hUkOCMj5XgVex7VM2XU3IlEAQxyPDdP0//n3GlYAh+FWs370OXBbbqWSfblNxAlbbsuUPyMLLBeA9YLafTZruB8+AO2vps+32650Flqem4b4T1d881oyreWICqJLL1e2XjQDkjUDkmX+d5WffEVeWE0CBNJU/qfq6f0eQBdVv/Qw1tdyCBWzGsDJGqBIZgiCAzjqK0kQ6A1hnjOGBNUEwIUmd5AAqxyndB0PFw7nkOAY9R5ePf+9XSUBGBAJudAVt234Ttn37xi4ESGyTE0rnAIBtBqwfAD/+Zl68r8nGdA3RykEsy2TtfJYkKsfWk+wM4GavJwnA2fj/CDCPgqzSPwoLov1HSOUVAeBKwGgtgJH80+AfbL8OC9A66Od0gFy0UiuCa+Sjt0cKboYQRGmHsR0w4vmGE0GRltk+AapuIlTbG9dcDh8mxpkCauL6wt/eUcojfY8AUiv0Wd+tc3ogAA/8xsKfDuykTVP2/YO1GlCLNnUCiii0Cpu7LUfgjUf2WTG/JgXLORwFtbkE2VLQRNKPTgiHjNKASBw7PZZ2J0Vnc+Q4ugsk6gAAG0BJREFUVVKKQH/muZxKCp/4Xv3DQGLn0fI3sEerAPVTghAaaFyllgcDi1Asq43t6yzwI2IIKgHiOFKWjZyjZ3XZBMuAOJqYbTJVwwuDfIb/l8FR2cy5VX6Ts0HmZdunz90i7eClJZnjZdoMv1EjAMcFbLiYAT+x8TpX0DCeAHPXxAA5XTug7YiW7on9NPYPwgLtEEKiSNjcTg2y4YSehCeBv+xUZid98ne5khCmwHaQDGeOGfVZVgKwqgAiiBH4U2XAfTCco1qxNcAZxiOAm+J/kSvwEoYU4Anl325ath0hr5BYNPDYq9Sr4LzY+reJfBZZVa/vhPYRGGf2Z/p4bZZPfM++CmCFAF4YIETR/upnApw3AqUJAQ4ShQPD/ovA3wjdANDwwxvKZbVjN45uSwI427eqnIywpsbIKOT7iAAy4Ix+p5kxMn2kzSsCCKoA+AiwJoOOAJTtF8vPSAK3NSFLhAJdPwLuTKiwHc8jhsx+1YaGBSRxJdeadQgWETBVTJNG0mVEE3TbXww9yg6lmPzL/gapawNSitpXgIdcF40783tlzmUd94EAEiVAuc8m+HWOoCH61fxAy19R/mplAElHicqrryeD3wM1fVkpm1gBkOgxHEV0gZA4VnpiFlQ5MzHNNoXjpM+9APBozKuI59BvpgAwJgE/B0KA6CWgrP7vZP4bWcBJZJYEI1FYQuzlAtw8gTFg2jXs12I+diz7gQA9tu/2GaRkOQvrfYapiZgNR6znyMn1zQCkpG7GOZfG0PenQAAZIM6cS2bcq9osnxAC0C6AgH14+Ie9EIQQwoY5FRo0HAbbKY5In3Yf2QtHEGVWiGEAVhHow1cHPHgeJnAZqAIll3GrSUdKBkdyBmQF41WTsxv3LMK6mAAe5bdwSKt6/AcCMEIAmevrbz88A7Dv1CofVQQ66w9ftAJrMdSuAHD46ucIiEGDeRDcKCwgB43KgZYa47l4biIav0QyybjfOufhWGcRiQHK7nivKQFUATcQ+Ylgnhl7+cT3sEOARgDO038dATjZ/w74AKTM9q05AScjBY8YEHRVy4/Kr4mEKZXbRnaSa/IAvR3HISk3CZkkr3AMOPeM3c2SiTtWAfyzgDyz3+xYZ/6e6XPoCMBZ9tuAboB8cALKIbT5x54H2CeVBrkGOHUFHjFQNlBJ6wnVZ+AWgogA3Fg6cVymuJ1zME/kYQdT0CwgXTUpEFdmUodtCgQQjrVf2NXtMuNn2lTu18x4rxyACgO8sp+n+ts+A+Rs+a+0Z1jFfXS/ASLLGQxjJEAYlgpn1FwdN0UazloDD6wR4aQVH4GTPP+ZCUkn/MmhxtWgsu7H7O9x5fkun/hsFQKw5B+AGsGfjfc9UrDIYjukmmjatlv4taoAFduvyccFWYJIvOSdFvIo7s8Avps0ScBaE606VoVUdFvL9byO4Inc2PvhnEcC2CfL+mf7p+P//ar1dgTsEA7AmJ1gFrZ36k36tXEjV8CshFwT3tEsqBPt2rDQNqX68GNl2kfEUQGmpcQR+VSOkQJIQf2vUMorxkxdd1R+hbl6aLzmAMhCnuEZAKPmrxW+EYAFcGtpsLM9dATgUrSiMvLQbSruYArQCaKIAJxyCjgxnGN6hGLuyy55npicFuEcJZSjAD7aPwvOK46TGfPBAej4nz3959T8B8VXYMR5aK4HIACOLD8DLZvzlp2nZiAB1G1+J9pVbD8jrdR6Awts5PymQL+Pf6j6EBCCNVHN/7iV/lgq6XkWCcn1k2NmwX2UxLLHyQBeLkPGXD7x3cccQGbdP1P9UPmt5CAAqiMLOVvD8re2XkjggHXASALUWfAzl4BzKLT0wblk+kdt0vuNc6lMbBPkhtU9tMpRgfUogGaApfmi8lsdPd9S/44ASLyPQEelZwlATQqIPU/56ctB1MtEGI61slP1NybvU4LfELBXmxMZfzZGxnGkQY8HgB9rxkVM9XkK0imqfYUYqgRYAnHBEelxXzkAJwcg4EOFz9p+5hSasBPlZuGCMgIPIkwmiN50RjWg+22zDsFxHRnwR21cEKtzjADvTUx0OzMgjsY2VbEI/iq4ps+L3JiKslfPszJ2pS2exwMBZHMA+8Re709HAGxxELTtnACgWZNIa5ew/APY9c0xngno+qlBXHxfDP7tBlaOwSZjsn+GFLZJciAMOUQYRQI4dKxHBvWVJDAz9vKJz4rXAYjidiHA/sPRtQDWE4LGOwIt1e+2KxvgEsD7DPyotNPqXwQNO84ApIkxI3IJwXryMcPjnUAAVeCd1f6MaxsJgNX9WXjgKbzlCIwyX7vn3jJhpZCUAGBjRBCKTzjukoraOlfbp04iooTk04mFic4I6QiwvQkvp+XlL44cewYkZwF0uDZ1D2Ztu76VR8ZZPv5ZDxpOwwDr+X9P4ZV9b66B2HodRmgXnHEGrc8Tgz98B4GF4wJp0Bud7B+BqDu9fcxMn6hNaT+5llL/IsnNkMNMn9eZUDYC0M/5I2jXzxqowzaw9l1bZzsCl1p9I1zQJCHkhffeVH+HJBgA9HwysZYE4TA/Z/sZziECi+clPAXOKg62y5xLFHJMjZFU2ciVnA30GRJ4jD7Lxz/zVQ5AwFVa/rt3osAv5gIQ3A+25OFuenbefV6AlBLZeBb4U/hMNSLQC8gonPyzx7Xq7gapyObwfKJx4SfIOJmzjveYQM78VlW7PktU2eseCSCI9wegW5Y/SQwakDpksPYLM1juofVTQHFxE71NKGkJQmyGDTyt9qsFGeCYo8N5ZcfJtnMnsvo9smNm2mWBUHU50bFnjvvYY67H6wiAvvLLyQPgk3xWqKCFRZSdAbdti5KBilws8YrcAd70cgxfJYtAYQPI97uPEog62DbxCmNGE7UKJjx2duwz2kVjXLl/hiAihzEz5isCCFYByhzRCj0A37H92xjE1neuwtmP/V1nQBYKWfMbQ40MCKvtD5EMO6ErgBqMGQGBnWa6z37sdPujoUYUipy4f9a+R0A/c9zl277bXgXYRQABjsDUIK0Anym7DiW0m2CCaS0ZHsggafuzYO6GSwCQNkn0CwnojDESYUwFjDjcTL9osVHZTTwigCMgvu77txCAEkCy7s9IAcHI3IIGNoJwIAV0ppmwYD+4xgn9HoCpAuIQl0aDsF9nH0J6KDWo2v5DKk86zxy/QjCZtq9Tm+hcrtq/EUCn9M4LQIYwYL+x5mpABUgK8H0jgmH47IC/U38Sl1fBnwV+GryzuYILwd+GTl5ENPmyzNONkzx2xg7PklP2ujLtHqtNdJxov3YljQBEibW1t7Y34CVW/Wngt3vv9MXxB4sPd5w5CBY+6PESTvihCUzU7JzF68uCwzrnSnKudCx1MZmJUxo/itWTP+bMeWX7PEW7s46ZGSdq00IA+uYfou4DkEG9vX2W7Weqz8gBccjcAQNPRfnNuUjcCQPB6a7BZIMqBI32SfBVjhZNtm6sxPFL48HglX5XtM2OeWa7zFhWm+VbP6NPAgrYXOX3VH8fwFT9qEqg+rvq76izRxQZfEVlQXcOJ4nDBdgZY6TZKoZ6ZpLFo4iq8JZHj1Htf1X7K8bNjDnTZiCAyPLPxvs4LnUEiaW/HaifCPyReEXEkSGfM22/nO82OaKTTyP4QMOLQo/M5NdnfXWf6viZ9pk263Vm2m0hwOoAUK3NxUCBsrvEkFH9YI1AN3+zFYHki0M6UBog8bCDYcth0SUHOgW3pwxyAPiJ9wvMjp6Z7Gzsx+pXPU62/RntGgFYyt/IQVnS9au3DwHL6vc6RIjWASDIBntvOMvsSkAPwBZuuu0HQBuNUwUFPd+LwZ+diFc4kPSxyQ/52H2rx6u0z7bV7ZZvkRyAEddr694BP3IFmXyAE/NHlt8iAv2fjXju1wJ/Cvhq4AzOzDZO58y4mXxClUxObX/4IvqzyU547xqOjnGkf7VvpX2p7bd8eCIJKIpLXAFTfq322jl0feCOee00qC2HYIHfUt408GFgb26n5v0JawVmiOVUgHuDpX6E+GwqEzseLRcnXz3OzDVV+3jtl5UAEKAIOhO40WO+mZifOA5KBEG7DuCJhUADIcDkZPPUJIQDil21/dP4KXYsNs9g46HNgYGrkz1/UucRwHrMo+c527/abwwBdgLoSIAou1bjSNU98jD/81Ct/t7/IyAuRPocAH9F9be2pEM0x+l+tTEag03u11H55Zy2yTZzURUUH2xbBVDmcEfGfOy+yzfrEMBaCrzfTAbsiBwyYcGg/oSEAOu9sKi2oe2fUP3WJQnacN4XbH84lp6VB9xJZoKn25RPPD3yaQ2PAC5zEkfHP9I/03cjAAbgAegHFv9YBMEsPyqsPgcNbNaWgb+bh4QsNLHgjWV9Q4IxZoZFIubxghmWcRWZSVrgj/xwb8Df/VYZMEY/7hVjPBAAgIIqvKHGkfJ3Y0UEsl99+L4AaQcoxLmm593Z4Gfz2pvrw76kg5giBXIiV+EwHDdsEE336/efAaiZszzzuEfHWr7508k7ARXIEMjMGZhKnnkpKGnDxhu2ESWfAX8K0Jn/ZwBmgjn3E7Y/i5uIWDITM3uszFgdYV01cPVEgvZHwXP0dK46fmXc5Zs+nZcBN8BFqn10v7H8V5NMZ7kTVYHBoicBTMkgqaqhC3AaRHiJ9m8TccJZeBM4dUw2wIHrjABVmdjkJ2nDV8eJzuus/VeelzX2RgCDwnuLghxV74CbedQ3Uy5MvBQkUn53P7odreIJUFnzvdueGKdq+b3xLwF2NqE/zRxnweiDNc6VpLD+Uo0AGnjBWg92f6dVur2yNFhA59h4nEfb5+T6fw2MCPxU9ZV8mG3UXKNzn1yjnqIRZtz9RXIpinaIplkiCgd+08D9Bc4ihuUbMQRQkzXrDBAv4UNBcllR+IDK/Ejgb5MZZnVEIJ7V9J4M9EAdEUI7ZqZhVrkzZJawFslTegPvR/gFMiSxEYBW2PX7oPIROWTe+JsIHzoygS/6fDTwjiq/Bv8s8BmJAOfR2x6BxnMW1dDBIyxrTkbnt/VzGqX6PwIgjhxCX0MGXEeO9xh912t4IIAo5nfAj2o0kAaqeDLb341hHNcDf/QEoAvsI8lCA4nW5D/iAE5558ABxR/O/SDCD3a/DCuZ83q/E8HyDZ/mVAF2pCEoKcizdj5DJEIaVfAnlgJXwT/lApxS3wzoM2DLTNSK8mfHE+UvtS/A9apxM6fwlMeW81vJ5WrnsREAA/W2LQHsVMyfGKez/gr8Q1ignEXm8V8PzFXXYIHJUmY2mWbIwPq/EvWEzkzeTJuQNMgg2XEzIJwJb6rjHgp7zjrYI43D3MryX8EBWHZ+VvUtEmGAbseAGUSPWwT/2apvglntOAv0bRwDWRnAXdYmM/BkEvKpgZm8tEeC7nWH6QhgRvVdkColt9rKcT1ioC4gsP0V8LttjUnMwFkBvjXJhu2EFGcBEk3saL8cN5uHmD3PaMpnzzMax9v/GMc4cn5n9N0IANXXBWnmPQCi0Enwb8AO2mbAXwFw1fJXiKQBxLg7FYJAR8aGiyboZfvVwNFxMhN1ZoyZPplzie5hZYzXve3y9RICEBAOZJAEdQnQxpiuG3DWBWA//RnJhu5TdyskFTIDKwBPtU2qfwQGb3/Ut/utEo0TTUxczPSd6ZMF5pVjZ88hanfkHDcCiAC7HSAqFQJthi4icAlU8YMyImPtAcAOmLBtCHzCHikwR6GEvtMnVxQY6ZFD2vMt8TDTjFN5yj5Xgisa29t/BNSV4y5f/6nj04ADABNZfI8kqJor5XcVPwF+D7RybimSgF/PHDNQ5YhAPCC2vkl3EYF6VvlpP7VxZpJW+lTasntbAYLVduYcKse9evzoXJav+9RX6wBkMnUKfgH4U+VFDcTkcmANCAR/SBIF8M+CPOUUCDnijZwB9UyfDlSJmZpo0s3HTPtMm7McRMkNRcgK9s9e18HDDt03AugArx7qMfftQ0XKP+MmvD4U4HguhDi8PpV9mfUGTJFToJdrMGaGNWHO2u46iYCQjgAwC4RsuyxRZoA0c8xo3CvGjI7p3dvla4kD2Dqom06JIOsOEs8A4A9jOZCzwV9yBKpxBtSZNt01JY5h3cwzicA7p84VZGZech1AFhjZdjPneYTIop+iet7ReGed60YAFuBc9T8R/IPiF2N+Rh6RWtM+xEmIw/EmlEckacA6KnsGuL0JaO5LJv2ykztqF+2fBXV23LNApcc5cnyPCM4Yd/kv6ACyoM62q7wSTD+BaDiQlAuYLBNSIBeAGRGBSQbkTlZAf0bb4dySbqQ62TOTNtPGDVkIarJjnkkCR45Z/V1nHMPa5xUBwEQ/TfnhF3DHJC8TYa7gKPhLqg8Hi4Bd3W9ZbDZhzgB3ZYx2bs7szUzsqM3R/Y/pBqJzPZM0HgP4eD0bAaTi/WxeoBDvD6SQIAzG/K1bslJgEUF3o48+XUhi32EiFev8WYKYAjzOPBCDSFkicHj7o75Zlc+MQy4vurS2vzp+9ryvtveZ81i+5lPGMiBT3zRJ7J3Tig9UHvVxHYC6SxmQm22csVwC2q8lcgTbGGRWHQF4tq83KbYxjNkegWAW6NG4mUk84wYyx50Zt3K+FgFUzu2o+9gIIALeVeBHuxmdQxb8VeAP48IAEZCn9zvHsCZQFuDZdvQ4CeWPJudTE0F0fjNOoDLmEQKoHmfmWjRhLF8dOQA1KVygFpKDrwP4B7IwgDkNdOYIDJBlgXt2O7wPenJEE3IG7DN9qhM9Ou8rx5slgMo5zzoT5hY2AjBBfTL48cfZhs6+OhzOvANtArBpR5AA5mEiIHc5GjPrCLLEcIXyW5O3uj07sTNgybTJgjU7Vna8KtEebe/1X/6z5QAmwT+AnL1g9CD4hTzcsMAiDba9mPCLQEv3G2RlTfoMoDNtvEnZ+quBZlR6Buwzx7lCvTMAz7SZIYDsuFlyZCrvnddGAIMDCMDfgbxCFIkKgUcg2q6m1X3/VWj7yTUD7Ec1iSHhLrJEcAT0dLIVKxHRRKwSQQSAq/dH15PdX2030z76LRj4oz7LV2kHQJRqIAgB1GOD31DRChF0bR3lM8GcKO91fYvuwmJr73y8yeQSRlL5zwL1rOJHk/jo/oxyR8e4GtDZ41fPoyeAQhKvVBk4Q/kD8FdIYLvhCTLxQozIAWzDBwCLQB3tj87BnQwTyl8hgkrbzKSNAHD1/gxJZNtkrhfVPLo2rfyV9hsBlMH8RMpfBjn8MpbyZ8asEEEbT/1GFZWOgB/tD13EBcpfBfwVbiCa+FfvrwA7OpfKWLNksZ7D8p8+lFwI9AS2H1U0A1Rp47YlwLTaTwF/7xSB9Oj+I+pfeX15SCYGyWYm5etGAhlQPmabqxwFjrsRgAaO+f0k5ccTcI+dBGuaHJLjReByCSNQ16PAj/qHgIUBKqrN2h7tH6ncFQQRgSoCeLQ/Gj+65gxxasufPSZrt/zHrAN4jcCfBjyG4RPPCZQdgAOuCLgeqUSEFIIeZt0VQD46pjeBryCBCMRX788CNjqPCplYx9wIIHQAB8GfVvwT3gNAgTQBflflme0l7qJCIDMgzwCvtQmcSZpECi82rTiECBTVsWbHi/pl9kdtzgT20bGW/xA5gNcc/K4bOAh8D8DdD3/kPygplhVLoL9Q+TPnESlUFdTV9rPOIgLw0f1HQRv9rjpE8I63EYDpAF5D8LuAP2j5o7GpSkMn/UNXvlfaZtxCa3Oh8lcAWWk7C9yzjpEFmAes2X3ZY2dIKNNm+feWA3hC8FeASNuS9QxZNbeOTfur38i6edkxI2BnVFc7kyPWPnO8yvhntI0m9WOSwBGQRy7g6P4skWwEMDiASfDjzTFdxX5m3f4CYCNyyCzwicZIkQUBv6fiFYWvtDVB9cjKnyWLqrqfBehZsM4CcbZfFrjR+BFRynGWf6cdwCT4GahSJBCAPwJrtx++6GOnQK3icVO5T3p+oAL0qG13fYScvImVAW/p+CoIzYxfPb8qkUSAuIIgZseMzjWzP9NmPb+NABpYXgPwlwAPE02vZjwT8BHJsMn7ZG6AzLoMAM9qU7H5Z6j7GWNkVLd6nCwAFVe2r5HCn7V/+crVAVSeAUALbyjhrPJ7LsIC9NaHKN4lDsBQVtMpOI7CIyg2ebxjzKr/DOgzfSok8NhtI2CeCfQjID3SN7pG3L985cvEOgAE/ZFXfSceCio7AMO1uIShriflFhySqQL2DMKgx0yofwbAnnupALYCpsx5PUaY8H4ILSoAjxzG8hUvi88C7Ee3VB5PjrZJuA02BgVp4EBSwM7E/cn1BBVV90A2tQ86RQCOCCuz/ygRZAF/lETOBLSnypXz9Igssy8igIp7WP7tTgAhcCfVuyOBE8DfLq4A/shVuERhAGsKpBeFBNH/gmRNqogoov2PRQJHj/MYJDBDDkeAPHs8fcxGAJaiVwHMwLZtS4Df7Kst+8HKgQX44fj7hizYz24XKbH8rmjzItAe3R+dU9WmZ53AB5UEZoE8228ggH+TdQAFADMgpQhGAZ0SAlHkSOGj/VZ4MRNCZPvMtuv6JQgqA9gqKWTBmAV3tl32uGcpvgWy6vZZpT8L5CgQlAA85a2qtwZ6RflDB5AEfwT4aL+21Fb7LIhn+kfAzfzHIhVgR22j8zmq/BVQZc61SgKV41fH9n6bWXI4q9/y5SoJiAMfBb9Xm7ccwXB8cQVE7QayIW8groI0s5KwOmYEHm9Cm/suUP+MEp/V5oiaV8B6VdsZEphR9Jk+FXLYCMAE0oTtb2OpCZoBq+kAjLFMsgDP4x33TOsfugohMnJuEUEM56lmRaSIV+/PnP8RwGfHrxzjyrZnksPlBPBlRhlwxrpnwW8CnWXJC0RymBCS5b4zwV5Wf+hwBNhH+lqW9rHdwVF1P9r/dQZ6ljiWlQC0SjIbPLRRilYFv0cC7Yc9WOrLAFWf94y9n+ljnZurdie8YnzquMS9PAUJHAVshqCs63oMsFeuzzvPaB8eZ/lS7QCU4jJVNckgUGurH1XuiVJfilSYFTdUtUIgR0nA67/tU7OjouBll2GEKVnQZ4EWXUPFps8es3KM15EEskoPt3T7KP02AojUO0UCk+CnoCWAzII7Au2w3yG8o6COzoUBioKCnKPrFBjJqRlQcQLVY2WJIjNuBaCvIwlUVX0G0NVjdATwMXEAAYBdEnhC8Ecgc/efGPNH5xFNdhOQRdt/ptpHCh3tj675CFE8JTFUjv2UriFz7GUlgOp/DNKRwUHwdxPfUeMjDoCCq5BfOOoEZvpr2x+BLavolXEyAM6obnTMzHEqoMuc09HxKv2rbTPAVYZO/ydUbXfkKP4/BnecprBuissAAAAASUVORK5CYII=",e}(),Ko.TextureTools=Qo,Zo=us||(us={}),qo=function(){function e(){this._mode=e.FitFrustumSidesMode,this._radiusScale=1,this._positionScale=.5,this._defaultElevation=.3,this._elevationReturnTime=1500,this._elevationReturnWaitTime=1e3,this._zoomStopsAnimation=!1,this._framingTime=1500,this._isPointerDown=!1,this._lastInteractionTime=-1/0,this._animatables=new Array,this._betaIsAnimating=!1}return Object.defineProperty(e.prototype,"name",{get:function(){return"Framing"},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"mode",{get:function(){return this._mode},set:function(e){this._mode=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"radiusScale",{get:function(){return this._radiusScale},set:function(e){this._radiusScale=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"positionScale",{get:function(){return this._positionScale},set:function(e){this._positionScale=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"defaultElevation",{get:function(){return this._defaultElevation},set:function(e){this._defaultElevation=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"elevationReturnTime",{get:function(){return this._elevationReturnTime},set:function(e){this._elevationReturnTime=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"elevationReturnWaitTime",{get:function(){return this._elevationReturnWaitTime},set:function(e){this._elevationReturnWaitTime=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"zoomStopsAnimation",{get:function(){return this._zoomStopsAnimation},set:function(e){this._zoomStopsAnimation=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"framingTime",{get:function(){return this._framingTime},set:function(e){this._framingTime=e},enumerable:!0,configurable:!0}),e.prototype.init=function(){},e.prototype.attach=function(t){var i=this;this._attachedCamera=t;var r=this._attachedCamera.getScene();e.EasingFunction.setEasingMode(e.EasingMode),this._onPrePointerObservableObserver=r.onPrePointerObservable.add(function(e){e.type!==Zo.PointerEventTypes.POINTERDOWN?e.type===Zo.PointerEventTypes.POINTERUP&&(i._isPointerDown=!1):i._isPointerDown=!0}),this._onMeshTargetChangedObserver=t.onMeshTargetChangedObservable.add(function(e){e&&i.zoomOnMesh(e)}),this._onAfterCheckInputsObserver=t.onAfterCheckInputsObservable.add(function(){i._applyUserInteraction(),i._maintainCameraAboveGround()})},e.prototype.detach=function(){if(this._attachedCamera){var e=this._attachedCamera.getScene();this._onPrePointerObservableObserver&&e.onPrePointerObservable.remove(this._onPrePointerObservableObserver),this._onAfterCheckInputsObserver&&this._attachedCamera.onAfterCheckInputsObservable.remove(this._onAfterCheckInputsObserver),this._onMeshTargetChangedObserver&&this._attachedCamera.onMeshTargetChangedObservable.remove(this._onMeshTargetChangedObserver),this._attachedCamera=null}},e.prototype.zoomOnMesh=function(e,t,i){void 0===t&&(t=!1),void 0===i&&(i=null),e.computeWorldMatrix(!0);var r=e.getBoundingInfo().boundingBox;this.zoomOnBoundingInfo(r.minimumWorld,r.maximumWorld,t,i)},e.prototype.zoomOnMeshHierarchy=function(e,t,i){void 0===t&&(t=!1),void 0===i&&(i=null),e.computeWorldMatrix(!0);var r=e.getHierarchyBoundingVectors(!0);this.zoomOnBoundingInfo(r.min,r.max,t,i)},e.prototype.zoomOnMeshesHierarchy=function(e,t,i){void 0===t&&(t=!1),void 0===i&&(i=null);for(var r=new Zo.Vector3(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),n=new Zo.Vector3(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE),o=0;o<e.length;o++){var s=e[o].getHierarchyBoundingVectors(!0);Zo.Tools.CheckExtends(s.min,r,n),Zo.Tools.CheckExtends(s.max,r,n)}this.zoomOnBoundingInfo(r,n,t,i)},e.prototype.zoomOnBoundingInfo=function(t,i,r,n){var o,s=this;if(void 0===r&&(r=!1),void 0===n&&(n=null),this._attachedCamera){var a=t.y,h=a+(i.y-a)*this._positionScale,l=i.subtract(t).scale(.5);if(r)o=new Zo.Vector3(0,h,0);else{var c=t.add(l);o=new Zo.Vector3(c.x,h,c.z)}this._vectorTransition||(this._vectorTransition=Zo.Animation.CreateAnimation("target",Zo.Animation.ANIMATIONTYPE_VECTOR3,60,e.EasingFunction)),this._betaIsAnimating=!0;var u=Zo.Animation.TransitionTo("target",o,this._attachedCamera,this._attachedCamera.getScene(),60,this._vectorTransition,this._framingTime);u&&this._animatables.push(u);var p=0;if(this._mode===e.FitFrustumSidesMode){var f=this._calculateLowerRadiusFromModelBoundingSphere(t,i);this._attachedCamera.lowerRadiusLimit=l.length()+this._attachedCamera.minZ,p=f}else this._mode===e.IgnoreBoundsSizeMode&&(p=this._calculateLowerRadiusFromModelBoundingSphere(t,i),null===this._attachedCamera.lowerRadiusLimit&&(this._attachedCamera.lowerRadiusLimit=this._attachedCamera.minZ));var d=i.subtract(t).length();this._attachedCamera.panningSensibility=5e3/d,this._attachedCamera.wheelPrecision=100/p,this._radiusTransition||(this._radiusTransition=Zo.Animation.CreateAnimation("radius",Zo.Animation.ANIMATIONTYPE_FLOAT,60,e.EasingFunction)),(u=Zo.Animation.TransitionTo("radius",p,this._attachedCamera,this._attachedCamera.getScene(),60,this._radiusTransition,this._framingTime,function(){n&&n(),s._attachedCamera&&s._attachedCamera.storeState()}))&&this._animatables.push(u)}},e.prototype._calculateLowerRadiusFromModelBoundingSphere=function(t,i){var r=i.subtract(t).length(),n=this._getFrustumSlope(),o=.5*r*this._radiusScale,s=o*Math.sqrt(1+1/(n.x*n.x)),a=o*Math.sqrt(1+1/(n.y*n.y)),h=Math.max(s,a),l=this._attachedCamera;return l?(l.lowerRadiusLimit&&this._mode===e.IgnoreBoundsSizeMode&&(h=h<l.lowerRadiusLimit?l.lowerRadiusLimit:h),l.upperRadiusLimit&&(h=h>l.upperRadiusLimit?l.upperRadiusLimit:h),h):0},e.prototype._maintainCameraAboveGround=function(){var t=this;if(!(this._elevationReturnTime<0)){var i=Zo.Tools.Now-this._lastInteractionTime,r=.5*Math.PI-this._defaultElevation,n=.5*Math.PI;if(this._attachedCamera&&!this._betaIsAnimating&&this._attachedCamera.beta>n&&i>=this._elevationReturnWaitTime){this._betaIsAnimating=!0,this.stopAllAnimations(),this._betaTransition||(this._betaTransition=Zo.Animation.CreateAnimation("beta",Zo.Animation.ANIMATIONTYPE_FLOAT,60,e.EasingFunction));var o=Zo.Animation.TransitionTo("beta",r,this._attachedCamera,this._attachedCamera.getScene(),60,this._betaTransition,this._elevationReturnTime,function(){t._clearAnimationLocks(),t.stopAllAnimations()});o&&this._animatables.push(o)}}},e.prototype._getFrustumSlope=function(){var e=this._attachedCamera;if(!e)return Zo.Vector2.Zero();var t=e.getScene().getEngine().getAspectRatio(e),i=Math.tan(e.fov/2),r=i*t;return new Zo.Vector2(r,i)},e.prototype._clearAnimationLocks=function(){this._betaIsAnimating=!1},e.prototype._applyUserInteraction=function(){this.isUserIsMoving&&(this._lastInteractionTime=Zo.Tools.Now,this.stopAllAnimations(),this._clearAnimationLocks())},e.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(e.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}),e.EasingFunction=new Zo.ExponentialEase,e.EasingMode=Zo.EasingFunction.EASINGMODE_EASEINOUT,e.IgnoreBoundsSizeMode=0,e.FitFrustumSidesMode=1,e}(),Zo.FramingBehavior=qo,Jo=us||(us={}),$o=function(){function e(){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(e.prototype,"name",{get:function(){return"Bouncing"},enumerable:!0,configurable:!0}),Object.defineProperty(e.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}),e.prototype.init=function(){},e.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))})},e.prototype.detach=function(){this._attachedCamera&&(this._onAfterCheckInputsObserver&&this._attachedCamera.onAfterCheckInputsObservable.remove(this._onAfterCheckInputsObserver),this._onMeshTargetChangedObserver&&this._attachedCamera.onMeshTargetChangedObservable.remove(this._onMeshTargetChangedObserver),this._attachedCamera=null)},e.prototype._isRadiusAtLimit=function(e){return!!this._attachedCamera&&(this._attachedCamera.radius===e&&!this._radiusIsAnimating)},e.prototype._applyBoundRadiusAnimation=function(t){var i=this;if(this._attachedCamera){this._radiusBounceTransition||(e.EasingFunction.setEasingMode(e.EasingMode),this._radiusBounceTransition=Jo.Animation.CreateAnimation("radius",Jo.Animation.ANIMATIONTYPE_FLOAT,60,e.EasingFunction)),this._cachedWheelPrecision=this._attachedCamera.wheelPrecision,this._attachedCamera.wheelPrecision=1/0,this._attachedCamera.inertialRadiusOffset=0,this.stopAllAnimations(),this._radiusIsAnimating=!0;var r=Jo.Animation.TransitionTo("radius",this._attachedCamera.radius+t,this._attachedCamera,this._attachedCamera.getScene(),60,this._radiusBounceTransition,this.transitionDuration,function(){return i._clearAnimationLocks()});r&&this._animatables.push(r)}},e.prototype._clearAnimationLocks=function(){this._radiusIsAnimating=!1,this._attachedCamera&&(this._attachedCamera.wheelPrecision=this._cachedWheelPrecision)},e.prototype.stopAllAnimations=function(){for(this._attachedCamera&&(this._attachedCamera.animations=[]);this._animatables.length;)this._animatables[0].onAnimationEnd=null,this._animatables[0].stop(),this._animatables.shift()},e.EasingFunction=new Jo.BackEase(.3),e.EasingMode=Jo.EasingFunction.EASINGMODE_EASEOUT,e}(),Jo.BouncingBehavior=$o,es=us||(us={}),ts=function(){function e(){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(e.prototype,"name",{get:function(){return"AutoRotation"},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"zoomStopsAnimation",{get:function(){return this._zoomStopsAnimation},set:function(e){this._zoomStopsAnimation=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"idleRotationSpeed",{get:function(){return this._idleRotationSpeed},set:function(e){this._idleRotationSpeed=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"idleRotationWaitTime",{get:function(){return this._idleRotationWaitTime},set:function(e){this._idleRotationWaitTime=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"idleRotationSpinupTime",{get:function(){return this._idleRotationSpinupTime},set:function(e){this._idleRotationSpinupTime=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rotationInProgress",{get:function(){return Math.abs(this._cameraRotationSpeed)>0},enumerable:!0,configurable:!0}),e.prototype.init=function(){},e.prototype.attach=function(e){var t=this;this._attachedCamera=e;var i=this._attachedCamera.getScene();this._onPrePointerObservableObserver=i.onPrePointerObservable.add(function(e){e.type!==es.PointerEventTypes.POINTERDOWN?e.type===es.PointerEventTypes.POINTERUP&&(t._isPointerDown=!1):t._isPointerDown=!0}),this._onAfterCheckInputsObserver=e.onAfterCheckInputsObservable.add(function(){var e=es.Tools.Now,i=0;null!=t._lastFrameTime&&(i=e-t._lastFrameTime),t._lastFrameTime=e,t._applyUserInteraction();var r=e-t._lastInteractionTime-t._idleRotationWaitTime,n=Math.max(Math.min(r/t._idleRotationSpinupTime,1),0);t._cameraRotationSpeed=t._idleRotationSpeed*n,t._attachedCamera&&(t._attachedCamera.alpha-=t._cameraRotationSpeed*(i/1e3))})},e.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}},e.prototype._userIsZooming=function(){return!!this._attachedCamera&&0!==this._attachedCamera.inertialRadiusOffset},e.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()},e.prototype._applyUserInteraction=function(){this._userIsMoving()&&!this._shouldAnimationStopForInteraction()&&(this._lastInteractionTime=es.Tools.Now)},e.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)},e}(),es.AutoRotationBehavior=ts,function(e){var t=function(){return function(){this.renderWidth=512,this.renderHeight=256,this.textureSize=512,this.deterministicLockstep=!1,this.lockstepMaxSteps=4}}();e.NullEngineOptions=t;var i=function(i){function r(r){void 0===r&&(r=new t);var n=i.call(this,null)||this;return void 0===r.deterministicLockstep&&(r.deterministicLockstep=!1),void 0===r.lockstepMaxSteps&&(r.lockstepMaxSteps=4),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 Y(r,i),r.prototype.isDeterministicLockStep=function(){return this._options.deterministicLockstep},r.prototype.getLockstepMaxSteps=function(){return this._options.lockstepMaxSteps},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.drawElementsType=function(e,t,i,r){},r.prototype.drawArraysType=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._activeChannel]!==t&&(this._boundTexturesCache[this._activeChannel]=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}(us||(us={})),is=us||(us={}),rs=function(){function e(e){this.engine=e,this._captureGPUFrameTime=!1,this._gpuFrameTime=new is.PerfCounter,this._captureShaderCompilationTime=!1,this._shaderCompilationTime=new is.PerfCounter,this._onBeginFrameObserver=null,this._onEndFrameObserver=null,this._onBeforeShaderCompilationObserver=null,this._onAfterShaderCompilationObserver=null}return Object.defineProperty(e.prototype,"gpuFrameTimeCounter",{get:function(){return this._gpuFrameTime},enumerable:!0,configurable:!0}),Object.defineProperty(e.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(e.prototype,"shaderCompilationTimeCounter",{get:function(){return this._shaderCompilationTime},enumerable:!0,configurable:!0}),Object.defineProperty(e.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}),e.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},e}(),is.EngineInstrumentation=rs,ns=us||(us={}),os=function(){function e(e){var t=this;this.scene=e,this._captureActiveMeshesEvaluationTime=!1,this._activeMeshesEvaluationTime=new ns.PerfCounter,this._captureRenderTargetsRenderTime=!1,this._renderTargetsRenderTime=new ns.PerfCounter,this._captureFrameTime=!1,this._frameTime=new ns.PerfCounter,this._captureRenderTime=!1,this._renderTime=new ns.PerfCounter,this._captureInterFrameTime=!1,this._interFrameTime=new ns.PerfCounter,this._captureParticlesRenderTime=!1,this._particlesRenderTime=new ns.PerfCounter,this._captureSpritesRenderTime=!1,this._spritesRenderTime=new ns.PerfCounter,this._capturePhysicsTime=!1,this._physicsTime=new ns.PerfCounter,this._captureAnimationsTime=!1,this._animationsTime=new ns.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=e.onBeforeAnimationsObservable.add(function(){t._captureActiveMeshesEvaluationTime&&t._activeMeshesEvaluationTime.fetchNewFrame(),t._captureRenderTargetsRenderTime&&t._renderTargetsRenderTime.fetchNewFrame(),t._captureFrameTime&&(ns.Tools.StartPerformanceCounter("Scene rendering"),t._frameTime.beginMonitoring()),t._captureInterFrameTime&&t._interFrameTime.endMonitoring(),t._captureParticlesRenderTime&&t._particlesRenderTime.fetchNewFrame(),t._captureSpritesRenderTime&&t._spritesRenderTime.fetchNewFrame(),t._captureAnimationsTime&&t._animationsTime.beginMonitoring(),t.scene.getEngine()._drawCalls.fetchNewFrame(),t.scene.getEngine()._textureCollisions.fetchNewFrame()}),this._onAfterRenderObserver=e.onAfterRenderObservable.add(function(){t._captureFrameTime&&(ns.Tools.EndPerformanceCounter("Scene rendering"),t._frameTime.endMonitoring()),t._captureRenderTime&&t._renderTime.endMonitoring(!1),t._captureInterFrameTime&&t._interFrameTime.beginMonitoring()})}return Object.defineProperty(e.prototype,"activeMeshesEvaluationTimeCounter",{get:function(){return this._activeMeshesEvaluationTime},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"captureActiveMeshesEvaluationTime",{get:function(){return this._captureActiveMeshesEvaluationTime},set:function(e){var t=this;e!==this._captureActiveMeshesEvaluationTime&&(this._captureActiveMeshesEvaluationTime=e,e?(this._onBeforeActiveMeshesEvaluationObserver=this.scene.onBeforeActiveMeshesEvaluationObservable.add(function(){ns.Tools.StartPerformanceCounter("Active meshes evaluation"),t._activeMeshesEvaluationTime.beginMonitoring()}),this._onAfterActiveMeshesEvaluationObserver=this.scene.onAfterActiveMeshesEvaluationObservable.add(function(){ns.Tools.EndPerformanceCounter("Active meshes evaluation"),t._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(e.prototype,"renderTargetsRenderTimeCounter",{get:function(){return this._renderTargetsRenderTime},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"captureRenderTargetsRenderTime",{get:function(){return this._captureRenderTargetsRenderTime},set:function(e){var t=this;e!==this._captureRenderTargetsRenderTime&&(this._captureRenderTargetsRenderTime=e,e?(this._onBeforeRenderTargetsRenderObserver=this.scene.OnBeforeRenderTargetsRenderObservable.add(function(){ns.Tools.StartPerformanceCounter("Render targets rendering"),t._renderTargetsRenderTime.beginMonitoring()}),this._onAfterRenderTargetsRenderObserver=this.scene.OnAfterRenderTargetsRenderObservable.add(function(){ns.Tools.EndPerformanceCounter("Render targets rendering"),t._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(e.prototype,"particlesRenderTimeCounter",{get:function(){return this._particlesRenderTime},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"captureParticlesRenderTime",{get:function(){return this._captureParticlesRenderTime},set:function(e){var t=this;e!==this._captureParticlesRenderTime&&(this._captureParticlesRenderTime=e,e?(this._onBeforeParticlesRenderingObserver=this.scene.onBeforeParticlesRenderingObservable.add(function(){ns.Tools.StartPerformanceCounter("Particles"),t._particlesRenderTime.beginMonitoring()}),this._onAfterParticlesRenderingObserver=this.scene.onAfterParticlesRenderingObservable.add(function(){ns.Tools.EndPerformanceCounter("Particles"),t._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(e.prototype,"spritesRenderTimeCounter",{get:function(){return this._spritesRenderTime},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"captureSpritesRenderTime",{get:function(){return this._captureSpritesRenderTime},set:function(e){var t=this;e!==this._captureSpritesRenderTime&&(this._captureSpritesRenderTime=e,e?(this._onBeforeSpritesRenderingObserver=this.scene.onBeforeSpritesRenderingObservable.add(function(){ns.Tools.StartPerformanceCounter("Sprites"),t._spritesRenderTime.beginMonitoring()}),this._onAfterSpritesRenderingObserver=this.scene.onAfterSpritesRenderingObservable.add(function(){ns.Tools.EndPerformanceCounter("Sprites"),t._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(e.prototype,"physicsTimeCounter",{get:function(){return this._physicsTime},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"capturePhysicsTime",{get:function(){return this._capturePhysicsTime},set:function(e){var t=this;e!==this._capturePhysicsTime&&(this._capturePhysicsTime=e,e?(this._onBeforePhysicsObserver=this.scene.onBeforePhysicsObservable.add(function(){ns.Tools.StartPerformanceCounter("Physics"),t._physicsTime.beginMonitoring()}),this._onAfterPhysicsObserver=this.scene.onAfterPhysicsObservable.add(function(){ns.Tools.EndPerformanceCounter("Physics"),t._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(e.prototype,"animationsTimeCounter",{get:function(){return this._animationsTime},enumerable:!0,configurable:!0}),Object.defineProperty(e.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(e.prototype,"frameTimeCounter",{get:function(){return this._frameTime},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"captureFrameTime",{get:function(){return this._captureFrameTime},set:function(e){this._captureFrameTime=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"interFrameTimeCounter",{get:function(){return this._interFrameTime},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"captureInterFrameTime",{get:function(){return this._captureInterFrameTime},set:function(e){this._captureInterFrameTime=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"renderTimeCounter",{get:function(){return this._renderTime},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"captureRenderTime",{get:function(){return this._captureRenderTime},set:function(e){var t=this;e!==this._captureRenderTime&&(this._captureRenderTime=e,e?(this._onBeforeDrawPhaseObserver=this.scene.onBeforeDrawPhaseObservable.add(function(){t._renderTime.beginMonitoring(),ns.Tools.StartPerformanceCounter("Main render")}),this._onAfterDrawPhaseObserver=this.scene.onAfterDrawPhaseObservable.add(function(){t._renderTime.endMonitoring(!1),ns.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(e.prototype,"drawCallsCounter",{get:function(){return this.scene.getEngine()._drawCalls},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"textureCollisionsCounter",{get:function(){return this.scene.getEngine()._textureCollisions},enumerable:!0,configurable:!0}),e.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},e}(),ns.SceneInstrumentation=os,ss=us||(us={}),as=function(){return function(){this._timeElapsedQueryEnded=!1}}(),ss._TimeToken=as,hs=us||(us={}),ls=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 Y(t,e),t}(hs.MaterialDefines),cs=function(e){function t(t,i){var r=e.call(this,t,i)||this;return r.primaryColor=hs.Color3.White(),r.primaryLevel=1,r.secondaryColor=hs.Color3.Gray(),r.secondaryLevel=1,r.tertiaryColor=hs.Color3.Black(),r.tertiaryLevel=1,r.reflectionTexture=null,r.reflectionBlur=0,r.diffuseTexture=null,r._shadowLights=null,r.shadowLights=null,r.shadowBlurScale=1,r.shadowLevel=0,r.sceneCenter=hs.Vector3.Zero(),r.opacityFresnel=!0,r.reflectionFresnel=!1,r.reflectionFalloffDistance=0,r.reflectionAmount=1,r.reflectionReflectance0=.05,r.reflectionReflectance90=.5,r.useRGBColor=!0,r.enableNoise=!1,r._maxSimultaneousLights=4,r.maxSimultaneousLights=4,r._imageProcessingObserver=null,r._renderTargets=new hs.SmartArray(16),r._reflectionControls=hs.Vector4.Zero(),r._attachImageProcessingConfiguration(null),r.getRenderTargetTextures=function(){return r._renderTargets.reset(),r._diffuseTexture&&r._diffuseTexture.isRenderTarget&&r._renderTargets.push(r._diffuseTexture),r._reflectionTexture&&r._reflectionTexture.isRenderTarget&&r._renderTargets.push(r._reflectionTexture),r._renderTargets},r}return Y(t,e),Object.defineProperty(t.prototype,"reflectionStandardFresnelWeight",{set:function(e){var i=e;i<.5?(i*=2,this.reflectionReflectance0=t.standardReflectance0*i,this.reflectionReflectance90=t.standardReflectance90*i):(i=2*i-1,this.reflectionReflectance0=t.standardReflectance0+(1-t.standardReflectance0)*i,this.reflectionReflectance90=t.standardReflectance90+(1-t.standardReflectance90)*i)},enumerable:!0,configurable:!0}),t.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(t.prototype,"imageProcessingConfiguration",{get:function(){return this._imageProcessingConfiguration},set:function(e){this._attachImageProcessingConfiguration(e),this._markAllSubMeshesAsTexturesDirty()},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"cameraColorCurvesEnabled",{get:function(){return this.imageProcessingConfiguration.colorCurvesEnabled},set:function(e){this.imageProcessingConfiguration.colorCurvesEnabled=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"cameraColorGradingEnabled",{get:function(){return this.imageProcessingConfiguration.colorGradingEnabled},set:function(e){this.imageProcessingConfiguration.colorGradingEnabled=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"cameraToneMappingEnabled",{get:function(){return this._imageProcessingConfiguration.toneMappingEnabled},set:function(e){this._imageProcessingConfiguration.toneMappingEnabled=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"cameraExposure",{get:function(){return this._imageProcessingConfiguration.exposure},set:function(e){this._imageProcessingConfiguration.exposure=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"cameraContrast",{get:function(){return this._imageProcessingConfiguration.contrast},set:function(e){this._imageProcessingConfiguration.contrast=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"cameraColorGradingTexture",{get:function(){return this._imageProcessingConfiguration.colorGradingTexture},set:function(e){this.imageProcessingConfiguration.colorGradingTexture=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"cameraColorCurves",{get:function(){return this.imageProcessingConfiguration.colorCurves},set:function(e){this.imageProcessingConfiguration.colorCurves=e},enumerable:!0,configurable:!0}),t.prototype.needAlphaTesting=function(){return!0},t.prototype.needAlphaBlending=function(){return this.alpha<0||null!=this._diffuseTexture&&this._diffuseTexture.hasAlpha},t.prototype.isReadyForSubMesh=function(e,t,i){var r=this;if(void 0===i&&(i=!1),t.effect&&this.isFrozen&&this._wasPreviouslyReady)return!0;t._materialDefines||(t._materialDefines=new ls);var n=this.getScene(),o=t._materialDefines;if(!this.checkReadyOnEveryCall&&t.effect&&o._renderId===n.getRenderId())return!0;var s=n.getEngine();if(hs.MaterialHelper.PrepareDefinesForLights(n,e,o,!1,this._maxSimultaneousLights),o._needNormals=!0,o._areTexturesDirty){if(o._needUVs=!1,n.texturesEnabled){if(n.getEngine().getCaps().textureLOD&&(o.TEXTURELODSUPPORT=!0),this._diffuseTexture&&hs.StandardMaterial.DiffuseTextureEnabled){if(!this._diffuseTexture.isReadyOrNotBlocking())return!1;hs.MaterialHelper.PrepareDefinesForMergedUV(this._diffuseTexture,o,"DIFFUSE"),o.DIFFUSEHASALPHA=this._diffuseTexture.hasAlpha,o.GAMMADIFFUSE=this._diffuseTexture.gammaSpace,o.OPACITYFRESNEL=this._opacityFresnel}else o.DIFFUSE=!1,o.DIFFUSEHASALPHA=!1,o.GAMMADIFFUSE=!1,o.OPACITYFRESNEL=!1;var a=this._reflectionTexture;if(a&&hs.StandardMaterial.ReflectionTextureEnabled){if(!a.isReadyOrNotBlocking())return!1;switch(o.REFLECTION=!0,o.GAMMAREFLECTION=a.gammaSpace,o.REFLECTIONBLUR=this._reflectionBlur>0,o.REFLECTIONMAP_OPPOSITEZ=this.getScene().useRightHandedSystem?!a.invertZ:a.invertZ,o.LODINREFLECTIONALPHA=a.lodLevelInAlpha,a.coordinatesMode===hs.Texture.INVCUBIC_MODE&&(o.INVERTCUBICMAP=!0),o.REFLECTIONMAP_3D=a.isCube,a.coordinatesMode){case hs.Texture.CUBIC_MODE:case hs.Texture.INVCUBIC_MODE:o.REFLECTIONMAP_CUBIC=!0;break;case hs.Texture.EXPLICIT_MODE:o.REFLECTIONMAP_EXPLICIT=!0;break;case hs.Texture.PLANAR_MODE:o.REFLECTIONMAP_PLANAR=!0;break;case hs.Texture.PROJECTION_MODE:o.REFLECTIONMAP_PROJECTION=!0;break;case hs.Texture.SKYBOX_MODE:o.REFLECTIONMAP_SKYBOX=!0;break;case hs.Texture.SPHERICAL_MODE:o.REFLECTIONMAP_SPHERICAL=!0;break;case hs.Texture.EQUIRECTANGULAR_MODE:o.REFLECTIONMAP_EQUIRECTANGULAR=!0;break;case hs.Texture.FIXED_EQUIRECTANGULAR_MODE:o.REFLECTIONMAP_EQUIRECTANGULAR_FIXED=!0;break;case hs.Texture.FIXED_EQUIRECTANGULAR_MIRRORED_MODE:o.REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED=!0}this.reflectionFresnel?(o.REFLECTIONFRESNEL=!0,o.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):(o.REFLECTIONFRESNEL=!1,o.REFLECTIONFALLOFF=!1)}else o.REFLECTION=!1,o.REFLECTIONFALLOFF=!1,o.REFLECTIONBLUR=!1,o.REFLECTIONMAP_3D=!1,o.REFLECTIONMAP_SPHERICAL=!1,o.REFLECTIONMAP_PLANAR=!1,o.REFLECTIONMAP_CUBIC=!1,o.REFLECTIONMAP_PROJECTION=!1,o.REFLECTIONMAP_SKYBOX=!1,o.REFLECTIONMAP_EXPLICIT=!1,o.REFLECTIONMAP_EQUIRECTANGULAR=!1,o.REFLECTIONMAP_EQUIRECTANGULAR_FIXED=!1,o.REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED=!1,o.INVERTCUBICMAP=!1,o.REFLECTIONMAP_OPPOSITEZ=!1,o.LODINREFLECTIONALPHA=!1,o.GAMMAREFLECTION=!1}o.PREMULTIPLYALPHA=this.alphaMode===hs.Engine.ALPHA_PREMULTIPLIED||this.alphaMode===hs.Engine.ALPHA_PREMULTIPLIED_PORTERDUFF,o.USERGBCOLOR=this._useRGBColor,o.NOISE=this._enableNoise}if(o._areImageProcessingDirty){if(!this._imageProcessingConfiguration.isReady())return!1;this._imageProcessingConfiguration.prepareDefines(o)}if(hs.MaterialHelper.PrepareDefinesForMisc(e,n,!1,this.pointsCloud,this.fogEnabled,o),hs.MaterialHelper.PrepareDefinesForFrameBoundValues(n,s,o,i,!1),hs.MaterialHelper.PrepareDefinesForAttributes(e,o,!1,!0,!1)&&e&&(n.getEngine().getCaps().standardDerivatives||e.isVerticesDataPresent(hs.VertexBuffer.NormalKind)||(e.createNormals(!0),hs.Tools.Warn("BackgroundMaterial: Normals have been created for the mesh: "+e.name))),o.isDirty){o.markAsProcessed(),n.resetCachedMaterial();var h=new hs.EffectFallbacks;o.FOG&&h.addFallback(0,"FOG"),o.POINTSIZE&&h.addFallback(1,"POINTSIZE"),hs.MaterialHelper.HandleFallbacksForShadows(o,h,this._maxSimultaneousLights),o.NUM_BONE_INFLUENCERS>0&&h.addCPUSkinningFallback(0,e);var l=[hs.VertexBuffer.PositionKind];o.NORMAL&&l.push(hs.VertexBuffer.NormalKind),o.UV1&&l.push(hs.VertexBuffer.UVKind),o.UV2&&l.push(hs.VertexBuffer.UV2Kind),hs.MaterialHelper.PrepareAttributesForBones(l,e,o,h),hs.MaterialHelper.PrepareAttributesForInstances(l,o);var c=["world","view","viewProjection","vEyePosition","vLightsType","vFogInfos","vFogColor","pointSize","vClipPlane","mBones","vPrimaryColor","vSecondaryColor","vTertiaryColor","vReflectionInfos","reflectionMatrix","vReflectionMicrosurfaceInfos","shadowLevel","alpha","vBackgroundCenter","vReflectionControl","vDiffuseInfos","diffuseMatrix"],u=["diffuseSampler","reflectionSampler","reflectionSamplerLow","reflectionSamplerHigh"],p=["Material","Scene"];hs.ImageProcessingConfiguration.PrepareUniforms(c,o),hs.ImageProcessingConfiguration.PrepareSamplers(u,o),hs.MaterialHelper.PrepareUniformsAndSamplersList({uniformsNames:c,uniformBuffersNames:p,samplers:u,defines:o,maxSimultaneousLights:this._maxSimultaneousLights});var f=o.toString();t.setEffect(n.getEngine().createEffect("background",{attributes:l,uniformsNames:c,uniformBuffersNames:p,samplers:u,defines:f,fallbacks:h,onCompiled:function(e){r.onCompiled&&r.onCompiled(e),r.bindSceneUniformBuffer(e,n.getSceneUniformBuffer())},onError:this.onError,indexParameters:{maxSimultaneousLights:this._maxSimultaneousLights}},s),o),this.buildUniformLayout()}return!(!t.effect||!t.effect.isReady())&&(o._renderId=n.getRenderId(),this._wasPreviouslyReady=!0,!0)},t.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()},t.prototype.unbind=function(){this._diffuseTexture&&this._diffuseTexture.isRenderTarget&&this._uniformBuffer.setTexture("diffuseSampler",null),this._reflectionTexture&&this._reflectionTexture.isRenderTarget&&this._uniformBuffer.setTexture("reflectionSampler",null),e.prototype.unbind.call(this)},t.prototype.bindOnlyWorldMatrix=function(e){this._activeEffect.setMatrix("world",e)},t.prototype.bindForSubMesh=function(e,t,i){var r=this.getScene(),n=i._materialDefines;if(n){var o=i.effect;if(o){this._activeEffect=o,this.bindOnlyWorldMatrix(e),hs.MaterialHelper.BindBonesParameters(t,this._activeEffect);var s=this._mustRebind(r,o,t.visibility);if(s){this._uniformBuffer.bindToEffect(o,"Material"),this.bindViewProjection(o);var a=this._reflectionTexture;this._uniformBuffer.useUbo&&this.isFrozen&&this._uniformBuffer.isSync||(r.texturesEnabled&&(this._diffuseTexture&&hs.StandardMaterial.DiffuseTextureEnabled&&(this._uniformBuffer.updateFloat2("vDiffuseInfos",this._diffuseTexture.coordinatesIndex,this._diffuseTexture.level),hs.MaterialHelper.BindTextureMatrix(this._diffuseTexture,this._uniformBuffer,"diffuse")),a&&hs.StandardMaterial.ReflectionTextureEnabled&&(this._uniformBuffer.updateMatrix("reflectionMatrix",a.getReflectionTextureMatrix()),this._uniformBuffer.updateFloat2("vReflectionInfos",a.level,this._reflectionBlur),this._uniformBuffer.updateFloat3("vReflectionMicrosurfaceInfos",a.getSize().width,a.lodGenerationScale,a.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)),r.texturesEnabled&&(this._diffuseTexture&&hs.StandardMaterial.DiffuseTextureEnabled&&this._uniformBuffer.setTexture("diffuseSampler",this._diffuseTexture),a&&hs.StandardMaterial.ReflectionTextureEnabled&&(n.REFLECTIONBLUR&&n.TEXTURELODSUPPORT?this._uniformBuffer.setTexture("reflectionSampler",a):n.REFLECTIONBLUR?(this._uniformBuffer.setTexture("reflectionSampler",a._lodTextureMid||a),this._uniformBuffer.setTexture("reflectionSamplerLow",a._lodTextureLow||a),this._uniformBuffer.setTexture("reflectionSamplerHigh",a._lodTextureHigh||a)):this._uniformBuffer.setTexture("reflectionSampler",a),n.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)))),hs.MaterialHelper.BindClipPlane(this._activeEffect,r),hs.MaterialHelper.BindEyePosition(o,r)}!s&&this.isFrozen||(r.lightsEnabled&&hs.MaterialHelper.BindLights(r,t,this._activeEffect,n,this._maxSimultaneousLights,!1),this.bindView(o),hs.MaterialHelper.BindFogParameters(r,t,this._activeEffect),this._imageProcessingConfiguration.bind(this._activeEffect)),this._uniformBuffer.update(),this._afterBind(t)}}},t.prototype.dispose=function(t,i){void 0===t&&(t=!1),void 0===i&&(i=!1),i&&(this.diffuseTexture&&this.diffuseTexture.dispose(),this.reflectionTexture&&this.reflectionTexture.dispose()),this._renderTargets.dispose(),this._imageProcessingConfiguration&&this._imageProcessingObserver&&this._imageProcessingConfiguration.onUpdateParameters.remove(this._imageProcessingObserver),e.prototype.dispose.call(this,t)},t.prototype.clone=function(e){var i=this;return hs.SerializationHelper.Clone(function(){return new t(e,i.getScene())},this)},t.prototype.serialize=function(){var e=hs.SerializationHelper.Serialize(this);return e.customType="BABYLON.BackgroundMaterial",e},t.prototype.getClassName=function(){return"BackgroundMaterial"},t.Parse=function(e,i,r){return hs.SerializationHelper.Parse(function(){return new t(e.name,i)},e,i,r)},t.standardReflectance0=.05,t.standardReflectance90=.5,X([hs.serializeAsColor3()],t.prototype,"_primaryColor",void 0),X([hs.expandToProperty("_markAllSubMeshesAsLightsDirty")],t.prototype,"primaryColor",void 0),X([hs.serialize()],t.prototype,"_primaryLevel",void 0),X([hs.expandToProperty("_markAllSubMeshesAsLightsDirty")],t.prototype,"primaryLevel",void 0),X([hs.serializeAsColor3()],t.prototype,"_secondaryColor",void 0),X([hs.expandToProperty("_markAllSubMeshesAsLightsDirty")],t.prototype,"secondaryColor",void 0),X([hs.serialize()],t.prototype,"_secondaryLevel",void 0),X([hs.expandToProperty("_markAllSubMeshesAsLightsDirty")],t.prototype,"secondaryLevel",void 0),X([hs.serializeAsColor3()],t.prototype,"_tertiaryColor",void 0),X([hs.expandToProperty("_markAllSubMeshesAsLightsDirty")],t.prototype,"tertiaryColor",void 0),X([hs.serialize()],t.prototype,"_tertiaryLevel",void 0),X([hs.expandToProperty("_markAllSubMeshesAsLightsDirty")],t.prototype,"tertiaryLevel",void 0),X([hs.serializeAsTexture()],t.prototype,"_reflectionTexture",void 0),X([hs.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"reflectionTexture",void 0),X([hs.serialize()],t.prototype,"_reflectionBlur",void 0),X([hs.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"reflectionBlur",void 0),X([hs.serializeAsTexture()],t.prototype,"_diffuseTexture",void 0),X([hs.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"diffuseTexture",void 0),X([hs.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"shadowLights",void 0),X([hs.serialize()],t.prototype,"_shadowBlurScale",void 0),X([hs.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"shadowBlurScale",void 0),X([hs.serialize()],t.prototype,"_shadowLevel",void 0),X([hs.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"shadowLevel",void 0),X([hs.serializeAsVector3()],t.prototype,"_sceneCenter",void 0),X([hs.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"sceneCenter",void 0),X([hs.serialize()],t.prototype,"_opacityFresnel",void 0),X([hs.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"opacityFresnel",void 0),X([hs.serialize()],t.prototype,"_reflectionFresnel",void 0),X([hs.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"reflectionFresnel",void 0),X([hs.serialize()],t.prototype,"_reflectionFalloffDistance",void 0),X([hs.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"reflectionFalloffDistance",void 0),X([hs.serialize()],t.prototype,"_reflectionAmount",void 0),X([hs.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"reflectionAmount",void 0),X([hs.serialize()],t.prototype,"_reflectionReflectance0",void 0),X([hs.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"reflectionReflectance0",void 0),X([hs.serialize()],t.prototype,"_reflectionReflectance90",void 0),X([hs.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"reflectionReflectance90",void 0),X([hs.serialize()],t.prototype,"_useRGBColor",void 0),X([hs.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"useRGBColor",void 0),X([hs.serialize()],t.prototype,"_enableNoise",void 0),X([hs.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"enableNoise",void 0),X([hs.serialize()],t.prototype,"_maxSimultaneousLights",void 0),X([hs.expandToProperty("_markAllSubMeshesAsTexturesDirty")],t.prototype,"maxSimultaneousLights",void 0),X([hs.serializeAsImageProcessingConfiguration()],t.prototype,"_imageProcessingConfiguration",void 0),t}(hs.PushMaterial),hs.BackgroundMaterial=cs;var us,ps,fs;ui=this&&this.__assign||Object.assign||function(e){for(var t,i=1,r=arguments.length;i<r;i++){t=arguments[i];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e};ps=us||(us={}),fs=function(){function e(t,i){this._options=ui({},e._getDefaultOptions(),t),this._scene=i,this._setupBackground(),this._setupImageProcessing()}return e._getDefaultOptions=function(){return{createGround:!0,groundSize:15,groundTexture:this._groundTextureCDNUrl,groundColor:new ps.Color3(.2,.2,.3).toLinearSpace().scale(3),groundOpacity:.9,enableGroundShadow:!0,groundShadowLevel:.5,enableGroundMirror:!1,groundMirrorSizeRatio:.3,groundMirrorBlurKernel:64,groundMirrorAmount:1,groundMirrorFresnelWeight:1,groundMirrorFallOffDistance:0,groundMirrorTextureType:ps.Engine.TEXTURETYPE_UNSIGNED_INT,groundYBias:1e-5,createSkybox:!0,skyboxSize:20,skyboxTexture:this._skyboxTextureCDNUrl,skyboxColor:new ps.Color3(.2,.2,.3).toLinearSpace().scale(3),backgroundYRotation:0,sizeAuto:!0,rootPosition:ps.Vector3.Zero(),setupImageProcessing:!0,environmentTexture:this._environmentTextureCDNUrl,cameraExposure:.8,cameraContrast:1.2,toneMappingEnabled:!0}},Object.defineProperty(e.prototype,"rootMesh",{get:function(){return this._rootMesh},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"skybox",{get:function(){return this._skybox},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"skyboxTexture",{get:function(){return this._skyboxTexture},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"skyboxMaterial",{get:function(){return this._skyboxMaterial},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"ground",{get:function(){return this._ground},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"groundTexture",{get:function(){return this._groundTexture},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"groundMirror",{get:function(){return this._groundMirror},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"groundMirrorRenderList",{get:function(){return this._groundMirror?this._groundMirror.renderList:null},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"groundMaterial",{get:function(){return this._groundMaterial},enumerable:!0,configurable:!0}),e.prototype.updateOptions=function(e){var t=ui({},this._options,e);this._ground&&!t.createGround&&(this._ground.dispose(),this._ground=null),this._groundMaterial&&!t.createGround&&(this._groundMaterial.dispose(),this._groundMaterial=null),this._groundTexture&&this._options.groundTexture!=t.groundTexture&&(this._groundTexture.dispose(),this._groundTexture=null),this._skybox&&!t.createSkybox&&(this._skybox.dispose(),this._skybox=null),this._skyboxMaterial&&!t.createSkybox&&(this._skyboxMaterial.dispose(),this._skyboxMaterial=null),this._skyboxTexture&&this._options.skyboxTexture!=t.skyboxTexture&&(this._skyboxTexture.dispose(),this._skyboxTexture=null),this._groundMirror&&!t.enableGroundMirror&&(this._groundMirror.dispose(),this._groundMirror=null),this._scene.environmentTexture&&this._options.environmentTexture!=t.environmentTexture&&this._scene.environmentTexture.dispose(),this._options=t,this._setupBackground(),this._setupImageProcessing()},e.prototype.setMainColor=function(e){this.groundMaterial&&(this.groundMaterial.primaryColor=e),this.skyboxMaterial&&(this.skyboxMaterial.primaryColor=e),this.groundMirror&&(this.groundMirror.clearColor=new ps.Color4(e.r,e.g,e.b,1))},e.prototype._setupImageProcessing=function(){this._options.setupImageProcessing&&(this._scene.imageProcessingConfiguration.contrast=this._options.cameraContrast,this._scene.imageProcessingConfiguration.exposure=this._options.cameraExposure,this._scene.imageProcessingConfiguration.toneMappingEnabled=this._options.toneMappingEnabled,this._setupEnvironmentTexture())},e.prototype._setupEnvironmentTexture=function(){if(!this._scene.environmentTexture)if(this._options.environmentTexture instanceof ps.BaseTexture)this._scene.environmentTexture=this._options.environmentTexture;else{var e=ps.CubeTexture.CreateFromPrefilteredData(this._options.environmentTexture,this._scene);this._scene.environmentTexture=e}},e.prototype._setupBackground=function(){this._rootMesh||(this._rootMesh=new ps.Mesh("BackgroundHelper",this._scene)),this._rootMesh.rotation.y=this._options.backgroundYRotation;var e=this._getSceneSize();this._options.createGround&&(this._setupGround(e),this._setupGroundMaterial(),this._setupGroundDiffuseTexture(),this._options.enableGroundMirror&&this._setupGroundMirrorTexture(e),this._setupMirrorInGroundMaterial()),this._options.createSkybox&&(this._setupSkybox(e),this._setupSkyboxMaterial(),this._setupSkyboxReflectionTexture()),this._rootMesh.position.x=e.rootPosition.x,this._rootMesh.position.z=e.rootPosition.z,this._rootMesh.position.y=e.rootPosition.y},e.prototype._getSceneSize=function(){var e=this._options.groundSize,t=this._options.skyboxSize,i=this._options.rootPosition;if(!this._scene.meshes||1===this._scene.meshes.length)return{groundSize:e,skyboxSize:t,rootPosition:i};var r=this._scene.getWorldExtends(),n=r.max.subtract(r.min);if(this._options.sizeAuto){this._scene.activeCamera instanceof ps.ArcRotateCamera&&this._scene.activeCamera.upperRadiusLimit&&(t=e=2*this._scene.activeCamera.upperRadiusLimit);var o=n.length();o>e&&(t=e=2*o),e*=1.1,t*=1.5,(i=r.min.add(n.scale(.5))).y=r.min.y-this._options.groundYBias}return{groundSize:e,skyboxSize:t,rootPosition:i}},e.prototype._setupGround=function(e){var t=this;this._ground||(this._ground=ps.Mesh.CreatePlane("BackgroundPlane",e.groundSize,this._scene),this._ground.rotation.x=Math.PI/2,this._ground.parent=this._rootMesh,this._ground.onDisposeObservable.add(function(){t._ground=null})),this._ground.receiveShadows=this._options.enableGroundShadow},e.prototype._setupGroundMaterial=function(){this._groundMaterial||(this._groundMaterial=new ps.BackgroundMaterial("BackgroundPlaneMaterial",this._scene)),this._groundMaterial.alpha=this._options.groundOpacity,this._groundMaterial.alphaMode=ps.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)},e.prototype._setupGroundDiffuseTexture=function(){if(this._groundMaterial&&!this._groundTexture)if(this._options.groundTexture instanceof ps.BaseTexture)this._groundMaterial.diffuseTexture=this._options.groundTexture;else{var e=new ps.Texture(this._options.groundTexture,this._scene);e.gammaSpace=!1,e.hasAlpha=!0,this._groundMaterial.diffuseTexture=e}},e.prototype._setupGroundMirrorTexture=function(e){var t=ps.Texture.CLAMP_ADDRESSMODE;if(!this._groundMirror&&(this._groundMirror=new ps.MirrorTexture("BackgroundPlaneMirrorTexture",{ratio:this._options.groundMirrorSizeRatio},this._scene,!1,this._options.groundMirrorTextureType,ps.Texture.BILINEAR_SAMPLINGMODE,!0),this._groundMirror.mirrorPlane=new ps.Plane(0,-1,0,e.rootPosition.y),this._groundMirror.anisotropicFilteringLevel=1,this._groundMirror.wrapU=t,this._groundMirror.wrapV=t,this._groundMirror.gammaSpace=!1,this._groundMirror.renderList))for(var i=0;i<this._scene.meshes.length;i++){var r=this._scene.meshes[i];r!==this._ground&&r!==this._skybox&&r!==this._rootMesh&&this._groundMirror.renderList.push(r)}this._groundMirror.clearColor=new ps.Color4(this._options.groundColor.r,this._options.groundColor.g,this._options.groundColor.b,1),this._groundMirror.adaptiveBlurKernel=this._options.groundMirrorBlurKernel},e.prototype._setupMirrorInGroundMaterial=function(){this._groundMaterial&&(this._groundMaterial.reflectionTexture=this._groundMirror,this._groundMaterial.reflectionFresnel=!0,this._groundMaterial.reflectionAmount=this._options.groundMirrorAmount,this._groundMaterial.reflectionStandardFresnelWeight=this._options.groundMirrorFresnelWeight,this._groundMaterial.reflectionFalloffDistance=this._options.groundMirrorFallOffDistance)},e.prototype._setupSkybox=function(e){var t=this;this._skybox||(this._skybox=ps.Mesh.CreateBox("BackgroundSkybox",e.skyboxSize,this._scene,void 0,ps.Mesh.BACKSIDE),this._skybox.onDisposeObservable.add(function(){t._skybox=null})),this._skybox.parent=this._rootMesh},e.prototype._setupSkyboxMaterial=function(){this._skybox&&(this._skyboxMaterial||(this._skyboxMaterial=new ps.BackgroundMaterial("BackgroundSkyboxMaterial",this._scene)),this._skyboxMaterial.useRGBColor=!1,this._skyboxMaterial.primaryLevel=1,this._skyboxMaterial.primaryColor=this._options.skyboxColor,this._skyboxMaterial.secondaryLevel=0,this._skyboxMaterial.tertiaryLevel=0,this._skyboxMaterial.enableNoise=!0,this._skybox.material=this._skyboxMaterial)},e.prototype._setupSkyboxReflectionTexture=function(){this._skyboxMaterial&&(this._skyboxTexture||(this._options.skyboxTexture instanceof ps.BaseTexture?this._skyboxMaterial.reflectionTexture=this._skyboxTexture:(this._skyboxTexture=new ps.CubeTexture(this._options.skyboxTexture,this._scene),this._skyboxTexture.coordinatesMode=ps.Texture.SKYBOX_MODE,this._skyboxTexture.gammaSpace=!1,this._skyboxMaterial.reflectionTexture=this._skyboxTexture)))},e.prototype.dispose=function(){this._groundMaterial&&this._groundMaterial.dispose(!0,!0),this._skyboxMaterial&&this._skyboxMaterial.dispose(!0,!0),this._rootMesh.dispose(!1)},e._groundTextureCDNUrl="https://assets.babylonjs.com/environments/backgroundGround.png",e._skyboxTextureCDNUrl="https://assets.babylonjs.com/environments/backgroundSkybox.dds",e._environmentTextureCDNUrl="https://assets.babylonjs.com/environments/environmentSpecular.dds",e}(),ps.EnvironmentHelper=fs,us.Effect.ShadersStore={defaultVertexShader:"#include<__decl__defaultVertex>\n\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\n#endif\n#ifdef TANGENT\nattribute vec4 tangent;\n#endif\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#ifdef VERTEXCOLOR\nattribute vec4 color;\n#endif\n#include<helperFunctions>\n#include<bonesDeclaration>\n\n#include<instancesDeclaration>\n#ifdef MAINUV1\nvarying vec2 vMainUV1;\n#endif\n#ifdef MAINUV2\nvarying vec2 vMainUV2;\n#endif\n#if defined(DIFFUSE) && DIFFUSEDIRECTUV == 0\nvarying vec2 vDiffuseUV;\n#endif\n#if defined(AMBIENT) && AMBIENTDIRECTUV == 0\nvarying vec2 vAmbientUV;\n#endif\n#if defined(OPACITY) && OPACITYDIRECTUV == 0\nvarying vec2 vOpacityUV;\n#endif\n#if defined(EMISSIVE) && EMISSIVEDIRECTUV == 0\nvarying vec2 vEmissiveUV;\n#endif\n#if defined(LIGHTMAP) && LIGHTMAPDIRECTUV == 0\nvarying vec2 vLightmapUV;\n#endif\n#if defined(SPECULAR) && defined(SPECULARTERM) && SPECULARDIRECTUV == 0\nvarying vec2 vSpecularUV;\n#endif\n#if defined(BUMP) && BUMPDIRECTUV == 0\nvarying vec2 vBumpUV;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<bumpVertexDeclaration>\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include<morphTargetsVertexGlobalDeclaration>\n#include<morphTargetsVertexDeclaration>[0..maxSimultaneousMorphTargets]\n#ifdef REFLECTIONMAP_SKYBOX\nvarying vec3 vPositionUVW;\n#endif\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvarying vec3 vDirectionW;\n#endif\n#include<logDepthDeclaration>\nvoid main(void) {\nvec3 positionUpdated=position;\n#ifdef NORMAL \nvec3 normalUpdated=normal;\n#endif\n#ifdef TANGENT\nvec4 tangentUpdated=tangent;\n#endif\n#include<morphTargetsVertex>[0..maxSimultaneousMorphTargets]\n#ifdef REFLECTIONMAP_SKYBOX\nvPositionUVW=positionUpdated;\n#endif \n#include<instancesVertex>\n#include<bonesVertex>\ngl_Position=viewProjection*finalWorld*vec4(positionUpdated,1.0);\nvec4 worldPos=finalWorld*vec4(positionUpdated,1.0);\nvPositionW=vec3(worldPos);\n#ifdef NORMAL\nmat3 normalWorld=mat3(finalWorld);\n#ifdef NONUNIFORMSCALING\nnormalWorld=transposeMat3(inverseMat3(normalWorld));\n#endif\nvNormalW=normalize(normalWorld*normalUpdated);\n#endif\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvDirectionW=normalize(vec3(finalWorld*vec4(positionUpdated,0.0)));\n#endif\n\n#ifndef UV1\nvec2 uv=vec2(0.,0.);\n#endif\n#ifndef UV2\nvec2 uv2=vec2(0.,0.);\n#endif\n#ifdef MAINUV1\nvMainUV1=uv;\n#endif\n#ifdef MAINUV2\nvMainUV2=uv2;\n#endif\n#if defined(DIFFUSE) && DIFFUSEDIRECTUV == 0\nif (vDiffuseInfos.x == 0.)\n{\nvDiffuseUV=vec2(diffuseMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvDiffuseUV=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(AMBIENT) && AMBIENTDIRECTUV == 0\nif (vAmbientInfos.x == 0.)\n{\nvAmbientUV=vec2(ambientMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvAmbientUV=vec2(ambientMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(OPACITY) && OPACITYDIRECTUV == 0\nif (vOpacityInfos.x == 0.)\n{\nvOpacityUV=vec2(opacityMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvOpacityUV=vec2(opacityMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(EMISSIVE) && EMISSIVEDIRECTUV == 0\nif (vEmissiveInfos.x == 0.)\n{\nvEmissiveUV=vec2(emissiveMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvEmissiveUV=vec2(emissiveMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(LIGHTMAP) && LIGHTMAPDIRECTUV == 0\nif (vLightmapInfos.x == 0.)\n{\nvLightmapUV=vec2(lightmapMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvLightmapUV=vec2(lightmapMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(SPECULAR) && defined(SPECULARTERM) && SPECULARDIRECTUV == 0\nif (vSpecularInfos.x == 0.)\n{\nvSpecularUV=vec2(specularMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvSpecularUV=vec2(specularMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(BUMP) && BUMPDIRECTUV == 0\nif (vBumpInfos.x == 0.)\n{\nvBumpUV=vec2(bumpMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvBumpUV=vec2(bumpMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#include<bumpVertex>\n#include<clipPlaneVertex>\n#include<fogVertex>\n#include<shadowsVertex>[0..maxSimultaneousLights]\n#ifdef VERTEXCOLOR\n\nvColor=color;\n#endif\n#include<pointCloudVertex>\n#include<logDepthVertex>\n}",defaultPixelShader:"#include<__decl__defaultFragment>\n#if defined(BUMP) || !defined(NORMAL)\n#extension GL_OES_standard_derivatives : enable\n#endif\n#ifdef LOGARITHMICDEPTH\n#extension GL_EXT_frag_depth : enable\n#endif\n\n#define RECIPROCAL_PI2 0.15915494\nuniform vec3 vEyePosition;\nuniform vec3 vAmbientColor;\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#ifdef MAINUV1\nvarying vec2 vMainUV1;\n#endif\n#ifdef MAINUV2\nvarying vec2 vMainUV2;\n#endif\n\n#include<helperFunctions>\n\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n\n#ifdef DIFFUSE\n#if DIFFUSEDIRECTUV == 1\n#define vDiffuseUV vMainUV1\n#elif DIFFUSEDIRECTUV == 2\n#define vDiffuseUV vMainUV2\n#else\nvarying vec2 vDiffuseUV;\n#endif\nuniform sampler2D diffuseSampler;\n#endif\n#ifdef AMBIENT\n#if AMBIENTDIRECTUV == 1\n#define vAmbientUV vMainUV1\n#elif AMBIENTDIRECTUV == 2\n#define vAmbientUV vMainUV2\n#else\nvarying vec2 vAmbientUV;\n#endif\nuniform sampler2D ambientSampler;\n#endif\n#ifdef OPACITY \n#if OPACITYDIRECTUV == 1\n#define vOpacityUV vMainUV1\n#elif OPACITYDIRECTUV == 2\n#define vOpacityUV vMainUV2\n#else\nvarying vec2 vOpacityUV;\n#endif\nuniform sampler2D opacitySampler;\n#endif\n#ifdef EMISSIVE\n#if EMISSIVEDIRECTUV == 1\n#define vEmissiveUV vMainUV1\n#elif EMISSIVEDIRECTUV == 2\n#define vEmissiveUV vMainUV2\n#else\nvarying vec2 vEmissiveUV;\n#endif\nuniform sampler2D emissiveSampler;\n#endif\n#ifdef LIGHTMAP\n#if LIGHTMAPDIRECTUV == 1\n#define vLightmapUV vMainUV1\n#elif LIGHTMAPDIRECTUV == 2\n#define vLightmapUV vMainUV2\n#else\nvarying vec2 vLightmapUV;\n#endif\nuniform sampler2D lightmapSampler;\n#endif\n#ifdef REFRACTION\n#ifdef REFRACTIONMAP_3D\nuniform samplerCube refractionCubeSampler;\n#else\nuniform sampler2D refraction2DSampler;\n#endif\n#endif\n#if defined(SPECULAR) && defined(SPECULARTERM)\n#if SPECULARDIRECTUV == 1\n#define vSpecularUV vMainUV1\n#elif SPECULARDIRECTUV == 2\n#define vSpecularUV vMainUV2\n#else\nvarying vec2 vSpecularUV;\n#endif\nuniform sampler2D specularSampler;\n#endif\n\n#include<fresnelFunction>\n\n#ifdef REFLECTION\n#ifdef REFLECTIONMAP_3D\nuniform samplerCube reflectionCubeSampler;\n#else\nuniform sampler2D reflection2DSampler;\n#endif\n#ifdef REFLECTIONMAP_SKYBOX\nvarying vec3 vPositionUVW;\n#else\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvarying vec3 vDirectionW;\n#endif\n#endif\n#include<reflectionFunction>\n#endif\n#include<imageProcessingDeclaration>\n#include<imageProcessingFunctions>\n#include<bumpFragmentFunctions>\n#include<clipPlaneFragmentDeclaration>\n#include<logDepthDeclaration>\n#include<fogFragmentDeclaration>\nvoid main(void) {\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\nvec4 baseColor=vec4(1.,1.,1.,1.);\nvec3 diffuseColor=vDiffuseColor.rgb;\n\nfloat alpha=vDiffuseColor.a;\n\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=normalize(-cross(dFdx(vPositionW),dFdy(vPositionW)));\n#endif\n#include<bumpFragment>\n#ifdef TWOSIDEDLIGHTING\nnormalW=gl_FrontFacing ? normalW : -normalW;\n#endif\n#ifdef DIFFUSE\nbaseColor=texture2D(diffuseSampler,vDiffuseUV+uvOffset);\n#ifdef ALPHATEST\nif (baseColor.a<0.4)\ndiscard;\n#endif\n#ifdef ALPHAFROMDIFFUSE\nalpha*=baseColor.a;\n#endif\nbaseColor.rgb*=vDiffuseInfos.y;\n#endif\n#include<depthPrePass>\n#ifdef VERTEXCOLOR\nbaseColor.rgb*=vColor.rgb;\n#endif\n\nvec3 baseAmbientColor=vec3(1.,1.,1.);\n#ifdef AMBIENT\nbaseAmbientColor=texture2D(ambientSampler,vAmbientUV+uvOffset).rgb*vAmbientInfos.y;\n#endif\n\n#ifdef SPECULARTERM\nfloat glossiness=vSpecularColor.a;\nvec3 specularColor=vSpecularColor.rgb;\n#ifdef SPECULAR\nvec4 specularMapColor=texture2D(specularSampler,vSpecularUV+uvOffset);\nspecularColor=specularMapColor.rgb;\n#ifdef GLOSSINESS\nglossiness=glossiness*specularMapColor.a;\n#endif\n#endif\n#else\nfloat glossiness=0.;\n#endif\n\nvec3 diffuseBase=vec3(0.,0.,0.);\nlightingInfo info;\n#ifdef SPECULARTERM\nvec3 specularBase=vec3(0.,0.,0.);\n#endif\nfloat shadow=1.;\n#ifdef LIGHTMAP\nvec3 lightmapColor=texture2D(lightmapSampler,vLightmapUV+uvOffset).rgb*vLightmapInfos.y;\n#endif\n#include<lightFragment>[0..maxSimultaneousLights]\n\nvec3 refractionColor=vec3(0.,0.,0.);\n#ifdef REFRACTION\nvec3 refractionVector=normalize(refract(-viewDirectionW,normalW,vRefractionInfos.y));\n#ifdef REFRACTIONMAP_3D\nrefractionVector.y=refractionVector.y*vRefractionInfos.w;\nif (dot(refractionVector,viewDirectionW)<1.0)\n{\nrefractionColor=textureCube(refractionCubeSampler,refractionVector).rgb*vRefractionInfos.x;\n}\n#else\nvec3 vRefractionUVW=vec3(refractionMatrix*(view*vec4(vPositionW+refractionVector*vRefractionInfos.z,1.0)));\nvec2 refractionCoords=vRefractionUVW.xy/vRefractionUVW.z;\nrefractionCoords.y=1.0-refractionCoords.y;\nrefractionColor=texture2D(refraction2DSampler,refractionCoords).rgb*vRefractionInfos.x;\n#endif\n#endif\n\nvec3 reflectionColor=vec3(0.,0.,0.);\n#ifdef REFLECTION\nvec3 vReflectionUVW=computeReflectionCoords(vec4(vPositionW,1.0),normalW);\n#ifdef REFLECTIONMAP_3D\n#ifdef ROUGHNESS\nfloat bias=vReflectionInfos.y;\n#ifdef SPECULARTERM\n#ifdef SPECULAR\n#ifdef GLOSSINESS\nbias*=(1.0-specularMapColor.a);\n#endif\n#endif\n#endif\nreflectionColor=textureCube(reflectionCubeSampler,vReflectionUVW,bias).rgb*vReflectionInfos.x;\n#else\nreflectionColor=textureCube(reflectionCubeSampler,vReflectionUVW).rgb*vReflectionInfos.x;\n#endif\n#else\nvec2 coords=vReflectionUVW.xy;\n#ifdef REFLECTIONMAP_PROJECTION\ncoords/=vReflectionUVW.z;\n#endif\ncoords.y=1.0-coords.y;\nreflectionColor=texture2D(reflection2DSampler,coords).rgb*vReflectionInfos.x;\n#endif\n#ifdef REFLECTIONFRESNEL\nfloat reflectionFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,reflectionRightColor.a,reflectionLeftColor.a);\n#ifdef REFLECTIONFRESNELFROMSPECULAR\n#ifdef SPECULARTERM\nreflectionColor*=specularColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*reflectionRightColor.rgb;\n#else\nreflectionColor*=reflectionLeftColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*reflectionRightColor.rgb;\n#endif\n#else\nreflectionColor*=reflectionLeftColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*reflectionRightColor.rgb;\n#endif\n#endif\n#endif\n#ifdef REFRACTIONFRESNEL\nfloat refractionFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,refractionRightColor.a,refractionLeftColor.a);\nrefractionColor*=refractionLeftColor.rgb*(1.0-refractionFresnelTerm)+refractionFresnelTerm*refractionRightColor.rgb;\n#endif\n#ifdef OPACITY\nvec4 opacityMap=texture2D(opacitySampler,vOpacityUV+uvOffset);\n#ifdef OPACITYRGB\nopacityMap.rgb=opacityMap.rgb*vec3(0.3,0.59,0.11);\nalpha*=(opacityMap.x+opacityMap.y+opacityMap.z)* vOpacityInfos.y;\n#else\nalpha*=opacityMap.a*vOpacityInfos.y;\n#endif\n#endif\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\n#ifdef OPACITYFRESNEL\nfloat opacityFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,opacityParts.z,opacityParts.w);\nalpha+=opacityParts.x*(1.0-opacityFresnelTerm)+opacityFresnelTerm*opacityParts.y;\n#endif\n\nvec3 emissiveColor=vEmissiveColor;\n#ifdef EMISSIVE\nemissiveColor+=texture2D(emissiveSampler,vEmissiveUV+uvOffset).rgb*vEmissiveInfos.y;\n#endif\n#ifdef EMISSIVEFRESNEL\nfloat emissiveFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,emissiveRightColor.a,emissiveLeftColor.a);\nemissiveColor*=emissiveLeftColor.rgb*(1.0-emissiveFresnelTerm)+emissiveFresnelTerm*emissiveRightColor.rgb;\n#endif\n\n#ifdef DIFFUSEFRESNEL\nfloat diffuseFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,diffuseRightColor.a,diffuseLeftColor.a);\ndiffuseBase*=diffuseLeftColor.rgb*(1.0-diffuseFresnelTerm)+diffuseFresnelTerm*diffuseRightColor.rgb;\n#endif\n\n#ifdef EMISSIVEASILLUMINATION\nvec3 finalDiffuse=clamp(diffuseBase*diffuseColor+vAmbientColor,0.0,1.0)*baseColor.rgb;\n#else\n#ifdef LINKEMISSIVEWITHDIFFUSE\nvec3 finalDiffuse=clamp((diffuseBase+emissiveColor)*diffuseColor+vAmbientColor,0.0,1.0)*baseColor.rgb;\n#else\nvec3 finalDiffuse=clamp(diffuseBase*diffuseColor+emissiveColor+vAmbientColor,0.0,1.0)*baseColor.rgb;\n#endif\n#endif\n#ifdef SPECULARTERM\nvec3 finalSpecular=specularBase*specularColor;\n#ifdef SPECULAROVERALPHA\nalpha=clamp(alpha+dot(finalSpecular,vec3(0.3,0.59,0.11)),0.,1.);\n#endif\n#else\nvec3 finalSpecular=vec3(0.0);\n#endif\n#ifdef REFLECTIONOVERALPHA\nalpha=clamp(alpha+dot(reflectionColor,vec3(0.3,0.59,0.11)),0.,1.);\n#endif\n\n#ifdef EMISSIVEASILLUMINATION\nvec4 color=vec4(clamp(finalDiffuse*baseAmbientColor+finalSpecular+reflectionColor+emissiveColor+refractionColor,0.0,1.0),alpha);\n#else\nvec4 color=vec4(finalDiffuse*baseAmbientColor+finalSpecular+reflectionColor+refractionColor,alpha);\n#endif\n\n#ifdef LIGHTMAP\n#ifndef LIGHTMAPEXCLUDED\n#ifdef USELIGHTMAPASSHADOWMAP\ncolor.rgb*=lightmapColor;\n#else\ncolor.rgb+=lightmapColor;\n#endif\n#endif\n#endif\n#include<logDepthFragment>\n#include<fogFragment>\n\n\n#ifdef IMAGEPROCESSINGPOSTPROCESS\ncolor.rgb=toLinearSpace(color.rgb);\n#else\n#ifdef IMAGEPROCESSING\ncolor.rgb=toLinearSpace(color.rgb);\ncolor=applyImageProcessing(color);\n#endif\n#endif\n#ifdef PREMULTIPLYALPHA\n\ncolor.rgb*=color.a;\n#endif\ngl_FragColor=color;\n}",pbrVertexShader:"precision highp float;\n#include<__decl__pbrVertex>\n\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\n#endif\n#ifdef TANGENT\nattribute vec4 tangent;\n#endif\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#ifdef MAINUV1\nvarying vec2 vMainUV1;\n#endif\n#ifdef MAINUV2\nvarying vec2 vMainUV2; \n#endif \n#ifdef VERTEXCOLOR\nattribute vec4 color;\n#endif\n#include<helperFunctions>\n#include<bonesDeclaration>\n\n#include<instancesDeclaration>\n#if defined(ALBEDO) && ALBEDODIRECTUV == 0\nvarying vec2 vAlbedoUV;\n#endif\n#if defined(AMBIENT) && AMBIENTDIRECTUV == 0\nvarying vec2 vAmbientUV;\n#endif\n#if defined(OPACITY) && OPACITYDIRECTUV == 0\nvarying vec2 vOpacityUV;\n#endif\n#if defined(EMISSIVE) && EMISSIVEDIRECTUV == 0\nvarying vec2 vEmissiveUV;\n#endif\n#if defined(LIGHTMAP) && LIGHTMAPDIRECTUV == 0\nvarying vec2 vLightmapUV;\n#endif\n#if defined(REFLECTIVITY) && REFLECTIVITYDIRECTUV == 0\nvarying vec2 vReflectivityUV;\n#endif\n#if defined(MICROSURFACEMAP) && MICROSURFACEMAPDIRECTUV == 0\nvarying vec2 vMicroSurfaceSamplerUV;\n#endif\n#if defined(BUMP) && BUMPDIRECTUV == 0\nvarying vec2 vBumpUV;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#if defined(USESPHERICALFROMREFLECTIONMAP) && defined(USESPHERICALINVERTEX)\nvarying vec3 vEnvironmentIrradiance;\n#include<harmonicsFunctions>\n#endif\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<bumpVertexDeclaration>\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include<morphTargetsVertexGlobalDeclaration>\n#include<morphTargetsVertexDeclaration>[0..maxSimultaneousMorphTargets]\n#ifdef REFLECTIONMAP_SKYBOX\nvarying vec3 vPositionUVW;\n#endif\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvarying vec3 vDirectionW;\n#endif\n#include<logDepthDeclaration>\nvoid main(void) {\nvec3 positionUpdated=position;\n#ifdef NORMAL\nvec3 normalUpdated=normal;\n#endif\n#ifdef TANGENT\nvec4 tangentUpdated=tangent;\n#endif\n#include<morphTargetsVertex>[0..maxSimultaneousMorphTargets]\n#ifdef REFLECTIONMAP_SKYBOX\nvPositionUVW=positionUpdated;\n#endif \n#include<instancesVertex>\n#include<bonesVertex>\ngl_Position=viewProjection*finalWorld*vec4(positionUpdated,1.0);\nvec4 worldPos=finalWorld*vec4(positionUpdated,1.0);\nvPositionW=vec3(worldPos);\n#ifdef NORMAL\nmat3 normalWorld=mat3(finalWorld);\n#ifdef NONUNIFORMSCALING\nnormalWorld=transposeMat3(inverseMat3(normalWorld));\n#endif\nvNormalW=normalize(normalWorld*normalUpdated);\n#if defined(USESPHERICALFROMREFLECTIONMAP) && defined(USESPHERICALINVERTEX)\nvec3 reflectionVector=vec3(reflectionMatrix*vec4(vNormalW,0)).xyz;\n#ifdef REFLECTIONMAP_OPPOSITEZ\nreflectionVector.z*=-1.0;\n#endif\nvEnvironmentIrradiance=environmentIrradianceJones(reflectionVector);\n#endif\n#endif\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvDirectionW=normalize(vec3(finalWorld*vec4(positionUpdated,0.0)));\n#endif\n\n#ifndef UV1\nvec2 uv=vec2(0.,0.);\n#endif\n#ifndef UV2\nvec2 uv2=vec2(0.,0.);\n#endif\n#ifdef MAINUV1\nvMainUV1=uv;\n#endif \n#ifdef MAINUV2\nvMainUV2=uv2;\n#endif \n#if defined(ALBEDO) && ALBEDODIRECTUV == 0 \nif (vAlbedoInfos.x == 0.)\n{\nvAlbedoUV=vec2(albedoMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvAlbedoUV=vec2(albedoMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(AMBIENT) && AMBIENTDIRECTUV == 0 \nif (vAmbientInfos.x == 0.)\n{\nvAmbientUV=vec2(ambientMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvAmbientUV=vec2(ambientMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(OPACITY) && OPACITYDIRECTUV == 0 \nif (vOpacityInfos.x == 0.)\n{\nvOpacityUV=vec2(opacityMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvOpacityUV=vec2(opacityMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(EMISSIVE) && EMISSIVEDIRECTUV == 0 \nif (vEmissiveInfos.x == 0.)\n{\nvEmissiveUV=vec2(emissiveMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvEmissiveUV=vec2(emissiveMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(LIGHTMAP) && LIGHTMAPDIRECTUV == 0 \nif (vLightmapInfos.x == 0.)\n{\nvLightmapUV=vec2(lightmapMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvLightmapUV=vec2(lightmapMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(REFLECTIVITY) && REFLECTIVITYDIRECTUV == 0 \nif (vReflectivityInfos.x == 0.)\n{\nvReflectivityUV=vec2(reflectivityMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvReflectivityUV=vec2(reflectivityMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(MICROSURFACEMAP) && MICROSURFACEMAPDIRECTUV == 0 \nif (vMicroSurfaceSamplerInfos.x == 0.)\n{\nvMicroSurfaceSamplerUV=vec2(microSurfaceSamplerMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvMicroSurfaceSamplerUV=vec2(microSurfaceSamplerMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(BUMP) && BUMPDIRECTUV == 0 \nif (vBumpInfos.x == 0.)\n{\nvBumpUV=vec2(bumpMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvBumpUV=vec2(bumpMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n\n#include<bumpVertex>\n\n#include<clipPlaneVertex>\n\n#include<fogVertex>\n\n#include<shadowsVertex>[0..maxSimultaneousLights]\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n\n#include<logDepthVertex>\n}",pbrPixelShader:"#if defined(BUMP) || !defined(NORMAL) || defined(FORCENORMALFORWARD)\n#extension GL_OES_standard_derivatives : enable\n#endif\n#ifdef LODBASEDMICROSFURACE\n#extension GL_EXT_shader_texture_lod : enable\n#endif\n#ifdef LOGARITHMICDEPTH\n#extension GL_EXT_frag_depth : enable\n#endif\nprecision highp float;\n#include<__decl__pbrFragment>\nuniform vec4 vEyePosition;\nuniform vec3 vAmbientColor;\nuniform vec4 vCameraInfos;\n\nvarying vec3 vPositionW;\n#ifdef MAINUV1\nvarying vec2 vMainUV1;\n#endif \n#ifdef MAINUV2 \nvarying vec2 vMainUV2;\n#endif \n#ifdef NORMAL\nvarying vec3 vNormalW;\n#if defined(USESPHERICALFROMREFLECTIONMAP) && defined(USESPHERICALINVERTEX)\nvarying vec3 vEnvironmentIrradiance;\n#endif\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n\n#ifdef ALBEDO\n#if ALBEDODIRECTUV == 1\n#define vAlbedoUV vMainUV1\n#elif ALBEDODIRECTUV == 2\n#define vAlbedoUV vMainUV2\n#else\nvarying vec2 vAlbedoUV;\n#endif\nuniform sampler2D albedoSampler;\n#endif\n#ifdef AMBIENT\n#if AMBIENTDIRECTUV == 1\n#define vAmbientUV vMainUV1\n#elif AMBIENTDIRECTUV == 2\n#define vAmbientUV vMainUV2\n#else\nvarying vec2 vAmbientUV;\n#endif\nuniform sampler2D ambientSampler;\n#endif\n#ifdef OPACITY\n#if OPACITYDIRECTUV == 1\n#define vOpacityUV vMainUV1\n#elif OPACITYDIRECTUV == 2\n#define vOpacityUV vMainUV2\n#else\nvarying vec2 vOpacityUV;\n#endif\nuniform sampler2D opacitySampler;\n#endif\n#ifdef EMISSIVE\n#if EMISSIVEDIRECTUV == 1\n#define vEmissiveUV vMainUV1\n#elif EMISSIVEDIRECTUV == 2\n#define vEmissiveUV vMainUV2\n#else\nvarying vec2 vEmissiveUV;\n#endif\nuniform sampler2D emissiveSampler;\n#endif\n#ifdef LIGHTMAP\n#if LIGHTMAPDIRECTUV == 1\n#define vLightmapUV vMainUV1\n#elif LIGHTMAPDIRECTUV == 2\n#define vLightmapUV vMainUV2\n#else\nvarying vec2 vLightmapUV;\n#endif\nuniform sampler2D lightmapSampler;\n#endif\n#ifdef REFLECTIVITY\n#if REFLECTIVITYDIRECTUV == 1\n#define vReflectivityUV vMainUV1\n#elif REFLECTIVITYDIRECTUV == 2\n#define vReflectivityUV vMainUV2\n#else\nvarying vec2 vReflectivityUV;\n#endif\nuniform sampler2D reflectivitySampler;\n#endif\n#ifdef MICROSURFACEMAP\n#if MICROSURFACEMAPDIRECTUV == 1\n#define vMicroSurfaceSamplerUV vMainUV1\n#elif MICROSURFACEMAPDIRECTUV == 2\n#define vMicroSurfaceSamplerUV vMainUV2\n#else\nvarying vec2 vMicroSurfaceSamplerUV;\n#endif\nuniform sampler2D microSurfaceSampler;\n#endif\n\n#ifdef REFRACTION\n#ifdef REFRACTIONMAP_3D\n#define sampleRefraction(s,c) textureCube(s,c)\nuniform samplerCube refractionSampler;\n#ifdef LODBASEDMICROSFURACE\n#define sampleRefractionLod(s,c,l) textureCubeLodEXT(s,c,l)\n#else\nuniform samplerCube refractionSamplerLow;\nuniform samplerCube refractionSamplerHigh;\n#endif\n#else\n#define sampleRefraction(s,c) texture2D(s,c)\nuniform sampler2D refractionSampler;\n#ifdef LODBASEDMICROSFURACE\n#define sampleRefractionLod(s,c,l) texture2DLodEXT(s,c,l)\n#else\nuniform samplerCube refractionSamplerLow;\nuniform samplerCube refractionSamplerHigh;\n#endif\n#endif\n#endif\n\n#ifdef REFLECTION\n#ifdef REFLECTIONMAP_3D\n#define sampleReflection(s,c) textureCube(s,c)\nuniform samplerCube reflectionSampler;\n#ifdef LODBASEDMICROSFURACE\n#define sampleReflectionLod(s,c,l) textureCubeLodEXT(s,c,l)\n#else\nuniform samplerCube reflectionSamplerLow;\nuniform samplerCube reflectionSamplerHigh;\n#endif\n#else\n#define sampleReflection(s,c) texture2D(s,c)\nuniform sampler2D reflectionSampler;\n#ifdef LODBASEDMICROSFURACE\n#define sampleReflectionLod(s,c,l) texture2DLodEXT(s,c,l)\n#else\nuniform samplerCube reflectionSamplerLow;\nuniform samplerCube reflectionSamplerHigh;\n#endif\n#endif\n#ifdef REFLECTIONMAP_SKYBOX\nvarying vec3 vPositionUVW;\n#else\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvarying vec3 vDirectionW;\n#endif\n#endif\n#include<reflectionFunction>\n#endif\n#ifdef ENVIRONMENTBRDF\nuniform sampler2D environmentBrdfSampler;\n#endif\n\n#ifndef FROMLINEARSPACE\n#define FROMLINEARSPACE;\n#endif\n#include<imageProcessingDeclaration>\n#include<helperFunctions>\n#include<imageProcessingFunctions>\n\n#include<shadowsFragmentFunctions>\n#include<pbrFunctions>\n#include<harmonicsFunctions>\n#include<pbrLightFunctions>\n#include<bumpFragmentFunctions>\n#include<clipPlaneFragmentDeclaration>\n#include<logDepthDeclaration>\n\n#include<fogFragmentDeclaration>\nvoid main(void) {\n#include<clipPlaneFragment>\n\n\nvec3 viewDirectionW=normalize(vEyePosition.xyz-vPositionW);\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=normalize(cross(dFdx(vPositionW),dFdy(vPositionW)))*vEyePosition.w;\n#endif\n#include<bumpFragment>\n#if defined(FORCENORMALFORWARD) && defined(NORMAL)\nvec3 faceNormal=normalize(cross(dFdx(vPositionW),dFdy(vPositionW)))*vEyePosition.w;\n#if defined(TWOSIDEDLIGHTING)\nfaceNormal=gl_FrontFacing ? faceNormal : -faceNormal;\n#endif\nnormalW*=sign(dot(normalW,faceNormal));\n#endif\n#if defined(TWOSIDEDLIGHTING) && defined(NORMAL)\nnormalW=gl_FrontFacing ? normalW : -normalW;\n#endif\n\n\nvec3 surfaceAlbedo=vAlbedoColor.rgb;\n\nfloat alpha=vAlbedoColor.a;\n#ifdef ALBEDO\nvec4 albedoTexture=texture2D(albedoSampler,vAlbedoUV+uvOffset);\n#if defined(ALPHAFROMALBEDO) || defined(ALPHATEST)\nalpha*=albedoTexture.a;\n#endif\nsurfaceAlbedo*=toLinearSpace(albedoTexture.rgb);\nsurfaceAlbedo*=vAlbedoInfos.y;\n#endif\n\n#ifdef OPACITY\nvec4 opacityMap=texture2D(opacitySampler,vOpacityUV+uvOffset);\n#ifdef OPACITYRGB\nalpha=getLuminance(opacityMap.rgb);\n#else\nalpha*=opacityMap.a;\n#endif\nalpha*=vOpacityInfos.y;\n#endif\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\n#if !defined(LINKREFRACTIONTOTRANSPARENCY) && !defined(ALPHAFRESNEL)\n#ifdef ALPHATEST\nif (alpha<=ALPHATESTVALUE)\ndiscard;\n#ifndef ALPHABLEND\n\nalpha=1.0;\n#endif\n#endif\n#endif\n#include<depthPrePass>\n#ifdef VERTEXCOLOR\nsurfaceAlbedo*=vColor.rgb;\n#endif\n\nvec3 ambientOcclusionColor=vec3(1.,1.,1.);\n#ifdef AMBIENT\nvec3 ambientOcclusionColorMap=texture2D(ambientSampler,vAmbientUV+uvOffset).rgb*vAmbientInfos.y;\n#ifdef AMBIENTINGRAYSCALE\nambientOcclusionColorMap=vec3(ambientOcclusionColorMap.r,ambientOcclusionColorMap.r,ambientOcclusionColorMap.r);\n#endif\nambientOcclusionColor=mix(ambientOcclusionColor,ambientOcclusionColorMap,vAmbientInfos.z);\n#endif\n\nfloat microSurface=vReflectivityColor.a;\nvec3 surfaceReflectivityColor=vReflectivityColor.rgb;\n#ifdef METALLICWORKFLOW\nvec2 metallicRoughness=surfaceReflectivityColor.rg;\n#ifdef REFLECTIVITY\nvec4 surfaceMetallicColorMap=texture2D(reflectivitySampler,vReflectivityUV+uvOffset);\n#ifdef AOSTOREINMETALMAPRED\nvec3 aoStoreInMetalMap=vec3(surfaceMetallicColorMap.r,surfaceMetallicColorMap.r,surfaceMetallicColorMap.r);\nambientOcclusionColor=mix(ambientOcclusionColor,aoStoreInMetalMap,vReflectivityInfos.z);\n#endif\n#ifdef METALLNESSSTOREINMETALMAPBLUE\nmetallicRoughness.r*=surfaceMetallicColorMap.b;\n#else\nmetallicRoughness.r*=surfaceMetallicColorMap.r;\n#endif\n#ifdef ROUGHNESSSTOREINMETALMAPALPHA\nmetallicRoughness.g*=surfaceMetallicColorMap.a;\n#else\n#ifdef ROUGHNESSSTOREINMETALMAPGREEN\nmetallicRoughness.g*=surfaceMetallicColorMap.g;\n#endif\n#endif\n#endif\n#ifdef MICROSURFACEMAP\nvec4 microSurfaceTexel=texture2D(microSurfaceSampler,vMicroSurfaceSamplerUV+uvOffset)*vMicroSurfaceSamplerInfos.y;\nmetallicRoughness.g*=microSurfaceTexel.r;\n#endif\n\nmicroSurface=1.0-metallicRoughness.g;\n\nvec3 baseColor=surfaceAlbedo;\n\n\nconst vec3 DefaultSpecularReflectanceDielectric=vec3(0.04,0.04,0.04);\n\nsurfaceAlbedo=mix(baseColor.rgb*(1.0-DefaultSpecularReflectanceDielectric.r),vec3(0.,0.,0.),metallicRoughness.r);\n\nsurfaceReflectivityColor=mix(DefaultSpecularReflectanceDielectric,baseColor,metallicRoughness.r);\n#else\n#ifdef REFLECTIVITY\nvec4 surfaceReflectivityColorMap=texture2D(reflectivitySampler,vReflectivityUV+uvOffset);\nsurfaceReflectivityColor*=toLinearSpace(surfaceReflectivityColorMap.rgb);\nsurfaceReflectivityColor*=vReflectivityInfos.y;\n#ifdef MICROSURFACEFROMREFLECTIVITYMAP\nmicroSurface*=surfaceReflectivityColorMap.a;\nmicroSurface*=vReflectivityInfos.z;\n#else\n#ifdef MICROSURFACEAUTOMATIC\nmicroSurface*=computeDefaultMicroSurface(microSurface,surfaceReflectivityColor);\n#endif\n#ifdef MICROSURFACEMAP\nvec4 microSurfaceTexel=texture2D(microSurfaceSampler,vMicroSurfaceSamplerUV+uvOffset)*vMicroSurfaceSamplerInfos.y;\nmicroSurface*=microSurfaceTexel.r;\n#endif\n#endif\n#endif\n#endif\n\nmicroSurface=clamp(microSurface,0.,1.);\n\nfloat roughness=1.-microSurface;\n\n#ifdef ALPHAFRESNEL\n#if defined(ALPHATEST) || defined(ALPHABLEND)\n\n\n\nfloat opacityPerceptual=alpha;\n#ifdef LINEARALPHAFRESNEL\nfloat opacity0=opacityPerceptual;\n#else\nfloat opacity0=opacityPerceptual*opacityPerceptual;\n#endif\nfloat opacity90=fresnelGrazingReflectance(opacity0);\nvec3 normalForward=faceforward(normalW,-viewDirectionW,normalW);\n\nalpha=fresnelSchlickEnvironmentGGX(clamp(dot(viewDirectionW,normalForward),0.0,1.0),vec3(opacity0),vec3(opacity90),sqrt(microSurface)).x;\n#ifdef ALPHATEST\nif (alpha<=ALPHATESTVALUE)\ndiscard;\n#ifndef ALPHABLEND\n\nalpha=1.0;\n#endif\n#endif\n#endif\n#endif\n\n\nfloat NdotVUnclamped=dot(normalW,viewDirectionW);\nfloat NdotV=clamp(NdotVUnclamped,0.,1.)+0.00001;\nfloat alphaG=convertRoughnessToAverageSlope(roughness);\n\n#ifdef REFRACTION\nvec3 environmentRefraction=vec3(0.,0.,0.);\nvec3 refractionVector=refract(-viewDirectionW,normalW,vRefractionInfos.y);\n#ifdef REFRACTIONMAP_OPPOSITEZ\nrefractionVector.z*=-1.0;\n#endif\n\n#ifdef REFRACTIONMAP_3D\nrefractionVector.y=refractionVector.y*vRefractionInfos.w;\nvec3 refractionCoords=refractionVector;\nrefractionCoords=vec3(refractionMatrix*vec4(refractionCoords,0));\n#else\nvec3 vRefractionUVW=vec3(refractionMatrix*(view*vec4(vPositionW+refractionVector*vRefractionInfos.z,1.0)));\nvec2 refractionCoords=vRefractionUVW.xy/vRefractionUVW.z;\nrefractionCoords.y=1.0-refractionCoords.y;\n#endif\n#ifdef LODINREFRACTIONALPHA\nfloat refractionLOD=getLodFromAlphaG(vRefractionMicrosurfaceInfos.x,alphaG,NdotVUnclamped);\n#else\nfloat refractionLOD=getLodFromAlphaG(vRefractionMicrosurfaceInfos.x,alphaG,1.0);\n#endif\n#ifdef LODBASEDMICROSFURACE\n\nrefractionLOD=refractionLOD*vRefractionMicrosurfaceInfos.y+vRefractionMicrosurfaceInfos.z;\n#ifdef LODINREFRACTIONALPHA\n\n\n\n\n\n\n\n\n\nfloat automaticRefractionLOD=UNPACK_LOD(sampleRefraction(refractionSampler,refractionCoords).a);\nfloat requestedRefractionLOD=max(automaticRefractionLOD,refractionLOD);\n#else\nfloat requestedRefractionLOD=refractionLOD;\n#endif\nenvironmentRefraction=sampleRefractionLod(refractionSampler,refractionCoords,requestedRefractionLOD).rgb;\n#else\nfloat lodRefractionNormalized=clamp(refractionLOD/log2(vRefractionMicrosurfaceInfos.x),0.,1.);\nfloat lodRefractionNormalizedDoubled=lodRefractionNormalized*2.0;\nvec3 environmentRefractionMid=sampleRefraction(refractionSampler,refractionCoords).rgb;\nif(lodRefractionNormalizedDoubled<1.0){\nenvironmentRefraction=mix(\nsampleRefraction(refractionSamplerHigh,refractionCoords).rgb,\nenvironmentRefractionMid,\nlodRefractionNormalizedDoubled\n);\n}else{\nenvironmentRefraction=mix(\nenvironmentRefractionMid,\nsampleRefraction(refractionSamplerLow,refractionCoords).rgb,\nlodRefractionNormalizedDoubled-1.0\n);\n}\n#endif\n#ifdef GAMMAREFRACTION\nenvironmentRefraction=toLinearSpace(environmentRefraction.rgb);\n#endif\n\nenvironmentRefraction*=vRefractionInfos.x;\n#endif\n\n#ifdef REFLECTION\nvec3 environmentRadiance=vec3(0.,0.,0.);\nvec3 environmentIrradiance=vec3(0.,0.,0.);\nvec3 reflectionVector=computeReflectionCoords(vec4(vPositionW,1.0),normalW);\n#ifdef REFLECTIONMAP_OPPOSITEZ\nreflectionVector.z*=-1.0;\n#endif\n\n#ifdef REFLECTIONMAP_3D\nvec3 reflectionCoords=reflectionVector;\n#else\nvec2 reflectionCoords=reflectionVector.xy;\n#ifdef REFLECTIONMAP_PROJECTION\nreflectionCoords/=reflectionVector.z;\n#endif\nreflectionCoords.y=1.0-reflectionCoords.y;\n#endif\n#if defined(LODINREFLECTIONALPHA) && !defined(REFLECTIONMAP_SKYBOX)\nfloat reflectionLOD=getLodFromAlphaG(vReflectionMicrosurfaceInfos.x,alphaG,NdotVUnclamped);\n#else\nfloat reflectionLOD=getLodFromAlphaG(vReflectionMicrosurfaceInfos.x,alphaG,1.);\n#endif\n#ifdef LODBASEDMICROSFURACE\n\nreflectionLOD=reflectionLOD*vReflectionMicrosurfaceInfos.y+vReflectionMicrosurfaceInfos.z;\n#ifdef LODINREFLECTIONALPHA\n\n\n\n\n\n\n\n\n\nfloat automaticReflectionLOD=UNPACK_LOD(sampleReflection(reflectionSampler,reflectionCoords).a);\nfloat requestedReflectionLOD=max(automaticReflectionLOD,reflectionLOD);\n#else\nfloat requestedReflectionLOD=reflectionLOD;\n#endif\nenvironmentRadiance=sampleReflectionLod(reflectionSampler,reflectionCoords,requestedReflectionLOD).rgb;\n#else\nfloat lodReflectionNormalized=clamp(reflectionLOD/log2(vReflectionMicrosurfaceInfos.x),0.,1.);\nfloat lodReflectionNormalizedDoubled=lodReflectionNormalized*2.0;\nvec3 environmentSpecularMid=sampleReflection(reflectionSampler,reflectionCoords).rgb;\nif(lodReflectionNormalizedDoubled<1.0){\nenvironmentRadiance=mix(\nsampleReflection(reflectionSamplerHigh,reflectionCoords).rgb,\nenvironmentSpecularMid,\nlodReflectionNormalizedDoubled\n);\n}else{\nenvironmentRadiance=mix(\nenvironmentSpecularMid,\nsampleReflection(reflectionSamplerLow,reflectionCoords).rgb,\nlodReflectionNormalizedDoubled-1.0\n);\n}\n#endif\n#ifdef GAMMAREFLECTION\nenvironmentRadiance=toLinearSpace(environmentRadiance.rgb);\n#endif\n\n#ifdef USESPHERICALFROMREFLECTIONMAP\n#if defined(NORMAL) && defined(USESPHERICALINVERTEX)\nenvironmentIrradiance=vEnvironmentIrradiance;\n#else\nvec3 irradianceVector=vec3(reflectionMatrix*vec4(normalW,0)).xyz;\n#ifdef REFLECTIONMAP_OPPOSITEZ\nirradianceVector.z*=-1.0;\n#endif\nenvironmentIrradiance=environmentIrradianceJones(irradianceVector);\n#endif\n#endif\n\nenvironmentRadiance*=vReflectionInfos.x;\nenvironmentRadiance*=vReflectionColor.rgb;\nenvironmentIrradiance*=vReflectionColor.rgb;\n#endif\n\n\n\nfloat reflectance=max(max(surfaceReflectivityColor.r,surfaceReflectivityColor.g),surfaceReflectivityColor.b);\nfloat reflectance90=fresnelGrazingReflectance(reflectance);\nvec3 specularEnvironmentR0=surfaceReflectivityColor.rgb;\nvec3 specularEnvironmentR90=vec3(1.0,1.0,1.0)*reflectance90;\n\nvec3 diffuseBase=vec3(0.,0.,0.);\n#ifdef SPECULARTERM\nvec3 specularBase=vec3(0.,0.,0.);\n#endif\n#ifdef LIGHTMAP\nvec3 lightmapColor=texture2D(lightmapSampler,vLightmapUV+uvOffset).rgb*vLightmapInfos.y;\n#endif\nlightingInfo info;\nfloat shadow=1.; \nfloat NdotL=-1.;\n#include<lightFragment>[0..maxSimultaneousLights]\n\n#if defined(ENVIRONMENTBRDF) && !defined(REFLECTIONMAP_SKYBOX)\n\nvec2 brdfSamplerUV=vec2(NdotV,roughness);\n\nvec4 environmentBrdf=texture2D(environmentBrdfSampler,brdfSamplerUV);\nvec3 specularEnvironmentReflectance=specularEnvironmentR0*environmentBrdf.x+environmentBrdf.y;\n#ifdef 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<logDepthFragment>\n#include<fogFragment>(color,finalColor)\n#ifdef IMAGEPROCESSINGPOSTPROCESS\n\n\nfinalColor.rgb=clamp(finalColor.rgb,0.,30.0);\n#else\n\nfinalColor=applyImageProcessing(finalColor);\n#endif\n#ifdef PREMULTIPLYALPHA\n\nfinalColor.rgb*=finalColor.a;\n#endif\ngl_FragColor=finalColor;\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n}",spritesVertexShader:"\nattribute vec4 position;\nattribute vec4 options;\nattribute vec4 cellInfo;\nattribute vec4 color;\n\nuniform vec2 textureInfos;\nuniform mat4 view;\nuniform mat4 projection;\n\nvarying vec2 vUV;\nvarying vec4 vColor;\n#include<fogVertexDeclaration>\nvoid main(void) { \nvec3 viewPos=(view*vec4(position.xyz,1.0)).xyz; \nvec2 cornerPos;\nfloat angle=position.w;\nvec2 size=vec2(options.x,options.y);\nvec2 offset=options.zw;\nvec2 uvScale=textureInfos.xy;\ncornerPos=vec2(offset.x-0.5,offset.y-0.5)*size;\n\nvec3 rotatedCorner;\nrotatedCorner.x=cornerPos.x*cos(angle)-cornerPos.y*sin(angle);\nrotatedCorner.y=cornerPos.x*sin(angle)+cornerPos.y*cos(angle);\nrotatedCorner.z=0.;\n\nviewPos+=rotatedCorner;\ngl_Position=projection*vec4(viewPos,1.0); \n\nvColor=color;\n\nvec2 uvOffset=vec2(abs(offset.x-cellInfo.x),1.0-abs(offset.y-cellInfo.y));\nvUV=(uvOffset+cellInfo.zw)*uvScale;\n\n#ifdef FOG\nvFogDistance=viewPos;\n#endif\n}",spritesPixelShader:"uniform bool alphaTest;\nvarying vec4 vColor;\n\nvarying vec2 vUV;\nuniform sampler2D diffuseSampler;\n\n#include<fogFragmentDeclaration>\nvoid main(void) {\nvec4 color=texture2D(diffuseSampler,vUV);\nif (alphaTest) \n{\nif (color.a<0.95)\ndiscard;\n}\ncolor*=vColor;\n#include<fogFragment>\ngl_FragColor=color;\n}",particlesVertexShader:"\nattribute vec3 position;\nattribute vec4 color;\nattribute vec4 options;\nattribute float cellIndex;\n\nuniform mat4 view;\nuniform mat4 projection;\nuniform vec3 particlesInfos; \n\nvarying vec2 vUV;\nvarying vec4 vColor;\n#ifdef CLIPPLANE\nuniform vec4 vClipPlane;\nuniform mat4 invView;\nvarying float fClipDistance;\n#endif\nvoid main(void) { \nvec3 viewPos=(view*vec4(position,1.0)).xyz; \nvec3 cornerPos;\nfloat size=options.y;\nfloat angle=options.x;\nvec2 offset=options.zw;\ncornerPos=vec3(offset.x-0.5,offset.y-0.5,0.)*size;\n\nvec3 rotatedCorner;\nrotatedCorner.x=cornerPos.x*cos(angle)-cornerPos.y*sin(angle);\nrotatedCorner.y=cornerPos.x*sin(angle)+cornerPos.y*cos(angle);\nrotatedCorner.z=0.;\n\nviewPos+=rotatedCorner;\ngl_Position=projection*vec4(viewPos,1.0); \nvColor=color;\n#ifdef ANIMATESHEET\nfloat rowOffset=floor(cellIndex/particlesInfos.z);\nfloat columnOffset=cellIndex-rowOffset*particlesInfos.z;\nvec2 uvScale=particlesInfos.xy;\nvec2 uvOffset=vec2(offset.x ,1.0-offset.y);\nvUV=(uvOffset+vec2(columnOffset,rowOffset))*uvScale;\n#else\nvUV=offset;\n#endif\n\n#ifdef CLIPPLANE\nvec4 worldPos=invView*vec4(viewPos,1.0);\nfClipDistance=dot(worldPos,vClipPlane);\n#endif\n}",particlesPixelShader:"\nvarying vec2 vUV;\nvarying vec4 vColor;\nuniform vec4 textureMask;\nuniform sampler2D diffuseSampler;\n#ifdef CLIPPLANE\nvarying float fClipDistance;\n#endif\nvoid main(void) {\n#ifdef CLIPPLANE\nif (fClipDistance>0.0)\ndiscard;\n#endif\nvec4 baseColor=texture2D(diffuseSampler,vUV);\ngl_FragColor=(baseColor*textureMask+(vec4(1.,1.,1.,1.)-textureMask))*vColor;\n}",gpuRenderParticlesVertexShader:"#version 300 es\n\nin vec3 position;\nin float age;\nin float life;\nin vec3 velocity;\nvoid main() {\ngl_PointSize=1.0;\ngl_Position=vec4(position,1.0);\n}",gpuRenderParticlesPixelShader:"void main() {\ngl_FragColor=vec4(1.0);\n}\n",gpuUpdateParticlesVertexShader:"#version 300 es\nuniform float timeDelta;\n\nin vec3 position;\nin float age;\nin float life;\nin vec3 velocity;\n\nout vec3 outPosition;\nout float outAge;\nout float outLife;\nout vec3 outVelocity;\nvoid main() {\nif (age>=life) {\n\noutPosition=vec3(0,0,0);\n\noutAge=0.0;\noutLife=life;\n\noutVelocity=vec3(0,1,0);\n} else {\noutPosition=position+velocity*timeDelta;\noutAge=age+timeDelta;\noutLife=life;\noutVelocity=velocity;\n}\n}",gpuUpdateParticlesPixelShader:"#version 300 es\nvoid main() {\ndiscard;\n}\n",colorVertexShader:"\nattribute vec3 position;\n#ifdef VERTEXCOLOR\nattribute vec4 color;\n#endif\n#include<bonesDeclaration>\n\nuniform mat4 viewProjection;\nuniform mat4 world;\n\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\nvoid main(void) {\nmat4 finalWorld=world;\n#include<bonesVertex>\ngl_Position=viewProjection*finalWorld*vec4(position,1.0);\n#ifdef VERTEXCOLOR\n\nvColor=color;\n#endif\n}",colorPixelShader:"#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#else\nuniform vec4 color;\n#endif\nvoid main(void) {\n#ifdef VERTEXCOLOR\ngl_FragColor=vColor;\n#else\ngl_FragColor=color;\n#endif\n}",postprocessVertexShader:"\nattribute vec2 position;\nuniform vec2 scale;\n\nvarying vec2 vUV;\nconst vec2 madd=vec2(0.5,0.5);\nvoid main(void) { \nvUV=(position*madd+madd)*scale;\ngl_Position=vec4(position,0.0,1.0);\n}",passPixelShader:"\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\nvoid main(void) \n{\ngl_FragColor=texture2D(textureSampler,vUV);\n}",shadowMapVertexShader:"\nattribute vec3 position;\n#include<bonesDeclaration>\n\n#include<instancesDeclaration>\nuniform mat4 viewProjection;\nuniform vec2 biasAndScale;\nuniform vec2 depthValues;\nvarying float vDepthMetric;\n#ifdef ALPHATEST\nvarying vec2 vUV;\nuniform mat4 diffuseMatrix;\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#endif\nvoid main(void)\n{\n#include<instancesVertex>\n#include<bonesVertex>\nvec4 worldPos=finalWorld*vec4(position,1.0);\ngl_Position=viewProjection*worldPos;\nvDepthMetric=((gl_Position.z+depthValues.x)/(depthValues.y))+biasAndScale.x;\n#ifdef ALPHATEST\n#ifdef UV1\nvUV=vec2(diffuseMatrix*vec4(uv,1.0,0.0));\n#endif\n#ifdef UV2\nvUV=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));\n#endif\n#endif\n}",shadowMapPixelShader:"#ifndef FLOAT\nvec4 pack(float depth)\n{\nconst vec4 bit_shift=vec4(255.0*255.0*255.0,255.0*255.0,255.0,1.0);\nconst vec4 bit_mask=vec4(0.0,1.0/255.0,1.0/255.0,1.0/255.0);\nvec4 res=fract(depth*bit_shift);\nres-=res.xxyz*bit_mask;\nreturn res;\n}\n#endif\nvarying float vDepthMetric;\n#ifdef ALPHATEST\nvarying vec2 vUV;\nuniform sampler2D diffuseSampler;\n#endif\nuniform vec2 biasAndScale;\nuniform vec2 depthValues;\nvoid main(void)\n{\n#ifdef ALPHATEST\nif (texture2D(diffuseSampler,vUV).a<0.4)\ndiscard;\n#endif\nfloat depth=vDepthMetric;\n#ifdef ESM\ndepth=clamp(exp(-min(87.,biasAndScale.y*depth)),0.,1.);\n#endif\n#ifdef FLOAT\ngl_FragColor=vec4(depth,1.0,1.0,1.0);\n#else\ngl_FragColor=pack(depth);\n#endif\n}",depthBoxBlurPixelShader:"\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\n\nuniform vec2 screenSize;\nvoid main(void)\n{\nvec4 colorDepth=vec4(0.0);\nfor (int x=-OFFSET; x<=OFFSET; x++)\nfor (int y=-OFFSET; y<=OFFSET; y++)\ncolorDepth+=texture2D(textureSampler,vUV+vec2(x,y)/screenSize);\ngl_FragColor=(colorDepth/float((OFFSET*2+1)*(OFFSET*2+1)));\n}",proceduralVertexShader:"\nattribute vec2 position;\n\nvarying vec2 vPosition;\nvarying vec2 vUV;\nconst vec2 madd=vec2(0.5,0.5);\nvoid main(void) { \nvPosition=position;\nvUV=position*madd+madd;\ngl_Position=vec4(position,0.0,1.0);\n}",depthVertexShader:"\nattribute vec3 position;\n#include<bonesDeclaration>\n\n#include<instancesDeclaration>\nuniform mat4 viewProjection;\nuniform vec2 depthValues;\n#if defined(ALPHATEST) || defined(NEED_UV)\nvarying vec2 vUV;\nuniform mat4 diffuseMatrix;\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#endif\nvarying float vDepthMetric;\nvoid main(void)\n{\n#include<instancesVertex>\n#include<bonesVertex>\ngl_Position=viewProjection*finalWorld*vec4(position,1.0);\nvDepthMetric=((gl_Position.z+depthValues.x)/(depthValues.y));\n#if defined(ALPHATEST) || defined(BASIC_RENDER)\n#ifdef UV1\nvUV=vec2(diffuseMatrix*vec4(uv,1.0,0.0));\n#endif\n#ifdef UV2\nvUV=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));\n#endif\n#endif\n}",depthPixelShader:"#ifdef ALPHATEST\nvarying vec2 vUV;\nuniform sampler2D diffuseSampler;\n#endif\nvarying float vDepthMetric;\nvoid main(void)\n{\n#ifdef ALPHATEST\nif (texture2D(diffuseSampler,vUV).a<0.4)\ndiscard;\n#endif\ngl_FragColor=vec4(vDepthMetric,vDepthMetric*vDepthMetric,0.0,1.0);\n}",ssaoPixelShader:"\nuniform sampler2D textureSampler;\nvarying vec2 vUV;\n#ifdef SSAO\nuniform sampler2D randomSampler;\nuniform float randTextureTiles;\nuniform float samplesFactor;\nuniform vec3 sampleSphere[SAMPLES];\nuniform float totalStrength;\nuniform float radius;\nuniform float area;\nuniform float fallOff;\nuniform float base;\nvec3 normalFromDepth(float depth,vec2 coords)\n{\nvec2 offset1=vec2(0.0,radius);\nvec2 offset2=vec2(radius,0.0);\nfloat depth1=texture2D(textureSampler,coords+offset1).r;\nfloat depth2=texture2D(textureSampler,coords+offset2).r;\nvec3 p1=vec3(offset1,depth1-depth);\nvec3 p2=vec3(offset2,depth2-depth);\nvec3 normal=cross(p1,p2);\nnormal.z=-normal.z;\nreturn normalize(normal);\n}\nvoid main()\n{\nvec3 random=normalize(texture2D(randomSampler,vUV*randTextureTiles).rgb);\nfloat depth=texture2D(textureSampler,vUV).r;\nvec3 position=vec3(vUV,depth);\nvec3 normal=normalFromDepth(depth,vUV);\nfloat radiusDepth=radius/depth;\nfloat occlusion=0.0;\nvec3 ray;\nvec3 hemiRay;\nfloat occlusionDepth;\nfloat difference;\nfor (int i=0; i<SAMPLES; i++)\n{\nray=radiusDepth*reflect(sampleSphere[i],random);\nhemiRay=position+sign(dot(ray,normal))*ray;\nocclusionDepth=texture2D(textureSampler,clamp(hemiRay.xy,vec2(0.001,0.001),vec2(0.999,0.999))).r;\ndifference=depth-occlusionDepth;\nocclusion+=step(fallOff,difference)*(1.0-smoothstep(fallOff,area,difference));\n}\nfloat ao=1.0-totalStrength*occlusion*samplesFactor;\nfloat result=clamp(ao+base,0.0,1.0);\ngl_FragColor.r=result;\ngl_FragColor.g=result;\ngl_FragColor.b=result;\ngl_FragColor.a=1.0;\n}\n#endif\n",ssao2PixelShader:"\nprecision highp float;\nuniform sampler2D textureSampler;\nuniform float near;\nuniform float far;\nuniform float radius;\nvarying vec2 vUV;\nfloat perspectiveDepthToViewZ( const in float invClipZ,const in float near,const in float far ) {\nreturn ( near*far )/( ( far-near )*invClipZ-far );\n}\nfloat viewZToPerspectiveDepth( const in float viewZ,const in float near,const in float far ) {\nreturn ( near*far/viewZ+far)/( far-near );\n}\nfloat viewZToOrthographicDepth( const in float viewZ,const in float near,const in float far ) {\nreturn ( viewZ+near )/( near-far );\n}\n#ifdef SSAO\nuniform sampler2D randomSampler;\nuniform sampler2D normalSampler;\nuniform float randTextureTiles;\nuniform float samplesFactor;\nuniform vec3 sampleSphere[SAMPLES];\nuniform float totalStrength;\nuniform float base;\nuniform float xViewport;\nuniform float yViewport;\nuniform float maxZ;\nuniform float minZAspect;\nuniform vec2 texelSize;\nuniform mat4 projection;\nvoid main()\n{\nvec3 random=texture2D(randomSampler,vUV*randTextureTiles).rgb;\nfloat depth=texture2D(textureSampler,vUV).r;\nfloat depthSign=depth/abs(depth);\ndepth=depth*depthSign;\nvec3 normal=texture2D(normalSampler,vUV).rgb; \nfloat occlusion=0.0;\nfloat correctedRadius=min(radius,minZAspect*depth/near);\nvec3 vViewRay=vec3((vUV.x*2.0-1.0)*xViewport,(vUV.y*2.0-1.0)*yViewport,depthSign);\nvec3 origin=vViewRay*depth;\nvec3 rvec=random*2.0-1.0;\nrvec.z=0.0;\nvec3 tangent=normalize(rvec-normal*dot(rvec,normal));\nvec3 bitangent=cross(normal,tangent);\nmat3 tbn=mat3(tangent,bitangent,normal);\nfloat difference;\nif (depth>maxZ) {\ngl_FragColor=vec4(1.0,1.0,1.0,1.0);\nreturn;\n}\nfor (int i=0; i<SAMPLES; ++i) {\n\nvec3 samplePosition=tbn*sampleSphere[i];\nsamplePosition=samplePosition*correctedRadius+origin;\n\nvec4 offset=vec4(samplePosition,1.0);\noffset=projection*offset;\noffset.xyz/=offset.w;\noffset.xy=offset.xy*0.5+0.5;\nif (offset.x<0.0 || offset.y<0.0 || offset.x>1.0 || offset.y>1.0) {\ncontinue;\n}\n\nfloat sampleDepth=abs(texture2D(textureSampler,offset.xy).r);\n\nfloat rangeCheck=abs(depth-sampleDepth)<correctedRadius ? 1.0 : 0.0;\ndifference=depthSign*samplePosition.z-sampleDepth;\n\nocclusion+=(difference>=1e-5 ? 1.0 : 0.0)*rangeCheck;\n}\n\nfloat ao=1.0-totalStrength*occlusion*samplesFactor;\nfloat result=clamp(ao+base,0.0,1.0);\ngl_FragColor=vec4(vec3(result),1.0);\n}\n#endif\n#ifdef BILATERAL_BLUR\nuniform sampler2D depthSampler;\nuniform float outSize;\nuniform float samplerOffsets[SAMPLES];\nvec4 blur9(sampler2D image,vec2 uv,float resolution,vec2 direction) {\nvec4 color=vec4(0.0);\nvec2 off1=vec2(1.3846153846)*direction;\nvec2 off2=vec2(3.2307692308)*direction;\ncolor+=texture2D(image,uv)*0.2270270270;\ncolor+=texture2D(image,uv+(off1/resolution))*0.3162162162;\ncolor+=texture2D(image,uv-(off1/resolution))*0.3162162162;\ncolor+=texture2D(image,uv+(off2/resolution))*0.0702702703;\ncolor+=texture2D(image,uv-(off2/resolution))*0.0702702703;\nreturn color;\n}\nvec4 blur13(sampler2D image,vec2 uv,float resolution,vec2 direction) {\nvec4 color=vec4(0.0);\nvec2 off1=vec2(1.411764705882353)*direction;\nvec2 off2=vec2(3.2941176470588234)*direction;\nvec2 off3=vec2(5.176470588235294)*direction;\ncolor+=texture2D(image,uv)*0.1964825501511404;\ncolor+=texture2D(image,uv+(off1/resolution))*0.2969069646728344;\ncolor+=texture2D(image,uv-(off1/resolution))*0.2969069646728344;\ncolor+=texture2D(image,uv+(off2/resolution))*0.09447039785044732;\ncolor+=texture2D(image,uv-(off2/resolution))*0.09447039785044732;\ncolor+=texture2D(image,uv+(off3/resolution))*0.010381362401148057;\ncolor+=texture2D(image,uv-(off3/resolution))*0.010381362401148057;\nreturn color;\n}\nvec4 blur13Bilateral(sampler2D image,vec2 uv,float resolution,vec2 direction) {\nvec4 color=vec4(0.0);\nvec2 off1=vec2(1.411764705882353)*direction;\nvec2 off2=vec2(3.2941176470588234)*direction;\nvec2 off3=vec2(5.176470588235294)*direction;\nfloat compareDepth=abs(texture2D(depthSampler,uv).r);\nfloat sampleDepth;\nfloat weight;\nfloat weightSum=30.0;\ncolor+=texture2D(image,uv)*30.0;\nsampleDepth=abs(texture2D(depthSampler,uv+(off1/resolution)).r);\nweight=clamp(1.0/( 0.003+abs(compareDepth-sampleDepth)),0.0,30.0);\nweightSum+=weight;\ncolor+=texture2D(image,uv+(off1/resolution))*weight;\nsampleDepth=abs(texture2D(depthSampler,uv-(off1/resolution)).r);\nweight=clamp(1.0/( 0.003+abs(compareDepth-sampleDepth)),0.0,30.0);\nweightSum+=weight;\ncolor+=texture2D(image,uv-(off1/resolution))*weight;\nsampleDepth=abs(texture2D(depthSampler,uv+(off2/resolution)).r);\nweight=clamp(1.0/( 0.003+abs(compareDepth-sampleDepth)),0.0,30.0);\nweightSum+=weight;\ncolor+=texture2D(image,uv+(off2/resolution))*weight;\nsampleDepth=abs(texture2D(depthSampler,uv-(off2/resolution)).r);\nweight=clamp(1.0/( 0.003+abs(compareDepth-sampleDepth)),0.0,30.0);\nweightSum+=weight;\ncolor+=texture2D(image,uv-(off2/resolution))*weight;\nsampleDepth=abs(texture2D(depthSampler,uv+(off3/resolution)).r);\nweight=clamp(1.0/( 0.003+abs(compareDepth-sampleDepth)),0.0,30.0);\nweightSum+=weight;\ncolor+=texture2D(image,uv+(off3/resolution))*weight;\nsampleDepth=abs(texture2D(depthSampler,uv-(off3/resolution)).r);\nweight=clamp(1.0/( 0.003+abs(compareDepth-sampleDepth)),0.0,30.0);\nweightSum+=weight;\ncolor+=texture2D(image,uv-(off3/resolution))*weight;\nreturn color/weightSum;\n}\nvoid main()\n{\n#if EXPENSIVE\nfloat compareDepth=abs(texture2D(depthSampler,vUV).r);\nfloat texelsize=1.0/outSize;\nfloat result=0.0;\nfloat weightSum=0.0;\nfor (int i=0; i<SAMPLES; ++i)\n{\n#ifdef BILATERAL_BLUR_H\nvec2 direction=vec2(1.0,0.0);\nvec2 sampleOffset=vec2(texelsize*samplerOffsets[i],0.0);\n#else\nvec2 direction=vec2(0.0,1.0);\nvec2 sampleOffset=vec2(0.0,texelsize*samplerOffsets[i]);\n#endif\nvec2 samplePos=vUV+sampleOffset;\nfloat sampleDepth=abs(texture2D(depthSampler,samplePos).r);\nfloat weight=clamp(1.0/( 0.003+abs(compareDepth-sampleDepth)),0.0,30000.0);\nresult+=texture2D(textureSampler,samplePos).r*weight;\nweightSum+=weight;\n}\nresult/=weightSum;\ngl_FragColor.rgb=vec3(result);\ngl_FragColor.a=1.0;\n#else\nvec4 color;\n#ifdef BILATERAL_BLUR_H\nvec2 direction=vec2(1.0,0.0);\ncolor=blur13Bilateral(textureSampler,vUV,outSize,direction);\n#else\nvec2 direction=vec2(0.0,1.0);\ncolor=blur13Bilateral(textureSampler,vUV,outSize,direction);\n#endif\ngl_FragColor.rgb=vec3(color.r);\ngl_FragColor.a=1.0;\n#endif\n}\n#endif\n",ssaoCombinePixelShader:"uniform sampler2D textureSampler;\nuniform sampler2D originalColor;\nvarying vec2 vUV;\nvoid main(void) {\nvec4 ssaoColor=texture2D(textureSampler,vUV);\nvec4 sceneColor=texture2D(originalColor,vUV);\ngl_FragColor=sceneColor*ssaoColor;\n}\n",chromaticAberrationPixelShader:"\nuniform sampler2D textureSampler; \n\nuniform float chromatic_aberration;\nuniform float screen_width;\nuniform float screen_height;\n\nvarying vec2 vUV;\nvoid main(void)\n{\nvec2 centered_screen_pos=vec2(vUV.x-0.5,vUV.y-0.5);\nfloat radius2=centered_screen_pos.x*centered_screen_pos.x\n+centered_screen_pos.y*centered_screen_pos.y;\nfloat radius=sqrt(radius2);\nvec4 original=texture2D(textureSampler,vUV);\nif (chromatic_aberration>0.0) {\n\nvec3 ref_indices=vec3(-0.3,0.0,0.3);\nfloat ref_shiftX=chromatic_aberration*radius*17.0/screen_width;\nfloat ref_shiftY=chromatic_aberration*radius*17.0/screen_height;\n\nvec2 ref_coords_r=vec2(vUV.x+ref_indices.r*ref_shiftX,vUV.y+ref_indices.r*ref_shiftY*0.5);\nvec2 ref_coords_g=vec2(vUV.x+ref_indices.g*ref_shiftX,vUV.y+ref_indices.g*ref_shiftY*0.5);\nvec2 ref_coords_b=vec2(vUV.x+ref_indices.b*ref_shiftX,vUV.y+ref_indices.b*ref_shiftY*0.5);\noriginal.r=texture2D(textureSampler,ref_coords_r).r;\noriginal.g=texture2D(textureSampler,ref_coords_g).g;\noriginal.b=texture2D(textureSampler,ref_coords_b).b;\n}\ngl_FragColor=original;\n}",lensHighlightsPixelShader:"\nuniform sampler2D textureSampler; \n\nuniform float gain;\nuniform float threshold;\nuniform float screen_width;\nuniform float screen_height;\n\nvarying vec2 vUV;\n\nvec4 highlightColor(vec4 color) {\nvec4 highlight=color;\nfloat luminance=dot(highlight.rgb,vec3(0.2125,0.7154,0.0721));\nfloat lum_threshold;\nif (threshold>1.0) { lum_threshold=0.94+0.01*threshold; }\nelse { lum_threshold=0.5+0.44*threshold; }\nluminance=clamp((luminance-lum_threshold)*(1.0/(1.0-lum_threshold)),0.0,1.0);\nhighlight*=luminance*gain;\nhighlight.a=1.0;\nreturn highlight;\n}\nvoid main(void)\n{\nvec4 original=texture2D(textureSampler,vUV);\n\nif (gain == -1.0) {\ngl_FragColor=vec4(0.0,0.0,0.0,1.0);\nreturn;\n}\nfloat w=2.0/screen_width;\nfloat h=2.0/screen_height;\nfloat weight=1.0;\n\nvec4 blurred=vec4(0.0,0.0,0.0,0.0);\n#ifdef PENTAGON\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.84*w,0.43*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(0.48*w,-1.29*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(0.61*w,1.51*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.55*w,-0.74*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.71*w,-0.52*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.94*w,1.59*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.40*w,-1.87*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.62*w,1.16*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.09*w,0.25*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.46*w,-1.71*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(0.08*w,2.42*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.85*w,-1.89*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.89*w,0.16*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.29*w,1.88*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(0.40*w,-2.81*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.54*w,2.26*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.60*w,-0.61*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.31*w,-1.30*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.83*w,2.53*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.12*w,-2.48*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.60*w,1.11*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.82*w,0.99*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.50*w,-2.81*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(0.85*w,3.33*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.94*w,-1.92*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(3.27*w,-0.53*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.95*w,2.48*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.23*w,-3.04*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.17*w,2.05*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.97*w,-0.04*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.25*w,-2.00*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.31*w,3.08*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.94*w,-2.59*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(3.37*w,0.64*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-3.13*w,1.93*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.03*w,-3.65*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.60*w,3.17*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-3.14*w,-1.19*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(3.00*w,-1.19*h)));\n#else\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.85*w,0.36*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(0.52*w,-1.14*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(0.46*w,1.42*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.46*w,-0.83*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.79*w,-0.42*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.11*w,1.62*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.29*w,-2.07*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.69*w,1.39*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.28*w,0.12*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.65*w,-1.69*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.08*w,2.44*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.63*w,-1.90*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.55*w,0.31*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.13*w,1.52*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(0.56*w,-2.61*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.38*w,2.34*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.64*w,-0.81*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.53*w,-1.21*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.06*w,2.63*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.00*w,-2.69*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.59*w,1.32*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.82*w,0.78*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.57*w,-2.50*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(0.54*w,2.93*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.39*w,-1.81*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(3.01*w,-0.28*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.04*w,2.25*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.02*w,-3.05*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.09*w,2.25*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-3.07*w,-0.25*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.44*w,-1.90*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.52*w,3.05*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.68*w,-2.61*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(3.01*w,0.79*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.76*w,1.46*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.05*w,-2.94*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.21*w,2.88*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.84*w,-1.30*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.98*w,-0.96*h)));\n#endif\nblurred/=39.0;\ngl_FragColor=blurred;\n\n}",depthOfFieldPixelShader:"\n\n\n\n\nuniform sampler2D textureSampler;\nuniform sampler2D highlightsSampler;\nuniform sampler2D depthSampler;\nuniform sampler2D grainSampler;\n\nuniform float grain_amount;\nuniform bool blur_noise;\nuniform float screen_width;\nuniform float screen_height;\nuniform float distortion;\nuniform bool dof_enabled;\n\nuniform float screen_distance; \nuniform float aperture;\nuniform float darken;\nuniform float edge_blur;\nuniform bool highlights;\n\nuniform float near;\nuniform float far;\n\nvarying vec2 vUV;\n\n#define PI 3.14159265\n#define TWOPI 6.28318530\n#define inverse_focal_length 0.1 \n\nvec2 centered_screen_pos;\nvec2 distorted_coords;\nfloat radius2;\nfloat radius;\n\nvec2 rand(vec2 co)\n{\nfloat noise1=(fract(sin(dot(co,vec2(12.9898,78.233)))*43758.5453));\nfloat noise2=(fract(sin(dot(co,vec2(12.9898,78.233)*2.0))*43758.5453));\nreturn clamp(vec2(noise1,noise2),0.0,1.0);\n}\n\nvec2 getDistortedCoords(vec2 coords) {\nif (distortion == 0.0) { return coords; }\nvec2 direction=1.0*normalize(centered_screen_pos);\nvec2 dist_coords=vec2(0.5,0.5);\ndist_coords.x=0.5+direction.x*radius2*1.0;\ndist_coords.y=0.5+direction.y*radius2*1.0;\nfloat dist_amount=clamp(distortion*0.23,0.0,1.0);\ndist_coords=mix(coords,dist_coords,dist_amount);\nreturn dist_coords;\n}\n\nfloat sampleScreen(inout vec4 color,const in vec2 offset,const in float weight) {\n\nvec2 coords=distorted_coords;\nfloat angle=rand(coords*100.0).x*TWOPI;\ncoords+=vec2(offset.x*cos(angle)-offset.y*sin(angle),offset.x*sin(angle)+offset.y*cos(angle));\ncolor+=texture2D(textureSampler,coords)*weight;\nreturn weight;\n}\n\nfloat getBlurLevel(float size) {\nreturn min(3.0,ceil(size/1.0));\n}\n\nvec4 getBlurColor(float size) {\nvec4 col=texture2D(textureSampler,distorted_coords);\nif (size == 0.0) { return col; }\n\n\nfloat blur_level=getBlurLevel(size);\nfloat w=(size/screen_width);\nfloat h=(size/screen_height);\nfloat total_weight=1.0;\nvec2 sample_coords;\ntotal_weight+=sampleScreen(col,vec2(-0.50*w,0.24*h),0.93);\ntotal_weight+=sampleScreen(col,vec2(0.30*w,-0.75*h),0.90);\ntotal_weight+=sampleScreen(col,vec2(0.36*w,0.96*h),0.87);\ntotal_weight+=sampleScreen(col,vec2(-1.08*w,-0.55*h),0.85);\ntotal_weight+=sampleScreen(col,vec2(1.33*w,-0.37*h),0.83);\ntotal_weight+=sampleScreen(col,vec2(-0.82*w,1.31*h),0.80);\ntotal_weight+=sampleScreen(col,vec2(-0.31*w,-1.67*h),0.78);\ntotal_weight+=sampleScreen(col,vec2(1.47*w,1.11*h),0.76);\ntotal_weight+=sampleScreen(col,vec2(-1.97*w,0.19*h),0.74);\ntotal_weight+=sampleScreen(col,vec2(1.42*w,-1.57*h),0.72);\nif (blur_level>1.0) {\ntotal_weight+=sampleScreen(col,vec2(0.01*w,2.25*h),0.70);\ntotal_weight+=sampleScreen(col,vec2(-1.62*w,-1.74*h),0.67);\ntotal_weight+=sampleScreen(col,vec2(2.49*w,0.20*h),0.65);\ntotal_weight+=sampleScreen(col,vec2(-2.07*w,1.61*h),0.63);\ntotal_weight+=sampleScreen(col,vec2(0.46*w,-2.70*h),0.61);\ntotal_weight+=sampleScreen(col,vec2(1.55*w,2.40*h),0.59);\ntotal_weight+=sampleScreen(col,vec2(-2.88*w,-0.75*h),0.56);\ntotal_weight+=sampleScreen(col,vec2(2.73*w,-1.44*h),0.54);\ntotal_weight+=sampleScreen(col,vec2(-1.08*w,3.02*h),0.52);\ntotal_weight+=sampleScreen(col,vec2(-1.28*w,-3.05*h),0.49);\n}\nif (blur_level>2.0) {\ntotal_weight+=sampleScreen(col,vec2(3.11*w,1.43*h),0.46);\ntotal_weight+=sampleScreen(col,vec2(-3.36*w,1.08*h),0.44);\ntotal_weight+=sampleScreen(col,vec2(1.80*w,-3.16*h),0.41);\ntotal_weight+=sampleScreen(col,vec2(0.83*w,3.65*h),0.38);\ntotal_weight+=sampleScreen(col,vec2(-3.16*w,-2.19*h),0.34);\ntotal_weight+=sampleScreen(col,vec2(3.92*w,-0.53*h),0.31);\ntotal_weight+=sampleScreen(col,vec2(-2.59*w,3.12*h),0.26);\ntotal_weight+=sampleScreen(col,vec2(-0.20*w,-4.15*h),0.22);\ntotal_weight+=sampleScreen(col,vec2(3.02*w,3.00*h),0.15);\n}\ncol/=total_weight; \n\nif (darken>0.0) {\ncol.rgb*=clamp(0.3,1.0,1.05-size*0.5*darken);\n}\n\n\n\n\nreturn col;\n}\nvoid main(void)\n{\n\ncentered_screen_pos=vec2(vUV.x-0.5,vUV.y-0.5);\nradius2=centered_screen_pos.x*centered_screen_pos.x+centered_screen_pos.y*centered_screen_pos.y;\nradius=sqrt(radius2);\ndistorted_coords=getDistortedCoords(vUV); \nvec2 texels_coords=vec2(vUV.x*screen_width,vUV.y*screen_height); \nfloat depth=texture2D(depthSampler,distorted_coords).r; \nfloat distance=near+(far-near)*depth; \nvec4 color=texture2D(textureSampler,vUV); \n\n\nfloat coc=abs(aperture*(screen_distance*(inverse_focal_length-1.0/distance)-1.0));\n\nif (dof_enabled == false || coc<0.07) { coc=0.0; }\n\nfloat edge_blur_amount=0.0;\nif (edge_blur>0.0) {\nedge_blur_amount=clamp((radius*2.0-1.0+0.15*edge_blur)*1.5,0.0,1.0)*1.3;\n}\n\nfloat blur_amount=max(edge_blur_amount,coc);\n\nif (blur_amount == 0.0) {\ngl_FragColor=texture2D(textureSampler,distorted_coords);\n}\nelse {\n\ngl_FragColor=getBlurColor(blur_amount*1.7);\n\nif (highlights) {\ngl_FragColor.rgb+=clamp(coc,0.0,1.0)*texture2D(highlightsSampler,distorted_coords).rgb;\n}\nif (blur_noise) {\n\nvec2 noise=rand(distorted_coords)*0.01*blur_amount;\nvec2 blurred_coord=vec2(distorted_coords.x+noise.x,distorted_coords.y+noise.y);\ngl_FragColor=0.04*texture2D(textureSampler,blurred_coord)+0.96*gl_FragColor;\n}\n}\n\nif (grain_amount>0.0) {\nvec4 grain_color=texture2D(grainSampler,texels_coords*0.003);\ngl_FragColor.rgb+=(-0.5+grain_color.rgb)*0.30*grain_amount;\n}\n}\n",standardPixelShader:"uniform sampler2D textureSampler;\nvarying vec2 vUV;\n#if defined(PASS_POST_PROCESS)\nvoid main(void)\n{\nvec4 color=texture2D(textureSampler,vUV);\ngl_FragColor=color;\n}\n#endif\n#if defined(DOWN_SAMPLE_X4)\nuniform vec2 dsOffsets[16];\nvoid main(void)\n{\nvec4 average=vec4(0.0,0.0,0.0,0.0);\naverage=texture2D(textureSampler,vUV+dsOffsets[0]);\naverage+=texture2D(textureSampler,vUV+dsOffsets[1]);\naverage+=texture2D(textureSampler,vUV+dsOffsets[2]);\naverage+=texture2D(textureSampler,vUV+dsOffsets[3]);\naverage+=texture2D(textureSampler,vUV+dsOffsets[4]);\naverage+=texture2D(textureSampler,vUV+dsOffsets[5]);\naverage+=texture2D(textureSampler,vUV+dsOffsets[6]);\naverage+=texture2D(textureSampler,vUV+dsOffsets[7]);\naverage+=texture2D(textureSampler,vUV+dsOffsets[8]);\naverage+=texture2D(textureSampler,vUV+dsOffsets[9]);\naverage+=texture2D(textureSampler,vUV+dsOffsets[10]);\naverage+=texture2D(textureSampler,vUV+dsOffsets[11]);\naverage+=texture2D(textureSampler,vUV+dsOffsets[12]);\naverage+=texture2D(textureSampler,vUV+dsOffsets[13]);\naverage+=texture2D(textureSampler,vUV+dsOffsets[14]);\naverage+=texture2D(textureSampler,vUV+dsOffsets[15]);\naverage/=16.0;\ngl_FragColor=average;\n}\n#endif\n#if defined(BRIGHT_PASS)\nuniform vec2 dsOffsets[4];\nuniform float brightThreshold;\nvoid main(void)\n{\nvec4 average=vec4(0.0,0.0,0.0,0.0);\naverage=texture2D(textureSampler,vUV+vec2(dsOffsets[0].x,dsOffsets[0].y));\naverage+=texture2D(textureSampler,vUV+vec2(dsOffsets[1].x,dsOffsets[1].y));\naverage+=texture2D(textureSampler,vUV+vec2(dsOffsets[2].x,dsOffsets[2].y));\naverage+=texture2D(textureSampler,vUV+vec2(dsOffsets[3].x,dsOffsets[3].y));\naverage*=0.25;\nfloat luminance=length(average.rgb);\nif (luminance<brightThreshold) {\naverage=vec4(0.0,0.0,0.0,1.0);\n}\ngl_FragColor=average;\n}\n#endif\n#if defined(TEXTURE_ADDER)\nuniform sampler2D otherSampler;\nuniform sampler2D lensSampler;\nuniform float exposure;\nvoid main(void)\n{\nvec3 colour=texture2D(textureSampler,vUV).rgb;\ncolour*=exposure;\nvec3 X=max(vec3(0.0,0.0,0.0),colour-0.004);\nvec3 retColor=(X*(6.2*X+0.5))/(X*(6.2*X+1.7)+0.06);\ncolour=retColor*retColor;\ncolour+=colour*texture2D(lensSampler,vUV).rgb;\nvec4 finalColor=vec4(colour.rgb,1.0)+texture2D(otherSampler,vUV);\ngl_FragColor=finalColor;\n}\n#endif\n#if defined(VLS)\n#define PI 3.1415926535897932384626433832795\nuniform mat4 shadowViewProjection;\nuniform mat4 lightWorld;\nuniform vec3 cameraPosition;\nuniform vec3 sunDirection;\nuniform vec3 sunColor;\nuniform vec2 depthValues;\nuniform float scatteringCoefficient;\nuniform float scatteringPower;\nuniform sampler2D shadowMapSampler;\nuniform sampler2D positionSampler;\nfloat computeScattering(float lightDotView)\n{\nfloat result=1.0-scatteringCoefficient*scatteringCoefficient;\nresult/=(4.0*PI*pow(1.0+scatteringCoefficient*scatteringCoefficient-(2.0*scatteringCoefficient)*lightDotView,1.5));\nreturn result;\n}\nvoid main(void)\n{\n\nvec3 worldPos=texture2D(positionSampler,vUV).rgb;\nvec3 startPosition=cameraPosition;\nvec3 rayVector=worldPos-startPosition;\nfloat rayLength=length(rayVector);\nvec3 rayDirection=rayVector/rayLength;\nfloat stepLength=rayLength/NB_STEPS;\nvec3 stepL=rayDirection*stepLength;\nvec3 currentPosition=startPosition;\nvec3 accumFog=vec3(0.0);\nfor (int i=0; i<int(NB_STEPS); i++)\n{\nvec4 worldInShadowCameraSpace=shadowViewProjection*vec4(currentPosition,1.0);\nfloat depthMetric=(worldInShadowCameraSpace.z+depthValues.x)/(depthValues.y);\nfloat shadowPixelDepth=clamp(depthMetric,0.0,1.0);\nworldInShadowCameraSpace.xyz/=worldInShadowCameraSpace.w;\nworldInShadowCameraSpace.xyz=0.5*worldInShadowCameraSpace.xyz+vec3(0.5);\nfloat shadowMapValue=texture2D(shadowMapSampler,worldInShadowCameraSpace.xy).r;\nif (shadowMapValue>shadowPixelDepth)\naccumFog+=sunColor*computeScattering(dot(rayDirection,sunDirection));\ncurrentPosition+=stepL;\n}\naccumFog/=NB_STEPS;\nvec3 color=accumFog*scatteringPower;\ngl_FragColor=vec4(color*exp(color) ,1.0);\n}\n#endif\n#if defined(VLSMERGE)\nuniform sampler2D originalSampler;\nvoid main(void)\n{\ngl_FragColor=texture2D(originalSampler,vUV)+texture2D(textureSampler,vUV);\n}\n#endif\n#if defined(LUMINANCE)\nuniform vec2 lumOffsets[4];\nvoid main()\n{\nfloat average=0.0;\nvec4 color=vec4(0.0);\nfloat maximum=-1e20;\nvec3 weight=vec3(0.299,0.587,0.114);\nfor (int i=0; i<4; i++)\n{\ncolor=texture2D(textureSampler,vUV+ lumOffsets[i]);\n\nfloat GreyValue=dot(color.rgb,vec3(0.33,0.33,0.33));\n\n#ifdef WEIGHTED_AVERAGE\nfloat GreyValue=dot(color.rgb,weight);\n#endif\n#ifdef BRIGHTNESS\nfloat GreyValue=max(color.r,max(color.g,color.b));\n#endif\n#ifdef HSL_COMPONENT\nfloat GreyValue=0.5*(max(color.r,max(color.g,color.b))+min(color.r,min(color.g,color.b)));\n#endif\n#ifdef MAGNITUDE\nfloat GreyValue=length(color.rgb);\n#endif\nmaximum=max(maximum,GreyValue);\naverage+=(0.25*log(1e-5+GreyValue));\n}\naverage=exp(average);\ngl_FragColor=vec4(average,maximum,0.0,1.0);\n}\n#endif\n#if defined(LUMINANCE_DOWN_SAMPLE)\nuniform vec2 dsOffsets[9];\nuniform float halfDestPixelSize;\n#ifdef FINAL_DOWN_SAMPLER\nvec4 pack(float value) {\nconst vec4 bit_shift=vec4(255.0*255.0*255.0,255.0*255.0,255.0,1.0);\nconst vec4 bit_mask=vec4(0.0,1.0/255.0,1.0/255.0,1.0/255.0);\nvec4 res=fract(value*bit_shift);\nres-=res.xxyz*bit_mask;\nreturn res;\n}\n#endif\nvoid main()\n{\nvec4 color=vec4(0.0);\nfloat average=0.0;\nfor (int i=0; i<9; i++)\n{\ncolor=texture2D(textureSampler,vUV+vec2(halfDestPixelSize,halfDestPixelSize)+dsOffsets[i]);\naverage+=color.r;\n}\naverage/=9.0;\n#ifdef FINAL_DOWN_SAMPLER\ngl_FragColor=pack(average);\n#else\ngl_FragColor=vec4(average,average,0.0,1.0);\n#endif\n}\n#endif\n#if defined(HDR)\nuniform sampler2D textureAdderSampler;\nuniform float averageLuminance;\nvoid main()\n{\nvec4 color=texture2D(textureAdderSampler,vUV);\nvec4 adjustedColor=color/averageLuminance;\ncolor=adjustedColor;\ncolor.a=1.0;\ngl_FragColor=color;\n}\n#endif\n#if defined(LENS_FLARE)\n#define GHOSTS 3\nuniform sampler2D lensColorSampler;\nuniform float strength;\nuniform float ghostDispersal;\nuniform float haloWidth;\nuniform vec2 resolution;\nuniform float distortionStrength;\nfloat hash(vec2 p)\n{\nfloat h=dot(p,vec2(127.1,311.7));\nreturn -1.0+2.0*fract(sin(h)*43758.5453123);\n}\nfloat noise(in vec2 p)\n{\nvec2 i=floor(p);\nvec2 f=fract(p);\nvec2 u=f*f*(3.0-2.0*f);\nreturn mix(mix(hash(i+vec2(0.0,0.0)),\nhash(i+vec2(1.0,0.0)),u.x),\nmix(hash(i+vec2(0.0,1.0)),\nhash(i+vec2(1.0,1.0)),u.x),u.y);\n}\nfloat fbm(vec2 p)\n{\nfloat f=0.0;\nf+=0.5000*noise(p); p*=2.02;\nf+=0.2500*noise(p); p*=2.03;\nf+=0.1250*noise(p); p*=2.01;\nf+=0.0625*noise(p); p*=2.04;\nf/=0.9375;\nreturn f;\n}\nvec3 pattern(vec2 uv)\n{\nvec2 p=-1.0+2.0*uv;\nfloat p2=dot(p,p);\nfloat f=fbm(vec2(15.0*p2))/2.0;\nfloat r=0.2+0.6*sin(12.5*length(uv-vec2(0.5)));\nfloat g=0.2+0.6*sin(20.5*length(uv-vec2(0.5)));\nfloat b=0.2+0.6*sin(17.2*length(uv-vec2(0.5)));\nreturn (1.0-f)*vec3(r,g,b);\n}\nfloat luminance(vec3 color)\n{\nreturn dot(color.rgb,vec3(0.2126,0.7152,0.0722));\n}\nvec4 textureDistorted(sampler2D tex,vec2 texcoord,vec2 direction,vec3 distortion)\n{\nreturn vec4(\ntexture2D(tex,texcoord+direction*distortion.r).r,\ntexture2D(tex,texcoord+direction*distortion.g).g,\ntexture2D(tex,texcoord+direction*distortion.b).b,\n1.0\n);\n}\nvoid main(void)\n{\nvec2 uv=-vUV+vec2(1.0);\nvec2 ghostDir=(vec2(0.5)-uv)*ghostDispersal;\nvec2 texelSize=1.0/resolution;\nvec3 distortion=vec3(-texelSize.x*distortionStrength,0.0,texelSize.x*distortionStrength);\nvec4 result=vec4(0.0);\nfloat ghostIndice=1.0;\nfor (int i=0; i<GHOSTS; ++i)\n{\nvec2 offset=fract(uv+ghostDir*ghostIndice);\nfloat weight=length(vec2(0.5)-offset)/length(vec2(0.5));\nweight=pow(1.0-weight,10.0);\nresult+=textureDistorted(textureSampler,offset,normalize(ghostDir),distortion)*weight*strength;\nghostIndice+=1.0;\n}\nvec2 haloVec=normalize(ghostDir)*haloWidth;\nfloat weight=length(vec2(0.5)-fract(uv+haloVec))/length(vec2(0.5));\nweight=pow(1.0-weight,10.0);\nresult+=textureDistorted(textureSampler,fract(uv+haloVec),normalize(ghostDir),distortion)*weight*strength;\nresult*=texture2D(lensColorSampler,vec2(length(vec2(0.5)-uv)/length(vec2(0.5))));\ngl_FragColor=result;\n}\n#endif\n#if defined(LENS_FLARE_COMPOSE)\nuniform sampler2D otherSampler;\nuniform sampler2D lensDirtSampler;\nuniform sampler2D lensStarSampler;\nuniform mat4 lensStarMatrix;\nvoid main(void)\n{\nvec2 lensFlareCoords=(lensStarMatrix*vec4(vUV,1.0,1.0)).xy;\nvec4 lensMod=texture2D(lensDirtSampler,vUV);\nlensMod+=texture2D(lensStarSampler,vUV);\nvec4 result=texture2D(textureSampler,vUV)*lensMod;\ngl_FragColor=texture2D(otherSampler,vUV)+result;\n}\n#endif\n#if defined(DEPTH_OF_FIELD)\nuniform sampler2D otherSampler;\nuniform sampler2D depthSampler;\nuniform float distance;\nvoid main(void)\n{\nvec4 sharp=texture2D(otherSampler,vUV);\nvec4 blur=texture2D(textureSampler,vUV);\nfloat dist=clamp(texture2D(depthSampler,vUV).r*distance,0.0,1.0);\nfloat factor=0.0;\nif (dist<0.05)\nfactor=1.0;\nelse if (dist<0.1)\nfactor=20.0*(0.1-dist);\nelse if (dist<0.5)\nfactor=0.0;\nelse\nfactor=2.0*(dist-0.5);\nfactor=clamp(factor,0.0,0.90);\ngl_FragColor=mix(sharp,blur,factor);\n}\n#endif\n#if defined(MOTION_BLUR)\nuniform mat4 inverseViewProjection;\nuniform mat4 prevViewProjection;\nuniform vec2 screenSize;\nuniform float motionScale;\nuniform float motionStrength;\nuniform sampler2D depthSampler;\nvoid main(void)\n{\nvec2 texelSize=1.0/screenSize;\nfloat depth=texture2D(depthSampler,vUV).r;\nvec4 cpos=vec4(vUV*2.0-1.0,depth,1.0);\ncpos=cpos*inverseViewProjection;\nvec4 ppos=cpos*prevViewProjection;\nppos.xyz/=ppos.w;\nppos.xy=ppos.xy*0.5+0.5;\nvec2 velocity=(ppos.xy-vUV)*motionScale*motionStrength;\nfloat speed=length(velocity/texelSize);\nint nSamples=int(clamp(speed,1.0,MAX_MOTION_SAMPLES));\nvec4 result=texture2D(textureSampler,vUV);\nfor (int i=1; i<int(MAX_MOTION_SAMPLES); ++i) {\nif (i>=nSamples)\nbreak;\nvec2 offset1=vUV+velocity*(float(i)/float(nSamples-1)-0.5);\nresult+=texture2D(textureSampler,offset1);\n}\ngl_FragColor=result/float(nSamples);\n}\n#endif\n",fxaaVertexShader:"\nattribute vec2 position;\nuniform vec2 texelSize;\n\nvarying vec2 vUV;\nvarying vec2 sampleCoordS;\nvarying vec2 sampleCoordE;\nvarying vec2 sampleCoordN;\nvarying vec2 sampleCoordW;\nvarying vec2 sampleCoordNW;\nvarying vec2 sampleCoordSE;\nvarying vec2 sampleCoordNE;\nvarying vec2 sampleCoordSW;\nconst vec2 madd=vec2(0.5,0.5);\nvoid main(void) { \nvUV=(position*madd+madd);\nsampleCoordS=vUV+vec2( 0.0,1.0)*texelSize;\nsampleCoordE=vUV+vec2( 1.0,0.0)*texelSize;\nsampleCoordN=vUV+vec2( 0.0,-1.0)*texelSize;\nsampleCoordW=vUV+vec2(-1.0,0.0)*texelSize;\nsampleCoordNW=vUV+vec2(-1.0,-1.0)*texelSize;\nsampleCoordSE=vUV+vec2( 1.0,1.0)*texelSize;\nsampleCoordNE=vUV+vec2( 1.0,-1.0)*texelSize;\nsampleCoordSW=vUV+vec2(-1.0,1.0)*texelSize;\ngl_Position=vec4(position,0.0,1.0);\n}",fxaaPixelShader:"uniform sampler2D textureSampler;\nuniform vec2 texelSize;\nvarying vec2 vUV;\nvarying vec2 sampleCoordS;\nvarying vec2 sampleCoordE;\nvarying vec2 sampleCoordN;\nvarying vec2 sampleCoordW;\nvarying vec2 sampleCoordNW;\nvarying vec2 sampleCoordSE;\nvarying vec2 sampleCoordNE;\nvarying vec2 sampleCoordSW;\nconst float fxaaQualitySubpix=1.0;\nconst float fxaaQualityEdgeThreshold=0.166;\nconst float fxaaQualityEdgeThresholdMin=0.0833;\nconst vec3 kLumaCoefficients=vec3(0.2126,0.7152,0.0722);\n#define FxaaLuma(rgba) dot(rgba.rgb,kLumaCoefficients)\nvoid main(){\nvec2 posM;\nposM.x=vUV.x;\nposM.y=vUV.y;\nvec4 rgbyM=texture2D(textureSampler,vUV,0.0);\nfloat lumaM=FxaaLuma(rgbyM);\nfloat lumaS=FxaaLuma(texture2D(textureSampler,sampleCoordS,0.0));\nfloat lumaE=FxaaLuma(texture2D(textureSampler,sampleCoordE,0.0));\nfloat lumaN=FxaaLuma(texture2D(textureSampler,sampleCoordN,0.0));\nfloat lumaW=FxaaLuma(texture2D(textureSampler,sampleCoordW,0.0));\nfloat maxSM=max(lumaS,lumaM);\nfloat minSM=min(lumaS,lumaM);\nfloat maxESM=max(lumaE,maxSM);\nfloat minESM=min(lumaE,minSM);\nfloat maxWN=max(lumaN,lumaW);\nfloat minWN=min(lumaN,lumaW);\nfloat rangeMax=max(maxWN,maxESM);\nfloat rangeMin=min(minWN,minESM);\nfloat rangeMaxScaled=rangeMax*fxaaQualityEdgeThreshold;\nfloat range=rangeMax-rangeMin;\nfloat rangeMaxClamped=max(fxaaQualityEdgeThresholdMin,rangeMaxScaled);\nif(range<rangeMaxClamped) \n{\ngl_FragColor=rgbyM;\nreturn;\n}\nfloat lumaNW=FxaaLuma(texture2D(textureSampler,sampleCoordNW,0.0));\nfloat lumaSE=FxaaLuma(texture2D(textureSampler,sampleCoordSE,0.0));\nfloat lumaNE=FxaaLuma(texture2D(textureSampler,sampleCoordNE,0.0));\nfloat lumaSW=FxaaLuma(texture2D(textureSampler,sampleCoordSW,0.0));\nfloat lumaNS=lumaN+lumaS;\nfloat lumaWE=lumaW+lumaE;\nfloat subpixRcpRange=1.0/range;\nfloat subpixNSWE=lumaNS+lumaWE;\nfloat edgeHorz1=(-2.0*lumaM)+lumaNS;\nfloat edgeVert1=(-2.0*lumaM)+lumaWE;\nfloat lumaNESE=lumaNE+lumaSE;\nfloat lumaNWNE=lumaNW+lumaNE;\nfloat edgeHorz2=(-2.0*lumaE)+lumaNESE;\nfloat edgeVert2=(-2.0*lumaN)+lumaNWNE;\nfloat lumaNWSW=lumaNW+lumaSW;\nfloat lumaSWSE=lumaSW+lumaSE;\nfloat edgeHorz4=(abs(edgeHorz1)*2.0)+abs(edgeHorz2);\nfloat edgeVert4=(abs(edgeVert1)*2.0)+abs(edgeVert2);\nfloat edgeHorz3=(-2.0*lumaW)+lumaNWSW;\nfloat edgeVert3=(-2.0*lumaS)+lumaSWSE;\nfloat edgeHorz=abs(edgeHorz3)+edgeHorz4;\nfloat edgeVert=abs(edgeVert3)+edgeVert4;\nfloat subpixNWSWNESE=lumaNWSW+lumaNESE;\nfloat lengthSign=texelSize.x;\nbool horzSpan=edgeHorz>=edgeVert;\nfloat subpixA=subpixNSWE*2.0+subpixNWSWNESE;\nif (!horzSpan)\n{\nlumaN=lumaW;\n}\nif (!horzSpan) \n{\nlumaS=lumaE;\n}\nif (horzSpan) \n{\nlengthSign=texelSize.y;\n}\nfloat subpixB=(subpixA*(1.0/12.0))-lumaM;\nfloat gradientN=lumaN-lumaM;\nfloat gradientS=lumaS-lumaM;\nfloat lumaNN=lumaN+lumaM;\nfloat lumaSS=lumaS+lumaM;\nbool pairN=abs(gradientN)>=abs(gradientS);\nfloat gradient=max(abs(gradientN),abs(gradientS));\nif (pairN)\n{\nlengthSign=-lengthSign;\n}\nfloat subpixC=clamp(abs(subpixB)*subpixRcpRange,0.0,1.0);\nvec2 posB;\nposB.x=posM.x;\nposB.y=posM.y;\nvec2 offNP;\noffNP.x=(!horzSpan) ? 0.0 : texelSize.x;\noffNP.y=(horzSpan) ? 0.0 : texelSize.y;\nif (!horzSpan) \n{\nposB.x+=lengthSign*0.5;\n}\nif (horzSpan)\n{\nposB.y+=lengthSign*0.5;\n}\nvec2 posN;\nposN.x=posB.x-offNP.x*1.5;\nposN.y=posB.y-offNP.y*1.5;\nvec2 posP;\nposP.x=posB.x+offNP.x*1.5;\nposP.y=posB.y+offNP.y*1.5;\nfloat subpixD=((-2.0)*subpixC)+3.0;\nfloat lumaEndN=FxaaLuma(texture2D(textureSampler,posN,0.0));\nfloat subpixE=subpixC*subpixC;\nfloat lumaEndP=FxaaLuma(texture2D(textureSampler,posP,0.0));\nif (!pairN) \n{\nlumaNN=lumaSS;\n}\nfloat gradientScaled=gradient*1.0/4.0;\nfloat lumaMM=lumaM-lumaNN*0.5;\nfloat subpixF=subpixD*subpixE;\nbool lumaMLTZero=lumaMM<0.0;\nlumaEndN-=lumaNN*0.5;\nlumaEndP-=lumaNN*0.5;\nbool doneN=abs(lumaEndN)>=gradientScaled;\nbool doneP=abs(lumaEndP)>=gradientScaled;\nif (!doneN) \n{\nposN.x-=offNP.x*3.0;\n}\nif (!doneN) \n{\nposN.y-=offNP.y*3.0;\n}\nbool doneNP=(!doneN) || (!doneP);\nif (!doneP) \n{\nposP.x+=offNP.x*3.0;\n}\nif (!doneP)\n{\nposP.y+=offNP.y*3.0;\n}\nif (doneNP)\n{\nif (!doneN) lumaEndN=FxaaLuma(texture2D(textureSampler,posN.xy,0.0));\nif (!doneP) lumaEndP=FxaaLuma(texture2D(textureSampler,posP.xy,0.0));\nif (!doneN) lumaEndN=lumaEndN-lumaNN*0.5;\nif (!doneP) lumaEndP=lumaEndP-lumaNN*0.5;\ndoneN=abs(lumaEndN)>=gradientScaled;\ndoneP=abs(lumaEndP)>=gradientScaled;\nif (!doneN) posN.x-=offNP.x*12.0;\nif (!doneN) posN.y-=offNP.y*12.0;\ndoneNP=(!doneN) || (!doneP);\nif (!doneP) posP.x+=offNP.x*12.0;\nif (!doneP) posP.y+=offNP.y*12.0;\n}\nfloat dstN=posM.x-posN.x;\nfloat dstP=posP.x-posM.x;\nif (!horzSpan)\n{\ndstN=posM.y-posN.y;\n}\nif (!horzSpan) \n{\ndstP=posP.y-posM.y;\n}\nbool goodSpanN=(lumaEndN<0.0) != lumaMLTZero;\nfloat spanLength=(dstP+dstN);\nbool goodSpanP=(lumaEndP<0.0) != lumaMLTZero;\nfloat spanLengthRcp=1.0/spanLength;\nbool directionN=dstN<dstP;\nfloat dst=min(dstN,dstP);\nbool goodSpan=directionN ? goodSpanN : goodSpanP;\nfloat subpixG=subpixF*subpixF;\nfloat pixelOffset=(dst*(-spanLengthRcp))+0.5;\nfloat subpixH=subpixG*fxaaQualitySubpix;\nfloat pixelOffsetGood=goodSpan ? pixelOffset : 0.0;\nfloat pixelOffsetSubpix=max(pixelOffsetGood,subpixH);\nif (!horzSpan)\n{\nposM.x+=pixelOffsetSubpix*lengthSign;\n}\nif (horzSpan)\n{\nposM.y+=pixelOffsetSubpix*lengthSign;\n}\ngl_FragColor=texture2D(textureSampler,posM,0.0);\n}",geometryVertexShader:"precision highp float;\nprecision highp int;\n#include<bonesDeclaration>\n#include<instancesDeclaration>\nattribute vec3 position;\nattribute vec3 normal;\n#if defined(ALPHATEST) || defined(NEED_UV)\nvarying vec2 vUV;\nuniform mat4 diffuseMatrix;\n#ifdef UV1\nvarying vec2 uv;\n#endif\n#ifdef UV2\nvarying vec2 uv2;\n#endif\n#endif\n\nuniform mat4 viewProjection;\nuniform mat4 view;\nvarying vec3 vNormalV;\nvarying vec4 vViewPos;\n#ifdef POSITION\nvarying vec3 vPosition;\n#endif\nvoid main(void)\n{\n#include<instancesVertex>\n#include<bonesVertex>\nvec4 pos=vec4(finalWorld*vec4(position,1.0));\nvNormalV=normalize(vec3((view*finalWorld)*vec4(normal,0.0)));\nvViewPos=view*pos;\n#ifdef POSITION\nvPosition=pos.xyz/pos.w;\n#endif\ngl_Position=viewProjection*finalWorld*vec4(position,1.0);\n#if defined(ALPHATEST) || defined(BASIC_RENDER)\n#ifdef UV1\nvUV=vec2(diffuseMatrix*vec4(uv,1.0,0.0));\n#endif\n#ifdef UV2\nvUV=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));\n#endif\n#endif\n}",geometryPixelShader:"#extension GL_EXT_draw_buffers : require\nprecision highp float;\nprecision highp int;\nvarying vec3 vNormalV;\nvarying vec4 vViewPos;\n#ifdef POSITION\nvarying vec3 vPosition;\n#endif\n#ifdef ALPHATEST\nvarying vec2 vUV;\nuniform sampler2D diffuseSampler;\n#endif\n#ifdef POSITION\n#include<mrtFragmentDeclaration>[3]\n#else\n#include<mrtFragmentDeclaration>[2]\n#endif\nvoid main() {\n#ifdef ALPHATEST\nif (texture2D(diffuseSampler,vUV).a<0.4)\ndiscard;\n#endif\ngl_FragData[0]=vec4(vViewPos.z/vViewPos.w,0.0,0.0,1.0);\n\ngl_FragData[1]=vec4(normalize(vNormalV),1.0);\n\n#ifdef POSITION\ngl_FragData[2]=vec4(vPosition,1.0);\n#endif\n}",refractionPixelShader:"\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\nuniform sampler2D refractionSampler;\n\nuniform vec3 baseColor;\nuniform float depth;\nuniform float colorLevel;\nvoid main() {\nfloat ref=1.0-texture2D(refractionSampler,vUV).r;\nvec2 uv=vUV-vec2(0.5);\nvec2 offset=uv*depth*ref;\nvec3 sourceColor=texture2D(textureSampler,vUV-offset).rgb;\ngl_FragColor=vec4(sourceColor+sourceColor*ref*colorLevel,1.0);\n}",blackAndWhitePixelShader:"\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\nuniform float degree;\nvoid main(void) \n{\nvec3 color=texture2D(textureSampler,vUV).rgb;\nfloat luminance=dot(color,vec3(0.3,0.59,0.11)); \nvec3 blackAndWhite=vec3(luminance,luminance,luminance);\ngl_FragColor=vec4(color-((color-blackAndWhite)*degree),1.0);\n}",convolutionPixelShader:"\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\nuniform vec2 screenSize;\nuniform float kernel[9];\nvoid main(void)\n{\nvec2 onePixel=vec2(1.0,1.0)/screenSize;\nvec4 colorSum =\ntexture2D(textureSampler,vUV+onePixel*vec2(-1,-1))*kernel[0] +\ntexture2D(textureSampler,vUV+onePixel*vec2(0,-1))*kernel[1] +\ntexture2D(textureSampler,vUV+onePixel*vec2(1,-1))*kernel[2] +\ntexture2D(textureSampler,vUV+onePixel*vec2(-1,0))*kernel[3] +\ntexture2D(textureSampler,vUV+onePixel*vec2(0,0))*kernel[4] +\ntexture2D(textureSampler,vUV+onePixel*vec2(1,0))*kernel[5] +\ntexture2D(textureSampler,vUV+onePixel*vec2(-1,1))*kernel[6] +\ntexture2D(textureSampler,vUV+onePixel*vec2(0,1))*kernel[7] +\ntexture2D(textureSampler,vUV+onePixel*vec2(1,1))*kernel[8];\nfloat kernelWeight =\nkernel[0] +\nkernel[1] +\nkernel[2] +\nkernel[3] +\nkernel[4] +\nkernel[5] +\nkernel[6] +\nkernel[7] +\nkernel[8];\nif (kernelWeight<=0.0) {\nkernelWeight=1.0;\n}\ngl_FragColor=vec4((colorSum/kernelWeight).rgb,1);\n}",filterPixelShader:"\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\nuniform mat4 kernelMatrix;\nvoid main(void)\n{\nvec3 baseColor=texture2D(textureSampler,vUV).rgb;\nvec3 updatedColor=(kernelMatrix*vec4(baseColor,1.0)).rgb;\ngl_FragColor=vec4(updatedColor,1.0);\n}",volumetricLightScatteringPixelShader:"uniform sampler2D textureSampler;\nuniform sampler2D lightScatteringSampler;\nuniform float decay;\nuniform float exposure;\nuniform float weight;\nuniform float density;\nuniform vec2 meshPositionOnScreen;\nvarying vec2 vUV;\nvoid main(void) {\nvec2 tc=vUV;\nvec2 deltaTexCoord=(tc-meshPositionOnScreen.xy);\ndeltaTexCoord*=1.0/float(NUM_SAMPLES)*density;\nfloat illuminationDecay=1.0;\nvec4 color=texture2D(lightScatteringSampler,tc)*0.4;\nfor(int i=0; i<NUM_SAMPLES; i++) {\ntc-=deltaTexCoord;\nvec4 dataSample=texture2D(lightScatteringSampler,tc)*0.4;\ndataSample*=illuminationDecay*weight;\ncolor+=dataSample;\nilluminationDecay*=decay;\n}\nvec4 realColor=texture2D(textureSampler,vUV);\ngl_FragColor=((vec4((vec3(color.r,color.g,color.b)*exposure),1))+(realColor*(1.5-0.4)));\n}\n",volumetricLightScatteringPassPixelShader:"#if defined(ALPHATEST) || defined(NEED_UV)\nvarying vec2 vUV;\n#endif\n#if defined(ALPHATEST)\nuniform sampler2D diffuseSampler;\n#endif\nvoid main(void)\n{\n#if defined(ALPHATEST)\nvec4 diffuseColor=texture2D(diffuseSampler,vUV);\nif (diffuseColor.a<0.4)\ndiscard;\n#endif\ngl_FragColor=vec4(0.0,0.0,0.0,1.0);\n}\n",colorCorrectionPixelShader:"\nuniform sampler2D textureSampler; \nuniform sampler2D colorTable; \n\nvarying vec2 vUV;\n\nconst float SLICE_COUNT=16.0; \n\nvec4 sampleAs3DTexture(sampler2D textureSampler,vec3 uv,float width) {\nfloat sliceSize=1.0/width; \nfloat slicePixelSize=sliceSize/width; \nfloat sliceInnerSize=slicePixelSize*(width-1.0); \nfloat zSlice0=min(floor(uv.z*width),width-1.0);\nfloat zSlice1=min(zSlice0+1.0,width-1.0);\nfloat xOffset=slicePixelSize*0.5+uv.x*sliceInnerSize;\nfloat s0=xOffset+(zSlice0*sliceSize);\nfloat s1=xOffset+(zSlice1*sliceSize);\nvec4 slice0Color=texture2D(textureSampler,vec2(s0,uv.y));\nvec4 slice1Color=texture2D(textureSampler,vec2(s1,uv.y));\nfloat zOffset=mod(uv.z*width,1.0);\nvec4 result=mix(slice0Color,slice1Color,zOffset);\nreturn result;\n}\nvoid main(void)\n{\nvec4 screen_color=texture2D(textureSampler,vUV);\ngl_FragColor=sampleAs3DTexture(colorTable,screen_color.rgb,SLICE_COUNT);\n}",tonemapPixelShader:"\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\n\nuniform float _ExposureAdjustment;\n#if defined(HABLE_TONEMAPPING)\nconst float A=0.15;\nconst float B=0.50;\nconst float C=0.10;\nconst float D=0.20;\nconst float E=0.02;\nconst float F=0.30;\nconst float W=11.2;\n#endif\nfloat Luminance(vec3 c)\n{\nreturn dot(c,vec3(0.22,0.707,0.071));\n}\nvoid main(void) \n{\nvec3 colour=texture2D(textureSampler,vUV).rgb;\n#if defined(REINHARD_TONEMAPPING)\nfloat lum=Luminance(colour.rgb); \nfloat lumTm=lum*_ExposureAdjustment;\nfloat scale=lumTm/(1.0+lumTm); \ncolour*=scale/lum;\n#elif defined(HABLE_TONEMAPPING)\ncolour*=_ExposureAdjustment;\nconst float ExposureBias=2.0;\nvec3 x=ExposureBias*colour;\nvec3 curr=((x*(A*x+C*B)+D*E)/(x*(A*x+B)+D*F))-E/F;\nx=vec3(W,W,W);\nvec3 whiteScale=1.0/(((x*(A*x+C*B)+D*E)/(x*(A*x+B)+D*F))-E/F);\ncolour=curr*whiteScale;\n#elif defined(OPTIMIZED_HEJIDAWSON_TONEMAPPING)\ncolour*=_ExposureAdjustment;\nvec3 X=max(vec3(0.0,0.0,0.0),colour-0.004);\nvec3 retColor=(X*(6.2*X+0.5))/(X*(6.2*X+1.7)+0.06);\ncolour=retColor*retColor;\n#elif defined(PHOTOGRAPHIC_TONEMAPPING)\ncolour=vec3(1.0,1.0,1.0)-exp2(-_ExposureAdjustment*colour);\n#endif\ngl_FragColor=vec4(colour.rgb,1.0);\n}",displayPassPixelShader:"\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\nuniform sampler2D passSampler;\nvoid main(void)\n{\ngl_FragColor=texture2D(passSampler,vUV);\n}",highlightsPixelShader:"\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\nconst vec3 RGBLuminanceCoefficients=vec3(0.2126,0.7152,0.0722);\nvoid main(void) \n{\nvec4 tex=texture2D(textureSampler,vUV);\nvec3 c=tex.rgb;\nfloat luma=dot(c.rgb,RGBLuminanceCoefficients);\n\n\ngl_FragColor=vec4(pow(c,vec3(25.0-luma*15.0)),tex.a); \n}",imageProcessingPixelShader:"\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\n#include<imageProcessingDeclaration>\n#include<helperFunctions>\n#include<imageProcessingFunctions>\nvoid main(void)\n{\nvec4 result=texture2D(textureSampler,vUV);\n#ifdef IMAGEPROCESSING\n#ifndef FROMLINEARSPACE\n\nresult.rgb=toLinearSpace(result.rgb);\n#endif\nresult=applyImageProcessing(result);\n#else\n\n#ifdef FROMLINEARSPACE\nresult=applyImageProcessing(result);\n#endif\n#endif\ngl_FragColor=result;\n}",kernelBlurVertexShader:"\nattribute vec2 position;\n\nuniform vec2 delta;\n\nvarying vec2 sampleCenter;\n#include<kernelBlurVaryingDeclaration>[0..varyingCount]\nconst vec2 madd=vec2(0.5,0.5);\nvoid main(void) { \nsampleCenter=(position*madd+madd);\n#include<kernelBlurVertex>[0..varyingCount]\ngl_Position=vec4(position,0.0,1.0);\n}",kernelBlurPixelShader:"\nuniform sampler2D textureSampler;\nuniform vec2 delta;\n\nvarying vec2 sampleCenter;\n#include<kernelBlurVaryingDeclaration>[0..varyingCount]\n#ifdef PACKEDFLOAT\nvec4 pack(float depth)\n{\nconst vec4 bit_shift=vec4(255.0*255.0*255.0,255.0*255.0,255.0,1.0);\nconst vec4 bit_mask=vec4(0.0,1.0/255.0,1.0/255.0,1.0/255.0);\nvec4 res=fract(depth*bit_shift);\nres-=res.xxyz*bit_mask;\nreturn res;\n}\nfloat unpack(vec4 color)\n{\nconst vec4 bit_shift=vec4(1.0/(255.0*255.0*255.0),1.0/(255.0*255.0),1.0/255.0,1.0);\nreturn dot(color,bit_shift);\n}\n#endif\nvoid main(void)\n{\n#ifdef PACKEDFLOAT \nfloat blend=0.;\n#else\nvec4 blend=vec4(0.);\n#endif\n#include<kernelBlurFragment>[0..varyingCount]\n#include<kernelBlurFragment2>[0..depCount]\n#ifdef PACKEDFLOAT\ngl_FragColor=pack(blend);\n#else\ngl_FragColor=blend;\n#endif\n}",lensFlareVertexShader:"\nattribute vec2 position;\n\nuniform mat4 viewportMatrix;\n\nvarying vec2 vUV;\nconst vec2 madd=vec2(0.5,0.5);\nvoid main(void) { \nvUV=position*madd+madd;\ngl_Position=viewportMatrix*vec4(position,0.0,1.0);\n}",lensFlarePixelShader:"\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\n\nuniform vec4 color;\nvoid main(void) {\nvec4 baseColor=texture2D(textureSampler,vUV);\ngl_FragColor=baseColor*color;\n}",anaglyphPixelShader:"\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\nuniform sampler2D leftSampler;\nvoid main(void)\n{\nvec4 leftFrag=texture2D(leftSampler,vUV);\nleftFrag=vec4(1.0,leftFrag.g,leftFrag.b,1.0);\nvec4 rightFrag=texture2D(textureSampler,vUV);\nrightFrag=vec4(rightFrag.r,1.0,1.0,1.0);\ngl_FragColor=vec4(rightFrag.rgb*leftFrag.rgb,1.0);\n}",stereoscopicInterlacePixelShader:"const vec3 TWO=vec3(2.0,2.0,2.0);\nvarying vec2 vUV;\nuniform sampler2D camASampler;\nuniform sampler2D textureSampler;\nuniform vec2 stepSize;\nvoid main(void)\n{\nbool useCamB;\nvec2 texCoord1;\nvec2 texCoord2;\nvec3 frag1;\nvec3 frag2;\n#ifdef IS_STEREOSCOPIC_HORIZ\nuseCamB=vUV.x>0.5;\ntexCoord1=vec2(useCamB ? (vUV.x-0.5)*2.0 : vUV.x*2.0,vUV.y);\ntexCoord2=vec2(texCoord1.x+stepSize.x,vUV.y);\n#else\nuseCamB=vUV.y>0.5;\ntexCoord1=vec2(vUV.x,useCamB ? (vUV.y-0.5)*2.0 : vUV.y*2.0);\ntexCoord2=vec2(vUV.x,texCoord1.y+stepSize.y);\n#endif\n\nif (useCamB){\nfrag1=texture2D(textureSampler,texCoord1).rgb;\nfrag2=texture2D(textureSampler,texCoord2).rgb;\n}else{\nfrag1=texture2D(camASampler ,texCoord1).rgb;\nfrag2=texture2D(camASampler ,texCoord2).rgb;\n}\ngl_FragColor=vec4((frag1+frag2)/TWO,1.0);\n}",vrDistortionCorrectionPixelShader:"\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\nuniform vec2 LensCenter;\nuniform vec2 Scale;\nuniform vec2 ScaleIn;\nuniform vec4 HmdWarpParam;\nvec2 HmdWarp(vec2 in01) {\nvec2 theta=(in01-LensCenter)*ScaleIn; \nfloat rSq=theta.x*theta.x+theta.y*theta.y;\nvec2 rvector=theta*(HmdWarpParam.x+HmdWarpParam.y*rSq+HmdWarpParam.z*rSq*rSq+HmdWarpParam.w*rSq*rSq*rSq);\nreturn LensCenter+Scale*rvector;\n}\nvoid main(void)\n{\nvec2 tc=HmdWarp(vUV);\nif (tc.x <0.0 || tc.x>1.0 || tc.y<0.0 || tc.y>1.0)\ngl_FragColor=vec4(0.0,0.0,0.0,0.0);\nelse{\ngl_FragColor=texture2D(textureSampler,tc);\n}\n}",glowBlurPostProcessPixelShader:"\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\n\nuniform vec2 screenSize;\nuniform vec2 direction;\nuniform float blurWidth;\n\nfloat getLuminance(vec3 color)\n{\nreturn dot(color,vec3(0.2126,0.7152,0.0722));\n}\nvoid main(void)\n{\nfloat weights[7];\nweights[0]=0.05;\nweights[1]=0.1;\nweights[2]=0.2;\nweights[3]=0.3;\nweights[4]=0.2;\nweights[5]=0.1;\nweights[6]=0.05;\nvec2 texelSize=vec2(1.0/screenSize.x,1.0/screenSize.y);\nvec2 texelStep=texelSize*direction*blurWidth;\nvec2 start=vUV-3.0*texelStep;\nvec4 baseColor=vec4(0.,0.,0.,0.);\nvec2 texelOffset=vec2(0.,0.);\nfor (int i=0; i<7; i++)\n{\n\nvec4 texel=texture2D(textureSampler,start+texelOffset);\nbaseColor.a+=texel.a*weights[i];\n\nfloat luminance=getLuminance(baseColor.rgb);\nfloat luminanceTexel=getLuminance(texel.rgb);\nfloat choice=step(luminanceTexel,luminance);\nbaseColor.rgb=choice*baseColor.rgb+(1.0-choice)*texel.rgb;\ntexelOffset+=texelStep;\n}\ngl_FragColor=baseColor;\n}",glowMapGenerationPixelShader:"#ifdef ALPHATEST\nvarying vec2 vUVDiffuse;\nuniform sampler2D diffuseSampler;\n#endif\n#ifdef EMISSIVE\nvarying vec2 vUVEmissive;\nuniform sampler2D emissiveSampler;\n#endif\nuniform vec4 color;\nvoid main(void)\n{\n#ifdef ALPHATEST\nif (texture2D(diffuseSampler,vUVDiffuse).a<0.4)\ndiscard;\n#endif\n#ifdef EMISSIVE\ngl_FragColor=texture2D(emissiveSampler,vUVEmissive);\n#else\ngl_FragColor=color;\n#endif\n}",glowMapGenerationVertexShader:"\nattribute vec3 position;\n#include<bonesDeclaration>\n\n#include<instancesDeclaration>\nuniform mat4 viewProjection;\nvarying vec4 vPosition;\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#ifdef ALPHATEST\nvarying vec2 vUVDiffuse;\nuniform mat4 diffuseMatrix;\n#endif\n#ifdef EMISSIVE\nvarying vec2 vUVEmissive;\nuniform mat4 emissiveMatrix;\n#endif\nvoid main(void)\n{\n#include<instancesVertex>\n#include<bonesVertex>\n#ifdef CUBEMAP\nvPosition=finalWorld*vec4(position,1.0);\ngl_Position=viewProjection*finalWorld*vec4(position,1.0);\n#else\nvPosition=viewProjection*finalWorld*vec4(position,1.0);\ngl_Position=vPosition;\n#endif\n#ifdef ALPHATEST\n#ifdef DIFFUSEUV1\nvUVDiffuse=vec2(diffuseMatrix*vec4(uv,1.0,0.0));\n#endif\n#ifdef DIFFUSEUV2\nvUVDiffuse=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));\n#endif\n#endif\n#ifdef EMISSIVE\n#ifdef EMISSIVEUV1\nvUVEmissive=vec2(emissiveMatrix*vec4(uv,1.0,0.0));\n#endif\n#ifdef EMISSIVEUV2\nvUVEmissive=vec2(emissiveMatrix*vec4(uv2,1.0,0.0));\n#endif\n#endif\n}",glowMapMergePixelShader:"\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\n\nuniform float offset;\nvoid main(void) {\nvec4 baseColor=texture2D(textureSampler,vUV);\nbaseColor.a=abs(offset-baseColor.a);\ngl_FragColor=baseColor;\n}",glowMapMergeVertexShader:"\nattribute vec2 position;\n\nvarying vec2 vUV;\nconst vec2 madd=vec2(0.5,0.5);\nvoid main(void) {\nvUV=position*madd+madd;\ngl_Position=vec4(position,0.0,1.0);\n}",lineVertexShader:"\nattribute vec3 position;\nattribute vec4 normal;\n\nuniform mat4 worldViewProjection;\nuniform float width;\nuniform float aspectRatio;\nvoid main(void) {\nvec4 viewPosition=worldViewProjection*vec4(position,1.0);\nvec4 viewPositionNext=worldViewProjection*vec4(normal.xyz,1.0);\nvec2 currentScreen=viewPosition.xy/viewPosition.w;\nvec2 nextScreen=viewPositionNext.xy/viewPositionNext.w;\ncurrentScreen.x*=aspectRatio;\nnextScreen.x*=aspectRatio;\nvec2 dir=normalize(nextScreen-currentScreen);\nvec2 normalDir=vec2(-dir.y,dir.x);\nnormalDir*=width/2.0;\nnormalDir.x/=aspectRatio;\nvec4 offset=vec4(normalDir*normal.w,0.0,0.0);\ngl_Position=viewPosition+offset;\n}",linePixelShader:"uniform vec4 color;\nvoid main(void) {\ngl_FragColor=color;\n}",outlineVertexShader:"\nattribute vec3 position;\nattribute vec3 normal;\n#include<bonesDeclaration>\n\nuniform float offset;\n#include<instancesDeclaration>\nuniform mat4 viewProjection;\n#ifdef ALPHATEST\nvarying vec2 vUV;\nuniform mat4 diffuseMatrix;\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#endif\n#include<logDepthDeclaration>\nvoid main(void)\n{\nvec3 offsetPosition=position+normal*offset;\n#include<instancesVertex>\n#include<bonesVertex>\ngl_Position=viewProjection*finalWorld*vec4(offsetPosition,1.0);\n#ifdef ALPHATEST\n#ifdef UV1\nvUV=vec2(diffuseMatrix*vec4(uv,1.0,0.0));\n#endif\n#ifdef UV2\nvUV=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));\n#endif\n#endif\n#include<logDepthVertex>\n}\n",outlinePixelShader:"#ifdef LOGARITHMICDEPTH\n#extension GL_EXT_frag_depth : enable\n#endif\nuniform vec4 color;\n#ifdef ALPHATEST\nvarying vec2 vUV;\nuniform sampler2D diffuseSampler;\n#endif\n#include<logDepthDeclaration>\nvoid main(void) {\n#ifdef ALPHATEST\nif (texture2D(diffuseSampler,vUV).a<0.4)\ndiscard;\n#endif\n#include<logDepthFragment>\ngl_FragColor=color;\n}",layerVertexShader:"\nattribute vec2 position;\n\nuniform vec2 scale;\nuniform vec2 offset;\nuniform mat4 textureMatrix;\n\nvarying vec2 vUV;\nconst vec2 madd=vec2(0.5,0.5);\nvoid main(void) { \nvec2 shiftedPosition=position*scale+offset;\nvUV=vec2(textureMatrix*vec4(shiftedPosition*madd+madd,1.0,0.0));\ngl_Position=vec4(shiftedPosition,0.0,1.0);\n}",layerPixelShader:"\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\n\nuniform vec4 color;\nvoid main(void) {\nvec4 baseColor=texture2D(textureSampler,vUV);\n#ifdef ALPHATEST\nif (baseColor.a<0.4)\ndiscard;\n#endif\ngl_FragColor=baseColor*color;\n}",backgroundVertexShader:"precision highp float;\n#include<__decl__backgroundVertex>\n\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\n#endif\n#include<bonesDeclaration>\n\n#include<instancesDeclaration>\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#ifdef MAINUV1\nvarying vec2 vMainUV1;\n#endif\n#ifdef MAINUV2\nvarying vec2 vMainUV2; \n#endif\n#if defined(DIFFUSE) && DIFFUSEDIRECTUV == 0\nvarying vec2 vDiffuseUV;\n#endif\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#ifdef REFLECTIONMAP_SKYBOX\nvarying vec3 vPositionUVW;\n#endif\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvarying vec3 vDirectionW;\n#endif\nvoid main(void) {\n#ifdef REFLECTIONMAP_SKYBOX\nvPositionUVW=position;\n#endif \n#include<instancesVertex>\n#include<bonesVertex>\ngl_Position=viewProjection*finalWorld*vec4(position,1.0);\nvec4 worldPos=finalWorld*vec4(position,1.0);\nvPositionW=vec3(worldPos);\n#ifdef NORMAL\nmat3 normalWorld=mat3(finalWorld);\n#ifdef NONUNIFORMSCALING\nnormalWorld=transposeMat3(inverseMat3(normalWorld));\n#endif\nvNormalW=normalize(normalWorld*normal);\n#endif\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvDirectionW=normalize(vec3(finalWorld*vec4(position,0.0)));\n#endif\n#ifndef UV1\nvec2 uv=vec2(0.,0.);\n#endif\n#ifndef UV2\nvec2 uv2=vec2(0.,0.);\n#endif\n#ifdef MAINUV1\nvMainUV1=uv;\n#endif \n#ifdef MAINUV2\nvMainUV2=uv2;\n#endif\n#if defined(DIFFUSE) && DIFFUSEDIRECTUV == 0 \nif (vDiffuseInfos.x == 0.)\n{\nvDiffuseUV=vec2(diffuseMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvDiffuseUV=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n\n#include<clipPlaneVertex>\n\n#include<fogVertex>\n\n#include<shadowsVertex>[0..maxSimultaneousLights]\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n}\n",backgroundPixelShader:"#ifdef TEXTURELODSUPPORT\n#extension GL_EXT_shader_texture_lod : enable\n#endif\nprecision highp float;\n#include<__decl__backgroundFragment>\n\nuniform vec3 vEyePosition;\n\nvarying vec3 vPositionW;\n#ifdef MAINUV1\nvarying vec2 vMainUV1;\n#endif \n#ifdef MAINUV2 \nvarying vec2 vMainUV2; \n#endif \n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef DIFFUSE\n#if DIFFUSEDIRECTUV == 1\n#define vDiffuseUV vMainUV1\n#elif DIFFUSEDIRECTUV == 2\n#define vDiffuseUV vMainUV2\n#else\nvarying vec2 vDiffuseUV;\n#endif\nuniform sampler2D diffuseSampler;\n#endif\n\n#ifdef REFLECTION\n#ifdef REFLECTIONMAP_3D\n#define sampleReflection(s,c) textureCube(s,c)\nuniform samplerCube reflectionSampler;\n#ifdef TEXTURELODSUPPORT\n#define sampleReflectionLod(s,c,l) textureCubeLodEXT(s,c,l)\n#else\nuniform samplerCube reflectionSamplerLow;\nuniform samplerCube reflectionSamplerHigh;\n#endif\n#else\n#define sampleReflection(s,c) texture2D(s,c)\nuniform sampler2D reflectionSampler;\n#ifdef TEXTURELODSUPPORT\n#define sampleReflectionLod(s,c,l) texture2DLodEXT(s,c,l)\n#else\nuniform samplerCube reflectionSamplerLow;\nuniform samplerCube reflectionSamplerHigh;\n#endif\n#endif\n#ifdef REFLECTIONMAP_SKYBOX\nvarying vec3 vPositionUVW;\n#else\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvarying vec3 vDirectionW;\n#endif\n#endif\n#include<reflectionFunction>\n#endif\n\n#ifndef FROMLINEARSPACE\n#define FROMLINEARSPACE;\n#endif\n\n#ifndef SHADOWONLY\n#define SHADOWONLY;\n#endif\n#include<imageProcessingDeclaration>\n\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include<helperFunctions>\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n#include<imageProcessingFunctions>\n#include<clipPlaneFragmentDeclaration>\n\n#include<fogFragmentDeclaration>\n#ifdef REFLECTIONFRESNEL\n#define FRESNEL_MAXIMUM_ON_ROUGH 0.25\nvec3 fresnelSchlickEnvironmentGGX(float VdotN,vec3 reflectance0,vec3 reflectance90,float smoothness)\n{\n\nfloat weight=mix(FRESNEL_MAXIMUM_ON_ROUGH,1.0,smoothness);\nreturn reflectance0+weight*(reflectance90-reflectance0)*pow(clamp(1.0-VdotN,0.,1.),5.0);\n}\n#endif\nvoid main(void) {\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=vec3(0.0,1.0,0.0);\n#endif\n\nfloat shadow=1.;\nfloat globalShadow=0.;\nfloat shadowLightCount=0.;\n#include<lightFragment>[0..maxSimultaneousLights]\n#ifdef SHADOWINUSE\nglobalShadow/=shadowLightCount;\n#else\nglobalShadow=1.0;\n#endif\n\nvec3 reflectionColor=vec3(1.,1.,1.);\n#ifdef REFLECTION\nvec3 reflectionVector=computeReflectionCoords(vec4(vPositionW,1.0),normalW);\n#ifdef REFLECTIONMAP_OPPOSITEZ\nreflectionVector.z*=-1.0;\n#endif\n\n#ifdef REFLECTIONMAP_3D\nvec3 reflectionCoords=reflectionVector;\n#else\nvec2 reflectionCoords=reflectionVector.xy;\n#ifdef REFLECTIONMAP_PROJECTION\nreflectionCoords/=reflectionVector.z;\n#endif\nreflectionCoords.y=1.0-reflectionCoords.y;\n#endif\n#ifdef REFLECTIONBLUR\nfloat reflectionLOD=vReflectionInfos.y;\n#ifdef TEXTURELODSUPPORT\n\nreflectionLOD=reflectionLOD*log2(vReflectionMicrosurfaceInfos.x)*vReflectionMicrosurfaceInfos.y+vReflectionMicrosurfaceInfos.z;\nreflectionColor=sampleReflectionLod(reflectionSampler,reflectionCoords,reflectionLOD).rgb;\n#else\nfloat lodReflectionNormalized=clamp(reflectionLOD,0.,1.);\nfloat lodReflectionNormalizedDoubled=lodReflectionNormalized*2.0;\nvec3 reflectionSpecularMid=sampleReflection(reflectionSampler,reflectionCoords).rgb;\nif(lodReflectionNormalizedDoubled<1.0){\nreflectionColor=mix(\nsampleReflection(reflectionSamplerHigh,reflectionCoords).rgb,\nreflectionSpecularMid,\nlodReflectionNormalizedDoubled\n);\n} else {\nreflectionColor=mix(\nreflectionSpecularMid,\nsampleReflection(reflectionSamplerLow,reflectionCoords).rgb,\nlodReflectionNormalizedDoubled-1.0\n);\n}\n#endif\n#else\nvec4 reflectionSample=sampleReflection(reflectionSampler,reflectionCoords);\nreflectionColor=reflectionSample.rgb;\n#endif\n#ifdef GAMMAREFLECTION\nreflectionColor=toLinearSpace(reflectionColor.rgb);\n#endif\n\nreflectionColor*=vReflectionInfos.x;\n#endif\n\nvec3 diffuseColor=vec3(1.,1.,1.);\nfloat finalAlpha=alpha;\n#ifdef DIFFUSE\nvec4 diffuseMap=texture2D(diffuseSampler,vDiffuseUV);\n#ifdef GAMMADIFFUSE\ndiffuseMap.rgb=toLinearSpace(diffuseMap.rgb);\n#endif\n\ndiffuseMap.rgb*=vDiffuseInfos.y;\n#ifdef DIFFUSEHASALPHA\nfinalAlpha*=diffuseMap.a;\n#endif\ndiffuseColor=diffuseMap.rgb;\n#endif\n\n#ifdef REFLECTIONFRESNEL\nvec3 colorBase=diffuseColor;\n#else\nvec3 colorBase=reflectionColor*diffuseColor;\n#endif\ncolorBase=max(colorBase,0.0);\n\n#ifdef USERGBCOLOR\nvec3 finalColor=colorBase;\n#else\nvec3 finalColor=colorBase.r*vPrimaryColor.rgb*vPrimaryColor.a;\nfinalColor+=colorBase.g*vSecondaryColor.rgb*vSecondaryColor.a;\nfinalColor+=colorBase.b*vTertiaryColor.rgb*vTertiaryColor.a;\n#endif\n\n#ifdef REFLECTIONFRESNEL\nvec3 reflectionAmount=vReflectionControl.xxx;\nvec3 reflectionReflectance0=vReflectionControl.yyy;\nvec3 reflectionReflectance90=vReflectionControl.zzz;\nfloat VdotN=dot(normalize(vEyePosition),normalW);\nvec3 planarReflectionFresnel=fresnelSchlickEnvironmentGGX(clamp(VdotN,0.0,1.0),reflectionReflectance0,reflectionReflectance90,1.0);\nreflectionAmount*=planarReflectionFresnel;\n#ifdef REFLECTIONFALLOFF\nfloat reflectionDistanceFalloff=1.0-clamp(length(vPositionW.xyz-vBackgroundCenter)*vReflectionControl.w,0.0,1.0);\nreflectionDistanceFalloff*=reflectionDistanceFalloff;\nreflectionAmount*=reflectionDistanceFalloff;\n#endif\nfinalColor=mix(finalColor,reflectionColor,clamp(reflectionAmount,0.,1.));\n#endif\n#ifdef OPACITYFRESNEL\nfloat viewAngleToFloor=dot(normalW,normalize(vEyePosition-vBackgroundCenter));\n\nconst float startAngle=0.1;\nfloat fadeFactor=clamp(viewAngleToFloor/startAngle,0.0,1.0);\nfinalAlpha*=fadeFactor*fadeFactor;\n#endif\n\n#ifdef SHADOWINUSE\nfinalColor=mix(finalColor*shadowLevel,finalColor,globalShadow);\n#endif\n\nvec4 color=vec4(finalColor,finalAlpha);\n#include<fogFragment>\n#ifdef IMAGEPROCESSINGPOSTPROCESS\n\n\ncolor.rgb=clamp(color.rgb,0.,30.0);\n#else\n\ncolor=applyImageProcessing(color);\n#endif\n#ifdef PREMULTIPLYALPHA\n\ncolor.rgb*=color.a;\n#endif\n#ifdef NOISE\ncolor.rgb=dither(vPositionW.xy,color.rgb);\n#endif\ngl_FragColor=color;\n}"},us.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+=mix(-0.5/255.0,0.5/255.0,rand);\ncolor=max(color,0.0);\nreturn color;\n}",lightFragmentDeclaration:"#ifdef LIGHT{X}\nuniform vec4 vLightData{X};\nuniform vec4 vLightDiffuse{X};\n#ifdef SPECULARTERM\nuniform vec3 vLightSpecular{X};\n#else\nvec3 vLightSpecular{X}=vec3(0.);\n#endif\n#ifdef SHADOW{X}\n#if defined(SHADOWCUBE{X})\nuniform samplerCube shadowSampler{X};\n#else\nvarying vec4 vPositionFromLight{X};\nvarying float vDepthMetric{X};\nuniform sampler2D shadowSampler{X};\nuniform mat4 lightMatrix{X};\n#endif\nuniform vec4 shadowsInfo{X};\nuniform vec2 depthValues{X};\n#endif\n#ifdef SPOTLIGHT{X}\nuniform vec4 vLightDirection{X};\n#endif\n#ifdef HEMILIGHT{X}\nuniform vec3 vLightGround{X};\n#endif\n#endif",lightsFragmentFunctions:"\nstruct lightingInfo\n{\nvec3 diffuse;\n#ifdef SPECULARTERM\nvec3 specular;\n#endif\n#ifdef NDOTL\nfloat ndl;\n#endif\n};\nlightingInfo computeLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec3 diffuseColor,vec3 specularColor,float range,float glossiness) {\nlightingInfo result;\nvec3 lightVectorW;\nfloat attenuation=1.0;\nif (lightData.w == 0.)\n{\nvec3 direction=lightData.xyz-vPositionW;\nattenuation=max(0.,1.0-length(direction)/range);\nlightVectorW=normalize(direction);\n}\nelse\n{\nlightVectorW=normalize(-lightData.xyz);\n}\n\nfloat ndl=max(0.,dot(vNormal,lightVectorW));\n#ifdef NDOTL\nresult.ndl=ndl;\n#endif\nresult.diffuse=ndl*diffuseColor*attenuation;\n#ifdef SPECULARTERM\n\nvec3 angleW=normalize(viewDirectionW+lightVectorW);\nfloat specComp=max(0.,dot(vNormal,angleW));\nspecComp=pow(specComp,max(1.,glossiness));\nresult.specular=specComp*specularColor*attenuation;\n#endif\nreturn result;\n}\nlightingInfo computeSpotLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec4 lightDirection,vec3 diffuseColor,vec3 specularColor,float range,float glossiness) {\nlightingInfo result;\nvec3 direction=lightData.xyz-vPositionW;\nvec3 lightVectorW=normalize(direction);\nfloat attenuation=max(0.,1.0-length(direction)/range);\n\nfloat cosAngle=max(0.,dot(lightDirection.xyz,-lightVectorW));\nif (cosAngle>=lightDirection.w)\n{\ncosAngle=max(0.,pow(cosAngle,lightData.w));\nattenuation*=cosAngle;\n\nfloat ndl=max(0.,dot(vNormal,lightVectorW));\n#ifdef NDOTL\nresult.ndl=ndl;\n#endif\nresult.diffuse=ndl*diffuseColor*attenuation;\n#ifdef SPECULARTERM\n\nvec3 angleW=normalize(viewDirectionW+lightVectorW);\nfloat specComp=max(0.,dot(vNormal,angleW));\nspecComp=pow(specComp,max(1.,glossiness));\nresult.specular=specComp*specularColor*attenuation;\n#endif\nreturn result;\n}\nresult.diffuse=vec3(0.);\n#ifdef SPECULARTERM\nresult.specular=vec3(0.);\n#endif\n#ifdef NDOTL\nresult.ndl=0.;\n#endif\nreturn result;\n}\nlightingInfo computeHemisphericLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec3 diffuseColor,vec3 specularColor,vec3 groundColor,float glossiness) {\nlightingInfo result;\n\nfloat ndl=dot(vNormal,lightData.xyz)*0.5+0.5;\n#ifdef NDOTL\nresult.ndl=ndl;\n#endif\nresult.diffuse=mix(groundColor,diffuseColor,ndl);\n#ifdef SPECULARTERM\n\nvec3 angleW=normalize(viewDirectionW+lightData.xyz);\nfloat specComp=max(0.,dot(vNormal,angleW));\nspecComp=pow(specComp,max(1.,glossiness));\nresult.specular=specComp*specularColor;\n#endif\nreturn result;\n}\n",lightUboDeclaration:"#ifdef LIGHT{X}\nuniform Light{X}\n{\nvec4 vLightData;\nvec4 vLightDiffuse;\nvec3 vLightSpecular;\n#ifdef SPOTLIGHT{X}\nvec4 vLightDirection;\n#endif\n#ifdef HEMILIGHT{X}\nvec3 vLightGround;\n#endif\nvec4 shadowsInfo;\nvec2 depthValues;\n} light{X};\n#ifdef SHADOW{X}\n#if defined(SHADOWCUBE{X})\nuniform samplerCube shadowSampler{X};\n#else\nvarying vec4 vPositionFromLight{X};\nvarying float vDepthMetric{X};\nuniform sampler2D shadowSampler{X};\nuniform mat4 lightMatrix{X};\n#endif\n#endif\n#endif",defaultVertexDeclaration:"\nuniform mat4 viewProjection;\nuniform mat4 view;\n#ifdef DIFFUSE\nuniform mat4 diffuseMatrix;\nuniform vec2 vDiffuseInfos;\n#endif\n#ifdef AMBIENT\nuniform mat4 ambientMatrix;\nuniform vec2 vAmbientInfos;\n#endif\n#ifdef OPACITY\nuniform mat4 opacityMatrix;\nuniform vec2 vOpacityInfos;\n#endif\n#ifdef EMISSIVE\nuniform vec2 vEmissiveInfos;\nuniform mat4 emissiveMatrix;\n#endif\n#ifdef LIGHTMAP\nuniform vec2 vLightmapInfos;\nuniform mat4 lightmapMatrix;\n#endif\n#if defined(SPECULAR) && defined(SPECULARTERM)\nuniform vec2 vSpecularInfos;\nuniform mat4 specularMatrix;\n#endif\n#ifdef BUMP\nuniform vec3 vBumpInfos;\nuniform mat4 bumpMatrix;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n",defaultFragmentDeclaration:"uniform vec4 vDiffuseColor;\n#ifdef SPECULARTERM\nuniform vec4 vSpecularColor;\n#endif\nuniform vec3 vEmissiveColor;\n\n#ifdef DIFFUSE\nuniform vec2 vDiffuseInfos;\n#endif\n#ifdef AMBIENT\nuniform vec2 vAmbientInfos;\n#endif\n#ifdef OPACITY \nuniform vec2 vOpacityInfos;\n#endif\n#ifdef EMISSIVE\nuniform vec2 vEmissiveInfos;\n#endif\n#ifdef LIGHTMAP\nuniform vec2 vLightmapInfos;\n#endif\n#ifdef BUMP\nuniform vec3 vBumpInfos;\nuniform vec2 vTangentSpaceParams;\n#endif\n#if defined(REFLECTIONMAP_SPHERICAL) || defined(REFLECTIONMAP_PROJECTION) || defined(REFRACTION)\nuniform mat4 view;\n#endif\n#ifdef REFRACTION\nuniform vec4 vRefractionInfos;\n#ifndef REFRACTIONMAP_3D\nuniform mat4 refractionMatrix;\n#endif\n#ifdef REFRACTIONFRESNEL\nuniform vec4 refractionLeftColor;\nuniform vec4 refractionRightColor;\n#endif\n#endif\n#if defined(SPECULAR) && defined(SPECULARTERM)\nuniform vec2 vSpecularInfos;\n#endif\n#ifdef DIFFUSEFRESNEL\nuniform vec4 diffuseLeftColor;\nuniform vec4 diffuseRightColor;\n#endif\n#ifdef OPACITYFRESNEL\nuniform vec4 opacityParts;\n#endif\n#ifdef EMISSIVEFRESNEL\nuniform vec4 emissiveLeftColor;\nuniform vec4 emissiveRightColor;\n#endif\n\n#ifdef REFLECTION\nuniform vec2 vReflectionInfos;\n#ifdef REFLECTIONMAP_SKYBOX\n#else\n#if defined(REFLECTIONMAP_PLANAR) || defined(REFLECTIONMAP_CUBIC) || defined(REFLECTIONMAP_PROJECTION)\nuniform mat4 reflectionMatrix;\n#endif\n#endif\n#ifdef REFLECTIONFRESNEL\nuniform vec4 reflectionLeftColor;\nuniform vec4 reflectionRightColor;\n#endif\n#endif",defaultUboDeclaration:"layout(std140,column_major) uniform;\nuniform Material\n{\nvec4 diffuseLeftColor;\nvec4 diffuseRightColor;\nvec4 opacityParts;\nvec4 reflectionLeftColor;\nvec4 reflectionRightColor;\nvec4 refractionLeftColor;\nvec4 refractionRightColor;\nvec4 emissiveLeftColor; \nvec4 emissiveRightColor;\nvec2 vDiffuseInfos;\nvec2 vAmbientInfos;\nvec2 vOpacityInfos;\nvec2 vReflectionInfos;\nvec2 vEmissiveInfos;\nvec2 vLightmapInfos;\nvec2 vSpecularInfos;\nvec3 vBumpInfos;\nmat4 diffuseMatrix;\nmat4 ambientMatrix;\nmat4 opacityMatrix;\nmat4 reflectionMatrix;\nmat4 emissiveMatrix;\nmat4 lightmapMatrix;\nmat4 specularMatrix;\nmat4 bumpMatrix; \nvec4 vTangentSpaceParams;\nmat4 refractionMatrix;\nvec4 vRefractionInfos;\nvec4 vSpecularColor;\nvec3 vEmissiveColor;\nvec4 vDiffuseColor;\nfloat pointSize; \n};\nuniform Scene {\nmat4 viewProjection;\nmat4 view;\n};",shadowsFragmentFunctions:"#ifdef SHADOWS\n#ifndef SHADOWFLOAT\nfloat unpack(vec4 color)\n{\nconst vec4 bit_shift=vec4(1.0/(255.0*255.0*255.0),1.0/(255.0*255.0),1.0/255.0,1.0);\nreturn dot(color,bit_shift);\n}\n#endif\nfloat computeShadowCube(vec3 lightPosition,samplerCube shadowSampler,float darkness,vec2 depthValues)\n{\nvec3 directionToLight=vPositionW-lightPosition;\nfloat depth=length(directionToLight);\ndepth=(depth+depthValues.x)/(depthValues.y);\ndepth=clamp(depth,0.,1.0);\ndirectionToLight=normalize(directionToLight);\ndirectionToLight.y=-directionToLight.y;\n#ifndef SHADOWFLOAT\nfloat shadow=unpack(textureCube(shadowSampler,directionToLight));\n#else\nfloat shadow=textureCube(shadowSampler,directionToLight).x;\n#endif\nif (depth>shadow)\n{\nreturn darkness;\n}\nreturn 1.0;\n}\nfloat computeShadowWithPCFCube(vec3 lightPosition,samplerCube shadowSampler,float mapSize,float darkness,vec2 depthValues)\n{\nvec3 directionToLight=vPositionW-lightPosition;\nfloat depth=length(directionToLight);\ndepth=(depth+depthValues.x)/(depthValues.y);\ndepth=clamp(depth,0.,1.0);\ndirectionToLight=normalize(directionToLight);\ndirectionToLight.y=-directionToLight.y;\nfloat visibility=1.;\nvec3 poissonDisk[4];\npoissonDisk[0]=vec3(-1.0,1.0,-1.0);\npoissonDisk[1]=vec3(1.0,-1.0,-1.0);\npoissonDisk[2]=vec3(-1.0,-1.0,-1.0);\npoissonDisk[3]=vec3(1.0,-1.0,1.0);\n\n#ifndef SHADOWFLOAT\nif (unpack(textureCube(shadowSampler,directionToLight+poissonDisk[0]*mapSize))<depth) visibility-=0.25;\nif (unpack(textureCube(shadowSampler,directionToLight+poissonDisk[1]*mapSize))<depth) visibility-=0.25;\nif (unpack(textureCube(shadowSampler,directionToLight+poissonDisk[2]*mapSize))<depth) visibility-=0.25;\nif (unpack(textureCube(shadowSampler,directionToLight+poissonDisk[3]*mapSize))<depth) visibility-=0.25;\n#else\nif (textureCube(shadowSampler,directionToLight+poissonDisk[0]*mapSize).x<depth) visibility-=0.25;\nif (textureCube(shadowSampler,directionToLight+poissonDisk[1]*mapSize).x<depth) visibility-=0.25;\nif (textureCube(shadowSampler,directionToLight+poissonDisk[2]*mapSize).x<depth) visibility-=0.25;\nif (textureCube(shadowSampler,directionToLight+poissonDisk[3]*mapSize).x<depth) visibility-=0.25;\n#endif\nreturn min(1.0,visibility+darkness);\n}\nfloat computeShadowWithESMCube(vec3 lightPosition,samplerCube shadowSampler,float darkness,float depthScale,vec2 depthValues)\n{\nvec3 directionToLight=vPositionW-lightPosition;\nfloat depth=length(directionToLight);\ndepth=(depth+depthValues.x)/(depthValues.y);\nfloat shadowPixelDepth=clamp(depth,0.,1.0);\ndirectionToLight=normalize(directionToLight);\ndirectionToLight.y=-directionToLight.y;\n#ifndef SHADOWFLOAT\nfloat shadowMapSample=unpack(textureCube(shadowSampler,directionToLight));\n#else\nfloat shadowMapSample=textureCube(shadowSampler,directionToLight).x;\n#endif\nfloat esm=1.0-clamp(exp(min(87.,depthScale*shadowPixelDepth))*shadowMapSample,0.,1.-darkness); \nreturn esm;\n}\nfloat computeShadowWithCloseESMCube(vec3 lightPosition,samplerCube shadowSampler,float darkness,float depthScale,vec2 depthValues)\n{\nvec3 directionToLight=vPositionW-lightPosition;\nfloat depth=length(directionToLight);\ndepth=(depth+depthValues.x)/(depthValues.y);\nfloat shadowPixelDepth=clamp(depth,0.,1.0);\ndirectionToLight=normalize(directionToLight);\ndirectionToLight.y=-directionToLight.y;\n#ifndef SHADOWFLOAT\nfloat shadowMapSample=unpack(textureCube(shadowSampler,directionToLight));\n#else\nfloat shadowMapSample=textureCube(shadowSampler,directionToLight).x;\n#endif\nfloat esm=clamp(exp(min(87.,-depthScale*(shadowPixelDepth-shadowMapSample))),darkness,1.);\nreturn esm;\n}\nfloat computeShadow(vec4 vPositionFromLight,float depthMetric,sampler2D shadowSampler,float darkness,float frustumEdgeFalloff)\n{\nvec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;\nvec2 uv=0.5*clipSpace.xy+vec2(0.5);\nif (uv.x<0. || uv.x>1.0 || uv.y<0. || uv.y>1.0)\n{\nreturn 1.0;\n}\nfloat shadowPixelDepth=clamp(depthMetric,0.,1.0);\n#ifndef SHADOWFLOAT\nfloat shadow=unpack(texture2D(shadowSampler,uv));\n#else\nfloat shadow=texture2D(shadowSampler,uv).x;\n#endif\nif (shadowPixelDepth>shadow)\n{\nreturn computeFallOff(darkness,clipSpace.xy,frustumEdgeFalloff);\n}\nreturn 1.;\n}\nfloat computeShadowWithPCF(vec4 vPositionFromLight,float depthMetric,sampler2D shadowSampler,float mapSize,float darkness,float frustumEdgeFalloff)\n{\nvec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;\nvec2 uv=0.5*clipSpace.xy+vec2(0.5);\nif (uv.x<0. || uv.x>1.0 || uv.y<0. || uv.y>1.0)\n{\nreturn 1.0;\n}\nfloat shadowPixelDepth=clamp(depthMetric,0.,1.0);\nfloat visibility=1.;\nvec2 poissonDisk[4];\npoissonDisk[0]=vec2(-0.94201624,-0.39906216);\npoissonDisk[1]=vec2(0.94558609,-0.76890725);\npoissonDisk[2]=vec2(-0.094184101,-0.92938870);\npoissonDisk[3]=vec2(0.34495938,0.29387760);\n\n#ifndef SHADOWFLOAT\nif (unpack(texture2D(shadowSampler,uv+poissonDisk[0]*mapSize))<shadowPixelDepth) visibility-=0.25;\nif (unpack(texture2D(shadowSampler,uv+poissonDisk[1]*mapSize))<shadowPixelDepth) visibility-=0.25;\nif (unpack(texture2D(shadowSampler,uv+poissonDisk[2]*mapSize))<shadowPixelDepth) visibility-=0.25;\nif (unpack(texture2D(shadowSampler,uv+poissonDisk[3]*mapSize))<shadowPixelDepth) visibility-=0.25;\n#else\nif (texture2D(shadowSampler,uv+poissonDisk[0]*mapSize).x<shadowPixelDepth) visibility-=0.25;\nif (texture2D(shadowSampler,uv+poissonDisk[1]*mapSize).x<shadowPixelDepth) visibility-=0.25;\nif (texture2D(shadowSampler,uv+poissonDisk[2]*mapSize).x<shadowPixelDepth) visibility-=0.25;\nif (texture2D(shadowSampler,uv+poissonDisk[3]*mapSize).x<shadowPixelDepth) visibility-=0.25;\n#endif\nreturn computeFallOff(min(1.0,visibility+darkness),clipSpace.xy,frustumEdgeFalloff);\n}\nfloat computeShadowWithESM(vec4 vPositionFromLight,float depthMetric,sampler2D shadowSampler,float darkness,float depthScale,float frustumEdgeFalloff)\n{\nvec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;\nvec2 uv=0.5*clipSpace.xy+vec2(0.5);\nif (uv.x<0. || uv.x>1.0 || uv.y<0. || uv.y>1.0)\n{\nreturn 1.0;\n}\nfloat shadowPixelDepth=clamp(depthMetric,0.,1.0);\n#ifndef SHADOWFLOAT\nfloat shadowMapSample=unpack(texture2D(shadowSampler,uv));\n#else\nfloat shadowMapSample=texture2D(shadowSampler,uv).x;\n#endif\nfloat esm=1.0-clamp(exp(min(87.,depthScale*shadowPixelDepth))*shadowMapSample,0.,1.-darkness);\nreturn computeFallOff(esm,clipSpace.xy,frustumEdgeFalloff);\n}\nfloat computeShadowWithCloseESM(vec4 vPositionFromLight,float depthMetric,sampler2D shadowSampler,float darkness,float depthScale,float frustumEdgeFalloff)\n{\nvec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;\nvec2 uv=0.5*clipSpace.xy+vec2(0.5);\nif (uv.x<0. || uv.x>1.0 || uv.y<0. || uv.y>1.0)\n{\nreturn 1.0;\n}\nfloat shadowPixelDepth=clamp(depthMetric,0.,1.0); \n#ifndef SHADOWFLOAT\nfloat shadowMapSample=unpack(texture2D(shadowSampler,uv));\n#else\nfloat shadowMapSample=texture2D(shadowSampler,uv).x;\n#endif\nfloat esm=clamp(exp(min(87.,-depthScale*(shadowPixelDepth-shadowMapSample))),darkness,1.);\nreturn computeFallOff(esm,clipSpace.xy,frustumEdgeFalloff);\n}\n#endif\n",fresnelFunction:"#ifdef FRESNEL\nfloat computeFresnelTerm(vec3 viewDirection,vec3 worldNormal,float bias,float power)\n{\nfloat fresnelTerm=pow(bias+abs(dot(viewDirection,worldNormal)),power);\nreturn clamp(fresnelTerm,0.,1.);\n}\n#endif",reflectionFunction:"vec3 computeReflectionCoords(vec4 worldPos,vec3 worldNormal)\n{\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvec3 direction=normalize(vDirectionW);\nfloat t=clamp(direction.y*-0.5+0.5,0.,1.0);\nfloat s=atan(direction.z,direction.x)*RECIPROCAL_PI2+0.5;\n#ifdef REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED\nreturn vec3(1.0-s,t,0);\n#else\nreturn vec3(s,t,0);\n#endif\n#endif\n#ifdef REFLECTIONMAP_EQUIRECTANGULAR\nvec3 cameraToVertex=normalize(worldPos.xyz-vEyePosition.xyz);\nvec3 r=reflect(cameraToVertex,worldNormal);\nfloat t=clamp(r.y*-0.5+0.5,0.,1.0);\nfloat s=atan(r.z,r.x)*RECIPROCAL_PI2+0.5;\nreturn vec3(s,t,0);\n#endif\n#ifdef REFLECTIONMAP_SPHERICAL\nvec3 viewDir=normalize(vec3(view*worldPos));\nvec3 viewNormal=normalize(vec3(view*vec4(worldNormal,0.0)));\nvec3 r=reflect(viewDir,viewNormal);\nr.z=r.z-1.0;\nfloat m=2.0*length(r);\nreturn vec3(r.x/m+0.5,1.0-r.y/m-0.5,0);\n#endif\n#ifdef REFLECTIONMAP_PLANAR\nvec3 viewDir=worldPos.xyz-vEyePosition.xyz;\nvec3 coords=normalize(reflect(viewDir,worldNormal));\nreturn vec3(reflectionMatrix*vec4(coords,1));\n#endif\n#ifdef REFLECTIONMAP_CUBIC\nvec3 viewDir=worldPos.xyz-vEyePosition.xyz;\nvec3 coords=reflect(viewDir,worldNormal);\n#ifdef INVERTCUBICMAP\ncoords.y=1.0-coords.y;\n#endif\nreturn vec3(reflectionMatrix*vec4(coords,0));\n#endif\n#ifdef REFLECTIONMAP_PROJECTION\nreturn vec3(reflectionMatrix*(view*worldPos));\n#endif\n#ifdef REFLECTIONMAP_SKYBOX\nreturn vPositionUVW;\n#endif\n#ifdef REFLECTIONMAP_EXPLICIT\nreturn vec3(0,0,0);\n#endif\n}",imageProcessingDeclaration:"#ifdef EXPOSURE\nuniform float exposureLinear;\n#endif\n#ifdef CONTRAST\nuniform float contrast;\n#endif\n#ifdef VIGNETTE\nuniform vec2 vInverseScreenSize;\nuniform vec4 vignetteSettings1;\nuniform vec4 vignetteSettings2;\n#endif\n#ifdef COLORCURVES\nuniform vec4 vCameraColorCurveNegative;\nuniform vec4 vCameraColorCurveNeutral;\nuniform vec4 vCameraColorCurvePositive;\n#endif\n#ifdef COLORGRADING\n#ifdef COLORGRADING3D\nuniform highp sampler3D txColorTransform;\n#else\nuniform sampler2D txColorTransform;\n#endif\nuniform vec4 colorTransformSettings;\n#endif",imageProcessingFunctions:"#if defined(COLORGRADING) && !defined(COLORGRADING3D)\n\nvec3 sampleTexture3D(sampler2D colorTransform,vec3 color,vec2 sampler3dSetting)\n{\nfloat sliceSize=2.0*sampler3dSetting.x; \n#ifdef SAMPLER3DGREENDEPTH\nfloat sliceContinuous=(color.g-sampler3dSetting.x)*sampler3dSetting.y;\n#else\nfloat sliceContinuous=(color.b-sampler3dSetting.x)*sampler3dSetting.y;\n#endif\nfloat sliceInteger=floor(sliceContinuous);\n\n\nfloat sliceFraction=sliceContinuous-sliceInteger;\n#ifdef SAMPLER3DGREENDEPTH\nvec2 sliceUV=color.rb;\n#else\nvec2 sliceUV=color.rg;\n#endif\nsliceUV.x*=sliceSize;\nsliceUV.x+=sliceInteger*sliceSize;\nsliceUV=clamp(sliceUV,0.,1.);\nvec4 slice0Color=texture2D(colorTransform,sliceUV);\nsliceUV.x+=sliceSize;\nsliceUV=clamp(sliceUV,0.,1.);\nvec4 slice1Color=texture2D(colorTransform,sliceUV);\nvec3 result=mix(slice0Color.rgb,slice1Color.rgb,sliceFraction);\n#ifdef SAMPLER3DBGRMAP\ncolor.rgb=result.rgb;\n#else\ncolor.rgb=result.bgr;\n#endif\nreturn color;\n}\n#endif\nvec4 applyImageProcessing(vec4 result) {\n#ifdef EXPOSURE\nresult.rgb*=exposureLinear;\n#endif\n#ifdef VIGNETTE\n\nvec2 viewportXY=gl_FragCoord.xy*vInverseScreenSize;\nviewportXY=viewportXY*2.0-1.0;\nvec3 vignetteXY1=vec3(viewportXY*vignetteSettings1.xy+vignetteSettings1.zw,1.0);\nfloat vignetteTerm=dot(vignetteXY1,vignetteXY1);\nfloat vignette=pow(vignetteTerm,vignetteSettings2.w);\n\nvec3 vignetteColor=vignetteSettings2.rgb;\n#ifdef VIGNETTEBLENDMODEMULTIPLY\nvec3 vignetteColorMultiplier=mix(vignetteColor,vec3(1,1,1),vignette);\nresult.rgb*=vignetteColorMultiplier;\n#endif\n#ifdef VIGNETTEBLENDMODEOPAQUE\nresult.rgb=mix(vignetteColor,result.rgb,vignette);\n#endif\n#endif\n#ifdef TONEMAPPING\nconst float tonemappingCalibration=1.590579;\nresult.rgb=1.0-exp2(-tonemappingCalibration*result.rgb);\n#endif\n\nresult.rgb=toGammaSpace(result.rgb);\nresult.rgb=clamp(result.rgb,0.0,1.0);\n#ifdef CONTRAST\n\nvec3 resultHighContrast=applyEaseInOut(result.rgb);\nif (contrast<1.0) {\n\nresult.rgb=mix(vec3(0.5,0.5,0.5),result.rgb,contrast);\n} else {\n\nresult.rgb=mix(result.rgb,resultHighContrast,contrast-1.0);\n}\n#endif\n\n#ifdef COLORGRADING\nvec3 colorTransformInput=result.rgb*colorTransformSettings.xxx+colorTransformSettings.yyy;\n#ifdef COLORGRADING3D\nvec3 colorTransformOutput=texture(txColorTransform,colorTransformInput).rgb;\n#else\nvec3 colorTransformOutput=sampleTexture3D(txColorTransform,colorTransformInput,colorTransformSettings.yz).rgb;\n#endif\nresult.rgb=mix(result.rgb,colorTransformOutput,colorTransformSettings.www);\n#endif\n#ifdef COLORCURVES\n\nfloat luma=getLuminance(result.rgb);\nvec2 curveMix=clamp(vec2(luma*3.0-1.5,luma*-3.0+1.5),vec2(0.0),vec2(1.0));\nvec4 colorCurve=vCameraColorCurveNeutral+curveMix.x*vCameraColorCurvePositive-curveMix.y*vCameraColorCurveNegative;\nresult.rgb*=colorCurve.rgb;\nresult.rgb=mix(vec3(luma),result.rgb,colorCurve.a);\n#endif\nreturn result;\n}",bumpFragmentFunctions:"#ifdef BUMP\n#if BUMPDIRECTUV == 1\n#define vBumpUV vMainUV1\n#elif BUMPDIRECTUV == 2\n#define vBumpUV vMainUV2\n#else\nvarying vec2 vBumpUV;\n#endif\nuniform sampler2D bumpSampler;\n#if defined(TANGENT) && defined(NORMAL) \nvarying mat3 vTBN;\n#endif\n\nmat3 cotangent_frame(vec3 normal,vec3 p,vec2 uv)\n{\n\nuv=gl_FrontFacing ? uv : -uv;\n\nvec3 dp1=dFdx(p);\nvec3 dp2=dFdy(p);\nvec2 duv1=dFdx(uv);\nvec2 duv2=dFdy(uv);\n\nvec3 dp2perp=cross(dp2,normal);\nvec3 dp1perp=cross(normal,dp1);\nvec3 tangent=dp2perp*duv1.x+dp1perp*duv2.x;\nvec3 bitangent=dp2perp*duv1.y+dp1perp*duv2.y;\n\ntangent*=vTangentSpaceParams.x;\nbitangent*=vTangentSpaceParams.y;\n\nfloat invmax=inversesqrt(max(dot(tangent,tangent),dot(bitangent,bitangent)));\nreturn mat3(tangent*invmax,bitangent*invmax,normal);\n}\nvec3 perturbNormal(mat3 cotangentFrame,vec2 uv)\n{\nvec3 map=texture2D(bumpSampler,uv).xyz;\nmap=map*2.0-1.0;\n#ifdef NORMALXYSCALE\nmap=normalize(map*vec3(vBumpInfos.y,vBumpInfos.y,1.0));\n#endif\nreturn normalize(cotangentFrame*map);\n}\n#ifdef PARALLAX\nconst float minSamples=4.;\nconst float maxSamples=15.;\nconst int iMaxSamples=15;\n\nvec2 parallaxOcclusion(vec3 vViewDirCoT,vec3 vNormalCoT,vec2 texCoord,float parallaxScale) {\nfloat parallaxLimit=length(vViewDirCoT.xy)/vViewDirCoT.z;\nparallaxLimit*=parallaxScale;\nvec2 vOffsetDir=normalize(vViewDirCoT.xy);\nvec2 vMaxOffset=vOffsetDir*parallaxLimit;\nfloat numSamples=maxSamples+(dot(vViewDirCoT,vNormalCoT)*(minSamples-maxSamples));\nfloat stepSize=1.0/numSamples;\n\nfloat currRayHeight=1.0;\nvec2 vCurrOffset=vec2(0,0);\nvec2 vLastOffset=vec2(0,0);\nfloat lastSampledHeight=1.0;\nfloat currSampledHeight=1.0;\nfor (int i=0; i<iMaxSamples; i++)\n{\ncurrSampledHeight=texture2D(bumpSampler,vBumpUV+vCurrOffset).w;\n\nif (currSampledHeight>currRayHeight)\n{\nfloat delta1=currSampledHeight-currRayHeight;\nfloat delta2=(currRayHeight+stepSize)-lastSampledHeight;\nfloat ratio=delta1/(delta1+delta2);\nvCurrOffset=(ratio)* vLastOffset+(1.0-ratio)*vCurrOffset;\n\nbreak;\n}\nelse\n{\ncurrRayHeight-=stepSize;\nvLastOffset=vCurrOffset;\nvCurrOffset+=stepSize*vMaxOffset;\nlastSampledHeight=currSampledHeight;\n}\n}\nreturn vCurrOffset;\n}\nvec2 parallaxOffset(vec3 viewDir,float heightScale)\n{\n\nfloat height=texture2D(bumpSampler,vBumpUV).w;\nvec2 texCoordOffset=heightScale*viewDir.xy*height;\nreturn -texCoordOffset;\n}\n#endif\n#endif",clipPlaneFragmentDeclaration:"#ifdef CLIPPLANE\nvarying float fClipDistance;\n#endif",fogFragmentDeclaration:"#ifdef FOG\n#define FOGMODE_NONE 0.\n#define FOGMODE_EXP 1.\n#define FOGMODE_EXP2 2.\n#define FOGMODE_LINEAR 3.\n#define E 2.71828\nuniform vec4 vFogInfos;\nuniform vec3 vFogColor;\nvarying vec3 vFogDistance;\nfloat CalcFogFactor()\n{\nfloat fogCoeff=1.0;\nfloat fogStart=vFogInfos.y;\nfloat fogEnd=vFogInfos.z;\nfloat fogDensity=vFogInfos.w;\nfloat fogDistance=length(vFogDistance);\nif (FOGMODE_LINEAR == vFogInfos.x)\n{\nfogCoeff=(fogEnd-fogDistance)/(fogEnd-fogStart);\n}\nelse if (FOGMODE_EXP == vFogInfos.x)\n{\nfogCoeff=1.0/pow(E,fogDistance*fogDensity);\n}\nelse if (FOGMODE_EXP2 == vFogInfos.x)\n{\nfogCoeff=1.0/pow(E,fogDistance*fogDistance*fogDensity*fogDensity);\n}\nreturn clamp(fogCoeff,0.0,1.0);\n}\n#endif",clipPlaneFragment:"#ifdef CLIPPLANE\nif (fClipDistance>0.0)\n{\ndiscard;\n}\n#endif",bumpFragment:"vec2 uvOffset=vec2(0.0,0.0);\n#if defined(BUMP) || defined(PARALLAX)\n#ifdef NORMALXYSCALE\nfloat normalScale=1.0;\n#else \nfloat normalScale=vBumpInfos.y;\n#endif\n#if defined(TANGENT) && defined(NORMAL)\nmat3 TBN=vTBN;\n#else\nmat3 TBN=cotangent_frame(normalW*normalScale,vPositionW,vBumpUV);\n#endif\n#endif\n#ifdef PARALLAX\nmat3 invTBN=transposeMat3(TBN);\n#ifdef PARALLAXOCCLUSION\nuvOffset=parallaxOcclusion(invTBN*-viewDirectionW,invTBN*normalW,vBumpUV,vBumpInfos.z);\n#else\nuvOffset=parallaxOffset(invTBN*viewDirectionW,vBumpInfos.z);\n#endif\n#endif\n#ifdef BUMP\nnormalW=perturbNormal(TBN,vBumpUV+uvOffset);\n#endif",lightFragment:"#ifdef LIGHT{X}\n#if defined(SHADOWONLY) || (defined(LIGHTMAP) && defined(LIGHTMAPEXCLUDED{X}) && defined(LIGHTMAPNOSPECULAR{X}))\n\n#else\n#ifdef PBR\n#ifdef SPOTLIGHT{X}\ninfo=computeSpotLighting(viewDirectionW,normalW,light{X}.vLightData,light{X}.vLightDirection,light{X}.vLightDiffuse.rgb,light{X}.vLightSpecular,light{X}.vLightDiffuse.a,roughness,NdotV,specularEnvironmentR0,specularEnvironmentR90,NdotL);\n#endif\n#ifdef HEMILIGHT{X}\ninfo=computeHemisphericLighting(viewDirectionW,normalW,light{X}.vLightData,light{X}.vLightDiffuse.rgb,light{X}.vLightSpecular,light{X}.vLightGround,roughness,NdotV,specularEnvironmentR0,specularEnvironmentR90,NdotL);\n#endif\n#if defined(POINTLIGHT{X}) || defined(DIRLIGHT{X})\ninfo=computeLighting(viewDirectionW,normalW,light{X}.vLightData,light{X}.vLightDiffuse.rgb,light{X}.vLightSpecular,light{X}.vLightDiffuse.a,roughness,NdotV,specularEnvironmentR0,specularEnvironmentR90,NdotL);\n#endif\n#else\n#ifdef SPOTLIGHT{X}\ninfo=computeSpotLighting(viewDirectionW,normalW,light{X}.vLightData,light{X}.vLightDirection,light{X}.vLightDiffuse.rgb,light{X}.vLightSpecular,light{X}.vLightDiffuse.a,glossiness);\n#endif\n#ifdef HEMILIGHT{X}\ninfo=computeHemisphericLighting(viewDirectionW,normalW,light{X}.vLightData,light{X}.vLightDiffuse.rgb,light{X}.vLightSpecular,light{X}.vLightGround,glossiness);\n#endif\n#if defined(POINTLIGHT{X}) || defined(DIRLIGHT{X})\ninfo=computeLighting(viewDirectionW,normalW,light{X}.vLightData,light{X}.vLightDiffuse.rgb,light{X}.vLightSpecular,light{X}.vLightDiffuse.a,glossiness);\n#endif\n#endif\n#endif\n#ifdef SHADOW{X}\n#ifdef SHADOWCLOSEESM{X}\n#if defined(SHADOWCUBE{X})\nshadow=computeShadowWithCloseESMCube(light{X}.vLightData.xyz,shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.z,light{X}.depthValues);\n#else\nshadow=computeShadowWithCloseESM(vPositionFromLight{X},vDepthMetric{X},shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.z,light{X}.shadowsInfo.w);\n#endif\n#else\n#ifdef SHADOWESM{X}\n#if defined(SHADOWCUBE{X})\nshadow=computeShadowWithESMCube(light{X}.vLightData.xyz,shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.z,light{X}.depthValues);\n#else\nshadow=computeShadowWithESM(vPositionFromLight{X},vDepthMetric{X},shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.z,light{X}.shadowsInfo.w);\n#endif\n#else \n#ifdef SHADOWPCF{X}\n#if defined(SHADOWCUBE{X})\nshadow=computeShadowWithPCFCube(light{X}.vLightData.xyz,shadowSampler{X},light{X}.shadowsInfo.y,light{X}.shadowsInfo.x,light{X}.depthValues);\n#else\nshadow=computeShadowWithPCF(vPositionFromLight{X},vDepthMetric{X},shadowSampler{X},light{X}.shadowsInfo.y,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);\n#endif\n#else\n#if defined(SHADOWCUBE{X})\nshadow=computeShadowCube(light{X}.vLightData.xyz,shadowSampler{X},light{X}.shadowsInfo.x,light{X}.depthValues);\n#else\nshadow=computeShadow(vPositionFromLight{X},vDepthMetric{X},shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);\n#endif\n#endif\n#endif\n#endif\n#ifdef SHADOWONLY\n#ifndef SHADOWINUSE\n#define SHADOWINUSE\n#endif\nglobalShadow+=shadow;\nshadowLightCount+=1.0;\n#endif\n#else\nshadow=1.;\n#endif\n#ifndef SHADOWONLY\n#ifdef CUSTOMUSERLIGHTING\ndiffuseBase+=computeCustomDiffuseLighting(info,diffuseBase,shadow);\n#ifdef SPECULARTERM\nspecularBase+=computeCustomSpecularLighting(info,specularBase,shadow);\n#endif\n#elif defined(LIGHTMAP) && defined(LIGHTMAPEXCLUDED{X})\ndiffuseBase+=lightmapColor*shadow;\n#ifdef SPECULARTERM\n#ifndef LIGHTMAPNOSPECULAR{X}\nspecularBase+=info.specular*shadow*lightmapColor;\n#endif\n#endif\n#else\ndiffuseBase+=info.diffuse*shadow;\n#ifdef SPECULARTERM\nspecularBase+=info.specular*shadow;\n#endif\n#endif\n#endif\n#endif",logDepthFragment:"#ifdef LOGARITHMICDEPTH\ngl_FragDepthEXT=log2(vFragmentDepth)*logarithmicDepthConstant*0.5;\n#endif",fogFragment:"#ifdef FOG\nfloat fog=CalcFogFactor();\ncolor.rgb=fog*color.rgb+(1.0-fog)*vFogColor;\n#endif",pbrVertexDeclaration:"uniform mat4 view;\nuniform mat4 viewProjection;\n#ifdef ALBEDO\nuniform mat4 albedoMatrix;\nuniform vec2 vAlbedoInfos;\n#endif\n#ifdef AMBIENT\nuniform mat4 ambientMatrix;\nuniform vec3 vAmbientInfos;\n#endif\n#ifdef OPACITY\nuniform mat4 opacityMatrix;\nuniform vec2 vOpacityInfos;\n#endif\n#ifdef EMISSIVE\nuniform vec2 vEmissiveInfos;\nuniform mat4 emissiveMatrix;\n#endif\n#ifdef LIGHTMAP\nuniform vec2 vLightmapInfos;\nuniform mat4 lightmapMatrix;\n#endif\n#ifdef REFLECTIVITY \nuniform vec3 vReflectivityInfos;\nuniform mat4 reflectivityMatrix;\n#endif\n#ifdef MICROSURFACEMAP\nuniform vec2 vMicroSurfaceSamplerInfos;\nuniform mat4 microSurfaceSamplerMatrix;\n#endif\n#ifdef BUMP\nuniform vec3 vBumpInfos;\nuniform mat4 bumpMatrix;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\n#ifdef REFRACTION\nuniform vec4 vRefractionInfos;\nuniform mat4 refractionMatrix;\nuniform vec3 vRefractionMicrosurfaceInfos;\n#endif\n\n#ifdef REFLECTION\nuniform vec2 vReflectionInfos;\nuniform mat4 reflectionMatrix;\nuniform vec3 vReflectionMicrosurfaceInfos;\n#endif\n",pbrFragmentDeclaration:"uniform vec3 vReflectionColor;\nuniform vec4 vAlbedoColor;\n\nuniform vec4 vLightingIntensity;\nuniform vec4 vReflectivityColor;\nuniform vec3 vEmissiveColor;\n\n#ifdef ALBEDO\nuniform vec2 vAlbedoInfos;\n#endif\n#ifdef AMBIENT\nuniform vec3 vAmbientInfos;\n#endif\n#ifdef BUMP\nuniform vec3 vBumpInfos;\nuniform vec2 vTangentSpaceParams;\n#endif\n#ifdef OPACITY \nuniform vec2 vOpacityInfos;\n#endif\n#ifdef EMISSIVE\nuniform vec2 vEmissiveInfos;\n#endif\n#ifdef LIGHTMAP\nuniform vec2 vLightmapInfos;\n#endif\n#ifdef REFLECTIVITY\nuniform vec3 vReflectivityInfos;\n#endif\n#ifdef MICROSURFACEMAP\nuniform vec2 vMicroSurfaceSamplerInfos;\n#endif\n\n#if defined(REFLECTIONMAP_SPHERICAL) || defined(REFLECTIONMAP_PROJECTION) || defined(REFRACTION)\nuniform mat4 view;\n#endif\n\n#ifdef REFRACTION\nuniform vec4 vRefractionInfos;\nuniform mat4 refractionMatrix;\nuniform vec3 vRefractionMicrosurfaceInfos;\n#endif\n\n#ifdef REFLECTION\nuniform vec2 vReflectionInfos;\nuniform mat4 reflectionMatrix;\nuniform vec3 vReflectionMicrosurfaceInfos;\n#endif",pbrUboDeclaration:"layout(std140,column_major) uniform;\nuniform Material\n{\nuniform vec2 vAlbedoInfos;\nuniform vec3 vAmbientInfos;\nuniform vec2 vOpacityInfos;\nuniform vec2 vEmissiveInfos;\nuniform vec2 vLightmapInfos;\nuniform vec3 vReflectivityInfos;\nuniform vec2 vMicroSurfaceSamplerInfos;\nuniform vec4 vRefractionInfos;\nuniform vec2 vReflectionInfos;\nuniform vec3 vBumpInfos;\nuniform mat4 albedoMatrix;\nuniform mat4 ambientMatrix;\nuniform mat4 opacityMatrix;\nuniform mat4 emissiveMatrix;\nuniform mat4 lightmapMatrix;\nuniform mat4 reflectivityMatrix;\nuniform mat4 microSurfaceSamplerMatrix;\nuniform mat4 bumpMatrix;\nuniform vec2 vTangentSpaceParams;\nuniform mat4 refractionMatrix;\nuniform mat4 reflectionMatrix;\nuniform vec3 vReflectionColor;\nuniform vec4 vAlbedoColor;\nuniform vec4 vLightingIntensity;\nuniform vec3 vRefractionMicrosurfaceInfos;\nuniform vec3 vReflectionMicrosurfaceInfos;\nuniform vec4 vReflectivityColor;\nuniform vec3 vEmissiveColor;\nuniform float pointSize;\n};\nuniform Scene {\nmat4 viewProjection;\nmat4 view;\n};",pbrFunctions:"\n#define RECIPROCAL_PI2 0.15915494\n#define FRESNEL_MAXIMUM_ON_ROUGH 0.25\n\nconst float kRougnhessToAlphaScale=0.1;\nconst float kRougnhessToAlphaOffset=0.29248125;\nfloat convertRoughnessToAverageSlope(float roughness)\n{\n\nconst float kMinimumVariance=0.0005;\nfloat alphaG=square(roughness)+kMinimumVariance;\nreturn alphaG;\n}\n\nfloat smithVisibilityG1_TrowbridgeReitzGGX(float dot,float alphaG)\n{\nfloat tanSquared=(1.0-dot*dot)/(dot*dot);\nreturn 2.0/(1.0+sqrt(1.0+alphaG*alphaG*tanSquared));\n}\nfloat smithVisibilityG_TrowbridgeReitzGGX_Walter(float NdotL,float NdotV,float alphaG)\n{\nreturn smithVisibilityG1_TrowbridgeReitzGGX(NdotL,alphaG)*smithVisibilityG1_TrowbridgeReitzGGX(NdotV,alphaG);\n}\n\n\nfloat normalDistributionFunction_TrowbridgeReitzGGX(float NdotH,float alphaG)\n{\n\n\n\nfloat a2=square(alphaG);\nfloat d=NdotH*NdotH*(a2-1.0)+1.0;\nreturn a2/(PI*d*d);\n}\nvec3 fresnelSchlickGGX(float VdotH,vec3 reflectance0,vec3 reflectance90)\n{\nreturn reflectance0+(reflectance90-reflectance0)*pow(clamp(1.0-VdotH,0.,1.),5.0);\n}\nvec3 fresnelSchlickEnvironmentGGX(float VdotN,vec3 reflectance0,vec3 reflectance90,float smoothness)\n{\n\nfloat weight=mix(FRESNEL_MAXIMUM_ON_ROUGH,1.0,smoothness);\nreturn reflectance0+weight*(reflectance90-reflectance0)*pow(clamp(1.0-VdotN,0.,1.),5.0);\n}\n\nvec3 computeSpecularTerm(float NdotH,float NdotL,float NdotV,float VdotH,float roughness,vec3 reflectance0,vec3 reflectance90)\n{\nfloat alphaG=convertRoughnessToAverageSlope(roughness);\nfloat distribution=normalDistributionFunction_TrowbridgeReitzGGX(NdotH,alphaG);\nfloat visibility=smithVisibilityG_TrowbridgeReitzGGX_Walter(NdotL,NdotV,alphaG);\nvisibility/=(4.0*NdotL*NdotV); \nfloat specTerm=max(0.,visibility*distribution)*NdotL;\nvec3 fresnel=fresnelSchlickGGX(VdotH,reflectance0,reflectance90);\nreturn fresnel*specTerm;\n}\nfloat computeDiffuseTerm(float NdotL,float NdotV,float VdotH,float roughness)\n{\n\n\nfloat diffuseFresnelNV=pow(clamp(1.0-NdotL,0.000001,1.),5.0);\nfloat diffuseFresnelNL=pow(clamp(1.0-NdotV,0.000001,1.),5.0);\nfloat diffuseFresnel90=0.5+2.0*VdotH*VdotH*roughness;\nfloat fresnel =\n(1.0+(diffuseFresnel90-1.0)*diffuseFresnelNL) *\n(1.0+(diffuseFresnel90-1.0)*diffuseFresnelNV);\nreturn fresnel*NdotL/PI;\n}\nfloat adjustRoughnessFromLightProperties(float roughness,float lightRadius,float lightDistance)\n{\n#ifdef USEPHYSICALLIGHTFALLOFF\n\nfloat lightRoughness=lightRadius/lightDistance;\n\nfloat totalRoughness=clamp(lightRoughness+roughness,0.,1.);\nreturn totalRoughness;\n#else\nreturn roughness;\n#endif\n}\nfloat computeDefaultMicroSurface(float microSurface,vec3 reflectivityColor)\n{\nconst float kReflectivityNoAlphaWorkflow_SmoothnessMax=0.95;\nfloat reflectivityLuminance=getLuminance(reflectivityColor);\nfloat reflectivityLuma=sqrt(reflectivityLuminance);\nmicroSurface=reflectivityLuma*kReflectivityNoAlphaWorkflow_SmoothnessMax;\nreturn microSurface;\n}\n\n\nfloat fresnelGrazingReflectance(float reflectance0) {\nfloat reflectance90=clamp(reflectance0*25.0,0.0,1.0);\nreturn reflectance90;\n}\n\n\n#define UNPACK_LOD(x) (1.0-x)*255.0\nfloat getLodFromAlphaG(float cubeMapDimensionPixels,float alphaG,float NdotV) {\nfloat microsurfaceAverageSlope=alphaG;\n\n\n\n\n\n\nmicrosurfaceAverageSlope*=sqrt(abs(NdotV));\nfloat microsurfaceAverageSlopeTexels=microsurfaceAverageSlope*cubeMapDimensionPixels;\nfloat lod=log2(microsurfaceAverageSlopeTexels);\nreturn lod;\n}\nfloat environmentRadianceOcclusion(float ambientOcclusion,float NdotVUnclamped) {\n\n\nfloat temp=NdotVUnclamped+ambientOcclusion;\nreturn clamp(square(temp)-1.0+ambientOcclusion,0.0,1.0);\n}\nfloat environmentHorizonOcclusion(vec3 reflection,vec3 normal) {\n\n#ifdef REFLECTIONMAP_OPPOSITEZ\nreflection.z*=-1.0;\n#endif\nfloat temp=clamp( 1.0+1.1*dot(reflection,normal),0.0,1.0);\nreturn square(temp);\n}",harmonicsFunctions:"#ifdef USESPHERICALFROMREFLECTIONMAP\nuniform vec3 vSphericalX;\nuniform vec3 vSphericalY;\nuniform vec3 vSphericalZ;\nuniform vec3 vSphericalXX_ZZ;\nuniform vec3 vSphericalYY_ZZ;\nuniform vec3 vSphericalZZ;\nuniform vec3 vSphericalXY;\nuniform vec3 vSphericalYZ;\nuniform vec3 vSphericalZX;\nvec3 quaternionVectorRotation_ScaledSqrtTwo(vec4 Q,vec3 V){\nvec3 T=cross(Q.xyz,V);\nT+=Q.www*V;\nreturn cross(Q.xyz,T)+V;\n}\nvec3 environmentIrradianceJones(vec3 normal)\n{\n\n\n\n\n\n\n\n\n\nfloat Nx=normal.x;\nfloat Ny=normal.y;\nfloat Nz=normal.z;\nvec3 C1=vSphericalZZ.rgb;\nvec3 Cx=vSphericalX.rgb;\nvec3 Cy=vSphericalY.rgb;\nvec3 Cz=vSphericalZ.rgb;\nvec3 Cxx_zz=vSphericalXX_ZZ.rgb;\nvec3 Cyy_zz=vSphericalYY_ZZ.rgb;\nvec3 Cxy=vSphericalXY.rgb;\nvec3 Cyz=vSphericalYZ.rgb;\nvec3 Czx=vSphericalZX.rgb;\nvec3 a1=Cyy_zz*Ny+Cy;\nvec3 a2=Cyz*Nz+a1;\nvec3 b1=Czx*Nz+Cx;\nvec3 b2=Cxy*Ny+b1;\nvec3 b3=Cxx_zz*Nx+b2;\nvec3 t1=Cz*Nz+C1;\nvec3 t2=a2*Ny+t1;\nvec3 t3=b3*Nx+t2;\nreturn t3;\n}\n#endif",pbrLightFunctions:"\nstruct lightingInfo\n{\nvec3 diffuse;\n#ifdef SPECULARTERM\nvec3 specular;\n#endif\n};\nfloat computeDistanceLightFalloff(vec3 lightOffset,float lightDistanceSquared,float range)\n{ \n#ifdef USEPHYSICALLIGHTFALLOFF\nfloat lightDistanceFalloff=1.0/((lightDistanceSquared+0.001));\n#else\nfloat lightDistanceFalloff=max(0.,1.0-length(lightOffset)/range);\n#endif\nreturn lightDistanceFalloff;\n}\nfloat computeDirectionalLightFalloff(vec3 lightDirection,vec3 directionToLightCenterW,float cosHalfAngle,float exponent)\n{\nfloat falloff=0.0;\n#ifdef USEPHYSICALLIGHTFALLOFF\nconst float kMinusLog2ConeAngleIntensityRatio=6.64385618977; \n\n\n\n\n\nfloat concentrationKappa=kMinusLog2ConeAngleIntensityRatio/(1.0-cosHalfAngle);\n\n\nvec4 lightDirectionSpreadSG=vec4(-lightDirection*concentrationKappa,-concentrationKappa);\nfalloff=exp2(dot(vec4(directionToLightCenterW,1.0),lightDirectionSpreadSG));\n#else\nfloat cosAngle=max(0.000000000000001,dot(-lightDirection,directionToLightCenterW));\nif (cosAngle>=cosHalfAngle)\n{\nfalloff=max(0.,pow(cosAngle,exponent));\n}\n#endif\nreturn falloff;\n}\nlightingInfo computeLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec3 diffuseColor,vec3 specularColor,float rangeRadius,float roughness,float NdotV,vec3 reflectance0,vec3 reflectance90,out float NdotL) {\nlightingInfo result;\nvec3 lightDirection;\nfloat attenuation=1.0;\nfloat lightDistance;\n\nif (lightData.w == 0.)\n{\nvec3 lightOffset=lightData.xyz-vPositionW;\nfloat lightDistanceSquared=dot(lightOffset,lightOffset);\nattenuation=computeDistanceLightFalloff(lightOffset,lightDistanceSquared,rangeRadius);\nlightDistance=sqrt(lightDistanceSquared);\nlightDirection=normalize(lightOffset);\n}\n\nelse\n{\nlightDistance=length(-lightData.xyz);\nlightDirection=normalize(-lightData.xyz);\n}\n\nroughness=adjustRoughnessFromLightProperties(roughness,rangeRadius,lightDistance);\n\nvec3 H=normalize(viewDirectionW+lightDirection);\nNdotL=clamp(dot(vNormal,lightDirection),0.00000000001,1.0);\nfloat VdotH=clamp(dot(viewDirectionW,H),0.0,1.0);\nfloat diffuseTerm=computeDiffuseTerm(NdotL,NdotV,VdotH,roughness);\nresult.diffuse=diffuseTerm*diffuseColor*attenuation;\n#ifdef SPECULARTERM\n\nfloat NdotH=clamp(dot(vNormal,H),0.000000000001,1.0);\nvec3 specTerm=computeSpecularTerm(NdotH,NdotL,NdotV,VdotH,roughness,reflectance0,reflectance90);\nresult.specular=specTerm*diffuseColor*attenuation;\n#endif\nreturn result;\n}\nlightingInfo computeSpotLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec4 lightDirection,vec3 diffuseColor,vec3 specularColor,float rangeRadius,float roughness,float NdotV,vec3 reflectance0,vec3 reflectance90,out float NdotL) {\nlightingInfo result;\nvec3 lightOffset=lightData.xyz-vPositionW;\nvec3 directionToLightCenterW=normalize(lightOffset);\n\nfloat lightDistanceSquared=dot(lightOffset,lightOffset);\nfloat attenuation=computeDistanceLightFalloff(lightOffset,lightDistanceSquared,rangeRadius);\n\nfloat directionalAttenuation=computeDirectionalLightFalloff(lightDirection.xyz,directionToLightCenterW,lightDirection.w,lightData.w);\nattenuation*=directionalAttenuation;\n\nfloat lightDistance=sqrt(lightDistanceSquared);\nroughness=adjustRoughnessFromLightProperties(roughness,rangeRadius,lightDistance);\n\nvec3 H=normalize(viewDirectionW+directionToLightCenterW);\nNdotL=clamp(dot(vNormal,directionToLightCenterW),0.000000000001,1.0);\nfloat VdotH=clamp(dot(viewDirectionW,H),0.0,1.0);\nfloat diffuseTerm=computeDiffuseTerm(NdotL,NdotV,VdotH,roughness);\nresult.diffuse=diffuseTerm*diffuseColor*attenuation;\n#ifdef SPECULARTERM\n\nfloat NdotH=clamp(dot(vNormal,H),0.000000000001,1.0);\nvec3 specTerm=computeSpecularTerm(NdotH,NdotL,NdotV,VdotH,roughness,reflectance0,reflectance90);\nresult.specular=specTerm*diffuseColor*attenuation;\n#endif\nreturn result;\n}\nlightingInfo computeHemisphericLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec3 diffuseColor,vec3 specularColor,vec3 groundColor,float roughness,float NdotV,vec3 reflectance0,vec3 reflectance90,out float NdotL) {\nlightingInfo result;\n\n\n\nNdotL=dot(vNormal,lightData.xyz)*0.5+0.5;\nresult.diffuse=mix(groundColor,diffuseColor,NdotL);\n#ifdef SPECULARTERM\n\nvec3 lightVectorW=normalize(lightData.xyz);\nvec3 H=normalize(viewDirectionW+lightVectorW);\nfloat NdotH=clamp(dot(vNormal,H),0.000000000001,1.0);\nNdotL=clamp(NdotL,0.000000000001,1.0);\nfloat VdotH=clamp(dot(viewDirectionW,H),0.0,1.0);\nvec3 specTerm=computeSpecularTerm(NdotH,NdotL,NdotV,VdotH,roughness,reflectance0,reflectance90);\nresult.specular=specTerm*diffuseColor;\n#endif\nreturn result;\n}",mrtFragmentDeclaration:"#if __VERSION__>=200\nlayout(location=0) out vec4 glFragData[{X}];\n#endif\n",bones300Declaration:"#if NUM_BONE_INFLUENCERS>0\nuniform mat4 mBones[BonesPerMesh];\nin vec4 matricesIndices;\nin vec4 matricesWeights;\n#if NUM_BONE_INFLUENCERS>4\nin vec4 matricesIndicesExtra;\nin vec4 matricesWeightsExtra;\n#endif\n#endif",instances300Declaration:"#ifdef INSTANCES\nin vec4 world0;\nin vec4 world1;\nin vec4 world2;\nin vec4 world3;\n#else\nuniform mat4 world;\n#endif",kernelBlurFragment:"#ifdef PACKEDFLOAT\nblend+=unpack(texture2D(textureSampler,sampleCoord{X}))*KERNEL_WEIGHT{X};\n#else\nblend+=texture2D(textureSampler,sampleCoord{X})*KERNEL_WEIGHT{X};\n#endif",kernelBlurFragment2:"#ifdef PACKEDFLOAT\nblend+=unpack(texture2D(textureSampler,sampleCenter+delta*KERNEL_DEP_OFFSET{X}))*KERNEL_DEP_WEIGHT{X};\n#else\nblend+=texture2D(textureSampler,sampleCenter+delta*KERNEL_DEP_OFFSET{X})*KERNEL_DEP_WEIGHT{X};\n#endif",kernelBlurVaryingDeclaration:"varying vec2 sampleCoord{X};",kernelBlurVertex:"sampleCoord{X}=sampleCenter+delta*KERNEL_OFFSET{X};",backgroundVertexDeclaration:"uniform mat4 view;\nuniform mat4 viewProjection;\nuniform float shadowLevel;\n#ifdef DIFFUSE\nuniform mat4 diffuseMatrix;\nuniform vec2 vDiffuseInfos;\n#endif\n#ifdef REFLECTION\nuniform vec2 vReflectionInfos;\nuniform mat4 reflectionMatrix;\nuniform vec3 vReflectionMicrosurfaceInfos;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif",backgroundFragmentDeclaration:" uniform vec4 vPrimaryColor;\nuniform vec4 vSecondaryColor;\nuniform vec4 vTertiaryColor;\nuniform float shadowLevel;\nuniform float alpha;\n#ifdef DIFFUSE\nuniform vec2 vDiffuseInfos;\n#endif\n#ifdef REFLECTION\nuniform vec2 vReflectionInfos;\nuniform mat4 reflectionMatrix;\nuniform vec3 vReflectionMicrosurfaceInfos;\n#endif\n#if defined(REFLECTIONFRESNEL) || defined(OPACITYFRESNEL)\nuniform vec3 vBackgroundCenter;\n#endif\n#ifdef REFLECTIONFRESNEL\nuniform vec4 vReflectionControl;\n#endif\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();i&&i.BABYLON||((void 0!==t?t:"undefined"!=typeof window?window:this).BABYLON=n,e.exports=n)}(this,function(){return us})}).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;r<e.attributes.length;++r)i(r);return t},e}(),s=function(){function e(){}return e.prototype.map=function(e){return JSON.parse(e)},e}(),a=function(){function e(){}return e.prototype.map=function(e){var t=new o,i=t.map(e),r=function(e,i){var o=e.children;if(o.length)for(var s=0;s<o.length;++s){var a=o.item(s),h=t.map(a),l=n.kebabToCamel(a.nodeName.toLowerCase());if(a.attributes.getNamedItem("array")&&"true"===a.attributes.getNamedItem("array").nodeValue)i[l]=[];else if(e.attributes.getNamedItem("array")&&"true"===e.attributes.getNamedItem("array").nodeValue)i.push(h);else if(i[l]){e.setAttribute("array","true"),i=[i[l],h]}else i[l]=h;r(a,i[l]||h)}return i};return r(e,i),i},e}(),h=function(){function e(){this.mappers={html:new o,json:new s,dom:new a}}return e.prototype.getMapper=function(t){return this.mappers[t]||r.Tools.Error("No mapper defined for "+t),this.mappers[t]||this.mappers[e.DefaultMapper]},e.prototype.registerMapper=function(e,t){this.mappers[e]=t},e.DefaultMapper="json",e}();t.MapperManager=h,t.mapperManager=new h},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.isUrl=function(e){return 0===e.indexOf("http")||0===e.indexOf("/")||0===e.indexOf("./")||0===e.indexOf("../")},t.loadFile=function(e){return new Promise(function(t,i){var r=new XMLHttpRequest;r.open("GET",e),r.send(),r.onreadystatechange=function(){4===r.readyState?200===r.status&&t(r.responseText):(console.log("Error: "+r.status,e),i("Error: "+r.status))}})},t.kebabToCamel=function(e){return e.replace(/(\-\w)/g,function(e){return e[1].toUpperCase()})},t.camelToKebab=function(e){return e?e.replace(/([A-Z])/g,function(e){return"-"+e[0].toLowerCase()}):null}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=i(0),n=function(){function e(){this.viewers={},this.onViewerAddedObservable=new r.Observable}return e.prototype.addViewer=function(e){this.viewers[e.getBaseId()]=e,this._onViewerAdded(e)},e.prototype.getViewerById=function(e){return this.viewers[e]},e.prototype.getViewerByHTMLElement=function(e){for(var t in this.viewers)if(this.viewers[t].containerElement===e)return this.getViewerById(t)},e.prototype.getViewerPromiseById=function(e){var t=this;return new Promise(function(i,r){var n=t.getViewerById(e);if(n)return i(n);var o=function(r){r.getBaseId()===e&&(i(r),t.onViewerAddedObservable.removeCallback(o))};t.onViewerAddedObservable.add(o)})},e.prototype._onViewerAdded=function(e){this.onViewerAdded&&this.onViewerAdded(e),this.onViewerAddedObservable.notifyObservers(e)},e}();t.ViewerManager=n,t.viewerManager=new n},function(e,t,i){"use strict";var r,n=this&&this.__extends||(r=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])},function(e,t){function i(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(i.prototype=t.prototype,new i)});Object.defineProperty(t,"__esModule",{value:!0});var o=i(6),s=i(0),a=function(e){function t(t,i){void 0===i&&(i={extends:"default"});var r=e.call(this,t,i)||this;return r.containerElement=t,r.onModelLoaded=function(e){return r.setModelMetaData(),setTimeout(function(){r.hideLoadingScreen()},500),r.scene.createDefaultCameraOrLight(!0,!0,!0),r.camera=r.scene.activeCamera,e[0].rotation.y+=Math.PI,r.setupCamera(e),r.setupLights(e),r.initEnvironment(e)},r.onModelLoadedObservable.add(r.onModelLoaded),r}return n(t,e),t.prototype.initScene=function(){var t=this;return e.prototype.initScene.call(this).then(function(){return t.extendClassWithConfig(t.scene,t.configuration.scene),t.scene})},t.prototype.onTemplatesLoaded=function(){var t=this;this.showLoadingScreen(),this.initNavbar();var i=document.getElementById("close-button");return i&&i.addEventListener("pointerdown",function(){t.hideOverlayScreen()}),e.prototype.onTemplatesLoaded.call(this)},t.prototype.initNavbar=function(){var e=this.templateManager.getTemplate("navBar");if(e){var t,i=e.parent.clientHeight+"px",r=!0,n=function(n,o){if(void 0===n&&(n=!1),e&&!(o.button>0)&&(t&&clearTimeout(t),n!==r))if(n)e.parent.style.bottom=n?"0px":"-"+i,r=n;else{var s=2e3;e.configuration.params&&void 0!==e.configuration.params.visibilityTimeout&&(s=e.configuration.params.visibilityTimeout),t=setTimeout(function(){e&&(e.parent.style.bottom="-"+i),r=n},s)}};this.templateManager.eventManager.registerCallback("viewer",n.bind(this,!1),"pointerout"),this.templateManager.eventManager.registerCallback("viewer",n.bind(this,!0),"pointerdown"),this.templateManager.eventManager.registerCallback("viewer",n.bind(this,!1),"pointerup"),this.templateManager.eventManager.registerCallback("navBar",n.bind(this,!0),"pointerover");var o=this.templateManager.getTemplate("viewer"),s=o&&o.parent;this.templateManager.eventManager.registerCallback("navBar",function(e){s&&(document.fullscreenElement||document.webkitFullscreenElement||document.mozFullScreenElement||document.msFullscreenElement?(document.exitFullscreen||document.webkitExitFullscreen||document.msExitFullscreen||document.mozCancelFullScreen).call(document):(s.requestFullscreen||s.webkitRequestFullscreen||s.msRequestFullscreen||s.mozRequestFullScreen).call(s))},"pointerdown","#fullscreen-button")}},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){var i;if(this.configuration.model.title)(i=t.querySelector("span.model-title"))&&(i.innerHTML=this.configuration.model.title);if(this.configuration.model.subtitle)(i=t.querySelector("span.model-subtitle"))&&(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?s.CubeTexture.CreateFromPrefilteredData(this.configuration.skybox.cubeTexture.url,this.scene):s.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 s.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,o=n.size||this.configuration.skybox&&this.configuration.skybox.scale||3e3,a=s.Mesh.CreatePlane("BackgroundPlane",o,this.scene),h=new s.BackgroundMaterial("groundmat",this.scene);a.rotation.x=Math.PI/2,a.receiveShadows=n.receiveShadows||!1;var l=e[0].getHierarchyBoundingVectors().min.y;if(a.position.y=l,h.alpha=.9,h.alphaMode=s.Engine.ALPHA_PREMULTIPLIED_PORTERDUFF,h.shadowLevel=.5,h.primaryLevel=1,h.primaryColor=new s.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,(u=new s.Texture("https://assets.babylonjs.com/environments/backgroundGround.png",this.scene)).gammaSpace=!1,u.hasAlpha=!0,h.diffuseTexture=u;else if(n.mirror){var c=new s.MirrorTexture("mirror",512,this.scene);c.mirrorPlane=new s.Plane(0,-1,0,0),c.renderList=c.renderList||[],e.length&&e.forEach(function(e){e&&c.renderList&&c.renderList.push(e)}),h.reflectionTexture=c}else if(n.material&&n.material.diffuseTexture){var u=new s.Texture(n.material.diffuseTexture,this.scene);h.diffuseTexture=u}!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<i.length;++r){i.item(r).style.display="none"}return Promise.resolve(e)}):Promise.reject("Overlay template not found")},t.prototype.showLoadingScreen=function(){var e=this,t=this.templateManager.getTemplate("loadingScreen");return t?t.show(function(t){var i=e.containerElement.getBoundingClientRect();window.getComputedStyle(e.containerElement).position;return t.parent.style.display="flex",t.parent.style.width=i.width+"px",t.parent.style.height=i.height+"px",t.parent.style.opacity="1",t.parent.style.backgroundColor="black",Promise.resolve(t)}):Promise.reject("oading Screen template not found")},t.prototype.hideLoadingScreen=function(){var e=this.templateManager.getTemplate("loadingScreen");return e?e.hide(function(e){e.parent.style.opacity="0";var t=function(){e.parent.removeEventListener("transitionend",t),e.parent.style.display="none"};return e.parent.addEventListener("transitionend",t),Promise.resolve(e)}):Promise.reject("oading Screen template not found")},t.prototype.setupLights=function(e){var t=this;void 0===e&&(e=[]),!(this.configuration.scene||{defaultLight:!0}).defaultLight&&this.configuration.lights&&Object.keys(this.configuration.lights).length&&(this.scene.lights.forEach(function(e){e.dispose()}),Object.keys(this.configuration.lights).forEach(function(i,r){var n=t.configuration.lights&&t.configuration.lights[i]||{name:i,type:0};n.name=i;var o=s.Light.GetConstructorFromName(n.type,n.name,t.scene);if(o){var a=o();if(a.isEnabled()!==!n.disabled&&a.setEnabled(!n.disabled),t.extendClassWithConfig(a,n),a instanceof s.ShadowLight&&n.shadowEnabled){var h=new s.ShadowGenerator(512,a);t.extendClassWithConfig(h,n.shadowConfig||{});var l=h.getShadowMap();if(!l)return;for(var c=l.renderList,u=0;u<e.length;u++)c&&c.push(e[u])}}}))},t.prototype.setupCamera=function(e){void 0===e&&(e=[]);var t=this.configuration.camera||{},i=this.configuration.scene||{autoRotate:!1,defaultCamera:!0};if(this.configuration.camera||!i.defaultCamera){if(t.position&&this.camera.position.copyFromFloats(t.position.x||0,t.position.y||0,t.position.z||0),t.rotation&&(this.camera.rotationQuaternion=new s.Quaternion(t.rotation.x||0,t.rotation.y||0,t.rotation.z||0,t.rotation.w||0)),this.camera.minZ=t.minZ||this.camera.minZ,this.camera.maxZ=t.maxZ||this.camera.maxZ,t.behaviors)for(var r in t.behaviors)this.setCameraBehavior(t.behaviors[r],e);i.autoRotate&&(this.camera.useAutoRotationBehavior=!0)}else i.autoRotate&&(this.camera.useAutoRotationBehavior=!0)},t.prototype.setCameraBehavior=function(e,t){var i,r="object"!=typeof e?e:e.type,n="object"==typeof e?e:{};switch(r){case 0:i=new s.AutoRotationBehavior;break;case 1:i=new s.BouncingBehavior;break;case 2:i=new s.FramingBehavior;break;default:i=null}switch(i&&("object"==typeof e&&this.extendClassWithConfig(i,e),this.camera.addBehavior(i)),r){case 0:case 1:break;case 2:if(n.zoomOnBoundingInfo){var o=t[0].getHierarchyBoundingVectors();i.zoomOnBoundingInfo(o.min,o.max)}}},t.prototype.extendClassWithConfig=function(e,t){var i=this;t&&Object.keys(t).forEach(function(r){if(r in e&&"function"!=typeof e[r]){if("function"==typeof e[r])return;"object"==typeof e[r]?i.extendClassWithConfig(e[r],t[r]):e[r]=t[r]}})},t}(o.AbstractViewer);t.DefaultViewer=a},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=i(4),n=i(17),o=i(20),s=i(0),a=i(29),h=function(){function e(e,t){void 0===t&&(t={});var i=this;this.containerElement=e,e.id?this.baseId=e.id:this.baseId=e.id="bjs"+Math.random().toString(32).substr(2,8),this.onSceneInitObservable=new a.PromiseObservable,this.onEngineInitObservable=new a.PromiseObservable,this.onModelLoadedObservable=new a.PromiseObservable,r.viewerManager.addViewer(this),this.templateManager=new n.TemplateManager(e),this.prepareContainerElement(),o.default.loadConfiguration(t).then(function(e){i.configuration=e,i.configuration.observers&&(i.configuration.observers.onEngineInit&&i.onEngineInitObservable.add(window[i.configuration.observers.onEngineInit]),i.configuration.observers.onSceneInit&&i.onSceneInitObservable.add(window[i.configuration.observers.onSceneInit]),i.configuration.observers.onModelLoaded&&i.onModelLoadedObservable.add(window[i.configuration.observers.onModelLoaded]));var t=i.configuration.templates||{};i.templateManager.initTemplate(t),i.templateManager.onAllLoaded.add(function(){i.onTemplatesLoaded()})})}return e.prototype.getBaseId=function(){return this.baseId},e.prototype.onTemplatesLoaded=function(){var e=this;return this.initEngine().then(function(){return e.loadModel()}).then(function(){return e})},e.prototype.initEngine=function(){var e=this,t=this.templateManager.getCanvas();if(!t)return Promise.reject("Canvas element not found!");var i=this.configuration.engine||{};this.engine=new s.Engine(t,!!i.antialiasing),s.Database.IDBStorageEnabled=!1,window.addEventListener("resize",function(){e.engine.resize()}),this.engine.runRenderLoop(function(){e.scene&&e.scene.render()});var r=Math.max(.5,1/(window.devicePixelRatio||2));return this.engine.setHardwareScalingLevel(r),this.onEngineInitObservable.notifyWithPromise(this.engine).then(function(){return e.engine})},e.prototype.initScene=function(){var e=this;return this.scene&&this.scene.dispose(),this.scene=new s.Scene(this.engine),this.scene.createDefaultCameraOrLight(!0,!0,!0),this.configuration.scene&&this.configuration.scene.debug&&this.scene.debugLayer.show(),this.onSceneInitObservable.notifyWithPromise(this.scene).then(function(){return e.scene})},e.prototype.loadModel=function(e,t){var i=this;void 0===e&&(e=this.configuration.model),void 0===t&&(t=!0),this.configuration.model=e;var r=("string"==typeof e?e:e.url).split("/"),n=r.pop(),o=r.join("/")+"/",a="string"==typeof e?void 0:e.loader;return Promise.resolve().then(function(){return!i.scene||t?i.initScene():i.scene}).then(function(){return new Promise(function(e,t){s.SceneLoader.ImportMesh(void 0,o,n,i.scene,function(t){e(t)},void 0,function(e,i,r){console.log(i,r),t(i)},a)})}).then(function(e){return i.onModelLoadedObservable.notifyWithPromise(e).then(function(){return i.scene})})},e}();t.AbstractViewer=h},function(e,t){e.exports="<viewer></viewer> <loading-screen></loading-screen> <overlay></overlay>"},function(e,t){e.exports="<style>loading-screen{position:absolute;left:0;z-index:100;opacity:1;pointer-events:none;display:flex;justify-content:center;align-items:center;-webkit-transition:opacity 2s ease;-moz-transition:opacity 2s ease;transition:opacity 2s ease}img.loading-image{-webkit-animation:spin 2s linear infinite;animation:spin 2s linear infinite}@-webkit-keyframes spin{0%{-webkit-transform:rotate(0)}100%{-webkit-transform:rotate(360deg)}}@keyframes spin{0%{transform:rotate(0)}100%{transform:rotate(360deg)}}</style> <img class=loading-image src={{loadingImage}}>"},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="<style>viewer{position:relative;overflow:hidden;flex:1;z-index:1;justify-content:center;align-items:center;width:100%;height:100%}.babylonjs-canvas{flex:1;width:100%;height:100%;touch-action:none}</style> <canvas class=babylonjs-canvas id={{canvasId}}> </canvas> <nav-bar></nav-bar>"},function(e,t){e.exports="<style>overlay{position:absolute;z-index:99;opacity:0;display:flex;justify-content:center;align-items:center;-webkit-transition:opacity 1s ease;-moz-transition:opacity 1s ease;transition:opacity 1s ease}.overlay-item{width:100%;height:100%;display:none;align-items:center;justify-content:center;background-color:rgba(121,121,121,.3)}error.overlay-item{background-color:rgba(121,121,121,1)}div#close-button{position:absolute;top:10px;right:10px;width:30px;height:30px;cursor:pointer}div#close-button img{width:100%}</style> <div id=close-button> <img src={{closeImage}} alt={{closeText}}> </div> <help class=overlay-item></help> <error class=overlay-item></error> <share class=overlay-item></share>"},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(30),i(31);var a=i(32);t.InitTags=a.InitTags,e.Promise="undefined"==typeof Promise?i(33).Promise:Promise,t.disableInit=!1,document.addEventListener("DOMContentLoaded",function(e){t.disableInit||a.InitTags()})}).call(t,i(1))},function(e,t,i){var r,n;n=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<n.length;a++)o(n[a]);return o}({1:[function(e,t,i){t.exports={name:"cannon",version:"0.6.2",description:"A lightweight 3D physics engine written in JavaScript.",homepage:"https://github.com/schteppe/cannon.js",author:"Stefan Hedman <schteppe@gmail.com> (http://steffe.se)",keywords:["cannon.js","cannon","physics","engine","3d"],main:"./build/cannon.js",engines:{node:"*"},repository:{type:"git",url:"https://github.com/schteppe/cannon.js.git"},bugs:{url:"https://github.com/schteppe/cannon.js/issues"},licenses:[{type:"MIT"}],devDependencies:{jshint:"latest","uglify-js":"latest",nodeunit:"^0.9.0",grunt:"~0.4.0","grunt-contrib-jshint":"~0.1.1","grunt-contrib-nodeunit":"^0.4.1","grunt-contrib-concat":"~0.1.3","grunt-contrib-uglify":"^0.5.1","grunt-browserify":"^2.1.4","grunt-contrib-yuidoc":"^0.5.2",browserify:"*"},dependencies:{}}},{}],2:[function(e,t,i){t.exports={version:e("../package.json").version,AABB:e("./collision/AABB"),ArrayCollisionMatrix:e("./collision/ArrayCollisionMatrix"),Body:e("./objects/Body"),Box:e("./shapes/Box"),Broadphase:e("./collision/Broadphase"),Constraint:e("./constraints/Constraint"),ContactEquation:e("./equations/ContactEquation"),Narrowphase:e("./world/Narrowphase"),ConeTwistConstraint:e("./constraints/ConeTwistConstraint"),ContactMaterial:e("./material/ContactMaterial"),ConvexPolyhedron:e("./shapes/ConvexPolyhedron"),Cylinder:e("./shapes/Cylinder"),DistanceConstraint:e("./constraints/DistanceConstraint"),Equation:e("./equations/Equation"),EventTarget:e("./utils/EventTarget"),FrictionEquation:e("./equations/FrictionEquation"),GSSolver:e("./solver/GSSolver"),GridBroadphase:e("./collision/GridBroadphase"),Heightfield:e("./shapes/Heightfield"),HingeConstraint:e("./constraints/HingeConstraint"),LockConstraint:e("./constraints/LockConstraint"),Mat3:e("./math/Mat3"),Material:e("./material/Material"),NaiveBroadphase:e("./collision/NaiveBroadphase"),ObjectCollisionMatrix:e("./collision/ObjectCollisionMatrix"),Pool:e("./utils/Pool"),Particle:e("./shapes/Particle"),Plane:e("./shapes/Plane"),PointToPointConstraint:e("./constraints/PointToPointConstraint"),Quaternion:e("./math/Quaternion"),Ray:e("./collision/Ray"),RaycastVehicle:e("./objects/RaycastVehicle"),RaycastResult:e("./collision/RaycastResult"),RigidVehicle:e("./objects/RigidVehicle"),RotationalEquation:e("./equations/RotationalEquation"),RotationalMotorEquation:e("./equations/RotationalMotorEquation"),SAPBroadphase:e("./collision/SAPBroadphase"),SPHSystem:e("./objects/SPHSystem"),Shape:e("./shapes/Shape"),Solver:e("./solver/Solver"),Sphere:e("./shapes/Sphere"),SplitSolver:e("./solver/SplitSolver"),Spring:e("./objects/Spring"),Trimesh:e("./shapes/Trimesh"),Vec3:e("./math/Vec3"),Vec3Pool:e("./utils/Vec3Pool"),World:e("./world/World")}},{"../package.json":1,"./collision/AABB":3,"./collision/ArrayCollisionMatrix":4,"./collision/Broadphase":5,"./collision/GridBroadphase":6,"./collision/NaiveBroadphase":7,"./collision/ObjectCollisionMatrix":8,"./collision/Ray":9,"./collision/RaycastResult":10,"./collision/SAPBroadphase":11,"./constraints/ConeTwistConstraint":12,"./constraints/Constraint":13,"./constraints/DistanceConstraint":14,"./constraints/HingeConstraint":15,"./constraints/LockConstraint":16,"./constraints/PointToPointConstraint":17,"./equations/ContactEquation":19,"./equations/Equation":20,"./equations/FrictionEquation":21,"./equations/RotationalEquation":22,"./equations/RotationalMotorEquation":23,"./material/ContactMaterial":24,"./material/Material":25,"./math/Mat3":27,"./math/Quaternion":28,"./math/Vec3":30,"./objects/Body":31,"./objects/RaycastVehicle":32,"./objects/RigidVehicle":33,"./objects/SPHSystem":34,"./objects/Spring":35,"./shapes/Box":37,"./shapes/ConvexPolyhedron":38,"./shapes/Cylinder":39,"./shapes/Heightfield":40,"./shapes/Particle":41,"./shapes/Plane":42,"./shapes/Shape":43,"./shapes/Sphere":44,"./shapes/Trimesh":45,"./solver/GSSolver":46,"./solver/Solver":47,"./solver/SplitSolver":48,"./utils/EventTarget":49,"./utils/Pool":51,"./utils/Vec3Pool":54,"./world/Narrowphase":55,"./world/World":56}],3:[function(e,t,i){var r=e("../math/Vec3");e("../utils/Utils");function n(e){e=e||{},this.lowerBound=new r,e.lowerBound&&this.lowerBound.copy(e.lowerBound),this.upperBound=new r,e.upperBound&&this.upperBound.copy(e.upperBound)}t.exports=n;var o=new r;n.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;h<e.length;h++){var l=e[h];a&&(a.vmult(l,o),l=o),l.x>s.x&&(s.x=l.x),l.x<n.x&&(n.x=l.x),l.y>s.y&&(s.y=l.y),l.y<n.y&&(n.y=l.y),l.z>s.z&&(s.z=l.z),l.z<n.z&&(n.z=l.z)}return t&&(t.vadd(n,n),t.vadd(s,s)),r&&(n.x-=r,n.y-=r,n.z-=r,s.x+=r,s.y+=r,s.z+=r),this},n.prototype.copy=function(e){return this.lowerBound.copy(e.lowerBound),this.upperBound.copy(e.upperBound),this},n.prototype.clone=function(){return(new n).copy(this)},n.prototype.extend=function(e){var t=e.lowerBound.x;this.lowerBound.x>t&&(this.lowerBound.x=t);var i=e.upperBound.x;this.upperBound.x<i&&(this.upperBound.x=i);t=e.lowerBound.y;this.lowerBound.y>t&&(this.lowerBound.y=t);i=e.upperBound.y;this.upperBound.y<i&&(this.upperBound.y=i);t=e.lowerBound.z;this.lowerBound.z>t&&(this.lowerBound.z=t);i=e.upperBound.z;this.upperBound.z<i&&(this.upperBound.z=i)},n.prototype.overlaps=function(e){var t=this.lowerBound,i=this.upperBound,r=e.lowerBound,n=e.upperBound;return(r.x<=i.x&&i.x<=n.x||t.x<=n.x&&n.x<=i.x)&&(r.y<=i.y&&i.y<=n.y||t.y<=n.y&&n.y<=i.y)&&(r.z<=i.z&&i.z<=n.z||t.z<=n.z&&n.z<=i.z)},n.prototype.contains=function(e){var t=this.lowerBound,i=this.upperBound,r=e.lowerBound,n=e.upperBound;return t.x<=r.x&&i.x>=n.x&&t.y<=r.y&&i.y>=n.y&&t.z<=r.z&&i.z>=n.z},n.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 r,new r,new r,new r,new r,new r,new r,new r];n.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)},n.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){var r=e("../objects/Body"),n=e("../math/Vec3"),o=e("../math/Quaternion");e("../shapes/Shape"),e("../shapes/Plane");function s(){this.world=null,this.useBoundingBoxes=!1,this.dirty=!0}t.exports=s,s.prototype.collisionPairs=function(e,t,i){throw new Error("collisionPairs not implemented for this BroadPhase class!")};var a=r.STATIC|r.KINEMATIC;s.prototype.needBroadphaseCollision=function(e,t){return 0!=(e.collisionFilterGroup&t.collisionFilterMask)&&0!=(t.collisionFilterGroup&e.collisionFilterMask)&&(0==(e.type&a)&&e.sleepState!==r.SLEEPING||0==(t.type&a)&&t.sleepState!==r.SLEEPING)},s.prototype.intersectionTest=function(e,t,i,r){this.useBoundingBoxes?this.doBoundingBoxBroadphase(e,t,i,r):this.doBoundingSphereBroadphase(e,t,i,r)};var h=new n;new n,new o,new n;s.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()<o&&(i.push(e),r.push(t))},s.prototype.doBoundingBoxBroadphase=function(e,t,i,r){e.aabbNeedsUpdate&&e.computeAABB(),t.aabbNeedsUpdate&&t.computeAABB(),e.aabb.overlaps(t.aabb)&&(i.push(e),r.push(t))};var l={keys:[]},c=[],u=[];s.prototype.makePairsUnique=function(e,t){for(var i=l,r=c,n=u,o=e.length,s=0;s!==o;s++)r[s]=e[s],n[s]=t[s];e.length=0,t.length=0;for(s=0;s!==o;s++){var a=r[s].id,h=n[s].id;i[p=a<h?a+","+h:h+","+a]=s,i.keys.push(p)}for(s=0;s!==i.keys.length;s++){var p,f=i[p=i.keys.pop()];e.push(r[f]),t.push(n[f]),delete i[p]}},s.prototype.setWorld=function(e){};var p=new n;s.boundingSphereCheck=function(e,t){var i=p;return e.position.vsub(t.position,i),Math.pow(e.shape.boundingSphereRadius+t.shape.boundingSphereRadius,2)>i.norm2()},s.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){t.exports=s;var r=e("./Broadphase"),n=e("../math/Vec3"),o=e("../shapes/Shape");function s(e,t,i,o,s){r.apply(this),this.nx=i||10,this.ny=o||10,this.nz=s||10,this.aabbMin=e||new n(100,100,100),this.aabbMax=t||new n(-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<a;h++)this.bins[h]=[],this.binLengths[h]=0}s.prototype=new r,s.prototype.constructor=s;var a=new n;new n;s.prototype.collisionPairs=function(e,t,i){for(var r=e.numObjects(),n=e.bodies,s=this.aabbMax,h=this.aabbMin,l=this.nx,c=this.ny,u=this.nz,p=c*u,f=u,d=1,m=s.x,g=s.y,_=s.z,v=h.x,y=h.y,b=h.z,x=l/(m-v),T=c/(g-y),E=u/(_-b),A=(m-v)/l,P=(g-y)/c,M=(_-b)/u,S=.5*Math.sqrt(A*A+P*P+M*M),C=o.types,R=C.SPHERE,O=C.PLANE,I=(C.BOX,C.COMPOUND,C.CONVEXPOLYHEDRON,this.bins),w=this.binLengths,D=this.bins.length,L=0;L!==D;L++)w[L]=0;var B=Math.ceil;h=Math.min,s=Math.max;function N(e,t,i,r,n,o,s){var a=(e-v)*x|0,h=(t-y)*T|0,m=(i-b)*E|0,g=B((r-v)*x),_=B((n-y)*T),A=B((o-b)*E);a<0?a=0:a>=l&&(a=l-1),h<0?h=0:h>=c&&(h=c-1),m<0?m=0:m>=u&&(m=u-1),g<0?g=0:g>=l&&(g=l-1),_<0?_=0:_>=c&&(_=c-1),A<0?A=0:A>=u&&(A=u-1),h*=f,m*=d,g*=p,_*=f,A*=d;for(var P=a*=p;P<=g;P+=p)for(var M=h;M<=_;M+=f)for(var S=m;S<=A;S+=d){var C=P+M+S;I[C][w[C]++]=s}}for(L=0;L!==r;L++){var F=(ie=n[L]).shape;switch(F.type){case R:var V=ie.position.x,k=ie.position.y,U=ie.position.z,z=F.radius;N(V-z,k-z,U-z,V+z,k+z,U+z,ie);break;case O:F.worldNormalNeedsUpdate&&F.computeWorldNormal(ie.quaternion);var G=F.worldNormal,W=v+.5*A-ie.position.x,H=y+.5*P-ie.position.y,j=b+.5*M-ie.position.z,X=a;X.set(W,H,j);for(var Y=0,K=0;Y!==l;Y++,K+=p,X.y=H,X.x+=A)for(var Q=0,Z=0;Q!==c;Q++,Z+=f,X.z=j,X.y+=P)for(var q=0,J=0;q!==u;q++,J+=d,X.z+=M)if(X.dot(G)<S){var $=K+Z+J;I[$][w[$]++]=ie}break;default:ie.aabbNeedsUpdate&&ie.computeAABB(),N(ie.aabb.lowerBound.x,ie.aabb.lowerBound.y,ie.aabb.lowerBound.z,ie.aabb.upperBound.x,ie.aabb.upperBound.y,ie.aabb.upperBound.z,ie)}}for(L=0;L!==D;L++){var ee=w[L];if(ee>1){var te=I[L];for(Y=0;Y!==ee;Y++){var ie=te[Y];for(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){t.exports=o;var r=e("./Broadphase"),n=e("./AABB");function o(){r.apply(this)}o.prototype=new r,o.prototype.constructor=o,o.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 n;o.prototype.aabbQuery=function(e,t,i){i=i||[];for(var r=0;r<e.bodies.length;r++){var n=e.bodies[r];n.aabbNeedsUpdate&&n.computeAABB(),n.aabb.overlaps(t)&&i.push(n)}return i}},{"./AABB":3,"./Broadphase":5}],8:[function(e,t,i){function r(){this.matrix={}}t.exports=r,r.prototype.get=function(e,t){if(e=e.id,(t=t.id)>e){var i=t;t=e,e=i}return e+"-"+t in this.matrix},r.prototype.set=function(e,t,i){if(e=e.id,(t=t.id)>e){var r=t;t=e,e=r}i?this.matrix[e+"-"+t]=!0:delete this.matrix[e+"-"+t]},r.prototype.reset=function(){this.matrix={}},r.prototype.setNumObjects=function(e){}},{}],9:[function(e,t,i){t.exports=l;var r=e("../math/Vec3"),n=e("../math/Quaternion"),o=e("../math/Transform"),s=(e("../shapes/ConvexPolyhedron"),e("../shapes/Box"),e("../collision/RaycastResult")),a=e("../shapes/Shape"),h=e("../collision/AABB");function l(e,t){this.from=e?e.clone():new r,this.to=t?t.clone():new r,this._direction=new r,this.precision=1e-4,this.checkCollisionResponse=!0,this.skipBackfaces=!1,this.collisionFilterMask=-1,this.collisionFilterGroup=-1,this.mode=l.ANY,this.result=new s,this.hasHit=!1,this.callback=function(e){}}l.prototype.constructor=l,l.CLOSEST=1,l.ANY=2,l.ALL=4;var c=new h,u=[];l.prototype.intersectWorld=function(e,t){return this.mode=t.mode||l.ANY,this.result=t.result||new s,this.skipBackfaces=!!t.skipBackfaces,this.collisionFilterMask=void 0!==t.collisionFilterMask?t.collisionFilterMask:-1,this.collisionFilterGroup=void 0!==t.collisionFilterGroup?t.collisionFilterGroup:-1,t.from&&this.from.copy(t.from),t.to&&this.to.copy(t.to),this.callback=t.callback||function(){},this.hasHit=!1,this.result.reset(),this._updateDirection(),this.getAABB(c),u.length=0,e.broadphase.aabbQuery(e,c,u),this.intersectBodies(u),this.hasHit};var p=new r,f=new r;function d(e,t,i,r){r.vsub(t,L),i.vsub(t,p),e.vsub(t,f);var n,o,s=L.dot(L),a=L.dot(p),h=L.dot(f),l=p.dot(p),c=p.dot(f);return(n=l*h-a*c)>=0&&(o=s*c-a*h)>=0&&n+o<s*l-a*a}l.pointInTriangle=d;var m=new r,g=new n;l.prototype.intersectBody=function(e,t){t&&(this.result=t,this._updateDirection());var i=this.checkCollisionResponse;if((!i||e.collisionResponse)&&0!=(this.collisionFilterGroup&e.collisionFilterMask)&&0!=(e.collisionFilterGroup&this.collisionFilterMask))for(var r=m,n=g,o=0,s=e.shapes.length;o<s;o++){var a=e.shapes[o];if((!i||a.collisionResponse)&&(e.quaternion.mult(e.shapeOrientations[o],n),e.quaternion.vmult(e.shapeOffsets[o],r),r.vadd(e.position,r),this.intersectShape(a,n,r,e),this.result._shouldStop))break}},l.prototype.intersectBodies=function(e,t){t&&(this.result=t,this._updateDirection());for(var i=0,r=e.length;!this.result._shouldStop&&i<r;i++)this.intersectBody(e[i])},l.prototype._updateDirection=function(){this.to.vsub(this.from,this._direction),this._direction.normalize()},l.prototype.intersectShape=function(e,t,i,r){if(!(function(e,t,i){i.vsub(e,L);var r=L.dot(t);return t.mult(r,B),B.vadd(e,B),i.distanceTo(B)}(this.from,this._direction,i)>e.boundingSphereRadius)){var n=this[e.type];n&&n.call(this,e,t,i,r)}};new r,new r;var _=new r,v=new r,y=new r,b=new r;new r,new s;l.prototype.intersectBox=function(e,t,i,r){return this.intersectConvex(e.convexPolyhedronRepresentation,t,i,r)},l.prototype[a.types.BOX]=l.prototype.intersectBox,l.prototype.intersectPlane=function(e,t,i,n){var o=this.from,s=this.to,a=this._direction,h=new r(0,0,1);t.vmult(h,h);var l=new r;o.vsub(i,l);var c=l.dot(h);if(s.vsub(i,l),!(c*l.dot(h)>0||o.distanceTo(s)<c)){var u=h.dot(a);if(!(Math.abs(u)<this.precision)){var p=new r,f=new r,d=new r;o.vsub(i,p);var m=-h.dot(p)/u;a.scale(m,f),o.vadd(f,d),this.reportIntersection(h,d,e,n,-1)}}},l.prototype[a.types.PLANE]=l.prototype.intersectPlane,l.prototype.getAABB=function(e){var t=this.to,i=this.from;e.lowerBound.x=Math.min(t.x,i.x),e.lowerBound.y=Math.min(t.y,i.y),e.lowerBound.z=Math.min(t.z,i.z),e.upperBound.x=Math.max(t.x,i.x),e.upperBound.y=Math.max(t.y,i.y),e.upperBound.z=Math.max(t.z,i.z)};var x={faceList:[0]};l.prototype.intersectHeightfield=function(e,t,i,n){e.data,e.elementSize;var s=new r,a=new l(this.from,this.to);o.pointToLocalFrame(i,t,a.from,a.from),o.pointToLocalFrame(i,t,a.to,a.to);var h=[],c=null,u=null,p=null,f=null,d=e.getIndexOfPosition(a.from.x,a.from.y,h,!1);if(d&&(c=h[0],u=h[1],p=h[0],f=h[1]),(d=e.getIndexOfPosition(a.to.x,a.to.y,h,!1))&&((null===c||h[0]<c)&&(c=h[0]),(null===p||h[0]>p)&&(p=h[0]),(null===u||h[1]<u)&&(u=h[1]),(null===f||h[1]>f)&&(f=h[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),o.pointToWorldFrame(i,t,e.pillarOffset,s),this.intersectConvex(e.pillarConvex,t,s,n,x),this.result._shouldStop)return;e.getConvexTrianglePillar(g,_,!0),o.pointToWorldFrame(i,t,e.pillarOffset,s),this.intersectConvex(e.pillarConvex,t,s,n,x)}}},l.prototype[a.types.HEIGHTFIELD]=l.prototype.intersectHeightfield;var T=new r,E=new r;l.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))}},l.prototype[a.types.SPHERE]=l.prototype.intersectSphere;var A=new r,P=(new r,new r,new r);l.prototype.intersectConvex=function(e,t,i,r,n){for(var o=A,s=P,a=n&&n.faceList||null,h=e.faces,l=e.vertices,c=e.faceNormals,u=this._direction,p=this.from,f=this.to,m=p.distanceTo(f),g=a?a.length:h.length,x=this.result,T=0;!x._shouldStop&&T<g;T++){var E=a?a[T]:T,M=h[E],S=c[E],C=t,R=i;s.copy(l[M[0]]),C.vmult(s,s),s.vadd(R,s),s.vsub(p,s),C.vmult(S,o);var O=u.dot(o);if(!(Math.abs(O)<this.precision)){var I=o.dot(s)/O;if(!(I<0)){u.mult(I,_),_.vadd(p,_),v.copy(l[M[0]]),C.vmult(v,v),R.vadd(v,v);for(var w=1;!x._shouldStop&&w<M.length-1;w++){y.copy(l[M[w]]),b.copy(l[M[w+1]]),C.vmult(y,y),C.vmult(b,b),R.vadd(y,y),R.vadd(b,b);var D=_.distanceTo(p);!d(_,v,y,b)&&!d(_,y,v,b)||D>m||this.reportIntersection(o,_,e,r,E)}}}}},l.prototype[a.types.CONVEXPOLYHEDRON]=l.prototype.intersectConvex;var M=new r,S=new r,C=new r,R=new r,O=new r,I=new r,w=(new h,[]),D=new o;l.prototype.intersectTrimesh=function(e,t,i,r,n){var s=M,a=w,h=D,l=P,c=S,u=C,p=R,f=I,m=O,g=(n&&n.faceList,e.indices),x=(e.vertices,e.faceNormals,this.from),T=this.to,E=this._direction;h.position.copy(i),h.quaternion.copy(t),o.vectorToLocalFrame(i,t,E,c),o.pointToLocalFrame(i,t,x,u),o.pointToLocalFrame(i,t,T,p);var A=u.distanceSquared(p);e.tree.rayQuery(this,h,a);for(var L=0,B=a.length;!this.result._shouldStop&&L!==B;L++){var N=a[L];e.getNormal(N,s),e.getVertex(g[3*N],v),v.vsub(u,l);var F=c.dot(s),V=s.dot(l)/F;if(!(V<0)){c.scale(V,_),_.vadd(u,_),e.getVertex(g[3*N+1],y),e.getVertex(g[3*N+2],b);var k=_.distanceSquared(u);!d(_,y,v,b)&&!d(_,v,y,b)||k>A||(o.vectorToWorldFrame(t,s,m),o.pointToWorldFrame(i,t,_,f),this.reportIntersection(m,f,e,r,N))}}a.length=0},l.prototype[a.types.TRIMESH]=l.prototype.intersectTrimesh,l.prototype.reportIntersection=function(e,t,i,r,n){var o=this.from,s=this.to,a=o.distanceTo(t),h=this.result;if(!(this.skipBackfaces&&e.dot(this._direction)>0))switch(h.hitFaceIndex=void 0!==n?n:-1,this.mode){case l.ALL:this.hasHit=!0,h.set(o,s,e,t,i,r,a),h.hasHit=!0,this.callback(h);break;case l.CLOSEST:(a<h.distance||!h.hasHit)&&(this.hasHit=!0,h.hasHit=!0,h.set(o,s,e,t,i,r,a));break;case l.ANY:this.hasHit=!0,h.hasHit=!0,h.set(o,s,e,t,i,r,a),h._shouldStop=!0}};var L=new r,B=new r},{"../collision/AABB":3,"../collision/RaycastResult":10,"../math/Quaternion":28,"../math/Transform":29,"../math/Vec3":30,"../shapes/Box":37,"../shapes/ConvexPolyhedron":38,"../shapes/Shape":43}],10:[function(e,t,i){var r=e("../math/Vec3");function n(){this.rayFromWorld=new r,this.rayToWorld=new r,this.hitNormalWorld=new r,this.hitPointWorld=new r,this.hasHit=!1,this.shape=null,this.body=null,this.hitFaceIndex=-1,this.distance=-1,this._shouldStop=!1}t.exports=n,n.prototype.reset=function(){this.rayFromWorld.setZero(),this.rayToWorld.setZero(),this.hitNormalWorld.setZero(),this.hitPointWorld.setZero(),this.hasHit=!1,this.shape=null,this.body=null,this.hitFaceIndex=-1,this.distance=-1,this._shouldStop=!1},n.prototype.abort=function(){this._shouldStop=!0},n.prototype.set=function(e,t,i,r,n,o,s){this.rayFromWorld.copy(e),this.rayToWorld.copy(t),this.hitNormalWorld.copy(i),this.hitPointWorld.copy(r),this.shape=n,this.body=o,this.distance=s}},{"../math/Vec3":30}],11:[function(e,t,i){e("../shapes/Shape");var r=e("../collision/Broadphase");function n(e){r.apply(this),this.axisList=[],this.world=null,this.axisIndex=0;var t=this.axisList;this._addBodyHandler=function(e){t.push(e.body)},this._removeBodyHandler=function(e){var i=t.indexOf(e.body);-1!==i&&t.splice(i,1)},e&&this.setWorld(e)}t.exports=n,n.prototype=new r,n.prototype.setWorld=function(e){this.axisList.length=0;for(var t=0;t<e.bodies.length;t++)this.axisList.push(e.bodies[t]);e.removeEventListener("addBody",this._addBodyHandler),e.removeEventListener("removeBody",this._removeBodyHandler),e.addEventListener("addBody",this._addBodyHandler),e.addEventListener("removeBody",this._removeBodyHandler),this.world=e,this.dirty=!0},n.insertionSortX=function(e){for(var t=1,i=e.length;t<i;t++){for(var r=e[t],n=t-1;n>=0&&!(e[n].aabb.lowerBound.x<=r.aabb.lowerBound.x);n--)e[n+1]=e[n];e[n+1]=r}return e},n.insertionSortY=function(e){for(var t=1,i=e.length;t<i;t++){for(var r=e[t],n=t-1;n>=0&&!(e[n].aabb.lowerBound.y<=r.aabb.lowerBound.y);n--)e[n+1]=e[n];e[n+1]=r}return e},n.insertionSortZ=function(e){for(var t=1,i=e.length;t<i;t++){for(var r=e[t],n=t-1;n>=0&&!(e[n].aabb.lowerBound.z<=r.aabb.lowerBound.z);n--)e[n+1]=e[n];e[n+1]=r}return e},n.prototype.collisionPairs=function(e,t,i){var r,o,s=this.axisList,a=s.length,h=this.axisIndex;for(this.dirty&&(this.sortList(),this.dirty=!1),r=0;r!==a;r++){var l=s[r];for(o=r+1;o<a;o++){var c=s[o];if(this.needBroadphaseCollision(l,c)){if(!n.checkBounds(l,c,h))break;this.intersectionTest(l,c,t,i)}}}},n.prototype.sortList=function(){for(var e=this.axisList,t=this.axisIndex,i=e.length,r=0;r!==i;r++){var o=e[r];o.aabbNeedsUpdate&&o.computeAABB()}0===t?n.insertionSortX(e):1===t?n.insertionSortY(e):2===t&&n.insertionSortZ(e)},n.checkBounds=function(e,t,i){var r,n;0===i?(r=e.position.x,n=t.position.x):1===i?(r=e.position.y,n=t.position.y):2===i&&(r=e.position.z,n=t.position.z);var o=e.boundingRadius,s=t.boundingRadius;return n-s<r+o},n.prototype.autoDetectAxis=function(){for(var e=0,t=0,i=0,r=0,n=0,o=0,s=this.axisList,a=s.length,h=1/a,l=0;l!==a;l++){var c=s[l],u=c.position.x;e+=u,t+=u*u;var p=c.position.y;i+=p,r+=p*p;var f=c.position.z;n+=f,o+=f*f}var d=t-e*e*h,m=r-i*i*h,g=o-n*n*h;this.axisIndex=d>m?d>g?0:2:m>g?1:2},n.prototype.aabbQuery=function(e,t,i){i=i||[],this.dirty&&(this.sortList(),this.dirty=!1);var r=this.axisIndex,n="x";1===r&&(n="y"),2===r&&(n="z");for(var o=this.axisList,s=(t.lowerBound[n],t.upperBound[n],0);s<o.length;s++){var a=o[s];a.aabbNeedsUpdate&&a.computeAABB(),a.aabb.overlaps(t)&&i.push(a)}return i}},{"../collision/Broadphase":5,"../shapes/Shape":43}],12:[function(e,t,i){t.exports=a;e("./Constraint");var r=e("./PointToPointConstraint"),n=e("../equations/ConeEquation"),o=e("../equations/RotationalEquation"),s=(e("../equations/ContactEquation"),e("../math/Vec3"));function a(e,t,i){var a=void 0!==(i=i||{}).maxForce?i.maxForce:1e6,h=i.pivotA?i.pivotA.clone():new s,l=i.pivotB?i.pivotB.clone():new s;this.axisA=i.axisA?i.axisA.clone():new s,this.axisB=i.axisB?i.axisB.clone():new s,r.call(this,e,h,t,l,a),this.collideConnected=!!i.collideConnected,this.angle=void 0!==i.angle?i.angle:0;var c=this.coneEquation=new n(e,t,i),u=this.twistEquation=new o(e,t,i);this.twistAngle=void 0!==i.twistAngle?i.twistAngle:0,c.maxForce=0,c.minForce=-a,u.maxForce=0,u.minForce=-a,this.equations.push(c,u)}a.prototype=new r,a.constructor=a;new s,new s;a.prototype.update=function(){var e=this.bodyA,t=this.bodyB,i=this.coneEquation,n=this.twistEquation;r.prototype.update.call(this),e.vectorToWorldFrame(this.axisA,i.axisA),t.vectorToWorldFrame(this.axisB,i.axisB),this.axisA.tangents(n.axisA,n.axisA),e.vectorToWorldFrame(n.axisA,n.axisA),this.axisB.tangents(n.axisB,n.axisB),t.vectorToWorldFrame(n.axisB,n.axisB),i.angle=this.angle,n.maxAngle=this.twistAngle}},{"../equations/ConeEquation":18,"../equations/ContactEquation":19,"../equations/RotationalEquation":22,"../math/Vec3":30,"./Constraint":13,"./PointToPointConstraint":17}],13:[function(e,t,i){t.exports=n;var r=e("../utils/Utils");function n(e,t,i){i=r.defaults(i,{collideConnected:!0,wakeUpBodies:!0}),this.equations=[],this.bodyA=e,this.bodyB=t,this.id=n.idCounter++,this.collideConnected=i.collideConnected,i.wakeUpBodies&&(e&&e.wakeUp(),t&&t.wakeUp())}n.prototype.update=function(){throw new Error("method update() not implmemented in this Constraint subclass!")},n.prototype.enable=function(){for(var e=this.equations,t=0;t<e.length;t++)e[t].enabled=!0},n.prototype.disable=function(){for(var e=this.equations,t=0;t<e.length;t++)e[t].enabled=!1},n.idCounter=0},{"../utils/Utils":53}],14:[function(e,t,i){t.exports=o;var r=e("./Constraint"),n=e("../equations/ContactEquation");function o(e,t,i,o){r.call(this,e,t),void 0===i&&(i=e.position.distanceTo(t.position)),void 0===o&&(o=1e6),this.distance=i;var s=this.distanceEquation=new n(e,t);this.equations.push(s),s.minForce=-o,s.maxForce=o}o.prototype=new r,o.prototype.update=function(){var e=this.bodyA,t=this.bodyB,i=this.distanceEquation,r=.5*this.distance,n=i.ni;t.position.vsub(e.position,n),n.normalize(),n.mult(r,i.ri),n.mult(-r,i.rj)}},{"../equations/ContactEquation":19,"./Constraint":13}],15:[function(e,t,i){t.exports=a;e("./Constraint");var r=e("./PointToPointConstraint"),n=e("../equations/RotationalEquation"),o=e("../equations/RotationalMotorEquation"),s=(e("../equations/ContactEquation"),e("../math/Vec3"));function a(e,t,i){var a=void 0!==(i=i||{}).maxForce?i.maxForce:1e6,h=i.pivotA?i.pivotA.clone():new s,l=i.pivotB?i.pivotB.clone():new s;r.call(this,e,h,t,l,a),(this.axisA=i.axisA?i.axisA.clone():new s(1,0,0)).normalize(),(this.axisB=i.axisB?i.axisB.clone():new s(1,0,0)).normalize();var c=this.rotationalEquation1=new n(e,t,i),u=this.rotationalEquation2=new n(e,t,i),p=this.motorEquation=new o(e,t,a);p.enabled=!1,this.equations.push(c,u,p)}a.prototype=new r,a.constructor=a,a.prototype.enableMotor=function(){this.motorEquation.enabled=!0},a.prototype.disableMotor=function(){this.motorEquation.enabled=!1},a.prototype.setMotorSpeed=function(e){this.motorEquation.targetVelocity=e},a.prototype.setMotorMaxForce=function(e){this.motorEquation.maxForce=e,this.motorEquation.minForce=-e};var h=new s,l=new s;a.prototype.update=function(){var e=this.bodyA,t=this.bodyB,i=this.motorEquation,n=this.rotationalEquation1,o=this.rotationalEquation2,s=h,a=l,c=this.axisA,u=this.axisB;r.prototype.update.call(this),e.quaternion.vmult(c,s),t.quaternion.vmult(u,a),s.tangents(n.axisA,o.axisA),n.axisB.copy(a),o.axisB.copy(a),this.motorEquation.enabled&&(e.quaternion.vmult(this.axisA,i.axisA),t.quaternion.vmult(this.axisB,i.axisB))}},{"../equations/ContactEquation":19,"../equations/RotationalEquation":22,"../equations/RotationalMotorEquation":23,"../math/Vec3":30,"./Constraint":13,"./PointToPointConstraint":17}],16:[function(e,t,i){t.exports=s;e("./Constraint");var r=e("./PointToPointConstraint"),n=e("../equations/RotationalEquation"),o=(e("../equations/RotationalMotorEquation"),e("../equations/ContactEquation"),e("../math/Vec3"));function s(e,t,i){var s=void 0!==(i=i||{}).maxForce?i.maxForce:1e6,a=new o,h=new o,l=new o;e.position.vadd(t.position,l),l.scale(.5,l),t.pointToLocalFrame(l,h),e.pointToLocalFrame(l,a),r.call(this,e,a,t,h,s);var c=this.rotationalEquation1=new n(e,t,i),u=this.rotationalEquation2=new n(e,t,i),p=this.rotationalEquation3=new n(e,t,i);this.equations.push(c,u,p)}s.prototype=new r,s.constructor=s;new o,new o;s.prototype.update=function(){var e=this.bodyA,t=this.bodyB,i=(this.motorEquation,this.rotationalEquation1),n=this.rotationalEquation2,s=this.rotationalEquation3;r.prototype.update.call(this),e.vectorToWorldFrame(o.UNIT_X,i.axisA),t.vectorToWorldFrame(o.UNIT_Y,i.axisB),e.vectorToWorldFrame(o.UNIT_Y,n.axisA),t.vectorToWorldFrame(o.UNIT_Z,n.axisB),e.vectorToWorldFrame(o.UNIT_Z,s.axisA),t.vectorToWorldFrame(o.UNIT_X,s.axisB)}},{"../equations/ContactEquation":19,"../equations/RotationalEquation":22,"../equations/RotationalMotorEquation":23,"../math/Vec3":30,"./Constraint":13,"./PointToPointConstraint":17}],17:[function(e,t,i){t.exports=s;var r=e("./Constraint"),n=e("../equations/ContactEquation"),o=e("../math/Vec3");function s(e,t,i,s,a){r.call(this,e,i),a=void 0!==a?a:1e6,this.pivotA=t?t.clone():new o,this.pivotB=s?s.clone():new o;var h=this.equationX=new n(e,i),l=this.equationY=new n(e,i),c=this.equationZ=new n(e,i);this.equations.push(h,l,c),h.minForce=l.minForce=c.minForce=-a,h.maxForce=l.maxForce=c.maxForce=a,h.ni.set(1,0,0),l.ni.set(0,1,0),c.ni.set(0,0,1)}s.prototype=new r,s.prototype.update=function(){var e=this.bodyA,t=this.bodyB,i=this.equationX,r=this.equationY,n=this.equationZ;e.quaternion.vmult(this.pivotA,i.ri),t.quaternion.vmult(this.pivotB,i.rj),r.ri.copy(i.ri),r.rj.copy(i.rj),n.ri.copy(i.ri),n.rj.copy(i.rj)}},{"../equations/ContactEquation":19,"../math/Vec3":30,"./Constraint":13}],18:[function(e,t,i){t.exports=o;var r=e("../math/Vec3"),n=(e("../math/Mat3"),e("./Equation"));function o(e,t,i){var o=void 0!==(i=i||{}).maxForce?i.maxForce:1e6;n.call(this,e,t,-o,o),this.axisA=i.axisA?i.axisA.clone():new r(1,0,0),this.axisB=i.axisB?i.axisB.clone():new r(0,1,0),this.angle=void 0!==i.angle?i.angle:0}o.prototype=new n,o.prototype.constructor=o;var s=new r,a=new r;o.prototype.computeB=function(e){var t=this.a,i=this.b,r=this.axisA,n=this.axisB,o=s,h=a,l=this.jacobianElementA,c=this.jacobianElementB;return r.cross(n,o),n.cross(r,h),l.rotational.copy(h),c.rotational.copy(o),-(Math.cos(this.angle)-r.dot(n))*t-this.computeGW()*i-e*this.computeGiMf()}},{"../math/Mat3":27,"../math/Vec3":30,"./Equation":20}],19:[function(e,t,i){t.exports=o;var r=e("./Equation"),n=e("../math/Vec3");e("../math/Mat3");function o(e,t,i){i=void 0!==i?i:1e6,r.call(this,e,t,0,i),this.restitution=0,this.ri=new n,this.rj=new n,this.ni=new n}o.prototype=new r,o.prototype.constructor=o;var s=new n,a=new n,h=new n;o.prototype.computeB=function(e){var t=this.a,i=this.b,r=this.bi,n=this.bj,o=this.ri,l=this.rj,c=s,u=a,p=r.velocity,f=r.angularVelocity,d=(r.force,r.torque,n.velocity),m=n.angularVelocity,g=(n.force,n.torque,h),_=this.jacobianElementA,v=this.jacobianElementB,y=this.ni;o.cross(y,c),l.cross(y,u),y.negate(_.spatial),c.negate(_.rotational),v.spatial.copy(y),v.rotational.copy(u),g.copy(n.position),g.vadd(l,g),g.vsub(r.position,g),g.vsub(o,g);var b=y.dot(g),x=this.restitution+1;return-b*t-(x*d.dot(y)-x*p.dot(y)+m.dot(u)-f.dot(c))*i-e*this.computeGiMf()};var l=new n,c=new n,u=new n,p=new n,f=new n;o.prototype.getImpactVelocityAlongNormal=function(){var e=l,t=c,i=u,r=p,n=f;return this.bi.position.vadd(this.ri,i),this.bj.position.vadd(this.rj,r),this.bi.getVelocityAtWorldPoint(i,e),this.bj.getVelocityAtWorldPoint(r,t),e.vsub(t,n),this.ni.dot(n)}},{"../math/Mat3":27,"../math/Vec3":30,"./Equation":20}],20:[function(e,t,i){t.exports=o;var r=e("../math/JacobianElement"),n=e("../math/Vec3");function o(e,t,i,n){this.id=o.id++,this.minForce=void 0===i?-1e6:i,this.maxForce=void 0===n?1e6:n,this.bi=e,this.bj=t,this.a=0,this.b=0,this.eps=0,this.jacobianElementA=new r,this.jacobianElementB=new r,this.enabled=!0,this.setSpookParams(1e7,4,1/60)}o.prototype.constructor=o,o.id=0,o.prototype.setSpookParams=function(e,t,i){var r=t,n=e,o=i;this.a=4/(o*(1+4*r)),this.b=4*r/(1+4*r),this.eps=4/(o*o*n*(1+4*r))},o.prototype.computeB=function(e,t,i){var r=this.computeGW();return-this.computeGq()*e-r*t-this.computeGiMf()*i},o.prototype.computeGq=function(){var e=this.jacobianElementA,t=this.jacobianElementB,i=this.bi,r=this.bj,n=i.position,o=r.position;return e.spatial.dot(n)+t.spatial.dot(o)};var s=new n;o.prototype.computeGW=function(){var e=this.jacobianElementA,t=this.jacobianElementB,i=this.bi,r=this.bj,n=i.velocity,o=r.velocity,a=i.angularVelocity||s,h=r.angularVelocity||s;return e.multiplyVectors(n,a)+t.multiplyVectors(o,h)},o.prototype.computeGWlambda=function(){var e=this.jacobianElementA,t=this.jacobianElementB,i=this.bi,r=this.bj,n=i.vlambda,o=r.vlambda,a=i.wlambda||s,h=r.wlambda||s;return e.multiplyVectors(n,a)+t.multiplyVectors(o,h)};var a=new n,h=new n,l=new n,c=new n;o.prototype.computeGiMf=function(){var e=this.jacobianElementA,t=this.jacobianElementB,i=this.bi,r=this.bj,n=i.force,o=i.torque,s=r.force,u=r.torque,p=i.invMassSolve,f=r.invMassSolve;return i.invInertiaWorldSolve?i.invInertiaWorldSolve.vmult(o,l):l.set(0,0,0),r.invInertiaWorldSolve?r.invInertiaWorldSolve.vmult(u,c):c.set(0,0,0),n.mult(p,a),s.mult(f,h),e.multiplyVectors(a,l)+t.multiplyVectors(h,c)};var u=new n;o.prototype.computeGiMGt=function(){var e=this.jacobianElementA,t=this.jacobianElementB,i=this.bi,r=this.bj,n=i.invMassSolve,o=r.invMassSolve,s=i.invInertiaWorldSolve,a=r.invInertiaWorldSolve,h=n+o;return s&&(s.vmult(e.rotational,u),h+=u.dot(e.rotational)),a&&(a.vmult(t.rotational,u),h+=u.dot(t.rotational)),h};var p=new n;new n,new n,new n,new n,new n;o.prototype.addToWlambda=function(e){var t=this.jacobianElementA,i=this.jacobianElementB,r=this.bi,n=this.bj,o=p;t.spatial.mult(r.invMassSolve*e,o),r.vlambda.vadd(o,r.vlambda),i.spatial.mult(n.invMassSolve*e,o),n.vlambda.vadd(o,n.vlambda),r.invInertiaWorldSolve&&(r.invInertiaWorldSolve.vmult(t.rotational,o),o.mult(e,o),r.wlambda.vadd(o,r.wlambda)),n.invInertiaWorldSolve&&(n.invInertiaWorldSolve.vmult(i.rotational,o),o.mult(e,o),n.wlambda.vadd(o,n.wlambda))},o.prototype.computeC=function(){return this.computeGiMGt()+this.eps}},{"../math/JacobianElement":26,"../math/Vec3":30}],21:[function(e,t,i){t.exports=o;var r=e("./Equation"),n=e("../math/Vec3");e("../math/Mat3");function o(e,t,i){r.call(this,e,t,-i,i),this.ri=new n,this.rj=new n,this.t=new n}o.prototype=new r,o.prototype.constructor=o;var s=new n,a=new n;o.prototype.computeB=function(e){this.a;var t=this.b,i=(this.bi,this.bj,this.ri),r=this.rj,n=s,o=a,h=this.t;i.cross(h,n),r.cross(h,o);var l=this.jacobianElementA,c=this.jacobianElementB;return h.negate(l.spatial),n.negate(l.rotational),c.spatial.copy(h),c.rotational.copy(o),-this.computeGW()*t-e*this.computeGiMf()}},{"../math/Mat3":27,"../math/Vec3":30,"./Equation":20}],22:[function(e,t,i){t.exports=o;var r=e("../math/Vec3"),n=(e("../math/Mat3"),e("./Equation"));function o(e,t,i){var o=void 0!==(i=i||{}).maxForce?i.maxForce:1e6;n.call(this,e,t,-o,o),this.axisA=i.axisA?i.axisA.clone():new r(1,0,0),this.axisB=i.axisB?i.axisB.clone():new r(0,1,0),this.maxAngle=Math.PI/2}o.prototype=new n,o.prototype.constructor=o;var s=new r,a=new r;o.prototype.computeB=function(e){var t=this.a,i=this.b,r=this.axisA,n=this.axisB,o=s,h=a,l=this.jacobianElementA,c=this.jacobianElementB;return r.cross(n,o),n.cross(r,h),l.rotational.copy(h),c.rotational.copy(o),-(Math.cos(this.maxAngle)-r.dot(n))*t-this.computeGW()*i-e*this.computeGiMf()}},{"../math/Mat3":27,"../math/Vec3":30,"./Equation":20}],23:[function(e,t,i){t.exports=o;var r=e("../math/Vec3"),n=(e("../math/Mat3"),e("./Equation"));function o(e,t,i){i=void 0!==i?i:1e6,n.call(this,e,t,-i,i),this.axisA=new r,this.axisB=new r,this.targetVelocity=0}o.prototype=new n,o.prototype.constructor=o,o.prototype.computeB=function(e){this.a;var t=this.b,i=(this.bi,this.bj,this.axisA),r=this.axisB,n=this.jacobianElementA,o=this.jacobianElementB;return n.rotational.copy(i),r.negate(o.rotational),-(this.computeGW()-this.targetVelocity)*t-e*this.computeGiMf()}},{"../math/Mat3":27,"../math/Vec3":30,"./Equation":20}],24:[function(e,t,i){var r=e("../utils/Utils");function n(e,t,i){i=r.defaults(i,{friction:.3,restitution:.3,contactEquationStiffness:1e7,contactEquationRelaxation:3,frictionEquationStiffness:1e7,frictionEquationRelaxation:3}),this.id=n.idCounter++,this.materials=[e,t],this.friction=i.friction,this.restitution=i.restitution,this.contactEquationStiffness=i.contactEquationStiffness,this.contactEquationRelaxation=i.contactEquationRelaxation,this.frictionEquationStiffness=i.frictionEquationStiffness,this.frictionEquationRelaxation=i.frictionEquationRelaxation}t.exports=n,n.idCounter=0},{"../utils/Utils":53}],25:[function(e,t,i){function r(e){var t="";"string"==typeof(e=e||{})?(t=e,e={}):"object"==typeof e&&(t=""),this.name=t,this.id=r.idCounter++,this.friction=void 0!==e.friction?e.friction:-1,this.restitution=void 0!==e.restitution?e.restitution:-1}t.exports=r,r.idCounter=0},{}],26:[function(e,t,i){t.exports=n;var r=e("./Vec3");function n(){this.spatial=new r,this.rotational=new r}n.prototype.multiplyElement=function(e){return e.spatial.dot(this.spatial)+e.rotational.dot(this.rotational)},n.prototype.multiplyVectors=function(e,t){return e.dot(this.spatial)+t.dot(this.rotational)}},{"./Vec3":30}],27:[function(e,t,i){t.exports=n;var r=e("./Vec3");function n(e){this.elements=e||[0,0,0,0,0,0,0,0,0]}n.prototype.identity=function(){var e=this.elements;e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=1,e[5]=0,e[6]=0,e[7]=0,e[8]=1},n.prototype.setZero=function(){var e=this.elements;e[0]=0,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=0,e[6]=0,e[7]=0,e[8]=0},n.prototype.setTrace=function(e){var t=this.elements;t[0]=e.x,t[4]=e.y,t[8]=e.z},n.prototype.getTrace=function(e){e=e||new r;var t=this.elements;e.x=t[0],e.y=t[4],e.z=t[8]},n.prototype.vmult=function(e,t){t=t||new r;var i=this.elements,n=e.x,o=e.y,s=e.z;return t.x=i[0]*n+i[1]*o+i[2]*s,t.y=i[3]*n+i[4]*o+i[5]*s,t.z=i[6]*n+i[7]*o+i[8]*s,t},n.prototype.smult=function(e){for(var t=0;t<this.elements.length;t++)this.elements[t]*=e},n.prototype.mmult=function(e,t){for(var i=t||new n,r=0;r<3;r++)for(var o=0;o<3;o++){for(var s=0,a=0;a<3;a++)s+=e.elements[r+3*a]*this.elements[a+3*o];i.elements[r+3*o]=s}return i},n.prototype.scale=function(e,t){t=t||new n;for(var i=this.elements,r=t.elements,o=0;3!==o;o++)r[3*o+0]=e.x*i[3*o+0],r[3*o+1]=e.y*i[3*o+1],r[3*o+2]=e.z*i[3*o+2];return t},n.prototype.solve=function(e,t){t=t||new r;for(var i,n=[],o=0;o<12;o++)n.push(0);for(o=0;o<3;o++)for(i=0;i<3;i++)n[o+4*i]=this.elements[o+3*i];n[3]=e.x,n[7]=e.y,n[11]=e.z;var s,a,h=3,l=h;do{if(0===n[(o=l-h)+4*o])for(i=o+1;i<l;i++)if(0!==n[o+4*i]){s=4;do{n[(a=4-s)+4*o]+=n[a+4*i]}while(--s);break}if(0!==n[o+4*o])for(i=o+1;i<l;i++){var c=n[o+4*i]/n[o+4*o];s=4;do{n[(a=4-s)+4*i]=a<=o?0:n[a+4*i]-n[a+4*o]*c}while(--s)}}while(--h);if(t.z=n[11]/n[10],t.y=(n[7]-n[6]*t.z)/n[5],t.x=(n[3]-n[2]*t.z-n[1]*t.y)/n[0],isNaN(t.x)||isNaN(t.y)||isNaN(t.z)||t.x===1/0||t.y===1/0||t.z===1/0)throw"Could not solve equation! Got x=["+t.toString()+"], b=["+e.toString()+"], A=["+this.toString()+"]";return t},n.prototype.e=function(e,t,i){if(void 0===i)return this.elements[t+3*e];this.elements[t+3*e]=i},n.prototype.copy=function(e){for(var t=0;t<e.elements.length;t++)this.elements[t]=e.elements[t];return this},n.prototype.toString=function(){for(var e="",t=0;t<9;t++)e+=this.elements[t]+",";return e},n.prototype.reverse=function(e){e=e||new n;for(var t,i=[],r=0;r<18;r++)i.push(0);for(r=0;r<3;r++)for(t=0;t<3;t++)i[r+6*t]=this.elements[r+3*t];i[3]=1,i[9]=0,i[15]=0,i[4]=0,i[10]=1,i[16]=0,i[5]=0,i[11]=0,i[17]=1;var o,s,a=3,h=a;do{if(0===i[(r=h-a)+6*r])for(t=r+1;t<h;t++)if(0!==i[r+6*t]){o=6;do{i[(s=6-o)+6*r]+=i[s+6*t]}while(--o);break}if(0!==i[r+6*r])for(t=r+1;t<h;t++){var l=i[r+6*t]/i[r+6*r];o=6;do{i[(s=6-o)+6*t]=s<=r?0:i[s+6*t]-i[s+6*r]*l}while(--o)}}while(--a);r=2;do{t=r-1;do{l=i[r+6*t]/i[r+6*r];o=6;do{i[(s=6-o)+6*t]=i[s+6*t]-i[s+6*r]*l}while(--o)}while(t--)}while(--r);r=2;do{l=1/i[r+6*r];o=6;do{i[(s=6-o)+6*r]=i[s+6*r]*l}while(--o)}while(r--);r=2;do{t=2;do{if(s=i[3+t+6*r],isNaN(s)||s===1/0)throw"Could not reverse! A=["+this.toString()+"]";e.e(r,t,s)}while(t--)}while(r--);return e},n.prototype.setRotationFromQuaternion=function(e){var t=e.x,i=e.y,r=e.z,n=e.w,o=t+t,s=i+i,a=r+r,h=t*o,l=t*s,c=t*a,u=i*s,p=i*a,f=r*a,d=n*o,m=n*s,g=n*a,_=this.elements;return _[0]=1-(u+f),_[1]=l-g,_[2]=c+m,_[3]=l+g,_[4]=1-(h+f),_[5]=p-d,_[6]=c-m,_[7]=p+d,_[8]=1-(h+u),this},n.prototype.transpose=function(e){for(var t=(e=e||new n).elements,i=this.elements,r=0;3!==r;r++)for(var o=0;3!==o;o++)t[3*r+o]=i[3*o+r];return e}},{"./Vec3":30}],28:[function(e,t,i){t.exports=n;var r=e("./Vec3");function n(e,t,i,r){this.x=void 0!==e?e:0,this.y=void 0!==t?t:0,this.z=void 0!==i?i:0,this.w=void 0!==r?r:1}n.prototype.set=function(e,t,i,r){this.x=e,this.y=t,this.z=i,this.w=r},n.prototype.toString=function(){return this.x+","+this.y+","+this.z+","+this.w},n.prototype.toArray=function(){return[this.x,this.y,this.z,this.w]},n.prototype.setFromAxisAngle=function(e,t){var i=Math.sin(.5*t);this.x=e.x*i,this.y=e.y*i,this.z=e.z*i,this.w=Math.cos(.5*t)},n.prototype.toAxisAngle=function(e){e=e||new r,this.normalize();var t=2*Math.acos(this.w),i=Math.sqrt(1-this.w*this.w);return i<.001?(e.x=this.x,e.y=this.y,e.z=this.z):(e.x=this.x/i,e.y=this.y/i,e.z=this.z/i),[e,t]};var o=new r,s=new r;n.prototype.setFromVectors=function(e,t){if(e.isAntiparallelTo(t)){var i=o,r=s;e.tangents(i,r),this.setFromAxisAngle(i,Math.PI)}else{var n=e.cross(t);this.x=n.x,this.y=n.y,this.z=n.z,this.w=Math.sqrt(Math.pow(e.norm(),2)*Math.pow(t.norm(),2))+e.dot(t),this.normalize()}};var a=new r,h=new r,l=new r;n.prototype.mult=function(e,t){t=t||new n;var i=this.w,r=a,o=h,s=l;return r.set(this.x,this.y,this.z),o.set(e.x,e.y,e.z),t.w=i*e.w-r.dot(o),r.cross(o,s),t.x=i*o.x+e.w*r.x+s.x,t.y=i*o.y+e.w*r.y+s.y,t.z=i*o.z+e.w*r.z+s.z,t},n.prototype.inverse=function(e){var t=this.x,i=this.y,r=this.z,o=this.w;e=e||new n,this.conjugate(e);var s=1/(t*t+i*i+r*r+o*o);return e.x*=s,e.y*=s,e.z*=s,e.w*=s,e},n.prototype.conjugate=function(e){return(e=e||new n).x=-this.x,e.y=-this.y,e.z=-this.z,e.w=this.w,e},n.prototype.normalize=function(){var e=Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w);0===e?(this.x=0,this.y=0,this.z=0,this.w=0):(e=1/e,this.x*=e,this.y*=e,this.z*=e,this.w*=e)},n.prototype.normalizeFast=function(){var e=(3-(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w))/2;0===e?(this.x=0,this.y=0,this.z=0,this.w=0):(this.x*=e,this.y*=e,this.z*=e,this.w*=e)},n.prototype.vmult=function(e,t){t=t||new r;var i=e.x,n=e.y,o=e.z,s=this.x,a=this.y,h=this.z,l=this.w,c=l*i+a*o-h*n,u=l*n+h*i-s*o,p=l*o+s*n-a*i,f=-s*i-a*n-h*o;return t.x=c*l+f*-s+u*-h-p*-a,t.y=u*l+f*-a+p*-s-c*-h,t.z=p*l+f*-h+c*-a-u*-s,t},n.prototype.copy=function(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w,this},n.prototype.toEuler=function(e,t){var i,r,n;t=t||"YZX";var o=this.x,s=this.y,a=this.z,h=this.w;switch(t){case"YZX":var l=o*s+a*h;if(l>.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},n.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},n.prototype.clone=function(){return new n(this.x,this.y,this.z,this.w)}},{"./Vec3":30}],29:[function(e,t,i){var r=e("./Vec3"),n=e("./Quaternion");function o(e){e=e||{},this.position=new r,e.position&&this.position.copy(e.position),this.quaternion=new n,e.quaternion&&this.quaternion.copy(e.quaternion)}t.exports=o;var s=new n;o.pointToLocalFrame=function(e,t,i,n){n=n||new r;return i.vsub(e,n),t.conjugate(s),s.vmult(n,n),n},o.prototype.pointToLocal=function(e,t){return o.pointToLocalFrame(this.position,this.quaternion,e,t)},o.pointToWorldFrame=function(e,t,i,n){n=n||new r;return t.vmult(i,n),n.vadd(e,n),n},o.prototype.pointToWorld=function(e,t){return o.pointToWorldFrame(this.position,this.quaternion,e,t)},o.prototype.vectorToWorldFrame=function(e,t){t=t||new r;return this.quaternion.vmult(e,t),t},o.vectorToWorldFrame=function(e,t,i){return e.vmult(t,i),i},o.vectorToLocalFrame=function(e,t,i,n){n=n||new r;return t.w*=-1,t.vmult(i,n),t.w*=-1,n}},{"./Quaternion":28,"./Vec3":30}],30:[function(e,t,i){t.exports=n;var r=e("./Mat3");function n(e,t,i){this.x=e||0,this.y=t||0,this.z=i||0}n.ZERO=new n(0,0,0),n.UNIT_X=new n(1,0,0),n.UNIT_Y=new n(0,1,0),n.UNIT_Z=new n(0,0,1),n.prototype.cross=function(e,t){var i=e.x,r=e.y,o=e.z,s=this.x,a=this.y,h=this.z;return(t=t||new n).x=a*o-h*r,t.y=h*i-s*o,t.z=s*r-a*i,t},n.prototype.set=function(e,t,i){return this.x=e,this.y=t,this.z=i,this},n.prototype.setZero=function(){this.x=this.y=this.z=0},n.prototype.vadd=function(e,t){if(!t)return new n(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},n.prototype.vsub=function(e,t){if(!t)return new n(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},n.prototype.crossmat=function(){return new r([0,-this.z,this.y,this.z,0,-this.x,-this.y,this.x,0])},n.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},n.prototype.unit=function(e){e=e||new n;var t=this.x,i=this.y,r=this.z,o=Math.sqrt(t*t+i*i+r*r);return o>0?(o=1/o,e.x=t*o,e.y=i*o,e.z=r*o):(e.x=1,e.y=0,e.z=0),e},n.prototype.norm=function(){var e=this.x,t=this.y,i=this.z;return Math.sqrt(e*e+t*t+i*i)},n.prototype.length=n.prototype.norm,n.prototype.norm2=function(){return this.dot(this)},n.prototype.lengthSquared=n.prototype.norm2,n.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))},n.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)},n.prototype.mult=function(e,t){t=t||new n;var i=this.x,r=this.y,o=this.z;return t.x=e*i,t.y=e*r,t.z=e*o,t},n.prototype.scale=n.prototype.mult,n.prototype.dot=function(e){return this.x*e.x+this.y*e.y+this.z*e.z},n.prototype.isZero=function(){return 0===this.x&&0===this.y&&0===this.z},n.prototype.negate=function(e){return(e=e||new n).x=-this.x,e.y=-this.y,e.z=-this.z,e};var o=new n,s=new n;n.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)},n.prototype.toString=function(){return this.x+","+this.y+","+this.z},n.prototype.toArray=function(){return[this.x,this.y,this.z]},n.prototype.copy=function(e){return this.x=e.x,this.y=e.y,this.z=e.z,this},n.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},n.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)},n.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 n;n.prototype.isAntiparallelTo=function(e,t){return this.negate(a),a.almostEquals(e,t)},n.prototype.clone=function(){return new n(this.x,this.y,this.z)}},{"./Mat3":27}],31:[function(e,t,i){t.exports=l;var r=e("../utils/EventTarget"),n=(e("../shapes/Shape"),e("../math/Vec3")),o=e("../math/Mat3"),s=e("../math/Quaternion"),a=(e("../material/Material"),e("../collision/AABB")),h=e("../shapes/Box");function l(e){e=e||{},r.apply(this),this.id=l.idCounter++,this.world=null,this.preStep=null,this.postStep=null,this.vlambda=new n,this.collisionFilterGroup="number"==typeof e.collisionFilterGroup?e.collisionFilterGroup:1,this.collisionFilterMask="number"==typeof e.collisionFilterMask?e.collisionFilterMask:1,this.collisionResponse=!0,this.position=new n,e.position&&this.position.copy(e.position),this.previousPosition=new n,this.initPosition=new n,this.velocity=new n,e.velocity&&this.velocity.copy(e.velocity),this.initVelocity=new n,this.force=new n;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?l.STATIC:l.DYNAMIC,typeof e.type==typeof l.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 n,this.quaternion=new s,e.quaternion&&this.quaternion.copy(e.quaternion),this.initQuaternion=new s,this.angularVelocity=new n,e.angularVelocity&&this.angularVelocity.copy(e.angularVelocity),this.initAngularVelocity=new n,this.interpolatedPosition=new n,this.interpolatedQuaternion=new s,this.shapes=[],this.shapeOffsets=[],this.shapeOrientations=[],this.inertia=new n,this.invInertia=new n,this.invInertiaWorld=new o,this.invMassSolve=0,this.invInertiaSolve=new n,this.invInertiaWorldSolve=new o,this.fixedRotation=void 0!==e.fixedRotation&&e.fixedRotation,this.angularDamping=void 0!==e.angularDamping?e.angularDamping:.01,this.aabb=new a,this.aabbNeedsUpdate=!0,this.wlambda=new n,e.shape&&this.addShape(e.shape),this.updateMassProperties()}l.prototype=new r,l.prototype.constructor=l,l.DYNAMIC=1,l.STATIC=2,l.KINEMATIC=4,l.AWAKE=0,l.SLEEPY=1,l.SLEEPING=2,l.idCounter=0,l.prototype.wakeUp=function(){var e=this.sleepState;this.sleepState=0,e===l.SLEEPING&&this.dispatchEvent({type:"wakeup"})},l.prototype.sleep=function(){this.sleepState=l.SLEEPING,this.velocity.set(0,0,0),this.angularVelocity.set(0,0,0)},l.sleepyEvent={type:"sleepy"},l.sleepEvent={type:"sleep"},l.prototype.sleepTick=function(e){if(this.allowSleep){var t=this.sleepState,i=this.velocity.norm2()+this.angularVelocity.norm2(),r=Math.pow(this.sleepSpeedLimit,2);t===l.AWAKE&&i<r?(this.sleepState=l.SLEEPY,this.timeLastSleepy=e,this.dispatchEvent(l.sleepyEvent)):t===l.SLEEPY&&i>r?this.wakeUp():t===l.SLEEPY&&e-this.timeLastSleepy>this.sleepTimeLimit&&(this.sleep(),this.dispatchEvent(l.sleepEvent))}},l.prototype.updateSolveMassProperties=function(){this.sleepState===l.SLEEPING||this.type===l.KINEMATIC?(this.invMassSolve=0,this.invInertiaSolve.setZero(),this.invInertiaWorldSolve.setZero()):(this.invMassSolve=this.invMass,this.invInertiaSolve.copy(this.invInertia),this.invInertiaWorldSolve.copy(this.invInertiaWorld))},l.prototype.pointToLocalFrame=function(e,t){t=t||new n;return e.vsub(this.position,t),this.quaternion.conjugate().vmult(t,t),t},l.prototype.vectorToLocalFrame=function(e,t){t=t||new n;return this.quaternion.conjugate().vmult(e,t),t},l.prototype.pointToWorldFrame=function(e,t){t=t||new n;return this.quaternion.vmult(e,t),t.vadd(this.position,t),t},l.prototype.vectorToWorldFrame=function(e,t){t=t||new n;return this.quaternion.vmult(e,t),t};var c=new n,u=new s;l.prototype.addShape=function(e,t,i){var r=new n,o=new s;return t&&r.copy(t),i&&o.copy(i),this.shapes.push(e),this.shapeOffsets.push(r),this.shapeOrientations.push(o),this.updateMassProperties(),this.updateBoundingRadius(),this.aabbNeedsUpdate=!0,this},l.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 a;l.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 o,d=new o;new o;l.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 n,g=new n;l.prototype.applyForce=function(e,t){if(this.type===l.DYNAMIC){var i=m;t.vsub(this.position,i);var r=g;i.cross(e,r),this.force.vadd(e,this.force),this.torque.vadd(r,this.torque)}};var _=new n,v=new n;l.prototype.applyLocalForce=function(e,t){if(this.type===l.DYNAMIC){var i=_,r=v;this.vectorToWorldFrame(e,i),this.pointToWorldFrame(t,r),this.applyForce(i,r)}};var y=new n,b=new n,x=new n;l.prototype.applyImpulse=function(e,t){if(this.type===l.DYNAMIC){var i=y;t.vsub(this.position,i);var r=b;r.copy(e),r.mult(this.invMass,r),this.velocity.vadd(r,this.velocity);var n=x;i.cross(e,n),this.invInertiaWorld.vmult(n,n),this.angularVelocity.vadd(n,this.angularVelocity)}};var T=new n,E=new n;l.prototype.applyLocalImpulse=function(e,t){if(this.type===l.DYNAMIC){var i=T,r=E;this.vectorToWorldFrame(e,i),this.pointToWorldFrame(t,r),this.applyImpulse(i,r)}};var A=new n;l.prototype.updateMassProperties=function(){var e=A;this.invMass=this.mass>0?1/this.mass:0;var t=this.inertia,i=this.fixedRotation;this.computeAABB(),e.set((this.aabb.upperBound.x-this.aabb.lowerBound.x)/2,(this.aabb.upperBound.y-this.aabb.lowerBound.y)/2,(this.aabb.upperBound.z-this.aabb.lowerBound.z)/2),h.calculateInertia(e,this.mass,t),this.invInertia.set(t.x>0&&!i?1/t.x:0,t.y>0&&!i?1/t.y:0,t.z>0&&!i?1/t.z:0),this.updateInertiaWorld(!0)},l.prototype.getVelocityAtWorldPoint=function(e,t){var i=new n;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){e("./Body");var r=e("../math/Vec3"),n=e("../math/Quaternion"),o=(e("../collision/RaycastResult"),e("../collision/Ray")),s=e("../objects/WheelInfo");function a(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}t.exports=a;new r,new r,new r;var h=new r,l=new r,c=new r;new o;a.prototype.addWheel=function(e){var t=new s(e=e||{}),i=this.wheelInfos.length;return this.wheelInfos.push(t),i},a.prototype.setSteeringValue=function(e,t){this.wheelInfos[t].steering=e};new r;a.prototype.applyEngineForce=function(e,t){this.wheelInfos[t].engineForce=e},a.prototype.setBrake=function(e,t){this.wheelInfos[t].brake=e},a.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},a.prototype.getVehicleAxisWorld=function(e,t){t.set(0===e?1:0,1===e?1:0,2===e?1:0),this.chassisBody.vectorToWorldFrame(t,t)},a.prototype.updateVehicle=function(e){for(var t=this.wheelInfos,i=t.length,n=this.chassisBody,o=0;o<i;o++)this.updateWheelTransform(o);this.currentVehicleSpeedKmHour=3.6*n.velocity.norm();var s=new r;this.getVehicleAxisWorld(this.indexForwardAxis,s),s.dot(n.velocity)<0&&(this.currentVehicleSpeedKmHour*=-1);for(o=0;o<i;o++)this.castRay(t[o]);this.updateSuspension(e);var a=new r,h=new r;for(o=0;o<i;o++){var l=(f=t[o]).suspensionForce;l>f.maxSuspensionForce&&(l=f.maxSuspensionForce),f.raycastResult.hitNormalWorld.scale(l*e,a),f.raycastResult.hitPointWorld.vsub(n.position,h),n.applyImpulse(a,f.raycastResult.hitPointWorld)}this.updateFriction(e);var c=new r,u=new r,p=new r;for(o=0;o<i;o++){var f=t[o];n.getVelocityAtWorldPoint(f.chassisConnectionPointWorld,p);var d=1;switch(this.indexUpAxis){case 1:d=-1}if(f.isInContact){this.getVehicleAxisWorld(this.indexForwardAxis,u);var m=u.dot(f.raycastResult.hitNormalWorld);f.raycastResult.hitNormalWorld.scale(m,c),u.vsub(c,u);var g=u.dot(p);f.deltaRotation=d*g*e/f.radius}!f.sliding&&f.isInContact||0===f.engineForce||!f.useCustomSlidingRotationalSpeed||(f.deltaRotation=(f.engineForce>0?1:-1)*f.customSlidingRotationalSpeed*e),Math.abs(f.brake)>Math.abs(f.engineForce)&&(f.deltaRotation=0),f.rotation+=f.deltaRotation,f.deltaRotation*=.99}},a.prototype.updateSuspension=function(e){for(var t=this.chassisBody.mass,i=this.wheelInfos,r=i.length,n=0;n<r;n++){var o=i[n];if(o.isInContact){var s,a=o.suspensionRestLength-o.suspensionLength;s=o.suspensionStiffness*a*o.clippedInvContactDotSuspension;var h=o.suspensionRelativeVelocity;s-=(h<0?o.dampingCompression:o.dampingRelaxation)*h,o.suspensionForce=s*t,o.suspensionForce<0&&(o.suspensionForce=0)}else o.suspensionForce=0}},a.prototype.removeFromWorld=function(e){this.constraints;e.remove(this.chassisBody),e.removeEventListener("preStep",this.preStepCallback),this.world=null};var u=new r,p=new r;a.prototype.castRay=function(e){var t=u,i=p;this.updateWheelTransformWorld(e);var n=this.chassisBody,o=-1,s=e.suspensionRestLength+e.radius;e.directionWorld.scale(s,t);var a=e.chassisConnectionPointWorld;a.vadd(t,i);var h=e.raycastResult;h.reset();var l=n.collisionResponse;n.collisionResponse=!1,this.world.rayTest(a,i,h),n.collisionResponse=l;var c=h.body;if(e.raycastResult.groundObject=0,c){o=h.distance,e.raycastResult.hitNormalWorld=h.hitNormalWorld,e.isInContact=!0;var f=h.distance;e.suspensionLength=f-e.radius;var d=e.suspensionRestLength-e.maxSuspensionTravel,m=e.suspensionRestLength+e.maxSuspensionTravel;e.suspensionLength<d&&(e.suspensionLength=d),e.suspensionLength>m&&(e.suspensionLength=m,e.raycastResult.reset());var g=e.raycastResult.hitNormalWorld.dot(e.directionWorld),_=new r;n.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 o},a.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)},a.prototype.updateWheelTransform=function(e){var t=h,i=l,r=c,o=this.wheelInfos[e];this.updateWheelTransformWorld(o),o.directionLocal.scale(-1,t),i.copy(o.axleLocal),t.cross(i,r),r.normalize(),i.normalize();var s=o.steering,a=new n;a.setFromAxisAngle(t,s);var u=new n;u.setFromAxisAngle(i,o.rotation);var p=o.worldTransform.quaternion;this.chassisBody.quaternion.mult(a,p),p.mult(u,p),p.normalize();var f=o.worldTransform.position;f.copy(o.directionWorld),f.scale(o.suspensionLength,f),f.vadd(o.chassisConnectionPointWorld,f)};var f=[new r(1,0,0),new r(0,1,0),new r(0,0,1)];a.prototype.getWheelTransformWorld=function(e){return this.wheelInfos[e].worldTransform};var d=new r,m=[],g=[];a.prototype.updateFriction=function(e){for(var t=d,i=this.wheelInfos,n=i.length,o=this.chassisBody,s=g,a=m,h=0;h<n;h++){(p=(M=i[h]).raycastResult.body)&&0,M.sideImpulse=0,M.forwardImpulse=0,s[h]||(s[h]=new r),a[h]||(a[h]=new r)}for(h=0;h<n;h++){if(p=(M=i[h]).raycastResult.body){var l=a[h];this.getWheelTransformWorld(h).vectorToWorldFrame(f[this.indexRightAxis],l);var c=M.raycastResult.hitNormalWorld,u=l.dot(c);c.scale(u,t),l.vsub(t,l),l.normalize(),c.cross(l,s[h]),s[h].normalize(),M.sideImpulse=R(o,M.raycastResult.hitPointWorld,p,M.raycastResult.hitPointWorld,l),M.sideImpulse*=1}}this.sliding=!1;for(h=0;h<n;h++){var p=(M=i[h]).raycastResult.body,_=0;if(M.slipInfo=1,p){var v=M.brake?M.brake:0;_=b(o,p,M.raycastResult.hitPointWorld,s[h],v);var y=v/(_+=M.engineForce*e);M.slipInfo*=y}if(M.forwardImpulse=0,M.skidInfo=1,p){M.skidInfo=1;var x=M.suspensionForce*e*M.frictionSlip,T=x*x;M.forwardImpulse=_;var E=.5*M.forwardImpulse,A=1*M.sideImpulse,P=E*E+A*A;if(M.sliding=!1,P>T){this.sliding=!0,M.sliding=!0;y=x/Math.sqrt(P);M.skidInfo*=y}}}if(this.sliding)for(h=0;h<n;h++){0!==(M=i[h]).sideImpulse&&M.skidInfo<1&&(M.forwardImpulse*=M.skidInfo,M.sideImpulse*=M.skidInfo)}for(h=0;h<n;h++){var M=i[h],S=new r;if(S.copy(M.raycastResult.hitPointWorld),0!==M.forwardImpulse){var C=new r;s[h].scale(M.forwardImpulse,C),o.applyImpulse(C,S)}if(0!==M.sideImpulse){p=M.raycastResult.body;var O=new r;O.copy(M.raycastResult.hitPointWorld);var I=new r;a[h].scale(M.sideImpulse,I),o.pointToLocalFrame(S,S),S["xyz"[this.indexUpAxis]]*=M.rollInfluence,o.pointToWorldFrame(S,S),o.applyImpulse(I,S),I.scale(-1,I),p.applyImpulse(I,O)}}};var _=new r,v=new r,y=new r;function b(e,t,i,r,n){var o=0,s=i,a=_,h=v,l=y;e.getVelocityAtWorldPoint(s,a),t.getVelocityAtWorldPoint(s,h),a.vsub(h,l);return n<(o=-r.dot(l)*(1/(P(e,i,r)+P(t,i,r))))&&(o=n),o<-n&&(o=-n),o}var x=new r,T=new r,E=new r,A=new r;function P(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)}var M=new r,S=new r,C=new r;function R(e,t,i,r,n,o){if(n.norm2()>1.1)return 0;var s=M,a=S,h=C;e.getVelocityAtWorldPoint(t,s),i.getVelocityAtWorldPoint(r,a),s.vsub(a,h);return-.2*n.dot(h)*(1/(e.invMass+i.invMass))}},{"../collision/Ray":9,"../collision/RaycastResult":10,"../math/Quaternion":28,"../math/Vec3":30,"../objects/WheelInfo":36,"./Body":31}],33:[function(e,t,i){var r=e("./Body"),n=e("../shapes/Sphere"),o=e("../shapes/Box"),s=e("../math/Vec3"),a=e("../constraints/HingeConstraint");function h(e){if(this.wheelBodies=[],this.coordinateSystem=void 0===e.coordinateSystem?new s(1,2,3):e.coordinateSystem.clone(),this.chassisBody=e.chassisBody,!this.chassisBody){var t=new o(new s(5,2,.5));this.chassisBody=new r(1,t)}this.constraints=[],this.wheelAxes=[],this.wheelForces=[]}t.exports=h,h.prototype.addWheel=function(e){var t=(e=e||{}).body;t||(t=new r(1,new n(1.2))),this.wheelBodies.push(t),this.wheelForces.push(0);new s;var i=void 0!==e.position?e.position.clone():new s,o=new s;this.chassisBody.pointToWorldFrame(i,o),t.position.set(o.x,o.y,o.z);var h=void 0!==e.axis?e.axis.clone():new s(0,1,0);this.wheelAxes.push(h);var l=new a(this.chassisBody,t,{pivotA:i,axisA:h,pivotB:s.ZERO,axisB:h,collideConnected:!1});return this.constraints.push(l),this.wheelBodies.length-1},h.prototype.setSteeringValue=function(e,t){var i=this.wheelAxes[t],r=Math.cos(e),n=Math.sin(e),o=i.x,s=i.y;this.constraints[t].axisA.set(r*o-n*s,n*o+r*s,0)},h.prototype.setMotorSpeed=function(e,t){var i=this.constraints[t];i.enableMotor(),i.motorTargetVelocity=e},h.prototype.disableMotor=function(e){this.constraints[e].disableMotor()};var l=new s;h.prototype.setWheelForce=function(e,t){this.wheelForces[t]=e},h.prototype.applyWheelForce=function(e,t){var i=this.wheelAxes[t],r=this.wheelBodies[t],n=r.torque;i.scale(e,l),r.vectorToWorldFrame(l,l),n.vadd(l,n)},h.prototype.addToWorld=function(e){for(var t=this.constraints,i=this.wheelBodies.concat([this.chassisBody]),r=0;r<i.length;r++)e.add(i[r]);for(r=0;r<t.length;r++)e.addConstraint(t[r]);e.addEventListener("preStep",this._update.bind(this))},h.prototype._update=function(){for(var e=this.wheelForces,t=0;t<e.length;t++)this.applyWheelForce(e[t],t)},h.prototype.removeFromWorld=function(e){for(var t=this.constraints,i=this.wheelBodies.concat([this.chassisBody]),r=0;r<i.length;r++)e.remove(i[r]);for(r=0;r<t.length;r++)e.removeConstraint(t[r])};var c=new s;h.prototype.getWheelSpeed=function(e){var t=this.wheelAxes[e],i=this.wheelBodies[e].angularVelocity;return this.chassisBody.vectorToWorldFrame(t,c),i.dot(c)}},{"../constraints/HingeConstraint":15,"../math/Vec3":30,"../shapes/Box":37,"../shapes/Sphere":44,"./Body":31}],34:[function(e,t,i){t.exports=n;e("../shapes/Shape");var r=e("../math/Vec3");e("../math/Quaternion"),e("../shapes/Particle"),e("../objects/Body"),e("../material/Material");function n(){this.particles=[],this.density=1,this.smoothingRadius=1,this.speedOfSound=1,this.viscosity=.01,this.eps=1e-6,this.pressures=[],this.densities=[],this.neighbors=[]}n.prototype.add=function(e){this.particles.push(e),this.neighbors.length<this.particles.length&&this.neighbors.push([])},n.prototype.remove=function(e){var t=this.particles.indexOf(e);-1!==t&&(this.particles.splice(t,1),this.neighbors.length>this.particles.length&&this.neighbors.pop())};var o=new r;n.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()<n&&t.push(h)}};var s=new r,a=new r,h=new r,l=new r,c=new r,u=new r;n.prototype.update=function(){for(var e=this.particles.length,t=s,i=this.speedOfSound,r=this.eps,n=0;n!==e;n++){var o=this.particles[n];(P=this.neighbors[n]).length=0,this.getNeighbors(o,P),P.push(this.particles[n]);for(var p=P.length,f=0,d=0;d!==p;d++){o.position.vsub(P[d].position,t);var m=t.norm(),g=this.w(m);f+=P[d].mass*g}this.densities[n]=f,this.pressures[n]=i*i*(this.densities[n]-this.density)}var _=a,v=h,y=l,b=c,x=u;for(n=0;n!==e;n++){var T,E,A=this.particles[n];_.set(0,0,0),v.set(0,0,0);var P;for(p=(P=this.neighbors[n]).length,d=0;d!==p;d++){var M=P[d];A.position.vsub(M.position,b);var S=b.norm();T=-M.mass*(this.pressures[n]/(this.densities[n]*this.densities[n]+r)+this.pressures[d]/(this.densities[d]*this.densities[d]+r)),this.gradw(b,y),y.mult(T,y),_.vadd(y,_),M.velocity.vsub(A.velocity,x),x.mult(1/(1e-4+this.densities[n]*this.densities[d])*this.viscosity*M.mass,x),E=this.nablaw(S),x.mult(E,x),v.vadd(x,v)}v.mult(A.mass,v),_.mult(A.mass,_),A.force.vadd(v,A.force),A.force.vadd(_,A.force)}},n.prototype.w=function(e){var t=this.smoothingRadius;return 315/(64*Math.PI*Math.pow(t,9))*Math.pow(t*t-e*e,3)},n.prototype.gradw=function(e,t){var i=e.norm(),r=this.smoothingRadius;e.mult(945/(32*Math.PI*Math.pow(r,9))*Math.pow(r*r-i*i,2),t)},n.prototype.nablaw=function(e){var t=this.smoothingRadius;return 945/(32*Math.PI*Math.pow(t,9))*(t*t-e*e)*(7*e*e-3*t*t)}},{"../material/Material":25,"../math/Quaternion":28,"../math/Vec3":30,"../objects/Body":31,"../shapes/Particle":41,"../shapes/Shape":43}],35:[function(e,t,i){var r=e("../math/Vec3");function n(e,t,i){i=i||{},this.restLength="number"==typeof i.restLength?i.restLength:1,this.stiffness=i.stiffness||100,this.damping=i.damping||1,this.bodyA=e,this.bodyB=t,this.localAnchorA=new r,this.localAnchorB=new r,i.localAnchorA&&this.localAnchorA.copy(i.localAnchorA),i.localAnchorB&&this.localAnchorB.copy(i.localAnchorB),i.worldAnchorA&&this.setWorldAnchorA(i.worldAnchorA),i.worldAnchorB&&this.setWorldAnchorB(i.worldAnchorB)}t.exports=n,n.prototype.setWorldAnchorA=function(e){this.bodyA.pointToLocalFrame(e,this.localAnchorA)},n.prototype.setWorldAnchorB=function(e){this.bodyB.pointToLocalFrame(e,this.localAnchorB)},n.prototype.getWorldAnchorA=function(e){this.bodyA.pointToWorldFrame(this.localAnchorA,e)},n.prototype.getWorldAnchorB=function(e){this.bodyB.pointToWorldFrame(this.localAnchorB,e)};var o=new r,s=new r,a=new r,h=new r,l=new r,c=new r,u=new r,p=new r,f=new r,d=new r,m=new r;n.prototype.applyForce=function(){var e=this.stiffness,t=this.damping,i=this.restLength,r=this.bodyA,n=this.bodyB,g=o,_=s,v=a,y=h,b=m,x=l,T=c,E=u,A=p,P=f,M=d;this.getWorldAnchorA(x),this.getWorldAnchorB(T),x.vsub(r.position,E),T.vsub(n.position,A),T.vsub(x,g);var S=g.norm();_.copy(g),_.normalize(),n.velocity.vsub(r.velocity,v),n.angularVelocity.cross(A,b),v.vadd(b,v),r.angularVelocity.cross(E,b),v.vsub(b,v),_.mult(-e*(S-i)-t*v.dot(_),y),r.force.vsub(y,r.force),n.force.vadd(y,n.force),E.cross(y,P),A.cross(y,M),r.torque.vsub(P,r.torque),n.torque.vadd(M,n.torque)}},{"../math/Vec3":30}],36:[function(e,t,i){var r=e("../math/Vec3"),n=e("../math/Transform"),o=e("../collision/RaycastResult"),s=e("../utils/Utils");function a(e){e=s.defaults(e,{chassisConnectionPointLocal:new r,chassisConnectionPointWorld:new r,directionLocal:new r,directionWorld:new r,axleLocal:new r,axleWorld:new r,suspensionRestLength:1,suspensionMaxLength:2,radius:1,suspensionStiffness:100,dampingCompression:10,dampingRelaxation:10,frictionSlip:1e4,steering:0,rotation:0,deltaRotation:0,rollInfluence:.01,maxSuspensionForce:Number.MAX_VALUE,isFrontWheel:!0,clippedInvContactDotSuspension:1,suspensionRelativeVelocity:0,suspensionForce:0,skidInfo:0,suspensionLength:0,maxSuspensionTravel:1,useCustomSlidingRotationalSpeed:!1,customSlidingRotationalSpeed:-.1}),this.maxSuspensionTravel=e.maxSuspensionTravel,this.customSlidingRotationalSpeed=e.customSlidingRotationalSpeed,this.useCustomSlidingRotationalSpeed=e.useCustomSlidingRotationalSpeed,this.sliding=!1,this.chassisConnectionPointLocal=e.chassisConnectionPointLocal.clone(),this.chassisConnectionPointWorld=e.chassisConnectionPointWorld.clone(),this.directionLocal=e.directionLocal.clone(),this.directionWorld=e.directionWorld.clone(),this.axleLocal=e.axleLocal.clone(),this.axleWorld=e.axleWorld.clone(),this.suspensionRestLength=e.suspensionRestLength,this.suspensionMaxLength=e.suspensionMaxLength,this.radius=e.radius,this.suspensionStiffness=e.suspensionStiffness,this.dampingCompression=e.dampingCompression,this.dampingRelaxation=e.dampingRelaxation,this.frictionSlip=e.frictionSlip,this.steering=0,this.rotation=0,this.deltaRotation=0,this.rollInfluence=e.rollInfluence,this.maxSuspensionForce=e.maxSuspensionForce,this.engineForce=0,this.brake=0,this.isFrontWheel=e.isFrontWheel,this.clippedInvContactDotSuspension=1,this.suspensionRelativeVelocity=0,this.suspensionForce=0,this.skidInfo=0,this.suspensionLength=0,this.sideImpulse=0,this.forwardImpulse=0,this.raycastResult=new o,this.worldTransform=new n,this.isInContact=!1}t.exports=a;var h=new r,l=new r;h=new r;a.prototype.updateWheel=function(e){var t=this.raycastResult;if(this.isInContact){var i=t.hitNormalWorld.dot(t.directionWorld);t.hitPointWorld.vsub(e.position,l),e.getVelocityAtWorldPoint(l,h);var r=t.hitNormalWorld.dot(h);if(i>=-.1)this.suspensionRelativeVelocity=0,this.clippedInvContactDotSuspension=10;else{var n=-1/i;this.suspensionRelativeVelocity=r*n,this.clippedInvContactDotSuspension=n}}else t.suspensionLength=this.suspensionRestLength,this.suspensionRelativeVelocity=0,t.directionWorld.scale(-1,t.hitNormalWorld),this.clippedInvContactDotSuspension=1}},{"../collision/RaycastResult":10,"../math/Transform":29,"../math/Vec3":30,"../utils/Utils":53}],37:[function(e,t,i){t.exports=s;var r=e("./Shape"),n=e("../math/Vec3"),o=e("./ConvexPolyhedron");function s(e){r.call(this),this.type=r.types.BOX,this.halfExtents=e,this.convexPolyhedronRepresentation=null,this.updateConvexPolyhedronRepresentation(),this.updateBoundingSphereRadius()}s.prototype=new r,s.prototype.constructor=s,s.prototype.updateConvexPolyhedronRepresentation=function(){var e=this.halfExtents.x,t=this.halfExtents.y,i=this.halfExtents.z,r=n,s=[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 o(s,[[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},s.prototype.calculateLocalInertia=function(e,t){return t=t||new n,s.calculateInertia(this.halfExtents,e,t),t},s.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)},s.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},s.prototype.volume=function(){return 8*this.halfExtents.x*this.halfExtents.y*this.halfExtents.z},s.prototype.updateBoundingSphereRadius=function(){this.boundingSphereRadius=this.halfExtents.norm()};var a=new n;new n;s.prototype.forEachWorldCorner=function(e,t,i){for(var r=this.halfExtents,n=[[r.x,r.y,r.z],[-r.x,r.y,r.z],[-r.x,-r.y,r.z],[-r.x,-r.y,-r.z],[r.x,-r.y,-r.z],[r.x,r.y,-r.z],[-r.x,r.y,-r.z],[r.x,-r.y,r.z]],o=0;o<n.length;o++)a.set(n[o][0],n[o][1],n[o][2]),t.vmult(a,a),e.vadd(a,a),i(a.x,a.y,a.z)};var h=[new n,new n,new n,new n,new n,new n,new n,new n];s.prototype.calculateWorldAABB=function(e,t,i,r){var n=this.halfExtents;h[0].set(n.x,n.y,n.z),h[1].set(-n.x,n.y,n.z),h[2].set(-n.x,-n.y,n.z),h[3].set(-n.x,-n.y,-n.z),h[4].set(n.x,-n.y,-n.z),h[5].set(n.x,n.y,-n.z),h[6].set(-n.x,n.y,-n.z),h[7].set(n.x,-n.y,n.z);var o=h[0];t.vmult(o,o),e.vadd(o,o),r.copy(o),i.copy(o);for(var s=1;s<8;s++){o=h[s];t.vmult(o,o),e.vadd(o,o);var a=o.x,l=o.y,c=o.z;a>r.x&&(r.x=a),l>r.y&&(r.y=l),c>r.z&&(r.z=c),a<i.x&&(i.x=a),l<i.y&&(i.y=l),c<i.z&&(i.z=c)}}},{"../math/Vec3":30,"./ConvexPolyhedron":38,"./Shape":43}],38:[function(e,t,i){t.exports=s;var r=e("./Shape"),n=e("../math/Vec3"),o=(e("../math/Quaternion"),e("../math/Transform"));function s(e,t,i){r.call(this),this.type=r.types.CONVEXPOLYHEDRON,this.vertices=e||[],this.worldVertices=[],this.worldVerticesNeedsUpdate=!0,this.faces=t||[],this.faceNormals=[],this.computeNormals(),this.worldFaceNormalsNeedsUpdate=!0,this.worldFaceNormals=[],this.uniqueEdges=[],this.uniqueAxes=i?i.slice():null,this.computeEdges(),this.updateBoundingSphereRadius()}s.prototype=new r,s.prototype.constructor=s;var a=new n;s.prototype.computeEdges=function(){var e=this.faces,t=this.vertices,i=(t.length,this.uniqueEdges);i.length=0;for(var r=a,n=0;n!==e.length;n++)for(var o=e[n],s=o.length,h=0;h!==s;h++){var l=(h+1)%s;t[o[h]].vsub(t[o[l]],r),r.normalize();for(var c=!1,u=0;u!==i.length;u++)if(i[u].almostEquals(r)||i[u].almostEquals(r)){c=!0;break}c||i.push(r.clone())}},s.prototype.computeNormals=function(){this.faceNormals.length=this.faces.length;for(var e=0;e<this.faces.length;e++){for(var t=0;t<this.faces[e].length;t++)if(!this.vertices[this.faces[e][t]])throw new Error("Vertex "+this.faces[e][t]+" not found!");var i=this.faceNormals[e]||new n;this.getFaceNormal(e,i),i.negate(i),this.faceNormals[e]=i;var r=this.vertices[this.faces[e][0]];if(i.dot(r)<0){console.error(".faceNormals["+e+"] = Vec3("+i.toString()+") looks like it points into the shape? The vertices follow. Make sure they are ordered CCW around the normal, using the right hand rule.");for(t=0;t<this.faces[e].length;t++)console.warn(".vertices["+this.faces[e][t]+"] = Vec3("+this.vertices[this.faces[e][t]].toString()+")")}}};var h=new n,l=new n;s.computeNormal=function(e,t,i,r){t.vsub(e,l),i.vsub(t,h),h.cross(l,r),r.isZero()||r.normalize()},s.prototype.getFaceNormal=function(e,t){var i=this.faces[e],r=this.vertices[i[0]],n=this.vertices[i[1]],o=this.vertices[i[2]];return s.computeNormal(r,n,o,t)};var c=new n;s.prototype.clipAgainstHull=function(e,t,i,r,o,s,a,h,l){for(var u=c,p=-1,f=-Number.MAX_VALUE,d=0;d<i.faces.length;d++){u.copy(i.faceNormals[d]),o.vmult(u,u);var m=u.dot(s);m>f&&(f=m,p=d)}for(var g=[],_=i.faces[p],v=_.length,y=0;y<v;y++){var b=i.vertices[_[y]],x=new n;x.copy(b),o.vmult(x,x),r.vadd(x,x),g.push(x)}p>=0&&this.clipFaceAgainstHull(s,e,t,g,a,h,l)};var u=new n,p=new n,f=new n,d=new n,m=new n,g=new n;s.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++){if(i.vmult(x.uniqueAxes[E],h),!1===(M=x.testSepAxis(h,e,t,i,r,n)))return!1;M<b&&(b=M,o.copy(h))}else for(var T=s?s.length:x.faces.length,E=0;E<T;E++){var A=s?s[E]:E;if(h.copy(x.faceNormals[A]),i.vmult(h,h),!1===(M=x.testSepAxis(h,e,t,i,r,n)))return!1;M<b&&(b=M,o.copy(h))}if(e.uniqueAxes)for(E=0;E!==e.uniqueAxes.length;E++){if(n.vmult(e.uniqueAxes[E],l),0,!1===(M=x.testSepAxis(l,e,t,i,r,n)))return!1;M<b&&(b=M,o.copy(l))}else for(var P=a?a.length:e.faces.length,E=0;E<P;E++){var M;A=a?a[E]:E;if(l.copy(e.faceNormals[A]),n.vmult(l,l),0,!1===(M=x.testSepAxis(l,e,t,i,r,n)))return!1;M<b&&(b=M,o.copy(l))}for(var S=0;S!==x.uniqueEdges.length;S++){i.vmult(x.uniqueEdges[S],_);for(var C=0;C!==e.uniqueEdges.length;C++)if(n.vmult(e.uniqueEdges[C],v),_.cross(v,y),!y.almostZero()){y.normalize();var R=x.testSepAxis(y,e,t,i,r,n);if(!1===R)return!1;R<b&&(b=R,o.copy(y))}}return r.vsub(t,c),c.dot(o)>0&&o.negate(o),!0};var _=[],v=[];s.prototype.testSepAxis=function(e,t,i,r,n,o){s.project(this,e,i,r,_),s.project(t,e,n,o,v);var a=_[0],h=_[1],l=v[0],c=v[1];if(a<c||l<h)return!1;var u=a-c,p=l-h;return u<p?u:p};var y=new n,b=new n;s.prototype.calculateLocalInertia=function(e,t){this.computeLocalAABB(y,b);var i=b.x-y.x,r=b.y-y.y,n=b.z-y.z;t.x=1/12*e*(2*r*2*r+2*n*2*n),t.y=1/12*e*(2*i*2*i+2*n*2*n),t.z=1/12*e*(2*r*2*r+2*i*2*i)},s.prototype.getPlaneConstantOfFace=function(e){var t=this.faces[e],i=this.faceNormals[e],r=this.vertices[t[0]];return-i.dot(r)};var x=new n,T=new n,E=new n,A=new n,P=new n,M=new n,S=new n,C=new n;s.prototype.clipFaceAgainstHull=function(e,t,i,r,n,o,s){for(var a=x,h=T,l=E,c=A,u=P,p=M,f=S,d=C,m=r,g=[],_=-1,v=Number.MAX_VALUE,y=0;y<this.faces.length;y++){a.copy(this.faceNormals[y]),i.vmult(a,a);var b=a.dot(e);b<v&&(v=b,_=y)}if(!(_<0)){var R=this.faces[_];R.connectedFaces=[];for(var O=0;O<this.faces.length;O++)for(var I=0;I<this.faces[O].length;I++)-1!==R.indexOf(this.faces[O][I])&&O!==_&&-1===R.connectedFaces.indexOf(O)&&R.connectedFaces.push(O);m.length;for(var w=R.length,D=0;D<w;D++){var L=this.vertices[R[D]],B=this.vertices[R[(D+1)%w]];L.vsub(B,h),l.copy(h),i.vmult(l,l),t.vadd(l,l),c.copy(this.faceNormals[_]),i.vmult(c,c),t.vadd(c,c),l.cross(c,u),u.negate(u),p.copy(L),i.vmult(p,p),t.vadd(p,p);p.dot(u);var N=R.connectedFaces[D];f.copy(this.faceNormals[N]);var F=this.getPlaneConstantOfFace(N);d.copy(f),i.vmult(d,d);var V=F-d.dot(t);for(this.clipFaceAgainstPlane(m,g,d,V);m.length;)m.shift();for(;g.length;)m.push(g.shift())}f.copy(this.faceNormals[_]);F=this.getPlaneConstantOfFace(_);d.copy(f),i.vmult(d,d);for(V=F-d.dot(t),O=0;O<m.length;O++){var k=d.dot(m[O])+V;if(k<=n&&(console.log("clamped: depth="+k+" to minDist="+n),k=n),k<=o){var U=m[O];if(k<=0){var z={point:U,normal:d,depth:k};s.push(z)}}}}},s.prototype.clipFaceAgainstPlane=function(e,t,i,r){var o,s,a=e.length;if(a<2)return t;var h=e[e.length-1],l=e[0];o=i.dot(h)+r;for(var c=0;c<a;c++){if(l=e[c],s=i.dot(l)+r,o<0)if(s<0){(u=new n).copy(l),t.push(u)}else{var u=new n;h.lerp(l,o/(o-s),u),t.push(u)}else if(s<0){u=new n;h.lerp(l,o/(o-s),u),t.push(u),t.push(l)}h=l,o=s}return t},s.prototype.computeWorldVertices=function(e,t){for(var i=this.vertices.length;this.worldVertices.length<i;)this.worldVertices.push(new n);for(var r=this.vertices,o=this.worldVertices,s=0;s!==i;s++)t.vmult(r[s],o[s]),e.vadd(o[s],o[s]);this.worldVerticesNeedsUpdate=!1};new n;s.prototype.computeLocalAABB=function(e,t){var i=this.vertices.length,r=this.vertices;e.set(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),t.set(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE);for(var n=0;n<i;n++){var o=r[n];o.x<e.x?e.x=o.x:o.x>t.x&&(t.x=o.x),o.y<e.y?e.y=o.y:o.y>t.y&&(t.y=o.y),o.z<e.z?e.z=o.z:o.z>t.z&&(t.z=o.z)}},s.prototype.computeWorldFaceNormals=function(e){for(var t=this.faceNormals.length;this.worldFaceNormals.length<t;)this.worldFaceNormals.push(new n);for(var i=this.faceNormals,r=this.worldFaceNormals,o=0;o!==t;o++)e.vmult(i[o],r[o]);this.worldFaceNormalsNeedsUpdate=!1},s.prototype.updateBoundingSphereRadius=function(){for(var e=0,t=this.vertices,i=0,r=t.length;i!==r;i++){var n=t[i].norm2();n>e&&(e=n)}this.boundingSphereRadius=Math.sqrt(e)};var R=new n;s.prototype.calculateWorldAABB=function(e,t,i,r){for(var n,o,s,a,h,l,c=this.vertices.length,u=this.vertices,p=0;p<c;p++){R.copy(u[p]),t.vmult(R,R),e.vadd(R,R);var f=R;f.x<n||void 0===n?n=f.x:(f.x>a||void 0===a)&&(a=f.x),f.y<o||void 0===o?o=f.y:(f.y>h||void 0===h)&&(h=f.y),f.z<s||void 0===s?s=f.z:(f.z>l||void 0===l)&&(l=f.z)}i.set(n,o,s),r.set(a,h,l)},s.prototype.volume=function(){return 4*Math.PI*this.boundingSphereRadius/3},s.prototype.getAveragePointLocal=function(e){e=e||new n;for(var t=this.vertices.length,i=this.vertices,r=0;r<t;r++)e.vadd(i[r],e);return e.mult(1/t,e),e},s.prototype.transformAllPoints=function(e,t){var i=this.vertices.length,r=this.vertices;if(t){for(var n=0;n<i;n++){var o=r[n];t.vmult(o,o)}for(n=0;n<this.faceNormals.length;n++){o=this.faceNormals[n];t.vmult(o,o)}}if(e)for(n=0;n<i;n++){(o=r[n]).vadd(e,o)}};var O=new n,I=new n,w=new n;s.prototype.pointIsInside=function(e){var t=this.vertices.length,i=this.vertices,r=this.faces,n=this.faceNormals,o=this.faces.length,s=O;this.getAveragePointLocal(s);for(var a=0;a<o;a++){this.faces[a].length,t=n[a];var h=i[r[a][0]],l=I;e.vsub(h,l);var c=t.dot(l),u=w;s.vsub(h,u);var p=t.dot(u);if(c<0&&p>0||c>0&&p<0)return!1}return-1};new n;var D=new n,L=new n;s.project=function(e,t,i,r,n){var s=e.vertices.length,a=D,h=0,l=0,c=L,u=e.vertices;c.setZero(),o.vectorToLocalFrame(i,r,t,a),o.pointToLocalFrame(i,r,c,c);var p=c.dot(a);l=h=u[0].dot(a);for(var f=1;f<s;f++){var d=u[f].dot(a);d>h&&(h=d),d<l&&(l=d)}if((l-=p)>(h-=p)){var m=l;l=h,h=m}n[0]=h,n[1]=l}},{"../math/Quaternion":28,"../math/Transform":29,"../math/Vec3":30,"./Shape":43}],39:[function(e,t,i){t.exports=s;var r=e("./Shape"),n=e("../math/Vec3"),o=(e("../math/Quaternion"),e("./ConvexPolyhedron"));function s(e,t,i,s){var a=s,h=[],l=[],c=[],u=[],p=[],f=Math.cos,d=Math.sin;h.push(new n(t*f(0),t*d(0),.5*-i)),u.push(0),h.push(new n(e*f(0),e*d(0),.5*i)),p.push(1);for(var m=0;m<a;m++){var g=2*Math.PI/a*(m+1),_=2*Math.PI/a*(m+.5);m<a-1?(h.push(new n(t*f(g),t*d(g),.5*-i)),u.push(2*m+2),h.push(new n(e*f(g),e*d(g),.5*i)),p.push(2*m+3),c.push([2*m+2,2*m+3,2*m+1,2*m])):c.push([0,1,2*m+1,2*m]),(a%2==1||m<a/2)&&l.push(new n(f(_),d(_),0))}c.push(p),l.push(new n(0,0,1));var v=[];for(m=0;m<u.length;m++)v.push(u[u.length-m-1]);c.push(v),this.type=r.types.CONVEXPOLYHEDRON,o.call(this,h,c,l)}s.prototype=new o},{"../math/Quaternion":28,"../math/Vec3":30,"./ConvexPolyhedron":38,"./Shape":43}],40:[function(e,t,i){var r=e("./Shape"),n=e("./ConvexPolyhedron"),o=e("../math/Vec3"),s=e("../utils/Utils");function a(e,t){t=s.defaults(t,{maxValue:null,minValue:null,elementSize:1}),this.data=e,this.maxValue=t.maxValue,this.minValue=t.minValue,this.elementSize=t.elementSize,null===t.minValue&&this.updateMinValue(),null===t.maxValue&&this.updateMaxValue(),this.cacheEnabled=!0,r.call(this),this.pillarConvex=new n,this.pillarOffset=new o,this.type=r.types.HEIGHTFIELD,this.updateBoundingSphereRadius(),this._cachedPillars={}}t.exports=a,a.prototype=new r,a.prototype.update=function(){this._cachedPillars={}},a.prototype.updateMinValue=function(){for(var e=this.data,t=e[0][0],i=0;i!==e.length;i++)for(var r=0;r!==e[i].length;r++){var n=e[i][r];n<t&&(t=n)}this.minValue=t},a.prototype.updateMaxValue=function(){for(var e=this.data,t=e[0][0],i=0;i!==e.length;i++)for(var r=0;r!==e[i].length;r++){var n=e[i][r];n>t&&(t=n)}this.maxValue=t},a.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)},a.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},a.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)},a.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},a.prototype.getCacheConvexTrianglePillarKey=function(e,t,i){return e+"_"+t+"_"+(i?1:0)},a.prototype.getCachedConvexTrianglePillar=function(e,t,i){return this._cachedPillars[this.getCacheConvexTrianglePillarKey(e,t,i)]},a.prototype.setCachedConvexTrianglePillar=function(e,t,i,r,n){this._cachedPillars[this.getCacheConvexTrianglePillarKey(e,t,i)]={convex:r,offset:n}},a.prototype.clearCachedConvexTrianglePillar=function(e,t,i){delete this._cachedPillars[this.getCacheConvexTrianglePillarKey(e,t,i)]},a.prototype.getConvexTrianglePillar=function(e,t,i){var r=this.pillarConvex,s=this.pillarOffset;if(this.cacheEnabled){if(a=this.getCachedConvexTrianglePillar(e,t,i))return this.pillarConvex=a.convex,void(this.pillarOffset=a.offset);r=new n,s=new o,this.pillarConvex=r,this.pillarOffset=s}var a=this.data,h=this.elementSize,l=r.faces;r.vertices.length=6;for(var c=0;c<6;c++)r.vertices[c]||(r.vertices[c]=new o);l.length=5;for(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?(s.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):(s.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,s)},a.prototype.calculateLocalInertia=function(e,t){return(t=t||new o).set(0,0,0),t},a.prototype.volume=function(){return Number.MAX_VALUE},a.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)},a.prototype.updateBoundingSphereRadius=function(){var e=this.data,t=this.elementSize;this.boundingSphereRadius=new o(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){t.exports=o;var r=e("./Shape"),n=e("../math/Vec3");function o(){r.call(this),this.type=r.types.PARTICLE}o.prototype=new r,o.prototype.constructor=o,o.prototype.calculateLocalInertia=function(e,t){return(t=t||new n).set(0,0,0),t},o.prototype.volume=function(){return 0},o.prototype.updateBoundingSphereRadius=function(){this.boundingSphereRadius=0},o.prototype.calculateWorldAABB=function(e,t,i,r){i.copy(e),r.copy(e)}},{"../math/Vec3":30,"./Shape":43}],42:[function(e,t,i){t.exports=o;var r=e("./Shape"),n=e("../math/Vec3");function o(){r.call(this),this.type=r.types.PLANE,this.worldNormal=new n,this.worldNormalNeedsUpdate=!0,this.boundingSphereRadius=Number.MAX_VALUE}o.prototype=new r,o.prototype.constructor=o,o.prototype.computeWorldNormal=function(e){var t=this.worldNormal;t.set(0,0,1),e.vmult(t,t),this.worldNormalNeedsUpdate=!1},o.prototype.calculateLocalInertia=function(e,t){return t=t||new n},o.prototype.volume=function(){return Number.MAX_VALUE};var s=new n;o.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)},o.prototype.updateBoundingSphereRadius=function(){this.boundingSphereRadius=Number.MAX_VALUE}},{"../math/Vec3":30,"./Shape":43}],43:[function(e,t,i){t.exports=r;var r=e("./Shape");e("../math/Vec3"),e("../math/Quaternion"),e("../material/Material");function r(){this.id=r.idCounter++,this.type=0,this.boundingSphereRadius=0,this.collisionResponse=!0,this.material=null}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){t.exports=o;var r=e("./Shape"),n=e("../math/Vec3");function o(e){if(r.call(this),this.radius=void 0!==e?Number(e):1,this.type=r.types.SPHERE,this.radius<0)throw new Error("The sphere radius cannot be negative.");this.updateBoundingSphereRadius()}o.prototype=new r,o.prototype.constructor=o,o.prototype.calculateLocalInertia=function(e,t){t=t||new n;var i=2*e*this.radius*this.radius/5;return t.x=i,t.y=i,t.z=i,t},o.prototype.volume=function(){return 4*Math.PI*this.radius/3},o.prototype.updateBoundingSphereRadius=function(){this.boundingSphereRadius=this.radius},o.prototype.calculateWorldAABB=function(e,t,i,r){for(var n=this.radius,o=["x","y","z"],s=0;s<o.length;s++){var a=o[s];i[a]=e[a]-n,r[a]=e[a]+n}}},{"../math/Vec3":30,"./Shape":43}],45:[function(e,t,i){t.exports=h;var r=e("./Shape"),n=e("../math/Vec3"),o=(e("../math/Quaternion"),e("../math/Transform")),s=e("../collision/AABB"),a=e("../utils/Octree");function h(e,t){r.call(this),this.type=r.types.TRIMESH,this.vertices=new Float32Array(e),this.indices=new Int16Array(t),this.normals=new Float32Array(t.length),this.aabb=new s,this.edges=null,this.scale=new n(1,1,1),this.tree=new a,this.updateEdges(),this.updateNormals(),this.updateAABB(),this.updateBoundingSphereRadius(),this.updateTree()}h.prototype=new r,h.prototype.constructor=h;var l=new n;h.prototype.updateTree=function(){var e=this.tree;e.reset(),e.aabb.copy(this.aabb);var t=this.scale;e.aabb.lowerBound.x*=1/t.x,e.aabb.lowerBound.y*=1/t.y,e.aabb.lowerBound.z*=1/t.z,e.aabb.upperBound.x*=1/t.x,e.aabb.upperBound.y*=1/t.y,e.aabb.upperBound.z*=1/t.z;for(var i=new s,r=new n,o=new n,a=new n,h=[r,o,a],l=0;l<this.indices.length/3;l++){var c=3*l;this._getUnscaledVertex(this.indices[c],r),this._getUnscaledVertex(this.indices[c+1],o),this._getUnscaledVertex(this.indices[c+2],a),i.setFromPoints(h),e.insert(i,l)}e.removeEmptyNodes()};var c=new s;h.prototype.getTrianglesInAABB=function(e,t){c.copy(e);var i=this.scale,r=i.x,n=i.y,o=i.z,s=c.lowerBound,a=c.upperBound;return s.x/=r,s.y/=n,s.z/=o,a.x/=r,a.y/=n,a.z/=o,this.tree.aabbQuery(c,t)},h.prototype.setScale=function(e){var t=this.scale.x===this.scale.y===this.scale.z,i=e.x===e.y===e.z;t&&i||this.updateNormals(),this.scale.copy(e),this.updateAABB(),this.updateBoundingSphereRadius()},h.prototype.updateNormals=function(){for(var e=l,t=this.normals,i=0;i<this.indices.length/3;i++){var r=3*i,n=this.indices[r],o=this.indices[r+1],s=this.indices[r+2];this.getVertex(n,m),this.getVertex(o,g),this.getVertex(s,_),h.computeNormal(g,m,_,e),t[r]=e.x,t[r+1]=e.y,t[r+2]=e.z}},h.prototype.updateEdges=function(){for(var e={},t=function(t,i){e[n<o?n+"_"+o:o+"_"+n]=!0},i=0;i<this.indices.length/3;i++){var r=3*i,n=this.indices[r],o=this.indices[r+1];this.indices[r+2];t(),t(),t()}var s=Object.keys(e);this.edges=new Int16Array(2*s.length);for(i=0;i<s.length;i++){var a=s[i].split("_");this.edges[2*i]=parseInt(a[0],10),this.edges[2*i+1]=parseInt(a[1],10)}},h.prototype.getEdgeVertex=function(e,t,i){var r=this.edges[2*e+(t?1:0)];this.getVertex(r,i)};var u=new n,p=new n;h.prototype.getEdgeVector=function(e,t){var i=u,r=p;this.getEdgeVertex(e,0,i),this.getEdgeVertex(e,1,r),r.vsub(i,t)};var f=new n,d=new n;h.computeNormal=function(e,t,i,r){t.vsub(e,d),i.vsub(t,f),f.cross(d,r),r.isZero()||r.normalize()};var m=new n,g=new n,_=new n;h.prototype.getVertex=function(e,t){var i=this.scale;return this._getUnscaledVertex(e,t),t.x*=i.x,t.y*=i.y,t.z*=i.z,t},h.prototype._getUnscaledVertex=function(e,t){var i=3*e,r=this.vertices;return t.set(r[i],r[i+1],r[i+2])},h.prototype.getWorldVertex=function(e,t,i,r){return this.getVertex(e,r),o.pointToWorldFrame(t,i,r,r),r},h.prototype.getTriangleVertices=function(e,t,i,r){var n=3*e;this.getVertex(this.indices[n],t),this.getVertex(this.indices[n+1],i),this.getVertex(this.indices[n+2],r)},h.prototype.getNormal=function(e,t){var i=3*e;return t.set(this.normals[i],this.normals[i+1],this.normals[i+2])};var v=new s;h.prototype.calculateLocalInertia=function(e,t){this.computeLocalAABB(v);var i=v.upperBound.x-v.lowerBound.x,r=v.upperBound.y-v.lowerBound.y,n=v.upperBound.z-v.lowerBound.z;return t.set(1/12*e*(2*r*2*r+2*n*2*n),1/12*e*(2*i*2*i+2*n*2*n),1/12*e*(2*r*2*r+2*i*2*i))};var y=new n;h.prototype.computeLocalAABB=function(e){var t=e.lowerBound,i=e.upperBound,r=this.vertices.length,n=(this.vertices,y);this.getVertex(0,n),t.copy(n),i.copy(n);for(var o=0;o!==r;o++)this.getVertex(o,n),n.x<t.x?t.x=n.x:n.x>i.x&&(i.x=n.x),n.y<t.y?t.y=n.y:n.y>i.y&&(i.y=n.y),n.z<t.z?t.z=n.z:n.z>i.z&&(i.z=n.z)},h.prototype.updateAABB=function(){this.computeLocalAABB(this.aabb)},h.prototype.updateBoundingSphereRadius=function(){for(var e=0,t=this.vertices,i=new n,r=0,o=t.length/3;r!==o;r++){this.getVertex(r,i);var s=i.norm2();s>e&&(e=s)}this.boundingSphereRadius=Math.sqrt(e)};new n;var b=new o,x=new s;h.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)},h.prototype.volume=function(){return 4*Math.PI*this.boundingSphereRadius/3},h.createTorus=function(e,t,i,r,n){e=e||1,t=t||.5,i=i||8,r=r||6,n=n||2*Math.PI;for(var o=[],s=[],a=0;a<=i;a++)for(var l=0;l<=r;l++){var c=l/r*n,u=a/i*Math.PI*2,p=(e+t*Math.cos(u))*Math.cos(c),f=(e+t*Math.cos(u))*Math.sin(c),d=t*Math.sin(u);o.push(p,f,d)}for(a=1;a<=i;a++)for(l=1;l<=r;l++){var m=(r+1)*a+l-1,g=(r+1)*(a-1)+l-1,_=(r+1)*(a-1)+l,v=(r+1)*a+l;s.push(m,g,v),s.push(g,_,v)}return new h(o,s)}},{"../collision/AABB":3,"../math/Quaternion":28,"../math/Transform":29,"../math/Vec3":30,"../utils/Octree":50,"./Shape":43}],46:[function(e,t,i){t.exports=n;e("../math/Vec3"),e("../math/Quaternion");var r=e("./Solver");function n(){r.call(this),this.iterations=10,this.tolerance=1e-7}n.prototype=new r;var o=[],s=[],a=[];n.prototype.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(var v=0;v!==g;v++)m[v].updateSolveMassProperties();var y=s,b=a,x=o;y.length=d,b.length=d,x.length=d;for(v=0;v!==d;v++){var T=f[v];x[v]=0,b[v]=T.computeB(_),y[v]=1/T.computeC()}if(0!==d){for(v=0;v!==g;v++){var E=(M=m[v]).vlambda,A=M.wlambda;E.set(0,0,0),A&&A.set(0,0,0)}for(c=0;c!==u;c++){h=0;for(var P=0;P!==d;P++){T=f[P];i=b[P],r=y[P],(l=x[P])+(n=r*(i-T.computeGWlambda()-T.eps*l))<T.minForce?n=T.minForce-l:l+n>T.maxForce&&(n=T.maxForce-l),x[P]+=n,h+=n>0?n:-n,T.addToWlambda(n)}if(h*h<p)break}for(v=0;v!==g;v++){var M,S=(M=m[v]).velocity,C=M.angularVelocity;S.vadd(M.vlambda,S),C&&C.vadd(M.wlambda,C)}}return c}},{"../math/Quaternion":28,"../math/Vec3":30,"./Solver":47}],47:[function(e,t,i){function r(){this.equations=[]}t.exports=r,r.prototype.solve=function(e,t){return 0},r.prototype.addEquation=function(e){e.enabled&&this.equations.push(e)},r.prototype.removeEquation=function(e){var t=this.equations,i=t.indexOf(e);-1!==i&&t.splice(i,1)},r.prototype.removeAllEquations=function(){this.equations.length=0}},{}],48:[function(e,t,i){t.exports=o;e("../math/Vec3"),e("../math/Quaternion");var r=e("./Solver"),n=e("../objects/Body");function o(e){for(r.call(this),this.iterations=10,this.tolerance=1e-7,this.subsolver=e,this.nodes=[],this.nodePool=[];this.nodePool.length<128;)this.nodePool.push(this.createNode())}o.prototype=new r;var s=[],a=[],h={bodies:[]},l=n.STATIC;function c(e){for(var t=e.length,i=0;i!==t;i++){var r=e[i];if(!(r.visited||r.body.type&l))return r}return!1}var u=[];function p(e,t,i,r){for(u.push(e),e.visited=!0,t(e,i,r);u.length;)for(var n,o=u.pop();n=c(o.children);)n.visited=!0,t(n,i,r),u.push(n)}function f(e,t,i){t.push(e.body);for(var r=e.eqs.length,n=0;n!==r;n++){var o=e.eqs[n];-1===i.indexOf(o)&&i.push(o)}}function d(e,t){return t.id-e.id}o.prototype.createNode=function(){return{body:null,children:[],eqs:[],visited:!1}},o.prototype.solve=function(e,t){for(var i=s,r=this.nodePool,n=t.bodies,o=this.equations,l=o.length,u=n.length,m=this.subsolver;r.length<u;)r.push(this.createNode());i.length=u;for(var g=0;g<u;g++)i[g]=r[g];for(g=0;g!==u;g++){var _=i[g];_.body=n[g],_.children.length=0,_.eqs.length=0,_.visited=!1}for(var v=0;v!==l;v++){var y=o[v],b=(g=n.indexOf(y.bi),n.indexOf(y.bj)),x=i[g],T=i[b];x.children.push(T),x.eqs.push(y),T.children.push(x),T.eqs.push(y)}var E,A=0,P=a;m.tolerance=this.tolerance,m.iterations=this.iterations;for(var M=h;E=c(i);){P.length=0,M.bodies.length=0,p(E,f,M.bodies,P);var S=P.length;P=P.sort(d);for(g=0;g!==S;g++)m.addEquation(P[g]);m.solve(e,M);m.removeAllEquations(),A++}return A}},{"../math/Quaternion":28,"../math/Vec3":30,"../objects/Body":31,"./Solver":47}],49:[function(e,t,i){var r=function(){};t.exports=r,r.prototype={constructor:r,addEventListener:function(e,t){void 0===this._listeners&&(this._listeners={});var i=this._listeners;return void 0===i[e]&&(i[e]=[]),-1===i[e].indexOf(t)&&i[e].push(t),this},hasEventListener:function(e,t){if(void 0===this._listeners)return!1;var i=this._listeners;return void 0!==i[e]&&-1!==i[e].indexOf(t)},removeEventListener:function(e,t){if(void 0===this._listeners)return this;var i=this._listeners;if(void 0===i[e])return this;var r=i[e].indexOf(t);return-1!==r&&i[e].splice(r,1),this},dispatchEvent:function(e){if(void 0===this._listeners)return this;var t=this._listeners[e.type];if(void 0!==t){e.target=this;for(var i=0,r=t.length;i<r;i++)t[i].call(this,e)}return this}}},{}],50:[function(e,t,i){var r=e("../collision/AABB"),n=e("../math/Vec3");function o(e){e=e||{},this.root=e.root||null,this.aabb=e.aabb?e.aabb.clone():new r,this.data=[],this.children=[]}function s(e,t){(t=t||{}).root=null,t.aabb=e,o.call(this,t),this.maxDepth=void 0!==t.maxDepth?t.maxDepth:8}t.exports=s,s.prototype=new o,o.prototype.reset=function(e,t){this.children.length=this.data.length=0},o.prototype.insert=function(e,t,i){var r=this.data;if(i=i||0,!this.aabb.contains(e))return!1;var n=this.children;if(i<(this.maxDepth||this.root.maxDepth)){var o=!1;n.length||(this.subdivide(),o=!0);for(var s=0;8!==s;s++)if(n[s].insert(e,t,i+1))return!0;o&&(n.length=0)}return r.push(t),!0};var a=new n;o.prototype.subdivide=function(){var e=this.aabb,t=e.lowerBound,i=e.upperBound,s=this.children;s.push(new o({aabb:new r({lowerBound:new n(0,0,0)})}),new o({aabb:new r({lowerBound:new n(1,0,0)})}),new o({aabb:new r({lowerBound:new n(1,1,0)})}),new o({aabb:new r({lowerBound:new n(1,1,1)})}),new o({aabb:new r({lowerBound:new n(0,1,1)})}),new o({aabb:new r({lowerBound:new n(0,0,1)})}),new o({aabb:new r({lowerBound:new n(1,0,1)})}),new o({aabb:new r({lowerBound:new n(0,1,0)})})),i.vsub(t,a),a.scale(.5,a);for(var h=this.root||this,l=0;8!==l;l++){var c=s[l];c.root=h;var u=c.aabb.lowerBound;u.x*=a.x,u.y*=a.y,u.z*=a.z,u.vadd(t,u),u.vadd(a,c.aabb.upperBound)}},o.prototype.aabbQuery=function(e,t){this.data,this.children;for(var i=[this];i.length;){var r=i.pop();r.aabb.overlaps(e)&&Array.prototype.push.apply(t,r.data),Array.prototype.push.apply(i,r.children)}return t};var h=new r;o.prototype.rayQuery=function(e,t,i){return e.getAABB(h),h.toLocalFrame(t,h),this.aabbQuery(h,i),i},o.prototype.removeEmptyNodes=function(){for(var e=[this];e.length;){for(var t=e.pop(),i=t.children.length-1;i>=0;i--)t.children[i].data.length||t.children.splice(i,1);Array.prototype.push.apply(e,t.children)}}},{"../collision/AABB":3,"../math/Vec3":30}],51:[function(e,t,i){function r(){this.objects=[],this.type=Object}t.exports=r,r.prototype.release=function(){for(var e=arguments.length,t=0;t!==e;t++)this.objects.push(arguments[t])},r.prototype.get=function(){return 0===this.objects.length?this.constructObject():this.objects.pop()},r.prototype.constructObject=function(){throw new Error("constructObject() not implemented in this Pool subclass yet!")}},{}],52:[function(e,t,i){function r(){this.data={keys:[]}}t.exports=r,r.prototype.get=function(e,t){if(e>t){var i=t;t=e,e=i}return this.data[e+"-"+t]},r.prototype.set=function(e,t,i){if(e>t){var r=t;t=e,e=r}var n=e+"-"+t;this.get(e,t)||this.data.keys.push(n),this.data[n]=i},r.prototype.reset=function(){for(var e=this.data,t=e.keys;t.length>0;){delete e[t.pop()]}}},{}],53:[function(e,t,i){function r(){}t.exports=r,r.defaults=function(e,t){e=e||{};for(var i in t)i in e||(e[i]=t[i]);return e}},{}],54:[function(e,t,i){t.exports=o;var r=e("../math/Vec3"),n=e("./Pool");function o(){n.call(this),this.type=r}o.prototype=new n,o.prototype.constructObject=function(){return new r}},{"../math/Vec3":30,"./Pool":51}],55:[function(e,t,i){t.exports=p;var r=e("../collision/AABB"),n=e("../shapes/Shape"),o=e("../collision/Ray"),s=e("../math/Vec3"),a=e("../math/Transform"),h=(e("../shapes/ConvexPolyhedron"),e("../math/Quaternion")),l=(e("../solver/Solver"),e("../utils/Vec3Pool")),c=e("../equations/ContactEquation"),u=e("../equations/FrictionEquation");function p(e){this.contactPointPool=[],this.frictionEquationPool=[],this.result=[],this.frictionResult=[],this.v3pool=new l,this.world=e,this.currentContactMaterial=null,this.enableFrictionReduction=!1}p.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 c(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},p.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 p=h*s.gravity.length(),f=i.invMass+r.invMass;f>0&&(f=1/f);var d=this.frictionEquationPool,m=d.length?d.pop():new u(i,r,p*f),g=d.length?d.pop():new u(i,r,p*f);return m.bi=g.bi=i,m.bj=g.bj=r,m.minForce=g.minForce=-p*f,m.maxForce=g.maxForce=p*f,m.ri.copy(e.ri),m.rj.copy(e.rj),g.ri.copy(e.ri),g.rj.copy(e.rj),e.ni.tangents(m.t,g.t),m.setSpookParams(a.frictionEquationStiffness,a.frictionEquationRelaxation,s.dt),g.setSpookParams(a.frictionEquationStiffness,a.frictionEquationRelaxation,s.dt),m.enabled=g.enabled=e.enabled,t.push(m,g),!0}return!1};var f=new s,d=new s,m=new s;p.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];f.setZero(),d.setZero(),m.setZero();for(var n=t.bi,o=(t.bj,0);o!==e;o++)(t=this.result[this.result.length-1-o]).bodyA!==n?(f.vadd(t.ni,f),d.vadd(t.ri,d),m.vadd(t.rj,m)):(f.vsub(t.ni,f),d.vadd(t.rj,d),m.vadd(t.ri,m));var s=1/e;d.scale(s,i.ri),m.scale(s,i.rj),r.ri.copy(i.ri),r.rj.copy(i.rj),f.normalize(),f.tangents(i.t,r.t)}};var g=new s,_=new s,v=new h,y=new h;p.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=v,h=y,l=g,c=_,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 b=0;b<f.shapes.length;b++){f.quaternion.mult(f.shapeOrientations[b],a),f.quaternion.vmult(f.shapeOffsets[b],l),l.vadd(f.position,l);for(var x=f.shapes[b],T=0;T<d.shapes.length;T++){d.quaternion.mult(d.shapeOrientations[T],h),d.quaternion.vmult(d.shapeOffsets[T],c),c.vadd(d.position,c);var E=d.shapes[T];if(!(l.distanceTo(c)>x.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.type<E.type?P.call(this,x,E,l,c,a,h,f,d,x,E):P.call(this,E,x,c,l,h,a,d,f,x,E))}}}}};p.prototype[n.types.BOX|n.types.BOX]=p.prototype.boxBox=function(e,t,i,r,n,o,s,a){e.convexPolyhedronRepresentation.material=e.material,t.convexPolyhedronRepresentation.material=t.material,e.convexPolyhedronRepresentation.collisionResponse=e.collisionResponse,t.convexPolyhedronRepresentation.collisionResponse=t.collisionResponse,this.convexConvex(e.convexPolyhedronRepresentation,t.convexPolyhedronRepresentation,i,r,n,o,s,a,e,t)},p.prototype[n.types.BOX|n.types.CONVEXPOLYHEDRON]=p.prototype.boxConvex=function(e,t,i,r,n,o,s,a){e.convexPolyhedronRepresentation.material=e.material,e.convexPolyhedronRepresentation.collisionResponse=e.collisionResponse,this.convexConvex(e.convexPolyhedronRepresentation,t,i,r,n,o,s,a,e,t)},p.prototype[n.types.BOX|n.types.PARTICLE]=p.prototype.boxParticle=function(e,t,i,r,n,o,s,a){e.convexPolyhedronRepresentation.material=e.material,e.convexPolyhedronRepresentation.collisionResponse=e.collisionResponse,this.convexParticle(e.convexPolyhedronRepresentation,t,i,r,n,o,s,a,e,t)},p.prototype[n.types.SPHERE]=p.prototype.sphereSphere=function(e,t,i,r,n,o,s,a){var h=this.createContactEquation(s,a,e,t);r.vsub(i,h.ni),h.ni.normalize(),h.ri.copy(h.ni),h.rj.copy(h.ni),h.ri.mult(e.radius,h.ri),h.rj.mult(-t.radius,h.rj),h.ri.vadd(i,h.ri),h.ri.vsub(s.position,h.ri),h.rj.vadd(r,h.rj),h.rj.vsub(a.position,h.rj),this.result.push(h),this.createFrictionEquationsFromContact(h,this.frictionResult)};var b=new s,x=new s,T=new s;p.prototype[n.types.PLANE|n.types.TRIMESH]=p.prototype.planeTrimesh=function(e,t,i,r,n,o,h,l){var c=new s,u=b;u.set(0,0,1),n.vmult(u,u);for(var p=0;p<t.vertices.length/3;p++){t.getVertex(p,c);var f=new s;f.copy(c),a.pointToWorldFrame(r,o,f,c);var d=x;if(c.vsub(i,d),u.dot(d)<=0){var m=this.createContactEquation(h,l,e,t);m.ni.copy(u);var g=T;u.scale(d.dot(u),g),c.vsub(g,g),m.ri.copy(g),m.ri.vsub(h.position,m.ri),m.rj.copy(c),m.rj.vsub(l.position,m.rj),this.result.push(m),this.createFrictionEquationsFromContact(m,this.frictionResult)}}};var E=new s,A=new s,P=(new s,new s),M=new s,S=new s,C=new s,R=new s,O=new s,I=new s,w=new s,D=new s,L=new s,B=new s,N=new r,F=[];p.prototype[n.types.SPHERE|n.types.TRIMESH]=p.prototype.sphereTrimesh=function(e,t,i,r,n,s,h,l){var c=S,u=C,p=R,f=O,d=I,m=w,g=N,_=M,v=A,y=F;a.pointToLocalFrame(r,s,i,d);var b=e.radius;g.lowerBound.set(d.x-b,d.y-b,d.z-b),g.upperBound.set(d.x+b,d.y+b,d.z+b),t.getTrianglesInAABB(g,y);for(var x=P,T=e.radius*e.radius,V=0;V<y.length;V++)for(var k=0;k<3;k++){if(t.getVertex(t.indices[3*y[V]+k],x),x.vsub(d,v),v.norm2()<=T)_.copy(x),a.pointToWorldFrame(r,s,_,x),x.vsub(i,v),(G=this.createContactEquation(h,l,e,t)).ni.copy(v),G.ni.normalize(),G.ri.copy(G.ni),G.ri.scale(e.radius,G.ri),G.ri.vadd(i,G.ri),G.ri.vsub(h.position,G.ri),G.rj.copy(x),G.rj.vsub(l.position,G.rj),this.result.push(G),this.createFrictionEquationsFromContact(G,this.frictionResult)}for(V=0;V<y.length;V++)for(k=0;k<3;k++){t.getVertex(t.indices[3*y[V]+k],c),t.getVertex(t.indices[3*y[V]+(k+1)%3],u),u.vsub(c,p),d.vsub(u,m);var U=m.dot(p);d.vsub(c,m);var z=m.dot(p);if(z>0&&U<0)if(d.vsub(c,m),f.copy(p),f.normalize(),z=m.dot(f),f.scale(z,m),m.vadd(c,m),(K=m.distanceTo(d))<e.radius){var G=this.createContactEquation(h,l,e,t);m.vsub(d,G.ni),G.ni.normalize(),G.ni.scale(e.radius,G.ri),a.pointToWorldFrame(r,s,m,m),m.vsub(l.position,G.rj),a.vectorToWorldFrame(s,G.ni,G.ni),a.vectorToWorldFrame(s,G.ri,G.ri),this.result.push(G),this.createFrictionEquationsFromContact(G,this.frictionResult)}}for(var W=D,H=L,j=B,X=E,Y=(V=0,y.length);V!==Y;V++){t.getTriangleVertices(y[V],W,H,j),t.getNormal(y[V],X),d.vsub(W,m);var K=m.dot(X);if(X.scale(K,m),d.vsub(m,m),K=m.distanceTo(d),o.pointInTriangle(m,W,H,j)&&K<e.radius){G=this.createContactEquation(h,l,e,t);m.vsub(d,G.ni),G.ni.normalize(),G.ni.scale(e.radius,G.ri),a.pointToWorldFrame(r,s,m,m),m.vsub(l.position,G.rj),a.vectorToWorldFrame(s,G.ni,G.ni),a.vectorToWorldFrame(s,G.ri,G.ri),this.result.push(G),this.createFrictionEquationsFromContact(G,this.frictionResult)}}y.length=0};var V=new s,k=new s;p.prototype[n.types.SPHERE|n.types.PLANE]=p.prototype.spherePlane=function(e,t,i,r,n,o,s,a){var h=this.createContactEquation(s,a,e,t);if(h.ni.set(0,0,1),o.vmult(h.ni,h.ni),h.ni.negate(h.ni),h.ni.normalize(),h.ni.mult(e.radius,h.ri),i.vsub(r,V),h.ni.mult(h.ni.dot(V),k),V.vsub(k,h.rj),-V.dot(h.ni)<=e.radius){var l=h.ri,c=h.rj;l.vadd(i,l),l.vsub(s.position,l),c.vadd(r,c),c.vsub(a.position,c),this.result.push(h),this.createFrictionEquationsFromContact(h,this.frictionResult)}};var U=new s,z=new s,G=new s;function W(e,t,i){for(var r=null,n=e.length,o=0;o!==n;o++){var s=e[o],a=U;e[(o+1)%n].vsub(s,a);var h=z;a.cross(t,h);var l=G;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}var H=new s,j=new s,X=new s,Y=new s,K=[new s,new s,new s,new s,new s,new s],Q=new s,Z=new s,q=new s,J=new s;p.prototype[n.types.SPHERE|n.types.BOX]=p.prototype.sphereBox=function(e,t,i,r,n,o,s,a){var h=this.v3pool,l=K;i.vsub(r,H),t.getSideNormals(l,o);for(var c=e.radius,u=!1,p=Z,f=q,d=J,m=null,g=0,_=0,v=0,y=null,b=0,x=l.length;b!==x&&!1===u;b++){var T=j;T.copy(l[b]);var E=T.norm();T.normalize();var A=H.dot(T);if(A<E+c&&A>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),O=H.dot(M);if(R<S&&R>-S&&O<C&&O>-C){var I=Math.abs(A-E-c);(null===y||I<y)&&(y=I,_=R,v=O,m=E,p.copy(T),f.copy(P),d.copy(M),g++)}}}if(g){u=!0;var w=this.createContactEquation(s,a,e,t);p.mult(-c,w.ri),w.ni.copy(p),w.ni.negate(w.ni),p.mult(m,p),f.mult(_,f),p.vadd(f,p),d.mult(v,d),p.vadd(d,w.rj),w.ri.vadd(i,w.ri),w.ri.vsub(s.position,w.ri),w.rj.vadd(r,w.rj),w.rj.vsub(a.position,w.rj),this.result.push(w),this.createFrictionEquationsFromContact(w,this.frictionResult)}for(var D=h.get(),L=Q,B=0;2!==B&&!u;B++)for(var N=0;2!==N&&!u;N++)for(var F=0;2!==F&&!u;F++){if(D.set(0,0,0),B?D.vadd(l[0],D):D.vsub(l[0],D),N?D.vadd(l[1],D):D.vsub(l[1],D),F?D.vadd(l[2],D):D.vsub(l[2],D),r.vadd(D,L),L.vsub(i,L),L.norm2()<c*c)u=!0,(w=this.createContactEquation(s,a,e,t)).ri.copy(L),w.ri.normalize(),w.ni.copy(w.ri),w.ri.mult(c,w.ri),w.rj.copy(D),w.ri.vadd(i,w.ri),w.ri.vsub(s.position,w.ri),w.rj.vadd(r,w.rj),w.rj.vsub(a.position,w.rj),this.result.push(w),this.createFrictionEquationsFromContact(w,this.frictionResult)}h.release(D),D=null;var V=h.get(),k=h.get(),U=(w=h.get(),h.get()),z=(I=h.get(),l.length);for(B=0;B!==z&&!u;B++)for(N=0;N!==z&&!u;N++)if(B%3!=N%3){l[N].cross(l[B],V),V.normalize(),l[B].vadd(l[N],k),w.copy(i),w.vsub(k,w),w.vsub(r,w);var G=w.dot(V);V.mult(G,U);for(F=0;F===B%3||F===N%3;)F++;I.copy(i),I.vsub(U,I),I.vsub(k,I),I.vsub(r,I);var W=Math.abs(G),$=I.norm();if(W<l[F].norm()&&$<c){u=!0;var ee=this.createContactEquation(s,a,e,t);k.vadd(U,ee.rj),ee.rj.copy(ee.rj),I.negate(ee.ni),ee.ni.normalize(),ee.ri.copy(ee.rj),ee.ri.vadd(r,ee.ri),ee.ri.vsub(i,ee.ri),ee.ri.normalize(),ee.ri.mult(c,ee.ri),ee.ri.vadd(i,ee.ri),ee.ri.vsub(s.position,ee.ri),ee.rj.vadd(r,ee.rj),ee.rj.vsub(a.position,ee.rj),this.result.push(ee),this.createFrictionEquationsFromContact(ee,this.frictionResult)}}h.release(V,k,w,U,I)};var $=new s,ee=new s,te=new s,ie=new s,re=new s,ne=new s,oe=new s,se=new s,ae=new s,he=new s;p.prototype[n.types.SPHERE|n.types.CONVEXPOLYHEDRON]=p.prototype.sphereConvex=function(e,t,i,r,n,o,s,a){var h=this.v3pool;i.vsub(r,$);for(var l=t.faceNormals,c=t.faces,u=t.vertices,p=e.radius,f=0;f!==u.length;f++){var d=u[f],m=re;o.vmult(d,m),r.vadd(m,m);var g=ie;if(m.vsub(i,g),g.norm2()<p*p)return _=!0,(I=this.createContactEquation(s,a,e,t)).ri.copy(g),I.ri.normalize(),I.ni.copy(I.ri),I.ri.mult(p,I.ri),m.vsub(r,I.rj),I.ri.vadd(i,I.ri),I.ri.vsub(s.position,I.ri),I.rj.vadd(r,I.rj),I.rj.vsub(a.position,I.rj),this.result.push(I),void this.createFrictionEquationsFromContact(I,this.frictionResult)}for(var _=!1,v=(f=0,c.length);f!==v&&!1===_;f++){var y=l[f],b=c[f],x=ne;o.vmult(y,x);var T=oe;o.vmult(u[b[0]],T),T.vadd(r,T);var E=se;x.mult(-p,E),i.vadd(E,E);var A=ae;E.vsub(T,A);var P=A.dot(x),M=he;if(i.vsub(T,M),P<0&&M.dot(x)>0){for(var S=[],C=0,R=b.length;C!==R;C++){var O=h.get();o.vmult(u[b[C]],O),r.vadd(O,O),S.push(O)}if(W(S,x,i)){_=!0;var I=this.createContactEquation(s,a,e,t);x.mult(-p,I.ri),x.negate(I.ni);var w=h.get();x.mult(-P,w);var D=h.get();x.mult(-p,D),i.vsub(r,I.rj),I.rj.vadd(D,I.rj),I.rj.vadd(w,I.rj),I.rj.vadd(r,I.rj),I.rj.vsub(a.position,I.rj),I.ri.vadd(i,I.ri),I.ri.vsub(s.position,I.ri),h.release(w),h.release(D),this.result.push(I),this.createFrictionEquationsFromContact(I,this.frictionResult);C=0;for(var L=S.length;C!==L;C++)h.release(S[C]);return}for(C=0;C!==b.length;C++){var B=h.get(),N=h.get();o.vmult(u[b[(C+1)%b.length]],B),o.vmult(u[b[(C+2)%b.length]],N),r.vadd(B,B),r.vadd(N,N);var F=ee;N.vsub(B,F);var V=te;F.unit(V);var k=h.get(),U=h.get();i.vsub(B,U);var z=U.dot(V);V.mult(z,k),k.vadd(B,k);var G=h.get();if(k.vsub(i,G),z>0&&z*z<F.norm2()&&G.norm2()<p*p){I=this.createContactEquation(s,a,e,t);k.vsub(r,I.rj),k.vsub(i,I.ni),I.ni.normalize(),I.ni.mult(p,I.ri),I.rj.vadd(r,I.rj),I.rj.vsub(a.position,I.rj),I.ri.vadd(i,I.ri),I.ri.vsub(s.position,I.ri),this.result.push(I),this.createFrictionEquationsFromContact(I,this.frictionResult);for(C=0,L=S.length;C!==L;C++)h.release(S[C]);return h.release(B),h.release(N),h.release(k),h.release(G),void h.release(U)}h.release(B),h.release(N),h.release(k),h.release(G),h.release(U)}for(C=0,L=S.length;C!==L;C++)h.release(S[C])}}};new s,new s;p.prototype[n.types.PLANE|n.types.BOX]=p.prototype.planeBox=function(e,t,i,r,n,o,s,a){t.convexPolyhedronRepresentation.material=t.material,t.convexPolyhedronRepresentation.collisionResponse=t.collisionResponse,this.planeConvex(e,t.convexPolyhedronRepresentation,i,r,n,o,s,a)};var le=new s,ce=new s,ue=new s,pe=new s;p.prototype[n.types.PLANE|n.types.CONVEXPOLYHEDRON]=p.prototype.planeConvex=function(e,t,i,r,n,o,s,a){var h=le,l=ce;l.set(0,0,1),n.vmult(l,l);for(var c=0,u=ue,p=0;p!==t.vertices.length;p++){if(h.copy(t.vertices[p]),o.vmult(h,h),r.vadd(h,h),h.vsub(i,u),l.dot(u)<=0){var f=this.createContactEquation(s,a,e,t),d=pe;l.mult(l.dot(u),d),h.vsub(d,d),d.vsub(i,f.ri),f.ni.copy(l),h.vsub(r,f.rj),f.ri.vadd(i,f.ri),f.ri.vsub(s.position,f.ri),f.rj.vadd(r,f.rj),f.rj.vsub(a.position,f.rj),this.result.push(f),c++,this.enableFrictionReduction||this.createFrictionEquationsFromContact(f,this.frictionResult)}}this.enableFrictionReduction&&c&&this.createFrictionFromAverage(c)};var fe=new s,de=new s;p.prototype[n.types.CONVEXPOLYHEDRON]=p.prototype.convexConvex=function(e,t,i,r,n,o,s,a,h,l,c,u){var p=fe;if(!(i.distanceTo(r)>e.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 s,ge=new s,_e=new s;p.prototype[n.types.PLANE|n.types.PARTICLE]=p.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;if(r.vsub(s.position,l),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 s;p.prototype[n.types.PARTICLE|n.types.SPHERE]=p.prototype.sphereParticle=function(e,t,i,r,n,o,s,a){var h=ve;if(h.set(0,0,1),r.vsub(i,h),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 h,be=new s,xe=(new s,new s),Te=new s,Ee=new s;p.prototype[n.types.PARTICLE|n.types.CONVEXPOLYHEDRON]=p.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(_)<Math.abs(u))&&(u=_,h=f,l.copy(g),0)}if(-1!==h){var v=this.createContactEquation(a,s,t,e);l.mult(u,c),c.vadd(r,c),c.vsub(i,c),v.rj.copy(c),l.negate(v.ni),v.ri.set(0,0,0);var y=v.ri,b=v.rj;y.vadd(r,y),y.vsub(a.position,y),b.vadd(i,b),b.vsub(s.position,b),this.result.push(v),this.createFrictionEquationsFromContact(v,this.frictionResult)}else console.warn("Point found inside convex, but did not find penetrating face!")}},p.prototype[n.types.BOX|n.types.HEIGHTFIELD]=p.prototype.boxHeightfield=function(e,t,i,r,n,o,s,a){e.convexPolyhedronRepresentation.material=e.material,e.convexPolyhedronRepresentation.collisionResponse=e.collisionResponse,this.convexHeightfield(e.convexPolyhedronRepresentation,t,i,r,n,o,s,a)};var Ae=new s,Pe=new s,Me=[0];p.prototype[n.types.CONVEXPOLYHEDRON|n.types.HEIGHTFIELD]=p.prototype.convexHeightfield=function(e,t,i,r,n,o,s,h){var l=t.data,c=t.elementSize,u=e.boundingSphereRadius,p=Pe,f=Me,d=Ae;a.pointToLocalFrame(r,o,i,d);var m=Math.floor((d.x-u)/c)-1,g=Math.ceil((d.x+u)/c)+1,_=Math.floor((d.y-u)/c)-1,v=Math.ceil((d.y+u)/c)+1;if(!(g<0||v<0||m>l.length||_>l[0].length)){m<0&&(m=0),g<0&&(g=0),_<0&&(_=0),v<0&&(v=0),m>=l.length&&(m=l.length-1),g>=l.length&&(g=l.length-1),v>=l[0].length&&(v=l[0].length-1),_>=l[0].length&&(_=l[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+u<b))for(var T=m;T<g;T++)for(var E=_;E<v;E++)t.getConvexTrianglePillar(T,E,!1),a.pointToWorldFrame(r,o,t.pillarOffset,p),i.distanceTo(p)<t.pillarConvex.boundingSphereRadius+e.boundingSphereRadius&&this.convexConvex(e,t.pillarConvex,i,p,n,o,s,h,null,null,f,null),t.getConvexTrianglePillar(T,E,!0),a.pointToWorldFrame(r,o,t.pillarOffset,p),i.distanceTo(p)<t.pillarConvex.boundingSphereRadius+e.boundingSphereRadius&&this.convexConvex(e,t.pillarConvex,i,p,n,o,s,h,null,null,f,null)}};var Se=new s,Ce=new s;p.prototype[n.types.SPHERE|n.types.HEIGHTFIELD]=p.prototype.sphereHeightfield=function(e,t,i,r,n,o,s,h){var l=t.data,c=e.radius,u=t.elementSize,p=Ce,f=Se;a.pointToLocalFrame(r,o,i,f);var d=Math.floor((f.x-c)/u)-1,m=Math.ceil((f.x+c)/u)+1,g=Math.floor((f.y-c)/u)-1,_=Math.ceil((f.y+c)/u)+1;if(!(m<0||_<0||d>l.length||_>l[0].length)){d<0&&(d=0),m<0&&(m=0),g<0&&(g=0),_<0&&(_=0),d>=l.length&&(d=l.length-1),m>=l.length&&(m=l.length-1),_>=l[0].length&&(_=l[0].length-1),g>=l[0].length&&(g=l[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+c<y))for(var x=this.result,T=d;T<m;T++)for(var E=g;E<_;E++){var A=x.length;if(t.getConvexTrianglePillar(T,E,!1),a.pointToWorldFrame(r,o,t.pillarOffset,p),i.distanceTo(p)<t.pillarConvex.boundingSphereRadius+e.boundingSphereRadius&&this.sphereConvex(e,t.pillarConvex,i,p,n,o,s,h),t.getConvexTrianglePillar(T,E,!0),a.pointToWorldFrame(r,o,t.pillarOffset,p),i.distanceTo(p)<t.pillarConvex.boundingSphereRadius+e.boundingSphereRadius&&this.sphereConvex(e,t.pillarConvex,i,p,n,o,s,h),x.length-A>2)return}}}},{"../collision/AABB":3,"../collision/Ray":9,"../equations/ContactEquation":19,"../equations/FrictionEquation":21,"../math/Quaternion":28,"../math/Transform":29,"../math/Vec3":30,"../shapes/ConvexPolyhedron":38,"../shapes/Shape":43,"../solver/Solver":47,"../utils/Vec3Pool":54}],56:[function(e,t,i){t.exports=v;var r=e("../shapes/Shape"),n=e("../math/Vec3"),o=e("../math/Quaternion"),s=e("../solver/GSSolver"),a=(e("../utils/Vec3Pool"),e("../equations/ContactEquation"),e("../equations/FrictionEquation"),e("./Narrowphase")),h=e("../utils/EventTarget"),l=e("../collision/ArrayCollisionMatrix"),c=e("../material/Material"),u=e("../material/ContactMaterial"),p=e("../objects/Body"),f=e("../utils/TupleDictionary"),d=e("../collision/RaycastResult"),m=e("../collision/AABB"),g=e("../collision/Ray"),_=e("../collision/NaiveBroadphase");function v(){h.apply(this),this.dt=-1,this.allowSleep=!1,this.contacts=[],this.frictionEquations=[],this.quatNormalizeSkip=0,this.quatNormalizeFast=!1,this.time=0,this.stepnumber=0,this.default_dt=1/60,this.nextId=0,this.gravity=new n,this.broadphase=new _,this.bodies=[],this.solver=new s,this.constraints=[],this.narrowphase=new a(this),this.collisionMatrix=new l,this.collisionMatrixPrevious=new l,this.materials=[],this.contactmaterials=[],this.contactMaterialTable=new f,this.defaultMaterial=new c("default"),this.defaultContactMaterial=new u(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}}v.prototype=new h;new m;var y=new g;if(v.prototype.getContactMaterial=function(e,t){return this.contactMaterialTable.get(e.id,t.id)},v.prototype.numObjects=function(){return this.bodies.length},v.prototype.collisionMatrixTick=function(){var e=this.collisionMatrixPrevious;this.collisionMatrixPrevious=this.collisionMatrix,this.collisionMatrix=e,this.collisionMatrix.reset()},v.prototype.add=v.prototype.addBody=function(e){-1===this.bodies.indexOf(e)&&(e.index=this.bodies.length,this.bodies.push(e),e.world=this,e.initPosition.copy(e.position),e.initVelocity.copy(e.velocity),e.timeLastSleepy=this.time,e instanceof p&&(e.initAngularVelocity.copy(e.angularVelocity),e.initQuaternion.copy(e.quaternion)),this.collisionMatrix.setNumObjects(this.bodies.length),this.addBodyEvent.body=e,this.dispatchEvent(this.addBodyEvent))},v.prototype.addConstraint=function(e){this.constraints.push(e)},v.prototype.removeConstraint=function(e){var t=this.constraints.indexOf(e);-1!==t&&this.constraints.splice(t,1)},v.prototype.rayTest=function(e,t,i){i instanceof d?this.raycastClosest(e,t,{skipBackfaces:!0},i):this.raycastAll(e,t,{skipBackfaces:!0},i)},v.prototype.raycastAll=function(e,t,i,r){return i.mode=g.ALL,i.from=e,i.to=t,i.callback=r,y.intersectWorld(this,i)},v.prototype.raycastAny=function(e,t,i,r){return i.mode=g.ANY,i.from=e,i.to=t,i.result=r,y.intersectWorld(this,i)},v.prototype.raycastClosest=function(e,t,i,r){return i.mode=g.CLOSEST,i.from=e,i.to=t,i.result=r,y.intersectWorld(this,i)},v.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)}},v.prototype.removeBody=v.prototype.remove,v.prototype.addMaterial=function(e){this.materials.push(e)},v.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 n;v.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!==p.STATIC&&c.sleepState!==p.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 n,new n,new n,new n,new n,new n,new n,new n,new n,new o,new o),O=new o,I=new n;v.prototype.internalStep=function(e){this.dt=e;var t,i=this.contacts,n=S,o=C,s=this.numObjects(),a=this.bodies,h=this.solver,l=this.gravity,c=this.doProfiling,u=this.profile,f=p.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((U=a[y]).type&f){var b=U.force,x=U.mass;b.x+=x*g,b.y+=x*_,b.z+=x*v}}y=0;for(var w=this.subsystems.length;y!==w;y++)this.subsystems[y].update();c&&(t=performance.now()),n.length=0,o.length=0,this.broadphase.collisionPairs(this,n,o),c&&(u.broadphase=performance.now()-t);var D=d.length;for(y=0;y!==D;y++){if(!(G=d[y]).collideConnected)for(var L=n.length-1;L>=0;L-=1)(G.bodyA===n[L]&&G.bodyB===o[L]||G.bodyB===n[L]&&G.bodyA===o[L])&&(n.splice(L,1),o.splice(L,1))}this.collisionMatrixTick(),c&&(t=performance.now());var B=P,N=i.length;for(y=0;y!==N;y++)B.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(n,o,this,i,B,this.frictionEquations,m),c&&(u.narrowphase=performance.now()-t),c&&(t=performance.now());for(y=0;y<this.frictionEquations.length;y++)h.addEquation(this.frictionEquations[y]);for(var V=i.length,k=0;k!==V;k++){var U=(G=i[k]).bi,z=G.bj;G.si,G.sj,(U.material&&z.material&&this.getContactMaterial(U.material,z.material)||this.defaultContactMaterial).friction;if(U.material&&z.material&&(U.material.friction>=0&&z.material.friction>=0&&U.material.friction*z.material.friction,U.material.restitution>=0&&z.material.restitution>=0&&(G.restitution=U.material.restitution*z.material.restitution)),h.addEquation(G),U.allowSleep&&U.type===p.DYNAMIC&&U.sleepState===p.SLEEPING&&z.sleepState===p.AWAKE&&z.type!==p.STATIC)z.velocity.norm2()+z.angularVelocity.norm2()>=2*Math.pow(z.sleepSpeedLimit,2)&&(U._wakeUpAfterNarrowphase=!0);if(z.allowSleep&&z.type===p.DYNAMIC&&z.sleepState===p.SLEEPING&&U.sleepState===p.AWAKE&&U.type!==p.STATIC)U.velocity.norm2()+U.angularVelocity.norm2()>=2*Math.pow(U.sleepSpeedLimit,2)&&(z._wakeUpAfterNarrowphase=!0);this.collisionMatrix.set(U,z,!0),this.collisionMatrixPrevious.get(U,z)||(A.body=z,A.contact=G,U.dispatchEvent(A),A.body=U,z.dispatchEvent(A))}for(c&&(u.makeContactConstraints=performance.now()-t,t=performance.now()),y=0;y!==s;y++){(U=a[y])._wakeUpAfterNarrowphase&&(U.wakeUp(),U._wakeUpAfterNarrowphase=!1)}D=d.length;for(y=0;y!==D;y++){var G;(G=d[y]).update();L=0;for(var W=G.equations.length;L!==W;L++){var H=G.equations[L];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((U=a[y]).type&f){var X=j(1-U.linearDamping,e),Y=U.velocity;Y.mult(X,Y);var K=U.angularVelocity;if(K){var Q=j(1-U.angularDamping,e);K.mult(Q,K)}}}for(this.dispatchEvent(E),y=0;y!==s;y++){(U=a[y]).preStep&&U.preStep.call(U)}c&&(t=performance.now());var Z=R,q=O,J=this.stepnumber,$=p.DYNAMIC|p.KINEMATIC,ee=J%(this.quatNormalizeSkip+1)==0,te=this.quatNormalizeFast,ie=.5*e;r.types.PLANE,r.types.CONVEXPOLYHEDRON;for(y=0;y!==s;y++){var re=a[y],ne=re.force,oe=re.torque;if(re.type&$&&re.sleepState!==p.SLEEPING){var se=re.velocity,ae=re.angularVelocity,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,I),I.mult(e,I),I.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=(U=a[y]).postStep;pe&&pe.call(U)}if(this.allowSleep)for(y=0;y!==s;y++)a[y].sleepTick(this.time)},v.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)},e.exports=n()},function(e,t,i){var r,n,o={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 o.lerp(e,t,o.random())},randInt:function(e,t,i){return 1*o.lerp(e,t,o.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 o.max(t,o.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==o.CustomError?console.error(e,t):o.CustomError.innerHTML+=e+" - "+t+"<br>"}};r||(r="undefined"!=typeof Float32Array?Float32Array:Array);try{!function(e){var t,i=["now","webkitNow","msNow","mozNow"];if(e.performance)for(var r=0;r<i.length;++r){var n=i[r];if(e.performance[n]){t=function(){return e.performance[n]()};break}}t||(t=Date.now),o.now=t}(window)}catch(e){o.now=function(){return 0}}function s(e,t,i){return{a:e,b:t,c:i}}function a(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 h(e,t){return{x:e,y:t}}o.World=function(e,t,i,r){switch(this.timeStep=e||.01666,this.numIterations=i||8,t||2){case 1:this.broadPhase=new o.BruteForceBroadPhase;break;case 2:default:this.broadPhase=new o.SAPBroadPhase;break;case 3:this.broadPhase=new o.DBVTBroadPhase}this.performance=null,this.isNoStat=r||!1,this.isNoStat||(this.performance=new o.Performance(this)),this.enableRandomizer=!0,this.rigidBodies=null,this.numRigidBodies=0,this.contacts=null,this.unusedContacts=null,this.numContacts=0,this.numContactPoints=0,this.joints=null,this.numJoints=0,this.numIslands=0,this.gravity=new o.Vec3(0,-9.80665,0);this.detectors=[],this.detectors.length=5;for(var n=5;n--;)this.detectors[n]=[],this.detectors[n].length=5;this.detectors[o.SHAPE_SPHERE][o.SHAPE_SPHERE]=new o.SphereSphereCollisionDetector,this.detectors[o.SHAPE_SPHERE][o.SHAPE_BOX]=new o.SphereBoxCollisionDetector(!1),this.detectors[o.SHAPE_BOX][o.SHAPE_SPHERE]=new o.SphereBoxCollisionDetector(!0),this.detectors[o.SHAPE_BOX][o.SHAPE_BOX]=new o.BoxBoxCollisionDetector,this.detectors[o.SHAPE_CYLINDER][o.SHAPE_CYLINDER]=new o.CylinderCylinderCollisionDetector,this.detectors[o.SHAPE_CYLINDER][o.SHAPE_BOX]=new o.BoxCylinderCollisionDetector(!0),this.detectors[o.SHAPE_BOX][o.SHAPE_CYLINDER]=new o.BoxCylinderCollisionDetector(!1),this.detectors[o.SHAPE_CYLINDER][o.SHAPE_SPHERE]=new o.SphereCylinderCollisionDetector(!0),this.detectors[o.SHAPE_SPHERE][o.SHAPE_CYLINDER]=new o.SphereCylinderCollisionDetector(!1),this.detectors[o.SHAPE_TETRA][o.SHAPE_TETRA]=new o.TetraTetraCollisionDetector,this.randX=65535,this.randA=98765,this.randB=123456789,this.islandRigidBodies=[],this.islandStack=[],this.islandConstraints=[]},o.World.prototype={constructor:o.World,clear:function(){for(this.randX=65535;null!==this.joints;)this.removeJoint(this.joints);for(;null!==this.contacts;)this.removeContact(this.contacts);for(;null!==this.rigidBodies;)this.removeRigidBody(this.rigidBodies);o.nextID=0,o.proxyID=0},addRigidBody:function(e){e.parent&&o.Error("World","It is not possible to be added to more than one world one of the rigid body"),e.parent=this,e.awake();for(var t=e.shapes;null!==t;t=t.next)this.addShape(t);null!==this.rigidBodies&&((this.rigidBodies.prev=e).next=this.rigidBodies),this.rigidBodies=e,this.numRigidBodies++},removeRigidBody:function(e){var t=e;if(t.parent===this){t.awake();for(var i=t.jointLink;null!=i;){var r=i.joint;i=i.next,this.removeJoint(r)}for(var n=e.shapes;null!==n;n=n.next)this.removeShape(n);var o=t.prev,s=t.next;null!==o&&(o.next=s),null!==s&&(s.prev=o),this.rigidBodies==t&&(this.rigidBodies=s),t.prev=null,t.next=null,t.parent=null,this.numRigidBodies--}},getByName:function(e){for(var t=null,i=this.rigidBodies;null!==i;)" "!==i.name&&i.name===e&&(t=i),i=i.next;for(var r=this.joints;null!==r;)""!==r.name&&r.name===e&&(t=r),r=r.next;return t},addShape:function(e){e.parent&&e.parent.parent||o.Error("World","It is not possible to be added alone to shape world"),e.proxy=this.broadPhase.createProxy(e),e.updateProxy(),this.broadPhase.addProxy(e.proxy)},removeShape:function(e){this.broadPhase.removeProxy(e.proxy),e.proxy=null},addJoint:function(e){e.parent&&o.Error("World","It is not possible to be added to more than one world one of the joint"),null!=this.joints&&((this.joints.prev=e).next=this.joints),this.joints=e,e.parent=this,this.numJoints++,e.awake(),e.attach()},removeJoint:function(e){var t=e,i=t.prev,r=t.next;null!==i&&(i.next=r),null!==r&&(r.prev=i),this.joints==t&&(this.joints=r),t.prev=null,t.next=null,this.numJoints--,t.awake(),t.detach(),t.parent=null},worldscale:function(e){o.WORLD_SCALE=e||100,o.INV_SCALE=1/o.WORLD_SCALE},addContact:function(e,t){var i;null!==this.unusedContacts?(i=this.unusedContacts,this.unusedContacts=this.unusedContacts.next):i=new o.Contact,i.attach(e,t),i.detector=this.detectors[e.type][t.type],this.contacts&&((this.contacts.prev=i).next=this.contacts),this.contacts=i,this.numContacts++},removeContact:function(e){var t=e.prev,i=e.next;i&&(i.prev=t),t&&(t.next=i),this.contacts==e&&(this.contacts=i),e.prev=null,e.next=null,e.detach(),e.next=this.unusedContacts,this.unusedContacts=e,this.numContacts--},checkContact:function(e,t){for(var i,r,n=this.contacts;null!==n;){if(i=n.body1.name||" ",r=n.body2.name||" ",i==e&&r==t||r==e&&i==t)return!!n.touching;n=n.next}return!1},callSleep:function(e){return!!e.allowSleep&&(!(e.linearVelocity.lengthSq()>.04)&&!(e.angularVelocity.lengthSq()>.25))},step:function(){var e,t,i,r,n=!this.isNoStat;n&&(e=o.now());for(var s=this.rigidBodies;null!==s;)s.addedToIsland=!1,s.sleeping&&(s.linearVelocity.testZero()||s.angularVelocity.testZero()||s.position.testDiff(s.sleepPosition)||s.orientation.testDiff(s.sleepOrientation))&&s.awake(),s=s.next;n&&(t=o.now()),this.broadPhase.detectPairs();for(var a=this.broadPhase.pairs,h=this.broadPhase.numPairs;h--;){var l,c,u,p=a[h];p.shape1.id<p.shape2.id?(l=p.shape1,c=p.shape2):(l=p.shape2,c=p.shape1),u=l.numContacts<c.numContacts?l.contactLink:c.contactLink;for(var f=!1;u;){if((P=u.contact).shape1==l&&P.shape2==c){P.persisting=!0,f=!0;break}u=u.next}f||this.addContact(l,c)}for(n&&(i=o.now(),this.performance.broadPhaseTime=i-t),this.numContactPoints=0,P=this.contacts;null!==P;)if(P.persisting||!P.shape1.aabb.intersectTest(P.shape2.aabb)){var d=P.body1,m=P.body2;(d.isDynamic&&!d.sleeping||m.isDynamic&&!m.sleeping)&&P.updateManifold(),this.numContactPoints+=P.manifold.numPoints,P.persisting=!1,P.constraint.addedToIsland=!1,P=P.next}else{var g=P.next;this.removeContact(P),P=g}n&&(r=o.now(),this.performance.narrowPhaseTime=r-i);var _,v,y=1/this.timeStep;for(_=this.joints;null!==_;_=_.next)_.addedToIsland=!1;this.islandRigidBodies=[],this.islandConstraints=[],this.islandStack=[],t=o.now(),this.numIslands=0;for(var b=this.rigidBodies;null!==b;b=b.next)if(!(b.addedToIsland||b.isStatic||b.sleeping))if(b.isLonely())b.isDynamic&&b.linearVelocity.addTime(this.gravity,this.timeStep),this.callSleep(b)?(b.sleepTime+=this.timeStep,b.sleepTime>.5?b.sleep():b.updatePosition(this.timeStep)):(b.sleepTime=0,b.updatePosition(this.timeStep)),this.numIslands++;else{var x=0,T=0,E=1;this.islandStack[0]=b,b.addedToIsland=!0;do{if(s=this.islandStack[--E],this.islandStack[E]=null,s.sleeping=!1,this.islandRigidBodies[x++]=s,!s.isStatic){for(var A=s.contactLink;null!==A;A=A.next){var P;if(!(v=(P=A.contact).constraint).addedToIsland&&P.touching)this.islandConstraints[T++]=v,v.addedToIsland=!0,(g=A.body).addedToIsland||(this.islandStack[E++]=g,g.addedToIsland=!0)}for(var M=s.jointLink;null!==M;M=M.next)(v=M.joint).addedToIsland||(this.islandConstraints[T++]=v,v.addedToIsland=!0,!(g=M.body).addedToIsland&&g.isDynamic&&(this.islandStack[E++]=g,g.addedToIsland=!0))}}while(0!=E);for(var S=(new o.Vec3).addTime(this.gravity,this.timeStep),C=x;C--;)(s=this.islandRigidBodies[C]).isDynamic&&s.linearVelocity.addEqual(S);if(this.enableRandomizer)for(C=T;C--;)if(0!==C){var R=(this.randX=this.randX*this.randA+this.randB&2147483647)/2147483648*C|0;v=this.islandConstraints[C],this.islandConstraints[C]=this.islandConstraints[R],this.islandConstraints[R]=v}for(C=T;C--;)this.islandConstraints[C].preSolve(this.timeStep,y);for(var O=this.numIterations;O--;)for(C=T;C--;)this.islandConstraints[C].solve();for(C=T;C--;)this.islandConstraints[C].postSolve(),this.islandConstraints[C]=null;var I=10;for(C=x;C--;)s=this.islandRigidBodies[C],this.callSleep(s)?(s.sleepTime+=this.timeStep,s.sleepTime<I&&(I=s.sleepTime)):(s.sleepTime=0,I=0);if(I>.5)for(C=x;C--;)this.islandRigidBodies[C].sleep(),this.islandRigidBodies[C]=null;else for(C=x;C--;)this.islandRigidBodies[C].updatePosition(this.timeStep),this.islandRigidBodies[C]=null;this.numIslands++}n&&(i=o.now(),this.performance.solvingTime=i-t,i=o.now(),this.performance.upfps(),this.performance.totalTime=i-e)}},o.RigidBody=function(e,t,i,r,n,s,a){this.name=" ",this.MAX_SHAPES=64,this.prev=null,this.next=null,this.type=o.BODY_NULL,this.massInfo=new o.MassInfo,this.position=new o.Vec3(e,t,i),this.orientation=this.rotationAxisToQuad(r||0,n||0,s||0,a||0),this.newPosition=new o.Vec3,this.controlPos=!1,this.newOrientation=new o.Quat,this.newRotation=new o.Vec3,this.currentRotation=new o.Vec3,this.controlRot=!1,this.controlRotInTime=!1,this.linearVelocity=new o.Vec3,this.angularVelocity=new o.Vec3,this.matrix=new o.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 o.Vec3,this.sleepOrientation=new o.Quat,this.isStatic=!1,this.isDynamic=!1,this.rotation=new o.Mat33,this.mass=NaN,this.inverseMass=NaN,this.inverseInertia=new o.Mat33,this.localInertia=new o.Mat33,this.inverseLocalInertia=new o.Mat33,this.addedToIsland=!1,this.allowSleep=!0,this.sleepTime=0,this.sleeping=!1},o.RigidBody.prototype={constructor:o.RigidBody,addShape:function(e){e.parent&&o.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||o.BODY_DYNAMIC,this.isDynamic=this.type==o.BODY_DYNAMIC,this.isStatic=this.type==o.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 o.Mat33,s=new o.Vec3,a=this.shapes;null!=a;a=a.next){a.calculateMassInfo(this.massInfo);var h=this.massInfo.mass,l=a.relativePosition.x,c=a.relativePosition.y,u=a.relativePosition.z;s.addScale(a.relativePosition,h),this.mass+=h,this.rotateInertia(a.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,s.scaleEqual(this.inverseMass),i){for(this.position.addEqual(s),a=this.shapes;null!=a;a=a.next)a.relativePosition.subEqual(s);l=s.x,c=s.y,u=s.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==o.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 o.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 o.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:o.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,O=a*_+c*v+f*y,I=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+O*h+I*u,w[7]=R*s+O*l+I*p,w[8]=R*a+O*c+I*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 o.Vec3;i.sub(e,this.position).cross(i,t).mulMat(this.inverseInertia,i),this.angularVelocity.addEqual(i)},rotationVectToQuad:function(e){var t=o.EulerToAxis(e.x*o.degtorad,e.y*o.degtorad,e.z*o.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/o.sqrt(n),i*=n,r*=n);var s=o.sin(.5*e),a=o.cos(.5*e);return new o.Quat(a,s*t,s*i,s*r)},setPosition:function(e){this.newPosition.copy(e).multiplyScalar(o.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(o.INV_SCALE),this.awake()},resetQuaternion:function(e){this.angularVelocity.set(0,0,0),this.orientation=new o.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 o.Vec3(e,t,i)),this.awake()},getPosition:function(){return(new o.Vec3).scale(this.position,o.WORLD_SCALE)},getRotation:function(){return(new o.Euler).setFromRotationMatrix(this.rotation)},getQuaternion:function(){return(new o.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*o.WORLD_SCALE,i[13]=t.y*o.WORLD_SCALE,i[14]=t.z*o.WORLD_SCALE,i[15]=0),i}},o.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))},o.Body.prototype={constructor:o.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)}},o.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))},o.Link.prototype={constructor:o.Link,getPosition:function(){return this.joint.getPosition()},getMatrix:function(){return this.joint.getMatrix()},remove:function(){this.joint.dispose()},awake:function(){this.joint.awake()}},o.Dictionary=function(){this.data={},this.keys=[]},o.Dictionary.prototype={constructor:o.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()]}},o.Performance=function(e){this.parent=e,this.infos=new r(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=o.REVISION,this.fps=0,this.broadPhaseTime=0,this.narrowPhaseTime=0,this.solvingTime=0,this.totalTime=0},o.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 o.fix(this.totalTime-(this.broadPhaseTime+this.narrowPhaseTime+this.solvingTime))},show:function(){return["Oimo.js "+this.version+"<br>",this.broadPhase+"<br><br>","FPS: "+this.fps+" fps<br><br>","rigidbody "+this.parent.numRigidBodies+"<br>","contact "+this.parent.numContacts+"<br>","ct-point "+this.parent.numContactPoints+"<br>","paircheck "+this.parent.broadPhase.numPairChecks+"<br>","island "+this.parent.numIslands+"<br><br>","Time in milliseconde<br><br>","broad-phase "+o.fix(this.broadPhaseTime)+"<br>","narrow-phase "+o.fix(this.narrowPhaseTime)+"<br>","solving "+o.fix(this.solvingTime)+"<br>","total "+o.fix(this.totalTime)+"<br>","updating "+this.updatingTime()+"<br>"].join("\n")},toArray:function(){return this.infos[0]=this.parent.broadPhase.types,this.infos[1]=this.parent.numRigidBodies,this.infos[2]=this.parent.numContacts,this.infos[3]=this.parent.broadPhase.numPairChecks,this.infos[4]=this.parent.numContactPoints,this.infos[5]=this.parent.numIslands,this.infos[6]=this.broadPhaseTime,this.infos[7]=this.narrowPhaseTime,this.infos[8]=this.solvingTime,this.infos[9]=this.updatingTime(),this.infos[10]=this.totalTime,this.infos[11]=this.fps,this.infos}},o.Mat44=function(e,t,i,n,o,s,a,h,l,c,u,p,f,d,m,g){this.elements=new r(16);var _=this.elements;_[0]=void 0!==e?e:1,_[4]=t||0,_[8]=i||0,_[12]=n||0,_[1]=o||0,_[5]=void 0!==s?s: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},o.Mat44.prototype={constructor:o.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}},o.Mat33=function(e,t,i,n,o,s,a,h,l){this.elements=new r(9);this.elements;this.init(void 0!==e?e:1,t||0,i||0,n||0,void 0!==o?o:1,s||0,a||0,h||0,void 0!==l?l:1)},o.Mat33.prototype={constructor:o.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,s){var a=s||!1,h=o.sin(t),l=o.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],O=this.elements;return a?(O[0]=u*x+p*T+f*E,O[1]=u*A+p*P+f*M,O[2]=u*S+p*C+f*R,O[3]=d*x+m*T+g*E,O[4]=d*A+m*P+g*M,O[5]=d*S+m*C+g*R,O[6]=_*x+v*T+y*E,O[7]=_*A+v*P+y*M,O[8]=_*S+v*C+y*R):(O[0]=x*u+A*d+S*_,O[1]=x*p+A*m+S*v,O[2]=x*f+A*g+S*y,O[3]=T*u+P*d+C*_,O[4]=T*p+P*m+C*v,O[5]=T*f+P*g+C*y,O[6]=E*u+M*d+R*_,O[7]=E*p+M*m+R*v,O[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,t=this.elements,i=t[0],r=t[3],n=t[6],s=(t[1],t[4]),a=t[7],h=(t[2],t[5]),l=t[8],c=new o.Vec3;new o.Quat;return c.y=o.asin((e=n,o.min(o.max(e,-1),1))),o.abs(n)<.99999?(c.x=o.atan2(-a,l),c.z=o.atan2(-r,i)):(c.x=o.atan2(h,s),c.z=0),c},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]]}},o.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},o.Quat.prototype={constructor:o.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,s=this.s,a=this.x,h=this.y,l=this.z,c=(i*s+r*l-n*h)*(t*=.5),u=(-i*l+r*s+n*a)*t,p=(i*h-r*a+n*s)*t;s+=(-i*a-r*h-n*l)*t,a+=c,h+=u,l+=p;var f=1/o.sqrt(s*s+a*a+h*h+l*l);return this.s=s*f,this.x=a*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,s=t.x,a=t.y,h=t.z,l=i*s+r*a+n*h;if(-1==l)return s=r*i-n*n,a=-n*r-i*i,h=i*n+r*r,l=1/o.sqrt(s*s+a*a+h*h),this.s=0,this.x=s*l,this.y=a*l,this.z=h*l,this;var c=r*h-n*a,u=n*s-i*h,p=i*a-r*s;return this.s=o.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=o.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 o.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 o.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)+")]"}},o.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},o.Quaternion.prototype={constructor:o.Quaternion,setFromRotationMatrix:function(e){var t,i=e.elements,r=i[0],n=i[1],s=i[2],a=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/o.sqrt(f+1),this.w=.25/t,this.x=(u-l)*t,this.y=(s-c)*t,this.z=(a-n)*t):r>h&&r>p?(t=2*o.sqrt(1+r-h-p),this.w=(u-l)/t,this.x=.25*t,this.y=(n+a)/t,this.z=(s+c)/t):h>p?(t=2*o.sqrt(1+h-r-p),this.w=(s-c)/t,this.x=(n+a)/t,this.y=.25*t,this.z=(l+u)/t):(t=2*o.sqrt(1+p-r-h),this.w=(a-n)/t,this.x=(s+c)/t,this.y=(l+u)/t,this.z=.25*t),this}},o.Vec3=function(e,t,i){this.x=e||0,this.y=t||0,this.z=i||0},o.Vec3.prototype={constructor:o.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/o.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 o.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())}},o.Euler=function(e,t,i,r){this._x=e||0,this._y=t||0,this._z=i||0,this._order=r||o.Euler.DefaultOrder},o.Euler.RotationOrders=["XYZ","YZX","ZXY","XZY","YXZ","ZYX"],o.Euler.DefaultOrder="XYZ",o.clamp=function(e,t,i){return e<t?t:e>i?i:e},o.Euler.prototype={constructor:o.Euler,_x:0,_y:0,_z:0,_order:o.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=o.clamp,r=e.elements,n=r[0],s=r[1],a=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=o.asin(i(a,-1,1)),o.abs(a)<.99999?(this._x=o.atan2(-c,f),this._z=o.atan2(-s,n)):(this._x=o.atan2(p,l),this._z=0)):"YXZ"===t?(this._x=o.asin(-i(c,-1,1)),o.abs(c)<.99999?(this._y=o.atan2(a,f),this._z=o.atan2(h,l)):(this._y=o.atan2(-u,n),this._z=0)):"ZXY"===t?(this._x=o.asin(i(p,-1,1)),o.abs(p)<.99999?(this._y=o.atan2(-u,f),this._z=o.atan2(-s,l)):(this._y=0,this._z=o.atan2(h,n))):"ZYX"===t?(this._y=o.asin(-i(u,-1,1)),o.abs(u)<.99999?(this._x=o.atan2(p,f),this._z=o.atan2(h,n)):(this._x=0,this._z=o.atan2(-s,l))):"YZX"===t?(this._z=o.asin(i(h,-1,1)),o.abs(h)<.99999?(this._x=o.atan2(-c,l),this._y=o.atan2(-u,n)):(this._x=0,this._y=o.atan2(a,f))):"XZY"===t?(this._z=o.asin(-i(s,-1,1)),o.abs(s)<.99999?(this._x=o.atan2(p,l),this._y=o.atan2(a,n)):(this._x=o.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=o.clamp,n=e.x*e.x,s=e.y*e.y,a=e.z*e.z,h=e.s*e.s;return"XYZ"===(t=t||this._order)?(this._x=o.atan2(2*(e.x*e.s-e.y*e.z),h-n-s+a),this._y=o.asin(r(2*(e.x*e.z+e.y*e.s),-1,1)),this._z=o.atan2(2*(e.z*e.s-e.x*e.y),h+n-s-a)):"YXZ"===t?(this._x=o.asin(r(2*(e.x*e.s-e.y*e.z),-1,1)),this._y=o.atan2(2*(e.x*e.z+e.y*e.s),h-n-s+a),this._z=o.atan2(2*(e.x*e.y+e.z*e.s),h-n+s-a)):"ZXY"===t?(this._x=o.asin(r(2*(e.x*e.s+e.y*e.z),-1,1)),this._y=o.atan2(2*(e.y*e.s-e.z*e.x),h-n-s+a),this._z=o.atan2(2*(e.z*e.s-e.x*e.y),h-n+s-a)):"ZYX"===t?(this._x=o.atan2(2*(e.x*e.s+e.z*e.y),h-n-s+a),this._y=o.asin(r(2*(e.y*e.s-e.x*e.z),-1,1)),this._z=o.atan2(2*(e.x*e.y+e.z*e.s),h+n-s-a)):"YZX"===t?(this._x=o.atan2(2*(e.x*e.s-e.z*e.y),h-n+s-a),this._y=o.atan2(2*(e.y*e.s-e.x*e.z),h+n-s-a),this._z=o.asin(r(2*(e.x*e.y+e.z*e.s),-1,1))):"XZY"===t?(this._x=o.atan2(2*(e.x*e.s+e.y*e.z),h-n+s-a),this._y=o.atan2(2*(e.x*e.z+e.y*e.s),h+n-s-a),this._z=o.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:(n=new o.Quat,function(e){n.setFromEuler(this),this.setFromQuaternion(n,e)}),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 o.Euler(this._x,this._y,this._z,this._order)}},o.EulerToAxis=function(e,t,i){var r=o.cos(.5*t),n=o.sin(.5*t),s=o.cos(.5*i),a=o.sin(.5*i),h=o.cos(.5*e),l=o.sin(.5*e),c=r*s,u=n*a,p=c*h-u*l,f=c*l+u*h,d=n*s*h+r*a*l,m=r*a*h-n*s*l,g=2*o.acos(p),_=f*f+d*d+m*m;return _<.001?(f=1,d=m=0):(f/=_=o.sqrt(_),d/=_,m/=_),[g,f,d,m]},o.EulerToMatrix=function(e,t,i){var r=o.cos(t),n=o.sin(t),s=o.cos(i),a=o.sin(i),h=o.cos(e),l=o.sin(e),c=new o.Mat33,u=c.elements;return u[0]=r*s,u[1]=n*l-r*a*h,u[2]=r*a*l+n*h,u[3]=a,u[4]=s*h,u[5]=-s*l,u[6]=-n*s,u[7]=n*a*h+r*l,u[8]=-n*a*l+r*h,c},o.MatrixToEuler=function(e){var t,i,r,n=e.elements;return n[3]>.998?(i=o.atan2(n[2],n[8]),r=o.PI/2,t=0):n[3]<-.998?(i=o.atan2(n[2],n[8]),r=-o.PI/2,t=0):(i=o.atan2(-n[6],n[0]),t=o.atan2(-n[5],n[4]),r=o.asin(n[3])),[t,i,r]},o.unwrapDegrees=function(e){return(e%=360)>180&&(e-=360),e<-180&&(e+=360),e},o.unwrapRadian=function(e){return(e%=o.TwoPI)>o.PI&&(e-=o.TwoPI),e<-o.PI&&(e+=o.TwoPI),e},o.Distance3d=function(e,t){var i=t[0]-e[0],r=t[1]-e[1],n=t[2]-e[2];return o.sqrt(i*i+r*r+n*n)},o.Constraint=function(){this.parent=null,this.body1=null,this.body2=null,this.addedToIsland=!1},o.Constraint.prototype={constructor:o.Constraint,preSolve:function(e,t){o.Error("Constraint","Inheritance error.")},solve:function(){o.Error("Constraint","Inheritance error.")},postSolve:function(){o.Error("Constraint","Inheritance error.")}},o.Joint=function(e){o.Constraint.call(this),this.name="",this.type=o.JOINT_NULL,this.prev=null,this.next=null,this.body1=e.body1,this.body2=e.body2,this.localAnchorPoint1=(new o.Vec3).copy(e.localAnchorPoint1),this.localAnchorPoint2=(new o.Vec3).copy(e.localAnchorPoint2),this.relativeAnchorPoint1=new o.Vec3,this.relativeAnchorPoint2=new o.Vec3,this.anchorPoint1=new o.Vec3,this.anchorPoint2=new o.Vec3,this.allowCollision=e.allowCollision,this.b1Link=new o.JointLink(this),this.b2Link=new o.JointLink(this),this.matrix=new o.Mat44},o.Joint.prototype=Object.create(o.Constraint.prototype),o.Joint.prototype.constructor=o.Joint,o.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)},o.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++},o.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},o.Joint.prototype.awake=function(){this.body1.awake(),this.body2.awake()},o.Joint.prototype.preSolve=function(e,t){},o.Joint.prototype.solve=function(){},o.Joint.prototype.postSolve=function(){},o.Joint.prototype.remove=function(){this.dispose()},o.Joint.prototype.dispose=function(){this.parent.removeJoint(this)},o.Joint.prototype.getPosition=function(){return[(new o.Vec3).scale(this.anchorPoint1,o.WORLD_SCALE),(new o.Vec3).scale(this.anchorPoint2,o.WORLD_SCALE)]},o.Joint.prototype.getMatrix=function(){var e=this.matrix.elements,t=this.anchorPoint1,i=this.anchorPoint2;return e[0]=t.x*o.WORLD_SCALE,e[1]=t.y*o.WORLD_SCALE,e[2]=t.z*o.WORLD_SCALE,e[3]=0,e[4]=i.x*o.WORLD_SCALE,e[5]=i.y*o.WORLD_SCALE,e[6]=i.z*o.WORLD_SCALE,e[7]=0,e},o.JointConfig=function(){this.body1=null,this.body2=null,this.localAnchorPoint1=new o.Vec3,this.localAnchorPoint2=new o.Vec3,this.localAxis1=new o.Vec3,this.localAxis2=new o.Vec3,this.allowCollision=!1},o.JointLink=function(e){this.prev=null,this.next=null,this.body=null,this.joint=e},o.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},o.LimitMotor.prototype={constructor:o.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}},o.BallAndSocketJoint=function(e){o.Joint.call(this,e),this.type=o.JOINT_BALL_AND_SOCKET,this.lc=new o.LinearConstraint(this)},o.BallAndSocketJoint.prototype=Object.create(o.Joint.prototype),o.BallAndSocketJoint.prototype.constructor=o.BallAndSocketJoint,o.BallAndSocketJoint.prototype.preSolve=function(e,t){this.updateAnchorPoints(),this.lc.preSolve(e,t)},o.BallAndSocketJoint.prototype.solve=function(){this.lc.solve()},o.BallAndSocketJoint.prototype.postSolve=function(){},o.DistanceJoint=function(e,t,i){o.Joint.call(this,e),this.type=o.JOINT_DISTANCE,this.normal=new o.Vec3,this.nr=new o.Vec3,this.limitMotor=new o.LimitMotor(this.normal,!0),this.limitMotor.lowerLimit=t,this.limitMotor.upperLimit=i,this.t=new o.TranslationalConstraint(this,this.limitMotor)},o.DistanceJoint.prototype=Object.create(o.Joint.prototype),o.DistanceJoint.prototype.constructor=o.DistanceJoint,o.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)},o.DistanceJoint.prototype.solve=function(){this.t.solve()},o.DistanceJoint.prototype.postSolve=function(){},o.HingeJoint=function(e,t,i){o.Joint.call(this,e),this.type=o.JOINT_HINGE,this.localAxis1=e.localAxis1.clone().norm(),this.localAxis2=e.localAxis2.clone().norm(),this.localAngle1=new o.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 o.Mat33).setQuat((new o.Quat).arc(this.localAxis1,this.localAxis2));this.localAngle2=(new o.Vec3).mulMat(r,this.localAngle1),this.nor=new o.Vec3,this.tan=new o.Vec3,this.bin=new o.Vec3,this.ax1=new o.Vec3,this.ax2=new o.Vec3,this.an1=new o.Vec3,this.an2=new o.Vec3,this.limitMotor=new o.LimitMotor(this.nor,!1),this.limitMotor.lowerLimit=t,this.limitMotor.upperLimit=i,this.lc=new o.LinearConstraint(this),this.r3=new o.Rotational3Constraint(this,this.limitMotor,new o.LimitMotor(this.tan,!0),new o.LimitMotor(this.bin,!0))},o.HingeJoint.prototype=Object.create(o.Joint.prototype),o.HingeJoint.prototype.constructor=o.HingeJoint,o.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)},o.HingeJoint.prototype.solve=function(){this.r3.solve(),this.lc.solve()},o.HingeJoint.prototype.postSolve=function(){},o.HingeJoint.prototype.acosClamp=function(e){return e>1?0:e<-1?o.PI:o.acos(e)},o.PrismaticJoint=function(e,t,i){o.Joint.call(this,e),this.type=o.JOINT_PRISMATIC,this.localAxis1=(new o.Vec3).normalize(e.localAxis1),this.localAxis2=(new o.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 o.Vec3,this.tan=new o.Vec3,this.bin=new o.Vec3,this.ac=new o.AngularConstraint(this,(new o.Quat).arc(this.localAxis1,this.localAxis2)),this.limitMotor=new o.LimitMotor(this.nor,!0),this.limitMotor.lowerLimit=t,this.limitMotor.upperLimit=i,this.t3=new o.Translational3Constraint(this,this.limitMotor,new o.LimitMotor(this.tan,!0),new o.LimitMotor(this.bin,!0))},o.PrismaticJoint.prototype=Object.create(o.Joint.prototype),o.PrismaticJoint.prototype.constructor=o.PrismaticJoint,o.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],s=this.localAxis1X*i[3]+this.localAxis1Y*i[4]+this.localAxis1Z*i[5],a=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=s*this.body2.inverseMass+l*this.body1.inverseMass,f=a*this.body2.inverseMass+c*this.body1.inverseMass;(r=o.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/o.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)},o.PrismaticJoint.prototype.solve=function(){this.ac.solve(),this.t3.solve()},o.PrismaticJoint.prototype.postSolve=function(){},o.SliderJoint=function(e,t,i){var r;o.Joint.call(this,e),this.type=o.JOINT_SLIDER,this.localAxis1=(new o.Vec3).normalize(e.localAxis1),this.localAxis2=(new o.Vec3).normalize(e.localAxis2),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/o.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 o.Mat33).setQuat((new o.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 o.Vec3,this.tan=new o.Vec3,this.bin=new o.Vec3,this.rotationalLimitMotor=new o.LimitMotor(this.nor,!1),this.r3=new o.Rotational3Constraint(this,this.rotationalLimitMotor,new o.LimitMotor(this.tan,!0),new o.LimitMotor(this.bin,!0)),this.translationalLimitMotor=new o.LimitMotor(this.nor,!0),this.translationalLimitMotor.lowerLimit=t,this.translationalLimitMotor.upperLimit=i,this.t3=new o.Translational3Constraint(this,this.translationalLimitMotor,new o.LimitMotor(this.tan,!0),new o.LimitMotor(this.bin,!0))},o.SliderJoint.prototype=Object.create(o.Joint.prototype),o.SliderJoint.prototype.constructor=o.SliderJoint,o.SliderJoint.prototype.preSolve=function(e,t){var i,r,n,s;this.updateAnchorPoints(),i=this.body1.rotation.elements;var a=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=a*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=o.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/o.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-a*m,s=a*d-h*f,this.r3.limitMotor2.angle=T*r+E*n+A*s,this.r3.limitMotor3.angle=P*r+M*n+S*s,this.r3.preSolve(e,t),this.t3.preSolve(e,t)},o.SliderJoint.prototype.solve=function(){this.r3.solve(),this.t3.solve()},o.SliderJoint.prototype.postSolve=function(){},o.SliderJoint.prototype.acosClamp=function(e){return e>1?0:e<-1?o.PI:o.acos(e)},o.WheelJoint=function(e){var t;o.Joint.call(this,e),this.type=o.JOINT_WHEEL,this.localAxis1=(new o.Vec3).normalize(e.localAxis1),this.localAxis2=(new o.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;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/o.sqrt(this.localAngAxis1X*this.localAngAxis1X+this.localAngAxis1Y*this.localAngAxis1Y+this.localAngAxis1Z*this.localAngAxis1Z),this.localAngAxis1X*=t,this.localAngAxis1Y*=t,this.localAngAxis1Z*=t,t=1/o.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/o.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 o.Mat33).setQuat((new o.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 o.Vec3,this.tan=new o.Vec3,this.bin=new o.Vec3,this.translationalLimitMotor=new o.LimitMotor(this.tan,!0),this.translationalLimitMotor.frequency=8,this.translationalLimitMotor.dampingRatio=1,this.rotationalLimitMotor1=new o.LimitMotor(this.tan,!1),this.rotationalLimitMotor2=new o.LimitMotor(this.bin,!1),this.t3=new o.Translational3Constraint(this,new o.LimitMotor(this.nor,!0),this.translationalLimitMotor,new o.LimitMotor(this.bin,!0)),this.t3.weight=1,this.r3=new o.Rotational3Constraint(this,new o.LimitMotor(this.nor,!0),this.rotationalLimitMotor1,this.rotationalLimitMotor2)},o.WheelJoint.prototype=Object.create(o.Joint.prototype),o.WheelJoint.prototype.constructor=o.WheelJoint,o.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],s=this.localAxis1X*i[3]+this.localAxis1Y*i[4]+this.localAxis1Z*i[5],a=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+s*p+a*f,this.rotationalLimitMotor1.angle=n*(l*f-c*p)+s*(c*u-h*f)+a*(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*a-g*s)+p*(g*n-d*a)+f*(d*s-m*n)<0?this.acosClamp(d*n+m*s+g*a):-this.acosClamp(d*n+m*s+g*a);var _=p*a-f*s,v=f*n-u*a,y=u*s-p*n;(r=o.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=o.sqrt(b*b+x*x+T*T))>0&&(r=1/r),b*=r,x*=r,T*=r;var E=s*y-a*v,A=a*_-n*y,P=n*v-s*_;(r=o.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)},o.WheelJoint.prototype.solve=function(){this.r3.solve(),this.t3.solve()},o.WheelJoint.prototype.postSolve=function(){},o.WheelJoint.prototype.acosClamp=function(e){return e>1?0:e<-1?o.PI:o.acos(e)},o.AngularConstraint=function(e,t){this.joint=e,this.targetOrientation=(new o.Quat).invert(t),this.relativeOrientation=new o.Quat,this.ii1=null,this.ii2=null,this.dd=null,this.vel=new o.Vec3,this.imp=new o.Vec3,this.rn0=new o.Vec3,this.rn1=new o.Vec3,this.rn2=new o.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},o.AngularConstraint.prototype={constructor:o.AngularConstraint,preSolve:function(e,t){var i,r,n;this.ii1=this.i1.clone(),this.ii2=this.i2.clone(),i=1/((n=(new o.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 o.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)}},o.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},o.LinearConstraint.prototype={constructor:o.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,s=new o.Mat33(n,0,0,0,n,0,0,0,n).elements;s[0]+=i[4]*this.r1z*this.r1z-(i[7]+i[5])*this.r1y*this.r1z+i[8]*this.r1y*this.r1y,s[1]+=(i[6]*this.r1y+i[5]*this.r1x)*this.r1z-i[3]*this.r1z*this.r1z-i[8]*this.r1x*this.r1y,s[2]+=(i[3]*this.r1y-i[4]*this.r1x)*this.r1z-i[6]*this.r1y*this.r1y+i[7]*this.r1x*this.r1y,s[3]+=(i[2]*this.r1y+i[7]*this.r1x)*this.r1z-i[1]*this.r1z*this.r1z-i[8]*this.r1x*this.r1y,s[4]+=i[0]*this.r1z*this.r1z-(i[6]+i[2])*this.r1x*this.r1z+i[8]*this.r1x*this.r1x,s[5]+=(i[1]*this.r1x-i[0]*this.r1y)*this.r1z-i[7]*this.r1x*this.r1x+i[6]*this.r1x*this.r1y,s[6]+=(i[1]*this.r1y-i[4]*this.r1x)*this.r1z-i[2]*this.r1y*this.r1y+i[5]*this.r1x*this.r1y,s[7]+=(i[3]*this.r1x-i[0]*this.r1y)*this.r1z-i[5]*this.r1x*this.r1x+i[2]*this.r1x*this.r1y,s[8]+=i[0]*this.r1y*this.r1y-(i[3]+i[1])*this.r1x*this.r1y+i[4]*this.r1x*this.r1x,s[0]+=r[4]*this.r2z*this.r2z-(r[7]+r[5])*this.r2y*this.r2z+r[8]*this.r2y*this.r2y,s[1]+=(r[6]*this.r2y+r[5]*this.r2x)*this.r2z-r[3]*this.r2z*this.r2z-r[8]*this.r2x*this.r2y,s[2]+=(r[3]*this.r2y-r[4]*this.r2x)*this.r2z-r[6]*this.r2y*this.r2y+r[7]*this.r2x*this.r2y,s[3]+=(r[2]*this.r2y+r[7]*this.r2x)*this.r2z-r[1]*this.r2z*this.r2z-r[8]*this.r2x*this.r2y,s[4]+=r[0]*this.r2z*this.r2z-(r[6]+r[2])*this.r2x*this.r2z+r[8]*this.r2x*this.r2x,s[5]+=(r[1]*this.r2x-r[0]*this.r2y)*this.r2z-r[7]*this.r2x*this.r2x+r[6]*this.r2x*this.r2y,s[6]+=(r[1]*this.r2y-r[4]*this.r2x)*this.r2z-r[2]*this.r2y*this.r2y+r[5]*this.r2x*this.r2y,s[7]+=(r[3]*this.r2x-r[0]*this.r2y)*this.r2z-r[5]*this.r2x*this.r2x+r[2]*this.r2x*this.r2y,s[8]+=r[0]*this.r2y*this.r2y-(r[3]+r[1])*this.r2x*this.r2y+r[4]*this.r2x*this.r2x;var a=1/(s[0]*(s[4]*s[8]-s[7]*s[5])+s[3]*(s[7]*s[2]-s[1]*s[8])+s[6]*(s[1]*s[5]-s[4]*s[2]));this.dd=new o.Mat33(s[4]*s[8]-s[5]*s[7],s[2]*s[7]-s[1]*s[8],s[1]*s[5]-s[2]*s[4],s[5]*s[6]-s[3]*s[8],s[0]*s[8]-s[2]*s[6],s[2]*s[3]-s[0]*s[5],s[3]*s[7]-s[4]*s[6],s[1]*s[6]-s[0]*s[7],s[0]*s[4]-s[1]*s[3]).multiply(a),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=o.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}},o.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},o.Rotational3Constraint.prototype={constructor:o.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):f<this.lowerLimit1?(-1!=this.limitState1&&(this.limitState1=-1,this.limitImpulse1=0),this.limitVelocity1=this.lowerLimit1-f):f>this.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):d<this.lowerLimit2?(-1!=this.limitState2&&(this.limitState2=-1,this.limitImpulse2=0),this.limitVelocity2=this.lowerLimit2-d):d>this.upperLimit2?(1!=this.limitState2&&(this.limitState2=1,this.limitImpulse2=0),this.limitVelocity2=this.upperLimit2-d):(this.limitState2=2,this.limitImpulse2=0,this.limitVelocity2=0),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):m<this.lowerLimit3?(-1!=this.limitState3&&(this.limitState3=-1,this.limitImpulse3=0),this.limitVelocity3=this.lowerLimit3-m):m>this.upperLimit3?(1!=this.limitState3&&(this.limitState3=1,this.limitImpulse3=0),this.limitVelocity3=this.upperLimit3-m):(this.limitState3=2,this.limitImpulse3=0,this.limitVelocity3=0),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,y=0;switch((2==this.limitState1||this.limitImpulse1*this.limitState1<0)&&(n+=(m=-p)*this.k10,o+=m*this.k20,y|=1),(2==this.limitState2||this.limitImpulse2*this.limitState2<0)&&(r+=(g=-f)*this.k01,o+=g*this.k21,y|=2),(2==this.limitState3||this.limitImpulse3*this.limitState3<0)&&(r+=(_=-d)*this.k02,n+=_*this.k12,y|=4),y){case 1:v=1/(this.k11*this.k22-this.k12*this.k21),g=(this.k22*n+-this.k12*o)*v,_=(-this.k21*n+this.k11*o)*v;break;case 2:v=1/(this.k00*this.k22-this.k02*this.k20),m=(this.k22*r+-this.k02*o)*v,_=(-this.k20*r+this.k00*o)*v;break;case 3:_=o/this.k22;break;case 4:v=1/(this.k00*this.k11-this.k01*this.k10),m=(this.k11*r+-this.k01*n)*v,g=(-this.k10*r+this.k00*n)*v;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}},o.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},o.RotationalConstraint.prototype={constructor:o.RotationalConstraint,preSolve:function(e,t){this.ax=this.limitMotor.axis.x,this.ay=this.limitMotor.axis.y,this.az=this.limitMotor.axis.z,this.lowerLimit=this.limitMotor.lowerLimit,this.upperLimit=this.limitMotor.upperLimit,this.motorSpeed=this.limitMotor.motorSpeed,this.maxMotorForce=this.limitMotor.maxMotorForce,this.enableMotor=this.maxMotorForce>0;var i=this.i1.elements,r=this.i2.elements;this.i1e00=i[0],this.i1e01=i[1],this.i1e02=i[2],this.i1e10=i[3],this.i1e11=i[4],this.i1e12=i[5],this.i1e20=i[6],this.i1e21=i[7],this.i1e22=i[8],this.i2e00=r[0],this.i2e01=r[1],this.i2e02=r[2],this.i2e10=r[3],this.i2e11=r[4],this.i2e12=r[5],this.i2e20=r[6],this.i2e21=r[7],this.i2e22=r[8];var n=this.limitMotor.frequency,o=n>0,s=this.lowerLimit<=this.upperLimit,a=this.limitMotor.angle;if(s?(this.lowerLimit==this.upperLimit?(0!=this.limitState&&(this.limitState=0,this.limitImpulse=0),this.limitVelocity=this.lowerLimit-a):a<this.lowerLimit?(-1!=this.limitState&&(this.limitState=-1,this.limitImpulse=0),this.limitVelocity=this.lowerLimit-a):a>this.upperLimit?(1!=this.limitState&&(this.limitState=1,this.limitImpulse=0),this.limitVelocity=this.upperLimit-a):(this.limitState=2,this.limitImpulse=0,this.limitVelocity=0),o||(this.limitVelocity>.02?this.limitVelocity-=.02:this.limitVelocity<-.02?this.limitVelocity+=.02:this.limitVelocity=0)):(this.limitState=2,this.limitImpulse=0),this.enableMotor&&(0!=this.limitState||o)?this.maxMotorImpulse=this.maxMotorForce*e:(this.motorImpulse=0,this.maxMotorImpulse=0),this.a1x=this.ax*this.i1e00+this.ay*this.i1e01+this.az*this.i1e02,this.a1y=this.ax*this.i1e10+this.ay*this.i1e11+this.az*this.i1e12,this.a1z=this.ax*this.i1e20+this.ay*this.i1e21+this.az*this.i1e22,this.a2x=this.ax*this.i2e00+this.ay*this.i2e01+this.az*this.i2e02,this.a2y=this.ax*this.i2e10+this.ay*this.i2e11+this.az*this.i2e12,this.a2z=this.ax*this.i2e20+this.ay*this.i2e21+this.az*this.i2e22,this.motorDenom=this.ax*(this.a1x+this.a2x)+this.ay*(this.a1y+this.a2y)+this.az*(this.a1z+this.a2z),this.invMotorDenom=1/this.motorDenom,o&&2!=this.limitState){var 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,i=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=(i-this.motorSpeed)*this.invMotorDenom;var r=this.motorImpulse;this.motorImpulse+=e,this.motorImpulse>this.maxMotorImpulse?this.motorImpulse=this.maxMotorImpulse:this.motorImpulse<-this.maxMotorImpulse&&(this.motorImpulse=-this.maxMotorImpulse),i-=(e=this.motorImpulse-r)*this.motorDenom}else e=0;if(2!=this.limitState){t=(i-this.limitVelocity-this.limitImpulse*this.cfm)*this.invDenom;var n=this.limitImpulse;this.limitImpulse+=t,this.limitImpulse*this.limitState<0&&(this.limitImpulse=0),t=this.limitImpulse-n}else t=0;var o=t+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}},o.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},o.Translational3Constraint.prototype={constructor:o.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)):a<this.lowerLimit1?(-1!=this.limitState1&&(this.limitState1=-1,this.limitImpulse1=0),this.limitVelocity1=this.lowerLimit1-a,f||(a=this.lowerLimit1)):a>this.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)):h<this.lowerLimit2?(-1!=this.limitState2&&(this.limitState2=-1,this.limitImpulse2=0),this.limitVelocity2=this.lowerLimit2-h,d||(h=this.lowerLimit2)):h>this.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)):l<this.lowerLimit3?(-1!=this.limitState3&&(this.limitState3=-1,this.limitImpulse3=0),this.limitVelocity3=this.lowerLimit3-l,m||(l=this.lowerLimit3)):l>this.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,O=this.limitImpulse2+this.motorImpulse2,I=this.limitImpulse3+this.motorImpulse3;this.l1.x+=R*this.l1x1+O*this.l1x2+I*this.l1x3,this.l1.y+=R*this.l1y1+O*this.l1y2+I*this.l1y3,this.l1.z+=R*this.l1z1+O*this.l1z2+I*this.l1z3,this.a1.x+=R*this.a1x1+O*this.a1x2+I*this.a1x3,this.a1.y+=R*this.a1y1+O*this.a1y2+I*this.a1y3,this.a1.z+=R*this.a1z1+O*this.a1z2+I*this.a1z3,this.l2.x-=R*this.l2x1+O*this.l2x2+I*this.l2x3,this.l2.y-=R*this.l2y1+O*this.l2y2+I*this.l2y3,this.l2.z-=R*this.l2z1+O*this.l2z2+I*this.l2z3,this.a2.x-=R*this.a2x1+O*this.a2x2+I*this.a2x3,this.a2.y-=R*this.a2y1+O*this.a2y2+I*this.a2y3,this.a2.z-=R*this.a2z1+O*this.a2z2+I*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,y=0;switch((2==this.limitState1||this.limitImpulse1*this.limitState1<0)&&(n+=(m=-p)*this.k10,o+=m*this.k20,y|=1),(2==this.limitState2||this.limitImpulse2*this.limitState2<0)&&(r+=(g=-f)*this.k01,o+=g*this.k21,y|=2),(2==this.limitState3||this.limitImpulse3*this.limitState3<0)&&(r+=(_=-d)*this.k02,n+=_*this.k12,y|=4),y){case 1:v=1/(this.k11*this.k22-this.k12*this.k21),g=(this.k22*n+-this.k12*o)*v,_=(-this.k21*n+this.k11*o)*v;break;case 2:v=1/(this.k00*this.k22-this.k02*this.k20),m=(this.k22*r+-this.k02*o)*v,_=(-this.k20*r+this.k00*o)*v;break;case 3:_=o/this.k22;break;case 4:v=1/(this.k00*this.k11-this.k01*this.k10),m=(this.k11*r+-this.k01*n)*v,g=(-this.k10*r+this.k00*n)*v;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}},o.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},o.TranslationalConstraint.prototype={constructor:o.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)):a<this.lowerLimit?(-1!=this.limitState&&(this.limitState=-1,this.limitImpulse=0),this.limitVelocity=this.lowerLimit-a,l||(a=this.lowerLimit)):a>this.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,i=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=(i-this.motorSpeed)*this.invMotorDenom;var r=this.motorImpulse;this.motorImpulse+=e,this.motorImpulse>this.maxMotorImpulse?this.motorImpulse=this.maxMotorImpulse:this.motorImpulse<-this.maxMotorImpulse&&(this.motorImpulse=-this.maxMotorImpulse),i-=(e=this.motorImpulse-r)*this.motorDenom}else e=0;if(2!=this.limitState){t=(i-this.limitVelocity-this.limitImpulse*this.cfm)*this.invDenom;var n=this.limitImpulse;this.limitImpulse+=t,this.limitImpulse*this.limitState<0&&(this.limitImpulse=0),t=this.limitImpulse-n}else t=0;var o=t+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}},o.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 o.ContactLink(this),this.b2Link=new o.ContactLink(this),this.s1Link=new o.ContactLink(this),this.s2Link=new o.ContactLink(this),this.manifold=new o.ContactManifold,this.buffer=[],this.buffer.length=4,this.buffer[0]=new o.ImpulseDataBuffer,this.buffer[1]=new o.ImpulseDataBuffer,this.buffer[2]=new o.ImpulseDataBuffer,this.buffer[3]=new o.ImpulseDataBuffer,this.points=this.manifold.points,this.constraint=new o.ContactConstraint(this.manifold)},o.Contact.prototype={constructor:o.Contact,mixRestitution:function(e,t){return o.sqrt(e*t)},mixFriction:function(e,t){return o.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;_<v?_<p&&(p=_,u=f):v<p&&(p=v,u=f)}if(-1!=u){var y=this.buffer[u];this.buffer[u]=this.buffer[--e],this.buffer[e]=y,r.normalImpulse=y.impulse,r.warmStarted=!0}else r.normalImpulse=0,r.warmStarted=!1}else this.touching=!1},attach:function(e,t){this.shape1=e,this.shape2=t,this.body1=e.parent,this.body2=t.parent,this.manifold.body1=this.body1,this.manifold.body2=this.body2,this.constraint.body1=this.body1,this.constraint.body2=this.body2,this.constraint.attach(),this.s1Link.shape=t,this.s1Link.body=this.body2,this.s2Link.shape=e,this.s2Link.body=this.body1,null!=e.contactLink?(this.s1Link.next=e.contactLink).prev=this.s1Link:this.s1Link.next=null,e.contactLink=this.s1Link,e.numContacts++,null!=t.contactLink?(this.s2Link.next=t.contactLink).prev=this.s2Link:this.s2Link.next=null,t.contactLink=this.s2Link,t.numContacts++,this.b1Link.shape=t,this.b1Link.body=this.body2,this.b2Link.shape=e,this.b2Link.body=this.body1,null!=this.body1.contactLink?(this.b1Link.next=this.body1.contactLink).prev=this.b1Link:this.b1Link.next=null,this.body1.contactLink=this.b1Link,this.body1.numContacts++,null!=this.body2.contactLink?(this.b2Link.next=this.body2.contactLink).prev=this.b2Link:this.b2Link.next=null,this.body2.contactLink=this.b2Link,this.body2.numContacts++,this.prev=null,this.next=null,this.persisting=!0,this.sleeping=this.body1.sleeping&&this.body2.sleeping,this.manifold.numPoints=0},detach:function(){var e=this.s1Link.prev,t=this.s1Link.next;null!==e&&(e.next=t),null!==t&&(t.prev=e),this.shape1.contactLink==this.s1Link&&(this.shape1.contactLink=t),this.s1Link.prev=null,this.s1Link.next=null,this.s1Link.shape=null,this.s1Link.body=null,this.shape1.numContacts--,e=this.s2Link.prev,t=this.s2Link.next,null!==e&&(e.next=t),null!==t&&(t.prev=e),this.shape2.contactLink==this.s2Link&&(this.shape2.contactLink=t),this.s2Link.prev=null,this.s2Link.next=null,this.s2Link.shape=null,this.s2Link.body=null,this.shape2.numContacts--,e=this.b1Link.prev,t=this.b1Link.next,null!==e&&(e.next=t),null!==t&&(t.prev=e),this.body1.contactLink==this.b1Link&&(this.body1.contactLink=t),this.b1Link.prev=null,this.b1Link.next=null,this.b1Link.shape=null,this.b1Link.body=null,this.body1.numContacts--,e=this.b2Link.prev,t=this.b2Link.next,null!==e&&(e.next=t),null!==t&&(t.prev=e),this.body2.contactLink==this.b2Link&&(this.body2.contactLink=t),this.b2Link.prev=null,this.b2Link.next=null,this.b2Link.shape=null,this.b2Link.body=null,this.body2.numContacts--,this.manifold.body1=null,this.manifold.body2=null,this.constraint.body1=null,this.constraint.body2=null,this.constraint.detach(),this.shape1=null,this.shape2=null,this.body1=null,this.body2=null}},o.ContactConstraint=function(e){o.Constraint.call(this),this.manifold=e,this.restitution=NaN,this.friction=NaN,this.p1=null,this.p2=null,this.lv1=null,this.lv2=null,this.av1=null,this.av2=null,this.i1=null,this.i2=null,this.ii1=null,this.ii2=null,this.m1=NaN,this.m2=NaN,this.num=0,this.ps=e.points,this.cs=new o.ContactPointDataBuffer,this.cs.next=new o.ContactPointDataBuffer,this.cs.next.next=new o.ContactPointDataBuffer,this.cs.next.next.next=new o.ContactPointDataBuffer},o.ContactConstraint.prototype=Object.create(o.Constraint.prototype),o.ContactConstraint.prototype.attach=function(){this.p1=this.body1.position,this.p2=this.body2.position,this.lv1=this.body1.linearVelocity,this.av1=this.body1.angularVelocity,this.lv2=this.body2.linearVelocity,this.av2=this.body2.angularVelocity,this.i1=this.body1.inverseInertia,this.i2=this.body2.inverseInertia},o.ContactConstraint.prototype.detach=function(){this.p1=null,this.p2=null,this.lv1=null,this.lv2=null,this.av1=null,this.av2=null,this.i1=null,this.i2=null},o.ContactConstraint.prototype.preSolve=function(e,t){this.m1=this.body1.inverseMass,this.m2=this.body2.inverseMass,this.ii1=this.i1.clone(),this.ii2=this.i2.clone();var i=this.ii1.elements,r=this.ii2.elements,n=this.p1.x,s=this.p1.y,a=this.p1.z,h=this.p2.x,l=this.p2.y,c=this.p2.z,u=this.m1+this.m2;this.num=this.manifold.numPoints;for(var p=this.cs,f=0;f<this.num;f++){var d,m,g,_,v,y,b=this.ps[f],x=(d=b.position.x)-n,T=(m=b.position.y)-s,E=(g=b.position.z)-a,A=d-h,P=m-l,M=g-c;p.rp1X=x,p.rp1Y=T,p.rp1Z=E,p.rp2X=A,p.rp2Y=P,p.rp2Z=M,p.norImp=b.normalImpulse,p.tanImp=b.tangentImpulse,p.binImp=b.binormalImpulse;var S=b.normal.x,C=b.normal.y,R=b.normal.z,O=this.lv2.x+this.av2.y*M-this.av2.z*P-(this.lv1.x+this.av1.y*E-this.av1.z*T),I=this.lv2.y+this.av2.z*A-this.av2.x*M-(this.lv1.y+this.av1.z*x-this.av1.x*E),w=this.lv2.z+this.av2.x*P-this.av2.y*A-(this.lv1.z+this.av1.x*T-this.av1.y*x),D=S*O+C*I+R*w,L=O-D*S,B=I-D*C,N=w-D*R,F=L*L+B*B+N*N;F>.04?F=1/o.sqrt(F):(L=C*S-R*R,B=-R*C-S*S,N=S*R+C*C,F=1/o.sqrt(L*L+B*B+N*N));var V=C*(N*=F)-R*(B*=F),k=R*(L*=F)-S*N,U=S*B-C*L;p.norX=S,p.norY=C,p.norZ=R,p.tanX=L,p.tanY=B,p.tanZ=N,p.binX=V,p.binY=k,p.binZ=U,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=B*this.m1,p.tanU1Z=N*this.m1,p.tanU2X=L*this.m2,p.tanU2Y=B*this.m2,p.tanU2Z=N*this.m2,p.binU1X=V*this.m1,p.binU1Y=k*this.m1,p.binU1Z=U*this.m1,p.binU2X=V*this.m2,p.binU2Y=k*this.m2,p.binU2Z=U*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*B,K=E*L-x*N,Q=x*B-T*L,Z=P*N-M*B,q=M*L-A*N,J=A*B-P*L,$=T*U-E*k,ee=E*V-x*U,te=x*k-T*V,ie=P*U-M*k,re=M*V-A*U,ne=A*k-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)+B*(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)+k*(v+=g*A-d*M)+U*(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;Se<Ce&&(Se=Ce),p.norTar=Se,p.last=f==this.num-1,p=p.next}},o.ContactConstraint.prototype.solve=function(){for(var e=this.lv1.x,t=this.lv1.y,i=this.lv1.z,r=this.lv2.x,n=this.lv2.y,s=this.lv2.z,a=this.av1.x,h=this.av1.y,l=this.av1.z,c=this.av2.x,u=this.av2.y,p=this.av2.z,f=this.cs;;){var d,m,g,_,v=f.norImp,y=f.tanImp,b=f.binImp,x=-v*this.friction,T=r-e,E=n-t,A=s-i;d=y,g=b;var P=(y+=m=(T*f.tanX+E*f.tanY+A*f.tanZ+c*f.tanT2X+u*f.tanT2Y+p*f.tanT2Z-a*f.tanT1X-h*f.tanT1Y-l*f.tanT1Z)*f.tanDen)*y+(b+=_=(T*f.binX+E*f.binY+A*f.binZ+c*f.binT2X+u*f.binT2Y+p*f.binT2Z-a*f.binT1X-h*f.binT1Y-l*f.binT1Z)*f.binDen)*b;if(P>x*x&&(y*=P=x/o.sqrt(P),b*=P),m=y-d,_=b-g,e+=f.tanU1X*m+f.binU1X*_,t+=f.tanU1Y*m+f.binU1Y*_,i+=f.tanU1Z*m+f.binU1Z*_,a+=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*_,s-=f.tanU2Z*m+f.binU2Z*_,c-=f.tanTU2X*m+f.binTU2X*_,u-=f.tanTU2Y*m+f.binTU2Y*_,p-=f.tanTU2Z*m+f.binTU2Z*_,d=v,(v+=m=((r-e)*f.norX+(n-t)*f.norY+(s-i)*f.norZ+c*f.norT2X+u*f.norT2Y+p*f.norT2Z-a*f.norT1X-h*f.norT1Y-l*f.norT1Z-f.norTar)*f.norDen)>0&&(v=0),m=v-d,e+=f.norU1X*m,t+=f.norU1Y*m,i+=f.norU1Z*m,a+=f.norTU1X*m,h+=f.norTU1Y*m,l+=f.norTU1Z*m,r-=f.norU2X*m,n-=f.norU2Y*m,s-=f.norU2Z*m,c-=f.norTU2X*m,u-=f.norTU2Y*m,p-=f.norTU2Z*m,f.norImp=v,f.tanImp=y,f.binImp=b,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=s,this.av1.x=a,this.av1.y=h,this.av1.z=l,this.av2.x=c,this.av2.y=u,this.av2.z=p},o.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}},o.ContactLink=function(e){this.prev=null,this.next=null,this.shape=null,this.body=null,this.contact=e},o.ContactManifold=function(){this.body1=null,this.body2=null,this.numPoints=0,this.points=[],this.points.length=4,this.points[0]=new o.ManifoldPoint,this.points[1]=new o.ManifoldPoint,this.points[2]=new o.ManifoldPoint,this.points[3]=new o.ManifoldPoint},o.ContactManifold.prototype={constructor:o.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}},o.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},o.ImpulseDataBuffer=function(){this.lp1X=NaN,this.lp1Y=NaN,this.lp1Z=NaN,this.lp2X=NaN,this.lp2Y=NaN,this.lp2Z=NaN,this.impulse=NaN},o.ManifoldPoint=function(){this.warmStarted=!1,this.position=new o.Vec3,this.localPoint1=new o.Vec3,this.localPoint2=new o.Vec3,this.normal=new o.Vec3,this.tangent=new o.Vec3,this.binormal=new o.Vec3,this.normalImpulse=0,this.tangentImpulse=0,this.binormalImpulse=0,this.normalDenominator=0,this.tangentDenominator=0,this.binormalDenominator=0,this.penetration=0},o.MassInfo=function(){this.mass=0,this.inertia=new o.Mat33},o.Shape=function(e){this.type=o.SHAPE_NULL,this.id=o.nextID++,this.prev=null,this.next=null,this.proxy=null,this.parent=null,this.contactLink=null,this.numContacts=0,this.position=new o.Vec3,this.rotation=new o.Mat33,this.relativePosition=(new o.Vec3).copy(e.relativePosition),this.relativeRotation=(new o.Mat33).copy(e.relativeRotation),this.aabb=new o.AABB,this.density=e.density,this.friction=e.friction,this.restitution=e.restitution,this.belongsTo=e.belongsTo,this.collidesWith=e.collidesWith},o.Shape.prototype={constructor:o.Shape,calculateMassInfo:function(e){o.Error("Shape","Inheritance error.")},updateProxy:function(){o.Error("Shape","Inheritance error.")}},o.ShapeConfig=function(){this.relativePosition=new o.Vec3,this.relativeRotation=new o.Mat33,this.friction=.4,this.restitution=.2,this.density=1,this.belongsTo=1,this.collidesWith=4294967295},o.BoxShape=function(e,t,i,n){o.Shape.call(this,e),this.type=o.SHAPE_BOX,this.width=t,this.height=i,this.depth=n,this.halfWidth=.5*t,this.halfHeight=.5*i,this.halfDepth=.5*n,this.dimentions=new r(18),this.elements=new r(24)},o.BoxShape.prototype=Object.create(o.Shape.prototype),o.BoxShape.prototype.constructor=o.BoxShape,o.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))},o.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],s=t[12],a=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+s+l,m[1]=f+r+a+c,m[2]=d+n+h+u,m[3]=p+i+s-l,m[4]=f+r+a-c,m[5]=d+n+h-u,m[6]=p+i-s+l,m[7]=f+r-a+c,m[8]=d+n-h+u,m[9]=p+i-s-l,m[10]=f+r-a-c,m[11]=d+n-h-u,m[12]=p-i+s+l,m[13]=f-r+a+c,m[14]=d-n+h+u,m[15]=p-i+s-l,m[16]=f-r+a-c,m[17]=d-n+h-u,m[18]=p-i-s+l,m[19]=f-r-a+c,m[20]=d-n-h+u,m[21]=p-i-s-l,m[22]=f-r-a-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=o.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()},o.SphereShape=function(e,t){o.Shape.call(this,e),this.type=o.SHAPE_SPHERE,this.radius=t},o.SphereShape.prototype=Object.create(o.Shape.prototype),o.SphereShape.prototype.constructor=o.SphereShape,o.SphereShape.prototype.calculateMassInfo=function(e){var t=1.333*o.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)},o.SphereShape.prototype.updateProxy=function(){var e=o.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()},o.CylinderShape=function(e,t,i){o.Shape.call(this,e),this.type=o.SHAPE_CYLINDER,this.radius=t,this.height=i,this.halfHeight=.5*i,this.normalDirection=new o.Vec3,this.halfDirection=new o.Vec3},o.CylinderShape.prototype=Object.create(o.Shape.prototype),o.CylinderShape.prototype.constructor=o.CylinderShape,o.CylinderShape.prototype.calculateMassInfo=function(e){var t=this.radius*this.radius,i=o.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)},o.CylinderShape.prototype.updateProxy=function(){var e,t,i,r,n,s,a,h,l,c,u,p=this.rotation.elements;n=p[1]*p[1],s=p[4]*p[4],a=p[7]*p[7],this.normalDirection.set(p[1],p[4],p[7]),this.halfDirection.scale(this.normalDirection,this.halfHeight),t=1-n,(e=o.sqrt(t*t+n*s+n*a))>0&&(e=this.radius/e),t*=e,i=1-s,(e=o.sqrt(s*n+i*i+s*a))>0&&(e=this.radius/e),i*=e,r=1-a,(e=o.sqrt(a*n+a*s+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=o.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()},o.TetraShape=function(e,t,i,r,n){o.Shape.call(this,e),this.type=o.SHAPE_TETRA,this.verts=[t,i,r,n],this.faces=[s(0,1,2),s(1,2,3),s(2,3,4),s(4,0,1)]},o.TetraShape.prototype=Object.create(o.Shape.prototype),o.TetraShape.prototype.constructor=o.TetraShape,o.TetraShape.prototype.calculateMassInfo=function(){},o.TetraShape.prototype.updateProxy=function(){this.aabb.setFromPoints(this.verts),null!==this.proxy&&this.proxy.update()},o.CollisionDetector=function(){this.flip=!1},o.CollisionDetector.prototype={constructor:o.CollisionDetector,detectCollision:function(e,t,i){o.Error("CollisionDetector","Inheritance error.")}},o.BoxBoxCollisionDetector=function(){o.CollisionDetector.call(this),this.clipVertices1=new r(24),this.clipVertices2=new r(24),this.used=new r(8),this.INF=1/0},o.BoxBoxCollisionDetector.prototype=Object.create(o.CollisionDetector.prototype),o.BoxBoxCollisionDetector.prototype.constructor=o.BoxBoxCollisionDetector,o.BoxBoxCollisionDetector.prototype.detectCollision=function(e,t,i){var r,n;e.id<t.id?(r=e,n=t):(r=t,n=e);var s,a,h,l,c,u,p,f,d,m,g,_,v,y,b,x,T,E,A,P,M,S,C,R,O,I,w,D,L,B,N,F,V,k,U,z=r.elements,G=n.elements,W=r.dimentions,H=n.dimentions,j=r.position,X=n.position,Y=j.x,K=j.y,Q=j.z,Z=X.x,q=X.y,J=X.z,$=Z-Y,ee=q-K,te=J-Q,ie=r.halfWidth,re=r.halfHeight,ne=r.halfDepth,oe=n.halfWidth,se=n.halfHeight,ae=n.halfDepth,he=W[0],le=W[1],ce=W[2],ue=W[3],pe=W[4],fe=W[5],de=W[6],me=W[7],ge=W[8],_e=W[9],ve=W[10],ye=W[11],be=W[12],xe=W[13],Te=W[14],Ee=W[15],Ae=W[16],Pe=W[17],Me=H[0],Se=H[1],Ce=H[2],Re=H[3],Oe=H[4],Ie=H[5],we=H[6],De=H[7],Le=H[8],Be=H[9],Ne=H[10],Fe=H[11],Ve=H[12],ke=H[13],Ue=H[14],ze=H[15],Ge=H[16],We=H[17],He=le*Ce-ce*Se,je=ce*Me-he*Ce,Xe=he*Se-le*Me,Ye=le*Ie-ce*Oe,Ke=ce*Re-he*Ie,Qe=he*Oe-le*Re,Ze=le*Le-ce*De,qe=ce*we-he*Le,Je=he*De-le*we,$e=pe*Ce-fe*Se,et=fe*Me-ue*Ce,tt=ue*Se-pe*Me,it=pe*Ie-fe*Oe,rt=fe*Re-ue*Ie,nt=ue*Oe-pe*Re,ot=pe*Le-fe*De,st=fe*we-ue*Le,at=ue*De-pe*we,ht=me*Ce-ge*Se,lt=ge*Me-de*Ce,ct=de*Se-me*Me,ut=me*Ie-ge*Oe,pt=ge*Re-de*Ie,ft=de*Oe-me*Re,dt=me*Le-ge*De,mt=ge*we-de*Le,gt=de*De-me*we,_t=!1,vt=!1,yt=!1,bt=!1,xt=!1,Tt=!1,Et=!1,At=!1,Pt=!1;if((s=(N=he*$+le*ee+ce*te)>0)||(N=-N),F=ie,k=he*Re+le*Oe+ce*Ie,U=he*we+le*De+ce*Le,(V=he*Me+le*Se+ce*Ce)<0&&(V=-V),k<0&&(k=-k),U<0&&(U=-U),!((x=N-F-(V*oe+k*se+U*ae))>0||((a=(N=ue*$+pe*ee+fe*te)>0)||(N=-N),F=re,k=ue*Re+pe*Oe+fe*Ie,U=ue*we+pe*De+fe*Le,(V=ue*Me+pe*Se+fe*Ce)<0&&(V=-V),k<0&&(k=-k),U<0&&(U=-U),(T=N-F-(V*oe+k*se+U*ae))>0||((h=(N=de*$+me*ee+ge*te)>0)||(N=-N),F=ne,k=de*Re+me*Oe+ge*Ie,U=de*we+me*De+ge*Le,(V=de*Me+me*Se+ge*Ce)<0&&(V=-V),k<0&&(k=-k),U<0&&(U=-U),(E=N-F-(V*oe+k*se+U*ae))>0||((l=(N=Me*$+Se*ee+Ce*te)>0)||(N=-N),k=Me*ue+Se*pe+Ce*fe,U=Me*de+Se*me+Ce*ge,(V=Me*he+Se*le+Ce*ce)<0&&(V=-V),k<0&&(k=-k),U<0&&(U=-U),(A=1*(N-(F=V*ie+k*re+U*ne)-oe))>0||((c=(N=Re*$+Oe*ee+Ie*te)>0)||(N=-N),k=Re*ue+Oe*pe+Ie*fe,U=Re*de+Oe*me+Ie*ge,(V=Re*he+Oe*le+Ie*ce)<0&&(V=-V),k<0&&(k=-k),U<0&&(U=-U),(P=1*(N-(F=V*ie+k*re+U*ne)-se))>0||((u=(N=we*$+De*ee+Le*te)>0)||(N=-N),k=we*ue+De*pe+Le*fe,U=we*de+De*me+Le*ge,(V=we*he+De*le+Le*ce)<0&&(V=-V),k<0&&(k=-k),U<0&&(U=-U),(M=1*(N-(F=V*ie+k*re+U*ne)-ae))>0))))))){if((N=He*He+je*je+Xe*Xe)>1e-5){if((p=(N=(He*=N=1/o.sqrt(N))*$+(je*=N)*ee+(Xe*=N)*te)>0)||(N=-N),k=He*de+je*me+Xe*ge,(V=He*ue+je*pe+Xe*fe)<0&&(V=-V),k<0&&(k=-k),F=V*re+k*ne,k=He*we+je*De+Xe*Le,(V=He*Re+je*Oe+Xe*Ie)<0&&(V=-V),k<0&&(k=-k),(S=N-F-(V*se+k*ae))>0)return}else p=!1,S=0,_t=!0;if((N=Ye*Ye+Ke*Ke+Qe*Qe)>1e-5){if((f=(N=(Ye*=N=1/o.sqrt(N))*$+(Ke*=N)*ee+(Qe*=N)*te)>0)||(N=-N),k=Ye*de+Ke*me+Qe*ge,(V=Ye*ue+Ke*pe+Qe*fe)<0&&(V=-V),k<0&&(k=-k),F=V*re+k*ne,k=Ye*we+Ke*De+Qe*Le,(V=Ye*Me+Ke*Se+Qe*Ce)<0&&(V=-V),k<0&&(k=-k),(C=N-F-(V*oe+k*ae))>0)return}else f=!1,C=0,vt=!0;if((N=Ze*Ze+qe*qe+Je*Je)>1e-5){if((d=(N=(Ze*=N=1/o.sqrt(N))*$+(qe*=N)*ee+(Je*=N)*te)>0)||(N=-N),k=Ze*de+qe*me+Je*ge,(V=Ze*ue+qe*pe+Je*fe)<0&&(V=-V),k<0&&(k=-k),F=V*re+k*ne,k=Ze*Re+qe*Oe+Je*Ie,(V=Ze*Me+qe*Se+Je*Ce)<0&&(V=-V),k<0&&(k=-k),(R=N-F-(V*oe+k*se))>0)return}else d=!1,R=0,yt=!0;if((N=$e*$e+et*et+tt*tt)>1e-5){if((m=(N=($e*=N=1/o.sqrt(N))*$+(et*=N)*ee+(tt*=N)*te)>0)||(N=-N),k=$e*de+et*me+tt*ge,(V=$e*he+et*le+tt*ce)<0&&(V=-V),k<0&&(k=-k),F=V*ie+k*ne,k=$e*we+et*De+tt*Le,(V=$e*Re+et*Oe+tt*Ie)<0&&(V=-V),k<0&&(k=-k),(O=N-F-(V*se+k*ae))>0)return}else m=!1,O=0,bt=!0;if((N=it*it+rt*rt+nt*nt)>1e-5){if((g=(N=(it*=N=1/o.sqrt(N))*$+(rt*=N)*ee+(nt*=N)*te)>0)||(N=-N),k=it*de+rt*me+nt*ge,(V=it*he+rt*le+nt*ce)<0&&(V=-V),k<0&&(k=-k),F=V*ie+k*ne,k=it*we+rt*De+nt*Le,(V=it*Me+rt*Se+nt*Ce)<0&&(V=-V),k<0&&(k=-k),(I=N-F-(V*oe+k*ae))>0)return}else g=!1,I=0,xt=!0;if((N=ot*ot+st*st+at*at)>1e-5){if((_=(N=(ot*=N=1/o.sqrt(N))*$+(st*=N)*ee+(at*=N)*te)>0)||(N=-N),k=ot*de+st*me+at*ge,(V=ot*he+st*le+at*ce)<0&&(V=-V),k<0&&(k=-k),F=V*ie+k*ne,k=ot*Re+st*Oe+at*Ie,(V=ot*Me+st*Se+at*Ce)<0&&(V=-V),k<0&&(k=-k),(w=N-F-(V*oe+k*se))>0)return}else _=!1,w=0,Tt=!0;if((N=ht*ht+lt*lt+ct*ct)>1e-5){if((v=(N=(ht*=N=1/o.sqrt(N))*$+(lt*=N)*ee+(ct*=N)*te)>0)||(N=-N),k=ht*ue+lt*pe+ct*fe,(V=ht*he+lt*le+ct*ce)<0&&(V=-V),k<0&&(k=-k),F=V*ie+k*re,k=ht*we+lt*De+ct*Le,(V=ht*Re+lt*Oe+ct*Ie)<0&&(V=-V),k<0&&(k=-k),(D=N-F-(V*se+k*ae))>0)return}else v=!1,D=0,Et=!0;if((N=ut*ut+pt*pt+ft*ft)>1e-5){if((y=(N=(ut*=N=1/o.sqrt(N))*$+(pt*=N)*ee+(ft*=N)*te)>0)||(N=-N),k=ut*ue+pt*pe+ft*fe,(V=ut*he+pt*le+ft*ce)<0&&(V=-V),k<0&&(k=-k),F=V*ie+k*re,k=ut*we+pt*De+ft*Le,(V=ut*Me+pt*Se+ft*Ce)<0&&(V=-V),k<0&&(k=-k),(L=N-F-(V*oe+k*ae))>0)return}else y=!1,L=0,At=!0;if((N=dt*dt+mt*mt+gt*gt)>1e-5){if((b=(N=(dt*=N=1/o.sqrt(N))*$+(mt*=N)*ee+(gt*=N)*te)>0)||(N=-N),k=dt*ue+mt*pe+gt*fe,(V=dt*he+mt*le+gt*ce)<0&&(V=-V),k<0&&(k=-k),F=V*ie+k*re,k=dt*Re+mt*Oe+gt*Ie,(V=dt*Me+mt*Se+gt*Ce)<0&&(V=-V),k<0&&(k=-k),(B=N-F-(V*oe+k*se))>0)return}else b=!1,B=0,Pt=!0;var Mt=x,St=x,Ct=0,Rt=s;T>St&&(Mt=T,St=T,Ct=1,Rt=a),E>St&&(Mt=E,St=E,Ct=2,Rt=h),A>St&&(Mt=A,St=A,Ct=3,Rt=l),P>St&&(Mt=P,St=P,Ct=4,Rt=c),M>St&&(Mt=M,St=M,Ct=5,Rt=u),S-.01>St&&!_t&&(Mt=S,St=S-.01,Ct=6,Rt=p),C-.01>St&&!vt&&(Mt=C,St=C-.01,Ct=7,Rt=f),R-.01>St&&!yt&&(Mt=R,St=R-.01,Ct=8,Rt=d),O-.01>St&&!bt&&(Mt=O,St=O-.01,Ct=9,Rt=m),I-.01>St&&!xt&&(Mt=I,St=I-.01,Ct=10,Rt=g),w-.01>St&&!Tt&&(Mt=w,St=w-.01,Ct=11,Rt=_),D-.01>St&&!Et&&(Mt=D,St=D-.01,Ct=12,Rt=v),L-.01>St&&!At&&(Mt=L,St=L-.01,Ct=13,Rt=y),B-.01>St&&!Pt&&(Mt=B,Ct=14,Rt=b);var Ot=0,It=0,wt=0,Dt=0,Lt=0,Bt=0,Nt=0,Ft=0,Vt=0,kt=0,Ut=0,zt=0,Gt=0,Wt=0,Ht=0,jt=0,Xt=0,Yt=0,Kt=!1;if(0==Ct?(Rt?(kt=Y+_e,Ut=K+ve,zt=Q+ye,Ot=he,It=le,wt=ce):(kt=Y-_e,Ut=K-ve,zt=Q-ye,Ot=-he,It=-le,wt=-ce),Gt=be,Wt=xe,Ht=Te,Dt=-ue,Lt=-pe,Bt=-fe,jt=Ee,Xt=Ae,Yt=Pe,Nt=-de,Ft=-me,Vt=-ge):1==Ct?(Rt?(kt=Y+be,Ut=K+xe,zt=Q+Te,Ot=ue,It=pe,wt=fe):(kt=Y-be,Ut=K-xe,zt=Q-Te,Ot=-ue,It=-pe,wt=-fe),Gt=_e,Wt=ve,Ht=ye,Dt=-he,Lt=-le,Bt=-ce,jt=Ee,Xt=Ae,Yt=Pe,Nt=-de,Ft=-me,Vt=-ge):2==Ct?(Rt?(kt=Y+Ee,Ut=K+Ae,zt=Q+Pe,Ot=de,It=me,wt=ge):(kt=Y-Ee,Ut=K-Ae,zt=Q-Pe,Ot=-de,It=-me,wt=-ge),Gt=_e,Wt=ve,Ht=ye,Dt=-he,Lt=-le,Bt=-ce,jt=be,Xt=xe,Yt=Te,Nt=-ue,Ft=-pe,Vt=-fe):3==Ct?(Kt=!0,Rt?(kt=Z-Be,Ut=q-Ne,zt=J-Fe,Ot=-Me,It=-Se,wt=-Ce):(kt=Z+Be,Ut=q+Ne,zt=J+Fe,Ot=Me,It=Se,wt=Ce),Gt=Ve,Wt=ke,Ht=Ue,Dt=-Re,Lt=-Oe,Bt=-Ie,jt=ze,Xt=Ge,Yt=We,Nt=-we,Ft=-De,Vt=-Le):4==Ct?(Kt=!0,Rt?(kt=Z-Ve,Ut=q-ke,zt=J-Ue,Ot=-Re,It=-Oe,wt=-Ie):(kt=Z+Ve,Ut=q+ke,zt=J+Ue,Ot=Re,It=Oe,wt=Ie),Gt=Be,Wt=Ne,Ht=Fe,Dt=-Me,Lt=-Se,Bt=-Ce,jt=ze,Xt=Ge,Yt=We,Nt=-we,Ft=-De,Vt=-Le):5==Ct?(Kt=!0,Rt?(kt=Z-ze,Ut=q-Ge,zt=J-We,Ot=-we,It=-De,wt=-Le):(kt=Z+ze,Ut=q+Ge,zt=J+We,Ot=we,It=De,wt=Le),Gt=Be,Wt=Ne,Ht=Fe,Dt=-Me,Lt=-Se,Bt=-Ce,jt=Ve,Xt=ke,Yt=Ue,Nt=-Re,Ft=-Oe,Vt=-Ie):6==Ct?(Ot=He,It=je,wt=Xe,Dt=he,Lt=le,Bt=ce,Nt=Me,Ft=Se,Vt=Ce):7==Ct?(Ot=Ye,It=Ke,wt=Qe,Dt=he,Lt=le,Bt=ce,Nt=Re,Ft=Oe,Vt=Ie):8==Ct?(Ot=Ze,It=qe,wt=Je,Dt=he,Lt=le,Bt=ce,Nt=we,Ft=De,Vt=Le):9==Ct?(Ot=$e,It=et,wt=tt,Dt=ue,Lt=pe,Bt=fe,Nt=Me,Ft=Se,Vt=Ce):10==Ct?(Ot=it,It=rt,wt=nt,Dt=ue,Lt=pe,Bt=fe,Nt=Re,Ft=Oe,Vt=Ie):11==Ct?(Ot=ot,It=st,wt=at,Dt=ue,Lt=pe,Bt=fe,Nt=we,Ft=De,Vt=Le):12==Ct?(Ot=ht,It=lt,wt=ct,Dt=de,Lt=me,Bt=ge,Nt=Me,Ft=Se,Vt=Ce):13==Ct?(Ot=ut,It=pt,wt=ft,Dt=de,Lt=me,Bt=ge,Nt=Re,Ft=Oe,Vt=Ie):14==Ct&&(Ot=dt,It=mt,wt=gt,Dt=de,Lt=me,Bt=ge,Nt=we,Ft=De,Vt=Le),Ct>5){var Qt,Zt,qt,Jt,$t,ei,ti,ii,ri,ni,oi;Rt||(Ot=-Ot,It=-It,wt=-wt),Zt=Ot*(ei=z[0])+It*(ti=z[1])+wt*(ii=z[2]),(Qt=Ot*(qt=z[3])+It*(Jt=z[4])+wt*($t=z[5]))>Zt&&(Zt=Qt,ei=qt,ti=Jt,ii=$t),(Qt=Ot*(qt=z[6])+It*(Jt=z[7])+wt*($t=z[8]))>Zt&&(Zt=Qt,ei=qt,ti=Jt,ii=$t),(Qt=Ot*(qt=z[9])+It*(Jt=z[10])+wt*($t=z[11]))>Zt&&(Zt=Qt,ei=qt,ti=Jt,ii=$t),(Qt=Ot*(qt=z[12])+It*(Jt=z[13])+wt*($t=z[14]))>Zt&&(Zt=Qt,ei=qt,ti=Jt,ii=$t),(Qt=Ot*(qt=z[15])+It*(Jt=z[16])+wt*($t=z[17]))>Zt&&(Zt=Qt,ei=qt,ti=Jt,ii=$t),(Qt=Ot*(qt=z[18])+It*(Jt=z[19])+wt*($t=z[20]))>Zt&&(Zt=Qt,ei=qt,ti=Jt,ii=$t),(Qt=Ot*(qt=z[21])+It*(Jt=z[22])+wt*($t=z[23]))>Zt&&(Zt=Qt,ei=qt,ti=Jt,ii=$t),Zt=Ot*(ri=G[0])+It*(ni=G[1])+wt*(oi=G[2]),(Qt=Ot*(qt=G[3])+It*(Jt=G[4])+wt*($t=G[5]))<Zt&&(Zt=Qt,ri=qt,ni=Jt,oi=$t),(Qt=Ot*(qt=G[6])+It*(Jt=G[7])+wt*($t=G[8]))<Zt&&(Zt=Qt,ri=qt,ni=Jt,oi=$t),(Qt=Ot*(qt=G[9])+It*(Jt=G[10])+wt*($t=G[11]))<Zt&&(Zt=Qt,ri=qt,ni=Jt,oi=$t),(Qt=Ot*(qt=G[12])+It*(Jt=G[13])+wt*($t=G[14]))<Zt&&(Zt=Qt,ri=qt,ni=Jt,oi=$t),(Qt=Ot*(qt=G[15])+It*(Jt=G[16])+wt*($t=G[17]))<Zt&&(Zt=Qt,ri=qt,ni=Jt,oi=$t),(Qt=Ot*(qt=G[18])+It*(Jt=G[19])+wt*($t=G[20]))<Zt&&(Zt=Qt,ri=qt,ni=Jt,oi=$t),(Qt=Ot*(qt=G[21])+It*(Jt=G[22])+wt*($t=G[23]))<Zt&&(Zt=Qt,ri=qt,ni=Jt,oi=$t);var si=((qt=ri-ei)*(Dt-Nt*(V=Dt*Nt+Lt*Ft+Bt*Vt))+(Jt=ni-ti)*(Lt-Ft*V)+($t=oi-ii)*(Bt-Vt*V))/(1-V*V);i.addPoint(ei+Dt*si+Ot*Mt*.5,ti+Lt*si+It*Mt*.5,ii+Bt*si+wt*Mt*.5,Ot,It,wt,Mt,!1)}else{var ai,hi,li,ci,ui,pi,fi,di,mi,gi,_i,vi,yi,bi,xi,Ti,Ei,Ai,Pi,Mi,Si,Ci=1,Ri=0,Oi=0;Kt?((Ri=he*Ot+le*It+ce*wt)<Ci&&(Ci=Ri,Oi=0),-Ri<Ci&&(Ci=-Ri,Oi=1),(Ri=ue*Ot+pe*It+fe*wt)<Ci&&(Ci=Ri,Oi=2),-Ri<Ci&&(Ci=-Ri,Oi=3),(Ri=de*Ot+me*It+ge*wt)<Ci&&(Ci=Ri,Oi=4),-Ri<Ci&&(Ci=-Ri,Oi=5),0==Oi?(ai=z[0],hi=z[1],li=z[2],ci=z[6],ui=z[7],pi=z[8],fi=z[9],di=z[10],mi=z[11],gi=z[3],_i=z[4],vi=z[5]):1==Oi?(ai=z[15],hi=z[16],li=z[17],ci=z[21],ui=z[22],pi=z[23],fi=z[18],di=z[19],mi=z[20],gi=z[12],_i=z[13],vi=z[14]):2==Oi?(ai=z[12],hi=z[13],li=z[14],ci=z[0],ui=z[1],pi=z[2],fi=z[3],di=z[4],mi=z[5],gi=z[15],_i=z[16],vi=z[17]):3==Oi?(ai=z[21],hi=z[22],li=z[23],ci=z[9],ui=z[10],pi=z[11],fi=z[6],di=z[7],mi=z[8],gi=z[18],_i=z[19],vi=z[20]):4==Oi?(ai=z[12],hi=z[13],li=z[14],ci=z[18],ui=z[19],pi=z[20],fi=z[6],di=z[7],mi=z[8],gi=z[0],_i=z[1],vi=z[2]):5==Oi&&(ai=z[3],hi=z[4],li=z[5],ci=z[6],ui=z[7],pi=z[8],fi=z[21],di=z[22],mi=z[23],gi=z[15],_i=z[16],vi=z[17])):((Ri=Me*Ot+Se*It+Ce*wt)<Ci&&(Ci=Ri,Oi=0),-Ri<Ci&&(Ci=-Ri,Oi=1),(Ri=Re*Ot+Oe*It+Ie*wt)<Ci&&(Ci=Ri,Oi=2),-Ri<Ci&&(Ci=-Ri,Oi=3),(Ri=we*Ot+De*It+Le*wt)<Ci&&(Ci=Ri,Oi=4),-Ri<Ci&&(Ci=-Ri,Oi=5),0==Oi?(ai=G[0],hi=G[1],li=G[2],ci=G[6],ui=G[7],pi=G[8],fi=G[9],di=G[10],mi=G[11],gi=G[3],_i=G[4],vi=G[5]):1==Oi?(ai=G[15],hi=G[16],li=G[17],ci=G[21],ui=G[22],pi=G[23],fi=G[18],di=G[19],mi=G[20],gi=G[12],_i=G[13],vi=G[14]):2==Oi?(ai=G[12],hi=G[13],li=G[14],ci=G[0],ui=G[1],pi=G[2],fi=G[3],di=G[4],mi=G[5],gi=G[15],_i=G[16],vi=G[17]):3==Oi?(ai=G[21],hi=G[22],li=G[23],ci=G[9],ui=G[10],pi=G[11],fi=G[6],di=G[7],mi=G[8],gi=G[18],_i=G[19],vi=G[20]):4==Oi?(ai=G[12],hi=G[13],li=G[14],ci=G[18],ui=G[19],pi=G[20],fi=G[6],di=G[7],mi=G[8],gi=G[0],_i=G[1],vi=G[2]):5==Oi&&(ai=G[3],hi=G[4],li=G[5],ci=G[9],ui=G[10],pi=G[11],fi=G[21],di=G[22],mi=G[23],gi=G[15],_i=G[16],vi=G[17])),this.clipVertices1[0]=ai,this.clipVertices1[1]=hi,this.clipVertices1[2]=li,this.clipVertices1[3]=ci,this.clipVertices1[4]=ui,this.clipVertices1[5]=pi,this.clipVertices1[6]=fi,this.clipVertices1[7]=di,this.clipVertices1[8]=mi,this.clipVertices1[9]=gi,this.clipVertices1[10]=_i,this.clipVertices1[11]=vi,bi=0,V=((Ti=this.clipVertices1[9])-kt-Gt)*Dt+((Ei=this.clipVertices1[10])-Ut-Wt)*Lt+((Ai=this.clipVertices1[11])-zt-Ht)*Bt;for(var Ii=0;Ii<4;Ii++)xi=3*Ii,k=((Pi=this.clipVertices1[xi])-kt-Gt)*Dt+((Mi=this.clipVertices1[xi+1])-Ut-Wt)*Lt+((Si=this.clipVertices1[xi+2])-zt-Ht)*Bt,V>0?k>0?(xi=3*bi,bi++,this.clipVertices2[xi]=Pi,this.clipVertices2[xi+1]=Mi,this.clipVertices2[xi+2]=Si):(xi=3*bi,bi++,si=V/(V-k),this.clipVertices2[xi]=Ti+(Pi-Ti)*si,this.clipVertices2[xi+1]=Ei+(Mi-Ei)*si,this.clipVertices2[xi+2]=Ai+(Si-Ai)*si):k>0&&(xi=3*bi,bi++,si=V/(V-k),this.clipVertices2[xi]=Ti+(Pi-Ti)*si,this.clipVertices2[xi+1]=Ei+(Mi-Ei)*si,this.clipVertices2[xi+2]=Ai+(Si-Ai)*si,xi=3*bi,bi++,this.clipVertices2[xi]=Pi,this.clipVertices2[xi+1]=Mi,this.clipVertices2[xi+2]=Si),Ti=Pi,Ei=Mi,Ai=Si,V=k;if(0!=(yi=bi)){for(bi=0,xi=3*(yi-1),V=((Ti=this.clipVertices2[xi])-kt-jt)*Nt+((Ei=this.clipVertices2[xi+1])-Ut-Xt)*Ft+((Ai=this.clipVertices2[xi+2])-zt-Yt)*Vt,Ii=0;Ii<yi;Ii++)xi=3*Ii,k=((Pi=this.clipVertices2[xi])-kt-jt)*Nt+((Mi=this.clipVertices2[xi+1])-Ut-Xt)*Ft+((Si=this.clipVertices2[xi+2])-zt-Yt)*Vt,V>0?k>0?(xi=3*bi,bi++,this.clipVertices1[xi]=Pi,this.clipVertices1[xi+1]=Mi,this.clipVertices1[xi+2]=Si):(xi=3*bi,bi++,si=V/(V-k),this.clipVertices1[xi]=Ti+(Pi-Ti)*si,this.clipVertices1[xi+1]=Ei+(Mi-Ei)*si,this.clipVertices1[xi+2]=Ai+(Si-Ai)*si):k>0&&(xi=3*bi,bi++,si=V/(V-k),this.clipVertices1[xi]=Ti+(Pi-Ti)*si,this.clipVertices1[xi+1]=Ei+(Mi-Ei)*si,this.clipVertices1[xi+2]=Ai+(Si-Ai)*si,xi=3*bi,bi++,this.clipVertices1[xi]=Pi,this.clipVertices1[xi+1]=Mi,this.clipVertices1[xi+2]=Si),Ti=Pi,Ei=Mi,Ai=Si,V=k;if(0!=(yi=bi)){for(bi=0,xi=3*(yi-1),V=((Ti=this.clipVertices1[xi])-kt+Gt)*-Dt+((Ei=this.clipVertices1[xi+1])-Ut+Wt)*-Lt+((Ai=this.clipVertices1[xi+2])-zt+Ht)*-Bt,Ii=0;Ii<yi;Ii++)xi=3*Ii,k=((Pi=this.clipVertices1[xi])-kt+Gt)*-Dt+((Mi=this.clipVertices1[xi+1])-Ut+Wt)*-Lt+((Si=this.clipVertices1[xi+2])-zt+Ht)*-Bt,V>0?k>0?(xi=3*bi,bi++,this.clipVertices2[xi]=Pi,this.clipVertices2[xi+1]=Mi,this.clipVertices2[xi+2]=Si):(xi=3*bi,bi++,si=V/(V-k),this.clipVertices2[xi]=Ti+(Pi-Ti)*si,this.clipVertices2[xi+1]=Ei+(Mi-Ei)*si,this.clipVertices2[xi+2]=Ai+(Si-Ai)*si):k>0&&(xi=3*bi,bi++,si=V/(V-k),this.clipVertices2[xi]=Ti+(Pi-Ti)*si,this.clipVertices2[xi+1]=Ei+(Mi-Ei)*si,this.clipVertices2[xi+2]=Ai+(Si-Ai)*si,xi=3*bi,bi++,this.clipVertices2[xi]=Pi,this.clipVertices2[xi+1]=Mi,this.clipVertices2[xi+2]=Si),Ti=Pi,Ei=Mi,Ai=Si,V=k;if(0!=(yi=bi)){for(bi=0,xi=3*(yi-1),V=((Ti=this.clipVertices2[xi])-kt+jt)*-Nt+((Ei=this.clipVertices2[xi+1])-Ut+Xt)*-Ft+((Ai=this.clipVertices2[xi+2])-zt+Yt)*-Vt,Ii=0;Ii<yi;Ii++)xi=3*Ii,k=((Pi=this.clipVertices2[xi])-kt+jt)*-Nt+((Mi=this.clipVertices2[xi+1])-Ut+Xt)*-Ft+((Si=this.clipVertices2[xi+2])-zt+Yt)*-Vt,V>0?k>0?(xi=3*bi,bi++,this.clipVertices1[xi]=Pi,this.clipVertices1[xi+1]=Mi,this.clipVertices1[xi+2]=Si):(xi=3*bi,bi++,si=V/(V-k),this.clipVertices1[xi]=Ti+(Pi-Ti)*si,this.clipVertices1[xi+1]=Ei+(Mi-Ei)*si,this.clipVertices1[xi+2]=Ai+(Si-Ai)*si):k>0&&(xi=3*bi,bi++,si=V/(V-k),this.clipVertices1[xi]=Ti+(Pi-Ti)*si,this.clipVertices1[xi+1]=Ei+(Mi-Ei)*si,this.clipVertices1[xi+2]=Ai+(Si-Ai)*si,xi=3*bi,bi++,this.clipVertices1[xi]=Pi,this.clipVertices1[xi+1]=Mi,this.clipVertices1[xi+2]=Si),Ti=Pi,Ei=Mi,Ai=Si,V=k;if(yi=bi,Kt){var wi=r;r=n,n=wi}if(0!=yi){var Di=r!=e;if(yi>4){Dt=ai-(Ti=.25*(ai+ci+fi+gi)),Lt=hi-(Ei=.25*(hi+ui+di+_i)),Bt=li-(Ai=.25*(li+pi+mi+vi)),Nt=ci-Ti,Ft=ui-Ei,Vt=pi-Ai;var Li=0,Bi=0,Ni=0,Fi=0,Vi=-this.INF;for(Ci=this.INF,Ii=0;Ii<yi;Ii++)this.used[Ii]=!1,xi=3*Ii,(Ri=(Ti=this.clipVertices1[xi])*Dt+(Ei=this.clipVertices1[xi+1])*Lt+(Ai=this.clipVertices1[xi+2])*Bt)<Ci&&(Ci=Ri,Li=Ii),Ri>Vi&&(Vi=Ri,Ni=Ii);for(this.used[Li]=!0,this.used[Ni]=!0,Vi=-this.INF,Ci=this.INF,Ii=0;Ii<yi;Ii++)this.used[Ii]||(xi=3*Ii,(Ri=(Ti=this.clipVertices1[xi])*Nt+(Ei=this.clipVertices1[xi+1])*Ft+(Ai=this.clipVertices1[xi+2])*Vt)<Ci&&(Ci=Ri,Bi=Ii),Ri>Vi&&(Vi=Ri,Fi=Ii));xi=3*Li,(Ri=((Ti=this.clipVertices1[xi])-kt)*Ot+((Ei=this.clipVertices1[xi+1])-Ut)*It+((Ai=this.clipVertices1[xi+2])-zt)*wt)<0&&i.addPoint(Ti,Ei,Ai,Ot,It,wt,Ri,Di),xi=3*Bi,(Ri=((Ti=this.clipVertices1[xi])-kt)*Ot+((Ei=this.clipVertices1[xi+1])-Ut)*It+((Ai=this.clipVertices1[xi+2])-zt)*wt)<0&&i.addPoint(Ti,Ei,Ai,Ot,It,wt,Ri,Di),xi=3*Ni,(Ri=((Ti=this.clipVertices1[xi])-kt)*Ot+((Ei=this.clipVertices1[xi+1])-Ut)*It+((Ai=this.clipVertices1[xi+2])-zt)*wt)<0&&i.addPoint(Ti,Ei,Ai,Ot,It,wt,Ri,Di),xi=3*Fi,(Ri=((Ti=this.clipVertices1[xi])-kt)*Ot+((Ei=this.clipVertices1[xi+1])-Ut)*It+((Ai=this.clipVertices1[xi+2])-zt)*wt)<0&&i.addPoint(Ti,Ei,Ai,Ot,It,wt,Ri,Di)}else for(Ii=0;Ii<yi;Ii++)xi=3*Ii,(Ri=((Ti=this.clipVertices1[xi])-kt)*Ot+((Ei=this.clipVertices1[xi+1])-Ut)*It+((Ai=this.clipVertices1[xi+2])-zt)*wt)<0&&i.addPoint(Ti,Ei,Ai,Ot,It,wt,Ri,Di)}}}}}}},o.SphereBoxCollisionDetector=function(e){o.CollisionDetector.call(this),this.flip=e},o.SphereBoxCollisionDetector.prototype=Object.create(o.CollisionDetector.prototype),o.SphereBoxCollisionDetector.prototype.constructor=o.SphereBoxCollisionDetector,o.SphereBoxCollisionDetector.prototype.detectCollision=function(e,t,i){var r,n;this.flip?(r=t,n=e):(r=e,n=t);var s,a,h,l,c,u=n.dimentions,p=r.position,f=p.x,d=p.y,m=p.z,g=n.position,_=g.x,v=g.y,y=g.z,b=r.radius,x=n.halfWidth,T=n.halfHeight,E=n.halfDepth,A=f-_,P=d-v,M=m-y,S=u[0]*A+u[1]*P+u[2]*M,C=u[3]*A+u[4]*P+u[5]*M,R=u[6]*A+u[7]*P+u[8]*M,O=0;S>x?S=x:S<-x?S=-x:O=1,C>T?C=T:C<-T?C=-T:O|=2,R>E?R=E:R<-E?R=-E:O|=4,7==O?(A=S<0?x+S:x-S,P=C<0?T+C:T-C,M=R<0?E+R:E-R,A<P?A<M?(l=A-x,S<0?(S=-x,A=u[0],P=u[1],M=u[2]):(S=x,A=-u[0],P=-u[1],M=-u[2])):(l=M-E,R<0?(R=-E,A=u[6],P=u[7],M=u[8]):(R=E,A=-u[6],P=-u[7],M=-u[8])):P<M?(l=P-T,C<0?(C=-T,A=u[3],P=u[4],M=u[5]):(C=T,A=-u[3],P=-u[4],M=-u[5])):(l=M-E,R<0?(R=-E,A=u[6],P=u[7],M=u[8]):(R=E,A=-u[6],P=-u[7],M=-u[8])),s=_+S*u[0]+C*u[3]+R*u[6],a=v+S*u[1]+C*u[4]+R*u[7],h=y+S*u[2]+C*u[5]+R*u[8],i.addPoint(f+b*A,d+b*P,m+b*M,A,P,M,l-b,this.flip)):(s=_+S*u[0]+C*u[3]+R*u[6],a=v+S*u[1]+C*u[4]+R*u[7],h=y+S*u[2]+C*u[5]+R*u[8],(l=(A=s-p.x)*A+(P=a-p.y)*P+(M=h-p.z)*M)>0&&l<b*b&&(A*=c=1/(l=o.sqrt(l)),P*=c,M*=c,i.addPoint(f+b*A,d+b*P,m+b*M,A,P,M,l-b,this.flip)))},o.SphereSphereCollisionDetector=function(){o.CollisionDetector.call(this)},o.SphereSphereCollisionDetector.prototype=Object.create(o.CollisionDetector.prototype),o.SphereSphereCollisionDetector.prototype.constructor=o.SphereSphereCollisionDetector,o.SphereSphereCollisionDetector.prototype.detectCollision=function(e,t,i){var r=e,n=t,s=r.position,a=n.position,h=a.x-s.x,l=a.y-s.y,c=a.z-s.z,u=h*h+l*l+c*c,p=r.radius,f=p+n.radius;if(u>0&&u<f*f){var d=1/(u=o.sqrt(u));h*=d,l*=d,c*=d,i.addPoint(s.x+h*p,s.y+l*p,s.z+c*p,h,l,c,u-f,!1)}},o.BoxCylinderCollisionDetector=function(e){o.CollisionDetector.call(this),this.flip=e},o.BoxCylinderCollisionDetector.prototype=Object.create(o.CollisionDetector.prototype),o.BoxCylinderCollisionDetector.prototype.constructor=o.BoxCylinderCollisionDetector,o.BoxCylinderCollisionDetector.prototype.getSep=function(e,t,i,r,n){var s,a,h,l,c,u,p,f,d,m,g,_,v,y=new o.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,O=-S,I=-C;this.supportPointB(e,-R,-O,-I,y);var w=y.x,D=y.y,L=y.z;this.supportPointC(t,R,O,I,y);var B=y.x,N=y.y,F=y.z,V=B-w,k=N-D,U=F-L;if(V*R+k*O+U*I<=0)return!1;if((R=k*C-U*S)*R+(O=U*M-V*C)*O+(I=V*S-k*M)*I==0)return i.init(V-M,k-S,U-C),i.normalize(i),r.init(.5*(w+B),.5*(D+N),.5*(L+F)),!0;this.supportPointB(e,-R,-O,-I,y);var z=y.x,G=y.y,W=y.z;this.supportPointC(t,R,O,I,y);var H=y.x,j=y.y,X=y.z,Y=H-z,K=j-G,Q=X-W;if(Y*R+K*O+Q*I<=0)return!1;(R=(a=k-S)*(u=Q-C)-(h=U-C)*(c=K-S))*M+(O=h*(l=Y-M)-(s=V-M)*u)*S+(I=s*c-a*l)*C>0&&(s=V,a=k,h=U,V=Y,k=K,U=Q,Y=s,K=a,Q=h,s=w,a=D,h=L,w=z,D=G,L=W,z=s,G=a,W=h,s=B,a=N,h=F,B=H,N=j,F=X,H=s,j=a,X=h,R=-R,O=-O,I=-I);for(var Z=0;;){if(++Z>100)return!1;this.supportPointB(e,-R,-O,-I,y);var q=y.x,J=y.y,$=y.z;this.supportPointC(t,R,O,I,y);var ee=y.x,te=y.y,ie=y.z,re=ee-q,ne=te-J,oe=ie-$;if(re*R+ne*O+oe*I<=0)return!1;if((k*oe-U*ne)*M+(U*re-V*oe)*S+(V*ne-k*re)*C<0)Y=re,K=ne,Q=oe,z=q,G=J,W=$,H=ee,j=te,X=ie,R=(a=k-S)*(u=oe-C)-(h=U-C)*(c=ne-S),O=h*(l=re-M)-(s=V-M)*u,I=s*c-a*l;else if((ne*Q-oe*K)*M+(oe*Y-re*Q)*S+(re*K-ne*Y)*C<0)V=re,k=ne,U=oe,w=q,D=J,L=$,B=ee,N=te,F=ie,R=(a=ne-S)*(u=Q-C)-(h=oe-C)*(c=K-S),O=h*(l=Y-M)-(s=re-M)*u,I=s*c-a*l;else for(var se=!1;;){if(R=(a=K-k)*(u=oe-U)-(h=Q-U)*(c=ne-k),O=h*(l=re-V)-(s=Y-V)*u,I=s*c-a*l,(R*=p=1/o.sqrt(R*R+O*O+I*I))*V+(O*=p)*k+(I*=p)*U>=0&&!se){var ae=(k*Q-U*K)*re+(U*Y-V*Q)*ne+(V*K-k*Y)*oe,he=(ne*Q-oe*K)*M+(oe*Y-re*Q)*S+(re*K-ne*Y)*C,le=(S*U-C*k)*re+(C*V-M*U)*ne+(M*k-S*V)*oe,ce=(K*U-Q*k)*M+(Q*V-Y*U)*S+(Y*k-K*V)*C,ue=ae+he+le+ce;ue<=0&&(ae=0,ue=(he=(K*oe-Q*ne)*R+(Q*re-Y*oe)*O+(Y*ne-K*re)*I)+(le=(ne*Q-oe*K)*R+(oe*Y-re*Q)*O+(re*K-ne*Y)*I)+(ce=(k*Q-U*K)*R+(U*Y-V*Q)*O+(V*K-k*Y)*I));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+B*he+H*le+ee*ce)*pe,_=(A*ae+N*he+j*le+te*ce)*pe,v=(P*ae+F*he+X*le+ie*ce)*pe,se=!0}this.supportPointB(e,-R,-O,-I,y);var fe=y.x,de=y.y,me=y.z;this.supportPointC(t,R,O,I,y);var ge=y.x,_e=y.y,ve=y.z,ye=ge-fe,be=_e-de,xe=ve-me,Te=-(ye*R+be*O+xe*I);if((ye-re)*R+(be-ne)*O+(xe-oe)*I<=.01||Te>=0)return!!se&&(i.init(-R,-O,-I),r.init(.5*(f+g),.5*(d+_),.5*(m+v)),n.x=Te,!0);(be*U-xe*k)*M+(xe*V-ye*U)*S+(ye*k-be*V)*C<0?(be*Q-xe*K)*M+(xe*Y-ye*Q)*S+(ye*K-be*Y)*C<0?(V=ye,k=be,U=xe,w=fe,D=de,L=me,B=ge,N=_e,F=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,k=be,U=xe,w=fe,D=de,L=me,B=ge,N=_e,F=ve)}}},o.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)},o.BoxCylinderCollisionDetector.prototype.supportPointC=function(e,t,i,r,n){var s,a,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?(s=g,a=-_,h=0):(s=g,a=_,h=0):(m=e.radius/o.sqrt(m),u<0?(s=f*m,a=-_,h=d*m):(s=f*m,a=_,h=d*m)),c=l[0]*s+l[1]*a+l[2]*h+e.position.x,u=l[3]*s+l[4]*a+l[5]*h+e.position.y,p=l[6]*s+l[7]*a+l[8]*h+e.position.z,n.init(c,u,p)},o.BoxCylinderCollisionDetector.prototype.detectCollision=function(e,t,i){var r,n;this.flip?(r=t,n=e):(r=e,n=t);var s=new o.Vec3,a=new o.Vec3,h=new o.Vec3;if(this.getSep(r,n,s,a,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],O=b[9],I=b[10],w=b[11],D=b[12],L=b[13],B=b[14],N=b[15],F=b[16],V=b[17],k=n.normalDirection.x,U=n.normalDirection.y,z=n.normalDirection.z,G=n.halfDirection.x,W=n.halfDirection.y,H=n.halfDirection.z,j=s.x,X=s.y,Y=s.z,K=j*x+X*T+Y*E,Q=j*A+X*P+Y*M,Z=j*S+X*C+Y*R,q=j*k+X*U+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,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,Oe,Ie,we,De,Le,Be,Ne,Fe,Ve,ke,Ue,ze,Ge,We,He,je,Xe,Ye,Ke,Qe,Ze,qe,Je,$e,et,tt=0;if(q>.999?tt=K>.999?K>q?1:4:Q>.999?Q>q?2:4:Z>.999&&Z>q?3:4:K>.999?tt=1:Q>.999?tt=2:Z>.999&&(tt=3),0==tt)i.addPoint(a.x,a.y,a.z,j,X,Y,h.x,this.flip);else if(4==tt){var it,rt,nt,ot,st,at,ht,lt,ct,ut,pt,ft;te?(oe=p-G,se=f-W,ae=d-H,j=-k,X=-U,Y=-z):(oe=p+G,se=f+W,ae=d+H,j=k,X=U,Y=z),tt=0,(He=x*j+T*X+E*Y)<(xe=1)&&(xe=He,tt=0),-He<xe&&(xe=-He,tt=1),(He=A*j+P*X+M*Y)<xe&&(xe=He,tt=2),-He<xe&&(xe=-He,tt=3),(He=S*j+C*X+R*Y)<xe&&(xe=He,tt=4),-He<xe&&(xe=-He,tt=5);var dt=r.elements;switch(tt){case 0:it=dt[0],rt=dt[1],nt=dt[2],ot=dt[6],st=dt[7],at=dt[8],ht=dt[9],lt=dt[10],ct=dt[11],ut=dt[3],pt=dt[4],ft=dt[5];break;case 1:it=dt[15],rt=dt[16],nt=dt[17],ot=dt[21],st=dt[22],at=dt[23],ht=dt[18],lt=dt[19],ct=dt[20],ut=dt[12],pt=dt[13],ft=dt[14];break;case 2:it=dt[12],rt=dt[13],nt=dt[14],ot=dt[0],st=dt[1],at=dt[2],ht=dt[3],lt=dt[4],ct=dt[5],ut=dt[15],pt=dt[16],ft=dt[17];break;case 3:it=dt[21],rt=dt[22],nt=dt[23],ot=dt[9],st=dt[10],at=dt[11],ht=dt[6],lt=dt[7],ct=dt[8],ut=dt[18],pt=dt[19],ft=dt[20];break;case 4:it=dt[12],rt=dt[13],nt=dt[14],ot=dt[18],st=dt[19],at=dt[20],ht=dt[6],lt=dt[7],ct=dt[8],ut=dt[0],pt=dt[1],ft=dt[2];break;case 5:it=dt[3],rt=dt[4],nt=dt[5],ot=dt[9],st=dt[10],at=dt[11],ht=dt[21],lt=dt[22],ct=dt[23],ut=dt[15],pt=dt[16],ft=dt[17]}(be=j*(it-oe)+X*(rt-se)+Y*(nt-ae))<=0&&i.addPoint(it,rt,nt,-j,-X,-Y,be,this.flip),(be=j*(ot-oe)+X*(st-se)+Y*(at-ae))<=0&&i.addPoint(ot,st,at,-j,-X,-Y,be,this.flip),(be=j*(ht-oe)+X*(lt-se)+Y*(ct-ae))<=0&&i.addPoint(ht,lt,ct,-j,-X,-Y,be,this.flip),(be=j*(ut-oe)+X*(pt-se)+Y*(ft-ae))<=0&&i.addPoint(ut,pt,ft,-j,-X,-Y,be,this.flip)}else{switch(tt){case 1:J?(ie=l+O,re=c+I,ne=u+w,j=x,X=T,Y=E):(ie=l-O,re=c-I,ne=u-w,j=-x,X=-T,Y=-E),Ye=A,Ke=P,Qe=M,$e=g,Ze=S,qe=C,Je=R,et=_;break;case 2:$?(ie=l+D,re=c+L,ne=u+B,j=A,X=P,Y=M):(ie=l-D,re=c-L,ne=u-B,j=-A,X=-P,Y=-M),Ye=x,Ke=T,Qe=E,$e=m,Ze=S,qe=C,Je=R,et=_;break;case 3:ee?(ie=l+N,re=c+F,ne=u+V,j=S,X=C,Y=R):(ie=l-N,re=c-F,ne=u-V,j=-S,X=-C,Y=-R),Ye=x,Ke=T,Qe=E,$e=m,Ze=A,qe=P,Je=M,et=g}if(oe=p+(Te=(xe=j*k+X*U+Y*z)<0?v:-v)*k,se=f+Te*U,ae=d+Te*z,q>=.999999?(Ee=-X,Ae=Y,Pe=j):(Ee=j,Ae=X,Pe=Y),Se=(Te=Ee*k+Ae*U+Pe*z)*k-Ee,Ce=Te*U-Ae,Re=Te*z-Pe,0==(Te=o.sqrt(Se*Se+Ce*Ce+Re*Re)))return;if(Ee=oe+(Se*=Te=y/Te),Ae=se+(Ce*=Te),Pe=ae+(Re*=Te),xe<-.96||xe>.96)he=k*k*1.5-.5,le=k*U*1.5-.866025403*z,ce=k*z*1.5+.866025403*U,ue=U*k*1.5+.866025403*z,pe=U*U*1.5-.5,fe=U*z*1.5-.866025403*k,de=z*k*1.5-.866025403*U,me=z*U*1.5+.866025403*k,ge=z*z*1.5-.5,We=Ze*(Ee=(_e=Ee)-(be=j*(_e-ie)+X*((ve=Ae)-re)+Y*((ye=Pe)-ne))*j-ie)+qe*(Ae=ve-be*X-re)+Je*(Pe=ye-be*Y-ne),(ke=Ye*Ee+Ke*Ae+Qe*Pe)<-$e?ke=-$e:ke>$e&&(ke=$e),We<-et?We=-et:We>et&&(We=et),_e=ie+(Ee=ke*Ye+We*Ze),ve=re+(Ae=ke*Ke+We*qe),ye=ne+(Pe=ke*Qe+We*Je),i.addPoint(_e,ve,ye,j,X,Y,be,this.flip),ve=Se*ue+Ce*pe+Re*fe,ye=Se*de+Ce*me+Re*ge,(be=j*((_e=(Se=_e=Se*he+Ce*le+Re*ce)+oe)-ie)+X*((ve=(Ce=ve)+se)-re)+Y*((ye=(Re=ye)+ae)-ne))<=0&&(We=Ze*(Ee=_e-be*j-ie)+qe*(Ae=ve-be*X-re)+Je*(Pe=ye-be*Y-ne),(ke=Ye*Ee+Ke*Ae+Qe*Pe)<-$e?ke=-$e:ke>$e&&(ke=$e),We<-et?We=-et:We>et&&(We=et),_e=ie+(Ee=ke*Ye+We*Ze),ve=re+(Ae=ke*Ke+We*qe),ye=ne+(Pe=ke*Qe+We*Je),i.addPoint(_e,ve,ye,j,X,Y,be,this.flip)),ve=Se*ue+Ce*pe+Re*fe,ye=Se*de+Ce*me+Re*ge,(be=j*((_e=(Se=_e=Se*he+Ce*le+Re*ce)+oe)-ie)+X*((ve=(Ce=ve)+se)-re)+Y*((ye=(Re=ye)+ae)-ne))<=0&&(We=Ze*(Ee=_e-be*j-ie)+qe*(Ae=ve-be*X-re)+Je*(Pe=ye-be*Y-ne),(ke=Ye*Ee+Ke*Ae+Qe*Pe)<-$e?ke=-$e:ke>$e&&(ke=$e),We<-et?We=-et:We>et&&(We=et),_e=ie+(Ee=ke*Ye+We*Ze),ve=re+(Ae=ke*Ke+We*qe),ye=ne+(Pe=ke*Qe+We*Je),i.addPoint(_e,ve,ye,j,X,Y,be,this.flip));else{if(Ne=Ee,Ne-=(ke=j*(Ne-ie)+X*((Fe=Ae)-re)+Y*((Ve=Pe)-ne))*j,Fe-=ke*X,Ve-=ke*Y,xe>0?(Ue=Ee+2*G,ze=Ae+2*W,Ge=Pe+2*H):(Ue=Ee-2*G,ze=Ae-2*W,Ge=Pe-2*H),Ee=(Ue-=(We=j*(Ue-ie)+X*(ze-re)+Y*(Ge-ne))*j)-Ne,Ae=(ze-=We*X)-Fe,Pe=(Ge-=We*Y)-Ve,Me=We-ke,je=(Q=(De=Ue-ie)*Ye+(Le=ze-re)*Ke+(Be=Ge-ne)*Qe)-$e,(He=(K=(Oe=Ne-ie)*Ye+(Ie=Fe-re)*Ke+(we=Ve-ne)*Qe)-$e)>0){if(je>0)return;K=(Oe=(Ne+=Ee*(Xe=He/(He-je)))-ie)*Ye+(Ie=(Fe+=Ae*Xe)-re)*Ke+(we=(Ve+=Pe*Xe)-ne)*Qe,Ee=Ue-Ne,Ae=ze-Fe,Pe=Ge-Ve,Me=We-(ke+=Me*Xe)}else je>0&&(Q=(De=(Ue=Ne+Ee*(Xe=He/(He-je)))-ie)*Ye+(Le=(ze=Fe+Ae*Xe)-re)*Ke+(Be=(Ge=Ve+Pe*Xe)-ne)*Qe,Ee=Ue-Ne,Ae=ze-Fe,Pe=Ge-Ve,Me=(We=ke+Me*Xe)-ke);if(je=Q+$e,(He=K+$e)<0){if(je<0)return;Oe=(Ne+=Ee*(Xe=He/(He-je)))-ie,Ie=(Fe+=Ae*Xe)-re,we=(Ve+=Pe*Xe)-ne,Ee=Ue-Ne,Ae=ze-Fe,Pe=Ge-Ve,Me=We-(ke+=Me*Xe)}else je<0&&(De=(Ue=Ne+Ee*(Xe=He/(He-je)))-ie,Le=(ze=Fe+Ae*Xe)-re,Be=(Ge=Ve+Pe*Xe)-ne,Ee=Ue-Ne,Ae=ze-Fe,Pe=Ge-Ve,Me=(We=ke+Me*Xe)-ke);if(je=(Q=De*Ze+Le*qe+Be*Je)-et,(He=(K=Oe*Ze+Ie*qe+we*Je)-et)>0){if(je>0)return;K=(Oe=(Ne+=Ee*(Xe=He/(He-je)))-ie)*Ze+(Ie=(Fe+=Ae*Xe)-re)*qe+(we=(Ve+=Pe*Xe)-ne)*Je,Ee=Ue-Ne,Ae=ze-Fe,Pe=Ge-Ve,Me=We-(ke+=Me*Xe)}else je>0&&(Q=(De=(Ue=Ne+Ee*(Xe=He/(He-je)))-ie)*Ze+(Le=(ze=Fe+Ae*Xe)-re)*qe+(Be=(Ge=Ve+Pe*Xe)-ne)*Je,Ee=Ue-Ne,Ae=ze-Fe,Pe=Ge-Ve,Me=(We=ke+Me*Xe)-ke);if(je=Q+et,(He=K+et)<0){if(je<0)return;Ne+=Ee*(Xe=He/(He-je)),Fe+=Ae*Xe,Ve+=Pe*Xe,ke+=Me*Xe}else je<0&&(Ue=Ne+Ee*(Xe=He/(He-je)),ze=Fe+Ae*Xe,Ge=Ve+Pe*Xe,We=ke+Me*Xe);ke<0&&i.addPoint(Ne,Fe,Ve,j,X,Y,ke,this.flip),We<0&&i.addPoint(Ue,ze,Ge,j,X,Y,We,this.flip)}}}},o.CylinderCylinderCollisionDetector=function(){o.CollisionDetector.call(this)},o.CylinderCylinderCollisionDetector.prototype=Object.create(o.CollisionDetector.prototype),o.CylinderCylinderCollisionDetector.prototype.constructor=o.CylinderCylinderCollisionDetector,o.CylinderCylinderCollisionDetector.prototype.getSep=function(e,t,i,r,n){var s,a,h,l,c,u,p,f,d,m,g,_,v,y=new o.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,O=-S,I=-C;this.supportPoint(e,-R,-O,-I,y);var w=y.x,D=y.y,L=y.z;this.supportPoint(t,R,O,I,y);var B=y.x,N=y.y,F=y.z,V=B-w,k=N-D,U=F-L;if(V*R+k*O+U*I<=0)return!1;if((R=k*C-U*S)*R+(O=U*M-V*C)*O+(I=V*S-k*M)*I==0)return i.init(V-M,k-S,U-C),i.normalize(i),r.init(.5*(w+B),.5*(D+N),.5*(L+F)),!0;this.supportPoint(e,-R,-O,-I,y);var z=y.x,G=y.y,W=y.z;this.supportPoint(t,R,O,I,y);var H=y.x,j=y.y,X=y.z,Y=H-z,K=j-G,Q=X-W;if(Y*R+K*O+Q*I<=0)return!1;(R=(a=k-S)*(u=Q-C)-(h=U-C)*(c=K-S))*M+(O=h*(l=Y-M)-(s=V-M)*u)*S+(I=s*c-a*l)*C>0&&(s=V,a=k,h=U,V=Y,k=K,U=Q,Y=s,K=a,Q=h,s=w,a=D,h=L,w=z,D=G,L=W,z=s,G=a,W=h,s=B,a=N,h=F,B=H,N=j,F=X,H=s,j=a,X=h,R=-R,O=-O,I=-I);for(var Z=0;;){if(++Z>100)return!1;this.supportPoint(e,-R,-O,-I,y);var q=y.x,J=y.y,$=y.z;this.supportPoint(t,R,O,I,y);var ee=y.x,te=y.y,ie=y.z,re=ee-q,ne=te-J,oe=ie-$;if(re*R+ne*O+oe*I<=0)return!1;if((k*oe-U*ne)*M+(U*re-V*oe)*S+(V*ne-k*re)*C<0)Y=re,K=ne,Q=oe,z=q,G=J,W=$,H=ee,j=te,X=ie,R=(a=k-S)*(u=oe-C)-(h=U-C)*(c=ne-S),O=h*(l=re-M)-(s=V-M)*u,I=s*c-a*l;else if((ne*Q-oe*K)*M+(oe*Y-re*Q)*S+(re*K-ne*Y)*C<0)V=re,k=ne,U=oe,w=q,D=J,L=$,B=ee,N=te,F=ie,R=(a=ne-S)*(u=Q-C)-(h=oe-C)*(c=K-S),O=h*(l=Y-M)-(s=re-M)*u,I=s*c-a*l;else for(var se=!1;;){if(R=(a=K-k)*(u=oe-U)-(h=Q-U)*(c=ne-k),O=h*(l=re-V)-(s=Y-V)*u,I=s*c-a*l,(R*=p=1/o.sqrt(R*R+O*O+I*I))*V+(O*=p)*k+(I*=p)*U>=0&&!se){var ae=(k*Q-U*K)*re+(U*Y-V*Q)*ne+(V*K-k*Y)*oe,he=(ne*Q-oe*K)*M+(oe*Y-re*Q)*S+(re*K-ne*Y)*C,le=(S*U-C*k)*re+(C*V-M*U)*ne+(M*k-S*V)*oe,ce=(K*U-Q*k)*M+(Q*V-Y*U)*S+(Y*k-K*V)*C,ue=ae+he+le+ce;ue<=0&&(ae=0,ue=(he=(K*oe-Q*ne)*R+(Q*re-Y*oe)*O+(Y*ne-K*re)*I)+(le=(ne*Q-oe*K)*R+(oe*Y-re*Q)*O+(re*K-ne*Y)*I)+(ce=(k*Q-U*K)*R+(U*Y-V*Q)*O+(V*K-k*Y)*I));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+B*he+H*le+ee*ce)*pe,_=(A*ae+N*he+j*le+te*ce)*pe,v=(P*ae+F*he+X*le+ie*ce)*pe,se=!0}this.supportPoint(e,-R,-O,-I,y);var fe=y.x,de=y.y,me=y.z;this.supportPoint(t,R,O,I,y);var ge=y.x,_e=y.y,ve=y.z,ye=ge-fe,be=_e-de,xe=ve-me,Te=-(ye*R+be*O+xe*I);if((ye-re)*R+(be-ne)*O+(xe-oe)*I<=.01||Te>=0)return!!se&&(i.init(-R,-O,-I),r.init(.5*(f+g),.5*(d+_),.5*(m+v)),n.x=Te,!0);(be*U-xe*k)*M+(xe*V-ye*U)*S+(ye*k-be*V)*C<0?(be*Q-xe*K)*M+(xe*Y-ye*Q)*S+(ye*K-be*Y)*C<0?(V=ye,k=be,U=xe,w=fe,D=de,L=me,B=ge,N=_e,F=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,k=be,U=xe,w=fe,D=de,L=me,B=ge,N=_e,F=ve)}}},o.CylinderCylinderCollisionDetector.prototype.supportPoint=function(e,t,i,r,n){var s,a,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?(s=g,a=-_,h=0):(s=g,a=_,h=0):(m=e.radius/o.sqrt(m),u<0?(s=f*m,a=-_,h=d*m):(s=f*m,a=_,h=d*m)),c=l[0]*s+l[1]*a+l[2]*h+e.position.x,u=l[3]*s+l[4]*a+l[5]*h+e.position.y,p=l[6]*s+l[7]*a+l[8]*h+e.position.z,n.init(c,u,p)},o.CylinderCylinderCollisionDetector.prototype.detectCollision=function(e,t,i){var r,n;e.id<t.id?(r=e,n=t):(r=t,n=e);var s,a,h,l,c,u,p,f,d,m,g,_,v,y,b,x,T,E,A,P,M,S=r.position,C=n.position,R=S.x,O=S.y,I=S.z,w=C.x,D=C.y,L=C.z,B=r.halfHeight,N=n.halfHeight,F=r.normalDirection,V=n.normalDirection,k=r.halfDirection,U=n.halfDirection,z=r.radius,G=n.radius,W=F.x,H=F.y,j=F.z,X=V.x,Y=V.y,K=V.z,Q=k.x,Z=k.y,q=k.z,J=U.x,$=U.y,ee=U.z,te=R-w,ie=O-D,re=I-L,ne=new o.Vec3,oe=new o.Vec3,se=new o.Vec3;if(this.getSep(r,n,ne,oe,se)){var ae=ne.x*W+ne.y*H+ne.z*j,he=ne.x*X+ne.y*Y+ne.z*K,le=ae>0,ce=he>0;le||(ae=-ae),ce||(he=-he);var ue,pe,fe,de=0;(ae>.999||he>.999)&&(de=ae>he?1:2);var me,ge,_e,ve,ye,be,xe,Te,Ee,Ae,Pe,Me,Se,Ce,Re,Oe,Ie=se.x;switch(ue=ne.x,pe=ne.y,fe=ne.z,de){case 0:i.addPoint(oe.x,oe.y,oe.z,ue,pe,fe,Ie,!1);break;case 1:if(le?(a=R+Q,h=O+Z,l=I+q,ue=W,pe=H,fe=j):(a=R-Q,h=O-Z,l=I-q,ue=-W,pe=-H,fe=-j),c=w+(s=(A=ue*X+pe*Y+fe*K)<0?N:-N)*X,u=D+s*Y,p=L+s*K,he>=.999999?(f=-pe,d=fe,m=ue):(f=ue,d=pe,m=fe),te=(s=f*X+d*Y+m*K)*X-f,ie=s*Y-d,re=s*K-m,0==(s=o.sqrt(te*te+ie*ie+re*re)))break;if(f=c+(te*=s=G/s),d=u+(ie*=s),m=p+(re*=s),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,(s=(f=(Ae=f)-(Se=ue*(Ae-a)+pe*((Pe=d)-h)+fe*((Me=m)-l))*ue-a)*f+(d=Pe-Se*pe-h)*d+(m=Me-Se*fe-l)*m)>z*z&&(f*=s=z/o.sqrt(s),d*=s,m*=s),Ae=a+f,Pe=h+d,Me=l+m,i.addPoint(Ae,Pe,Me,ue,pe,fe,Se,!1),Pe=te*ve+ie*ye+re*be,Me=te*xe+ie*Te+re*Ee,(Se=ue*((Ae=(te=Ae=te*me+ie*ge+re*_e)+c)-a)+pe*((Pe=(ie=Pe)+u)-h)+fe*((Me=(re=Me)+p)-l))<=0&&((s=(f=Ae-Se*ue-a)*f+(d=Pe-Se*pe-h)*d+(m=Me-Se*fe-l)*m)>z*z&&(f*=s=z/o.sqrt(s),d*=s,m*=s),Ae=a+f,Pe=h+d,Me=l+m,i.addPoint(Ae,Pe,Me,ue,pe,fe,Se,!1)),Pe=te*ve+ie*ye+re*be,Me=te*xe+ie*Te+re*Ee,(Se=ue*((Ae=(te=Ae=te*me+ie*ge+re*_e)+c)-a)+pe*((Pe=(ie=Pe)+u)-h)+fe*((Me=(re=Me)+p)-l))<=0&&((s=(f=Ae-Se*ue-a)*f+(d=Pe-Se*pe-h)*d+(m=Me-Se*fe-l)*m)>z*z&&(f*=s=z/o.sqrt(s),d*=s,m*=s),Ae=a+f,Pe=h+d,Me=l+m,i.addPoint(Ae,Pe,Me,ue,pe,fe,Se,!1));else{if(g=f,g-=(T=ue*(g-a)+pe*((_=d)-h)+fe*((v=m)-l))*ue,_-=T*pe,v-=T*fe,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),(Oe=(Ce=(te=a-g)*(f=(y-=(E=ue*(y-a)+pe*(b-h)+fe*(x-l))*ue)-g)+(ie=h-_)*(d=(b-=E*pe)-_)+(re=l-v)*(m=(x-=E*fe)-v))*Ce-(Re=f*f+d*d+m*m)*(te*te+ie*ie+re*re-z*z))<0)break;(M=(Ce-(Oe=o.sqrt(Oe)))/Re)<(P=(Ce+Oe)/Re)&&(s=P,P=M,M=s),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,s=T+(E-T)*P,E=T+(E-T)*M,(T=s)<0&&i.addPoint(g,_,v,ue,pe,fe,Se,!1),E<0&&i.addPoint(y,b,x,ue,pe,fe,Se,!1)}break;case 2:if(ce?(c=w-J,u=D-$,p=L-ee,ue=-X,pe=-Y,fe=-K):(c=w+J,u=D+$,p=L+ee,ue=X,pe=Y,fe=K),a=R+(s=(A=ue*W+pe*H+fe*j)<0?B:-B)*W,h=O+s*H,l=I+s*j,ae>=.999999?(f=-pe,d=fe,m=ue):(f=ue,d=pe,m=fe),te=(s=f*W+d*H+m*j)*W-f,ie=s*H-d,re=s*j-m,0==(s=o.sqrt(te*te+ie*ie+re*re)))break;if(f=a+(te*=s=z/s),d=h+(ie*=s),m=l+(re*=s),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,(s=(f=(Ae=f)-(Se=ue*(Ae-c)+pe*((Pe=d)-u)+fe*((Me=m)-p))*ue-c)*f+(d=Pe-Se*pe-u)*d+(m=Me-Se*fe-p)*m)>G*G&&(f*=s=G/o.sqrt(s),d*=s,m*=s),Ae=c+f,Pe=u+d,Me=p+m,i.addPoint(Ae,Pe,Me,-ue,-pe,-fe,Se,!1),Pe=te*ve+ie*ye+re*be,Me=te*xe+ie*Te+re*Ee,(Se=ue*((Ae=(te=Ae=te*me+ie*ge+re*_e)+a)-c)+pe*((Pe=(ie=Pe)+h)-u)+fe*((Me=(re=Me)+l)-p))<=0&&((s=(f=Ae-Se*ue-c)*f+(d=Pe-Se*pe-u)*d+(m=Me-Se*fe-p)*m)>G*G&&(f*=s=G/o.sqrt(s),d*=s,m*=s),Ae=c+f,Pe=u+d,Me=p+m,i.addPoint(Ae,Pe,Me,-ue,-pe,-fe,Se,!1)),Pe=te*ve+ie*ye+re*be,Me=te*xe+ie*Te+re*Ee,(Se=ue*((Ae=(te=Ae=te*me+ie*ge+re*_e)+a)-c)+pe*((Pe=(ie=Pe)+h)-u)+fe*((Me=(re=Me)+l)-p))<=0&&((s=(f=Ae-Se*ue-c)*f+(d=Pe-Se*pe-u)*d+(m=Me-Se*fe-p)*m)>G*G&&(f*=s=G/o.sqrt(s),d*=s,m*=s),Ae=c+f,Pe=u+d,Me=p+m,i.addPoint(Ae,Pe,Me,-ue,-pe,-fe,Se,!1));else{if(g=f,g-=(T=ue*(g-c)+pe*((_=d)-u)+fe*((v=m)-p))*ue,_-=T*pe,v-=T*fe,A>0?(y=f+W*B*2,b=d+H*B*2,x=m+j*B*2):(y=f-W*B*2,b=d-H*B*2,x=m-j*B*2),(Oe=(Ce=(te=c-g)*(f=(y-=(E=ue*(y-c)+pe*(b-u)+fe*(x-p))*ue)-g)+(ie=u-_)*(d=(b-=E*pe)-_)+(re=p-v)*(m=(x-=E*fe)-v))*Ce-(Re=f*f+d*d+m*m)*(te*te+ie*ie+re*re-G*G))<0)break;(M=(Ce-(Oe=o.sqrt(Oe)))/Re)<(P=(Ce+Oe)/Re)&&(s=P,P=M,M=s),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,s=T+(E-T)*P,E=T+(E-T)*M,(T=s)<0&&i.addPoint(g,_,v,-ue,-pe,-fe,T,!1),E<0&&i.addPoint(y,b,x,-ue,-pe,-fe,E,!1)}}}},o.SphereCylinderCollisionDetector=function(e){o.CollisionDetector.call(this),this.flip=e},o.SphereCylinderCollisionDetector.prototype=Object.create(o.CollisionDetector.prototype),o.SphereCylinderCollisionDetector.prototype.constructor=o.SphereCylinderCollisionDetector,o.SphereCylinderCollisionDetector.prototype.detectCollision=function(e,t,i){var r,n;this.flip?(r=t,n=e):(r=e,n=t);var s=r.position,a=s.x,h=s.y,l=s.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=a-u,T=h-p,E=l-f,A=x*d+T*m+E*g;if(!(A<-b-_||A>b+_)){var P,M=u+A*d,S=p+A*m,C=f+A*g,R=a-M,O=h-S,I=l-C,w=R*R+O*O+I*I;if(!(w>y*y))w>v*v&&(R*=w=v/o.sqrt(w),O*=w,I*=w),A<-b?A=-b:A>b&&(A=b),(w=(x=(M=u+A*d+R)-a)*x+(T=(S=p+A*m+O)-h)*T+(E=(C=f+A*g+I)-l)*E)>0&&w<_*_&&(x*=P=1/(w=o.sqrt(w)),T*=P,E*=P,i.addPoint(a+x*_,h+T*_,l+E*_,x,T,E,w-_,this.flip))}},o.TetraTetraCollisionDetector=function(){o.CollisionDetector.call(this)},o.TetraTetraCollisionDetector.prototype=Object.create(o.CollisionDetector.prototype),o.TetraTetraCollisionDetector.prototype.constructor=o.TetraTetraCollisionDetector,o.TetraTetraCollisionDetector.prototype.detectCollision=function(e,t,i){var r,n,o,s,l,c,u=e.faces,p=e.verts,f=(t.faces,t.verts),d=0,m=u;for(r=0;r<4;r++)for(o=p[r],n=0;n<4;n++)s=f[m[r].a],l=f[m[r].b],c=f[m[r].c],a(h(o.x,o.y),h(s.x,s.y),h(l.x,l.y),h(c.x,c.y))&&a(h(o.x,o.z),h(s.x,s.z),h(l.x,l.z),h(c.x,c.z))&&a(h(o.z,o.y),h(s.z,s.y),h(l.z,l.y),h(c.z,c.y))&&d++,4===d&&i.addPoint(o)},o.AABB=function(e,t,i,n,o,s){this.elements=new r(6);var a=this.elements;a[0]=e||0,a[1]=i||0,a[2]=o||0,a[3]=t||0,a[4]=n||0,a[5]=s||0},o.AABB.prototype={constructor:o.AABB,set:function(e,t,i,r,n,o){var s=this.elements;return s[0]=e,s[3]=t,s[1]=i,s[4]=r,s[2]=n,s[5]=o,this},intersectTest:function(e){var t=this.elements,i=e.elements;return t[0]>i[3]||t[1]>i[4]||t[2]>i[5]||t[3]<i[0]||t[4]<i[1]||t[5]<i[2]},intersectTestTwo:function(e){var t=this.elements,i=e.elements;return t[0]<i[0]||t[1]<i[1]||t[2]<i[2]||t[3]>i[3]||t[4]>i[4]||t[5]>i[5]},clone:function(){return(new this.constructor).fromArray(this.elements)},copy:function(e,t){var i=t||0,r=e.elements;return this.set(r[0]-i,r[3]+i,r[1]-i,r[4]+i,r[2]-i,r[5]+i),this},fromArray:function(e){return this.elements.set(e),this},combine:function(e,t){var i=e.elements,r=t.elements,n=this.elements;return n[0]=i[0]<r[0]?i[0]:r[0],n[1]=i[1]<r[1]?i[1]:r[1],n[2]=i[2]<r[2]?i[2]:r[2],n[3]=i[3]>r[3]?i[3]:r[3],n[4]=i[4]>r[4]?i[4]:r[4],n[5]=i[5]>r[5]?i[5]:r[5],this},surfaceArea:function(){var e=this.elements,t=e[3]-e[0],i=e[4]-e[1],r=e[5]-e[2];return 2*(t*(i+r)+i*r)},intersectsWithPoint:function(e,t,i){var r=this.elements;return e>=r[0]&&e<=r[3]&&t>=r[1]&&t<=r[4]&&i>=r[2]&&i<=r[5]},setFromPoints:function(e){this.makeEmpty();for(var t=0;t<e.length;t++)this.expandByPoint(e[t])},makeEmpty:function(){this.set(-1/0,-1/0,-1/0,1/0,1/0,1/0)},expandByPoint:function(e){var t=this.elements;this.set(o.min(t[0],e.x),o.min(t[1],e.y),o.min(t[2],e.z),o.max(t[3],e.x),o.max(t[4],e.y),o.max(t[5],e.z))}},o.Proxy=function(e){this.shape=e,this.aabb=e.aabb},o.Proxy.prototype={constructor:o.Proxy,update:function(){o.Error("Proxy","Inheritance error.")}},o.BasicProxy=function(e){o.Proxy.call(this,e),this.id=o.proxyID++},o.BasicProxy.prototype=Object.create(o.Proxy.prototype),o.BasicProxy.prototype.constructor=o.BasicProxy,o.BasicProxy.prototype.update=function(){},o.BroadPhase=function(){this.types=o.BR_NULL,this.numPairChecks=0,this.numPairs=0,this.pairs=[]},o.BroadPhase.prototype={constructor:o.BroadPhase,createProxy:function(e){o.Error("BroadPhase","Inheritance error.")},addProxy:function(e){o.Error("BroadPhase","Inheritance error.")},removeProxy:function(e){o.Error("BroadPhase","Inheritance error.")},isAvailablePair:function(e,t){var i,r=e.parent,n=t.parent;if(r==n||!r.isDynamic&&!n.isDynamic||0==(e.belongsTo&t.collidesWith)||0==(t.belongsTo&e.collidesWith))return!1;for(i=r.numJoints<n.numJoints?r.jointLink:n.jointLink;null!==i;){var o=i.joint;if(!o.allowCollision&&(o.body1==r&&o.body2==n||o.body1==n&&o.body2==r))return!1;i=i.next}return!0},detectPairs:function(){this.pairs=[],this.numPairs=0,this.numPairChecks=0,this.collectPairs()},collectPairs:function(){o.Error("BroadPhase","Inheritance error.")},addPair:function(e,t){var i=new o.Pair(e,t);this.pairs.push(i),this.numPairs++}},o.BruteForceBroadPhase=function(){o.BroadPhase.call(this),this.types=o.BR_BRUTE_FORCE,this.proxies=[]},o.BruteForceBroadPhase.prototype=Object.create(o.BroadPhase.prototype),o.BruteForceBroadPhase.prototype.constructor=o.BruteForceBroadPhase,o.BruteForceBroadPhase.prototype.createProxy=function(e){return new o.BasicProxy(e)},o.BruteForceBroadPhase.prototype.addProxy=function(e){this.proxies.push(e)},o.BruteForceBroadPhase.prototype.removeProxy=function(e){var t=this.proxies.indexOf(e);t>-1&&this.proxies.splice(t,1)},o.BruteForceBroadPhase.prototype.collectPairs=function(){var e,t,i,r=0,n=this.proxies,o=n.length;for(this.numPairChecks=o*(o-1)>>1;r<o;)for(t=n[r++],e=r+1;e<o;)i=n[e++],!t.aabb.intersectTest(i.aabb)&&this.isAvailablePair(t.shape,i.shape)&&this.addPair(t.shape,i.shape)},o.Pair=function(e,t){this.shape1=e||null,this.shape2=t||null},o.SAPAxis=function(){this.numElements=0,this.bufferSize=256,this.elements=[],this.elements.length=this.bufferSize,this.stack=new r(64)},o.SAPAxis.prototype={constructor:o.SAPAxis,addElements:function(e,t){if(this.numElements+2>=this.bufferSize){this.bufferSize*=2;for(var i=[],r=this.numElements;r--;)i[r]=this.elements[r]}this.elements[this.numElements++]=e,this.elements[this.numElements++]=t},removeElements:function(e,t){for(var i=-1,r=-1,n=0,o=this.numElements;n<o;n++){var s=this.elements[n];if(s==e||s==t){if(-1!=i){r=n;break}i=n}}for(n=i+1,o=r;n<o;n++)this.elements[n-1]=this.elements[n];for(n=r+1,o=this.numElements;n<o;n++)this.elements[n-2]=this.elements[n];this.elements[--this.numElements]=null,this.elements[--this.numElements]=null},sort:function(){for(var e=0,t=1;this.numElements>>t!=0;)t++;t=t*this.numElements>>2,e=0;for(var i=!1,r=this.elements,n=1,s=this.numElements;n<s;n++){var a=r[n],h=a.value,l=r[n-1];if(l.value>h){var c=n;do{if(r[c]=l,0==--c)break;l=r[c-1]}while(l.value>h);if(r[c]=a,(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+o.floor(.5*d);for(a=r[m],r[m]=r[p],r[p]=a,h=a.value,n=f-1,c=p;;){var g,_;do{g=r[++n]}while(g.value<h);do{_=r[--c]}while(h<_.value&&c!=f);if(n>=c)break;r[n]=_,r[c]=g}r[p]=r[n],r[n]=a,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(h=(a=r[n]).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]=a}}}},calculateTestCount:function(){for(var e=1,t=0,i=1,r=this.numElements;i<r;i++)this.elements[i].max?e--:(t+=e,e++);return t}},o.SAPBroadPhase=function(){o.BroadPhase.call(this),this.types=o.BR_SWEEP_AND_PRUNE,this.numElementsD=0,this.numElementsS=0,this.axesD=[new o.SAPAxis,new o.SAPAxis,new o.SAPAxis],this.axesS=[new o.SAPAxis,new o.SAPAxis,new o.SAPAxis],this.index1=0,this.index2=1},o.SAPBroadPhase.prototype=Object.create(o.BroadPhase.prototype),o.SAPBroadPhase.prototype.constructor=o.SAPBroadPhase,o.SAPBroadPhase.prototype.createProxy=function(e){return new o.SAPProxy(this,e)},o.SAPBroadPhase.prototype.addProxy=function(e){var t=e;t.isDynamic()?(this.axesD[0].addElements(t.min[0],t.max[0]),this.axesD[1].addElements(t.min[1],t.max[1]),this.axesD[2].addElements(t.min[2],t.max[2]),t.belongsTo=1,this.numElementsD+=2):(this.axesS[0].addElements(t.min[0],t.max[0]),this.axesS[1].addElements(t.min[1],t.max[1]),this.axesS[2].addElements(t.min[2],t.max[2]),t.belongsTo=2,this.numElementsS+=2)},o.SAPBroadPhase.prototype.removeProxy=function(e){var t=e;if(0!=t.belongsTo){switch(t.belongsTo){case 1:this.axesD[0].removeElements(t.min[0],t.max[0]),this.axesD[1].removeElements(t.min[1],t.max[1]),this.axesD[2].removeElements(t.min[2],t.max[2]),this.numElementsD-=2;break;case 2:this.axesS[0].removeElements(t.min[0],t.max[0]),this.axesS[1].removeElements(t.min[1],t.max[1]),this.axesS[2].removeElements(t.min[2],t.max[2]),this.numElementsS-=2}t.belongsTo=0}},o.SAPBroadPhase.prototype.collectPairs=function(){if(0!=this.numElementsD){var e,t,i,r,n=this.axesD[this.index1],o=this.axesD[this.index2];n.sort(),o.sort(),n.calculateTestCount()<=o.calculateTestCount()?((o=this.axesS[this.index1]).sort(),e=n.elements,t=o.elements):((n=this.axesS[this.index2]).sort(),e=o.elements,t=n.elements,this.index1^=this.index2,this.index2^=this.index1,this.index1^=this.index2);for(var s=0,a=0;s<this.numElementsD;){var h,l;if(a==this.numElementsS)h=e[s],l=!0,s++;else{var c=e[s],u=t[a];c.value<u.value?(h=c,l=!0,s++):(h=u,l=!1,a++)}if(h.max){var p=h.pair;if(l){if(p==i){i=i.pair;continue}h=i}else{if(p==r){r=r.pair;continue}h=r}do{if((v=h.pair)==p){h.pair=v.pair;break}h=v}while(null!=h)}else{for(var f=h.proxy.shape,d=h.min1.value,m=h.max1.value,g=h.min2.value,_=h.max2.value,v=i;null!=v;v=v.pair){var y=v.proxy.shape;this.numPairChecks++,d>v.max1.value||m<v.min1.value||g>v.max2.value||_<v.min2.value||!this.isAvailablePair(f,y)||this.addPair(f,y)}if(l){for(v=r;null!=v;v=v.pair)y=v.proxy.shape,this.numPairChecks++,d>v.max1.value||m<v.min1.value||g>v.max2.value||_<v.min2.value||!this.isAvailablePair(f,y)||this.addPair(f,y);h.pair=i,i=h}else h.pair=r,r=h}}this.index2=3^(this.index1|this.index2)}},o.SAPElement=function(e,t){this.proxy=e,this.pair=null,this.min1=null,this.max1=null,this.min2=null,this.max2=null,this.max=t,this.value=0},o.SAPProxy=function(e,t){o.Proxy.call(this,t),this.belongsTo=0,this.max=[],this.min=[],this.sap=e,this.min[0]=new o.SAPElement(this,!1),this.max[0]=new o.SAPElement(this,!0),this.min[1]=new o.SAPElement(this,!1),this.max[1]=new o.SAPElement(this,!0),this.min[2]=new o.SAPElement(this,!1),this.max[2]=new o.SAPElement(this,!0),this.max[0].pair=this.min[0],this.max[1].pair=this.min[1],this.max[2].pair=this.min[2],this.min[0].min1=this.min[1],this.min[0].max1=this.max[1],this.min[0].min2=this.min[2],this.min[0].max2=this.max[2],this.min[1].min1=this.min[0],this.min[1].max1=this.max[0],this.min[1].min2=this.min[2],this.min[1].max2=this.max[2],this.min[2].min1=this.min[0],this.min[2].max1=this.max[0],this.min[2].min2=this.min[1],this.min[2].max2=this.max[1]},o.SAPProxy.prototype=Object.create(o.Proxy.prototype),o.SAPProxy.prototype.constructor=o.SAPProxy,o.SAPProxy.prototype.isDynamic=function(){var e=this.shape.parent;return e.isDynamic&&!e.sleeping},o.SAPProxy.prototype.update=function(){var e=this.aabb.elements;this.min[0].value=e[0],this.min[1].value=e[1],this.min[2].value=e[2],this.max[0].value=e[3],this.max[1].value=e[4],this.max[2].value=e[5],(1==this.belongsTo&&!this.isDynamic()||2==this.belongsTo&&this.isDynamic())&&(this.sap.removeProxy(this),this.sap.addProxy(this))},o.DBVT=function(){this.root=null,this.freeNodes=[],this.freeNodes.length=16384,this.numFreeNodes=0,this.aabb=new o.AABB},o.DBVT.prototype={constructor:o.DBVT,moveLeaf:function(e){this.deleteLeaf(e),this.insertLeaf(e)},insertLeaf:function(e){if(null!=this.root){for(var t,i,r=e.aabb,n=this.root;null==n.proxy;){var s=n.child1,a=n.child2,h=n.aabb,l=s.aabb,c=a.aabb;t=h.surfaceArea(),this.aabb.combine(r,h);var u=2*(i=this.aabb.surfaceArea()),p=2*(i-t),f=p;this.aabb.combine(r,l),null!=s.proxy?f+=this.aabb.surfaceArea():f+=this.aabb.surfaceArea()-l.surfaceArea();var d=p;if(this.aabb.combine(r,c),null!=a.proxy?d+=this.aabb.surfaceArea():d+=this.aabb.surfaceArea()-c.surfaceArea(),f<d){if(u<f)break;n=s}else{if(u<d)break;n=a}}var m,g=n.parent;(m=this.numFreeNodes>0?this.freeNodes[--this.numFreeNodes]:new o.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<i.height?i.height+1:t.height+1}},o.DBVTBroadPhase=function(){o.BroadPhase.call(this),this.types=o.BR_BOUNDING_VOLUME_TREE,this.tree=new o.DBVT,this.stack=[],this.leaves=[],this.numLeaves=0},o.DBVTBroadPhase.prototype=Object.create(o.BroadPhase.prototype),o.DBVTBroadPhase.prototype.constructor=o.DBVTBroadPhase,o.DBVTBroadPhase.prototype.createProxy=function(e){return new o.DBVTProxy(e)},o.DBVTBroadPhase.prototype.addProxy=function(e){this.tree.insertLeaf(e.leaf),this.leaves.push(e.leaf),this.numLeaves++},o.DBVTBroadPhase.prototype.removeProxy=function(e){this.tree.deleteLeaf(e.leaf);var t=this.leaves.indexOf(e.leaf);t>-1&&(this.leaves.splice(t,1),this.numLeaves--)},o.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))},o.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.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)}},o.DBVTNode=function(){this.child1=null,this.child2=null,this.parent=null,this.proxy=null,this.height=0,this.aabb=new o.AABB},o.DBVTProxy=function(e){o.Proxy.call(this,e),this.leaf=new o.DBVTNode,this.leaf.proxy=this},o.DBVTProxy.prototype=Object.create(o.Proxy.prototype),o.DBVTProxy.prototype.constructor=o.DBVTProxy,o.DBVTProxy.prototype.update=function(){},o.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,r,n=e.axe1||[1,0,0],s=e.axe2||[1,0,0],a=e.pos1||[0,0,0],h=e.pos2||[0,0,0];a=a.map(function(e){return e*o.INV_SCALE}),h=h.map(function(e){return e*o.INV_SCALE}),"jointDistance"===t[0]?(i=e.min||0,r=e.max||10,i*=o.INV_SCALE,r*=o.INV_SCALE):(i=e.min||57.29578,r=e.max||0,i*=o.degtorad,r*=o.degtorad);var l,c=e.limit||null,u=e.spring||null,p=e.motor||null,f=new o.JointConfig;switch(f.allowCollision=e.collision||!1,f.localAxis1.init(n[0],n[1],n[2]),f.localAxis2.init(s[0],s[1],s[2]),f.localAnchorPoint1.init(a[0],a[1],a[2]),f.localAnchorPoint2.init(h[0],h[1],h[2]),("string"==typeof e.body1||e.body1 instanceof String)&&(e.body1=this.getByName(e.body1)),("string"==typeof e.body2||e.body2 instanceof String)&&(e.body2=this.getByName(e.body2)),f.body1=e.body1,f.body2=e.body2,t[0]){case"jointDistance":l=new o.DistanceJoint(f,i,r),null!==u&&l.limitMotor.setSpring(u[0],u[1]),null!==p&&l.limitMotor.setSpring(p[0],p[1]);break;case"jointHinge":l=new o.HingeJoint(f,i,r),null!==u&&l.limitMotor.setSpring(u[0],u[1]),null!==p&&l.limitMotor.setSpring(p[0],p[1]);break;case"jointPrisme":l=new o.PrismaticJoint(f,i,r);break;case"jointSlide":l=new o.SliderJoint(f,i,r);break;case"jointBall":l=new o.BallAndSocketJoint(f);break;case"jointWheel":l=new o.WheelJoint(f),null!==c&&l.rotationalLimitMotor1.setLimit(c[0],c[1]),null!==u&&l.rotationalLimitMotor1.setSpring(u[0],u[1]),null!==p&&l.rotationalLimitMotor1.setSpring(p[0],p[1])}return l.name=e.name||"",this.addJoint(l),l}var d=e.move||!1,m=e.noSleep||!1,g=e.pos||[0,0,0];g=g.map(function(e){return e*o.INV_SCALE});var _=e.size||[1,1,1];_=_.map(function(e){return e*o.INV_SCALE});var v=e.rot||[0,0,0];v=v.map(function(e){return e*o.degtorad});for(var y=[],b=0;b<v.length/3;b++){var x=o.EulerToAxis(v[b+0],v[b+1],v[b+2]);y.push(x[0]),y.push(x[1]),y.push(x[2]),y.push(x[3])}var T=new o.ShapeConfig;void 0!==e.sc&&(T=e.sc),e.config&&(T.density=void 0===e.config[0]?1:e.config[0],T.friction=void 0===e.config[1]?.4:e.config[1],T.restitution=void 0===e.config[2]?.2:e.config[2],T.belongsTo=e.config[3]||1,T.collidesWith=e.config[4]||4294967295),void 0!==e.density&&(T.density=e.density),void 0!==e.friction&&(T.friction=e.friction),void 0!==e.restitution&&(T.restitution=e.restitution),void 0!==e.belongsTo&&(T.belongsTo=e.belongsTo),void 0!==e.collidesWith&&(T.collidesWith=e.collidesWith),e.massPos&&(e.massPos=e.massPos.map(function(e){return e*o.INV_SCALE}),T.relativePosition.init(e.massPos[0],e.massPos[1],e.massPos[2])),e.massRot&&(e.massRot=e.massRot.map(function(e){return e*o.degtorad}),T.relativeRotation=o.EulerToMatrix(e.massRot[0],e.massRot[1],e.massRot[2]));var E,A,P=new o.RigidBody(g[0],g[1],g[2],y[0],y[1],y[2],y[3]),M=[];for(b=0;b<t.length;b++){switch(E=3*b,A=4*b,t[b]){case"sphere":M[b]=new o.SphereShape(T,_[E]);break;case"cylinder":M[b]=new o.CylinderShape(T,_[E],_[E+1]);break;case"box":M[b]=new o.BoxShape(T,_[E],_[E+1],_[E+2])}P.addShape(M[b]),b>0&&(M[b].relativePosition=new o.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};this.OIMO||(e.exports=o)},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=i(0),n=i(3),o=function(){function e(e){this.containerElement=e,this.templates={},this.onInit=new r.Observable,this.onLoaded=new r.Observable,this.onStateChange=new r.Observable,this.onAllLoaded=new r.Observable,this.onEventTriggered=new r.Observable,this.eventManager=new a.EventManager(this)}return e.prototype.initTemplate=function(e){var t=this,i=function(e,r,o){var s=t.templates[r],a=(Object.keys(e).map(function(t){return i(e[t],t,s)}),function(){var e=o&&o.parent.querySelector(n.camelToKebab(r))||t.containerElement;s.appendTo(e),t.checkLoadedState()});return o&&!o.parent?o.onAppended.add(function(){a()}):a(),s};this.buildHTMLTree(e).then(function(e){i(e,"main")})},e.prototype.buildHTMLTree=function(e){var t=this,i=Object.keys(e).map(function(i){var r=new h(i,e[i]);return r.onEventTriggered.add(function(e){return t.onEventTriggered.notifyObservers(e)}),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=o;var s=i(18),a=i(19);s.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 h=function(){function e(e,t){var i=this;this.name=e,this._configuration=t,this.onInit=new r.Observable,this.onLoaded=new r.Observable,this.onAppended=new r.Observable,this.onStateChange=new r.Observable,this.onEventTriggered=new r.Observable,this.isLoaded=!1,this.isShown=!1,this.onInit.notifyObservers(this);var n=l(t);this.initPromise=n.then(function(e){if(e){var t=s.compile(e)(i._configuration.params||{});i.fragment=document.createRange().createContextualFragment(t),i.isLoaded=!0,i.isShown=!0,i.onLoaded.notifyObservers(i)}return i})}return Object.defineProperty(e.prototype,"configuration",{get:function(){return this._configuration},enumerable:!0,configurable:!0}),e.prototype.getChildElements=function(){var e=[],t=this.fragment.children;t||(t=this.fragment.querySelectorAll("*"));for(var i=0;i<t.length;++i)e.push(n.kebabToCamel(t.item(i).nodeName.toLowerCase()));return e},e.prototype.appendTo=function(e){var t=this;this.parent?console.error("Already appanded to ",this.parent):(this.parent=e,this._configuration.id&&(this.parent.id=this._configuration.id),this.parent.appendChild(this.fragment),setTimeout(function(){t.registerEvents(),t.onAppended.notifyObservers(t)}))},e.prototype.show=function(e){var t=this;return Promise.resolve().then(function(){return e?e(t):(t.parent.style.display="flex",t)}).then(function(){return t.isShown=!0,t.onStateChange.notifyObservers(t),t})},e.prototype.hide=function(e){var t=this;return Promise.resolve().then(function(){return e?e(t):(t.parent.style.display="hide",t)}).then(function(){return t.isShown=!1,t.onStateChange.notifyObservers(t),t})},e.prototype.dispose=function(){this.onAppended.clear(),this.onEventTriggered.clear(),this.onInit.clear(),this.onLoaded.clear(),this.onStateChange.clear(),this.isLoaded=!1},e.prototype.registerEvents=function(){var e=this;if(this._configuration.events){var t=function(t){if(i._configuration.events&&i._configuration.events[t]){var r=function(t,i){e.onEventTriggered.notifyObservers({event:i,template:e,selector:t})};if("boolean"==typeof i._configuration.events[t])i.parent.addEventListener(t,r.bind(i,"#"+i.parent.id),!1);else if("object"==typeof i._configuration.events[t]){var n=Object.keys(i._configuration.events[t]||{}),o=i._configuration.events[t]||{};n.filter(function(e){return o[e]}).forEach(function(i){i&&0!==i.indexOf("#")&&(i="#"+i);var n=e.parent.querySelector(i);n&&n.addEventListener(t,r.bind(e,i),!1)})}}},i=this;for(var r in this._configuration.events)t(r)}},e}();function l(e){if(e){if(e.html)return Promise.resolve(e.html);var t=c(e);if(n.isUrl(t))return n.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 c(e){return e&&"string"!=typeof e?e.location:e}t.Template=h,t.getTemplateAsHtml=l,t.getTemplateLocation=c},function(e,t,i){var r;r=function(){return function(e){function t(r){if(i[r])return i[r].exports;var n=i[r]={exports:{},id:r,loaded:!1};return e[r].call(n.exports,n,n.exports,t),n.loaded=!0,n.exports}var i={};return t.m=e,t.c=i,t.p="",t(0)}([function(e,t,i){"use strict";function r(){var e=p();return e.compile=function(t,i){return h.compile(t,i,e)},e.precompile=function(t,i){return h.precompile(t,i,e)},e.AST=s.default,e.Compiler=h.Compiler,e.JavaScriptCompiler=l.default,e.Parser=a.parser,e.parse=a.parse,e}var n=i(1).default;t.__esModule=!0;var o=n(i(2)),s=n(i(35)),a=i(36),h=i(41),l=n(i(42)),c=n(i(39)),u=n(i(34)),p=o.default.create,f=r();f.create=r,u.default(f),f.Visitor=c.default,f.default=f,t.default=f,e.exports=t.default},function(e,t){"use strict";t.default=function(e){return e&&e.__esModule?e:{default:e}},t.__esModule=!0},function(e,t,i){"use strict";function r(){var e=new s.HandlebarsEnvironment;return l.extend(e,s),e.SafeString=a.default,e.Exception=h.default,e.Utils=l,e.escapeExpression=l.escapeExpression,e.VM=c,e.template=function(t){return c.template(t,e)},e}var n=i(3).default,o=i(1).default;t.__esModule=!0;var s=n(i(4)),a=o(i(21)),h=o(i(6)),l=n(i(5)),c=n(i(22)),u=o(i(34)),p=r();p.create=r,u.default(p),p.default=p,t.default=p,e.exports=t.default},function(e,t){"use strict";t.default=function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t.default=e,t},t.__esModule=!0},function(e,t,i){"use strict";function r(e,t,i){this.helpers=e||{},this.partials=t||{},this.decorators=i||{},a.registerDefaultHelpers(this),h.registerDefaultDecorators(this)}var n=i(1).default;t.__esModule=!0,t.HandlebarsEnvironment=r;var o=i(5),s=n(i(6)),a=i(10),h=i(18),l=n(i(20));t.VERSION="4.0.11";t.COMPILER_REVISION=7;t.REVISION_CHANGES={1:"<= 1.0.rc.2",2:"== 1.0.0-rc.3",3:"== 1.0.0-rc.4",4:"== 1.x.x",5:"== 2.0.0-alpha.x",6:">= 2.0.0-beta.1",7:">= 4.0.0"};var 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<arguments.length;t++)for(var i in arguments[t])Object.prototype.hasOwnProperty.call(arguments[t],i)&&(e[i]=arguments[t][i]);return e}t.__esModule=!0,t.extend=r,t.indexOf=function(e,t){for(var i=0,r=e.length;i<r;i++)if(e[i]===t)return i;return-1},t.escapeExpression=function(e){if("string"!=typeof e){if(e&&e.toHTML)return e.toHTML();if(null==e)return"";if(!e)return e+"";e=""+e}return s.test(e)?e.replace(o,i):e},t.isEmpty=function(e){return!e&&0!==e||!(!l(e)||0!==e.length)},t.createFrame=function(e){var t=r({},e);return t._parent=e,t},t.blockParams=function(e,t){return e.path=t,e},t.appendContextPath=function(e,t){return(e?e+".":"")+t};var n={"&":"&","<":"<",">":">",'"':""","'":"'","`":"`","=":"="},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&&(e+=" - "+(s=i.start.line)+":"+(a=i.start.column));for(var h=Error.prototype.constructor.call(this,e),l=0;l<o.length;l++)this[o[l]]=h[o[l]];Error.captureStackTrace&&Error.captureStackTrace(this,r);try{i&&(this.lineNumber=s,n?Object.defineProperty(this,"column",{value:a,enumerable:!0}):this.column=a)}catch(e){}}var n=i(7).default;t.__esModule=!0;var o=["description","fileName","lineNumber","message","name","number","stack"];r.prototype=new Error,t.default=r,e.exports=t.default},function(e,t,i){e.exports={default:i(8),__esModule:!0}},function(e,t,i){var r=i(9);e.exports=function(e,t,i){return r.setDesc(e,t,i)}},function(e,t){var i=Object;e.exports={create:i.create,getProto:i.getPrototypeOf,isEnum:{}.propertyIsEnumerable,getDesc:i.getOwnPropertyDescriptor,setDesc:i.defineProperty,setDescs:i.defineProperties,getKeys:i.keys,getNames:i.getOwnPropertyNames,getSymbols:i.getOwnPropertySymbols,each:[].forEach}},function(e,t,i){"use strict";var r=i(1).default;t.__esModule=!0,t.registerDefaultHelpers=function(e){n.default(e),o.default(e),s.default(e),a.default(e),h.default(e),l.default(e),c.default(e)};var n=r(i(11)),o=r(i(12)),s=r(i(13)),a=r(i(14)),h=r(i(15)),l=r(i(16)),c=r(i(17))},function(e,t,i){"use strict";t.__esModule=!0;var r=i(5);t.default=function(e){e.registerHelper("blockHelperMissing",function(t,i){var n=i.inverse,o=i.fn;if(!0===t)return o(this);if(!1===t||null==t)return n(this);if(r.isArray(t))return t.length>0?(i.ids&&(i.ids=[i.name]),e.helpers.each(t,i)):n(this);if(i.data&&i.ids){var s=r.createFrame(i.data);s.contextPath=r.appendContextPath(i.data.contextPath,i.name),i={data:s}}return o(t,i)})},e.exports=t.default},function(e,t,i){"use strict";var r=i(1).default;t.__esModule=!0;var n=i(5),o=r(i(6));t.default=function(e){e.registerHelper("each",function(e,t){function i(t,i,o){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<u;a++)a in e&&i(a,a,a===e.length-1);else{var p=void 0;for(var f in e)e.hasOwnProperty(f)&&(void 0!==p&&i(p,a-1),p=f,a++);void 0!==p&&i(p,a-1,!0)}return 0===a&&(h=s(this)),h})},e.exports=t.default},function(e,t,i){"use strict";var r=i(1).default;t.__esModule=!0;var n=r(i(6));t.default=function(e){e.registerHelper("helperMissing",function(){if(1!==arguments.length)throw new n.default('Missing helper: "'+arguments[arguments.length-1].name+'"')})},e.exports=t.default},function(e,t,i){"use strict";t.__esModule=!0;var r=i(5);t.default=function(e){e.registerHelper("if",function(e,t){return r.isFunction(e)&&(e=e.call(this)),!t.hash.includeZero&&!e||r.isEmpty(e)?t.inverse(this):t.fn(this)}),e.registerHelper("unless",function(t,i){return e.helpers.if.call(this,t,{fn:i.inverse,inverse:i.fn,hash:i.hash})})},e.exports=t.default},function(e,t){"use strict";t.__esModule=!0,t.default=function(e){e.registerHelper("log",function(){for(var t=[void 0],i=arguments[arguments.length-1],r=0;r<arguments.length-1;r++)t.push(arguments[r]);var n=1;null!=i.hash.level?n=i.hash.level:i.data&&null!=i.data.level&&(n=i.data.level),t[0]=n,e.log.apply(e,t)})},e.exports=t.default},function(e,t){"use strict";t.__esModule=!0,t.default=function(e){e.registerHelper("lookup",function(e,t){return e&&e[t]})},e.exports=t.default},function(e,t,i){"use strict";t.__esModule=!0;var r=i(5);t.default=function(e){e.registerHelper("with",function(e,t){r.isFunction(e)&&(e=e.call(this));var i=t.fn;if(r.isEmpty(e))return t.inverse(this);var n=t.data;return t.data&&t.ids&&((n=r.createFrame(t.data)).contextPath=r.appendContextPath(t.data.contextPath,t.ids[0])),i(e,{data:n,blockParams:r.blockParams([e],[n&&n.contextPath])})})},e.exports=t.default},function(e,t,i){"use strict";var r=i(1).default;t.__esModule=!0,t.registerDefaultDecorators=function(e){n.default(e)};var n=r(i(19))},function(e,t,i){"use strict";t.__esModule=!0;var r=i(5);t.default=function(e){e.registerDecorator("inline",function(e,t,i,n){var o=e;return t.partials||(t.partials={},o=function(n,o){var s=i.partials;i.partials=r.extend({},s,t.partials);var a=e(n,o);return i.partials=s,a}),t.partials[n.args[0]]=n.fn,o})},e.exports=t.default},function(e,t,i){"use strict";t.__esModule=!0;var r=i(5),n={methodMap:["debug","info","warn","error"],level:"info",lookupLevel:function(e){if("string"==typeof e){var t=r.indexOf(n.methodMap,e.toLowerCase());e=t>=0?t:parseInt(e,10)}return e},log:function(e){if(e=n.lookupLevel(e),"undefined"!=typeof console&&n.lookupLevel(n.level)<=e){var t=n.methodMap[e];console[t]||(t="log");for(var i=arguments.length,r=Array(i>1?i-1:0),o=1;o<i;o++)r[o-1]=arguments[o];console[t].apply(console,r)}}};t.default=n,e.exports=t.default},function(e,t){"use strict";function i(e){this.string=e}t.__esModule=!0,i.prototype.toString=i.prototype.toHTML=function(){return""+this.string},t.default=i,e.exports=t.default},function(e,t,i){"use strict";function r(e,t,i,r,n,s,a){function h(t){var n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],o=a;return!a||t==a[0]||t===e.nullContext&&null===a[0]||(o=[t].concat(a)),i(e,t,e.helpers,e.partials,n.data||r,s&&[n.blockParams].concat(s),o)}return(h=o(i,h,e,a,r,s)).program=t,h.depth=a?a.length:0,h.blockParams=n||0,h}function n(){return""}function o(e,t,i,r,n,o){if(e.decorator){var s={};t=e.decorator(t,s,i,r&&r[0],n,o,r),l.extend(t,s)}return t}var s=i(23).default,a=i(3).default,h=i(1).default;t.__esModule=!0,t.checkRevision=function(e){var t=e&&e[0]||1,i=u.COMPILER_REVISION;if(t!==i){if(t<i){var r=u.REVISION_CHANGES[i],n=u.REVISION_CHANGES[t];throw new c.default("Template was precompiled with an older version of Handlebars than the current runtime. Please update your precompiler to a newer version ("+r+") or downgrade your runtime to an older version ("+n+").")}throw new c.default("Template was precompiled with a newer version of Handlebars than the current runtime. Please update your runtime to a newer version ("+e[1]+").")}},t.template=function(e,t){function i(t){function r(t){return""+e.main(n,t,n.helpers,n.partials,l,p,c)}var s,a,h=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],l=h.data;i._setup(h),!h.partial&&e.useData&&(s=t,(a=l)&&"root"in a||((a=a?u.createFrame(a):{}).root=s),l=a);var c=void 0,p=e.useBlockParams?[]:void 0;return e.useDepths&&(c=h.depths?t!=h.depths[0]?[t].concat(h.depths):h.depths:[t]),(r=o(e.main,r,n,h.depths||[],l,p))(t,h)}if(!t)throw new c.default("No environment passed to template");if(!e||!e.main)throw new c.default("Unknown template object: "+typeof e);e.main.decorator=e.main_d,t.VM.checkRevision(e.compiler);var n={strict:function(e,t){if(!(t in e))throw new c.default('"'+t+'" not defined in '+e);return e[t]},lookup:function(e,t){for(var i=e.length,r=0;r<i;r++)if(e[r]&&null!=e[r][t])return e[r][t]},lambda:function(e,t){return"function"==typeof e?e.call(t):e},escapeExpression:l.escapeExpression,invokePartial:function(i,r,n){n.hash&&(r=l.extend({},r,n.hash),n.ids&&(n.ids[0]=!0)),i=t.VM.resolvePartial.call(this,i,r,n);var o=t.VM.invokePartial.call(this,i,r,n);if(null==o&&t.compile&&(n.partials[n.name]=t.compile(i,e.compilerOptions,t),o=n.partials[n.name](r,n)),null!=o){if(n.indent){for(var s=o.split("\n"),a=0,h=s.length;a<h&&(s[a]||a+1!==h);a++)s[a]=n.indent+s[a];o=s.join("\n")}return o}throw new c.default("The partial "+n.name+" could not be compiled when running in runtime-only mode")},fn:function(t){var i=e[t];return i.decorator=e[t+"_d"],i},programs:[],program:function(e,t,i,n,o){var s=this.programs[e],a=this.fn(e);return t||o||n||i?s=r(this,e,a,t,i,n,o):s||(s=this.programs[e]=r(this,e,a)),s},data:function(e,t){for(;e&&t--;)e=e._parent;return e},merge:function(e,t){var i=e||t;return e&&t&&e!==t&&(i=l.extend({},t,e)),i},nullContext:s({}),noop:t.VM.noop,compilerInfo:e.compiler};return i.isTop=!0,i._setup=function(i){i.partial?(n.helpers=i.helpers,n.partials=i.partials,n.decorators=i.decorators):(n.helpers=n.merge(i.helpers,t.helpers),e.usePartial&&(n.partials=n.merge(i.partials,t.partials)),(e.usePartial||e.useDecorators)&&(n.decorators=n.merge(i.decorators,t.decorators)))},i._child=function(t,i,o,s){if(e.useBlockParams&&!o)throw new c.default("must pass block params");if(e.useDepths&&!s)throw new c.default("must pass parent depths");return r(n,t,e[t],i,0,o,s)},i},t.wrapProgram=r,t.resolvePartial=function(e,t,i){return e?e.call||i.name||(i.name=e,e=i.partials[e]):e="@partial-block"===i.name?i.data["partial-block"]:i.partials[i.name],e},t.invokePartial=function(e,t,i){var r=i.data&&i.data["partial-block"];i.partial=!0,i.ids&&(i.data.contextPath=i.ids[0]||i.data.contextPath);var o=void 0;if(i.fn&&i.fn!==n&&function(){i.data=u.createFrame(i.data);var e=i.fn;o=i.data["partial-block"]=function(t){var i=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];return i.data=u.createFrame(i.data),i.data["partial-block"]=r,e(t,i)},e.partials&&(i.partials=l.extend({},i.partials,e.partials))}(),void 0===e&&o&&(e=o),void 0===e)throw new c.default("The partial "+i.name+" could not be found");if(e instanceof Function)return e(t,i)},t.noop=n;var l=a(i(5)),c=h(i(6)),u=i(4)},function(e,t,i){e.exports={default:i(24),__esModule:!0}},function(e,t,i){i(25),e.exports=i(30).Object.seal},function(e,t,i){var r=i(26);i(27)("seal",function(e){return function(t){return e&&r(t)?e(t):t}})},function(e,t){e.exports=function(e){return"object"==typeof e?null!==e:"function"==typeof e}},function(e,t,i){var r=i(28),n=i(30),o=i(33);e.exports=function(e,t){var i=(n.Object||{})[e]||Object[e],s={};s[e]=t(i),r(r.S+r.F*o(function(){i(1)}),"Object",s)}},function(e,t,i){var r=i(29),n=i(30),o=i(31),s="prototype",a=function(e,t,i){var h,l,c,u=e&a.F,p=e&a.G,f=e&a.S,d=e&a.P,m=e&a.B,g=e&a.W,_=p?n:n[t]||(n[t]={}),v=p?r:f?r[t]:(r[t]||{})[s];p&&(i=t);for(h in i)l=!u&&v&&h in v,l&&h in _||(c=l?v[h]:i[h],_[h]=p&&"function"!=typeof v[h]?i[h]:m&&l?o(c,r):g&&v[h]==c?function(e){var t=function(t){return this instanceof e?new e(t):e(t)};return t[s]=e[s],t}(c):d&&"function"==typeof c?o(Function.call,c):c,d&&((_[s]||(_[s]={}))[h]=c))};a.F=1,a.G=2,a.S=4,a.P=8,a.B=16,a.W=32,e.exports=a},function(e,t){var i=e.exports="undefined"!=typeof window&&window.Math==Math?window:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")();"number"==typeof __g&&(__g=i)},function(e,t){var i=e.exports={version:"1.2.6"};"number"==typeof __e&&(__e=i)},function(e,t,i){var r=i(32);e.exports=function(e,t,i){if(r(e),void 0===t)return e;switch(i){case 1:return function(i){return e.call(t,i)};case 2:return function(i,r){return e.call(t,i,r)};case 3:return function(i,r,n){return e.call(t,i,r,n)}}return function(){return e.apply(t,arguments)}}},function(e,t){e.exports=function(e){if("function"!=typeof e)throw TypeError(e+" is not a function!");return e}},function(e,t){e.exports=function(e){try{return!!e()}catch(e){return!0}}},function(e,t){(function(i){"use strict";t.__esModule=!0,t.default=function(e){var t=void 0!==i?i:window,r=t.Handlebars;e.noConflict=function(){return t.Handlebars===e&&(t.Handlebars=r),e}},e.exports=t.default}).call(t,function(){return this}())},function(e,t){"use strict";t.__esModule=!0;var i={helpers:{helperExpression:function(e){return"SubExpression"===e.type||("MustacheStatement"===e.type||"BlockStatement"===e.type)&&!!(e.params&&e.params.length||e.hash)},scopedId:function(e){return/^\.|this\b/.test(e.original)},simpleId:function(e){return 1===e.parts.length&&!i.helpers.scopedId(e)&&!e.depth}}};t.default=i,e.exports=t.default},function(e,t,i){"use strict";var r=i(1).default,n=i(3).default;t.__esModule=!0,t.parse=function(e,t){return"Program"===e.type?e:(o.default.yy=l,l.locInfo=function(e){return new l.SourceLocation(t&&t.srcName,e)},new s.default(t).accept(o.default.parse(e)))};var o=r(i(37)),s=r(i(38)),a=n(i(40)),h=i(5);t.parser=o.default;var l={};h.extend(l,a)},function(e,t){"use strict";t.__esModule=!0;var i=function(){function e(){this.yy={}}var t={trace:function(){},yy:{},symbols_:{error:2,root:3,program:4,EOF:5,program_repetition0:6,statement:7,mustache:8,block:9,rawBlock:10,partial:11,partialBlock:12,content:13,COMMENT:14,CONTENT:15,openRawBlock:16,rawBlock_repetition_plus0:17,END_RAW_BLOCK:18,OPEN_RAW_BLOCK:19,helperName:20,openRawBlock_repetition0:21,openRawBlock_option0:22,CLOSE_RAW_BLOCK:23,openBlock:24,block_option0:25,closeBlock:26,openInverse:27,block_option1:28,OPEN_BLOCK:29,openBlock_repetition0:30,openBlock_option0:31,openBlock_option1:32,CLOSE:33,OPEN_INVERSE:34,openInverse_repetition0:35,openInverse_option0:36,openInverse_option1:37,openInverseChain:38,OPEN_INVERSE_CHAIN:39,openInverseChain_repetition0:40,openInverseChain_option0:41,openInverseChain_option1:42,inverseAndProgram:43,INVERSE:44,inverseChain:45,inverseChain_option0:46,OPEN_ENDBLOCK:47,OPEN:48,mustache_repetition0:49,mustache_option0:50,OPEN_UNESCAPED:51,mustache_repetition1:52,mustache_option1:53,CLOSE_UNESCAPED:54,OPEN_PARTIAL:55,partialName:56,partial_repetition0:57,partial_option0:58,openPartialBlock:59,OPEN_PARTIAL_BLOCK:60,openPartialBlock_repetition0:61,openPartialBlock_option0:62,param:63,sexpr:64,OPEN_SEXPR:65,sexpr_repetition0:66,sexpr_option0:67,CLOSE_SEXPR:68,hash:69,hash_repetition_plus0:70,hashSegment:71,ID:72,EQUALS:73,blockParams:74,OPEN_BLOCK_PARAMS:75,blockParams_repetition_plus0:76,CLOSE_BLOCK_PARAMS:77,path:78,dataName:79,STRING:80,NUMBER:81,BOOLEAN:82,UNDEFINED:83,NULL:84,DATA:85,pathSegments:86,SEP:87,$accept:0,$end:1},terminals_:{2:"error",5:"EOF",14:"COMMENT",15:"CONTENT",18:"END_RAW_BLOCK",19:"OPEN_RAW_BLOCK",23:"CLOSE_RAW_BLOCK",29:"OPEN_BLOCK",33:"CLOSE",34:"OPEN_INVERSE",39:"OPEN_INVERSE_CHAIN",44:"INVERSE",47:"OPEN_ENDBLOCK",48:"OPEN",51:"OPEN_UNESCAPED",54:"CLOSE_UNESCAPED",55:"OPEN_PARTIAL",60:"OPEN_PARTIAL_BLOCK",65:"OPEN_SEXPR",68:"CLOSE_SEXPR",72:"ID",73:"EQUALS",75:"OPEN_BLOCK_PARAMS",77:"CLOSE_BLOCK_PARAMS",80:"STRING",81:"NUMBER",82:"BOOLEAN",83:"UNDEFINED",84:"NULL",85:"DATA",87:"SEP"},productions_:[0,[3,2],[4,1],[7,1],[7,1],[7,1],[7,1],[7,1],[7,1],[7,1],[13,1],[10,3],[16,5],[9,4],[9,4],[24,6],[27,6],[38,6],[43,2],[45,3],[45,1],[26,3],[8,5],[8,5],[11,5],[12,3],[59,5],[63,1],[63,1],[64,5],[69,1],[71,3],[74,3],[20,1],[20,1],[20,1],[20,1],[20,1],[20,1],[20,1],[56,1],[56,1],[79,2],[78,1],[86,3],[86,1],[6,0],[6,2],[17,1],[17,2],[21,0],[21,2],[22,0],[22,1],[25,0],[25,1],[28,0],[28,1],[30,0],[30,2],[31,0],[31,1],[32,0],[32,1],[35,0],[35,2],[36,0],[36,1],[37,0],[37,1],[40,0],[40,2],[41,0],[41,1],[42,0],[42,1],[46,0],[46,1],[49,0],[49,2],[50,0],[50,1],[52,0],[52,2],[53,0],[53,1],[57,0],[57,2],[58,0],[58,1],[61,0],[61,2],[62,0],[62,1],[66,0],[66,2],[67,0],[67,1],[70,1],[70,2],[76,1],[76,2]],performAction:function(e,t,i,r,n,o,s){var a=o.length-1;switch(n){case 1:return o[a-1];case 2:this.$=r.prepareProgram(o[a]);break;case 3:case 4:case 5:case 6:case 7:case 8:this.$=o[a];break;case 9:this.$={type:"CommentStatement",value:r.stripComment(o[a]),strip:r.stripFlags(o[a],o[a]),loc:r.locInfo(this._$)};break;case 10:this.$={type:"ContentStatement",original:o[a],value:o[a],loc:r.locInfo(this._$)};break;case 11:this.$=r.prepareRawBlock(o[a-2],o[a-1],o[a],this._$);break;case 12:this.$={path:o[a-3],params:o[a-2],hash:o[a-1]};break;case 13:this.$=r.prepareBlock(o[a-3],o[a-2],o[a-1],o[a],!1,this._$);break;case 14:this.$=r.prepareBlock(o[a-3],o[a-2],o[a-1],o[a],!0,this._$);break;case 15:this.$={open:o[a-5],path:o[a-4],params:o[a-3],hash:o[a-2],blockParams:o[a-1],strip:r.stripFlags(o[a-5],o[a])};break;case 16:case 17:this.$={path:o[a-4],params:o[a-3],hash:o[a-2],blockParams:o[a-1],strip:r.stripFlags(o[a-5],o[a])};break;case 18:this.$={strip:r.stripFlags(o[a-1],o[a-1]),program:o[a]};break;case 19:var h=r.prepareBlock(o[a-2],o[a-1],o[a],o[a],!1,this._$),l=r.prepareProgram([h],o[a-1].loc);l.chained=!0,this.$={strip:o[a-2].strip,program:l,chain:!0};break;case 20:this.$=o[a];break;case 21:this.$={path:o[a-1],strip:r.stripFlags(o[a-2],o[a])};break;case 22:case 23:this.$=r.prepareMustache(o[a-3],o[a-2],o[a-1],o[a-4],r.stripFlags(o[a-4],o[a]),this._$);break;case 24:this.$={type:"PartialStatement",name:o[a-3],params:o[a-2],hash:o[a-1],indent:"",strip:r.stripFlags(o[a-4],o[a]),loc:r.locInfo(this._$)};break;case 25:this.$=r.preparePartialBlock(o[a-2],o[a-1],o[a],this._$);break;case 26:this.$={path:o[a-3],params:o[a-2],hash:o[a-1],strip:r.stripFlags(o[a-4],o[a])};break;case 27:case 28:this.$=o[a];break;case 29:this.$={type:"SubExpression",path:o[a-3],params:o[a-2],hash:o[a-1],loc:r.locInfo(this._$)};break;case 30:this.$={type:"Hash",pairs:o[a],loc:r.locInfo(this._$)};break;case 31:this.$={type:"HashPair",key:r.id(o[a-2]),value:o[a],loc:r.locInfo(this._$)};break;case 32:this.$=r.id(o[a-1]);break;case 33:case 34:this.$=o[a];break;case 35:this.$={type:"StringLiteral",value:o[a],original:o[a],loc:r.locInfo(this._$)};break;case 36:this.$={type:"NumberLiteral",value:Number(o[a]),original:Number(o[a]),loc:r.locInfo(this._$)};break;case 37:this.$={type:"BooleanLiteral",value:"true"===o[a],original:"true"===o[a],loc:r.locInfo(this._$)};break;case 38:this.$={type:"UndefinedLiteral",original:void 0,value:void 0,loc:r.locInfo(this._$)};break;case 39:this.$={type:"NullLiteral",original:null,value:null,loc:r.locInfo(this._$)};break;case 40:case 41:this.$=o[a];break;case 42:this.$=r.preparePath(!0,o[a],this._$);break;case 43:this.$=r.preparePath(!1,o[a],this._$);break;case 44:o[a-2].push({part:r.id(o[a]),original:o[a],separator:o[a-1]}),this.$=o[a-2];break;case 45:this.$=[{part:r.id(o[a]),original:o[a]}];break;case 46:this.$=[];break;case 47:o[a-1].push(o[a]);break;case 48:this.$=[o[a]];break;case 49:o[a-1].push(o[a]);break;case 50:this.$=[];break;case 51:o[a-1].push(o[a]);break;case 58:this.$=[];break;case 59:o[a-1].push(o[a]);break;case 64:this.$=[];break;case 65:o[a-1].push(o[a]);break;case 70:this.$=[];break;case 71:o[a-1].push(o[a]);break;case 78:this.$=[];break;case 79:o[a-1].push(o[a]);break;case 82:this.$=[];break;case 83:o[a-1].push(o[a]);break;case 86:this.$=[];break;case 87:o[a-1].push(o[a]);break;case 90:this.$=[];break;case 91:o[a-1].push(o[a]);break;case 94:this.$=[];break;case 95:o[a-1].push(o[a]);break;case 98:this.$=[o[a]];break;case 99:o[a-1].push(o[a]);break;case 100:this.$=[o[a]];break;case 101:o[a-1].push(o[a])}},table:[{3:1,4:2,5:[2,46],6:3,14:[2,46],15:[2,46],19:[2,46],29:[2,46],34:[2,46],48:[2,46],51:[2,46],55:[2,46],60:[2,46]},{1:[3]},{5:[1,4]},{5:[2,2],7:5,8:6,9:7,10:8,11:9,12:10,13:11,14:[1,12],15:[1,20],16:17,19:[1,23],24:15,27:16,29:[1,21],34:[1,22],39:[2,2],44:[2,2],47:[2,2],48:[1,13],51:[1,14],55:[1,18],59:19,60:[1,24]},{1:[2,1]},{5:[2,47],14:[2,47],15:[2,47],19:[2,47],29:[2,47],34:[2,47],39:[2,47],44:[2,47],47:[2,47],48:[2,47],51:[2,47],55:[2,47],60:[2,47]},{5:[2,3],14:[2,3],15:[2,3],19:[2,3],29:[2,3],34:[2,3],39:[2,3],44:[2,3],47:[2,3],48:[2,3],51:[2,3],55:[2,3],60:[2,3]},{5:[2,4],14:[2,4],15:[2,4],19:[2,4],29:[2,4],34:[2,4],39:[2,4],44:[2,4],47:[2,4],48:[2,4],51:[2,4],55:[2,4],60:[2,4]},{5:[2,5],14:[2,5],15:[2,5],19:[2,5],29:[2,5],34:[2,5],39:[2,5],44:[2,5],47:[2,5],48:[2,5],51:[2,5],55:[2,5],60:[2,5]},{5:[2,6],14:[2,6],15:[2,6],19:[2,6],29:[2,6],34:[2,6],39:[2,6],44:[2,6],47:[2,6],48:[2,6],51:[2,6],55:[2,6],60:[2,6]},{5:[2,7],14:[2,7],15:[2,7],19:[2,7],29:[2,7],34:[2,7],39:[2,7],44:[2,7],47:[2,7],48:[2,7],51:[2,7],55:[2,7],60:[2,7]},{5:[2,8],14:[2,8],15:[2,8],19:[2,8],29:[2,8],34:[2,8],39:[2,8],44:[2,8],47:[2,8],48:[2,8],51:[2,8],55:[2,8],60:[2,8]},{5:[2,9],14:[2,9],15:[2,9],19:[2,9],29:[2,9],34:[2,9],39:[2,9],44:[2,9],47:[2,9],48:[2,9],51:[2,9],55:[2,9],60:[2,9]},{20:25,72:[1,35],78:26,79:27,80:[1,28],81:[1,29],82:[1,30],83:[1,31],84:[1,32],85:[1,34],86:33},{20:36,72:[1,35],78:26,79:27,80:[1,28],81:[1,29],82:[1,30],83:[1,31],84:[1,32],85:[1,34],86:33},{4:37,6:3,14:[2,46],15:[2,46],19:[2,46],29:[2,46],34:[2,46],39:[2,46],44:[2,46],47:[2,46],48:[2,46],51:[2,46],55:[2,46],60:[2,46]},{4:38,6:3,14:[2,46],15:[2,46],19:[2,46],29:[2,46],34:[2,46],44:[2,46],47:[2,46],48:[2,46],51:[2,46],55:[2,46],60:[2,46]},{13:40,15:[1,20],17:39},{20:42,56:41,64:43,65:[1,44],72:[1,35],78:26,79:27,80:[1,28],81:[1,29],82:[1,30],83:[1,31],84:[1,32],85:[1,34],86:33},{4:45,6:3,14:[2,46],15:[2,46],19:[2,46],29:[2,46],34:[2,46],47:[2,46],48:[2,46],51:[2,46],55:[2,46],60:[2,46]},{5:[2,10],14:[2,10],15:[2,10],18:[2,10],19:[2,10],29:[2,10],34:[2,10],39:[2,10],44:[2,10],47:[2,10],48:[2,10],51:[2,10],55:[2,10],60:[2,10]},{20:46,72:[1,35],78:26,79:27,80:[1,28],81:[1,29],82:[1,30],83:[1,31],84:[1,32],85:[1,34],86:33},{20:47,72:[1,35],78:26,79:27,80:[1,28],81:[1,29],82:[1,30],83:[1,31],84:[1,32],85:[1,34],86:33},{20:48,72:[1,35],78:26,79:27,80:[1,28],81:[1,29],82:[1,30],83:[1,31],84:[1,32],85:[1,34],86:33},{20:42,56:49,64:43,65:[1,44],72:[1,35],78:26,79:27,80:[1,28],81:[1,29],82:[1,30],83:[1,31],84:[1,32],85:[1,34],86:33},{33:[2,78],49:50,65:[2,78],72:[2,78],80:[2,78],81:[2,78],82:[2,78],83:[2,78],84:[2,78],85:[2,78]},{23:[2,33],33:[2,33],54:[2,33],65:[2,33],68:[2,33],72:[2,33],75:[2,33],80:[2,33],81:[2,33],82:[2,33],83:[2,33],84:[2,33],85:[2,33]},{23:[2,34],33:[2,34],54:[2,34],65:[2,34],68:[2,34],72:[2,34],75:[2,34],80:[2,34],81:[2,34],82:[2,34],83:[2,34],84:[2,34],85:[2,34]},{23:[2,35],33:[2,35],54:[2,35],65:[2,35],68:[2,35],72:[2,35],75:[2,35],80:[2,35],81:[2,35],82:[2,35],83:[2,35],84:[2,35],85:[2,35]},{23:[2,36],33:[2,36],54:[2,36],65:[2,36],68:[2,36],72:[2,36],75:[2,36],80:[2,36],81:[2,36],82:[2,36],83:[2,36],84:[2,36],85:[2,36]},{23:[2,37],33:[2,37],54:[2,37],65:[2,37],68:[2,37],72:[2,37],75:[2,37],80:[2,37],81:[2,37],82:[2,37],83:[2,37],84:[2,37],85:[2,37]},{23:[2,38],33:[2,38],54:[2,38],65:[2,38],68:[2,38],72:[2,38],75:[2,38],80:[2,38],81:[2,38],82:[2,38],83:[2,38],84:[2,38],85:[2,38]},{23:[2,39],33:[2,39],54:[2,39],65:[2,39],68:[2,39],72:[2,39],75:[2,39],80:[2,39],81:[2,39],82:[2,39],83:[2,39],84:[2,39],85:[2,39]},{23:[2,43],33:[2,43],54:[2,43],65:[2,43],68:[2,43],72:[2,43],75:[2,43],80:[2,43],81:[2,43],82:[2,43],83:[2,43],84:[2,43],85:[2,43],87:[1,51]},{72:[1,35],86:52},{23:[2,45],33:[2,45],54:[2,45],65:[2,45],68:[2,45],72:[2,45],75:[2,45],80:[2,45],81:[2,45],82:[2,45],83:[2,45],84:[2,45],85:[2,45],87:[2,45]},{52:53,54:[2,82],65:[2,82],72:[2,82],80:[2,82],81:[2,82],82:[2,82],83:[2,82],84:[2,82],85:[2,82]},{25:54,38:56,39:[1,58],43:57,44:[1,59],45:55,47:[2,54]},{28:60,43:61,44:[1,59],47:[2,56]},{13:63,15:[1,20],18:[1,62]},{15:[2,48],18:[2,48]},{33:[2,86],57:64,65:[2,86],72:[2,86],80:[2,86],81:[2,86],82:[2,86],83:[2,86],84:[2,86],85:[2,86]},{33:[2,40],65:[2,40],72:[2,40],80:[2,40],81:[2,40],82:[2,40],83:[2,40],84:[2,40],85:[2,40]},{33:[2,41],65:[2,41],72:[2,41],80:[2,41],81:[2,41],82:[2,41],83:[2,41],84:[2,41],85:[2,41]},{20:65,72:[1,35],78:26,79:27,80:[1,28],81:[1,29],82:[1,30],83:[1,31],84:[1,32],85:[1,34],86:33},{26:66,47:[1,67]},{30:68,33:[2,58],65:[2,58],72:[2,58],75:[2,58],80:[2,58],81:[2,58],82:[2,58],83:[2,58],84:[2,58],85:[2,58]},{33:[2,64],35:69,65:[2,64],72:[2,64],75:[2,64],80:[2,64],81:[2,64],82:[2,64],83:[2,64],84:[2,64],85:[2,64]},{21:70,23:[2,50],65:[2,50],72:[2,50],80:[2,50],81:[2,50],82:[2,50],83:[2,50],84:[2,50],85:[2,50]},{33:[2,90],61:71,65:[2,90],72:[2,90],80:[2,90],81:[2,90],82:[2,90],83:[2,90],84:[2,90],85:[2,90]},{20:75,33:[2,80],50:72,63:73,64:76,65:[1,44],69:74,70:77,71:78,72:[1,79],78:26,79:27,80:[1,28],81:[1,29],82:[1,30],83:[1,31],84:[1,32],85:[1,34],86:33},{72:[1,80]},{23:[2,42],33:[2,42],54:[2,42],65:[2,42],68:[2,42],72:[2,42],75:[2,42],80:[2,42],81:[2,42],82:[2,42],83:[2,42],84:[2,42],85:[2,42],87:[1,51]},{20:75,53:81,54:[2,84],63:82,64:76,65:[1,44],69:83,70:77,71:78,72:[1,79],78:26,79:27,80:[1,28],81:[1,29],82:[1,30],83:[1,31],84:[1,32],85:[1,34],86:33},{26:84,47:[1,67]},{47:[2,55]},{4:85,6:3,14:[2,46],15:[2,46],19:[2,46],29:[2,46],34:[2,46],39:[2,46],44:[2,46],47:[2,46],48:[2,46],51:[2,46],55:[2,46],60:[2,46]},{47:[2,20]},{20:86,72:[1,35],78:26,79:27,80:[1,28],81:[1,29],82:[1,30],83:[1,31],84:[1,32],85:[1,34],86:33},{4:87,6:3,14:[2,46],15:[2,46],19:[2,46],29:[2,46],34:[2,46],47:[2,46],48:[2,46],51:[2,46],55:[2,46],60:[2,46]},{26:88,47:[1,67]},{47:[2,57]},{5:[2,11],14:[2,11],15:[2,11],19:[2,11],29:[2,11],34:[2,11],39:[2,11],44:[2,11],47:[2,11],48:[2,11],51:[2,11],55:[2,11],60:[2,11]},{15:[2,49],18:[2,49]},{20:75,33:[2,88],58:89,63:90,64:76,65:[1,44],69:91,70:77,71:78,72:[1,79],78:26,79:27,80:[1,28],81:[1,29],82:[1,30],83:[1,31],84:[1,32],85:[1,34],86:33},{65:[2,94],66:92,68:[2,94],72:[2,94],80:[2,94],81:[2,94],82:[2,94],83:[2,94],84:[2,94],85:[2,94]},{5:[2,25],14:[2,25],15:[2,25],19:[2,25],29:[2,25],34:[2,25],39:[2,25],44:[2,25],47:[2,25],48:[2,25],51:[2,25],55:[2,25],60:[2,25]},{20:93,72:[1,35],78:26,79:27,80:[1,28],81:[1,29],82:[1,30],83:[1,31],84:[1,32],85:[1,34],86:33},{20:75,31:94,33:[2,60],63:95,64:76,65:[1,44],69:96,70:77,71:78,72:[1,79],75:[2,60],78:26,79:27,80:[1,28],81:[1,29],82:[1,30],83:[1,31],84:[1,32],85:[1,34],86:33},{20:75,33:[2,66],36:97,63:98,64:76,65:[1,44],69:99,70:77,71:78,72:[1,79],75:[2,66],78:26,79:27,80:[1,28],81:[1,29],82:[1,30],83:[1,31],84:[1,32],85:[1,34],86:33},{20:75,22:100,23:[2,52],63:101,64:76,65:[1,44],69:102,70:77,71:78,72:[1,79],78:26,79:27,80:[1,28],81:[1,29],82:[1,30],83:[1,31],84:[1,32],85:[1,34],86:33},{20:75,33:[2,92],62:103,63:104,64:76,65:[1,44],69:105,70:77,71:78,72:[1,79],78:26,79:27,80:[1,28],81:[1,29],82:[1,30],83:[1,31],84:[1,32],85:[1,34],86:33},{33:[1,106]},{33:[2,79],65:[2,79],72:[2,79],80:[2,79],81:[2,79],82:[2,79],83:[2,79],84:[2,79],85:[2,79]},{33:[2,81]},{23:[2,27],33:[2,27],54:[2,27],65:[2,27],68:[2,27],72:[2,27],75:[2,27],80:[2,27],81:[2,27],82:[2,27],83:[2,27],84:[2,27],85:[2,27]},{23:[2,28],33:[2,28],54:[2,28],65:[2,28],68:[2,28],72:[2,28],75:[2,28],80:[2,28],81:[2,28],82:[2,28],83:[2,28],84:[2,28],85:[2,28]},{23:[2,30],33:[2,30],54:[2,30],68:[2,30],71:107,72:[1,108],75:[2,30]},{23:[2,98],33:[2,98],54:[2,98],68:[2,98],72:[2,98],75:[2,98]},{23:[2,45],33:[2,45],54:[2,45],65:[2,45],68:[2,45],72:[2,45],73:[1,109],75:[2,45],80:[2,45],81:[2,45],82:[2,45],83:[2,45],84:[2,45],85:[2,45],87:[2,45]},{23:[2,44],33:[2,44],54:[2,44],65:[2,44],68:[2,44],72:[2,44],75:[2,44],80:[2,44],81:[2,44],82:[2,44],83:[2,44],84:[2,44],85:[2,44],87:[2,44]},{54:[1,110]},{54:[2,83],65:[2,83],72:[2,83],80:[2,83],81:[2,83],82:[2,83],83:[2,83],84:[2,83],85:[2,83]},{54:[2,85]},{5:[2,13],14:[2,13],15:[2,13],19:[2,13],29:[2,13],34:[2,13],39:[2,13],44:[2,13],47:[2,13],48:[2,13],51:[2,13],55:[2,13],60:[2,13]},{38:56,39:[1,58],43:57,44:[1,59],45:112,46:111,47:[2,76]},{33:[2,70],40:113,65:[2,70],72:[2,70],75:[2,70],80:[2,70],81:[2,70],82:[2,70],83:[2,70],84:[2,70],85:[2,70]},{47:[2,18]},{5:[2,14],14:[2,14],15:[2,14],19:[2,14],29:[2,14],34:[2,14],39:[2,14],44:[2,14],47:[2,14],48:[2,14],51:[2,14],55:[2,14],60:[2,14]},{33:[1,114]},{33:[2,87],65:[2,87],72:[2,87],80:[2,87],81:[2,87],82:[2,87],83:[2,87],84:[2,87],85:[2,87]},{33:[2,89]},{20:75,63:116,64:76,65:[1,44],67:115,68:[2,96],69:117,70:77,71:78,72:[1,79],78:26,79:27,80:[1,28],81:[1,29],82:[1,30],83:[1,31],84:[1,32],85:[1,34],86:33},{33:[1,118]},{32:119,33:[2,62],74:120,75:[1,121]},{33:[2,59],65:[2,59],72:[2,59],75:[2,59],80:[2,59],81:[2,59],82:[2,59],83:[2,59],84:[2,59],85:[2,59]},{33:[2,61],75:[2,61]},{33:[2,68],37:122,74:123,75:[1,121]},{33:[2,65],65:[2,65],72:[2,65],75:[2,65],80:[2,65],81:[2,65],82:[2,65],83:[2,65],84:[2,65],85:[2,65]},{33:[2,67],75:[2,67]},{23:[1,124]},{23:[2,51],65:[2,51],72:[2,51],80:[2,51],81:[2,51],82:[2,51],83:[2,51],84:[2,51],85:[2,51]},{23:[2,53]},{33:[1,125]},{33:[2,91],65:[2,91],72:[2,91],80:[2,91],81:[2,91],82:[2,91],83:[2,91],84:[2,91],85:[2,91]},{33:[2,93]},{5:[2,22],14:[2,22],15:[2,22],19:[2,22],29:[2,22],34:[2,22],39:[2,22],44:[2,22],47:[2,22],48:[2,22],51:[2,22],55:[2,22],60:[2,22]},{23:[2,99],33:[2,99],54:[2,99],68:[2,99],72:[2,99],75:[2,99]},{73:[1,109]},{20:75,63:126,64:76,65:[1,44],72:[1,35],78:26,79:27,80:[1,28],81:[1,29],82:[1,30],83:[1,31],84:[1,32],85:[1,34],86:33},{5:[2,23],14:[2,23],15:[2,23],19:[2,23],29:[2,23],34:[2,23],39:[2,23],44:[2,23],47:[2,23],48:[2,23],51:[2,23],55:[2,23],60:[2,23]},{47:[2,19]},{47:[2,77]},{20:75,33:[2,72],41:127,63:128,64:76,65:[1,44],69:129,70:77,71:78,72:[1,79],75:[2,72],78:26,79:27,80:[1,28],81:[1,29],82:[1,30],83:[1,31],84:[1,32],85:[1,34],86:33},{5:[2,24],14:[2,24],15:[2,24],19:[2,24],29:[2,24],34:[2,24],39:[2,24],44:[2,24],47:[2,24],48:[2,24],51:[2,24],55:[2,24],60:[2,24]},{68:[1,130]},{65:[2,95],68:[2,95],72:[2,95],80:[2,95],81:[2,95],82:[2,95],83:[2,95],84:[2,95],85:[2,95]},{68:[2,97]},{5:[2,21],14:[2,21],15:[2,21],19:[2,21],29:[2,21],34:[2,21],39:[2,21],44:[2,21],47:[2,21],48:[2,21],51:[2,21],55:[2,21],60:[2,21]},{33:[1,131]},{33:[2,63]},{72:[1,133],76:132},{33:[1,134]},{33:[2,69]},{15:[2,12]},{14:[2,26],15:[2,26],19:[2,26],29:[2,26],34:[2,26],47:[2,26],48:[2,26],51:[2,26],55:[2,26],60:[2,26]},{23:[2,31],33:[2,31],54:[2,31],68:[2,31],72:[2,31],75:[2,31]},{33:[2,74],42:135,74:136,75:[1,121]},{33:[2,71],65:[2,71],72:[2,71],75:[2,71],80:[2,71],81:[2,71],82:[2,71],83:[2,71],84:[2,71],85:[2,71]},{33:[2,73],75:[2,73]},{23:[2,29],33:[2,29],54:[2,29],65:[2,29],68:[2,29],72:[2,29],75:[2,29],80:[2,29],81:[2,29],82:[2,29],83:[2,29],84:[2,29],85:[2,29]},{14:[2,15],15:[2,15],19:[2,15],29:[2,15],34:[2,15],39:[2,15],44:[2,15],47:[2,15],48:[2,15],51:[2,15],55:[2,15],60:[2,15]},{72:[1,138],77:[1,137]},{72:[2,100],77:[2,100]},{14:[2,16],15:[2,16],19:[2,16],29:[2,16],34:[2,16],44:[2,16],47:[2,16],48:[2,16],51:[2,16],55:[2,16],60:[2,16]},{33:[1,139]},{33:[2,75]},{33:[2,32]},{72:[2,101],77:[2,101]},{14:[2,17],15:[2,17],19:[2,17],29:[2,17],34:[2,17],39:[2,17],44:[2,17],47:[2,17],48:[2,17],51:[2,17],55:[2,17],60:[2,17]}],defaultActions:{4:[2,1],55:[2,55],57:[2,20],61:[2,57],74:[2,81],83:[2,85],87:[2,18],91:[2,89],102:[2,53],105:[2,93],111:[2,19],112:[2,77],117:[2,97],120:[2,63],123:[2,69],124:[2,12],136:[2,75],137:[2,32]},parseError:function(e,t){throw new Error(e)},parse:function(e){var t=this,i=[0],r=[null],n=[],o=this.table,s="",a=0,h=0,l=0;this.lexer.setInput(e),this.lexer.yy=this.yy,this.yy.lexer=this.lexer,this.yy.parser=this,void 0===this.lexer.yylloc&&(this.lexer.yylloc={});var c=this.lexer.yylloc;n.push(c);var u,p=this.lexer.options&&this.lexer.options.ranges;"function"==typeof this.yy.parseError&&(this.parseError=this.yy.parseError);for(var f,d,m,g,_,v,y,b,x,T={};;){if(m=i[i.length-1],this.defaultActions[m]?g=this.defaultActions[m]:(null!==f&&void 0!==f||(u=void 0,"number"!=typeof(u=t.lexer.lex()||1)&&(u=t.symbols_[u]||u),f=u),g=o[m]&&o[m][f]),void 0===g||!g.length||!g[0]){var E="";if(!l){x=[];for(v in o[m])this.terminals_[v]&&v>2&&x.push("'"+this.terminals_[v]+"'");E=this.lexer.showPosition?"Parse error on line "+(a+1)+":\n"+this.lexer.showPosition()+"\nExpecting "+x.join(", ")+", got '"+(this.terminals_[f]||f)+"'":"Parse error on line "+(a+1)+": Unexpected "+(1==f?"end of input":"'"+(this.terminals_[f]||f)+"'"),this.parseError(E,{text:this.lexer.match,token:this.terminals_[f]||f,line:this.lexer.yylineno,loc:c,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:i.push(f),r.push(this.lexer.yytext),n.push(this.lexer.yylloc),i.push(g[1]),f=null,d?(f=d,d=null):(h=this.lexer.yyleng,s=this.lexer.yytext,a=this.lexer.yylineno,c=this.lexer.yylloc,l>0&&l--);break;case 2:if(y=this.productions_[g[1]][1],T.$=r[r.length-y],T._$={first_line:n[n.length-(y||1)].first_line,last_line:n[n.length-1].last_line,first_column:n[n.length-(y||1)].first_column,last_column:n[n.length-1].last_column},p&&(T._$.range=[n[n.length-(y||1)].range[0],n[n.length-1].range[1]]),void 0!==(_=this.performAction.call(T,s,h,a,this.yy,g[1],r,n)))return _;y&&(i=i.slice(0,-1*y*2),r=r.slice(0,-1*y),n=n.slice(0,-1*y)),i.push(this.productions_[g[1]][0]),r.push(T.$),n.push(T._$),b=o[i[i.length-2]][i[i.length-1]],i.push(b);break;case 3:return!0}}return!0}},i={EOF:1,parseError:function(e,t){if(!this.yy.parser)throw new Error(e);this.yy.parser.parseError(e,t)},setInput:function(e){return this._input=e,this._more=this._less=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this.options.ranges&&(this.yylloc.range=[0,0]),this.offset=0,this},input:function(){var e=this._input[0];return this.yytext+=e,this.yyleng++,this.offset++,this.match+=e,this.matched+=e,e.match(/(?:\r\n?|\n).*/g)?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),e},unput:function(e){var t=e.length,i=e.split(/(?:\r\n?|\n)/g);this._input=e+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-t-1),this.offset-=t;var r=this.match.split(/(?:\r\n?|\n)/g);this.match=this.match.substr(0,this.match.length-1),this.matched=this.matched.substr(0,this.matched.length-1),i.length-1&&(this.yylineno-=i.length-1);var n=this.yylloc.range;return this.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:i?(i.length===r.length?this.yylloc.first_column:0)+r[r.length-i.length].length-i[0].length:this.yylloc.first_column-t},this.options.ranges&&(this.yylloc.range=[n[0],n[0]+this.yyleng-t]),this},more:function(){return this._more=!0,this},less:function(e){this.unput(this.match.slice(e))},pastInput:function(){var e=this.matched.substr(0,this.matched.length-this.match.length);return(e.length>20?"...":"")+e.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var e=this.match;return e.length<20&&(e+=this._input.substr(0,20-e.length)),(e.substr(0,20)+(e.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){var e=this.pastInput(),t=new Array(e.length+1).join("-");return e+this.upcomingInput()+"\n"+t+"^"},next:function(){if(this.done)return this.EOF;var e,t,i,r,n;this._input||(this.done=!0),this._more||(this.yytext="",this.match="");for(var o=this._currentRules(),s=0;s<o.length&&(!(i=this._input.match(this.rules[o[s]]))||t&&!(i[0].length>t[0].length)||(t=i,r=s,this.options.flex));s++);return t?((n=t[0].match(/(?:\r\n?|\n).*/g))&&(this.yylineno+=n.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:n?n[n.length-1].length-n[n.length-1].match(/\r?\n?/)[0].length:this.yylloc.last_column+t[0].length},this.yytext+=t[0],this.match+=t[0],this.matches=t,this.yyleng=this.yytext.length,this.options.ranges&&(this.yylloc.range=[this.offset,this.offset+=this.yyleng]),this._more=!1,this._input=this._input.slice(t[0].length),this.matched+=t[0],e=this.performAction.call(this,this.yy,this,o[r],this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1),e||void 0):""===this._input?this.EOF:this.parseError("Lexical error on line "+(this.yylineno+1)+". Unrecognized text.\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},lex:function(){var e=this.next();return void 0!==e?e:this.lex()},begin:function(e){this.conditionStack.push(e)},popState:function(){return this.conditionStack.pop()},_currentRules:function(){return this.conditions[this.conditionStack[this.conditionStack.length-1]].rules},topState:function(){return this.conditionStack[this.conditionStack.length-2]},pushState:function(e){this.begin(e)},options:{},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}},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\/.)|]))))/,/^(?:\[(\\\]|[^\]])*\])/,/^(?:.)/,/^(?:$)/],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}}};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,r.prototype.Program=function(e){var t=!this.options.ignoreStandalone,i=!this.isRootSeen;this.isRootSeen=!0;for(var r=e.body,h=0,l=r.length;h<l;h++){var c=r[h],u=this.accept(c);if(u){var p=n(r,h,i),f=o(r,h,i),d=u.openStandalone&&p,m=u.closeStandalone&&f,g=u.inlineStandalone&&p&&f;u.close&&s(r,h,!0),u.open&&a(r,h,!0),t&&g&&(s(r,h),a(r,h)&&"PartialStatement"===c.type&&(c.indent=/([ \t]+$)/.exec(r[h-1].original)[1])),t&&d&&(s((c.program||c.inverse).body),a(r,h)),t&&m&&(s(r,h),a((c.inverse||c.program).body))}}return e},r.prototype.BlockStatement=r.prototype.DecoratorBlock=r.prototype.PartialBlockStatement=function(e){this.accept(e.program),this.accept(e.inverse);var t=e.program||e.inverse,i=e.program&&e.inverse,r=i,h=i;if(i&&i.chained)for(r=i.body[0].program;h.chained;)h=h.body[h.body.length-1].program;var l={open:e.openStrip.open,close:e.closeStrip.close,openStandalone:o(t.body),closeStandalone:n((r||t).body)};if(e.openStrip.close&&s(t.body,null,!0),i){var c=e.inverseStrip;c.open&&a(t.body,null,!0),c.close&&s(r.body,null,!0),e.closeStrip.open&&a(h.body,null,!0),!this.options.ignoreStandalone&&n(t.body)&&o(r.body)&&(a(t.body),s(r.body))}else e.closeStrip.open&&a(t.body,null,!0);return l},r.prototype.Decorator=r.prototype.MustacheStatement=function(e){return e.strip},r.prototype.PartialStatement=r.prototype.CommentStatement=function(e){var t=e.strip||{};return{inlineStandalone:!0,open:t.open,close:t.close}},t.default=r,e.exports=t.default},function(e,t,i){"use strict";function r(){this.parents=[]}function n(e){this.acceptRequired(e,"path"),this.acceptArray(e.params),this.acceptKey(e,"hash")}function o(e){n.call(this,e),this.acceptKey(e,"program"),this.acceptKey(e,"inverse")}function s(e){this.acceptRequired(e,"name"),this.acceptArray(e.params),this.acceptKey(e,"hash")}var a=i(1).default;t.__esModule=!0;var h=a(i(6));r.prototype={constructor:r,mutating:!1,acceptKey:function(e,t){var i=this.accept(e[t]);if(this.mutating){if(i&&!r.prototype[i.type])throw new h.default('Unexpected node type "'+i.type+'" found when accepting '+t+" on "+e.type);e[t]=i}},acceptRequired:function(e,t){if(this.acceptKey(e,t),!e[t])throw new h.default(e.type+" requires "+t)},acceptArray:function(e){for(var t=0,i=e.length;t<i;t++)this.acceptKey(e,t),e[t]||(e.splice(t,1),t--,i--)},accept:function(e){if(e){if(!this[e.type])throw new h.default("Unknown type: "+e.type,e);this.current&&this.parents.unshift(this.current),this.current=e;var t=this[e.type](e);return this.current=this.parents.shift(),!this.mutating||t?t:!1!==t?e:void 0}},Program:function(e){this.acceptArray(e.body)},MustacheStatement:n,Decorator:n,BlockStatement:o,DecoratorBlock:o,PartialStatement:s,PartialBlockStatement:function(e){s.call(this,e),this.acceptKey(e,"program")},ContentStatement:function(){},CommentStatement:function(){},SubExpression:n,PathExpression:function(){},StringLiteral:function(){},NumberLiteral:function(){},BooleanLiteral:function(){},UndefinedLiteral:function(){},NullLiteral:function(){},Hash:function(e){this.acceptArray(e.pairs)},HashPair:function(e){this.acceptRequired(e,"value")}},t.default=r,e.exports=t.default},function(e,t,i){"use strict";function r(e,t){if(t=t.path?t.path.original:t,e.path.original!==t){var i={loc:e.path.loc};throw new o.default(e.path.original+" doesn't match "+t,i)}}var n=i(1).default;t.__esModule=!0,t.SourceLocation=function(e,t){this.source=e,this.start={line:t.first_line,column:t.first_column},this.end={line:t.last_line,column:t.last_column}},t.id=function(e){return/^\[.*\]$/.test(e)?e.substr(1,e.length-2):e},t.stripFlags=function(e,t){return{open:"~"===e.charAt(2),close:"~"===t.charAt(t.length-3)}},t.stripComment=function(e){return e.replace(/^\{\{~?\!-?-?/,"").replace(/-?-?~?\}\}$/,"")},t.preparePath=function(e,t,i){i=this.locInfo(i);for(var r=e?"@":"",n=[],s=0,a=0,h=t.length;a<h;a++){var l=t[a].part,c=t[a].original!==l;if(r+=(t[a].separator||"")+l,c||".."!==l&&"."!==l&&"this"!==l)n.push(l);else{if(n.length>0)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;i<e.length;i++)if(!n(e[i],t[i]))return!1;return!0}}function o(e){if(!e.path.parts){var t=e.path;e.path={type:"PathExpression",data:!1,depth:0,parts:[t.original+""],original:t.original+"",loc:t.loc}}}var s=i(1).default;t.__esModule=!0,t.Compiler=r,t.precompile=function(e,t,i){if(null==e||"string"!=typeof e&&"Program"!==e.type)throw new a.default("You must pass a string or Handlebars AST to Handlebars.precompile. You passed "+e);"data"in(t=t||{})||(t.data=!0),t.compat&&(t.useDepths=!0);var r=i.parse(e,t),n=(new i.Compiler).compile(r,t);return(new i.JavaScriptCompiler).compile(n,t)},t.compile=function(e,t,i){function r(){var r=i.parse(e,t),n=(new i.Compiler).compile(r,t),o=(new i.JavaScriptCompiler).compile(n,t,void 0,!0);return i.template(o)}function n(e,t){return o||(o=r()),o.call(this,e,t)}if(void 0===t&&(t={}),null==e||"string"!=typeof e&&"Program"!==e.type)throw new a.default("You must pass a string or Handlebars AST to Handlebars.compile. You passed "+e);"data"in(t=h.extend({},t))||(t.data=!0),t.compat&&(t.useDepths=!0);var o=void 0;return n._setup=function(e){return o||(o=r()),o._setup(e)},n._child=function(e,t,i,n){return o||(o=r()),o._child(e,t,i,n)},n};var a=s(i(6)),h=i(5),l=s(i(35)),c=[].slice;r.prototype={compiler:r,equals:function(e){var t=this.opcodes.length;if(e.opcodes.length!==t)return!1;for(var i=0;i<t;i++){var r=this.opcodes[i],o=e.opcodes[i];if(r.opcode!==o.opcode||!n(r.args,o.args))return!1}t=this.children.length;for(i=0;i<t;i++)if(!this.children[i].equals(e.children[i]))return!1;return!0},guid:0,compile:function(e,t){this.sourceNode=[],this.opcodes=[],this.children=[],this.options=t,this.stringParams=t.stringParams,this.trackIds=t.trackIds,t.blockParams=t.blockParams||[];var i=t.knownHelpers;if(t.knownHelpers={helperMissing:!0,blockHelperMissing:!0,each:!0,if:!0,unless:!0,with:!0,log:!0,lookup:!0},i)for(var r in i)r in i&&(this.options.knownHelpers[r]=i[r]);return this.accept(e)},compileProgram:function(e){var t=(new this.compiler).compile(e,this.options),i=this.guid++;return this.usePartial=this.usePartial||t.usePartial,this.children[i]=t,this.useDepths=this.useDepths||t.useDepths,i},accept:function(e){if(!this[e.type])throw new a.default("Unknown type: "+e.type,e);this.sourceNode.unshift(e);var t=this[e.type](e);return this.sourceNode.shift(),t},Program:function(e){this.options.blockParams.unshift(e.blockParams);for(var t=e.body,i=t.length,r=0;r<i;r++)this.accept(t[r]);return this.options.blockParams.shift(),this.isSimple=1===i,this.blockParams=e.blockParams?e.blockParams.length:0,this},BlockStatement:function(e){o(e);var t=e.program,i=e.inverse;t=t&&this.compileProgram(t),i=i&&this.compileProgram(i);var r=this.classifySexpr(e);"helper"===r?this.helperSexpr(e,t,i):"simple"===r?(this.simpleSexpr(e),this.opcode("pushProgram",t),this.opcode("pushProgram",i),this.opcode("emptyHash"),this.opcode("blockValue",e.path.original)):(this.ambiguousSexpr(e,t,i),this.opcode("pushProgram",t),this.opcode("pushProgram",i),this.opcode("emptyHash"),this.opcode("ambiguousBlockValue")),this.opcode("append")},DecoratorBlock:function(e){var t=e.program&&this.compileProgram(e.program),i=this.setupFullMustacheParams(e,t,void 0),r=e.path;this.useDecorators=!0,this.opcode("registerDecorator",i.length,r.original)},PartialStatement:function(e){this.usePartial=!0;var t=e.program;t&&(t=this.compileProgram(e.program));var i=e.params;if(i.length>1)throw new a.default("Unsupported number of partial arguments: "+i.length,e);i.length||(this.options.explicitPartialContext?this.opcode("pushLiteral","undefined"):i.push({type:"PathExpression",parts:[],depth:0}));var r=e.name.original,n="SubExpression"===e.name.type;n&&this.accept(e.name),this.setupFullMustacheParams(e,t,void 0,!0);var o=e.indent||"";this.options.preventIndent&&o&&(this.opcode("appendContent",o),o=""),this.opcode("invokePartial",n,r,o),this.opcode("append")},PartialBlockStatement:function(e){this.PartialStatement(e)},MustacheStatement:function(e){this.SubExpression(e),e.escaped&&!this.options.noEscape?this.opcode("appendEscaped"):this.opcode("append")},Decorator:function(e){this.DecoratorBlock(e)},ContentStatement:function(e){e.value&&this.opcode("appendContent",e.value)},CommentStatement:function(){},SubExpression:function(e){o(e);var t=this.classifySexpr(e);"simple"===t?this.simpleSexpr(e):"helper"===t?this.helperSexpr(e):this.ambiguousSexpr(e)},ambiguousSexpr:function(e,t,i){var r=e.path,n=r.parts[0],o=null!=t||null!=i;this.opcode("getContext",r.depth),this.opcode("pushProgram",t),this.opcode("pushProgram",i),r.strict=!0,this.accept(r),this.opcode("invokeAmbiguous",n,o)},simpleSexpr:function(e){var t=e.path;t.strict=!0,this.accept(t),this.opcode("resolvePossibleLambda")},helperSexpr:function(e,t,i){var r=this.setupFullMustacheParams(e,t,i),n=e.path,o=n.parts[0];if(this.options.knownHelpers[o])this.opcode("invokeKnownHelper",r.length,o);else{if(this.options.knownHelpersOnly)throw new a.default("You specified knownHelpersOnly, but used the unknown helper "+o,e);n.strict=!0,n.falsy=!0,this.accept(n),this.opcode("invokeHelper",r.length,n.original,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<r;i++)this.pushParam(t[i].value);for(;i--;)this.opcode("assignToHash",t[i].key);this.opcode("popHash")},opcode:function(e){this.opcodes.push({opcode:e,args:c.call(arguments,1),loc:this.sourceNode[0].loc})},addDepth:function(e){e&&(this.useDepths=!0)},classifySexpr:function(e){var t=l.default.helpers.simpleId(e.path),i=t&&!!this.blockParamIndex(e.path.parts[0]),r=!i&&l.default.helpers.helperExpression(e),n=!i&&(r||t);if(n&&!r){var o=e.path.parts[0],s=this.options;s.knownHelpers[o]?r=!0:s.knownHelpersOnly&&(n=!1)}return r?"helper":n?"ambiguous":"simple"},pushParams:function(e){for(var t=0,i=e.length;t<i;t++)this.pushParam(e[t])},pushParam:function(e){var t=null!=e.value?e.value:e.original||"";if(this.stringParams)t.replace&&(t=t.replace(/^(\.?\.\/)*/g,"").replace(/\//g,".")),e.depth&&this.addDepth(e.depth),this.opcode("getContext",e.depth||0),this.opcode("pushStringParam",t,e.type),"SubExpression"===e.type&&this.accept(e);else{if(this.trackIds){var i=void 0;if(!e.parts||l.default.helpers.scopedId(e)||e.depth||(i=this.blockParamIndex(e.parts[0])),i){var r=e.parts.slice(1).join(".");this.opcode("pushId","BlockParam",i,r)}else t=e.original||t,t.replace&&(t=t.replace(/^this(?:\.|$)/,"").replace(/^\.\//,"").replace(/^\.$/,"")),this.opcode("pushId",e.type,t)}this.accept(e)}},setupFullMustacheParams:function(e,t,i,r){var n=e.params;return this.pushParams(n),this.opcode("pushProgram",t),this.opcode("pushProgram",i),e.hash?this.accept(e.hash):this.opcode("emptyHash",r),n},blockParamIndex:function(e){for(var t=0,i=this.options.blockParams.length;t<i;t++){var r=this.options.blockParams[t],n=r&&h.indexOf(r,e);if(r&&n>=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;h<l;h++)o=n[h],this.source.currentLocation=o.loc,s=s||o.loc,this[o.opcode].apply(this,o.args);if(this.source.currentLocation=s,this.pushSource(""),this.stackSlot||this.inlineStack.length||this.compileStack.length)throw new a.default("Compile completed with content left on stack");this.decorators.isEmpty()?this.decorators=void 0:(this.useDecorators=!0,this.decorators.prepend("var decorators = container.decorators;\n"),this.decorators.push("return fn;"),r?this.decorators=Function.apply(this,["fn","props","container","depth0","data","blockParams","depths",this.decorators.merge()]):(this.decorators.prepend("function(fn, props, container, depth0, data, blockParams, depths) {\n"),this.decorators.push("}\n"),this.decorators=this.decorators.merge()));var c=this.createFunctionContext(r);if(this.isChild)return c;var u={compiler:this.compilerInfo(),main:c};this.decorators&&(u.main_d=this.decorators,u.useDecorators=!0);var p=this.context,f=p.programs,d=p.decorators;for(h=0,l=f.length;h<l;h++)f[h]&&(u[h]=f[h],d[h]&&(u[h+"_d"]=d[h],u.useDecorators=!0));return this.environment.usePartial&&(u.usePartial=!0),this.options.data&&(u.useData=!0),this.useDepths&&(u.useDepths=!0),this.useBlockParams&&(u.useBlockParams=!0),this.options.compat&&(u.compat=!0),r?u.compilerOptions=this.options:(u.compiler=JSON.stringify(u.compiler),this.source.currentLocation={start:{line:1,column:0}},u=this.objectLiteral(u),t.srcName?(u=u.toStringWithSourceMap({file:t.destName})).map=u.map&&u.map.toString():u=u.toString()),u},preamble:function(){this.lastContext=0,this.source=new l.default(this.options.srcName),this.decorators=new l.default(this.options.srcName)},createFunctionContext:function(e){var t="",i=this.stackVars.concat(this.registers.list);i.length>0&&(t+=", "+i.join(", "));var r=0;for(var n in this.aliases){var o=this.aliases[n];this.aliases.hasOwnProperty(n)&&o.children&&o.referenceCount>1&&(t+=", alias"+ ++r+"="+n,o.children[0]="alias"+r)}var s=["container","depth0","helpers","partials","data"];(this.useBlockParams||this.useDepths)&&s.push("blockParams"),this.useDepths&&s.push("depths");var a=this.mergeSource(t);return e?(s.push(a),Function.apply(this,s)):this.source.wrap(["function(",s.join(","),") {\n ",a,"}"])},mergeSource:function(e){var t=this.environment.isSimple,i=!this.forceBuffer,r=void 0,n=void 0,o=void 0,s=void 0;return this.source.each(function(e){e.appendToBuffer?(o?e.prepend(" + "):o=e,s=e):(o&&(n?o.prepend("buffer += "):r=!0,s.add(";"),o=s=void 0),n=!0,t||(i=!1))}),i?o?(o.prepend("return "),s.add(";")):n||this.source.push('return "";'):(e+=", buffer = "+(r?"":this.initializeBuffer()),o?(o.prepend("return buffer + "),s.add(";")):this.source.push("return buffer;")),e&&this.source.prepend("var "+e.substring(2)+(r?"":";\n")),this.source.merge()},blockValue:function(e){var t=this.aliasable("helpers.blockHelperMissing"),i=[this.contextName(0)];this.setupHelperArgs(e,0,i);var r=this.popStack();i.splice(1,0,r),this.push(this.source.functionCall(t,"call",i))},ambiguousBlockValue:function(){var e=this.aliasable("helpers.blockHelperMissing"),t=[this.contextName(0)];this.setupHelperArgs("",0,t,!0),this.flushInline();var i=this.topStack();t.splice(1,0,i),this.pushSource(["if (!",this.lastHelper,") { ",i," = ",this.source.functionCall(e,"call",t),"}"])},appendContent:function(e){this.pendingContent?e=this.pendingContent+e:this.pendingLocation=this.source.currentLocation,this.pendingContent=e},append:function(){if(this.isInline())this.replaceStack(function(e){return[" != null ? ",e,' : ""']}),this.pushSource(this.appendToBuffer(this.popStack()));else{var e=this.popStack();this.pushSource(["if (",e," != null) { ",this.appendToBuffer(e,void 0,!0)," }"]),this.environment.isSimple&&this.pushSource(["else { ",this.appendToBuffer("''",void 0,!0)," }"])}},appendEscaped:function(){this.pushSource(this.appendToBuffer([this.aliasable("container.escapeExpression"),"(",this.popStack(),")"]))},getContext:function(e){this.lastContext=e},pushContext:function(){this.pushStackLiteral(this.contextName(this.lastContext))},lookupOnContext:function(e,t,i,r){var n=0;r||!this.options.compat||this.lastContext?this.pushContext():this.push(this.depthedLookup(e[n++])),this.resolvePath("context",e,n,t,i)},lookupBlockParam:function(e,t){this.useBlockParams=!0,this.push(["blockParams[",e[0],"][",e[1],"]"]),this.resolvePath("context",t,1)},lookupData:function(e,t,i){e?this.pushStackLiteral("container.data(data, "+e+")"):this.pushStackLiteral("data"),this.resolvePath("data",t,0,!0,i)},resolvePath:function(e,t,i,r,n){var 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--;o<s;o++)n=t.nameLookup(n,i[o],r);return e?[t.aliasable("container.strict"),"(",n,", ",t.quotedString(i[o]),")"]:n}(this.options.strict&&n,this,t,e));else for(var s=t.length;i<s;i++)this.replaceStack(function(n){var s=o.nameLookup(n,t[i],e);return r?[" && ",s]:[" != null ? ",s," : ",n]})},resolvePossibleLambda:function(){this.push([this.aliasable("container.lambda"),"(",this.popStack(),", ",this.contextName(0),")"])},pushStringParam:function(e,t){this.pushContext(),this.pushString(t),"SubExpression"!==t&&("string"==typeof e?this.pushString(e):this.pushStackLiteral(e))},emptyHash:function(e){this.trackIds&&this.push("{}"),this.stringParams&&(this.push("{}"),this.push("{}")),this.pushStackLiteral(e?"undefined":"{}")},pushHash:function(){this.hash&&this.hashes.push(this.hash),this.hash={values:[],types:[],contexts:[],ids:[]}},popHash:function(){var e=this.hash;this.hash=this.hashes.pop(),this.trackIds&&this.push(this.objectLiteral(e.ids)),this.stringParams&&(this.push(this.objectLiteral(e.contexts)),this.push(this.objectLiteral(e.types))),this.push(this.objectLiteral(e.values))},pushString:function(e){this.pushStackLiteral(this.quotedString(e))},pushLiteral:function(e){this.pushStackLiteral(e)},pushProgram:function(e){null!=e?this.pushStackLiteral(this.programExpression(e)):this.pushStackLiteral(null)},registerDecorator:function(e,t){var i=this.nameLookup("decorators",t,"decorator"),r=this.setupHelperArgs(t,e);this.decorators.push(["fn = ",this.decorators.functionCall(i,"",["fn","props","container",r])," || fn;"])},invokeHelper:function(e,t,i){var r=this.popStack(),n=this.setupHelper(e,t),o=i?[n.name," || "]:"",s=["("].concat(o,r);this.options.strict||s.push(" || ",this.aliasable("helpers.helperMissing")),s.push(")"),this.push(this.source.functionCall(s,"call",n.callParams))},invokeKnownHelper:function(e,t){var i=this.setupHelper(e,t);this.push(this.source.functionCall(i.name,"call",i.callParams))},invokeAmbiguous:function(e,t){this.useRegister("helper");var i=this.popStack();this.emptyHash();var r=this.setupHelper(0,e,t),n=["(","(helper = ",this.lastHelper=this.nameLookup("helpers",e,"helper")," || ",i,")"];this.options.strict||(n[0]="(helper = ",n.push(" != null ? helper : ",this.aliasable("helpers.helperMissing"))),this.push(["(",n,r.paramsInit?["),(",r.paramsInit]:[],"),","(typeof helper === ",this.aliasable('"function"')," ? ",this.source.functionCall("helper","call",r.callParams)," : helper))"])},invokePartial:function(e,t,i){var r=[],n=this.setupParams(t,1,r);e&&(t=this.popStack(),delete n.name),i&&(n.indent=JSON.stringify(i)),n.helpers="helpers",n.partials="partials",n.decorators="container.decorators",e?r.unshift(t):r.unshift(this.nameLookup("partials",t,"partial")),this.options.compat&&(n.depths="depths"),n=this.objectLiteral(n),r.push(n),this.push(this.source.functionCall("container.invokePartial","",r))},assignToHash:function(e){var t=this.popStack(),i=void 0,r=void 0,n=void 0;this.trackIds&&(n=this.popStack()),this.stringParams&&(r=this.popStack(),i=this.popStack());var o=this.hash;i&&(o.contexts[e]=i),r&&(o.types[e]=r),n&&(o.ids[e]=n),o.values[e]=t},pushId:function(e,t,i){"BlockParam"===e?this.pushStackLiteral("blockParams["+t[0]+"].path["+t[1]+"]"+(i?" + "+JSON.stringify("."+i):"")):"PathExpression"===e?this.pushString(t):"SubExpression"===e?this.pushStackLiteral("true"):this.pushStackLiteral("null")},compiler:n,compileChildren:function(e,t){for(var i=e.children,r=void 0,n=void 0,o=0,s=i.length;o<s;o++){r=i[o],n=new this.compiler;var a=this.matchExistingProgram(r);if(null==a){this.context.programs.push("");var h=this.context.programs.length;r.index=h,r.name="program"+h,this.context.programs[h]=n.compile(r,t,this.context,!this.precompile),this.context.decorators[h]=n.decorators,this.context.environments[h]=r,this.useDepths=this.useDepths||n.useDepths,this.useBlockParams=this.useBlockParams||n.useBlockParams,r.useDepths=this.useDepths,r.useBlockParams=this.useBlockParams}else r.index=a.index,r.name="program"+a.index,this.useDepths=this.useDepths||a.useDepths,this.useBlockParams=this.useBlockParams||a.useBlockParams}},matchExistingProgram:function(e){for(var t=0,i=this.context.environments.length;t<i;t++){var r=this.context.environments[t];if(r&&r.equals(e))return r}},programExpression:function(e){var t=this.environment.children[e],i=[t.index,"data",t.blockParams];return(this.useBlockParams||this.useDepths)&&i.push("blockParams"),this.useDepths&&i.push("depths"),"container.program("+i.join(", ")+")"},useRegister:function(e){this.registers[e]||(this.registers[e]=!0,this.registers.list.push(e))},push:function(e){return e instanceof r||(e=this.source.wrap(e)),this.inlineStack.push(e),e},pushStackLiteral:function(e){this.push(new r(e))},pushSource:function(e){this.pendingContent&&(this.source.push(this.appendToBuffer(this.source.quotedString(this.pendingContent),this.pendingLocation)),this.pendingContent=void 0),e&&this.source.push(e)},replaceStack:function(e){var t=["("],i=void 0,n=void 0,o=void 0;if(!this.isInline())throw new a.default("replaceStack on non-inline");var s=this.popStack(!0);if(s instanceof r)i=[s.value],t=["(",i],o=!0;else{n=!0;var h=this.incrStack();t=["((",this.push(h)," = ",s,")"],i=this.topStack()}var l=e.call(this,i);o||this.popStack(),n&&this.stackSlot--,this.push(t.concat(l,")"))},incrStack:function(){return this.stackSlot++,this.stackSlot>this.stackVars.length&&this.stackVars.push("stack"+this.stackSlot),this.topStackName()},topStackName:function(){return"stack"+this.stackSlot},flushInline:function(){var e=this.inlineStack;this.inlineStack=[];for(var t=0,i=e.length;t<i;t++){var n=e[t];if(n instanceof r)this.compileStack.push(n);else{var o=this.incrStack();this.pushSource([o," = ",n,";"]),this.compileStack.push(o)}}},isInline:function(){return this.inlineStack.length},popStack:function(e){var t=this.isInline(),i=(t?this.inlineStack:this.compileStack).pop();if(!e&&i instanceof r)return i.value;if(!t){if(!this.stackSlot)throw new a.default("Invalid stack pop");this.stackSlot--}return i},topStack:function(){var e=this.isInline()?this.inlineStack:this.compileStack,t=e[e.length-1];return t instanceof r?t.value:t},contextName:function(e){return this.useDepths&&e?"depths["+e+"]":"depth"+e},quotedString:function(e){return this.source.quotedString(e)},objectLiteral:function(e){return this.source.objectLiteral(e)},aliasable:function(e){var t=this.aliases[e];return t?(t.referenceCount++,t):((t=this.aliases[e]=this.source.wrap(e)).aliasable=!0,t.referenceCount=1,t)},setupHelper:function(e,t,i){var r=[];return{params:r,paramsInit:this.setupHelperArgs(t,e,r,i),name:this.nameLookup("helpers",t,"helper"),callParams:[this.aliasable(this.contextName(0)+" != null ? "+this.contextName(0)+" : (container.nullContext || {})")].concat(r)}},setupParams:function(e,t,i){var r={},n=[],o=[],s=[],a=!i,h=void 0;a&&(i=[]),r.name=this.quotedString(e),r.hash=this.popStack(),this.trackIds&&(r.hashIds=this.popStack()),this.stringParams&&(r.hashTypes=this.popStack(),r.hashContexts=this.popStack());var l=this.popStack(),c=this.popStack();(c||l)&&(r.fn=c||"container.noop",r.inverse=l||"container.noop");for(var u=t;u--;)h=this.popStack(),i[u]=h,this.trackIds&&(s[u]=this.popStack()),this.stringParams&&(o[u]=this.popStack(),n[u]=this.popStack());return a&&(r.args=this.source.generateArray(i)),this.trackIds&&(r.ids=this.source.generateArray(s)),this.stringParams&&(r.types=this.source.generateArray(o),r.contexts=this.source.generateArray(n)),this.options.data&&(r.data="data"),this.useBlockParams&&(r.blockParams="blockParams"),r},setupHelperArgs:function(e,t,i,r){var n=this.setupParams(e,t,i);return n=this.objectLiteral(n),r?(this.useRegister("options"),i.push("options"),["options=",n]):i?(i.push(n),""):n}},function(){for(var e="break else new var case finally return void catch for switch while continue function this with default if throw delete in try do instanceof typeof abstract enum int short boolean export interface static byte extends long super char final native synchronized class float package throws const goto private transient debugger implements protected volatile double import public let yield await null true false".split(" "),t=n.RESERVED_WORDS={},i=0,r=e.length;i<r;i++)t[e[i]]=!0}(),n.isValidJavaScriptVariableName=function(e){return!n.RESERVED_WORDS[e]&&/^[a-zA-Z_$][0-9a-zA-Z_$]*$/.test(e)},t.default=n,e.exports=t.default},function(e,t,i){"use strict";function r(e,t,i){if(o.isArray(e)){for(var r=[],n=0,s=e.length;n<s;n++)r.push(t.wrap(e[n],i));return r}return"boolean"==typeof e||"number"==typeof e?e+"":e}function n(e){this.srcFile=e,this.source=[]}t.__esModule=!0;var o=i(5),s=void 0;s||((s=function(e,t,i,r){this.src="",r&&this.add(r)}).prototype={add:function(e){o.isArray(e)&&(e=e.join("")),this.src+=e},prepend:function(e){o.isArray(e)&&(e=e.join("")),this.src=e+this.src},toStringWithSourceMap:function(){return{code:this.toString()}},toString:function(){return this.src}}),n.prototype={isEmpty:function(){return!this.source.length},prepend:function(e,t){this.source.unshift(this.wrap(e,t))},push:function(e,t){this.source.push(this.wrap(e,t))},merge:function(){var e=this.empty();return this.each(function(t){e.add([" ",t,"\n"])}),e},each:function(e){for(var t=0,i=this.source.length;t<i;t++)e(this.source[t])},empty:function(){var e=this.currentLocation||{start:{}};return new s(e.start.line,e.start.column,this.srcFile)},wrap:function(e){var t=arguments.length<=1||void 0===arguments[1]?this.currentLocation||{start:{}}:arguments[1];return e instanceof s?e:(e=r(e,this,t),new s(t.start.line,t.start.column,this.srcFile,e))},functionCall:function(e,t,i){return i=this.generateList(i),this.wrap([e,t?"."+t+"(":"(",i,")"])},quotedString:function(e){return'"'+(e+"").replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")+'"'},objectLiteral:function(e){var t=[];for(var i in e)if(e.hasOwnProperty(i)){var n=r(e[i],this);"undefined"!==n&&t.push([this.quotedString(i),":",n])}var o=this.generateList(t);return o.prepend("{"),o.add("}"),o},generateList:function(e){for(var t=this.empty(),i=0,n=e.length;i<n;i++)i&&t.add(","),t.add(r(e[i],this));return t},generateArray:function(e){var t=this.generateList(e);return t.prepend("["),t.add("]"),t}},t.default=n,e.exports=t.default}])},e.exports=r()},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function(){function e(e){var t=this;this.templateManager=e,this.callbacksContainer={},this.templateManager.onEventTriggered.add(function(e){t.eventTriggered(e)})}return e.prototype.registerCallback=function(e,t,i,r){this.callbacksContainer[e]||(this.callbacksContainer[e]=[]),this.callbacksContainer[e].push({eventType:i,callback:t})},e.prototype.unregisterCallback=function(e,t,i,r){var n=this.callbacksContainer[e]||[];this.callbacksContainer[e]=n.filter(function(e){return!(e.eventType&&e.eventType!==i||e.selector&&e.selector!==r)})},e.prototype.eventTriggered=function(e){var t=e.template.name,i=e.event.type,r=e.selector;(this.callbacksContainer[t]||[]).filter(function(e){return!(e.eventType&&e.eventType!==i||e.selector&&e.selector!==r)}).forEach(function(t){t.callback(e)})},e}();t.EventManager=r},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=i(2),n=i(21),o=i(28),s=function(){function e(){this.configurationCache={}}return e.prototype.loadConfiguration=function(e){void 0===e&&(e={});var t=o({},e),i=n.getConfigurationType(t&&t.extends);if((t=o(i,t)).configuration){var s="json",a=t.configuration;t.configuration.url&&(a=t.configuration.url,(s=t.configuration.mapper)||(s=t.configuration.url.split(".").pop()));var h=r.mapperManager.getMapper(s);return this.loadFile(a).then(function(e){var i=h.map(e);return o(t,i)})}return Promise.resolve(t)},e.prototype.getConfigurationType=function(e){},e.prototype.loadFile=function(e){var t=this.configurationCache;return t[e]?Promise.resolve(t[e]):new Promise(function(i,r){var n=new XMLHttpRequest;n.open("GET",e),n.send(),n.onreadystatechange=function(){4===n.readyState&&(200===n.status?(t[e]=n.responseText,i(n.responseText)):(console.log("Error: "+n.status,e),r("Error: "+n.status)))}})},e}();t.ConfigurationLoader=s,t.configurationLoader=new s,t.default=t.configurationLoader},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=i(22);t.minimalConfiguration=r.minimalConfiguration;var n=i(23);t.defaultConfiguration=n.defaultConfiguration;t.getConfigurationType=function(e){switch(e){case"default":return n.defaultConfiguration;case"minimal":return r.minimalConfiguration;default:return n.defaultConfiguration}}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.minimalConfiguration={version:"0.1",templates:{main:{html:i(7)},loadingScreen:{html:i(8),params:{backgroundColor:"#000000",loadingImage:i(9)}},viewer:{html:i(10)},overlay:{html:i(11),params:{closeImage:i(12),closeText:"Close"}},error:{html:i(13)}},engine:{antialiasing:!0}}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.defaultConfiguration={version:"0.1",templates:{main:{html:i(7)},loadingScreen:{html:i(8),params:{backgroundColor:"#000000",loadingImage:i(9)}},viewer:{html:i(10),events:{pointerout:!0,pointerdown:!0,pointerup:!0}},navBar:{html:i(24),params:{buttons:{"fullscreen-button":{altText:"Fullscreen",image:i(25)}},visibilityTimeout:2e3},events:{pointerdown:{"fullscreen-button":!0},pointerover:!0}},overlay:{html:i(11),params:{closeImage:i(12),closeText:"Close"}},help:{html:i(26)},share:{html:i(27)},error:{html:i(13)}},camera:{behaviors:{autoRotate:0,framing:{type:2,zoomOnBoundingInfo:!0,zoomStopsAnimation:!1}}},skybox:{cubeTexture:{url:"https://playground.babylonjs.com/textures/environment.dds",gammaSpace:!1},pbr:!0,blur:.7,infiniteDIstance:!1,material:{imageProcessingConfiguration:{colorCurves:{globalDensity:89,globalHue:58.88,globalSaturation:94},colorCurvesEnabled:!0,exposure:1.5,contrast:1.66,toneMappingEnabled:!0,vignetteEnabled:!0,vignetteWeight:5,vignetteColor:{r:.8,g:.6,b:.4},vignetteM:!0}}},ground:!0,engine:{antialiasing:!0},scene:{imageProcessingConfiguration:{exposure:1.4,contrast:1.66,toneMappingEnabled:!0}}}},function(e,t){e.exports='<style>nav-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%}</style> {{#if disableOnFullscreen}} <style>viewer:fullscreen nav-bar{display:none}viewer:-moz-full-screen nav-bar{display:none}viewer:-webkit-full-screen nav-bar{display:none}</style> {{/if}} <div class=flex-container id=model-metadata> <div class=thumbnail> </div> <div class=title-container> <span class=model-title>{{#if title}}{{title}}{{/if}}</span> <span class=model-subtitle> {{#if subtitle}}{{subtitle}} {{/if}}</span> </div> </div> <div class="button-container flex-container"> {{#eachInMap buttons}} <div id={{id}} class=button> {{#if text}} <span>{{text}}</span>> {{/if}} {{#if image}} <img src={{image}} alt={{altText}}> {{/if}} </div> {{/eachInMap}} </div>'},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){var r;r=function(){"use strict";var e=function(e){return!(o=e,!o||"object"!=typeof o||(i=e,r=Object.prototype.toString.call(i),"[object RegExp]"===r||"[object Date]"===r||(n=i,n.$$typeof===t)));var i,r,n,o};var t="function"==typeof Symbol&&Symbol.for?Symbol.for("react.element"):60103;function i(t,i){var r;return(!i||!1!==i.clone)&&e(t)?n((r=t,Array.isArray(r)?[]:{}),t,i):t}function r(e,t,r){return e.concat(t).map(function(e){return i(e,r)})}function n(t,o,s){var a,h,l,c,u=Array.isArray(o);return u===Array.isArray(t)?u?((s||{arrayMerge:r}).arrayMerge||r)(t,o,s):(h=o,l=s,c={},e(a=t)&&Object.keys(a).forEach(function(e){c[e]=i(a[e],l)}),Object.keys(h).forEach(function(t){e(h[t])&&a[t]?c[t]=n(a[t],h[t],l):c[t]=i(h[t],l)}),c):i(o,s)}return n.all=function(e,t){if(!Array.isArray(e))throw new Error("first argument should be an array");return e.reduce(function(e,i){return n(e,i,t)},{})},n},e.exports=r()},function(e,t,i){"use strict";var r,n=this&&this.__extends||(r=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])},function(e,t){function i(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(i.prototype=t.prototype,new i)});Object.defineProperty(t,"__esModule",{value:!0});var o=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return n(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=o},function(e,t,i){(function(t){var r,n,o,s,a,h,l,c,u,p,f,d,m,g,_,v,y,b,x,T,E,A,P,M,S,C,R,O,I,w,D,L,B,N,F,V,k,U,z,G,W,H,j,X,Y,K,Q,Z,q,J,$,ee,te,ie=void 0!==t?t:"undefined"!=typeof window?window:this,re=ie&&ie.BABYLON||re||i(0),ne=(this&&this.__decorate,this&&this.__extends||(r=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])},function(e,t){function i(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(i.prototype=t.prototype,new i)}));n=re||(re={}),o=function(){function e(){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 e.prototype.importMesh=function(e,t,i,r,o,s,a){var h;if(this.isBinary(i)){var l=new n.Mesh("stlmesh",t);return this.parseBinary(l,i),o&&o.push(l),!0}for(var c=new Uint8Array(i),u="",p=0;p<i.byteLength;p++)u+=String.fromCharCode(c[p]);for(i=u;h=this.solidPattern.exec(i);){var f=h[1];if(f!=h[3])return n.Tools.Error("Error in STL, solid name != endsolid name"),!1;if(e&&f)if(e instanceof Array){if(!e.indexOf(f))continue}else if(f!==e)continue;f=f||"stlmesh";l=new n.Mesh(f,t);this.parseASCII(l,h[2]),o&&o.push(l)}return!0},e.prototype.load=function(e,t,i){var r=this.importMesh(null,e,t,i,null,null,null);return r&&e.createDefaultCameraOrLight(),r},e.prototype.loadAssets=function(e,t,i,r){var o=new n.AssetContainer(e);return this.importMesh(null,e,t,i,o.meshes,null,null)?(o.removeAllFromScene(),o):null},e.prototype.isBinary=function(e){var t;if(50,84+50*(t=new DataView(e)).getUint32(80,!0)===t.byteLength)return!0;for(var i=t.byteLength,r=0;r<i;r++)if(t.getUint8(r)>127)return!0;return!1},e.prototype.parseBinary=function(e,t){for(var i=new DataView(t),r=i.getUint32(80,!0),o=0,s=new Float32Array(3*r*3),a=new Float32Array(3*r*3),h=new Uint32Array(3*r),l=0,c=0;c<r;c++){for(var u=84+50*c,p=i.getFloat32(u,!0),f=i.getFloat32(u+4,!0),d=i.getFloat32(u+8,!0),m=1;m<=3;m++){var g=u+12*m;s[o]=i.getFloat32(g,!0),s[o+2]=i.getFloat32(g+4,!0),s[o+1]=i.getFloat32(g+8,!0),a[o]=p,a[o+2]=f,a[o+1]=d,o+=3}h[l]=l++,h[l]=l++,h[l]=l++}e.setVerticesData(n.VertexBuffer.PositionKind,s),e.setVerticesData(n.VertexBuffer.NormalKind,a),e.setIndices(h),e.computeWorldMatrix(!0)},e.prototype.parseASCII=function(e,t){for(var i,r=[],o=[],s=[],a=0;i=this.facetsPattern.exec(t);){var h=i[1],l=this.normalPattern.exec(h);if(this.normalPattern.lastIndex=0,l){for(var c,u=[Number(l[1]),Number(l[5]),Number(l[3])];c=this.vertexPattern.exec(h);)r.push(Number(c[1]),Number(c[5]),Number(c[3])),o.push(u[0],u[1],u[2]);s.push(a++,a++,a++),this.vertexPattern.lastIndex=0}}this.facetsPattern.lastIndex=0,e.setVerticesData(n.VertexBuffer.PositionKind,r),e.setVerticesData(n.VertexBuffer.NormalKind,o),e.setIndices(s),e.computeWorldMatrix(!0)},e}(),n.STLFileLoader=o,n.SceneLoader&&n.SceneLoader.RegisterPlugin(new o),function(e){var t=function(){function t(){this.materials=[]}return t.prototype.parseMTL=function(i,r,n){for(var o,s=r.split("\n"),a=/\s+/,h=null,l=0;l<s.length;l++){var c=s[l].trim();if(0!==c.length&&"#"!==c.charAt(0)){var u=c.indexOf(" "),p=u>=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.loadAssets=function(t,i,r,n){var o=new e.AssetContainer(t);return this.importMesh(null,t,i,r,o.meshes,null,null)?(o.removeAllFromScene(),o):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;e<f.length;e++)y.push(f[e].x,f[e].y,f[e].z),b.push(m[e].x,m[e].y,m[e].z),x.push(d[e].x,d[e].y);f=[],m=[],d=[],g=[],_=0},O=function(e,t){t+1<e.length&&(T.push(e[0],e[t],e[t+1]),O(e,t+=1))},I=function(){u.length>0&&(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<w.length;D++){var L,B=w[D].trim();if(0!==B.length&&"#"!==B.charAt(0))if(null!==(L=this.vertexPattern.exec(B)))h.push(new e.Vector3(parseFloat(L[1]),parseFloat(L[2]),parseFloat(L[3])));else if(null!==(L=this.normalPattern.exec(B)))l.push(new e.Vector3(parseFloat(L[1]),parseFloat(L[2]),parseFloat(L[3])));else if(null!==(L=this.uvPattern.exec(B)))c.push(new e.Vector2(parseFloat(L[1]),parseFloat(L[2])));else if(null!==(L=this.facePattern3.exec(B)))!function(e,t){O(e,1);for(var i=0;i<T.length;i++){var r=T[i].split("/"),n=parseInt(r[0])-1,o=parseInt(r[1])-1,s=parseInt(r[2])-1;C(n,o,s,h[n],c[o],l[s])}T=[]}(L[1].trim().split(" "));else if(null!==(L=this.facePattern4.exec(B)))!function(t,i){O(t,1);for(var r=0;r<T.length;r++){var n=T[r].split("//"),o=parseInt(n[0])-1,s=parseInt(n[1])-1;C(o,1,s,h[o],e.Vector2.Zero(),l[s])}T=[]}(L[1].trim().split(" "));else if(null!==(L=this.facePattern2.exec(B)))!function(t,i){O(t,1);for(var r=0;r<T.length;r++){var n=T[r].split("/"),o=parseInt(n[0])-1,s=parseInt(n[1])-1;C(o,s,0,h[o],c[s],e.Vector3.Up())}T=[]}(L[1].trim().split(" "));else if(null!==(L=this.facePattern1.exec(B)))!function(t,i){O(t,1);for(var r=0;r<T.length;r++){var n=parseInt(T[r])-1;C(n,0,0,h[n],e.Vector2.Zero(),e.Vector3.Up())}T=[]}(L[1].trim().split(" "));else if(this.group.test(B)||this.obj.test(B)){var N={name:B.substring(2).trim(),indices:void 0,positions:void 0,normals:void 0,uvs:void 0,materialName:""};I(),u.push(N),v=!0,S=!0,M=1}else if(this.usemtl.test(B)){if(E=B.substring(7).trim(),!S){I();N={name:"_mm"+M.toString(),indices:void 0,positions:void 0,normals:void 0,uvs:void 0,materialName:E};M++,u.push(N)}v&&S&&(u[u.length-1].materialName=E,S=!1)}else this.mtllib.test(B)?A=B.substring(7).trim():this.smooth.test(B)||console.log("Unhandled expression at line : "+B)}v&&(a=u[u.length-1],p.reverse(),R(),a.indices=p,a.positions=y,a.normals=b,a.uvs=x),v||(p.reverse(),R(),u.push({name:e.Geometry.RandomId(),indices:p,positions:y,normals:b,uvs:x,materialName:E}));for(var F=[],V=new Array,k=0;k<u.length;k++){if(r&&u[k].name)if(r instanceof Array){if(-1==r.indexOf(u[k].name))continue}else if(u[k].name!==r)continue;a=u[k];var U=new e.Mesh(u[k].name,n);V.push(u[k].materialName);var z=new e.VertexData;z.positions=a.positions,z.normals=a.normals,z.uvs=a.uvs,z.indices=a.indices,z.applyToMesh(U),F.push(U)}return""!==A&&this._loadMTL(A,s,function(e){P.parseMTL(n,e,s);for(var t=0;t<P.materials.length;t++){for(var i,r=0,o=[];(i=V.indexOf(P.materials[t].name,r))>-1;)o.push(i),r=i+1;if(-1==i&&0==o.length)P.materials[t].dispose();else for(var a=0;a<o.length;a++)F[o[a]].material=P.materials[t]}}),F},i.OPTIMIZE_WITH_UV=!1,i}();e.OBJFileLoader=i,e.SceneLoader&&e.SceneLoader.RegisterPlugin(new i)}(re||(re={})),function(e){var t,i,r,n;(i=t=e.GLTFLoaderCoordinateSystemMode||(e.GLTFLoaderCoordinateSystemMode={}))[i.AUTO=0]="AUTO",i[i.FORCE_RIGHT_HANDED=1]="FORCE_RIGHT_HANDED",(n=r=e.GLTFLoaderAnimationStartMode||(e.GLTFLoaderAnimationStartMode={}))[n.NONE=0]="NONE",n[n.FIRST=1]="FIRST",n[n.ALL=2]="ALL";var o=function(){function i(){this.onParsedObservable=new e.Observable,this.coordinateSystemMode=t.AUTO,this.animationStartMode=r.FIRST,this.compileMaterials=!1,this.useClipPlane=!1,this.compileShadowGenerators=!1,this.onMeshLoadedObservable=new e.Observable,this.onTextureLoadedObservable=new e.Observable,this.onMaterialLoadedObservable=new e.Observable,this.onCompleteObservable=new e.Observable,this.onDisposeObservable=new e.Observable,this._loader=null,this.name="gltf",this.extensions={".gltf":{isBinary:!1},".glb":{isBinary:!0}}}return Object.defineProperty(i.prototype,"onParsed",{set:function(e){this._onParsedObserver&&this.onParsedObservable.remove(this._onParsedObserver),this._onParsedObserver=this.onParsedObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"onMeshLoaded",{set:function(e){this._onMeshLoadedObserver&&this.onMeshLoadedObservable.remove(this._onMeshLoadedObserver),this._onMeshLoadedObserver=this.onMeshLoadedObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"onTextureLoaded",{set:function(e){this._onTextureLoadedObserver&&this.onTextureLoadedObservable.remove(this._onTextureLoadedObserver),this._onTextureLoadedObserver=this.onTextureLoadedObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"onMaterialLoaded",{set:function(e){this._onMaterialLoadedObserver&&this.onMaterialLoadedObservable.remove(this._onMaterialLoadedObserver),this._onMaterialLoadedObserver=this.onMaterialLoadedObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"onComplete",{set:function(e){this._onCompleteObserver&&this.onCompleteObservable.remove(this._onCompleteObserver),this._onCompleteObserver=this.onCompleteObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"onDispose",{set:function(e){this._onDisposeObserver&&this.onDisposeObservable.remove(this._onDisposeObserver),this._onDisposeObserver=this.onDisposeObservable.add(e)},enumerable:!0,configurable:!0}),i.prototype.dispose=function(){this._loader&&(this._loader.dispose(),this._loader=null),this.onParsedObservable.clear(),this.onMeshLoadedObservable.clear(),this.onTextureLoadedObservable.clear(),this.onMaterialLoadedObservable.clear(),this.onCompleteObservable.clear(),this.onDisposeObservable.notifyObservers(this),this.onDisposeObservable.clear()},i.prototype.importMeshAsync=function(t,i,r,n,o,s,a){try{var h=this._parse(r);this._loader=this._getLoader(h),this._loader.importMeshAsync(t,i,h,n,o,s,a)}catch(t){a?a(t.message,t):e.Tools.Error(t.message)}},i.prototype.loadAsync=function(t,i,r,n,o,s){try{var a=this._parse(i);this._loader=this._getLoader(a),this._loader.loadAsync(t,a,r,n,o,s)}catch(t){s?s(t.message,t):e.Tools.Error(t.message)}},i.prototype.loadAssetsAsync=function(t,i,r,n,o,s){try{var a=this._parse(i);this._loader=this._getLoader(a),this._loader.importMeshAsync(null,t,a,r,function(i,r,o){var s=new e.AssetContainer(t);Array.prototype.push.apply(s.meshes,i),Array.prototype.push.apply(s.particleSystems,r),Array.prototype.push.apply(s.skeletons,o),s.removeAllFromScene(),n(s)},o,s)}catch(t){s?s(t.message,t):e.Tools.Error(t.message)}},i.prototype.canDirectLoad=function(e){return-1!==e.indexOf("scene")&&-1!==e.indexOf("node")},i.prototype.createPlugin=function(){return new i},i.prototype._parse=function(e){var t;return t=e instanceof ArrayBuffer?i._parseBinary(e):{json:JSON.parse(e),bin:null},this.onParsedObservable.notifyObservers(t),t},i.prototype._getLoader=function(e){var t=this,r=e.json.asset||{},n=i._parseVersion(r.version);if(!n)throw new Error("Invalid version: "+r.version);if(void 0!==r.minVersion){var o=i._parseVersion(r.minVersion);if(!o)throw new Error("Invalid minimum version: "+r.minVersion);if(i._compareVersion(o,{major:2,minor:0})>0)throw new Error("Incompatible minimum version: "+r.minVersion)}var s={1:i.CreateGLTFLoaderV1,2:i.CreateGLTFLoaderV2}[n.major];if(!s)throw new Error("Unsupported version: "+r.version);var a=s();return a.coordinateSystemMode=this.coordinateSystemMode,a.animationStartMode=this.animationStartMode,a.compileMaterials=this.compileMaterials,a.useClipPlane=this.useClipPlane,a.compileShadowGenerators=this.compileShadowGenerators,a.onMeshLoadedObservable.add(function(e){return t.onMeshLoadedObservable.notifyObservers(e)}),a.onTextureLoadedObservable.add(function(e){return t.onTextureLoadedObservable.notifyObservers(e)}),a.onMaterialLoadedObservable.add(function(e){return t.onMaterialLoadedObservable.notifyObservers(e)}),a.onCompleteObservable.add(function(){return t.onCompleteObservable.notifyObservers(t)}),a},i._parseBinary=function(e){var t=new s(e),r=t.readUint32();if(1179937895!==r)throw new Error("Unexpected magic: "+r);var n=t.readUint32();switch(n){case 1:return i._parseV1(t);case 2:return i._parseV2(t)}throw new Error("Unsupported version: "+n)},i._parseV1=function(e){var t=e.readUint32();if(t!=e.getLength())throw new Error("Length in header does not match actual data length: "+t+" != "+e.getLength());var r,n=e.readUint32(),o=e.readUint32();switch(o){case 0:r=JSON.parse(i._decodeBufferToText(e.readUint8Array(n)));break;default:throw new Error("Unexpected content format: "+o)}var s=e.getLength()-e.getPosition();return{json:r,bin:e.readUint8Array(s)}},i._parseV2=function(e){var t=1313821514,r=5130562,n=e.readUint32();if(n!==e.getLength())throw new Error("Length in header does not match actual data length: "+n+" != "+e.getLength());var o=e.readUint32();if(e.readUint32()!==t)throw new Error("First chunk format is not JSON");for(var s=JSON.parse(i._decodeBufferToText(e.readUint8Array(o))),a=null;e.getPosition()<e.getLength();){var h=e.readUint32();switch(e.readUint32()){case t:throw new Error("Unexpected JSON chunk");case r:a=e.readUint8Array(h);break;default:e.skipBytes(h)}}return{json:s,bin:a}},i._parseVersion=function(e){if("1.0"===e||"1.0.1"===e)return{major:1,minor:0};var t=(e+"").match(/^(\d+)\.(\d+)/);return t?{major:parseInt(t[1]),minor:parseInt(t[2])}:null},i._compareVersion=function(e,t){return e.major>t.major?1:e.major<t.major?-1:e.minor>t.minor?1:e.minor<t.minor?-1:0},i._decodeBufferToText=function(e){for(var t="",i=e.byteLength,r=0;r<i;r++)t+=String.fromCharCode(e[r]);return t},i.IncrementalLoading=!0,i.HomogeneousCoordinates=!1,i}();e.GLTFFileLoader=o;var s=function(){function e(e){this._arrayBuffer=e,this._dataView=new DataView(e),this._byteOffset=0}return e.prototype.getPosition=function(){return this._byteOffset},e.prototype.getLength=function(){return this._arrayBuffer.byteLength},e.prototype.readUint32=function(){var e=this._dataView.getUint32(this._byteOffset,!0);return this._byteOffset+=4,e},e.prototype.readUint8Array=function(e){var t=new Uint8Array(this._arrayBuffer,this._byteOffset,e);return this._byteOffset+=e,t},e.prototype.skipBytes=function(e){this._byteOffset+=e},e}();e.SceneLoader&&e.SceneLoader.RegisterPlugin(new o)}(re||(re={})),s=re||(re={}),a=s.GLTF1||(s.GLTF1={}),(h=a.EComponentType||(a.EComponentType={}))[h.BYTE=5120]="BYTE",h[h.UNSIGNED_BYTE=5121]="UNSIGNED_BYTE",h[h.SHORT=5122]="SHORT",h[h.UNSIGNED_SHORT=5123]="UNSIGNED_SHORT",h[h.FLOAT=5126]="FLOAT",(l=a.EShaderType||(a.EShaderType={}))[l.FRAGMENT=35632]="FRAGMENT",l[l.VERTEX=35633]="VERTEX",(c=a.EParameterType||(a.EParameterType={}))[c.BYTE=5120]="BYTE",c[c.UNSIGNED_BYTE=5121]="UNSIGNED_BYTE",c[c.SHORT=5122]="SHORT",c[c.UNSIGNED_SHORT=5123]="UNSIGNED_SHORT",c[c.INT=5124]="INT",c[c.UNSIGNED_INT=5125]="UNSIGNED_INT",c[c.FLOAT=5126]="FLOAT",c[c.FLOAT_VEC2=35664]="FLOAT_VEC2",c[c.FLOAT_VEC3=35665]="FLOAT_VEC3",c[c.FLOAT_VEC4=35666]="FLOAT_VEC4",c[c.INT_VEC2=35667]="INT_VEC2",c[c.INT_VEC3=35668]="INT_VEC3",c[c.INT_VEC4=35669]="INT_VEC4",c[c.BOOL=35670]="BOOL",c[c.BOOL_VEC2=35671]="BOOL_VEC2",c[c.BOOL_VEC3=35672]="BOOL_VEC3",c[c.BOOL_VEC4=35673]="BOOL_VEC4",c[c.FLOAT_MAT2=35674]="FLOAT_MAT2",c[c.FLOAT_MAT3=35675]="FLOAT_MAT3",c[c.FLOAT_MAT4=35676]="FLOAT_MAT4",c[c.SAMPLER_2D=35678]="SAMPLER_2D",(u=a.ETextureWrapMode||(a.ETextureWrapMode={}))[u.CLAMP_TO_EDGE=33071]="CLAMP_TO_EDGE",u[u.MIRRORED_REPEAT=33648]="MIRRORED_REPEAT",u[u.REPEAT=10497]="REPEAT",(p=a.ETextureFilterType||(a.ETextureFilterType={}))[p.NEAREST=9728]="NEAREST",p[p.LINEAR=9728]="LINEAR",p[p.NEAREST_MIPMAP_NEAREST=9984]="NEAREST_MIPMAP_NEAREST",p[p.LINEAR_MIPMAP_NEAREST=9985]="LINEAR_MIPMAP_NEAREST",p[p.NEAREST_MIPMAP_LINEAR=9986]="NEAREST_MIPMAP_LINEAR",p[p.LINEAR_MIPMAP_LINEAR=9987]="LINEAR_MIPMAP_LINEAR",(f=a.ETextureFormat||(a.ETextureFormat={}))[f.ALPHA=6406]="ALPHA",f[f.RGB=6407]="RGB",f[f.RGBA=6408]="RGBA",f[f.LUMINANCE=6409]="LUMINANCE",f[f.LUMINANCE_ALPHA=6410]="LUMINANCE_ALPHA",(d=a.ECullingType||(a.ECullingType={}))[d.FRONT=1028]="FRONT",d[d.BACK=1029]="BACK",d[d.FRONT_AND_BACK=1032]="FRONT_AND_BACK",(m=a.EBlendingFunction||(a.EBlendingFunction={}))[m.ZERO=0]="ZERO",m[m.ONE=1]="ONE",m[m.SRC_COLOR=768]="SRC_COLOR",m[m.ONE_MINUS_SRC_COLOR=769]="ONE_MINUS_SRC_COLOR",m[m.DST_COLOR=774]="DST_COLOR",m[m.ONE_MINUS_DST_COLOR=775]="ONE_MINUS_DST_COLOR",m[m.SRC_ALPHA=770]="SRC_ALPHA",m[m.ONE_MINUS_SRC_ALPHA=771]="ONE_MINUS_SRC_ALPHA",m[m.DST_ALPHA=772]="DST_ALPHA",m[m.ONE_MINUS_DST_ALPHA=773]="ONE_MINUS_DST_ALPHA",m[m.CONSTANT_COLOR=32769]="CONSTANT_COLOR",m[m.ONE_MINUS_CONSTANT_COLOR=32770]="ONE_MINUS_CONSTANT_COLOR",m[m.CONSTANT_ALPHA=32771]="CONSTANT_ALPHA",m[m.ONE_MINUS_CONSTANT_ALPHA=32772]="ONE_MINUS_CONSTANT_ALPHA",m[m.SRC_ALPHA_SATURATE=776]="SRC_ALPHA_SATURATE",function(e){var t,i;(i=t||(t={}))[i.IDENTIFIER=1]="IDENTIFIER",i[i.UNKNOWN=2]="UNKNOWN",i[i.END_OF_INPUT=3]="END_OF_INPUT";var r=function(){function e(e){this._pos=0,this.isLetterOrDigitPattern=/^[a-zA-Z0-9]+$/,this._toParse=e,this._maxPos=e.length}return e.prototype.getNextToken=function(){if(this.isEnd())return t.END_OF_INPUT;if(this.currentString=this.read(),this.currentToken=t.UNKNOWN,"_"===this.currentString||this.isLetterOrDigitPattern.test(this.currentString))for(this.currentToken=t.IDENTIFIER,this.currentIdentifier=this.currentString;!this.isEnd()&&(this.isLetterOrDigitPattern.test(this.currentString=this.peek())||"_"===this.currentString);)this.currentIdentifier+=this.currentString,this.forward();return this.currentToken},e.prototype.peek=function(){return this._toParse[this._pos]},e.prototype.read=function(){return this._toParse[this._pos++]},e.prototype.forward=function(){this._pos++},e.prototype.isEnd=function(){return this._pos>=this._maxPos},e}(),n=["MODEL","VIEW","PROJECTION","MODELVIEW","MODELVIEWPROJECTION","JOINTMATRIX"],o=["world","view","projection","worldView","worldViewProjection","mBones"],s=["translation","rotation","scale"],a=["position","rotationQuaternion","scaling"],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;t<e.length/2;t++)e[2*t+1]=1-e[2*t+1]},c=function(e){if("NORMAL"===e.semantic)return"normal";if("POSITION"===e.semantic)return"position";if("JOINT"===e.semantic)return"matricesIndices";if("WEIGHT"===e.semantic)return"matricesWeights";if("COLOR"===e.semantic)return"color";if(e.semantic&&-1!==e.semantic.indexOf("TEXCOORD_")){var t=Number(e.semantic.split("_")[1]);return"uv"+(0===t?"":t+1)}return null},u=function(e){var t=null;if(e.translation||e.rotation||e.scale){var i=g.Vector3.FromArray(e.scale||[1,1,1]),r=g.Quaternion.FromArray(e.rotation||[0,0,0,1]),n=g.Vector3.FromArray(e.translation||[0,0,0]);t=g.Matrix.Compose(i,r,n)}else t=g.Matrix.FromArray(e.matrix);return t},p=function(e,t,i,r){for(var n=0;n<r.bones.length;n++)if(r.bones[n].name===i)return r.bones[n];var o=e.nodes;for(var s in o){var a=o[s];if(a.jointName){var h=a.children;for(n=0;n<h.length;n++){var l=e.nodes[h[n]];if(l.jointName&&l.jointName===i){var c=u(a),f=new g.Bone(a.name||"",r,p(e,t,a.jointName,r),c);return f.id=s,f}}}}return null},f=function(e,t){for(var i=0;i<e.length;i++)for(var r=e[i],n=0;n<r.node.children.length;n++)if(r.node.children[n]===t)return r.bone;return null},d=function(e,t){var i=e.nodes,r=i[t];if(r)return{node:r,id:t};for(var n in i)if(r=i[n],r.jointName===t)return{node:r,id:n};return null},m=function(e,t){for(var i=0;i<e.jointNames.length;i++)if(e.jointNames[i]===t)return!0;return!1},_=function(e,t,i,r,n){if(r||(r=new g.Skeleton(t.name||"","",e.scene)),!t.babylonSkeleton)return r;var o=[],s=[];(function(e,t,i,r){for(var n in e.nodes){var o=e.nodes[n],s=n;if(o.jointName&&!m(i,o.jointName)){var a=u(o),h=new g.Bone(o.name||"",t,null,a);h.id=s,r.push({bone:h,node:o,id:s})}}for(var l=0;l<r.length;l++)for(var c=r[l],p=c.node.children,f=0;f<p.length;f++){for(var d=null,_=0;_<r.length;_++)if(r[_].id===p[f]){d=r[_];break}d&&(d.bone._parent=c.bone,c.bone.children.push(d.bone))}})(e,r,t,o),r.bones=[];for(var a=0;a<t.jointNames.length;a++)if(P=d(e,t.jointNames[a])){var h=P.node;if(h){n=P.id;var l=e.scene.getBoneByID(n);if(l)r.bones.push(l);else{for(var c=!1,_=null,v=0;v<a;v++){var y=d(e,t.jointNames[v]);if(y){var b=y.node;if(b){var x=b.children;if(x){c=!1;for(var T=0;T<x.length;T++)if(x[T]===n){_=p(e,t,t.jointNames[v],r),c=!0;break}if(c)break}}else g.Tools.Warn("Joint named "+t.jointNames[v]+" does not exist when looking for parent")}}var E=u(h);!_&&o.length>0&&(_=f(o,n))&&-1===s.indexOf(_)&&s.push(_),new g.Bone(h.jointName||"",r,_,E).id=n}}else g.Tools.Warn("Joint named "+t.jointNames[a]+" does not exist")}var A=r.bones;for(r.bones=[],a=0;a<t.jointNames.length;a++){var P;if(P=d(e,t.jointNames[a]))for(v=0;v<A.length;v++)if(A[v].id===P.id){r.bones.push(A[v]);break}}for(r.prepare(),a=0;a<s.length;a++)r.bones.push(s[a]);return r},v=function(t,i,r,n,o){if(o||((o=new g.Mesh(i.name||"",t.scene)).id=n),!i.babylonNode)return o;for(var s=[],a=new g.VertexData,h=new g.Geometry(n,t.scene,a,!1,o),c=new Array,u=new Array,p=new Array,f=new Array,d=0;d<r.length;d++){var m=r[d];if(w=t.meshes[m])for(var _=0;_<w.primitives.length;_++){var v=new g.VertexData,y=w.primitives[_];y.mode;var b=y.attributes,x=null,T=null;for(var E in b)if(x=t.accessors[b[E]],T=e.GLTFUtils.GetBufferFromAccessor(t,x),"NORMAL"===E)v.normals=new Float32Array(T.length),v.normals.set(T);else if("POSITION"===E){if(g.GLTFFileLoader.HomogeneousCoordinates){v.positions=new Float32Array(T.length-T.length/4);for(var A=0;A<T.length;A+=4)v.positions[A]=T[A],v.positions[A+1]=T[A+1],v.positions[A+2]=T[A+2]}else v.positions=new Float32Array(T.length),v.positions.set(T);u.push(v.positions.length)}else if(-1!==E.indexOf("TEXCOORD_")){var P=Number(E.split("_")[1]),M=g.VertexBuffer.UVKind+(0===P?"":P+1),S=new Float32Array(T.length);S.set(T),l(S),v.set(S,M)}else"JOINT"===E?(v.matricesIndices=new Float32Array(T.length),v.matricesIndices.set(T)):"WEIGHT"===E?(v.matricesWeights=new Float32Array(T.length),v.matricesWeights.set(T)):"COLOR"===E&&(v.colors=new Float32Array(T.length),v.colors.set(T));if(x=t.accessors[y.indices])T=e.GLTFUtils.GetBufferFromAccessor(t,x),v.indices=new Int32Array(T.length),v.indices.set(T),f.push(v.indices.length);else{var C=[];for(A=0;A<v.positions.length/3;A++)C.push(A);v.indices=new Int32Array(C),f.push(v.indices.length)}a.merge(v);var R=t.scene.getMaterialByID(y.material);s.push(null===R?e.GLTFUtils.GetDefaultMaterial(t.scene):R),c.push(0===c.length?0:c[c.length-1]+u[u.length-2]),p.push(0===p.length?0:p[p.length-1]+f[f.length-2])}}var O;s.length>1?(O=new g.MultiMaterial("multimat"+n,t.scene)).subMaterials=s:O=new g.StandardMaterial("multimat"+n,t.scene),1===s.length&&(O=s[0]),o.material||(o.material=O),h.setAllVerticesData(a,!1),o.computeWorldMatrix(!0),o.subMeshes=[];var I=0;for(d=0;d<r.length;d++){var w;if(m=r[d],w=t.meshes[m])for(_=0;_<w.primitives.length;_++)w.primitives[_].mode,g.SubMesh.AddToMesh(I,c[I],u[I],p[I],f[I],o,o,!0),I++}return o},y=function(e,t,i,r){e.position&&(e.position=t),(e.rotationQuaternion||e.rotation)&&(e.rotationQuaternion=i),e.scaling&&(e.scaling=r)},b=function(e,t,i,r){var n=null;if(e.importOnlyMeshes&&(t.skin||t.meshes)&&e.importMeshesNames&&e.importMeshesNames.length>0&&-1===e.importMeshesNames.indexOf(t.name||""))return null;if(t.skin){if(t.meshes){var o=e.skins[t.skin];(s=v(e,t,t.meshes,i,t.babylonNode)).skeleton=e.scene.getLastSkeletonByID(t.skin),null===s.skeleton&&(s.skeleton=_(e,o,0,o.babylonSkeleton,t.skin),o.babylonSkeleton||(o.babylonSkeleton=s.skeleton)),n=s}}else if(t.meshes){var s;n=s=v(e,t,t.mesh?[t.mesh]:t.meshes,i,t.babylonNode)}else if(!t.light||t.babylonNode||e.importOnlyMeshes){if(t.camera&&!t.babylonNode&&!e.importOnlyMeshes){var a=e.cameras[t.camera];if(a)if("orthographic"===a.type){var h=new g.FreeCamera(t.camera,g.Vector3.Zero(),e.scene);h.name=t.name||"",h.mode=g.Camera.ORTHOGRAPHIC_CAMERA,h.attachControl(e.scene.getEngine().getRenderingCanvas()),n=h}else if("perspective"===a.type){var l=a[a.type],c=new g.FreeCamera(t.camera,g.Vector3.Zero(),e.scene);c.name=t.name||"",c.attachControl(e.scene.getEngine().getRenderingCanvas()),l.aspectRatio||(l.aspectRatio=e.scene.getEngine().getRenderWidth()/e.scene.getEngine().getRenderHeight()),l.znear&&l.zfar&&(c.maxZ=l.zfar,c.minZ=l.znear),n=c}}}else{var u=e.lights[t.light];if(u)if("ambient"===u.type){var p=u[u.type],f=new g.HemisphericLight(t.light,g.Vector3.Zero(),e.scene);f.name=t.name||"",p.color&&(f.diffuse=g.Color3.FromArray(p.color)),n=f}else if("directional"===u.type){var d=u[u.type],m=new g.DirectionalLight(t.light,g.Vector3.Zero(),e.scene);m.name=t.name||"",d.color&&(m.diffuse=g.Color3.FromArray(d.color)),n=m}else if("point"===u.type){var b=u[u.type],x=new g.PointLight(t.light,g.Vector3.Zero(),e.scene);x.name=t.name||"",b.color&&(x.diffuse=g.Color3.FromArray(b.color)),n=x}else if("spot"===u.type){var T=u[u.type],E=new g.SpotLight(t.light,g.Vector3.Zero(),g.Vector3.Zero(),0,0,e.scene);E.name=t.name||"",T.color&&(E.diffuse=g.Color3.FromArray(T.color)),T.fallOfAngle&&(E.angle=T.fallOfAngle),T.fallOffExponent&&(E.exponent=T.fallOffExponent),n=E}}if(!t.jointName){if(t.babylonNode)return t.babylonNode;if(null===n){var A=new g.Mesh(t.name||"",e.scene);t.babylonNode=A,n=A}}if(null!==n){if(t.matrix&&n instanceof g.Mesh)!function(e,t,i){if(t.matrix){var r=new g.Vector3(0,0,0),n=new g.Quaternion,o=new g.Vector3(0,0,0);g.Matrix.FromArray(t.matrix).decompose(o,n,r),y(e,r,n,o)}else t.translation&&t.rotation&&t.scale&&y(e,g.Vector3.FromArray(t.translation),g.Quaternion.FromArray(t.rotation),g.Vector3.FromArray(t.scale));e.computeWorldMatrix(!0)}(n,t);else{var P=t.translation||[0,0,0],M=t.rotation||[0,0,0,1],S=t.scale||[1,1,1];y(n,g.Vector3.FromArray(P),g.Quaternion.FromArray(M),g.Vector3.FromArray(S))}n.updateCache(!0),t.babylonNode=n}return n},x=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=b(e,n,t))&&(o.id=t,o.parent=i),n.children)for(var s=0;s<n.children.length;s++)x(e,n.children[s],o,r)},T=function(t){var i=t.currentScene;if(i)for(var r=0;r<i.nodes.length;r++)x(t,i.nodes[r],null);else for(var n in t.scenes)for(i=t.scenes[n],r=0;r<i.nodes.length;r++)x(t,i.nodes[r],null);for(function(t){for(var i in t.animations){var r=t.animations[i];if(r.channels&&r.samplers)for(var n=null,o=0;o<r.channels.length;o++){var h=r.channels[o],l=r.samplers[h.sampler];if(l){var c=null,u=null;r.parameters?(c=r.parameters[l.input],u=r.parameters[l.output]):(c=l.input,u=l.output);var p=e.GLTFUtils.GetBufferFromAccessor(t,t.accessors[c]),f=e.GLTFUtils.GetBufferFromAccessor(t,t.accessors[u]),d=h.target.id,m=t.scene.getNodeByID(d);if(null===m&&(m=t.scene.getNodeByName(d)),null!==m){var _=m instanceof g.Bone,v=h.target.path,y=s.indexOf(v);-1!==y&&(v=a[y]);var b=g.Animation.ANIMATIONTYPE_MATRIX;_||("rotationQuaternion"===v?(b=g.Animation.ANIMATIONTYPE_QUATERNION,m.rotationQuaternion=new g.Quaternion):b=g.Animation.ANIMATIONTYPE_VECTOR3);var x=null,T=[],E=0,A=!1;_&&n&&n.getKeys().length===p.length&&(x=n,A=!0),A||(x=new g.Animation(i,_?"_matrix":v,1,b,g.Animation.ANIMATIONLOOPMODE_CYCLE));for(var P=0;P<p.length;P++){var M=null;if("rotationQuaternion"===v?(M=g.Quaternion.FromArray([f[E],f[E+1],f[E+2],f[E+3]]),E+=4):(M=g.Vector3.FromArray([f[E],f[E+1],f[E+2]]),E+=3),_){var S=m,C=g.Vector3.Zero(),R=new g.Quaternion,O=g.Vector3.Zero(),I=S.getBaseMatrix();A&&n&&(I=n.getKeys()[P].value),I.decompose(O,R,C),"position"===v?C=M:"rotationQuaternion"===v?R=M:O=M,M=g.Matrix.Compose(O,R,C)}A?n&&(n.getKeys()[P].value=M):T.push({frame:p[P],value:M})}!A&&x&&(x.setKeys(T),m.animations.push(x)),n=x,t.scene.stopAnimation(m),t.scene.beginAnimation(m,0,p[p.length-1],!0,1)}else g.Tools.Warn("Creating animation named "+i+". But cannot find node named "+d+" to attach to")}}}}(t),r=0;r<t.scene.skeletons.length;r++){var o=t.scene.skeletons[r];t.scene.beginAnimation(o,0,Number.MAX_VALUE,!0,1)}},E=function(t,i,r,n,o,s){return function(a){(function(t,i,r,n,o){var s=n.values||r.parameters,a=r.uniforms;for(var h in o){var l=o[h],c=l.type,u=s[a[h]];if(void 0===u&&(u=l.value),u){var p=function(e){return function(t){l.value&&e&&(i.setTexture(e,t),delete o[e])}};c===e.EParameterType.SAMPLER_2D?e.GLTFLoaderExtension.LoadTextureAsync(t,n.values?u:l.value,p(h),function(){return p(null)}):l.value&&e.GLTFUtils.SetUniform(i,h,n.values?u:l.value,c)&&delete o[h]}}})(t,i,r,n,o),i.onBind=function(a){!function(t,i,r,n,o,s,a){var h=s.values||o.parameters;for(var l in r){var c=r[l],u=c.type;if(u===e.EParameterType.FLOAT_MAT2||u===e.EParameterType.FLOAT_MAT3||u===e.EParameterType.FLOAT_MAT4)if(!c.semantic||c.source||c.node){if(c.semantic&&(c.source||c.node)){var p=i.scene.getNodeByName(c.source||c.node||"");if(null===p&&(p=i.scene.getNodeByID(c.source||c.node||"")),null===p)continue;e.GLTFUtils.SetMatrix(i.scene,p,c,l,n.getEffect())}}else e.GLTFUtils.SetMatrix(i.scene,t,c,l,n.getEffect());else{var f=h[o.uniforms[l]];if(!f)continue;if(u===e.EParameterType.SAMPLER_2D){var d=i.textures[s.values?f:c.value].babylonTexture;if(null===d||void 0===d)continue;n.getEffect().setTexture(l,d)}else e.GLTFUtils.SetUniform(n.getEffect(),l,f,u)}}a(n)}(a,t,o,i,r,n,s)}}},A=function(e,t,i){for(var r in t.uniforms){var s=t.uniforms[r],a=t.parameters[s];if(e.currentIdentifier===r&&a.semantic&&!a.source&&!a.node){var h=n.indexOf(a.semantic);if(-1!==h)return delete i[r],o[h]}}return e.currentIdentifier},P=function(t){for(var i in t.materials)e.GLTFLoaderExtension.LoadMaterialAsync(t,i,function(e){},function(){})},M=function(){function i(){}return i.CreateRuntime=function(e,t,i){var r={extensions:{},accessors:{},buffers:{},bufferViews:{},meshes:{},lights:{},cameras:{},nodes:{},images:{},textures:{},shaders:{},programs:{},samplers:{},techniques:{},materials:{},animations:{},skins:{},extensionsUsed:[],scenes:{},buffersCount:0,shaderscount:0,scene:t,rootUrl:i,loadedBufferCount:0,loadedBufferViews:{},loadedShaderCount:0,importOnlyMeshes:!1,dummyNodes:[]};return e.extensions&&h(e.extensions,"extensions",r),e.extensionsUsed&&h(e.extensionsUsed,"extensionsUsed",r),e.buffers&&function(e,t){for(var i in e){var r=e[i];t.buffers[i]=r,t.buffersCount++}}(e.buffers,r),e.bufferViews&&h(e.bufferViews,"bufferViews",r),e.accessors&&h(e.accessors,"accessors",r),e.meshes&&h(e.meshes,"meshes",r),e.lights&&h(e.lights,"lights",r),e.cameras&&h(e.cameras,"cameras",r),e.nodes&&h(e.nodes,"nodes",r),e.images&&h(e.images,"images",r),e.textures&&h(e.textures,"textures",r),e.shaders&&function(e,t){for(var i in e){var r=e[i];t.shaders[i]=r,t.shaderscount++}}(e.shaders,r),e.programs&&h(e.programs,"programs",r),e.samplers&&h(e.samplers,"samplers",r),e.techniques&&h(e.techniques,"techniques",r),e.materials&&h(e.materials,"materials",r),e.animations&&h(e.animations,"animations",r),e.skins&&h(e.skins,"skins",r),e.scenes&&(r.scenes=e.scenes),e.scene&&e.scenes&&(r.currentScene=e.scenes[e.scene]),r},i.LoadBufferAsync=function(t,i,r,n,o){var s=t.buffers[i];e.GLTFUtils.IsBase64(s.uri)?setTimeout(function(){return r(new Uint8Array(e.GLTFUtils.DecodeBase64(s.uri)))}):g.Tools.LoadFile(t.rootUrl+s.uri,function(e){return r(new Uint8Array(e))},o,void 0,!0,function(e){e&&n(e.status+" "+e.statusText)})},i.LoadTextureBufferAsync=function(t,i,r,n){var o=t.textures[i];if(o&&o.source)if(o.babylonTexture)r(null);else{var s=t.images[o.source];e.GLTFUtils.IsBase64(s.uri)?setTimeout(function(){return r(new Uint8Array(e.GLTFUtils.DecodeBase64(s.uri)))}):g.Tools.LoadFile(t.rootUrl+s.uri,function(e){return r(new Uint8Array(e))},void 0,void 0,!0,function(e){e&&n(e.status+" "+e.statusText)})}else n("")},i.CreateTextureAsync=function(t,i,r,n,o){var s=t.textures[i];if(s.babylonTexture)n(s.babylonTexture);else{var a=t.samplers[s.sampler],h=a.minFilter===e.ETextureFilterType.NEAREST_MIPMAP_NEAREST||a.minFilter===e.ETextureFilterType.NEAREST_MIPMAP_LINEAR||a.minFilter===e.ETextureFilterType.LINEAR_MIPMAP_NEAREST||a.minFilter===e.ETextureFilterType.LINEAR_MIPMAP_LINEAR,l=g.Texture.BILINEAR_SAMPLINGMODE,c=new Blob([r]),u=URL.createObjectURL(c),p=function(){return URL.revokeObjectURL(u)},f=new g.Texture(u,t.scene,!h,!0,l,p,p);void 0!==a.wrapS&&(f.wrapU=e.GLTFUtils.GetWrapMode(a.wrapS)),void 0!==a.wrapT&&(f.wrapV=e.GLTFUtils.GetWrapMode(a.wrapT)),f.name=i,s.babylonTexture=f,n(f)}},i.LoadShaderStringAsync=function(t,i,r,n){var o=t.shaders[i];e.GLTFUtils.IsBase64(o.uri)?r(atob(o.uri.split(",")[1])):g.Tools.LoadFile(t.rootUrl+o.uri,r,void 0,void 0,!1,function(e){e&&n(e.status+" "+e.statusText)})},i.LoadMaterialAsync=function(i,s,a,h){var l=i.materials[s];if(l.technique){var u=i.techniques[l.technique];if(!u){var p=new g.StandardMaterial(s,i.scene);return p.diffuseColor=new g.Color3(.5,.5,.5),p.sideOrientation=g.Material.CounterClockWiseSideOrientation,void a(p)}var f=i.programs[u.program],d=u.states,m=g.Effect.ShadersStore[f.vertexShader+"VertexShader"],_=g.Effect.ShadersStore[f.fragmentShader+"PixelShader"],v="",y="",b=new r(m),x=new r(_),T={},P=[],M=[],S=[];for(var C in u.uniforms){var R=u.uniforms[C],O=u.parameters[R];if(T[C]=O,!O.semantic||O.node||O.source)O.type===e.EParameterType.SAMPLER_2D?S.push(C):P.push(C);else{var I=n.indexOf(O.semantic);-1!==I?(P.push(o[I]),delete T[C]):P.push(C)}}for(var w in u.attributes){var D=u.attributes[w];(B=u.parameters[D]).semantic&&M.push(c(B))}for(;!b.isEnd()&&b.getNextToken();)if(b.currentToken===t.IDENTIFIER){var L=!1;for(var w in u.attributes){D=u.attributes[w];var B=u.parameters[D];if(b.currentIdentifier===w&&B.semantic){v+=c(B),L=!0;break}}L||(v+=A(b,u,T))}else v+=b.currentString;for(;!x.isEnd()&&x.getNextToken();)x.currentToken===t.IDENTIFIER?y+=A(x,u,T):y+=x.currentString;var N={vertex:f.vertexShader+s,fragment:f.fragmentShader+s},F={attributes:M,uniforms:P,samplers:S,needAlphaBlending:d&&d.enable&&-1!==d.enable.indexOf(3042)};g.Effect.ShadersStore[f.vertexShader+s+"VertexShader"]=v,g.Effect.ShadersStore[f.fragmentShader+s+"PixelShader"]=y;var V,k,U,z=new g.ShaderMaterial(s,i.scene,N,F);if(z.onError=(V=f,k=z,U=h,function(e,t){k.dispose(!0),U("Cannot compile program named "+V.name+". Error: "+t+". Default material will be applied")}),z.onCompiled=E(i,z,u,l,T,a),z.sideOrientation=g.Material.CounterClockWiseSideOrientation,d&&d.functions){var G=d.functions;G.cullFace&&G.cullFace[0]!==e.ECullingType.BACK&&(z.backFaceCulling=!1);var W=G.blendFuncSeparate;W&&(W[0]===e.EBlendingFunction.SRC_ALPHA&&W[1]===e.EBlendingFunction.ONE_MINUS_SRC_ALPHA&&W[2]===e.EBlendingFunction.ONE&&W[3]===e.EBlendingFunction.ONE?z.alphaMode=g.Engine.ALPHA_COMBINE:W[0]===e.EBlendingFunction.ONE&&W[1]===e.EBlendingFunction.ONE&&W[2]===e.EBlendingFunction.ZERO&&W[3]===e.EBlendingFunction.ONE?z.alphaMode=g.Engine.ALPHA_ONEONE:W[0]===e.EBlendingFunction.SRC_ALPHA&&W[1]===e.EBlendingFunction.ONE&&W[2]===e.EBlendingFunction.ZERO&&W[3]===e.EBlendingFunction.ONE?z.alphaMode=g.Engine.ALPHA_ADD:W[0]===e.EBlendingFunction.ZERO&&W[1]===e.EBlendingFunction.ONE_MINUS_SRC_COLOR&&W[2]===e.EBlendingFunction.ONE&&W[3]===e.EBlendingFunction.ONE?z.alphaMode=g.Engine.ALPHA_SUBTRACT:W[0]===e.EBlendingFunction.DST_COLOR&&W[1]===e.EBlendingFunction.ZERO&&W[2]===e.EBlendingFunction.ONE&&W[3]===e.EBlendingFunction.ONE?z.alphaMode=g.Engine.ALPHA_MULTIPLY:W[0]===e.EBlendingFunction.SRC_ALPHA&&W[1]===e.EBlendingFunction.ONE_MINUS_SRC_COLOR&&W[2]===e.EBlendingFunction.ONE&&W[3]===e.EBlendingFunction.ONE&&(z.alphaMode=g.Engine.ALPHA_MAXIMIZED))}}else h&&h("No technique found.")},i}();e.GLTFLoaderBase=M;var S=function(){function t(){this.coordinateSystemMode=g.GLTFLoaderCoordinateSystemMode.AUTO,this.animationStartMode=g.GLTFLoaderAnimationStartMode.FIRST,this.compileMaterials=!1,this.useClipPlane=!1,this.compileShadowGenerators=!1,this.onDisposeObservable=new g.Observable,this.onMeshLoadedObservable=new g.Observable,this.onTextureLoadedObservable=new g.Observable,this.onMaterialLoadedObservable=new g.Observable,this.onCompleteObservable=new g.Observable}return t.RegisterExtension=function(e){t.Extensions[e.name]?g.Tools.Error('Tool with the same name "'+e.name+'" already exists'):t.Extensions[e.name]=e},t.prototype.dispose=function(){},t.prototype.importMeshAsync=function(t,i,r,n,o,s,a){var h=this;return i.useRightHandedSystem=!0,e.GLTFLoaderExtension.LoadRuntimeAsync(i,r,n,function(e){e.importOnlyMeshes=!0,""===t?e.importMeshesNames=[]:"string"==typeof t?e.importMeshesNames=[t]:!t||t instanceof Array?(e.importMeshesNames=[],g.Tools.Warn("Argument meshesNames must be of type string or string[]")):e.importMeshesNames=[t],h._createNodes(e);var i=new Array,r=new Array;for(var n in e.nodes){var a=e.nodes[n];a.babylonNode instanceof g.AbstractMesh&&i.push(a.babylonNode)}for(var l in e.skins){var c=e.skins[l];c.babylonSkeleton instanceof g.Skeleton&&r.push(c.babylonSkeleton)}h._loadBuffersAsync(e,function(){h._loadShadersAsync(e,function(){P(e),T(e),!g.GLTFFileLoader.IncrementalLoading&&o&&o(i,[],r)})},s),g.GLTFFileLoader.IncrementalLoading&&o&&o(i,[],r)},a),!0},t.prototype.loadAsync=function(t,i,r,n,o,s){var a=this;t.useRightHandedSystem=!0,e.GLTFLoaderExtension.LoadRuntimeAsync(t,i,r,function(t){e.GLTFLoaderExtension.LoadRuntimeExtensionsAsync(t,function(){a._createNodes(t),a._loadBuffersAsync(t,function(){a._loadShadersAsync(t,function(){P(t),T(t),g.GLTFFileLoader.IncrementalLoading||n()})}),g.GLTFFileLoader.IncrementalLoading&&n()},s)},s)},t.prototype._loadShadersAsync=function(t,i){var r=!1,n=function(r,n){e.GLTFLoaderExtension.LoadShaderStringAsync(t,r,function(o){t.loadedShaderCount++,o&&(g.Effect.ShadersStore[r+(n.type===e.EShaderType.VERTEX?"VertexShader":"PixelShader")]=o),t.loadedShaderCount===t.shaderscount&&i()},function(){g.Tools.Error("Error when loading shader program named "+r+" located at "+n.uri)})};for(var o in t.shaders){r=!0;var s=t.shaders[o];s?n.bind(this,o,s)():g.Tools.Error("No shader named: "+o)}r||i()},t.prototype._loadBuffersAsync=function(t,i,r){var n=!1,o=function(r,n){e.GLTFLoaderExtension.LoadBufferAsync(t,r,function(e){t.loadedBufferCount++,e&&(e.byteLength!=t.buffers[r].byteLength&&g.Tools.Error("Buffer named "+r+" is length "+e.byteLength+". Expected: "+n.byteLength),t.loadedBufferViews[r]=e),t.loadedBufferCount===t.buffersCount&&i()},function(){g.Tools.Error("Error when loading buffer named "+r+" located at "+n.uri)})};for(var s in t.buffers){n=!0;var a=t.buffers[s];a?o.bind(this,s,a)():g.Tools.Error("No buffer named: "+s)}n||i()},t.prototype._createNodes=function(e){var t=e.currentScene;if(t)for(var i=0;i<t.nodes.length;i++)x(e,t.nodes[i],null);else for(var r in e.scenes)for(t=e.scenes[r],i=0;i<t.nodes.length;i++)x(e,t.nodes[i],null)},t.Extensions={},t}();e.GLTFLoader=S,g.GLTFFileLoader.CreateGLTFLoaderV1=function(){return new S}}((g=re||(re={})).GLTF1||(g.GLTF1={})),_=re||(re={}),v=_.GLTF1||(_.GLTF1={}),y=function(){function e(){}return e.SetMatrix=function(e,t,i,r,n){var o=null;if("MODEL"===i.semantic?o=t.getWorldMatrix():"PROJECTION"===i.semantic?o=e.getProjectionMatrix():"VIEW"===i.semantic?o=e.getViewMatrix():"MODELVIEWINVERSETRANSPOSE"===i.semantic?o=_.Matrix.Transpose(t.getWorldMatrix().multiply(e.getViewMatrix()).invert()):"MODELVIEW"===i.semantic?o=t.getWorldMatrix().multiply(e.getViewMatrix()):"MODELVIEWPROJECTION"===i.semantic?o=t.getWorldMatrix().multiply(e.getTransformMatrix()):"MODELINVERSE"===i.semantic?o=t.getWorldMatrix().invert():"VIEWINVERSE"===i.semantic?o=e.getViewMatrix().invert():"PROJECTIONINVERSE"===i.semantic?o=e.getProjectionMatrix().invert():"MODELVIEWINVERSE"===i.semantic?o=t.getWorldMatrix().multiply(e.getViewMatrix()).invert():"MODELVIEWPROJECTIONINVERSE"===i.semantic?o=t.getWorldMatrix().multiply(e.getTransformMatrix()).invert():"MODELINVERSETRANSPOSE"===i.semantic&&(o=_.Matrix.Transpose(t.getWorldMatrix().invert())),o)switch(i.type){case v.EParameterType.FLOAT_MAT2:n.setMatrix2x2(r,_.Matrix.GetAsMatrix2x2(o));break;case v.EParameterType.FLOAT_MAT3:n.setMatrix3x3(r,_.Matrix.GetAsMatrix3x3(o));break;case v.EParameterType.FLOAT_MAT4:n.setMatrix(r,o)}},e.SetUniform=function(e,t,i,r){switch(r){case v.EParameterType.FLOAT:return e.setFloat(t,i),!0;case v.EParameterType.FLOAT_VEC2:return e.setVector2(t,_.Vector2.FromArray(i)),!0;case v.EParameterType.FLOAT_VEC3:return e.setVector3(t,_.Vector3.FromArray(i)),!0;case v.EParameterType.FLOAT_VEC4:return e.setVector4(t,_.Vector4.FromArray(i)),!0;default:return!1}},e.IsBase64=function(e){return!(e.length<5)&&"data:"===e.substr(0,5)},e.DecodeBase64=function(e){for(var t=atob(e.split(",")[1]),i=t.length,r=new Uint8Array(new ArrayBuffer(i)),n=0;n<i;n++)r[n]=t.charCodeAt(n);return r.buffer},e.GetWrapMode=function(e){switch(e){case v.ETextureWrapMode.CLAMP_TO_EDGE:return _.Texture.CLAMP_ADDRESSMODE;case v.ETextureWrapMode.MIRRORED_REPEAT:return _.Texture.MIRROR_ADDRESSMODE;case v.ETextureWrapMode.REPEAT:default:return _.Texture.WRAP_ADDRESSMODE}},e.GetByteStrideFromType=function(e){switch(e.type){case"VEC2":return 2;case"VEC3":return 3;case"VEC4":case"MAT2":return 4;case"MAT3":return 9;case"MAT4":return 16;default:return 1}},e.GetTextureFilterMode=function(e){switch(e){case v.ETextureFilterType.LINEAR:case v.ETextureFilterType.LINEAR_MIPMAP_NEAREST:case v.ETextureFilterType.LINEAR_MIPMAP_LINEAR:return _.Texture.TRILINEAR_SAMPLINGMODE;case v.ETextureFilterType.NEAREST:case v.ETextureFilterType.NEAREST_MIPMAP_NEAREST:return _.Texture.NEAREST_SAMPLINGMODE;default:return _.Texture.BILINEAR_SAMPLINGMODE}},e.GetBufferFromBufferView=function(e,t,i,r,n){i=t.byteOffset+i;var o=e.loadedBufferViews[t.buffer];if(i+r>o.byteLength)throw new Error("Buffer access is out of range");var s=o.buffer;switch(i+=o.byteOffset,n){case v.EComponentType.BYTE:return new Int8Array(s,i,r);case v.EComponentType.UNSIGNED_BYTE:return new Uint8Array(s,i,r);case v.EComponentType.SHORT:return new Int16Array(s,i,r);case v.EComponentType.UNSIGNED_SHORT:return new Uint16Array(s,i,r);default:return new Float32Array(s,i,r)}},e.GetBufferFromAccessor=function(t,i){var r=t.bufferViews[i.bufferView],n=i.count*e.GetByteStrideFromType(i);return e.GetBufferFromBufferView(t,r,i.byteOffset,n,i.componentType)},e.DecodeBufferToText=function(e){for(var t="",i=e.byteLength,r=0;r<i;++r)t+=String.fromCharCode(e[r]);return t},e.GetDefaultMaterial=function(t){if(!e._DefaultMaterial){_.Effect.ShadersStore.GLTFDefaultMaterialVertexShader=["precision highp float;","","uniform mat4 worldView;","uniform mat4 projection;","","attribute vec3 position;","","void main(void)","{"," gl_Position = projection * worldView * vec4(position, 1.0);","}"].join("\n"),_.Effect.ShadersStore.GLTFDefaultMaterialPixelShader=["precision highp float;","","uniform vec4 u_emission;","","void main(void)","{"," gl_FragColor = u_emission;","}"].join("\n");var i={attributes:["position"],uniforms:["worldView","projection","u_emission"],samplers:new Array,needAlphaBlending:!1};e._DefaultMaterial=new _.ShaderMaterial("GLTFDefaultMaterial",t,{vertex:"GLTFDefaultMaterial",fragment:"GLTFDefaultMaterial"},i),e._DefaultMaterial.setColor4("u_emission",new _.Color4(.5,.5,.5,1))}return e._DefaultMaterial},e._DefaultMaterial=null,e}(),v.GLTFUtils=y,b=re||(re={}),x=b.GLTF1||(b.GLTF1={}),T=function(){function e(e){this._name=e}return Object.defineProperty(e.prototype,"name",{get:function(){return this._name},enumerable:!0,configurable:!0}),e.prototype.loadRuntimeAsync=function(e,t,i,r,n){return!1},e.prototype.loadRuntimeExtensionsAsync=function(e,t,i){return!1},e.prototype.loadBufferAsync=function(e,t,i,r,n){return!1},e.prototype.loadTextureBufferAsync=function(e,t,i,r){return!1},e.prototype.createTextureAsync=function(e,t,i,r,n){return!1},e.prototype.loadShaderStringAsync=function(e,t,i,r){return!1},e.prototype.loadMaterialAsync=function(e,t,i,r){return!1},e.LoadRuntimeAsync=function(t,i,r,n,o){e.ApplyExtensions(function(e){return e.loadRuntimeAsync(t,i,r,n,o)},function(){setTimeout(function(){n(x.GLTFLoaderBase.CreateRuntime(i.json,t,r))})})},e.LoadRuntimeExtensionsAsync=function(t,i,r){e.ApplyExtensions(function(e){return e.loadRuntimeExtensionsAsync(t,i,r)},function(){setTimeout(function(){i()})})},e.LoadBufferAsync=function(t,i,r,n,o){e.ApplyExtensions(function(e){return e.loadBufferAsync(t,i,r,n,o)},function(){x.GLTFLoaderBase.LoadBufferAsync(t,i,r,n,o)})},e.LoadTextureAsync=function(t,i,r,n){e.LoadTextureBufferAsync(t,i,function(o){return e.CreateTextureAsync(t,i,o,r,n)},n)},e.LoadShaderStringAsync=function(t,i,r,n){e.ApplyExtensions(function(e){return e.loadShaderStringAsync(t,i,r,n)},function(){x.GLTFLoaderBase.LoadShaderStringAsync(t,i,r,n)})},e.LoadMaterialAsync=function(t,i,r,n){e.ApplyExtensions(function(e){return e.loadMaterialAsync(t,i,r,n)},function(){x.GLTFLoaderBase.LoadMaterialAsync(t,i,r,n)})},e.LoadTextureBufferAsync=function(t,i,r,n){e.ApplyExtensions(function(e){return e.loadTextureBufferAsync(t,i,r,n)},function(){x.GLTFLoaderBase.LoadTextureBufferAsync(t,i,r,n)})},e.CreateTextureAsync=function(t,i,r,n,o){e.ApplyExtensions(function(e){return e.createTextureAsync(t,i,r,n,o)},function(){x.GLTFLoaderBase.CreateTextureAsync(t,i,r,n,o)})},e.ApplyExtensions=function(e,t){for(var i in x.GLTFLoader.Extensions)if(e(x.GLTFLoader.Extensions[i]))return;t()},e}(),x.GLTFLoaderExtension=T,E=re||(re={}),A=E.GLTF1||(E.GLTF1={}),P=function(e){function t(){return e.call(this,"KHR_binary_glTF")||this}return ne(t,e),t.prototype.loadRuntimeAsync=function(e,t,i,r,n){var o=t.json.extensionsUsed;return!(!o||-1===o.indexOf(this.name)||!t.bin||(this._bin=t.bin,r(A.GLTFLoaderBase.CreateRuntime(t.json,e,i)),0))},t.prototype.loadBufferAsync=function(e,t,i,r){return-1!==e.extensionsUsed.indexOf(this.name)&&"binary_glTF"===t&&(i(this._bin),!0)},t.prototype.loadTextureBufferAsync=function(e,t,i,r){var n=e.textures[t],o=e.images[n.source];if(!(o.extensions&&this.name in o.extensions))return!1;var s=o.extensions[this.name],a=e.bufferViews[s.bufferView];return i(A.GLTFUtils.GetBufferFromBufferView(e,a,0,a.byteLength,A.EComponentType.UNSIGNED_BYTE)),!0},t.prototype.loadShaderStringAsync=function(e,t,i,r){var n=e.shaders[t];if(!(n.extensions&&this.name in n.extensions))return!1;var o=n.extensions[this.name],s=e.bufferViews[o.bufferView],a=A.GLTFUtils.GetBufferFromBufferView(e,s,0,s.byteLength,A.EComponentType.UNSIGNED_BYTE);return setTimeout(function(){var e=A.GLTFUtils.DecodeBufferToText(a);i(e)}),!0},t}(A.GLTFLoaderExtension),A.GLTFBinaryExtension=P,A.GLTFLoader.RegisterExtension(new P),M=re||(re={}),S=M.GLTF1||(M.GLTF1={}),C=function(e){function t(){return e.call(this,"KHR_materials_common")||this}return ne(t,e),t.prototype.loadRuntimeExtensionsAsync=function(e,t,i){if(!e.extensions)return!1;var r=e.extensions[this.name];if(!r)return!1;var n=r.lights;if(n)for(var o in n){var s=n[o];switch(s.type){case"ambient":var a=new M.HemisphericLight(s.name,new M.Vector3(0,1,0),e.scene),h=s.ambient;h&&(a.diffuse=M.Color3.FromArray(h.color||[1,1,1]));break;case"point":var l=new M.PointLight(s.name,new M.Vector3(10,10,10),e.scene),c=s.point;c&&(l.diffuse=M.Color3.FromArray(c.color||[1,1,1]));break;case"directional":var u=new M.DirectionalLight(s.name,new M.Vector3(0,-1,0),e.scene),p=s.directional;p&&(u.diffuse=M.Color3.FromArray(p.color||[1,1,1]));break;case"spot":var f=s.spot;f&&(new M.SpotLight(s.name,new M.Vector3(0,10,0),new M.Vector3(0,-1,0),f.fallOffAngle||Math.PI,f.fallOffExponent||0,e.scene).diffuse=M.Color3.FromArray(f.color||[1,1,1]));break;default:M.Tools.Warn('GLTF Material Common extension: light type "'+s.type+"” not supported")}}return!1},t.prototype.loadMaterialAsync=function(e,t,i,r){var n=e.materials[t];if(!n||!n.extensions)return!1;var o=n.extensions[this.name];if(!o)return!1;var s=new M.StandardMaterial(t,e.scene);return s.sideOrientation=M.Material.CounterClockWiseSideOrientation,"CONSTANT"===o.technique&&(s.disableLighting=!0),s.backFaceCulling=void 0!==o.doubleSided&&!o.doubleSided,s.alpha=void 0===o.values.transparency?1:o.values.transparency,s.specularPower=void 0===o.values.shininess?0:o.values.shininess,"string"==typeof o.values.ambient?this._loadTexture(e,o.values.ambient,s,"ambientTexture",r):s.ambientColor=M.Color3.FromArray(o.values.ambient||[0,0,0]),"string"==typeof o.values.diffuse?this._loadTexture(e,o.values.diffuse,s,"diffuseTexture",r):s.diffuseColor=M.Color3.FromArray(o.values.diffuse||[0,0,0]),"string"==typeof o.values.emission?this._loadTexture(e,o.values.emission,s,"emissiveTexture",r):s.emissiveColor=M.Color3.FromArray(o.values.emission||[0,0,0]),"string"==typeof o.values.specular?this._loadTexture(e,o.values.specular,s,"specularTexture",r):s.specularColor=M.Color3.FromArray(o.values.specular||[0,0,0]),!0},t.prototype._loadTexture=function(e,t,i,r,n){S.GLTFLoaderBase.LoadTextureBufferAsync(e,t,function(o){S.GLTFLoaderBase.CreateTextureAsync(e,t,o,function(e){return i[r]=e},n)},n)},t}(S.GLTFLoaderExtension),S.GLTFMaterialsCommonExtension=C,S.GLTFLoader.RegisterExtension(new C),R=re||(re={}),O=R.GLTF2||(R.GLTF2={}),(I=O.EComponentType||(O.EComponentType={}))[I.BYTE=5120]="BYTE",I[I.UNSIGNED_BYTE=5121]="UNSIGNED_BYTE",I[I.SHORT=5122]="SHORT",I[I.UNSIGNED_SHORT=5123]="UNSIGNED_SHORT",I[I.UNSIGNED_INT=5125]="UNSIGNED_INT",I[I.FLOAT=5126]="FLOAT",(w=O.EMeshPrimitiveMode||(O.EMeshPrimitiveMode={}))[w.POINTS=0]="POINTS",w[w.LINES=1]="LINES",w[w.LINE_LOOP=2]="LINE_LOOP",w[w.LINE_STRIP=3]="LINE_STRIP",w[w.TRIANGLES=4]="TRIANGLES",w[w.TRIANGLE_STRIP=5]="TRIANGLE_STRIP",w[w.TRIANGLE_FAN=6]="TRIANGLE_FAN",(D=O.ETextureMagFilter||(O.ETextureMagFilter={}))[D.NEAREST=9728]="NEAREST",D[D.LINEAR=9729]="LINEAR",(L=O.ETextureMinFilter||(O.ETextureMinFilter={}))[L.NEAREST=9728]="NEAREST",L[L.LINEAR=9729]="LINEAR",L[L.NEAREST_MIPMAP_NEAREST=9984]="NEAREST_MIPMAP_NEAREST",L[L.LINEAR_MIPMAP_NEAREST=9985]="LINEAR_MIPMAP_NEAREST",L[L.NEAREST_MIPMAP_LINEAR=9986]="NEAREST_MIPMAP_LINEAR",L[L.LINEAR_MIPMAP_LINEAR=9987]="LINEAR_MIPMAP_LINEAR",(B=O.ETextureWrapMode||(O.ETextureWrapMode={}))[B.CLAMP_TO_EDGE=33071]="CLAMP_TO_EDGE",B[B.MIRRORED_REPEAT=33648]="MIRRORED_REPEAT",B[B.REPEAT=10497]="REPEAT",N=re||(re={}),F=N.GLTF2||(N.GLTF2={}),V=function(){function e(e){this._pendingCount=0,this._callback=e}return e.prototype._addPendingData=function(e){this._pendingCount++},e.prototype._removePendingData=function(e){0==--this._pendingCount&&this._callback()},e}(),k=function(){function e(){this._disposed=!1,this._defaultSampler={},this._renderReady=!1,this._requests=new Array,this._renderReadyObservable=new N.Observable,this._renderPendingCount=0,this._loaderPendingCount=0,this._loaderTrackers=new Array,this.coordinateSystemMode=N.GLTFLoaderCoordinateSystemMode.AUTO,this.animationStartMode=N.GLTFLoaderAnimationStartMode.FIRST,this.compileMaterials=!1,this.useClipPlane=!1,this.compileShadowGenerators=!1,this.onDisposeObservable=new N.Observable,this.onMeshLoadedObservable=new N.Observable,this.onTextureLoadedObservable=new N.Observable,this.onMaterialLoadedObservable=new N.Observable,this.onCompleteObservable=new N.Observable}return e.RegisterExtension=function(t){e.Extensions[t.name]?N.Tools.Error("Extension with the same name '"+t.name+"' already exists"):(e.Extensions[t.name]=t,F.GLTFLoaderExtension._Extensions.push(t))},e.prototype.dispose=function(){this._disposed||(this._disposed=!0,this._abortRequests(),this._releaseResources(),this.onDisposeObservable.notifyObservers(this))},e.prototype.importMeshAsync=function(e,t,i,r,n,o,s){var a=this;this._loadAsync(e,t,i,r,function(){n&&n(a._getMeshes(),[],a._getSkeletons())},o,s)},e.prototype.loadAsync=function(e,t,i,r,n,o){this._loadAsync(null,e,t,i,r,n,o)},e.prototype._loadAsync=function(e,t,i,r,n,o,s){var a=this;this._babylonScene=t,this._rootUrl=r,this._successCallback=n,this._progressCallback=o,this._errorCallback=s,this._tryCatchOnError(function(){a._loadData(i),a._addPendingData(a),a._loadDefaultScene(e),a._loadAnimations(),a._removePendingData(a)})},e.prototype._onProgress=function(){if(this._progressCallback){for(var e=!0,t=0,i=0,r=0,n=this._requests;r<n.length;r++){var o=n[r];if(void 0===o._lengthComputable||void 0===o._loaded||void 0===o._total)return;e=e&&o._lengthComputable,t+=o._loaded,i+=o._total}this._progressCallback(new N.SceneLoaderProgressEvent(e,t,e?i:0))}},e.prototype._executeWhenRenderReady=function(e){this._renderReady?e():this._renderReadyObservable.add(e)},e.prototype._onRenderReady=function(){this._rootNode.babylonMesh.setEnabled(!0),this._startAnimations(),this._successCallback&&this._successCallback(),this._renderReadyObservable.notifyObservers(this)},e.prototype._onComplete=function(){this._abortRequests(),this._releaseResources(),this.onCompleteObservable.notifyObservers(this)},e.prototype._loadData=function(t){if(this._gltf=t.json,e._AssignIndices(this._gltf.accessors),e._AssignIndices(this._gltf.animations),e._AssignIndices(this._gltf.buffers),e._AssignIndices(this._gltf.bufferViews),e._AssignIndices(this._gltf.images),e._AssignIndices(this._gltf.materials),e._AssignIndices(this._gltf.meshes),e._AssignIndices(this._gltf.nodes),e._AssignIndices(this._gltf.samplers),e._AssignIndices(this._gltf.scenes),e._AssignIndices(this._gltf.skins),e._AssignIndices(this._gltf.textures),t.bin){var i=this._gltf.buffers;if(i&&i[0]&&!i[0].uri){var r=i[0];(r.byteLength<t.bin.byteLength-3||r.byteLength>t.bin.byteLength)&&N.Tools.Warn("Binary buffer length ("+r.byteLength+") from JSON does not match chunk length ("+t.bin.byteLength+")"),r.loadedData=t.bin}else N.Tools.Warn("Unexpected BIN chunk")}},e.prototype._getMeshes=function(){var e=new Array;e.push(this._rootNode.babylonMesh);var t=this._gltf.nodes;if(t)for(var i=0,r=t;i<r.length;i++){var n=r[i];n.babylonMesh&&e.push(n.babylonMesh)}return e},e.prototype._getSkeletons=function(){var e=new Array,t=this._gltf.skins;if(t)for(var i=0,r=t;i<r.length;i++){var n=r[i];n.babylonSkeleton&&e.push(n.babylonSkeleton)}return e},e.prototype._startAnimations=function(){var e=this._gltf.animations;if(e)switch(this.animationStartMode){case N.GLTFLoaderAnimationStartMode.NONE:break;case N.GLTFLoaderAnimationStartMode.FIRST:for(var t=0,i=(s=e[0]).targets;t<i.length;t++){var r=i[t];this._babylonScene.beginAnimation(r,0,Number.MAX_VALUE,!0)}break;case N.GLTFLoaderAnimationStartMode.ALL:for(var n=0,o=e;n<o.length;n++)for(var s=o[n],a=0,h=s.targets;a<h.length;a++)r=h[a],this._babylonScene.beginAnimation(r,0,Number.MAX_VALUE,!0);break;default:return void N.Tools.Error("Invalid animation start mode "+this.animationStartMode)}},e.prototype._loadDefaultScene=function(t){var i=e._GetProperty(this._gltf.scenes,this._gltf.scene||0);if(!i)throw new Error("Failed to find scene "+(this._gltf.scene||0));this._loadScene("#/scenes/"+i.index,i,t)},e.prototype._loadScene=function(t,i,r){var n=this;switch(this._rootNode={babylonMesh:new N.Mesh("__root__",this._babylonScene)},this.coordinateSystemMode){case N.GLTFLoaderCoordinateSystemMode.AUTO:this._babylonScene.useRightHandedSystem||(this._rootNode.rotation=[0,1,0,0],this._rootNode.scale=[1,1,-1],this._loadTransform(this._rootNode));break;case N.GLTFLoaderCoordinateSystemMode.FORCE_RIGHT_HANDED:this._babylonScene.useRightHandedSystem=!0;break;default:return void N.Tools.Error("Invalid coordinate system mode "+this.coordinateSystemMode)}this.onMeshLoadedObservable.notifyObservers(this._rootNode.babylonMesh);var o=i.nodes;if(this._traverseNodes(t,o,function(e,t){return e.parent=t,!0},this._rootNode),r){r instanceof Array||(r=[r]);var s=new Array;this._traverseNodes(t,o,function(e){return-1===r.indexOf(e.name)||(s.push(e.index),e.parent=n._rootNode,!1)},this._rootNode),o=s}for(var a=0,h=o;a<h.length;a++){var l=h[a],c=e._GetProperty(this._gltf.nodes,l);if(!c)throw new Error(t+": Failed to find node "+l);this._loadNode("#/nodes/"+l,c)}this._rootNode.babylonMesh.setEnabled(!1)},e.prototype._loadNode=function(t,i){if(!F.GLTFLoaderExtension.LoadNode(this,t,i)){if(i.babylonMesh=new N.Mesh(i.name||"mesh"+i.index,this._babylonScene),this._loadTransform(i),null!=i.mesh){var r=e._GetProperty(this._gltf.meshes,i.mesh);if(!r)throw new Error(t+": Failed to find mesh "+i.mesh);this._loadMesh("#/meshes/"+i.mesh,i,r)}if(i.babylonMesh.parent=i.parent.babylonMesh,i.babylonAnimationTargets=i.babylonAnimationTargets||[],i.babylonAnimationTargets.push(i.babylonMesh),null!=i.skin){var n=e._GetProperty(this._gltf.skins,i.skin);if(!n)throw new Error(t+": Failed to find skin "+i.skin);this._loadSkinAsync("#/skins/"+i.skin,n,function(){i.babylonMesh.skeleton=n.babylonSkeleton,i.babylonMesh._refreshBoundingInfo(!0)}),i.babylonMesh.parent=this._rootNode.babylonMesh,i.babylonMesh.position=N.Vector3.Zero(),i.babylonMesh.rotationQuaternion=N.Quaternion.Identity(),i.babylonMesh.scaling=N.Vector3.One()}if(i.camera,i.children)for(var o=0,s=i.children;o<s.length;o++){var a=s[o],h=e._GetProperty(this._gltf.nodes,a);if(!h)throw new Error(t+": Failed to find child node "+a);this._loadNode("#/nodes/"+a,h)}this.onMeshLoadedObservable.notifyObservers(i.babylonMesh)}},e.prototype._loadMesh=function(t,i,r){var n=this,o=r.primitives;if(!o||0===o.length)throw new Error(t+": Primitives are missing");if(this._createMorphTargets(t,i,r),this._loadAllVertexDataAsync(t,r,function(){n._loadMorphTargets(t,i,r);for(var e=new N.VertexData,s=0,a=o;s<a.length;s++){var h=a[s];e.merge(h.vertexData)}i.babylonMesh.hasVertexAlpha=r.hasVertexAlpha,new N.Geometry(i.babylonMesh.name,n._babylonScene,e,!1,i.babylonMesh),i.babylonMesh.subMeshes=[];for(var l=0,c=0,u=0;u<o.length;u++){var p=o[u].vertexData,f=p.positions.length,d=p.indices.length;N.SubMesh.AddToMesh(u,l,f,c,d,i.babylonMesh),l+=f,c+=d}}),1===o.length){var s=o[0];if(null==s.material)i.babylonMesh.material=this._getDefaultMaterial();else{var a=e._GetProperty(this._gltf.materials,s.material);if(!a)throw new Error(t+": Failed to find material "+s.material);this._loadMaterial("#/materials/"+a.index,a,function(e,t){t&&n.onMaterialLoadedObservable.notifyObservers(e),i.babylonMesh.material=e})}}else{var h=new N.MultiMaterial(i.babylonMesh.name,this._babylonScene);i.babylonMesh.material=h;for(var l=h.subMaterials,c=this,u=0;u<o.length;u++)!function(i){var r=o[i];if(null==r.material)l[i]=c._getDefaultMaterial();else{var s=e._GetProperty(c._gltf.materials,r.material);if(!s)throw new Error(t+": Failed to find material "+r.material);c._loadMaterial("#/materials/"+s.index,s,function(e,t){t&&n.onMaterialLoadedObservable.notifyObservers(e),l[i]=e})}}(u)}},e.prototype._loadAllVertexDataAsync=function(e,t,i){for(var r=t.primitives,n=r.length,o=this,s=0;s<r.length;s++)!function(s){var a=r[s];o._loadVertexDataAsync(e+"/primitive/"+s,t,a,function(e){a.vertexData=e,0==--n&&i()})}(s)},e.prototype._convertToFloat4TextureCoordArray=function(e,t,i){if(i.componentType==F.EComponentType.FLOAT)return t;var r=t,n=1;switch(i.componentType){case F.EComponentType.UNSIGNED_BYTE:n=1/255;break;case F.EComponentType.UNSIGNED_SHORT:n=1/65535;break;default:throw new Error(e+": Invalid component type ("+i.componentType+")")}for(var o=new Float32Array(2*i.count),s=0;s<o.length;++s)o[s]=r[s]*n;return o},e.prototype._convertToFloat4ColorArray=function(t,i,r){var n=e._GetNumComponents(t,r.type);if(4===n&&r.componentType===F.EComponentType.FLOAT)return i;var o=i,s=1;switch(r.componentType){case F.EComponentType.FLOAT:s=1;break;case F.EComponentType.UNSIGNED_BYTE:s=1/255;break;case F.EComponentType.UNSIGNED_SHORT:s=1/65535;break;default:throw new Error(t+": Invalid component type ("+r.componentType+")")}var a=new Float32Array(4*r.count);if(4===n)for(var h=0;h<a.length;++h)a[h]=o[h]*s;else{var l=0;for(h=0;h<a.length;++h)a[h]=(h+1)%4==0?1:o[l++]*s}return a},e.prototype._loadVertexDataAsync=function(t,i,r,n){var o=this,s=r.attributes;if(!s)throw new Error(t+": Attributes are missing");if(r.mode&&r.mode!==F.EMeshPrimitiveMode.TRIANGLES)throw new Error(t+": Mode "+r.mode+" is not currently supported");var a=new N.VertexData,h=Object.keys(s).length,l=this;for(var c in s)!function(c){var u=e._GetProperty(l._gltf.accessors,s[c]);if(!u)throw new Error(t+": Failed to find attribute '"+c+"' accessor "+s[c]);l._loadAccessorAsync("#/accessors/"+u.index,u,function(s){switch(c){case"POSITION":a.positions=s;break;case"NORMAL":a.normals=s;break;case"TANGENT":a.tangents=s;break;case"TEXCOORD_0":a.uvs=o._convertToFloat4TextureCoordArray(t,s,u);break;case"TEXCOORD_1":a.uvs2=o._convertToFloat4TextureCoordArray(t,s,u);break;case"JOINTS_0":a.matricesIndices=new Float32Array(Array.prototype.slice.apply(s));break;case"WEIGHTS_0":a.matricesWeights=s;break;case"COLOR_0":a.colors=o._convertToFloat4ColorArray(t,s,u);var l=4===e._GetNumComponents(t,u.type);!i.hasVertexAlpha&&l&&(i.hasVertexAlpha=l);break;default:N.Tools.Warn(t+": Ignoring unrecognized attribute '"+c+"'")}if(0==--h)if(null==r.indices){a.indices=new Uint32Array(a.positions.length/3);for(var p=0;p<a.indices.length;p++)a.indices[p]=p;n(a)}else{var f=e._GetProperty(o._gltf.accessors,r.indices);if(!f)throw new Error(t+": Failed to find indices accessor "+r.indices);o._loadAccessorAsync("#/accessors/"+f.index,f,function(e){a.indices=e,n(a)})}})}(c)},e.prototype._createMorphTargets=function(e,t,i){var r=i.primitives,n=r[0].targets;if(n){for(var o=0,s=r;o<s.length;o++){var a=s[o];if(!a.targets||a.targets.length!=n.length)throw new Error(e+": All primitives are required to list the same number of targets")}var h=new N.MorphTargetManager;t.babylonMesh.morphTargetManager=h;for(var l=0;l<n.length;l++){var c=t.weights?t.weights[l]:i.weights?i.weights[l]:0;h.addTarget(new N.MorphTarget("morphTarget"+l,c))}}},e.prototype._loadMorphTargets=function(e,t,i){var r=t.babylonMesh.morphTargetManager;r&&this._loadAllMorphTargetVertexDataAsync(e,t,i,function(){for(var t=r.numTargets,n=0;n<t;n++){for(var o=new N.VertexData,s=0,a=i.primitives;s<a.length;s++){var h=a[s];o.merge(h.targetsVertexData[n],{tangentLength:3})}if(!o.positions)throw new Error(e+": Positions are missing");var l=r.getTarget(n);l.setPositions(o.positions),l.setNormals(o.normals),l.setTangents(o.tangents)}})},e.prototype._loadAllMorphTargetVertexDataAsync=function(e,t,i,r){for(var n=i.primitives.length*t.babylonMesh.morphTargetManager.numTargets,o=this,s=0,a=i.primitives;s<a.length;s++)!function(t){var i=t.targets;t.targetsVertexData=new Array(i.length);for(var s=0;s<i.length;s++)!function(s){o._loadMorphTargetVertexDataAsync(e+"/targets/"+s,t.vertexData,i[s],function(e){t.targetsVertexData[s]=e,0==--n&&r()})}(s)}(a[s])},e.prototype._loadMorphTargetVertexDataAsync=function(t,i,r,n){var o=new N.VertexData,s=Object.keys(r).length,a=this;for(var h in r)!function(h){var l=e._GetProperty(a._gltf.accessors,r[h]);if(!l)throw new Error(t+": Failed to find attribute '"+h+"' accessor "+r[h]);a._loadAccessorAsync("#/accessors/"+l.index,l,function(e){var r=e;switch(h){case"POSITION":for(var a=0;a<r.length;a++)r[a]+=i.positions[a];o.positions=r;break;case"NORMAL":for(a=0;a<r.length;a++)r[a]+=i.normals[a];o.normals=r;break;case"TANGENT":a=0;for(var l=0;a<r.length;a++,l++)r[a]+=i.tangents[l],(a+1)%3==0&&l++;o.tangents=r;break;default:N.Tools.Warn(t+": Ignoring unrecognized attribute '"+h+"'")}0==--s&&n(o)})}(h)},e.prototype._loadTransform=function(e){var t=N.Vector3.Zero(),i=N.Quaternion.Identity(),r=N.Vector3.One();e.matrix?N.Matrix.FromArray(e.matrix).decompose(r,i,t):(e.translation&&(t=N.Vector3.FromArray(e.translation)),e.rotation&&(i=N.Quaternion.FromArray(e.rotation)),e.scale&&(r=N.Vector3.FromArray(e.scale))),e.babylonMesh.position=t,e.babylonMesh.rotationQuaternion=i,e.babylonMesh.scaling=r},e.prototype._loadSkinAsync=function(t,i,r){var n=this;if(i.babylonSkeleton)r();else{var o="skeleton"+i.index;if(i.babylonSkeleton=new N.Skeleton(i.name||o,o,this._babylonScene),null==i.inverseBindMatrices)this._loadBones(t,i,null),r();else{var s=e._GetProperty(this._gltf.accessors,i.inverseBindMatrices);if(!s)throw new Error(t+": Failed to find inverse bind matrices attribute "+i.inverseBindMatrices);this._loadAccessorAsync("#/accessors/"+s.index,s,function(e){n._loadBones(t,i,e),r()})}}},e.prototype._createBone=function(e,t,i,r,n,o){var s=new N.Bone(e.name||"bone"+e.index,t.babylonSkeleton,i,r,null,n,o);return e.babylonAnimationTargets=e.babylonAnimationTargets||[],e.babylonAnimationTargets.push(s),s},e.prototype._loadBones=function(t,i,r){for(var n={},o=0,s=i.joints;o<s.length;o++){var a=s[o],h=e._GetProperty(this._gltf.nodes,a);if(!h)throw new Error(t+": Failed to find joint "+a);this._loadBone(h,i,r,n)}},e.prototype._loadBone=function(e,t,i,r){var n=r[e.index];if(n)return n;var o=t.joints.indexOf(e.index),s=N.Matrix.Identity();i&&-1!==o&&(s=N.Matrix.FromArray(i,16*o)).invertToRef(s);var a=null;return e.parent!==this._rootNode&&(a=this._loadBone(e.parent,t,i,r),s.multiplyToRef(a.getInvertedAbsoluteTransform(),s)),n=this._createBone(e,t,a,this._getNodeMatrix(e),s,o),r[e.index]=n,n},e.prototype._getNodeMatrix=function(e){return e.matrix?N.Matrix.FromArray(e.matrix):N.Matrix.Compose(e.scale?N.Vector3.FromArray(e.scale):N.Vector3.One(),e.rotation?N.Quaternion.FromArray(e.rotation):N.Quaternion.Identity(),e.translation?N.Vector3.FromArray(e.translation):N.Vector3.Zero())},e.prototype._traverseNodes=function(t,i,r,n){for(var o=0,s=i;o<s.length;o++){var a=s[o],h=e._GetProperty(this._gltf.nodes,a);if(!h)throw new Error(t+": Failed to find node "+a);this._traverseNode(t,h,r,n)}},e.prototype._traverseNode=function(e,t,i,r){F.GLTFLoaderExtension.TraverseNode(this,e,t,i,r)||i(t,r)&&t.children&&this._traverseNodes(e,t.children,i,t)},e.prototype._loadAnimations=function(){var e=this._gltf.animations;if(e)for(var t=0;t<e.length;t++){var i=e[t];this._loadAnimation("#/animations/"+t,i)}},e.prototype._loadAnimation=function(t,i){i.targets=[];for(var r=0;r<i.channels.length;r++){var n=e._GetProperty(i.channels,r);if(!n)throw new Error(t+": Failed to find channel "+r);var o=e._GetProperty(i.samplers,n.sampler);if(!o)throw new Error(t+": Failed to find sampler "+n.sampler);this._loadAnimationChannel(i,t+"/channels/"+r,n,t+"/samplers/"+n.sampler,o)}},e.prototype._loadAnimationChannel=function(t,i,r,n,o){var s,a,h=e._GetProperty(this._gltf.nodes,r.target.node);if(!h)throw new Error(i+": Failed to find target node "+r.target.node);switch(r.target.path){case"translation":s="position",a=N.Animation.ANIMATIONTYPE_VECTOR3;break;case"rotation":s="rotationQuaternion",a=N.Animation.ANIMATIONTYPE_QUATERNION;break;case"scale":s="scaling",a=N.Animation.ANIMATIONTYPE_VECTOR3;break;case"weights":s="influence",a=N.Animation.ANIMATIONTYPE_FLOAT;break;default:throw new Error(i+": Invalid target path "+r.target.path)}var l,c,u=function(){if(l&&c){var e,i,r,u=0;switch(s){case"position":e=function(){var e=N.Vector3.FromArray(c,u);return u+=3,e};break;case"rotationQuaternion":e=function(){var e=N.Quaternion.FromArray(c,u);return u+=4,e};break;case"scaling":e=function(){var e=N.Vector3.FromArray(c,u);return u+=3,e};break;case"influence":e=function(){for(var e=h.babylonMesh.morphTargetManager.numTargets,t=new Array(e),i=0;i<e;i++)t[i]=c[u++];return t}}switch(o.interpolation=o.interpolation||"LINEAR",o.interpolation){case"STEP":i=function(t){return{frame:l[t],value:e(),interpolation:N.AnimationKeyInterpolation.STEP}};break;case"LINEAR":i=function(t){return{frame:l[t],value:e()}};break;case"CUBICSPLINE":i=function(t){return{frame:l[t],inTangent:e(),value:e(),outTangent:e()}};break;default:throw new Error(n+": Invalid interpolation "+o.interpolation)}if(1===l.length){var p=i(0);r=[{frame:p.frame,value:p.value},{frame:p.frame+1,value:p.value}]}else{r=new Array(l.length);for(var f=0;f<l.length;f++)r[f]=i(f)}if("influence"===s)for(var d=h.babylonMesh.morphTargetManager,m=0;m<d.numTargets;m++)!function(e){var i=d.getTarget(e),n=(t.name||"anim"+t.index)+"_"+e,o=new N.Animation(n,s,1,a);o.setKeys(r.map(function(t){return{frame:t.frame,inTangent:t.inTangent?t.inTangent[e]:void 0,value:t.value[e],outTangent:t.outTangent?t.outTangent[e]:void 0}})),i.animations.push(o),t.targets.push(i)}(m);else{var g=t.name||"anim"+t.index,_=new N.Animation(g,s,1,a);if(_.setKeys(r),h.babylonAnimationTargets)for(var v=0,y=h.babylonAnimationTargets;v<y.length;v++){var b=y[v];b.animations.push(_.clone()),t.targets.push(b)}}}},p=e._GetProperty(this._gltf.accessors,o.input);if(!p)throw new Error(n+": Failed to find input accessor "+o.input);this._loadAccessorAsync("#/accessors/"+p.index,p,function(e){l=e,u()});var f=e._GetProperty(this._gltf.accessors,o.output);if(!f)throw new Error(n+": Failed to find output accessor "+o.output);this._loadAccessorAsync("#/accessors/"+f.index,f,function(e){c=e,u()})},e.prototype._loadBufferAsync=function(e,t,i){var r=this;if(this._addPendingData(t),t.loadedData)i(t.loadedData),this._removePendingData(t);else if(t.loadedObservable)t.loadedObservable.add(function(e){i(e.loadedData),r._removePendingData(e)});else{if(!t.uri)throw new Error(e+": Uri is missing");t.loadedObservable=new N.Observable,t.loadedObservable.add(function(e){i(e.loadedData),r._removePendingData(e)}),this._loadUriAsync(e,t.uri,function(e){t.loadedData=e,t.loadedObservable.notifyObservers(t),t.loadedObservable=void 0})}},e.prototype._loadBufferViewAsync=function(t,i,r){var n=e._GetProperty(this._gltf.buffers,i.buffer);if(!n)throw new Error(t+": Failed to find buffer "+i.buffer);this._loadBufferAsync("#/buffers/"+n.index,n,function(e){var n;try{n=new Uint8Array(e.buffer,e.byteOffset+(i.byteOffset||0),i.byteLength)}catch(e){throw new Error(t+": "+e.message)}r(n)})},e.prototype._loadAccessorAsync=function(t,i,r){var n=this;if(i.sparse)throw new Error(t+": Sparse accessors are not currently supported");var o=e._GetProperty(this._gltf.bufferViews,i.bufferView);if(!o)throw new Error(t+": Failed to find buffer view "+i.bufferView);this._loadBufferViewAsync("#/bufferViews/"+o.index,o,function(s){var a,h=e._GetNumComponents(t,i.type),l=i.byteOffset||0,c=o.byteStride;0===c&&N.Tools.Warn(t+": Byte stride of 0 is not valid");try{switch(i.componentType){case F.EComponentType.BYTE:a=n._buildArrayBuffer(Float32Array,s,l,i.count,h,c);break;case F.EComponentType.UNSIGNED_BYTE:a=n._buildArrayBuffer(Uint8Array,s,l,i.count,h,c);break;case F.EComponentType.SHORT:a=n._buildArrayBuffer(Int16Array,s,l,i.count,h,c);break;case F.EComponentType.UNSIGNED_SHORT:a=n._buildArrayBuffer(Uint16Array,s,l,i.count,h,c);break;case F.EComponentType.UNSIGNED_INT:a=n._buildArrayBuffer(Uint32Array,s,l,i.count,h,c);break;case F.EComponentType.FLOAT:a=n._buildArrayBuffer(Float32Array,s,l,i.count,h,c);break;default:throw new Error(t+": Invalid component type "+i.componentType)}}catch(e){throw new Error(t+": "+e)}r(a)})},e.prototype._buildArrayBuffer=function(e,t,i,r,n,o){i+=t.byteOffset;var s=r*n;if(!o||o===n*e.BYTES_PER_ELEMENT)return new e(t.buffer,i,s);for(var a=o/e.BYTES_PER_ELEMENT,h=new e(t.buffer,i,a*r),l=new e(s),c=0,u=0;u<s;){for(var p=0;p<n;p++)l[u]=h[c+p],u++;c+=a}return l},e.prototype._addPendingData=function(e){this._renderReady||this._renderPendingCount++,this._addLoaderPendingData(e)},e.prototype._removePendingData=function(e){var t=this;this._renderReady||0==--this._renderPendingCount&&(this._addLoaderPendingData(this),this._compileMaterialsAsync(function(){t._compileShadowGeneratorsAsync(function(){t._removeLoaderPendingData(t),t._renderReady=!0,t._onRenderReady()})})),this._removeLoaderPendingData(e)},e.prototype._addLoaderPendingData=function(e){this._loaderPendingCount++;for(var t=0,i=this._loaderTrackers;t<i.length;t++)i[t]._addPendingData(e)},e.prototype._removeLoaderPendingData=function(e){for(var t=0,i=this._loaderTrackers;t<i.length;t++)i[t]._removePendingData(e);0==--this._loaderPendingCount&&this._onComplete()},e.prototype._whenAction=function(e,t){var i=this,r=new V(function(){i._loaderTrackers.splice(i._loaderTrackers.indexOf(r),1),t()});this._loaderTrackers.push(r),this._addLoaderPendingData(r),e(),this._removeLoaderPendingData(r)},e.prototype._getDefaultMaterial=function(){if(!this._defaultMaterial){var e="__gltf_default",t=this._babylonScene.getMaterialByName(e);t||((t=new N.PBRMaterial(e,this._babylonScene)).transparencyMode=N.PBRMaterial.PBRMATERIAL_OPAQUE,t.sideOrientation=N.Material.ClockWiseSideOrientation,t.metallic=1,t.roughness=1),this._defaultMaterial=t}return this._defaultMaterial},e.prototype._loadMaterialMetallicRoughnessProperties=function(t,i){var r=i.babylonMaterial;r.metallic=1,r.roughness=1;var n=i.pbrMetallicRoughness;if(n){if(r.albedoColor=n.baseColorFactor?N.Color3.FromArray(n.baseColorFactor):new N.Color3(1,1,1),r.metallic=null==n.metallicFactor?1:n.metallicFactor,r.roughness=null==n.roughnessFactor?1:n.roughnessFactor,n.baseColorTexture){if(!(o=e._GetProperty(this._gltf.textures,n.baseColorTexture.index)))throw new Error(t+": Failed to find base color texture "+n.baseColorTexture.index);r.albedoTexture=this._loadTexture("#/textures/"+o.index,o,n.baseColorTexture.texCoord)}if(n.metallicRoughnessTexture){var o;if(!(o=e._GetProperty(this._gltf.textures,n.metallicRoughnessTexture.index)))throw new Error(t+": Failed to find metallic roughness texture "+n.metallicRoughnessTexture.index);r.metallicTexture=this._loadTexture("#/textures/"+o.index,o,n.metallicRoughnessTexture.texCoord),r.useMetallnessFromMetallicTextureBlue=!0,r.useRoughnessFromMetallicTextureGreen=!0,r.useRoughnessFromMetallicTextureAlpha=!1}this._loadMaterialAlphaProperties(t,i,n.baseColorFactor)}},e.prototype._loadMaterial=function(e,t,i){t.babylonMaterial?i(t.babylonMaterial,!1):F.GLTFLoaderExtension.LoadMaterial(this,e,t,i)||(this._createPbrMaterial(t),this._loadMaterialBaseProperties(e,t),this._loadMaterialMetallicRoughnessProperties(e,t),i(t.babylonMaterial,!0))},e.prototype._createPbrMaterial=function(e){var t=new N.PBRMaterial(e.name||"mat"+e.index,this._babylonScene);t.sideOrientation=N.Material.ClockWiseSideOrientation,e.babylonMaterial=t},e.prototype._loadMaterialBaseProperties=function(t,i){var r=i.babylonMaterial;if(r.emissiveColor=i.emissiveFactor?N.Color3.FromArray(i.emissiveFactor):new N.Color3(0,0,0),i.doubleSided&&(r.backFaceCulling=!1,r.twoSidedLighting=!0),i.normalTexture){if(!(n=e._GetProperty(this._gltf.textures,i.normalTexture.index)))throw new Error(t+": Failed to find normal texture "+i.normalTexture.index);r.bumpTexture=this._loadTexture("#/textures/"+n.index,n,i.normalTexture.texCoord),r.invertNormalMapX=!this._babylonScene.useRightHandedSystem,r.invertNormalMapY=this._babylonScene.useRightHandedSystem,null!=i.normalTexture.scale&&(r.bumpTexture.level=i.normalTexture.scale)}if(i.occlusionTexture){if(!(n=e._GetProperty(this._gltf.textures,i.occlusionTexture.index)))throw new Error(t+": Failed to find occlusion texture "+i.occlusionTexture.index);r.ambientTexture=this._loadTexture("#/textures/"+n.index,n,i.occlusionTexture.texCoord),r.useAmbientInGrayScale=!0,null!=i.occlusionTexture.strength&&(r.ambientTextureStrength=i.occlusionTexture.strength)}if(i.emissiveTexture){var n;if(!(n=e._GetProperty(this._gltf.textures,i.emissiveTexture.index)))throw new Error(t+": Failed to find emissive texture "+i.emissiveTexture.index);r.emissiveTexture=this._loadTexture("#/textures/"+n.index,n,i.emissiveTexture.texCoord)}},e.prototype._loadMaterialAlphaProperties=function(e,t,i){var r=t.babylonMaterial;switch(t.alphaMode||"OPAQUE"){case"OPAQUE":r.transparencyMode=N.PBRMaterial.PBRMATERIAL_OPAQUE;break;case"MASK":r.transparencyMode=N.PBRMaterial.PBRMATERIAL_ALPHATEST,r.alphaCutOff=null==t.alphaCutoff?.5:t.alphaCutoff,i&&(0==i[3]?r.alphaCutOff=1:r.alphaCutOff/=i[3]),r.albedoTexture&&(r.albedoTexture.hasAlpha=!0);break;case"BLEND":r.transparencyMode=N.PBRMaterial.PBRMATERIAL_ALPHABLEND,i&&(r.alpha=i[3]),r.albedoTexture&&(r.albedoTexture.hasAlpha=!0,r.useAlphaFromAlbedoTexture=!0);break;default:throw new Error(e+": Invalid alpha mode "+t.alphaMode)}},e.prototype._loadTexture=function(t,i,r){var n=this,o=void 0==i.sampler?this._defaultSampler:e._GetProperty(this._gltf.samplers,i.sampler);if(!o)throw new Error(t+": Failed to find sampler "+i.sampler);this._loadSampler("#/samplers/"+o.index,o),this._addPendingData(i);var s=new N.Texture(null,this._babylonScene,o.noMipMaps,!1,o.samplingMode,function(){n._tryCatchOnError(function(){n._removePendingData(i)})},function(e){n._tryCatchOnError(function(){throw new Error(t+": "+e)})});if(i.url)s.updateURL(i.url);else if(i.dataReadyObservable)i.dataReadyObservable.add(function(e){s.updateURL(e.url)});else{i.dataReadyObservable=new N.Observable,i.dataReadyObservable.add(function(e){s.updateURL(e.url)});var a=e._GetProperty(this._gltf.images,i.source);if(!a)throw new Error(t+": Failed to find source "+i.source);this._loadImageAsync("#/images/"+a.index,a,function(e){i.url=URL.createObjectURL(new Blob([e],{type:a.mimeType})),i.dataReadyObservable.notifyObservers(i),i.dataReadyObservable=void 0})}return s.coordinatesIndex=r||0,s.wrapU=o.wrapU,s.wrapV=o.wrapV,s.name=i.name||"texture"+i.index,this.onTextureLoadedObservable.notifyObservers(s),s},e.prototype._loadSampler=function(t,i){void 0==i.noMipMaps&&(i.noMipMaps=i.minFilter===F.ETextureMinFilter.NEAREST||i.minFilter===F.ETextureMinFilter.LINEAR,i.samplingMode=e._GetTextureSamplingMode(t,i.magFilter,i.minFilter),i.wrapU=e._GetTextureWrapMode(t,i.wrapS),i.wrapV=e._GetTextureWrapMode(t,i.wrapT))},e.prototype._loadImageAsync=function(t,i,r){if(i.uri)this._loadUriAsync(t,i.uri,r);else{var n=e._GetProperty(this._gltf.bufferViews,i.bufferView);if(!n)throw new Error(t+": Failed to find buffer view "+i.bufferView);this._loadBufferViewAsync("#/bufferViews/"+n.index,n,r)}},e.prototype._loadUriAsync=function(e,t,i){var r=this;if(F.GLTFUtils.IsBase64(t))i(new Uint8Array(F.GLTFUtils.DecodeBase64(t)));else{if(!F.GLTFUtils.ValidateUri(t))throw new Error(e+": Uri '"+t+"' is invalid");var n=N.Tools.LoadFile(this._rootUrl+t,function(e){r._tryCatchOnError(function(){i(new Uint8Array(e))})},function(e){r._tryCatchOnError(function(){n&&!r._renderReady&&(n._lengthComputable=e.lengthComputable,n._loaded=e.loaded,n._total=e.total,r._onProgress())})},this._babylonScene.database,!0,function(i,n){r._tryCatchOnError(function(){throw new N.LoadFileError(e+": Failed to load '"+t+"'"+(i?": "+i.status+" "+i.statusText:""),i)})});this._requests.push(n),n.onCompleteObservable.add(function(){r._requests.splice(r._requests.indexOf(n),1)})}},e.prototype._tryCatchOnError=function(e){if(!this._disposed)try{e()}catch(e){N.Tools.Error("glTF Loader: "+e.message),this._errorCallback&&this._errorCallback(e.message,e),this.dispose()}},e._AssignIndices=function(e){if(e)for(var t=0;t<e.length;t++)e[t].index=t},e._GetProperty=function(e,t){return e&&void 0!=t&&e[t]?e[t]:null},e._GetTextureWrapMode=function(e,t){switch(t=void 0==t?F.ETextureWrapMode.REPEAT:t){case F.ETextureWrapMode.CLAMP_TO_EDGE:return N.Texture.CLAMP_ADDRESSMODE;case F.ETextureWrapMode.MIRRORED_REPEAT:return N.Texture.MIRROR_ADDRESSMODE;case F.ETextureWrapMode.REPEAT:return N.Texture.WRAP_ADDRESSMODE;default:return N.Tools.Warn(e+": Invalid texture wrap mode "+t),N.Texture.WRAP_ADDRESSMODE}},e._GetTextureSamplingMode=function(e,t,i){if(t=void 0==t?F.ETextureMagFilter.LINEAR:t,i=void 0==i?F.ETextureMinFilter.LINEAR_MIPMAP_LINEAR:i,t===F.ETextureMagFilter.LINEAR)switch(i){case F.ETextureMinFilter.NEAREST:return N.Texture.LINEAR_NEAREST;case F.ETextureMinFilter.LINEAR:return N.Texture.LINEAR_LINEAR;case F.ETextureMinFilter.NEAREST_MIPMAP_NEAREST:return N.Texture.LINEAR_NEAREST_MIPNEAREST;case F.ETextureMinFilter.LINEAR_MIPMAP_NEAREST:return N.Texture.LINEAR_LINEAR_MIPNEAREST;case F.ETextureMinFilter.NEAREST_MIPMAP_LINEAR:return N.Texture.LINEAR_NEAREST_MIPLINEAR;case F.ETextureMinFilter.LINEAR_MIPMAP_LINEAR:return N.Texture.LINEAR_LINEAR_MIPLINEAR;default:return N.Tools.Warn(e+": Invalid texture minification filter "+i),N.Texture.LINEAR_LINEAR_MIPLINEAR}else switch(t!==F.ETextureMagFilter.NEAREST&&N.Tools.Warn(e+": Invalid texture magnification filter "+t),i){case F.ETextureMinFilter.NEAREST:return N.Texture.NEAREST_NEAREST;case F.ETextureMinFilter.LINEAR:return N.Texture.NEAREST_LINEAR;case F.ETextureMinFilter.NEAREST_MIPMAP_NEAREST:return N.Texture.NEAREST_NEAREST_MIPNEAREST;case F.ETextureMinFilter.LINEAR_MIPMAP_NEAREST:return N.Texture.NEAREST_LINEAR_MIPNEAREST;case F.ETextureMinFilter.NEAREST_MIPMAP_LINEAR:return N.Texture.NEAREST_NEAREST_MIPLINEAR;case F.ETextureMinFilter.LINEAR_MIPMAP_LINEAR:return N.Texture.NEAREST_LINEAR_MIPLINEAR;default:return N.Tools.Warn(e+": Invalid texture minification filter "+i),N.Texture.NEAREST_NEAREST_MIPNEAREST}},e._GetNumComponents=function(e,t){switch(t){case"SCALAR":return 1;case"VEC2":return 2;case"VEC3":return 3;case"VEC4":case"MAT2":return 4;case"MAT3":return 9;case"MAT4":return 16}throw new Error(e+": Invalid type "+t)},e.prototype._compileMaterialAsync=function(e,t,i){var r=this;this.useClipPlane?e.forceCompilation(t,function(){e.forceCompilation(t,function(){r._tryCatchOnError(i)},{clipPlane:!0})}):e.forceCompilation(t,function(){r._tryCatchOnError(i)})},e.prototype._compileMaterialsAsync=function(e){if(this.compileMaterials&&this._gltf.materials){for(var t=this._getMeshes(),i=0,r=0,n=t;r<n.length;r++)if((l=n[r]).material instanceof N.MultiMaterial)for(var o=0,s=l.material.subMaterials;o<s.length;o++)(p=s[o])&&i++;else l.material&&i++;if(0!==i)for(var a=0,h=t;a<h.length;a++){var l;if((l=h[a]).material instanceof N.MultiMaterial)for(var c=0,u=l.material.subMaterials;c<u.length;c++){var p;(p=u[c])&&this._compileMaterialAsync(p,l,function(){0==--i&&e()})}else l.material&&this._compileMaterialAsync(l.material,l,function(){0==--i&&e()})}else e()}else e()},e.prototype._compileShadowGeneratorsAsync=function(e){var t=this;if(this.compileShadowGenerators){for(var i=this._babylonScene.lights,r=0,n=0,o=i;n<o.length;n++)(h=o[n].getShadowGenerator())&&r++;if(0!==r)for(var s=0,a=i;s<a.length;s++){var h;(h=a[s].getShadowGenerator())&&h.forceCompilation(function(){0==--r&&t._tryCatchOnError(e)})}else e()}else e()},e.prototype._abortRequests=function(){for(var e=0,t=this._requests;e<t.length;e++)t[e].abort();this._requests.length=0},e.prototype._releaseResources=function(){if(this._gltf.textures)for(var e=0,t=this._gltf.textures;e<t.length;e++){var i=t[e];i.url&&(URL.revokeObjectURL(i.url),i.url=void 0)}},e.Extensions={},e}(),F.GLTFLoader=k,N.GLTFFileLoader.CreateGLTFLoaderV2=function(){return new k},U=re||(re={}),z=U.GLTF2||(U.GLTF2={}),G=function(){function e(){}return e.IsBase64=function(e){return!(e.length<5)&&"data:"===e.substr(0,5)},e.DecodeBase64=function(e){for(var t=atob(e.split(",")[1]),i=t.length,r=new Uint8Array(new ArrayBuffer(i)),n=0;n<i;n++)r[n]=t.charCodeAt(n);return r.buffer},e.ValidateUri=function(e){return-1===e.indexOf("..")},e}(),z.GLTFUtils=G,W=re||(re={}),H=W.GLTF2||(W.GLTF2={}),j=function(){function e(){this.enabled=!0}return e.prototype._traverseNode=function(e,t,i,r,n){return!1},e.prototype._loadNode=function(e,t,i){return!1},e.prototype._loadMaterial=function(e,t,i,r){return!1},e.prototype._loadExtension=function(e,t,i){var r=this;if(!t.extensions)return!1;var n=t.extensions[this.name];return!!n&&(t.extensions[this.name]=void 0,i(e+"extensions/"+this.name,n,function(){t.extensions[r.name]=n}),!0)},e.TraverseNode=function(e,t,i,r,n){return this._ApplyExtensions(function(o){return o._traverseNode(e,t,i,r,n)})},e.LoadNode=function(e,t,i){return this._ApplyExtensions(function(r){return r._loadNode(e,t,i)})},e.LoadMaterial=function(e,t,i,r){return this._ApplyExtensions(function(n){return n._loadMaterial(e,t,i,r)})},e._ApplyExtensions=function(t){var i=e._Extensions;if(!i)return!1;for(var r=0,n=i;r<n.length;r++){var o=n[r];if(o.enabled&&t(o))return!0}return!1},e._Extensions=[],e}(),H.GLTFLoaderExtension=j,X=re||(re={}),Y=X.GLTF2||(X.GLTF2={}),K=Y.Extensions||(Y.Extensions={}),Q=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.Delay=250,t}return ne(t,e),Object.defineProperty(t.prototype,"name",{get:function(){return"MSFT_lod"},enumerable:!0,configurable:!0}),t.prototype._traverseNode=function(e,t,i,r,n){return this._loadExtension(t,i,function(t,o,s){for(var a=o.ids.length-1;a>=0;a--){var h=Y.GLTFLoader._GetProperty(e._gltf.nodes,o.ids[a]);if(!h)throw new Error(t+": Failed to find node "+o.ids[a]);e._traverseNode(t,h,r,n)}e._traverseNode(t,i,r,n),s()})},t.prototype._loadNode=function(e,t,i){var r=this;return this._loadExtension(t,i,function(t,n,o){for(var s=[i],a=0,h=n.ids;a<h.length;a++){var l=h[a],c=Y.GLTFLoader._GetProperty(e._gltf.nodes,l);if(!c)throw new Error(t+": Failed to find node "+l);s.push(c)}e._addLoaderPendingData(i),r._loadNodeLOD(e,t,s,s.length-1,function(){e._removeLoaderPendingData(i),o()})})},t.prototype._loadNodeLOD=function(e,t,i,r,n){var o=this;e._whenAction(function(){e._loadNode(t,i[r])},function(){r!==i.length-1&&i[r+1].babylonMesh.setEnabled(!1),0!==r?setTimeout(function(){e._tryCatchOnError(function(){o._loadNodeLOD(e,t,i,r-1,n)})},o.Delay):n()})},t.prototype._loadMaterial=function(e,t,i,r){var n=this;return this._loadExtension(t,i,function(t,o,s){for(var a=[i],h=0,l=o.ids;h<l.length;h++){var c=l[h],u=Y.GLTFLoader._GetProperty(e._gltf.materials,c);if(!u)throw new Error(t+": Failed to find material "+c);a.push(u)}e._addLoaderPendingData(i),n._loadMaterialLOD(e,t,a,a.length-1,r,function(){e._removeLoaderPendingData(i),s()})})},t.prototype._loadMaterialLOD=function(e,t,i,r,n,o){var s=this;e._loadMaterial(t,i[r],function(a,h){r===i.length-1?(n(a,h),e._executeWhenRenderReady(function(){s._loadMaterialLOD(e,t,i,r-1,n,o)})):X.BaseTexture.WhenAllReady(a.getActiveTextures(),function(){n(a,h),0===r?o():setTimeout(function(){e._tryCatchOnError(function(){s._loadMaterialLOD(e,t,i,r-1,n,o)})},s.Delay)})})},t}(Y.GLTFLoaderExtension),K.MSFTLOD=Q,Y.GLTFLoader.RegisterExtension(new Q),J=re||(re={}),$=J.GLTF2||(J.GLTF2={}),ee=$.Extensions||($.Extensions={}),te=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return ne(t,e),Object.defineProperty(t.prototype,"name",{get:function(){return"KHR_materials_pbrSpecularGlossiness"},enumerable:!0,configurable:!0}),t.prototype._loadMaterial=function(e,t,i,r){var n=this;return this._loadExtension(t,i,function(t,o,s){e._createPbrMaterial(i),e._loadMaterialBaseProperties(t,i),n._loadSpecularGlossinessProperties(e,t,i,o),r(i.babylonMaterial,!0),s()})},t.prototype._loadSpecularGlossinessProperties=function(e,t,i,r){var n=i.babylonMaterial;if(n.albedoColor=r.diffuseFactor?J.Color3.FromArray(r.diffuseFactor):new J.Color3(1,1,1),n.reflectivityColor=r.specularFactor?J.Color3.FromArray(r.specularFactor):new J.Color3(1,1,1),n.microSurface=null==r.glossinessFactor?1:r.glossinessFactor,r.diffuseTexture){if(!(o=$.GLTFLoader._GetProperty(e._gltf.textures,r.diffuseTexture.index)))throw new Error(t+": Failed to find diffuse texture "+r.diffuseTexture.index);n.albedoTexture=e._loadTexture("textures["+o.index+"]",o,r.diffuseTexture.texCoord)}if(r.specularGlossinessTexture){var o;if(!(o=$.GLTFLoader._GetProperty(e._gltf.textures,r.specularGlossinessTexture.index)))throw new Error(t+": Failed to find diffuse texture "+r.specularGlossinessTexture.index);n.reflectivityTexture=e._loadTexture("textures["+o.index+"]",o,r.specularGlossinessTexture.texCoord),n.reflectivityTexture.hasAlpha=!0,n.useMicroSurfaceFromReflectivityMapAlpha=!0}e._loadMaterialAlphaProperties(t,i,r.diffuseFactor)},t}($.GLTFLoaderExtension),ee.KHRMaterialsPbrSpecularGlossiness=te,$.GLTFLoader.RegisterExtension(new te),Z=this,q=function(){return re}(),Z&&Z.BABYLON||(e.exports=q)}).call(t,i(1))},function(e,t,i){var r;r=function(){"use strict";function e(e,t){t=t||Object.create(null);var i=document.createEvent("Event");i.initEvent(e,t.bubbles||!1,t.cancelable||!1);for(var r,n=2;n<l.length;n++)r=l[n],i[r]=t[r]||c[n];i.buttons=t.buttons||0;var o;return o=t.pressure&&i.buttons?t.pressure:i.buttons?.5:0,i.x=i.clientX,i.y=i.clientY,i.pointerId=t.pointerId||0,i.width=t.width||0,i.height=t.height||0,i.pressure=o,i.tiltX=t.tiltX||0,i.tiltY=t.tiltY||0,i.twist=t.twist||0,i.tangentialPressure=t.tangentialPressure||0,i.pointerType=t.pointerType||"",i.hwTimestamp=t.hwTimestamp||0,i.isPrimary=t.isPrimary||!1,i}function t(){this.array=[],this.size=0}function i(e,t,i,r){this.addCallback=e.bind(r),this.removeCallback=t.bind(r),this.changedCallback=i.bind(r),T&&(this.observer=new T(this.mutationWatcher.bind(this)))}function r(e){return"body /shadow-deep/ "+n(e)}function n(e){return'[touch-action="'+e+'"]'}function o(e){return"{ -ms-touch-action: "+e+"; touch-action: "+e+"; }"}function s(e){if(!g.pointermap.has(e)){var t=new Error("InvalidPointerId");throw t.name="InvalidPointerId",t}}function a(e){for(var t=e.parentNode;t&&t!==e.ownerDocument;)t=t.parentNode;if(!t){var i=new Error("InvalidStateError");throw i.name="InvalidStateError",i}}function h(e){return 0!==g.pointermap.get(e).buttons}var l=["bubbles","cancelable","view","detail","screenX","screenY","clientX","clientY","ctrlKey","altKey","shiftKey","metaKey","button","relatedTarget","pageX","pageY"],c=[!1,!1,null,null,0,0,0,0,!1,!1,!1,!1,0,null,0,0],u=window.Map&&window.Map.prototype.forEach?Map:t;t.prototype={set:function(e,t){return void 0===t?this.delete(e):(this.has(e)||this.size++,void(this.array[e]=t))},has:function(e){return void 0!==this.array[e]},delete:function(e){this.has(e)&&(delete this.array[e],this.size--)},get:function(e){return this.array[e]},clear:function(){this.array.length=0,this.size=0},forEach:function(e,t){return this.array.forEach(function(i,r){e.call(t,i,r,this)},this)}};var p=["bubbles","cancelable","view","detail","screenX","screenY","clientX","clientY","ctrlKey","altKey","shiftKey","metaKey","button","relatedTarget","buttons","pointerId","width","height","pressure","tiltX","tiltY","pointerType","hwTimestamp","isPrimary","type","target","currentTarget","which","pageX","pageY","timeStamp"],f=[!1,!1,null,null,0,0,0,0,!1,!1,!1,!1,0,null,0,0,0,0,0,0,0,"",0,!1,"",null,null,0,0,0,0],d={pointerover:1,pointerout:1,pointerenter:1,pointerleave:1},m="undefined"!=typeof SVGElementInstance,g={pointermap:new u,eventMap:Object.create(null),captureInfo:Object.create(null),eventSources:Object.create(null),eventSourceList:[],registerSource:function(e,t){var i=t,r=i.events;r&&(r.forEach(function(e){i[e]&&(this.eventMap[e]=i[e].bind(i))},this),this.eventSources[e]=i,this.eventSourceList.push(i))},register:function(e){for(var t,i=this.eventSourceList.length,r=0;r<i&&(t=this.eventSourceList[r]);r++)t.register.call(t,e)},unregister:function(e){for(var t,i=this.eventSourceList.length,r=0;r<i&&(t=this.eventSourceList[r]);r++)t.unregister.call(t,e)},contains:function(e,t){try{return e.contains(t)}catch(e){return!1}},down:function(e){e.bubbles=!0,this.fireEvent("pointerdown",e)},move:function(e){e.bubbles=!0,this.fireEvent("pointermove",e)},up:function(e){e.bubbles=!0,this.fireEvent("pointerup",e)},enter:function(e){e.bubbles=!1,this.fireEvent("pointerenter",e)},leave:function(e){e.bubbles=!1,this.fireEvent("pointerleave",e)},over:function(e){e.bubbles=!0,this.fireEvent("pointerover",e)},out:function(e){e.bubbles=!0,this.fireEvent("pointerout",e)},cancel:function(e){e.bubbles=!0,this.fireEvent("pointercancel",e)},leaveOut:function(e){this.out(e),this.propagate(e,this.leave,!1)},enterOver:function(e){this.over(e),this.propagate(e,this.enter,!0)},eventHandler:function(e){if(!e._handledByPE){var t=e.type,i=this.eventMap&&this.eventMap[t];i&&i(e),e._handledByPE=!0}},listen:function(e,t){t.forEach(function(t){this.addEvent(e,t)},this)},unlisten:function(e,t){t.forEach(function(t){this.removeEvent(e,t)},this)},addEvent:function(e,t){e.addEventListener(t,this.boundHandler)},removeEvent:function(e,t){e.removeEventListener(t,this.boundHandler)},makeEvent:function(t,i){this.captureInfo[i.pointerId]&&(i.relatedTarget=null);var r=new e(t,i);return i.preventDefault&&(r.preventDefault=i.preventDefault),r._target=r._target||i.target,r},fireEvent:function(e,t){var i=this.makeEvent(e,t);return this.dispatchEvent(i)},cloneEvent:function(e){for(var t,i=Object.create(null),r=0;r<p.length;r++)t=p[r],i[t]=e[t]||f[r],!m||"target"!==t&&"relatedTarget"!==t||i[t]instanceof SVGElementInstance&&(i[t]=i[t].correspondingUseElement);return e.preventDefault&&(i.preventDefault=function(){e.preventDefault()}),i},getTarget:function(e){var t=this.captureInfo[e.pointerId];return t?e._target!==t&&e.type in d?void 0:t:e._target},propagate:function(e,t,i){for(var r=e.target,n=[];r!==document&&!r.contains(e.relatedTarget);)if(n.push(r),r=r.parentNode,!r)return;i&&n.reverse(),n.forEach(function(i){e.target=i,t.call(this,e)},this)},setCapture:function(t,i,r){this.captureInfo[t]&&this.releaseCapture(t,r),this.captureInfo[t]=i,this.implicitRelease=this.releaseCapture.bind(this,t,r),document.addEventListener("pointerup",this.implicitRelease),document.addEventListener("pointercancel",this.implicitRelease);var n=new e("gotpointercapture");n.pointerId=t,n._target=i,r||this.asyncDispatchEvent(n)},releaseCapture:function(t,i){var r=this.captureInfo[t];if(r){this.captureInfo[t]=void 0,document.removeEventListener("pointerup",this.implicitRelease),document.removeEventListener("pointercancel",this.implicitRelease);var n=new e("lostpointercapture");n.pointerId=t,n._target=r,i||this.asyncDispatchEvent(n)}},dispatchEvent:function(e){var t=this.getTarget(e);if(t)return t.dispatchEvent(e)},asyncDispatchEvent:function(e){requestAnimationFrame(this.dispatchEvent.bind(this,e))}};g.boundHandler=g.eventHandler.bind(g);var _={shadow:function(e){if(e)return e.shadowRoot||e.webkitShadowRoot},canTarget:function(e){return e&&Boolean(e.elementFromPoint)},targetingShadow:function(e){var t=this.shadow(e);if(this.canTarget(t))return t},olderShadow:function(e){var t=e.olderShadowRoot;if(!t){var i=e.querySelector("shadow");i&&(t=i.olderShadowRoot)}return t},allShadows:function(e){for(var t=[],i=this.shadow(e);i;)t.push(i),i=this.olderShadow(i);return t},searchRoot:function(e,t,i){if(e){var r,n,o=e.elementFromPoint(t,i);for(n=this.targetingShadow(o);n;){if(r=n.elementFromPoint(t,i)){var s=this.targetingShadow(r);return this.searchRoot(s,t,i)||r}n=this.olderShadow(n)}return o}},owner:function(e){for(var t=e;t.parentNode;)t=t.parentNode;return t.nodeType!==Node.DOCUMENT_NODE&&t.nodeType!==Node.DOCUMENT_FRAGMENT_NODE&&(t=document),t},findTarget:function(e){var t=e.clientX,i=e.clientY,r=this.owner(e.target);return r.elementFromPoint(t,i)||(r=document),this.searchRoot(r,t,i)}},v=Array.prototype.forEach.call.bind(Array.prototype.forEach),y=Array.prototype.map.call.bind(Array.prototype.map),b=Array.prototype.slice.call.bind(Array.prototype.slice),x=Array.prototype.filter.call.bind(Array.prototype.filter),T=window.MutationObserver||window.WebKitMutationObserver,E={subtree:!0,childList:!0,attributes:!0,attributeOldValue:!0,attributeFilter:["touch-action"]};i.prototype={watchSubtree:function(e){this.observer&&_.canTarget(e)&&this.observer.observe(e,E)},enableOnSubtree:function(e){this.watchSubtree(e),e===document&&"complete"!==document.readyState?this.installOnLoad():this.installNewSubtree(e)},installNewSubtree:function(e){v(this.findElements(e),this.addElement,this)},findElements:function(e){return e.querySelectorAll?e.querySelectorAll("[touch-action]"):[]},removeElement:function(e){this.removeCallback(e)},addElement:function(e){this.addCallback(e)},elementChanged:function(e,t){this.changedCallback(e,t)},concatLists:function(e,t){return e.concat(b(t))},installOnLoad:function(){document.addEventListener("readystatechange",function(){"complete"===document.readyState&&this.installNewSubtree(document)}.bind(this))},isElement:function(e){return e.nodeType===Node.ELEMENT_NODE},flattenMutationTree:function(e){var t=y(e,this.findElements,this);return t.push(x(e,this.isElement)),t.reduce(this.concatLists,[])},mutationWatcher:function(e){e.forEach(this.mutationHandler,this)},mutationHandler:function(e){"childList"===e.type?(this.flattenMutationTree(e.addedNodes).forEach(this.addElement,this),this.flattenMutationTree(e.removedNodes).forEach(this.removeElement,this)):"attributes"===e.type&&this.elementChanged(e.target,e.oldValue)}};var A=["none","auto","pan-x","pan-y",{rule:"pan-x pan-y",selectors:["pan-x pan-y","pan-y pan-x"]}],P="",M=window.PointerEvent||window.MSPointerEvent,S=!window.ShadowDOMPolyfill&&document.head.createShadowRoot,C=g.pointermap,R=[1,4,2,8,16],O=!1;try{O=1===new MouseEvent("test",{buttons:1}).buttons}catch(e){}var I,w={POINTER_ID:1,POINTER_TYPE:"mouse",events:["mousedown","mousemove","mouseup","mouseover","mouseout"],register:function(e){g.listen(e,this.events)},unregister:function(e){g.unlisten(e,this.events)},lastTouches:[],isEventSimulatedFromTouch:function(e){for(var t,i=this.lastTouches,r=e.clientX,n=e.clientY,o=0,s=i.length;o<s&&(t=i[o]);o++){var a=Math.abs(r-t.x),h=Math.abs(n-t.y);if(a<=25&&h<=25)return!0}},prepareEvent:function(e){var t=g.cloneEvent(e),i=t.preventDefault;return t.preventDefault=function(){e.preventDefault(),i()},t.pointerId=this.POINTER_ID,t.isPrimary=!0,t.pointerType=this.POINTER_TYPE,t},prepareButtonsForMove:function(e,t){var i=C.get(this.POINTER_ID);0!==t.which&&i?e.buttons=i.buttons:e.buttons=0,t.buttons=e.buttons},mousedown:function(e){if(!this.isEventSimulatedFromTouch(e)){var t=C.get(this.POINTER_ID),i=this.prepareEvent(e);O||(i.buttons=R[i.button],t&&(i.buttons|=t.buttons),e.buttons=i.buttons),C.set(this.POINTER_ID,e),t&&0!==t.buttons?g.move(i):g.down(i)}},mousemove:function(e){if(!this.isEventSimulatedFromTouch(e)){var t=this.prepareEvent(e);O||this.prepareButtonsForMove(t,e),t.button=-1,C.set(this.POINTER_ID,e),g.move(t)}},mouseup:function(e){if(!this.isEventSimulatedFromTouch(e)){var t=C.get(this.POINTER_ID),i=this.prepareEvent(e);if(!O){var r=R[i.button];i.buttons=t?t.buttons&~r:0,e.buttons=i.buttons}C.set(this.POINTER_ID,e),i.buttons&=~R[i.button],0===i.buttons?g.up(i):g.move(i)}},mouseover:function(e){if(!this.isEventSimulatedFromTouch(e)){var t=this.prepareEvent(e);O||this.prepareButtonsForMove(t,e),t.button=-1,C.set(this.POINTER_ID,e),g.enterOver(t)}},mouseout:function(e){if(!this.isEventSimulatedFromTouch(e)){var t=this.prepareEvent(e);O||this.prepareButtonsForMove(t,e),t.button=-1,g.leaveOut(t)}},cancel:function(e){var t=this.prepareEvent(e);g.cancel(t),this.deactivateMouse()},deactivateMouse:function(){C.delete(this.POINTER_ID)}},D=g.captureInfo,L=_.findTarget.bind(_),B=_.allShadows.bind(_),N=g.pointermap,F="touch-action",V={events:["touchstart","touchmove","touchend","touchcancel"],register:function(e){I.enableOnSubtree(e)},unregister:function(){},elementAdded:function(e){var t=e.getAttribute(F),i=this.touchActionToScrollType(t);i&&(e._scrollType=i,g.listen(e,this.events),B(e).forEach(function(e){e._scrollType=i,g.listen(e,this.events)},this))},elementRemoved:function(e){e._scrollType=void 0,g.unlisten(e,this.events),B(e).forEach(function(e){e._scrollType=void 0,g.unlisten(e,this.events)},this)},elementChanged:function(e,t){var i=e.getAttribute(F),r=this.touchActionToScrollType(i),n=this.touchActionToScrollType(t);r&&n?(e._scrollType=r,B(e).forEach(function(e){e._scrollType=r},this)):n?this.elementRemoved(e):r&&this.elementAdded(e)},scrollTypes:{EMITTER:"none",XSCROLLER:"pan-x",YSCROLLER:"pan-y",SCROLLER:/^(?:pan-x pan-y)|(?:pan-y pan-x)|auto$/},touchActionToScrollType:function(e){var t=e,i=this.scrollTypes;return"none"===t?"none":t===i.XSCROLLER?"X":t===i.YSCROLLER?"Y":i.SCROLLER.exec(t)?"XY":void 0},POINTER_TYPE:"touch",firstTouch:null,isPrimaryTouch:function(e){return this.firstTouch===e.identifier},setPrimaryTouch:function(e){(0===N.size||1===N.size&&N.has(1))&&(this.firstTouch=e.identifier,this.firstXY={X:e.clientX,Y:e.clientY},this.scrolling=!1,this.cancelResetClickCount())},removePrimaryPointer:function(e){e.isPrimary&&(this.firstTouch=null,this.firstXY=null,this.resetClickCount())},clickCount:0,resetId:null,resetClickCount:function(){var e=function(){this.clickCount=0,this.resetId=null}.bind(this);this.resetId=setTimeout(e,200)},cancelResetClickCount:function(){this.resetId&&clearTimeout(this.resetId)},typeToButtons:function(e){var t=0;return"touchstart"!==e&&"touchmove"!==e||(t=1),t},touchToPointer:function(e){var t=this.currentTouchEvent,i=g.cloneEvent(e),r=i.pointerId=e.identifier+2;i.target=D[r]||L(i),i.bubbles=!0,i.cancelable=!0,i.detail=this.clickCount,i.button=0,i.buttons=this.typeToButtons(t.type),i.width=2*(e.radiusX||e.webkitRadiusX||0),i.height=2*(e.radiusY||e.webkitRadiusY||0),i.pressure=e.force||e.webkitForce||.5,i.isPrimary=this.isPrimaryTouch(e),i.pointerType=this.POINTER_TYPE,i.altKey=t.altKey,i.ctrlKey=t.ctrlKey,i.metaKey=t.metaKey,i.shiftKey=t.shiftKey;var n=this;return i.preventDefault=function(){n.scrolling=!1,n.firstXY=null,t.preventDefault()},i},processTouches:function(e,t){var i=e.changedTouches;this.currentTouchEvent=e;for(var r,n=0;n<i.length;n++)r=i[n],t.call(this,this.touchToPointer(r))},shouldScroll:function(e){if(this.firstXY){var t,i=e.currentTarget._scrollType;if("none"===i)t=!1;else if("XY"===i)t=!0;else{var r=e.changedTouches[0],n=i,o="Y"===i?"X":"Y";t=Math.abs(r["client"+n]-this.firstXY[n])>=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<n&&(i=e[r]);r++)if(i.identifier===t)return!0},vacuumTouches:function(e){var t=e.touches;if(N.size>=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)}}};I=new i(V.elementAdded,V.elementRemoved,V.elementChanged,V);var k,U,z,G=g.pointermap,W=window.MSPointerEvent&&"number"==typeof window.MSPointerEvent.MSPOINTER_TYPE_MOUSE,H={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 W&&((t=g.cloneEvent(e)).pointerType=this.POINTER_TYPES[e.pointerType]),t},cleanup:function(e){G.delete(e)},MSPointerDown:function(e){G.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)}};return window.navigator.msPointerEnabled?(k=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)}):(k=function(e){s(e),a(this),h(e)&&g.setCapture(e,this)},U=function(e){s(e),g.releaseCapture(e)}),z=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",H)}else Object.defineProperty(window.navigator,"maxTouchPoints",{value:0,enumerable:!0}),g.registerSource("mouse",w),void 0!==window.ontouchstart&&g.registerSource("touch",V);g.register(document)}}(),window.Element&&!Element.prototype.setPointerCapture&&Object.defineProperties(Element.prototype,{setPointerCapture:{value:k},releasePointerCapture:{value:U},hasPointerCapture:{value:z}}),{dispatcher:g,Installer:i,PointerEvent:e,PointerMap:u,targetFinding:_}},e.exports=r()},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=i(5),n=i(2);t.InitTags=function(e){void 0===e&&(e="babylon");for(var t=document.querySelectorAll(e),i=0;i<t.length;++i){var o=t.item(i),s=n.mapperManager.getMapper("dom").map(o);new r.DefaultViewer(o,s)}}},function(e,t,i){(function(t,r){var n;n=function(){"use strict";function e(e){return"function"==typeof e}var n=Array.isArray?Array.isArray:function(e){return"[object Array]"===Object.prototype.toString.call(e)},o=0,s=void 0,a=void 0,h=function(e,t){m[o]=e,m[o+1]=t,2===(o+=2)&&(a?a(g):x())};var l="undefined"!=typeof window?window:void 0,c=l||{},u=c.MutationObserver||c.WebKitMutationObserver,p="undefined"==typeof self&&void 0!==t&&"[object process]"==={}.toString.call(t),f="undefined"!=typeof Uint8ClampedArray&&"undefined"!=typeof importScripts&&"undefined"!=typeof MessageChannel;function d(){var e=setTimeout;return function(){return e(g,1)}}var m=new Array(1e3);function g(){for(var e=0;e<o;e+=2){(0,m[e])(m[e+1]),m[e]=void 0,m[e+1]=void 0}o=0}var _,v,y,b,x=void 0;function T(e,t){var i=this,r=new this.constructor(P);void 0===r[A]&&G(r);var n=i._state;if(n){var o=arguments[n-1];h(function(){return U(n,r,o,i._result)})}else N(i,r,e,t);return r}function E(e){if(e&&"object"==typeof e&&e.constructor===this)return e;var t=new this(P);return w(t,e),t}p?x=function(){return t.nextTick(g)}:u?(v=0,y=new u(g),b=document.createTextNode(""),y.observe(b,{characterData:!0}),x=function(){b.data=v=++v%2}):f?((_=new MessageChannel).port1.onmessage=g,x=function(){return _.port2.postMessage(0)}):x=void 0===l?function(){try{var e=i(35);return void 0!==(s=e.runOnLoop||e.runOnContext)?function(){s(g)}:d()}catch(e){return d()}}():d();var A=Math.random().toString(36).substring(16);function P(){}var M=void 0,S=1,C=2,R=new V;function O(e){try{return e.then}catch(e){return R.error=e,R}}function I(t,i,r){var n,o,s,a;i.constructor===t.constructor&&r===T&&i.constructor.resolve===E?(s=t,(a=i)._state===S?L(s,a._result):a._state===C?B(s,a._result):N(a,void 0,function(e){return w(s,e)},function(e){return B(s,e)})):r===R?(B(t,R.error),R.error=null):void 0===r?L(t,i):e(r)?(n=i,o=r,h(function(e){var t=!1,i=function(e,t,i,r){try{e.call(t,i,r)}catch(e){return e}}(o,n,function(i){t||(t=!0,n!==i?w(e,i):L(e,i))},function(i){t||(t=!0,B(e,i))},e._label);!t&&i&&(t=!0,B(e,i))},t)):L(t,i)}function w(e,t){var i,r;e===t?B(e,new TypeError("You cannot resolve a promise with itself")):(r=typeof(i=t),null===i||"object"!==r&&"function"!==r?L(e,t):I(e,t,O(t)))}function D(e){e._onerror&&e._onerror(e._result),F(e)}function L(e,t){e._state===M&&(e._result=t,e._state=S,0!==e._subscribers.length&&h(F,e))}function B(e,t){e._state===M&&(e._state=C,e._result=t,h(D,e))}function N(e,t,i,r){var n=e._subscribers,o=n.length;e._onerror=null,n[o]=t,n[o+S]=i,n[o+C]=r,0===o&&e._state&&h(F,e)}function F(e){var t=e._subscribers,i=e._state;if(0!==t.length){for(var r=void 0,n=void 0,o=e._result,s=0;s<t.length;s+=3)r=t[s],n=t[s+i],r?U(i,r,n,o):n(o);e._subscribers.length=0}}function V(){this.error=null}var k=new V;function U(t,i,r,n){var o=e(r),s=void 0,a=void 0,h=void 0,l=void 0;if(o){if((s=function(e,t){try{return e(t)}catch(e){return k.error=e,k}}(r,n))===k?(l=!0,a=s.error,s.error=null):h=!0,i===s)return void B(i,new TypeError("A promises callback cannot return that same promise."))}else s=n,h=!0;i._state!==M||(o&&h?w(i,s):l?B(i,a):t===S?L(i,s):t===C&&B(i,s))}var z=0;function G(e){e[A]=z++,e._state=void 0,e._result=void 0,e._subscribers=[]}var W=function(){function e(e,t){this._instanceConstructor=e,this.promise=new e(P),this.promise[A]||G(this.promise),n(t)?(this.length=t.length,this._remaining=t.length,this._result=new Array(this.length),0===this.length?L(this.promise,this._result):(this.length=this.length||0,this._enumerate(t),0===this._remaining&&L(this.promise,this._result))):B(this.promise,new Error("Array Methods must be provided an Array"))}return e.prototype._enumerate=function(e){for(var t=0;this._state===M&&t<e.length;t++)this._eachEntry(e[t],t)},e.prototype._eachEntry=function(e,t){var i=this._instanceConstructor,r=i.resolve;if(r===E){var n=O(e);if(n===T&&e._state!==M)this._settledAt(e._state,t,e._result);else if("function"!=typeof n)this._remaining--,this._result[t]=e;else if(i===H){var o=new i(P);I(o,e,n),this._willSettleAt(o,t)}else this._willSettleAt(new i(function(t){return t(e)}),t)}else this._willSettleAt(r(e),t)},e.prototype._settledAt=function(e,t,i){var r=this.promise;r._state===M&&(this._remaining--,e===C?B(r,i):this._result[t]=i),0===this._remaining&&L(r,this._result)},e.prototype._willSettleAt=function(e,t){var i=this;N(e,void 0,function(e){return i._settledAt(S,t,e)},function(e){return i._settledAt(C,t,e)})},e}();var H=function(){function e(t){this[A]=z++,this._result=this._state=void 0,this._subscribers=[],P!==t&&("function"!=typeof t&&function(){throw new TypeError("You must pass a resolver function as the first argument to the promise constructor")}(),this instanceof e?function(e,t){try{t(function(t){w(e,t)},function(t){B(e,t)})}catch(t){B(e,t)}}(this,t):function(){throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.")}())}return e.prototype.catch=function(e){return this.then(null,e)},e.prototype.finally=function(e){var t=this.constructor;return this.then(function(i){return t.resolve(e()).then(function(){return i})},function(i){return t.resolve(e()).then(function(){throw i})})},e}();return H.prototype.then=T,H.all=function(e){return new W(this,e).promise},H.race=function(e){var t=this;return n(e)?new t(function(i,r){for(var n=e.length,o=0;o<n;o++)t.resolve(e[o]).then(i,r)}):new t(function(e,t){return t(new TypeError("You must pass an array to race."))})},H.resolve=E,H.reject=function(e){var t=new this(P);return B(t,e),t},H._setScheduler=function(e){a=e},H._setAsap=function(e){h=e},H._asap=h,H.polyfill=function(){var e=void 0;if(void 0!==r)e=r;else if("undefined"!=typeof self)e=self;else try{e=Function("return this")()}catch(e){throw new Error("polyfill failed because global object is unavailable in this environment")}var t=e.Promise;if(t){var i=null;try{i=Object.prototype.toString.call(t.resolve())}catch(e){}if("[object Promise]"===i&&!t.cast)return}e.Promise=H},H.Promise=H,H},e.exports=n()}).call(t,i(34),i(1))},function(e,t){var i,r,n=e.exports={};function o(){throw new Error("setTimeout has not been defined")}function s(){throw new Error("clearTimeout has not been defined")}function a(e){if(i===setTimeout)return setTimeout(e,0);if((i===o||!i)&&setTimeout)return i=setTimeout,setTimeout(e,0);try{return i(e,0)}catch(t){try{return i.call(null,e,0)}catch(t){return i.call(this,e,0)}}}!function(){try{i="function"==typeof setTimeout?setTimeout:o}catch(e){i=o}try{r="function"==typeof clearTimeout?clearTimeout:s}catch(e){r=s}}();var h,l=[],c=!1,u=-1;function p(){c&&h&&(c=!1,h.length?l=h.concat(l):u=-1,l.length&&f())}function f(){if(!c){var e=a(p);c=!0;for(var t=l.length;t;){for(h=l,l=[];++u<t;)h&&h[u].run();u=-1,t=l.length}h=null,c=!1,function(e){if(r===clearTimeout)return clearTimeout(e);if((r===s||!r)&&clearTimeout)return r=clearTimeout,clearTimeout(e);try{r(e)}catch(t){try{return r.call(null,e)}catch(t){return r.call(this,e)}}}(e)}}function d(e,t){this.fun=e,this.array=t}function m(){}n.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var i=1;i<arguments.length;i++)t[i-1]=arguments[i];l.push(new d(e,t)),1!==l.length||c||a(f)},d.prototype.run=function(){this.fun.apply(null,this.array)},n.title="browser",n.browser=!0,n.env={},n.argv=[],n.version="",n.versions={},n.on=m,n.addListener=m,n.once=m,n.off=m,n.removeListener=m,n.removeAllListeners=m,n.emit=m,n.prependListener=m,n.prependOnceListener=m,n.listeners=function(e){return[]},n.binding=function(e){throw new Error("process.binding is not supported")},n.cwd=function(){return"/"},n.chdir=function(e){throw new Error("process.chdir is not supported")},n.umask=function(){return 0}},function(e,t){}])});
|