var __decorate=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},__extends=this&&this.__extends||(function(){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i])};return function(t,i){function r(){this.constructor=t}e(t,i),t.prototype=null===i?Object.create(i):(r.prototype=i.prototype,new r)}})();!(function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("babylonjs",[],t):"object"==typeof exports?exports.babylonjs=t():e.BABYLON=t(e.BABYLON)})(this,(function(){var e;!(function(e){var t=(function(){function e(){this._defines={},this._currentRank=32,this._maxRank=-1}return e.prototype.unBindMesh=function(){this._mesh=null},e.prototype.addFallback=function(e,t){this._defines[e]||(ethis._maxRank&&(this._maxRank=e),this._defines[e]=new Array),this._defines[e].push(t)},e.prototype.addCPUSkinningFallback=function(e,t){this._mesh=t,ethis._maxRank&&(this._maxRank=e)},Object.defineProperty(e.prototype,"isMoreFallbacks",{get:function(){return this._currentRank<=this._maxRank},enumerable:!0,configurable:!0}),e.prototype.reduce=function(e,t){if(this._mesh&&this._mesh.computeBonesUsingShaders&&this._mesh.numBoneInfluencers>0&&this._mesh.material){this._mesh.computeBonesUsingShaders=!1,e=e.replace("#define NUM_BONE_INFLUENCERS "+this._mesh.numBoneInfluencers,"#define NUM_BONE_INFLUENCERS 0");for(var i=this._mesh.getScene(),r=0;r-1?i:e.Engine.ShadersRepository+i,this._engine._loadFileAsync(o+".vertex.fx")},t.prototype._loadFragmentShaderAsync=function(i){if(e.Tools.IsWindowObjectExist()&&i instanceof HTMLElement){var r=e.Tools.GetDOMTextContent(i);return Promise.resolve(r)}if("base64:"===i.substr(0,7)){var n=window.atob(i.substr(7));return Promise.resolve(n)}if(t.ShadersStore[i+"PixelShader"])return Promise.resolve(t.ShadersStore[i+"PixelShader"]);if(t.ShadersStore[i+"FragmentShader"])return Promise.resolve(t.ShadersStore[i+"FragmentShader"]);var o;return o="."===i[0]||"/"===i[0]||i.indexOf("http")>-1?i:e.Engine.ShadersRepository+i,this._engine._loadFileAsync(o+".fragment.fx")},t.prototype._dumpShadersSource=function(t,i,r){var n=this._engine.webGLVersion>1?"#version 300 es\n":"",o=n+(r?r+"\n":"");t=o+t,i=o+i;var s=2,a=/\n/gm,l="\n1\t"+t.replace(a,(function(){return"\n"+s+++"\t"}));s=2;var c="\n1\t"+i.replace(a,(function(){return"\n"+s+++"\t"}));this.name.vertexElement?(e.Tools.Error("Vertex shader: "+this.name.vertexElement+l),e.Tools.Error("Fragment shader: "+this.name.fragmentElement+c)):this.name.vertex?(e.Tools.Error("Vertex shader: "+this.name.vertex+l),e.Tools.Error("Fragment shader: "+this.name.fragment+c)):(e.Tools.Error("Vertex shader: "+this.name+l),e.Tools.Error("Fragment shader: "+this.name+c))},t.prototype._processShaderConversion=function(e,t){var i=this._processPrecision(e);if(1==this._engine.webGLVersion)return i;if(-1!==i.indexOf("#version 3"))return i.replace("#version 300 es","");var r=-1!==i.search(/#extension.+GL_EXT_draw_buffers.+require/),n=/#extension.+(GL_OES_standard_derivatives|GL_EXT_shader_texture_lod|GL_EXT_frag_depth|GL_EXT_draw_buffers).+(enable|require)/g,o=i.replace(n,"");return o=o.replace(/varying(?![\n\r])\s/g,t?"in ":"out "),o=o.replace(/attribute[ \t]/g,"in "),o=o.replace(/[ \t]attribute/g," in"),t&&(o=o.replace(/texture2DLodEXT\s*\(/g,"textureLod("),o=o.replace(/textureCubeLodEXT\s*\(/g,"textureLod("),o=o.replace(/texture2D\s*\(/g,"texture("),o=o.replace(/textureCube\s*\(/g,"texture("),o=o.replace(/gl_FragDepthEXT/g,"gl_FragDepth"),o=o.replace(/gl_FragColor/g,"glFragColor"),o=o.replace(/gl_FragData/g,"glFragData"),o=o.replace(/void\s+?main\s*\(/g,(r?"":"out vec4 glFragColor;\n")+"void main(")),o},t.prototype._processIncludesAsync=function(i){var r=this;return new Promise(function(n,o){for(var s=/#include<(.+)>(\((.*)\))*(\[(.*)\])*/g,a=s.exec(i),l=i;null!=a;){var c=a[1];if(-1!==c.indexOf("__decl__")&&(c=c.replace(/__decl__/,""),r._engine.supportsUniformBuffers&&(c=c.replace(/Vertex/,"Ubo"),c=c.replace(/Fragment/,"Ubo")),c+="Declaration"),!t.IncludesShadersStore[c]){var h=e.Engine.ShadersRepository+"ShadersInclude/"+c+".fx";return void r._engine._loadFileAsync(h).then((function(e){return t.IncludesShadersStore[c]=e,r._processIncludesAsync(l)})).then((function(e){n(e)}))}var u=t.IncludesShadersStore[c];if(a[2])for(var f=a[3].split(","),d=0;dr.x?r.x:n,n=nr.y?r.y:o,o=oi.x?e.x:i.x,e.y>i.y?e.y:i.y)},t.Transform=function(e,i){var r=t.Zero();return t.TransformToRef(e,i,r),r},t.TransformToRef=function(e,t,i){var r=e.x*t.m[0]+e.y*t.m[4]+t.m[12],n=e.x*t.m[1]+e.y*t.m[5]+t.m[13];i.x=r,i.y=n},t.PointInTriangle=function(e,t,i,r){var n=.5*(-i.y*r.x+t.y*(-i.x+r.x)+t.x*(i.y-r.y)+i.x*r.y),o=n<0?-1:1,s=(t.y*r.x-t.x*r.y+(r.y-t.y)*e.x+(t.x-r.x)*e.y)*o,a=(t.x*i.y-t.y*i.x+(t.y-i.y)*e.x+(i.x-t.x)*e.y)*o;return s>0&&a>0&&s+a<2*n*o},t.Distance=function(e,i){return Math.sqrt(t.DistanceSquared(e,i))},t.DistanceSquared=function(e,t){var i=e.x-t.x,r=e.y-t.y;return i*i+r*r},t.Center=function(e,t){var i=e.add(t);return i.scaleInPlace(.5),i},t.DistanceOfPointFromSegment=function(e,i,r){var n=t.DistanceSquared(i,r);if(0===n)return t.Distance(e,i);var o=r.subtract(i),s=Math.max(0,Math.min(1,t.Dot(e.subtract(i),o)/n)),a=i.add(o.multiplyByFloats(s,s));return t.Distance(e,a)},t})();e.Vector2=r;var n=(function(){function t(e,t,i){this.x=e,this.y=t,this.z=i}return t.prototype.toString=function(){return"{X: "+this.x+" Y:"+this.y+" Z:"+this.z+"}"},t.prototype.getClassName=function(){return"Vector3"},t.prototype.getHashCode=function(){var e=this.x||0;return e=397*e^(this.y||0),e=397*e^(this.z||0)},t.prototype.asArray=function(){var e=[];return this.toArray(e,0),e},t.prototype.toArray=function(e,t){return void 0===t&&(t=0),e[t]=this.x,e[t+1]=this.y, e[t+2]=this.z,this},t.prototype.toQuaternion=function(){var e=new a(0,0,0,1),t=Math.cos(.5*(this.x+this.z)),i=Math.sin(.5*(this.x+this.z)),r=Math.cos(.5*(this.z-this.x)),n=Math.sin(.5*(this.z-this.x)),o=Math.cos(.5*this.y),s=Math.sin(.5*this.y);return e.x=r*s,e.y=-n*s,e.z=i*o,e.w=t*o,e},t.prototype.addInPlace=function(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this},t.prototype.add=function(e){return new t(this.x+e.x,this.y+e.y,this.z+e.z)},t.prototype.addToRef=function(e,t){return t.x=this.x+e.x,t.y=this.y+e.y,t.z=this.z+e.z,this},t.prototype.subtractInPlace=function(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this},t.prototype.subtract=function(e){return new t(this.x-e.x,this.y-e.y,this.z-e.z)},t.prototype.subtractToRef=function(e,t){return t.x=this.x-e.x,t.y=this.y-e.y,t.z=this.z-e.z,this},t.prototype.subtractFromFloats=function(e,i,r){return new t(this.x-e,this.y-i,this.z-r)},t.prototype.subtractFromFloatsToRef=function(e,t,i,r){return r.x=this.x-e,r.y=this.y-t,r.z=this.z-i,this},t.prototype.negate=function(){return new t(-this.x,-this.y,-this.z)},t.prototype.scaleInPlace=function(e){return this.x*=e,this.y*=e,this.z*=e,this},t.prototype.scale=function(e){return new t(this.x*e,this.y*e,this.z*e)},t.prototype.scaleToRef=function(e,t){return t.x=this.x*e,t.y=this.y*e,t.z=this.z*e,this},t.prototype.equals=function(e){return e&&this.x===e.x&&this.y===e.y&&this.z===e.z},t.prototype.equalsWithEpsilon=function(t,i){return void 0===i&&(i=e.Epsilon),t&&e.Scalar.WithinEpsilon(this.x,t.x,i)&&e.Scalar.WithinEpsilon(this.y,t.y,i)&&e.Scalar.WithinEpsilon(this.z,t.z,i)},t.prototype.equalsToFloats=function(e,t,i){return this.x===e&&this.y===t&&this.z===i},t.prototype.multiplyInPlace=function(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this},t.prototype.multiply=function(e){return new t(this.x*e.x,this.y*e.y,this.z*e.z)},t.prototype.multiplyToRef=function(e,t){return t.x=this.x*e.x,t.y=this.y*e.y,t.z=this.z*e.z,this},t.prototype.multiplyByFloats=function(e,i,r){return new t(this.x*e,this.y*i,this.z*r)},t.prototype.divide=function(e){return new t(this.x/e.x,this.y/e.y,this.z/e.z)},t.prototype.divideToRef=function(e,t){return t.x=this.x/e.x,t.y=this.y/e.y,t.z=this.z/e.z,this},t.prototype.divideInPlace=function(e){return this.divideToRef(e,this)},t.prototype.minimizeInPlace=function(e){return e.xthis.x&&(this.x=e.x),e.y>this.y&&(this.y=e.y),e.z>this.z&&(this.z=e.z),this},Object.defineProperty(t.prototype,"isNonUniform",{get:function(){var e=Math.abs(this.x),t=Math.abs(this.y);if(e!==t)return!0;var i=Math.abs(this.z);return e!==i||t!==i},enumerable:!0,configurable:!0}),t.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)},t.prototype.lengthSquared=function(){return this.x*this.x+this.y*this.y+this.z*this.z},t.prototype.normalize=function(){var e=this.length();if(0===e||1===e)return this;var t=1/e;return this.x*=t,this.y*=t,this.z*=t,this},t.prototype.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.GetAngleBetweenVectors=function(e,i,r){var n=e.clone().normalize(),o=i.clone().normalize(),s=t.Dot(n,o),a=t.Cross(n,o);return t.Dot(a,r)>0?Math.acos(s):-Math.acos(s)},t.FromArray=function(e,i){return i||(i=0),new t(e[i],e[i+1],e[i+2])},t.FromFloatArray=function(e,i){return t.FromArray(e,i)},t.FromArrayToRef=function(e,t,i){i.x=e[t],i.y=e[t+1],i.z=e[t+2]},t.FromFloatArrayToRef=function(e,i,r){return t.FromArrayToRef(e,i,r)},t.FromFloatsToRef=function(e,t,i,r){r.x=e,r.y=t,r.z=i},t.Zero=function(){return new t(0,0,0)},t.One=function(){return new t(1,1,1)},t.Up=function(){return new t(0,1,0)},t.Forward=function(){return new t(0,0,1)},t.Right=function(){return new t(1,0,0)},t.Left=function(){return new t(-1,0,0)},t.TransformCoordinates=function(e,i){var r=t.Zero();return t.TransformCoordinatesToRef(e,i,r),r},t.TransformCoordinatesToRef=function(e,t,i){var r=e.x*t.m[0]+e.y*t.m[4]+e.z*t.m[8]+t.m[12],n=e.x*t.m[1]+e.y*t.m[5]+e.z*t.m[9]+t.m[13],o=e.x*t.m[2]+e.y*t.m[6]+e.z*t.m[10]+t.m[14],s=e.x*t.m[3]+e.y*t.m[7]+e.z*t.m[11]+t.m[15];i.x=r/s,i.y=n/s,i.z=o/s},t.TransformCoordinatesFromFloatsToRef=function(e,t,i,r,n){var o=e*r.m[0]+t*r.m[4]+i*r.m[8]+r.m[12],s=e*r.m[1]+t*r.m[5]+i*r.m[9]+r.m[13],a=e*r.m[2]+t*r.m[6]+i*r.m[10]+r.m[14],l=e*r.m[3]+t*r.m[7]+i*r.m[11]+r.m[15];n.x=o/l,n.y=s/l,n.z=a/l},t.TransformNormal=function(e,i){var r=t.Zero();return t.TransformNormalToRef(e,i,r),r},t.TransformNormalToRef=function(e,t,i){var r=e.x*t.m[0]+e.y*t.m[4]+e.z*t.m[8],n=e.x*t.m[1]+e.y*t.m[5]+e.z*t.m[9],o=e.x*t.m[2]+e.y*t.m[6]+e.z*t.m[10];i.x=r,i.y=n,i.z=o},t.TransformNormalFromFloatsToRef=function(e,t,i,r,n){n.x=e*r.m[0]+t*r.m[4]+i*r.m[8],n.y=e*r.m[1]+t*r.m[5]+i*r.m[9],n.z=e*r.m[2]+t*r.m[6]+i*r.m[10]},t.CatmullRom=function(e,i,r,n,o){var s=o*o,a=o*s;return new t(.5*(2*i.x+(-e.x+r.x)*o+(2*e.x-5*i.x+4*r.x-n.x)*s+(-e.x+3*i.x-3*r.x+n.x)*a),.5*(2*i.y+(-e.y+r.y)*o+(2*e.y-5*i.y+4*r.y-n.y)*s+(-e.y+3*i.y-3*r.y+n.y)*a),.5*(2*i.z+(-e.z+r.z)*o+(2*e.z-5*i.z+4*r.z-n.z)*s+(-e.z+3*i.z-3*r.z+n.z)*a))},t.Clamp=function(e,i,r){var n=e.x;n=n>r.x?r.x:n,n=nr.y?r.y:o,o=or.z?r.z:s,s=sthis.x&&(this.x=e.x),e.y>this.y&&(this.y=e.y),e.z>this.z&&(this.z=e.z),e.w>this.w&&(this.w=e.w),this},t.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},t.prototype.lengthSquared=function(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w},t.prototype.normalize=function(){var e=this.length();if(0===e)return this;var t=1/e;return this.x*=t,this.y*=t,this.z*=t,this.w*=t,this},t.prototype.toVector3=function(){return new n(this.x,this.y,this.z)},t.prototype.clone=function(){return new t(this.x,this.y,this.z,this.w)},t.prototype.copyFrom=function(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w,this},t.prototype.copyFromFloats=function(e,t,i,r){return this.x=e,this.y=t,this.z=i,this.w=r,this},t.prototype.set=function(e,t,i,r){return this.copyFromFloats(e,t,i,r)},t.FromArray=function(e,i){return i||(i=0),new t(e[i],e[i+1],e[i+2],e[i+3])},t.FromArrayToRef=function(e,t,i){i.x=e[t],i.y=e[t+1],i.z=e[t+2],i.w=e[t+3]},t.FromFloatArrayToRef=function(e,i,r){t.FromArrayToRef(e,i,r)},t.FromFloatsToRef=function(e,t,i,r,n){n.x=e,n.y=t,n.z=i,n.w=r},t.Zero=function(){return new t(0,0,0,0)},t.One=function(){return new t(1,1,1,1)},t.Normalize=function(e){var i=t.Zero();return t.NormalizeToRef(e,i),i},t.NormalizeToRef=function(e,t){t.copyFrom(e),t.normalize()},t.Minimize=function(e,t){var i=e.clone();return i.minimizeInPlace(t),i},t.Maximize=function(e,t){var i=e.clone();return i.maximizeInPlace(t),i},t.Distance=function(e,i){return Math.sqrt(t.DistanceSquared(e,i))},t.DistanceSquared=function(e,t){var i=e.x-t.x,r=e.y-t.y,n=e.z-t.z,o=e.w-t.w;return i*i+r*r+n*n+o*o},t.Center=function(e,t){var i=e.add(t);return i.scaleInPlace(.5),i},t.TransformNormal=function(e,i){var r=t.Zero();return t.TransformNormalToRef(e,i,r),r},t.TransformNormalToRef=function(e,t,i){var r=e.x*t.m[0]+e.y*t.m[4]+e.z*t.m[8],n=e.x*t.m[1]+e.y*t.m[5]+e.z*t.m[9],o=e.x*t.m[2]+e.y*t.m[6]+e.z*t.m[10];i.x=r,i.y=n,i.z=o,i.w=e.w},t.TransformNormalFromFloatsToRef=function(e,t,i,r,n,o){o.x=e*n.m[0]+t*n.m[4]+i*n.m[8],o.y=e*n.m[1]+t*n.m[5]+i*n.m[9],o.z=e*n.m[2]+t*n.m[6]+i*n.m[10],o.w=r},t})();e.Vector4=o;var s=(function(){function e(e,t){this.width=e,this.height=t}return e.prototype.toString=function(){return"{W: "+this.width+", H: "+this.height+"}"},e.prototype.getClassName=function(){return"Size"},e.prototype.getHashCode=function(){var e=this.width||0;return e=397*e^(this.height||0)},e.prototype.copyFrom=function(e){this.width=e.width,this.height=e.height},e.prototype.copyFromFloats=function(e,t){return this.width=e,this.height=t,this},e.prototype.set=function(e,t){return this.copyFromFloats(e,t)},e.prototype.multiplyByFloats=function(t,i){return new e(this.width*t,this.height*i)},e.prototype.clone=function(){return new e(this.width,this.height)},e.prototype.equals=function(e){return!!e&&(this.width===e.width&&this.height===e.height)},Object.defineProperty(e.prototype,"surface",{get:function(){return this.width*this.height},enumerable:!0,configurable:!0}),e.Zero=function(){return new e(0,0)},e.prototype.add=function(t){return new e(this.width+t.width,this.height+t.height)},e.prototype.subtract=function(t){return new e(this.width-t.width,this.height-t.height)},e.Lerp=function(t,i,r){return new e(t.width+(i.width-t.width)*r,t.height+(i.height-t.height)*r)},e})();e.Size=s;var a=(function(){function 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^(this.y||0),e=397*e^(this.z||0),e=397*e^(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,l=r*r,c=n*n,h=n*i-r*o;return h<-.4999999?(e.y=2*Math.atan2(n,o),e.x=Math.PI/2,e.z=0):h>.4999999?(e.y=2*Math.atan2(n,o),e.x=-Math.PI/2,e.z=0):(e.z=Math.atan2(2*(r*n+i*o),-a-l+c+s),e.x=Math.asin(-2*(i*n-r*o)),e.y=Math.atan2(2*(i*r+n*o),a-l-c+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,l=this.y*this.z,c=this.x*this.w;return e.m[0]=1-2*(i+r),e.m[1]=2*(n+o),e.m[2]=2*(s-a),e.m[3]=0,e.m[4]=2*(n-o),e.m[5]=1-2*(r+t),e.m[6]=2*(l+c),e.m[7]=0,e.m[8]=2*(s+a),e.m[9]=2*(l-c),e.m[10]=1-2*(i+t),e.m[11]=0,e.m[12]=0,e.m[13]=0,e.m[14]=0,e.m[15]=1,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],l=r[5],c=r[9],h=r[2],u=r[6],f=r[10],d=n+l+f;d>0?(i=.5/Math.sqrt(d+1),t.w=.25/i,t.x=(u-c)*i,t.y=(s-h)*i,t.z=(a-o)*i):n>l&&n>f?(i=2*Math.sqrt(1+n-l-f),t.w=(u-c)/i,t.x=.25*i,t.y=(o+a)/i,t.z=(s+h)/i):l>f?(i=2*Math.sqrt(1+l-n-f),t.w=(s-h)/i,t.x=(o+a)/i,t.y=.25*i,t.z=(c+u)/i):(i=2*Math.sqrt(1+f-n-l),t.w=(a-o)/i,t.x=(s+h)/i,t.y=(c+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),l=Math.cos(n),c=Math.sin(o),h=Math.cos(o),u=Math.sin(s),f=Math.cos(s);r.x=f*c*l+u*h*a,r.y=u*h*l-f*c*a,r.z=f*h*a-u*c*l,r.w=f*h*l+u*c*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=E.Matrix[0];l.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,l=!1;if(a<0&&(l=!0,a=-a),a>.999999)o=1-s,n=l?-s:s;else{var c=Math.acos(a),h=1/Math.sin(c);o=Math.sin((1-s)*c)*h,n=l?-Math.sin(s*c)*h:Math.sin(s*c)*h}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,l=2*a-3*s+1,c=-2*a+3*s,h=a-2*s+o,u=a-s;return new e(t.x*l+r.x*c+i.x*h+n.x*u,t.y*l+r.y*c+i.y*h+n.y*u,t.z*l+r.z*c+i.z*h+n.z*u,t.w*l+r.w*c+i.w*h+n.w*u)},e})();e.Quaternion=a;var l=(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],l=this.m[7],c=this.m[8],h=this.m[9],u=this.m[10],f=this.m[11],d=this.m[12],p=this.m[13],_=this.m[14],m=this.m[15],g=u*m-f*_,v=h*m-f*p,y=h*_-u*p,b=c*m-f*d,x=c*_-u*d,T=c*p-h*d,E=s*g-a*v+l*y,A=-(o*g-a*b+l*x),P=o*v-s*b+l*T,M=-(o*y-s*x+a*T),S=1/(t*E+i*A+r*P+n*M),C=a*m-l*_,R=s*m-l*p,O=s*_-a*p,I=o*m-l*d,D=o*_-a*d,L=o*p-s*d,w=a*f-l*u,F=s*f-l*h,B=s*u-a*h,N=o*f-l*c,V=o*u-a*c,U=o*h-s*c;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*g-r*v+n*y)*S,e.m[5]=(t*g-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*D)*S,e.m[10]=(t*R-i*I+n*L)*S,e.m[14]=-(t*O-i*D+r*L)*S,e.m[3]=-(i*w-r*F+n*B)*S,e.m[7]=(t*w-r*N+n*V)*S,e.m[11]=-(t*F-i*N+n*U)*S,e.m[15]=(t*B-i*V+r*U)*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],l=this.m[5],c=this.m[6],h=this.m[7],u=this.m[8],f=this.m[9],d=this.m[10],p=this.m[11],_=this.m[12],m=this.m[13],g=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],D=e.m[13],L=e.m[14],w=e.m[15];return t[i]=r*y+n*E+o*S+s*I,t[i+1]=r*b+n*A+o*C+s*D,t[i+2]=r*x+n*P+o*R+s*L,t[i+3]=r*T+n*M+o*O+s*w,t[i+4]=a*y+l*E+c*S+h*I,t[i+5]=a*b+l*A+c*C+h*D,t[i+6]=a*x+l*P+c*R+h*L,t[i+7]=a*T+l*M+c*O+h*w,t[i+8]=u*y+f*E+d*S+p*I,t[i+9]=u*b+f*A+d*C+p*D,t[i+10]=u*x+f*P+d*R+p*L,t[i+11]=u*T+f*M+d*O+p*w,t[i+12]=_*y+m*E+g*S+v*I,t[i+13]=_*b+m*A+g*C+v*D,t[i+14]=_*x+m*P+g*R+v*L,t[i+15]=_*T+m*M+g*O+v*w,this},e.prototype.equals=function(e){return e&&this.m[0]===e.m[0]&&this.m[1]===e.m[1]&&this.m[2]===e.m[2]&&this.m[3]===e.m[3]&&this.m[4]===e.m[4]&&this.m[5]===e.m[5]&&this.m[6]===e.m[6]&&this.m[7]===e.m[7]&&this.m[8]===e.m[8]&&this.m[9]===e.m[9]&&this.m[10]===e.m[10]&&this.m[11]===e.m[11]&&this.m[12]===e.m[12]&&this.m[13]===e.m[13]&&this.m[14]===e.m[14]&&this.m[15]===e.m[15]},e.prototype.clone=function(){return e.FromValues(this.m[0],this.m[1],this.m[2],this.m[3],this.m[4],this.m[5],this.m[6],this.m[7],this.m[8],this.m[9],this.m[10],this.m[11],this.m[12],this.m[13],this.m[14],this.m[15])},e.prototype.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,E.Matrix[0]),a.FromRotationMatrixToRef(E.Matrix[0],i),!0)},e.prototype.toNormalMatrix=function(t){this.invertToRef(t),t.transpose();var i=t.m;e.FromValuesToRef(i[0],i[1],i[2],0,i[4],i[5],i[6],0,i[8],i[9],i[10],0,0,0,0,1,t)},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]),l=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]/l,i[9]/l,i[10]/l,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,l,c,h,u,f,d,p,_,m){m.m[0]=e,m.m[1]=t,m.m[2]=i,m.m[3]=r,m.m[4]=n,m.m[5]=o,m.m[6]=s,m.m[7]=a,m.m[8]=l,m.m[9]=c,m.m[10]=h,m.m[11]=u,m.m[12]=f,m.m[13]=d,m.m[14]=p,m.m[15]=_,m._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,l,c,h,u,f,d,p,_,m){var g=new e;return g.m[0]=t,g.m[1]=i,g.m[2]=r,g.m[3]=n,g.m[4]=o,g.m[5]=s,g.m[6]=a,g.m[7]=l,g.m[8]=c,g.m[9]=h,g.m[10]=u,g.m[11]=f,g.m[12]=d,g.m[13]=p,g.m[14]=_,g.m[15]=m,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,E.Matrix[1]),i.toRotationMatrix(E.Matrix[0]),E.Matrix[1].multiplyToRef(E.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){var n=e.Zero();return e.LerpToRef(t,i,r,n),n},e.LerpToRef=function(e,t,i,r){for(var n=0;n<16;n++)r.m[n]=e.m[n]*(1-i)+t.m[n]*i;r._markAsUpdated()},e.DecomposeLerp=function(t,i,r){var o=new n(0,0,0),s=new a,l=new n(0,0,0);t.decompose(o,s,l);var c=new n(0,0,0),h=new a,u=new n(0,0,0);i.decompose(c,h,u);var f=n.Lerp(o,c,r),d=a.Slerp(s,h,r),p=n.Lerp(l,u,r);return e.Compose(f,d,p)},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),l=-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,l,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),l=-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,l,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=r,a=n,l=2/t,c=2/i,h=2/(a-s),u=-(a+s)/(a-s);e.FromValuesToRef(l,0,0,0,0,c,0,0,0,0,h,0,0,0,u,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 l=o,c=s,h=2/(i-t),u=2/(n-r),f=2/(c-l),d=-(c+l)/(c-l),p=(t+i)/(t-i),_=(n+r)/(r-n);e.FromValuesToRef(h,0,0,0,0,u,0,0,0,0,f,0,p,_,d,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=r,a=n,l=2*s/t,c=2*s/i,h=(a+s)/(a-s),u=-2*a*s/(a-s);return e.FromValuesToRef(l,0,0,0,0,c,0,0,0,0,h,1,0,0,u,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,l=n,c=1/Math.tan(.5*t),h=s?c/i:c,u=s?c:c*i,f=(l+a)/(l-a),d=-2*l*a/(l-a);e.FromValuesToRef(h,0,0,0,0,u,0,0,0,0,f,1,0,0,d,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,l=n,c=1/Math.tan(.5*t),h=s?c/i:c,u=s?c:c*i,f=-(l+a)/(l-a),d=-2*l*a/(l-a);e.FromValuesToRef(h,0,0,0,0,u,0,0,0,0,f,-1,0,0,d,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),l=Math.tan(e.leftDegrees*Math.PI/180),c=Math.tan(e.rightDegrees*Math.PI/180),h=2/(l+c),u=2/(s+a);r.m[0]=h,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]=(l-c)*h*.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,l=t.height,c=t.x,h=t.y,u=e.FromValues(a/2,0,0,0,0,-l/2,0,0,0,0,s-o,0,c+a/2,l/2+h,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,l=e.y*e.w,c=e.y*e.z,h=e.x*e.w;t.m[0]=1-2*(r+n),t.m[1]=2*(o+s),t.m[2]=2*(a-l),t.m[3]=0,t.m[4]=2*(o-s),t.m[5]=1-2*(n+i),t.m[6]=2*(c+h),t.m[7]=0,t.m[8]=2*(a+l),t.m[9]=2*(c-h),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=l;var c=(function(){function e(e,t,i,r){this.normal=new n(e,t,i),this.d=r}return e.prototype.asArray=function(){return[this.normal.x,this.normal.y,this.normal.z,this.d]},e.prototype.clone=function(){return new e(this.normal.x,this.normal.y,this.normal.z,this.d)},e.prototype.getClassName=function(){return"Plane"},e.prototype.getHashCode=function(){var e=this.normal.getHashCode();return e=397*e^(this.d||0)},e.prototype.normalize=function(){var e=Math.sqrt(this.normal.x*this.normal.x+this.normal.y*this.normal.y+this.normal.z*this.normal.z),t=0;return 0!==e&&(t=1/e),this.normal.x*=t,this.normal.y*=t,this.normal.z*=t,this.d*=t,this},e.prototype.transform=function(t){var i=l.Transpose(t),r=this.normal.x,n=this.normal.y,o=this.normal.z,s=this.d;return new e(r*i.m[0]+n*i.m[1]+o*i.m[2]+s*i.m[3],r*i.m[4]+n*i.m[5]+o*i.m[6]+s*i.m[7],r*i.m[8]+n*i.m[9]+o*i.m[10]+s*i.m[11],r*i.m[12]+n*i.m[13]+o*i.m[14]+s*i.m[15])},e.prototype.dotCoordinate=function(e){return this.normal.x*e.x+this.normal.y*e.y+this.normal.z*e.z+this.d},e.prototype.copyFromPoints=function(e,t,i){var r,n=t.x-e.x,o=t.y-e.y,s=t.z-e.z,a=i.x-e.x,l=i.y-e.y,c=i.z-e.z,h=o*c-s*l,u=s*a-n*c,f=n*l-o*a,d=Math.sqrt(h*h+u*u+f*f);return r=0!==d?1/d:0,this.normal.x=h*r,this.normal.y=u*r,this.normal.z=f*r,this.d=-(this.normal.x*e.x+this.normal.y*e.y+this.normal.z*e.z),this},e.prototype.isFrontFacingTo=function(e,t){return n.Dot(this.normal,e)<=t},e.prototype.signedDistanceTo=function(e){return n.Dot(e,this.normal)+this.d},e.FromArray=function(t){return new e(t[0],t[1],t[2],t[3])},e.FromPoints=function(t,i,r){var n=new e(0,0,0,0);return n.copyFromPoints(t,i,r),n},e.FromPositionAndNormal=function(t,i){var r=new e(0,0,0,0);return i.normalize(),r.normal=i,r.d=-(i.x*t.x+i.y*t.y+i.z*t.z),r},e.SignedDistanceToPlaneFromPositionAndNormal=function(e,t,i){var r=-(t.x*e.x+t.y*e.y+t.z*e.z);return n.Dot(i,t)+r},e})();e.Plane=c;var h=(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=h;var u=(function(){function e(){}return e.GetPlanes=function(t){for(var i=[],r=0;r<6;r++)i.push(new c(0,0,0,0));return e.GetPlanesToRef(t,i),i},e.GetNearPlaneToRef=function(e,t){t.normal.x=e.m[3]+e.m[2],t.normal.y=e.m[7]+e.m[6],t.normal.z=e.m[11]+e.m[10],t.d=e.m[15]+e.m[14],t.normalize()},e.GetFarPlaneToRef=function(e,t){t.normal.x=e.m[3]-e.m[2],t.normal.y=e.m[7]-e.m[6],t.normal.z=e.m[11]-e.m[10],t.d=e.m[15]-e.m[14],t.normalize()},e.GetLeftPlaneToRef=function(e,t){t.normal.x=e.m[3]+e.m[0],t.normal.y=e.m[7]+e.m[4],t.normal.z=e.m[11]+e.m[8],t.d=e.m[15]+e.m[12],t.normalize()},e.GetRightPlaneToRef=function(e,t){t.normal.x=e.m[3]-e.m[0],t.normal.y=e.m[7]-e.m[4],t.normal.z=e.m[11]-e.m[8],t.d=e.m[15]-e.m[12],t.normalize()},e.GetTopPlaneToRef=function(e,t){t.normal.x=e.m[3]-e.m[1],t.normal.y=e.m[7]-e.m[5],t.normal.z=e.m[11]-e.m[9],t.d=e.m[15]-e.m[13],t.normalize()},e.GetBottomPlaneToRef=function(e,t){t.normal.x=e.m[3]+e.m[1],t.normal.y=e.m[7]+e.m[5],t.normal.z=e.m[11]+e.m[9],t.d=e.m[15]+e.m[13],t.normalize()},e.GetPlanesToRef=function(t,i){e.GetNearPlaneToRef(t,i[0]),e.GetFarPlaneToRef(t,i[1]),e.GetLeftPlaneToRef(t,i[2]),e.GetRightPlaneToRef(t,i[3]),e.GetTopPlaneToRef(t,i[4]),e.GetBottomPlaneToRef(t,i[5])},e})();e.Frustum=u;!(function(e){e[e.LOCAL=0]="LOCAL",e[e.WORLD=1]="WORLD",e[e.BONE=2]="BONE"})(e.Space||(e.Space={}));var 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=(function(){function e(){}return e.interpolate=function(e,t,i,r,n){for(var o=1-3*r+3*t,s=3*r-6*t,a=3*t,l=e,c=0;c<5;c++){var h=l*l;l-=(o*(h*l)+s*h+a*l-e)*(1/(3*o*h+2*s*l+a)),l=Math.min(1,Math.max(0,l))}return 3*Math.pow(1-l,2)*l*i+3*(1-l)*Math.pow(l,2)*n+Math.pow(l,3)},e})();e.BezierCurve=d;var p;!(function(e){e[e.CW=0]="CW",e[e.CCW=1]="CCW"})(p=e.Orientation||(e.Orientation={}));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 m=(function(){function e(e,t,i){this.startPoint=e,this.midPoint=t,this.endPoint=i;var n=Math.pow(t.x,2)+Math.pow(t.y,2),o=(Math.pow(e.x,2)+Math.pow(e.y,2)-n)/2,s=(n-Math.pow(i.x,2)-Math.pow(i.y,2))/2,a=(e.x-t.x)*(t.y-i.y)-(t.x-i.x)*(e.y-t.y);this.centerPoint=new r((o*(t.y-i.y)-s*(e.y-t.y))/a,((e.x-t.x)*s-(t.x-i.x)*o)/a),this.radius=this.centerPoint.subtract(this.startPoint).length(),this.startAngle=_.BetweenTwoPoints(this.centerPoint,this.startPoint);var l=this.startAngle.degrees(),c=_.BetweenTwoPoints(this.centerPoint,this.midPoint).degrees(),h=_.BetweenTwoPoints(this.centerPoint,this.endPoint).degrees();c-l>180&&(c-=360),c-l<-180&&(c+=360),h-c>180&&(h-=360),h-c<-180&&(h+=360),this.orientation=c-l<0?p.CW:p.CCW,this.angle=_.FromDegrees(this.orientation===p.CW?l-h:h-l)}return e})();e.Arc2=m;var g=(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),l=new r(i,n),c=new m(s,a,l),h=c.angle.radians()/o;c.orientation===p.CW&&(h*=-1);for(var u=c.startAngle.radians()+h,f=0;f1)return r.Zero();for(var t=e*this.length(),i=0,n=0;n=i&&t<=c){var h=l.normalize(),u=t-i;return new r(s.x+h.x*u,s.y+h.y*u)}i=c}return r.Zero()},e.StartingAt=function(t,i){return new e(t,i)},e})();e.Path2=g;var v=(function(){function t(e,t,i){void 0===t&&(t=null),this.path=e,this._curve=new Array,this._distances=new Array,this._tangents=new Array,this._normals=new Array,this._binormals=new Array;for(var r=0;rt+1;)t++,i=this._curve[e].subtract(this._curve[e-t]);return i},t.prototype._normalVector=function(t,i,r){var o,s=i.length();if(0===s&&(s=1),void 0===r||null===r){var a;a=e.Scalar.WithinEpsilon(Math.abs(i.y)/s,1,e.Epsilon)?e.Scalar.WithinEpsilon(Math.abs(i.x)/s,1,e.Epsilon)?e.Scalar.WithinEpsilon(Math.abs(i.z)/s,1,e.Epsilon)?n.Zero():new n(0,0,1):new n(1,0,0):new n(0,-1,0),o=n.Cross(i,a)}else o=n.Cross(i,r),n.CrossToRef(o,i,o);return o.normalize(),o},t})();e.Path3D=v;var y=(function(){function e(e){this._length=0,this._points=e,this._length=this._computeLength(e)}return e.CreateQuadraticBezier=function(t,i,r,o){o=o>2?o:3;for(var s=new Array,a=function(e,t,i,r){return(1-e)*(1-e)*t+2*e*(1-e)*i+e*e*r},l=0;l<=o;l++)s.push(new n(a(l/o,t.x,i.x,r.x),a(l/o,t.y,i.y,r.y),a(l/o,t.z,i.z,r.z)));return new e(s)},e.CreateCubicBezier=function(t,i,r,o,s){s=s>3?s:4;for(var a=new Array,l=function(e,t,i,r,n){return(1-e)*(1-e)*(1-e)*t+3*e*(1-e)*(1-e)*i+3*e*e*(1-e)*r+e*e*e*n},c=0;c<=s;c++)a.push(new n(l(c/s,t.x,i.x,r.x,o.x),l(c/s,t.y,i.y,r.y,o.y),l(c/s,t.z,i.z,r.z,o.z)));return new e(a)},e.CreateHermiteSpline=function(t,i,r,o,s){for(var a=new Array,l=1/s,c=0;c<=s;c++)a.push(n.Hermite(t,i,r,o,c*l));return new e(a)},e.CreateCatmullRomSpline=function(t,i){var r=new Array;r.push(t[0].clone()),Array.prototype.push.apply(r,t),r.push(t[t.length-1].clone());for(var o=new Array,s=1/i,a=0,l=0;l0?1:-1},e.Clamp=function(e,t,i){return void 0===t&&(t=0),void 0===i&&(i=1),Math.min(i,Math.max(t,e))},e.Log2=function(e){return Math.log(e)*Math.LOG2E},e.Repeat=function(e,t){return e-Math.floor(e/t)*t},e.Normalize=function(e,t,i){return(e-t)/(i-t)},e.Denormalize=function(e,t,i){return e*(i-t)+t},e.DeltaAngle=function(t,i){var r=e.Repeat(i-t,360);return r>180&&(r-=360),r},e.PingPong=function(t,i){var r=e.Repeat(t,2*i);return i-Math.abs(r-i)},e.SmoothStep=function(t,i,r){var n=e.Clamp(r);return n=-2*n*n*n+3*n*n,i*n+t*(1-n)},e.MoveTowards=function(t,i,r){return Math.abs(i-t)<=r?i:t+e.Sign(i-t)*r},e.MoveTowardsAngle=function(t,i,r){var n=e.DeltaAngle(t,i),o=0;return-r180&&(n-=360),t+n*e.Clamp(r)},e.InverseLerp=function(t,i,r){return t!=i?e.Clamp((r-t)/(i-t)):0},e.Hermite=function(e,t,i,r,n){var o=n*n,s=n*o;return e*(2*s-3*o+1)+i*(-2*s+3*o)+t*(s-2*o+n)+r*(s-o)},e.RandomRange=function(e,t){return e===t?e:Math.random()*(t-e)+e},e.RangeToPercent=function(e,t,i){return(e-t)/(i-t)},e.PercentToRange=function(e,t,i){return(i-t)*e+t},e.NormalizeRadians=function(t){return t-=e.TwoPi*Math.floor((t+Math.PI)/e.TwoPi)},e.TwoPi=2*Math.PI,e})();e.Scalar=t})(e||(e={}));var e;!(function(e){function t(e){var t=e.getClassName();return g[t]||(g[t]={}),g[t]}function i(e){var t=e.getClassName();if(v[t])return v[t];v[t]={};for(var i=v[t],r=e,n=t;n;){var o=g[n];for(var s in o)i[s]=o[s];var a=void 0,l=!1;do{if(a=Object.getPrototypeOf(r),!a.getClassName){l=!0;break}if(a.getClassName()!==n)break;r=a}while(a);if(l)break;n=a.getClassName(),r=a}return i}function r(e,i){return function(r,n){var o=t(r);o[n]||(o[n]={type:e,sourceName:i})}}function n(e,t){return void 0===t&&(t=null),function(i,r){var n=t||"_"+r;Object.defineProperty(i,r,{get:function(){return this[n]},set:function(t){this[n]!==t&&(this[n]=t,i[e].apply(this))},enumerable:!0,configurable:!0})}}function o(e,t){return void 0===t&&(t=null),n(e,t)}function s(e){return r(0,e)}function a(e){return r(1,e)}function l(e){return r(2,e)}function c(e){return r(3,e)}function h(e){return r(4,e)}function u(e){return r(5,e)}function f(e){return r(6,e)}function d(e){return r(7,e)}function p(e){return r(8,e)}function _(e){return r(9,e)}function m(e){return r(10,e)}var g={},v={},y=function(t,r,n){var o=t();e.Tags&&e.Tags.AddTagsTo(o,r.tags);var s=i(o);for(var a in s){var l=s[a],c=r[a],h=l.type;if(void 0!==c&&null!==c)switch(h){case 0:case 6:o[a]=c;break;case 1:o[a]=n||c.isRenderTarget?c:c.clone();break;case 2:case 3:case 4:case 5:case 7:case 10:o[a]=n?c:c.clone()}}return o};e.expandToProperty=o,e.serialize=s,e.serializeAsTexture=a,e.serializeAsColor3=l,e.serializeAsFresnelParameters=c,e.serializeAsVector2=h,e.serializeAsVector3=u,e.serializeAsMeshReference=f,e.serializeAsColorCurves=d,e.serializeAsColor4=p,e.serializeAsImageProcessingConfiguration=_,e.serializeAsQuaternion=m;var b=(function(){function t(){}return t.Serialize=function(t,r){r||(r={}),e.Tags&&(r.tags=e.Tags.GetTags(t));var n=i(t);for(var o in n){var s=n[o],a=s.sourceName||o,l=s.type,c=t[o];if(void 0!==c&&null!==c)switch(l){case 0:r[a]=c;break;case 1:r[a]=c.serialize();break;case 2:r[a]=c.asArray();break;case 3:r[a]=c.serialize();break;case 4:case 5:r[a]=c.asArray();break;case 6:r[a]=c.id;break;case 7:r[a]=c.serialize();break;case 8:r[a]=c.asArray();break;case 9:r[a]=c.serialize()}}return r},t.Parse=function(t,r,n,o){void 0===o&&(o=null);var s=t();o||(o=""),e.Tags&&e.Tags.AddTagsTo(s,r.tags);var a=i(s);for(var l in a){var c=a[l],h=r[c.sourceName||l],u=c.type;if(void 0!==h&&null!==h){var f=s;switch(u){case 0:f[l]=h;break;case 1:n&&(f[l]=e.Texture.Parse(h,n,o));break;case 2:f[l]=e.Color3.FromArray(h);break;case 3:f[l]=e.FresnelParameters.Parse(h);break;case 4:f[l]=e.Vector2.FromArray(h);break;case 5:f[l]=e.Vector3.FromArray(h);break;case 6:n&&(f[l]=n.getLastMeshByID(h));break;case 7:f[l]=e.ColorCurves.Parse(h);break;case 8:f[l]=e.Color4.FromArray(h);break;case 9:f[l]=e.ImageProcessingConfiguration.Parse(h)}}}return s},t.Clone=function(e,t){return y(e,t,!1)},t.Instanciate=function(e,t){return y(e,t,!0)},t})();e.SerializationHelper=b})(e||(e={}));var e;!(function(e){var t=(function(){function e(){var e=this;this.promise=new Promise(function(t,i){e._resolve=t,e._reject=i})}return Object.defineProperty(e.prototype,"resolve",{get:function(){return this._resolve},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"reject",{get:function(){return this._reject},enumerable:!0,configurable:!0}),e})();e.Deferred=t})(e||(e={}));var e;!(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(){function e(e,t,i){void 0===i&&(i=null),this.callback=e,this.mask=t,this.scope=i,this._willBeUnregistered=!1,this.unregisterOnNextCall=!1}return e})();e.Observer=i;var r=(function(){function e(){}return e.prototype.dispose=function(){if(this._observers&&this._observables)for(var e=0;e0},r.prototype.clear=function(){this._observers=new Array,this._onObserverAdded=null},r.prototype.clone=function(){var e=new r;return e._observers=this._observers.slice(0),e},r.prototype.hasSpecificMask=function(e){void 0===e&&(e=-1);for(var t=0,i=this._observers;tthis.data.length&&(this.data.length*=2)},e.prototype.forEach=function(e){for(var t=0;tthis.data.length&&(this.data.length=2*(this.length+e.length));for(var t=0;t=this.length?-1:t},e.prototype.contains=function(e){return-1!==this.data.indexOf(e)},e._GlobalId=0,e})();e.SmartArray=t;var i=(function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t._duplicateId=0,t}return __extends(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||-1!==i.indexOf("file:")?-1:Math.pow(2,n)*t}},e})();e.RetryStrategy=r;var n,o=function(t,i){return t?t instanceof e.Mesh?null:t instanceof e.SubMesh?t.clone(i):t.clone?t.clone():null:null},s=(function(){function t(){}return t.Mix=function(e,t,i){return e*(1-i)+t*i},t.Instantiate=function(e){if(t.RegisteredExternalClasses&&t.RegisteredExternalClasses[e])return t.RegisteredExternalClasses[e];for(var i=e.split("."),r=window||this,n=0,o=i.length;n>1,e|=e>>2,e|=e>>4,e|=e>>8,e|=e>>16,++e},t.FloorPOT=function(e){return e|=e>>1,e|=e>>2,e|=e>>4,e|=e>>8,(e|=e>>16)-(e>>1)},t.NearestPOT=function(e){var i=t.CeilingPOT(e),r=t.FloorPOT(e);return i-e>e-r?r:i},t.GetExponentOfTwo=function(i,r,n){void 0===n&&(n=e.Engine.SCALEMODE_NEAREST);var o;switch(n){case e.Engine.SCALEMODE_FLOOR:o=t.FloorPOT(i);break;case e.Engine.SCALEMODE_NEAREST:o=t.NearestPOT(i);break;case e.Engine.SCALEMODE_CEILING:default:o=t.CeilingPOT(i)}return Math.min(o,r)},t.GetFilename=function(e){var t=e.lastIndexOf("/");return t<0?e:e.substring(t+1)},t.GetFolderPath=function(e,t){void 0===t&&(t=!1);var i=e.lastIndexOf("/");return i<0?t?e:"":e.substring(0,i+1)},t.GetDOMTextContent=function(e){for(var t="",i=e.firstChild;i;)3===i.nodeType&&(t+=i.textContent),i=i.nextSibling;return t},t.ToDegrees=function(e){return 180*e/Math.PI},t.ToRadians=function(e){return e*Math.PI/180},t.EncodeArrayBufferTobase64=function(e){for(var t,i,r,n,o,s,a,l="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",c="",h=0,u=new Uint8Array(e);h>2,o=(3&t)<<4|i>>4,s=(15&i)<<2|r>>6,a=63&r,isNaN(i)?s=a=64:isNaN(r)&&(a=64),c+=l.charAt(n)+l.charAt(o)+l.charAt(s)+l.charAt(a);return"data:image/png;base64,"+c},t.ExtractMinAndMaxIndexed=function(t,i,r,n,o){void 0===o&&(o=null);for(var s=new e.Vector3(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),a=new e.Vector3(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE),l=r;l=(r?t.length/2:t.length))return null;if(r){var n=t;return new e.Vector2(n[2*i+0],n[2*i+1])}return t[i]}},t.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}},t.MakeArray=function(e,t){return!0===t||void 0!==e&&null!=e?Array.isArray(e)?e:[e]:null},t.GetPointerPrefix=function(){var e="pointer";return!t.IsWindowObjectExist()||window.PointerEvent||navigator.pointerEnabled||(e="mouse"),e},t.QueueNewFrame=function(e,i){return t.IsWindowObjectExist()?(i||(i=window),i.requestAnimationFrame?i.requestAnimationFrame(e):i.msRequestAnimationFrame?i.msRequestAnimationFrame(e):i.webkitRequestAnimationFrame?i.webkitRequestAnimationFrame(e):i.mozRequestAnimationFrame?i.mozRequestAnimationFrame(e):i.oRequestAnimationFrame?i.oRequestAnimationFrame(e):window.setTimeout(e,16)):setTimeout(e,16)},t.RequestFullscreen=function(e){var t=e.requestFullscreen||e.msRequestFullscreen||e.webkitRequestFullscreen||e.mozRequestFullScreen;t&&t.call(e)},t.ExitFullscreen=function(){document.exitFullscreen?document.exitFullscreen():document.mozCancelFullScreen?document.mozCancelFullScreen():document.webkitCancelFullScreen?document.webkitCancelFullScreen():document.msCancelFullScreen&&document.msCancelFullScreen()},t.SetCorsBehavior=function(e,i){if((!e||0!==e.indexOf("data:"))&&t.CorsBehavior)if("string"==typeof t.CorsBehavior||t.CorsBehavior instanceof String)i.crossOrigin=t.CorsBehavior;else{var r=t.CorsBehavior(e);r&&(i.crossOrigin=r)}},t.CleanUrl=function(e){return e=e.replace(/#/gm,"%23")},t.LoadImage=function(i,r,n,o){i instanceof ArrayBuffer&&(i=t.EncodeArrayBufferTobase64(i)),i=t.CleanUrl(i),i=t.PreprocessUrl(i);var s=new Image;t.SetCorsBehavior(i,s);var a=function(){s.removeEventListener("load",a),s.removeEventListener("error",l),r(s)},l=function(e){s.removeEventListener("load",a),s.removeEventListener("error",l),t.Error("Error while trying to load image: "+i),n&&n("Error while trying to load image: "+i,e)};s.addEventListener("load",a),s.addEventListener("error",l);var c=function(){s.src=i},h=function(){o&&o.loadImageFromDB(i,s)};if("data:"!==i.substr(0,5)&&o&&o.enableTexturesOffline&&e.Database.IsUASupportingBlobStorage)o.openAsync(h,c);else{if(-1!==i.indexOf("file:")){var u=decodeURIComponent(i.substring(5).toLowerCase());if(e.FilesInput.FilesToLoad[u]){try{var f;try{f=URL.createObjectURL(e.FilesInput.FilesToLoad[u],{oneTimeOnly:!0})}catch(t){f=URL.createObjectURL(e.FilesInput.FilesToLoad[u])}s.src=f}catch(e){ s.src=""}return s}}c()}return s},t.LoadFile=function(r,n,o,s,a,l){if(r=t.CleanUrl(r),r=t.PreprocessUrl(r),-1!==r.indexOf("file:")){var c=decodeURIComponent(r.substring(5).toLowerCase());if(e.FilesInput.FilesToLoad[c])return t.ReadFile(e.FilesInput.FilesToLoad[c],n,o,a)}var h=t.BaseUrl+r,u=!1,f={onCompleteObservable:new e.Observable,abort:function(){return u=!0}},d=function(){var e=new XMLHttpRequest,r=null;f.abort=function(){u=!0,e.readyState!==(XMLHttpRequest.DONE||4)&&e.abort(),null!==r&&(clearTimeout(r),r=null)};var s=function(c){e.open("GET",h,!0),a&&(e.responseType="arraybuffer"),o&&e.addEventListener("progress",o);var d=function(){e.removeEventListener("loadend",d),f.onCompleteObservable.notifyObservers(f),f.onCompleteObservable.clear()};e.addEventListener("loadend",d);var p=function(){if(!u&&e.readyState===(XMLHttpRequest.DONE||4)){if(e.removeEventListener("readystatechange",p),e.status>=200&&e.status<300||!t.IsWindowObjectExist()&&0===e.status)return void n(a?e.response:e.responseText,e.responseURL);var o=t.DefaultRetryStrategy;if(o){var f=o(h,e,c);if(-1!==f)return e.removeEventListener("loadend",d),e=new XMLHttpRequest,void(r=setTimeout((function(){return s(c+1)}),f))}var _=new i("Error status: "+e.status+" "+e.statusText+" - Unable to load "+h,e);if(!l)throw _;l(e,_)}};e.addEventListener("readystatechange",p),e.send()};s(0)};if(s&&s.enableSceneOffline){var p=function(){u||d()},_=function(){u||s&&s.loadFileFromDB(r,(function(e){u||n(e),f.onCompleteObservable.notifyObservers(f)}),o?function(e){u||o(e)}:void 0,p,a)};s.openAsync(_,p)}else d();return f},t.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)},t.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},t.ReadFile=function(i,r,n,o){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){t.Log("Error while reading file: "+i.name),r(JSON.stringify({autoClear:!0,clearColor:[1,0,0],ambientColor:[0,0,0],gravity:[0,-9.807,0],meshes:[],cameras:[],lights:[]}))},s.onload=function(e){r(e.target.result)},n&&(s.onprogress=n),o?s.readAsArrayBuffer(i):s.readAsText(i),a},t.FileAsURL=function(e){var t=new Blob([e]);return(window.URL||window.webkitURL).createObjectURL(t)},t.Format=function(e,t){return void 0===t&&(t=2),e.toFixed(t)},t.CheckExtends=function(e,t,i){e.xi.x&&(i.x=e.x),e.y>i.y&&(i.y=e.y),e.z>i.z&&(i.z=e.z)},t.DeepCopy=function(e,t,i,r){for(var n in e)if(("_"!==n[0]||r&&-1!==r.indexOf(n))&&(!i||-1===i.indexOf(n))){var s=e[n],a=typeof s;if("function"!==a)if("object"===a)if(s instanceof Array){if(t[n]=[],s.length>0)if("object"==typeof s[0])for(var l=0;ll&&(f=l,u=f*h);var d=Math.max(0,a-u)/2,p=Math.max(0,l-f)/2,_=e.getRenderingCanvas();c&&_&&c.drawImage(_,d,p,u,f),t.EncodeScreenshotCanvasData(o,s)},t.CreateScreenshotUsingRenderTarget=function(i,r,n,o,s,a,l,c){void 0===s&&(s="image/png"),void 0===a&&(a=1),void 0===l&&(l=!1);var h,u;if(n.precision)h=Math.round(i.getRenderWidth()*n.precision),u=Math.round(h/i.getAspectRatio(r)),n={width:h,height:u};else if(n.width&&n.height)h=n.width,u=n.height;else if(n.width&&!n.height)h=n.width,u=Math.round(h/i.getAspectRatio(r)),n={width:h,height:u};else if(n.height&&!n.width)u=n.height,h=Math.round(u*i.getAspectRatio(r)),n={width:h,height:u};else{if(isNaN(n))return void t.Error("Invalid 'size' parameter !");u=n,h=n}var f=r.getScene(),d=null;f.activeCamera!==r&&(d=f.activeCamera,f.activeCamera=r);var p=new e.RenderTargetTexture("screenShot",n,f,!1,!1,e.Engine.TEXTURETYPE_UNSIGNED_INT,!1,e.Texture.NEAREST_SAMPLINGMODE);p.renderList=null,p.samples=a,l&&p.addPostProcess(new e.FxaaPostProcess("antialiasing",1,f.activeCamera)),p.onAfterRenderObservable.add((function(){t.DumpFramebuffer(h,u,i,o,s,c)})),f.incrementRenderId(),f.resetCachedMaterial(),p.render(!0),p.dispose(),d&&(f.activeCamera=d),r.getProjectionMatrix(!0)},t.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},t.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)}))},t.IsBase64=function(e){return!(e.length<5)&&"data:"===e.substr(0,5)},t.DecodeBase64=function(e){for(var t=atob(e.split(",")[1]),i=t.length,r=new Uint8Array(new ArrayBuffer(i)),n=0;n
";t._AddLogEntry(r)},t._WarnDisabled=function(e){},t._WarnEnabled=function(e){var i=t._FormatMessage(e);console.warn("BJS - "+i);var r="
"+i+"

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

";t._AddLogEntry(r)},Object.defineProperty(t,"LogCache",{get:function(){return t._LogCache},enumerable:!0,configurable:!0}),t.ClearLogCache=function(){t._LogCache="",t.errorsCount=0},Object.defineProperty(t,"LogLevels",{set:function(e){(e&t.MessageLogLevel)===t.MessageLogLevel?t.Log=t._LogEnabled:t.Log=t._LogDisabled,(e&t.WarningLogLevel)===t.WarningLogLevel?t.Warn=t._WarnEnabled:t.Warn=t._WarnDisabled,(e&t.ErrorLogLevel)===t.ErrorLogLevel?t.Error=t._ErrorEnabled:t.Error=t._ErrorDisabled},enumerable:!0,configurable:!0}),t.IsWindowObjectExist=function(){return"undefined"!=typeof window},Object.defineProperty(t,"PerformanceNoneLogLevel",{get:function(){return t._PerformanceNoneLogLevel},enumerable:!0,configurable:!0}),Object.defineProperty(t,"PerformanceUserMarkLogLevel",{get:function(){return t._PerformanceUserMarkLogLevel},enumerable:!0,configurable:!0}),Object.defineProperty(t,"PerformanceConsoleLogLevel",{get:function(){return t._PerformanceConsoleLogLevel},enumerable:!0,configurable:!0}),Object.defineProperty(t,"PerformanceLogLevel",{set:function(e){return(e&t.PerformanceUserMarkLogLevel)===t.PerformanceUserMarkLogLevel?(t.StartPerformanceCounter=t._StartUserMark,void(t.EndPerformanceCounter=t._EndUserMark)):(e&t.PerformanceConsoleLogLevel)===t.PerformanceConsoleLogLevel?(t.StartPerformanceCounter=t._StartPerformanceConsole,void(t.EndPerformanceCounter=t._EndPerformanceConsole)):(t.StartPerformanceCounter=t._StartPerformanceCounterDisabled,void(t.EndPerformanceCounter=t._EndPerformanceCounterDisabled))},enumerable:!0,configurable:!0}),t._StartPerformanceCounterDisabled=function(e,t){},t._EndPerformanceCounterDisabled=function(e,t){},t._StartUserMark=function(e,i){if(void 0===i&&(i=!0),!t._performance){if(!t.IsWindowObjectExist())return;t._performance=window.performance}i&&t._performance.mark&&t._performance.mark(e+"-Begin")},t._EndUserMark=function(e,i){void 0===i&&(i=!0),i&&t._performance.mark&&(t._performance.mark(e+"-End"),t._performance.measure(e,e+"-Begin",e+"-End"))},t._StartPerformanceConsole=function(e,i){void 0===i&&(i=!0),i&&(t._StartUserMark(e,i),console.time&&console.time(e))},t._EndPerformanceConsole=function(e,i){void 0===i&&(i=!0),i&&(t._EndUserMark(e,i),console.time&&console.timeEnd(e))},Object.defineProperty(t,"Now",{get:function(){return t.IsWindowObjectExist()&&window.performance&&window.performance.now?window.performance.now():(new Date).getTime()},enumerable:!0,configurable:!0}),t.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},t.First=function(e,t){for(var i=0,r=e;i=e.length)return null;var r=e.charCodeAt?e.charCodeAt(i):e[i];return r&&r.getHashCode&&(r=r.getHashCode()),"string"==typeof r?t.hashCodeFromStream(t.arrayOrStringFeeder(r)):r}},t.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},t.DelayAsync=function(e){return new Promise(function(t){setTimeout((function(){t()}),e)})},t.BaseUrl="",t.DefaultRetryStrategy=r.ExponentialBackoff(),t.CorsBehavior="anonymous",t.UseFallbackTexture=!0,t.RegisteredExternalClasses={},t.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",t.PreprocessUrl=function(e){return e},t._NoneLogLevel=0,t._MessageLogLevel=1,t._WarningLogLevel=2,t._ErrorLogLevel=4,t._LogCache="",t.errorsCount=0,t.Log=t._LogEnabled,t.Warn=t._WarnEnabled,t.Error=t._ErrorEnabled,t._PerformanceNoneLogLevel=0,t._PerformanceUserMarkLogLevel=1,t._PerformanceConsoleLogLevel=2,t.StartPerformanceCounter=t._StartPerformanceCounterDisabled,t.EndPerformanceCounter=t._EndPerformanceCounterDisabled,t})();e.Tools=s;var a=(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=s.Now)},e.prototype.endMonitoring=function(t){if(void 0===t&&(t=!0),e.Enabled){t&&this.fetchNewFrame();var i=s.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=s.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=a,e.className=t;var l=(function(){function e(e,t,i,r){void 0===r&&(r=0),this.iterations=e,this._fn=t,this._successCallback=i,this.index=r-1,this._done=!1}return e.prototype.executeNext=function(){this._done||(this.index+1=t)break;if(r(s),o&&o()){e.breakLoop();break}}e.executeNext()}),s)}),n)},e})();e.AsyncLoop=l})(e||(e={}));var e;!(function(e){var t;!(function(e){e[e.Pending=0]="Pending",e[e.Fulfilled=1]="Fulfilled",e[e.Rejected=2]="Rejected"})(t||(t={}));var i=(function(){function e(){this.count=0,this.target=0,this.results=[]}return e})(),r=(function(){function r(e){var i=this;if(this._state=t.Pending,this._children=new Array,this._rejectWasConsumed=!1,e)try{e((function(e){i._resolve(e)}),(function(e){i._reject(e)}))}catch(e){this._reject(e)}}return r.prototype.catch=function(e){return this.then(void 0,e)},r.prototype.then=function(i,n){var o=this,s=new r;return s._onFulfilled=i,s._onRejected=n,this._children.push(s),this._state!==t.Pending&&e.Tools.SetImmediate((function(){if(o._state===t.Fulfilled||o._rejectWasConsumed){var e=s._resolve(o._result);if(void 0!==e&&null!==e)if(void 0!==e._state){var i=e;s._children.push(i),s=i}else s._result=e}else s._reject(o._reason)})),s},r.prototype._moveChildren=function(e){if((a=this._children).push.apply(a,e.splice(0,e.length)),this._state===t.Fulfilled)for(var i=0,r=this._children;i-1){if(f.capture&&f.captureConstraint){var _=f.capture,m=f.captureConstraint,g=new RegExp(_),v=g.exec(c);if(v&&v.length>0){var y=parseInt(v[v.length-1]);if(y>=m)continue}}for(var b=0,x=p;b1&&!this.disableUniformBuffers},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"needPOTTextures",{get:function(){return this._webGLVersion<2||this.forcePOTTextures},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"badOS",{get:function(){return this._badOS},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"badDesktopOS",{get:function(){return this._badDesktopOS},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"performanceMonitor",{get:function(){return this._performanceMonitor},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"texturesSupported",{get:function(){return this._texturesSupported},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"textureFormatInUse",{get:function(){return this._textureFormatInUse},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"currentViewport",{get:function(){return this._cachedViewport},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"emptyTexture",{get:function(){return this._emptyTexture||(this._emptyTexture=this.createRawTexture(new Uint8Array(4),1,1,o.TEXTUREFORMAT_RGBA,!1,!1,e.Texture.NEAREST_SAMPLINGMODE)),this._emptyTexture},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"emptyTexture3D",{get:function(){return this._emptyTexture3D||(this._emptyTexture3D=this.createRawTexture3D(new Uint8Array(4),1,1,1,o.TEXTUREFORMAT_RGBA,!1,!1,e.Texture.NEAREST_SAMPLINGMODE)),this._emptyTexture3D},enumerable:!0,configurable:!0}),Object.defineProperty(o.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,o.TEXTUREFORMAT_RGBA,o.TEXTURETYPE_UNSIGNED_INT,!1,!1,e.Texture.NEAREST_SAMPLINGMODE)}return this._emptyCubeTexture},enumerable:!0,configurable:!0}),o.prototype._rebuildInternalTextures=function(){for(var e=this._internalTexturesCache.slice(),t=0,i=e;t1||null!==this._gl.getExtension("OES_standard_derivatives"),this._caps.astc=this._gl.getExtension("WEBGL_compressed_texture_astc")||this._gl.getExtension("WEBKIT_WEBGL_compressed_texture_astc"),this._caps.s3tc=this._gl.getExtension("WEBGL_compressed_texture_s3tc")||this._gl.getExtension("WEBKIT_WEBGL_compressed_texture_s3tc"),this._caps.pvrtc=this._gl.getExtension("WEBGL_compressed_texture_pvrtc")||this._gl.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc"),this._caps.etc1=this._gl.getExtension("WEBGL_compressed_texture_etc1")||this._gl.getExtension("WEBKIT_WEBGL_compressed_texture_etc1"),this._caps.etc2=this._gl.getExtension("WEBGL_compressed_texture_etc")||this._gl.getExtension("WEBKIT_WEBGL_compressed_texture_etc")||this._gl.getExtension("WEBGL_compressed_texture_es3_0"),this._caps.textureAnisotropicFilterExtension=this._gl.getExtension("EXT_texture_filter_anisotropic")||this._gl.getExtension("WEBKIT_EXT_texture_filter_anisotropic")||this._gl.getExtension("MOZ_EXT_texture_filter_anisotropic"),this._caps.maxAnisotropy=this._caps.textureAnisotropicFilterExtension?this._gl.getParameter(this._caps.textureAnisotropicFilterExtension.MAX_TEXTURE_MAX_ANISOTROPY_EXT):0,this._caps.uintIndices=this._webGLVersion>1||null!==this._gl.getExtension("OES_element_index_uint"),this._caps.fragmentDepthSupported=this._webGLVersion>1||null!==this._gl.getExtension("EXT_frag_depth"),this._caps.highPrecisionShaderSupported=!0,this._caps.timerQuery=this._gl.getExtension("EXT_disjoint_timer_query_webgl2")||this._gl.getExtension("EXT_disjoint_timer_query"),this._caps.timerQuery&&(1===this._webGLVersion&&(this._gl.getQuery=this._caps.timerQuery.getQueryEXT.bind(this._caps.timerQuery)),this._caps.canUseTimestampForTimerQuery=this._gl.getQuery(this._caps.timerQuery.TIMESTAMP_EXT,this._caps.timerQuery.QUERY_COUNTER_BITS_EXT)>0),this._caps.colorBufferFloat=this._webGLVersion>1&&this._gl.getExtension("EXT_color_buffer_float"),this._caps.textureFloat=this._webGLVersion>1||this._gl.getExtension("OES_texture_float"),this._caps.textureFloatLinearFiltering=this._caps.textureFloat&&this._gl.getExtension("OES_texture_float_linear"),this._caps.textureFloatRender=this._caps.textureFloat&&this._canRenderToFloatFramebuffer(),this._caps.textureHalfFloat=this._webGLVersion>1||this._gl.getExtension("OES_texture_half_float"),this._caps.textureHalfFloatLinearFiltering=this._webGLVersion>1||this._caps.textureHalfFloat&&this._gl.getExtension("OES_texture_half_float_linear"),this._webGLVersion>1&&(this._gl.HALF_FLOAT_OES=5131),this._caps.textureHalfFloatRender=this._caps.textureHalfFloat&&this._canRenderToHalfFloatFramebuffer(),this._caps.textureLOD=this._webGLVersion>1||this._gl.getExtension("EXT_shader_texture_lod"),this._webGLVersion>1)this._caps.drawBuffersExtension=!0;else{var t=this._gl.getExtension("WEBGL_draw_buffers");if(null!==t){this._caps.drawBuffersExtension=!0,this._gl.drawBuffers=t.drawBuffersWEBGL.bind(t),this._gl.DRAW_FRAMEBUFFER=this._gl.FRAMEBUFFER;for(var i=0;i<16;i++)this._gl["COLOR_ATTACHMENT"+i+"_WEBGL"]=t["COLOR_ATTACHMENT"+i+"_WEBGL"]}else this._caps.drawBuffersExtension=!1}if(this._webGLVersion>1)this._caps.depthTextureExtension=!0;else{var r=this._gl.getExtension("WEBGL_depth_texture");null!=r&&(this._caps.depthTextureExtension=!0,this._gl.UNSIGNED_INT_24_8=r.UNSIGNED_INT_24_8_WEBGL)}if(this._webGLVersion>1)this._caps.vertexArrayObject=!0;else{var n=this._gl.getExtension("OES_vertex_array_object");null!=n?(this._caps.vertexArrayObject=!0,this._gl.createVertexArray=n.createVertexArrayOES.bind(n),this._gl.bindVertexArray=n.bindVertexArrayOES.bind(n),this._gl.deleteVertexArray=n.deleteVertexArrayOES.bind(n)):this._caps.vertexArrayObject=!1}if(this._webGLVersion>1)this._caps.instancedArrays=!0;else{var o=this._gl.getExtension("ANGLE_instanced_arrays");null!=o?(this._caps.instancedArrays=!0,this._gl.drawArraysInstanced=o.drawArraysInstancedANGLE.bind(o),this._gl.drawElementsInstanced=o.drawElementsInstancedANGLE.bind(o),this._gl.vertexAttribDivisor=o.vertexAttribDivisorANGLE.bind(o)):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 s=this._gl.getShaderPrecisionFormat(this._gl.FRAGMENT_SHADER,this._gl.HIGH_FLOAT);s&&(this._caps.highPrecisionShaderSupported=0!==s.precision)}this.setDepthBuffer(!0),this.setDepthFunctionToLessOrEqual(),this.setDepthWrite(!0),this._maxSimultaneousTextures=this._caps.maxCombinedTexturesImageUnits;for(var a=0;a=0&&this._activeRenderLoops.splice(t,1)},o.prototype._renderLoop=function(){if(!this._contextWasLost){var t=!0;if(!this.renderEvenInBackground&&this._windowIsBackground&&(t=!1),t){this.beginFrame();for(var i=0;i0){var r=null;this._vrDisplay&&this._vrDisplay.isPresenting&&(r=this._vrDisplay),this._frameHandler=e.Tools.QueueNewFrame(this._bindedRenderFunction,r)}else this._renderingQueueLaunched=!1},o.prototype.runRenderLoop=function(t){-1===this._activeRenderLoops.indexOf(t)&&(this._activeRenderLoops.push(t),this._renderingQueueLaunched||(this._renderingQueueLaunched=!0,this._bindedRenderFunction=this._renderLoop.bind(this),this._frameHandler=e.Tools.QueueNewFrame(this._bindedRenderFunction)))},o.prototype.switchFullscreen=function(t){this.isFullscreen?e.Tools.ExitFullscreen():(this._pointerLockRequested=t,this._renderingCanvas&&e.Tools.RequestFullscreen(this._renderingCanvas))},o.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)},o.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)},o.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)},o.prototype.setDirectViewport=function(e,t,i,r){var n=this._cachedViewport;return this._cachedViewport=null,this._gl.viewport(e,t,i,r),n},o.prototype.beginFrame=function(){this.onBeginFrameObservable.notifyObservers(this),this._measureFps()},o.prototype.endFrame=function(){this._badOS&&this.flushFramebuffer(),this._vrDisplay&&this._vrDisplay.isPresenting&&this._vrDisplay.submitFrame(),this.onEndFrameObservable.notifyObservers(this)},o.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)}},o.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;i1?"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(var o=0;o1?"COLOR_ATTACHMENT"+o:"COLOR_ATTACHMENT"+o+"_WEBGL"];r.drawBuffers(n)}for(var o=0;o65535){n=!0;break}r=n?new Uint32Array(e):new Uint16Array(e)}else r=new Uint16Array(e);return this._gl.bufferData(this._gl.ELEMENT_ARRAY_BUFFER,r,t?this._gl.DYNAMIC_DRAW:this._gl.STATIC_DRAW),this._resetIndexBufferBinding(),i.references=1,i.is32Bits=n,i},o.prototype.bindArrayBuffer=function(e){this._vaoRecordInProgress||this._unbindVertexArrayObject(),this.bindBuffer(e,this._gl.ARRAY_BUFFER)},o.prototype.bindUniformBuffer=function(e){this._gl.bindBuffer(this._gl.UNIFORM_BUFFER,e)},o.prototype.bindUniformBufferBase=function(e,t){this._gl.bindBufferBase(this._gl.UNIFORM_BUFFER,t,e)},o.prototype.bindUniformBlock=function(e,t,i){var r=this._gl.getUniformBlockIndex(e,t);this._gl.uniformBlockBinding(e,r,i)},o.prototype.bindIndexBuffer=function(e){this._vaoRecordInProgress||this._unbindVertexArrayObject(),this.bindBuffer(e,this._gl.ELEMENT_ARRAY_BUFFER)},o.prototype.bindBuffer=function(e,t){(this._vaoRecordInProgress||this._currentBoundBuffer[t]!==e)&&(this._gl.bindBuffer(t,e),this._currentBoundBuffer[t]=e)},o.prototype.updateArrayBuffer=function(e){this._gl.bufferSubData(this._gl.ARRAY_BUFFER,0,e)},o.prototype.vertexAttribPointer=function(e,t,i,r,n,o,s){var a=this._currentBufferPointers[t],l=!1;a.active?(a.buffer!==e&&(a.buffer=e,l=!0),a.size!==i&&(a.size=i,l=!0),a.type!==r&&(a.type=r,l=!0),a.normalized!==n&&(a.normalized=n,l=!0),a.stride!==o&&(a.stride=o,l=!0),a.offset!==s&&(a.offset=s,l=!0)):(l=!0,a.active=!0,a.index=t,a.size=i,a.type=r,a.normalized=n,a.stride=o,a.offset=s,a.buffer=e),(l||this._vaoRecordInProgress)&&(this.bindArrayBuffer(e),this._gl.vertexAttribPointer(t,i,r,n,o,s))},o.prototype._bindIndexBufferWithCache=function(e){null!=e&&this._cachedIndexBuffer!==e&&(this._cachedIndexBuffer=e,this.bindIndexBuffer(e),this._uintIndicesCurrentlySet=e.is32Bits)},o.prototype._bindVertexBuffersAttributes=function(e,t){var i=t.getAttributesNames();this._vaoRecordInProgress||this._unbindVertexArrayObject(),this.unbindAllAttributes();for(var r=0;r=0){var o=e[i[r]];if(!o)continue;this._gl.enableVertexAttribArray(n),this._vaoRecordInProgress||(this._vertexAttribArraysEnabled[n]=!0);var s=o.getBuffer();s&&(this.vertexAttribPointer(s,n,o.getSize(),this._gl.FLOAT,!1,4*o.getStrideSize(),4*o.getOffset()),o.getIsInstanced()&&(this._gl.vertexAttribDivisor(n,o.getInstanceDivisor()),this._vaoRecordInProgress||(this._currentInstanceLocations.push(n),this._currentInstanceBuffers.push(s))))}}},o.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},o.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)},o.prototype.bindBuffersDirectly=function(e,t,i,r,n){if(this._cachedVertexBuffers!==e||this._cachedEffectForVertexBuffers!==n){this._cachedVertexBuffers=e,this._cachedEffectForVertexBuffers=n;var o=n.getAttributesCount();this._unbindVertexArrayObject(),this.unbindAllAttributes();for(var s=0,a=0;a=0&&(this._gl.enableVertexAttribArray(l),this._vertexAttribArraysEnabled[l]=!0,this.vertexAttribPointer(e,l,i[a],this._gl.FLOAT,!1,r,s)),s+=4*i[a]}}this._bindIndexBufferWithCache(t)},o.prototype._unbindVertexArrayObject=function(){this._cachedVertexArrayObject&&(this._cachedVertexArrayObject=null,this._gl.bindVertexArray(null))},o.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)},o.prototype.unbindInstanceAttributes=function(){for(var e,t=0,i=this._currentInstanceLocations.length;t1?"#version 300 es\n":"",a=i(n,e,"vertex",r,s),l=i(n,t,"fragment",r,s),c=this._createShaderProgram(a,l,n,o);return this.onAfterShaderCompilationObservable.notifyObservers(this),c},o.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},o.prototype.getUniforms=function(e,t){for(var i=new Array,r=0;r0?f.substring(g).toLowerCase():"",y=this.getCaps().s3tc&&0===v.indexOf(".dds"),b=0===v.indexOf(".tga"),x=!1;!this._textureFormatInUse||_||c||(f=f.substring(0,g)+this._textureFormatInUse,x=!0),n&&n._addPendingData(m),m.url=f,m.generateMipMaps=!i,m.samplingMode=o,m.invertY=r,this._doNotHandleContextLost||(m._buffer=l);var T=null;s&&!c&&(T=m.onLoadedObservable.add(s)),c||this._internalTexturesCache.push(m);var E=function(s,c){n&&n._removePendingData(m),T&&m.onLoadedObservable.remove(T),x?u.createTexture(t,i,r,n,o,null,a,l,m):e.Tools.UseFallbackTexture&&u.createTexture(e.Tools.fallbackTexture,i,r,n,o,null,a,l,m),a&&a(s||"Unknown error",c)},A=null;if(x||b||y)x?A=function(t){var s=new e.KhronosTextureContainer(t,1);u._prepareWebGLTexture(m,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(m,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(m,n,s.width,s.height,r,!a,s.isFourCC,(function(){return e.DDSTools.UploadDDSLevels(u,u._gl,t,s,a,1),!1}),o)}),l?A&&A(l):this._loadFile(f,(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){p&&!u._doNotHandleContextLost&&(m._buffer=t),u._prepareWebGLTexture(m,n,t.width,t.height,r,i,!1,(function(i,r,o){var s=u._gl,a=t.width===i&&t.height===r,l=h?u._getInternalFormat(h):".jpg"===v?s.RGB:s.RGBA;if(a)return s.texImage2D(s.TEXTURE_2D,0,l,l,s.UNSIGNED_BYTE,t),!1;var c=new e.InternalTexture(u,e.InternalTexture.DATASOURCE_TEMP);return u._bindTextureDirectly(s.TEXTURE_2D,c,!0),s.texImage2D(s.TEXTURE_2D,0,l,l,s.UNSIGNED_BYTE,t),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MAG_FILTER,s.LINEAR),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MIN_FILTER,s.LINEAR),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_S,s.CLAMP_TO_EDGE),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_T,s.CLAMP_TO_EDGE),u._rescaleTexture(c,m,n,l,(function(){u._releaseTexture(c),u._bindTextureDirectly(s.TEXTURE_2D,m,!0),o()})),!0}),o)};!d||_?l instanceof HTMLImageElement?P(l):e.Tools.LoadImage(f,P,E,n?n.database:null):l instanceof Array||"string"==typeof l||l instanceof ArrayBuffer?e.Tools.LoadImage(l,P,E,n?n.database:null):P(l)}return m},o.prototype._rescaleTexture=function(t,i,r,n,s){var a=this,l=this.createRenderTargetTexture({width:i.width,height:i.height},{generateMipMaps:!1,type:o.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,o.TEXTURETYPE_UNSIGNED_INT)),this._rescalePostProcess.getEffect().executeWhenCompiled((function(){a._rescalePostProcess.onApply=function(e){e._bindTexture("textureSampler",t)};var e=r;e||(e=a.scenes[a.scenes.length-1]),e.postProcessManager.directRender([a._rescalePostProcess],l,!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(l),a._releaseTexture(l),s&&s()}))},o.prototype._getInternalFormat=function(e){var t=this._gl.RGBA;switch(e){case o.TEXTUREFORMAT_ALPHA:t=this._gl.ALPHA;break;case o.TEXTUREFORMAT_LUMINANCE:t=this._gl.LUMINANCE;break;case o.TEXTUREFORMAT_LUMINANCE_ALPHA:t=this._gl.LUMINANCE_ALPHA;break;case o.TEXTUREFORMAT_RGB:case o.TEXTUREFORMAT_RGB32F:t=this._gl.RGB;break;case o.TEXTUREFORMAT_RGBA:case o.TEXTUREFORMAT_RGBA32F:t=this._gl.RGBA;break;case o.TEXTUREFORMAT_R32F:t=this._gl.RED;break;case o.TEXTUREFORMAT_RG32F:t=this._gl.RG}return t},o.prototype.updateRawTexture=function(e,t,i,r,n,s){if(void 0===n&&(n=null),void 0===s&&(s=o.TEXTURETYPE_UNSIGNED_INT),e){var a=this._getRGBABufferInternalSizedFormat(s,i),l=this._getInternalFormat(i),c=this._getWebGLTextureType(s);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=s,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,a,e.width,e.height,0,l,c,t),e.generateMipMaps&&this._gl.generateMipmap(this._gl.TEXTURE_2D),this._bindTextureDirectly(this._gl.TEXTURE_2D,null),e.isReady=!0}},o.prototype.createRawTexture=function(t,i,r,s,a,l,c,h,u){void 0===h&&(h=null),void 0===u&&(u=o.TEXTURETYPE_UNSIGNED_INT);var f=new e.InternalTexture(this,e.InternalTexture.DATASOURCE_RAW);f.baseWidth=i,f.baseHeight=r,f.width=i,f.height=r,f.format=s,f.generateMipMaps=a,f.samplingMode=c,f.invertY=l,f._compression=h,f.type=u,this._doNotHandleContextLost||(f._bufferView=t),this.updateRawTexture(f,t,s,l,h,u),this._bindTextureDirectly(this._gl.TEXTURE_2D,f,!0);var d=n(c,a,this._gl);return this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_MAG_FILTER,d.mag),this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_MIN_FILTER,d.min),a&&this._gl.generateMipmap(this._gl.TEXTURE_2D),this._bindTextureDirectly(this._gl.TEXTURE_2D,null),this._internalTexturesCache.push(f),f},o.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},o.prototype.updateTextureSamplingMode=function(e,t){var i=n(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},o.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}},o.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}}},o.prototype.updateTextureComparisonFunction=function(t,i){if(1===this.webGLVersion)return void e.Tools.Error("WebGL 1 does not support texture comparison.");var r=this._gl;t.isCube?(this._bindTextureDirectly(this._gl.TEXTURE_CUBE_MAP,t,!0),0===i?(r.texParameteri(r.TEXTURE_CUBE_MAP,r.TEXTURE_COMPARE_FUNC,o.LEQUAL),r.texParameteri(r.TEXTURE_CUBE_MAP,r.TEXTURE_COMPARE_MODE,r.NONE)):(r.texParameteri(r.TEXTURE_CUBE_MAP,r.TEXTURE_COMPARE_FUNC,i),r.texParameteri(r.TEXTURE_CUBE_MAP,r.TEXTURE_COMPARE_MODE,r.COMPARE_REF_TO_TEXTURE)),this._bindTextureDirectly(this._gl.TEXTURE_CUBE_MAP,null)):(this._bindTextureDirectly(this._gl.TEXTURE_2D,t,!0),0===i?(r.texParameteri(r.TEXTURE_2D,r.TEXTURE_COMPARE_FUNC,o.LEQUAL),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_COMPARE_MODE,r.NONE)):(r.texParameteri(r.TEXTURE_2D,r.TEXTURE_COMPARE_FUNC,i),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_COMPARE_MODE,r.COMPARE_REF_TO_TEXTURE)),this._bindTextureDirectly(this._gl.TEXTURE_2D,null)),t._comparisonFunction=i},o.prototype._setupDepthStencilTexture=function(t,i,r,s,a){var l=i.width||i,c=i.height||i;t.baseWidth=l,t.baseHeight=c,t.width=l,t.height=c,t.isReady=!0,t.samples=1,t.generateMipMaps=!1,t._generateDepthBuffer=!0,t._generateStencilBuffer=r,t.samplingMode=s?e.Texture.NEAREST_SAMPLINGMODE:e.Texture.BILINEAR_SAMPLINGMODE,t.type=o.TEXTURETYPE_UNSIGNED_INT,t._comparisonFunction=a;var h=this._gl,u=t.isCube?h.TEXTURE_CUBE_MAP:h.TEXTURE_2D,f=n(t.samplingMode,!1,h);h.texParameteri(u,h.TEXTURE_MAG_FILTER,f.mag),h.texParameteri(u,h.TEXTURE_MIN_FILTER,f.min),h.texParameteri(u,h.TEXTURE_WRAP_S,h.CLAMP_TO_EDGE),h.texParameteri(u,h.TEXTURE_WRAP_T,h.CLAMP_TO_EDGE),0===a?(h.texParameteri(u,h.TEXTURE_COMPARE_FUNC,o.LEQUAL),h.texParameteri(u,h.TEXTURE_COMPARE_MODE,h.NONE)):(h.texParameteri(u,h.TEXTURE_COMPARE_FUNC,a),h.texParameteri(u,h.TEXTURE_COMPARE_MODE,h.COMPARE_REF_TO_TEXTURE))},o.prototype.createDepthStencilTexture=function(i,r){var n=new e.InternalTexture(this,e.InternalTexture.DATASOURCE_DEPTHTEXTURE);if(!this._caps.depthTextureExtension)return e.Tools.Error("Depth texture is not supported by your browser or hardware."),n;var o=t({bilinearFiltering:!1,comparisonFunction:0,generateStencil:!1},r),s=this._gl;return this._bindTextureDirectly(s.TEXTURE_2D,n,!0),this._setupDepthStencilTexture(n,i,o.generateStencil,o.bilinearFiltering,o.comparisonFunction),this.webGLVersion>1?o.generateStencil?s.texImage2D(s.TEXTURE_2D,0,s.DEPTH24_STENCIL8,n.width,n.height,0,s.DEPTH_STENCIL,s.UNSIGNED_INT_24_8,null):s.texImage2D(s.TEXTURE_2D,0,s.DEPTH_COMPONENT24,n.width,n.height,0,s.DEPTH_COMPONENT,s.UNSIGNED_INT,null):o.generateStencil?s.texImage2D(s.TEXTURE_2D,0,s.DEPTH_STENCIL,n.width,n.height,0,s.DEPTH_STENCIL,s.UNSIGNED_INT_24_8,null):s.texImage2D(s.TEXTURE_2D,0,s.DEPTH_COMPONENT,n.width,n.height,0,s.DEPTH_COMPONENT,s.UNSIGNED_INT,null),this._bindTextureDirectly(s.TEXTURE_2D,null),n},o.prototype.createDepthStencilCubeTexture=function(i,r){var n=new e.InternalTexture(this,e.InternalTexture.DATASOURCE_UNKNOWN);if(n.isCube=!0,1===this.webGLVersion)return e.Tools.Error("Depth cube texture is not supported by WebGL 1."),n;var o=t({bilinearFiltering:!1,comparisonFunction:0,generateStencil:!1},r),s=this._gl;this._bindTextureDirectly(s.TEXTURE_CUBE_MAP,n,!0),this._setupDepthStencilTexture(n,i,o.generateStencil,o.bilinearFiltering,o.comparisonFunction);for(var a=0;a<6;a++)o.generateStencil?s.texImage2D(s.TEXTURE_CUBE_MAP_POSITIVE_X+a,0,s.DEPTH24_STENCIL8,i,i,0,s.DEPTH_STENCIL,s.UNSIGNED_INT_24_8,null):s.texImage2D(s.TEXTURE_CUBE_MAP_POSITIVE_X+a,0,s.DEPTH_COMPONENT24,i,i,0,s.DEPTH_COMPONENT,s.UNSIGNED_INT,null);return this._bindTextureDirectly(s.TEXTURE_CUBE_MAP,null),n},o.prototype.setFrameBufferDepthStencilTexture=function(e){var t=e.getInternalTexture();if(t&&t._framebuffer&&e.depthStencilTexture){var i=this._gl,r=e.depthStencilTexture;this.bindUnboundFramebuffer(t._framebuffer),r.isCube?r._generateStencilBuffer?i.framebufferTexture2D(i.FRAMEBUFFER,i.DEPTH_STENCIL_ATTACHMENT,i.TEXTURE_CUBE_MAP_POSITIVE_X,r,0):i.framebufferTexture2D(i.FRAMEBUFFER,i.DEPTH_ATTACHMENT,i.TEXTURE_CUBE_MAP_POSITIVE_X,r,0):r._generateStencilBuffer?i.framebufferTexture2D(i.FRAMEBUFFER,i.DEPTH_STENCIL_ATTACHMENT,i.TEXTURE_2D,r,0):i.framebufferTexture2D(i.FRAMEBUFFER,i.DEPTH_ATTACHMENT,i.TEXTURE_2D,r,0),this.bindUnboundFramebuffer(null)}},o.prototype.createRenderTargetTexture=function(t,i){var r=new c;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?o.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=o.TEXTURETYPE_UNSIGNED_INT,r.samplingMode=e.Texture.TRILINEAR_SAMPLINGMODE),r.type!==o.TEXTURETYPE_FLOAT||this._caps.textureFloatLinearFiltering?r.type!==o.TEXTURETYPE_HALF_FLOAT||this._caps.textureHalfFloatLinearFiltering||(r.samplingMode=e.Texture.NEAREST_SAMPLINGMODE):r.samplingMode=e.Texture.NEAREST_SAMPLINGMODE;var s=this._gl,a=new e.InternalTexture(this,e.InternalTexture.DATASOURCE_RENDERTARGET);this._bindTextureDirectly(s.TEXTURE_2D,a,!0);var l=t.width||t,h=t.height||t,u=n(r.samplingMode,!!r.generateMipMaps,s);r.type!==o.TEXTURETYPE_FLOAT||this._caps.textureFloat||(r.type=o.TEXTURETYPE_UNSIGNED_INT,e.Tools.Warn("Float textures are not supported. Render target forced to TEXTURETYPE_UNSIGNED_BYTE type")),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MAG_FILTER,u.mag),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MIN_FILTER,u.min),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_S,s.CLAMP_TO_EDGE),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_T,s.CLAMP_TO_EDGE),s.texImage2D(s.TEXTURE_2D,0,this._getRGBABufferInternalSizedFormat(r.type),l,h,0,s.RGBA,this._getWebGLTextureType(r.type),null);var f=s.createFramebuffer();return this.bindUnboundFramebuffer(f),s.framebufferTexture2D(s.FRAMEBUFFER,s.COLOR_ATTACHMENT0,s.TEXTURE_2D,a._webGLTexture,0),a._depthStencilBuffer=this._setupFramebufferDepthAttachments(!!r.generateStencilBuffer,r.generateDepthBuffer,l,h),r.generateMipMaps&&this._gl.generateMipmap(this._gl.TEXTURE_2D),this._bindTextureDirectly(s.TEXTURE_2D,null),s.bindRenderbuffer(s.RENDERBUFFER,null),this.bindUnboundFramebuffer(null),a._framebuffer=f,a.baseWidth=l,a.baseHeight=h,a.width=l,a.height=h,a.isReady=!0,a.samples=1,a.generateMipMaps=!!r.generateMipMaps,a.samplingMode=r.samplingMode,a.type=r.type,a._generateDepthBuffer=r.generateDepthBuffer,a._generateStencilBuffer=!!r.generateStencilBuffer,this._internalTexturesCache.push(a),a},o.prototype.createMultipleRenderTarget=function(t,i){var r=!1,s=!0,a=!1,l=!1,c=1,h=o.TEXTURETYPE_UNSIGNED_INT,u=e.Texture.TRILINEAR_SAMPLINGMODE,f=[],d=[];void 0!==i&&(r=i.generateMipMaps,s=void 0===i.generateDepthBuffer||i.generateDepthBuffer,a=i.generateStencilBuffer,l=i.generateDepthTexture,c=i.textureCount||1,i.types&&(f=i.types),i.samplingModes&&(d=i.samplingModes));var p=this._gl,_=p.createFramebuffer();this.bindUnboundFramebuffer(_);for(var m=t.width||t,g=t.height||t,v=[],y=[],b=this._setupFramebufferDepthAttachments(a,s,m,g),x=0;x1?"COLOR_ATTACHMENT"+x:"COLOR_ATTACHMENT"+x+"_WEBGL"];v.push(P),y.push(M),p.activeTexture(p["TEXTURE"+x]),p.bindTexture(p.TEXTURE_2D,P._webGLTexture),p.texParameteri(p.TEXTURE_2D,p.TEXTURE_MAG_FILTER,A.mag),p.texParameteri(p.TEXTURE_2D,p.TEXTURE_MIN_FILTER,A.min),p.texParameteri(p.TEXTURE_2D,p.TEXTURE_WRAP_S,p.CLAMP_TO_EDGE),p.texParameteri(p.TEXTURE_2D,p.TEXTURE_WRAP_T,p.CLAMP_TO_EDGE),p.texImage2D(p.TEXTURE_2D,0,this._getRGBABufferInternalSizedFormat(E),m,g,0,p.RGBA,this._getWebGLTextureType(E),null),p.framebufferTexture2D(p.DRAW_FRAMEBUFFER,M,p.TEXTURE_2D,P._webGLTexture,0),r&&this._gl.generateMipmap(this._gl.TEXTURE_2D),this._bindTextureDirectly(p.TEXTURE_2D,null),P._framebuffer=_,P._depthStencilBuffer=b,P.baseWidth=m,P.baseHeight=g,P.width=m,P.height=g,P.isReady=!0,P.samples=1,P.generateMipMaps=r,P.samplingMode=T,P.type=E,P._generateDepthBuffer=s,P._generateStencilBuffer=a,P._attachments=y,this._internalTexturesCache.push(P)}if(l&&this._caps.depthTextureExtension){var S=new e.InternalTexture(this,e.InternalTexture.DATASOURCE_MULTIRENDERTARGET);p.activeTexture(p.TEXTURE0),p.bindTexture(p.TEXTURE_2D,S._webGLTexture),p.texParameteri(p.TEXTURE_2D,p.TEXTURE_MAG_FILTER,p.NEAREST),p.texParameteri(p.TEXTURE_2D,p.TEXTURE_MIN_FILTER,p.NEAREST),p.texParameteri(p.TEXTURE_2D,p.TEXTURE_WRAP_S,p.CLAMP_TO_EDGE),p.texParameteri(p.TEXTURE_2D,p.TEXTURE_WRAP_T,p.CLAMP_TO_EDGE),p.texImage2D(p.TEXTURE_2D,0,this.webGLVersion<2?p.DEPTH_COMPONENT:p.DEPTH_COMPONENT16,m,g,0,p.DEPTH_COMPONENT,p.UNSIGNED_SHORT,null),p.framebufferTexture2D(p.FRAMEBUFFER,p.DEPTH_ATTACHMENT,p.TEXTURE_2D,S._webGLTexture,0),S._framebuffer=_,S.baseWidth=m,S.baseHeight=g,S.width=m,S.height=g,S.isReady=!0,S.samples=1,S.generateMipMaps=r,S.samplingMode=p.NEAREST,S._generateDepthBuffer=s,S._generateStencilBuffer=a,v.push(S),this._internalTexturesCache.push(S)}return p.drawBuffers(y),p.bindRenderbuffer(p.RENDERBUFFER,null),this.bindUnboundFramebuffer(null),this.resetTextureCache(),v},o.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},o.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},o.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;r1){var n=i.createFramebuffer();if(!n)throw new Error("Unable to create multi sampled framebuffer");this.bindUnboundFramebuffer(n);for(var o=this._setupFramebufferDepthAttachments(e[0]._generateStencilBuffer,e[0]._generateDepthBuffer,e[0].width,e[0].height,t),s=[],r=0;r1?"COLOR_ATTACHMENT"+r:"COLOR_ATTACHMENT"+r+"_WEBGL"],c=i.createRenderbuffer();if(!c)throw new Error("Unable to create multi sampled framebuffer");i.bindRenderbuffer(i.RENDERBUFFER,c),i.renderbufferStorageMultisample(i.RENDERBUFFER,t,this._getRGBAMultiSampleBufferFormat(a.type),a.width,a.height),i.framebufferRenderbuffer(i.FRAMEBUFFER,l,i.RENDERBUFFER,c),a._MSAAFramebuffer=n,a._MSAARenderBuffer=c,a.samples=t,a._depthStencilBuffer=o,i.bindRenderbuffer(i.RENDERBUFFER,null),s.push(l)}i.drawBuffers(s)}else this.bindUnboundFramebuffer(e[0]._framebuffer);return this.bindUnboundFramebuffer(null),t},o.prototype._uploadDataToTexture=function(e,t,i,r,n,o,s,a){this._gl.texImage2D(e,t,i,r,n,0,o,s,a)},o.prototype._uploadCompressedDataToTexture=function(e,t,i,r,n,o){this._gl.compressedTexImage2D(e,t,i,r,n,0,o)},o.prototype.createRenderTargetCubeTexture=function(i,r){var s=t({generateMipMaps:!0,generateDepthBuffer:!0,generateStencilBuffer:!1,type:o.TEXTURETYPE_UNSIGNED_INT,samplingMode:e.Texture.TRILINEAR_SAMPLINGMODE},r);s.generateStencilBuffer=s.generateDepthBuffer&&s.generateStencilBuffer,s.type!==o.TEXTURETYPE_FLOAT||this._caps.textureFloatLinearFiltering?s.type!==o.TEXTURETYPE_HALF_FLOAT||this._caps.textureHalfFloatLinearFiltering||(s.samplingMode=e.Texture.NEAREST_SAMPLINGMODE):s.samplingMode=e.Texture.NEAREST_SAMPLINGMODE;var a=this._gl,l=new e.InternalTexture(this,e.InternalTexture.DATASOURCE_RENDERTARGET);this._bindTextureDirectly(a.TEXTURE_CUBE_MAP,l,!0);var c=n(s.samplingMode,s.generateMipMaps,a);s.type!==o.TEXTURETYPE_FLOAT||this._caps.textureFloat||(s.type=o.TEXTURETYPE_UNSIGNED_INT,e.Tools.Warn("Float textures are not supported. Cube render target forced to TEXTURETYPE_UNESIGNED_BYTE type")),a.texParameteri(a.TEXTURE_CUBE_MAP,a.TEXTURE_MAG_FILTER,c.mag),a.texParameteri(a.TEXTURE_CUBE_MAP,a.TEXTURE_MIN_FILTER,c.min),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);for(var h=0;h<6;h++)a.texImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X+h,0,this._getRGBABufferInternalSizedFormat(s.type),i,i,0,a.RGBA,this._getWebGLTextureType(s.type),null);var u=a.createFramebuffer();return this.bindUnboundFramebuffer(u),l._depthStencilBuffer=this._setupFramebufferDepthAttachments(s.generateStencilBuffer,s.generateDepthBuffer,i,i),s.generateMipMaps&&a.generateMipmap(a.TEXTURE_CUBE_MAP),this._bindTextureDirectly(a.TEXTURE_CUBE_MAP,null),a.bindRenderbuffer(a.RENDERBUFFER,null),this.bindUnboundFramebuffer(null),l._framebuffer=u,l.width=i,l.height=i,l.isReady=!0,l.isCube=!0,l.samples=1,l.generateMipMaps=s.generateMipMaps,l.samplingMode=s.samplingMode,l.type=s.type,l._generateDepthBuffer=s.generateDepthBuffer,l._generateStencilBuffer=s.generateStencilBuffer,this._internalTexturesCache.push(l),l},o.prototype.createPrefilteredCubeTexture=function(t,i,r,n,o,s,a,l){var c=this;void 0===o&&(o=null),void 0===s&&(s=null),void 0===l&&(l=null);var h=function(t){if(!t)return void(o&&o(null));var s=t.texture;if(s._dataSource=e.InternalTexture.DATASOURCE_CUBEPREFILTERED,s._lodGenerationScale=r,s._lodGenerationOffset=n,c._caps.textureLOD)return void(o&&o(s));var a=c._gl,l=t.width;if(l){for(var h=[],u=0;u<3;u++){var f=u/2,d=1-f,p=n,_=e.Scalar.Log2(l)*r+n,m=p+(_-p)*d,g=Math.round(Math.min(Math.max(m,0),_)),v=new e.InternalTexture(c,e.InternalTexture.DATASOURCE_TEMP);if(v.isCube=!0,c._bindTextureDirectly(a.TEXTURE_CUBE_MAP,v,!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 y=t.info,b=t.data;a.pixelStorei(a.UNPACK_FLIP_Y_WEBGL,y.isCompressed?1:0),e.DDSTools.UploadDDSLevels(c,c._gl,b,y,!0,6,g)}else e.Tools.Warn("DDS is the only prefiltered cube map supported so far.");c._bindTextureDirectly(a.TEXTURE_CUBE_MAP,null);var x=new e.BaseTexture(i);x.isCube=!0,x._texture=v,v.isReady=!0,h.push(x)}s._lodTextureHigh=h[2],s._lodTextureMid=h[1],s._lodTextureLow=h[0],o&&o(s)}};return this.createCubeTexture(t,i,null,!1,h,s,a,l)},o.prototype.createCubeTexture=function(t,i,r,n,o,a,l,c){var h=this;void 0===o&&(o=null),void 0===a&&(a=null),void 0===c&&(c=null);var u=this._gl,f=new e.InternalTexture(this,e.InternalTexture.DATASOURCE_CUBE);f.isCube=!0,f.url=t,f.generateMipMaps=!n,this._doNotHandleContextLost||(f._extension=c,f._files=r);var d=!1,p=!1,_=t.lastIndexOf("."),m=c||(_>-1?t.substring(_).toLowerCase():"");this._textureFormatInUse?(m=this._textureFormatInUse,t=(_>-1?t.substring(0,_):t)+this._textureFormatInUse,d=!0):p=".dds"===m;var g=function(e,t){a&&e&&a(e.status+" "+e.statusText,t)};if(d)this._loadFile(t,(function(t){var i=new e.KhronosTextureContainer(t,6),r=i.numberOfMipmapLevels>1&&!n;h._bindTextureDirectly(u.TEXTURE_CUBE_MAP,f,!0),u.pixelStorei(u.UNPACK_FLIP_Y_WEBGL,1),i.uploadLevels(h._gl,!n),h.setCubeMapTextureParams(u,r),f.width=i.pixelWidth,f.height=i.pixelHeight,f.isReady=!0}),void 0,void 0,!0,g);else if(p)r&&6===r.length?this._cascadeLoadFiles(i,(function(t){for(var i,r=!1,s=0,a=0;a1)&&!n,h._bindTextureDirectly(u.TEXTURE_CUBE_MAP,f,!0),u.pixelStorei(u.UNPACK_FLIP_Y_WEBGL,i.isCompressed?1:0),e.DDSTools.UploadDDSLevels(h,h._gl,l,i,r,6,-1,a),n||i.isFourCC||1!==i.mipmapCount||u.generateMipmap(u.TEXTURE_CUBE_MAP),f.width=i.width,f.height=i.height,f.type=i.textureType,s=i.width}h.setCubeMapTextureParams(u,r),f.isReady=!0,o&&o({isDDS:!0,width:s,info:i,imgs:t,texture:f})}),r,a):this._loadFile(t,(function(t){var i=e.DDSTools.GetDDSInfo(t),r=(i.isRGB||i.isLuminance||i.mipmapCount>1)&&!n;h._bindTextureDirectly(u.TEXTURE_CUBE_MAP,f,!0),u.pixelStorei(u.UNPACK_FLIP_Y_WEBGL,i.isCompressed?1:0),e.DDSTools.UploadDDSLevels(h,h._gl,t,i,r,6),n||i.isFourCC||1!==i.mipmapCount||u.generateMipmap(u.TEXTURE_CUBE_MAP),h.setCubeMapTextureParams(u,r),f.width=i.width,f.height=i.height,f.isReady=!0,f.type=i.textureType,o&&o({isDDS:!0,width:i.width,info:i,data:t,texture:f})}),void 0,void 0,!0,g);else{if(!r)throw new Error("Cannot load cubemap because files were not defined");s(0,i,(function(t){var i=h.needPOTTextures?e.Tools.GetExponentOfTwo(t[0].width,h._caps.maxCubemapTextureSize):t[0].width,r=i;if(h._prepareWorkingCanvas(),h._workingCanvas&&h._workingContext){h._workingCanvas.width=i,h._workingCanvas.height=r;var s=[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];h._bindTextureDirectly(u.TEXTURE_CUBE_MAP,f,!0),u.pixelStorei(u.UNPACK_FLIP_Y_WEBGL,0);for(var a=l?h._getInternalFormat(l):h._gl.RGBA,c=0;c>y,x=0;x<6;x++){var T=v[y][x];g&&(T=d._convertRGBtoRGBATextureData(T,b,b,o)),p.texImage2D(x,y,m,b,b,0,u,h,T)}d._bindTextureDirectly(p.TEXTURE_CUBE_MAP,null)}else _.generateMipMaps=!s,d.updateRawCubeTexture(_,r,n,o,f);_.isReady=!0,i._removePendingData(_),c&&c()}};return this._loadFile(t,(function(e){g(e)}),void 0,i.database,!0,m),_},o.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},o.prototype.createRawTexture3D=function(t,i,r,o,s,a,l,c,h){void 0===h&&(h=null);var u=new e.InternalTexture(this,e.InternalTexture.DATASOURCE_RAW3D);u.baseWidth=i,u.baseHeight=r,u.baseDepth=o,u.width=i,u.height=r,u.depth=o,u.format=s,u.generateMipMaps=a,u.samplingMode=c,u.is3D=!0,this._doNotHandleContextLost||(u._bufferView=t),this.updateRawTexture3D(u,t,s,l,h),this._bindTextureDirectly(this._gl.TEXTURE_3D,u,!0);var f=n(c,a,this._gl);return this._gl.texParameteri(this._gl.TEXTURE_3D,this._gl.TEXTURE_MAG_FILTER,f.mag),this._gl.texParameteri(this._gl.TEXTURE_3D,this._gl.TEXTURE_MIN_FILTER,f.min),a&&this._gl.generateMipmap(this._gl.TEXTURE_3D),this._bindTextureDirectly(this._gl.TEXTURE_3D,null),this._internalTexturesCache.push(u),u},o.prototype._prepareWebGLTextureContinuation=function(e,t,i,r,o){var s=this._gl;if(s){var a=n(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||r||s.generateMipmap(s.TEXTURE_2D),this._bindTextureDirectly(s.TEXTURE_2D,null),t&&t._removePendingData(e),e.onLoadedObservable.notifyObservers(e),e.onLoadedObservable.clear()}},o.prototype._prepareWebGLTexture=function(t,i,r,n,o,s,a,l,c){var h=this;void 0===c&&(c=e.Texture.TRILINEAR_SAMPLINGMODE);var u=this.needPOTTextures?e.Tools.GetExponentOfTwo(r,this.getCaps().maxTextureSize):r,f=this.needPOTTextures?e.Tools.GetExponentOfTwo(n,this.getCaps().maxTextureSize):n,d=this._gl;if(d){if(!t._webGLTexture)return void(i&&i._removePendingData(t));this._bindTextureDirectly(d.TEXTURE_2D,t,!0),d.pixelStorei(d.UNPACK_FLIP_Y_WEBGL,void 0===o?1:o?1:0),t.baseWidth=r,t.baseHeight=n,t.width=u,t.height=f,t.isReady=!0,l(u,f,(function(){h._prepareWebGLTextureContinuation(t,i,s,a,c)}))||this._prepareWebGLTextureContinuation(t,i,s,a,c)}},o.prototype._convertRGBtoRGBATextureData=function(e,t,i,r){var n;n=r===o.TEXTURETYPE_FLOAT?new Float32Array(t*i*4):new Uint32Array(t*i*4);for(var s=0;s-1?t._designatedSlot:this._nextFreeTextureSlots.length?this._nextFreeTextureSlots[0]:(this._textureCollisions.addCount(1,!1),this._removeDesignatedSlot(this._firstBoundInternalTextureTracker.next));return e},o.prototype._linkTrackers=function(e,t){e.next=t,t.previous=e},o.prototype._removeDesignatedSlot=function(e){var t=e._designatedSlot;return-1===t?-1:(e._designatedSlot=-1,this.disableTextureBindingOptimization?-1:(this._linkTrackers(e.previous,e.next),this._boundTexturesCache[t]=null,this._nextFreeTextureSlots.push(t),t))},o.prototype._activateCurrentTexture=function(){this._currentTextureChannel!==this._activeChannel&&(this._gl.activeTexture(this._gl.TEXTURE0+this._activeChannel),this._currentTextureChannel=this._activeChannel)},o.prototype._bindTextureDirectly=function(e,t,i){void 0===i&&(i=!1),i&&t&&t._designatedSlot>-1&&(this._activeChannel=t._designatedSlot);var r=this._boundTexturesCache[this._activeChannel],n=t&&t._initialSlot>-1;if(r!==t){if(r&&this._removeDesignatedSlot(r),this._activateCurrentTexture(),this._gl.bindTexture(e,t?t._webGLTexture:null),this._boundTexturesCache[this._activeChannel]=t,t){if(!this.disableTextureBindingOptimization){ var o=this._nextFreeTextureSlots.indexOf(this._activeChannel);o>-1&&this._nextFreeTextureSlots.splice(o,1),this._linkTrackers(this._lastBoundInternalTextureTracker.previous,t),this._linkTrackers(t,this._lastBoundInternalTextureTracker)}t._designatedSlot=this._activeChannel}}else i&&this._activateCurrentTexture();n&&!i&&this._bindSamplerUniformToChannel(t._initialSlot,this._activeChannel)},o.prototype._bindTexture=function(e,t){e<0||(t&&(e=this._getCorrectTextureChannel(e,t)),this._activeChannel=e,this._bindTextureDirectly(this._gl.TEXTURE_2D,t))},o.prototype.setTextureFromPostProcess=function(e,t){this._bindTexture(e,t?t._textures.data[t._currentRenderTextureInd]:null)},o.prototype.unbindAllTextures=function(){for(var e=0;e1&&this._bindTextureDirectly(this._gl.TEXTURE_3D,null)},o.prototype.setTexture=function(e,t,i){e<0||(t&&(this._boundUniforms[e]=t),this._setTexture(e,i))},o.prototype._bindSamplerUniformToChannel=function(e,t){var i=this._boundUniforms[e];i._currentState!==t&&(this._gl.uniform1i(i,t),i._currentState=t)},o.prototype._setTexture=function(t,i,r){if(void 0===r&&(r=!1),!i)return null!=this._boundTexturesCache[t]&&(this._activeChannel=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;if(i.video)this._activeChannel=t,i.update();else if(i.delayLoadState===o.DELAYLOADSTATE_NOTLOADED)return i.delayLoad(),!1;var n;if(n=i.isReady()?i.getInternalTexture():i.isCube?this.emptyCubeTexture:i.is3D?this.emptyTexture3D:this.emptyTexture,r||(t=this._getCorrectTextureChannel(t,n)),this._boundTexturesCache[t]===n)return this._moveBoundTextureOnTop(n),r||this._bindSamplerUniformToChannel(n._initialSlot,t),!1;if(this._activeChannel=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.wrapR){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 s=i.coordinatesMode!==e.Texture.CUBIC_MODE&&i.coordinatesMode!==e.Texture.SKYBOX_MODE?this._gl.REPEAT:this._gl.CLAMP_TO_EDGE;this._gl.texParameteri(this._gl.TEXTURE_CUBE_MAP,this._gl.TEXTURE_WRAP_S,s),this._gl.texParameteri(this._gl.TEXTURE_CUBE_MAP,this._gl.TEXTURE_WRAP_T,s)}this._setAnisotropicLevel(this._gl.TEXTURE_CUBE_MAP,i)}else{if(this._bindTextureDirectly(this._gl.TEXTURE_2D,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},o.prototype.setTextureArray=function(e,t,i){if(!(e<0)&&t){this._textureUnits&&this._textureUnits.length===i.length||(this._textureUnits=new Int32Array(i.length));for(var r=0;r=this._caps.maxVertexAttribs||!this._vertexAttribArraysEnabled[e]||(this._gl.disableVertexAttribArray(e),this._vertexAttribArraysEnabled[e]=!1,this._currentBufferPointers[e].active=!1)},o.prototype.releaseEffects=function(){for(var e in this._compiledEffects)this._deleteProgram(this._compiledEffects[e]._program);this._compiledEffects={}},o.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();o.audioEngine&&o.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=o.Instances.indexOf(this);t>=0&&o.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-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},o.prototype._canRenderToFloatFramebuffer=function(){return this._webGLVersion>1?this._caps.colorBufferFloat:this._canRenderToFramebuffer(o.TEXTURETYPE_FLOAT)},o.prototype._canRenderToHalfFloatFramebuffer=function(){return this._webGLVersion>1?this._caps.colorBufferFloat:this._canRenderToFramebuffer(o.TEXTURETYPE_HALF_FLOAT)},o.prototype._canRenderToFramebuffer=function(e){for(var t=this._gl;t.getError()!==t.NO_ERROR;);var i=!0,r=t.createTexture();t.bindTexture(t.TEXTURE_2D,r),t.texImage2D(t.TEXTURE_2D,0,this._getRGBABufferInternalSizedFormat(e),1,1,0,t.RGBA,this._getWebGLTextureType(e),null),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST);var n=t.createFramebuffer();t.bindFramebuffer(t.FRAMEBUFFER,n),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,r,0);var o=t.checkFramebufferStatus(t.FRAMEBUFFER);if(i=i&&o===t.FRAMEBUFFER_COMPLETE,i=i&&t.getError()===t.NO_ERROR,i&&(t.clear(t.COLOR_BUFFER_BIT),i=i&&t.getError()===t.NO_ERROR),i){t.bindFramebuffer(t.FRAMEBUFFER,null);var s=t.RGBA,a=t.UNSIGNED_BYTE,l=new Uint8Array(4);t.readPixels(0,0,1,1,s,a,l),i=i&&t.getError()===t.NO_ERROR}for(t.deleteTexture(r),t.deleteFramebuffer(n),t.bindFramebuffer(t.FRAMEBUFFER,null);!i&&t.getError()!==t.NO_ERROR;);return i},o.prototype._getWebGLTextureType=function(e){return e===o.TEXTURETYPE_FLOAT?this._gl.FLOAT:e===o.TEXTURETYPE_HALF_FLOAT?this._gl.HALF_FLOAT_OES:this._gl.UNSIGNED_BYTE},o.prototype._getRGBABufferInternalSizedFormat=function(e,t){if(1===this._webGLVersion)return this._gl.RGBA;if(e===o.TEXTURETYPE_FLOAT){if(t)switch(t){case o.TEXTUREFORMAT_R32F:return this._gl.R32F;case o.TEXTUREFORMAT_RG32F:return this._gl.RG32F;case o.TEXTUREFORMAT_RGB32F:return this._gl.RGB32F}return this._gl.RGBA32F}return e===o.TEXTURETYPE_HALF_FLOAT?this._gl.RGBA16F:this._gl.RGBA},o.prototype._getRGBAMultiSampleBufferFormat=function(e){return e===o.TEXTURETYPE_FLOAT?this._gl.RGBA32F:e===o.TEXTURETYPE_HALF_FLOAT?this._gl.RGBA16F:this._gl.RGBA8},o.prototype.createQuery=function(){return this._gl.createQuery()},o.prototype.deleteQuery=function(e){return this._gl.deleteQuery(e),this},o.prototype.isQueryResultAvailable=function(e){return this._gl.getQueryParameter(e,this._gl.QUERY_RESULT_AVAILABLE)},o.prototype.getQueryResult=function(e){return this._gl.getQueryParameter(e,this._gl.QUERY_RESULT)},o.prototype.beginOcclusionQuery=function(e,t){var i=this.getGlAlgorithmType(e);return this._gl.beginQuery(i,t),this},o.prototype.endOcclusionQuery=function(e){var t=this.getGlAlgorithmType(e);return this._gl.endQuery(t),this},o.prototype._createTimeQuery=function(){var e=this._caps.timerQuery;return e.createQueryEXT?e.createQueryEXT():this.createQuery()},o.prototype._deleteTimeQuery=function(e){var t=this._caps.timerQuery;if(t.deleteQueryEXT)return void t.deleteQueryEXT(e);this.deleteQuery(e)},o.prototype._getTimeQueryResult=function(e){var t=this._caps.timerQuery;return t.getQueryObjectEXT?t.getQueryObjectEXT(e,t.QUERY_RESULT_EXT):this.getQueryResult(e)},o.prototype._getTimeQueryAvailability=function(e){var t=this._caps.timerQuery;return t.getQueryObjectEXT?t.getQueryObjectEXT(e,t.QUERY_RESULT_AVAILABLE_EXT):this.isQueryResultAvailable(e)},o.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},o.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},o.prototype.getGlAlgorithmType=function(t){return t===e.AbstractMesh.OCCLUSION_ALGORITHM_TYPE_CONSERVATIVE?this._gl.ANY_SAMPLES_PASSED_CONSERVATIVE:this._gl.ANY_SAMPLES_PASSED},o.prototype.createTransformFeedback=function(){return this._gl.createTransformFeedback()},o.prototype.deleteTransformFeedback=function(e){this._gl.deleteTransformFeedback(e)},o.prototype.bindTransformFeedback=function(e){this._gl.bindTransformFeedback(this._gl.TRANSFORM_FEEDBACK,e)},o.prototype.beginTransformFeedback=function(e){void 0===e&&(e=!0),this._gl.beginTransformFeedback(e?this._gl.POINTS:this._gl.TRIANGLES)},o.prototype.endTransformFeedback=function(){this._gl.endTransformFeedback()},o.prototype.setTranformFeedbackVaryings=function(e,t){this._gl.transformFeedbackVaryings(e,t,this._gl.INTERLEAVED_ATTRIBS)},o.prototype.bindTransformFeedbackBuffer=function(e){this._gl.bindBufferBase(this._gl.TRANSFORM_FEEDBACK_BUFFER,0,e)},o.prototype._loadFile=function(t,i,r,n,o,s){var a=this,l=e.Tools.LoadFile(t,i,r,n,o,s);return this._activeRequests.push(l),l.onCompleteObservable.add((function(e){a._activeRequests.splice(a._activeRequests.indexOf(e),1)})),l},o.prototype._loadFileAsync=function(e,t,i){var r=this;return new Promise(function(n,o){r._loadFile(e,(function(e){n(e)}),void 0,t,i,(function(e,t){o(t)}))})},o.prototype._partialLoadFile=function(e,t,i,r,n,o){void 0===o&&(o=null);var s=function(e){i[t]=e,6===++i._internalCount&&n(i)},a=function(e,t){o&&e&&o(e.status+" "+e.statusText,t)};this._loadFile(e,s,void 0,void 0,!0,a)},o.prototype._cascadeLoadFiles=function(e,t,i,r){void 0===r&&(r=null);var n=[];n._internalCount=0;for(var o=0;o<6;o++)this._partialLoadFile(i[o],o,n,e,t,r)},o.isSupported=function(){try{var e=document.createElement("canvas");return null!=(e.getContext("webgl")||e.getContext("experimental-webgl"))&&!!window.WebGLRenderingContext}catch(e){return!1}},o.ExceptionList=[{key:"Chrome/63.0",capture:"63\\.0\\.3239\\.(\\d+)",captureConstraint:108,targets:["uniformBuffer"]},{key:"Firefox/58",capture:null,captureConstraint:null,targets:["uniformBuffer"]},{key:"Firefox/59",capture:null,captureConstraint:null,targets:["uniformBuffer"]},{key:"Macintosh",capture:null,captureConstraint:null,targets:["textureBindingOptimization"]},{key:"iPhone",capture:null,captureConstraint:null,targets:["textureBindingOptimization"]},{key:"iPad",capture:null,captureConstraint:null,targets:["textureBindingOptimization"]}],o.Instances=new Array,o._ALPHA_DISABLE=0,o._ALPHA_ADD=1,o._ALPHA_COMBINE=2,o._ALPHA_SUBTRACT=3,o._ALPHA_MULTIPLY=4,o._ALPHA_MAXIMIZED=5,o._ALPHA_ONEONE=6,o._ALPHA_PREMULTIPLIED=7,o._ALPHA_PREMULTIPLIED_PORTERDUFF=8,o._ALPHA_INTERPOLATE=9,o._ALPHA_SCREENMODE=10,o._DELAYLOADSTATE_NONE=0,o._DELAYLOADSTATE_LOADED=1,o._DELAYLOADSTATE_LOADING=2,o._DELAYLOADSTATE_NOTLOADED=4,o._TEXTUREFORMAT_ALPHA=0,o._TEXTUREFORMAT_LUMINANCE=1,o._TEXTUREFORMAT_LUMINANCE_ALPHA=2,o._TEXTUREFORMAT_RGB=4,o._TEXTUREFORMAT_RGBA=5,o._TEXTUREFORMAT_R32F=6,o._TEXTUREFORMAT_RG32F=7,o._TEXTUREFORMAT_RGB32F=8,o._TEXTUREFORMAT_RGBA32F=9,o._TEXTURETYPE_UNSIGNED_INT=0,o._TEXTURETYPE_FLOAT=1,o._TEXTURETYPE_HALF_FLOAT=2,o._NEVER=512,o._ALWAYS=519,o._LESS=513,o._EQUAL=514,o._LEQUAL=515,o._GREATER=516,o._GEQUAL=518,o._NOTEQUAL=517,o._KEEP=7680,o._REPLACE=7681,o._INCR=7682,o._DECR=7683,o._INVERT=5386,o._INCR_WRAP=34055,o._DECR_WRAP=34056,o._SCALEMODE_FLOOR=1,o._SCALEMODE_NEAREST=2,o._SCALEMODE_CEILING=3,o.CollisionsEpsilon=.001,o.CodeRepository="src/",o.ShadersRepository="src/Shaders/",o})();e.Engine=f})(e||(e={}));var e;!(function(e){var t=(function(){function t(t,i){void 0===i&&(i=null),this.state="",this.metadata=null,this.doNotSerialize=!1,this._isDisposed=!1,this.animations=new Array,this._ranges={},this._isEnabled=!0,this._isReady=!0,this._currentRenderId=-1,this._parentRenderId=-1,this._animationPropertiesOverride=null,this.onDisposeObservable=new e.Observable,this._behaviors=new Array,this.name=t,this.id=t,this._scene=i||e.Engine.LastCreatedScene,this.uniqueId=this._scene.getUniqueId(),this._initCache()}return t.prototype.isDisposed=function(){return this._isDisposed},Object.defineProperty(t.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}),Object.defineProperty(t.prototype,"animationPropertiesOverride",{get:function(){return this._animationPropertiesOverride},set:function(e){this._animationPropertiesOverride=e},enumerable:!0,configurable:!0}),t.prototype.getClassName=function(){return"Node"},Object.defineProperty(t.prototype,"onDispose",{set:function(e){this._onDisposeObserver&&this.onDisposeObservable.remove(this._onDisposeObserver),this._onDisposeObserver=this.onDisposeObservable.add(e)},enumerable:!0,configurable:!0}),t.prototype.getScene=function(){return this._scene},t.prototype.getEngine=function(){return this._scene.getEngine()},t.prototype.addBehavior=function(e){var t=this;if(-1!==this._behaviors.indexOf(e))return this;if(e.init(),this._scene.isLoading)var i=this._scene.onDataLoadedObservable.add((function(){e.attach(t),setTimeout((function(){t._scene.onDataLoadedObservable.remove(i)}),0)}));else e.attach(this);return this._behaviors.push(e),this},t.prototype.removeBehavior=function(e){var t=this._behaviors.indexOf(e);return-1===t?this:(this._behaviors[t].detach(),this._behaviors.splice(t,1),this)},Object.defineProperty(t.prototype,"behaviors",{get:function(){return this._behaviors},enumerable:!0,configurable:!0}),t.prototype.getBehaviorByName=function(e){for(var t=0,i=this._behaviors;tthis.maximumWorld.x&&(this.maximumWorld.x=r.x),r.y>this.maximumWorld.y&&(this.maximumWorld.y=r.y),r.z>this.maximumWorld.z&&(this.maximumWorld.z=r.z)}this.maximumWorld.subtractToRef(this.minimumWorld,this.extendSizeWorld),this.extendSizeWorld.scaleInPlace(.5),this.maximumWorld.addToRef(this.minimumWorld,this.centerWorld),this.centerWorld.scaleInPlace(.5),e.Vector3.FromFloatArrayToRef(t.m,0,this.directions[0]),e.Vector3.FromFloatArrayToRef(t.m,4,this.directions[1]),e.Vector3.FromFloatArrayToRef(t.m,8,this.directions[2]),this._worldMatrix=t},t.prototype.isInFrustum=function(e){return t.IsInFrustum(this.vectorsWorld,e)},t.prototype.isCompletelyInFrustum=function(e){return t.IsCompletelyInFrustum(this.vectorsWorld,e)},t.prototype.intersectsPoint=function(t){var i=-e.Epsilon;return!(this.maximumWorld.x-t.xt.x-this.minimumWorld.x)&&(!(this.maximumWorld.y-t.yt.y-this.minimumWorld.y)&&!(this.maximumWorld.z-t.zt.z-this.minimumWorld.z))},t.prototype.intersectsSphere=function(e){return t.IntersectsSphere(this.minimumWorld,this.maximumWorld,e.centerWorld,e.radiusWorld)},t.prototype.intersectsMinMax=function(e,t){return!(this.maximumWorld.xt.x)&&(!(this.maximumWorld.yt.y)&&!(this.maximumWorld.zt.z))},t.Intersects=function(e,t){ return!(e.maximumWorld.xt.maximumWorld.x)&&(!(e.maximumWorld.yt.maximumWorld.y)&&!(e.maximumWorld.zt.maximumWorld.z))},t.IntersectsSphere=function(t,i,r,n){var o=e.Vector3.Clamp(r,t,i);return e.Vector3.DistanceSquared(r,o)<=n*n},t.IsCompletelyInFrustum=function(e,t){for(var i=0;i<6;i++)for(var r=0;r<8;r++)if(t[i].dotCoordinate(e[r])<0)return!1;return!0},t.IsInFrustum=function(e,t){for(var i=0;i<6;i++){for(var r=8,n=0;n<8&&t[i].dotCoordinate(e[n])<0;n++)--r;if(0===r)return!1}return!0},t})();e.BoundingBox=t})(e||(e={}));var e;!(function(e){var t=function(t,i){var r=e.Vector3.Dot(i.centerWorld,t),n=Math.abs(e.Vector3.Dot(i.directions[0],t))*i.extendSize.x,o=Math.abs(e.Vector3.Dot(i.directions[1],t))*i.extendSize.y,s=Math.abs(e.Vector3.Dot(i.directions[2],t))*i.extendSize.z,a=n+o+s;return{min:r-a,max:r+a}},i=function(e,t,i,r){return!(e>r||i>t)},r=function(e,r,n){var o=t(e,r),s=t(e,n);return i(o.min,o.max,s.min,s.max)},n=(function(){function t(t,i){this.minimum=t,this.maximum=i,this._isLocked=!1,this.boundingBox=new e.BoundingBox(t,i),this.boundingSphere=new e.BoundingSphere(t,i)}return Object.defineProperty(t.prototype,"isLocked",{get:function(){return this._isLocked},set:function(e){this._isLocked=e},enumerable:!0,configurable:!0}),t.prototype.update=function(e){this._isLocked||(this.boundingBox._update(e),this.boundingSphere._update(e))},t.prototype.centerOn=function(t,i){return this.minimum=t.subtract(i),this.maximum=t.add(i),this.boundingBox=new e.BoundingBox(this.minimum,this.maximum),this.boundingSphere=new e.BoundingSphere(this.minimum,this.maximum),this},t.prototype.isInFrustum=function(e){return!!this.boundingSphere.isInFrustum(e)&&this.boundingBox.isInFrustum(e)},Object.defineProperty(t.prototype,"diagonalLength",{get:function(){var e=this.boundingBox;return e.maximumWorld.subtract(e.minimumWorld).length()},enumerable:!0,configurable:!0}),t.prototype.isCompletelyInFrustum=function(e){return this.boundingBox.isCompletelyInFrustum(e)},t.prototype._checkCollision=function(e){return e._canDoCollision(this.boundingSphere.centerWorld,this.boundingSphere.radiusWorld,this.boundingBox.minimumWorld,this.boundingBox.maximumWorld)},t.prototype.intersectsPoint=function(e){return!!this.boundingSphere.centerWorld&&(!!this.boundingSphere.intersectsPoint(e)&&!!this.boundingBox.intersectsPoint(e))},t.prototype.intersects=function(t,i){if(!this.boundingSphere.centerWorld||!t.boundingSphere.centerWorld)return!1;if(!e.BoundingSphere.Intersects(this.boundingSphere,t.boundingSphere))return!1;if(!e.BoundingBox.Intersects(this.boundingBox,t.boundingBox))return!1;if(!i)return!0;var n=this.boundingBox,o=t.boundingBox;return!!r(n.directions[0],n,o)&&(!!r(n.directions[1],n,o)&&(!!r(n.directions[2],n,o)&&(!!r(o.directions[0],n,o)&&(!!r(o.directions[1],n,o)&&(!!r(o.directions[2],n,o)&&(!!r(e.Vector3.Cross(n.directions[0],o.directions[0]),n,o)&&(!!r(e.Vector3.Cross(n.directions[0],o.directions[1]),n,o)&&(!!r(e.Vector3.Cross(n.directions[0],o.directions[2]),n,o)&&(!!r(e.Vector3.Cross(n.directions[1],o.directions[0]),n,o)&&(!!r(e.Vector3.Cross(n.directions[1],o.directions[1]),n,o)&&(!!r(e.Vector3.Cross(n.directions[1],o.directions[2]),n,o)&&(!!r(e.Vector3.Cross(n.directions[2],o.directions[0]),n,o)&&(!!r(e.Vector3.Cross(n.directions[2],o.directions[1]),n,o)&&!!r(e.Vector3.Cross(n.directions[2],o.directions[2]),n,o))))))))))))))},t})();e.BoundingInfo=n})(e||(e={}));var e;!(function(e){var t=(function(t){function i(i,r,n){void 0===r&&(r=null),void 0===n&&(n=!0);var o=t.call(this,i,r)||this;return o._rotation=e.Vector3.Zero(),o._scaling=e.Vector3.One(),o._isDirty=!1,o.billboardMode=e.AbstractMesh.BILLBOARDMODE_NONE,o.scalingDeterminant=1,o.infiniteDistance=!1,o.position=e.Vector3.Zero(),o._localWorld=e.Matrix.Zero(),o._worldMatrix=e.Matrix.Zero(),o._worldMatrixDeterminant=0,o._absolutePosition=e.Vector3.Zero(),o._pivotMatrix=e.Matrix.Identity(),o._postMultiplyPivotMatrix=!1,o._isWorldMatrixFrozen=!1,o.onAfterWorldMatrixUpdateObservable=new e.Observable,o._nonUniformScaling=!1,n&&o.getScene().addTransformNode(o),o}return __extends(i,t),i.prototype.getClassName=function(){return"TransformNode"},Object.defineProperty(i.prototype,"rotation",{get:function(){return this._rotation},set:function(e){this._rotation=e},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"scaling",{get:function(){return this._scaling},set:function(e){this._scaling=e},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"rotationQuaternion",{get:function(){return this._rotationQuaternion},set:function(e){this._rotationQuaternion=e,e&&this.rotation.length()&&this.rotation.copyFromFloats(0,0,0)},enumerable:!0,configurable:!0}),i.prototype.getWorldMatrix=function(){return this._currentRenderId!==this.getScene().getRenderId()&&this.computeWorldMatrix(),this._worldMatrix},i.prototype._getWorldMatrixDeterminant=function(){return this._worldMatrixDeterminant},Object.defineProperty(i.prototype,"worldMatrixFromCache",{get:function(){return this._worldMatrix},enumerable:!0,configurable:!0}),i.prototype.updatePoseMatrix=function(e){return this._poseMatrix.copyFrom(e),this},i.prototype.getPoseMatrix=function(){return this._poseMatrix},i.prototype._isSynchronized=function(){return!this._isDirty&&(this.billboardMode===this._cache.billboardMode&&this.billboardMode===e.AbstractMesh.BILLBOARDMODE_NONE&&(!this._cache.pivotMatrixUpdated&&(!this.infiniteDistance&&(!!this._cache.position.equals(this.position)&&(!(this.rotationQuaternion&&!this._cache.rotationQuaternion.equals(this.rotationQuaternion))&&(!!this._cache.rotation.equals(this.rotation)&&!!this._cache.scaling.equals(this.scaling)))))))},i.prototype._initCache=function(){t.prototype._initCache.call(this),this._cache.localMatrixUpdated=!1,this._cache.position=e.Vector3.Zero(),this._cache.scaling=e.Vector3.Zero(),this._cache.rotation=e.Vector3.Zero(),this._cache.rotationQuaternion=new e.Quaternion(0,0,0,0),this._cache.billboardMode=-1},i.prototype.markAsDirty=function(e){return"rotation"===e&&(this.rotationQuaternion=null),this._currentRenderId=Number.MAX_VALUE,this._isDirty=!0,this},Object.defineProperty(i.prototype,"absolutePosition",{get:function(){return this._absolutePosition},enumerable:!0,configurable:!0}),i.prototype.setPreTransformMatrix=function(e){return this.setPivotMatrix(e,!1)},i.prototype.setPivotMatrix=function(t,i){return void 0===i&&(i=!0),this._pivotMatrix=t.clone(),this._cache.pivotMatrixUpdated=!0,this._postMultiplyPivotMatrix=i,this._postMultiplyPivotMatrix&&(this._pivotMatrixInverse?this._pivotMatrix.invertToRef(this._pivotMatrixInverse):this._pivotMatrixInverse=e.Matrix.Invert(this._pivotMatrix)),this},i.prototype.getPivotMatrix=function(){return this._pivotMatrix},i.prototype.freezeWorldMatrix=function(){return this._isWorldMatrixFrozen=!1,this.computeWorldMatrix(!0),this._isWorldMatrixFrozen=!0,this},i.prototype.unfreezeWorldMatrix=function(){return this._isWorldMatrixFrozen=!1,this.computeWorldMatrix(!0),this},Object.defineProperty(i.prototype,"isWorldMatrixFrozen",{get:function(){return this._isWorldMatrixFrozen},enumerable:!0,configurable:!0}),i.prototype.getAbsolutePosition=function(){return this.computeWorldMatrix(),this._absolutePosition},i.prototype.setAbsolutePosition=function(t){if(!t)return this;var i,r,n;if(void 0===t.x){if(arguments.length<3)return this;i=arguments[0],r=arguments[1],n=arguments[2]}else i=t.x,r=t.y,n=t.z;if(this.parent){var o=this.parent.getWorldMatrix().clone();o.invert();var s=new e.Vector3(i,r,n);this.position=e.Vector3.TransformCoordinates(s,o)}else this.position.x=i,this.position.y=r,this.position.z=n;return this},i.prototype.setPositionWithLocalVector=function(t){return this.computeWorldMatrix(),this.position=e.Vector3.TransformNormal(t,this._localWorld),this},i.prototype.getPositionExpressedInLocalSpace=function(){this.computeWorldMatrix();var t=this._localWorld.clone();return t.invert(),e.Vector3.TransformNormal(this.position,t)},i.prototype.locallyTranslate=function(t){return this.computeWorldMatrix(!0),this.position=e.Vector3.TransformCoordinates(t,this._localWorld),this},i.prototype.lookAt=function(t,i,r,n,o){void 0===i&&(i=0),void 0===r&&(r=0),void 0===n&&(n=0),void 0===o&&(o=e.Space.LOCAL);var s=e.AbstractMesh._lookAtVectorCache,a=o===e.Space.LOCAL?this.position:this.getAbsolutePosition();t.subtractToRef(a,s);var l=-Math.atan2(s.z,s.x)-Math.PI/2,c=Math.sqrt(s.x*s.x+s.z*s.z),h=Math.atan2(s.y,c);return this.rotationQuaternion?e.Quaternion.RotationYawPitchRollToRef(l+i,h+r,n,this.rotationQuaternion):(this.rotation.x=h+r,this.rotation.y=l+i,this.rotation.z=n),this},i.prototype.getDirection=function(t){var i=e.Vector3.Zero();return this.getDirectionToRef(t,i),i},i.prototype.getDirectionToRef=function(t,i){return e.Vector3.TransformNormalToRef(t,this.getWorldMatrix(),i),this},i.prototype.setPivotPoint=function(t,i){void 0===i&&(i=e.Space.LOCAL),0==this.getScene().getRenderId()&&this.computeWorldMatrix(!0);var r=this.getWorldMatrix();if(i==e.Space.WORLD){var n=e.Tmp.Matrix[0];r.invertToRef(n),t=e.Vector3.TransformCoordinates(t,n)}return this.setPivotMatrix(e.Matrix.Translation(-t.x,-t.y,-t.z),!0)},i.prototype.getPivotPoint=function(){var t=e.Vector3.Zero();return this.getPivotPointToRef(t),t},i.prototype.getPivotPointToRef=function(e){return e.x=-this._pivotMatrix.m[12],e.y=-this._pivotMatrix.m[13],e.z=-this._pivotMatrix.m[14],this},i.prototype.getAbsolutePivotPoint=function(){var t=e.Vector3.Zero();return this.getAbsolutePivotPointToRef(t),t},i.prototype.getAbsolutePivotPointToRef=function(t){return t.x=this._pivotMatrix.m[12],t.y=this._pivotMatrix.m[13],t.z=this._pivotMatrix.m[14],this.getPivotPointToRef(t),e.Vector3.TransformCoordinatesToRef(t,this.getWorldMatrix(),t),this},i.prototype.setParent=function(t){if(null===t){var i=e.Tmp.Quaternion[0],r=e.Tmp.Vector3[0],n=e.Tmp.Vector3[1];this.parent&&this.parent.computeWorldMatrix&&this.parent.computeWorldMatrix(!0),this.computeWorldMatrix(!0),this.getWorldMatrix().decompose(n,i,r),this.rotationQuaternion?this.rotationQuaternion.copyFrom(i):i.toEulerAnglesToRef(this.rotation),this.scaling.x=n.x,this.scaling.y=n.y,this.scaling.z=n.z,this.position.x=r.x,this.position.y=r.y,this.position.z=r.z}else{var i=e.Tmp.Quaternion[0],r=e.Tmp.Vector3[0],n=e.Tmp.Vector3[1],o=e.Tmp.Matrix[0],s=e.Tmp.Matrix[1];this.computeWorldMatrix(!0),t.computeWorldMatrix(!0),t.getWorldMatrix().invertToRef(s),this.getWorldMatrix().multiplyToRef(s,o),o.decompose(n,i,r),this.rotationQuaternion?this.rotationQuaternion.copyFrom(i):i.toEulerAnglesToRef(this.rotation),this.position.x=r.x,this.position.y=r.y,this.position.z=r.z,this.scaling.x=n.x,this.scaling.y=n.y,this.scaling.z=n.z}return this.parent=t,this},Object.defineProperty(i.prototype,"nonUniformScaling",{get:function(){return this._nonUniformScaling},enumerable:!0,configurable:!0}),i.prototype._updateNonUniformScalingState=function(e){return this._nonUniformScaling!==e&&(this._nonUniformScaling=!0,!0)},i.prototype.attachToBone=function(e,t){return this._transformToBoneReferal=t,this.parent=e,e.getWorldMatrix().determinant()<0&&(this.scalingDeterminant*=-1),this},i.prototype.detachFromBone=function(){return this.parent?(this.parent.getWorldMatrix().determinant()<0&&(this.scalingDeterminant*=-1),this._transformToBoneReferal=null,this.parent=null,this):this},i.prototype.rotate=function(t,i,r){t.normalize(),this.rotationQuaternion||(this.rotationQuaternion=e.Quaternion.RotationYawPitchRoll(this.rotation.y,this.rotation.x,this.rotation.z),this.rotation=e.Vector3.Zero());var n;if(r&&r!==e.Space.LOCAL){if(this.parent){var o=this.parent.getWorldMatrix().clone();o.invert(),t=e.Vector3.TransformNormal(t,o)}n=e.Quaternion.RotationAxisToRef(t,i,e.AbstractMesh._rotationAxisCache),n.multiplyToRef(this.rotationQuaternion,this.rotationQuaternion)}else n=e.Quaternion.RotationAxisToRef(t,i,e.AbstractMesh._rotationAxisCache),this.rotationQuaternion.multiplyToRef(n,this.rotationQuaternion);return this},i.prototype.rotateAround=function(t,i,r){return i.normalize(),this.rotationQuaternion||(this.rotationQuaternion=e.Quaternion.RotationYawPitchRoll(this.rotation.y,this.rotation.x,this.rotation.z),this.rotation.copyFromFloats(0,0,0)),t.subtractToRef(this.position,e.Tmp.Vector3[0]),e.Matrix.TranslationToRef(e.Tmp.Vector3[0].x,e.Tmp.Vector3[0].y,e.Tmp.Vector3[0].z,e.Tmp.Matrix[0]),e.Tmp.Matrix[0].invertToRef(e.Tmp.Matrix[2]),e.Matrix.RotationAxisToRef(i,r,e.Tmp.Matrix[1]),e.Tmp.Matrix[2].multiplyToRef(e.Tmp.Matrix[1],e.Tmp.Matrix[2]),e.Tmp.Matrix[2].multiplyToRef(e.Tmp.Matrix[0],e.Tmp.Matrix[2]),e.Tmp.Matrix[2].decompose(e.Tmp.Vector3[0],e.Tmp.Quaternion[0],e.Tmp.Vector3[1]),this.position.addInPlace(e.Tmp.Vector3[1]),e.Tmp.Quaternion[0].multiplyToRef(this.rotationQuaternion,this.rotationQuaternion),this},i.prototype.translate=function(t,i,r){var n=t.scale(i);if(r&&r!==e.Space.LOCAL)this.setAbsolutePosition(this.getAbsolutePosition().add(n));else{var o=this.getPositionExpressedInLocalSpace().add(n);this.setPositionWithLocalVector(o)}return this},i.prototype.addRotation=function(t,i,r){var n;this.rotationQuaternion?n=this.rotationQuaternion:(n=e.Tmp.Quaternion[1],e.Quaternion.RotationYawPitchRollToRef(this.rotation.y,this.rotation.x,this.rotation.z,n));var o=e.Tmp.Quaternion[0];return e.Quaternion.RotationYawPitchRollToRef(i,t,r,o),n.multiplyInPlace(o),this.rotationQuaternion||n.toEulerAnglesToRef(this.rotation),this},i.prototype.computeWorldMatrix=function(t){if(this._isWorldMatrixFrozen)return this._worldMatrix;if(!t&&this.isSynchronized(!0))return this._worldMatrix;if(this._cache.position.copyFrom(this.position),this._cache.scaling.copyFrom(this.scaling),this._cache.pivotMatrixUpdated=!1,this._cache.billboardMode=this.billboardMode,this._currentRenderId=this.getScene().getRenderId(),this._isDirty=!1,e.Matrix.ScalingToRef(this.scaling.x*this.scalingDeterminant,this.scaling.y*this.scalingDeterminant,this.scaling.z*this.scalingDeterminant,e.Tmp.Matrix[1]),this.rotationQuaternion){this.rotation.length()&&(this.rotationQuaternion.multiplyInPlace(e.Quaternion.RotationYawPitchRoll(this.rotation.y,this.rotation.x,this.rotation.z)),this.rotation.copyFromFloats(0,0,0))}this.rotationQuaternion?(this.rotationQuaternion.toRotationMatrix(e.Tmp.Matrix[0]),this._cache.rotationQuaternion.copyFrom(this.rotationQuaternion)):(e.Matrix.RotationYawPitchRollToRef(this.rotation.y,this.rotation.x,this.rotation.z,e.Tmp.Matrix[0]),this._cache.rotation.copyFrom(this.rotation));var i=this.getScene().activeCamera;if(this.infiniteDistance&&!this.parent&&i){var r=i.getWorldMatrix(),n=new e.Vector3(r.m[12],r.m[13],r.m[14]);e.Matrix.TranslationToRef(this.position.x+n.x,this.position.y+n.y,this.position.z+n.z,e.Tmp.Matrix[2])}else e.Matrix.TranslationToRef(this.position.x,this.position.y,this.position.z,e.Tmp.Matrix[2]);if(this._pivotMatrix.multiplyToRef(e.Tmp.Matrix[1],e.Tmp.Matrix[4]),e.Tmp.Matrix[4].multiplyToRef(e.Tmp.Matrix[0],e.Tmp.Matrix[5]),this.billboardMode!==e.AbstractMesh.BILLBOARDMODE_NONE&&i){if((this.billboardMode&e.AbstractMesh.BILLBOARDMODE_ALL)!==e.AbstractMesh.BILLBOARDMODE_ALL){var o=e.Tmp.Vector3[3];this.parent&&this.parent.getWorldMatrix?this._transformToBoneReferal?(this.parent.getWorldMatrix().multiplyToRef(this._transformToBoneReferal.getWorldMatrix(),e.Tmp.Matrix[6]),e.Vector3.TransformCoordinatesToRef(this.position,e.Tmp.Matrix[6],o)):e.Vector3.TransformCoordinatesToRef(this.position,this.parent.getWorldMatrix(),o):o.copyFrom(this.position),o.subtractInPlace(i.globalPosition);var s=e.Tmp.Vector3[4].copyFromFloats(0,0,0);(this.billboardMode&e.AbstractMesh.BILLBOARDMODE_X)===e.AbstractMesh.BILLBOARDMODE_X&&(s.x=Math.atan2(-o.y,o.z)),(this.billboardMode&e.AbstractMesh.BILLBOARDMODE_Y)===e.AbstractMesh.BILLBOARDMODE_Y&&(s.y=Math.atan2(o.x,o.z)),(this.billboardMode&e.AbstractMesh.BILLBOARDMODE_Z)===e.AbstractMesh.BILLBOARDMODE_Z&&(s.z=Math.atan2(o.y,o.x)),e.Matrix.RotationYawPitchRollToRef(s.y,s.x,s.z,e.Tmp.Matrix[0])}else e.Tmp.Matrix[1].copyFrom(i.getViewMatrix()),e.Tmp.Matrix[1].setTranslationFromFloats(0,0,0),e.Tmp.Matrix[1].invertToRef(e.Tmp.Matrix[0]);e.Tmp.Matrix[1].copyFrom(e.Tmp.Matrix[5]),e.Tmp.Matrix[1].multiplyToRef(e.Tmp.Matrix[0],e.Tmp.Matrix[5])}return e.Tmp.Matrix[5].multiplyToRef(e.Tmp.Matrix[2],this._localWorld),this.parent&&this.parent.getWorldMatrix?(this.billboardMode!==e.AbstractMesh.BILLBOARDMODE_NONE?(this._transformToBoneReferal?(this.parent.getWorldMatrix().multiplyToRef(this._transformToBoneReferal.getWorldMatrix(),e.Tmp.Matrix[6]),e.Tmp.Matrix[5].copyFrom(e.Tmp.Matrix[6])):e.Tmp.Matrix[5].copyFrom(this.parent.getWorldMatrix()),this._localWorld.getTranslationToRef(e.Tmp.Vector3[5]),e.Vector3.TransformCoordinatesToRef(e.Tmp.Vector3[5],e.Tmp.Matrix[5],e.Tmp.Vector3[5]),this._worldMatrix.copyFrom(this._localWorld),this._worldMatrix.setTranslation(e.Tmp.Vector3[5])):this._transformToBoneReferal?(this._localWorld.multiplyToRef(this.parent.getWorldMatrix(),e.Tmp.Matrix[6]),e.Tmp.Matrix[6].multiplyToRef(this._transformToBoneReferal.getWorldMatrix(),this._worldMatrix)):this._localWorld.multiplyToRef(this.parent.getWorldMatrix(),this._worldMatrix),this._markSyncedWithParent()):this._worldMatrix.copyFrom(this._localWorld),this._postMultiplyPivotMatrix&&this._worldMatrix.multiplyToRef(this._pivotMatrixInverse,this._worldMatrix),this.scaling.isNonUniform?this._updateNonUniformScalingState(!0):this.parent&&this.parent._nonUniformScaling?this._updateNonUniformScalingState(this.parent._nonUniformScaling):this._updateNonUniformScalingState(!1),this._afterComputeWorldMatrix(),this._absolutePosition.copyFromFloats(this._worldMatrix.m[12],this._worldMatrix.m[13],this._worldMatrix.m[14]),this.onAfterWorldMatrixUpdateObservable.notifyObservers(this),this._poseMatrix||(this._poseMatrix=e.Matrix.Invert(this._worldMatrix)),this._worldMatrixDeterminant=this._worldMatrix.determinant(),this._worldMatrix},i.prototype._afterComputeWorldMatrix=function(){},i.prototype.registerAfterWorldMatrixUpdate=function(e){return this.onAfterWorldMatrixUpdateObservable.add(e),this},i.prototype.unregisterAfterWorldMatrixUpdate=function(e){return this.onAfterWorldMatrixUpdateObservable.removeCallback(e),this},i.prototype.clone=function(t,r,n){var o=this,s=e.SerializationHelper.Clone((function(){return new i(t,o.getScene())}),this);if(s.name=t,s.id=t,r&&(s.parent=r),!n)for(var a=this.getDescendants(!0),l=0;le.Engine.CollisionsEpsilon&&o.position.addInPlace(o._diffPositionForCollisions),r&&o.onCollideObservable.notifyObservers(r),o.onCollisionPositionChangeObservable.notifyObservers(o.position)},o.getScene().addMesh(o),o._resyncLightSources(),o}return __extends(i,t),Object.defineProperty(i,"BILLBOARDMODE_NONE",{get:function(){return e.TransformNode.BILLBOARDMODE_NONE},enumerable:!0,configurable:!0}),Object.defineProperty(i,"BILLBOARDMODE_X",{get:function(){return e.TransformNode.BILLBOARDMODE_X},enumerable:!0,configurable:!0}),Object.defineProperty(i,"BILLBOARDMODE_Y",{get:function(){return e.TransformNode.BILLBOARDMODE_Y},enumerable:!0,configurable:!0}),Object.defineProperty(i,"BILLBOARDMODE_Z",{get:function(){return e.TransformNode.BILLBOARDMODE_Z},enumerable:!0,configurable:!0}),Object.defineProperty(i,"BILLBOARDMODE_ALL",{get:function(){return e.TransformNode.BILLBOARDMODE_ALL},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"facetNb",{get:function(){return this._facetNb},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"partitioningSubdivisions",{get:function(){return this._partitioningSubdivisions},set:function(e){this._partitioningSubdivisions=e},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"partitioningBBoxRatio",{get:function(){return this._partitioningBBoxRatio},set:function(e){this._partitioningBBoxRatio=e},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"mustDepthSortFacets",{get:function(){return this._facetDepthSort},set:function(e){this._facetDepthSort=e},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"facetDepthSortFrom",{get:function(){return this._facetDepthSortFrom},set:function(e){this._facetDepthSortFrom=e},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"isFacetDataEnabled",{get:function(){return this._facetDataEnabled},enumerable:!0,configurable:!0}),i.prototype._updateNonUniformScalingState=function(e){return!!t.prototype._updateNonUniformScalingState.call(this,e)&&(this._markSubMeshesAsMiscDirty(),!0)},Object.defineProperty(i.prototype,"onCollide",{set:function(e){this._onCollideObserver&&this.onCollideObservable.remove(this._onCollideObserver),this._onCollideObserver=this.onCollideObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"onCollisionPositionChange",{set:function(e){this._onCollisionPositionChangeObserver&&this.onCollisionPositionChangeObservable.remove(this._onCollisionPositionChangeObserver),this._onCollisionPositionChangeObserver=this.onCollisionPositionChangeObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"isOccluded",{get:function(){return this._isOccluded},set:function(e){this._isOccluded=e},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"isOcclusionQueryInProgress",{get:function(){return this._isOcclusionQueryInProgress},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"visibility",{get:function(){return this._visibility},set:function(e){this._visibility!==e&&(this._visibility=e,this._markSubMeshesAsMiscDirty())},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"material",{get:function(){return this._material},set:function(e){if(this._material!==e&&(this._material=e,this.onMaterialChangedObservable.hasObservers&&this.onMaterialChangedObservable.notifyObservers(this),this.subMeshes))for(var t=0,i=this.subMeshes;t1&&!a._checkCollision(e)||this._collideForSubMesh(a,t,e)}return this},i.prototype._checkCollision=function(t){return this._boundingInfo&&this._boundingInfo._checkCollision(t)?(e.Matrix.ScalingToRef(1/t._radius.x,1/t._radius.y,1/t._radius.z,this._collisionsScalingMatrix),this.worldMatrixFromCache.multiplyToRef(this._collisionsScalingMatrix,this._collisionsTransformMatrix),this._processCollisionsForSubMeshes(t,this._collisionsTransformMatrix),this):this},i.prototype._generatePointsArray=function(){return!1},i.prototype.intersects=function(t,i){var r=new e.PickingInfo;if(!(this.subMeshes&&this._boundingInfo&&t.intersectsSphere(this._boundingInfo.boundingSphere)&&t.intersectsBox(this._boundingInfo.boundingBox)))return r;if(!this._generatePointsArray())return r;var n,o,s=null;if(this._submeshesOctree&&this.useOctreeForPicking){var a=e.Ray.Transform(t,this.getWorldMatrix()),l=this._submeshesOctree.intersectsRay(a);o=l.length,n=l.data}else n=this.subMeshes,o=n.length;for(var c=0;c1)||h.canIntersects(t)){var u=h.intersects(t,this._positions,this.getIndices(),i);if(u&&(i||!s||u.distance65535){o=!0;break}this._depthSortedIndices=o?new Uint32Array(i):new Uint16Array(i)}if(this._facetDepthSortFunction=function(e,t){return t.sqDistance-e.sqDistance},!this._facetDepthSortFrom){var a=this.getScene().activeCamera;this._facetDepthSortFrom=a?a.position:e.Vector3.Zero()}this._depthSortedFacets=[];for(var l=0;le.Epsilon?n.maximum.x-n.minimum.x:e.Epsilon,this._bbSize.y=n.maximum.y-n.minimum.y>e.Epsilon?n.maximum.y-n.minimum.y:e.Epsilon,this._bbSize.z=n.maximum.z-n.minimum.z>e.Epsilon?n.maximum.z-n.minimum.z:e.Epsilon;var h=this._bbSize.x>this._bbSize.y?this._bbSize.x:this._bbSize.y;if(h=h>this._bbSize.z?h:this._bbSize.z,this._subDiv.max=this._partitioningSubdivisions,this._subDiv.X=Math.floor(this._subDiv.max*this._bbSize.x/h),this._subDiv.Y=Math.floor(this._subDiv.max*this._bbSize.y/h),this._subDiv.Z=Math.floor(this._subDiv.max*this._bbSize.z/h),this._subDiv.X=this._subDiv.X<1?1:this._subDiv.X,this._subDiv.Y=this._subDiv.Y<1?1:this._subDiv.Y,this._subDiv.Z=this._subDiv.Z<1?1:this._subDiv.Z,this._facetParameters.facetNormals=this.getFacetLocalNormals(),this._facetParameters.facetPositions=this.getFacetLocalPositions(),this._facetParameters.facetPartitioning=this.getFacetLocalPartitioning(),this._facetParameters.bInfo=n,this._facetParameters.bbSize=this._bbSize,this._facetParameters.subDiv=this._subDiv,this._facetParameters.ratio=this.partitioningBBoxRatio,this._facetParameters.depthSort=this._facetDepthSort,this._facetDepthSort&&this._facetDepthSortEnabled&&(this.computeWorldMatrix(!0),this._worldMatrix.invertToRef(this._invertedMatrix),e.Vector3.TransformCoordinatesToRef(this._facetDepthSortFrom,this._invertedMatrix,this._facetDepthSortOrigin),this._facetParameters.distanceTo=this._facetDepthSortOrigin),this._facetParameters.depthSortedFacets=this._depthSortedFacets,e.VertexData.ComputeNormals(t,i,r,this._facetParameters),this._facetDepthSort&&this._facetDepthSortEnabled){this._depthSortedFacets.sort(this._facetDepthSortFunction);for(var u=this._depthSortedIndices.length/3|0,l=0;lthis._subDiv.max||o<0||o>this._subDiv.max||s<0||s>this._subDiv.max?null:this._facetPartitioning[n+this._subDiv.max*o+this._subDiv.max*this._subDiv.max*s]},i.prototype.getClosestFacetAtCoordinates=function(t,i,r,n,o,s){void 0===o&&(o=!1),void 0===s&&(s=!0);var a=this.getWorldMatrix(),l=e.Tmp.Matrix[5];a.invertToRef(l);var c=e.Tmp.Vector3[8];e.Vector3.TransformCoordinatesFromFloatsToRef(t,i,r,l,c);var h=this.getClosestFacetAtLocalCoordinates(c.x,c.y,c.z,n,o,s);return n&&e.Vector3.TransformCoordinatesFromFloatsToRef(n.x,n.y,n.z,a,n),h},i.prototype.getClosestFacetAtLocalCoordinates=function(e,t,i,r,n,o){void 0===n&&(n=!1),void 0===o&&(o=!0);var s=null,a=0,l=0,c=0,h=0,u=0,f=0,d=0,p=0,_=this.getFacetLocalPositions(),m=this.getFacetLocalNormals(),g=this.getFacetsAtLocalCoordinates(e,t,i);if(!g)return null;for(var v,y,b,x=Number.MAX_VALUE,T=x,E=0;E=0||n&&!o&&h<=0)&&(h=y.x*b.x+y.y*b.y+y.z*b.z,u=-(y.x*e+y.y*t+y.z*i-h)/(y.x*y.x+y.y*y.y+y.z*y.z),f=e+y.x*u,d=t+y.y*u,p=i+y.z*u,a=f-e,l=d-t,c=p-i,(T=a*a+l*l+c*c)this.occlusionRetryCount))return;this._isOcclusionQueryInProgress=!1,this._occlusionInternalRetryCounter=0,this._isOccluded=this.occlusionType!==i.OCCLUSION_TYPE_OPTIMISTIC&&this._isOccluded}}var r=this.getScene(),n=r.getBoundingBoxRenderer();this._occlusionQuery||(this._occlusionQuery=e.createQuery()),e.beginOcclusionQuery(this.occlusionQueryAlgorithmType,this._occlusionQuery),n.renderOcclusionBoundingBox(this),e.endOcclusionQuery(this.occlusionQueryAlgorithmType),this._isOcclusionQueryInProgress=!0},i.OCCLUSION_TYPE_NONE=0,i.OCCLUSION_TYPE_OPTIMISTIC=1,i.OCCLUSION_TYPE_STRICT=2,i.OCCLUSION_ALGORITHM_TYPE_ACCURATE=0,i.OCCLUSION_ALGORITHM_TYPE_CONSERVATIVE=1,i})(e.TransformNode);e.AbstractMesh=t})(e||(e={}));var e;!(function(e){var t=(function(t){function i(r,n){var o=t.call(this,r,n)||this;return o.diffuse=new e.Color3(1,1,1),o.specular=new e.Color3(1,1,1),o.intensity=1,o.range=Number.MAX_VALUE,o._photometricScale=1,o._intensityMode=i.INTENSITYMODE_AUTOMATIC,o._radius=1e-5,o.renderPriority=0,o.shadowEnabled=!0,o._excludeWithLayerMask=0,o._includeOnlyWithLayerMask=0,o._lightmapMode=0,o._excludedMeshesIds=new Array,o._includedOnlyMeshesIds=new Array,o.getScene().addLight(o),o._uniformBuffer=new e.UniformBuffer(o.getScene().getEngine()),o._buildUniformLayout(),o.includedOnlyMeshes=new Array,o.excludedMeshes=new Array,o._resyncMeshes(),o}return __extends(i,t),Object.defineProperty(i,"LIGHTMAP_DEFAULT",{get:function(){return i._LIGHTMAP_DEFAULT},enumerable:!0,configurable:!0}),Object.defineProperty(i,"LIGHTMAP_SPECULAR",{get:function(){return i._LIGHTMAP_SPECULAR},enumerable:!0,configurable:!0}),Object.defineProperty(i,"LIGHTMAP_SHADOWSONLY",{get:function(){return i._LIGHTMAP_SHADOWSONLY},enumerable:!0,configurable:!0}),Object.defineProperty(i,"INTENSITYMODE_AUTOMATIC",{get:function(){return i._INTENSITYMODE_AUTOMATIC},enumerable:!0,configurable:!0}),Object.defineProperty(i,"INTENSITYMODE_LUMINOUSPOWER",{get:function(){return i._INTENSITYMODE_LUMINOUSPOWER},enumerable:!0,configurable:!0}),Object.defineProperty(i,"INTENSITYMODE_LUMINOUSINTENSITY",{get:function(){return i._INTENSITYMODE_LUMINOUSINTENSITY},enumerable:!0,configurable:!0}),Object.defineProperty(i,"INTENSITYMODE_ILLUMINANCE",{get:function(){return i._INTENSITYMODE_ILLUMINANCE},enumerable:!0,configurable:!0}),Object.defineProperty(i,"INTENSITYMODE_LUMINANCE",{get:function(){return i._INTENSITYMODE_LUMINANCE},enumerable:!0,configurable:!0}),Object.defineProperty(i,"LIGHTTYPEID_POINTLIGHT",{get:function(){return i._LIGHTTYPEID_POINTLIGHT},enumerable:!0,configurable:!0}),Object.defineProperty(i,"LIGHTTYPEID_DIRECTIONALLIGHT",{get:function(){return i._LIGHTTYPEID_DIRECTIONALLIGHT},enumerable:!0,configurable:!0}),Object.defineProperty(i,"LIGHTTYPEID_SPOTLIGHT",{get:function(){return i._LIGHTTYPEID_SPOTLIGHT},enumerable:!0,configurable:!0}),Object.defineProperty(i,"LIGHTTYPEID_HEMISPHERICLIGHT",{get:function(){return i._LIGHTTYPEID_HEMISPHERICLIGHT},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"intensityMode",{get:function(){return this._intensityMode},set:function(e){this._intensityMode=e,this._computePhotometricScale()},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"radius",{get:function(){return this._radius},set:function(e){this._radius=e,this._computePhotometricScale()},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"includedOnlyMeshes",{get:function(){return this._includedOnlyMeshes},set:function(e){this._includedOnlyMeshes=e,this._hookArrayForIncludedOnly(e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"excludedMeshes",{get:function(){return this._excludedMeshes},set:function(e){this._excludedMeshes=e,this._hookArrayForExcluded(e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"excludeWithLayerMask",{get:function(){return this._excludeWithLayerMask},set:function(e){this._excludeWithLayerMask=e,this._resyncMeshes()},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"includeOnlyWithLayerMask",{get:function(){return this._includeOnlyWithLayerMask},set:function(e){this._includeOnlyWithLayerMask=e,this._resyncMeshes()},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"lightmapMode",{get:function(){return this._lightmapMode},set:function(e){this._lightmapMode!==e&&(this._lightmapMode=e,this._markMeshesAsLightDirty())},enumerable:!0,configurable:!0}),i.prototype.getClassName=function(){return"Light"},i.prototype.toString=function(e){var t="Name: "+this.name;if(t+=", type: "+["Point","Directional","Spot","Hemispheric"][this.getTypeID()],this.animations)for(var i=0;i0&&-1===this.includedOnlyMeshes.indexOf(e))&&(!(this.excludedMeshes&&this.excludedMeshes.length>0&&-1!==this.excludedMeshes.indexOf(e))&&((0===this.includeOnlyWithLayerMask||0!=(this.includeOnlyWithLayerMask&e.layerMask))&&!(0!==this.excludeWithLayerMask&&this.excludeWithLayerMask&e.layerMask)))},i.prototype.getWorldMatrix=function(){this._currentRenderId=this.getScene().getRenderId();var t=this._getWorldMatrix();return this.parent&&this.parent.getWorldMatrix?(this._parentedWorldMatrix||(this._parentedWorldMatrix=e.Matrix.Identity()),t.multiplyToRef(this.parent.getWorldMatrix(),this._parentedWorldMatrix),this._markSyncedWithParent(),this._parentedWorldMatrix):t},i.CompareLightsPriority=function(e,t){return e.shadowEnabled!==t.shadowEnabled?(t.shadowEnabled?1:0)-(e.shadowEnabled?1:0):t.renderPriority-e.renderPriority},i.prototype.dispose=function(e,i){void 0===i&&(i=!1),this._shadowGenerator&&(this._shadowGenerator.dispose(),this._shadowGenerator=null),this.getScene().stopAnimation(this);for(var r=0,n=this.getScene().meshes;r0&&(t.excludedMeshesIds=[],this.excludedMeshes.forEach((function(e){t.excludedMeshesIds.push(e.id)}))),this.includedOnlyMeshes.length>0&&(t.includedOnlyMeshesIds=[],this.includedOnlyMeshes.forEach((function(e){t.includedOnlyMeshesIds.push(e.id)}))),e.Animation.AppendSerializedAnimations(this,t),t.ranges=this.serializeAnimationRanges(),t},i.GetConstructorFromName=function(t,i,r){switch(t){case 0:return function(){return new e.PointLight(i,e.Vector3.Zero(),r)};case 1:return function(){return new e.DirectionalLight(i,e.Vector3.Zero(),r)};case 2:return function(){return new e.SpotLight(i,e.Vector3.Zero(),e.Vector3.Zero(),0,0,r)};case 3:return function(){return new e.HemisphericLight(i,e.Vector3.Zero(),r)}}return null},i.Parse=function(t,r){var n=i.GetConstructorFromName(t.type,t.name,r);if(!n)return null;var o=e.SerializationHelper.Parse(n,t,r);if(t.excludedMeshesIds&&(o._excludedMeshesIds=t.excludedMeshesIds),t.includedOnlyMeshesIds&&(o._includedOnlyMeshesIds=t.includedOnlyMeshesIds),t.parentId&&(o._waitingParentId=t.parentId),t.animations){for(var s=0;s0&&this._postProcesses[0].markTextureDirty();for(var t=0,i=this._rigCameras.length;t-1?(e.Tools.Error("You're trying to reuse a post process not defined as reusable."),0):(null==i||i<0?this._postProcesses.push(t):this._postProcesses.splice(i,0,t),this._cascadePostProcessesToRigCams(),this._postProcesses.indexOf(t))},i.prototype.detachPostProcess=function(e){var t=this._postProcesses.indexOf(e);-1!==t&&this._postProcesses.splice(t,1),this._cascadePostProcessesToRigCams()},i.prototype.getWorldMatrix=function(){return this._worldMatrix||(this._worldMatrix=e.Matrix.Identity()),this.getViewMatrix().invertToRef(this._worldMatrix),this._worldMatrix},i.prototype._getViewMatrix=function(){return e.Matrix.Identity()},i.prototype.getViewMatrix=function(t){return!t&&this._isSynchronizedViewMatrix()?this._computedViewMatrix:(this.updateCache(),this._computedViewMatrix=this._getViewMatrix(),this._currentRenderId=this.getScene().getRenderId(),this._refreshFrustumPlanes=!0,this.parent&&this.parent.getWorldMatrix?(this._worldMatrix||(this._worldMatrix=e.Matrix.Identity()),this._computedViewMatrix.invertToRef(this._worldMatrix),this._worldMatrix.multiplyToRef(this.parent.getWorldMatrix(),this._computedViewMatrix),this._globalPosition.copyFromFloats(this._computedViewMatrix.m[12],this._computedViewMatrix.m[13],this._computedViewMatrix.m[14]),this._computedViewMatrix.invert(),this._markSyncedWithParent()):this._globalPosition.copyFrom(this.position),this._cameraRigParams&&this._cameraRigParams.vrPreViewMatrix&&this._computedViewMatrix.multiplyToRef(this._cameraRigParams.vrPreViewMatrix,this._computedViewMatrix),this.onViewMatrixChangedObservable.notifyObservers(this),this._computedViewMatrix)},i.prototype.freezeProjectionMatrix=function(e){this._doNotComputeProjectionMatrix=!0,void 0!==e&&(this._projectionMatrix=e)},i.prototype.unfreezeProjectionMatrix=function(){this._doNotComputeProjectionMatrix=!1},i.prototype.getProjectionMatrix=function(t){if(this._doNotComputeProjectionMatrix||!t&&this._isSynchronizedProjectionMatrix())return this._projectionMatrix;this._cache.mode=this.mode,this._cache.minZ=this.minZ,this._cache.maxZ=this.maxZ,this._refreshFrustumPlanes=!0;var r=this.getEngine(),n=this.getScene();if(this.mode===i.PERSPECTIVE_CAMERA)this._cache.fov=this.fov,this._cache.fovMode=this.fovMode,this._cache.aspectRatio=r.getAspectRatio(this),this.minZ<=0&&(this.minZ=.1),n.useRightHandedSystem?e.Matrix.PerspectiveFovRHToRef(this.fov,r.getAspectRatio(this),this.minZ,this.maxZ,this._projectionMatrix,this.fovMode===i.FOVMODE_VERTICAL_FIXED):e.Matrix.PerspectiveFovLHToRef(this.fov,r.getAspectRatio(this),this.minZ,this.maxZ,this._projectionMatrix,this.fovMode===i.FOVMODE_VERTICAL_FIXED);else{var o=r.getRenderWidth()/2,s=r.getRenderHeight()/2;n.useRightHandedSystem?e.Matrix.OrthoOffCenterRHToRef(this.orthoLeft||-o,this.orthoRight||o,this.orthoBottom||-s,this.orthoTop||s,this.minZ,this.maxZ,this._projectionMatrix):e.Matrix.OrthoOffCenterLHToRef(this.orthoLeft||-o,this.orthoRight||o,this.orthoBottom||-s,this.orthoTop||s,this.minZ,this.maxZ,this._projectionMatrix),this._cache.orthoLeft=this.orthoLeft,this._cache.orthoRight=this.orthoRight,this._cache.orthoBottom=this.orthoBottom,this._cache.orthoTop=this.orthoTop,this._cache.renderWidth=r.getRenderWidth(),this._cache.renderHeight=r.getRenderHeight()}return this.onProjectionMatrixChangedObservable.notifyObservers(this),this._projectionMatrix},i.prototype.getTranformationMatrix=function(){return this._computedViewMatrix.multiplyToRef(this._projectionMatrix,this._transformMatrix),this._transformMatrix},i.prototype.updateFrustumPlanes=function(){this._refreshFrustumPlanes&&(this.getTranformationMatrix(),this._frustumPlanes?e.Frustum.GetPlanesToRef(this._transformMatrix,this._frustumPlanes):this._frustumPlanes=e.Frustum.GetPlanes(this._transformMatrix),this._refreshFrustumPlanes=!1)},i.prototype.isInFrustum=function(e){return this.updateFrustumPlanes(),e.isInFrustum(this._frustumPlanes)},i.prototype.isCompletelyInFrustum=function(e){return this.updateFrustumPlanes(),e.isCompletelyInFrustum(this._frustumPlanes)},i.prototype.getForwardRay=function(t,i,r){void 0===t&&(t=100),i||(i=this.getWorldMatrix()),r||(r=this.position);var n=new e.Vector3(0,0,1),o=e.Vector3.TransformNormal(n,i),s=e.Vector3.Normalize(o);return new e.Ray(r,s,t)},i.prototype.dispose=function(e,r){for(void 0===r&&(r=!1),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 n=this._rigCameras.pop();n&&n.dispose()}if(this._rigPostProcess)this._rigPostProcess.dispose(this),this._rigPostProcess=null,this._postProcesses=[];else if(this.cameraRigMode!==i.RIG_MODE_NONE)this._rigPostProcess=null,this._postProcesses=[];else for(var o=this._postProcesses.length;--o>=0;)this._postProcesses[o].dispose(this);for(var o=this.customRenderTargets.length;--o>=0;)this.customRenderTargets[o].dispose();this.customRenderTargets=[],this._activeMeshes.dispose(),t.prototype.dispose.call(this,e,r)},Object.defineProperty(i.prototype,"leftCamera",{get:function(){return this._rigCameras.length<1?null:this._rigCameras[0]},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"rightCamera",{get:function(){return this._rigCameras.length<2?null:this._rigCameras[1]},enumerable:!0,configurable:!0}),i.prototype.getLeftTarget=function(){return this._rigCameras.length<1?null:this._rigCameras[0].getTarget()},i.prototype.getRightTarget=function(){return this._rigCameras.length<2?null:this._rigCameras[1].getTarget()},i.prototype.setCameraRigMode=function(t,r){if(this.cameraRigMode!==t){for(;this._rigCameras.length>0;){var n=this._rigCameras.pop();n&&n.dispose()}if(this.cameraRigMode=t,this._cameraRigParams={},this._cameraRigParams.interaxialDistance=r.interaxialDistance||.0637,this._cameraRigParams.stereoHalfAngle=e.Tools.ToRadians(this._cameraRigParams.interaxialDistance/.0637),this.cameraRigMode!==i.RIG_MODE_NONE){var o=this.createRigCamera(this.name+"_L",0),s=this.createRigCamera(this.name+"_R",1);o&&s&&(this._rigCameras.push(o),this._rigCameras.push(s))}switch(this.cameraRigMode){case i.RIG_MODE_STEREOSCOPIC_ANAGLYPH:this._rigCameras[0]._rigPostProcess=new e.PassPostProcess(this.name+"_passthru",1,this._rigCameras[0]),this._rigCameras[1]._rigPostProcess=new e.AnaglyphPostProcess(this.name+"_anaglyph",1,this._rigCameras);break;case i.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL:case i.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED:case i.RIG_MODE_STEREOSCOPIC_OVERUNDER:var a=this.cameraRigMode===i.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL||this.cameraRigMode===i.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED;this._rigCameras[0]._rigPostProcess=new e.PassPostProcess(this.name+"_passthru",1,this._rigCameras[0]),this._rigCameras[1]._rigPostProcess=new e.StereoscopicInterlacePostProcess(this.name+"_stereoInterlace",this._rigCameras,a);break;case i.RIG_MODE_VR:var l=r.vrCameraMetrics||e.VRCameraMetrics.GetDefault();this._rigCameras[0]._cameraRigParams.vrMetrics=l,this._rigCameras[0].viewport=new e.Viewport(0,0,.5,1),this._rigCameras[0]._cameraRigParams.vrWorkMatrix=new e.Matrix,this._rigCameras[0]._cameraRigParams.vrHMatrix=l.leftHMatrix,this._rigCameras[0]._cameraRigParams.vrPreViewMatrix=l.leftPreViewMatrix,this._rigCameras[0].getProjectionMatrix=this._rigCameras[0]._getVRProjectionMatrix,this._rigCameras[1]._cameraRigParams.vrMetrics=l,this._rigCameras[1].viewport=new e.Viewport(.5,0,.5,1),this._rigCameras[1]._cameraRigParams.vrWorkMatrix=new e.Matrix,this._rigCameras[1]._cameraRigParams.vrHMatrix=l.rightHMatrix,this._rigCameras[1]._cameraRigParams.vrPreViewMatrix=l.rightPreViewMatrix,this._rigCameras[1].getProjectionMatrix=this._rigCameras[1]._getVRProjectionMatrix,l.compensateDistortion&&(this._rigCameras[0]._rigPostProcess=new e.VRDistortionCorrectionPostProcess("VR_Distort_Compensation_Left",this._rigCameras[0],!1,l),this._rigCameras[1]._rigPostProcess=new e.VRDistortionCorrectionPostProcess("VR_Distort_Compensation_Right",this._rigCameras[1],!0,l));break;case i.RIG_MODE_WEBVR:if(r.vrDisplay){var c=r.vrDisplay.getEyeParameters("left"),h=r.vrDisplay.getEyeParameters("right");this._rigCameras[0].viewport=new e.Viewport(0,0,.5,1),this._rigCameras[0].setCameraRigParameter("left",!0),this._rigCameras[0].setCameraRigParameter("specs",r.specs),this._rigCameras[0].setCameraRigParameter("eyeParameters",c),this._rigCameras[0].setCameraRigParameter("frameData",r.frameData),this._rigCameras[0].setCameraRigParameter("parentCamera",r.parentCamera),this._rigCameras[0]._cameraRigParams.vrWorkMatrix=new e.Matrix,this._rigCameras[0].getProjectionMatrix=this._getWebVRProjectionMatrix,this._rigCameras[0].parent=this,this._rigCameras[0]._getViewMatrix=this._getWebVRViewMatrix,this._rigCameras[1].viewport=new e.Viewport(.5,0,.5,1),this._rigCameras[1].setCameraRigParameter("eyeParameters",h),this._rigCameras[1].setCameraRigParameter("specs",r.specs),this._rigCameras[1].setCameraRigParameter("frameData",r.frameData),this._rigCameras[1].setCameraRigParameter("parentCamera",r.parentCamera),this._rigCameras[1]._cameraRigParams.vrWorkMatrix=new e.Matrix,this._rigCameras[1].getProjectionMatrix=this._getWebVRProjectionMatrix,this._rigCameras[1].parent=this,this._rigCameras[1]._getViewMatrix=this._getWebVRViewMatrix,i.UseAlternateWebVRRendering&&(this._rigCameras[1]._skipRendering=!0,this._rigCameras[0]._alternateCamera=this._rigCameras[1])}}this._cascadePostProcessesToRigCams(),this.update()}},i.prototype._getVRProjectionMatrix=function(){return e.Matrix.PerspectiveFovLHToRef(this._cameraRigParams.vrMetrics.aspectRatioFov,this._cameraRigParams.vrMetrics.aspectRatio,this.minZ,this.maxZ,this._cameraRigParams.vrWorkMatrix),this._cameraRigParams.vrWorkMatrix.multiplyToRef(this._cameraRigParams.vrHMatrix,this._projectionMatrix),this._projectionMatrix},i.prototype._updateCameraRotationMatrix=function(){},i.prototype._updateWebVRCameraRotationMatrix=function(){},i.prototype._getWebVRProjectionMatrix=function(){return e.Matrix.Identity()},i.prototype._getWebVRViewMatrix=function(){return e.Matrix.Identity()},i.prototype.setCameraRigParameter=function(t,i){this._cameraRigParams||(this._cameraRigParams={}),this._cameraRigParams[t]=i,"interaxialDistance"===t&&(this._cameraRigParams.stereoHalfAngle=e.Tools.ToRadians(i/.0637))},i.prototype.createRigCamera=function(e,t){return null},i.prototype._updateRigCameras=function(){for(var e=0;ei._alphaIndex?1:e._alphaIndext._distanceToCamera?-1:0},t.frontToBackSortCompare=function(e,t){return e._distanceToCamerat._distanceToCamera?1:0},t.prototype.prepare=function(){this._opaqueSubMeshes.reset(),this._transparentSubMeshes.reset(),this._alphaTestSubMeshes.reset(),this._depthOnlySubMeshes.reset(),this._particleSystems.reset(),this._spriteManagers.reset(),this._edgesRenderers.reset()},t.prototype.dispose=function(){this._opaqueSubMeshes.dispose(),this._transparentSubMeshes.dispose(),this._alphaTestSubMeshes.dispose(),this._depthOnlySubMeshes.dispose(),this._particleSystems.dispose(),this._spriteManagers.dispose(),this._edgesRenderers.dispose()},t.prototype.dispatch=function(e,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))},t.prototype.dispatchSprites=function(e){this._spriteManagers.push(e)},t.prototype.dispatchParticles=function(e){this._particleSystems.push(e)},t.prototype._renderParticles=function(e){if(0!==this._particleSystems.length){var t=this._scene.activeCamera;this._scene.onBeforeParticlesRenderingObservable.notifyObservers(this._scene);for(var i=0;ii.LongPressDelay&&Math.abs(n._startingPointerPosition.x-n._pointerX)i.DoubleClickDelay&&!s._doubleClickOccured||e!==s._previousButtonPressed)&&(s._doubleClickOccured=!1,t.singleClick=!0,t.ignore=!1,r(t,s._currentPickResult))},this._initClickEvent=function(r,n,o,a){var l=new t;s._currentPickResult=null;var c=null,h=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(!h&&e.ActionManager&&e.ActionManager.HasPickTriggers&&(c=s._initActionManager(c,l))&&(h=c.hasPickTriggers),h){var u=o.button;if(l.hasSwiped=Math.abs(s._startingPointerPosition.x-s._pointerX)>i.DragMovementThreshold||Math.abs(s._startingPointerPosition.y-s._pointerY)>i.DragMovementThreshold,!l.hasSwiped){var f=!i.ExclusiveDoubleClickMode;f||(f=!r.hasSpecificMask(e.PointerEventTypes.POINTERDOUBLETAP)&&!n.hasSpecificMask(e.PointerEventTypes.POINTERDOUBLETAP))&&!e.ActionManager.HasSpecificTrigger(e.ActionManager.OnDoublePickTrigger)&&(c=s._initActionManager(c,l))&&(f=!c.hasSpecificTrigger(e.ActionManager.OnDoublePickTrigger)),f?((new Date).getTime()-s._previousStartingPointerTime>i.DoubleClickDelay||u!==s._previousButtonPressed)&&(l.singleClick=!0,a(l,s._currentPickResult)):(s._previousDelayedSimpleClickTimeout=s._delayedSimpleClickTimeout,s._delayedSimpleClickTimeout=window.setTimeout(s._delayedSimpleClick.bind(s,u,l,a),i.DoubleClickDelay));var d=r.hasSpecificMask(e.PointerEventTypes.POINTERDOUBLETAP)||n.hasSpecificMask(e.PointerEventTypes.POINTERDOUBLETAP);!d&&e.ActionManager.HasSpecificTrigger(e.ActionManager.OnDoublePickTrigger)&&(c=s._initActionManager(c,l))&&(d=c.hasSpecificTrigger(e.ActionManager.OnDoublePickTrigger)),d&&(u===s._previousButtonPressed&&(new Date).getTime()-s._previousStartingPointerTime0&&(n=s.pickSprite(s._unTranslatedPointerX,s._unTranslatedPointerY,s._spritePredicate,!1,s.cameraToUseForPointers||void 0))&&n.hit&&n.pickedSprite&&n.pickedSprite.actionManager){switch(s._pickedDownSprite=n.pickedSprite,t.button){case 0:n.pickedSprite.actionManager.processTrigger(e.ActionManager.OnLeftPickTrigger,e.ActionEvent.CreateNewFromSprite(n.pickedSprite,s,t));break;case 1:n.pickedSprite.actionManager.processTrigger(e.ActionManager.OnCenterPickTrigger,e.ActionEvent.CreateNewFromSprite(n.pickedSprite,s,t));break;case 2:n.pickedSprite.actionManager.processTrigger(e.ActionManager.OnRightPickTrigger,e.ActionEvent.CreateNewFromSprite(n.pickedSprite,s,t))}n.pickedSprite.actionManager&&n.pickedSprite.actionManager.processTrigger(e.ActionManager.OnPickDownTrigger,e.ActionEvent.CreateNewFromSprite(n.pickedSprite,s,t))}}},this._onPointerUp=function(t){0!==s._totalPointersPressed&&(s._totalPointersPressed--,s._pickedUpMesh=null,s._meshPickProceed=!1,s._updatePointerPosition(t),s._initClickEvent(s.onPrePointerObservable,s.onPointerObservable,t,(function(r,n){if(s.onPrePointerObservable.hasObservers())if(r.ignore){var o=e.PointerEventTypes.POINTERUP,a=new e.PointerInfoPre(o,t,s._unTranslatedPointerX,s._unTranslatedPointerY);if(s.onPrePointerObservable.notifyObservers(a,o),a.skipOnPointerObservable)return}else if(!r.hasSwiped){if(r.singleClick&&s.onPrePointerObservable.hasSpecificMask(e.PointerEventTypes.POINTERTAP)){var o=e.PointerEventTypes.POINTERTAP,a=new e.PointerInfoPre(o,t,s._unTranslatedPointerX,s._unTranslatedPointerY);if(s.onPrePointerObservable.notifyObservers(a,o),a.skipOnPointerObservable)return}if(r.doubleClick&&s.onPrePointerObservable.hasSpecificMask(e.PointerEventTypes.POINTERDOUBLETAP)){var o=e.PointerEventTypes.POINTERDOUBLETAP,a=new e.PointerInfoPre(o,t,s._unTranslatedPointerX,s._unTranslatedPointerY);if(s.onPrePointerObservable.notifyObservers(a,o),a.skipOnPointerObservable)return}}if(s.cameraToUseForPointers||s.activeCamera){if(s.pointerUpPredicate||(s.pointerUpPredicate=function(e){return e.isPickable&&e.isVisible&&e.isReady()&&e.isEnabled()}),!s._meshPickProceed&&(e.ActionManager&&e.ActionManager.HasTriggers||s.onPointerObservable.hasObservers())&&s._initActionManager(null,r),n||(n=s._currentPickResult),s._processPointerUp(n,t,r),s.spriteManagers.length>0){var l=s.pickSprite(s._unTranslatedPointerX,s._unTranslatedPointerY,s._spritePredicate,!1,s.cameraToUseForPointers||void 0);l&&(l.hit&&l.pickedSprite&&l.pickedSprite.actionManager&&(l.pickedSprite.actionManager.processTrigger(e.ActionManager.OnPickUpTrigger,e.ActionEvent.CreateNewFromSprite(l.pickedSprite,s,t)),l.pickedSprite.actionManager&&Math.abs(s._startingPointerPosition.x-s._pointerX)0)return!1;var t,i=this.getEngine();for(t=0;t0,o=0,s=this.effectLayers;o0},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.whenReadyAsync=function(){var e=this;return new Promise(function(t){e.executeWhenReady((function(){t()}))})},i.prototype._checkIsReady=function(){var e=this;if(this.isReady())return this.onReadyObservable.notifyObservers(this),this.onReadyObservable.clear(),void(this._executeWhenReadyTimeoutId=-1);this._executeWhenReadyTimeoutId=setTimeout((function(){e._checkIsReady()}),150)},i.prototype.beginAnimation=function(t,i,r,n,o,s,a){if(void 0===o&&(o=1),i>r&&o>0&&(o*=-1),this.stopAnimation(t),a||(a=new e.Animatable(this,t,i,r,n,o,s)),t.animations&&a.appendAnimations(t,t.animations),t.getAnimatables)for(var l=t.getAnimatables(),c=0;c0)return;this._animationTimeLast=t}var i=this.useConstantAnimationDeltaTime?16:(t-this._animationTimeLast)*this.animationTimeScale;this._animationTime+=i,this._animationTimeLast=t;for(var r=0;r0?this.activeCamera=this.cameras[0]:this.activeCamera=null),this.onCameraRemovedObservable.notifyObservers(e),t},i.prototype.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-1&&(this._geometries.splice(t,1),this.collisionCoordinator&&this.collisionCoordinator.onGeometryDeleted(e),this.onGeometryRemovedObservable.notifyObservers(e),!0)},i.prototype.getGeometries=function(){return this._geometries},i.prototype.getMeshByID=function(e){for(var t=0;t=0;t--)if(this.meshes[t].id===e)return this.meshes[t];return null},i.prototype.getLastEntryByID=function(e){var t;for(t=this.meshes.length-1;t>=0;t--)if(this.meshes[t].id===e)return this.meshes[t];for(t=this.transformNodes.length-1;t>=0;t--)if(this.transformNodes[t].id===e)return this.transformNodes[t];for(t=this.cameras.length-1;t>=0;t--)if(this.cameras[t].id===e)return this.cameras[t];for(t=this.lights.length-1;t>=0;t--)if(this.lights[t].id===e)return this.lights[t];return null},i.prototype.getNodeByID=function(e){var t=this.getMeshByID(e);if(t)return t;var i=this.getLightByID(e);if(i)return i;var r=this.getCameraByID(e);return r||this.getBoneByID(e)},i.prototype.getNodeByName=function(e){var t=this.getMeshByName(e);if(t)return t;var i=this.getLightByName(e);if(i)return i;var r=this.getCameraByName(e);return r||this.getBoneByName(e)},i.prototype.getMeshByName=function(e){for(var t=0;t=0;t--)if(this.skeletons[t].id===e)return this.skeletons[t];return null},i.prototype.getSkeletonById=function(e){for(var t=0;t0&&0!=(o.layerMask&this.activeCamera.layerMask)&&o.isInFrustum(this._frustumPlanes))&&(this._activeMeshes.push(o),this.activeCamera._activeMeshes.push(o),o._activate(this._renderId),s!==o&&s._activate(this._renderId),this._activeMesh(o,s)))));if(this.onAfterActiveMeshesEvaluationObservable.notifyObservers(this),this.particlesEnabled){this.onBeforeParticlesRenderingObservable.notifyObservers(this);for(var l=0;l0){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 n=t.subMeshes,r=n.length;for(var s,a=0;a0&&this._renderTargets.concatWithNoDuplicate(t.customRenderTargets),i&&i.customRenderTargets&&i.customRenderTargets.length>0&&this._renderTargets.concatWithNoDuplicate(i.customRenderTargets),this.renderTargetsEnabled&&this._renderTargets.length>0){this._intermediateRendering=!0,e.Tools.StartPerformanceCounter("Render targets",this._renderTargets.length>0);for(var a=0;a0),this._intermediateRendering=!1,this._renderId++,s=!0}var h=this._engine.getStencilBuffer(),u=!1,f=!1;if(this.renderTargetsEnabled&&this.effectLayers&&this.effectLayers.length>0){this._intermediateRendering=!0;for(var d=0;d-1)){u=!0,f=f||p.needStencil();var l=p._mainTexture;l._shouldRender()&&(this._renderId++,l.render(!1,!1),s=!0)}}this._intermediateRendering=!1,this._renderId++}s&&r.restoreDefaultFramebuffer(),this.OnAfterRenderTargetsRenderObservable.notifyObservers(this),this.postProcessManager._prepareFrame();var _,m;if(this.layers.length){for(r.setDepthBuffer(!1),_=0;_0);for(var g=0;g0)}if(this.layers.length){for(r.setDepthBuffer(!1),_=0;_-1&&(n.trigger===e.ActionManager.OnIntersectionExitTrigger&&n._executeCurrent(e.ActionEvent.CreateNew(i,void 0,s)),i.actionManager.hasSpecificTrigger(e.ActionManager.OnIntersectionExitTrigger)&&n.trigger!==e.ActionManager.OnIntersectionExitTrigger||i._intersectionsInProgress.splice(l,1))}}}},i.prototype.render=function(){if(!this.isDisposed){if(this._activeParticles.fetchNewFrame(),this._totalVertices.fetchNewFrame(),this._activeIndices.fetchNewFrame(),this._activeBones.fetchNewFrame(),this._meshesForIntersections.reset(),this.resetCachedMaterial(),this.onBeforeAnimationsObservable.notifyObservers(this),this.actionManager&&this.actionManager.processTrigger(e.ActionManager.OnEveryFrameTrigger),this.simplificationQueue&&!this.simplificationQueue.running&&this.simplificationQueue.executeNext(),this._engine.isDeterministicLockStep()){var t=Math.max(i.MinDeltaTime,Math.min(this._engine.getDeltaTime(),i.MaxDeltaTime))+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&&n0)for(var a=0;a0),this._intermediateRendering=!0;for(var f=0;f0),this._intermediateRendering=!1,this._renderId++}if(this.customRenderTargets.length>0&&h.restoreDefaultFramebuffer(),this.OnAfterRenderTargetsRenderObservable.notifyObservers(this),this.activeCamera=u,this.proceduralTexturesEnabled){e.Tools.StartPerformanceCounter("Procedural textures",this._proceduralTextures.length>0);for(var p=0;p0)}if((this.autoClearDepthAndStencil||this.autoClear)&&this._engine.clear(this.clearColor,this.autoClear||this.forceWireframe||this.forcePointsCloud,this.autoClearDepthAndStencil,this.autoClearDepthAndStencil),this.shadowsEnabled)for(var m=0;m0)for(var a=0;a0&&this._engine.clear(null,!1,!0,!0),this._processSubCameras(this.activeCameras[a]);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 c=0;c0?this.activeCameras[0]:this.activeCamera)&&i.canUseWebAudio&&i.audioContext){i.audioContext.listener.setPosition(t.position.x,t.position.y,t.position.z),t.rigCameras&&t.rigCameras.length>0&&(t=t.rigCameras[0]);var r=e.Matrix.Invert(t.getViewMatrix()),n=e.Vector3.TransformNormal(new e.Vector3(0,0,-1),r);n.normalize(),isNaN(n.x)||isNaN(n.y)||isNaN(n.z)||i.audioContext.listener.setOrientation(n.x,n.y,n.z,0,1,0);var o;for(o=0;o-1&&this._engine.scenes.splice(o,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=n.distance))&&(n=c,r)))break}return n||new e.PickingInfo},i.prototype._internalMultiPick=function(t,i){if(!e.PickingInfo)return null;for(var r=new Array,n=0;n0)for(var s=0;s=o.distance))&&(o=l,r))break}}return o||new e.PickingInfo},i.prototype.pick=function(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=0&&this._scene.textures.splice(e,1),void 0!==this._texture&&(this.releaseInternalTexture(),this.onDisposeObservable.notifyObservers(this),this.onDisposeObservable.clear())}},t.prototype.serialize=function(){if(!this.name)return null;var t=e.SerializationHelper.Serialize(this);return e.Animation.AppendSerializedAnimations(this,t),t},t.WhenAllReady=function(e,t){var i=e.length;if(0===i)return void t();for(var r,n,o=0;o0},enumerable:!0,configurable:!0}),r.prototype.getLODLevels=function(){return this._LODLevels},r.prototype._sortLODLevels=function(){this._LODLevels.sort((function(e,t){return e.distancet.distance?-1:0}))},r.prototype.addLODLevel=function(t,i){if(i&&i._masterMesh)return e.Tools.Warn("You cannot use a mesh as LOD level twice"),this;var r=new e.MeshLODLevel(t,i);return this._LODLevels.push(r),i&&(i._masterMesh=this),this._sortLODLevels(),this},r.prototype.getLODLevelAtDistance=function(e){for(var t=0;tr)return this.onLODLevelSelection&&this.onLODLevelSelection(r,this,this._LODLevels[this._LODLevels.length-1].mesh),this;for(var n=0;n0;this.computeWorldMatrix();var a=this.material||o.defaultMaterial;if(a)if(a.storeEffectOnSubMeshes)for(var l=0,c=this.subMeshes;l4,s=o?this.getVerticesData(e.VertexBuffer.MatricesIndicesExtraKind):null,a=o?this.getVerticesData(e.VertexBuffer.MatricesWeightsExtraKind):null,l=this.skeleton.getTransformMatrices(this),c=e.Tmp.Vector3[0],h=e.Tmp.Matrix[0],u=e.Tmp.Matrix[1],f=0,d=0;d0){var r=this.getIndices();if(!r)return null;var n=r.length,o=!1;if(t)o=!0;else for(var s=0,a=this.subMeshes;s=n){o=!0;break}if(l.verticesStart+l.verticesCount>=i){o=!0;break}}if(!o)return this.subMeshes[0]}return this.releaseSubMeshes(),new e.SubMesh(0,0,i,0,this.getTotalIndices(),this)},r.prototype.subdivide=function(t){if(!(t<1)){for(var i=this.getTotalIndices(),r=i/t|0,n=0;r%3!=0;)r++;this.releaseSubMeshes();for(var o=0;o=i);o++)e.SubMesh.CreateFromIndices(0,n,Math.min(r,i-n),this),n+=r;this.synchronizeInstances()}},r.prototype.setVerticesData=function(t,i,r,n){if(void 0===r&&(r=!1),this._geometry)this._geometry.setVerticesData(t,i,r,n);else{var o=new e.VertexData;o.set(i,t);var s=this.getScene();new e.Geometry(e.Geometry.RandomId(),s,o,r,this)}return this},r.prototype.markVerticesDataAsUpdatable=function(e,t){void 0===t&&(t=!0);var i=this.getVertexBuffer(e);i&&i.isUpdatable()!==t&&this.setVerticesData(e,this.getVerticesData(e),t)},r.prototype.setVerticesBuffer=function(t){return this._geometry||(this._geometry=e.Geometry.CreateGeometryForMesh(this)),this._geometry.setVerticesBuffer(t),this},r.prototype.updateVerticesData=function(e,t,i,r){return this._geometry?(r?(this.makeGeometryUnique(),this.updateVerticesData(e,t,i,!1)):this._geometry.updateVerticesData(e,t,i),this):this},r.prototype.updateMeshPositions=function(t,i){void 0===i&&(i=!0);var r=this.getVerticesData(e.VertexBuffer.PositionKind);if(!r)return this;if(t(r),this.updateVerticesData(e.VertexBuffer.PositionKind,r,!1,!1),i){var n=this.getIndices(),o=this.getVerticesData(e.VertexBuffer.NormalKind);if(!o)return this;e.VertexData.ComputeNormals(r,n,o),this.updateVerticesData(e.VertexBuffer.NormalKind,o,!1,!1)}return this},r.prototype.makeGeometryUnique=function(){if(!this._geometry)return this;var t=this._geometry,i=this._geometry.copy(e.Geometry.RandomId());return t.releaseForMesh(this,!0),i.applyToMesh(this),this},r.prototype.setIndices=function(t,i,r){if(void 0===i&&(i=null),void 0===r&&(r=!1),this._geometry)this._geometry.setIndices(t,i,r);else{var n=new e.VertexData;n.indices=t;var o=this.getScene();new e.Geometry(e.Geometry.RandomId(),o,n,r,this)}return this},r.prototype.updateIndices=function(e,t){return this._geometry?(this._geometry.updateIndices(e,t),this):this},r.prototype.toLeftHanded=function(){return this._geometry?(this._geometry.toLeftHanded(),this):this},r.prototype._bind=function(t,i,r){if(!this._geometry)return this;var n,o=this.getScene().getEngine();if(this._unIndexed)n=null;else switch(r){case e.Material.PointFillMode:n=null;break;case e.Material.WireFrameFillMode:n=t.getLinesIndexBuffer(this.getIndices(),o);break;default:case e.Material.TriangleFillMode:n=this._unIndexed?null:this._geometry.getIndexBuffer()}return this._geometry._bind(i,n),this},r.prototype._draw=function(t,i,r,n){if(void 0===n&&(n=!1),!this._geometry||!this._geometry.getVertexBuffers()||!this._geometry.getIndexBuffer())return this;this.onBeforeDrawObservable.notifyObservers(this);var o=this.getScene(),s=o.getEngine();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=s.length+1,l=16*a*4,c=this._instancesBufferSize,h=this._instancesBuffer;this._instancesBufferSize-1;t--)if(i[t].id===e)return this.material=i[t],this;var r=this.getScene().multiMaterials;for(t=r.length-1;t>-1;t--)if(r[t].id===e)return this.material=r[t],this;return this},r.prototype.getAnimatables=function(){var e=new Array;return this.material&&e.push(this.material),this.skeleton&&e.push(this.skeleton),e},r.prototype.bakeTransformIntoVertices=function(t){if(!this.isVerticesDataPresent(e.VertexBuffer.PositionKind))return this;var i=this.subMeshes.splice(0);this._resetPointsArrayCache();var r,n=this.getVerticesData(e.VertexBuffer.PositionKind),o=new Array;for(r=0;r-1&&(o.morphTargetManager=i.getMorphTargetManagerById(t.morphTargetManagerId)),t.skeletonId>-1&&(o.skeleton=i.getLastSkeletonByID(t.skeletonId),t.numBoneInfluencers&&(o.numBoneInfluencers=t.numBoneInfluencers)),t.animations){for(var s=0;s4,c=l?this.getVerticesData(e.VertexBuffer.MatricesIndicesExtraKind):null,h=l?this.getVerticesData(e.VertexBuffer.MatricesWeightsExtraKind):null,u=t.getTransformMatrices(this),f=e.Vector3.Zero(),d=new e.Matrix,p=new e.Matrix,_=0,m=0;m0;a++)e.Matrix.FromFloat32ArrayToRefScaled(u,Math.floor(16*o[_+a]),g,p),d.addToSelf(p);if(l)for(a=0;a<4&&(g=h[_+a])>0;a++)e.Matrix.FromFloat32ArrayToRefScaled(u,Math.floor(16*c[_+a]),g,p),d.addToSelf(p);e.Vector3.TransformCoordinatesFromFloatsToRef(this._sourcePositions[m],this._sourcePositions[m+1],this._sourcePositions[m+2],d,f),f.toArray(r,m),e.Vector3.TransformNormalFromFloatsToRef(this._sourceNormals[m],this._sourceNormals[m+1],this._sourceNormals[m+2],d,f),f.toArray(n,m),d.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(),s=o.boundingBox;i&&r?(i.minimizeInPlace(s.minimumWorld),r.maximizeInPlace(s.maximumWorld)):(i=s.minimumWorld,r=s.maximumWorld)})),i&&r?{min:i,max:r}:{min:e.Vector3.Zero(),max:e.Vector3.Zero()}},r.Center=function(t){var i=t instanceof Array?r.MinMax(t):t;return e.Vector3.Center(i.min,i.max)},r.MergeMeshes=function(t,i,n,o,s){void 0===i&&(i=!0);var a;if(!n){var l=0;for(a=0;a65536)return e.Tools.Warn("Cannot merge meshes because resulting mesh will have more than 65536 vertices. Please use allow32BitsIndices = true to use 32 bits indices"),null}var c,h=null,u=new Array,f=null;for(a=0;aa&&(a=h)}return new i(e,s,a-s+1,t,r,n,o)},i})(t);e.SubMesh=i})(e||(e={}));var e,t=this&&this.__assign||Object.assign||function(e){for(var t,i=1,r=arguments.length;i=0&&this._scene.materials.splice(i,1),i=0;ia?a:Math.floor(l);var c,h,u,f,d=0===i.sideOrientation?0:i.sideOrientation||e.Mesh.DEFAULTSIDE,p=i.uvs,_=i.colors,m=[],g=[],v=[],y=[],b=[],x=[],T=[],E=[],A=[],P=[];if(r.length<2){var M=[],S=[];for(u=0;u0&&(D=C[f].subtract(C[f-1]).length(),L=D+T[h],b[h].push(L),T[h]=L),f++;o&&(f--,m.push(C[0].x,C[0].y,C[0].z),D=C[f].subtract(C[0]).length(),L=D+T[h],b[h].push(L),T[h]=L),A[h]=R+I,P[h]=O,O+=R+I}var w,F,B=null,N=null;for(u=0;u1)?1:i.arc||1,l=i.slice&&i.slice<=0?1:i.slice||1,c=0===i.sideOrientation?0:i.sideOrientation||e.Mesh.DEFAULTSIDE,h=new e.Vector3(n/2,o/2,s/2),u=2+r,f=2*u,d=[],p=[],_=[],m=[],g=0;g<=u;g++){for(var v=g/u,y=v*Math.PI*l,b=0;b<=f;b++){var x=b/f,T=x*Math.PI*2*a,E=e.Matrix.RotationZ(-y),A=e.Matrix.RotationY(T),P=e.Vector3.TransformCoordinates(e.Vector3.Up(),E),M=e.Vector3.TransformCoordinates(P,A),S=M.multiply(h),C=M.divide(h).normalize();p.push(S.x,S.y,S.z),_.push(C.x,C.y,C.z),m.push(x,v)}if(g>0)for(var R=p.length/3,O=R-2*(f+1);O+f+21)?1:i.arc||1,f=0===i.sideOrientation?0:i.sideOrientation||e.Mesh.DEFAULTSIDE,d=i.faceUV||new Array(3),p=i.faceColors,_=1!==u&&h?2:0,m=c?l:1,g=2+(1+_)*m;for(r=0;r0&&(i.push(a-1),i.push(a)),a++}var f=new t;return f.indices=i,f.positions=r,o&&(f.colors=s),f},t.CreateDashedLines=function(i){var r=i.dashSize||3,n=i.gapSize||1,o=i.dashNb||200,s=i.points,a=new Array,l=new Array,c=e.Vector3.Zero(),h=0,u=0,f=0,d=0,p=0,_=0,m=0;for(m=0;m1)?1:i.arc||1,h=0===i.sideOrientation?0:i.sideOrientation||e.Mesh.DEFAULTSIDE;r.push(0,0,0),s.push(.5,.5);for(var u=2*Math.PI*c,f=u/l,d=0;d=r.length)?0:i.type||0,u=i.size,f=i.sizeX||u||1,d=i.sizeY||u||1,p=i.sizeZ||u||1,_=i.custom||r[h],m=_.face.length,g=i.faceUV||new Array(m),v=i.faceColors,y=void 0===i.flat||i.flat,b=0===i.sideOrientation?0:i.sideOrientation||e.Mesh.DEFAULTSIDE,x=new Array,T=new Array,E=new Array,A=new Array,P=new Array,M=0,S=0,C=new Array,R=0,O=0;if(y)for(O=0;On.bbSize.y?n.bbSize.x:n.bbSize.y;$=$>n.bbSize.z?$:n.bbSize.z,L=n.subDiv.X*O/n.bbSize.x,w=n.subDiv.Y*O/n.bbSize.y,F=n.subDiv.Z*O/n.bbSize.z,B=n.subDiv.max*n.subDiv.max,n.facetPartitioning.length=0}for(o=0;o0&&(this._indexBuffer=this._engine.createIndexBuffer(this._indices)),this._indexBuffer&&(this._indexBuffer.references=i)},t.prototype.notifyUpdate=function(e){this.onGeometryUpdated&&this.onGeometryUpdated(this,e);for(var t=0,i=this._meshes;t0){for(var i=0;i0){for(var i=0;i0){for(var i=0;i0){var l=new Float32Array(i,a.positionsAttrDesc.offset,a.positionsAttrDesc.count);r.setVerticesData(e.VertexBuffer.PositionKind,l,!1)}if(a.normalsAttrDesc&&a.normalsAttrDesc.count>0){var c=new Float32Array(i,a.normalsAttrDesc.offset,a.normalsAttrDesc.count);r.setVerticesData(e.VertexBuffer.NormalKind,c,!1)}if(a.tangetsAttrDesc&&a.tangetsAttrDesc.count>0){var h=new Float32Array(i,a.tangetsAttrDesc.offset,a.tangetsAttrDesc.count);r.setVerticesData(e.VertexBuffer.TangentKind,h,!1)}if(a.uvsAttrDesc&&a.uvsAttrDesc.count>0){var u=new Float32Array(i,a.uvsAttrDesc.offset,a.uvsAttrDesc.count);r.setVerticesData(e.VertexBuffer.UVKind,u,!1)}if(a.uvs2AttrDesc&&a.uvs2AttrDesc.count>0){var f=new Float32Array(i,a.uvs2AttrDesc.offset,a.uvs2AttrDesc.count);r.setVerticesData(e.VertexBuffer.UV2Kind,f,!1)}if(a.uvs3AttrDesc&&a.uvs3AttrDesc.count>0){var d=new Float32Array(i,a.uvs3AttrDesc.offset,a.uvs3AttrDesc.count);r.setVerticesData(e.VertexBuffer.UV3Kind,d,!1)}if(a.uvs4AttrDesc&&a.uvs4AttrDesc.count>0){var p=new Float32Array(i,a.uvs4AttrDesc.offset,a.uvs4AttrDesc.count);r.setVerticesData(e.VertexBuffer.UV4Kind,p,!1)}if(a.uvs5AttrDesc&&a.uvs5AttrDesc.count>0){var _=new Float32Array(i,a.uvs5AttrDesc.offset,a.uvs5AttrDesc.count);r.setVerticesData(e.VertexBuffer.UV5Kind,_,!1)}if(a.uvs6AttrDesc&&a.uvs6AttrDesc.count>0){var m=new Float32Array(i,a.uvs6AttrDesc.offset,a.uvs6AttrDesc.count);r.setVerticesData(e.VertexBuffer.UV6Kind,m,!1)}if(a.colorsAttrDesc&&a.colorsAttrDesc.count>0){var g=new Float32Array(i,a.colorsAttrDesc.offset,a.colorsAttrDesc.count);r.setVerticesData(e.VertexBuffer.ColorKind,g,!1,a.colorsAttrDesc.stride)}if(a.matricesIndicesAttrDesc&&a.matricesIndicesAttrDesc.count>0){var v=new Int32Array(i,a.matricesIndicesAttrDesc.offset,a.matricesIndicesAttrDesc.count);r.setVerticesData(e.VertexBuffer.MatricesIndicesKind,v,!1)}if(a.matricesWeightsAttrDesc&&a.matricesWeightsAttrDesc.count>0){var y=new Float32Array(i,a.matricesWeightsAttrDesc.offset,a.matricesWeightsAttrDesc.count);r.setVerticesData(e.VertexBuffer.MatricesWeightsKind,y,!1)}if(a.indicesAttrDesc&&a.indicesAttrDesc.count>0){var b=new Int32Array(i,a.indicesAttrDesc.offset,a.indicesAttrDesc.count);r.setIndices(b,null)}if(a.subMeshesAttrDesc&&a.subMeshesAttrDesc.count>0){var x=new Int32Array(i,a.subMeshesAttrDesc.offset,5*a.subMeshesAttrDesc.count);r.subMeshes=[];for(var T=0;T>8),C.push((16711680&R)>>16),C.push(R>>24)}r.setVerticesData(e.VertexBuffer.MatricesIndicesKind,C,i.matricesIndices._updatable)}if(i.matricesIndicesExtra)if(i.matricesIndicesExtra._isExpanded)delete i.matricesIndices._isExpanded,r.setVerticesData(e.VertexBuffer.MatricesIndicesExtraKind,i.matricesIndicesExtra,i.matricesIndicesExtra._updatable);else{for(var C=[],T=0;T>8),C.push((16711680&R)>>16),C.push(R>>24)}r.setVerticesData(e.VertexBuffer.MatricesIndicesExtraKind,C,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 O=0;O-1){var n=i.getScene().getLastSkeletonByID(t.skeletonId);if(n){r=n.bones.length;for(var o=i.getVerticesData(e.VertexBuffer.MatricesIndicesKind),s=i.getVerticesData(e.VertexBuffer.MatricesIndicesExtraKind),a=t.matricesWeights,l=t.matricesWeightsExtra,c=t.numBoneInfluencer,h=a.length,u=0;uc-1)&&(d=c-1),f>.001){for(var m=1/f,p=0;p<4;p++)a[u+p]*=m;if(l)for(var p=0;p<4;p++)l[u+p]*=m}else d>=4?(l[u+d-4]=1-f,s[u+d-4]=r):(a[u+d]=1-f,o[u+d]=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 __extends(t,e),t.prototype.canBeRegenerated=function(){return this._canBeRegenerated},t.prototype.regenerate=function(){this._canBeRegenerated&&(this._beingRegenerated=!0,this.setAllVerticesData(this._regenerateVertexData(),!1),this._beingRegenerated=!1)},t.prototype.asNewGeometry=function(t){return e.prototype.copy.call(this,t)},t.prototype.setAllVerticesData=function(t,i){this._beingRegenerated&&e.prototype.setAllVerticesData.call(this,t,!1)},t.prototype.setVerticesData=function(t,i,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,l,c,h){void 0===h&&(h=e.Mesh.DEFAULTSIDE);var u=t.call(this,i,r,l,c)||this;return u.pathArray=n,u.closeArray=o,u.closePath=s,u.offset=a,u.side=h,u}return __extends(i,t),i.prototype._regenerateVertexData=function(){return e.VertexData.CreateRibbon({pathArray:this.pathArray,closeArray:this.closeArray,closePath:this.closePath,offset:this.offset,sideOrientation:this.side})},i.prototype.copy=function(e){return new i(e,this.getScene(),this.pathArray,this.closeArray,this.closePath,this.offset,this.canBeRegenerated(),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 l=t.call(this,i,r,o,s)||this;return l.size=n,l.side=a,l}return __extends(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,l){void 0===a&&(a=null),void 0===l&&(l=e.Mesh.DEFAULTSIDE);var c=t.call(this,i,r,s,a)||this;return c.segments=n,c.diameter=o,c.side=l,c}return __extends(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,l){void 0===a&&(a=null),void 0===l&&(l=e.Mesh.DEFAULTSIDE);var c=t.call(this,i,r,s,a)||this;return c.radius=n,c.tessellation=o,c.side=l,c}return __extends(i,t),i.prototype._regenerateVertexData=function(){return e.VertexData.CreateDisc({radius:this.radius,tessellation:this.tessellation,sideOrientation:this.side})},i.prototype.copy=function(e){return new i(e,this.getScene(),this.radius,this.tessellation,this.canBeRegenerated(),null,this.side)},i})(i);e.DiscGeometry=s;var a=(function(t){function i(i,r,n,o,s,a,l,c,h,u){void 0===l&&(l=1),void 0===h&&(h=null),void 0===u&&(u=e.Mesh.DEFAULTSIDE);var f=t.call(this,i,r,c,h)||this;return f.height=n,f.diameterTop=o,f.diameterBottom=s,f.tessellation=a,f.subdivisions=l,f.side=u,f}return __extends(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 l=(function(t){function i(i,r,n,o,s,a,l,c){void 0===l&&(l=null),void 0===c&&(c=e.Mesh.DEFAULTSIDE);var h=t.call(this,i,r,a,l)||this;return h.diameter=n,h.thickness=o,h.tessellation=s,h.side=c,h}return __extends(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=l;var c=(function(t){function i(e,i,r,n,o,s,a){void 0===a&&(a=null);var l=t.call(this,e,i,s,a)||this;return l.width=r,l.height=n,l.subdivisions=o,l}return __extends(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=c;var h=(function(t){function i(e,i,r,n,o,s,a,l,c,h){void 0===h&&(h=null);var u=t.call(this,e,i,c,h)||this;return u.xmin=r,u.zmin=n,u.xmax=o,u.zmax=s,u.subdivisions=a,u.precision=l,u}return __extends(i,t),i.prototype._regenerateVertexData=function(){return e.VertexData.CreateTiledGround({xmin:this.xmin,zmin:this.zmin,xmax:this.xmax,zmax:this.zmax,subdivisions:this.subdivisions,precision:this.precision})},i.prototype.copy=function(e){return new i(e,this.getScene(),this.xmin,this.zmin,this.xmax,this.zmax,this.subdivisions,this.precision,this.canBeRegenerated(),null)},i})(i);e.TiledGroundGeometry=h;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 l=t.call(this,i,r,o,s)||this;return l.size=n,l.side=a,l}return __extends(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 f=(function(t){function i(i,r,n,o,s,a,l,c,h,u,f){void 0===u&&(u=null),void 0===f&&(f=e.Mesh.DEFAULTSIDE);var d=t.call(this,i,r,h,u)||this;return d.radius=n,d.tube=o,d.radialSegments=s,d.tubularSegments=a,d.p=l,d.q=c,d.side=f,d}return __extends(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=f})(e||(e={}));var e;!(function(e){var t=(function(){function t(e){this._vertexBuffers={},this._scene=e}return t.prototype._prepareBuffers=function(){if(!this._vertexBuffers[e.VertexBuffer.PositionKind]){var t=[];t.push(1,1),t.push(-1,1),t.push(-1,-1),t.push(1,-1),this._vertexBuffers[e.VertexBuffer.PositionKind]=new e.VertexBuffer(this._scene.getEngine(),t,e.VertexBuffer.PositionKind,!1,!1,2),this._buildIndexBuffer()}},t.prototype._buildIndexBuffer=function(){var e=[];e.push(0),e.push(1),e.push(2),e.push(0),e.push(2),e.push(3),this._indexBuffer=this._scene.getEngine().createIndexBuffer(e)},t.prototype._rebuild=function(){var t=this._vertexBuffers[e.VertexBuffer.PositionKind];t&&(t._rebuild(),this._buildIndexBuffer())},t.prototype._prepareFrame=function(e,t){void 0===e&&(e=null),void 0===t&&(t=null);var i=this._scene.activeCamera;if(!i)return!1;var t=t||i._postProcesses;return!(!t||0===t.length||!this._scene.postProcessesEnabled)&&(t[0].activate(i,e,null!==t&&void 0!==t),!0)},t.prototype.directRender=function(t,i,r){void 0===i&&(i=null),void 0===r&&(r=!1);for(var n=this._scene.getEngine(),o=0;o=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})(e||(e={}));var e;!(function(e){var t=(function(){function t(){this.colorCurves=new e.ColorCurves,this._colorCurvesEnabled=!1,this._colorGradingEnabled=!1,this._colorGradingWithGreenDepth=!0,this._colorGradingBGR=!0,this._exposure=1,this._toneMappingEnabled=!1,this._contrast=1,this.vignetteStretch=0,this.vignetteCentreX=0,this.vignetteCentreY=0,this.vignetteWeight=1.5,this.vignetteColor=new e.Color4(0,0,0,0),this.vignetteCameraFov=.5,this._grainEnabled=!1,this._grainIntensity=30,this._grainAnimated=!1,this._vignetteBlendMode=t.VIGNETTEMODE_MULTIPLY,this._vignetteEnabled=!1,this._applyByPostProcess=!1,this._isEnabled=!0,this.onUpdateParameters=new e.Observable}return Object.defineProperty(t.prototype,"colorCurvesEnabled",{get:function(){ return this._colorCurvesEnabled},set:function(e){this._colorCurvesEnabled!==e&&(this._colorCurvesEnabled=e,this._updateParameters())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"colorGradingEnabled",{get:function(){return this._colorGradingEnabled},set:function(e){this._colorGradingEnabled!==e&&(this._colorGradingEnabled=e,this._updateParameters())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"colorGradingWithGreenDepth",{get:function(){return this._colorGradingWithGreenDepth},set:function(e){this._colorGradingWithGreenDepth!==e&&(this._colorGradingWithGreenDepth=e,this._updateParameters())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"colorGradingBGR",{get:function(){return this._colorGradingBGR},set:function(e){this._colorGradingBGR!==e&&(this._colorGradingBGR=e,this._updateParameters())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"exposure",{get:function(){return this._exposure},set:function(e){this._exposure!==e&&(this._exposure=e,this._updateParameters())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"toneMappingEnabled",{get:function(){return this._toneMappingEnabled},set:function(e){this._toneMappingEnabled!==e&&(this._toneMappingEnabled=e,this._updateParameters())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"contrast",{get:function(){return this._contrast},set:function(e){this._contrast!==e&&(this._contrast=e,this._updateParameters())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"grainEnabled",{get:function(){return this._grainEnabled},set:function(e){this._grainEnabled!==e&&(this._grainEnabled=e,this._updateParameters())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"grainIntensity",{get:function(){return this._grainIntensity},set:function(e){this._grainIntensity!==e&&(this._grainIntensity=e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"grainAnimated",{get:function(){return this._grainAnimated},set:function(e){this._grainAnimated!==e&&(this._grainAnimated=e,this._updateParameters())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"vignetteBlendMode",{get:function(){return this._vignetteBlendMode},set:function(e){this._vignetteBlendMode!==e&&(this._vignetteBlendMode=e,this._updateParameters())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"vignetteEnabled",{get:function(){return this._vignetteEnabled},set:function(e){this._vignetteEnabled!==e&&(this._vignetteEnabled=e,this._updateParameters())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"applyByPostProcess",{get:function(){return this._applyByPostProcess},set:function(e){this._applyByPostProcess!==e&&(this._applyByPostProcess=e,this._updateParameters())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isEnabled",{get:function(){return this._isEnabled},set:function(e){this._isEnabled!==e&&(this._isEnabled=e,this._updateParameters())},enumerable:!0,configurable:!0}),t.prototype._updateParameters=function(){this.onUpdateParameters.notifyObservers(this)},t.prototype.getClassName=function(){return"ImageProcessingConfiguration"},t.PrepareUniforms=function(t,i){i.EXPOSURE&&t.push("exposureLinear"),i.CONTRAST&&t.push("contrast"),i.COLORGRADING&&t.push("colorTransformSettings"),i.VIGNETTE&&(t.push("vInverseScreenSize"),t.push("vignetteSettings1"),t.push("vignetteSettings2")),i.COLORCURVES&&e.ColorCurves.PrepareUniforms(t),i.GRAIN&&(t.push("grainVarianceAmount"),t.push("grainAnimatedSeed"))},t.PrepareSamplers=function(e,t){t.COLORGRADING&&e.push("txColorTransform")},t.prototype.prepareDefines=function(e,i){if(void 0===i&&(i=!1),i!==this.applyByPostProcess||!this._isEnabled)return e.VIGNETTE=!1,e.TONEMAPPING=!1,e.CONTRAST=!1,e.EXPOSURE=!1,e.COLORCURVES=!1,e.COLORGRADING=!1,e.COLORGRADING3D=!1,e.IMAGEPROCESSING=!1,void(e.IMAGEPROCESSINGPOSTPROCESS=this.applyByPostProcess&&this._isEnabled);e.VIGNETTE=this.vignetteEnabled,e.VIGNETTEBLENDMODEMULTIPLY=this.vignetteBlendMode===t._VIGNETTEMODE_MULTIPLY,e.VIGNETTEBLENDMODEOPAQUE=!e.VIGNETTEBLENDMODEMULTIPLY,e.TONEMAPPING=this.toneMappingEnabled,e.CONTRAST=1!==this.contrast,e.EXPOSURE=1!==this.exposure,e.COLORCURVES=this.colorCurvesEnabled&&!!this.colorCurves,e.COLORGRADING=this.colorGradingEnabled&&!!this.colorGradingTexture,e.COLORGRADING?e.COLORGRADING3D=this.colorGradingTexture.is3D:e.COLORGRADING3D=!1,e.SAMPLER3DGREENDEPTH=this.colorGradingWithGreenDepth,e.SAMPLER3DBGRMAP=this.colorGradingBGR,e.IMAGEPROCESSINGPOSTPROCESS=this.applyByPostProcess,e.GRAIN=this.grainEnabled,e.IMAGEPROCESSING=e.VIGNETTE||e.TONEMAPPING||e.CONTRAST||e.EXPOSURE||e.COLORCURVES||e.COLORGRADING||e.GRAIN},t.prototype.isReady=function(){return!this.colorGradingEnabled||!this.colorGradingTexture||this.colorGradingTexture.isReady()},t.prototype.bind=function(t,i){if(void 0===i&&(i=1),this._colorCurvesEnabled&&this.colorCurves&&e.ColorCurves.Bind(this.colorCurves,t),this._vignetteEnabled){var r=1/t.getEngine().getRenderWidth(),n=1/t.getEngine().getRenderHeight();t.setFloat2("vInverseScreenSize",r,n);var o=Math.tan(.5*this.vignetteCameraFov),s=o*i,a=Math.sqrt(s*o);s=e.Tools.Mix(s,a,this.vignetteStretch),o=e.Tools.Mix(o,a,this.vignetteStretch),t.setFloat4("vignetteSettings1",s,o,-s*this.vignetteCentreX,-o*this.vignetteCentreY);var l=-2*this.vignetteWeight;t.setFloat4("vignetteSettings2",this.vignetteColor.r,this.vignetteColor.g,this.vignetteColor.b,l)}if(t.setFloat("exposureLinear",this.exposure),t.setFloat("contrast",this.contrast),this.colorGradingTexture){t.setTexture("txColorTransform",this.colorGradingTexture);var c=this.colorGradingTexture.getSize().height;t.setFloat4("colorTransformSettings",(c-1)/c,.5/c,c,this.colorGradingTexture.level)}t.setFloat("grainVarianceAmount",this.grainIntensity),t.setFloat("grainAnimatedSeed",this.grainAnimated?Math.random()+1:1)},t.prototype.clone=function(){return e.SerializationHelper.Clone((function(){return new t}),this)},t.prototype.serialize=function(){return e.SerializationHelper.Serialize(this)},t.Parse=function(i){return e.SerializationHelper.Parse((function(){return new t}),i,null,null)},Object.defineProperty(t,"VIGNETTEMODE_MULTIPLY",{get:function(){return this._VIGNETTEMODE_MULTIPLY},enumerable:!0,configurable:!0}),Object.defineProperty(t,"VIGNETTEMODE_OPAQUE",{get:function(){return this._VIGNETTEMODE_OPAQUE},enumerable:!0,configurable:!0}),t._VIGNETTEMODE_MULTIPLY=0,t._VIGNETTEMODE_OPAQUE=1,__decorate([e.serializeAsColorCurves()],t.prototype,"colorCurves",void 0),__decorate([e.serialize()],t.prototype,"_colorCurvesEnabled",void 0),__decorate([e.serializeAsTexture()],t.prototype,"colorGradingTexture",void 0),__decorate([e.serialize()],t.prototype,"_colorGradingEnabled",void 0),__decorate([e.serialize()],t.prototype,"_colorGradingWithGreenDepth",void 0),__decorate([e.serialize()],t.prototype,"_colorGradingBGR",void 0),__decorate([e.serialize()],t.prototype,"_exposure",void 0),__decorate([e.serialize()],t.prototype,"_toneMappingEnabled",void 0),__decorate([e.serialize()],t.prototype,"_contrast",void 0),__decorate([e.serialize()],t.prototype,"vignetteStretch",void 0),__decorate([e.serialize()],t.prototype,"vignetteCentreX",void 0),__decorate([e.serialize()],t.prototype,"vignetteCentreY",void 0),__decorate([e.serialize()],t.prototype,"vignetteWeight",void 0),__decorate([e.serializeAsColor4()],t.prototype,"vignetteColor",void 0),__decorate([e.serialize()],t.prototype,"vignetteCameraFov",void 0),__decorate([e.serialize()],t.prototype,"_grainEnabled",void 0),__decorate([e.serialize()],t.prototype,"_grainIntensity",void 0),__decorate([e.serialize()],t.prototype,"_grainAnimated",void 0),__decorate([e.serialize()],t.prototype,"_vignetteBlendMode",void 0),__decorate([e.serialize()],t.prototype,"_vignetteEnabled",void 0),__decorate([e.serialize()],t.prototype,"_applyByPostProcess",void 0),__decorate([e.serialize()],t.prototype,"_isEnabled",void 0),t})();e.ImageProcessingConfiguration=t})(e||(e={}));var e;!(function(e){var t=(function(t){function i(i,r){var n=t.call(this,r)||this;return i?(n._engine=r.getEngine(),n._textureMatrix=e.Matrix.Identity(),n.name=i,n.url=i,n.hasAlpha=!1,n.isCube=!1,n.is3D=n._engine.webGLVersion>1,n.wrapU=e.Texture.CLAMP_ADDRESSMODE,n.wrapV=e.Texture.CLAMP_ADDRESSMODE,n.wrapR=e.Texture.CLAMP_ADDRESSMODE,n.anisotropicFilteringLevel=1,n._texture=n._getFromCache(i,!0),n._texture||(r.useDelayedTextureLoading?n.delayLoadState=e.Engine.DELAYLOADSTATE_NOTLOADED:n.loadTexture()),n):n}return __extends(i,t),i.prototype.getTextureMatrix=function(){return this._textureMatrix},i.prototype.load3dlTexture=function(){var t,r=this._engine;t=1===r.webGLVersion?r.createRawTexture(null,1,1,e.Engine.TEXTUREFORMAT_RGBA,!1,!1,e.Texture.BILINEAR_SAMPLINGMODE):r.createRawTexture3D(null,1,1,1,e.Engine.TEXTUREFORMAT_RGBA,!1,!1,e.Texture.BILINEAR_SAMPLINGMODE),this._texture=t;var n=function(n){if("string"==typeof n){for(var o,s=null,a=null,l=n.split("\n"),c=0,h=0,u=0,f=0,d=0,p=0;p0&&(p+1)%4==0)s[p]=255;else{var b=a[p];s[p]=b/d*255}t.is3D?(t.updateSize(c,c,c),r.updateRawTexture3D(t,s,e.Engine.TEXTUREFORMAT_RGBA,!1)):(t.updateSize(c*c,c),r.updateRawTexture(t,s,e.Engine.TEXTUREFORMAT_RGBA,!1))}},o=this.getScene();return o?o._loadFile(this.url,n):this._engine._loadFile(this.url,n),this._texture},i.prototype.loadTexture=function(){this.url&&this.url.toLocaleLowerCase().indexOf(".3dl")==this.url.length-4&&this.load3dlTexture()},i.prototype.clone=function(){var e=new i(this.url,this.getScene());return e.level=this.level,e},i.prototype.delayLoad=function(){this.delayLoadState===e.Engine.DELAYLOADSTATE_NOTLOADED&&(this.delayLoadState=e.Engine.DELAYLOADSTATE_LOADED,this._texture=this._getFromCache(this.url,!0),this._texture||this.loadTexture())},i.Parse=function(e,t,r){var n=null;return e.name&&!e.isRenderTarget&&(n=new i(e.name,t),n.name=e.name,n.level=e.level),n},i.prototype.serialize=function(){if(!this.name)return null;var e={};return e.name=this.name,e.level=this.level,e.customType="BABYLON.ColorGradingTexture",e},i._noneEmptyLineRegex=/\S+/,i})(e.BaseTexture);e.ColorGradingTexture=t})(e||(e={}));var e;!(function(e){var t=(function(){function t(){this._dirty=!0,this._tempColor=new e.Color4(0,0,0,0),this._globalCurve=new e.Color4(0,0,0,0),this._highlightsCurve=new e.Color4(0,0,0,0),this._midtonesCurve=new e.Color4(0,0,0,0),this._shadowsCurve=new e.Color4(0,0,0,0),this._positiveCurve=new e.Color4(0,0,0,0),this._negativeCurve=new e.Color4(0,0,0,0),this._globalHue=30,this._globalDensity=0,this._globalSaturation=0,this._globalExposure=0,this._highlightsHue=30,this._highlightsDensity=0,this._highlightsSaturation=0,this._highlightsExposure=0,this._midtonesHue=30,this._midtonesDensity=0,this._midtonesSaturation=0,this._midtonesExposure=0,this._shadowsHue=30,this._shadowsDensity=0,this._shadowsSaturation=0,this._shadowsExposure=0}return Object.defineProperty(t.prototype,"globalHue",{get:function(){return this._globalHue},set:function(e){this._globalHue=e,this._dirty=!0},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"globalDensity",{get:function(){return this._globalDensity},set:function(e){this._globalDensity=e,this._dirty=!0},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"globalSaturation",{get:function(){return this._globalSaturation},set:function(e){this._globalSaturation=e,this._dirty=!0},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"highlightsHue",{get:function(){return this._highlightsHue},set:function(e){this._highlightsHue=e,this._dirty=!0},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"highlightsDensity",{get:function(){return this._highlightsDensity},set:function(e){this._highlightsDensity=e,this._dirty=!0},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"highlightsSaturation",{get:function(){return this._highlightsSaturation},set:function(e){this._highlightsSaturation=e,this._dirty=!0},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"highlightsExposure",{get:function(){return this._highlightsExposure},set:function(e){this._highlightsExposure=e,this._dirty=!0},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"midtonesHue",{get:function(){return this._midtonesHue},set:function(e){this._midtonesHue=e,this._dirty=!0},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"midtonesDensity",{get:function(){return this._midtonesDensity},set:function(e){this._midtonesDensity=e,this._dirty=!0},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"midtonesSaturation",{get:function(){return this._midtonesSaturation},set:function(e){this._midtonesSaturation=e,this._dirty=!0},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"midtonesExposure",{get:function(){return this._midtonesExposure},set:function(e){this._midtonesExposure=e,this._dirty=!0},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"shadowsHue",{get:function(){return this._shadowsHue},set:function(e){this._shadowsHue=e,this._dirty=!0},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"shadowsDensity",{get:function(){return this._shadowsDensity},set:function(e){this._shadowsDensity=e,this._dirty=!0},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"shadowsSaturation",{get:function(){return this._shadowsSaturation},set:function(e){this._shadowsSaturation=e,this._dirty=!0},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"shadowsExposure",{get:function(){return this._shadowsExposure},set:function(e){this._shadowsExposure=e,this._dirty=!0},enumerable:!0,configurable:!0}),t.prototype.getClassName=function(){return"ColorCurves"},t.Bind=function(e,t,i,r,n){void 0===i&&(i="vCameraColorCurvePositive"),void 0===r&&(r="vCameraColorCurveNeutral"),void 0===n&&(n="vCameraColorCurveNegative"),e._dirty&&(e._dirty=!1,e.getColorGradingDataToRef(e._globalHue,e._globalDensity,e._globalSaturation,e._globalExposure,e._globalCurve),e.getColorGradingDataToRef(e._highlightsHue,e._highlightsDensity,e._highlightsSaturation,e._highlightsExposure,e._tempColor),e._tempColor.multiplyToRef(e._globalCurve,e._highlightsCurve),e.getColorGradingDataToRef(e._midtonesHue,e._midtonesDensity,e._midtonesSaturation,e._midtonesExposure,e._tempColor),e._tempColor.multiplyToRef(e._globalCurve,e._midtonesCurve),e.getColorGradingDataToRef(e._shadowsHue,e._shadowsDensity,e._shadowsSaturation,e._shadowsExposure,e._tempColor),e._tempColor.multiplyToRef(e._globalCurve,e._shadowsCurve),e._highlightsCurve.subtractToRef(e._midtonesCurve,e._positiveCurve),e._midtonesCurve.subtractToRef(e._shadowsCurve,e._negativeCurve)),t&&(t.setFloat4(i,e._positiveCurve.r,e._positiveCurve.g,e._positiveCurve.b,e._positiveCurve.a),t.setFloat4(r,e._midtonesCurve.r,e._midtonesCurve.g,e._midtonesCurve.b,e._midtonesCurve.a),t.setFloat4(n,e._negativeCurve.r,e._negativeCurve.g,e._negativeCurve.b,e._negativeCurve.a))},t.PrepareUniforms=function(e){e.push("vCameraColorCurveNeutral","vCameraColorCurvePositive","vCameraColorCurveNegative")},t.prototype.getColorGradingDataToRef=function(e,i,r,n,o){null!=e&&(e=t.clamp(e,0,360),i=t.clamp(i,-100,100),r=t.clamp(r,-100,100),n=t.clamp(n,-100,100),i=t.applyColorGradingSliderNonlinear(i),i*=.5,n=t.applyColorGradingSliderNonlinear(n),i<0&&(i*=-1,e=(e+180)%360),t.fromHSBToRef(e,i,50+.25*n,o),o.scaleToRef(2,o),o.a=1+.01*r)},t.applyColorGradingSliderNonlinear=function(e){e/=100;var t=Math.abs(e);return t=Math.pow(t,2),e<0&&(t*=-1),t*=100},t.fromHSBToRef=function(e,i,r,n){var o=t.clamp(e,0,360),s=t.clamp(i/100,0,1),a=t.clamp(r/100,0,1);if(0===s)n.r=a,n.g=a,n.b=a;else{o/=60;var l=Math.floor(o),c=o-l,h=a*(1-s),u=a*(1-s*c),f=a*(1-s*(1-c));switch(l){case 0:n.r=a,n.g=f,n.b=h;break;case 1:n.r=u,n.g=a,n.b=h;break;case 2:n.r=h,n.g=a,n.b=f;break;case 3:n.r=h,n.g=u,n.b=a;break;case 4:n.r=f,n.g=h,n.b=a;break;default:n.r=a,n.g=h,n.b=u}}n.a=1},t.clamp=function(e,t,i){return Math.min(Math.max(e,t),i)},t.prototype.clone=function(){return e.SerializationHelper.Clone((function(){return new t}),this)},t.prototype.serialize=function(){return e.SerializationHelper.Serialize(this)},t.Parse=function(i){return e.SerializationHelper.Parse((function(){return new t}),i,null,null)},__decorate([e.serialize()],t.prototype,"_globalHue",void 0),__decorate([e.serialize()],t.prototype,"_globalDensity",void 0),__decorate([e.serialize()],t.prototype,"_globalSaturation",void 0),__decorate([e.serialize()],t.prototype,"_globalExposure",void 0),__decorate([e.serialize()],t.prototype,"_highlightsHue",void 0),__decorate([e.serialize()],t.prototype,"_highlightsDensity",void 0),__decorate([e.serialize()],t.prototype,"_highlightsSaturation",void 0),__decorate([e.serialize()],t.prototype,"_highlightsExposure",void 0),__decorate([e.serialize()],t.prototype,"_midtonesHue",void 0),__decorate([e.serialize()],t.prototype,"_midtonesDensity",void 0),__decorate([e.serialize()],t.prototype,"_midtonesSaturation",void 0),__decorate([e.serialize()],t.prototype,"_midtonesExposure",void 0),t})();e.ColorCurves=t})(e||(e={}));var e;!(function(e){var t=(function(){function t(){}return t.BindEyePosition=function(e,t){if(t._forcedViewPosition)return void e.setVector3("vEyePosition",t._forcedViewPosition);e.setVector3("vEyePosition",t._mirroredCameraPosition?t._mirroredCameraPosition:t.activeCamera.globalPosition)},t.PrepareDefinesForMergedUV=function(e,t,i){t._needUVs=!0,t[i]=!0,e.getTextureMatrix().isIdentity(!0)?(t[i+"DIRECTUV"]=e.coordinatesIndex+1,0===e.coordinatesIndex?t.MAINUV1=!0:t.MAINUV2=!0):t[i+"DIRECTUV"]=0},t.BindTextureMatrix=function(e,t,i){var r=e.getTextureMatrix();r.isIdentity(!0)||t.updateMatrix(i+"Matrix",r)},t.PrepareDefinesForMisc=function(t,i,r,n,o,s,a){a._areMiscDirty&&(a.LOGARITHMICDEPTH=r,a.POINTSIZE=n||i.forcePointsCloud,a.FOG=i.fogEnabled&&t.applyFog&&i.fogMode!==e.Scene.FOGMODE_NONE&&o,a.NONUNIFORMSCALING=t.nonUniformScaling,a.ALPHATEST=s)},t.PrepareDefinesForFrameBoundValues=function(e,t,i,r,n){void 0===n&&(n=null);var o=!1;null==n&&(n=void 0!==e.clipPlane&&null!==e.clipPlane),i.CLIPPLANE!==n&&(i.CLIPPLANE=n,o=!0),i.DEPTHPREPASS!==!t.getColorWrite()&&(i.DEPTHPREPASS=!i.DEPTHPREPASS,o=!0),i.INSTANCES!==r&&(i.INSTANCES=r,o=!0),o&&i.markAsUnprocessed()},t.PrepareDefinesForAttributes=function(t,i,r,n,o,s){if(void 0===o&&(o=!1),void 0===s&&(s=!0),!i._areAttributesDirty&&i._needNormals===i._normals&&i._needUVs===i._uvs)return!1;if(i._normals=i._needNormals,i._uvs=i._needUVs,i.NORMAL=i._needNormals&&t.isVerticesDataPresent(e.VertexBuffer.NormalKind),i._needNormals&&t.isVerticesDataPresent(e.VertexBuffer.TangentKind)&&(i.TANGENT=!0),i._needUVs?(i.UV1=t.isVerticesDataPresent(e.VertexBuffer.UVKind),i.UV2=t.isVerticesDataPresent(e.VertexBuffer.UV2Kind)):(i.UV1=!1,i.UV2=!1),r){var a=t.useVertexColors&&t.isVerticesDataPresent(e.VertexBuffer.ColorKind);i.VERTEXCOLOR=a,i.VERTEXALPHA=t.hasVertexAlpha&&a&&s}if(n&&(t.useBones&&t.computeBonesUsingShaders&&t.skeleton?(i.NUM_BONE_INFLUENCERS=t.numBoneInfluencers,i.BonesPerMesh=t.skeleton.bones.length+1):(i.NUM_BONE_INFLUENCERS=0,i.BonesPerMesh=0)),o){var l=t.morphTargetManager;l?(i.MORPHTARGETS_TANGENT=l.supportsTangents&&i.TANGENT,i.MORPHTARGETS_NORMAL=l.supportsNormals&&i.NORMAL,i.MORPHTARGETS=l.numInfluencers>0,i.NUM_MORPH_INFLUENCERS=l.numInfluencers):(i.MORPHTARGETS_TANGENT=!1,i.MORPHTARGETS_NORMAL=!1,i.MORPHTARGETS=!1,i.NUM_MORPH_INFLUENCERS=0)}return!0},t.PrepareDefinesForLights=function(t,i,r,n,o,s){if(void 0===o&&(o=4),void 0===s&&(s=!1),!r._areLightsDirty)return r._needNormals;var a=0,l=!1,c=!1,h=!1,u=!1,f=!1;if(t.lightsEnabled&&!s)for(var d=0,p=i._lightSources;d0&&(n=r+o,t.addFallback(n,"LIGHT"+o)),e.SHADOWS||(e["SHADOW"+o]&&t.addFallback(r,"SHADOW"+o),e["SHADOWPCF"+o]&&t.addFallback(r,"SHADOWPCF"+o),e["SHADOWESM"+o]&&t.addFallback(r,"SHADOWESM"+o));return n++},t.PrepareAttributesForMorphTargets=function(t,i,r){var n=r.NUM_MORPH_INFLUENCERS;if(n>0&&e.Engine.LastCreatedEngine)for(var o=e.Engine.LastCreatedEngine.getCaps().maxVertexAttribs,s=i.morphTargetManager,a=s&&s.supportsNormals&&r.NORMAL,l=s&&s.supportsTangents&&r.TANGENT,c=0;co&&e.Tools.Error("Cannot add more vertex attributes for mesh "+i.name)},t.PrepareAttributesForBones=function(t,i,r,n){r.NUM_BONE_INFLUENCERS>0&&(n.addCPUSkinningFallback(0,i),t.push(e.VertexBuffer.MatricesIndicesKind),t.push(e.VertexBuffer.MatricesWeightsKind),r.NUM_BONE_INFLUENCERS>4&&(t.push(e.VertexBuffer.MatricesIndicesExtraKind),t.push(e.VertexBuffer.MatricesWeightsExtraKind)))},t.PrepareAttributesForInstances=function(e,t){t.INSTANCES&&(e.push("world0"),e.push("world1"),e.push("world2"),e.push("world3"))},t.BindLightShadow=function(e,t,i,r,n){if(e.shadowEnabled&&i.receiveShadows){var o=e.getShadowGenerator();o&&o.bindShadowLight(r,n)}},t.BindLightProperties=function(e,t,i){e.transferToEffect(t,i+"")},t.BindLights=function(i,r,n,o,s,a){void 0===s&&(s=4),void 0===a&&(a=!1);for(var l=Math.min(r._lightSources.length,s),c=0;c0,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")}a.USE_LOCAL_REFLECTIONMAP_CUBIC=!!this._reflectionTexture.boundingBoxSize}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,a.OBJECTSPACE_NORMALMAP=this._useObjectSpaceNormalMap}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,this._shouldTurnAlphaTestOn(i),a),e.MaterialHelper.PrepareDefinesForAttributes(i,a,!0,!0,!0),e.MaterialHelper.PrepareDefinesForFrameBoundValues(s,l,a,o),a.isDirty){a.markAsProcessed(),s.resetCachedMaterial();var c=new e.EffectFallbacks;a.REFLECTION&&c.addFallback(0,"REFLECTION"),a.SPECULAR&&c.addFallback(0,"SPECULAR"),a.BUMP&&c.addFallback(0,"BUMP"),a.PARALLAX&&c.addFallback(1,"PARALLAX"),a.PARALLAXOCCLUSION&&c.addFallback(0,"PARALLAXOCCLUSION"),a.SPECULAROVERALPHA&&c.addFallback(0,"SPECULAROVERALPHA"),a.FOG&&c.addFallback(1,"FOG"),a.POINTSIZE&&c.addFallback(0,"POINTSIZE"),a.LOGARITHMICDEPTH&&c.addFallback(0,"LOGARITHMICDEPTH"),e.MaterialHelper.HandleFallbacksForShadows(a,c,this._maxSimultaneousLights),a.SPECULARTERM&&c.addFallback(0,"SPECULARTERM"),a.DIFFUSEFRESNEL&&c.addFallback(1,"DIFFUSEFRESNEL"),a.OPACITYFRESNEL&&c.addFallback(2,"OPACITYFRESNEL"),a.REFLECTIONFRESNEL&&c.addFallback(3,"REFLECTIONFRESNEL"),a.EMISSIVEFRESNEL&&c.addFallback(4,"EMISSIVEFRESNEL"),a.FRESNEL&&c.addFallback(4,"FRESNEL");var h=[e.VertexBuffer.PositionKind];a.NORMAL&&h.push(e.VertexBuffer.NormalKind),a.UV1&&h.push(e.VertexBuffer.UVKind),a.UV2&&h.push(e.VertexBuffer.UV2Kind),a.VERTEXCOLOR&&h.push(e.VertexBuffer.ColorKind),e.MaterialHelper.PrepareAttributesForBones(h,i,a,c),e.MaterialHelper.PrepareAttributesForInstances(h,a),e.MaterialHelper.PrepareAttributesForMorphTargets(h,i,a);var u="default",f=["world","view","viewProjection","vEyePosition","vLightsType","vAmbientColor","vDiffuseColor","vSpecularColor","vEmissiveColor","vFogInfos","vFogColor","pointSize","vDiffuseInfos","vAmbientInfos","vOpacityInfos","vReflectionInfos","vEmissiveInfos","vSpecularInfos","vBumpInfos","vLightmapInfos","vRefractionInfos","mBones","vClipPlane","diffuseMatrix","ambientMatrix","opacityMatrix","reflectionMatrix","emissiveMatrix","specularMatrix","bumpMatrix","normalMatrix","lightmapMatrix","refractionMatrix","diffuseLeftColor","diffuseRightColor","opacityParts","reflectionLeftColor","reflectionRightColor","emissiveLeftColor","emissiveRightColor","refractionLeftColor","refractionRightColor","vReflectionPosition","vReflectionSize","logarithmicDepthConstant","vTangentSpaceParams"],d=["diffuseSampler","ambientSampler","opacitySampler","reflectionCubeSampler","reflection2DSampler","emissiveSampler","specularSampler","bumpSampler","lightmapSampler","refractionCubeSampler","refraction2DSampler"],p=["Material","Scene"];e.ImageProcessingConfiguration.PrepareUniforms(f,a),e.ImageProcessingConfiguration.PrepareSamplers(d,a),e.MaterialHelper.PrepareUniformsAndSamplersList({uniformsNames:f,uniformBuffersNames:p,samplers:d,defines:a,maxSimultaneousLights:this._maxSimultaneousLights}),this.customShaderNameResolve&&(u=this.customShaderNameResolve(u,f,p,d,a));var _=a.toString();n.setEffect(s.getEngine().createEffect(u,{attributes:h,uniformsNames:f,uniformBuffersNames:p,samplers:d,defines:_,fallbacks:c,onCompiled:this.onCompiled,onError:this.onError,indexParameters:{maxSimultaneousLights:this._maxSimultaneousLights,maxSimultaneousMorphTargets:a.NUM_MORPH_INFLUENCERS}},l),a),this.buildUniformLayout()}return!(!n.effect||!n.effect.isReady())&&(a._renderId=s.getRenderId(),this._wasPreviouslyReady=!0,!0)},r.prototype.buildUniformLayout=function(){this._uniformBuffer.addUniform("diffuseLeftColor",4),this._uniformBuffer.addUniform("diffuseRightColor",4),this._uniformBuffer.addUniform("opacityParts",4),this._uniformBuffer.addUniform("reflectionLeftColor",4),this._uniformBuffer.addUniform("reflectionRightColor",4),this._uniformBuffer.addUniform("refractionLeftColor",4),this._uniformBuffer.addUniform("refractionRightColor",4),this._uniformBuffer.addUniform("emissiveLeftColor",4),this._uniformBuffer.addUniform("emissiveRightColor",4),this._uniformBuffer.addUniform("vDiffuseInfos",2),this._uniformBuffer.addUniform("vAmbientInfos",2),this._uniformBuffer.addUniform("vOpacityInfos",2),this._uniformBuffer.addUniform("vReflectionInfos",2),this._uniformBuffer.addUniform("vReflectionPosition",3),this._uniformBuffer.addUniform("vReflectionSize",3),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),s.OBJECTSPACE_NORMALMAP&&(t.toNormalMatrix(this._normalMatrix),this.bindOnlyNormalMatrix(this._normalMatrix));var l=this._mustRebind(o,a,i.visibility);if(e.MaterialHelper.BindBonesParameters(i,a),l){if(this._uniformBuffer.bindToEffect(a,"Material"),this.bindViewProjection(a),!this._uniformBuffer.useUbo||!this.isFrozen||!this._uniformBuffer.isSync){if(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){if(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._reflectionTexture.boundingBoxSize)){var c=this._reflectionTexture;this._uniformBuffer.updateVector3("vReflectionPosition",c.boundingBoxPosition),this._uniformBuffer.updateVector3("vReflectionSize",c.boundingBoxSize)}if(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 h=1;this._refractionTexture.isCube||(this._uniformBuffer.updateMatrix("refractionMatrix",this._refractionTexture.getReflectionTextureMatrix()),this._refractionTexture.depth&&(h=this._refractionTexture.depth)),this._uniformBuffer.updateFloat4("vRefractionInfos",this._refractionTexture.level,this.indexOfRefraction,h,this.invertRefractionY?-1:1)}}this.pointsCloud&&this._uniformBuffer.updateFloat("pointSize",this.pointSize),s.SPECULARTERM&&this._uniformBuffer.updateColor4("vSpecularColor",this.specularColor,this.specularPower),this._uniformBuffer.updateColor3("vEmissiveColor",this.emissiveColor),this._uniformBuffer.updateColor4("vDiffuseColor",this.diffuseColor,this.alpha*i.visibility)}if(o.texturesEnabled&&(this._diffuseTexture&&r.DiffuseTextureEnabled&&a.setTexture("diffuseSampler",this._diffuseTexture),this._ambientTexture&&r.AmbientTextureEnabled&&a.setTexture("ambientSampler",this._ambientTexture),this._opacityTexture&&r.OpacityTextureEnabled&&a.setTexture("opacitySampler",this._opacityTexture),this._reflectionTexture&&r.ReflectionTextureEnabled&&(this._reflectionTexture.isCube?a.setTexture("reflectionCubeSampler",this._reflectionTexture):a.setTexture("reflection2DSampler",this._reflectionTexture)),this._emissiveTexture&&r.EmissiveTextureEnabled&&a.setTexture("emissiveSampler",this._emissiveTexture),this._lightmapTexture&&r.LightmapTextureEnabled&&a.setTexture("lightmapSampler",this._lightmapTexture),this._specularTexture&&r.SpecularTextureEnabled&&a.setTexture("specularSampler",this._specularTexture),this._bumpTexture&&o.getEngine().getCaps().standardDerivatives&&r.BumpTextureEnabled&&a.setTexture("bumpSampler",this._bumpTexture),this._refractionTexture&&r.RefractionTextureEnabled)){var h=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)}!l&&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,__decorate([e.serializeAsTexture("diffuseTexture")],r.prototype,"_diffuseTexture",void 0),__decorate([e.expandToProperty("_markAllSubMeshesAsTexturesAndMiscDirty")],r.prototype,"diffuseTexture",void 0),__decorate([e.serializeAsTexture("ambientTexture")],r.prototype,"_ambientTexture",void 0),__decorate([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"ambientTexture",void 0),__decorate([e.serializeAsTexture("opacityTexture")],r.prototype,"_opacityTexture",void 0),__decorate([e.expandToProperty("_markAllSubMeshesAsTexturesAndMiscDirty")],r.prototype,"opacityTexture",void 0),__decorate([e.serializeAsTexture("reflectionTexture")],r.prototype,"_reflectionTexture",void 0),__decorate([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"reflectionTexture",void 0),__decorate([e.serializeAsTexture("emissiveTexture")],r.prototype,"_emissiveTexture",void 0),__decorate([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"emissiveTexture",void 0),__decorate([e.serializeAsTexture("specularTexture")],r.prototype,"_specularTexture",void 0),__decorate([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"specularTexture",void 0),__decorate([e.serializeAsTexture("bumpTexture")],r.prototype,"_bumpTexture",void 0),__decorate([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"bumpTexture",void 0),__decorate([e.serializeAsTexture("lightmapTexture")],r.prototype,"_lightmapTexture",void 0),__decorate([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"lightmapTexture",void 0),__decorate([e.serializeAsTexture("refractionTexture")],r.prototype,"_refractionTexture",void 0),__decorate([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"refractionTexture",void 0),__decorate([e.serializeAsColor3("ambient")],r.prototype,"ambientColor",void 0),__decorate([e.serializeAsColor3("diffuse")],r.prototype,"diffuseColor",void 0),__decorate([e.serializeAsColor3("specular")],r.prototype,"specularColor",void 0),__decorate([e.serializeAsColor3("emissive")],r.prototype,"emissiveColor",void 0),__decorate([e.serialize()],r.prototype,"specularPower",void 0),__decorate([e.serialize("useAlphaFromDiffuseTexture")],r.prototype,"_useAlphaFromDiffuseTexture",void 0),__decorate([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"useAlphaFromDiffuseTexture",void 0),__decorate([e.serialize("useEmissiveAsIllumination")],r.prototype,"_useEmissiveAsIllumination",void 0),__decorate([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"useEmissiveAsIllumination",void 0),__decorate([e.serialize("linkEmissiveWithDiffuse")],r.prototype,"_linkEmissiveWithDiffuse",void 0),__decorate([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"linkEmissiveWithDiffuse",void 0),__decorate([e.serialize("useSpecularOverAlpha")],r.prototype,"_useSpecularOverAlpha",void 0),__decorate([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"useSpecularOverAlpha",void 0),__decorate([e.serialize("useReflectionOverAlpha")],r.prototype,"_useReflectionOverAlpha",void 0),__decorate([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"useReflectionOverAlpha",void 0),__decorate([e.serialize("disableLighting")],r.prototype,"_disableLighting",void 0),__decorate([e.expandToProperty("_markAllSubMeshesAsLightsDirty")],r.prototype,"disableLighting",void 0),__decorate([e.serialize("useObjectSpaceNormalMap")],r.prototype,"_useObjectSpaceNormalMap",void 0),__decorate([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"useObjectSpaceNormalMap",void 0),__decorate([e.serialize("useParallax")],r.prototype,"_useParallax",void 0),__decorate([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"useParallax",void 0),__decorate([e.serialize("useParallaxOcclusion")],r.prototype,"_useParallaxOcclusion",void 0),__decorate([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"useParallaxOcclusion",void 0),__decorate([e.serialize()],r.prototype,"parallaxScaleBias",void 0),__decorate([e.serialize("roughness")],r.prototype,"_roughness",void 0),__decorate([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"roughness",void 0),__decorate([e.serialize()],r.prototype,"indexOfRefraction",void 0),__decorate([e.serialize()],r.prototype,"invertRefractionY",void 0),__decorate([e.serialize("useLightmapAsShadowmap")],r.prototype,"_useLightmapAsShadowmap",void 0),__decorate([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"useLightmapAsShadowmap",void 0),__decorate([e.serializeAsFresnelParameters("diffuseFresnelParameters")],r.prototype,"_diffuseFresnelParameters",void 0),__decorate([e.expandToProperty("_markAllSubMeshesAsFresnelDirty")],r.prototype,"diffuseFresnelParameters",void 0),__decorate([e.serializeAsFresnelParameters("opacityFresnelParameters")],r.prototype,"_opacityFresnelParameters",void 0),__decorate([e.expandToProperty("_markAllSubMeshesAsFresnelAndMiscDirty")],r.prototype,"opacityFresnelParameters",void 0),__decorate([e.serializeAsFresnelParameters("reflectionFresnelParameters")],r.prototype,"_reflectionFresnelParameters",void 0),__decorate([e.expandToProperty("_markAllSubMeshesAsFresnelDirty")],r.prototype,"reflectionFresnelParameters",void 0),__decorate([e.serializeAsFresnelParameters("refractionFresnelParameters")],r.prototype,"_refractionFresnelParameters",void 0),__decorate([e.expandToProperty("_markAllSubMeshesAsFresnelDirty")],r.prototype,"refractionFresnelParameters",void 0),__decorate([e.serializeAsFresnelParameters("emissiveFresnelParameters")],r.prototype,"_emissiveFresnelParameters",void 0),__decorate([e.expandToProperty("_markAllSubMeshesAsFresnelDirty")],r.prototype,"emissiveFresnelParameters",void 0),__decorate([e.serialize("useReflectionFresnelFromSpecular")],r.prototype,"_useReflectionFresnelFromSpecular",void 0),__decorate([e.expandToProperty("_markAllSubMeshesAsFresnelDirty")],r.prototype,"useReflectionFresnelFromSpecular",void 0),__decorate([e.serialize("useGlossinessFromSpecularMapAlpha")],r.prototype,"_useGlossinessFromSpecularMapAlpha",void 0),__decorate([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"useGlossinessFromSpecularMapAlpha",void 0),__decorate([e.serialize("maxSimultaneousLights")],r.prototype,"_maxSimultaneousLights",void 0),__decorate([e.expandToProperty("_markAllSubMeshesAsLightsDirty")],r.prototype,"maxSimultaneousLights",void 0), __decorate([e.serialize("invertNormalMapX")],r.prototype,"_invertNormalMapX",void 0),__decorate([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"invertNormalMapX",void 0),__decorate([e.serialize("invertNormalMapY")],r.prototype,"_invertNormalMapY",void 0),__decorate([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"invertNormalMapY",void 0),__decorate([e.serialize("twoSidedLighting")],r.prototype,"_twoSidedLighting",void 0),__decorate([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"twoSidedLighting",void 0),__decorate([e.serialize()],r.prototype,"useLogarithmicDepth",null),r})(e.PushMaterial);e.StandardMaterial=i})(e||(e={}));var e;!(function(e){var i=(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.OBJECTSPACE_NORMALMAP=!1,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.USE_LOCAL_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.GRAIN=!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 __extends(t,e),t.prototype.reset=function(){e.prototype.reset.call(this),this.ALPHATESTVALUE=.5,this.PBR=!0},t})(e.MaterialDefines),r=(function(r){function n(t,i){var n=r.call(this,t,i)||this;return n._directIntensity=1,n._emissiveIntensity=1,n._environmentIntensity=1,n._specularIntensity=1,n._lightingInfos=new e.Vector4(n._directIntensity,n._emissiveIntensity,n._environmentIntensity,n._specularIntensity),n._disableBumpMap=!1,n._ambientTextureStrength=1,n._ambientColor=new e.Color3(0,0,0),n._albedoColor=new e.Color3(1,1,1),n._reflectivityColor=new e.Color3(1,1,1),n._reflectionColor=new e.Color3(1,1,1),n._emissiveColor=new e.Color3(0,0,0),n._microSurface=.9,n._indexOfRefraction=.66,n._invertRefractionY=!1,n._linkRefractionWithTransparency=!1,n._useLightmapAsShadowmap=!1,n._useHorizonOcclusion=!0,n._useRadianceOcclusion=!0,n._useAlphaFromAlbedoTexture=!1,n._useSpecularOverAlpha=!0,n._useMicroSurfaceFromReflectivityMapAlpha=!1,n._useRoughnessFromMetallicTextureAlpha=!0,n._useRoughnessFromMetallicTextureGreen=!1,n._useMetallnessFromMetallicTextureBlue=!1,n._useAmbientOcclusionFromMetallicTextureRed=!1,n._useAmbientInGrayScale=!1,n._useAutoMicroSurfaceFromReflectivityMap=!1,n._usePhysicalLightFalloff=!0,n._useRadianceOverAlpha=!0,n._useObjectSpaceNormalMap=!1,n._useParallax=!1,n._useParallaxOcclusion=!1,n._parallaxScaleBias=.05,n._disableLighting=!1,n._maxSimultaneousLights=4,n._invertNormalMapX=!1,n._invertNormalMapY=!1,n._twoSidedLighting=!1,n._alphaCutOff=.4,n._forceAlphaTest=!1,n._useAlphaFresnel=!1,n._useLinearAlphaFresnel=!1,n._transparencyMode=null,n._environmentBRDFTexture=null,n._forceIrradianceInFragment=!1,n._forceNormalForward=!1,n._renderTargets=new e.SmartArray(16),n._globalAmbientColor=new e.Color3(0,0,0),n._attachImageProcessingConfiguration(null),n.getRenderTargetTextures=function(){return n._renderTargets.reset(),e.StandardMaterial.ReflectionTextureEnabled&&n._reflectionTexture&&n._reflectionTexture.isRenderTarget&&n._renderTargets.push(n._reflectionTexture),e.StandardMaterial.RefractionTextureEnabled&&n._refractionTexture&&n._refractionTexture.isRenderTarget&&n._renderTargets.push(n._refractionTexture),n._renderTargets},n._environmentBRDFTexture=e.TextureTools.GetEnvironmentBRDFTexture(i),n}return __extends(n,r),n.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()})))},n.prototype.getClassName=function(){return"PBRBaseMaterial"},Object.defineProperty(n.prototype,"useLogarithmicDepth",{get:function(){return this._useLogarithmicDepth},set:function(e){this._useLogarithmicDepth=e&&this.getScene().getEngine().getCaps().fragmentDepthSupported},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"transparencyMode",{get:function(){return this._transparencyMode},set:function(t){this._transparencyMode!==t&&(this._transparencyMode=t,this._forceAlphaTest=t===e.PBRMaterial.PBRMATERIAL_ALPHATESTANDBLEND,this._markAllSubMeshesAsTexturesAndMiscDirty())},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"_disableAlphaBlending",{get:function(){return this._linkRefractionWithTransparency||this._transparencyMode===e.PBRMaterial.PBRMATERIAL_OPAQUE||this._transparencyMode===e.PBRMaterial.PBRMATERIAL_ALPHATEST},enumerable:!0,configurable:!0}),n.prototype.needAlphaBlending=function(){return!this._disableAlphaBlending&&(this.alpha<1||null!=this._opacityTexture||this._shouldUseAlphaFromAlbedoTexture())},n.prototype.needAlphaBlendingForMesh=function(e){return!this._disableAlphaBlending&&r.prototype.needAlphaBlendingForMesh.call(this,e)},n.prototype.needAlphaTesting=function(){return!!this._forceAlphaTest||!this._linkRefractionWithTransparency&&(null!=this._albedoTexture&&this._albedoTexture.hasAlpha&&(null==this._transparencyMode||this._transparencyMode===e.PBRMaterial.PBRMATERIAL_ALPHATEST))},n.prototype._shouldUseAlphaFromAlbedoTexture=function(){return null!=this._albedoTexture&&this._albedoTexture.hasAlpha&&this._useAlphaFromAlbedoTexture&&this._transparencyMode!==e.PBRMaterial.PBRMATERIAL_OPAQUE},n.prototype.getAlphaTestTexture=function(){return this._albedoTexture},n.prototype.isReadyForSubMesh=function(t,r,n){if(r.effect&&this.isFrozen&&this._wasPreviouslyReady)return!0;r._materialDefines||(r._materialDefines=new i);var o=r._materialDefines;if(!this.checkReadyOnEveryCall&&r.effect&&o._renderId===this.getScene().getRenderId())return!0;var s=this.getScene(),a=s.getEngine();if(o._areTexturesDirty&&s.texturesEnabled){if(this._albedoTexture&&e.StandardMaterial.DiffuseTextureEnabled&&!this._albedoTexture.isReadyOrNotBlocking())return!1;if(this._ambientTexture&&e.StandardMaterial.AmbientTextureEnabled&&!this._ambientTexture.isReadyOrNotBlocking())return!1;if(this._opacityTexture&&e.StandardMaterial.OpacityTextureEnabled&&!this._opacityTexture.isReadyOrNotBlocking())return!1;var l=this._getReflectionTexture();if(l&&e.StandardMaterial.ReflectionTextureEnabled&&!l.isReadyOrNotBlocking())return!1;if(this._lightmapTexture&&e.StandardMaterial.LightmapTextureEnabled&&!this._lightmapTexture.isReadyOrNotBlocking())return!1;if(this._emissiveTexture&&e.StandardMaterial.EmissiveTextureEnabled&&!this._emissiveTexture.isReadyOrNotBlocking())return!1;if(e.StandardMaterial.SpecularTextureEnabled){if(this._metallicTexture){if(!this._metallicTexture.isReadyOrNotBlocking())return!1}else if(this._reflectivityTexture&&!this._reflectivityTexture.isReadyOrNotBlocking())return!1;if(this._microSurfaceTexture&&!this._microSurfaceTexture.isReadyOrNotBlocking())return!1}if(a.getCaps().standardDerivatives&&this._bumpTexture&&e.StandardMaterial.BumpTextureEnabled&&!this._disableBumpMap&&!this._bumpTexture.isReady())return!1;var c=this._getRefractionTexture();if(c&&e.StandardMaterial.RefractionTextureEnabled&&!c.isReadyOrNotBlocking())return!1;if(this._environmentBRDFTexture&&e.StandardMaterial.ReflectionTextureEnabled&&!this._environmentBRDFTexture.isReady())return!1}if(o._areImageProcessingDirty&&!this._imageProcessingConfiguration.isReady())return!1;if(!a.getCaps().standardDerivatives){var h=null;"InstancedMesh"===t.getClassName()?h=t.sourceMesh:"Mesh"===t.getClassName()&&(h=t),h&&h.geometry&&h.geometry.isReady()&&!h.geometry.isVerticesDataPresent(e.VertexBuffer.NormalKind)&&(h.createNormals(!0),e.Tools.Warn("PBRMaterial: Normals have been created for the mesh: "+h.name))}var u=this._prepareEffect(t,o,this.onCompiled,this.onError,n);return u&&(s.resetCachedMaterial(),r.setEffect(u,o),this.buildUniformLayout()),!(!r.effect||!r.effect.isReady())&&(o._renderId=s.getRenderId(),this._wasPreviouslyReady=!0,!0)},n.prototype.isMetallicWorkflow=function(){return!(null==this._metallic&&null==this._roughness&&!this._metallicTexture)},n.prototype._prepareEffect=function(t,i,r,n,o,s){if(void 0===r&&(r=null),void 0===n&&(n=null),void 0===o&&(o=null),void 0===s&&(s=null),this._prepareDefines(t,i,o,s),!i.isDirty)return null;i.markAsProcessed();var a=this.getScene(),l=a.getEngine(),c=new e.EffectFallbacks,h=0;i.USESPHERICALINVERTEX&&c.addFallback(h++,"USESPHERICALINVERTEX"),i.FOG&&c.addFallback(h,"FOG"),i.POINTSIZE&&c.addFallback(h,"POINTSIZE"),i.LOGARITHMICDEPTH&&c.addFallback(h,"LOGARITHMICDEPTH"),i.PARALLAX&&c.addFallback(h,"PARALLAX"),i.PARALLAXOCCLUSION&&c.addFallback(h++,"PARALLAXOCCLUSION"),i.ENVIRONMENTBRDF&&c.addFallback(h++,"ENVIRONMENTBRDF"),i.TANGENT&&c.addFallback(h++,"TANGENT"),i.BUMP&&c.addFallback(h++,"BUMP"),h=e.MaterialHelper.HandleFallbacksForShadows(i,c,this._maxSimultaneousLights,h++),i.SPECULARTERM&&c.addFallback(h++,"SPECULARTERM"),i.USESPHERICALFROMREFLECTIONMAP&&c.addFallback(h++,"USESPHERICALFROMREFLECTIONMAP"),i.LIGHTMAP&&c.addFallback(h++,"LIGHTMAP"),i.NORMAL&&c.addFallback(h++,"NORMAL"),i.AMBIENT&&c.addFallback(h++,"AMBIENT"),i.EMISSIVE&&c.addFallback(h++,"EMISSIVE"),i.VERTEXCOLOR&&c.addFallback(h++,"VERTEXCOLOR"),i.NUM_BONE_INFLUENCERS>0&&c.addCPUSkinningFallback(h++,t),i.MORPHTARGETS&&c.addFallback(h++,"MORPHTARGETS");var u=[e.VertexBuffer.PositionKind];i.NORMAL&&u.push(e.VertexBuffer.NormalKind),i.TANGENT&&u.push(e.VertexBuffer.TangentKind),i.UV1&&u.push(e.VertexBuffer.UVKind),i.UV2&&u.push(e.VertexBuffer.UV2Kind),i.VERTEXCOLOR&&u.push(e.VertexBuffer.ColorKind),e.MaterialHelper.PrepareAttributesForBones(u,t,i,c),e.MaterialHelper.PrepareAttributesForInstances(u,i),e.MaterialHelper.PrepareAttributesForMorphTargets(u,t,i);var f=["world","view","viewProjection","vEyePosition","vLightsType","vAmbientColor","vAlbedoColor","vReflectivityColor","vEmissiveColor","vReflectionColor","vFogInfos","vFogColor","pointSize","vAlbedoInfos","vAmbientInfos","vOpacityInfos","vReflectionInfos","vReflectionPosition","vReflectionSize","vEmissiveInfos","vReflectivityInfos","vMicroSurfaceSamplerInfos","vBumpInfos","vLightmapInfos","vRefractionInfos","mBones","vClipPlane","albedoMatrix","ambientMatrix","opacityMatrix","reflectionMatrix","emissiveMatrix","reflectivityMatrix","normalMatrix","microSurfaceSamplerMatrix","bumpMatrix","lightmapMatrix","refractionMatrix","vLightingIntensity","logarithmicDepthConstant","vSphericalX","vSphericalY","vSphericalZ","vSphericalXX","vSphericalYY","vSphericalZZ","vSphericalXY","vSphericalYZ","vSphericalZX","vReflectionMicrosurfaceInfos","vRefractionMicrosurfaceInfos","vTangentSpaceParams"],d=["albedoSampler","reflectivitySampler","ambientSampler","emissiveSampler","bumpSampler","lightmapSampler","opacitySampler","refractionSampler","refractionSamplerLow","refractionSamplerHigh","reflectionSampler","reflectionSamplerLow","reflectionSamplerHigh","microSurfaceSampler","environmentBrdfSampler"],p=["Material","Scene"];e.ImageProcessingConfiguration.PrepareUniforms(f,i),e.ImageProcessingConfiguration.PrepareSamplers(d,i),e.MaterialHelper.PrepareUniformsAndSamplersList({uniformsNames:f,uniformBuffersNames:p,samplers:d,defines:i,maxSimultaneousLights:this._maxSimultaneousLights});var _=i.toString();return l.createEffect("pbr",{attributes:u,uniformsNames:f,uniformBuffersNames:p,samplers:d,defines:_,fallbacks:c,onCompiled:r,onError:n,indexParameters:{maxSimultaneousLights:this._maxSimultaneousLights,maxSimultaneousMorphTargets:i.NUM_MORPH_INFLUENCERS}},l)},n.prototype._prepareDefines=function(t,i,r,n){void 0===r&&(r=null),void 0===n&&(n=null);var o=this.getScene(),s=o.getEngine();if(e.MaterialHelper.PrepareDefinesForLights(o,t,i,!0,this._maxSimultaneousLights,this._disableLighting),i._needNormals=!0,i.METALLICWORKFLOW=this.isMetallicWorkflow(),i._areTexturesDirty){if(i._needUVs=!1,o.texturesEnabled){o.getEngine().getCaps().textureLOD&&(i.LODBASEDMICROSFURACE=!0),this._albedoTexture&&e.StandardMaterial.DiffuseTextureEnabled?e.MaterialHelper.PrepareDefinesForMergedUV(this._albedoTexture,i,"ALBEDO"):i.ALBEDO=!1,this._ambientTexture&&e.StandardMaterial.AmbientTextureEnabled?(e.MaterialHelper.PrepareDefinesForMergedUV(this._ambientTexture,i,"AMBIENT"),i.AMBIENTINGRAYSCALE=this._useAmbientInGrayScale):i.AMBIENT=!1,this._opacityTexture&&e.StandardMaterial.OpacityTextureEnabled?(e.MaterialHelper.PrepareDefinesForMergedUV(this._opacityTexture,i,"OPACITY"),i.OPACITYRGB=this._opacityTexture.getAlphaFromRGB):i.OPACITY=!1;var a=this._getReflectionTexture();if(a&&e.StandardMaterial.ReflectionTextureEnabled){switch(i.REFLECTION=!0,i.GAMMAREFLECTION=a.gammaSpace,i.REFLECTIONMAP_OPPOSITEZ=this.getScene().useRightHandedSystem?!a.invertZ:a.invertZ,i.LODINREFLECTIONALPHA=a.lodLevelInAlpha,a.coordinatesMode===e.Texture.INVCUBIC_MODE&&(i.INVERTCUBICMAP=!0),i.REFLECTIONMAP_3D=a.isCube,a.coordinatesMode){case e.Texture.CUBIC_MODE:case e.Texture.INVCUBIC_MODE:i.REFLECTIONMAP_CUBIC=!0,i.USE_LOCAL_REFLECTIONMAP_CUBIC=!!a.boundingBoxSize;break;case e.Texture.EXPLICIT_MODE:i.REFLECTIONMAP_EXPLICIT=!0;break;case e.Texture.PLANAR_MODE:i.REFLECTIONMAP_PLANAR=!0;break;case e.Texture.PROJECTION_MODE:i.REFLECTIONMAP_PROJECTION=!0;break;case e.Texture.SKYBOX_MODE:i.REFLECTIONMAP_SKYBOX=!0;break;case e.Texture.SPHERICAL_MODE:i.REFLECTIONMAP_SPHERICAL=!0;break;case e.Texture.EQUIRECTANGULAR_MODE:i.REFLECTIONMAP_EQUIRECTANGULAR=!0;break;case e.Texture.FIXED_EQUIRECTANGULAR_MODE:i.REFLECTIONMAP_EQUIRECTANGULAR_FIXED=!0;break;case e.Texture.FIXED_EQUIRECTANGULAR_MIRRORED_MODE:i.REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED=!0}a.coordinatesMode!==e.Texture.SKYBOX_MODE&&a.sphericalPolynomial&&(i.USESPHERICALFROMREFLECTIONMAP=!0,this._forceIrradianceInFragment||o.getEngine().getCaps().maxVaryingVectors<=8?i.USESPHERICALINVERTEX=!1:i.USESPHERICALINVERTEX=!0)}else i.REFLECTION=!1,i.REFLECTIONMAP_3D=!1,i.REFLECTIONMAP_SPHERICAL=!1,i.REFLECTIONMAP_PLANAR=!1,i.REFLECTIONMAP_CUBIC=!1,i.USE_LOCAL_REFLECTIONMAP_CUBIC=!1,i.REFLECTIONMAP_PROJECTION=!1,i.REFLECTIONMAP_SKYBOX=!1,i.REFLECTIONMAP_EXPLICIT=!1,i.REFLECTIONMAP_EQUIRECTANGULAR=!1,i.REFLECTIONMAP_EQUIRECTANGULAR_FIXED=!1,i.REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED=!1,i.INVERTCUBICMAP=!1,i.USESPHERICALFROMREFLECTIONMAP=!1,i.USESPHERICALINVERTEX=!1,i.REFLECTIONMAP_OPPOSITEZ=!1,i.LODINREFLECTIONALPHA=!1,i.GAMMAREFLECTION=!1;this._lightmapTexture&&e.StandardMaterial.LightmapTextureEnabled?(e.MaterialHelper.PrepareDefinesForMergedUV(this._lightmapTexture,i,"LIGHTMAP"),i.USELIGHTMAPASSHADOWMAP=this._useLightmapAsShadowmap):i.LIGHTMAP=!1,this._emissiveTexture&&e.StandardMaterial.EmissiveTextureEnabled?e.MaterialHelper.PrepareDefinesForMergedUV(this._emissiveTexture,i,"EMISSIVE"):i.EMISSIVE=!1,e.StandardMaterial.SpecularTextureEnabled?(this._metallicTexture?(e.MaterialHelper.PrepareDefinesForMergedUV(this._metallicTexture,i,"REFLECTIVITY"),i.ROUGHNESSSTOREINMETALMAPALPHA=this._useRoughnessFromMetallicTextureAlpha,i.ROUGHNESSSTOREINMETALMAPGREEN=!this._useRoughnessFromMetallicTextureAlpha&&this._useRoughnessFromMetallicTextureGreen,i.METALLNESSSTOREINMETALMAPBLUE=this._useMetallnessFromMetallicTextureBlue,i.AOSTOREINMETALMAPRED=this._useAmbientOcclusionFromMetallicTextureRed):this._reflectivityTexture?(e.MaterialHelper.PrepareDefinesForMergedUV(this._reflectivityTexture,i,"REFLECTIVITY"),i.MICROSURFACEFROMREFLECTIVITYMAP=this._useMicroSurfaceFromReflectivityMapAlpha,i.MICROSURFACEAUTOMATIC=this._useAutoMicroSurfaceFromReflectivityMap):i.REFLECTIVITY=!1,this._microSurfaceTexture?e.MaterialHelper.PrepareDefinesForMergedUV(this._microSurfaceTexture,i,"MICROSURFACEMAP"):i.MICROSURFACEMAP=!1):(i.REFLECTIVITY=!1,i.MICROSURFACEMAP=!1),o.getEngine().getCaps().standardDerivatives&&this._bumpTexture&&e.StandardMaterial.BumpTextureEnabled&&!this._disableBumpMap?(e.MaterialHelper.PrepareDefinesForMergedUV(this._bumpTexture,i,"BUMP"),this._useParallax&&this._albedoTexture&&e.StandardMaterial.DiffuseTextureEnabled?(i.PARALLAX=!0,i.PARALLAXOCCLUSION=!!this._useParallaxOcclusion):i.PARALLAX=!1,i.OBJECTSPACE_NORMALMAP=this._useObjectSpaceNormalMap):i.BUMP=!1;var l=this._getRefractionTexture();l&&e.StandardMaterial.RefractionTextureEnabled?(i.REFRACTION=!0,i.REFRACTIONMAP_3D=l.isCube,i.GAMMAREFRACTION=l.gammaSpace,i.REFRACTIONMAP_OPPOSITEZ=l.invertZ,i.LODINREFRACTIONALPHA=l.lodLevelInAlpha,this._linkRefractionWithTransparency&&(i.LINKREFRACTIONTOTRANSPARENCY=!0)):i.REFRACTION=!1,this._environmentBRDFTexture&&e.StandardMaterial.ReflectionTextureEnabled?i.ENVIRONMENTBRDF=!0:i.ENVIRONMENTBRDF=!1,this._shouldUseAlphaFromAlbedoTexture()?i.ALPHAFROMALBEDO=!0:i.ALPHAFROMALBEDO=!1}i.SPECULAROVERALPHA=this._useSpecularOverAlpha,i.USEPHYSICALLIGHTFALLOFF=this._usePhysicalLightFalloff,i.RADIANCEOVERALPHA=this._useRadianceOverAlpha,!this.backFaceCulling&&this._twoSidedLighting?i.TWOSIDEDLIGHTING=!0:i.TWOSIDEDLIGHTING=!1,i.ALPHATESTVALUE=this._alphaCutOff,i.PREMULTIPLYALPHA=this.alphaMode===e.Engine.ALPHA_PREMULTIPLIED||this.alphaMode===e.Engine.ALPHA_PREMULTIPLIED_PORTERDUFF,i.ALPHABLEND=this.needAlphaBlendingForMesh(t),i.ALPHAFRESNEL=this._useAlphaFresnel||this._useLinearAlphaFresnel,i.LINEARALPHAFRESNEL=this._useLinearAlphaFresnel}i._areImageProcessingDirty&&this._imageProcessingConfiguration.prepareDefines(i),i.FORCENORMALFORWARD=this._forceNormalForward,i.RADIANCEOCCLUSION=this._useRadianceOcclusion,i.HORIZONOCCLUSION=this._useHorizonOcclusion,e.MaterialHelper.PrepareDefinesForMisc(t,o,this._useLogarithmicDepth,this.pointsCloud,this.fogEnabled,this._shouldTurnAlphaTestOn(t)||this._forceAlphaTest,i),e.MaterialHelper.PrepareDefinesForFrameBoundValues(o,s,i,!!r,n),e.MaterialHelper.PrepareDefinesForAttributes(t,i,!0,!0,!0,this._transparencyMode!==e.PBRMaterial.PBRMATERIAL_OPAQUE)},n.prototype.forceCompilation=function(e,r,n){var o=this,s=t({clipPlane:!1},n),a=new i,l=this._prepareEffect(e,a,void 0,void 0,void 0,s.clipPlane);l.isReady()?r&&r(this):l.onCompileObservable.add((function(){r&&r(o)}))},n.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("vReflectionPosition",3),this._uniformBuffer.addUniform("vReflectionSize",3),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()},n.prototype.unbind=function(){this._reflectionTexture&&this._reflectionTexture.isRenderTarget&&this._uniformBuffer.setTexture("reflectionSampler",null),this._refractionTexture&&this._refractionTexture.isRenderTarget&&this._uniformBuffer.setTexture("refractionSampler",null),r.prototype.unbind.call(this)},n.prototype.bindForSubMesh=function(t,i,r){var n=this.getScene(),o=r._materialDefines;if(o){var s=r.effect;if(s){this._activeEffect=s,this.bindOnlyWorldMatrix(t),o.OBJECTSPACE_NORMALMAP&&(t.toNormalMatrix(this._normalMatrix),this.bindOnlyNormalMatrix(this._normalMatrix));var a=this._mustRebind(n,s,i.visibility);e.MaterialHelper.BindBonesParameters(i,this._activeEffect);var l=null;if(a){this._uniformBuffer.bindToEffect(s,"Material"),this.bindViewProjection(s),l=this._getReflectionTexture();var c=this._getRefractionTexture();if(!this._uniformBuffer.useUbo||!this.isFrozen||!this._uniformBuffer.isSync){if(n.texturesEnabled){if(this._albedoTexture&&e.StandardMaterial.DiffuseTextureEnabled&&(this._uniformBuffer.updateFloat2("vAlbedoInfos",this._albedoTexture.coordinatesIndex,this._albedoTexture.level),e.MaterialHelper.BindTextureMatrix(this._albedoTexture,this._uniformBuffer,"albedo")),this._ambientTexture&&e.StandardMaterial.AmbientTextureEnabled&&(this._uniformBuffer.updateFloat3("vAmbientInfos",this._ambientTexture.coordinatesIndex,this._ambientTexture.level,this._ambientTextureStrength),e.MaterialHelper.BindTextureMatrix(this._ambientTexture,this._uniformBuffer,"ambient")),this._opacityTexture&&e.StandardMaterial.OpacityTextureEnabled&&(this._uniformBuffer.updateFloat2("vOpacityInfos",this._opacityTexture.coordinatesIndex,this._opacityTexture.level),e.MaterialHelper.BindTextureMatrix(this._opacityTexture,this._uniformBuffer,"opacity")),l&&e.StandardMaterial.ReflectionTextureEnabled){if(this._uniformBuffer.updateMatrix("reflectionMatrix",l.getReflectionTextureMatrix()),this._uniformBuffer.updateFloat2("vReflectionInfos",l.level,0),l.boundingBoxSize){var h=l;this._uniformBuffer.updateVector3("vReflectionPosition",h.boundingBoxPosition),this._uniformBuffer.updateVector3("vReflectionSize",h.boundingBoxSize)}var u=l.sphericalPolynomial;o.USESPHERICALFROMREFLECTIONMAP&&u&&(this._activeEffect.setFloat3("vSphericalX",u.x.x,u.x.y,u.x.z),this._activeEffect.setFloat3("vSphericalY",u.y.x,u.y.y,u.y.z),this._activeEffect.setFloat3("vSphericalZ",u.z.x,u.z.y,u.z.z),this._activeEffect.setFloat3("vSphericalXX_ZZ",u.xx.x-u.zz.x,u.xx.y-u.zz.y,u.xx.z-u.zz.z),this._activeEffect.setFloat3("vSphericalYY_ZZ",u.yy.x-u.zz.x,u.yy.y-u.zz.y,u.yy.z-u.zz.z),this._activeEffect.setFloat3("vSphericalZZ",u.zz.x,u.zz.y,u.zz.z),this._activeEffect.setFloat3("vSphericalXY",u.xy.x,u.xy.y,u.xy.z),this._activeEffect.setFloat3("vSphericalYZ",u.yz.x,u.yz.y,u.yz.z),this._activeEffect.setFloat3("vSphericalZX",u.zx.x,u.zx.y,u.zx.z)),this._uniformBuffer.updateFloat3("vReflectionMicrosurfaceInfos",l.getSize().width,l.lodGenerationScale,l.lodGenerationOffset)}if(this._emissiveTexture&&e.StandardMaterial.EmissiveTextureEnabled&&(this._uniformBuffer.updateFloat2("vEmissiveInfos",this._emissiveTexture.coordinatesIndex,this._emissiveTexture.level),e.MaterialHelper.BindTextureMatrix(this._emissiveTexture,this._uniformBuffer,"emissive")),this._lightmapTexture&&e.StandardMaterial.LightmapTextureEnabled&&(this._uniformBuffer.updateFloat2("vLightmapInfos",this._lightmapTexture.coordinatesIndex,this._lightmapTexture.level),e.MaterialHelper.BindTextureMatrix(this._lightmapTexture,this._uniformBuffer,"lightmap")),e.StandardMaterial.SpecularTextureEnabled&&(this._metallicTexture?(this._uniformBuffer.updateFloat3("vReflectivityInfos",this._metallicTexture.coordinatesIndex,this._metallicTexture.level,this._ambientTextureStrength),e.MaterialHelper.BindTextureMatrix(this._metallicTexture,this._uniformBuffer,"reflectivity")):this._reflectivityTexture&&(this._uniformBuffer.updateFloat3("vReflectivityInfos",this._reflectivityTexture.coordinatesIndex,this._reflectivityTexture.level,1),e.MaterialHelper.BindTextureMatrix(this._reflectivityTexture,this._uniformBuffer,"reflectivity")),this._microSurfaceTexture&&(this._uniformBuffer.updateFloat2("vMicroSurfaceSamplerInfos",this._microSurfaceTexture.coordinatesIndex,this._microSurfaceTexture.level),e.MaterialHelper.BindTextureMatrix(this._microSurfaceTexture,this._uniformBuffer,"microSurfaceSampler"))),this._bumpTexture&&n.getEngine().getCaps().standardDerivatives&&e.StandardMaterial.BumpTextureEnabled&&!this._disableBumpMap&&(this._uniformBuffer.updateFloat3("vBumpInfos",this._bumpTexture.coordinatesIndex,this._bumpTexture.level,this._parallaxScaleBias),e.MaterialHelper.BindTextureMatrix(this._bumpTexture,this._uniformBuffer,"bump"),n._mirroredCameraPosition?this._uniformBuffer.updateFloat2("vTangentSpaceParams",this._invertNormalMapX?1:-1,this._invertNormalMapY?1:-1):this._uniformBuffer.updateFloat2("vTangentSpaceParams",this._invertNormalMapX?-1:1,this._invertNormalMapY?-1:1)),c&&e.StandardMaterial.RefractionTextureEnabled){this._uniformBuffer.updateMatrix("refractionMatrix",c.getReflectionTextureMatrix());var f=1;c.isCube||c.depth&&(f=c.depth),this._uniformBuffer.updateFloat4("vRefractionInfos",c.level,this._indexOfRefraction,f,this._invertRefractionY?-1:1),this._uniformBuffer.updateFloat3("vRefractionMicrosurfaceInfos",c.getSize().width,c.lodGenerationScale,c.lodGenerationOffset)}}this.pointsCloud&&this._uniformBuffer.updateFloat("pointSize",this.pointSize),o.METALLICWORKFLOW?(e.PBRMaterial._scaledReflectivity.r=void 0===this._metallic||null===this._metallic?1:this._metallic,e.PBRMaterial._scaledReflectivity.g=void 0===this._roughness||null===this._roughness?1:this._roughness,this._uniformBuffer.updateColor4("vReflectivityColor",e.PBRMaterial._scaledReflectivity,0)):this._uniformBuffer.updateColor4("vReflectivityColor",this._reflectivityColor,this._microSurface),this._uniformBuffer.updateColor3("vEmissiveColor",this._emissiveColor),this._uniformBuffer.updateColor3("vReflectionColor",this._reflectionColor),this._uniformBuffer.updateColor4("vAlbedoColor",this._albedoColor,this.alpha*i.visibility),this._lightingInfos.x=this._directIntensity,this._lightingInfos.y=this._emissiveIntensity,this._lightingInfos.z=this._environmentIntensity,this._lightingInfos.w=this._specularIntensity,this._uniformBuffer.updateVector4("vLightingIntensity",this._lightingInfos)}n.texturesEnabled&&(this._albedoTexture&&e.StandardMaterial.DiffuseTextureEnabled&&this._uniformBuffer.setTexture("albedoSampler",this._albedoTexture),this._ambientTexture&&e.StandardMaterial.AmbientTextureEnabled&&this._uniformBuffer.setTexture("ambientSampler",this._ambientTexture),this._opacityTexture&&e.StandardMaterial.OpacityTextureEnabled&&this._uniformBuffer.setTexture("opacitySampler",this._opacityTexture),l&&e.StandardMaterial.ReflectionTextureEnabled&&(o.LODBASEDMICROSFURACE?this._uniformBuffer.setTexture("reflectionSampler",l):(this._uniformBuffer.setTexture("reflectionSampler",l._lodTextureMid||l),this._uniformBuffer.setTexture("reflectionSamplerLow",l._lodTextureLow||l),this._uniformBuffer.setTexture("reflectionSamplerHigh",l._lodTextureHigh||l))),o.ENVIRONMENTBRDF&&this._uniformBuffer.setTexture("environmentBrdfSampler",this._environmentBRDFTexture),c&&e.StandardMaterial.RefractionTextureEnabled&&(o.LODBASEDMICROSFURACE?this._uniformBuffer.setTexture("refractionSampler",c):(this._uniformBuffer.setTexture("refractionSampler",c._lodTextureMid||c),this._uniformBuffer.setTexture("refractionSamplerLow",c._lodTextureLow||c),this._uniformBuffer.setTexture("refractionSamplerHigh",c._lodTextureHigh||c))),this._emissiveTexture&&e.StandardMaterial.EmissiveTextureEnabled&&this._uniformBuffer.setTexture("emissiveSampler",this._emissiveTexture),this._lightmapTexture&&e.StandardMaterial.LightmapTextureEnabled&&this._uniformBuffer.setTexture("lightmapSampler",this._lightmapTexture),e.StandardMaterial.SpecularTextureEnabled&&(this._metallicTexture?this._uniformBuffer.setTexture("reflectivitySampler",this._metallicTexture):this._reflectivityTexture&&this._uniformBuffer.setTexture("reflectivitySampler",this._reflectivityTexture),this._microSurfaceTexture&&this._uniformBuffer.setTexture("microSurfaceSampler",this._microSurfaceTexture)),this._bumpTexture&&n.getEngine().getCaps().standardDerivatives&&e.StandardMaterial.BumpTextureEnabled&&!this._disableBumpMap&&this._uniformBuffer.setTexture("bumpSampler",this._bumpTexture)),e.MaterialHelper.BindClipPlane(this._activeEffect,n),n.ambientColor.multiplyToRef(this._ambientColor,this._globalAmbientColor);var d=n._forcedViewPosition?n._forcedViewPosition:n._mirroredCameraPosition?n._mirroredCameraPosition:n.activeCamera.globalPosition,p=n.useRightHandedSystem===(null!=n._mirroredCameraPosition);s.setFloat4("vEyePosition",d.x,d.y,d.z,p?-1:1),s.setColor3("vAmbientColor",this._globalAmbientColor)}!a&&this.isFrozen||(n.lightsEnabled&&!this._disableLighting&&e.MaterialHelper.BindLights(n,i,this._activeEffect,o,this._maxSimultaneousLights,this._usePhysicalLightFalloff),(n.fogEnabled&&i.applyFog&&n.fogMode!==e.Scene.FOGMODE_NONE||l)&&this.bindView(s),e.MaterialHelper.BindFogParameters(n,i,this._activeEffect),o.NUM_MORPH_INFLUENCERS&&e.MaterialHelper.BindMorphTargetParameters(i,this._activeEffect),this._imageProcessingConfiguration.bind(this._activeEffect),e.MaterialHelper.BindLogDepth(o,this._activeEffect,n)),this._uniformBuffer.update(),this._afterBind(i)}}},n.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},n.prototype._getReflectionTexture=function(){return this._reflectionTexture?this._reflectionTexture:this.getScene().environmentTexture},n.prototype._getRefractionTexture=function(){return this._refractionTexture?this._refractionTexture:this._linkRefractionWithTransparency?this.getScene().environmentTexture:null},n.prototype.dispose=function(e,t){t&&(this._albedoTexture&&this._albedoTexture.dispose(),this._ambientTexture&&this._ambientTexture.dispose(),this._opacityTexture&&this._opacityTexture.dispose(),this._reflectionTexture&&this._reflectionTexture.dispose(),this._environmentBRDFTexture&&this.getScene()._environmentBRDFTexture!==this._environmentBRDFTexture&&this._environmentBRDFTexture.dispose(),this._emissiveTexture&&this._emissiveTexture.dispose(),this._metallicTexture&&this._metallicTexture.dispose(),this._reflectivityTexture&&this._reflectivityTexture.dispose(),this._bumpTexture&&this._bumpTexture.dispose(),this._lightmapTexture&&this._lightmapTexture.dispose(),this._refractionTexture&&this._refractionTexture.dispose()),this._renderTargets.dispose(),this._imageProcessingConfiguration&&this._imageProcessingObserver&&this._imageProcessingConfiguration.onUpdateParameters.remove(this._imageProcessingObserver),r.prototype.dispose.call(this,e,t)},n._scaledReflectivity=new e.Color3,__decorate([e.serializeAsImageProcessingConfiguration()],n.prototype,"_imageProcessingConfiguration",void 0),__decorate([e.serialize()],n.prototype,"useLogarithmicDepth",null),__decorate([e.serialize()],n.prototype,"transparencyMode",null),n})(e.PushMaterial);e.PBRBaseMaterial=r})(e||(e={}));var e;!(function(e){var t=(function(t){function i(i,r){var n=t.call(this,i,r)||this;return n.maxSimultaneousLights=4,n.disableLighting=!1,n.invertNormalMapX=!1,n.invertNormalMapY=!1,n.emissiveColor=new e.Color3(0,0,0),n.occlusionStrength=1,n.useLightmapAsShadowmap=!1,n._useAlphaFromAlbedoTexture=!0,n._useAmbientInGrayScale=!0,n}return __extends(i,t),Object.defineProperty(i.prototype,"doubleSided",{get:function(){return this._twoSidedLighting},set:function(e){this._twoSidedLighting!==e&&(this._twoSidedLighting=e,this.backFaceCulling=!e,this._markAllSubMeshesAsTexturesDirty())},enumerable:!0,configurable:!0}),i.prototype.getActiveTextures=function(){var e=t.prototype.getActiveTextures.call(this);return this.environmentTexture&&e.push(this.environmentTexture),this.normalTexture&&e.push(this.normalTexture),this.emissiveTexture&&e.push(this.emissiveTexture),this.occlusionTexture&&e.push(this.occlusionTexture),this.lightmapTexture&&e.push(this.lightmapTexture),e},i.prototype.hasTexture=function(e){return!!t.prototype.hasTexture.call(this,e)||this.lightmapTexture===e},i.prototype.getClassName=function(){return"PBRBaseSimpleMaterial"},__decorate([e.serialize(),e.expandToProperty("_markAllSubMeshesAsLightsDirty")],i.prototype,"maxSimultaneousLights",void 0),__decorate([e.serialize(),e.expandToProperty("_markAllSubMeshesAsLightsDirty")],i.prototype,"disableLighting",void 0),__decorate([e.serializeAsTexture(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty","_reflectionTexture")],i.prototype,"environmentTexture",void 0),__decorate([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"invertNormalMapX",void 0),__decorate([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"invertNormalMapY",void 0),__decorate([e.serializeAsTexture(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty","_bumpTexture")],i.prototype,"normalTexture",void 0),__decorate([e.serializeAsColor3("emissive"),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"emissiveColor",void 0),__decorate([e.serializeAsTexture(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"emissiveTexture",void 0),__decorate([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty","_ambientTextureStrength")],i.prototype,"occlusionStrength",void 0),__decorate([e.serializeAsTexture(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty","_ambientTexture")],i.prototype,"occlusionTexture",void 0),__decorate([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty","_alphaCutOff")],i.prototype,"alphaCutOff",void 0),__decorate([e.serialize()],i.prototype,"doubleSided",null),__decorate([e.serializeAsTexture(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty",null)],i.prototype,"lightmapTexture",void 0),__decorate([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"useLightmapAsShadowmap",void 0),i})(e.PBRBaseMaterial);e.PBRBaseSimpleMaterial=t})(e||(e={}));var e;!(function(e){var t=(function(t){function i(i,r){var n=t.call(this,i,r)||this;return n.directIntensity=1,n.emissiveIntensity=1,n.environmentIntensity=1,n.specularIntensity=1,n.disableBumpMap=!1,n.ambientTextureStrength=1,n.ambientColor=new e.Color3(0,0,0),n.albedoColor=new e.Color3(1,1,1),n.reflectivityColor=new e.Color3(1,1,1),n.reflectionColor=new e.Color3(1,1,1),n.emissiveColor=new e.Color3(0,0,0),n.microSurface=1,n.indexOfRefraction=.66,n.invertRefractionY=!1,n.linkRefractionWithTransparency=!1,n.useLightmapAsShadowmap=!1,n.useAlphaFromAlbedoTexture=!1,n.forceAlphaTest=!1,n.alphaCutOff=.4,n.useSpecularOverAlpha=!0,n.useMicroSurfaceFromReflectivityMapAlpha=!1,n.useRoughnessFromMetallicTextureAlpha=!0,n.useRoughnessFromMetallicTextureGreen=!1,n.useMetallnessFromMetallicTextureBlue=!1,n.useAmbientOcclusionFromMetallicTextureRed=!1,n.useAmbientInGrayScale=!1,n.useAutoMicroSurfaceFromReflectivityMap=!1,n.usePhysicalLightFalloff=!0,n.useRadianceOverAlpha=!0,n.useObjectSpaceNormalMap=!1,n.useParallax=!1,n.useParallaxOcclusion=!1,n.parallaxScaleBias=.05,n.disableLighting=!1,n.forceIrradianceInFragment=!1,n.maxSimultaneousLights=4,n.invertNormalMapX=!1,n.invertNormalMapY=!1,n.twoSidedLighting=!1,n.useAlphaFresnel=!1,n.useLinearAlphaFresnel=!1,n.environmentBRDFTexture=null,n.forceNormalForward=!1,n.useHorizonOcclusion=!0,n.useRadianceOcclusion=!0,n._environmentBRDFTexture=e.TextureTools.GetEnvironmentBRDFTexture(r),n}return __extends(i,t),Object.defineProperty(i,"PBRMATERIAL_OPAQUE",{get:function(){return this._PBRMATERIAL_OPAQUE},enumerable:!0,configurable:!0}),Object.defineProperty(i,"PBRMATERIAL_ALPHATEST",{get:function(){return this._PBRMATERIAL_ALPHATEST},enumerable:!0,configurable:!0}),Object.defineProperty(i,"PBRMATERIAL_ALPHABLEND",{get:function(){return this._PBRMATERIAL_ALPHABLEND},enumerable:!0,configurable:!0}),Object.defineProperty(i,"PBRMATERIAL_ALPHATESTANDBLEND",{get:function(){return this._PBRMATERIAL_ALPHATESTANDBLEND},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"imageProcessingConfiguration",{get:function(){return this._imageProcessingConfiguration},set:function(e){this._attachImageProcessingConfiguration(e),this._markAllSubMeshesAsTexturesDirty()},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"cameraColorCurvesEnabled",{get:function(){return this.imageProcessingConfiguration.colorCurvesEnabled},set:function(e){this.imageProcessingConfiguration.colorCurvesEnabled=e},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"cameraColorGradingEnabled",{get:function(){return this.imageProcessingConfiguration.colorGradingEnabled},set:function(e){this.imageProcessingConfiguration.colorGradingEnabled=e},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"cameraToneMappingEnabled",{get:function(){return this._imageProcessingConfiguration.toneMappingEnabled},set:function(e){this._imageProcessingConfiguration.toneMappingEnabled=e},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"cameraExposure",{get:function(){return this._imageProcessingConfiguration.exposure},set:function(e){this._imageProcessingConfiguration.exposure=e},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"cameraContrast",{get:function(){return this._imageProcessingConfiguration.contrast},set:function(e){this._imageProcessingConfiguration.contrast=e},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"cameraColorGradingTexture",{get:function(){return this._imageProcessingConfiguration.colorGradingTexture},set:function(e){this._imageProcessingConfiguration.colorGradingTexture=e},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"cameraColorCurves",{get:function(){return this._imageProcessingConfiguration.colorCurves},set:function(e){this._imageProcessingConfiguration.colorCurves=e},enumerable:!0,configurable:!0}),i.prototype.getClassName=function(){return"PBRMaterial"},i.prototype.getActiveTextures=function(){var e=t.prototype.getActiveTextures.call(this);return this._albedoTexture&&e.push(this._albedoTexture),this._ambientTexture&&e.push(this._ambientTexture),this._opacityTexture&&e.push(this._opacityTexture),this._reflectionTexture&&e.push(this._reflectionTexture),this._emissiveTexture&&e.push(this._emissiveTexture),this._reflectivityTexture&&e.push(this._reflectivityTexture),this._metallicTexture&&e.push(this._metallicTexture),this._microSurfaceTexture&&e.push(this._microSurfaceTexture),this._bumpTexture&&e.push(this._bumpTexture),this._lightmapTexture&&e.push(this._lightmapTexture),this._refractionTexture&&e.push(this._refractionTexture),e},i.prototype.hasTexture=function(e){return!!t.prototype.hasTexture.call(this,e)||(this._albedoTexture===e||(this._ambientTexture===e||(this._opacityTexture===e||(this._reflectionTexture===e||(this._reflectivityTexture===e||(this._metallicTexture===e||(this._microSurfaceTexture===e||(this._bumpTexture===e||(this._lightmapTexture===e||this._refractionTexture===e)))))))))},i.prototype.clone=function(t){var r=this,n=e.SerializationHelper.Clone((function(){return new i(t,r.getScene())}),this);return n.id=t,n.name=t,n},i.prototype.serialize=function(){var t=e.SerializationHelper.Serialize(this);return t.customType="BABYLON.PBRMaterial",t},i.Parse=function(t,r,n){return e.SerializationHelper.Parse((function(){return new i(t.name,r)}),t,r,n)},i._PBRMATERIAL_OPAQUE=0,i._PBRMATERIAL_ALPHATEST=1,i._PBRMATERIAL_ALPHABLEND=2,i._PBRMATERIAL_ALPHATESTANDBLEND=3,__decorate([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"directIntensity",void 0),__decorate([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"emissiveIntensity",void 0),__decorate([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"environmentIntensity",void 0),__decorate([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"specularIntensity",void 0),__decorate([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"disableBumpMap",void 0),__decorate([e.serializeAsTexture(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"albedoTexture",void 0),__decorate([e.serializeAsTexture(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"ambientTexture",void 0),__decorate([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"ambientTextureStrength",void 0),__decorate([e.serializeAsTexture(),e.expandToProperty("_markAllSubMeshesAsTexturesAndMiscDirty")],i.prototype,"opacityTexture",void 0),__decorate([e.serializeAsTexture(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"reflectionTexture",void 0),__decorate([e.serializeAsTexture(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"emissiveTexture",void 0),__decorate([e.serializeAsTexture(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"reflectivityTexture",void 0),__decorate([e.serializeAsTexture(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"metallicTexture",void 0),__decorate([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"metallic",void 0),__decorate([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"roughness",void 0),__decorate([e.serializeAsTexture(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"microSurfaceTexture",void 0),__decorate([e.serializeAsTexture(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"bumpTexture",void 0),__decorate([e.serializeAsTexture(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty",null)],i.prototype,"lightmapTexture",void 0),__decorate([e.serializeAsTexture(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"refractionTexture",void 0),__decorate([e.serializeAsColor3("ambient"),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"ambientColor",void 0),__decorate([e.serializeAsColor3("albedo"),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"albedoColor",void 0),__decorate([e.serializeAsColor3("reflectivity"),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"reflectivityColor",void 0),__decorate([e.serializeAsColor3("reflection"),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"reflectionColor",void 0),__decorate([e.serializeAsColor3("emissive"),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"emissiveColor",void 0),__decorate([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"microSurface",void 0),__decorate([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"indexOfRefraction",void 0),__decorate([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"invertRefractionY",void 0),__decorate([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"linkRefractionWithTransparency",void 0),__decorate([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"useLightmapAsShadowmap",void 0),__decorate([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesAndMiscDirty")],i.prototype,"useAlphaFromAlbedoTexture",void 0),__decorate([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesAndMiscDirty")],i.prototype,"forceAlphaTest",void 0),__decorate([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesAndMiscDirty")],i.prototype,"alphaCutOff",void 0),__decorate([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"useSpecularOverAlpha",void 0),__decorate([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"useMicroSurfaceFromReflectivityMapAlpha",void 0),__decorate([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"useRoughnessFromMetallicTextureAlpha",void 0),__decorate([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"useRoughnessFromMetallicTextureGreen",void 0),__decorate([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"useMetallnessFromMetallicTextureBlue",void 0),__decorate([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"useAmbientOcclusionFromMetallicTextureRed",void 0),__decorate([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"useAmbientInGrayScale",void 0),__decorate([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"useAutoMicroSurfaceFromReflectivityMap",void 0),__decorate([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"usePhysicalLightFalloff",void 0),__decorate([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"useRadianceOverAlpha",void 0),__decorate([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"useObjectSpaceNormalMap",void 0),__decorate([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"useParallax",void 0),__decorate([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"useParallaxOcclusion",void 0),__decorate([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"parallaxScaleBias",void 0),__decorate([e.serialize(),e.expandToProperty("_markAllSubMeshesAsLightsDirty")],i.prototype,"disableLighting",void 0),__decorate([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"forceIrradianceInFragment",void 0),__decorate([e.serialize(),e.expandToProperty("_markAllSubMeshesAsLightsDirty")],i.prototype,"maxSimultaneousLights",void 0),__decorate([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"invertNormalMapX",void 0),__decorate([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"invertNormalMapY",void 0),__decorate([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"twoSidedLighting",void 0),__decorate([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"useAlphaFresnel",void 0),__decorate([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"useLinearAlphaFresnel",void 0),__decorate([e.serializeAsTexture(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"environmentBRDFTexture",void 0),__decorate([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"forceNormalForward",void 0),__decorate([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"useHorizonOcclusion",void 0),__decorate([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"useRadianceOcclusion",void 0),i})(e.PBRBaseMaterial);e.PBRMaterial=t})(e||(e={}));var e;!(function(e){var t=(function(t){function i(e,i){var r=t.call(this,e,i)||this;return r._useRoughnessFromMetallicTextureAlpha=!1,r._useRoughnessFromMetallicTextureGreen=!0,r._useMetallnessFromMetallicTextureBlue=!0,r.metallic=1,r.roughness=1,r}return __extends(i,t),i.prototype.getClassName=function(){return"PBRMetallicRoughnessMaterial"},i.prototype.getActiveTextures=function(){var e=t.prototype.getActiveTextures.call(this);return this.baseTexture&&e.push(this.baseTexture),this.metallicRoughnessTexture&&e.push(this.metallicRoughnessTexture),e},i.prototype.hasTexture=function(e){return!!t.prototype.hasTexture.call(this,e)||(this.baseTexture===e||this.metallicRoughnessTexture===e)},i.prototype.clone=function(t){var r=this,n=e.SerializationHelper.Clone((function(){return new i(t,r.getScene())}),this);return n.id=t,n.name=t,n},i.prototype.serialize=function(){var t=e.SerializationHelper.Serialize(this);return t.customType="BABYLON.PBRMetallicRoughnessMaterial",t},i.Parse=function(t,r,n){return e.SerializationHelper.Parse((function(){return new i(t.name,r)}),t,r,n)},__decorate([e.serializeAsColor3(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty","_albedoColor")],i.prototype,"baseColor",void 0),__decorate([e.serializeAsTexture(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty","_albedoTexture")],i.prototype,"baseTexture",void 0),__decorate([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"metallic",void 0),__decorate([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],i.prototype,"roughness",void 0),__decorate([e.serializeAsTexture(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty","_metallicTexture")],i.prototype,"metallicRoughnessTexture",void 0),i})(e.PBRBaseSimpleMaterial);e.PBRMetallicRoughnessMaterial=t})(e||(e={}));var e;!(function(e){var t=(function(t){function i(e,i){var r=t.call(this,e,i)||this;return r._useMicroSurfaceFromReflectivityMapAlpha=!0,r}return __extends(i,t),i.prototype.getClassName=function(){return"PBRSpecularGlossinessMaterial"},i.prototype.getActiveTextures=function(){var e=t.prototype.getActiveTextures.call(this);return this.diffuseTexture&&e.push(this.diffuseTexture),this.specularGlossinessTexture&&e.push(this.specularGlossinessTexture),e},i.prototype.hasTexture=function(e){return!!t.prototype.hasTexture.call(this,e)||(this.diffuseTexture===e||this.specularGlossinessTexture===e)},i.prototype.clone=function(t){var r=this,n=e.SerializationHelper.Clone((function(){return new i(t,r.getScene())}),this);return n.id=t,n.name=t,n},i.prototype.serialize=function(){var t=e.SerializationHelper.Serialize(this);return t.customType="BABYLON.PBRSpecularGlossinessMaterial",t},i.Parse=function(t,r,n){return e.SerializationHelper.Parse((function(){return new i(t.name,r)}),t,r,n)},__decorate([e.serializeAsColor3("diffuse"),e.expandToProperty("_markAllSubMeshesAsTexturesDirty","_albedoColor")],i.prototype,"diffuseColor",void 0),__decorate([e.serializeAsTexture(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty","_albedoTexture")],i.prototype,"diffuseTexture",void 0),__decorate([e.serializeAsColor3("specular"),e.expandToProperty("_markAllSubMeshesAsTexturesDirty","_reflectivityColor")],i.prototype,"specularColor",void 0),__decorate([e.serialize(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty","_microSurface")],i.prototype,"glossiness",void 0),__decorate([e.serializeAsTexture(),e.expandToProperty("_markAllSubMeshesAsTexturesDirty","_reflectivityTexture")],i.prototype,"specularGlossinessTexture",void 0),i})(e.PBRBaseSimpleMaterial);e.PBRSpecularGlossinessMaterial=t})(e||(e={}));var e;!(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();if(this.attached[i])return void e.Tools.Warn("camera input of type "+i+" already exists on camera");this.attached[i]=t,t.camera=this.camera,t.checkInputs&&(this.checkInputs=this._addCheckInputs(t.checkInputs.bind(t))),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){var n=e.CameraInputTypes[r];if(n){var o=i[r],s=e.SerializationHelper.Parse((function(){return new n}),o,null);this.add(s)}}}else for(var r in this.attached){var n=e.CameraInputTypes[this.attached[r].getClassName()];if(n){var s=e.SerializationHelper.Parse((function(){return new n}),t,null);this.remove(this.attached[r]),this.add(s)}}},t})();e.CameraInputsManager=t})(e||(e={}));var e;!(function(e){var t=(function(t){function i(i,r,n){var o=t.call(this,i,r,n)||this;return o.cameraDirection=new e.Vector3(0,0,0),o.cameraRotation=new e.Vector2(0,0),o.rotation=new e.Vector3(0,0,0),o.speed=2,o.noRotationConstraint=!1,o.lockedTarget=null,o._currentTarget=e.Vector3.Zero(),o._viewMatrix=e.Matrix.Zero(),o._camMatrix=e.Matrix.Zero(),o._cameraTransformMatrix=e.Matrix.Zero(),o._cameraRotationMatrix=e.Matrix.Zero(),o._referencePoint=new e.Vector3(0,0,1),o._currentUpVector=new e.Vector3(0,1,0),o._transformedReferencePoint=e.Vector3.Zero(),o._lookAtTemp=e.Matrix.Zero(),o._tempMatrix=e.Matrix.Zero(),o}return __extends(i,t),i.prototype.getFrontPosition=function(e){this.getWorldMatrix();var t=this.getTarget().subtract(this.position);return t.normalize(),t.scaleInPlace(e),this.globalPosition.add(t)},i.prototype._getLockedTargetPosition=function(){return this.lockedTarget?(this.lockedTarget.absolutePosition&&this.lockedTarget.computeWorldMatrix(),this.lockedTarget.absolutePosition||this.lockedTarget):null},i.prototype.storeState=function(){return this._storedPosition=this.position.clone(),this._storedRotation=this.rotation.clone(),this.rotationQuaternion&&(this._storedRotationQuaternion=this.rotationQuaternion.clone()),t.prototype.storeState.call(this)},i.prototype._restoreStateValues=function(){return!!t.prototype._restoreStateValues.call(this)&&(this.position=this._storedPosition.clone(),this.rotation=this._storedRotation.clone(),this.rotationQuaternion&&(this.rotationQuaternion=this._storedRotationQuaternion.clone()),this.cameraDirection.copyFromFloats(0,0,0),this.cameraRotation.copyFromFloats(0,0),!0)},i.prototype._initCache=function(){t.prototype._initCache.call(this),this._cache.lockedTarget=new e.Vector3(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),this._cache.rotation=new e.Vector3(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),this._cache.rotationQuaternion=new e.Quaternion(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE)},i.prototype._updateCache=function(e){e||t.prototype._updateCache.call(this);var i=this._getLockedTargetPosition();i?this._cache.lockedTarget?this._cache.lockedTarget.copyFrom(i):this._cache.lockedTarget=i.clone():this._cache.lockedTarget=null,this._cache.rotation.copyFrom(this.rotation),this.rotationQuaternion&&this._cache.rotationQuaternion.copyFrom(this.rotationQuaternion)},i.prototype._isSynchronizedViewMatrix=function(){if(!t.prototype._isSynchronizedViewMatrix.call(this))return!1;var e=this._getLockedTargetPosition();return(this._cache.lockedTarget?this._cache.lockedTarget.equals(e):!e)&&(this.rotationQuaternion?this.rotationQuaternion.equals(this._cache.rotationQuaternion):this._cache.rotation.equals(this.rotation))},i.prototype._computeLocalCameraSpeed=function(){var e=this.getEngine();return this.speed*Math.sqrt(e.getDeltaTime()/(100*e.getFps()))},i.prototype.setTarget=function(t){this.upVector.normalize(),e.Matrix.LookAtLHToRef(this.position,t,this.upVector,this._camMatrix),this._camMatrix.invert(),this.rotation.x=Math.atan(this._camMatrix.m[6]/this._camMatrix.m[10]);var i=t.subtract(this.position);i.x>=0?this.rotation.y=-Math.atan(i.z/i.x)+Math.PI/2:this.rotation.y=-Math.atan(i.z/i.x)-Math.PI/2,this.rotation.z=0,isNaN(this.rotation.x)&&(this.rotation.x=0),isNaN(this.rotation.y)&&(this.rotation.y=0),isNaN(this.rotation.z)&&(this.rotation.z=0),this.rotationQuaternion&&e.Quaternion.RotationYawPitchRollToRef(this.rotation.y,this.rotation.x,this.rotation.z,this.rotationQuaternion)},i.prototype.getTarget=function(){return this._currentTarget},i.prototype._decideIfNeedsToMove=function(){return Math.abs(this.cameraDirection.x)>0||Math.abs(this.cameraDirection.y)>0||Math.abs(this.cameraDirection.z)>0},i.prototype._updatePosition=function(){if(this.parent)return this.parent.getWorldMatrix().invertToRef(e.Tmp.Matrix[0]),e.Vector3.TransformNormalToRef(this.cameraDirection,e.Tmp.Matrix[0],e.Tmp.Vector3[0]),void this.position.addInPlace(e.Tmp.Vector3[0]);this.position.addInPlace(this.cameraDirection)},i.prototype._checkInputs=function(){var i=this._decideIfNeedsToMove(),r=Math.abs(this.cameraRotation.x)>0||Math.abs(this.cameraRotation.y)>0;if(i&&this._updatePosition(),r){if(this.rotation.x+=this.cameraRotation.x,this.rotation.y+=this.cameraRotation.y,this.rotationQuaternion){this.rotation.lengthSquared()&&e.Quaternion.RotationYawPitchRollToRef(this.rotation.y,this.rotation.x,this.rotation.z,this.rotationQuaternion)}if(!this.noRotationConstraint){var n=Math.PI/2*.95;this.rotation.x>n&&(this.rotation.x=n),this.rotation.x<-n&&(this.rotation.x=-n)}}i&&(Math.abs(this.cameraDirection.x)=0&&r._keys.splice(o,1),i||n.preventDefault()}})))},t.prototype.detachControl=function(e){this._scene&&(this._onKeyboardObserver&&this._scene.onKeyboardObservable.remove(this._onKeyboardObserver),this._onCanvasBlurObserver&&this._engine.onCanvasBlurObservable.remove(this._onCanvasBlurObserver),this._onKeyboardObserver=null,this._onCanvasBlurObserver=null),this._keys=[]},t.prototype.checkInputs=function(){if(this._onKeyboardObserver)for(var t=this.camera,i=0;ie.Engine.CollisionsEpsilon&&(o.position.addInPlace(o._diffPosition),o.onCollide&&r&&o.onCollide(r))})(i)},o.inputs=new e.FreeCameraInputsManager(o),o.inputs.addKeyboard().addMouse(),o}return __extends(i,t),Object.defineProperty(i.prototype,"angularSensibility",{get:function(){var e=this.inputs.attached.mouse;return e?e.angularSensibility:0},set:function(e){var t=this.inputs.attached.mouse;t&&(t.angularSensibility=e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"keysUp",{get:function(){var e=this.inputs.attached.keyboard;return e?e.keysUp:[]},set:function(e){var t=this.inputs.attached.keyboard;t&&(t.keysUp=e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"keysDown",{get:function(){var e=this.inputs.attached.keyboard;return e?e.keysDown:[]},set:function(e){var t=this.inputs.attached.keyboard;t&&(t.keysDown=e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"keysLeft",{get:function(){var e=this.inputs.attached.keyboard;return e?e.keysLeft:[]},set:function(e){var t=this.inputs.attached.keyboard;t&&(t.keysLeft=e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"keysRight",{get:function(){var e=this.inputs.attached.keyboard;return e?e.keysRight:[]},set:function(e){var t=this.inputs.attached.keyboard;t&&(t.keysRight=e)},enumerable:!0,configurable:!0}),i.prototype.attachControl=function(e,t){this.inputs.attachElement(e,t)},i.prototype.detachControl=function(t){this.inputs.detachElement(t),this.cameraDirection=new e.Vector3(0,0,0),this.cameraRotation=new e.Vector2(0,0)},Object.defineProperty(i.prototype,"collisionMask",{get:function(){return this._collisionMask},set:function(e){this._collisionMask=isNaN(e)?-1:e},enumerable:!0,configurable:!0}),i.prototype._collideWithWorld=function(t){var i;i=this.parent?e.Vector3.TransformCoordinates(this.position,this.parent.getWorldMatrix()):this.position,i.subtractFromFloatsToRef(0,this.ellipsoid.y,0,this._oldPosition),this._oldPosition.addInPlace(this.ellipsoidOffset),this._collider||(this._collider=new e.Collider),this._collider._radius=this.ellipsoid,this._collider.collisionMask=this._collisionMask;var r=t;this.applyGravity&&(r=t.add(this.getScene().gravity)),this.getScene().collisionCoordinator.getNewPosition(this._oldPosition,r,this._collider,3,null,this._onCollisionPositionChange,this.uniqueId)},i.prototype._checkInputs=function(){this._localDirection||(this._localDirection=e.Vector3.Zero(),this._transformedDirection=e.Vector3.Zero()),this.inputs.checkInputs(),t.prototype._checkInputs.call(this)},i.prototype._decideIfNeedsToMove=function(){return this._needMoveForGravity||Math.abs(this.cameraDirection.x)>0||Math.abs(this.cameraDirection.y)>0||Math.abs(this.cameraDirection.z)>0},i.prototype._updatePosition=function(){this.checkCollisions&&this.getScene().collisionsEnabled?this._collideWithWorld(this.cameraDirection):t.prototype._updatePosition.call(this)},i.prototype.dispose=function(){this.inputs.clear(),t.prototype.dispose.call(this)},i.prototype.getClassName=function(){return"FreeCamera"},__decorate([e.serializeAsVector3()],i.prototype,"ellipsoid",void 0),__decorate([e.serializeAsVector3()],i.prototype,"ellipsoidOffset",void 0),__decorate([e.serialize()],i.prototype,"checkCollisions",void 0),__decorate([e.serialize()],i.prototype,"applyGravity",void 0),i})(e.TargetCamera);e.FreeCamera=t})(e||(e={}));var e;!(function(e){var t=(function(){function t(){this._keys=new Array,this.keysUp=[38],this.keysDown=[40],this.keysLeft=[37],this.keysRight=[39],this.keysReset=[220],this.panningSensibility=50,this.zoomingSensibility=25,this.useAltToZoom=!0}return t.prototype.attachControl=function(t,i){var r=this;this._onCanvasBlurObserver||(this._scene=this.camera.getScene(),this._engine=this._scene.getEngine(),this._onCanvasBlurObserver=this._engine.onCanvasBlurObservable.add((function(){r._keys=[]})),this._onKeyboardObserver=this._scene.onKeyboardObservable.add((function(t){var n=t.event;if(t.type===e.KeyboardEventTypes.KEYDOWN){if(r._ctrlPressed=n.ctrlKey,r._altPressed=n.altKey,-1!==r.keysUp.indexOf(n.keyCode)||-1!==r.keysDown.indexOf(n.keyCode)||-1!==r.keysLeft.indexOf(n.keyCode)||-1!==r.keysRight.indexOf(n.keyCode)||-1!==r.keysReset.indexOf(n.keyCode)){var o=r._keys.indexOf(n.keyCode);-1===o&&r._keys.push(n.keyCode),n.preventDefault&&(i||n.preventDefault())}}else if(-1!==r.keysUp.indexOf(n.keyCode)||-1!==r.keysDown.indexOf(n.keyCode)||-1!==r.keysLeft.indexOf(n.keyCode)||-1!==r.keysRight.indexOf(n.keyCode)||-1!==r.keysReset.indexOf(n.keyCode)){var o=r._keys.indexOf(n.keyCode);o>=0&&r._keys.splice(o,1),n.preventDefault&&(i||n.preventDefault())}})))},t.prototype.detachControl=function(e){this._scene&&(this._onKeyboardObserver&&this._scene.onKeyboardObservable.remove(this._onKeyboardObserver),this._onCanvasBlurObserver&&this._engine.onCanvasBlurObservable.remove(this._onCanvasBlurObserver),this._onKeyboardObserver=null,this._onCanvasBlurObserver=null),this._keys=[]},t.prototype.checkInputs=function(){if(this._onKeyboardObserver)for(var e=this.camera,t=0;tn.camera.pinchToPanMaxDistance)n.pinchDeltaPercentage?n.camera.inertialRadiusOffset+=.001*(E-l)*n.camera.radius*n.pinchDeltaPercentage:n.camera.inertialRadiusOffset+=(E-l)/(n.pinchPrecision*((n.angularSensibilityX+n.angularSensibilityY)/2)*b),u.isPaning=!1,u.isPinching=!0;else if(r&&r.pointerId===y.pointerId&&0!==n.panningSensibility&&n.multiTouchPanning){if(!u.isPaning)return u.isPaning=!0,u.isPinching=!1,u.x=y.x,void(u.y=y.y);n.camera.inertialPanningX+=-(y.x-u.x)/n.panningSensibility,n.camera.inertialPanningY+=(y.y-u.y)/n.panningSensibility}r&&r.pointerId===p.pointerId&&(u.x=y.x,u.y=y.y)}l=E}}},this._observer=this.camera.getScene().onPointerObservable.add(this._pointerInput,e.PointerEventTypes.POINTERDOWN|e.PointerEventTypes.POINTERUP|e.PointerEventTypes.POINTERMOVE|e.PointerEventTypes._POINTERDOUBLETAP),this._onContextMenu=function(e){e.preventDefault()},this.camera._useCtrlForPanning||t.addEventListener("contextmenu",this._onContextMenu,!1),this._onLostFocus=function(){s=a=null,l=0,u.isPaning=!1,u.isPinching=!1,h=0,r=null,c=0},this._onMouseMove=function(e){if(o.isPointerLock){var t=e.movementX||e.mozMovementX||e.webkitMovementX||e.msMovementX||0,r=e.movementY||e.mozMovementY||e.webkitMovementY||e.msMovementY||0;n.camera.inertialAlphaOffset-=t/n.angularSensibilityX,n.camera.inertialBetaOffset-=r/n.angularSensibilityY,i||e.preventDefault()}},this._onGestureStart=function(e){void 0!==window.MSGesture&&(n._MSGestureHandler||(n._MSGestureHandler=new MSGesture,n._MSGestureHandler.target=t),n._MSGestureHandler.addPointer(e.pointerId))},this._onGesture=function(e){n.camera.radius*=e.scale,e.preventDefault&&(i||(e.stopPropagation(),e.preventDefault()))},t.addEventListener("mousemove",this._onMouseMove,!1),t.addEventListener("MSPointerDown",this._onGestureStart,!1),t.addEventListener("MSGestureChange",this._onGesture,!1),e.Tools.RegisterTopRootEvents([{name:"blur",handler:this._onLostFocus}])},t.prototype.detachControl=function(t){this._onLostFocus&&e.Tools.UnregisterTopRootEvents([{name:"blur",handler:this._onLostFocus}]),t&&this._observer&&(this.camera.getScene().onPointerObservable.remove(this._observer),this._observer=null,this._onContextMenu&&t.removeEventListener("contextmenu",this._onContextMenu),this._onMouseMove&&t.removeEventListener("mousemove",this._onMouseMove),this._onGestureStart&&t.removeEventListener("MSPointerDown",this._onGestureStart),this._onGesture&&t.removeEventListener("MSGestureChange",this._onGesture),this._isPanClick=!1,this.pinchInwards=!0,this._onMouseMove=null,this._onGestureStart=null,this._onGesture=null,this._MSGestureHandler=null,this._onLostFocus=null,this._onContextMenu=null)},t.prototype.getClassName=function(){return"ArcRotateCameraPointersInput"},t.prototype.getSimpleName=function(){return"pointers"},__decorate([e.serialize()],t.prototype,"buttons",void 0),__decorate([e.serialize()],t.prototype,"angularSensibilityX",void 0),__decorate([e.serialize()],t.prototype,"angularSensibilityY",void 0),__decorate([e.serialize()],t.prototype,"pinchPrecision",void 0),__decorate([e.serialize()],t.prototype,"pinchDeltaPercentage",void 0),__decorate([e.serialize()],t.prototype,"panningSensibility",void 0),__decorate([e.serialize()],t.prototype,"multiTouchPanning",void 0),__decorate([e.serialize()],t.prototype,"multiTouchPanAndZoom",void 0),t})();e.ArcRotateCameraPointersInput=t,e.CameraInputTypes.ArcRotateCameraPointersInput=t})(e||(e={}));var e;!(function(e){var t=(function(t){function i(e){return t.call(this,e)||this}return __extends(i,t),i.prototype.addMouseWheel=function(){return this.add(new e.ArcRotateCameraMouseWheelInput),this},i.prototype.addPointers=function(){return this.add(new e.ArcRotateCameraPointersInput),this},i.prototype.addKeyboard=function(){return this.add(new e.ArcRotateCameraKeyboardMoveInput),this},i.prototype.addGamepad=function(){return this.add(new e.ArcRotateCameraGamepadInput),this},i.prototype.addVRDeviceOrientation=function(){return this.add(new e.ArcRotateCameraVRDeviceOrientationInput),this},i})(e.CameraInputsManager);e.ArcRotateCameraInputsManager=t})(e||(e={}));var e;!(function(e){var t=(function(t){function i(i,r,n,o,s,a){var l=t.call(this,i,e.Vector3.Zero(),a)||this;return l.inertialAlphaOffset=0,l.inertialBetaOffset=0,l.inertialRadiusOffset=0,l.lowerAlphaLimit=null,l.upperAlphaLimit=null,l.lowerBetaLimit=.01,l.upperBetaLimit=Math.PI,l.lowerRadiusLimit=null,l.upperRadiusLimit=null,l.inertialPanningX=0,l.inertialPanningY=0,l.pinchToPanMaxDistance=20,l.panningDistanceLimit=null,l.panningOriginTarget=e.Vector3.Zero(),l.panningInertia=.9,l.zoomOnFactor=1,l.targetScreenOffset=e.Vector2.Zero(),l.allowUpsideDown=!0,l._viewMatrix=new e.Matrix,l.panningAxis=new e.Vector3(1,1,0),l.onMeshTargetChangedObservable=new e.Observable,l.checkCollisions=!1,l.collisionRadius=new e.Vector3(.5,.5,.5),l._previousPosition=e.Vector3.Zero(),l._collisionVelocity=e.Vector3.Zero(),l._newPosition=e.Vector3.Zero(),l._computationVector=e.Vector3.Zero(),l._onCollisionPositionChange=function(t,i,r){void 0===r&&(r=null),l.getScene().workerCollisions&&l.checkCollisions&&i.multiplyInPlace(l._collider._radius),r?(l.setPosition(i),l.onCollide&&l.onCollide(r)):l._previousPosition.copyFrom(l.position);var n=Math.cos(l.alpha),o=Math.sin(l.alpha),s=Math.cos(l.beta),a=Math.sin(l.beta);0===a&&(a=1e-4);var c=l._getTargetPosition();l._computationVector.copyFromFloats(l.radius*n*a,l.radius*s,l.radius*o*a),c.addToRef(l._computationVector,l._newPosition),l.position.copyFrom(l._newPosition);var h=l.upVector;l.allowUpsideDown&&l.beta<0&&(h=h.clone(),h=h.negate()),e.Matrix.LookAtLHToRef(l.position,c,h,l._viewMatrix),l._viewMatrix.m[12]+=l.targetScreenOffset.x,l._viewMatrix.m[13]+=l.targetScreenOffset.y,l._collisionTriggered=!1},l._target=e.Vector3.Zero(),s&&l.setTarget(s),l.alpha=r,l.beta=n,l.radius=o,l.getViewMatrix(),l.inputs=new e.ArcRotateCameraInputsManager(l),l.inputs.addKeyboard().addMouseWheel().addPointers(),l}return __extends(i,t),Object.defineProperty(i.prototype,"target",{get:function(){return this._target},set:function(e){this.setTarget(e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"angularSensibilityX",{get:function(){var e=this.inputs.attached.pointers;return e?e.angularSensibilityX:0},set:function(e){var t=this.inputs.attached.pointers;t&&(t.angularSensibilityX=e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"angularSensibilityY",{get:function(){var e=this.inputs.attached.pointers;return e?e.angularSensibilityY:0},set:function(e){var t=this.inputs.attached.pointers;t&&(t.angularSensibilityY=e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"pinchPrecision",{get:function(){var e=this.inputs.attached.pointers;return e?e.pinchPrecision:0},set:function(e){var t=this.inputs.attached.pointers;t&&(t.pinchPrecision=e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"pinchDeltaPercentage",{get:function(){var e=this.inputs.attached.pointers;return e?e.pinchDeltaPercentage:0},set:function(e){var t=this.inputs.attached.pointers;t&&(t.pinchDeltaPercentage=e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"panningSensibility",{get:function(){var e=this.inputs.attached.pointers;return e?e.panningSensibility:0},set:function(e){var t=this.inputs.attached.pointers;t&&(t.panningSensibility=e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"keysUp",{get:function(){var e=this.inputs.attached.keyboard;return e?e.keysUp:[]},set:function(e){var t=this.inputs.attached.keyboard;t&&(t.keysUp=e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"keysDown",{get:function(){var e=this.inputs.attached.keyboard;return e?e.keysDown:[]},set:function(e){var t=this.inputs.attached.keyboard;t&&(t.keysDown=e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"keysLeft",{get:function(){var e=this.inputs.attached.keyboard;return e?e.keysLeft:[]},set:function(e){var t=this.inputs.attached.keyboard;t&&(t.keysLeft=e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"keysRight",{get:function(){var e=this.inputs.attached.keyboard;return e?e.keysRight:[]},set:function(e){var t=this.inputs.attached.keyboard;t&&(t.keysRight=e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"wheelPrecision",{get:function(){var e=this.inputs.attached.mousewheel;return e?e.wheelPrecision:0},set:function(e){var t=this.inputs.attached.mousewheel;t&&(t.wheelPrecision=e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"wheelDeltaPercentage",{get:function(){var e=this.inputs.attached.mousewheel;return e?e.wheelDeltaPercentage:0},set:function(e){var t=this.inputs.attached.mousewheel;t&&(t.wheelDeltaPercentage=e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"bouncingBehavior",{get:function(){return this._bouncingBehavior},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"useBouncingBehavior",{get:function(){return null!=this._bouncingBehavior},set:function(t){t!==this.useBouncingBehavior&&(t?(this._bouncingBehavior=new e.BouncingBehavior,this.addBehavior(this._bouncingBehavior)):this._bouncingBehavior&&(this.removeBehavior(this._bouncingBehavior),this._bouncingBehavior=null))},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"framingBehavior",{get:function(){return this._framingBehavior},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"useFramingBehavior",{get:function(){return null!=this._framingBehavior},set:function(t){t!==this.useFramingBehavior&&(t?(this._framingBehavior=new e.FramingBehavior,this.addBehavior(this._framingBehavior)):this._framingBehavior&&(this.removeBehavior(this._framingBehavior),this._framingBehavior=null))},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"autoRotationBehavior",{get:function(){return this._autoRotationBehavior},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"useAutoRotationBehavior",{get:function(){return null!=this._autoRotationBehavior},set:function(t){t!==this.useAutoRotationBehavior&&(t?(this._autoRotationBehavior=new e.AutoRotationBehavior,this.addBehavior(this._autoRotationBehavior)):this._autoRotationBehavior&&(this.removeBehavior(this._autoRotationBehavior),this._autoRotationBehavior=null))},enumerable:!0,configurable:!0}),i.prototype._initCache=function(){t.prototype._initCache.call(this),this._cache._target=new e.Vector3(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),this._cache.alpha=void 0,this._cache.beta=void 0,this._cache.radius=void 0,this._cache.targetScreenOffset=e.Vector2.Zero()},i.prototype._updateCache=function(e){e||t.prototype._updateCache.call(this),this._cache._target.copyFrom(this._getTargetPosition()),this._cache.alpha=this.alpha,this._cache.beta=this.beta,this._cache.radius=this.radius,this._cache.targetScreenOffset.copyFrom(this.targetScreenOffset)},i.prototype._getTargetPosition=function(){if(this._targetHost&&this._targetHost.getAbsolutePosition){var e=this._targetHost.getAbsolutePosition();this._targetBoundingCenter?e.addToRef(this._targetBoundingCenter,this._target):this._target.copyFrom(e)}var t=this._getLockedTargetPosition();return t||this._target},i.prototype.storeState=function(){return this._storedAlpha=this.alpha,this._storedBeta=this.beta,this._storedRadius=this.radius,this._storedTarget=this._getTargetPosition().clone(),t.prototype.storeState.call(this)},i.prototype._restoreStateValues=function(){return!!t.prototype._restoreStateValues.call(this)&&(this.alpha=this._storedAlpha,this.beta=this._storedBeta,this.radius=this._storedRadius,this.setTarget(this._storedTarget.clone()),this.inertialAlphaOffset=0,this.inertialBetaOffset=0,this.inertialRadiusOffset=0,this.inertialPanningX=0,this.inertialPanningY=0,!0)},i.prototype._isSynchronizedViewMatrix=function(){return!!t.prototype._isSynchronizedViewMatrix.call(this)&&(this._cache._target.equals(this._getTargetPosition())&&this._cache.alpha===this.alpha&&this._cache.beta===this.beta&&this._cache.radius===this.radius&&this._cache.targetScreenOffset.equals(this.targetScreenOffset))},i.prototype.attachControl=function(e,t,i,r){var n=this;void 0===i&&(i=!0),void 0===r&&(r=2),this._useCtrlForPanning=i,this._panningMouseButton=r,this.inputs.attachElement(e,t),this._reset=function(){n.inertialAlphaOffset=0,n.inertialBetaOffset=0,n.inertialRadiusOffset=0,n.inertialPanningX=0,n.inertialPanningY=0}},i.prototype.detachControl=function(e){this.inputs.detachElement(e),this._reset&&this._reset()},i.prototype._checkInputs=function(){if(!this._collisionTriggered){if(this.inputs.checkInputs(),0===this.inertialAlphaOffset&&0===this.inertialBetaOffset&&0===this.inertialRadiusOffset||(this.getScene().useRightHandedSystem?this.alpha-=this.beta<=0?-this.inertialAlphaOffset:this.inertialAlphaOffset:this.alpha+=this.beta<=0?-this.inertialAlphaOffset:this.inertialAlphaOffset,this.beta+=this.inertialBetaOffset,this.radius-=this.inertialRadiusOffset,this.inertialAlphaOffset*=this.inertia,this.inertialBetaOffset*=this.inertia,this.inertialRadiusOffset*=this.inertia,Math.abs(this.inertialAlphaOffset)Math.PI&&(this.beta=this.beta-2*Math.PI):this.betathis.upperBetaLimit&&(this.beta=this.upperBetaLimit),this.lowerAlphaLimit&&this.alphathis.upperAlphaLimit&&(this.alpha=this.upperAlphaLimit),this.lowerRadiusLimit&&this.radiusthis.upperRadiusLimit&&(this.radius=this.upperRadiusLimit)},i.prototype.rebuildAnglesAndRadius=function(){this.position.subtractToRef(this._getTargetPosition(),this._computationVector),this.radius=this._computationVector.length(),0===this.radius&&(this.radius=1e-4),this.alpha=Math.acos(this._computationVector.x/Math.sqrt(Math.pow(this._computationVector.x,2)+Math.pow(this._computationVector.z,2))),this._computationVector.z<0&&(this.alpha=2*Math.PI-this.alpha),this.beta=Math.acos(this._computationVector.y/this.radius),this._checkLimits()},i.prototype.setPosition=function(e){this.position.equals(e)||(this.position.copyFrom(e),this.rebuildAnglesAndRadius())},i.prototype.setTarget=function(e,t,i){if(void 0===t&&(t=!1),void 0===i&&(i=!1),e.getBoundingInfo)this._targetBoundingCenter=t?e.getBoundingInfo().boundingBox.centerWorld.clone():null,this._targetHost=e,this._target=this._getTargetPosition(),this.onMeshTargetChangedObservable.notifyObservers(this._targetHost);else{var r=e,n=this._getTargetPosition();if(n&&!i&&n.equals(r))return;this._targetHost=null,this._target=r,this._targetBoundingCenter=null,this.onMeshTargetChangedObservable.notifyObservers(null)}this.rebuildAnglesAndRadius()},i.prototype._getViewMatrix=function(){var t=Math.cos(this.alpha),i=Math.sin(this.alpha),r=Math.cos(this.beta),n=Math.sin(this.beta);0===n&&(n=1e-4);var o=this._getTargetPosition();if(this._computationVector.copyFromFloats(this.radius*t*n,this.radius*r,this.radius*i*n),o.addToRef(this._computationVector,this._newPosition),this.getScene().collisionsEnabled&&this.checkCollisions)this._collider||(this._collider=new e.Collider),this._collider._radius=this.collisionRadius,this._newPosition.subtractToRef(this.position,this._collisionVelocity),this._collisionTriggered=!0,this.getScene().collisionCoordinator.getNewPosition(this.position,this._collisionVelocity,this._collider,3,null,this._onCollisionPositionChange,this.uniqueId);else{this.position.copyFrom(this._newPosition);var s=this.upVector;this.allowUpsideDown&&n<0&&(s=s.clone(),s=s.negate()),this.getScene().useRightHandedSystem?e.Matrix.LookAtRHToRef(this.position,o,s,this._viewMatrix):e.Matrix.LookAtLHToRef(this.position,o,s,this._viewMatrix),this._viewMatrix.m[12]+=this.targetScreenOffset.x,this._viewMatrix.m[13]+=this.targetScreenOffset.y}return this._currentTarget=o,this._viewMatrix},i.prototype.zoomOn=function(t,i){void 0===i&&(i=!1),t=t||this.getScene().meshes;var r=e.Mesh.MinMax(t),n=e.Vector3.Distance(r.min,r.max);this.radius=n*this.zoomOnFactor,this.focusOn({min:r.min,max:r.max,distance:n},i)},i.prototype.focusOn=function(t,i){void 0===i&&(i=!1);var r,n;if(void 0===t.min){var o=t||this.getScene().meshes;r=e.Mesh.MinMax(o),n=e.Vector3.Distance(r.min,r.max)}else{var s=t;r=s,n=s.distance}this._target=e.Mesh.Center(r),i||(this.maxZ=2*n)},i.prototype.createRigCamera=function(t,r){var n=0;switch(this.cameraRigMode){case e.Camera.RIG_MODE_STEREOSCOPIC_ANAGLYPH:case e.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL:case e.Camera.RIG_MODE_STEREOSCOPIC_OVERUNDER:case e.Camera.RIG_MODE_VR:n=this._cameraRigParams.stereoHalfAngle*(0===r?1:-1);break;case e.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED:n=this._cameraRigParams.stereoHalfAngle*(0===r?-1:1)}var o=new i(t,this.alpha+n,this.beta,this.radius,this._target,this.getScene());return o._cameraRigParams={},o},i.prototype._updateRigCameras=function(){var i=this._rigCameras[0],r=this._rigCameras[1];switch(i.beta=r.beta=this.beta,i.radius=r.radius=this.radius,this.cameraRigMode){case e.Camera.RIG_MODE_STEREOSCOPIC_ANAGLYPH:case e.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL:case e.Camera.RIG_MODE_STEREOSCOPIC_OVERUNDER:case e.Camera.RIG_MODE_VR:i.alpha=this.alpha-this._cameraRigParams.stereoHalfAngle,r.alpha=this.alpha+this._cameraRigParams.stereoHalfAngle;break;case e.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED:i.alpha=this.alpha+this._cameraRigParams.stereoHalfAngle,r.alpha=this.alpha-this._cameraRigParams.stereoHalfAngle}t.prototype._updateRigCameras.call(this)},i.prototype.dispose=function(){this.inputs.clear(),t.prototype.dispose.call(this)},i.prototype.getClassName=function(){return"ArcRotateCamera"},__decorate([e.serialize()],i.prototype,"alpha",void 0),__decorate([e.serialize()],i.prototype,"beta",void 0),__decorate([e.serialize()],i.prototype,"radius",void 0),__decorate([e.serializeAsVector3("target")],i.prototype,"_target",void 0),__decorate([e.serialize()],i.prototype,"inertialAlphaOffset",void 0),__decorate([e.serialize()],i.prototype,"inertialBetaOffset",void 0),__decorate([e.serialize()],i.prototype,"inertialRadiusOffset",void 0),__decorate([e.serialize()],i.prototype,"lowerAlphaLimit",void 0),__decorate([e.serialize()],i.prototype,"upperAlphaLimit",void 0),__decorate([e.serialize()],i.prototype,"lowerBetaLimit",void 0),__decorate([e.serialize()],i.prototype,"upperBetaLimit",void 0),__decorate([e.serialize()],i.prototype,"lowerRadiusLimit",void 0),__decorate([e.serialize()],i.prototype,"upperRadiusLimit",void 0),__decorate([e.serialize()],i.prototype,"inertialPanningX",void 0),__decorate([e.serialize()],i.prototype,"inertialPanningY",void 0),__decorate([e.serialize()],i.prototype,"pinchToPanMaxDistance",void 0),__decorate([e.serialize()],i.prototype,"panningDistanceLimit",void 0),__decorate([e.serializeAsVector3()],i.prototype,"panningOriginTarget",void 0),__decorate([e.serialize()],i.prototype,"panningInertia",void 0),__decorate([e.serialize()],i.prototype,"zoomOnFactor",void 0),__decorate([e.serialize()],i.prototype,"allowUpsideDown",void 0),i})(e.TargetCamera);e.ArcRotateCamera=t})(e||(e={}));var e;!(function(e){var t=(function(t){function i(i,r,n){var o=t.call(this,i,n)||this;return o.groundColor=new e.Color3(0,0,0),o.direction=r||e.Vector3.Up(),o}return __extends(i,t),i.prototype._buildUniformLayout=function(){this._uniformBuffer.addUniform("vLightData",4),this._uniformBuffer.addUniform("vLightDiffuse",4),this._uniformBuffer.addUniform("vLightSpecular",3),this._uniformBuffer.addUniform("vLightGround",3),this._uniformBuffer.addUniform("shadowsInfo",3),this._uniformBuffer.addUniform("depthValues",2),this._uniformBuffer.create()},i.prototype.getClassName=function(){return"HemisphericLight"},i.prototype.setDirectionToTarget=function(t){return this.direction=e.Vector3.Normalize(t.subtract(e.Vector3.Zero())),this.direction},i.prototype.getShadowGenerator=function(){return null},i.prototype.transferToEffect=function(t,i){var r=e.Vector3.Normalize(this.direction);return this._uniformBuffer.updateFloat4("vLightData",r.x,r.y,r.z,0,i),this._uniformBuffer.updateColor3("vLightGround",this.groundColor.scale(this.intensity),i),this},i.prototype._getWorldMatrix=function(){return this._worldMatrix||(this._worldMatrix=e.Matrix.Identity()),this._worldMatrix},i.prototype.getTypeID=function(){return e.Light.LIGHTTYPEID_HEMISPHERICLIGHT},__decorate([e.serializeAsColor3()],i.prototype,"groundColor",void 0),__decorate([e.serializeAsVector3()],i.prototype,"direction",void 0),i})(e.Light);e.HemisphericLight=t})(e||(e={}));var e;!(function(e){var t=(function(t){function i(){var e=null!==t&&t.apply(this,arguments)||this;return e._needProjectionMatrixCompute=!0,e}return __extends(i,t),i.prototype._setPosition=function(e){this._position=e},Object.defineProperty(i.prototype,"position",{get:function(){return this._position},set:function(e){this._setPosition(e)},enumerable:!0,configurable:!0}),i.prototype._setDirection=function(e){this._direction=e},Object.defineProperty(i.prototype,"direction",{get:function(){return this._direction},set:function(e){this._setDirection(e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"shadowMinZ",{get:function(){return this._shadowMinZ},set:function(e){this._shadowMinZ=e,this.forceProjectionMatrixCompute()},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"shadowMaxZ",{get:function(){return this._shadowMaxZ},set:function(e){this._shadowMaxZ=e,this.forceProjectionMatrixCompute()},enumerable:!0,configurable:!0}),i.prototype.computeTransformedInformation=function(){return!(!this.parent||!this.parent.getWorldMatrix)&&(this.transformedPosition||(this.transformedPosition=e.Vector3.Zero()),e.Vector3.TransformCoordinatesToRef(this.position,this.parent.getWorldMatrix(),this.transformedPosition),this.direction&&(this.transformedDirection||(this.transformedDirection=e.Vector3.Zero()),e.Vector3.TransformNormalToRef(this.direction,this.parent.getWorldMatrix(),this.transformedDirection)),!0)},i.prototype.getDepthScale=function(){return 50},i.prototype.getShadowDirection=function(e){return this.transformedDirection?this.transformedDirection:this.direction},i.prototype.getAbsolutePosition=function(){return this.transformedPosition?this.transformedPosition:this.position},i.prototype.setDirectionToTarget=function(t){return this.direction=e.Vector3.Normalize(t.subtract(this.position)),this.direction},i.prototype.getRotation=function(){this.direction.normalize();var t=e.Vector3.Cross(this.direction,e.Axis.Y),i=e.Vector3.Cross(t,this.direction);return e.Vector3.RotationFromAxis(t,i,this.direction)},i.prototype.needCube=function(){return!1},i.prototype.needProjectionMatrixCompute=function(){return this._needProjectionMatrixCompute},i.prototype.forceProjectionMatrixCompute=function(){this._needProjectionMatrixCompute=!0},i.prototype._getWorldMatrix=function(){return this._worldMatrix||(this._worldMatrix=e.Matrix.Identity()),e.Matrix.TranslationToRef(this.position.x,this.position.y,this.position.z,this._worldMatrix),this._worldMatrix},i.prototype.getDepthMinZ=function(e){return void 0!==this.shadowMinZ?this.shadowMinZ:e.minZ},i.prototype.getDepthMaxZ=function(e){return void 0!==this.shadowMaxZ?this.shadowMaxZ:e.maxZ},i.prototype.setShadowProjectionMatrix=function(e,t,i){return this.customProjectionMatrixBuilder?this.customProjectionMatrixBuilder(t,i,e):this._setDefaultShadowProjectionMatrix(e,t,i),this},__decorate([e.serializeAsVector3()],i.prototype,"position",null),__decorate([e.serializeAsVector3()],i.prototype,"direction",null),__decorate([e.serialize()],i.prototype,"shadowMinZ",null),__decorate([e.serialize()],i.prototype,"shadowMaxZ",null),i})(e.Light);e.ShadowLight=t})(e||(e={}));var e;!(function(e){var t=(function(t){function i(e,i,r){var n=t.call(this,e,r)||this;return n._shadowAngle=Math.PI/2,n.position=i,n}return __extends(i,t),Object.defineProperty(i.prototype,"shadowAngle",{get:function(){return this._shadowAngle},set:function(e){this._shadowAngle=e,this.forceProjectionMatrixCompute()},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"direction",{get:function(){return this._direction},set:function(e){var t=this.needCube();this._direction=e,this.needCube()!==t&&this._shadowGenerator&&this._shadowGenerator.recreateShadowMap()},enumerable:!0,configurable:!0}),i.prototype.getClassName=function(){return"PointLight"},i.prototype.getTypeID=function(){return e.Light.LIGHTTYPEID_POINTLIGHT},i.prototype.needCube=function(){return!this.direction},i.prototype.getShadowDirection=function(i){if(this.direction)return t.prototype.getShadowDirection.call(this,i);switch(i){case 0:return new e.Vector3(1,0,0);case 1:return new e.Vector3(-1,0,0);case 2:return new e.Vector3(0,-1,0);case 3:return new e.Vector3(0,1,0);case 4:return new e.Vector3(0,0,1);case 5:return new e.Vector3(0,0,-1)}return e.Vector3.Zero()},i.prototype._setDefaultShadowProjectionMatrix=function(t,i,r){var n=this.getScene().activeCamera;n&&e.Matrix.PerspectiveFovLHToRef(this.shadowAngle,1,this.getDepthMinZ(n),this.getDepthMaxZ(n),t)},i.prototype._buildUniformLayout=function(){this._uniformBuffer.addUniform("vLightData",4),this._uniformBuffer.addUniform("vLightDiffuse",4),this._uniformBuffer.addUniform("vLightSpecular",3),this._uniformBuffer.addUniform("shadowsInfo",3),this._uniformBuffer.addUniform("depthValues",2),this._uniformBuffer.create()},i.prototype.transferToEffect=function(e,t){return this.computeTransformedInformation()?(this._uniformBuffer.updateFloat4("vLightData",this.transformedPosition.x,this.transformedPosition.y,this.transformedPosition.z,0,t),this):(this._uniformBuffer.updateFloat4("vLightData",this.position.x,this.position.y,this.position.z,0,t),this)},__decorate([e.serialize()],i.prototype,"shadowAngle",null),i})(e.ShadowLight);e.PointLight=t})(e||(e={}));var e;!(function(e){var t=(function(t){function i(e,i,r){var n=t.call(this,e,r)||this;return n._shadowFrustumSize=0,n._shadowOrthoScale=.5,n.autoUpdateExtends=!0,n._orthoLeft=Number.MAX_VALUE,n._orthoRight=Number.MIN_VALUE,n._orthoTop=Number.MIN_VALUE,n._orthoBottom=Number.MAX_VALUE,n.position=i.scale(-1),n.direction=i,n}return __extends(i,t),Object.defineProperty(i.prototype,"shadowFrustumSize",{get:function(){return this._shadowFrustumSize},set:function(e){this._shadowFrustumSize=e,this.forceProjectionMatrixCompute()},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"shadowOrthoScale",{get:function(){return this._shadowOrthoScale},set:function(e){this._shadowOrthoScale=e,this.forceProjectionMatrixCompute()},enumerable:!0,configurable:!0}),i.prototype.getClassName=function(){return"DirectionalLight"},i.prototype.getTypeID=function(){return e.Light.LIGHTTYPEID_DIRECTIONALLIGHT},i.prototype._setDefaultShadowProjectionMatrix=function(e,t,i){this.shadowFrustumSize>0?this._setDefaultFixedFrustumShadowProjectionMatrix(e,t):this._setDefaultAutoExtendShadowProjectionMatrix(e,t,i)},i.prototype._setDefaultFixedFrustumShadowProjectionMatrix=function(t,i){var r=this.getScene().activeCamera;r&&e.Matrix.OrthoLHToRef(this.shadowFrustumSize,this.shadowFrustumSize,void 0!==this.shadowMinZ?this.shadowMinZ:r.minZ,void 0!==this.shadowMaxZ?this.shadowMaxZ:r.maxZ,t)},i.prototype._setDefaultAutoExtendShadowProjectionMatrix=function(t,i,r){var n=this.getScene().activeCamera;if(n){if(this.autoUpdateExtends||this._orthoLeft===Number.MAX_VALUE){var o=e.Vector3.Zero();this._orthoLeft=Number.MAX_VALUE,this._orthoRight=Number.MIN_VALUE,this._orthoTop=Number.MIN_VALUE,this._orthoBottom=Number.MAX_VALUE;for(var s=0;sthis._orthoRight&&(this._orthoRight=o.x),o.y>this._orthoTop&&(this._orthoTop=o.y)}}var u=this._orthoRight-this._orthoLeft,f=this._orthoTop-this._orthoBottom;e.Matrix.OrthoOffCenterLHToRef(this._orthoLeft-u*this.shadowOrthoScale,this._orthoRight+u*this.shadowOrthoScale,this._orthoBottom-f*this.shadowOrthoScale,this._orthoTop+f*this.shadowOrthoScale,void 0!==this.shadowMinZ?this.shadowMinZ:n.minZ,void 0!==this.shadowMaxZ?this.shadowMaxZ:n.maxZ,t)}},i.prototype._buildUniformLayout=function(){this._uniformBuffer.addUniform("vLightData",4),this._uniformBuffer.addUniform("vLightDiffuse",4),this._uniformBuffer.addUniform("vLightSpecular",3),this._uniformBuffer.addUniform("shadowsInfo",3),this._uniformBuffer.addUniform("depthValues",2),this._uniformBuffer.create()},i.prototype.transferToEffect=function(e,t){return this.computeTransformedInformation()?(this._uniformBuffer.updateFloat4("vLightData",this.transformedDirection.x,this.transformedDirection.y,this.transformedDirection.z,1,t),this):(this._uniformBuffer.updateFloat4("vLightData",this.direction.x,this.direction.y,this.direction.z,1,t),this)},i.prototype.getDepthMinZ=function(e){return 1},i.prototype.getDepthMaxZ=function(e){return 1},__decorate([e.serialize()],i.prototype,"shadowFrustumSize",null),__decorate([e.serialize()],i.prototype,"shadowOrthoScale",null),__decorate([e.serialize()],i.prototype,"autoUpdateExtends",void 0),i})(e.ShadowLight);e.DirectionalLight=t})(e||(e={}));var e;!(function(e){var t=(function(t){function i(i,r,n,o,s,a){var l=t.call(this,i,a)||this;return l._projectionTextureMatrix=e.Matrix.Zero(),l._projectionTextureLightNear=1e-6,l._projectionTextureLightFar=1e3,l._projectionTextureUpDirection=e.Vector3.Up(),l._projectionTextureViewLightDirty=!0,l._projectionTextureProjectionLightDirty=!0,l._projectionTextureDirty=!0,l._projectionTextureViewTargetVector=e.Vector3.Zero(),l._projectionTextureViewLightMatrix=e.Matrix.Zero(),l._projectionTextureProjectionLightMatrix=e.Matrix.Zero(),l._projectionTextureScalingMatrix=e.Matrix.FromValues(.5,0,0,0,0,.5,0,0,0,0,.5,0,.5,.5,.5,1),l.position=r,l.direction=n,l.angle=o,l.exponent=s,l}return __extends(i,t),Object.defineProperty(i.prototype,"angle",{get:function(){return this._angle},set:function(e){this._angle=e,this._projectionTextureProjectionLightDirty=!0,this.forceProjectionMatrixCompute()},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"shadowAngleScale",{get:function(){return this._shadowAngleScale},set:function(e){this._shadowAngleScale=e,this.forceProjectionMatrixCompute()},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"projectionTextureMatrix",{get:function(){return this._projectionTextureMatrix},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"projectionTextureLightNear",{get:function(){return this._projectionTextureLightNear},set:function(e){this._projectionTextureLightNear=e,this._projectionTextureProjectionLightDirty=!0},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"projectionTextureLightFar",{get:function(){return this._projectionTextureLightFar},set:function(e){this._projectionTextureLightFar=e,this._projectionTextureProjectionLightDirty=!0},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"projectionTextureUpDirection",{get:function(){return this._projectionTextureUpDirection},set:function(e){this._projectionTextureUpDirection=e,this._projectionTextureProjectionLightDirty=!0},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"projectionTexture",{get:function(){return this._projectionTexture},set:function(e){this._projectionTexture=e,this._projectionTextureDirty=!0},enumerable:!0,configurable:!0}),i.prototype.getClassName=function(){return"SpotLight"},i.prototype.getTypeID=function(){return e.Light.LIGHTTYPEID_SPOTLIGHT},i.prototype._setDirection=function(e){t.prototype._setDirection.call(this,e),this._projectionTextureViewLightDirty=!0},i.prototype._setPosition=function(e){t.prototype._setPosition.call(this,e),this._projectionTextureViewLightDirty=!0},i.prototype._setDefaultShadowProjectionMatrix=function(t,i,r){var n=this.getScene().activeCamera;if(n){this._shadowAngleScale=this._shadowAngleScale||1;var o=this._shadowAngleScale*this._angle;e.Matrix.PerspectiveFovLHToRef(o,1,this.getDepthMinZ(n),this.getDepthMaxZ(n),t)}},i.prototype._computeProjectionTextureViewLightMatrix=function(){this._projectionTextureViewLightDirty=!1,this._projectionTextureDirty=!0,this.position.addToRef(this.direction,this._projectionTextureViewTargetVector),e.Matrix.LookAtLHToRef(this.position,this._projectionTextureViewTargetVector,this._projectionTextureUpDirection,this._projectionTextureViewLightMatrix)},i.prototype._computeProjectionTextureProjectionLightMatrix=function(){this._projectionTextureProjectionLightDirty=!1,this._projectionTextureDirty=!0;var t=this.projectionTextureLightFar,i=this.projectionTextureLightNear,r=t/(t-i),n=-r*i,o=1/Math.tan(this._angle/2);e.Matrix.FromValuesToRef(o/1,0,0,0,0,o,0,0,0,0,r,1,0,0,n,0,this._projectionTextureProjectionLightMatrix)},i.prototype._computeProjectionTextureMatrix=function(){this._projectionTextureDirty=!1,this._projectionTextureViewLightMatrix.multiplyToRef(this._projectionTextureProjectionLightMatrix,this._projectionTextureMatrix),this._projectionTextureMatrix.multiplyToRef(this._projectionTextureScalingMatrix,this._projectionTextureMatrix)},i.prototype._buildUniformLayout=function(){this._uniformBuffer.addUniform("vLightData",4),this._uniformBuffer.addUniform("vLightDiffuse",4),this._uniformBuffer.addUniform("vLightSpecular",3),this._uniformBuffer.addUniform("vLightDirection",3),this._uniformBuffer.addUniform("shadowsInfo",3),this._uniformBuffer.addUniform("depthValues",2),this._uniformBuffer.create()},i.prototype.transferToEffect=function(t,i){var r;return this.computeTransformedInformation()?(this._uniformBuffer.updateFloat4("vLightData",this.transformedPosition.x,this.transformedPosition.y,this.transformedPosition.z,this.exponent,i),r=e.Vector3.Normalize(this.transformedDirection)):(this._uniformBuffer.updateFloat4("vLightData",this.position.x,this.position.y,this.position.z,this.exponent,i),r=e.Vector3.Normalize(this.direction)),this._uniformBuffer.updateFloat4("vLightDirection",r.x,r.y,r.z,Math.cos(.5*this.angle),i),this.projectionTexture&&this.projectionTexture.isReady()&&(this._projectionTextureViewLightDirty&&this._computeProjectionTextureViewLightMatrix(),this._projectionTextureProjectionLightDirty&&this._computeProjectionTextureProjectionLightMatrix(),this._projectionTextureDirty&&this._computeProjectionTextureMatrix(),t.setMatrix("textureProjectionMatrix"+i,this._projectionTextureMatrix),t.setTexture("projectionLightSampler"+i,this.projectionTexture)),this},i.prototype.dispose=function(){t.prototype.dispose.call(this),this._projectionTexture&&this._projectionTexture.dispose()},__decorate([e.serialize()],i.prototype,"angle",null),__decorate([e.serialize()],i.prototype,"shadowAngleScale",null),__decorate([e.serialize()],i.prototype,"exponent",void 0),__decorate([e.serialize()],i.prototype,"projectionTextureLightNear",null),__decorate([e.serialize()],i.prototype,"projectionTextureLightFar",null),__decorate([e.serialize()],i.prototype,"projectionTextureUpDirection",null),__decorate([e.serializeAsTexture("projectedLightTexture")],i.prototype,"_projectionTexture",void 0),i})(e.ShadowLight);e.SpotLight=t})(e||(e={}));var e;!(function(e){var t=(function(){function t(){this.enableBlending=!1,this.blendingSpeed=.01,this.loopMode=e.Animation.ANIMATIONLOOPMODE_CYCLE}return t})();e.AnimationPropertiesOverride=t})(e||(e={}));var e;!(function(e){var t=(function(){function e(e,t,i){this.name=e,this.from=t,this.to=i}return e.prototype.clone=function(){return new e(this.name,this.from,this.to)},e})();e.AnimationRange=t;var i=(function(){function e(e,t,i){this.frame=e,this.action=t,this.onlyOnce=i,this.isDone=!1}return e})();e.AnimationEvent=i;var r=(function(){function t(e){this.path=e,this._onchange=new Array,this.value=0,this.animations=new Array}return t.prototype.getPoint=function(){var t=this.path.getPointAtLengthPosition(this.value);return new e.Vector3(t.x,0,t.y)},t.prototype.moveAhead=function(e){return void 0===e&&(e=.002),this.move(e),this},t.prototype.moveBack=function(e){return void 0===e&&(e=.002),this.move(-e),this},t.prototype.move=function(e){if(Math.abs(e)>1)throw"step size should be less than 1.";return this.value+=e,this.ensureLimits(),this.raiseOnChange(),this},t.prototype.ensureLimits=function(){for(;this.value>1;)this.value-=1;for(;this.value<0;)this.value+=1;return this},t.prototype.raiseOnChange=function(){var e=this;return this._onchange.forEach((function(t){return t(e)})),this},t.prototype.onchange=function(e){return this._onchange.push(e),this},t})();e.PathCursor=r;!(function(e){e[e.STEP=1]="STEP"})(e.AnimationKeyInterpolation||(e.AnimationKeyInterpolation={}));var n=(function(){function i(e,t,r,n,o,s){this.name=e,this.targetProperty=t,this.framePerSecond=r,this.dataType=n,this.loopMode=o,this.enableBlending=s,this._runtimeAnimations=new Array,this._events=new Array,this.blendingSpeed=.01,this._ranges={},this.targetPropertyPath=t.split("."),this.dataType=n,this.loopMode=void 0===o?i.ANIMATIONLOOPMODE_CYCLE:o}return i._PrepareAnimation=function(t,r,n,o,s,a,l,c){var h=void 0;if(!isNaN(parseFloat(s))&&isFinite(s)?h=i.ANIMATIONTYPE_FLOAT:s instanceof e.Quaternion?h=i.ANIMATIONTYPE_QUATERNION:s instanceof e.Vector3?h=i.ANIMATIONTYPE_VECTOR3:s instanceof e.Vector2?h=i.ANIMATIONTYPE_VECTOR2:s instanceof e.Color3?h=i.ANIMATIONTYPE_COLOR3:s instanceof e.Size&&(h=i.ANIMATIONTYPE_SIZE),void 0==h)return null;var u=new i(t,r,n,h,l),f=[{frame:0,value:s},{frame:o,value:a}];return u.setKeys(f),void 0!==c&&u.setEasingFunction(c),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,l,c,h){var u=i._PrepareAnimation(e,r,n,o,s,a,l,c);return u?t.getScene().beginDirectAnimation(t,[u],0,o,1===u.loopMode,1,h):null},i.CreateAndStartHierarchyAnimation=function(e,t,r,n,o,s,a,l,c,h,u){var f=i._PrepareAnimation(e,n,o,s,a,l,c,h);return f?t.getScene().beginDirectHierarchyAnimation(t,r,[f],0,s,1===f.loopMode,1,u):null},i.CreateMergeAndStartAnimation=function(e,t,r,n,o,s,a,l,c,h){var u=i._PrepareAnimation(e,r,n,o,s,a,l,c);return u?(t.animations.push(u),t.getScene().beginAnimation(t,0,o,1===u.loopMode,1,h)):null},i.TransitionTo=function(e,t,i,r,n,o,s,a){if(void 0===a&&(a=null),s<=0)return i[e]=t,a&&a(),null;var l=n*(s/1e3);o.setKeys([{frame:0,value:i[e].clone?i[e].clone():i[e]},{frame:l,value:t}]),i.animations||(i.animations=[]),i.animations.push(o);var c=r.beginAnimation(i,0,l,!1);return c.onAnimationEnd=a,c},Object.defineProperty(i.prototype,"runtimeAnimations",{get:function(){return this._runtimeAnimations},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"hasRunningRuntimeAnimations",{get:function(){for(var e=0,t=this._runtimeAnimations;e=0;o--)this._keys[o].frame>=r&&this._keys[o].frame<=n&&this._keys.splice(o,1);this._ranges[e]=null}},i.prototype.getRange=function(e){return this._ranges[e]},i.prototype.getKeys=function(){return this._keys},i.prototype.getHighestFrame=function(){for(var e=0,t=0,i=this._keys.length;t=1&&(l=h.values[1]),h.values.length>=2&&(c=h.values[2]);break;case i.ANIMATIONTYPE_QUATERNION:if(r=e.Quaternion.FromArray(h.values),h.values.length>=8){var u=e.Quaternion.FromArray(h.values.slice(4,8));u.equals(e.Quaternion.Zero())||(l=u)}if(h.values.length>=12){var f=e.Quaternion.FromArray(h.values.slice(8,12));f.equals(e.Quaternion.Zero())||(c=f)}break;case i.ANIMATIONTYPE_MATRIX:r=e.Matrix.FromArray(h.values);break;case i.ANIMATIONTYPE_COLOR3:r=e.Color3.FromArray(h.values);break;case i.ANIMATIONTYPE_VECTOR3:default:r=e.Vector3.FromArray(h.values)}var d={};d.frame=h.frame,d.value=r,void 0!=l&&(d.inTangent=l),void 0!=c&&(d.outTangent=c),a.push(d)}if(o.setKeys(a),t.ranges)for(n=0;nr[0].frame&&(this._from=r[0].frame),this._toe){var a={frame:e,value:o.value,inTangent:o.inTangent,outTangent:o.outTangent,interpolation:o.interpolation};n.splice(0,0,a)}if(s.frame-1&&this._scene.animationGroups.splice(e,1)},t})();e.AnimationGroup=i})(e||(e={}));var e;!(function(e){var t=(function(){function t(e,t){this._offsetsCache={},this._highLimitsCache={},this._stopped=!1,this._blendingFactor=0,this._ratioOffset=0,this._animation=t,this._target=e,t._runtimeAnimations.push(this)}return Object.defineProperty(t.prototype,"animation",{get:function(){return this._animation},enumerable:!0,configurable:!0}),t.prototype.reset=function(){this._offsetsCache={},this._highLimitsCache={},this.currentFrame=0,this._blendingFactor=0,this._originalBlendValue=null},t.prototype.isStopped=function(){return this._stopped},t.prototype.dispose=function(){var e=this._animation.runtimeAnimations.indexOf(this);e>-1&&this._animation.runtimeAnimations.splice(e,1)},t.prototype._getKeyValue=function(e){return"function"==typeof e?e():e},t.prototype._interpolate=function(t,i,r,n,o){if(r===e.Animation.ANIMATIONLOOPMODE_CONSTANT&&i>0)return o.clone?o.clone():o;this.currentFrame=t;var s=this._animation.getKeys(),a=Math.max(0,Math.min(s.length-1,Math.floor(s.length*(t-s[0].frame)/(s[s.length-1].frame-s[0].frame))-1));if(s[a].frame>=t)for(;a-1>=0&&s[a].frame>=t;)a--;for(var l=a;l=t){var h=s[l],u=this._getKeyValue(h.value);if(h.interpolation===e.AnimationKeyInterpolation.STEP)return u;var f=this._getKeyValue(c.value),d=void 0!==h.outTangent&&void 0!==c.inTangent,p=c.frame-h.frame,_=(t-h.frame)/p,m=this._animation.getEasingFunction();switch(null!=m&&(_=m.ease(_)),this._animation.dataType){case e.Animation.ANIMATIONTYPE_FLOAT:var g=d?this._animation.floatInterpolateFunctionWithTangents(u,h.outTangent*p,f,c.inTangent*p,_):this._animation.floatInterpolateFunction(u,f,_);switch(r){case e.Animation.ANIMATIONLOOPMODE_CYCLE:case e.Animation.ANIMATIONLOOPMODE_CONSTANT:return g;case e.Animation.ANIMATIONLOOPMODE_RELATIVE:return n*i+g}break;case e.Animation.ANIMATIONTYPE_QUATERNION:var v=d?this._animation.quaternionInterpolateFunctionWithTangents(u,h.outTangent.scale(p),f,c.inTangent.scale(p),_):this._animation.quaternionInterpolateFunction(u,f,_);switch(r){case e.Animation.ANIMATIONLOOPMODE_CYCLE:case e.Animation.ANIMATIONLOOPMODE_CONSTANT:return v;case e.Animation.ANIMATIONLOOPMODE_RELATIVE:return v.add(n.scale(i))}return v;case e.Animation.ANIMATIONTYPE_VECTOR3:var y=d?this._animation.vector3InterpolateFunctionWithTangents(u,h.outTangent.scale(p),f,c.inTangent.scale(p),_):this._animation.vector3InterpolateFunction(u,f,_);switch(r){case e.Animation.ANIMATIONLOOPMODE_CYCLE:case e.Animation.ANIMATIONLOOPMODE_CONSTANT:return y;case e.Animation.ANIMATIONLOOPMODE_RELATIVE:return y.add(n.scale(i))}case e.Animation.ANIMATIONTYPE_VECTOR2:var b=d?this._animation.vector2InterpolateFunctionWithTangents(u,h.outTangent.scale(p),f,c.inTangent.scale(p),_):this._animation.vector2InterpolateFunction(u,f,_);switch(r){case e.Animation.ANIMATIONLOOPMODE_CYCLE:case e.Animation.ANIMATIONLOOPMODE_CONSTANT:return b;case e.Animation.ANIMATIONLOOPMODE_RELATIVE:return b.add(n.scale(i))}case e.Animation.ANIMATIONTYPE_SIZE:switch(r){case e.Animation.ANIMATIONLOOPMODE_CYCLE:case e.Animation.ANIMATIONLOOPMODE_CONSTANT:return this._animation.sizeInterpolateFunction(u,f,_);case e.Animation.ANIMATIONLOOPMODE_RELATIVE:return this._animation.sizeInterpolateFunction(u,f,_).add(n.scale(i))}case e.Animation.ANIMATIONTYPE_COLOR3:switch(r){case e.Animation.ANIMATIONLOOPMODE_CYCLE:case e.Animation.ANIMATIONLOOPMODE_CONSTANT:return this._animation.color3InterpolateFunction(u,f,_);case e.Animation.ANIMATIONLOOPMODE_RELATIVE:return this._animation.color3InterpolateFunction(u,f,_).add(n.scale(i))}case e.Animation.ANIMATIONTYPE_MATRIX:switch(r){case e.Animation.ANIMATIONLOOPMODE_CYCLE:case e.Animation.ANIMATIONLOOPMODE_CONSTANT:if(e.Animation.AllowMatricesInterpolation)return this._animation.matrixInterpolateFunction(u,f,_);case e.Animation.ANIMATIONLOOPMODE_RELATIVE:return u}}break}}return this._getKeyValue(s[s.length-1].value)},t.prototype.setValue=function(t,i){void 0===i&&(i=!1);var r,n,o=this._animation.targetPropertyPath;if(o.length>1){for(var s=this._target[o[0]],a=1;at[t.length-1].frame&&(e=t[t.length-1].frame);var i=this._interpolate(e,0,this._getCorrectLoopMode());this.setValue(i)},t.prototype._prepareForSpeedRatioChange=function(e){var t=this._previousDelay*(this._animation.framePerSecond*e)/1e3;this._ratioOffset=this._previousRatio-t},t.prototype.animate=function(t,i,r,n,o,s){void 0===s&&(s=!1);var a=this._animation.targetPropertyPath;if(!a||a.length<1)return this._stopped=!0,!1;var l=!0,c=this._animation.getKeys();if(0!==c[0].frame){var h={frame:0,value:c[0].value};c.splice(0,0,h)}(ic[c.length-1].frame)&&(i=c[0].frame),(rc[c.length-1].frame)&&(r=c[c.length-1].frame),i===r&&(i>c[0].frame?i--:ri&&d>f||i>r&&d>0,y=l?i+d%f:r,b=this._interpolate(y,v,this._getCorrectLoopMode(),u,p);this.setValue(b);for(var x=this._animation.getEvents(),T=0;T0&&y>=x[T].frame&&x[T].frame>=i||f<0&&y<=x[T].frame&&x[T].frame<=i){var E=x[T];E.isDone||(E.onlyOnce&&(x.splice(T,1),T--),E.isDone=!0,E.action())}else x[T].isDone&&!x[T].onlyOnce&&(x[T].isDone=!1);return l||(this._stopped=!0),l},t})();e.RuntimeAnimation=t})(e||(e={}));var e;!(function(e){var t=(function(){function t(e,t,i,r,n,o,s,a){void 0===i&&(i=0),void 0===r&&(r=100),void 0===n&&(n=!1),void 0===o&&(o=1),this.target=t,this.fromFrame=i,this.toFrame=r,this.loopAnimation=n,this.onAnimationEnd=s,this._localDelayOffset=null,this._pausedDelay=null,this._runtimeAnimations=new Array,this._paused=!1,this._speedRatio=1,this.animationStarted=!1,a&&this.appendAnimations(t,a),this._speedRatio=o,this._scene=e,e._activeAnimatables.push(this)}return Object.defineProperty(t.prototype,"speedRatio",{get:function(){return this._speedRatio},set:function(e){for(var t=0;t-1){for(var i=this._runtimeAnimations,r=i.length-1;r>=0;r--)"string"==typeof e&&i[r].animation.name!=e||(i[r].dispose(),i.splice(r,1));0==i.length&&(this._scene._activeAnimatables.splice(t,1),this.onAnimationEnd&&this.onAnimationEnd())}}else{var r=this._scene._activeAnimatables.indexOf(this);if(r>-1){this._scene._activeAnimatables.splice(r,1);for(var i=this._runtimeAnimations,r=0;r=.5?.5*(1-this.easeInCore(2*(1-t)))+.5:.5*this.easeInCore(2*t)},e._EASINGMODE_EASEIN=0,e._EASINGMODE_EASEOUT=1,e._EASINGMODE_EASEINOUT=2,e})();e.EasingFunction=t;var i=(function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return __extends(t,e),t.prototype.easeInCore=function(e){return e=Math.max(0,Math.min(1,e)),1-Math.sqrt(1-e*e)},t})(t);e.CircleEase=i;var r=(function(e){function t(t){void 0===t&&(t=1);var i=e.call(this)||this;return i.amplitude=t,i}return __extends(t,e),t.prototype.easeInCore=function(e){var t=Math.max(0,this.amplitude);return Math.pow(e,3)-e*t*Math.sin(3.141592653589793*e)},t})(t);e.BackEase=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 __extends(t,e),t.prototype.easeInCore=function(e){var t=Math.max(0,this.bounces),i=this.bounciness;i<=1&&(i=1.001);var r=Math.pow(i,t),n=1-i,o=(1-r)/n+.5*r,s=e*o,a=Math.log(-s*(1-i)+1)/Math.log(i),l=Math.floor(a),c=l+1,h=(1-Math.pow(i,l))/(n*o),u=(1-Math.pow(i,c))/(n*o),f=.5*(h+u),d=e-f,p=f-h;return-Math.pow(1/i,t-l)/(p*p)*(d-p)*(d+p)},t})(t);e.BounceEase=n;var o=(function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return __extends(t,e),t.prototype.easeInCore=function(e){return e*e*e},t})(t);e.CubicEase=o;var s=(function(e){function t(t,i){void 0===t&&(t=3),void 0===i&&(i=3);var r=e.call(this)||this;return r.oscillations=t,r.springiness=i,r}return __extends(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 __extends(t,e),t.prototype.easeInCore=function(e){return this.exponent<=0?e:(Math.exp(this.exponent*e)-1)/(Math.exp(this.exponent)-1)},t})(t);e.ExponentialEase=a;var l=(function(e){function t(t){void 0===t&&(t=2);var i=e.call(this)||this;return i.power=t,i}return __extends(t,e),t.prototype.easeInCore=function(e){var t=Math.max(0,this.power);return Math.pow(e,t)},t})(t);e.PowerEase=l;var c=(function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return __extends(t,e),t.prototype.easeInCore=function(e){return e*e},t})(t);e.QuadraticEase=c;var h=(function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return __extends(t,e),t.prototype.easeInCore=function(e){return e*e*e*e},t})(t);e.QuarticEase=h;var u=(function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return __extends(t,e),t.prototype.easeInCore=function(e){return e*e*e*e*e},t})(t);e.QuinticEase=u;var f=(function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return __extends(t,e),t.prototype.easeInCore=function(e){return 1-Math.sin(1.5707963267948966*(1-e))},t})(t);e.SineEase=f;var d=(function(t){function i(e,i,r,n){void 0===e&&(e=0),void 0===i&&(i=0),void 0===r&&(r=1),void 0===n&&(n=1);var o=t.call(this)||this;return o.x1=e,o.y1=i,o.x2=r,o.y2=n,o}return __extends(i,t),i.prototype.easeInCore=function(t){return e.BezierCurve.interpolate(t,this.x1,this.y1,this.x2,this.y2)},i})(t);e.BezierCurveEase=d})(e||(e={}));var e;!(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 __extends(i,t),Object.defineProperty(i,"IsEqual",{get:function(){return i._IsEqual},enumerable:!0,configurable:!0}),Object.defineProperty(i,"IsDifferent",{get:function(){return i._IsDifferent},enumerable:!0,configurable:!0}),Object.defineProperty(i,"IsGreater",{get:function(){return i._IsGreater},enumerable:!0,configurable:!0}),Object.defineProperty(i,"IsLesser",{get:function(){return i._IsLesser},enumerable:!0,configurable:!0}),i.prototype.isValid=function(){switch(this.operator){case i.IsGreater:return this._effectiveTarget[this._property]>this.value;case i.IsLesser:return this._effectiveTarget[this._property]-1&&this._scene._actionManagers.splice(e,1)},t.prototype.getScene=function(){return this._scene},t.prototype.hasSpecificTriggers=function(e){for(var t=0;t-1)return!0}return!1},t.prototype.hasSpecificTrigger=function(e){for(var t=0;t=t._OnPickTrigger&&i.trigger<=t._OnPointerOutTrigger)return!0}return!1},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"hasPickTriggers",{get:function(){for(var e=0;e=t._OnPickTrigger&&i.trigger<=t._OnPickUpTrigger)return!0}return!1},enumerable:!0,configurable:!0}),Object.defineProperty(t,"HasTriggers",{get:function(){for(var e in t.Triggers)if(t.Triggers.hasOwnProperty(e))return!0;return!1},enumerable:!0,configurable:!0}),Object.defineProperty(t,"HasPickTriggers",{get:function(){for(var e in t.Triggers)if(t.Triggers.hasOwnProperty(e)){var i=parseInt(e);if(i>=t._OnPickTrigger&&i<=t._OnPickUpTrigger)return!0}return!1},enumerable:!0,configurable:!0}),t.HasSpecificTrigger=function(e){for(var i in t.Triggers)if(t.Triggers.hasOwnProperty(i)){var r=parseInt(i);if(r===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.unregisterAction=function(e){var i=this.actions.indexOf(e);return-1!==i&&(this.actions.splice(i,1),t.Triggers[e.trigger]-=1,0===t.Triggers[e.trigger]&&delete t.Triggers[e.trigger],delete e._actionManager,!0)},t.prototype.processTrigger=function(e,i){for(var r=0;r0;if(2===i.type?f.push(o):f.push(r),_){for(var m=new Array,g=0;g0){var f=u.properties[0].value,d=null===u.properties[0].targetType?f:n.getMeshByName(f);d._meshId&&(d.mesh=n.getMeshByID(d._meshId)),h={trigger:t[u.name],parameter:d}}else h=t[u.name];for(var p=0;p>0;this._vertexData[o+10]=t.cellIndex-s*n,this._vertexData[o+11]=s,this._vertexData[o+12]=t.color.r,this._vertexData[o+13]=t.color.g,this._vertexData[o+14]=t.color.b,this._vertexData[o+15]=t.color.a},t.prototype.intersects=function(t,i,r,n){for(var o=Math.min(this._capacity,this.sprites.length),s=e.Vector3.Zero(),a=e.Vector3.Zero(),l=Number.MAX_VALUE,c=null,h=e.Vector3.Zero(),u=i.getViewMatrix(),f=0;fp&&(l=p,c=d,n))break}}}if(c){var _=new e.PickingInfo;return _.hit=!0,_.pickedSprite=c,_.distance=l,_}return null},t.prototype.render=function(){if(this._effectBase.isReady()&&this._effectFog.isReady()&&this._spriteTexture&&this._spriteTexture.isReady()){for(var t=this._scene.getEngine(),i=this._spriteTexture.getBaseSize(),r=t.getDeltaTime(),n=Math.min(this._capacity,this.sprites.length),o=i.width/this.cellWidth,s=0,a=0;athis._delay&&(this._time=this._time%this._delay,this.cellIndex+=this._direction,this.cellIndex>this._toIndex&&(this._loopAnimation?this.cellIndex=this._fromIndex:(this.cellIndex=this._toIndex,this._animationStarted=!1,this._onAnimationEnd&&this._onAnimationEnd(),this.disposeWhenFinishedAnimating&&this.dispose()))))},t.prototype.dispose=function(){for(var e=0;et.x)return!1}else if(i=1/this.direction.x,r=(e.x-this.origin.x)*i,n=(t.x-this.origin.x)*i,n===-1/0&&(n=1/0),r>n&&(o=r,r=n,n=o),s=Math.max(r,s),a=Math.min(n,a),s>a)return!1;if(Math.abs(this.direction.y)<1e-7){if(this.origin.yt.y)return!1}else if(i=1/this.direction.y,r=(e.y-this.origin.y)*i,n=(t.y-this.origin.y)*i,n===-1/0&&(n=1/0),r>n&&(o=r,r=n,n=o),s=Math.max(r,s),a=Math.min(n,a),s>a)return!1;if(Math.abs(this.direction.z)<1e-7){if(this.origin.zt.z)return!1}else if(i=1/this.direction.z,r=(e.z-this.origin.z)*i,n=(t.z-this.origin.z)*i,n===-1/0&&(n=1/0),r>n&&(o=r,r=n,n=o),s=Math.max(r,s),a=Math.min(n,a),s>a)return!1;return!0},t.prototype.intersectsBox=function(e){return this.intersectsBoxMinMax(e.minimum,e.maximum)},t.prototype.intersectsSphere=function(e){var t=e.center.x-this.origin.x,i=e.center.y-this.origin.y,r=e.center.z-this.origin.z,n=t*t+i*i+r*r,o=e.radius*e.radius;if(n<=o)return!0;var s=t*this.direction.x+i*this.direction.y+r*this.direction.z;return!(s<0)&&n-s*s<=o},t.prototype.intersectsTriangle=function(t,i,r){this._edge1||(this._edge1=e.Vector3.Zero(),this._edge2=e.Vector3.Zero(),this._pvec=e.Vector3.Zero(),this._tvec=e.Vector3.Zero(),this._qvec=e.Vector3.Zero()),i.subtractToRef(t,this._edge1),r.subtractToRef(t,this._edge2),e.Vector3.CrossToRef(this.direction,this._edge2,this._pvec);var n=e.Vector3.Dot(this._edge1,this._pvec);if(0===n)return null;var o=1/n;this.origin.subtractToRef(t,this._tvec);var s=e.Vector3.Dot(this._tvec,this._pvec)*o;if(s<0||s>1)return null;e.Vector3.CrossToRef(this._tvec,this._edge1,this._qvec);var a=e.Vector3.Dot(this.direction,this._qvec)*o;if(a<0||s+a>1)return null;var l=e.Vector3.Dot(this._edge2,this._qvec)*o;return l>this.length?null:new e.IntersectionInfo(s,a,l)},t.prototype.intersectsPlane=function(t){var i,r=e.Vector3.Dot(t.normal,this.direction);if(Math.abs(r)<9.99999997475243e-7)return null;var n=e.Vector3.Dot(t.normal,this.origin);return i=(-t.d-n)/r,i<0?i<-9.99999997475243e-7?null:0:i},t.prototype.intersectsMesh=function(i,r){var n=e.Tmp.Matrix[0];return i.getWorldMatrix().invertToRef(n),this._tmpRay?t.TransformToRef(this,n,this._tmpRay):this._tmpRay=t.Transform(this,n),i.intersects(this._tmpRay,r)},t.prototype.intersectsMeshes=function(e,t,i){i?i.length=0:i=[];for(var r=0;rt.distance?1:0},t.prototype.intersectionSegment=function(i,r,n){var o,s,a,l,c=this.origin.add(this.direction.multiplyByFloats(t.rayl,t.rayl,t.rayl)),h=r.subtract(i),u=c.subtract(this.origin),f=i.subtract(this.origin),d=e.Vector3.Dot(h,h),p=e.Vector3.Dot(h,u),_=e.Vector3.Dot(u,u),m=e.Vector3.Dot(h,f),g=e.Vector3.Dot(u,f),v=d*_-p*p,y=v,b=v;vy&&(s=y,l=g+p,b=_)),l<0?(l=0,-m<0?s=0:-m>d?s=y:(s=-m,y=d)):l>b&&(l=b,-m+p<0?s=0:-m+p>d?s=y:(s=-m+p,y=d)),o=Math.abs(s)0&&a<=this.length&&T.lengthSquared()i.x+r)&&(!(i.x-r>t.x)&&(!(e.y>i.y+r)&&(!(i.y-r>t.y)&&(!(e.z>i.z+r)&&!(i.z-r>t.z)))))},i=(function(){var e={root:0,found:!1};return function(t,i,r,n){e.root=0,e.found=!1;var o=i*i-4*t*r;if(o<0)return e;var s=Math.sqrt(o),a=(-i-s)/(2*t),l=(-i+s)/(2*t);if(a>l){var c=l;l=a,a=c}return a>0&&a0&&l=0))},r.prototype._canDoCollision=function(i,r,n,o){var s=e.Vector3.Distance(this._basePointWorld,i),a=Math.max(this._radius.x,this._radius.y,this._radius.z);return!(s>this._velocityWorldLength+a+r)&&!!t(n,o,this._basePointWorld,this._velocityWorldLength+a)},r.prototype._testTriangle=function(t,r,n,o,s,a){var l,c=!1;r||(r=[]),r[t]||(r[t]=new e.Plane(0,0,0,0),r[t].copyFromPoints(n,o,s));var h=r[t];if(a||h.isFrontFacingTo(this._normalizedVelocity,0)){var u=h.signedDistanceTo(this._basePoint),f=e.Vector3.Dot(h.normal,this._velocity);if(0==f){if(Math.abs(u)>=1)return;c=!0,l=0}else{l=(-1-u)/f;var d=(1-u)/f;if(l>d){var p=d;d=l,l=p}if(l>1||d<0)return;l<0&&(l=0),l>1&&(l=1)}this._collisionPoint.copyFromFloats(0,0,0);var _=!1,m=1;if(c||(this._basePoint.subtractToRef(h.normal,this._planeIntersectionPoint),this._velocity.scaleToRef(l,this._tempVector),this._planeIntersectionPoint.addInPlace(this._tempVector),this._checkPointInTriangle(this._planeIntersectionPoint,n,o,s,h.normal)&&(_=!0,m=l,this._collisionPoint.copyFrom(this._planeIntersectionPoint))),!_){var g=this._velocity.lengthSquared(),v=g;this._basePoint.subtractToRef(n,this._tempVector);var y=2*e.Vector3.Dot(this._velocity,this._tempVector),b=this._tempVector.lengthSquared()-1,x=i(v,y,b,m);x.found&&(m=x.root,_=!0,this._collisionPoint.copyFrom(n)),this._basePoint.subtractToRef(o,this._tempVector),y=2*e.Vector3.Dot(this._velocity,this._tempVector),b=this._tempVector.lengthSquared()-1,x=i(v,y,b,m),x.found&&(m=x.root,_=!0,this._collisionPoint.copyFrom(o)),this._basePoint.subtractToRef(s,this._tempVector),y=2*e.Vector3.Dot(this._velocity,this._tempVector),b=this._tempVector.lengthSquared()-1,x=i(v,y,b,m),x.found&&(m=x.root,_=!0,this._collisionPoint.copyFrom(s)),o.subtractToRef(n,this._edge),n.subtractToRef(this._basePoint,this._baseToVertex);var T=this._edge.lengthSquared(),E=e.Vector3.Dot(this._edge,this._velocity),A=e.Vector3.Dot(this._edge,this._baseToVertex);if(v=T*-g+E*E,y=T*(2*e.Vector3.Dot(this._velocity,this._baseToVertex))-2*E*A,b=T*(1-this._baseToVertex.lengthSquared())+A*A,x=i(v,y,b,m),x.found){var P=(E*x.root-A)/T;P>=0&&P<=1&&(m=x.root,_=!0,this._edge.scaleInPlace(P),n.addToRef(this._edge,this._collisionPoint))}s.subtractToRef(o,this._edge),o.subtractToRef(this._basePoint,this._baseToVertex),T=this._edge.lengthSquared(),E=e.Vector3.Dot(this._edge,this._velocity),A=e.Vector3.Dot(this._edge,this._baseToVertex),v=T*-g+E*E,y=T*(2*e.Vector3.Dot(this._velocity,this._baseToVertex))-2*E*A,b=T*(1-this._baseToVertex.lengthSquared())+A*A,x=i(v,y,b,m),x.found&&(P=(E*x.root-A)/T)>=0&&P<=1&&(m=x.root,_=!0,this._edge.scaleInPlace(P),o.addToRef(this._edge,this._collisionPoint)),n.subtractToRef(s,this._edge),s.subtractToRef(this._basePoint,this._baseToVertex),T=this._edge.lengthSquared(),E=e.Vector3.Dot(this._edge,this._velocity),A=e.Vector3.Dot(this._edge,this._baseToVertex),v=T*-g+E*E,y=T*(2*e.Vector3.Dot(this._velocity,this._baseToVertex))-2*E*A,b=T*(1-this._baseToVertex.lengthSquared())+A*A,x=i(v,y,b,m),x.found&&(P=(E*x.root-A)/T)>=0&&P<=1&&(m=x.root,_=!0,this._edge.scaleInPlace(P),s.addToRef(this._edge,this._collisionPoint))}if(_){var M=m*this._velocity.length();(!this.collisionFound||M4)){++n._runningUpdated;var e={updatedMeshes:n._addUpdateMeshesList,updatedGeometries:n._addUpdateGeometriesList,removedGeometries:n._toRemoveGeometryArray,removedMeshes:n._toRemoveMeshesArray},i={payload:e,taskType:t.UPDATE},r=[];for(var o in e.updatedGeometries)e.updatedGeometries.hasOwnProperty(o)&&(r.push(i.payload.updatedGeometries[o].indices.buffer),r.push(i.payload.updatedGeometries[o].normals.buffer),r.push(i.payload.updatedGeometries[o].positions.buffer));n._worker.postMessage(i,r),n._addUpdateMeshesList={},n._addUpdateGeometriesList={},n._toRemoveGeometryArray=[],n._toRemoveMeshesArray=[]}},this._onMessageFromWorker=function(r){var o=r.data;if(o.error!=i.SUCCESS)return void e.Tools.Warn("error returned from worker!");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 l=n._scene.getMeshByUniqueID(s.collidedMeshUniqueId);l&&a(s.collisionId,e.Vector3.FromArray(s.newPosition),l)}n._collisionsCallbackArray[s.collisionId]=null}},this._collisionsCallbackArray=[],this._init=!1,this._runningUpdated=0,this._addUpdateMeshesList={},this._addUpdateGeometriesList={},this._toRemoveGeometryArray=[],this._toRemoveMeshesArray=[]}return r.prototype.getNewPosition=function(e,i,r,n,o,s,a){if(this._init&&!this._collisionsCallbackArray[a]&&!this._collisionsCallbackArray[a+1e5]){e.divideToRef(r._radius,this._scaledPosition),i.divideToRef(r._radius,this._scaledVelocity),this._collisionsCallbackArray[a]=s;var l={collider:{position:this._scaledPosition.asArray(),velocity:this._scaledVelocity.asArray(),radius:r._radius.asArray()},collisionId:a,excludedMeshUniqueId:o?o.uniqueId:null,maximumRetry:n},c={payload:l,taskType:t.COLLIDE};this._worker.postMessage(c)}},r.prototype.init=function(i){this._scene=i,this._scene.registerAfterRender(this._afterRender);var r=e.WorkerIncluded?e.Engine.CodeRepository+"Collisions/babylon.collisionWorker.js":URL.createObjectURL(new Blob([e.CollisionWorker],{type:"application/javascript"}));this._worker=new Worker(r),this._worker.onmessage=this._onMessageFromWorker;var n={payload:{},taskType:t.INIT};this._worker.postMessage(n)},r.prototype.destroy=function(){this._scene.unregisterAfterRender(this._afterRender),this._worker.terminate()},r.prototype.onMeshAdded=function(e){e.registerAfterWorldMatrixUpdate(this.onMeshUpdated),this.onMeshUpdated(e)},r.prototype.onMeshRemoved=function(e){this._toRemoveMeshesArray.push(e.uniqueId)},r.prototype.onGeometryAdded=function(e){e.onGeometryUpdated=this.onGeometryUpdated,this.onGeometryUpdated(e)},r.prototype.onGeometryDeleted=function(e){this._toRemoveGeometryArray.push(e.id)},r.SerializeMesh=function(t){var i=[];t.subMeshes&&(i=t.subMeshes.map((function(e,t){var i=e.getBoundingInfo();return{position:t,verticesStart:e.verticesStart,verticesCount:e.verticesCount,indexStart:e.indexStart,indexCount:e.indexCount,hasMaterial:!!e.getMaterial(),sphereCenter:i.boundingSphere.centerWorld.asArray(),sphereRadius:i.boundingSphere.radiusWorld,boxMinimum:i.boundingBox.minimumWorld.asArray(),boxMaximum:i.boundingBox.maximumWorld.asArray()}})));var r=null;if(t instanceof e.Mesh){var n=t.geometry;r=n?n.id:null}else if(t instanceof e.InstancedMesh){var n=t.sourceMesh&&t.sourceMesh.geometry;r=n?n.id:null}var o=t.getBoundingInfo();return{uniqueId:t.uniqueId,id:t.id,name:t.name,geometryId:r,sphereCenter:o.boundingSphere.centerWorld.asArray(),sphereRadius:o.boundingSphere.radiusWorld,boxMinimum:o.boundingBox.minimumWorld.asArray(),boxMaximum:o.boundingBox.maximumWorld.asArray(),worldMatrixFromCache:t.worldMatrixFromCache.asArray(),subMeshes:i,checkCollisions:t.checkCollisions}},r.SerializeGeometry=function(t){return{id:t.id,positions:new Float32Array(t.getVerticesData(e.VertexBuffer.PositionKind)||[]),normals:new Float32Array(t.getVerticesData(e.VertexBuffer.NormalKind)||[]),indices:new Uint32Array(t.getIndices()||[])}},r})();e.CollisionCoordinatorWorker=r;var n=(function(){function t(){this._scaledPosition=e.Vector3.Zero(),this._scaledVelocity=e.Vector3.Zero(),this._finalPosition=e.Vector3.Zero()}return t.prototype.getNewPosition=function(e,t,i,r,n,o,s){e.divideToRef(i._radius,this._scaledPosition),t.divideToRef(i._radius,this._scaledVelocity),i.collidedMesh=null,i._retry=0,i._initialVelocity=this._scaledVelocity,i._initialPosition=this._scaledPosition,this._collideWithWorld(this._scaledPosition,this._scaledVelocity,i,r,this._finalPosition,n),this._finalPosition.multiplyInPlace(i._radius),o(s,this._finalPosition,i.collidedMesh)},t.prototype.init=function(e){this._scene=e},t.prototype.destroy=function(){},t.prototype.onMeshAdded=function(e){},t.prototype.onMeshUpdated=function(e){},t.prototype.onMeshRemoved=function(e){},t.prototype.onGeometryAdded=function(e){},t.prototype.onGeometryUpdated=function(e){},t.prototype.onGeometryDeleted=function(e){},t.prototype._collideWithWorld=function(t,i,r,n,o,s){void 0===s&&(s=null);var a=10*e.Engine.CollisionsEpsilon;if(r._retry>=n)return void o.copyFrom(t);var l=s?s.collisionMask:r.collisionMask;r._initialize(t,i,a);for(var c=0;c=t*e&&(this._currentFrameCounter=0,++this.cellIndex>this.particleSystem.endSpriteCellID&&(this.cellIndex=this.particleSystem.endSpriteCellID))},t.prototype.updateCellIndexWithCustomSpeed=function(){this._currentFrameCounter>=this.particleSystem.spriteCellChangeSpeed?(this.cellIndex++,this._currentFrameCounter=0,this.cellIndex>this.particleSystem.endSpriteCellID&&(this.particleSystem.spriteCellLoop?this.cellIndex=this.particleSystem.startSpriteCellID:this.cellIndex=this.particleSystem.endSpriteCellID)):this._currentFrameCounter++},t.prototype.copyTo=function(e){e.position.copyFrom(this.position),e.direction.copyFrom(this.direction),e.color.copyFrom(this.color),e.colorStep.copyFrom(this.colorStep),e.lifeTime=this.lifeTime,e.age=this.age,e.size=this.size,e.angle=this.angle,e.angularSpeed=this.angularSpeed,e.particleSystem=this.particleSystem,e.cellIndex=this.cellIndex},t})();e.Particle=t})(e||(e={}));var e;!(function(e){var t=(function(){function t(i,r,n,o,s,a){void 0===o&&(o=null),void 0===s&&(s=!1),void 0===a&&(a=.01);var l=this;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.onAnimationEnd=null,this.blendMode=t.BLENDMODE_ONEONE,this.forceDepthWrite=!1,this.gravity=e.Vector3.Zero(),this.color1=new e.Color4(1,1,1,1),this.color2=new e.Color4(1,1,1,1),this.colorDead=new e.Color4(0,0,0,1),this.textureMask=new e.Color4(1,1,1,1),this.spriteCellLoop=!0,this.spriteCellChangeSpeed=0,this.startSpriteCellID=0,this.endSpriteCellID=0,this.spriteCellWidth=0,this.spriteCellHeight=0,this.onDisposeObservable=new e.Observable,this._particles=new Array,this._stockParticles=new Array,this._newPartsExcess=0,this._vertexBuffers={},this._scaledColorStep=new e.Color4(0,0,0,0),this._colorDiff=new e.Color4(0,0,0,0),this._scaledDirection=e.Vector3.Zero(),this._scaledGravity=e.Vector3.Zero(),this._currentRenderId=-1,this._started=!1,this._stopped=!1,this._actualFrame=0,this._vertexBufferSize=11,this._appendParticleVertexes=null,this.id=i,this.name=i,this._capacity=r,this._epsilon=a,this._isAnimationSheetEnabled=s,s&&(this._vertexBufferSize=12),this._scene=n||e.Engine.LastCreatedScene,this._customEffect=o,n.particleSystems.push(this),this._createIndexBuffer(),this._vertexData=new Float32Array(r*this._vertexBufferSize*4),this._vertexBuffer=new e.Buffer(n.getEngine(),this._vertexData,!0,this._vertexBufferSize);var c=this._vertexBuffer.createVertexBuffer(e.VertexBuffer.PositionKind,0,3),h=this._vertexBuffer.createVertexBuffer(e.VertexBuffer.ColorKind,3,4),u=this._vertexBuffer.createVertexBuffer("options",7,4);if(this._isAnimationSheetEnabled){var f=this._vertexBuffer.createVertexBuffer("cellIndex",11,1);this._vertexBuffers.cellIndex=f}this._vertexBuffers[e.VertexBuffer.PositionKind]=c,this._vertexBuffers[e.VertexBuffer.ColorKind]=h,this._vertexBuffers.options=u,this.particleEmitterType=new e.BoxParticleEmitter,this.updateFunction=function(e){for(var t=0;t=i.lifeTime?(l.recycleParticle(i),t--):(i.colorStep.scaleToRef(l._scaledUpdateSpeed,l._scaledColorStep),i.color.addInPlace(l._scaledColorStep),i.color.a<0&&(i.color.a=0),i.angle+=i.angularSpeed*l._scaledUpdateSpeed,i.direction.scaleToRef(l._scaledUpdateSpeed,l._scaledDirection),i.position.addInPlace(l._scaledDirection),l.gravity.scaleToRef(l._scaledUpdateSpeed,l._scaledGravity),i.direction.addInPlace(l._scaledGravity),l._isAnimationSheetEnabled&&i.updateCellIndex(l._scaledUpdateSpeed))}}}return Object.defineProperty(t.prototype,"direction1",{get:function(){return this.particleEmitterType.direction1?this.particleEmitterType.direction1:e.Vector3.Zero()},set:function(e){this.particleEmitterType.direction1&&(this.particleEmitterType.direction1=e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"direction2",{get:function(){return this.particleEmitterType.direction2?this.particleEmitterType.direction2:e.Vector3.Zero()},set:function(e){this.particleEmitterType.direction2&&(this.particleEmitterType.direction2=e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"minEmitBox",{get:function(){return this.particleEmitterType.minEmitBox?this.particleEmitterType.minEmitBox:e.Vector3.Zero()},set:function(e){this.particleEmitterType.minEmitBox&&(this.particleEmitterType.minEmitBox=e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"maxEmitBox",{get:function(){return this.particleEmitterType.maxEmitBox?this.particleEmitterType.maxEmitBox:e.Vector3.Zero()},set:function(e){this.particleEmitterType.maxEmitBox&&(this.particleEmitterType.maxEmitBox=e)},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,"isAnimationSheetEnabled",{get:function(){return this._isAnimationSheetEnabled},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"particles",{get:function(){return this._particles},enumerable:!0,configurable:!0}),t.prototype.getClassName=function(){return"ParticleSystem"},t.prototype._createIndexBuffer=function(){for(var e=[],t=0,i=0;i0,this.updateFunction(this._particles);var i;if(this.emitter.position){i=this.emitter.getWorldMatrix()}else{var r=this.emitter;i=e.Matrix.Translation(r.x,r.y,r.z)}for(var n,o=0;o-1?(t=this.manualEmitCount,this._newPartsExcess=0,this.manualEmitCount=0):(t=this.emitRate*this._scaledUpdateSpeed>>0,this._newPartsExcess+=this.emitRate*this._scaledUpdateSpeed-t),this._newPartsExcess>1&&(t+=this._newPartsExcess>>0,this._newPartsExcess-=this._newPartsExcess>>0),this._alive=!1,this._stopped?t=0:(this._actualFrame+=this._scaledUpdateSpeed,this.targetStopDuration&&this._actualFrame>=this.targetStopDuration&&this.stop()),this._update(t),this._stopped&&(this._alive||(this._started=!1,this.onAnimationEnd&&this.onAnimationEnd(),this.disposeOnStop&&this._scene._toBeDisposed.push(this))),this._isAnimationSheetEnabled?this._appendParticleVertexes=this._appenedParticleVertexesWithSheet:this._appendParticleVertexes=this._appenedParticleVertexesNoSheet;for(var i=0,r=0;r-1&&this._scene.particleSystems.splice(t,1),this.onDisposeObservable.notifyObservers(this),this.onDisposeObservable.clear()},t.prototype.createSphereEmitter=function(t){void 0===t&&(t=1);var i=new e.SphereParticleEmitter(t);return this.particleEmitterType=i,i},t.prototype.createDirectedSphereEmitter=function(t,i,r){void 0===t&&(t=1),void 0===i&&(i=new e.Vector3(0,1,0)),void 0===r&&(r=new e.Vector3(0,1,0));var n=new e.SphereDirectedParticleEmitter(t,i,r);return this.particleEmitterType=n,n},t.prototype.createConeEmitter=function(t,i){void 0===t&&(t=1),void 0===i&&(i=Math.PI/4);var r=new e.ConeParticleEmitter(t,i);return this.particleEmitterType=r,r},t.prototype.createBoxEmitter=function(t,i,r,n){var o=new e.BoxParticleEmitter;return this.direction1=t,this.direction2=i,this.minEmitBox=r,this.maxEmitBox=n,this.particleEmitterType=o,o},t.prototype.clone=function(i,r){var n=null,o=null;if(null!=this.customShader){o=this.customShader;var s=o.shaderOptions.defines.length>0?o.shaderOptions.defines.join("\n"):"";n=this._scene.getEngine().createEffectForParticles(o.shaderPath.fragmentElement,o.shaderOptions.uniforms,o.shaderOptions.samplers,s)}var a=new t(i,this._capacity,this._scene,n);return a.customShader=o,e.Tools.DeepCopy(this,a,["particles","customShader"]),void 0===r&&(r=this.emitter),a.emitter=r,this.particleTexture&&(a.particleTexture=new e.Texture(this.particleTexture.url,this._scene)),this.preventAutoStart||a.start(),a},t.prototype.serialize=function(){var t={};if(t.name=this.name,t.id=this.id,this.emitter.position){var i=this.emitter;t.emitterId=i.id}else{var r=this.emitter;t.emitter=r.asArray()}return t.capacity=this.getCapacity(),this.particleTexture&&(t.textureName=this.particleTexture.name),e.Animation.AppendSerializedAnimations(this,t),t.minAngularSpeed=this.minAngularSpeed,t.maxAngularSpeed=this.maxAngularSpeed,t.minSize=this.minSize,t.maxSize=this.maxSize,t.minEmitPower=this.minEmitPower,t.maxEmitPower=this.maxEmitPower,t.minLifeTime=this.minLifeTime,t.maxLifeTime=this.maxLifeTime,t.emitRate=this.emitRate,t.minEmitBox=this.minEmitBox.asArray(),t.maxEmitBox=this.maxEmitBox.asArray(),t.gravity=this.gravity.asArray(),t.direction1=this.direction1.asArray(),t.direction2=this.direction2.asArray(),t.color1=this.color1.asArray(),t.color2=this.color2.asArray(),t.colorDead=this.colorDead.asArray(),t.updateSpeed=this.updateSpeed,t.targetStopDuration=this.targetStopDuration,t.textureMask=this.textureMask.asArray(),t.blendMode=this.blendMode,t.customShader=this.customShader,t.preventAutoStart=this.preventAutoStart,t.startSpriteCellID=this.startSpriteCellID,t.endSpriteCellID=this.endSpriteCellID,t.spriteCellLoop=this.spriteCellLoop,t.spriteCellChangeSpeed=this.spriteCellChangeSpeed,t.spriteCellWidth=this.spriteCellWidth,t.spriteCellHeight=this.spriteCellHeight,t.isAnimationSheetEnabled=this._isAnimationSheetEnabled,this.particleEmitterType&&(t.particleEmitterType=this.particleEmitterType.serialize()),t},t.Parse=function(i,r,n){var o=i.name,s=null,a=null;if(i.customShader){a=i.customShader;var l=a.shaderOptions.defines.length>0?a.shaderOptions.defines.join("\n"):"";s=r.getEngine().createEffectForParticles(a.shaderPath.fragmentElement,a.shaderOptions.uniforms,a.shaderOptions.samplers,l)}var c=new t(o,i.capacity,r,s,i.isAnimationSheetEnabled);if(c.customShader=a,i.id&&(c.id=i.id),i.preventAutoStart&&(c.preventAutoStart=i.preventAutoStart),i.textureName&&(c.particleTexture=new e.Texture(n+i.textureName,r),c.particleTexture.name=i.textureName),i.emitterId?c.emitter=r.getLastMeshByID(i.emitterId):c.emitter=e.Vector3.FromArray(i.emitter),i.animations)for(var h=0;hf?f:n,r=Math.round(f/n),o=0):r=r>f?f:r;for(var d=[],p=[],_=[],m=[],g=e.Vector3.Zero(),v=r;uf-r&&(r=f-u),d.length=0,p.length=0,_.length=0,m.length=0;for(var y=0,b=3*u;b<3*(u+r);b++){p.push(y);var x=a[b];d.push(s[3*x],s[3*x+1],s[3*x+2]),l&&_.push(l[2*x],l[2*x+1]),c&&m.push(c[4*x],c[4*x+1],c[4*x+2],c[4*x+3]),y++}var T,E=this.nbParticles,A=this._posToShape(d),P=this._uvsToShapeUV(_);for(T=0;T65535&&(this._needs32Bits=!0)}if(this._pickable){var b=n.length/3;for(_=0;_=this.nbParticles?this.nbParticles-1:i,this._computeBoundingBox&&(0==t&&i==this.nbParticles-1?(e.Vector3.FromFloatsToRef(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE,this._minimum),e.Vector3.FromFloatsToRef(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE,this._maximum)):this.mesh._boundingInfo&&(this._minimum.copyFrom(this.mesh._boundingInfo.boundingBox.minimum),this._maximum.copyFrom(this.mesh._boundingInfo.boundingBox.maximum))),s=this.particles[t]._pos;var f=s/3|0;l=4*f,h=2*f;for(var d=t;d<=i;d++){if(this._particle=this.particles[d],this._shape=this._particle._model._shape,this._shapeUV=this._particle._model._shapeUV,this.updateParticle(this._particle),this._depthSort&&this._depthSortParticles){var p=this.depthSortedParticles[d];p.ind=this._particle._ind,p.indicesLength=this._particle._model._indicesLength,p.sqDistance=e.Vector3.DistanceSquared(this._particle.position,this._camInvertedPosition)}if(!this._particle.alive||this._particle._stillInvisible&&!this._particle.isVisible)u=this._shape.length,s+=3*u,l+=4*u,h+=2*u;else{if(this._particle.isVisible)for(this._particle._stillInvisible=!1,this._particleHasParent=null!==this._particle.parentId,this._scaledPivot.x=this._particle.pivot.x*this._particle.scaling.x,this._scaledPivot.y=this._particle.pivot.y*this._particle.scaling.y,this._scaledPivot.z=this._particle.pivot.z*this._particle.scaling.z,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()),this._particleHasParent?(this._parent=this.particles[this._particle.parentId],this._rotated.x=this._particle.position.x*this._parent._rotationMatrix[0]+this._particle.position.y*this._parent._rotationMatrix[3]+this._particle.position.z*this._parent._rotationMatrix[6],this._rotated.y=this._particle.position.x*this._parent._rotationMatrix[1]+this._particle.position.y*this._parent._rotationMatrix[4]+this._particle.position.z*this._parent._rotationMatrix[7],this._rotated.z=this._particle.position.x*this._parent._rotationMatrix[2]+this._particle.position.y*this._parent._rotationMatrix[5]+this._particle.position.z*this._parent._rotationMatrix[8],this._particle._globalPosition.x=this._parent._globalPosition.x+this._rotated.x,this._particle._globalPosition.y=this._parent._globalPosition.y+this._rotated.y,this._particle._globalPosition.z=this._parent._globalPosition.z+this._rotated.z,(this._computeParticleRotation||this.billboard)&&(this._particle._rotationMatrix[0]=this._rotMatrix.m[0]*this._parent._rotationMatrix[0]+this._rotMatrix.m[1]*this._parent._rotationMatrix[3]+this._rotMatrix.m[2]*this._parent._rotationMatrix[6],this._particle._rotationMatrix[1]=this._rotMatrix.m[0]*this._parent._rotationMatrix[1]+this._rotMatrix.m[1]*this._parent._rotationMatrix[4]+this._rotMatrix.m[2]*this._parent._rotationMatrix[7],this._particle._rotationMatrix[2]=this._rotMatrix.m[0]*this._parent._rotationMatrix[2]+this._rotMatrix.m[1]*this._parent._rotationMatrix[5]+this._rotMatrix.m[2]*this._parent._rotationMatrix[8],this._particle._rotationMatrix[3]=this._rotMatrix.m[4]*this._parent._rotationMatrix[0]+this._rotMatrix.m[5]*this._parent._rotationMatrix[3]+this._rotMatrix.m[6]*this._parent._rotationMatrix[6],this._particle._rotationMatrix[4]=this._rotMatrix.m[4]*this._parent._rotationMatrix[1]+this._rotMatrix.m[5]*this._parent._rotationMatrix[4]+this._rotMatrix.m[6]*this._parent._rotationMatrix[7],this._particle._rotationMatrix[5]=this._rotMatrix.m[4]*this._parent._rotationMatrix[2]+this._rotMatrix.m[5]*this._parent._rotationMatrix[5]+this._rotMatrix.m[6]*this._parent._rotationMatrix[8],this._particle._rotationMatrix[6]=this._rotMatrix.m[8]*this._parent._rotationMatrix[0]+this._rotMatrix.m[9]*this._parent._rotationMatrix[3]+this._rotMatrix.m[10]*this._parent._rotationMatrix[6],this._particle._rotationMatrix[7]=this._rotMatrix.m[8]*this._parent._rotationMatrix[1]+this._rotMatrix.m[9]*this._parent._rotationMatrix[4]+this._rotMatrix.m[10]*this._parent._rotationMatrix[7],this._particle._rotationMatrix[8]=this._rotMatrix.m[8]*this._parent._rotationMatrix[2]+this._rotMatrix.m[9]*this._parent._rotationMatrix[5]+this._rotMatrix.m[10]*this._parent._rotationMatrix[8])):(this._particle._globalPosition.x=this._particle.position.x,this._particle._globalPosition.y=this._particle.position.y,this._particle._globalPosition.z=this._particle.position.z,(this._computeParticleRotation||this.billboard)&&(this._particle._rotationMatrix[0]=this._rotMatrix.m[0],this._particle._rotationMatrix[1]=this._rotMatrix.m[1],this._particle._rotationMatrix[2]=this._rotMatrix.m[2],this._particle._rotationMatrix[3]=this._rotMatrix.m[4],this._particle._rotationMatrix[4]=this._rotMatrix.m[5],this._particle._rotationMatrix[5]=this._rotMatrix.m[6],this._particle._rotationMatrix[6]=this._rotMatrix.m[8],this._particle._rotationMatrix[7]=this._rotMatrix.m[9],this._particle._rotationMatrix[8]=this._rotMatrix.m[10])),this._particle.translateFromPivot?(this._pivotBackTranslation.x=0,this._pivotBackTranslation.y=0,this._pivotBackTranslation.z=0):(this._pivotBackTranslation.x=this._scaledPivot.x,this._pivotBackTranslation.y=this._scaledPivot.y,this._pivotBackTranslation.z=this._scaledPivot.z),u=0;uthis._maximum.x&&(this._maximum.x=this._positions32[o]),this._positions32[o+1]this._maximum.y&&(this._maximum.y=this._positions32[o+1]),this._positions32[o+2]this._maximum.z&&(this._maximum.z=this._positions32[o+2])),this._computeParticleVertex||(this._normal.x=this._fixedNormal32[o],this._normal.y=this._fixedNormal32[o+1],this._normal.z=this._fixedNormal32[o+2],this._rotated.x=this._normal.x*this._particle._rotationMatrix[0]+this._normal.y*this._particle._rotationMatrix[3]+this._normal.z*this._particle._rotationMatrix[6],this._rotated.y=this._normal.x*this._particle._rotationMatrix[1]+this._normal.y*this._particle._rotationMatrix[4]+this._normal.z*this._particle._rotationMatrix[7],this._rotated.z=this._normal.x*this._particle._rotationMatrix[2]+this._normal.y*this._particle._rotationMatrix[5]+this._normal.z*this._particle._rotationMatrix[8],this._normals32[o]=this._cam_axisX.x*this._rotated.x+this._cam_axisY.x*this._rotated.y+this._cam_axisZ.x*this._rotated.z,this._normals32[o+1]=this._cam_axisX.y*this._rotated.x+this._cam_axisY.y*this._rotated.y+this._cam_axisZ.y*this._rotated.z,this._normals32[o+2]=this._cam_axisX.z*this._rotated.x+this._cam_axisY.z*this._rotated.y+this._cam_axisZ.z*this._rotated.z),this._computeParticleColor&&this._particle.color&&(this._colors32[a]=this._particle.color.r,this._colors32[a+1]=this._particle.color.g,this._colors32[a+2]=this._particle.color.b,this._colors32[a+3]=this._particle.color.a),this._computeParticleTexture&&(this._uvs32[c]=this._shapeUV[2*u]*(this._particle.uvs.z-this._particle.uvs.x)+this._particle.uvs.x,this._uvs32[c+1]=this._shapeUV[2*u+1]*(this._particle.uvs.w-this._particle.uvs.y)+this._particle.uvs.y);else for(this._particle._stillInvisible=!0,u=0;u4&&(s.push(e.VertexBuffer.MatricesIndicesExtraKind),s.push(e.VertexBuffer.MatricesWeightsExtraKind)),o.push("#define NUM_BONE_INFLUENCERS "+t.numBoneInfluencers),o.push("#define BonesPerMesh "+(t.skeleton.bones.length+1)),a.addCPUSkinningFallback(0,t),-1===this._options.uniforms.indexOf("mBones")&&this._options.uniforms.push("mBones")):o.push("#define NUM_BONE_INFLUENCERS 0");for(var c in this._textures)if(!this._textures[c].isReady())return!1;t&&this._shouldTurnAlphaTestOn(t)&&o.push("#define ALPHATEST");var h=this._effect,u=o.join("\n");return this._effect=n.createEffect(this._shaderPath,{attributes:s,uniformsNames:this._options.uniforms,uniformBuffersNames:this._options.uniformBuffers,samplers:this._options.samplers,defines:u,fallbacks:a,onCompiled:this.onCompiled,onError:this.onError},n),!!this._effect.isReady()&&(h!==this._effect&&r.resetCachedMaterial(),this._renderId=r.getRenderId(),!0)},i.prototype.bindOnlyWorldMatrix=function(e){var t=this.getScene();this._effect&&(-1!==this._options.uniforms.indexOf("world")&&this._effect.setMatrix("world",e),-1!==this._options.uniforms.indexOf("worldView")&&(e.multiplyToRef(t.getViewMatrix(),this._cachedWorldViewMatrix),this._effect.setMatrix("worldView",this._cachedWorldViewMatrix)),-1!==this._options.uniforms.indexOf("worldViewProjection")&&this._effect.setMatrix("worldViewProjection",e.multiply(t.getTransformMatrix())))},i.prototype.bind=function(t,i){if(this.bindOnlyWorldMatrix(t),this._effect&&this.getScene().getCachedMaterial()!==this){-1!==this._options.uniforms.indexOf("view")&&this._effect.setMatrix("view",this.getScene().getViewMatrix()),-1!==this._options.uniforms.indexOf("projection")&&this._effect.setMatrix("projection",this.getScene().getProjectionMatrix()),-1!==this._options.uniforms.indexOf("viewProjection")&&this._effect.setMatrix("viewProjection",this.getScene().getTransformMatrix()),e.MaterialHelper.BindBonesParameters(i,this._effect);var r;for(r in this._textures)this._effect.setTexture(r,this._textures[r]);for(r in this._textureArrays)this._effect.setTextureArray(r,this._textureArrays[r]);for(r in this._ints)this._effect.setInt(r,this._ints[r]);for(r in this._floats)this._effect.setFloat(r,this._floats[r]);for(r in this._floatsArrays)this._effect.setArray(r,this._floatsArrays[r]);for(r in this._colors3)this._effect.setColor3(r,this._colors3[r]);for(r in this._colors3Arrays)this._effect.setArray3(r,this._colors3Arrays[r]);for(r in this._colors4){var n=this._colors4[r];this._effect.setFloat4(r,n.r,n.g,n.b,n.a)}for(r in this._vectors2)this._effect.setVector2(r,this._vectors2[r]);for(r in this._vectors3)this._effect.setVector3(r,this._vectors3[r]);for(r in this._vectors4)this._effect.setVector4(r,this._vectors4[r]);for(r in this._matrices)this._effect.setMatrix(r,this._matrices[r]);for(r in this._matrices3x3)this._effect.setMatrix3x3(r,this._matrices3x3[r]);for(r in this._matrices2x2)this._effect.setMatrix2x2(r,this._matrices2x2[r]);for(r in this._vectors2Arrays)this._effect.setArray2(r,this._vectors2Arrays[r]);for(r in this._vectors3Arrays)this._effect.setArray3(r,this._vectors3Arrays[r])}this._afterBind(i)},i.prototype.getActiveTextures=function(){var e=t.prototype.getActiveTextures.call(this);for(var i in this._textures)e.push(this._textures[i]);for(var i in this._textureArrays)for(var r=this._textureArrays[i],n=0;nthis._maxX||ithis._maxZ)return this.position.y;this._heightQuads&&0!=this._heightQuads.length||(this._initHeightQuads(),this._computeHeightQuads());var s=this._getFacetAt(t,i),a=-(s.x*t+s.z*i+s.w)/s.y;return e.Vector3.TransformCoordinatesFromFloatsToRef(0,a,0,r,o),o.y},i.prototype.getNormalAtCoordinates=function(t,i){var r=new e.Vector3(0,1,0);return this.getNormalAtCoordinatesToRef(t,i,r),r},i.prototype.getNormalAtCoordinatesToRef=function(t,i,r){var n=this.getWorldMatrix(),o=e.Tmp.Matrix[5];n.invertToRef(o);var s=e.Tmp.Vector3[8];if(e.Vector3.TransformCoordinatesFromFloatsToRef(t,0,i,o,s),t=s.x,i=s.z,tthis._maxX||ithis._maxZ)return this;this._heightQuads&&0!=this._heightQuads.length||(this._initHeightQuads(),this._computeHeightQuads());var a=this._getFacetAt(t,i);return e.Vector3.TransformNormalFromFloatsToRef(a.x,a.y,a.z,n,r),this},i.prototype.updateCoordinateHeights=function(){return this._heightQuads&&0!=this._heightQuads.length||this._initHeightQuads(),this._computeHeightQuads(),this},i.prototype._getFacetAt=function(e,t){var i=Math.floor((e+this._maxX)*this._subdivisionsX/this._width),r=Math.floor(-(t+this._maxZ)*this._subdivisionsY/this._height+this._subdivisionsY),n=this._heightQuads[r*this._subdivisionsX+i];return te.Tmp.Vector3[1].x&&(e.Tmp.Vector3[1].x=l[u].x),l[u].ye.Tmp.Vector3[1].y&&(e.Tmp.Vector3[1].y=l[u].y),l[u].ze.Tmp.Vector3[1].z&&(e.Tmp.Vector3[1].z=l[u].z),u++,r+=3;c._closePath&&(t[r]=l[0].x,t[r+1]=l[0].y,t[r+2]=l[0].z,r+=3)}}(u),c._boundingInfo=new e.BoundingInfo(e.Tmp.Vector3[0],e.Tmp.Vector3[1]),c._boundingInfo.update(c._worldMatrix),c.updateVerticesData(e.VertexBuffer.PositionKind,u,!1,!1),r.colors){for(var f=c.getVerticesData(e.VertexBuffer.ColorKind),d=0;d1?1:r.arc:1,a=void 0===r.closed||r.closed,l=r.shape,c=r.radius||1,h=r.tessellation||64,u=r.updatable,f=t.updateSideOrientation(r.sideOrientation),d=r.cap||e.Mesh.NO_CAP,p=2*Math.PI,_=new Array,m=r.invertUV||!1,g=0,v=0,y=p/h*s,b=new Array;for(g=0;g<=h;g++){var b=[];for(d!=e.Mesh.CAP_START&&d!=e.Mesh.CAP_ALL||(b.push(new e.Vector3(0,l[0].y,0)),b.push(new e.Vector3(Math.cos(g*y)*l[0].x*c,l[0].y,Math.sin(g*y)*l[0].x*c))),v=0;v1)?1:r.arc||1;var p,_,m=function(t,i,r,n,o,s,a,l){for(var c,h,u,f,d=i.getTangents(),p=i.getNormals(),_=i.getDistances(),m=2*Math.PI,g=m/o*l,v=function(){return n},y=s||v,b=e.Tmp.Matrix[0],x=a===e.Mesh._NO_CAP||a===e.Mesh.CAP_END?0:2,T=0;T3?0:h,_=m(o,p,v,a,l,c,h,r.arc);var y=t.CreateRibbon(i,{pathArray:_,closePath:!0,closeArray:!1,updatable:f,sideOrientation:d,invertUV:u,frontUVs:r.frontUVs,backUVs:r.backUVs},n);return y.pathArray=_,y.path3D=p,y.tessellation=l,y.cap=h,y.arc=r.arc,y.radius=a,y},t.CreatePolyhedron=function(i,r,n){var o=new e.Mesh(i,n);return r.sideOrientation=t.updateSideOrientation(r.sideOrientation),o._originalBuilderSideOrientation=r.sideOrientation,e.VertexData.CreatePolyhedron(r).applyToMesh(o,r.updatable),o},t.CreateDecal=function(t,i,r){var n=i.getIndices(),o=i.getVerticesData(e.VertexBuffer.PositionKind),s=i.getVerticesData(e.VertexBuffer.NormalKind),a=r.position||e.Vector3.Zero(),l=r.normal||e.Vector3.Up(),c=r.size||e.Vector3.One(),h=r.angle||0;if(!l){var u=new e.Vector3(0,0,1),f=i.getScene().activeCamera,d=e.Vector3.TransformCoordinates(u,f.getWorldMatrix());l=f.globalPosition.subtract(d)}var p=-Math.atan2(l.z,l.x)-Math.PI/2,_=Math.sqrt(l.x*l.x+l.z*l.z),m=Math.atan2(l.y,_),g=e.Matrix.RotationYawPitchRoll(p,m,h).multiply(e.Matrix.Translation(a.x,a.y,a.z)),v=e.Matrix.Invert(g),y=i.getWorldMatrix(),b=y.multiply(v),x=new e.VertexData;x.indices=[],x.positions=[],x.normals=[],x.uvs=[];for(var T=0,E=function(t){var i=new e.PositionNormalVertex;if(!n||!o||!s)return i;var r=n[t];return i.position=new e.Vector3(o[3*r],o[3*r+1],o[3*r+2]),i.position=e.Vector3.TransformCoordinates(i.position,b),i.normal=new e.Vector3(s[3*r],s[3*r+1],s[3*r+2]),i.normal=e.Vector3.TransformNormal(i.normal,b),i},A=function(t,i){if(0===t.length)return t;for(var r=.5*Math.abs(e.Vector3.Dot(c,i)),n=function(t,n){var o=e.Vector3.GetClipFactor(t.position,n.position,i,r);return new e.PositionNormalVertex(e.Vector3.Lerp(t.position,n.position,o),e.Vector3.Lerp(t.normal,n.normal,o))},o=new Array,s=0;s0,l=m>0,h=g>0,(a?1:0)+(l?1:0)+(h?1:0)){case 0:o.push(t[s]),o.push(t[s+1]),o.push(t[s+2]);break;case 1:if(a&&(u=t[s+1],f=t[s+2],d=n(t[s],u),p=n(t[s],f)),l){u=t[s],f=t[s+2],d=n(t[s+1],u),p=n(t[s+1],f),o.push(d),o.push(f.clone()),o.push(u.clone()),o.push(f.clone()),o.push(d.clone()),o.push(p);break}h&&(u=t[s],f=t[s+1],d=n(t[s+2],u),p=n(t[s+2],f)),u&&f&&d&&p&&(o.push(u.clone()),o.push(f.clone()),o.push(d),o.push(p),o.push(d.clone()),o.push(f.clone()));break;case 2:a||(u=t[s].clone(),f=n(u,t[s+1]),d=n(u,t[s+2]),o.push(u),o.push(f),o.push(d)),l||(u=t[s+1].clone(),f=n(u,t[s+2]), d=n(u,t[s]),o.push(u),o.push(f),o.push(d)),h||(u=t[s+2].clone(),f=n(u,t[s]),d=n(u,t[s+1]),o.push(u),o.push(f),o.push(d))}}return o},P=0;P3?0:u,x=T(r,n,b,E,o,s,a,l,u,f);var A=t.CreateRibbon(i,{pathArray:x,closeArray:c,closePath:h,updatable:p,sideOrientation:_,invertUV:g,frontUVs:v||void 0,backUVs:y||void 0},d);return A.pathArray=x,A.path3D=b,A.cap=u,A},t})();e.MeshBuilder=t})(e||(e={}));var e;!(function(e){var t=(function(){function t(i){void 0===i&&(i=navigator.hardwareConcurrency||4);var r=URL&&URL.createObjectURL&&URL.createObjectURL(new Blob(["("+t._Worker.toString()+")()"],{type:"application/javascript"}));if(!r||!Worker)return void e.Tools.Error("Draco Compression disabled. The current context doesn't support worker creation or URL.createObjectURL");for(var n=new Array(i),o=0;o0&&(c=!0,this._soundLoaded(i));break;case"String":l.push(i);case"Array":0===l.length&&(l=i);for(var h=0;h0&&(this._htmlAudioElement.currentTime=0);else if(e.Engine.audioEngine.audioContext&&this._soundSource){var i=t?e.Engine.audioEngine.audioContext.currentTime+t:e.Engine.audioEngine.audioContext.currentTime;this._soundSource.stop(i),this._soundSource.onended=function(){},this.isPaused||(this._startOffset=0)}this.isPlaying=!1}},t.prototype.pause=function(){this.isPlaying&&(this.isPaused=!0,this._streaming?this._htmlAudioElement.pause():e.Engine.audioEngine.audioContext&&(this.stop(0),this._startOffset+=e.Engine.audioEngine.audioContext.currentTime-this._startTime))},t.prototype.setVolume=function(t,i){e.Engine.audioEngine.canUseWebAudio&&this._soundGain&&(i&&e.Engine.audioEngine.audioContext?(this._soundGain.gain.cancelScheduledValues(e.Engine.audioEngine.audioContext.currentTime),this._soundGain.gain.setValueAtTime(this._soundGain.gain.value,e.Engine.audioEngine.audioContext.currentTime),this._soundGain.gain.linearRampToValueAtTime(t,e.Engine.audioEngine.audioContext.currentTime+i)):this._soundGain.gain.value=t),this._volume=t},t.prototype.setPlaybackRate=function(e){this._playbackRate=e,this.isPlaying&&(this._streaming?this._htmlAudioElement.playbackRate=this._playbackRate:this._soundSource&&(this._soundSource.playbackRate.value=this._playbackRate))},t.prototype.getVolume=function(){return this._volume},t.prototype.attachToMesh=function(e){var t=this;this._connectedMesh&&this._registerFunc&&(this._connectedMesh.unregisterAfterWorldMatrixUpdate(this._registerFunc),this._registerFunc=null),this._connectedMesh=e,this.spatialSound||(this.spatialSound=!0,this._createSpatialParameters(),this.isPlaying&&this.loop&&(this.stop(),this.play())),this._onRegisterAfterWorldMatrixUpdate(this._connectedMesh),this._registerFunc=function(e){return t._onRegisterAfterWorldMatrixUpdate(e)},e.registerAfterWorldMatrixUpdate(this._registerFunc)},t.prototype.detachFromMesh=function(){this._connectedMesh&&this._registerFunc&&(this._connectedMesh.unregisterAfterWorldMatrixUpdate(this._registerFunc),this._registerFunc=null,this._connectedMesh=null)},t.prototype._onRegisterAfterWorldMatrixUpdate=function(t){if(t.getBoundingInfo){var i=t,r=i.getBoundingInfo();this.setPosition(r.boundingSphere.centerWorld),e.Engine.audioEngine.canUseWebAudio&&this._isDirectional&&this.isPlaying&&this._updateDirection()}},t.prototype.clone=function(){var e=this;if(this._streaming)return null;var i=function(){e._isReadyToPlay?(n._audioBuffer=e.getAudioBuffer(),n._isReadyToPlay=!0,n.autoplay&&n.play()):window.setTimeout(i,300)},r={autoplay:this.autoplay,loop:this.loop,volume:this._volume,spatialSound:this.spatialSound,maxDistance:this.maxDistance,useCustomAttenuation:this.useCustomAttenuation,rolloffFactor:this.rolloffFactor,refDistance:this.refDistance,distanceModel:this.distanceModel},n=new t(this.name+"_cloned",new ArrayBuffer(0),this._scene,null,r);return this.useCustomAttenuation&&n.setAttenuationFunction(this._customAttenuationFunction),n.setPosition(this._position),n.setPlaybackRate(this._playbackRate),i(),n},t.prototype.getAudioBuffer=function(){return this._audioBuffer},t.prototype.serialize=function(){var e={name:this.name,url:this.name,autoplay:this.autoplay,loop:this.loop,volume:this._volume,spatialSound:this.spatialSound,maxDistance:this.maxDistance,rolloffFactor:this.rolloffFactor,refDistance:this.refDistance,distanceModel:this.distanceModel,playbackRate:this._playbackRate,panningModel:this._panningModel,soundTrackId:this.soundTrackId};return this.spatialSound&&(this._connectedMesh&&(e.connectedMeshId=this._connectedMesh.id),e.position=this._position.asArray(),e.refDistance=this.refDistance,e.distanceModel=this.distanceModel,e.isDirectional=this._isDirectional,e.localDirectionToMesh=this._localDirection.asArray(),e.coneInnerAngle=this._coneInnerAngle,e.coneOuterAngle=this._coneOuterAngle,e.coneOuterGain=this._coneOuterGain),e},t.Parse=function(i,r,n,o){var s,a=i.name;s=i.url?n+i.url:n+a;var l,c={autoplay:i.autoplay,loop:i.loop,volume:i.volume,spatialSound:i.spatialSound,maxDistance:i.maxDistance,rolloffFactor:i.rolloffFactor,refDistance:i.refDistance,distanceModel:i.distanceModel,playbackRate:i.playbackRate};if(o){var h=function(){o._isReadyToPlay?(l._audioBuffer=o.getAudioBuffer(),l._isReadyToPlay=!0,l.autoplay&&l.play()):window.setTimeout(h,300)};l=new t(a,new ArrayBuffer(0),r,null,c),h()}else l=new t(a,s,r,function(){r._removePendingData(l)},c),r._addPendingData(l);if(i.position){var u=e.Vector3.FromArray(i.position);l.setPosition(u)}if(i.isDirectional&&(l.setDirectionalCone(i.coneInnerAngle||360,i.coneOuterAngle||360,i.coneOuterGain||0),i.localDirectionToMesh)){var f=e.Vector3.FromArray(i.localDirectionToMesh);l.setLocalDirectionToMesh(f)}if(i.connectedMeshId){var d=r.getMeshByID(i.connectedMeshId);d&&l.attachToMesh(d)}return l},t})();e.Sound=t})(e||(e={}));var e;!(function(e){var t=(function(){function t(e,t){this.id=-1,this._isMainTrack=!1,this._isInitialized=!1,this._scene=e,this.soundCollection=new Array,this._options=t,this._isMainTrack||(this._scene.soundTracks.push(this),this.id=this._scene.soundTracks.length-1)}return t.prototype._initializeSoundTrackAudioGraph=function(){e.Engine.audioEngine.canUseWebAudio&&e.Engine.audioEngine.audioContext&&(this._outputAudioNode=e.Engine.audioEngine.audioContext.createGain(),this._outputAudioNode.connect(e.Engine.audioEngine.masterGain),this._options&&(this._options.volume&&(this._outputAudioNode.gain.value=this._options.volume),this._options.mainTrack&&(this._isMainTrack=this._options.mainTrack)),this._isInitialized=!0)},t.prototype.dispose=function(){if(e.Engine.audioEngine&&e.Engine.audioEngine.canUseWebAudio){for(this._connectedAnalyser&&this._connectedAnalyser.stopDebugCanvas();this.soundCollection.length;)this.soundCollection[0].dispose();this._outputAudioNode&&this._outputAudioNode.disconnect(),this._outputAudioNode=null}},t.prototype.AddSound=function(t){this._isInitialized||this._initializeSoundTrackAudioGraph(),e.Engine.audioEngine.canUseWebAudio&&this._outputAudioNode&&t.connectToSoundTrackAudioNode(this._outputAudioNode),t.soundTrackId&&(-1===t.soundTrackId?this._scene.mainSoundTrack.RemoveSound(t):this._scene.soundTracks[t.soundTrackId].RemoveSound(t)),this.soundCollection.push(t),t.soundTrackId=this.id},t.prototype.RemoveSound=function(e){var t=this.soundCollection.indexOf(e);-1!==t&&this.soundCollection.splice(t,1)},t.prototype.setVolume=function(t){e.Engine.audioEngine.canUseWebAudio&&this._outputAudioNode&&(this._outputAudioNode.gain.value=t)},t.prototype.switchPanningModelToHRTF=function(){if(e.Engine.audioEngine.canUseWebAudio)for(var t=0;t-1?i.substring(d).toLowerCase():""),_=".dds"===p;if(!s&&(_||n||(n=["_px.jpg","_py.jpg","_pz.jpg","_nx.jpg","_ny.jpg","_nz.jpg"]),s=[],n))for(var m=0;m0&&(this._postProcesses[0].autoClear=!1))}},i.prototype._shouldRender=function(){return-1===this._currentRefreshId?(this._currentRefreshId=1,!0):this.refreshRate===this._currentRefreshId?(this._currentRefreshId=1,!0):(this._currentRefreshId++,!1)},i.prototype.getRenderSize=function(){return this._size.width?this._size.width:this._size},i.prototype.getRenderWidth=function(){return this._size.width?this._size.width:this._size},i.prototype.getRenderHeight=function(){return this._size.width?this._size.height:this._size},Object.defineProperty(i.prototype,"canRescale",{get:function(){return!0},enumerable:!0,configurable:!0}),i.prototype.scale=function(e){var t=this.getRenderSize()*e;this.resize(t)},i.prototype.getReflectionTextureMatrix=function(){return this.isCube?this._textureMatrix:t.prototype.getReflectionTextureMatrix.call(this)},i.prototype.resize=function(e){this.releaseInternalTexture();var t=this.getScene();t&&(this._processSizeParameter(e),this.isCube?this._texture=t.getEngine().createRenderTargetCubeTexture(this.getRenderSize(),this._renderTargetOptions):this._texture=t.getEngine().createRenderTargetTexture(this._size,this._renderTargetOptions))},i.prototype.render=function(e,t){void 0===e&&(e=!1),void 0===t&&(t=!1);var i=this.getScene();if(i){var r=i.getEngine();if(void 0!==this.useCameraPostProcesses&&(e=this.useCameraPostProcesses),this._waitingRenderList){this.renderList=[];for(var n=0;n=0&&this._renderingManager.dispatchParticles(v))}if(this.isCube)for(var b=0;b<6;b++)this.renderToTarget(b,h,u,e,t),i.incrementRenderId(),i.resetCachedMaterial();else this.renderToTarget(0,h,u,e,t);this.onAfterUnbindObservable.notifyObservers(this),i.activeCamera&&(this.activeCamera&&this.activeCamera!==i.activeCamera&&i.setTransformMatrix(i.activeCamera.getViewMatrix(),i.activeCamera.getProjectionMatrix(!0)),r.setViewport(i.activeCamera.viewport)),i.resetCachedMaterial()}},i.prototype._bestReflectionRenderTargetDimension=function(t,i){var r=t*i,n=e.Tools.NearestPOT(r+16384/(128+r));return Math.min(e.Tools.FloorPOT(t),n)},i.prototype.unbindFrameBuffer=function(e,t){var i=this;this._texture&&e.unBindFramebuffer(this._texture,this.isCube,(function(){i.onAfterRenderObservable.notifyObservers(t)}))},i.prototype.renderToTarget=function(t,i,r,n,o){var s=this.getScene();if(s){var a=s.getEngine();this._texture&&(this._postProcessManager?this._postProcessManager._prepareFrame(this._texture,this._postProcesses):n&&s.postProcessManager._prepareFrame(this._texture)||this._texture&&a.bindFramebuffer(this._texture,this.isCube?t:void 0,void 0,void 0,this.ignoreCameraViewport,this.depthStencilTexture?this.depthStencilTexture:void 0),this.onBeforeRenderObservable.notifyObservers(t),this.onClearObservable.hasObservers()?this.onClearObservable.notifyObservers(a):a.clear(this.clearColor||s.clearColor,!0,!0,!0),this._doNotChangeAspectRatio||s.updateTransformMatrix(!0),this._renderingManager.render(this.customRenderFunction,i,this.renderParticles,this.renderSprites),this._postProcessManager?this._postProcessManager._finalizeFrame(!1,this._texture,t,this._postProcesses,this.ignoreCameraViewport):n&&s.postProcessManager._finalizeFrame(!1,this._texture,t),this._doNotChangeAspectRatio||s.updateTransformMatrix(!0),o&&e.Tools.DumpFramebuffer(this.getRenderWidth(),this.getRenderHeight(),a),this.isCube&&5!==t?this.onAfterRenderObservable.notifyObservers(t):(this.isCube&&5===t&&a.generateMipMapsForCubemap(this._texture),this.unbindFrameBuffer(a,t)))}},i.prototype.setRenderingOrder=function(e,t,i,r){void 0===t&&(t=null),void 0===i&&(i=null),void 0===r&&(r=null),this._renderingManager.setRenderingOrder(e,t,i,r)},i.prototype.setRenderingAutoClearDepthStencil=function(e,t){this._renderingManager.setRenderingAutoClearDepthStencil(e,t)},i.prototype.clone=function(){var e=this.getSize(),t=new i(this.name,e.width,this.getScene(),this._renderTargetOptions.generateMipMaps,this._doNotChangeAspectRatio,this._renderTargetOptions.type,this.isCube,this._renderTargetOptions.samplingMode,this._renderTargetOptions.generateDepthBuffer,this._renderTargetOptions.generateStencilBuffer);return t.hasAlpha=this.hasAlpha,t.level=this.level,t.coordinatesMode=this.coordinatesMode,this.renderList&&(t.renderList=this.renderList.slice(0)),t},i.prototype.serialize=function(){if(!this.name)return null;var e=t.prototype.serialize.call(this);if(e.renderTargetSize=this.getRenderSize(),e.renderList=[],this.renderList)for(var i=0;i=0&&e.customRenderTargets.splice(i,1);for(var r=0,n=e.cameras;r=0&&o.customRenderTargets.splice(i,1)}t.prototype.dispose.call(this)}},i.prototype._rebuild=function(){this.refreshRate===i.REFRESHRATE_RENDER_ONCE&&(this.refreshRate=i.REFRESHRATE_RENDER_ONCE),this._postProcessManager&&this._postProcessManager._rebuild()},i._REFRESHRATE_RENDER_ONCE=0,i._REFRESHRATE_RENDER_ONEVERYFRAME=1,i._REFRESHRATE_RENDER_ONEVERYTWOFRAMES=2,i})(e.Texture);e.RenderTargetTexture=t})(e||(e={}));var e;!(function(e){var t=(function(t){function i(i,r,n,o,s){var a=this,l=!(!s||!s.generateMipMaps)&&s.generateMipMaps,c=!(!s||!s.generateDepthTexture)&&s.generateDepthTexture,h=!s||void 0===s.doNotChangeAspectRatio||s.doNotChangeAspectRatio;if(a=t.call(this,i,r,o,l,h)||this,a._engine=o.getEngine(),!a.isSupported)return void a.dispose();for(var u=[],f=[],d=0;d1||this._engine.getCaps().drawBuffersExtension},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"textures",{get:function(){return this._textures},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"depthTexture",{get:function(){return this._textures[this._textures.length-1]},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"wrapU",{set:function(e){if(this._textures)for(var t=0;t=0;e--)void 0!==this._internalTextures[e]&&(this._internalTextures[e].dispose(),this._internalTextures.splice(e,1))},i})(e.RenderTargetTexture);e.MultiRenderTarget=t})(e||(e={}));var e;!(function(e){var t=(function(t){function i(i,r,n,o,s,a,l){void 0===s&&(s=e.Engine.TEXTURETYPE_UNSIGNED_INT),void 0===a&&(a=e.Texture.BILINEAR_SAMPLINGMODE),void 0===l&&(l=!0);var c=t.call(this,i,r,n,o,!0,s,!1,a,l)||this;return c.mirrorPlane=new e.Plane(0,1,0,1),c._transformMatrix=e.Matrix.Zero(),c._mirrorMatrix=e.Matrix.Zero(),c._adaptiveBlurKernel=0,c._blurKernelX=0,c._blurKernelY=0,c._blurRatio=1,c.ignoreCameraViewport=!0,c.onBeforeRenderObservable.add((function(){e.Matrix.ReflectionToRef(c.mirrorPlane,c._mirrorMatrix),c._savedViewMatrix=n.getViewMatrix(),c._mirrorMatrix.multiplyToRef(c._savedViewMatrix,c._transformMatrix),n.setTransformMatrix(c._transformMatrix,n.getProjectionMatrix()),n.clipPlane=c.mirrorPlane,n.getEngine().cullBackFaces=!1,n._mirroredCameraPosition=e.Vector3.TransformCoordinates(n.activeCamera.globalPosition,c._mirrorMatrix)})),c.onAfterRenderObservable.add((function(){n.setTransformMatrix(c._savedViewMatrix,n.getProjectionMatrix()),n.getEngine().cullBackFaces=!0,n._mirroredCameraPosition=null,delete n.clipPlane})),c}return __extends(i,t),Object.defineProperty(i.prototype,"blurRatio",{get:function(){return this._blurRatio},set:function(e){this._blurRatio!==e&&(this._blurRatio=e,this._preparePostProcesses())},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"adaptiveBlurKernel",{set:function(e){this._adaptiveBlurKernel=e,this._autoComputeBlurKernel()},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"blurKernel",{set:function(e){this.blurKernelX=e,this.blurKernelY=e},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"blurKernelX",{get:function(){return this._blurKernelX},set:function(e){this._blurKernelX!==e&&(this._blurKernelX=e,this._preparePostProcesses())},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"blurKernelY",{get:function(){return this._blurKernelY},set:function(e){this._blurKernelY!==e&&(this._blurKernelY=e,this._preparePostProcesses())},enumerable:!0,configurable:!0}),i.prototype._autoComputeBlurKernel=function(){var e=this.getScene().getEngine(),t=this.getRenderWidth()/e.getRenderWidth(),i=this.getRenderHeight()/e.getRenderHeight();this.blurKernelX=this._adaptiveBlurKernel*t,this.blurKernelY=this._adaptiveBlurKernel*i},i.prototype._onRatioRescale=function(){this._sizeRatio&&(this.resize(this._initialSizeParameter),this._adaptiveBlurKernel||this._preparePostProcesses()),this._adaptiveBlurKernel&&this._autoComputeBlurKernel()},i.prototype._preparePostProcesses=function(){if(this.clearPostProcesses(!0),this._blurKernelX&&this._blurKernelY){var t=this.getScene().getEngine(),i=t.getCaps().textureFloatRender?e.Engine.TEXTURETYPE_FLOAT:e.Engine.TEXTURETYPE_HALF_FLOAT;this._blurX=new e.BlurPostProcess("horizontal blur",new e.Vector2(1,0),this._blurKernelX,this._blurRatio,null,e.Texture.BILINEAR_SAMPLINGMODE,t,!1,i),this._blurX.autoClear=!1,1===this._blurRatio&&this.samples<2&&this._texture?this._blurX.inputTexture=this._texture:this._blurX.alwaysForcePOT=!0,this._blurY=new e.BlurPostProcess("vertical blur",new e.Vector2(0,1),this._blurKernelY,this._blurRatio,null,e.Texture.BILINEAR_SAMPLINGMODE,t,!1,i),this._blurY.autoClear=!1,this._blurY.alwaysForcePOT=1!==this._blurRatio,this.addPostProcess(this._blurX),this.addPostProcess(this._blurY)}else this._blurY&&(this.removePostProcess(this._blurY),this._blurY.dispose(),this._blurY=null),this._blurX&&(this.removePostProcess(this._blurX),this._blurX.dispose(),this._blurX=null)},i.prototype.clone=function(){var e=this.getScene();if(!e)return this;var t=this.getSize(),r=new i(this.name,t.width,e,this._renderTargetOptions.generateMipMaps,this._renderTargetOptions.type,this._renderTargetOptions.samplingMode,this._renderTargetOptions.generateDepthBuffer);return r.hasAlpha=this.hasAlpha,r.level=this.level,r.mirrorPlane=this.mirrorPlane.clone(),this.renderList&&(r.renderList=this.renderList.slice(0)),r},i.prototype.serialize=function(){if(!this.name)return null;var e=t.prototype.serialize.call(this);return e.mirrorPlane=this.mirrorPlane.asArray(),e},i})(e.RenderTargetTexture);e.MirrorTexture=t})(e||(e={}));var e;!(function(e){var t=(function(t){function i(i,r,n,o){var s=t.call(this,i,r,n,o,!0)||this;return s.refractionPlane=new e.Plane(0,1,0,1),s.depth=2,s.onBeforeRenderObservable.add((function(){n.clipPlane=s.refractionPlane})),s.onAfterRenderObservable.add((function(){delete n.clipPlane})),s}return __extends(i,t),i.prototype.clone=function(){var e=this.getScene();if(!e)return this;var t=this.getSize(),r=new i(this.name,t.width,e,this._generateMipMaps);return r.hasAlpha=this.hasAlpha,r.level=this.level,r.refractionPlane=this.refractionPlane.clone(),this.renderList&&(r.renderList=this.renderList.slice(0)),r.depth=this.depth,r},i.prototype.serialize=function(){if(!this.name)return null;var e=t.prototype.serialize.call(this);return e.mirrorPlane=this.refractionPlane.asArray(),e.depth=this.depth,e},i})(e.RenderTargetTexture);e.RefractionTexture=t})(e||(e={}));var e;!(function(e){var t=(function(t){function i(i,r,n,o,s,a){void 0===n&&(n=null),void 0===s&&(s=e.Texture.TRILINEAR_SAMPLINGMODE),void 0===a&&(a=e.Engine.TEXTUREFORMAT_RGBA);var l=t.call(this,null,n,!o,void 0,s,void 0,void 0,void 0,void 0,a)||this;l.name=i,l._engine=l.getScene().getEngine(),l.wrapU=e.Texture.CLAMP_ADDRESSMODE,l.wrapV=e.Texture.CLAMP_ADDRESSMODE,l._generateMipMaps=o,r.getContext?(l._canvas=r,l._texture=l._engine.createDynamicTexture(r.width,r.height,o,s)):(l._canvas=document.createElement("canvas"),r.width?l._texture=l._engine.createDynamicTexture(r.width,r.height,o,s):l._texture=l._engine.createDynamicTexture(r,r,o,s));var c=l.getSize();return l._canvas.width=c.width,l._canvas.height=c.height,l._context=l._canvas.getContext("2d"),l}return __extends(i,t),Object.defineProperty(i.prototype,"canRescale",{get:function(){return!0},enumerable:!0,configurable:!0}),i.prototype._recreate=function(e){this._canvas.width=e.width,this._canvas.height=e.height,this.releaseInternalTexture(),this._texture=this._engine.createDynamicTexture(e.width,e.height,this._generateMipMaps,this._samplingMode)},i.prototype.scale=function(e){var t=this.getSize();t.width*=e,t.height*=e,this._recreate(t)},i.prototype.scaleTo=function(e,t){var i=this.getSize();i.width=e,i.height=t,this._recreate(i)},i.prototype.getContext=function(){return this._context},i.prototype.clear=function(){var e=this.getSize();this._context.fillRect(0,0,e.width,e.height)},i.prototype.update=function(e){this._engine.updateDynamicTexture(this._texture,this._canvas,void 0===e||e,void 0,this._format||void 0)},i.prototype.drawText=function(e,t,i,r,n,o,s,a){void 0===a&&(a=!0);var l=this.getSize();if(o&&(this._context.fillStyle=o,this._context.fillRect(0,0,l.width,l.height)),this._context.font=r,null===t||void 0===t){var c=this._context.measureText(e);t=(l.width-c.width)/2}if(null===i||void 0===i){var h=parseInt(r.replace(/\D/g,""));i=l.height/2+h/3.65}this._context.fillStyle=n,this._context.fillText(e,t,i),a&&this.update(s)},i.prototype.clone=function(){var e=this.getScene();if(!e)return this;var t=this.getSize(),r=new i(this.name,t,e,this._generateMipMaps);return r.hasAlpha=this.hasAlpha,r.level=this.level,r.wrapU=this.wrapU,r.wrapV=this.wrapV,r},i.prototype._rebuild=function(){this.update()},i})(e.Texture);e.DynamicTexture=t})(e||(e={}));var e;!(function(e){var t=(function(t){function i(i,r,n,o,s,a,l){void 0===o&&(o=!1),void 0===s&&(s=!1),void 0===a&&(a=e.Texture.TRILINEAR_SAMPLINGMODE),void 0===l&&(l={autoPlay:!0,loop:!0,autoUpdateTexture:!0});var c=t.call(this,null,n,!o,s)||this;return c._createInternalTexture=function(){null==c._texture&&(!c._engine.needPOTTextures||e.Tools.IsExponentOfTwo(c.video.videoWidth)&&e.Tools.IsExponentOfTwo(c.video.videoHeight)?(c.wrapU=e.Texture.WRAP_ADDRESSMODE,c.wrapV=e.Texture.WRAP_ADDRESSMODE):(c.wrapU=e.Texture.CLAMP_ADDRESSMODE,c.wrapV=e.Texture.CLAMP_ADDRESSMODE,c._generateMipMaps=!1),c._texture=c._engine.createDynamicTexture(c.video.videoWidth,c.video.videoHeight,c._generateMipMaps,c._samplingMode),c._texture.isReady=!0,c._updateInternalTexture(),c._onLoadObservable&&c._onLoadObservable.hasObservers()&&c.onLoadObservable.notifyObservers(c))},c.reset=function(){null!=c._texture&&(c._texture.dispose(),c._texture=null)},c._updateInternalTexture=function(e){null!=c._texture&&c._texture.isReady&&(c.video.readyState=c.video.HAVE_CURRENT_DATA&&c._createInternalTexture(),c}return __extends(i,t),i.prototype._getName=function(e){return e instanceof HTMLVideoElement?e.currentSrc:"object"==typeof e?e.toString():e},i.prototype._getVideo=function(t){if(t instanceof HTMLVideoElement)return e.Tools.SetCorsBehavior(t.currentSrc,t),t;var i=document.createElement("video");return"string"==typeof t?(e.Tools.SetCorsBehavior(t,i),i.src=t):(e.Tools.SetCorsBehavior(t[0],i),t.forEach((function(e){var t=document.createElement("source");t.src=e,i.appendChild(t)}))),i},i.prototype._rebuild=function(){this.update()},i.prototype.update=function(){this.autoUpdateTexture&&this.updateTexture(!0)},i.prototype.updateTexture=function(e){e&&(this.video.paused||this._updateInternalTexture())},i.prototype.updateURL=function(e){this.video.src=e},i.prototype.dispose=function(){t.prototype.dispose.call(this),this.video.removeEventListener("canplay",this._createInternalTexture),this.video.removeEventListener("paused",this._updateInternalTexture),this.video.removeEventListener("seeked",this._updateInternalTexture),this.video.removeEventListener("emptied",this.reset),this.video.pause()},i.CreateFromWebCam=function(t,r,n){var o,s=document.createElement("video");n&&n.deviceId&&(o={exact:n.deviceId}),window.URL=window.URL||window.webkitURL||window.mozURL||window.msURL,navigator.mediaDevices?navigator.mediaDevices.getUserMedia({video:n}).then((function(e){void 0!==s.mozSrcObject?s.mozSrcObject=e:s.srcObject=e;var n=function(){r&&r(new i("video",s,t,!0,!0)),s.removeEventListener("playing",n)};s.addEventListener("playing",n),s.play()})).catch((function(t){e.Tools.Error(t.name)})):(navigator.getUserMedia=navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia,navigator.getUserMedia&&navigator.getUserMedia({video:{deviceId:o,width:{min:n&&n.minWidth||256,max:n&&n.maxWidth||640},height:{min:n&&n.minHeight||256,max:n&&n.maxHeight||480}}},(function(e){void 0!==s.mozSrcObject?s.mozSrcObject=e:s.src=window.URL&&window.URL.createObjectURL(e)||e,s.play(),r&&r(new i("video",s,t,!0,!0))}),(function(t){e.Tools.Error(t.name)})))},i})(e.Texture);e.VideoTexture=t})(e||(e={}));var e;!(function(e){var t=(function(t){function i(i,r,n,o,s,a,l,c,h){void 0===a&&(a=!0),void 0===l&&(l=!1),void 0===c&&(c=e.Texture.TRILINEAR_SAMPLINGMODE),void 0===h&&(h=e.Engine.TEXTURETYPE_UNSIGNED_INT);var u=t.call(this,null,s,!a,l)||this;return u.format=o,u._engine=s.getEngine(),u._texture=s.getEngine().createRawTexture(i,r,n,o,a,l,c,null,h),u.wrapU=e.Texture.CLAMP_ADDRESSMODE,u.wrapV=e.Texture.CLAMP_ADDRESSMODE,u}return __extends(i,t),i.prototype.update=function(e){this._engine.updateRawTexture(this._texture,e,this._texture.format,this._texture.invertY,void 0,this._texture.type)},i.CreateLuminanceTexture=function(t,r,n,o,s,a,l){return void 0===s&&(s=!0),void 0===a&&(a=!1),void 0===l&&(l=e.Texture.TRILINEAR_SAMPLINGMODE),new i(t,r,n,e.Engine.TEXTUREFORMAT_LUMINANCE,o,s,a,l)},i.CreateLuminanceAlphaTexture=function(t,r,n,o,s,a,l){return void 0===s&&(s=!0),void 0===a&&(a=!1),void 0===l&&(l=e.Texture.TRILINEAR_SAMPLINGMODE),new i(t,r,n,e.Engine.TEXTUREFORMAT_LUMINANCE_ALPHA,o,s,a,l)},i.CreateAlphaTexture=function(t,r,n,o,s,a,l){return void 0===s&&(s=!0),void 0===a&&(a=!1),void 0===l&&(l=e.Texture.TRILINEAR_SAMPLINGMODE),new i(t,r,n,e.Engine.TEXTUREFORMAT_ALPHA,o,s,a,l)},i.CreateRGBTexture=function(t,r,n,o,s,a,l,c){return void 0===s&&(s=!0),void 0===a&&(a=!1),void 0===l&&(l=e.Texture.TRILINEAR_SAMPLINGMODE),void 0===c&&(c=e.Engine.TEXTURETYPE_UNSIGNED_INT),new i(t,r,n,e.Engine.TEXTUREFORMAT_RGB,o,s,a,l,c)},i.CreateRGBATexture=function(t,r,n,o,s,a,l,c){return void 0===s&&(s=!0),void 0===a&&(a=!1),void 0===l&&(l=e.Texture.TRILINEAR_SAMPLINGMODE),void 0===c&&(c=e.Engine.TEXTURETYPE_UNSIGNED_INT),new i(t,r,n,e.Engine.TEXTUREFORMAT_RGBA,o,s,a,l,c)},i})(e.Texture);e.RawTexture=t})(e||(e={}));var e;!(function(e){var t=(function(){function t(t,i,r,n,o,s,a,l,c,h,u,f,d,p){void 0===a&&(a=e.Texture.NEAREST_SAMPLINGMODE),void 0===h&&(h=null),void 0===u&&(u=e.Engine.TEXTURETYPE_UNSIGNED_INT),void 0===f&&(f="postprocess"),void 0===p&&(p=!1),this.name=t,this.width=-1,this.height=-1,this.autoClear=!0,this.alphaMode=e.Engine.ALPHA_DISABLE,this.animations=new Array,this.enablePixelPerfectMode=!1,this.scaleMode=e.Engine.SCALEMODE_FLOOR,this.alwaysForcePOT=!1,this.samples=1,this.adaptScaleToCurrentViewport=!1,this._reusable=!1,this._textures=new e.SmartArray(2),this._currentRenderTextureInd=0,this._scaleRatio=new e.Vector2(1,1),this._texelSize=e.Vector2.Zero(),this.onActivateObservable=new e.Observable,this.onSizeChangedObservable=new e.Observable,this.onApplyObservable=new e.Observable,this.onBeforeRenderObservable=new e.Observable,this.onAfterRenderObservable=new e.Observable,null!=s?(this._camera=s,this._scene=s.getScene(),s.attachPostProcess(this),this._engine=this._scene.getEngine(),this._scene.postProcesses.push(this)):l&&(this._engine=l,this._engine.postProcesses.push(this)),this._options=o,this.renderTargetSamplingMode=a||e.Texture.NEAREST_SAMPLINGMODE,this._reusable=c||!1,this._textureType=u,this._samplers=n||[],this._samplers.push("textureSampler"),this._fragmentUrl=i,this._vertexUrl=f,this._parameters=r||[],this._parameters.push("scale"),this._indexParameters=d,p||this.updateEffect(h)}return Object.defineProperty(t.prototype,"onActivate",{set:function(e){this._onActivateObserver&&this.onActivateObservable.remove(this._onActivateObserver),e&&(this._onActivateObserver=this.onActivateObservable.add(e))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"onSizeChanged",{set:function(e){this._onSizeChangedObserver&&this.onSizeChangedObservable.remove(this._onSizeChangedObserver),this._onSizeChangedObserver=this.onSizeChangedObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"onApply",{set:function(e){this._onApplyObserver&&this.onApplyObservable.remove(this._onApplyObserver),this._onApplyObserver=this.onApplyObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"onBeforeRender",{set:function(e){this._onBeforeRenderObserver&&this.onBeforeRenderObservable.remove(this._onBeforeRenderObserver),this._onBeforeRenderObserver=this.onBeforeRenderObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"onAfterRender",{set:function(e){this._onAfterRenderObserver&&this.onAfterRenderObservable.remove(this._onAfterRenderObserver),this._onAfterRenderObserver=this.onAfterRenderObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"inputTexture",{get:function(){return this._textures.data[this._currentRenderTextureInd]},set:function(e){this._forcedOutputTexture=e},enumerable:!0,configurable:!0}),t.prototype.getCamera=function(){return this._camera},Object.defineProperty(t.prototype,"texelSize",{get:function(){return this._shareOutputWithPostProcess?this._shareOutputWithPostProcess.texelSize:(this._forcedOutputTexture&&this._texelSize.copyFromFloats(1/this._forcedOutputTexture.width,1/this._forcedOutputTexture.height),this._texelSize)},enumerable:!0,configurable:!0}),t.prototype.getEngine=function(){return this._engine},t.prototype.getEffect=function(){return this._effect},t.prototype.shareOutputWith=function(e){return this._disposeTextures(),this._shareOutputWithPostProcess=e,this},t.prototype.useOwnOutput=function(){0==this._textures.length&&(this._textures=new e.SmartArray(2)),this._shareOutputWithPostProcess=null},t.prototype.updateEffect=function(e,t,i,r,n,o){void 0===e&&(e=null),void 0===t&&(t=null),void 0===i&&(i=null),this._effect=this._engine.createEffect({vertex:this._vertexUrl,fragment:this._fragmentUrl},["position"],t||this._parameters,i||this._samplers,null!==e?e:"",void 0,n,o,r||this._indexParameters)},t.prototype.isReusable=function(){return this._reusable},t.prototype.markTextureDirty=function(){this.width=-1},t.prototype.activate=function(t,i,r){var n=this;void 0===i&&(i=null),t=t||this._camera ;var o=t.getScene(),s=o.getEngine(),a=s.getCaps().maxTextureSize,l=(i?i.width:this._engine.getRenderWidth(!0))*this._options|0,c=(i?i.height:this._engine.getRenderHeight(!0))*this._options|0,h=t.parent;!h||h.leftCamera!=t&&h.rightCamera!=t||(l/=2);var u=this._options.width||l,f=this._options.height||c;if(!this._shareOutputWithPostProcess&&!this._forcedOutputTexture){if(this.adaptScaleToCurrentViewport){var d=s.currentViewport;d&&(u*=d.width,f*=d.height)}if((this.renderTargetSamplingMode===e.Texture.TRILINEAR_SAMPLINGMODE||this.alwaysForcePOT)&&(this._options.width||(u=s.needPOTTextures?e.Tools.GetExponentOfTwo(u,a,this.scaleMode):u),this._options.height||(f=s.needPOTTextures?e.Tools.GetExponentOfTwo(f,a,this.scaleMode):f)),this.width!==u||this.height!==f){if(this._textures.length>0){for(var p=0;p0)for(var e=0;e0&&this._camera._postProcesses[0].markTextureDirty(),this.onActivateObservable.clear(),this.onAfterRenderObservable.clear(),this.onApplyObservable.clear(),this.onBeforeRenderObservable.clear(),this.onSizeChangedObservable.clear()}},t})();e.PostProcess=t})(e||(e={}));var e;!(function(e){var t=(function(t){function i(i,r,n,o,s,a,l){return void 0===n&&(n=null),void 0===l&&(l=e.Engine.TEXTURETYPE_UNSIGNED_INT),t.call(this,i,"pass",null,null,r,n,o,s,a,void 0,l)||this}return __extends(i,t),i})(e.PostProcess);e.PassPostProcess=t})(e||(e={}));var e,t=this&&this.__assign||Object.assign||function(e){for(var t,i=1,r=arguments.length;i=1?1:e<=0?0:e,this},i.prototype.setTransparencyShadow=function(e){return this._transparencyShadow=e,this},i.prototype.getShadowMap=function(){return this._shadowMap},i.prototype.getShadowMapForRendering=function(){return this._shadowMap2?this._shadowMap2:this._shadowMap},i.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},i.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=a.length)return void(e&&e(r));setTimeout(f,16)}};f()},i.prototype.forceCompilationAsync=function(e){var t=this;return new Promise(function(i){t.forceCompilation((function(){i()}),e)})},i.prototype.isReady=function(t,i){var r=[];this._textureType!==e.Engine.TEXTURETYPE_UNSIGNED_INT&&r.push("#define FLOAT"),(this.useExponentialShadowMap||this.useBlurExponentialShadowMap)&&r.push("#define ESM");var n=[e.VertexBuffer.PositionKind],o=t.getMesh(),s=t.getMaterial();if(s&&s.needAlphaTesting()){var a=s.getAlphaTestTexture();a&&(r.push("#define ALPHATEST"),o.isVerticesDataPresent(e.VertexBuffer.UVKind)&&(n.push(e.VertexBuffer.UVKind),r.push("#define UV1")),o.isVerticesDataPresent(e.VertexBuffer.UV2Kind)&&1===a.coordinatesIndex&&(n.push(e.VertexBuffer.UV2Kind),r.push("#define UV2")))}o.useBones&&o.computeBonesUsingShaders?(n.push(e.VertexBuffer.MatricesIndicesKind),n.push(e.VertexBuffer.MatricesWeightsKind),o.numBoneInfluencers>4&&(n.push(e.VertexBuffer.MatricesIndicesExtraKind),n.push(e.VertexBuffer.MatricesWeightsExtraKind)),r.push("#define NUM_BONE_INFLUENCERS "+o.numBoneInfluencers),r.push("#define BonesPerMesh "+(o.skeleton.bones.length+1))):r.push("#define NUM_BONE_INFLUENCERS 0"),i&&(r.push("#define INSTANCES"),n.push("world0"),n.push("world1"),n.push("world2"),n.push("world3"));var l=r.join("\n");return this._cachedDefines!==l&&(this._cachedDefines=l,this._effect=this._scene.getEngine().createEffect("shadowMap",n,["world","mBones","viewProjection","diffuseMatrix","lightPosition","depthValues","biasAndScale"],["diffuseSampler"],l)),!!this._effect.isReady()&&((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())))},i.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))},i.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))}}},i.prototype.getTransformMatrix=function(){var t=this._scene;if(this._currentRenderID===t.getRenderId()&&this._currentFaceIndexCache===this._currentFaceIndex)return this._transformMatrix;this._currentRenderID=t.getRenderId(),this._currentFaceIndexCache=this._currentFaceIndex;var i=this._light.position;if(this._light.computeTransformedInformation()&&(i=this._light.transformedPosition),e.Vector3.NormalizeToRef(this._light.getShadowDirection(this._currentFaceIndex),this._lightDirection),1===Math.abs(e.Vector3.Dot(this._lightDirection,e.Vector3.Up()))&&(this._lightDirection.z=1e-13),this._light.needProjectionMatrixCompute()||!this._cachedPosition||!this._cachedDirection||!i.equals(this._cachedPosition)||!this._lightDirection.equals(this._cachedDirection)){this._cachedPosition.copyFrom(i),this._cachedDirection.copyFrom(this._lightDirection),e.Matrix.LookAtLHToRef(i,i.add(this._lightDirection),e.Vector3.Up(),this._viewMatrix);var r=this.getShadowMap();if(r){var n=r.renderList;n&&this._light.setShadowProjectionMatrix(this._projectionMatrix,this._viewMatrix,n)}this._viewMatrix.multiplyToRef(this._projectionMatrix,this._transformMatrix)}return this._transformMatrix},i.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}},i.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=[]},i.prototype._disposeRTTandPostProcesses=function(){this._shadowMap&&(this._shadowMap.dispose(),this._shadowMap=null),this._disposeBlurPostProcesses()},i.prototype.dispose=function(){this._disposeRTTandPostProcesses(),this._light&&(this._light._shadowGenerator=null,this._light._markMeshesAsLightDirty())},i.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;i0){for(var ce=0;ce0){for(var ue=0;ue-1&&void 0!==d.skeletons&&null!==d.skeletons){if(!1===v.indexOf(b.skeletonId)>-1)for(var I=0,D=d.skeletons.length;I0&&this._textureLoadingCallback(e)}this._currentScene.render()}},t.prototype.drag=function(e){e.stopPropagation(),e.preventDefault()},t.prototype.drop=function(e){e.stopPropagation(),e.preventDefault(),this.loadFiles(e)},t.prototype._traverseFolder=function(e,t,i,r){var n=this,o=e.createReader(),s=e.fullPath.replace(/^\//,"").replace(/(.+?)\/?$/,"$1/");o.readEntries((function(e){i.count+=e.length;for(var o=0,a=e;o0){for(var i=new Array,r=[],n=e.dataTransfer?e.dataTransfer.items:null,o=0;o0&&e.Tools.ClearLogCache(),this._engine.stopRenderLoop(),this._currentScene.dispose()),e.SceneLoader.LoadAsync("file:",this._sceneFileToLoad,this._engine,(function(e){t._progressCallback&&t._progressCallback(e)})).then((function(e){t._currentScene=e,t._sceneLoadedCallback&&t._sceneLoadedCallback(t._sceneFileToLoad,t._currentScene),t._currentScene.executeWhenReady((function(){t._engine.runRenderLoop((function(){t.renderFunction()}))}))})).catch((function(e){t._errorCallback&&t._errorCallback(t._sceneFileToLoad,t._currentScene,e.message)}))):e.Tools.Error("Please provide a valid .babylon file.")},t.FilesToLoad={},t})();e.FilesInput=t})(e||(e={}));var e;!(function(e){var t=(function(){function e(){this._count=0,this._data={}}return e.prototype.copyFrom=function(e){var t=this;this.clear(),e.forEach((function(e,i){return t.add(e,i)}))},e.prototype.get=function(e){var t=this._data[e];if(void 0!==t)return t},e.prototype.getOrAddWithFactory=function(e,t){var i=this.get(e);return void 0!==i?i:(i=t(e),i&&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=this._data[t],r=e(t,i);if(r)return r}return null},e})();e.StringDictionary=t})(e||(e={}));var e;!(function(e){var t=(function(){function t(){}return t.EnableFor=function(e){e._tags=e._tags||{},e.hasTags=function(){return t.HasTags(e)},e.addTags=function(i){return t.AddTagsTo(e,i)},e.removeTags=function(i){return t.RemoveTagsFrom(e,i)},e.matchesTagsQuery=function(i){return t.MatchesQuery(e,i)}},t.DisableFor=function(e){delete e._tags,delete e.hasTags,delete e.addTags,delete e.removeTags,delete e.matchesTagsQuery},t.HasTags=function(t){return!!t._tags&&!e.Tools.IsEmpty(t._tags)},t.GetTags=function(e,t){if(void 0===t&&(t=!0),!e._tags)return null;if(t){var i=[];for(var r in e._tags)e._tags.hasOwnProperty(r)&&!0===e._tags[r]&&i.push(r);return i.join(" ")}return e._tags},t.AddTagsTo=function(e,i){if(i&&"string"==typeof i){i.split(" ").forEach((function(i,r,n){t._AddTagTo(e,i)}))}},t._AddTagTo=function(e,i){""!==(i=i.trim())&&"true"!==i&&"false"!==i&&(i.match(/[\s]/)||i.match(/^([!]|([|]|[&]){2})/)||(t.EnableFor(e),e._tags[i]=!0))},t.RemoveTagsFrom=function(e,i){if(t.HasTags(e)){var r=i.split(" ");for(var n in r)t._RemoveTagFrom(e,r[n])}},t._RemoveTagFrom=function(e,t){delete e._tags[t]},t.MatchesQuery=function(i,r){return void 0===r||(""===r?t.HasTags(i):e.AndOrNotEvaluator.Eval(r,(function(e){return t.HasTags(i)&&i._tags[e]})))},t})();e.Tags=t})(e||(e={}));var e;!(function(e){var t=(function(){function e(){}return e.Eval=function(t,i){return"true"===(t=t.match(/\([^\(\)]*\)/g)?t.replace(/\([^\(\)]*\)/g,(function(t){return t=t.slice(1,t.length-1),e._HandleParenthesisContent(t,i)})):e._HandleParenthesisContent(t,i))||"false"!==t&&e.Eval(t,i)},e._HandleParenthesisContent=function(t,i){i=i||function(e){return"true"===e};var r,n=t.split("||");for(var o in n)if(n.hasOwnProperty(o)){var s=e._SimplifyNegation(n[o].trim()),a=s.split("&&");if(a.length>1)for(var l=0;lo.data?(n.mustUpdateRessources=!0,r()):i(o.data):(n.mustUpdateRessources=!0,r())},s.onabort=function(e){i(-1)};var a=s.objectStore("versions").get(t);a.onsuccess=function(e){o=e.target.result},a.onerror=function(r){e.Tools.Error("Error loading version for scene "+t+" from DB."),i(-1)}}catch(t){e.Tools.Error("Error while accessing 'versions' object store (READ OP). Exception: "+t.message),i(-1)}}else e.Tools.Error("Error: IndexedDB not supported by your browser or BabylonJS Database is not open."),i(-1)},t.prototype._saveVersionIntoDBAsync=function(t,i){var r=this;if(this.isSupported&&!this.hasReachedQuota&&this.db)try{var n=this.db.transaction(["versions"],"readwrite");n.onabort=function(e){try{var t=e.srcElement.error;t&&"QuotaExceededError"===t.name&&(r.hasReachedQuota=!0)}catch(e){}i(-1)},n.oncomplete=function(e){i(r.manifestVersionFound)};var o={sceneUrl:t,data:this.manifestVersionFound},s=n.objectStore("versions").put(o);s.onsuccess=function(e){},s.onerror=function(t){e.Tools.Error("Error in DB add version request in BABYLON.Database.")}}catch(t){e.Tools.Error("Error while accessing 'versions' object store (WRITE OP). Exception: "+t.message),i(-1)}else i(-1)},t.prototype.loadFileFromDB=function(e,i,r,n,o){var s=this,a=t.ReturnFullUrlLocation(e),l=function(){s._saveFileIntoDBAsync(a,i,r)};this._checkVersionFromDB(a,(function(e){-1!==e?s.mustUpdateRessources?s._saveFileIntoDBAsync(a,i,r,o):s._loadFileFromDBAsync(a,i,l,o):n&&n()}))},t.prototype._loadFileFromDBAsync=function(t,i,r,n){if(this.isSupported&&this.db){var o;o=-1!==t.indexOf(".babylon")?"scenes":"textures";var s,a=this.db.transaction([o]);a.oncomplete=function(e){s?i(s.data):r()},a.onabort=function(e){r()};var l=a.objectStore(o).get(t);l.onsuccess=function(e){s=e.target.result},l.onerror=function(i){e.Tools.Error("Error loading file "+t+" from DB."),r()}}else e.Tools.Error("Error: IndexedDB not supported by your browser or BabylonJS Database is not open."),i()},t.prototype._saveFileIntoDBAsync=function(t,i,r,n){var o=this;if(this.isSupported){var s;s=-1!==t.indexOf(".babylon")?"scenes":"textures";var a,l=new XMLHttpRequest;l.open("GET",t,!0),n&&(l.responseType="arraybuffer"),r&&(l.onprogress=r),l.addEventListener("load",(function(){if(200===l.status||e.Tools.ValidateXHRData(l,n?6:1))if(a=n?l.response:l.responseText,!o.hasReachedQuota&&o.db){var r=o.db.transaction([s],"readwrite");r.onabort=function(e){try{var t=e.srcElement.error;t&&"QuotaExceededError"===t.name&&(o.hasReachedQuota=!0)}catch(e){}i(a)},r.oncomplete=function(e){i(a)};var c;c="scenes"===s?{sceneUrl:t,data:a,version:o.manifestVersionFound}:{textureUrl:t,data:a};try{var h=r.objectStore(s).put(c);h.onsuccess=function(e){},h.onerror=function(t){e.Tools.Error("Error in DB add file request in BABYLON.Database.")}}catch(e){i(a)}}else i(a);else i()}),!1),l.addEventListener("error",(function(t){e.Tools.Error("error on XHR request."),i()}),!1),l.send()}else e.Tools.Error("Error: IndexedDB not supported by your browser or BabylonJS Database is not open."),i()},t.IsUASupportingBlobStorage=!0,t.IDBStorageEnabled=!0,t.parseURL=function(e){document.createElement("a").href=e;var t=e.substring(0,e.lastIndexOf("#")),i=e.substring(t.lastIndexOf("/")+1,e.length);return e.substring(0,e.indexOf(i,0))},t.ReturnFullUrlLocation=function(e){return-1===e.indexOf("http:/")&&-1===e.indexOf("https:/")?t.parseURL(window.location.href)+e:e},t})();e.Database=t})(e||(e={}));var e;!(function(e){var t=(function(){function t(){this._isEnabled=!0,this.leftColor=e.Color3.White(),this.rightColor=e.Color3.Black(),this.bias=0,this.power=1}return Object.defineProperty(t.prototype,"isEnabled",{get:function(){return this._isEnabled},set:function(t){this._isEnabled!==t&&(this._isEnabled=t,e.Engine.MarkAllMaterialsAsDirty(e.Material.FresnelDirtyFlag|e.Material.MiscDirtyFlag))},enumerable:!0,configurable:!0}),t.prototype.clone=function(){var i=new t;return e.Tools.DeepCopy(this,i),i},t.prototype.serialize=function(){var e={};return e.isEnabled=this.isEnabled,e.leftColor=this.leftColor,e.rightColor=this.rightColor,e.bias=this.bias,e.power=this.power,e},t.Parse=function(i){var r=new t;return r.isEnabled=i.isEnabled,r.leftColor=e.Color3.FromArray(i.leftColor),r.rightColor=e.Color3.FromArray(i.rightColor),r.bias=i.bias,r.power=i.power||1,r},t})();e.FresnelParameters=t})(e||(e={}));var e;!(function(e){var t=(function(t){function i(e,i){var r=t.call(this,e,i,!0)||this;return i.multiMaterials.push(r),r.subMaterials=new Array,r.storeEffectOnSubMeshes=!0,r}return __extends(i,t),Object.defineProperty(i.prototype,"subMaterials",{get:function(){return this._subMaterials},set:function(e){this._subMaterials=e,this._hookArray(e)},enumerable:!0,configurable:!0}),i.prototype._hookArray=function(e){var t=this,i=e.push;e.push=function(){for(var r=[],n=0;n=this.subMaterials.length?this.getScene().defaultMaterial:this.subMaterials[e]},i.prototype.getActiveTextures=function(){return(e=t.prototype.getActiveTextures.call(this)).concat.apply(e,this.subMaterials.map((function(e){return e?e.getActiveTextures():[]})));var e},i.prototype.getClassName=function(){return"MultiMaterial"},i.prototype.isReadyForSubMesh=function(e,t,i){for(var r=0;r=0&&r.multiMaterials.splice(n,1),t.prototype.dispose.call(this,e,i)}},i})(e.Material);e.MultiMaterial=t})(e||(e={}));var e;!(function(e){var t=(function(){function t(){this._offsetX=null,this._offsetY=null,this._pointerPressed=new Array,this.touchAngularSensibility=2e5,this.touchMoveSensibility=250}return t.prototype.attachControl=function(t,i){var r=this,n=null;void 0===this._pointerInput&&(this._onLostFocus=function(e){r._offsetX=null,r._offsetY=null},this._pointerInput=function(t,o){var s=t.event;if("mouse"!==s.pointerType)if(t.type===e.PointerEventTypes.POINTERDOWN){if(i||s.preventDefault(),r._pointerPressed.push(s.pointerId),1!==r._pointerPressed.length)return;n={x:s.clientX,y:s.clientY}}else if(t.type===e.PointerEventTypes.POINTERUP){i||s.preventDefault();var a=r._pointerPressed.indexOf(s.pointerId);if(-1===a)return;if(r._pointerPressed.splice(a,1),0!=a)return;n=null,r._offsetX=null,r._offsetY=null}else if(t.type===e.PointerEventTypes.POINTERMOVE){if(i||s.preventDefault(),!n)return;var a=r._pointerPressed.indexOf(s.pointerId);if(0!=a)return;r._offsetX=s.clientX-n.x,r._offsetY=-(s.clientY-n.y)}}),this._observer=this.camera.getScene().onPointerObservable.add(this._pointerInput,e.PointerEventTypes.POINTERDOWN|e.PointerEventTypes.POINTERUP|e.PointerEventTypes.POINTERMOVE),this._onLostFocus&&t.addEventListener("blur",this._onLostFocus)},t.prototype.detachControl=function(e){this._pointerInput&&e&&(this._observer&&(this.camera.getScene().onPointerObservable.remove(this._observer),this._observer=null),this._onLostFocus&&(e.removeEventListener("blur",this._onLostFocus),this._onLostFocus=null),this._pointerPressed=[],this._offsetX=null,this._offsetY=null)},t.prototype.checkInputs=function(){if(this._offsetX&&this._offsetY){var t=this.camera;if(t.cameraRotation.y+=this._offsetX/this.touchAngularSensibility,this._pointerPressed.length>1)t.cameraRotation.x+=-this._offsetY/this.touchAngularSensibility;else{var i=t._computeLocalCameraSpeed(),r=new e.Vector3(0,0,i*this._offsetY/this.touchMoveSensibility);e.Matrix.RotationYawPitchRollToRef(t.rotation.y,t.rotation.x,0,t._cameraRotationMatrix),t.cameraDirection.addInPlace(e.Vector3.TransformCoordinates(r,t._cameraRotationMatrix))}}},t.prototype.getClassName=function(){return"FreeCameraTouchInput"},t.prototype.getSimpleName=function(){return"touch"},__decorate([e.serialize()],t.prototype,"touchAngularSensibility",void 0),__decorate([e.serialize()],t.prototype,"touchMoveSensibility",void 0),t})();e.FreeCameraTouchInput=t,e.CameraInputTypes.FreeCameraTouchInput=t})(e||(e={}));var e;!(function(e){var t=(function(e){function t(t,i,r){var n=e.call(this,t,i,r)||this;return n.inputs.addTouch(),n._setupInputs(),n}return __extends(t,e),Object.defineProperty(t.prototype,"touchAngularSensibility",{get:function(){var e=this.inputs.attached.touch;return e?e.touchAngularSensibility:0},set:function(e){var t=this.inputs.attached.touch;t&&(t.touchAngularSensibility=e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"touchMoveSensibility",{get:function(){var e=this.inputs.attached.touch;return e?e.touchMoveSensibility:0},set:function(e){var t=this.inputs.attached.touch;t&&(t.touchMoveSensibility=e)},enumerable:!0,configurable:!0}),t.prototype.getClassName=function(){return"TouchCamera"},t.prototype._setupInputs=function(){var e=this.inputs.attached.mouse;e&&(e.touchEnabled=!1)},t})(e.FreeCamera);e.TouchCamera=t})(e||(e={}));var e;!(function(e){var t=(function(t){function i(i,r,n,o,s,a,l){void 0===s&&(s=null),void 0===a&&(a=!0),void 0===l&&(l=!1);var c=t.call(this,null,o,!a)||this;c.isCube=l,c.isEnabled=!0,c._currentRefreshId=-1,c._refreshRate=1,c._vertexBuffers={},c._uniforms=new Array,c._samplers=new Array,c._textures={},c._floats={},c._floatsArrays={},c._colors3={},c._colors4={},c._vectors2={},c._vectors3={},c._matrices={},c._fallbackTextureUsed=!1,o._proceduralTextures.push(c),c._engine=o.getEngine(),c.name=i,c.isRenderTarget=!0,c._size=r,c._generateMipMaps=a,c.setFragment(n),c._fallbackTexture=s,l?(c._texture=c._engine.createRenderTargetCubeTexture(r,{generateMipMaps:a}),c.setFloat("face",0)):c._texture=c._engine.createRenderTargetTexture(r,a);var h=[];return h.push(1,1),h.push(-1,1),h.push(-1,-1),h.push(1,-1),c._vertexBuffers[e.VertexBuffer.PositionKind]=new e.VertexBuffer(c._engine,h,e.VertexBuffer.PositionKind,!1,!1,2),c._createIndexBuffer(),c}return __extends(i,t),i.prototype._createIndexBuffer=function(){var e=this._engine,t=[];t.push(0),t.push(1),t.push(2),t.push(0),t.push(2),t.push(3),this._indexBuffer=e.createIndexBuffer(t)},i.prototype._rebuild=function(){var t=this._vertexBuffers[e.VertexBuffer.PositionKind];t&&t._rebuild(),this._createIndexBuffer(),this.refreshRate===e.RenderTargetTexture.REFRESHRATE_RENDER_ONCE&&(this.refreshRate=e.RenderTargetTexture.REFRESHRATE_RENDER_ONCE)},i.prototype.reset=function(){if(void 0!==this._effect){this._engine._releaseEffect(this._effect)}},i.prototype.isReady=function(){var t,i=this,r=this._engine;return!!this._fragment&&(!!this._fallbackTextureUsed||(t=void 0!==this._fragment.fragmentElement?{vertex:"procedural",fragmentElement:this._fragment.fragmentElement}:{vertex:"procedural",fragment:this._fragment},this._effect=r.createEffect(t,[e.VertexBuffer.PositionKind],this._uniforms,this._samplers,"",void 0,void 0,(function(){i.releaseInternalTexture(),i._fallbackTexture&&(i._texture=i._fallbackTexture._texture,i._texture&&i._texture.incrementReferences()),i._fallbackTextureUsed=!0})),this._effect.isReady()))},i.prototype.resetRefreshCounter=function(){this._currentRefreshId=-1},i.prototype.setFragment=function(e){this._fragment=e},Object.defineProperty(i.prototype,"refreshRate",{get:function(){return this._refreshRate},set:function(e){this._refreshRate=e,this.resetRefreshCounter()},enumerable:!0,configurable:!0}),i.prototype._shouldRender=function(){return!!(this.isEnabled&&this.isReady()&&this._texture)&&(!this._fallbackTextureUsed&&(-1===this._currentRefreshId?(this._currentRefreshId=1,!0):this.refreshRate===this._currentRefreshId?(this._currentRefreshId=1,!0):(this._currentRefreshId++,!1)))},i.prototype.getRenderSize=function(){return this._size},i.prototype.resize=function(e,t){this._fallbackTextureUsed||(this.releaseInternalTexture(),this._texture=this._engine.createRenderTargetTexture(e,t))},i.prototype._checkUniform=function(e){-1===this._uniforms.indexOf(e)&&this._uniforms.push(e)},i.prototype.setTexture=function(e,t){return-1===this._samplers.indexOf(e)&&this._samplers.push(e),this._textures[e]=t,this},i.prototype.setFloat=function(e,t){return this._checkUniform(e),this._floats[e]=t,this},i.prototype.setFloats=function(e,t){return this._checkUniform(e),this._floatsArrays[e]=t,this},i.prototype.setColor3=function(e,t){return this._checkUniform(e),this._colors3[e]=t,this},i.prototype.setColor4=function(e,t){return this._checkUniform(e),this._colors4[e]=t,this},i.prototype.setVector2=function(e,t){return this._checkUniform(e),this._vectors2[e]=t,this},i.prototype.setVector3=function(e,t){return this._checkUniform(e),this._vectors3[e]=t,this},i.prototype.setMatrix=function(e,t){return this._checkUniform(e),this._matrices[e]=t,this},i.prototype.render=function(t){var i=this.getScene();if(i){var r=this._engine;r.enableEffect(this._effect),r.setState(!1);for(var n in this._textures)this._effect.setTexture(n,this._textures[n]);for(n in this._floats)this._effect.setFloat(n,this._floats[n]);for(n in this._floatsArrays)this._effect.setArray(n,this._floatsArrays[n]);for(n in this._colors3)this._effect.setColor3(n,this._colors3[n]);for(n in this._colors4){var o=this._colors4[n];this._effect.setFloat4(n,o.r,o.g,o.b,o.a)}for(n in this._vectors2)this._effect.setVector2(n,this._vectors2[n]);for(n in this._vectors3)this._effect.setVector3(n,this._vectors3[n]);for(n in this._matrices)this._effect.setMatrix(n,this._matrices[n]);if(this._texture){if(this.isCube)for(var s=0;s<6;s++)r.bindFramebuffer(this._texture,s,void 0,void 0,!0),r.bindBuffers(this._vertexBuffers,this._indexBuffer,this._effect),this._effect.setFloat("face",s),r.clear(i.clearColor,!0,!0,!0),r.drawElementsType(e.Material.TriangleFillMode,0,6),5===s&&r.generateMipMapsForCubemap(this._texture);else r.bindFramebuffer(this._texture,0,void 0,void 0,!0),r.bindBuffers(this._vertexBuffers,this._indexBuffer,this._effect),r.clear(i.clearColor,!0,!0,!0),r.drawElementsType(e.Material.TriangleFillMode,0,6);r.unBindFramebuffer(this._texture,this.isCube),this.onGenerated&&this.onGenerated()}}},i.prototype.clone=function(){var e=this.getSize(),t=new i(this.name,e.width,this._fragment,this.getScene(),this._fallbackTexture,this._generateMipMaps);return t.hasAlpha=this.hasAlpha,t.level=this.level,t.coordinatesMode=this.coordinatesMode,t},i.prototype.dispose=function(){var i=this.getScene();if(i){var r=i._proceduralTextures.indexOf(this);r>=0&&i._proceduralTextures.splice(r,1);var n=this._vertexBuffers[e.VertexBuffer.PositionKind];n&&(n.dispose(),this._vertexBuffers[e.VertexBuffer.PositionKind]=null),this._indexBuffer&&this._engine._releaseBuffer(this._indexBuffer)&&(this._indexBuffer=null),t.prototype.dispose.call(this)}},i})(e.Texture);e.ProceduralTexture=t})(e||(e={}));var e;!(function(e){var t=(function(t){function i(e,i,r,n,o,s){var a=t.call(this,e,r,null,n,o,s)||this;return a._animate=!0,a._time=0,a._texturePath=i,a.loadJson(i),a.refreshRate=1,a}return __extends(i,t),i.prototype.loadJson=function(t){var i=this,r=function(){e.Tools.Log("No config file found in "+t+" trying to use ShadersStore or DOM element");try{i.setFragment(i._texturePath)}catch(t){e.Tools.Error("No json or ShaderStore or DOM element found for CustomProceduralTexture")}},n=t+"/config.json",o=new XMLHttpRequest;o.open("GET",n,!0),o.addEventListener("load",(function(){if(200===o.status||e.Tools.ValidateXHRData(o,1))try{i._config=JSON.parse(o.response),i.updateShaderUniforms(),i.updateTextures(),i.setFragment(i._texturePath+"/custom"),i._animate=i._config.animate,i.refreshRate=i._config.refreshrate}catch(e){r()}else r()}),!1),o.addEventListener("error",(function(){r()}),!1);try{o.send()}catch(t){e.Tools.Error("CustomProceduralTexture: Error on XHR send request.")}},i.prototype.isReady=function(){if(!t.prototype.isReady.call(this))return!1;for(var e in this._textures){if(!this._textures[e].isReady())return!1}return!0},i.prototype.render=function(e){var i=this.getScene();this._animate&&i&&(this._time+=.03*i.getAnimationRatio(),this.updateShaderUniforms()),t.prototype.render.call(this,e)},i.prototype.updateTextures=function(){for(var t=0;t.005?0+r:0,i.y=Math.abs(n)>.005?0+n:0;var o=this.gamepad.rightStick;if(o){var s=o.x/this.gamepadAngularSensibility,a=o.y/this.gamepadAngularSensibility;o.x=Math.abs(s)>.001?0+s:0,o.y=Math.abs(a)>.001?0+a:0}else o={x:0,y:0};t.rotationQuaternion?t.rotationQuaternion.toRotationMatrix(this._cameraTransform):e.Matrix.RotationYawPitchRollToRef(t.rotation.y,t.rotation.x,0,this._cameraTransform);var l=50*t._computeLocalCameraSpeed();this._vector3.copyFromFloats(i.x*l,0,-i.y*l),e.Vector3.TransformCoordinatesToRef(this._vector3,this._cameraTransform,this._deltaTransform),t.cameraDirection.addInPlace(this._deltaTransform),this._vector2.copyFromFloats(o.y,o.x),t.cameraRotation.addInPlace(this._vector2)}},t.prototype.getClassName=function(){return"FreeCameraGamepadInput"},t.prototype.getSimpleName=function(){return"gamepad"},__decorate([e.serialize()],t.prototype,"gamepadAngularSensibility",void 0),__decorate([e.serialize()],t.prototype,"gamepadMoveSensibility",void 0),t})();e.FreeCameraGamepadInput=t,e.CameraInputTypes.FreeCameraGamepadInput=t})(e||(e={}));var e;!(function(e){var t=(function(){function t(){this.gamepadRotationSensibility=80,this.gamepadMoveSensibility=40}return t.prototype.attachControl=function(t,i){var r=this,n=this.camera.getScene().gamepadManager;this._onGamepadConnectedObserver=n.onGamepadConnectedObservable.add((function(t){t.type!==e.Gamepad.POSE_ENABLED&&(r.gamepad&&t.type!==e.Gamepad.XBOX||(r.gamepad=t))})),this._onGamepadDisconnectedObserver=n.onGamepadDisconnectedObservable.add((function(e){r.gamepad===e&&(r.gamepad=null)})),this.gamepad=n.getGamepadByType(e.Gamepad.XBOX)},t.prototype.detachControl=function(e){this.camera.getScene().gamepadManager.onGamepadConnectedObservable.remove(this._onGamepadConnectedObserver),this.camera.getScene().gamepadManager.onGamepadDisconnectedObservable.remove(this._onGamepadDisconnectedObserver),this.gamepad=null},t.prototype.checkInputs=function(){if(this.gamepad){var e=this.camera,t=this.gamepad.rightStick;if(t){if(0!=t.x){var i=t.x/this.gamepadRotationSensibility;0!=i&&Math.abs(i)>.005&&(e.inertialAlphaOffset+=i)}if(0!=t.y){var r=t.y/this.gamepadRotationSensibility;0!=r&&Math.abs(r)>.005&&(e.inertialBetaOffset+=r)}}var n=this.gamepad.leftStick;if(n&&0!=n.y){var o=n.y/this.gamepadMoveSensibility;0!=o&&Math.abs(o)>.005&&(this.camera.inertialRadiusOffset-=o)}}},t.prototype.getClassName=function(){return"ArcRotateCameraGamepadInput"},t.prototype.getSimpleName=function(){return"gamepad"},__decorate([e.serialize()],t.prototype,"gamepadRotationSensibility",void 0),__decorate([e.serialize()],t.prototype,"gamepadMoveSensibility",void 0),t})();e.ArcRotateCameraGamepadInput=t,e.CameraInputTypes.ArcRotateCameraGamepadInput=t})(e||(e={}));var e;!(function(e){var t=(function(){function t(t){var i=this;this._scene=t,this._babylonGamepads=[],this._oneGamepadConnected=!1,this._isMonitoring=!1,this.onGamepadDisconnectedObservable=new e.Observable,e.Tools.IsWindowObjectExist()?(this._gamepadEventSupported="GamepadEvent"in window,this._gamepadSupport=navigator.getGamepads||navigator.webkitGetGamepads||navigator.msGetGamepads||navigator.webkitGamepads):this._gamepadEventSupported=!1,this.onGamepadConnectedObservable=new e.Observable(function(e){for(var t in i._babylonGamepads){var r=i._babylonGamepads[t] ;r&&r._isConnected&&i.onGamepadConnectedObservable.notifyObserver(e,r)}}),this._onGamepadConnectedEvent=function(e){var t=e.gamepad;if(!(t.index in i._babylonGamepads&&i._babylonGamepads[t.index].isConnected)){var r;i._babylonGamepads[t.index]?(r=i._babylonGamepads[t.index],r.browserGamepad=t,r._isConnected=!0):r=i._addNewGamepad(t),i.onGamepadConnectedObservable.notifyObservers(r),i._startMonitoringGamepads()}},this._onGamepadDisconnectedEvent=function(e){var t=e.gamepad;for(var r in i._babylonGamepads)if(i._babylonGamepads[r].index===t.index){var n=i._babylonGamepads[r];n._isConnected=!1,i.onGamepadDisconnectedObservable.notifyObservers(n);break}},this._gamepadSupport&&(this._updateGamepadObjects(),this._babylonGamepads.length&&this._startMonitoringGamepads(),this._gamepadEventSupported?(window.addEventListener("gamepadconnected",this._onGamepadConnectedEvent,!1),window.addEventListener("gamepaddisconnected",this._onGamepadDisconnectedEvent,!1)):this._startMonitoringGamepads())}return Object.defineProperty(t.prototype,"gamepads",{get:function(){return this._babylonGamepads},enumerable:!0,configurable:!0}),t.prototype.getGamepadByType=function(t){void 0===t&&(t=e.Gamepad.XBOX);for(var i=0,r=this._babylonGamepads;i=2&&(this._leftStick={x:this.browserGamepad.axes[this._leftStickAxisX],y:this.browserGamepad.axes[this._leftStickAxisY]}),this.browserGamepad.axes.length>=4&&(this._rightStick={x:this.browserGamepad.axes[this._rightStickAxisX],y:this.browserGamepad.axes[this._rightStickAxisY]})}return Object.defineProperty(e.prototype,"isConnected",{get:function(){return this._isConnected},enumerable:!0,configurable:!0}),e.prototype.onleftstickchanged=function(e){this._onleftstickchanged=e},e.prototype.onrightstickchanged=function(e){this._onrightstickchanged=e},Object.defineProperty(e.prototype,"leftStick",{get:function(){return this._leftStick},set:function(e){!this._onleftstickchanged||this._leftStick.x===e.x&&this._leftStick.y===e.y||this._onleftstickchanged(e),this._leftStick=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rightStick",{get:function(){return this._rightStick},set:function(e){!this._onrightstickchanged||this._rightStick.x===e.x&&this._rightStick.y===e.y||this._onrightstickchanged(e),this._rightStick=e},enumerable:!0,configurable:!0}),e.prototype.update=function(){this._leftStick&&(this.leftStick={x:this.browserGamepad.axes[this._leftStickAxisX],y:this.browserGamepad.axes[this._leftStickAxisY]},this._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 __extends(r,t),r.prototype.onbuttondown=function(e){this._onbuttondown=e},r.prototype.onbuttonup=function(e){this._onbuttonup=e},r.prototype._setButtonValue=function(e,t,i){return e!==t&&(1===e&&(this._onbuttondown&&this._onbuttondown(i),this.onButtonDownObservable.notifyObservers(i)),0===e&&(this._onbuttonup&&this._onbuttonup(i),this.onButtonUpObservable.notifyObservers(i))),e},r.prototype.update=function(){t.prototype.update.call(this);for(var e=0;ethis.maxCameraSpeed||u<-this.maxCameraSpeed)&&(u=u<1?-this.maxCameraSpeed:this.maxCameraSpeed),(f>this.maxCameraSpeed||f<-this.maxCameraSpeed)&&(f=f<1?-this.maxCameraSpeed:this.maxCameraSpeed),(d>this.maxCameraSpeed||d<-this.maxCameraSpeed)&&(d=d<1?-this.maxCameraSpeed:this.maxCameraSpeed),this.position=new e.Vector3(this.position.x+u,this.position.y+f,this.position.z+d),this.setTarget(o)}},i.prototype._checkInputs=function(){t.prototype._checkInputs.call(this),this.lockedTarget&&this.follow(this.lockedTarget)},i.prototype.getClassName=function(){return"FollowCamera"},__decorate([e.serialize()],i.prototype,"radius",void 0),__decorate([e.serialize()],i.prototype,"rotationOffset",void 0),__decorate([e.serialize()],i.prototype,"heightOffset",void 0),__decorate([e.serialize()],i.prototype,"cameraAcceleration",void 0),__decorate([e.serialize()],i.prototype,"maxCameraSpeed",void 0),__decorate([e.serializeAsMeshReference("lockedTargetId")],i.prototype,"lockedTarget",void 0),i})(e.TargetCamera);e.FollowCamera=t;var i=(function(t){function i(i,r,n,o,s,a){var l=t.call(this,i,e.Vector3.Zero(),a)||this;return l.alpha=r,l.beta=n,l.radius=o,l.target=s,l._cartesianCoordinates=e.Vector3.Zero(),l.follow(),l}return __extends(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})(e||(e={}));var e;!(function(e){var t=(function(e){function t(t,i,r){var n=e.call(this,t,i,r)||this;return n.inputs.addGamepad(),n}return __extends(t,e),Object.defineProperty(t.prototype,"gamepadAngularSensibility",{get:function(){var e=this.inputs.attached.gamepad;return e?e.gamepadAngularSensibility:0},set:function(e){var t=this.inputs.attached.gamepad;t&&(t.gamepadAngularSensibility=e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"gamepadMoveSensibility",{get:function(){var e=this.inputs.attached.gamepad;return e?e.gamepadMoveSensibility:0},set:function(e){var t=this.inputs.attached.gamepad;t&&(t.gamepadMoveSensibility=e)},enumerable:!0,configurable:!0}),t.prototype.getClassName=function(){return"UniversalCamera"},t})(e.TouchCamera);e.UniversalCamera=t})(e||(e={}));var e;!(function(e){var t=(function(e){function t(t,i,r){return e.call(this,t,i,r)||this}return __extends(t,e),Object.defineProperty(t.prototype,"gamepadAngularSensibility",{get:function(){var e=this.inputs.attached.gamepad;return e?e.gamepadAngularSensibility:0},set:function(e){var t=this.inputs.attached.gamepad;t&&(t.gamepadAngularSensibility=e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"gamepadMoveSensibility",{get:function(){var e=this.inputs.attached.gamepad;return e?e.gamepadMoveSensibility:0},set:function(e){var t=this.inputs.attached.gamepad;t&&(t.gamepadMoveSensibility=e)},enumerable:!0,configurable:!0}),t.prototype.getClassName=function(){return"GamepadCamera"},t})(e.UniversalCamera);e.GamepadCamera=t})(e||(e={}));var e;!(function(e){var t=(function(){function e(){this._renderPipelines={}}return e.prototype.addPipeline=function(e){this._renderPipelines[e._name]=e},e.prototype.attachCamerasToRenderPipeline=function(e,t,i){void 0===i&&(i=!1);var r=this._renderPipelines[e];r&&r._attachCameras(t,i)},e.prototype.detachCamerasFromRenderPipeline=function(e,t){var i=this._renderPipelines[e];i&&i._detachCameras(t)},e.prototype.enableEffectInPipeline=function(e,t,i){var r=this._renderPipelines[e];r&&r._enableEffect(t,i)},e.prototype.disableEffectInPipeline=function(e,t,i){var r=this._renderPipelines[e];r&&r._disableEffect(t,i)},e.prototype.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)){var t=this._renderPipelines[e];t._rebuild()}},e.prototype.dispose=function(){for(var e in this._renderPipelines)if(this._renderPipelines.hasOwnProperty(e)){var t=this._renderPipelines[e];t.dispose()}},e})();e.PostProcessRenderPipelineManager=t})(e||(e={}));var e;!(function(e){var t=(function(){function t(e,t,i,r){this._name=t,this._singleInstance=r||!0,this._getPostProcesses=i,this._cameras={},this._indicesForCamera={},this._postProcesses={}}return Object.defineProperty(t.prototype,"isSupported",{get:function(){for(var e in this._postProcesses)for(var t in this._postProcesses[e])if(!this._postProcesses[e][t].isSupported)return!1;return!0},enumerable:!0,configurable:!0}),t.prototype._update=function(){},t.prototype._attachCameras=function(t){var i,r=this,n=e.Tools.MakeArray(t||this._cameras);if(n)for(var o=0;o=2&&e.length>0){var t=this._renderEffects[e[0]].getPostProcesses();if(t)return t[0].samples=4,!0}return!1},t.prototype.dispose=function(){},__decorate([e.serialize()],t.prototype,"_name",void 0),t})();e.PostProcessRenderPipeline=t})(e||(e={}));var e;!(function(e){var t=(function(){function t(t,i,r){void 0===i&&(i=e.Engine.TEXTURETYPE_FLOAT),void 0===r&&(r=null);var n=this;this._scene=t,this._camera=r;var o=t.getEngine();this._depthMap=new e.RenderTargetTexture("depthMap",{width:o.getRenderWidth(),height:o.getRenderHeight()},this._scene,!1,!0,i),this._depthMap.wrapU=e.Texture.CLAMP_ADDRESSMODE,this._depthMap.wrapV=e.Texture.CLAMP_ADDRESSMODE,this._depthMap.refreshRate=1,this._depthMap.renderParticles=!1,this._depthMap.renderList=null,this._depthMap.activeCamera=this._camera,this._depthMap.ignoreCameraViewport=!0,this._depthMap.useCameraPostProcesses=!1,this._depthMap.onClearObservable.add((function(t){t.clear(new e.Color4(1,1,1,1),!0,!0,!0)}));var s=function(t){var i=t.getRenderingMesh(),r=n._scene,o=r.getEngine(),s=t.getMaterial();if(s){o.setState(s.backFaceCulling,0,!1,r.useRightHandedSystem);var a=i._getInstancesRenderList(t._id);if(!a.mustReturn){var l=o.getCaps().instancedArrays&&null!==a.visibleInstances[t._id],c=n._camera||r.activeCamera;if(n.isReady(t,l)&&c){if(o.enableEffect(n._effect),i._bind(t,n._effect,e.Material.TriangleFillMode),n._effect.setMatrix("viewProjection",r.getTransformMatrix()),n._effect.setFloat2("depthValues",c.minZ,c.minZ+c.maxZ),s&&s.needAlphaTesting()){var h=s.getAlphaTestTexture();h&&(n._effect.setTexture("diffuseSampler",h),n._effect.setMatrix("diffuseMatrix",h.getTextureMatrix()))}i.useBones&&i.computeBonesUsingShaders&&i.skeleton&&n._effect.setMatrices("mBones",i.skeleton.getTransformMatrices(i)),i._processRendering(t,n._effect,e.Material.TriangleFillMode,a,l,(function(e,t){return n._effect.setMatrix("world",t)}))}}}};this._depthMap.customRenderFunction=function(e,t,i,r){var n;if(r.length){for(o.setColorWrite(!1),n=0;n4&&(o.push(e.VertexBuffer.MatricesIndicesExtraKind),o.push(e.VertexBuffer.MatricesWeightsExtraKind)),n.push("#define NUM_BONE_INFLUENCERS "+s.numBoneInfluencers),n.push("#define BonesPerMesh "+(s.skeleton?s.skeleton.bones.length+1:0))):n.push("#define NUM_BONE_INFLUENCERS 0"),i&&(n.push("#define INSTANCES"),o.push("world0"),o.push("world1"),o.push("world2"),o.push("world3"));var a=n.join("\n");return this._cachedDefines!==a&&(this._cachedDefines=a,this._effect=this._scene.getEngine().createEffect("depth",o,["world","mBones","viewProjection","diffuseMatrix","depthValues"],["diffuseSampler"],a)),this._effect.isReady()},t.prototype.getDepthMap=function(){return this._depthMap},t.prototype.dispose=function(){this._depthMap.dispose()},t})();e.DepthRenderer=t})(e||(e={}));var e;!(function(e){var t=(function(t){function i(i,r,n,o){var s=t.call(this,r.getEngine(),i)||this;s.SSAOOriginalSceneColorEffect="SSAOOriginalSceneColorEffect",s.SSAORenderEffect="SSAORenderEffect",s.SSAOBlurHRenderEffect="SSAOBlurHRenderEffect",s.SSAOBlurVRenderEffect="SSAOBlurVRenderEffect",s.SSAOCombineRenderEffect="SSAOCombineRenderEffect",s.totalStrength=1,s.radius=1e-4,s.area=.0075,s.fallOff=1e-6,s.base=.5,s._firstUpdate=!0,s._scene=r,s._createRandomTexture(),s._depthTexture=r.enableDepthRenderer().getDepthMap();var a=n.ssaoRatio||n,l=n.combineRatio||n;return s._originalColorPostProcess=new e.PassPostProcess("SSAOOriginalSceneColor",l,null,e.Texture.BILINEAR_SAMPLINGMODE,r.getEngine(),!1),s._createSSAOPostProcess(a),s._createBlurPostProcess(a),s._createSSAOCombinePostProcess(l),s.addEffect(new e.PostProcessRenderEffect(r.getEngine(),s.SSAOOriginalSceneColorEffect,function(){return s._originalColorPostProcess},!0)),s.addEffect(new e.PostProcessRenderEffect(r.getEngine(),s.SSAORenderEffect,function(){return s._ssaoPostProcess},!0)),s.addEffect(new e.PostProcessRenderEffect(r.getEngine(),s.SSAOBlurHRenderEffect,function(){return s._blurHPostProcess},!0)),s.addEffect(new e.PostProcessRenderEffect(r.getEngine(),s.SSAOBlurVRenderEffect,function(){return s._blurVPostProcess},!0)),s.addEffect(new e.PostProcessRenderEffect(r.getEngine(),s.SSAOCombineRenderEffect,function(){return s._ssaoCombinePostProcess},!0)),r.postProcessRenderPipelineManager.addPipeline(s),o&&r.postProcessRenderPipelineManager.attachCamerasToRenderPipeline(i,o),s}return __extends(i,t),i.prototype.dispose=function(e){void 0===e&&(e=!1);for(var i=0;i0?r._ssaoCombinePostProcess.width:r._originalColorPostProcess.width),e.setFloat("near",r._scene.activeCamera.minZ),e.setFloat("far",r._scene.activeCamera.maxZ),e.setFloat("radius",r.radius),e.setTexture("depthSampler",r._depthTexture),r._firstUpdate&&e.setArray("samplerOffsets",r._samplerOffsets))},this._blurVPostProcess=new e.PostProcess("BlurV","ssao2",["outSize","samplerOffsets","near","far","radius"],["depthSampler"],i,null,e.Texture.TRILINEAR_SAMPLINGMODE,this._scene.getEngine(),!1,"#define BILATERAL_BLUR\n#define BILATERAL_BLUR_V\n#define SAMPLES 16\n#define EXPENSIVE "+(n?"1":"0")+"\n"),this._blurVPostProcess.onApply=function(e){r._scene.activeCamera&&(e.setFloat("outSize",r._ssaoCombinePostProcess.height>0?r._ssaoCombinePostProcess.height:r._originalColorPostProcess.height),e.setFloat("near",r._scene.activeCamera.minZ),e.setFloat("far",r._scene.activeCamera.maxZ),e.setFloat("radius",r.radius),e.setTexture("depthSampler",r._depthTexture),r._firstUpdate&&(e.setArray("samplerOffsets",r._samplerOffsets),r._firstUpdate=!1))}},i.prototype._rebuild=function(){this._firstUpdate=!0,t.prototype._rebuild.call(this)},i.prototype._generateHemisphere=function(){for(var t,i,r=this.samples,n=[],o=function(e,t){return Math.random()*(t-e)+e},s=0;s=0;a--){var o=Math.pow(3,a),l="#define LUMINANCE_DOWN_SAMPLE\n";0===a&&(l+="#define FINAL_DOWN_SAMPLER");var c=new e.PostProcess("HDRLuminanceDownSample"+a,"standard",["dsOffsets","halfDestPixelSize"],[],{width:o,height:o},null,e.Texture.BILINEAR_SAMPLINGMODE,t.getEngine(),!1,l,r);this.luminanceDownSamplePostProcesses.push(c)}var h=this.luminancePostProcess;this.luminanceDownSamplePostProcesses.forEach((function(i,r){var o=new Array(18);i.onApply=function(e){if(h){for(var t=0,s=-1;s<2;s++)for(var a=-1;a<2;a++)o[t]=s/h.width,o[t+1]=a/h.height,t+=2;e.setArray2("dsOffsets",o),e.setFloat("halfDestPixelSize",.5/h.width),h=r===n.luminanceDownSamplePostProcesses.length-1?n.luminancePostProcess:i}},r===n.luminanceDownSamplePostProcesses.length-1&&(i.onAfterRender=function(i){var r=t.getEngine().readPixels(0,0,1,1),o=new e.Vector4(1/16581375,1/65025,1/255,1);n._hdrCurrentLuminance=(r[0]*o.x+r[1]*o.y+r[2]*o.z+r[3]*o.w)/100}),n.addEffect(new e.PostProcessRenderEffect(t.getEngine(),"HDRLuminanceDownSample"+r,function(){return i},!0))}))},i.prototype._createHdrPostProcess=function(t,i){var r=this;this.hdrPostProcess=new e.PostProcess("HDR","standard",["averageLuminance"],["textureAdderSampler"],i,null,e.Texture.BILINEAR_SAMPLINGMODE,t.getEngine(),!1,"#define HDR",e.Engine.TEXTURETYPE_UNSIGNED_INT);var n=1,o=0,s=0;this.hdrPostProcess.onApply=function(i){if(i.setTextureFromPostProcess("textureAdderSampler",r._currentDepthOfFieldSource),o+=t.getEngine().getDeltaTime(),n<0)n=r._hdrCurrentLuminance;else{var a=(s-o)/1e3;r._hdrCurrentLuminancen-r.hdrIncreaseRate*a?n-=r.hdrIncreaseRate*a:n=r._hdrCurrentLuminance}n=e.Scalar.Clamp(n,r.hdrMinimumLuminance,1e20),i.setFloat("averageLuminance",n),s=o,r._currentDepthOfFieldSource=r.hdrFinalPostProcess},this.addEffect(new e.PostProcessRenderEffect(t.getEngine(),"HDR",function(){return r.hdrPostProcess},!0))},i.prototype._createLensFlarePostProcess=function(t,i){var r=this;this.lensFlarePostProcess=new e.PostProcess("HDRLensFlare","standard",["strength","ghostDispersal","haloWidth","resolution","distortionStrength"],["lensColorSampler"],i/2,null,e.Texture.BILINEAR_SAMPLINGMODE,t.getEngine(),!1,"#define LENS_FLARE",e.Engine.TEXTURETYPE_UNSIGNED_INT),this.addEffect(new e.PostProcessRenderEffect(t.getEngine(),"HDRLensFlare",function(){return r.lensFlarePostProcess},!0)),this._createBlurPostProcesses(t,i/4,2),this.lensFlareComposePostProcess=new e.PostProcess("HDRLensFlareCompose","standard",["lensStarMatrix"],["otherSampler","lensDirtSampler","lensStarSampler"],i,null,e.Texture.BILINEAR_SAMPLINGMODE,t.getEngine(),!1,"#define LENS_FLARE_COMPOSE",e.Engine.TEXTURETYPE_UNSIGNED_INT),this.addEffect(new e.PostProcessRenderEffect(t.getEngine(),"HDRLensFlareCompose",function(){return r.lensFlareComposePostProcess},!0));var n=new e.Vector2(0,0);this.lensFlarePostProcess.onApply=function(e){e.setTextureFromPostProcess("textureSampler",r._bloomEnabled?r.blurHPostProcesses[0]:r.originalPostProcess),e.setTexture("lensColorSampler",r.lensColorTexture),e.setFloat("strength",r.lensFlareStrength),e.setFloat("ghostDispersal",r.lensFlareGhostDispersal),e.setFloat("haloWidth",r.lensFlareHaloWidth),n.x=r.lensFlarePostProcess.width,n.y=r.lensFlarePostProcess.height,e.setVector2("resolution",n),e.setFloat("distortionStrength",r.lensFlareDistortionStrength)};var o=e.Matrix.FromValues(2,0,-1,0,0,2,-1,0,0,0,1,0,0,0,0,1),s=e.Matrix.FromValues(.5,0,.5,0,0,.5,.5,0,0,0,1,0,0,0,0,1);this.lensFlareComposePostProcess.onApply=function(t){if(r._scene.activeCamera){t.setTextureFromPostProcess("otherSampler",r._currentDepthOfFieldSource),t.setTexture("lensDirtSampler",r.lensFlareDirtTexture),t.setTexture("lensStarSampler",r.lensStarTexture);var i=r._scene.activeCamera.getViewMatrix().getRow(0),n=r._scene.activeCamera.getViewMatrix().getRow(2),a=e.Vector3.Dot(i.toVector3(),new e.Vector3(1,0,0))+e.Vector3.Dot(n.toVector3(),new e.Vector3(0,0,1));a*=4;var l=e.Matrix.FromValues(.5*Math.cos(a),-Math.sin(a),0,0,Math.sin(a),.5*Math.cos(a),0,0,0,0,1,0,0,0,0,1),c=s.multiply(l).multiply(o);t.setMatrix("lensStarMatrix",c),r._currentDepthOfFieldSource=r.lensFlareFinalPostProcess}}},i.prototype._createDepthOfFieldPostProcess=function(t,i){var r=this;this.depthOfFieldPostProcess=new e.PostProcess("HDRDepthOfField","standard",["distance"],["otherSampler","depthSampler"],i,null,e.Texture.BILINEAR_SAMPLINGMODE,t.getEngine(),!1,"#define DEPTH_OF_FIELD",e.Engine.TEXTURETYPE_UNSIGNED_INT),this.depthOfFieldPostProcess.onApply=function(e){e.setTextureFromPostProcess("otherSampler",r._currentDepthOfFieldSource),e.setTexture("depthSampler",r._getDepthTexture()),e.setFloat("distance",r.depthOfFieldDistance)},this.addEffect(new e.PostProcessRenderEffect(t.getEngine(),"HDRDepthOfField",function(){return r.depthOfFieldPostProcess},!0))},i.prototype._createMotionBlurPostProcess=function(t,i){var r=this;this.motionBlurPostProcess=new e.PostProcess("HDRMotionBlur","standard",["inverseViewProjection","prevViewProjection","screenSize","motionScale","motionStrength"],["depthSampler"],i,null,e.Texture.BILINEAR_SAMPLINGMODE,t.getEngine(),!1,"#define MOTION_BLUR\n#define MAX_MOTION_SAMPLES "+this.motionBlurSamples.toFixed(1),e.Engine.TEXTURETYPE_UNSIGNED_INT);var n=0,o=e.Matrix.Identity(),s=e.Matrix.Identity(),a=e.Matrix.Identity(),l=e.Vector2.Zero();this.motionBlurPostProcess.onApply=function(e){a=t.getProjectionMatrix().multiply(t.getViewMatrix()),a.invertToRef(s),e.setMatrix("inverseViewProjection",s),e.setMatrix("prevViewProjection",o),o=a,l.x=r.motionBlurPostProcess.width,l.y=r.motionBlurPostProcess.height,e.setVector2("screenSize",l),n=t.getEngine().getFps()/60,e.setFloat("motionScale",n),e.setFloat("motionStrength",r.motionStrength),e.setTexture("depthSampler",r._getDepthTexture())},this.addEffect(new e.PostProcessRenderEffect(t.getEngine(),"HDRMotionBlur",function(){return r.motionBlurPostProcess},!0))},i.prototype._getDepthTexture=function(){if(this._scene.getEngine().getCaps().drawBuffersExtension){return this._scene.enableGeometryBufferRenderer().getGBuffer().textures[0]}return this._scene.enableDepthRenderer().getDepthMap()},i.prototype._disposePostProcesses=function(){for(var e=0;e0)return Math.max(n,3)}return Math.max(t,3)},i.prototype._gaussianWeight=function(e){var t=Math.sqrt(2*Math.PI)*(1/3),i=-e*e/(1/3*2*(1/3));return 1/t*Math.exp(i)},i.prototype._glslFloat=function(e,t){return void 0===t&&(t=8),e.toFixed(t).replace(/0+$/,"")},i})(e.PostProcess);e.BlurPostProcess=t})(e||(e={}));var e;!(function(e){var t=(function(t){function i(i,r,n,o,s,a,l,c,h,u,f,d){void 0===c&&(c=null),void 0===h&&(h=e.Texture.BILINEAR_SAMPLINGMODE),void 0===d&&(d=e.Engine.TEXTURETYPE_UNSIGNED_INT);var p=t.call(this,i,n,o,s,a,h=e.Texture.BILINEAR_SAMPLINGMODE,u,f,d=e.Engine.TEXTURETYPE_UNSIGNED_INT,"#define DOF 1\r\n")||this;return p.direction=n,p.onApplyObservable.add((function(e){null!=c&&e.setTextureFromPostProcess("textureSampler",c),e.setTextureFromPostProcess("circleOfConfusionSampler",l),r.activeCamera&&e.setFloat2("cameraMinMaxZ",r.activeCamera.minZ,r.activeCamera.maxZ)})),p}return __extends(i,t),i})(e.BlurPostProcess);e.DepthOfFieldBlurPostProcess=t})(e||(e={}));var e;!(function(e){var t=(function(t){function i(i,r,n,o,s,a,l,c,h,u){void 0===u&&(u=e.Engine.TEXTURETYPE_UNSIGNED_INT);var f=t.call(this,i,"depthOfFieldMerge",[],["circleOfConfusionSampler","originalSampler","blurStep1","blurStep2"],s,a,l,c,h,"#define BLUR_LEVEL "+o.length+"\n",u)||this;return f.onApplyObservable.add((function(e){e.setTextureFromPostProcess("circleOfConfusionSampler",n),e.setTextureFromPostProcess("originalSampler",r),o.forEach((function(t,i){e.setTextureFromPostProcess("blurStep"+(i+1),t)}))})),f}return __extends(i,t),i})(e.PostProcess);e.DepthOfFieldMergePostProcess=t})(e||(e={}));var e;!(function(e){var t=(function(t){function i(i,r,n,o,s,a,l,c){void 0===c&&(c=e.Engine.TEXTURETYPE_UNSIGNED_INT);var h=t.call(this,i,"circleOfConfusion",["cameraMinMaxZ","focusDistance","cocPrecalculation"],["depthSampler"],n,o,s,a,l,null,c)||this;return h.lensSize=50,h.fStop=1.4,h.focusDistance=2e3,h.focalLength=50,h._depthTexture=null,h._depthTexture=r,h.onApplyObservable.add((function(t){if(!h._depthTexture)return void e.Tools.Warn("No depth texture set on CircleOfConfusionPostProcess");t.setTexture("depthSampler",h._depthTexture);var i=h.lensSize/h.fStop,r=i*h.focalLength/(h.focusDistance-h.focalLength);t.setFloat("focusDistance",h.focusDistance),t.setFloat("cocPrecalculation",r),t.setFloat2("cameraMinMaxZ",h._depthTexture.activeCamera.minZ,h._depthTexture.activeCamera.maxZ)})),h}return __extends(i,t),Object.defineProperty(i.prototype,"depthTexture",{set:function(e){this._depthTexture=e},enumerable:!0,configurable:!0}),i})(e.PostProcess);e.CircleOfConfusionPostProcess=t})(e||(e={}));var e;!(function(e){var t;!(function(e){e[e.Low=0]="Low",e[e.Medium=1]="Medium",e[e.High=2]="High" })(t=e.DepthOfFieldEffectBlurLevel||(e.DepthOfFieldEffectBlurLevel={}));var i=(function(i){function r(r,n,o,s){void 0===o&&(o=t.Low),void 0===s&&(s=0);var a=i.call(this,r.getEngine(),"depth of field",(function(){return a._effects}),!0)||this;a._effects=[],a._circleOfConfusion=new e.CircleOfConfusionPostProcess("circleOfConfusion",n,1,null,e.Texture.BILINEAR_SAMPLINGMODE,r.getEngine(),!1,s),a._depthOfFieldPass=new e.PassPostProcess("depthOfFieldPass",1,null,e.Texture.BILINEAR_SAMPLINGMODE,r.getEngine(),!1,s),a._depthOfFieldPass.autoClear=!1,a._depthOfFieldBlurY=[],a._depthOfFieldBlurX=[];var l=1,c=15;switch(o){case t.High:l=3,c=51;break;case t.Medium:l=2,c=31;break;default:c=15,l=1}for(var h=c/Math.pow(2,l-1),u=0;u= 2.0"))}},i.prototype._disposePostProcesses=function(e){void 0===e&&(e=!1);for(var t=0;t4&&(o.push(e.VertexBuffer.MatricesIndicesExtraKind),o.push(e.VertexBuffer.MatricesWeightsExtraKind)),n.push("#define NUM_BONE_INFLUENCERS "+s.numBoneInfluencers),n.push("#define BonesPerMesh "+(s.skeleton?s.skeleton.bones.length+1:0))):n.push("#define NUM_BONE_INFLUENCERS 0"),i&&(n.push("#define INSTANCES"),o.push("world0"),o.push("world1"),o.push("world2"),o.push("world3"));var a=n.join("\n");return this._cachedDefines!==a&&(this._cachedDefines=a,this._effect=this._scene.getEngine().createEffect("geometry",o,["world","mBones","viewProjection","diffuseMatrix","view"],["diffuseSampler"],a,void 0,void 0,void 0,{buffersCount:this._enablePosition?3:2})),this._effect.isReady()},t.prototype.getGBuffer=function(){return this._multiRenderTarget},Object.defineProperty(t.prototype,"samples",{get:function(){return this._multiRenderTarget.samples},set:function(e){this._multiRenderTarget.samples=e},enumerable:!0,configurable:!0}),t.prototype.dispose=function(){this.getGBuffer().dispose()},t.prototype._createRenderTargets=function(){var t=this,i=this._scene.getEngine(),r=this._enablePosition?3:2;if(this._multiRenderTarget=new e.MultiRenderTarget("gBuffer",{width:i.getRenderWidth()*this._ratio,height:i.getRenderHeight()*this._ratio},r,this._scene,{generateMipMaps:!1,generateDepthTexture:!0,defaultType:e.Engine.TEXTURETYPE_FLOAT}),this.isSupported){this._multiRenderTarget.wrapU=e.Texture.CLAMP_ADDRESSMODE,this._multiRenderTarget.wrapV=e.Texture.CLAMP_ADDRESSMODE,this._multiRenderTarget.refreshRate=1,this._multiRenderTarget.renderParticles=!1,this._multiRenderTarget.renderList=null,this._multiRenderTarget.onClearObservable.add((function(t){t.clear(new e.Color4(0,0,0,1),!0,!0,!0)}));var n=function(i){var r=i.getRenderingMesh(),n=t._scene,o=n.getEngine(),s=i.getMaterial();if(s){o.setState(s.backFaceCulling,0,!1,n.useRightHandedSystem);var a=r._getInstancesRenderList(i._id);if(!a.mustReturn){var l=o.getCaps().instancedArrays&&null!==a.visibleInstances[i._id];if(t.isReady(i,l)){if(o.enableEffect(t._effect),r._bind(i,t._effect,e.Material.TriangleFillMode),t._effect.setMatrix("viewProjection",n.getTransformMatrix()),t._effect.setMatrix("view",n.getViewMatrix()),s&&s.needAlphaTesting()){var c=s.getAlphaTestTexture();c&&(t._effect.setTexture("diffuseSampler",c),t._effect.setMatrix("diffuseMatrix",c.getTextureMatrix()))}r.useBones&&r.computeBonesUsingShaders&&r.skeleton&&t._effect.setMatrices("mBones",r.skeleton.getTransformMatrices(r)),r._processRendering(i,t._effect,e.Material.TriangleFillMode,a,l,(function(e,i){return t._effect.setMatrix("world",i)}))}}}};this._multiRenderTarget.customRenderFunction=function(e,t,r,o){var s;if(o.length){for(i.setColorWrite(!1),s=0;s0&&-1!==this.excludedMeshes.indexOf(e)},i.prototype._createPass=function(t,i){var r=this,n=t.getEngine();this._volumetricLightScatteringRTT=new e.RenderTargetTexture("volumetricLightScatteringMap",{width:n.getRenderWidth()*i,height:n.getRenderHeight()*i},t,!1,!0,e.Engine.TEXTURETYPE_UNSIGNED_INT),this._volumetricLightScatteringRTT.wrapU=e.Texture.CLAMP_ADDRESSMODE,this._volumetricLightScatteringRTT.wrapV=e.Texture.CLAMP_ADDRESSMODE,this._volumetricLightScatteringRTT.renderList=null,this._volumetricLightScatteringRTT.renderParticles=!1,this._volumetricLightScatteringRTT.ignoreCameraViewport=!0;var o=this.getCamera();o?o.customRenderTargets.push(this._volumetricLightScatteringRTT):t.customRenderTargets.push(this._volumetricLightScatteringRTT);var s,a=function(t){var i=t.getRenderingMesh();if(!r._meshExcluded(i)){var n=t.getMaterial();if(n){var o=i.getScene(),s=o.getEngine();s.setState(n.backFaceCulling);var a=i._getInstancesRenderList(t._id);if(!a.mustReturn){var l=s.getCaps().instancedArrays&&null!==a.visibleInstances[t._id];if(r._isReady(t,l)){var c=r._volumetricLightScatteringPass;if(i===r.mesh&&(c=t.effect?t.effect:n.getEffect()),s.enableEffect(c),i._bind(t,c,e.Material.TriangleFillMode),i===r.mesh)n.bind(i.getWorldMatrix(),i);else{if(r._volumetricLightScatteringPass.setMatrix("viewProjection",o.getTransformMatrix()),n&&n.needAlphaTesting()){var h=n.getAlphaTestTexture();r._volumetricLightScatteringPass.setTexture("diffuseSampler",h),h&&r._volumetricLightScatteringPass.setMatrix("diffuseMatrix",h.getTextureMatrix())}i.useBones&&i.computeBonesUsingShaders&&i.skeleton&&r._volumetricLightScatteringPass.setMatrices("mBones",i.skeleton.getTransformMatrices(i))}i._processRendering(t,r._volumetricLightScatteringPass,e.Material.TriangleFillMode,a,l,(function(e,t){return c.setMatrix("world",t)}))}}}}},l=new e.Color4(0,0,0,1);this._volumetricLightScatteringRTT.onBeforeRenderObservable.add((function(){s=t.clearColor,t.clearColor=l})),this._volumetricLightScatteringRTT.onAfterRenderObservable.add((function(){t.clearColor=s})),this._volumetricLightScatteringRTT.customRenderFunction=function(i,r,n,o){var s,l=t.getEngine();if(o.length){for(l.setColorWrite(!1),s=0;st._alphaIndex?1:e._alphaIndext._distanceToCamera?-1:0})),l.setAlphaMode(e.Engine.ALPHA_COMBINE),s=0;s=h&&a.frame<=u&&(n?(c=a.value.clone(),m?(l=c.getTranslation(),c.setTranslation(l.scaleInPlace(g))):v&&o?(l=c.getTranslation(),c.setTranslation(l.multiplyInPlace(o))):c=a.value):c=a.value,y.push({frame:a.frame+r,value:c}));return this.animations[0].createRange(i,h+r,u+r),!0},i.prototype.translate=function(t,r,n){void 0===r&&(r=e.Space.LOCAL);var o=this.getLocalMatrix();if(r==e.Space.LOCAL)o.m[12]+=t.x,o.m[13]+=t.y,o.m[14]+=t.z;else{var s=null;n&&(s=n.getWorldMatrix()),this._skeleton.computeAbsoluteTransforms();var a=i._tmpMats[0],l=i._tmpVecs[0];this._parent&&(n&&s?(a.copyFrom(this._parent.getAbsoluteTransform()),a.multiplyToRef(s,a)):a.copyFrom(this._parent.getAbsoluteTransform())),a.m[12]=0,a.m[13]=0,a.m[14]=0,a.invert(),e.Vector3.TransformCoordinatesToRef(t,a,l),o.m[12]+=l.x,o.m[13]+=l.y,o.m[14]+=l.z}this.markAsDirty()},i.prototype.setPosition=function(t,r,n){void 0===r&&(r=e.Space.LOCAL);var o=this.getLocalMatrix();if(r==e.Space.LOCAL)o.m[12]=t.x,o.m[13]=t.y,o.m[14]=t.z;else{var s=null;n&&(s=n.getWorldMatrix()),this._skeleton.computeAbsoluteTransforms();var a=i._tmpMats[0],l=i._tmpVecs[0];this._parent&&(n&&s?(a.copyFrom(this._parent.getAbsoluteTransform()),a.multiplyToRef(s,a)):a.copyFrom(this._parent.getAbsoluteTransform())),a.invert(),e.Vector3.TransformCoordinatesToRef(t,a,l),o.m[12]=l.x,o.m[13]=l.y,o.m[14]=l.z}this.markAsDirty()},i.prototype.setAbsolutePosition=function(t,i){this.setPosition(t,e.Space.WORLD,i)},i.prototype.setScale=function(e,t,i,r){void 0===r&&(r=!1),this.animations[0]&&!this.animations[0].hasRunningRuntimeAnimations&&(r||(this._negateScaleChildren.x=1/e,this._negateScaleChildren.y=1/t,this._negateScaleChildren.z=1/i),this._syncScaleVector()),this.scale(e/this._scaleVector.x,t/this._scaleVector.y,i/this._scaleVector.z,r)},i.prototype.scale=function(t,r,n,o){void 0===o&&(o=!1);var s=this.getLocalMatrix(),a=i._tmpMats[0];a.copyFrom(s);var l=i._tmpMats[1];l.copyFrom(a),l.invert();var c=i._tmpMats[2];e.Matrix.FromValuesToRef(t,0,0,0,0,r,0,0,0,0,n,0,0,0,0,1,c),this._scaleMatrix.multiplyToRef(c,this._scaleMatrix),this._scaleVector.x*=t,this._scaleVector.y*=r,this._scaleVector.z*=n,s.multiplyToRef(l,s),s.multiplyToRef(c,s),s.multiplyToRef(a,s);var h=this.getParent();h?s.multiplyToRef(h.getAbsoluteTransform(),this.getAbsoluteTransform()):this.getAbsoluteTransform().copyFrom(s);var u=this.children.length;c.invert();for(var f=0;f0&&(this._rightHandedSystem=!0,this._bendAxis.x=0,this._bendAxis.y=0,this._bendAxis.z=-1,n.x>n.y&&n.x>n.z&&(this._adjustRoll=.5*Math.PI,this._bendAxis.z=1)),this._bone1.length){var o=this._bone1.getScale(),s=this._bone2.getScale();this._bone1Length=this._bone1.length*o.y*this.mesh.scaling.y,this._bone2Length=this._bone2.length*s.y*this.mesh.scaling.y}else if(this._bone1.children[0]){t.computeWorldMatrix(!0);var a=this._bone2.children[0].getAbsolutePosition(t),l=this._bone2.getAbsolutePosition(t),c=this._bone1.getAbsolutePosition(t);this._bone1Length=e.Vector3.Distance(a,l),this._bone2Length=e.Vector3.Distance(l,c)}this._bone1.getRotationMatrixToRef(e.Space.WORLD,t,this._bone1Mat),this.maxAngle=Math.PI,r&&(r.targetMesh&&(this.targetMesh=r.targetMesh,this.targetMesh.computeWorldMatrix(!0)),r.poleTargetMesh?(this.poleTargetMesh=r.poleTargetMesh,this.poleTargetMesh.computeWorldMatrix(!0)):r.poleTargetBone?this.poleTargetBone=r.poleTargetBone:this._bone1.getParent()&&(this.poleTargetBone=this._bone1.getParent()),r.poleTargetLocalOffset&&this.poleTargetLocalOffset.copyFrom(r.poleTargetLocalOffset),r.poleAngle&&(this.poleAngle=r.poleAngle),r.bendAxis&&this._bendAxis.copyFrom(r.bendAxis),r.maxAngle&&(this.maxAngle=r.maxAngle),r.slerpAmount&&(this.slerpAmount=r.slerpAmount))}}return Object.defineProperty(t.prototype,"maxAngle",{get:function(){return this._maxAngle},set:function(e){this._setMaxAngle(e)},enumerable:!0,configurable:!0}),t.prototype._setMaxAngle=function(e){e<0&&(e=0),(e>Math.PI||void 0==e)&&(e=Math.PI),this._maxAngle=e;var t=this._bone1Length,i=this._bone2Length;this._maxReach=Math.sqrt(t*t+i*i-2*t*i*Math.cos(e))},t.prototype.update=function(){var i=this._bone1;if(i){var r=this.targetPosition,n=this.poleTargetPosition,o=t._tmpMats[0],s=t._tmpMats[1];this.targetMesh&&r.copyFrom(this.targetMesh.getAbsolutePosition()),this.poleTargetBone?this.poleTargetBone.getAbsolutePositionFromLocalToRef(this.poleTargetLocalOffset,this.mesh,n):this.poleTargetMesh&&e.Vector3.TransformCoordinatesToRef(this.poleTargetLocalOffset,this.poleTargetMesh.getWorldMatrix(),n);var a=t._tmpVecs[0],l=t._tmpVecs[1],c=t._tmpVecs[2],h=t._tmpVecs[3],u=t._tmpVecs[4],f=t._tmpQuat;i.getAbsolutePositionToRef(this.mesh,a),n.subtractToRef(a,u),0==u.x&&0==u.y&&0==u.z?u.y=1:u.normalize(),r.subtractToRef(a,h),h.normalize(),e.Vector3.CrossToRef(h,u,l),l.normalize(),e.Vector3.CrossToRef(h,l,c),c.normalize(),e.Matrix.FromXYZAxesToRef(c,h,l,o);var d=this._bone1Length,p=this._bone2Length,_=e.Vector3.Distance(a,r);this._maxReach>0&&(_=Math.min(this._maxReach,_));var m=(p*p+_*_-d*d)/(2*p*_),g=(_*_+d*d-p*p)/(2*_*d);m>1&&(m=1),g>1&&(g=1),m<-1&&(m=-1),g<-1&&(g=-1);var v=Math.acos(m),y=Math.acos(g),b=-v-y;if(this._rightHandedSystem)e.Matrix.RotationYawPitchRollToRef(0,0,this._adjustRoll,s),s.multiplyToRef(o,o),e.Matrix.RotationAxisToRef(this._bendAxis,y,s),s.multiplyToRef(o,o);else{var x=t._tmpVecs[5];x.copyFrom(this._bendAxis),x.x*=-1,e.Matrix.RotationAxisToRef(x,-y,s),s.multiplyToRef(o,o)}this.poleAngle&&(e.Matrix.RotationAxisToRef(h,this.poleAngle,s),o.multiplyToRef(s,o)),this._bone1&&(this.slerpAmount<1?(this._slerping||e.Quaternion.FromRotationMatrixToRef(this._bone1Mat,this._bone1Quat),e.Quaternion.FromRotationMatrixToRef(o,f),e.Quaternion.SlerpToRef(this._bone1Quat,f,this.slerpAmount,this._bone1Quat),b=this._bone2Ang*(1-this.slerpAmount)+b*this.slerpAmount,this._bone1.setRotationQuaternion(this._bone1Quat,e.Space.WORLD,this.mesh),this._slerping=!0):(this._bone1.setRotationMatrix(o,e.Space.WORLD,this.mesh),this._bone1Mat.copyFrom(o),this._slerping=!1)),this._bone2.setAxisAngle(this._bendAxis,b,e.Space.LOCAL),this._bone2Ang=b}},t._tmpVecs=[e.Vector3.Zero(),e.Vector3.Zero(),e.Vector3.Zero(),e.Vector3.Zero(),e.Vector3.Zero(),e.Vector3.Zero()],t._tmpQuat=e.Quaternion.Identity(),t._tmpMats=[e.Matrix.Identity(),e.Matrix.Identity()],t})();e.BoneIKController=t})(e||(e={}));var e;!(function(e){var t=(function(){function t(t,i,r,n){if(this.upAxis=e.Vector3.Up(),this.upAxisSpace=e.Space.LOCAL,this.adjustYaw=0,this.adjustPitch=0,this.adjustRoll=0,this.slerpAmount=1,this._boneQuat=e.Quaternion.Identity(),this._slerping=!1,this._firstFrameSkipped=!1,this._fowardAxis=e.Vector3.Forward(),this.mesh=t,this.bone=i,this.target=r,n&&(n.adjustYaw&&(this.adjustYaw=n.adjustYaw),n.adjustPitch&&(this.adjustPitch=n.adjustPitch),n.adjustRoll&&(this.adjustRoll=n.adjustRoll),null!=n.maxYaw?this.maxYaw=n.maxYaw:this.maxYaw=Math.PI,null!=n.minYaw?this.minYaw=n.minYaw:this.minYaw=-Math.PI,null!=n.maxPitch?this.maxPitch=n.maxPitch:this.maxPitch=Math.PI,null!=n.minPitch?this.minPitch=n.minPitch:this.minPitch=-Math.PI,null!=n.slerpAmount&&(this.slerpAmount=n.slerpAmount),null!=n.upAxis&&(this.upAxis=n.upAxis),null!=n.upAxisSpace&&(this.upAxisSpace=n.upAxisSpace),null!=n.yawAxis||null!=n.pitchAxis)){var o=e.Axis.Y,s=e.Axis.X;null!=n.yawAxis&&(o=n.yawAxis.clone(),o.normalize()),null!=n.pitchAxis&&(s=n.pitchAxis.clone(),s.normalize());var a=e.Vector3.Cross(s,o);this._transformYawPitch=e.Matrix.Identity(),e.Matrix.FromXYZAxesToRef(s,o,a,this._transformYawPitch),this._transformYawPitchInv=this._transformYawPitch.clone(),this._transformYawPitch.invert()}i.getParent()||this.upAxisSpace!=e.Space.BONE||(this.upAxisSpace=e.Space.LOCAL)}return Object.defineProperty(t.prototype,"minYaw",{get:function(){return this._minYaw},set:function(e){this._minYaw=e,this._minYawSin=Math.sin(e),this._minYawCos=Math.cos(e),null!=this._maxYaw&&(this._midYawConstraint=.5*this._getAngleDiff(this._minYaw,this._maxYaw)+this._minYaw,this._yawRange=this._maxYaw-this._minYaw)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"maxYaw",{get:function(){return this._maxYaw},set:function(e){this._maxYaw=e,this._maxYawSin=Math.sin(e),this._maxYawCos=Math.cos(e),null!=this._minYaw&&(this._midYawConstraint=.5*this._getAngleDiff(this._minYaw,this._maxYaw)+this._minYaw,this._yawRange=this._maxYaw-this._minYaw)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"minPitch",{get:function(){return this._minPitch},set:function(e){this._minPitch=e,this._minPitchTan=Math.tan(e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"maxPitch",{get:function(){return this._maxPitch},set:function(e){this._maxPitch=e,this._maxPitchTan=Math.tan(e)},enumerable:!0,configurable:!0}),t.prototype.update=function(){if(this.slerpAmount<1&&!this._firstFrameSkipped)return void(this._firstFrameSkipped=!0);var i=this.bone,r=t._tmpVecs[0];i.getAbsolutePositionToRef(this.mesh,r);var n=this.target,o=t._tmpMats[0],s=t._tmpMats[1],a=this.mesh,l=i.getParent(),c=t._tmpVecs[1];c.copyFrom(this.upAxis),this.upAxisSpace==e.Space.BONE&&l?(this._transformYawPitch&&e.Vector3.TransformCoordinatesToRef(c,this._transformYawPitchInv,c),l.getDirectionToRef(c,this.mesh,c)):this.upAxisSpace==e.Space.LOCAL&&(a.getDirectionToRef(c,c),1==a.scaling.x&&1==a.scaling.y&&1==a.scaling.z||c.normalize());var h=!1,u=!1;if(this._maxYaw==Math.PI&&this._minYaw==-Math.PI||(h=!0),this._maxPitch==Math.PI&&this._minPitch==-Math.PI||(u=!0),h||u){var f=t._tmpMats[2],d=t._tmpMats[3];if(this.upAxisSpace==e.Space.BONE&&1==c.y&&l)l.getRotationMatrixToRef(e.Space.WORLD,this.mesh,f);else if(this.upAxisSpace!=e.Space.LOCAL||1!=c.y||l){var p=t._tmpVecs[2];p.copyFrom(this._fowardAxis),this._transformYawPitch&&e.Vector3.TransformCoordinatesToRef(p,this._transformYawPitchInv,p),l?l.getDirectionToRef(p,this.mesh,p):a.getDirectionToRef(p,p);var _=e.Vector3.Cross(c,p);_.normalize();var p=e.Vector3.Cross(_,c);e.Matrix.FromXYZAxesToRef(_,c,p,f)}else f.copyFrom(a.getWorldMatrix());f.invertToRef(d);var m=null;if(u){var g=t._tmpVecs[3];n.subtractToRef(r,g),e.Vector3.TransformCoordinatesToRef(g,d,g),m=Math.sqrt(g.x*g.x+g.z*g.z);var v=Math.atan2(g.y,m),y=v;v>this._maxPitch?(g.y=this._maxPitchTan*m,y=this._maxPitch):vthis._maxYaw||bMath.PI?this._isAngleBetween(b,this._maxYaw,this._midYawConstraint)?(g.z=this._maxYawCos*m,g.x=this._maxYawSin*m,x=this._maxYaw):this._isAngleBetween(b,this._midYawConstraint,this._minYaw)&&(g.z=this._minYawCos*m,g.x=this._minYawSin*m,x=this._minYaw):b>this._maxYaw?(g.z=this._maxYawCos*m,g.x=this._maxYawSin*m,x=this._maxYaw):bMath.PI){var T=t._tmpVecs[8];T.copyFrom(e.Axis.Z),this._transformYawPitch&&e.Vector3.TransformCoordinatesToRef(T,this._transformYawPitchInv,T);var E=t._tmpMats[4];this._boneQuat.toRotationMatrix(E),this.mesh.getWorldMatrix().multiplyToRef(E,E),e.Vector3.TransformCoordinatesToRef(T,E,T),e.Vector3.TransformCoordinatesToRef(T,d,T);var A=Math.atan2(T.x,T.z);if(this._getAngleBetween(A,b)>this._getAngleBetween(A,this._midYawConstraint)){null==m&&(m=Math.sqrt(g.x*g.x+g.z*g.z));var P=this._getAngleBetween(A,this._maxYaw);this._getAngleBetween(A,this._minYaw)Math.PI?i-=2*Math.PI:i<-Math.PI&&(i+=2*Math.PI),i},t.prototype._getAngleBetween=function(e,t){e%=2*Math.PI,e=e<0?e+2*Math.PI:e,t%=2*Math.PI,t=t<0?t+2*Math.PI:t;var i=0;return i=eMath.PI&&(i=2*Math.PI-i),i},t.prototype._isAngleBetween=function(e,t,i){if(e%=2*Math.PI,e=e<0?e+2*Math.PI:e,t%=2*Math.PI,t=t<0?t+2*Math.PI:t,i%=2*Math.PI,i=i<0?i+2*Math.PI:i,tt&&ei&&e-1&&this._meshesWithPoseMatrix.splice(t,1)},t.prototype._computeTransformMatrices=function(e,t){this.onBeforeComputeObservable.notifyObservers(this);for(var i=0;i0&&(n.animation=i.animations[0].serialize()),e.ranges=[];for(var o in this._ranges){var s=this._ranges[o];if(s){var a={};a.name=o,a.from=s.from,a.to=s.to,e.ranges.push(a)}}}return e},t.Parse=function(i,r){var n=new t(i.name,i.id,r);i.dimensionsAtRest&&(n.dimensionsAtRest=e.Vector3.FromArray(i.dimensionsAtRest)),n.needInitialSkinMatrix=i.needInitialSkinMatrix;var o;for(o=0;o-1&&(a=n.bones[s.parentBoneIndex]);var l=s.rest?e.Matrix.FromArray(s.rest):null,c=new e.Bone(s.name,n,a,e.Matrix.FromArray(s.matrix),l);s.length&&(c.length=s.length),s.animation&&c.animations.push(e.Animation.Parse(s.animation))}if(i.ranges)for(o=0;o0&&(e=this._meshesWithPoseMatrix[0].getPoseMatrix()),e},t.prototype.sortBones=function(){for(var e=new Array,t=new Array(this.bones.length),i=0;iMath.PI;)n-=2*Math.PI;var s=n/Math.PI,a=o/Math.PI;s=.5*s+.5;var l=Math.round(s*i);l<0?l=0:l>=i&&(l=i-1);var c=Math.round(a*r);c<0?c=0:c>=r&&(c=r-1);var h=r-c-1;return{r:t[h*i*3+3*l+0],g:t[h*i*3+3*l+1],b:t[h*i*3+3*l+2]}},t.FACE_FRONT=[new e.Vector3(-1,-1,-1),new e.Vector3(1,-1,-1),new e.Vector3(-1,1,-1),new e.Vector3(1,1,-1)],t.FACE_BACK=[new e.Vector3(1,-1,1),new e.Vector3(-1,-1,1),new e.Vector3(1,1,1),new e.Vector3(-1,1,1)],t.FACE_RIGHT=[new e.Vector3(1,-1,-1),new e.Vector3(1,-1,1),new e.Vector3(1,1,-1),new e.Vector3(1,1,1)],t.FACE_LEFT=[new e.Vector3(-1,-1,1),new e.Vector3(-1,-1,-1),new e.Vector3(-1,1,1),new e.Vector3(-1,1,-1)],t.FACE_DOWN=[new e.Vector3(-1,1,-1),new e.Vector3(1,1,-1),new e.Vector3(-1,1,1),new e.Vector3(1,1,1)],t.FACE_UP=[new e.Vector3(-1,-1,1),new e.Vector3(1,-1,1),new e.Vector3(-1,-1,-1),new e.Vector3(1,-1,-1)],t})();e.PanoramaToCubeMapTools=t})(e||(e={}));var e;!(function(e){var t=(function(){function t(){}return t.Ldexp=function(e,t){return t>1023?e*Math.pow(2,1023)*Math.pow(2,t-1023):t<-1074?e*Math.pow(2,-1074)*Math.pow(2,t+1074):e*Math.pow(2,t)},t.Rgbe2float=function(e,t,i,r,n,o){n>0?(n=this.Ldexp(1,n-136),e[o+0]=t*n,e[o+1]=i*n,e[o+2]=r*n):(e[o+0]=0,e[o+1]=0,e[o+2]=0)},t.readStringLine=function(e,t){for(var i="",r="",n=t;n32767)throw"HDR Bad header format, unsupported size";return s+=r.length+1,{height:t,width:i,dataPosition:s}},t.GetCubeMapTextureData=function(t,i){var r=new Uint8Array(t),n=this.RGBE_ReadHeader(r),o=this.RGBE_ReadPixels_RLE(r,n);return e.PanoramaToCubeMapTools.ConvertPanoramaToCubemap(o,n.width,n.height,i)},t.RGBE_ReadPixels=function(e,t){return this.RGBE_ReadPixels_RLE(e,t)},t.RGBE_ReadPixels_RLE=function(e,t){for(var i,r,n,o,s,a=t.height,l=t.width,c=t.dataPosition,h=0,u=0,f=0,d=new ArrayBuffer(4*l),p=new Uint8Array(d),_=new ArrayBuffer(t.width*t.height*4*3),m=new Float32Array(_);a>0;){if(i=e[c++],r=e[c++],n=e[c++],o=e[c++],2!=i||2!=r||128&n)throw"HDR Bad header format, not RLE";if((n<<8|o)!=l)throw"HDR Bad header format, wrong scan line width";for(h=0,f=0;f<4;f++)for(u=(f+1)*l;h128){if(0==(s=i-128)||s>u-h)throw"HDR Bad Format, bad scanline data (run)";for(;s-- >0;)p[h++]=r}else{if(0==(s=i)||s>u-h)throw"HDR Bad Format, bad scanline data (non-run)";if(p[h++]=r,--s>0)for(var g=0;g>s,2),l=0;l<6;l++){var c=r.subarray(o,o+a);n[s].push(c),o+=a}}return n}:null,s=function(n){var s=t.getScene();if(!s)return null;var a=new Int32Array(n);r=new Float32Array(n);var l=a[0];if(t._size=a[1],!t._texture)return null;t._texture.updateSize(t._size,t._size);var c=new e.SphericalPolynomial;c.x.copyFromFloats(r[2],r[3],r[4]),c.y.copyFromFloats(r[5],r[6],r[7]),c.z.copyFromFloats(r[8],r[9],r[10]),c.xx.copyFromFloats(r[11],r[12],r[13]),c.yy.copyFromFloats(r[14],r[15],r[16]),c.zz.copyFromFloats(r[17],r[18],r[19]),c.xy.copyFromFloats(r[20],r[21],r[22]),c.yz.copyFromFloats(r[23],r[24],r[25]),c.zx.copyFromFloats(r[26],r[27],r[28]),t.sphericalPolynomial=c,i=a[29];for(var h=30,u=[],f=3*Math.pow(t._size,2),d=0;d<6;d++)u.push(r.subarray(h,h+f)),h+=f;for(var p=[],_=null,m=0;m<6;m++){var g=null;if(1===l){g=u[[0,2,4,1,3,5][m]]}if(!o&&g){if(!s.getEngine().getCaps().textureFloat){var v=new ArrayBuffer(f);_=new Uint8Array(v)}for(var y=0;y255){var A=255/E;b*=A,x*=A,T*=A}_[3*y+0]=b,_[3*y+1]=x,_[3*y+2]=T}}_?p.push(_):p.push(g)}return p};n&&(this._texture=n.getEngine().createRawCubeTextureFromUrl(this.url,n,this._size,e.Engine.TEXTUREFORMAT_RGB,n.getEngine().getCaps().textureFloat?e.Engine.TEXTURETYPE_FLOAT:e.Engine.TEXTURETYPE_UNSIGNED_INT,this._noMipmap,s,o,this._onLoad,this._onError))},i.prototype.loadHDRTexture=function(){var t=this,r=function(r){var n=t.getScene();if(!n)return null;var o=e.HDRTools.GetCubeMapTextureData(r,t._size);if(t._generateHarmonics){var s=e.CubeMapToSphericalPolynomialTools.ConvertCubeMapToSphericalPolynomial(o);t.sphericalPolynomial=s}for(var a=[],l=null,c=0;c<6;c++){if(!n.getEngine().getCaps().textureFloat){var h=new ArrayBuffer(t._size*t._size*3);l=new Uint8Array(h)}var u=o[i._facesMapping[c]];if(t._useInGammaSpace||l)for(var f=0;f255){var g=255/m;d*=g,p*=g,_*=g}l[3*f+0]=d,l[3*f+1]=p,l[3*f+2]=_}l?a.push(l):a.push(u)}return a},n=this.getScene();n&&(this._texture=n.getEngine().createRawCubeTextureFromUrl(this.url,n,this._size,e.Engine.TEXTUREFORMAT_RGB,n.getEngine().getCaps().textureFloat?e.Engine.TEXTURETYPE_FLOAT:e.Engine.TEXTURETYPE_UNSIGNED_INT,this._noMipmap,r,null,this._onLoad,this._onError))},i.prototype.loadTexture=function(){this._isBABYLONPreprocessed?this.loadBabylonTexture():this.loadHDRTexture()},i.prototype.clone=function(){var e=this.getScene();if(!e)return this;var t=this._isBABYLONPreprocessed?null:this._size,r=new i(this.url,e,t,this._noMipmap,this._generateHarmonics,this._useInGammaSpace,this._usePMREMGenerator);return r.level=this.level,r.wrapU=this.wrapU,r.wrapV=this.wrapV,r.coordinatesIndex=this.coordinatesIndex,r.coordinatesMode=this.coordinatesMode,r},i.prototype.delayLoad=function(){this.delayLoadState===e.Engine.DELAYLOADSTATE_NOTLOADED&&(this.delayLoadState=e.Engine.DELAYLOADSTATE_LOADED,this._texture=this._getFromCache(this.url,this._noMipmap),this._texture||this.loadTexture())},i.prototype.getReflectionTextureMatrix=function(){return this._textureMatrix},i.prototype.setReflectionTextureMatrix=function(e){this._textureMatrix=e},i.Parse=function(t,r,n){var o=null;if(t.name&&!t.isRenderTarget){var s=t.isBABYLONPreprocessed?null:t.size;o=new i(n+t.name,r,s,t.noMipmap,t.generateHarmonics,t.useInGammaSpace,t.usePMREMGenerator),o.name=t.name,o.hasAlpha=t.hasAlpha,o.level=t.level,o.coordinatesMode=t.coordinatesMode,o.isBlocking=t.isBlocking}return o&&(t.boundingBoxPosition&&(o.boundingBoxPosition=e.Vector3.FromArray(t.boundingBoxPosition)),t.boundingBoxSize&&(o.boundingBoxSize=e.Vector3.FromArray(t.boundingBoxSize))),o},i.prototype.serialize=function(){if(!this.name)return null;var e={};return e.name=this.name,e.hasAlpha=this.hasAlpha,e.isCube=!0,e.level=this.level,e.size=this._size,e.coordinatesMode=this.coordinatesMode,e.useInGammaSpace=this._useInGammaSpace,e.generateHarmonics=this._generateHarmonics,e.usePMREMGenerator=this._usePMREMGenerator,e.isBABYLONPreprocessed=this._isBABYLONPreprocessed,e.customType="BABYLON.HDRCubeTexture",e.noMipmap=this._noMipmap,e.isBlocking=this._isBlocking,e},i.generateBabylonHDROnDisk=function(e,t,r){void 0===r&&(r=null);var n=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()};i.generateBabylonHDR(e,t,n,r)},i.generateBabylonHDR=function(t,i,r,n){void 0===n&&(n=null),t&&e.Tools.IsExponentOfTwo(i)&&e.Tools.Error("Generation of Babylon HDR is coming back in 3.2.")},i._facesMapping=["right","left","up","down","front","back"],i})(e.BaseTexture);e.HDRCubeTexture=t})(e||(e={}));var i;!(function(e){function t(e,t,r){r=r||2;var o=t&&t.length,s=o?t[0]*r:e.length,a=i(e,0,s,r,!0),l=new Array;if(!a)return l;var h,u,f,d,p=0,_=0,m=0;if(o&&(a=c(e,t,a,r)),e.length>80*r){p=h=e[0],_=u=e[1];for(var g=r;gh&&(h=f),d>u&&(u=d);m=Math.max(h-p,u-_)}return n(a,l,r,p,_,m,0),l}function i(e,t,i,r,n){var o,s=null;if(n===R(e,t,i,r)>0)for(o=t;o=t;o-=r)s=M(o,e[o],e[o+1],s);return s&&b(s,s.next)&&(S(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||!b(r,r.next)&&0!==y(r.prev,r,r.next))r=r.next;else{if(S(r),(r=t=r.prev)===r.next)return;i=!0}}while(i||r!==t);return t}function n(e,t,i,c,h,u,f){if(e){!f&&u&&d(e,c,h,u);for(var p,_,m=e;e.prev!==e.next;)if(p=e.prev,_=e.next,u?s(e,c,h,u):o(e))t.push(p.i/i),t.push(e.i/i),t.push(_.i/i),S(e),e=_.next,m=_.next;else if((e=_)===m){f?1===f?(e=a(e,t,i),n(e,t,i,c,h,u,2)):2===f&&l(e,t,i,c,h,u):n(r(e,void 0),t,i,c,h,u,1);break}}}function o(e){var t=e.prev,i=e,r=e.next;if(y(t,i,r)>=0)return!1;for(var n=e.next.next;n!==e.prev;){if(g(t.x,t.y,i.x,i.y,r.x,r.y,n.x,n.y)&&y(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(y(n,o,s)>=0)return!1;for(var a=n.xo.x?n.x>s.x?n.x:s.x:o.x>s.x?o.x:s.x,h=n.y>o.y?n.y>s.y?n.y:s.y:o.y>s.y?o.y:s.y,u=_(a,l,t,i,r),f=_(c,h,t,i,r),d=e.nextZ;d&&d.z<=f;){if(d!==e.prev&&d!==e.next&&g(n.x,n.y,o.x,o.y,s.x,s.y,d.x,d.y)&&y(d.prev,d,d.next)>=0)return!1;d=d.nextZ}for(d=e.prevZ;d&&d.z>=u;){if(d!==e.prev&&d!==e.next&&g(n.x,n.y,o.x,o.y,s.x,s.y,d.x,d.y)&&y(d.prev,d,d.next)>=0)return!1;d=d.prevZ}return!0}function a(e,t,i){var r=e;do{var n=r.prev,o=r.next.next;!b(n,o)&&x(n,r,r.next,o)&&E(n,o)&&E(o,n)&&(t.push(n.i/i),t.push(r.i/i),t.push(o.i/i),S(r),S(r.next),r=e=o),r=r.next}while(r!==e);return r}function l(e,t,i,o,s,a){var l=e;do{for(var c=l.next.next;c!==l.prev;){if(l.i!==c.i&&v(l,c)){var h=P(l,c);return l=r(l,l.next),h=r(h,h.next),n(l,t,i,o,s,a,void 0),void n(h,t,i,o,s,a,void 0)}c=c.next}l=l.next}while(l!==e)}function c(e,t,n,o){var s,a,l,c,f,d=[];for(s=0,a=t.length;s=r.next.y){var a=r.x+(o-r.y)*(r.next.x-r.x)/(r.next.y-r.y);if(a<=n&&a>s){if(s=a,a===n){if(o===r.y)return r;if(o===r.next.y)return r.next}i=r.x=r.x&&r.x>=h&&g(oi.x)&&E(r,e)&&(i=r,f=l),r=r.next;return i}function d(e,t,i,r){var n=e;do{null===n.z&&(n.z=_(n.x,n.y,t,i,r)),n.prevZ=n.prev,n.nextZ=n.next,n=n.next}while(n!==e);n.prevZ.nextZ=null,n.prevZ=null,p(n)}function p(e){var t,i,r,n,o,s,a,l,c=1;do{for(i=e,e=null,o=null,s=0;i;){for(s++,r=i,a=0,t=0;t0||l>0&&r;)0===a?(n=r,r=r.nextZ,l--):0!==l&&r?i.z<=r.z?(n=i,i=i.nextZ,a--):(n=r,r=r.nextZ,l--):(n=i,i=i.nextZ,a--),o?o.nextZ=n:e=n,n.prevZ=o,o=n;i=r}o.nextZ=null,c*=2}while(s>1);return e}function _(e,t,i,r,n){return e=32767*(e-i)/n,t=32767*(t-r)/n,e=16711935&(e|e<<8),e=252645135&(e|e<<4),e=858993459&(e|e<<2),e=1431655765&(e|e<<1),t=16711935&(t|t<<8),t=252645135&(t|t<<4),t=858993459&(t|t<<2),t=1431655765&(t|t<<1),e|t<<1}function m(e){var t=e,i=e;do{t.x=0&&(e-s)*(r-a)-(i-s)*(t-a)>=0&&(i-s)*(o-a)-(n-s)*(r-a)>=0}function v(e,t){return e.next.i!==t.i&&e.prev.i!==t.i&&!T(e,t)&&E(e,t)&&E(t,e)&&A(e,t)}function y(e,t,i){return(t.y-e.y)*(i.x-t.x)-(t.x-e.x)*(i.y-t.y)}function b(e,t){return e.x===t.x&&e.y===t.y}function x(e,t,i,r){return!!(b(e,t)&&b(i,r)||b(e,r)&&b(i,t))||y(e,t,i)>0!=y(e,t,r)>0&&y(i,r,e)>0!=y(i,r,t)>0}function T(e,t){var i=e;do{if(i.i!==e.i&&i.next.i!==e.i&&i.i!==t.i&&i.next.i!==t.i&&x(i,i.next,e,t))return!0;i=i.next}while(i!==e);return!1}function E(e,t){return y(e.prev,e,e.next)<0?y(e,t,e.next)>=0&&y(e,e.prev,t)>=0:y(e,t,e.prev)<0||y(e,e.next,t)<0}function A(e,t){var i=e,r=!1,n=(e.x+t.x)/2,o=(e.y+t.y)/2;do{i.y>o!=i.next.y>o&&n<(i.next.x-i.x)*(o-i.y)/(i.next.y-i.y)+i.x&&(r=!r),i=i.next}while(i!==e);return r}function P(e,t){var i=new I(e.i,e.x,e.y),r=new I(t.i,t.x,t.y),n=e.next,o=t.prev;return e.next=t,t.prev=e,i.next=n,n.prev=i,r.next=i,i.prev=r,o.next=r,r.prev=o,r}function M(e,t,i,r){var n=new I(e,t,i);return r?(n.next=r.next,n.prev=r,r.next.prev=n,r.next=n):(n.prev=n,n.next=n),n}function S(e){e.next.prev=e.prev,e.prev.next=e.next,e.prevZ&&(e.prevZ.nextZ=e.nextZ),e.nextZ&&(e.nextZ.prevZ=e.prevZ)}function C(e,t,i,r){var n=t&&t.length,o=n?t[0]*i:e.length,s=Math.abs(R(e,0,o,i));if(n)for(var a=0,l=t.length;a0&&(r+=e[n-1].length,i.holes.push(r))}return i}e.earcut=t;var I=(function(){function e(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}return e})();e.deviation=C,e.flatten=O})(i||(i={}));var e;!(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 __extends(t,e),t})(e.Vector2),r=(function(){function i(){this.elements=new Array}return i.prototype.add=function(e){var i=this,r=new Array;return e.forEach((function(e){if(0===r.length||!e.equalsWithEpsilon(r[0])){var n=new t(e,i.elements.length);r.push(n),i.elements.push(n)}})),r},i.prototype.computeBounds=function(){var t=new e.Vector2(this.elements[0].x,this.elements[0].y),i=new e.Vector2(this.elements[0].x,this.elements[0].y);return this.elements.forEach((function(e){e.xi.x&&(i.x=e.x),e.yi.y&&(i.y=e.y)})),{min:t,max:i,width:i.x-t.x,height:i.y-t.y}},i})(),n=(function(){function t(){}return t.Rectangle=function(t,i,r,n){return[new e.Vector2(t,i),new e.Vector2(r,i),new e.Vector2(r,n),new e.Vector2(t,n)]},t.Circle=function(t,i,r,n){void 0===i&&(i=0),void 0===r&&(r=0),void 0===n&&(n=32);for(var o=new Array,s=0,a=2*Math.PI/n,l=0;l0){var d=a.length/3;this._points.elements.forEach((function(e){s.push(0,-1,0),a.push(e.x,-r,e.y),l.push(1-(e.x-c.min.x)/c.width,1-(e.y-c.min.y)/c.height)}));for(var p=h.length,f=0;fs.elements.length-1?s.elements[0]:s.elements[u+1],t.push(d.x,0,d.y),t.push(d.x,-a,d.y),t.push(f.x,0,f.y),t.push(f.x,-a,f.y);var p=new e.Vector3(d.x,0,d.y),_=new e.Vector3(f.x,0,f.y),m=_.subtract(p),g=new e.Vector3(0,1,0),v=e.Vector3.Cross(m,g);v=v.normalize(),r.push(h/o.width,0),r.push(h/o.width,1),h+=m.length(),r.push(h/o.width,0),r.push(h/o.width,1),l?(i.push(v.x,v.y,v.z),i.push(v.x,v.y,v.z),i.push(v.x,v.y,v.z),i.push(v.x,v.y,v.z),n.push(c),n.push(c+2),n.push(c+1),n.push(c+1),n.push(c+2),n.push(c+3)):(i.push(-v.x,-v.y,-v.z),i.push(-v.x,-v.y,-v.z),i.push(-v.x,-v.y,-v.z),i.push(-v.x,-v.y,-v.z),n.push(c),n.push(c+1),n.push(c+2),n.push(c+1),n.push(c+3),n.push(c+2)),c+=4}},t})();e.PolygonMeshBuilder=o})(e||(e={}));var e;!(function(e){var t=0,i=(function(){function t(e,t,i){this.pos=e,this.normal=t,this.uv=i}return t.prototype.clone=function(){return new t(this.pos.clone(),this.normal.clone(),this.uv.clone())},t.prototype.flip=function(){this.normal=this.normal.scale(-1)},t.prototype.interpolate=function(i,r){return new t(e.Vector3.Lerp(this.pos,i.pos,r),e.Vector3.Lerp(this.normal,i.normal,r),e.Vector2.Lerp(this.uv,i.uv,r))},t})(),r=(function(){function t(e,t){this.normal=e,this.w=t}return t.FromPoints=function(i,r,n){var o=n.subtract(i),s=r.subtract(i);if(0===o.lengthSquared()||0===s.lengthSquared())return null;var a=e.Vector3.Normalize(e.Vector3.Cross(o,s));return new t(a,e.Vector3.Dot(a,i))},t.prototype.clone=function(){return new t(this.normal.clone(),this.w)},t.prototype.flip=function(){this.normal.scaleInPlace(-1),this.w=-this.w},t.prototype.splitPolygon=function(i,r,o,s,a){var l,c,h=0,u=[];for(l=0;lt.EPSILON?1:0;h|=f,u.push(f)}switch(h){case 0:(e.Vector3.Dot(this.normal,i.plane.normal)>0?r:o).push(i);break;case 1:s.push(i);break;case 2:a.push(i);break;case 3:var d=[],p=[];for(l=0;l=3&&(x=new n(d,i.shared),x.plane&&s.push(x)),p.length>=3&&(x=new n(p,i.shared),x.plane&&a.push(x))}},t.EPSILON=1e-5,t})(),n=(function(){function e(e,t){this.vertices=e,this.shared=t,this.plane=r.FromPoints(e[0].pos,e[1].pos,e[2].pos)}return e.prototype.clone=function(){return new e(this.vertices.map((function(e){return e.clone()})),this.shared)},e.prototype.flip=function(){this.vertices.reverse().map((function(e){e.flip()})),this.plane.flip()},e})(),o=(function(){function e(e){this.plane=null,this.front=null,this.back=null,this.polygons=new Array,e&&this.build(e)}return e.prototype.clone=function(){var t=new e;return t.plane=this.plane&&this.plane.clone(),t.front=this.front&&this.front.clone(),t.back=this.back&&this.back.clone(),t.polygons=this.polygons.map((function(e){return e.clone()})),t},e.prototype.invert=function(){for(var e=0;e0&&(t.x-=this.viewportBorder,t.y-=this.viewportBorder,t.width+=2*this.viewportBorder,t.height+=2*this.viewportBorder,i.x+=this.viewportBorder,i.y+=this.viewportBorder,this._positionX+=this.viewportBorder,this._positionY+=this.viewportBorder),i.z>0&&(this._positionX>t.x&&this._positionXt.y&&(this._positionY,t.y,t.height),!0)},t.prototype._isVisible=function(){if(!this._isEnabled||!this._scene.activeCamera)return!1;var t=this.getEmitterPosition(),i=t.subtract(this._scene.activeCamera.globalPosition),r=i.length();i.normalize();var n=new e.Ray(this._scene.activeCamera.globalPosition,i),o=this._scene.pickWithRay(n,this.meshesSelectionPredicate,!0);return!o||!o.hit||o.distance>r},t.prototype.render=function(){if(!this._effect.isReady()||!this._scene.activeCamera)return!1;var t=this._scene.getEngine(),i=this._scene.activeCamera.viewport,r=i.toGlobal(t.getRenderWidth(!0),t.getRenderHeight(!0));if(!this.computeEffectivePosition(r))return!1;if(!this._isVisible())return!1;var n,o;n=this._positionXr.x+r.width-this.borderLimit?this._positionX-r.x-r.width+this.borderLimit:0,o=this._positionYr.y+r.height-this.borderLimit?this._positionY-r.y-r.height+this.borderLimit:0;var s=n>o?n:o;(s-=this.viewportBorder)>this.borderLimit&&(s=this.borderLimit);var a=1-s/this.borderLimit;if(a<0)return!1;a>1&&(a=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 l=r.x+r.width/2,c=r.y+r.height/2,h=l-this._positionX,u=c-this._positionY;t.enableEffect(this._effect),t.setState(!1),t.setDepthBuffer(!1),t.bindBuffers(this._vertexBuffers,this._indexBuffer,this._effect);for(var f=0;f-1?this._onBeforePhysicsStepCallbacks.splice(i,1):e.Tools.Warn("Function to remove was not found")},t.prototype.registerAfterPhysicsStep=function(e){this._onAfterPhysicsStepCallbacks.push(e)},t.prototype.unregisterAfterPhysicsStep=function(t){var i=this._onAfterPhysicsStepCallbacks.indexOf(t);i>-1?this._onAfterPhysicsStepCallbacks.splice(i,1):e.Tools.Warn("Function to remove was not found")},t.prototype.registerOnPhysicsCollide=function(e,t){var i=e instanceof Array?e:[e];this._onPhysicsCollideCallbacks.push({callback:t,otherImpostors:i})},t.prototype.unregisterOnPhysicsCollide=function(t,i){var r=t instanceof Array?t:[t],n=this._onPhysicsCollideCallbacks.indexOf({callback:i,otherImpostors:r});n>-1?this._onPhysicsCollideCallbacks.splice(n,1):e.Tools.Warn("Function to remove was not found")},t.prototype.getParentsRotation=function(){var t=this.object.parent;for(this._tmpQuat.copyFromFloats(0,0,0,1);t;)t.rotationQuaternion?this._tmpQuat2.copyFrom(t.rotationQuaternion):e.Quaternion.RotationYawPitchRollToRef(t.rotation.y,t.rotation.x,t.rotation.z,this._tmpQuat2),this._tmpQuat.multiplyToRef(this._tmpQuat2,this._tmpQuat),t=t.parent;return this._tmpQuat},t.prototype.applyForce=function(e,t){return this._physicsEngine&&this._physicsEngine.getPhysicsPlugin().applyForce(this,e,t),this},t.prototype.applyImpulse=function(e,t){return this._physicsEngine&&this._physicsEngine.getPhysicsPlugin().applyImpulse(this,e,t),this},t.prototype.createJoint=function(t,i,r){var n=new e.PhysicsJoint(i,r);return this.addJoint(t,n),this},t.prototype.addJoint=function(e,t){return this._joints.push({otherImpostor:e,joint:t}),this._physicsEngine&&this._physicsEngine.addJoint(this,e,t),this},t.prototype.sleep=function(){return this._physicsEngine&&this._physicsEngine.getPhysicsPlugin().sleepBody(this),this},t.prototype.wakeUp=function(){return this._physicsEngine&&this._physicsEngine.getPhysicsPlugin().wakeUpBody(this),this},t.prototype.clone=function(e){return e?new t(e,this.type,this._options,this._scene):null},t.prototype.dispose=function(){var e=this;this._physicsEngine&&(this._joints.forEach((function(t){e._physicsEngine&&e._physicsEngine.removeJoint(e,t.otherImpostor,t.joint)})),this._physicsEngine.removeImpostor(this),this.parent&&this.parent.forceUpdate(),this._isDisposed=!0)},t.prototype.setDeltaPosition=function(e){this._deltaPosition.copyFrom(e)},t.prototype.setDeltaRotation=function(t){this._deltaRotation||(this._deltaRotation=new e.Quaternion),this._deltaRotation.copyFrom(t),this._deltaRotationConjugated=this._deltaRotation.conjugate()},t.prototype.getBoxSizeToRef=function(e){return this._physicsEngine&&this._physicsEngine.getPhysicsPlugin().getBoxSizeToRef(this,e),this},t.prototype.getRadius=function(){return this._physicsEngine?this._physicsEngine.getPhysicsPlugin().getRadius(this):0},t.prototype.syncBoneWithImpostor=function(i,r,n,o,s){var a=t._tmpVecs[0],l=this.object;if(l.rotationQuaternion)if(s){var c=t._tmpQuat;l.rotationQuaternion.multiplyToRef(s,c),i.setRotationQuaternion(c,e.Space.WORLD,r)}else i.setRotationQuaternion(l.rotationQuaternion,e.Space.WORLD,r);a.x=0,a.y=0,a.z=0,n&&(a.x=n.x,a.y=n.y,a.z=n.z,i.getDirectionToRef(a,r,a),void 0!==o&&null!==o||(o=n.length()),a.x*=o,a.y*=o,a.z*=o),i.getParent()?(a.addInPlace(l.getAbsolutePosition()),i.setAbsolutePosition(a,r)):(r.setAbsolutePosition(l.getAbsolutePosition()),r.position.x-=a.x,r.position.y-=a.y,r.position.z-=a.z)},t.prototype.syncImpostorWithBone=function(i,r,n,o,s,a){var l=this.object;if(l.rotationQuaternion)if(s){var c=t._tmpQuat;i.getRotationQuaternionToRef(e.Space.WORLD,r,c),c.multiplyToRef(s,l.rotationQuaternion)}else i.getRotationQuaternionToRef(e.Space.WORLD,r,l.rotationQuaternion);var h=t._tmpVecs[0],u=t._tmpVecs[1];a||(a=t._tmpVecs[2],a.x=0,a.y=1,a.z=0),i.getDirectionToRef(a,r,u),i.getAbsolutePositionToRef(r,h),void 0!==o&&null!==o||!n||(o=n.length()),void 0!==o&&null!==o&&(h.x+=u.x*o,h.y+=u.y*o,h.z+=u.z*o),l.setAbsolutePosition(h)},t.DEFAULT_OBJECT_SIZE=new e.Vector3(1,1,1),t.IDENTITY_QUATERNION=e.Quaternion.Identity(),t._tmpVecs=[e.Vector3.Zero(),e.Vector3.Zero(),e.Vector3.Zero()],t._tmpQuat=e.Quaternion.Identity(),t.NoImpostor=0,t.SphereImpostor=1,t.BoxImpostor=2,t.PlaneImpostor=3,t.MeshImpostor=4,t.CylinderImpostor=7,t.ParticleImpostor=8,t.HeightmapImpostor=9,t})();e.PhysicsImpostor=t})(e||(e={}));var e;!(function(e){var t=(function(){function t(t,i){if(void 0===i&&(i=new e.CannonJSPlugin),this._physicsPlugin=i,this._impostors=[],this._joints=[],!this._physicsPlugin.isSupported())throw new Error("Physics Engine "+this._physicsPlugin.name+" cannot be found. Please make sure it is included.");t=t||new e.Vector3(0,-9.807,0),this.setGravity(t),this.setTimeStep()}return t.prototype.setGravity=function(e){this.gravity=e,this._physicsPlugin.setGravity(this.gravity)},t.prototype.setTimeStep=function(e){void 0===e&&(e=1/60),this._physicsPlugin.setTimeStep(e)},t.prototype.getTimeStep=function(){return this._physicsPlugin.getTimeStep()},t.prototype.dispose=function(){this._impostors.forEach((function(e){e.dispose()})),this._physicsPlugin.dispose()},t.prototype.getPhysicsPluginName=function(){return this._physicsPlugin.name},t.prototype.addImpostor=function(e){e.uniqueId=this._impostors.push(e),e.parent||this._physicsPlugin.generatePhysicsBody(e)},t.prototype.removeImpostor=function(e){var t=this._impostors.indexOf(e);if(t>-1){var i=this._impostors.splice(t,1);i.length&&(i[0].physicsBody=null)}},t.prototype.addJoint=function(e,t,i){var r={mainImpostor:e,connectedImpostor:t,joint:i};i.physicsPlugin=this._physicsPlugin,this._joints.push(r),this._physicsPlugin.generateJoint(r)},t.prototype.removeJoint=function(e,t,i){var r=this._joints.filter((function(r){return r.connectedImpostor===t&&r.joint===i&&r.mainImpostor===e}));r.length&&this._physicsPlugin.removeJoint(r[0])},t.prototype._step=function(e){var t=this;this._impostors.forEach((function(e){e.isBodyInitRequired()&&t._physicsPlugin.generatePhysicsBody(e)})),e>.1?e=.1:e<=0&&(e=1/60),this._physicsPlugin.executeStep(e,this._impostors)},t.prototype.getPhysicsPlugin=function(){return this._physicsPlugin},t.prototype.getImpostors=function(){return this._impostors},t.prototype.getImpostorForPhysicsObject=function(e){for(var t=0;tr)return null;var p=o===s.Constant?n:n*(1-d/r);return{force:c.multiplyByFloats(p,p,p),contactPoint:f}},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,o){void 0===o&&(o=s.Constant),this._dataFetched=!1,this._physicsHelper=e,this._scene=t,this._origin=i,this._radius=r,this._strength=n,this._falloff=o,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 var 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=(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),a=s.intersectsMesh(i),l=a.pickedPoint;if(!l)return null;var c=a.distance/this._radius,h=e.Vector3.Cross(n,r).normalize(),u=l.normalize();if(c>this._centripetalForceThreshold&&(u=u.negate()),c>this._centripetalForceThreshold)var f=u.x*this._strength/8,d=u.y*this._updraftMultiplier,p=u.z*this._strength/8;else var f=(h.x+u.x)/2,d=this._originTop.y*this._updraftMultiplier,p=(h.z+u.z)/2;var _=new e.Vector3(f,d,p);return _=_.multiplyByFloats(this._strength,this._strength,this._strength),{force:_,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=o;var s;!(function(e){e[e.Constant=0]="Constant",e[e.Linear=1]="Linear"})(s=e.PhysicsRadialImpulseFalloff||(e.PhysicsRadialImpulseFalloff={}));var a;!(function(e){e[e.Center=0]="Center",e[e.Perpendicular=1]="Perpendicular"})(a=e.PhysicsUpdraftMode||(e.PhysicsUpdraftMode={}))})(e||(e={}));var e;!(function(e){var t=(function(){function t(t,i){if(void 0===t&&(t=!0),void 0===i&&(i=10),this._useDeltaForWorldStep=t,this.name="CannonJSPlugin",this._physicsMaterials=new Array,this._fixedTimeStep=1/60,this.BJSCANNON="undefined"!=typeof CANNON?CANNON:"undefined"!=typeof require?require("cannon"):void 0,this._minus90X=new e.Quaternion(-.7071067811865475,0,0,.7071067811865475),this._plus90X=new e.Quaternion(.7071067811865475,0,0,.7071067811865475),this._tmpPosition=e.Vector3.Zero(),this._tmpDeltaPosition=e.Vector3.Zero(),this._tmpUnityRotation=new e.Quaternion,!this.isSupported())return void e.Tools.Error("CannonJS is not available. Please make sure you included the js file.");this._extendNamespace(),this.world=new this.BJSCANNON.World,this.world.broadphase=new this.BJSCANNON.NaiveBroadphase,this.world.solver.iterations=i}return t.prototype.setGravity=function(e){this.world.gravity.copy(e)},t.prototype.setTimeStep=function(e){this._fixedTimeStep=e},t.prototype.getTimeStep=function(){return this._fixedTimeStep},t.prototype.executeStep=function(e,t){this.world.step(this._fixedTimeStep,this._useDeltaForWorldStep?e:0,3)},t.prototype.applyImpulse=function(e,t,i){var r=new this.BJSCANNON.Vec3(i.x,i.y,i.z),n=new this.BJSCANNON.Vec3(t.x,t.y,t.z);e.physicsBody.applyImpulse(n,r)},t.prototype.applyForce=function(e,t,i){var r=new this.BJSCANNON.Vec3(i.x,i.y,i.z),n=new this.BJSCANNON.Vec3(t.x,t.y,t.z);e.physicsBody.applyForce(n,r)},t.prototype.generatePhysicsBody=function(e){if(e.parent)return void(e.physicsBody&&(this.removePhysicsBody(e),e.forceUpdate()));if(e.isBodyInitRequired()){var t=this._createShape(e),i=e.physicsBody;i&&this.removePhysicsBody(e);var r=this._addMaterial("mat-"+e.uniqueId,e.getParam("friction"),e.getParam("restitution")),n={mass:e.getParam("mass"),material:r},o=e.getParam("nativeOptions");for(var s in o)o.hasOwnProperty(s)&&(n[s]=o[s]);e.physicsBody=new this.BJSCANNON.Body(n),e.physicsBody.addEventListener("collide",e.onCollide),this.world.addEventListener("preStep",e.beforeStep),this.world.addEventListener("postStep",e.afterStep),e.physicsBody.addShape(t),this.world.add(e.physicsBody),i&&["force","torque","velocity","angularVelocity"].forEach((function(t){e.physicsBody[t].copy(i[t])})),this._processChildMeshes(e)}this._updatePhysicsBodyTransformation(e)},t.prototype._processChildMeshes=function(t){var i=this,r=t.object.getChildMeshes?t.object.getChildMeshes(!0):[],n=t.object.rotationQuaternion;if(r.length){var o=function(r,s){if(n&&s.rotationQuaternion){var a=s.getPhysicsImpostor();if(a){if(a.parent!==t){var l=s.getAbsolutePosition().subtract(t.object.getAbsolutePosition()),c=s.rotationQuaternion.multiply(e.Quaternion.Inverse(n));a.physicsBody&&(i.removePhysicsBody(a),a.physicsBody=null),a.parent=t,a.resetUpdateFlags(),t.physicsBody.addShape(i._createShape(a),new i.BJSCANNON.Vec3(l.x,l.y,l.z),new i.BJSCANNON.Quaternion(c.x,c.y,c.z,c.w)),t.physicsBody.mass+=a.getParam("mass")}}n.multiplyInPlace(s.rotationQuaternion),s.getChildMeshes(!0).filter((function(e){return!!e.physicsImpostor})).forEach(o.bind(i,s.getAbsolutePosition()))}};r.filter((function(e){return!!e.physicsImpostor})).forEach(o.bind(this,t.object.getAbsolutePosition()))}},t.prototype.removePhysicsBody=function(e){e.physicsBody.removeEventListener("collide",e.onCollide),this.world.removeEventListener("preStep",e.beforeStep),this.world.removeEventListener("postStep",e.afterStep),this.world.remove(e.physicsBody)},t.prototype.generateJoint=function(t){var i=t.mainImpostor.physicsBody,r=t.connectedImpostor.physicsBody;if(i&&r){var n,o=t.joint.jointData,s={pivotA:o.mainPivot?(new this.BJSCANNON.Vec3).copy(o.mainPivot):null,pivotB:o.connectedPivot?(new this.BJSCANNON.Vec3).copy(o.connectedPivot):null,axisA:o.mainAxis?(new this.BJSCANNON.Vec3).copy(o.mainAxis):null,axisB:o.connectedAxis?(new this.BJSCANNON.Vec3).copy(o.connectedAxis):null,maxForce:o.nativeParams.maxForce,collideConnected:!!o.collision};switch(t.joint.type){case e.PhysicsJoint.HingeJoint:case e.PhysicsJoint.Hinge2Joint:n=new this.BJSCANNON.HingeConstraint(i,r,s);break;case e.PhysicsJoint.DistanceJoint:n=new this.BJSCANNON.DistanceConstraint(i,r,o.maxDistance||2);break;case e.PhysicsJoint.SpringJoint:var a=o;n=new this.BJSCANNON.Spring(i,r,{restLength:a.length,stiffness:a.stiffness,damping:a.damping,localAnchorA:s.pivotA,localAnchorB:s.pivotB});break;case e.PhysicsJoint.LockJoint:n=new this.BJSCANNON.LockConstraint(i,r,s);break;case e.PhysicsJoint.PointToPointJoint:case e.PhysicsJoint.BallAndSocketJoint:default:n=new this.BJSCANNON.PointToPointConstraint(i,s.pivotA,r,s.pivotA,s.maxForce)}n.collideConnected=!!o.collision,t.joint.physicsJoint=n,t.joint.type!==e.PhysicsJoint.SpringJoint?this.world.addConstraint(n):t.mainImpostor.registerAfterPhysicsStep((function(){n.applyForce()}))}},t.prototype.removeJoint=function(e){this.world.removeConstraint(e.joint.physicsJoint)},t.prototype._addMaterial=function(e,t,i){var r,n;for(r=0;r1e3*i));a++);this.time+=r;for(var l=this.time%i,c=l/i,h=e,u=this.bodies,f=0;f!==u.length;f++){var d=u[f];d.type!==t.Body.STATIC&&d.sleepState!==t.Body.SLEEPING?(d.position.vsub(d.previousPosition,h),h.scale(c,h),d.position.vadd(h,d.interpolatedPosition)):(d.interpolatedPosition.copy(d.position),d.interpolatedQuaternion.copy(d.quaternion))}}}},t})();e.CannonJSPlugin=t})(e||(e={}));var e;!(function(e){var t=(function(){function t(t){this.name="OimoJSPlugin",this._tmpImpostorsArray=[],this._tmpPositionVector=e.Vector3.Zero(),this.BJSOIMO="undefined"!=typeof OIMO?OIMO:"undefined"!=typeof require?require("./Oimo"):void 0,this.world=new this.BJSOIMO.World(1/60,2,t,!0),this.world.worldscale(1),this.world.clear(),this.world.isNoStat=!0}return t.prototype.setGravity=function(e){this.world.gravity.copy(e)},t.prototype.setTimeStep=function(e){this.world.timeStep=e},t.prototype.getTimeStep=function(){return this.world.timeStep},t.prototype.executeStep=function(e,t){var i=this;t.forEach((function(e){e.beforeStep()})),this.world.step(),t.forEach((function(e){e.afterStep(),i._tmpImpostorsArray[e.uniqueId]=e}));for(var r=this.world.contacts;null!==r;)if(!r.touching||r.body1.sleeping||r.body2.sleeping){var n=this._tmpImpostorsArray[+r.body1.name],o=this._tmpImpostorsArray[+r.body2.name];n&&o?(n.onCollide({body:o.physicsBody}),o.onCollide({body:n.physicsBody}),r=r.next):r=r.next}else r=r.next},t.prototype.applyImpulse=function(e,t,i){var r=e.physicsBody.massInfo.mass;e.physicsBody.applyImpulse(i.scale(this.BJSOIMO.INV_SCALE),t.scale(this.BJSOIMO.INV_SCALE*r))},t.prototype.applyForce=function(t,i,r){e.Tools.Warn("Oimo doesn't support applying force. Using impule instead."),this.applyImpulse(t,i,r)},t.prototype.generatePhysicsBody=function(t){var i=this;if(t.parent)return void(t.physicsBody&&(this.removePhysicsBody(t),t.forceUpdate()));if(t.isBodyInitRequired()){var r={name:t.uniqueId,config:[t.getParam("mass")||1,t.getParam("friction"),t.getParam("restitution")],size:[],type:[],pos:[],rot:[],move:0!==t.getParam("mass"),world:this.world},n=[t];!(function(e){e.getChildMeshes&&e.getChildMeshes().forEach((function(e){e.physicsImpostor&&n.push(e.physicsImpostor)}))})(t.object);var o=function(t){return Math.max(t,e.PhysicsEngine.Epsilon)};n.forEach((function(n){if(t.object.rotationQuaternion){var s=n.object.rotationQuaternion,a=(new i.BJSOIMO.Euler).setFromQuaternion({x:t.object.rotationQuaternion.x,y:t.object.rotationQuaternion.y,z:t.object.rotationQuaternion.z,s:t.object.rotationQuaternion.w}),l=n.getObjectExtendSize();if(n===t){var c=t.getObjectCenter();t.object.getAbsolutePivotPoint().subtractToRef(c,i._tmpPositionVector),i._tmpPositionVector.divideInPlace(t.object.scaling),r.pos.push(c.x),r.pos.push(c.y),r.pos.push(c.z),r.rot.push(a.x/(i.BJSOIMO.degtorad||i.BJSOIMO.TO_RAD)),r.rot.push(a.y/(i.BJSOIMO.degtorad||i.BJSOIMO.TO_RAD)),r.rot.push(a.z/(i.BJSOIMO.degtorad||i.BJSOIMO.TO_RAD))}else{var h=n.object.getAbsolutePosition().subtract(t.object.getAbsolutePosition());r.pos.push(h.x),r.pos.push(h.y),r.pos.push(h.z),r.rot.push(0),r.rot.push(0),r.rot.push(0)}switch(n.type){case e.PhysicsImpostor.ParticleImpostor:e.Tools.Warn("No Particle support in this.BJSOIMO.js. using SphereImpostor instead");case e.PhysicsImpostor.SphereImpostor:var u=l.x,f=l.y,d=l.z,p=Math.max(o(u),o(f),o(d))/2;r.type.push("sphere"),r.size.push(p),r.size.push(p),r.size.push(p);break;case e.PhysicsImpostor.CylinderImpostor:var _=o(l.x)/2,m=o(l.y);r.type.push("cylinder"),r.size.push(_),r.size.push(m),r.size.push(m);break;case e.PhysicsImpostor.PlaneImpostor:case e.PhysicsImpostor.BoxImpostor:default:var _=o(l.x),m=o(l.y),g=o(l.z);r.type.push("box"),r.size.push(_),r.size.push(m),r.size.push(g)}n.object.rotationQuaternion=s}})),t.physicsBody=new this.BJSOIMO.Body(r).body}else this._tmpPositionVector.copyFromFloats(0,0,0);t.setDeltaPosition(this._tmpPositionVector)},t.prototype.removePhysicsBody=function(e){this.world.removeRigidBody(e.physicsBody)},t.prototype.generateJoint=function(t){var i=t.mainImpostor.physicsBody,r=t.connectedImpostor.physicsBody;if(i&&r){var n,o=t.joint.jointData,s=o.nativeParams||{},a={body1:i,body2:r,axe1:s.axe1||(o.mainAxis?o.mainAxis.asArray():null),axe2:s.axe2||(o.connectedAxis?o.connectedAxis.asArray():null),pos1:s.pos1||(o.mainPivot?o.mainPivot.asArray():null),pos2:s.pos2||(o.connectedPivot?o.connectedPivot.asArray():null),min:s.min,max:s.max,collision:s.collision||o.collision,spring:s.spring,world:this.world};switch(t.joint.type){case e.PhysicsJoint.BallAndSocketJoint:n="jointBall";break;case e.PhysicsJoint.SpringJoint:e.Tools.Warn("this.BJSOIMO.js doesn't support Spring Constraint. Simulating using DistanceJoint instead");var l=o;a.min=l.length||a.min,a.max=Math.max(a.min,a.max);case e.PhysicsJoint.DistanceJoint:n="jointDistance",a.max=o.maxDistance;break;case e.PhysicsJoint.PrismaticJoint:n="jointPrisme";break;case e.PhysicsJoint.SliderJoint:n="jointSlide";break;case e.PhysicsJoint.WheelJoint:n="jointWheel";break;case e.PhysicsJoint.HingeJoint:default:n="jointHinge"}a.type=n,t.joint.physicsJoint=new this.BJSOIMO.Link(a).joint}},t.prototype.removeJoint=function(t){try{this.world.removeJoint(t.joint.physicsJoint)}catch(t){e.Tools.Warn(t)}},t.prototype.isSupported=function(){return void 0!==this.BJSOIMO},t.prototype.setTransformationFromPhysicsBody=function(e){if(!e.physicsBody.sleeping){if(e.physicsBody.shapes.next){var t=this._getLastShape(e.physicsBody);e.object.position.x=t.position.x*this.BJSOIMO.WORLD_SCALE,e.object.position.y=t.position.y*this.BJSOIMO.WORLD_SCALE,e.object.position.z=t.position.z*this.BJSOIMO.WORLD_SCALE}else e.object.position.copyFrom(e.physicsBody.getPosition());e.object.rotationQuaternion&&(e.object.rotationQuaternion.copyFrom(e.physicsBody.getQuaternion()),e.object.rotationQuaternion.normalize())}},t.prototype.setPhysicsBodyTransformation=function(e,t,i){var r=e.physicsBody;r.position.init(t.x*this.BJSOIMO.INV_SCALE,t.y*this.BJSOIMO.INV_SCALE,t.z*this.BJSOIMO.INV_SCALE),r.orientation.init(i.w,i.x,i.y,i.z),r.syncShapes(),r.awake()},t.prototype._getLastShape=function(e){for(var t=e.shapes;t.next;)t=t.next;return t},t.prototype.setLinearVelocity=function(e,t){e.physicsBody.linearVelocity.init(t.x,t.y,t.z)},t.prototype.setAngularVelocity=function(e,t){e.physicsBody.angularVelocity.init(t.x,t.y,t.z)},t.prototype.getLinearVelocity=function(t){var i=t.physicsBody.linearVelocity;return i?new e.Vector3(i.x,i.y,i.z):null},t.prototype.getAngularVelocity=function(t){var i=t.physicsBody.angularVelocity;return i?new e.Vector3(i.x,i.y,i.z):null},t.prototype.setBodyMass=function(e,t){var i=0===t;e.physicsBody.shapes.density=i?1:t,e.physicsBody.setupMass(i?2:1)},t.prototype.getBodyMass=function(e){return e.physicsBody.shapes.density},t.prototype.getBodyFriction=function(e){return e.physicsBody.shapes.friction},t.prototype.setBodyFriction=function(e,t){e.physicsBody.shapes.friction=t},t.prototype.getBodyRestitution=function(e){return e.physicsBody.shapes.restitution},t.prototype.setBodyRestitution=function(e,t){e.physicsBody.shapes.restitution=t},t.prototype.sleepBody=function(e){e.physicsBody.sleep()},t.prototype.wakeUpBody=function(e){e.physicsBody.awake()},t.prototype.updateDistanceJoint=function(e,t,i){e.physicsJoint.limitMotor.upperLimit=t,void 0!==i&&(e.physicsJoint.limitMotor.lowerLimit=i)},t.prototype.setMotor=function(e,t,i,r){var n=r?e.physicsJoint.rotationalLimitMotor2:e.physicsJoint.rotationalLimitMotor1||e.physicsJoint.rotationalLimitMotor||e.physicsJoint.limitMotor;n&&n.setMotor(t,i)},t.prototype.setLimit=function(e,t,i,r){var n=r?e.physicsJoint.rotationalLimitMotor2:e.physicsJoint.rotationalLimitMotor1||e.physicsJoint.rotationalLimitMotor||e.physicsJoint.limitMotor;n&&n.setLimit(t,void 0===i?-t:i)},t.prototype.syncMeshWithImpostor=function(e,t){var i=t.physicsBody;e.position.x=i.position.x,e.position.y=i.position.y,e.position.z=i.position.z,e.rotationQuaternion&&(e.rotationQuaternion.x=i.orientation.x,e.rotationQuaternion.y=i.orientation.y,e.rotationQuaternion.z=i.orientation.z,e.rotationQuaternion.w=i.orientation.s)},t.prototype.getRadius=function(e){return e.physicsBody.shapes.radius},t.prototype.getBoxSizeToRef=function(e,t){var i=e.physicsBody.shapes;t.x=2*i.halfWidth,t.y=2*i.halfHeight,t.z=2*i.halfDepth},t.prototype.dispose=function(){this.world.clear()},t})();e.OimoJSPlugin=t})(e||(e={}));var e;!(function(e){var t=(function(){function t(){}return t.GetTGAHeader=function(e){var t=0;return{id_length:e[t++],colormap_type:e[t++],image_type:e[t++],colormap_index:e[t++]|e[t++]<<8,colormap_length:e[t++]|e[t++]<<8,colormap_size:e[t++],origin:[e[t++]|e[t++]<<8,e[t++]|e[t++]<<8],width:e[t++]|e[t++]<<8,height:e[t++]|e[t++]<<8,pixel_size:e[t++],flags:e[t++]}},t.UploadContent=function(i,r){if(r.length<19)return void e.Tools.Error("Unable to load TGA file - Not enough data to contain header");var n=18,o=t.GetTGAHeader(r);if(o.id_length+n>r.length)return void e.Tools.Error("Unable to load TGA file - Not enough data");n+=o.id_length;var s=!1,a=!1,l=!1;switch(o.image_type){case t._TYPE_RLE_INDEXED:s=!0;case t._TYPE_INDEXED:a=!0;break;case t._TYPE_RLE_RGB:s=!0;case t._TYPE_RGB:break;case t._TYPE_RLE_GREY:s=!0;case t._TYPE_GREY:l=!0}var c,h,u=o.pixel_size>>3,f=o.width*o.height*u;if(a&&(h=r.subarray(n,n+=o.colormap_length*(o.colormap_size>>3))),s){c=new Uint8Array(f);for(var d,p,_,m=0,g=new Uint8Array(u);n>t._ORIGIN_SHIFT){default:case t._ORIGIN_UL:v=0,b=1,E=o.width,y=0,x=1,T=o.height;break;case t._ORIGIN_BL:v=0,b=1,E=o.width,y=o.height-1,x=-1,T=-1;break;case t._ORIGIN_UR:v=o.width-1,b=-1,E=-1,y=0,x=1,T=o.height;break;case t._ORIGIN_BR:v=o.width-1,b=-1,E=-1,y=o.height-1,x=-1,T=-1}var A="_getImageData"+(l?"Grey":"")+o.pixel_size+"bits",P=t[A](o,h,c,y,x,T,v,b,E);i.texImage2D(i.TEXTURE_2D,0,i.RGBA,o.width,o.height,0,i.RGBA,i.UNSIGNED_BYTE,P)},t._getImageData8bits=function(e,t,i,r,n,o,s,a,l){var c,h,u,f=i,d=t,p=e.width,_=e.height,m=0,g=new Uint8Array(p*_*4);for(u=r;u!==o;u+=n)for(h=s;h!==l;h+=a,m++)c=f[m],g[4*(h+p*u)+3]=255, g[4*(h+p*u)+2]=d[3*c+0],g[4*(h+p*u)+1]=d[3*c+1],g[4*(h+p*u)+0]=d[3*c+2];return g},t._getImageData16bits=function(e,t,i,r,n,o,s,a,l){var c,h,u,f=i,d=e.width,p=e.height,_=0,m=new Uint8Array(d*p*4);for(u=r;u!==o;u+=n)for(h=s;h!==l;h+=a,_+=2){c=f[_+0]+(f[_+1]<<8);var g=255*((31744&c)>>10)/31|0,v=255*((992&c)>>5)/31|0,y=255*(31&c)/31|0;m[4*(h+d*u)+0]=g,m[4*(h+d*u)+1]=v,m[4*(h+d*u)+2]=y,m[4*(h+d*u)+3]=32768&c?0:255}return m},t._getImageData24bits=function(e,t,i,r,n,o,s,a,l){var c,h,u=i,f=e.width,d=e.height,p=0,_=new Uint8Array(f*d*4);for(h=r;h!==o;h+=n)for(c=s;c!==l;c+=a,p+=3)_[4*(c+f*h)+3]=255,_[4*(c+f*h)+2]=u[p+0],_[4*(c+f*h)+1]=u[p+1],_[4*(c+f*h)+0]=u[p+2];return _},t._getImageData32bits=function(e,t,i,r,n,o,s,a,l){var c,h,u=i,f=e.width,d=e.height,p=0,_=new Uint8Array(f*d*4);for(h=r;h!==o;h+=n)for(c=s;c!==l;c+=a,p+=4)_[4*(c+f*h)+2]=u[p+0],_[4*(c+f*h)+1]=u[p+1],_[4*(c+f*h)+0]=u[p+2],_[4*(c+f*h)+3]=u[p+3];return _},t._getImageDataGrey8bits=function(e,t,i,r,n,o,s,a,l){var c,h,u,f=i,d=e.width,p=e.height,_=0,m=new Uint8Array(d*p*4);for(u=r;u!==o;u+=n)for(h=s;h!==l;h+=a,_++)c=f[_],m[4*(h+d*u)+0]=c,m[4*(h+d*u)+1]=c,m[4*(h+d*u)+2]=c,m[4*(h+d*u)+3]=255;return m},t._getImageDataGrey16bits=function(e,t,i,r,n,o,s,a,l){var c,h,u=i,f=e.width,d=e.height,p=0,_=new Uint8Array(f*d*4);for(h=r;h!==o;h+=n)for(c=s;c!==l;c+=a,p+=2)_[4*(c+f*h)+0]=u[p+0],_[4*(c+f*h)+1]=u[p+0],_[4*(c+f*h)+2]=u[p+0],_[4*(c+f*h)+3]=u[p+1];return _},t._TYPE_INDEXED=1,t._TYPE_RGB=2,t._TYPE_GREY=3,t._TYPE_RLE_INDEXED=9,t._TYPE_RLE_RGB=10,t._TYPE_RLE_GREY=11,t._ORIGIN_MASK=48,t._ORIGIN_SHIFT=4,t._ORIGIN_BL=0,t._ORIGIN_BR=1,t._ORIGIN_UL=2,t._ORIGIN_UR=3,t})();e.TGATools=t})(e||(e={}));var e;!(function(e){function t(e){return e.charCodeAt(0)+(e.charCodeAt(1)<<8)+(e.charCodeAt(2)<<16)+(e.charCodeAt(3)<<24)}function i(e){return String.fromCharCode(255&e,e>>8&255,e>>16&255,e>>24&255)}var r=t("DXT1"),n=t("DXT3"),o=t("DXT5"),s=t("DX10"),a=(function(){function t(){}return t.GetDDSInfo=function(t){var i=new Int32Array(t,0,31),a=new Int32Array(t,0,35),l=1;131072&i[2]&&(l=Math.max(1,i[7]));var c=i[21],h=c===s?a[32]:0,u=e.Engine.TEXTURETYPE_UNSIGNED_INT;switch(c){case 113:u=e.Engine.TEXTURETYPE_HALF_FLOAT;break;case 116:u=e.Engine.TEXTURETYPE_FLOAT;break;case s:if(10===h){u=e.Engine.TEXTURETYPE_HALF_FLOAT;break}}return{width:i[4],height:i[3],mipmapCount:l,isFourCC:4==(4&i[20]),isRGB:64==(64&i[20]),isLuminance:131072==(131072&i[20]),isCube:512==(512&i[28]),isCompressed:c===r||c===n||c===o,dxgiFormat:h,textureType:u}},t._ToHalfFloat=function(e){t._FloatView||(t._FloatView=new Float32Array(1),t._Int32View=new Int32Array(t._FloatView.buffer)),t._FloatView[0]=e;var i=t._Int32View[0],r=i>>16&32768,n=i>>12&2047,o=i>>23&255;return o<103?r:o>142?(r|=31744,r|=(255==o?0:1)&&8388607&i):o<113?(n|=2048,r|=(n>>114-o)+(n>>113-o&1)):(r|=o-112<<10|n>>1,r+=1&n)},t._FromHalfFloat=function(e){var t=(32768&e)>>15,i=(31744&e)>>10,r=1023&e;return 0===i?(t?-1:1)*Math.pow(2,-14)*(r/Math.pow(2,10)):31==i?r?NaN:1/0*(t?-1:1):(t?-1:1)*Math.pow(2,i-15)*(1+r/Math.pow(2,10))},t._GetHalfFloatAsFloatRGBAArrayBuffer=function(e,i,r,n,o,s){for(var a=new Float32Array(n),l=new Uint16Array(o,r),c=0,h=0;h>8)},t._GetRGBArrayBuffer=function(e,t,i,r,n,o,s,a){for(var l=new Uint8Array(r),c=new Uint8Array(n,i),h=0,u=0;u>8&65280|e>>24&255},t.prototype.uploadLevels=function(e,i){switch(this.loadType){case t.COMPRESSED_2D:this._upload2DCompressedLevels(e,i);break;case t.TEX_2D:case t.COMPRESSED_3D:case t.TEX_3D:}},t.prototype._upload2DCompressedLevels=function(e,i){for(var r=t.HEADER_LEN+this.bytesOfKeyValueData,n=this.pixelWidth,o=this.pixelHeight,s=i?this.numberOfMipmapLevels:1,a=0;a0?(this._meshes[i]=this._meshes[this._numMeshes],this._impostors[i]=this._impostors[this._numMeshes],this._meshes[this._numMeshes]=null,this._impostors[this._numMeshes]=null):(this._meshes[0]=null,this._impostors[0]=null),t=!0;break}t&&0===this._numMeshes&&this._scene.unregisterBeforeRender(this._renderFunction)}},t.prototype._getDebugMaterial=function(t){return this._debugMaterial||(this._debugMaterial=new e.StandardMaterial("",t),this._debugMaterial.wireframe=!0),this._debugMaterial},t.prototype._getDebugBoxMesh=function(t){return this._debugBoxMesh||(this._debugBoxMesh=e.MeshBuilder.CreateBox("physicsBodyBoxViewMesh",{size:1},t),this._debugBoxMesh.renderingGroupId=1,this._debugBoxMesh.rotationQuaternion=e.Quaternion.Identity(),this._debugBoxMesh.material=this._getDebugMaterial(t),t.removeMesh(this._debugBoxMesh)),this._debugBoxMesh.createInstance("physicsBodyBoxViewInstance")},t.prototype._getDebugSphereMesh=function(t){return this._debugSphereMesh||(this._debugSphereMesh=e.MeshBuilder.CreateSphere("physicsBodySphereViewMesh",{diameter:1},t),this._debugSphereMesh.renderingGroupId=1,this._debugSphereMesh.rotationQuaternion=e.Quaternion.Identity(),this._debugSphereMesh.material=this._getDebugMaterial(t),t.removeMesh(this._debugSphereMesh)),this._debugSphereMesh.createInstance("physicsBodyBoxViewInstance")},t.prototype._getDebugMesh=function(t,i){var r=null;if(t.type==e.PhysicsImpostor.BoxImpostor)r=this._getDebugBoxMesh(i),t.getBoxSizeToRef(r.scaling);else if(t.type==e.PhysicsImpostor.SphereImpostor){r=this._getDebugSphereMesh(i);var n=t.getRadius();r.scaling.x=2*n,r.scaling.y=2*n,r.scaling.z=2*n}return r},t.prototype.dispose=function(){for(var e=0;e=0;s--){var a=t[s],l=a.getParent();if(l){var c=this._debugLines[n];c||(c=[e.Vector3.Zero(),e.Vector3.Zero()],this._debugLines[n]=c),a.getAbsolutePositionToRef(this.mesh,c[0]),l.getAbsolutePositionToRef(this.mesh,c[1]),c[0].subtractInPlace(o),c[1].subtractInPlace(o),n++}}},t.prototype.update=function(){this.autoUpdateBonesMatrices&&this.skeleton.computeAbsoluteTransforms(),void 0===this.skeleton.bones[0].length?this._getLinesForBonesNoLength(this.skeleton.bones,this.mesh.getWorldMatrix()):this._getLinesForBonesWithLength(this.skeleton.bones,this.mesh.getWorldMatrix()),this._debugMesh?e.MeshBuilder.CreateLineSystem("",{lines:this._debugLines,updatable:!0,instance:this._debugMesh},this._scene):(this._debugMesh=e.MeshBuilder.CreateLineSystem("",{lines:this._debugLines,updatable:!0,instance:null},this._scene),this._debugMesh.renderingGroupId=this.renderingGroupId),this._debugMesh.position.copyFrom(this.mesh.position),this._debugMesh.color=this.color},t.prototype.dispose=function(){this._debugMesh&&(this.isEnabled=!1,this._debugMesh.dispose(),this._debugMesh=null)},t})(),t})();e.Debug=t})(e||(e={}));var e;!(function(e){var t=(function(){function t(e){this.ray=e}return t.CreateAndShow=function(e,i,r){var n=new t(e);return n.show(i,r),n},t.prototype.show=function(t,i){if(!this._renderFunction&&this.ray){var r=this.ray;this._renderFunction=this._render.bind(this),this._scene=t,this._renderPoints=[r.origin,r.origin.add(r.direction.scale(r.length))],this._renderLine=e.Mesh.CreateLines("ray",this._renderPoints,t,!0),this._renderFunction&&this._scene.registerBeforeRender(this._renderFunction)}i&&this._renderLine&&this._renderLine.color.copyFrom(i)},t.prototype.hide=function(){this._renderFunction&&this._scene&&(this._scene.unregisterBeforeRender(this._renderFunction),this._scene=null,this._renderFunction=null,this._renderLine&&(this._renderLine.dispose(),this._renderLine=null),this._renderPoints=[])},t.prototype._render=function(){var t=this.ray;if(t){var i=this._renderPoints[1],r=Math.min(t.length,1e6);i.copyFrom(t.direction),i.scaleInPlace(r),i.addInPlace(t.origin),e.Mesh.CreateLines("ray",this._renderPoints,this._scene,!0,this._renderLine)}},t.prototype.attachToMesh=function(t,i,r,n){this._attachedToMesh=t;var o=this.ray;o&&(o.direction||(o.direction=e.Vector3.Zero()),o.origin||(o.origin=e.Vector3.Zero()),n&&(o.length=n),r||(r=e.Vector3.Zero()),i||(i=new e.Vector3(0,0,-1)),this._meshSpaceDirection?(this._meshSpaceDirection.copyFrom(i),this._meshSpaceOrigin.copyFrom(r)):(this._meshSpaceDirection=i.clone(),this._meshSpaceOrigin=r.clone()),this._updateToMeshFunction||(this._updateToMeshFunction=this._updateToMesh.bind(this),this._attachedToMesh.getScene().registerBeforeRender(this._updateToMeshFunction)),this._updateToMesh())},t.prototype.detachFromMesh=function(){this._attachedToMesh&&(this._updateToMeshFunction&&this._attachedToMesh.getScene().unregisterBeforeRender(this._updateToMeshFunction),this._attachedToMesh=null,this._updateToMeshFunction=null)},t.prototype._updateToMesh=function(){var t=this.ray;if(this._attachedToMesh&&t){if(this._attachedToMesh._isDisposed)return void this.detachFromMesh();this._attachedToMesh.getDirectionToRef(this._meshSpaceDirection,t.direction),e.Vector3.TransformCoordinatesToRef(this._meshSpaceOrigin,this._attachedToMesh.getWorldMatrix(),t.origin)}},t.prototype.dispose=function(){this.hide(),this.detachFromMesh(),this.ray=null},t})();e.RayHelper=t})(e||(e={}));var e;!(function(e){var t=(function(){function t(e){this.BJSINSPECTOR="undefined"!=typeof INSPECTOR?INSPECTOR:void 0,this._scene=e}return t.prototype._createInspector=function(e){void 0===e&&(e={});var t=e.popup||!1,i=e.initialTab||0,r=e.parentElement||null;this._inspector||(this.BJSINSPECTOR=this.BJSINSPECTOR||"undefined"!=typeof INSPECTOR?INSPECTOR:void 0,this._inspector=new this.BJSINSPECTOR.Inspector(this._scene,t,i,r,e.newColors))},t.prototype.isVisible=function(){return!!this._inspector},t.prototype.hide=function(){if(this._inspector){try{this._inspector.dispose()}catch(e){}this._inspector=null}},t.prototype.show=function(i){void 0===i&&(i={}),void 0===this.BJSINSPECTOR?e.Tools.LoadScript(t.InspectorURL,this._createInspector.bind(this,i)):this._createInspector(i)},t.InspectorURL="https://preview.babylonjs.com/inspector/babylon.inspector.bundle.js",t})();e.DebugLayer=t})(e||(e={}));var e;!(function(e){var t=(function(){function t(t){this.frontColor=new e.Color3(1,1,1),this.backColor=new e.Color3(.1,.1,.1),this.showBackLines=!0,this.renderList=new e.SmartArray(32),this._vertexBuffers={},this._scene=t}return t.prototype._prepareRessources=function(){if(!this._colorShader){this._colorShader=new e.ShaderMaterial("colorShader",this._scene,"color",{attributes:[e.VertexBuffer.PositionKind],uniforms:["world","viewProjection","color"]});var t=this._scene.getEngine(),i=e.VertexData.CreateBox({size:1});this._vertexBuffers[e.VertexBuffer.PositionKind]=new e.VertexBuffer(t,i.positions,e.VertexBuffer.PositionKind,!1),this._createIndexBuffer()}},t.prototype._createIndexBuffer=function(){var e=this._scene.getEngine();this._indexBuffer=e.createIndexBuffer([0,1,1,2,2,3,3,0,4,5,5,6,6,7,7,4,0,7,1,6,2,5,3,4])},t.prototype._rebuild=function(){var t=this._vertexBuffers[e.VertexBuffer.PositionKind];t&&t._rebuild(),this._createIndexBuffer()},t.prototype.reset=function(){this.renderList.reset()},t.prototype.render=function(){if(0!==this.renderList.length&&(this._prepareRessources(),this._colorShader.isReady())){var t=this._scene.getEngine();t.setDepthWrite(!1),this._colorShader._preBind();for(var i=0;i=0&&(this._targets.splice(t,1),e.onInfluenceChanged.remove(this._targetObservable.splice(t,1)[0]),this._syncActiveTargets(!0))},t.prototype.serialize=function(){var e={};e.id=this.uniqueId,e.targets=[];for(var t=0,i=this._targets;tthis.capacity&&this._depth=2&&t.onControllersAttachedObservable.notifyObservers(t.controllers)}}}))},i})(e.FreeCamera);e.WebVRFreeCamera=t})(e||(e={}));var e;!(function(e){var t=(function(t){function i(i,r,n){var o=t.call(this,i,r,n)||this;return o._quaternionCache=new e.Quaternion,o.inputs.addDeviceOrientation(),o}return __extends(i,t),i.prototype.getClassName=function(){return"DeviceOrientationCamera"},i.prototype._checkInputs=function(){t.prototype._checkInputs.call(this),this._quaternionCache.copyFrom(this.rotationQuaternion),this._initialQuaternion&&this._initialQuaternion.multiplyToRef(this.rotationQuaternion,this.rotationQuaternion)},i.prototype.resetToCurrentRotation=function(t){var i=this;void 0===t&&(t=e.Axis.Y),this.rotationQuaternion&&(this._initialQuaternion||(this._initialQuaternion=new e.Quaternion),this._initialQuaternion.copyFrom(this._quaternionCache||this.rotationQuaternion),["x","y","z"].forEach((function(e){t[e]?i._initialQuaternion[e]*=-1:i._initialQuaternion[e]=0})),this._initialQuaternion.normalize(),this._initialQuaternion.multiplyToRef(this.rotationQuaternion,this.rotationQuaternion))},i})(e.FreeCamera);e.DeviceOrientationCamera=t})(e||(e={}));var e;!(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 __extends(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 __extends(i,t),i.prototype.getClassName=function(){return"VRDeviceOrientationGamepadCamera"},i})(t);e.VRDeviceOrientationGamepadCamera=i;var r=(function(t){function i(i,r,n,o,s,a,l,c){void 0===l&&(l=!0),void 0===c&&(c=e.VRCameraMetrics.GetDefault());var h=t.call(this,i,r,n,o,s,a)||this;return c.compensateDistortion=l,h.setCameraRigMode(e.Camera.RIG_MODE_VR,{vrCameraMetrics:c}),h.inputs.addVRDeviceOrientation(),h}return __extends(i,t),i.prototype.getClassName=function(){return"VRDeviceOrientationArcRotateCamera"},i})(e.ArcRotateCamera);e.VRDeviceOrientationArcRotateCamera=r})(e||(e={}));var e;!(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 __extends(i,t),i.prototype.getClassName=function(){return"AnaglyphFreeCamera"},i})(e.FreeCamera);e.AnaglyphFreeCamera=t;var i=(function(t){function i(i,r,n,o,s,a,l){var c=t.call(this,i,r,n,o,s,l)||this;return c.interaxialDistance=a,c.setCameraRigMode(e.Camera.RIG_MODE_STEREOSCOPIC_ANAGLYPH,{interaxialDistance:a}),c}return __extends(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 __extends(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 __extends(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 __extends(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,l,c){var h=t.call(this,i,r,n,o,s,c)||this;return h.interaxialDistance=a,h.isStereoscopicSideBySide=l,h.setCameraRigMode(l?e.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL:e.Camera.RIG_MODE_STEREOSCOPIC_OVERUNDER,{interaxialDistance:a}),h}return __extends(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 __extends(i,t),i.prototype.getClassName=function(){return"StereoscopicGamepadCamera"},i})(e.GamepadCamera);e.StereoscopicGamepadCamera=a;var l=(function(t){function i(i,r,n,o,s){var a=t.call(this,i,r,s)||this;return a.interaxialDistance=n,a.isStereoscopicSideBySide=o,a.setCameraRigMode(o?e.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL:e.Camera.RIG_MODE_STEREOSCOPIC_OVERUNDER,{interaxialDistance:n}),a}return __extends(i,t),i.prototype.getClassName=function(){return"StereoscopicUniversalCamera"},i})(e.UniversalCamera);e.StereoscopicUniversalCamera=l})(e||(e={}));var e;!(function(e){var t=(function(){function t(i,r){if(void 0===r&&(r=null),this.scene=i,this._pointerDownOnMeshAsked=!1,this._isActionableMesh=!1,this._teleportationRequestInitiated=!1,this._teleportationBackRequestInitiated=!1,this._dpadPressed=!0,this._activePointer=!1,this._id=t._idCounter++,r)this._gazeTracker=r.clone("gazeTracker");else{this._gazeTracker=e.Mesh.CreateTorus("gazeTracker",.0035,.0025,20,i,!1),this._gazeTracker.bakeCurrentTransformIntoVertices(),this._gazeTracker.isPickable=!1,this._gazeTracker.isVisible=!1;var n=new e.StandardMaterial("targetMat",i);n.specularColor=e.Color3.Black(),n.emissiveColor=new e.Color3(.7,.7,.7),n.backFaceCulling=!1,this._gazeTracker.material=n}}return t.prototype._getForwardRay=function(t){return new e.Ray(e.Vector3.Zero(),new e.Vector3(0,0,t))},t.prototype._selectionPointerDown=function(){this._pointerDownOnMeshAsked=!0,this._currentMeshSelected&&this._currentHit&&this.scene.simulatePointerDown(this._currentHit,{pointerId:this._id})},t.prototype._selectionPointerUp=function(){this._currentMeshSelected&&this._currentHit&&this.scene.simulatePointerUp(this._currentHit,{pointerId:this._id}),this._pointerDownOnMeshAsked=!1},t.prototype._activatePointer=function(){this._activePointer=!0},t.prototype._deactivatePointer=function(){this._activePointer=!1},t.prototype._updatePointerDistance=function(e){},t.prototype.dispose=function(){this._interactionsEnabled=!1,this._teleportationEnabled=!1},t._idCounter=0,t})(),i=(function(t){function i(i,r,n){var o=t.call(this,r,n)||this;o.webVRController=i,o._laserPointer=e.Mesh.CreateCylinder("laserPointer",1,.004,2e-4,20,1,r,!1);var s=new e.StandardMaterial("laserPointerMat",r);if(s.emissiveColor=new e.Color3(.7,.7,.7),s.alpha=.6,o._laserPointer.material=s,o._laserPointer.rotation.x=Math.PI/2,o._laserPointer.position.z=-.5,o._laserPointer.isVisible=!1,!i.mesh){var a=new e.Mesh("preloadControllerMesh",r),l=new e.Mesh(e.PoseEnabledController.POINTING_POSE,r);l.rotation.x=-.7,a.addChild(l),i.attachToMesh(a)}return o._setLaserPointerParent(i.mesh),o}return __extends(i,t),i.prototype._getForwardRay=function(e){return this.webVRController.getForwardRay(e)},i.prototype._activatePointer=function(){t.prototype._activatePointer.call(this),this._laserPointer.isVisible=!0},i.prototype._deactivatePointer=function(){t.prototype._deactivatePointer.call(this),this._laserPointer.isVisible=!1},i.prototype._setLaserPointerColor=function(e){this._laserPointer.material.emissiveColor=e},i.prototype._setLaserPointerParent=function(t){var i=function(e){e.name+=" laserPointer",e.getChildMeshes().forEach((function(e){i(e)}))};i(t);var r=t.getChildMeshes();this.webVRController._pointingPoseNode=null;for(var n=0;n=0){t=r[n],this.webVRController._pointingPoseNode=t;break}this._laserPointer.parent=t},i.prototype._updatePointerDistance=function(e){this._laserPointer.scaling.y=e,this._laserPointer.position.z=-e/2},i.prototype.dispose=function(){t.prototype.dispose.call(this),this._laserPointer.dispose()},i})(t),r=(function(t){function i(e,i){var r=t.call(this,i)||this;return r.getCamera=e,r}return __extends(i,t),i.prototype._getForwardRay=function(t){var i=this.getCamera();return i?i.getForwardRay(t):new e.Ray(e.Vector3.Zero(),e.Vector3.Forward())},i})(t),n=(function(){function t(t,n){void 0===n&&(n={});var o=this;if(this.webVROptions=n,this._webVRsupported=!1,this._webVRready=!1,this._webVRrequesting=!1,this._webVRpresenting=!1,this._fullscreenVRpresenting=!1,this.onEnteringVRObservable=new e.Observable,this.onExitingVRObservable=new e.Observable,this.onControllerMeshLoadedObservable=new e.Observable,this._useCustomVRButton=!1,this._teleportationRequested=!1,this._teleportActive=!1,this._floorMeshesCollection=[],this._rotationAllowed=!0,this._teleportBackwardsVector=new e.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 e.Vector3(0,0,0),this._padSensibilityUp=.65,this._padSensibilityDown=.35,this.leftController=null,this.rightController=null,this.onNewMeshSelected=new e.Observable,this.onNewMeshPicked=new e.Observable,this.onBeforeCameraTeleport=new e.Observable,this.onAfterCameraTeleport=new e.Observable,this.onSelectedMeshUnselected=new e.Observable,this.teleportationEnabled=!0,this._teleportationInitialized=!1,this._interactionsEnabled=!1,this._interactionsRequested=!1,this._displayGaze=!0,this._displayLaserPointer=!0,this._onResize=function(){o.moveButtonToBottomRight(),o._fullscreenVRpresenting&&o._webVRready&&o.exitVR()},this._onFullscreenChange=function(){void 0!==document.fullscreen?o._fullscreenVRpresenting=document.fullscreen:void 0!==document.mozFullScreen?o._fullscreenVRpresenting=document.mozFullScreen:void 0!==document.webkitIsFullScreen?o._fullscreenVRpresenting=document.webkitIsFullScreen:void 0!==document.msIsFullScreen&&(o._fullscreenVRpresenting=document.msIsFullScreen),!o._fullscreenVRpresenting&&o._canvas&&(o.exitVR(),o._useCustomVRButton||(o._btnVR.style.top=o._canvas.offsetTop+o._canvas.offsetHeight-70+"px",o._btnVR.style.left=o._canvas.offsetLeft+o._canvas.offsetWidth-100+"px"))},this.beforeRender=function(){o.leftController&&o.leftController._activePointer&&o._castRayAndSelectObject(o.leftController),o.rightController&&o.rightController._activePointer&&o._castRayAndSelectObject(o.rightController),o.leftController&&o.leftController._activePointer||o.rightController&&o.rightController._activePointer?o._cameraGazer._gazeTracker.isVisible=!1:o._castRayAndSelectObject(o._cameraGazer)},this._onNewGamepadConnected=function(t){if(t.type!==e.Gamepad.POSE_ENABLED)t.leftStick&&t.onleftstickchanged((function(e){o._teleportationInitialized&&o.teleportationEnabled&&(!o.leftController&&!o.rightController||o.leftController&&!o.leftController._activePointer&&o.rightController&&!o.rightController._activePointer)&&(o._checkTeleportWithRay(e,o._cameraGazer),o._checkTeleportBackwards(e,o._cameraGazer))})),t.rightStick&&t.onrightstickchanged((function(e){o._teleportationInitialized&&o._checkRotate(e,o._cameraGazer)})),t.type===e.Gamepad.XBOX&&(t.onbuttondown((function(t){o._interactionsEnabled&&t===e.Xbox360Button.A&&o._cameraGazer._selectionPointerDown()})),t.onbuttonup((function(t){o._interactionsEnabled&&t===e.Xbox360Button.A&&o._cameraGazer._selectionPointerUp()})));else{var r=t,n=new i(r,o._scene,o._cameraGazer._gazeTracker);"right"===r.hand||o.leftController&&o.leftController.webVRController!=r?o.rightController=n:o.leftController=n,o._tryEnableInteractionOnController(n)}},this._tryEnableInteractionOnController=function(e){ o._interactionsRequested&&!e._interactionsEnabled&&o._enableInteractionOnController(e),o._teleportationRequested&&!e._teleportationEnabled&&o._enableTeleportationOnController(e)},this._onNewGamepadDisconnected=function(t){t instanceof e.WebVRController&&("left"===t.hand&&null!=o.leftController&&(o.leftController.dispose(),o.leftController=null),"right"===t.hand&&null!=o.rightController&&(o.rightController.dispose(),o.rightController=null))},this._workingVector=e.Vector3.Zero(),this._workingQuaternion=e.Quaternion.Identity(),this._workingMatrix=e.Matrix.Identity(),this._scene=t,this._canvas=t.getEngine().getRenderingCanvas(),void 0===n.createFallbackVRDeviceOrientationFreeCamera&&(n.createFallbackVRDeviceOrientationFreeCamera=!0),void 0===n.createDeviceOrientationCamera&&(n.createDeviceOrientationCamera=!0),void 0===n.defaultHeight&&(n.defaultHeight=1.7),n.useCustomVRButton&&(this._useCustomVRButton=!0,n.customVRButton&&(this._btnVR=n.customVRButton)),n.rayLength&&(this._rayLength=n.rayLength),this._defaultHeight=n.defaultHeight,n.positionScale&&(this._rayLength*=n.positionScale,this._defaultHeight*=n.positionScale),this._scene.activeCamera?this._position=this._scene.activeCamera.position.clone():this._position=new e.Vector3(0,this._defaultHeight,0),n.createDeviceOrientationCamera||!this._scene.activeCamera){if(this._deviceOrientationCamera=new e.DeviceOrientationCamera("deviceOrientationVRHelper",this._position.clone(),t),this._scene.activeCamera&&(this._deviceOrientationCamera.minZ=this._scene.activeCamera.minZ,this._deviceOrientationCamera.maxZ=this._scene.activeCamera.maxZ,this._scene.activeCamera instanceof e.TargetCamera&&this._scene.activeCamera.rotation)){var s=this._scene.activeCamera;s.rotationQuaternion?this._deviceOrientationCamera.rotationQuaternion.copyFrom(s.rotationQuaternion):this._deviceOrientationCamera.rotationQuaternion.copyFrom(e.Quaternion.RotationYawPitchRoll(s.rotation.y,s.rotation.x,s.rotation.z)),this._deviceOrientationCamera.rotation=s.rotation.clone()}this._scene.activeCamera=this._deviceOrientationCamera,this._canvas&&this._scene.activeCamera.attachControl(this._canvas)}else this._existingCamera=this._scene.activeCamera;if(n.createFallbackVRDeviceOrientationFreeCamera&&(this._vrDeviceOrientationCamera=new e.VRDeviceOrientationFreeCamera("VRDeviceOrientationVRHelper",this._position,this._scene)),this._webVRCamera=new e.WebVRFreeCamera("WebVRHelper",this._position,this._scene,n),this._webVRCamera.useStandingMatrix(),this._cameraGazer=new r(function(){return o.currentVRCamera},t),!this._useCustomVRButton){this._btnVR=document.createElement("BUTTON"),this._btnVR.className="babylonVRicon",this._btnVR.id="babylonVRiconbtn",this._btnVR.title="Click to switch to VR";var a=".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) }";a+=".babylonVRicon.vrdisplaypresenting { display: none; }";var l=document.createElement("style");l.appendChild(document.createTextNode(a)),document.getElementsByTagName("head")[0].appendChild(l),this.moveButtonToBottomRight()}this._btnVR&&this._btnVR.addEventListener("click",(function(){o.isInVRMode?o.exitVR():o.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),n.createFallbackVRDeviceOrientationFreeCamera?this.displayVRButton():this._scene.getEngine().onVRDisplayChangedObservable.add((function(e){e.vrDisplay&&o.displayVRButton()})),this._onKeyDown=function(e){27===e.keyCode&&o.isInVRMode&&o.exitVR()},document.addEventListener("keydown",this._onKeyDown),this._scene.onPrePointerObservable.add((function(e,t){o.isInVRMode&&(o.exitVR(),o._fullscreenVRpresenting&&o._scene.getEngine().switchFullscreen(!0))}),e.PointerEventTypes.POINTERDOUBLETAP,!1),this._onVRDisplayChanged=function(e){return o.onVRDisplayChanged(e)},this._onVrDisplayPresentChange=function(){return o.onVrDisplayPresentChange()},this._onVRRequestPresentStart=function(){o._webVRrequesting=!0,o.updateButtonVisibility()},this._onVRRequestPresentComplete=function(e){o._webVRrequesting=!1,o.updateButtonVisibility()},t.getEngine().onVRDisplayChangedObservable.add(this._onVRDisplayChanged),t.getEngine().onVRRequestPresentStart.add(this._onVRRequestPresentStart),t.getEngine().onVRRequestPresentComplete.add(this._onVRRequestPresentComplete),window.addEventListener("vrdisplaypresentchange",this._onVrDisplayPresentChange),t.onDisposeObservable.add((function(){o.dispose()})),this._webVRCamera.onControllerMeshLoadedObservable.add((function(e){return o._onDefaultMeshLoaded(e)})),this._scene.gamepadManager.onGamepadConnectedObservable.add(this._onNewGamepadConnected),this._scene.gamepadManager.onGamepadDisconnectedObservable.add(this._onNewGamepadDisconnected),this.updateButtonVisibility(),this._circleEase=new e.CircleEase,this._circleEase.setEasingMode(e.EasingFunction.EASINGMODE_EASEINOUT)}return Object.defineProperty(t.prototype,"onEnteringVR",{get:function(){return this.onEnteringVRObservable},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"onExitingVR",{get:function(){return this.onExitingVRObservable},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"onControllerMeshLoaded",{get:function(){return this.onControllerMeshLoadedObservable},enumerable:!0,configurable:!0}),Object.defineProperty(t.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(t.prototype,"gazeTrackerMesh",{get:function(){return this._cameraGazer._gazeTracker},set:function(e){e&&(this._cameraGazer._gazeTracker=e,this._cameraGazer._gazeTracker.bakeCurrentTransformIntoVertices(),this._cameraGazer._gazeTracker.isPickable=!1,this._cameraGazer._gazeTracker.isVisible=!1,this._cameraGazer._gazeTracker.name="gazeTracker",this.leftController&&(this.leftController._gazeTracker=this._cameraGazer._gazeTracker.clone("gazeTracker")),this.rightController&&(this.rightController._gazeTracker=this._cameraGazer._gazeTracker.clone("gazeTracker")))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"displayGaze",{get:function(){return this._displayGaze},set:function(e){this._displayGaze=e,e||(this._cameraGazer._gazeTracker.isVisible=!1,this.leftController&&(this.leftController._gazeTracker.isVisible=!1),this.rightController&&(this.rightController._gazeTracker.isVisible=!1))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"displayLaserPointer",{get:function(){return this._displayLaserPointer},set:function(e){this._displayLaserPointer=e,e?this.rightController?this.rightController._activatePointer():this.leftController&&this.leftController._activatePointer():(this.rightController&&(this.rightController._deactivatePointer(),this.rightController._gazeTracker.isVisible=!1),this.leftController&&(this.leftController._deactivatePointer(),this.leftController._gazeTracker.isVisible=!1))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"deviceOrientationCamera",{get:function(){return this._deviceOrientationCamera},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"currentVRCamera",{get:function(){return this._webVRready?this._webVRCamera:this._scene.activeCamera},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"webVRCamera",{get:function(){return this._webVRCamera},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"vrDeviceOrientationCamera",{get:function(){return this._vrDeviceOrientationCamera},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"_teleportationRequestInitiated",{get:function(){return this._cameraGazer._teleportationRequestInitiated||null!==this.leftController&&this.leftController._teleportationRequestInitiated||null!==this.rightController&&this.rightController._teleportationRequestInitiated},enumerable:!0,configurable:!0}),t.prototype._onDefaultMeshLoaded=function(t){this.leftController&&this.leftController.webVRController==t&&t.mesh&&this.leftController._setLaserPointerParent(t.mesh),this.rightController&&this.rightController.webVRController==t&&t.mesh&&this.rightController._setLaserPointerParent(t.mesh);try{this.onControllerMeshLoadedObservable.notifyObservers(t)}catch(t){e.Tools.Warn("Error in your custom logic onControllerMeshLoaded: "+t)}},Object.defineProperty(t.prototype,"isInVRMode",{get:function(){return this._webVRpresenting||this._fullscreenVRpresenting},enumerable:!0,configurable:!0}),t.prototype.onVrDisplayPresentChange=function(){var t=this._scene.getEngine().getVRDevice();if(t){var i=this._webVRpresenting;this._webVRpresenting=t.isPresenting,i&&!this._webVRpresenting&&this.exitVR()}else e.Tools.Warn("Detected VRDisplayPresentChange on an unknown VRDisplay. Did you can enterVR on the vrExperienceHelper?");this.updateButtonVisibility()},t.prototype.onVRDisplayChanged=function(e){this._webVRsupported=e.vrSupported,this._webVRready=!!e.vrDisplay,this._webVRpresenting=e.vrDisplay&&e.vrDisplay.isPresenting,this.updateButtonVisibility()},t.prototype.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")},t.prototype.displayVRButton=function(){this._useCustomVRButton||this._btnVRDisplayed||(document.body.appendChild(this._btnVR),this._btnVRDisplayed=!0)},t.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")))},t.prototype.enterVR=function(){if(this.onEnteringVRObservable)try{this.onEnteringVRObservable.notifyObservers(this)}catch(t){e.Tools.Warn("Error in your custom logic onEnteringVR: "+t)}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))},t.prototype.exitVR=function(){if(this.onExitingVRObservable)try{this.onExitingVRObservable.notifyObservers(this)}catch(t){e.Tools.Warn("Error in your custom logic onExitingVR: "+t)}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(t.prototype,"position",{get:function(){return this._position},set:function(e){this._position=e,this._scene.activeCamera&&(this._scene.activeCamera.position=e)},enumerable:!0,configurable:!0}),t.prototype.enableInteractions=function(){var e=this;this._interactionsEnabled||(this._interactionsRequested=!0,this.leftController&&this._enableInteractionOnController(this.leftController),this.rightController&&this._enableInteractionOnController(this.rightController),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)},t.prototype._isTeleportationFloor=function(e){for(var t=0;t-1||this._floorMeshesCollection.push(e))},t.prototype.removeFloorMesh=function(e){if(this._floorMeshesCollection){var t=this._floorMeshesCollection.indexOf(e);-1!==t&&this._floorMeshesCollection.splice(t,1)}},t.prototype.enableTeleportation=function(t){if(void 0===t&&(t={}),!this._teleportationInitialized){this._teleportationRequested=!0,this.enableInteractions(),t.floorMeshName&&(this._floorMeshName=t.floorMeshName),t.floorMeshes&&(this._floorMeshesCollection=t.floorMeshes),null!=this.leftController&&this._enableTeleportationOnController(this.leftController),null!=this.rightController&&this._enableTeleportationOnController(this.rightController);var i=new e.ImageProcessingConfiguration;i.vignetteColor=new e.Color4(0,0,0,0),i.vignetteEnabled=!0,this._postProcessMove=new e.ImageProcessingPostProcess("postProcessMove",1,this._webVRCamera,void 0,void 0,void 0,void 0,i),this._webVRCamera.detachPostProcess(this._postProcessMove),this._teleportationInitialized=!0,this._isDefaultTeleportationTarget&&(this._createTeleportationCircles(),this._teleportationTarget.scaling.scaleInPlace(this._webVRCamera.deviceScaleFactor))}},t.prototype._enableInteractionOnController=function(e){var t=this;e.webVRController.mesh&&(e._interactionsEnabled=!0,e._activatePointer(),e.webVRController.onMainButtonStateChangedObservable.add((function(i){t._displayLaserPointer&&1===i.value&&(e._activePointer?e._deactivatePointer():e._activatePointer(),t.displayGaze&&(e._gazeTracker.isVisible=e._activePointer))})),e.webVRController.onTriggerStateChangedObservable.add((function(i){e._pointerDownOnMeshAsked?i.valuet._padSensibilityUp&&e._selectionPointerDown()})))},t.prototype._checkTeleportWithRay=function(e,t){this._teleportationRequestInitiated&&!t._teleportationRequestInitiated||(t._teleportationRequestInitiated?Math.sqrt(e.y*e.y+e.x*e.x)-this._padSensibilityDown&&(this._rotationLeftAsked=!1):e.x<-this._padSensibilityUp&&t._dpadPressed&&(this._rotationLeftAsked=!0,this._rotationAllowed&&this._rotateCamera(!1)),this._rotationRightAsked?e.xthis._padSensibilityUp&&t._dpadPressed&&(this._rotationRightAsked=!0,this._rotationAllowed&&this._rotateCamera(!0)))},t.prototype._checkTeleportBackwards=function(t,i){if(!i._teleportationRequestInitiated)if(t.y>this._padSensibilityUp&&i._dpadPressed){if(!i._teleportationBackRequestInitiated){if(!this.currentVRCamera)return;var r=e.Quaternion.FromRotationMatrix(this.currentVRCamera.getWorldMatrix().getRotationMatrix()),n=this.currentVRCamera.position;this.currentVRCamera.devicePosition&&this.currentVRCamera.deviceRotationQuaternion&&(r=this.currentVRCamera.deviceRotationQuaternion,n=this.currentVRCamera.devicePosition),r.toEulerAnglesToRef(this._workingVector),this._workingVector.z=0,this._workingVector.x=0,e.Quaternion.RotationYawPitchRollToRef(this._workingVector.y,this._workingVector.x,this._workingVector.z,this._workingQuaternion),this._workingQuaternion.toRotationMatrix(this._workingMatrix),e.Vector3.TransformCoordinatesToRef(this._teleportBackwardsVector,this._workingMatrix,this._workingVector);var o=new e.Ray(n,this._workingVector),s=this._scene.pickWithRay(o,this._raySelectionPredicate);s&&s.pickedPoint&&s.pickedMesh&&this._isTeleportationFloor(s.pickedMesh)&&s.distance<5&&this._teleportCamera(s.pickedPoint),i._teleportationBackRequestInitiated=!0}}else i._teleportationBackRequestInitiated=!1},t.prototype._enableTeleportationOnController=function(t){var i=this;t.webVRController.mesh&&(t._interactionsEnabled||this._enableInteractionOnController(t),t._interactionsEnabled=!0,t._teleportationEnabled=!0,t.webVRController.controllerType===e.PoseEnabledControllerType.VIVE&&(t._dpadPressed=!1,t.webVRController.onPadStateChangedObservable.add((function(e){t._dpadPressed=e.pressed,t._dpadPressed||(i._rotationLeftAsked=!1,i._rotationRightAsked=!1,t._teleportationBackRequestInitiated=!1)}))),t.webVRController.onPadValuesChangedObservable.add((function(e){i.teleportationEnabled&&(i._checkTeleportBackwards(e,t),i._checkTeleportWithRay(e,t)),i._checkRotate(e,t)})))},t.prototype._createTeleportationCircles=function(){this._teleportationTarget=e.Mesh.CreateGround("teleportationTarget",2,2,2,this._scene),this._teleportationTarget.isPickable=!1;var t=new e.DynamicTexture("DynamicTexture",512,this._scene,!0);t.hasAlpha=!0;var i=t.getContext();i.beginPath(),i.arc(256,256,200,0,2*Math.PI,!1),i.fillStyle=this._teleportationFillColor,i.fill(),i.lineWidth=10,i.strokeStyle=this._teleportationBorderColor,i.stroke(),i.closePath(),t.update();var r=new e.StandardMaterial("TextPlaneMaterial",this._scene);r.diffuseTexture=t,this._teleportationTarget.material=r;var n=e.Mesh.CreateTorus("torusTeleportation",.75,.1,25,this._scene,!1);n.isPickable=!1,n.parent=this._teleportationTarget;var o=new e.Animation("animationInnerCircle","position.y",30,e.Animation.ANIMATIONTYPE_FLOAT,e.Animation.ANIMATIONLOOPMODE_CYCLE),s=[];s.push({frame:0,value:0}),s.push({frame:30,value:.4}),s.push({frame:60,value:0}),o.setKeys(s);var a=new e.SineEase;a.setEasingMode(e.EasingFunction.EASINGMODE_EASEINOUT),o.setEasingFunction(a),n.animations=[],n.animations.push(o),this._scene.beginAnimation(n,0,60,!0),this._hideTeleportationTarget()},t.prototype._displayTeleportationTarget=function(){this._teleportActive=!0,this._teleportationInitialized&&(this._teleportationTarget.isVisible=!0,this._isDefaultTeleportationTarget&&(this._teleportationTarget.getChildren()[0].isVisible=!0))},t.prototype._hideTeleportationTarget=function(){this._teleportActive=!1,this._teleportationInitialized&&(this._teleportationTarget.isVisible=!1,this._isDefaultTeleportationTarget&&(this._teleportationTarget.getChildren()[0].isVisible=!1))},t.prototype._rotateCamera=function(t){var i=this;if(this.currentVRCamera instanceof e.FreeCamera){t?this._rotationAngle++:this._rotationAngle--,this.currentVRCamera.animations=[];var r=e.Quaternion.FromRotationMatrix(e.Matrix.RotationY(Math.PI/4*this._rotationAngle)),n=new e.Animation("animationRotation","rotationQuaternion",90,e.Animation.ANIMATIONTYPE_QUATERNION,e.Animation.ANIMATIONLOOPMODE_CONSTANT),o=[];o.push({frame:0,value:this.currentVRCamera.rotationQuaternion}),o.push({frame:6,value:r}),n.setKeys(o),n.setEasingFunction(this._circleEase),this.currentVRCamera.animations.push(n),this._postProcessMove.animations=[];var s=new e.Animation("animationPP","vignetteWeight",90,e.Animation.ANIMATIONTYPE_FLOAT,e.Animation.ANIMATIONLOOPMODE_CONSTANT),a=[];a.push({frame:0,value:0}),a.push({frame:3,value:4}),a.push({frame:6,value:0}),s.setKeys(a),s.setEasingFunction(this._circleEase),this._postProcessMove.animations.push(s);var l=new e.Animation("animationPP2","vignetteStretch",90,e.Animation.ANIMATIONTYPE_FLOAT,e.Animation.ANIMATIONLOOPMODE_CONSTANT),c=[];c.push({frame:0,value:0}),c.push({frame:3,value:10}),c.push({frame:6,value:0}),l.setKeys(c),l.setEasingFunction(this._circleEase),this._postProcessMove.animations.push(l),this._postProcessMove.imageProcessingConfiguration.vignetteWeight=0,this._postProcessMove.imageProcessingConfiguration.vignetteStretch=0,this._postProcessMove.samples=4,this._webVRCamera.attachPostProcess(this._postProcessMove),this._scene.beginAnimation(this._postProcessMove,0,6,!1,1,(function(){i._webVRCamera.detachPostProcess(i._postProcessMove)})),this._scene.beginAnimation(this.currentVRCamera,0,6,!1,1)}},t.prototype._moveTeleportationSelectorTo=function(t,i){if(t.pickedPoint){i._teleportationRequestInitiated&&(this._displayTeleportationTarget(),this._haloCenter.copyFrom(t.pickedPoint),this._teleportationTarget.position.copyFrom(t.pickedPoint));var r=t.getNormal(!0,!1);if(r){var n=e.Vector3.Cross(e.Axis.Y,r),o=e.Vector3.Cross(r,n);e.Vector3.RotationFromAxisToRef(o,r,n,this._teleportationTarget.rotation)}this._teleportationTarget.position.y+=.1}},t.prototype._teleportCamera=function(t){var i=this;if(this.currentVRCamera instanceof e.FreeCamera){this.webVRCamera.leftCamera?(this._workingVector.copyFrom(this.webVRCamera.leftCamera.globalPosition),this._workingVector.subtractInPlace(this.webVRCamera.position),t.subtractToRef(this._workingVector,this._workingVector)):this._workingVector.copyFrom(t),this.isInVRMode?this._workingVector.y+=this.webVRCamera.deviceDistanceToRoomGround()*this._webVRCamera.deviceScaleFactor:this._workingVector.y+=this._defaultHeight,this.onBeforeCameraTeleport.notifyObservers(this._workingVector),this.currentVRCamera.animations=[];var r=new e.Animation("animationCameraTeleportation","position",90,e.Animation.ANIMATIONTYPE_VECTOR3,e.Animation.ANIMATIONLOOPMODE_CONSTANT),n=[{frame:0,value:this.currentVRCamera.position},{frame:11,value:this._workingVector}];r.setKeys(n),r.setEasingFunction(this._circleEase),this.currentVRCamera.animations.push(r),this._postProcessMove.animations=[];var o=new e.Animation("animationPP","vignetteWeight",90,e.Animation.ANIMATIONTYPE_FLOAT,e.Animation.ANIMATIONLOOPMODE_CONSTANT),s=[];s.push({frame:0,value:0}),s.push({frame:5,value:8}),s.push({frame:11,value:0}),o.setKeys(s),this._postProcessMove.animations.push(o);var a=new e.Animation("animationPP2","vignetteStretch",90,e.Animation.ANIMATIONTYPE_FLOAT,e.Animation.ANIMATIONLOOPMODE_CONSTANT),l=[];l.push({frame:0,value:0}),l.push({frame:5,value:10}),l.push({frame:11,value:0}),a.setKeys(l),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,11,!1,1,(function(){i._webVRCamera.detachPostProcess(i._postProcessMove)})),this._scene.beginAnimation(this.currentVRCamera,0,11,!1,1,(function(){i.onAfterCameraTeleport.notifyObservers(i._workingVector)})),this._hideTeleportationTarget()}},t.prototype._castRayAndSelectObject=function(t){if(this.currentVRCamera instanceof e.FreeCamera){var i=this._scene.pickWithRay(t._getForwardRay(this._rayLength),this._raySelectionPredicate);if(i&&i.pickedPoint){if(this._displayGaze){var r=1;t._gazeTracker.isVisible=!0,t._isActionableMesh&&(r=3),t._gazeTracker.scaling.x=i.distance*r,t._gazeTracker.scaling.y=i.distance*r,t._gazeTracker.scaling.z=i.distance*r;var n=i.getNormal();if(n){var o=e.Vector3.Cross(e.Axis.Y,n),s=e.Vector3.Cross(n,o);e.Vector3.RotationFromAxisToRef(s,n,o,t._gazeTracker.rotation)}t._gazeTracker.position.copyFrom(i.pickedPoint),t._gazeTracker.position.x<0?t._gazeTracker.position.x+=.002:t._gazeTracker.position.x-=.002,t._gazeTracker.position.y<0?t._gazeTracker.position.y+=.002:t._gazeTracker.position.y-=.002,t._gazeTracker.position.z<0?t._gazeTracker.position.z+=.002:t._gazeTracker.position.z-=.002}t._updatePointerDistance(i.distance)}else t._gazeTracker.isVisible=!1;if(i&&i.pickedMesh){if(t._currentHit=i,t._pointerDownOnMeshAsked&&this._scene.simulatePointerMove(t._currentHit,{pointerId:t._id}),this._teleportationInitialized&&this._isTeleportationFloor(i.pickedMesh)&&i.pickedPoint)return t._currentMeshSelected&&!this._isTeleportationFloor(t._currentMeshSelected)&&this._notifySelectedMeshUnselected(t._currentMeshSelected),t._currentMeshSelected=null,void(t._teleportationRequestInitiated&&this._moveTeleportationSelectorTo(i,t));if(i.pickedMesh!==t._currentMeshSelected)if(this.meshSelectionPredicate(i.pickedMesh)){this.onNewMeshPicked.notifyObservers(i),t._currentMeshSelected=i.pickedMesh,i.pickedMesh.isPickable&&i.pickedMesh.actionManager?(this.changeGazeColor(new e.Color3(0,0,1)),this.changeLaserColor(new e.Color3(.2,.2,1)),t._isActionableMesh=!0):(this.changeGazeColor(new e.Color3(.7,.7,.7)),this.changeLaserColor(new e.Color3(.7,.7,.7)),t._isActionableMesh=!1);try{this.onNewMeshSelected.notifyObservers(i.pickedMesh)}catch(t){e.Tools.Warn("Error in your custom logic onNewMeshSelected: "+t)}}else this._notifySelectedMeshUnselected(t._currentMeshSelected),t._currentMeshSelected=null,this.changeGazeColor(new e.Color3(.7,.7,.7)),this.changeLaserColor(new e.Color3(.7,.7,.7))}else t._currentHit=null,this._notifySelectedMeshUnselected(t._currentMeshSelected),t._currentMeshSelected=null,this.changeGazeColor(new e.Color3(.7,.7,.7)),this.changeLaserColor(new e.Color3(.7,.7,.7))}},t.prototype._notifySelectedMeshUnselected=function(e){e&&this.onSelectedMeshUnselected.notifyObservers(e)},t.prototype.changeLaserColor=function(e){this.leftController&&this.leftController._setLaserPointerColor(e),this.rightController&&this.rightController._setLaserPointerColor(e)},t.prototype.changeGazeColor=function(e){this._cameraGazer._gazeTracker.material&&(this._cameraGazer._gazeTracker.material.emissiveColor=e,this.leftController&&(this.leftController._gazeTracker.material.emissiveColor=e),this.rightController&&(this.rightController._gazeTracker.material.emissiveColor=e))},t.prototype.dispose=function(){this.isInVRMode&&this.exitVR(),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._cameraGazer&&this._cameraGazer.dispose(),this.leftController&&this.leftController.dispose(),this.rightController&&this.rightController.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)},t.prototype.getClassName=function(){return"VRExperienceHelper"},t})();e.VRExperienceHelper=n})(e||(e={}));var e;!(function(e){var t;!(function(e){e[e.X=0]="X",e[e.Y=1]="Y",e[e.Z=2]="Z"})(t=e.JoystickAxis||(e.JoystickAxis={}));var i=(function(){function i(r){var n=this;if(this._leftJoystick=!!r,i._globalJoystickIndex++,this._axisTargetedByLeftAndRight=t.X,this._axisTargetedByUpAndDown=t.Y,this.reverseLeftRight=!1,this.reverseUpDown=!1,this._touches=new e.StringDictionary,this.deltaPosition=e.Vector3.Zero(),this._joystickSensibility=25,this._inversedSensibility=1/(this._joystickSensibility/1e3),this._onResize=function(e){i.vjCanvasWidth=window.innerWidth,i.vjCanvasHeight=window.innerHeight,i.vjCanvas&&(i.vjCanvas.width=i.vjCanvasWidth,i.vjCanvas.height=i.vjCanvasHeight),i.halfWidth=i.vjCanvasWidth/2},!i.vjCanvas){window.addEventListener("resize",this._onResize,!1),i.vjCanvas=document.createElement("canvas"),i.vjCanvasWidth=window.innerWidth,i.vjCanvasHeight=window.innerHeight,i.vjCanvas.width=window.innerWidth,i.vjCanvas.height=window.innerHeight,i.vjCanvas.style.width="100%",i.vjCanvas.style.height="100%",i.vjCanvas.style.position="absolute",i.vjCanvas.style.backgroundColor="transparent",i.vjCanvas.style.top="0px",i.vjCanvas.style.left="0px",i.vjCanvas.style.zIndex="5",i.vjCanvas.style.msTouchAction="none",i.vjCanvas.setAttribute("touch-action","none");var o=i.vjCanvas.getContext("2d");if(!o)throw new Error("Unable to create canvas for virtual joystick");i.vjCanvasContext=o,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){var t;e.preventDefault(),t=!0===this._leftJoystick?e.clientXi.halfWidth,t&&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,r=i*this._deltaJoystickVector.x/this._inversedSensibility;switch(this._axisTargetedByLeftAndRight){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))}var n=this.reverseUpDown?1:-1,o=n*this._deltaJoystickVector.y/this._inversedSensibility;switch(this._axisTargetedByUpAndDown){case t.X:this.deltaPosition.x=Math.min(1,Math.max(-1,o));break;case t.Y:this.deltaPosition.y=Math.min(1,Math.max(-1,o));break;case t.Z:this.deltaPosition.z=Math.min(1,Math.max(-1,o))}}else{var s=this._touches.get(e.pointerId.toString());s&&(s.x=e.clientX,s.y=e.clientY)}},i.prototype._onPointerUp=function(e){if(this._joystickPointerID==e.pointerId)i.vjCanvasContext.clearRect(this._joystickPointerStartPos.x-64,this._joystickPointerStartPos.y-64,128,128),i.vjCanvasContext.clearRect(this._joystickPreviousPointerPos.x-42,this._joystickPreviousPointerPos.y-42,84,84),this._joystickPointerID=-1,this.pressed=!1;else{var t=this._touches.get(e.pointerId.toString());t&&i.vjCanvasContext.clearRect(t.prevX-44,t.prevY-44,88,88)}this._deltaJoystickVector.x=0,this._deltaJoystickVector.y=0,this._touches.remove(e.pointerId.toString())},i.prototype.setJoystickColor=function(e){this._joystickColor=e},i.prototype.setActionOnTouch=function(e){this._action=e},i.prototype.setAxisForLeftRight=function(e){switch(e){case t.X:case t.Y:case t.Z:this._axisTargetedByLeftAndRight=e;break;default:this._axisTargetedByLeftAndRight=t.X}},i.prototype.setAxisForUpDown=function(e){switch(e){case t.X:case t.Y:case t.Z:this._axisTargetedByUpAndDown=e;break;default:this._axisTargetedByUpAndDown=t.Y}},i.prototype._drawVirtualJoystick=function(){var e=this;this.pressed&&this._touches.forEach((function(t,r){r.pointerId===e._joystickPointerID?(i.vjCanvasContext.clearRect(e._joystickPointerStartPos.x-64,e._joystickPointerStartPos.y-64,128,128),i.vjCanvasContext.clearRect(e._joystickPreviousPointerPos.x-42,e._joystickPreviousPointerPos.y-42,84,84),i.vjCanvasContext.beginPath(),i.vjCanvasContext.lineWidth=6,i.vjCanvasContext.strokeStyle=e._joystickColor,i.vjCanvasContext.arc(e._joystickPointerStartPos.x,e._joystickPointerStartPos.y,40,0,2*Math.PI,!0),i.vjCanvasContext.stroke(),i.vjCanvasContext.closePath(),i.vjCanvasContext.beginPath(),i.vjCanvasContext.strokeStyle=e._joystickColor,i.vjCanvasContext.lineWidth=2,i.vjCanvasContext.arc(e._joystickPointerStartPos.x,e._joystickPointerStartPos.y,60,0,2*Math.PI,!0),i.vjCanvasContext.stroke(),i.vjCanvasContext.closePath(),i.vjCanvasContext.beginPath(),i.vjCanvasContext.strokeStyle=e._joystickColor,i.vjCanvasContext.arc(e._joystickPointerPos.x,e._joystickPointerPos.y,40,0,2*Math.PI,!0),i.vjCanvasContext.stroke(),i.vjCanvasContext.closePath(),e._joystickPreviousPointerPos=e._joystickPointerPos.clone()):(i.vjCanvasContext.clearRect(r.prevX-44,r.prevY-44,88,88),i.vjCanvasContext.beginPath(),i.vjCanvasContext.fillStyle="white",i.vjCanvasContext.beginPath(),i.vjCanvasContext.strokeStyle="red",i.vjCanvasContext.lineWidth=6,i.vjCanvasContext.arc(r.x,r.y,40,0,2*Math.PI,!0),i.vjCanvasContext.stroke(),i.vjCanvasContext.closePath(),r.prevX=r.x,r.prevY=r.y)})),requestAnimationFrame((function(){e._drawVirtualJoystick()}))},i.prototype.releaseCanvas=function(){i.vjCanvas&&(i.vjCanvas.removeEventListener("pointerdown",this._onPointerDownHandlerRef),i.vjCanvas.removeEventListener("pointermove",this._onPointerMoveHandlerRef),i.vjCanvas.removeEventListener("pointerup",this._onPointerUpHandlerRef),i.vjCanvas.removeEventListener("pointerout",this._onPointerUpHandlerRef),window.removeEventListener("resize",this._onResize),document.body.removeChild(i.vjCanvas),i.vjCanvas=null)},i._globalJoystickIndex=0,i})();e.VirtualJoystick=i})(e||(e={}));var e;!(function(e){var t=(function(e){function t(t,i,r){var n=e.call(this,t,i,r)||this;return n.inputs.addVirtualJoystick(),n}return __extends(t,e),t.prototype.getClassName=function(){return"VirtualJoysticksCamera"},t})(e.FreeCamera);e.VirtualJoysticksCamera=t})(e||(e={}));var e;!(function(e){var t=(function(){function t(){}return t.prototype.getLeftJoystick=function(){return this._leftjoystick},t.prototype.getRightJoystick=function(){return this._rightjoystick},t.prototype.checkInputs=function(){if(this._leftjoystick){var t=this.camera,i=50*t._computeLocalCameraSpeed(),r=e.Matrix.RotationYawPitchRoll(t.rotation.y,t.rotation.x,0),n=e.Vector3.TransformCoordinates(new e.Vector3(this._leftjoystick.deltaPosition.x*i,this._leftjoystick.deltaPosition.y*i,this._leftjoystick.deltaPosition.z*i),r);t.cameraDirection=t.cameraDirection.add(n),t.cameraRotation=t.cameraRotation.addVector3(this._rightjoystick.deltaPosition),this._leftjoystick.pressed||(this._leftjoystick.deltaPosition=this._leftjoystick.deltaPosition.scale(.9)),this._rightjoystick.pressed||(this._rightjoystick.deltaPosition=this._rightjoystick.deltaPosition.scale(.9))}},t.prototype.attachControl=function(t,i){this._leftjoystick=new e.VirtualJoystick(!0),this._leftjoystick.setAxisForUpDown(e.JoystickAxis.Z),this._leftjoystick.setAxisForLeftRight(e.JoystickAxis.X),this._leftjoystick.setJoystickSensibility(.15),this._rightjoystick=new e.VirtualJoystick(!1),this._rightjoystick.setAxisForUpDown(e.JoystickAxis.X),this._rightjoystick.setAxisForLeftRight(e.JoystickAxis.Y),this._rightjoystick.reverseUpDown=!0,this._rightjoystick.setJoystickSensibility(.05),this._rightjoystick.setJoystickColor("yellow")},t.prototype.detachControl=function(e){this._leftjoystick.releaseCanvas(),this._rightjoystick.releaseCanvas()},t.prototype.getClassName=function(){return"FreeCameraVirtualJoystickInput"},t.prototype.getSimpleName=function(){return"virtualJoystick"},t})();e.FreeCameraVirtualJoystickInput=t,e.CameraInputTypes.FreeCameraVirtualJoystickInput=t})(e||(e={}));var e;!(function(e){var t=(function(){function e(e,t,i){this.quality=e,this.distance=t,this.optimizeMesh=i}return e})();e.SimplificationSettings=t;var i=(function(){function t(){this.running=!1,this._simplificationArray=[]}return t.prototype.addTask=function(e){this._simplificationArray.push(e)},t.prototype.executeNext=function(){var e=this._simplificationArray.pop();e?(this.running=!0,this.runSimplification(e)):this.running=!1},t.prototype.runSimplification=function(t){var i=this;if(t.parallelProcessing)t.settings.forEach((function(e){i.getSimplifier(t).simplify(e,(function(r){t.mesh.addLODLevel(e.distance,r),r.isVisible=!0,e.quality===t.settings[t.settings.length-1].quality&&t.successCallback&&t.successCallback(),i.executeNext()}))}));else{var r=this.getSimplifier(t),n=function(e,i){r.simplify(e,(function(r){t.mesh.addLODLevel(e.distance,r),r.isVisible=!0,i()}))};e.AsyncLoop.Run(t.settings.length,(function(e){n(t.settings[e.index],(function(){e.executeNext()}))}),(function(){t.successCallback&&t.successCallback(),i.executeNext()}))}},t.prototype.getSimplifier=function(e){switch(e.simplificationType){case r.QUADRATIC:default:return new l(e.mesh)}},t})();e.SimplificationQueue=i;var r;!(function(e){e[e.QUADRATIC=0]="QUADRATIC"})(r=e.SimplificationType||(e.SimplificationType={}));var n=(function(){function e(e){this.vertices=e,this.error=new Array(4),this.deleted=!1,this.isDirty=!1,this.deletePending=!1,this.borderFactor=0}return e})();e.DecimationTriangle=n;var o=(function(){function e(e,t){this.position=e,this.id=t,this.isBorder=!0,this.q=new s,this.triangleCount=0,this.triangleStart=0,this.originalOffsets=[]}return e.prototype.updatePosition=function(e){this.position.copyFrom(e)},e})();e.DecimationVertex=o;var s=(function(){function e(e){this.data=new Array(10);for(var t=0;t<10;++t)e&&e[t]?this.data[t]=e[t]:this.data[t]=0}return e.prototype.det=function(e,t,i,r,n,o,s,a,l){return this.data[e]*this.data[n]*this.data[l]+this.data[i]*this.data[r]*this.data[a]+this.data[t]*this.data[o]*this.data[s]-this.data[i]*this.data[n]*this.data[s]-this.data[e]*this.data[o]*this.data[a]-this.data[t]*this.data[r]*this.data[l]},e.prototype.addInPlace=function(e){for(var t=0;t<10;++t)this.data[t]+=e.data[t]},e.prototype.addArrayInPlace=function(e){for(var t=0;t<10;++t)this.data[t]+=e[t]},e.prototype.add=function(t){for(var i=new e,r=0;r<10;++r)i.data[r]=this.data[r]+t.data[r];return i},e.FromData=function(t,i,r,n){return new e(e.DataFromNumbers(t,i,r,n))},e.DataFromNumbers=function(e,t,i,r){return[e*e,e*t,e*i,e*r,t*t,t*i,t*r,i*i,i*r,r*r]},e})();e.QuadraticMatrix=s;var a=(function(){function e(e,t){this.vertexId=e,this.triangleId=t}return e})();e.Reference=a;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,l=function(t,i){setTimeout((function(){t%5==0&&n.updateMesh(0===t);for(var r=0;rl||r.deleted||r.isDirty))for(var o=0;o<3;++o)if(r.error[o]>0,f,(function(){var t=function(e){if(l){var t=c.indexStart/3+e,i=3*t,r=l[i+0],o=l[i+1],a=l[i+2],h=s.vertices[u[r-c.verticesStart]],f=s.vertices[u[o-c.verticesStart]],d=s.vertices[u[a-c.verticesStart]],p=new n([h,f,d]);p.originalOffset=i,s.triangles.push(p)}};e.AsyncLoop.SyncAsyncForLoop(c.indexCount/3,s.syncIterations,t,(function(){s.init(i)}))}))},t.prototype.init=function(t){var i=this,r=function(t){var r=i.triangles[t];r.normal=e.Vector3.Cross(r.vertices[1].position.subtract(r.vertices[0].position),r.vertices[2].position.subtract(r.vertices[0].position)).normalize();for(var n=0;n<3;n++)r.vertices[n].q.addArrayInPlace(s.DataFromNumbers(r.normal.x,r.normal.y,r.normal.z,-e.Vector3.Dot(r.normal,r.vertices[0].position)))};e.AsyncLoop.SyncAsyncForLoop(this.triangles.length,this.syncIterations,r,(function(){var r=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])};e.AsyncLoop.SyncAsyncForLoop(i.triangles.length,i.syncIterations,r,(function(){t()}))}))},t.prototype.reconstructMesh=function(t){var i,r=[];for(i=0;i0&&this._reconstructedMesh.setVerticesData(e.VertexBuffer.UVKind,l),c.length>0&&this._reconstructedMesh.setVerticesData(e.VertexBuffer.ColorKind,c);var b=this._mesh.subMeshes[t];t>0&&(this._reconstructedMesh.subMeshes=[],g.forEach((function(t){e.SubMesh.AddToMesh(t.materialIndex,t.verticesStart,t.verticesCount,t.indexStart,t.indexCount,t.getMesh())})),e.SubMesh.AddToMesh(b.materialIndex,m,d,_,3*r.length,this._reconstructedMesh))},t.prototype.initDecimatedMesh=function(){this._reconstructedMesh=new e.Mesh(this._mesh.name+"Decimated",this._mesh.getScene()),this._reconstructedMesh.material=this._mesh.material,this._reconstructedMesh.parent=this._mesh.parent,this._reconstructedMesh.isVisible=!1,this._reconstructedMesh.renderingGroupId=this._mesh.renderingGroupId},t.prototype.isFlipped=function(t,i,r,n,o,s){for(var a=0;a.999)return!0;var p=e.Vector3.Cross(f,d).normalize();if(n[a]=!1,e.Vector3.Dot(p,l.normal)<.2)return!0}else n[a]=!0,s.push(l)}}return!1},t.prototype.updateTriangles=function(e,t,i,r){for(var n=r,o=0;othis.maximumSize&&(n.scale(this.step),i=!1)}}return i},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 __extends(t,e),t.prototype.getDescription=function(){return"Setting hardware scaling level to "+this._currentScale},t.prototype.apply=function(e,t){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 __extends(t,e),t.prototype.getDescription=function(){return"Turning shadows on/off"},t.prototype.apply=function(e,t){return e.shadowsEnabled=t.isInImprovementMode,!0},t})(t);e.ShadowsOptimization=n;var o=(function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return __extends(t,e),t.prototype.getDescription=function(){return"Turning post-processes on/off"},t.prototype.apply=function(e,t){return e.postProcessesEnabled=t.isInImprovementMode,!0},t})(t);e.PostProcessesOptimization=o;var s=(function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return __extends(t,e),t.prototype.getDescription=function(){return"Turning lens flares on/off"},t.prototype.apply=function(e,t){return e.lensFlaresEnabled=t.isInImprovementMode,!0},t})(t);e.LensFlaresOptimization=s;var a=(function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return __extends(t,e),t.prototype.getDescription=function(){return this.onGetDescription?this.onGetDescription():"Running user defined callback"},t.prototype.apply=function(e,t){return!this.onApply||this.onApply(e,t)},t})(t);e.CustomOptimization=a;var l=(function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return __extends(t,e),t.prototype.getDescription=function(){return"Turning particles on/off"},t.prototype.apply=function(e,t){return e.particlesEnabled=t.isInImprovementMode,!0},t})(t);e.ParticlesOptimization=l;var c=(function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return __extends(t,e),t.prototype.getDescription=function(){return"Turning render targets off"},t.prototype.apply=function(e,t){return e.renderTargetsEnabled=t.isInImprovementMode,!0},t})(t);e.RenderTargetsOptimization=c;var h=(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 __extends(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,n){for(var o=t.meshes.slice(0),s=o.length,a=0;a=this._targetFrameRate)return this._isRunning=!1,void this.onSuccessObservable.notifyObservers(this);for(var r=!0,n=!0,o=0;o4&&(n.push(e.VertexBuffer.MatricesIndicesExtraKind),n.push(e.VertexBuffer.MatricesWeightsExtraKind)),r.push("#define NUM_BONE_INFLUENCERS "+o.numBoneInfluencers),r.push("#define BonesPerMesh "+(o.skeleton?o.skeleton.bones.length+1:0))):r.push("#define NUM_BONE_INFLUENCERS 0"),i&&(r.push("#define INSTANCES"),n.push("world0"),n.push("world1"),n.push("world2"),n.push("world3"));var a=r.join("\n");return this._cachedDefines!==a&&(this._cachedDefines=a,this._effect=this._scene.getEngine().createEffect("outline",n,["world","mBones","viewProjection","diffuseMatrix","offset","color","logarithmicDepthConstant"],["diffuseSampler"],a)),this._effect.isReady()},t})();e.OutlineRenderer=t})(e||(e={}));var e;!(function(e){var t=(function(){function e(){this.edges=new Array,this.edgesConnectedCount=0}return e})(),i=(function(){function i(e,t,i){void 0===t&&(t=.95),void 0===i&&(i=!1),this.edgesWidthScalerForOrthographic=1e3,this.edgesWidthScalerForPerspective=50,this._linesPositions=new Array,this._linesNormals=new Array,this._linesIndices=new Array,this._buffers={},this._checkVerticesInsteadOfIndices=!1,this._source=e,this._checkVerticesInsteadOfIndices=i,this._epsilon=t,this._prepareRessources(),this._generateEdgesLines()}return i.prototype._prepareRessources=function(){this._lineShader||(this._lineShader=new e.ShaderMaterial("lineShader",this._source.getScene(),"line",{attributes:["position","normal"],uniforms:["worldViewProjection","color","width","aspectRatio"]}),this._lineShader.disableDepthWrite=!0,this._lineShader.backFaceCulling=!1)},i.prototype._rebuild=function(){var t=this._buffers[e.VertexBuffer.PositionKind];t&&t._rebuild(),(t=this._buffers[e.VertexBuffer.NormalKind])&&t._rebuild();var i=this._source.getScene(),r=i.getEngine() ;this._ib=r.createIndexBuffer(this._linesIndices)},i.prototype.dispose=function(){var t=this._buffers[e.VertexBuffer.PositionKind];t&&(t.dispose(),this._buffers[e.VertexBuffer.PositionKind]=null),t=this._buffers[e.VertexBuffer.NormalKind],t&&(t.dispose(),this._buffers[e.VertexBuffer.NormalKind]=null),this._source.getScene().getEngine()._releaseBuffer(this._ib),this._lineShader.dispose()},i.prototype._processEdgeForAdjacencies=function(e,t,i,r,n){return e===i&&t===r||e===r&&t===i?0:e===r&&t===n||e===n&&t===r?1:e===n&&t===i||e===i&&t===n?2:-1},i.prototype._processEdgeForAdjacenciesWithVertices=function(e,t,i,r,n){return e.equalsWithEpsilon(i)&&t.equalsWithEpsilon(r)||e.equalsWithEpsilon(r)&&t.equalsWithEpsilon(i)?0:e.equalsWithEpsilon(r)&&t.equalsWithEpsilon(n)||e.equalsWithEpsilon(n)&&t.equalsWithEpsilon(r)?1:e.equalsWithEpsilon(n)&&t.equalsWithEpsilon(i)||e.equalsWithEpsilon(i)&&t.equalsWithEpsilon(n)?2:-1},i.prototype._checkEdge=function(t,i,r,n,o){var s;if(void 0===i)s=!0;else{s=e.Vector3.Dot(r[t],r[i])4&&(s.push(e.VertexBuffer.MatricesIndicesExtraKind),s.push(e.VertexBuffer.MatricesWeightsExtraKind)),o.push("#define NUM_BONE_INFLUENCERS "+a.numBoneInfluencers),o.push("#define BonesPerMesh "+(a.skeleton?a.skeleton.bones.length+1:0))):o.push("#define NUM_BONE_INFLUENCERS 0"),i&&(o.push("#define INSTANCES"),s.push("world0"),s.push("world1"),s.push("world2"),s.push("world3"));var u=o.join("\n");return this._cachedDefines!==u&&(this._cachedDefines=u,this._effectLayerMapGenerationEffect=this._scene.getEngine().createEffect("glowMapGeneration",s,["world","mBones","viewProjection","diffuseMatrix","color","emissiveMatrix"],["diffuseSampler","emissiveSampler"],u)),this._effectLayerMapGenerationEffect.isReady()},i.prototype.render=function(){var e=this._mergeEffect;if(e.isReady()){for(var t=0;t-1&&this._scene.effectLayers.splice(i,1),this.onDisposeObservable.notifyObservers(this),this.onDisposeObservable.clear(),this.onBeforeRenderMainTextureObservable.clear(),this.onBeforeComposeObservable.clear(),this.onAfterComposeObservable.clear(),this.onSizeChangedObservable.clear()},i})();e.EffectLayer=i})(e||(e={}));var e;!(function(e){var i=(function(t){function i(i,r,n,o,s,a,l,c){void 0===a&&(a=e.Texture.BILINEAR_SAMPLINGMODE);var h=t.call(this,i,"glowBlurPostProcess",["screenSize","direction","blurWidth"],null,o,s,a,l,c)||this;return h.direction=r,h.kernel=n,h.onApplyObservable.add((function(e){e.setFloat2("screenSize",h.width,h.height),e.setVector2("direction",h.direction),e.setFloat("blurWidth",h.kernel)})),h}return __extends(i,t),i})(e.PostProcess),r=(function(r){function n(i,o,s){var a=r.call(this,i,o)||this;return a.name=i,a.innerGlow=!0,a.outerGlow=!0,a.onBeforeBlurObservable=new e.Observable,a.onAfterBlurObservable=new e.Observable,a._instanceGlowingMeshStencilReference=n.GlowingMeshStencilReference++,a._meshes={},a._excludedMeshes={},a.neutralColor=n.NeutralColor,a._engine.isStencilEnable||e.Tools.Warn("Rendering the Highlight Layer requires the stencil to be active on the canvas. var engine = new BABYLON.Engine(canvas, antialias, { stencil: true }"),a._options=t({mainTextureRatio:.5,blurTextureSizeRatio:.5,blurHorizontalSize:1,blurVerticalSize:1,alphaBlendingMode:e.Engine.ALPHA_COMBINE,camera:null},s),a._init({alphaBlendingMode:a._options.alphaBlendingMode,camera:a._options.camera,mainTextureFixedSize:a._options.mainTextureFixedSize,mainTextureRatio:a._options.mainTextureRatio}),a._shouldRender=!1,a}return __extends(n,r),Object.defineProperty(n.prototype,"blurHorizontalSize",{get:function(){return this._horizontalBlurPostprocess.kernel},set:function(e){this._horizontalBlurPostprocess.kernel=e},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"blurVerticalSize",{get:function(){return this._verticalBlurPostprocess.kernel},set:function(e){this._verticalBlurPostprocess.kernel=e},enumerable:!0,configurable:!0}),n.prototype.getEffectName=function(){return n.EffectName},n.prototype._createMergeEffect=function(){return this._engine.createEffect("glowMapMerge",[e.VertexBuffer.PositionKind],["offset"],["textureSampler"],this._options.isStroke?"#define STROKE \n":void 0)},n.prototype._createTextureAndPostProcesses=function(){var t=this,r=this._mainTextureDesiredSize.width*this._options.blurTextureSizeRatio,n=this._mainTextureDesiredSize.height*this._options.blurTextureSizeRatio;r=this._engine.needPOTTextures?e.Tools.GetExponentOfTwo(r,this._maxSize):r,n=this._engine.needPOTTextures?e.Tools.GetExponentOfTwo(n,this._maxSize):n,this._blurTexture=new e.RenderTargetTexture("HighlightLayerBlurRTT",{width:r,height:n},this._scene,!1,!0,e.Engine.TEXTURETYPE_HALF_FLOAT),this._blurTexture.wrapU=e.Texture.CLAMP_ADDRESSMODE,this._blurTexture.wrapV=e.Texture.CLAMP_ADDRESSMODE,this._blurTexture.anisotropicFilteringLevel=16,this._blurTexture.updateSamplingMode(e.Texture.TRILINEAR_SAMPLINGMODE),this._blurTexture.renderParticles=!1,this._blurTexture.ignoreCameraViewport=!0,this._textures=[this._blurTexture],this._options.alphaBlendingMode===e.Engine.ALPHA_COMBINE?(this._downSamplePostprocess=new e.PassPostProcess("HighlightLayerPPP",this._options.blurTextureSizeRatio,null,e.Texture.BILINEAR_SAMPLINGMODE,this._scene.getEngine()),this._downSamplePostprocess.onApplyObservable.add((function(e){e.setTexture("textureSampler",t._mainTexture)})),this._horizontalBlurPostprocess=new i("HighlightLayerHBP",new e.Vector2(1,0),this._options.blurHorizontalSize,1,null,e.Texture.BILINEAR_SAMPLINGMODE,this._scene.getEngine()),this._horizontalBlurPostprocess.onApplyObservable.add((function(e){e.setFloat2("screenSize",r,n)})),this._verticalBlurPostprocess=new i("HighlightLayerVBP",new e.Vector2(0,1),this._options.blurVerticalSize,1,null,e.Texture.BILINEAR_SAMPLINGMODE,this._scene.getEngine()),this._verticalBlurPostprocess.onApplyObservable.add((function(e){e.setFloat2("screenSize",r,n)})),this._postProcesses=[this._downSamplePostprocess,this._horizontalBlurPostprocess,this._verticalBlurPostprocess]):(this._horizontalBlurPostprocess=new e.BlurPostProcess("HighlightLayerHBP",new e.Vector2(1,0),this._options.blurHorizontalSize/2,{width:r,height:n},null,e.Texture.BILINEAR_SAMPLINGMODE,this._scene.getEngine(),!1,e.Engine.TEXTURETYPE_HALF_FLOAT),this._horizontalBlurPostprocess.width=r,this._horizontalBlurPostprocess.height=n,this._horizontalBlurPostprocess.onApplyObservable.add((function(e){e.setTexture("textureSampler",t._mainTexture)})),this._verticalBlurPostprocess=new e.BlurPostProcess("HighlightLayerVBP",new e.Vector2(0,1),this._options.blurVerticalSize/2,{width:r,height:n},null,e.Texture.BILINEAR_SAMPLINGMODE,this._scene.getEngine(),!1,e.Engine.TEXTURETYPE_HALF_FLOAT),this._postProcesses=[this._horizontalBlurPostprocess,this._verticalBlurPostprocess]),this._mainTexture.onAfterUnbindObservable.add((function(){t.onBeforeBlurObservable.notifyObservers(t);var e=t._blurTexture.getInternalTexture();e&&t._scene.postProcessManager.directRender(t._postProcesses,e,!0),t.onAfterBlurObservable.notifyObservers(t)})),this._postProcesses.map((function(e){e.autoClear=!1}))},n.prototype.needStencil=function(){return!0},n.prototype.isReady=function(e,t){var i=e.getMaterial(),n=e.getRenderingMesh();if(!i||!n||!this._meshes)return!1;var o=null,s=this._meshes[n.uniqueId];return s&&s.glowEmissiveOnly&&i&&(o=i.emissiveTexture),r.prototype._isReady.call(this,e,t,o)},n.prototype._internalRender=function(t){t.setTexture("textureSampler",this._blurTexture);var i=this._engine,r=i.getStencilBuffer(),n=i.getStencilFunction(),o=i.getStencilMask(),s=i.getStencilOperationPass(),a=i.getStencilOperationFail(),l=i.getStencilOperationDepthFail(),c=i.getStencilFunctionReference();i.setStencilOperationPass(e.Engine.REPLACE),i.setStencilOperationFail(e.Engine.KEEP),i.setStencilOperationDepthFail(e.Engine.KEEP),i.setStencilMask(0),i.setStencilBuffer(!0),i.setStencilFunctionReference(this._instanceGlowingMeshStencilReference),this.outerGlow&&(t.setFloat("offset",0),i.setStencilFunction(e.Engine.NOTEQUAL),i.drawElementsType(e.Material.TriangleFillMode,0,6)),this.innerGlow&&(t.setFloat("offset",1),i.setStencilFunction(e.Engine.EQUAL),i.drawElementsType(e.Material.TriangleFillMode,0,6)),i.setStencilFunction(n),i.setStencilMask(o),i.setStencilBuffer(r),i.setStencilOperationPass(s),i.setStencilOperationFail(a),i.setStencilOperationDepthFail(l),i.setStencilFunctionReference(c)},n.prototype.shouldRender=function(){return!!r.prototype.shouldRender.call(this)&&!!this._meshes},n.prototype._shouldRenderMesh=function(e){return!this._excludedMeshes||!this._excludedMeshes[e.uniqueId]},n.prototype._setEmissiveTextureAndColor=function(e,t,i){var r=this._meshes[e.uniqueId];r?this._emissiveTextureAndColor.color.set(r.color.r,r.color.g,r.color.b,1):this._emissiveTextureAndColor.color.set(this.neutralColor.r,this.neutralColor.g,this.neutralColor.b,this.neutralColor.a),r&&r.glowEmissiveOnly&&i?(this._emissiveTextureAndColor.texture=i.emissiveTexture,this._emissiveTextureAndColor.color.set(1,1,1,1)):this._emissiveTextureAndColor.texture=null},n.prototype.addExcludedMesh=function(e){if(this._excludedMeshes){this._excludedMeshes[e.uniqueId]||(this._excludedMeshes[e.uniqueId]={mesh:e,beforeRender:e.onBeforeRenderObservable.add((function(e){e.getEngine().setStencilBuffer(!1)})),afterRender:e.onAfterRenderObservable.add((function(e){e.getEngine().setStencilBuffer(!0)}))})}},n.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}},n.prototype.hasMesh=function(e){return!!this._meshes&&(void 0!==this._meshes[e.uniqueId]&&null!==this._meshes[e.uniqueId])},n.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}},n.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}}},n.prototype._defaultStencilReference=function(e){e.getScene().getEngine().setStencilFunctionReference(n.NormalMeshStencilReference)},n.prototype._disposeMesh=function(e){this.removeMesh(e),this.removeExcludedMesh(e)},n.prototype.dispose=function(){if(this._meshes){for(var e in this._meshes){var t=this._meshes[e];t&&t.mesh&&(t.observerHighlight&&t.mesh.onBeforeRenderObservable.remove(t.observerHighlight),t.observerDefault&&t.mesh.onAfterRenderObservable.remove(t.observerDefault))}this._meshes=null}if(this._excludedMeshes){for(var e in this._excludedMeshes){var t=this._excludedMeshes[e];t&&(t.beforeRender&&t.mesh.onBeforeRenderObservable.remove(t.beforeRender),t.afterRender&&t.mesh.onAfterRenderObservable.remove(t.afterRender))}this._excludedMeshes=null}r.prototype.dispose.call(this)},n.EffectName="HighlightLayer",n.NeutralColor=new e.Color4(0,0,0,0),n.GlowingMeshStencilReference=2,n.NormalMeshStencilReference=1,n})(e.EffectLayer);e.HighlightLayer=r})(e||(e={}));var e;!(function(e){var i=(function(i){function r(n,o,s){var a=i.call(this,n,o)||this;return a.name=n,a._intensity=1,a._includedOnlyMeshes=[],a._excludedMeshes=[],a.neutralColor=new e.Color4(0,0,0,1),a._options=t({mainTextureRatio:r.DefaultTextureRatio,blurKernelSize:32,mainTextureFixedSize:void 0,camera:null,mainTextureSamples:1},s),a._init({alphaBlendingMode:e.Engine.ALPHA_ADD,camera:a._options.camera,mainTextureFixedSize:a._options.mainTextureFixedSize,mainTextureRatio:a._options.mainTextureRatio}),a}return __extends(r,i),Object.defineProperty(r.prototype,"blurKernelSize",{get:function(){return this._horizontalBlurPostprocess1.kernel},set:function(e){this._horizontalBlurPostprocess1.kernel=e,this._verticalBlurPostprocess1.kernel=e,this._horizontalBlurPostprocess2.kernel=e,this._verticalBlurPostprocess2.kernel=e},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"intensity",{get:function(){return this._intensity},set:function(e){this._intensity=e},enumerable:!0,configurable:!0}),r.prototype.getEffectName=function(){return r.EffectName},r.prototype._createMergeEffect=function(){return this._engine.createEffect("glowMapMerge",[e.VertexBuffer.PositionKind],["offset"],["textureSampler","textureSampler2"],"#define EMISSIVE \n")},r.prototype._createTextureAndPostProcesses=function(){var t=this,i=this._mainTextureDesiredSize.width,r=this._mainTextureDesiredSize.height;i=this._engine.needPOTTextures?e.Tools.GetExponentOfTwo(i,this._maxSize):i,r=this._engine.needPOTTextures?e.Tools.GetExponentOfTwo(r,this._maxSize):r,this._blurTexture1=new e.RenderTargetTexture("GlowLayerBlurRTT",{width:i,height:r},this._scene,!1,!0,e.Engine.TEXTURETYPE_HALF_FLOAT),this._blurTexture1.wrapU=e.Texture.CLAMP_ADDRESSMODE,this._blurTexture1.wrapV=e.Texture.CLAMP_ADDRESSMODE,this._blurTexture1.updateSamplingMode(e.Texture.BILINEAR_SAMPLINGMODE),this._blurTexture1.renderParticles=!1,this._blurTexture1.ignoreCameraViewport=!0;var n=Math.floor(i/2),o=Math.floor(r/2);this._blurTexture2=new e.RenderTargetTexture("GlowLayerBlurRTT2",{width:n,height:o},this._scene,!1,!0,e.Engine.TEXTURETYPE_HALF_FLOAT),this._blurTexture2.wrapU=e.Texture.CLAMP_ADDRESSMODE,this._blurTexture2.wrapV=e.Texture.CLAMP_ADDRESSMODE,this._blurTexture2.updateSamplingMode(e.Texture.BILINEAR_SAMPLINGMODE),this._blurTexture2.renderParticles=!1,this._blurTexture2.ignoreCameraViewport=!0,this._textures=[this._blurTexture1,this._blurTexture2],this._horizontalBlurPostprocess1=new e.BlurPostProcess("GlowLayerHBP1",new e.Vector2(1,0),this._options.blurKernelSize/2,{width:i,height:r},null,e.Texture.BILINEAR_SAMPLINGMODE,this._scene.getEngine(),!1,e.Engine.TEXTURETYPE_HALF_FLOAT),this._horizontalBlurPostprocess1.width=i,this._horizontalBlurPostprocess1.height=r,this._horizontalBlurPostprocess1.onApplyObservable.add((function(e){e.setTexture("textureSampler",t._mainTexture)})),this._verticalBlurPostprocess1=new e.BlurPostProcess("GlowLayerVBP1",new e.Vector2(0,1),this._options.blurKernelSize/2,{width:i,height:r},null,e.Texture.BILINEAR_SAMPLINGMODE,this._scene.getEngine(),!1,e.Engine.TEXTURETYPE_HALF_FLOAT),this._horizontalBlurPostprocess2=new e.BlurPostProcess("GlowLayerHBP2",new e.Vector2(1,0),this._options.blurKernelSize/2,{width:n,height:o},null,e.Texture.BILINEAR_SAMPLINGMODE,this._scene.getEngine(),!1,e.Engine.TEXTURETYPE_HALF_FLOAT),this._horizontalBlurPostprocess2.width=n,this._horizontalBlurPostprocess2.height=o,this._horizontalBlurPostprocess2.onApplyObservable.add((function(e){e.setTexture("textureSampler",t._blurTexture1)})),this._verticalBlurPostprocess2=new e.BlurPostProcess("GlowLayerVBP2",new e.Vector2(0,1),this._options.blurKernelSize/2,{width:n,height:o},null,e.Texture.BILINEAR_SAMPLINGMODE,this._scene.getEngine(),!1,e.Engine.TEXTURETYPE_HALF_FLOAT),this._postProcesses=[this._horizontalBlurPostprocess1,this._verticalBlurPostprocess1,this._horizontalBlurPostprocess2,this._verticalBlurPostprocess2],this._postProcesses1=[this._horizontalBlurPostprocess1,this._verticalBlurPostprocess1],this._postProcesses2=[this._horizontalBlurPostprocess2,this._verticalBlurPostprocess2],this._mainTexture.samples=this._options.mainTextureSamples,this._mainTexture.onAfterUnbindObservable.add((function(){var e=t._blurTexture1.getInternalTexture();e&&(t._scene.postProcessManager.directRender(t._postProcesses1,e,!0),(e=t._blurTexture2.getInternalTexture())&&t._scene.postProcessManager.directRender(t._postProcesses2,e,!0))})),this._postProcesses.map((function(e){e.autoClear=!1}))},r.prototype.isReady=function(e,t){var r=e.getMaterial(),n=e.getRenderingMesh();if(!r||!n)return!1;var o=r.emissiveTexture;return i.prototype._isReady.call(this,e,t,o)},r.prototype.needStencil=function(){return!1},r.prototype._internalRender=function(t){t.setTexture("textureSampler",this._blurTexture1),t.setTexture("textureSampler2",this._blurTexture2),t.setFloat("offset",this._intensity);var i=this._engine,r=i.getStencilBuffer();i.setStencilBuffer(!1),i.drawElementsType(e.Material.TriangleFillMode,0,6),i.setStencilBuffer(r)},r.prototype._setEmissiveTextureAndColor=function(e,t,i){var r=1;this.customEmissiveTextureSelector?this._emissiveTextureAndColor.texture=this.customEmissiveTextureSelector(e,t,i):i?(this._emissiveTextureAndColor.texture=i.emissiveTexture,this._emissiveTextureAndColor.texture&&(r=this._emissiveTextureAndColor.texture.level)):this._emissiveTextureAndColor.texture=null,this.customEmissiveColorSelector?this.customEmissiveColorSelector(e,t,i,this._emissiveTextureAndColor.color):i.emissiveColor?this._emissiveTextureAndColor.color.set(i.emissiveColor.r*r,i.emissiveColor.g*r,i.emissiveColor.b*r,1):this._emissiveTextureAndColor.color.set(this.neutralColor.r,this.neutralColor.g,this.neutralColor.b,this.neutralColor.a)},r.prototype._shouldRenderMesh=function(e){return this.hasMesh(e)},r.prototype.addExcludedMesh=function(e){-1===this._excludedMeshes.indexOf(e.uniqueId)&&this._excludedMeshes.push(e.uniqueId)},r.prototype.removeExcludedMesh=function(e){var t=this._excludedMeshes.indexOf(e.uniqueId);-1!==t&&this._excludedMeshes.splice(t,1)},r.prototype.addIncludedOnlyMesh=function(e){-1===this._includedOnlyMeshes.indexOf(e.uniqueId)&&this._includedOnlyMeshes.push(e.uniqueId)},r.prototype.removeIncludedOnlyMesh=function(e){var t=this._includedOnlyMeshes.indexOf(e.uniqueId);-1!==t&&this._includedOnlyMeshes.splice(t,1)},r.prototype.hasMesh=function(e){return this._includedOnlyMeshes.length?-1!==this._includedOnlyMeshes.indexOf(e.uniqueId):!this._excludedMeshes.length||-1===this._excludedMeshes.indexOf(e.uniqueId)},r.prototype._disposeMesh=function(e){this.removeIncludedOnlyMesh(e),this.removeExcludedMesh(e)},r.EffectName="GlowLayer",r.DefaultBlurKernelSize=32,r.DefaultTextureRatio=.5,r})(e.EffectLayer);e.GlowLayer=i})(e||(e={}));var e;!(function(e){var t;!(function(e){e[e.INIT=0]="INIT",e[e.RUNNING=1]="RUNNING",e[e.DONE=2]="DONE",e[e.ERROR=3]="ERROR"})(t=e.AssetTaskState||(e.AssetTaskState={}));var i=(function(){function e(e){this.name=e,this._isCompleted=!1,this._taskState=t.INIT}return Object.defineProperty(e.prototype,"isCompleted",{get:function(){return this._isCompleted},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"taskState",{get:function(){return this._taskState},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"errorObject",{get:function(){return this._errorObject},enumerable:!0,configurable:!0}),e.prototype._setErrorObject=function(e,t){this._errorObject||(this._errorObject={message:e,exception:t})},e.prototype.run=function(e,i,r){var n=this;this._taskState=t.RUNNING,this.runTask(e,(function(){n.onDoneCallback(i,r)}),(function(e,t){n.onErrorCallback(r,e,t)}))},e.prototype.runTask=function(e,t,i){throw new Error("runTask is not implemented")},e.prototype.onErrorCallback=function(e,i,r){this._taskState=t.ERROR,this._errorObject={message:i,exception:r},this.onError&&this.onError(this,i,r),e()},e.prototype.onDoneCallback=function(e,i){try{this._taskState=t.DONE,this._isCompleted=!0,this.onSuccess&&this.onSuccess(this),e()}catch(e){this.onErrorCallback(i,"Task is done, error executing success callback(s)",e)}},e})();e.AbstractAssetTask=i;var r=(function(){function e(e,t,i){this.remainingCount=e, this.totalCount=t,this.task=i}return e})();e.AssetsProgressEvent=r;var n=(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 __extends(i,t),i.prototype.runTask=function(t,i,r){var n=this;e.SceneLoader.ImportMesh(this.meshesNames,this.rootUrl,this.sceneFilename,t,(function(e,t,r){n.loadedMeshes=e,n.loadedParticleSystems=t,n.loadedSkeletons=r,i()}),null,(function(e,t,i){r(t,i)}))},i})(i);e.MeshAssetTask=n;var o=(function(e){function t(t,i){var r=e.call(this,t)||this;return r.name=t,r.url=i,r}return __extends(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,!1,(function(e,t){e&&i(e.status+" "+e.statusText,t)}))},t})(i);e.TextFileAssetTask=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 __extends(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})(i);e.BinaryFileAssetTask=s;var a=(function(t){function i(e,i){var r=t.call(this,e)||this;return r.name=e,r.url=i,r}return __extends(i,t),i.prototype.runTask=function(t,i,r){var n=this,o=new Image;e.Tools.SetCorsBehavior(this.url,o),o.onload=function(){n.image=o,i()},o.onerror=function(e){r("Error loading image",e)},o.src=this.url},i})(i);e.ImageAssetTask=a;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 __extends(i,t),i.prototype.runTask=function(t,i,r){var n=function(){i()},o=function(e,t){r(e,t)};this.texture=new e.Texture(this.url,t,this.noMipmap,this.invertY,this.samplingMode,n,o)},i})(i);e.TextureAssetTask=l;var c=(function(t){function i(e,i,r,n,o){var s=t.call(this,e)||this;return s.name=e,s.url=i,s.extensions=r,s.noMipmap=n,s.files=o,s}return __extends(i,t),i.prototype.runTask=function(t,i,r){var n=function(){i()},o=function(e,t){r(e,t)};this.texture=new e.CubeTexture(this.url,t,this.extensions,this.noMipmap,this.files,n,o)},i})(i);e.CubeTextureAssetTask=c;var h=(function(t){function i(e,i,r,n,o,s,a){void 0===n&&(n=!1),void 0===o&&(o=!0),void 0===s&&(s=!1),void 0===a&&(a=!1);var l=t.call(this,e)||this;return l.name=e,l.url=i,l.size=r,l.noMipmap=n,l.generateHarmonics=o,l.useInGammaSpace=s,l.usePMREMGenerator=a,l}return __extends(i,t),i.prototype.run=function(t,i,r){var n=function(){i()},o=function(e,t){r(e,t)};this.texture=new e.HDRCubeTexture(this.url,t,this.size,this.noMipmap,this.generateHarmonics,this.useInGammaSpace,this.usePMREMGenerator,n,o)},i})(i);e.HDRCubeTextureAssetTask=h;var u=(function(){function i(t){this._isLoading=!1,this._tasks=new Array,this._waitingTasksCount=0,this._totalTasksCount=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 i.prototype.addMeshTask=function(e,t,i,r){var o=new n(e,t,i,r);return this._tasks.push(o),o},i.prototype.addTextFileTask=function(e,t){var i=new o(e,t);return this._tasks.push(i),i},i.prototype.addBinaryFileTask=function(e,t){var i=new s(e,t);return this._tasks.push(i),i},i.prototype.addImageTask=function(e,t){var i=new a(e,t);return this._tasks.push(i),i},i.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},i.prototype.addCubeTextureTask=function(e,t,i,r,n){var o=new c(e,t,i,r,n);return this._tasks.push(o),o},i.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 h(e,t,i,r,n,o,s);return this._tasks.push(a),a},i.prototype._decreaseWaitingTasksCount=function(i){var n=this;this._waitingTasksCount--;try{i.taskState===t.DONE&&e.Tools.SetImmediate((function(){var e=n._tasks.indexOf(i);e>-1&&n._tasks.splice(e,1)})),this.onProgress&&this.onProgress(this._waitingTasksCount,this._totalTasksCount,i),this.onProgressObservable.notifyObservers(new r(this._waitingTasksCount,this._totalTasksCount,i))}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()}},i.prototype._runTask=function(e){var t=this,i=function(){try{t.onTaskSuccess&&t.onTaskSuccess(e),t.onTaskSuccessObservable.notifyObservers(e),t._decreaseWaitingTasksCount(e)}catch(e){r("Error executing task success callbacks",e)}},r=function(i,r){e._setErrorObject(i,r),t.onTaskError&&t.onTaskError(e),t.onTaskErrorObservable.notifyObservers(e),t._decreaseWaitingTasksCount(e)};e.run(this._scene,i,r)},i.prototype.reset=function(){return this._isLoading=!1,this._tasks=new Array,this},i.prototype.load=function(){if(this._isLoading)return this;if(this._isLoading=!0,this._waitingTasksCount=this._tasks.length,this._totalTasksCount=this._tasks.length,0===this._waitingTasksCount)return this._isLoading=!1,this.onFinish&&this.onFinish(this._tasks),this.onTasksDoneObservable.notifyObservers(this._tasks),this;this.useDefaultLoadingScreen&&this._scene.getEngine().displayLoadingUI();for(var e=0;eu.upperRadiusLimit?u.upperRadiusLimit:h),h):0},t.prototype._maintainCameraAboveGround=function(){var i=this;if(!(this._elevationReturnTime<0)){var r=e.Tools.Now-this._lastInteractionTime,n=.5*Math.PI-this._defaultElevation,o=.5*Math.PI;if(this._attachedCamera&&!this._betaIsAnimating&&this._attachedCamera.beta>o&&r>=this._elevationReturnWaitTime){this._betaIsAnimating=!0,this.stopAllAnimations(),this._betaTransition||(this._betaTransition=e.Animation.CreateAnimation("beta",e.Animation.ANIMATIONTYPE_FLOAT,60,t.EasingFunction));var s=e.Animation.TransitionTo("beta",n,this._attachedCamera,this._attachedCamera.getScene(),60,this._betaTransition,this._elevationReturnTime,(function(){i._clearAnimationLocks(),i.stopAllAnimations()}));s&&this._animatables.push(s)}}},t.prototype._getFrustumSlope=function(){var t=this._attachedCamera;if(!t)return e.Vector2.Zero();var i=t.getScene().getEngine(),r=i.getAspectRatio(t),n=Math.tan(t.fov/2),o=n*r;return new e.Vector2(o,n)},t.prototype._clearAnimationLocks=function(){this._betaIsAnimating=!1},t.prototype._applyUserInteraction=function(){this.isUserIsMoving&&(this._lastInteractionTime=e.Tools.Now,this.stopAllAnimations(),this._clearAnimationLocks())},t.prototype.stopAllAnimations=function(){for(this._attachedCamera&&(this._attachedCamera.animations=[]);this._animatables.length;)this._animatables[0]&&(this._animatables[0].onAnimationEnd=null,this._animatables[0].stop()),this._animatables.shift()},Object.defineProperty(t.prototype,"isUserIsMoving",{get:function(){return!!this._attachedCamera&&(0!==this._attachedCamera.inertialAlphaOffset||0!==this._attachedCamera.inertialBetaOffset||0!==this._attachedCamera.inertialRadiusOffset||0!==this._attachedCamera.inertialPanningX||0!==this._attachedCamera.inertialPanningY||this._isPointerDown)},enumerable:!0,configurable:!0}),t.EasingFunction=new e.ExponentialEase,t.EasingMode=e.EasingFunction.EASINGMODE_EASEINOUT,t.IgnoreBoundsSizeMode=0,t.FitFrustumSidesMode=1,t})();e.FramingBehavior=t})(e||(e={}));var e;!(function(e){var t=(function(){function t(){this.transitionDuration=450,this.lowerRadiusTransitionRange=2,this.upperRadiusTransitionRange=-2,this._autoTransitionRange=!1,this._radiusIsAnimating=!1,this._radiusBounceTransition=null,this._animatables=new Array}return Object.defineProperty(t.prototype,"name",{get:function(){return"Bouncing"},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"autoTransitionRange",{get:function(){return this._autoTransitionRange},set:function(e){var t=this;if(this._autoTransitionRange!==e){this._autoTransitionRange=e;var i=this._attachedCamera;i&&(e?this._onMeshTargetChangedObserver=i.onMeshTargetChangedObservable.add((function(e){if(e){e.computeWorldMatrix(!0);var i=e.getBoundingInfo().diagonalLength;t.lowerRadiusTransitionRange=.05*i,t.upperRadiusTransitionRange=.05*i}})):this._onMeshTargetChangedObserver&&i.onMeshTargetChangedObservable.remove(this._onMeshTargetChangedObserver))}},enumerable:!0,configurable:!0}),t.prototype.init=function(){},t.prototype.attach=function(e){var t=this;this._attachedCamera=e,this._onAfterCheckInputsObserver=e.onAfterCheckInputsObservable.add((function(){t._attachedCamera&&(t._isRadiusAtLimit(t._attachedCamera.lowerRadiusLimit)&&t._applyBoundRadiusAnimation(t.lowerRadiusTransitionRange),t._isRadiusAtLimit(t._attachedCamera.upperRadiusLimit)&&t._applyBoundRadiusAnimation(t.upperRadiusTransitionRange))}))},t.prototype.detach=function(){this._attachedCamera&&(this._onAfterCheckInputsObserver&&this._attachedCamera.onAfterCheckInputsObservable.remove(this._onAfterCheckInputsObserver),this._onMeshTargetChangedObserver&&this._attachedCamera.onMeshTargetChangedObservable.remove(this._onMeshTargetChangedObserver),this._attachedCamera=null)},t.prototype._isRadiusAtLimit=function(e){return!!this._attachedCamera&&(this._attachedCamera.radius===e&&!this._radiusIsAnimating)},t.prototype._applyBoundRadiusAnimation=function(i){var r=this;if(this._attachedCamera){this._radiusBounceTransition||(t.EasingFunction.setEasingMode(t.EasingMode),this._radiusBounceTransition=e.Animation.CreateAnimation("radius",e.Animation.ANIMATIONTYPE_FLOAT,60,t.EasingFunction)),this._cachedWheelPrecision=this._attachedCamera.wheelPrecision,this._attachedCamera.wheelPrecision=1/0,this._attachedCamera.inertialRadiusOffset=0,this.stopAllAnimations(),this._radiusIsAnimating=!0;var n=e.Animation.TransitionTo("radius",this._attachedCamera.radius+i,this._attachedCamera,this._attachedCamera.getScene(),60,this._radiusBounceTransition,this.transitionDuration,(function(){return r._clearAnimationLocks()}));n&&this._animatables.push(n)}},t.prototype._clearAnimationLocks=function(){this._radiusIsAnimating=!1,this._attachedCamera&&(this._attachedCamera.wheelPrecision=this._cachedWheelPrecision)},t.prototype.stopAllAnimations=function(){for(this._attachedCamera&&(this._attachedCamera.animations=[]);this._animatables.length;)this._animatables[0].onAnimationEnd=null,this._animatables[0].stop(),this._animatables.shift()},t.EasingFunction=new e.BackEase(.3),t.EasingMode=e.EasingFunction.EASINGMODE_EASEOUT,t})();e.BouncingBehavior=t})(e||(e={}));var e;!(function(e){var t=(function(){function t(){this._zoomStopsAnimation=!1,this._idleRotationSpeed=.05,this._idleRotationWaitTime=2e3,this._idleRotationSpinupTime=2e3,this._isPointerDown=!1,this._lastFrameTime=null,this._lastInteractionTime=-1/0,this._cameraRotationSpeed=0,this._lastFrameRadius=0}return Object.defineProperty(t.prototype,"name",{get:function(){return"AutoRotation"},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"zoomStopsAnimation",{get:function(){return this._zoomStopsAnimation},set:function(e){this._zoomStopsAnimation=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"idleRotationSpeed",{get:function(){return this._idleRotationSpeed},set:function(e){this._idleRotationSpeed=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"idleRotationWaitTime",{get:function(){return this._idleRotationWaitTime},set:function(e){this._idleRotationWaitTime=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"idleRotationSpinupTime",{get:function(){return this._idleRotationSpinupTime},set:function(e){this._idleRotationSpinupTime=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotationInProgress",{get:function(){return Math.abs(this._cameraRotationSpeed)>0},enumerable:!0,configurable:!0}),t.prototype.init=function(){},t.prototype.attach=function(t){var i=this;this._attachedCamera=t;var r=this._attachedCamera.getScene();this._onPrePointerObservableObserver=r.onPrePointerObservable.add((function(t){if(t.type===e.PointerEventTypes.POINTERDOWN)return void(i._isPointerDown=!0);t.type===e.PointerEventTypes.POINTERUP&&(i._isPointerDown=!1)})),this._onAfterCheckInputsObserver=t.onAfterCheckInputsObservable.add((function(){var t=e.Tools.Now,r=0;null!=i._lastFrameTime&&(r=t-i._lastFrameTime),i._lastFrameTime=t,i._applyUserInteraction();var n=t-i._lastInteractionTime-i._idleRotationWaitTime,o=Math.max(Math.min(n/i._idleRotationSpinupTime,1),0);i._cameraRotationSpeed=i._idleRotationSpeed*o,i._attachedCamera&&(i._attachedCamera.alpha-=i._cameraRotationSpeed*(r/1e3))}))},t.prototype.detach=function(){if(this._attachedCamera){var e=this._attachedCamera.getScene();this._onPrePointerObservableObserver&&e.onPrePointerObservable.remove(this._onPrePointerObservableObserver),this._attachedCamera.onAfterCheckInputsObservable.remove(this._onAfterCheckInputsObserver),this._attachedCamera=null}},t.prototype._userIsZooming=function(){return!!this._attachedCamera&&0!==this._attachedCamera.inertialRadiusOffset},t.prototype._shouldAnimationStopForInteraction=function(){if(!this._attachedCamera)return!1;var e=!1;return this._lastFrameRadius===this._attachedCamera.radius&&0!==this._attachedCamera.inertialRadiusOffset&&(e=!0),this._lastFrameRadius=this._attachedCamera.radius,this._zoomStopsAnimation?e:this._userIsZooming()},t.prototype._applyUserInteraction=function(){this._userIsMoving()&&!this._shouldAnimationStopForInteraction()&&(this._lastInteractionTime=e.Tools.Now)},t.prototype._userIsMoving=function(){return!!this._attachedCamera&&(0!==this._attachedCamera.inertialAlphaOffset||0!==this._attachedCamera.inertialBetaOffset||0!==this._attachedCamera.inertialRadiusOffset||0!==this._attachedCamera.inertialPanningX||0!==this._attachedCamera.inertialPanningY||this._isPointerDown)},t})();e.AutoRotationBehavior=t})(e||(e={}));var e;!(function(e){var t=(function(){function t(t){this.engine=t,this._captureGPUFrameTime=!1,this._gpuFrameTime=new e.PerfCounter,this._captureShaderCompilationTime=!1,this._shaderCompilationTime=new e.PerfCounter,this._onBeginFrameObserver=null,this._onEndFrameObserver=null,this._onBeforeShaderCompilationObserver=null,this._onAfterShaderCompilationObserver=null}return Object.defineProperty(t.prototype,"gpuFrameTimeCounter",{get:function(){return this._gpuFrameTime},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"captureGPUFrameTime",{get:function(){return this._captureGPUFrameTime},set:function(e){var t=this;e!==this._captureGPUFrameTime&&(this._captureGPUFrameTime=e,e?(this._onBeginFrameObserver=this.engine.onBeginFrameObservable.add((function(){t._gpuFrameTimeToken||(t._gpuFrameTimeToken=t.engine.startTimeQuery())})),this._onEndFrameObserver=this.engine.onEndFrameObservable.add((function(){if(t._gpuFrameTimeToken){var e=t.engine.endTimeQuery(t._gpuFrameTimeToken);e>-1&&(t._gpuFrameTimeToken=null,t._gpuFrameTime.fetchNewFrame(),t._gpuFrameTime.addCount(e,!0))}}))):(this.engine.onBeginFrameObservable.remove(this._onBeginFrameObserver),this._onBeginFrameObserver=null,this.engine.onEndFrameObservable.remove(this._onEndFrameObserver),this._onEndFrameObserver=null))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"shaderCompilationTimeCounter",{get:function(){return this._shaderCompilationTime},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"captureShaderCompilationTime",{get:function(){return this._captureShaderCompilationTime},set:function(e){var t=this;e!==this._captureShaderCompilationTime&&(this._captureShaderCompilationTime=e,e?(this._onBeforeShaderCompilationObserver=this.engine.onBeforeShaderCompilationObservable.add((function(){t._shaderCompilationTime.fetchNewFrame(),t._shaderCompilationTime.beginMonitoring()})),this._onAfterShaderCompilationObserver=this.engine.onAfterShaderCompilationObservable.add((function(){t._shaderCompilationTime.endMonitoring()}))):(this.engine.onBeforeShaderCompilationObservable.remove(this._onBeforeShaderCompilationObserver),this._onBeforeShaderCompilationObserver=null,this.engine.onAfterShaderCompilationObservable.remove(this._onAfterShaderCompilationObserver),this._onAfterShaderCompilationObserver=null))},enumerable:!0,configurable:!0}),t.prototype.dispose=function(){this.engine.onBeginFrameObservable.remove(this._onBeginFrameObserver),this._onBeginFrameObserver=null,this.engine.onEndFrameObservable.remove(this._onEndFrameObserver),this._onEndFrameObserver=null,this.engine.onBeforeShaderCompilationObservable.remove(this._onBeforeShaderCompilationObserver),this._onBeforeShaderCompilationObserver=null,this.engine.onAfterShaderCompilationObservable.remove(this._onAfterShaderCompilationObserver),this._onAfterShaderCompilationObserver=null,this.engine=null},t})();e.EngineInstrumentation=t})(e||(e={}));var e;!(function(e){var t=(function(){function t(t){var i=this;this.scene=t,this._captureActiveMeshesEvaluationTime=!1,this._activeMeshesEvaluationTime=new e.PerfCounter,this._captureRenderTargetsRenderTime=!1,this._renderTargetsRenderTime=new e.PerfCounter,this._captureFrameTime=!1,this._frameTime=new e.PerfCounter,this._captureRenderTime=!1,this._renderTime=new e.PerfCounter,this._captureInterFrameTime=!1,this._interFrameTime=new e.PerfCounter,this._captureParticlesRenderTime=!1,this._particlesRenderTime=new e.PerfCounter,this._captureSpritesRenderTime=!1,this._spritesRenderTime=new e.PerfCounter,this._capturePhysicsTime=!1,this._physicsTime=new e.PerfCounter,this._captureAnimationsTime=!1,this._animationsTime=new e.PerfCounter,this._onBeforeActiveMeshesEvaluationObserver=null,this._onAfterActiveMeshesEvaluationObserver=null,this._onBeforeRenderTargetsRenderObserver=null,this._onAfterRenderTargetsRenderObserver=null,this._onAfterRenderObserver=null,this._onBeforeDrawPhaseObserver=null,this._onAfterDrawPhaseObserver=null,this._onBeforeAnimationsObserver=null,this._onBeforeParticlesRenderingObserver=null,this._onAfterParticlesRenderingObserver=null,this._onBeforeSpritesRenderingObserver=null,this._onAfterSpritesRenderingObserver=null,this._onBeforePhysicsObserver=null,this._onAfterPhysicsObserver=null,this._onAfterAnimationsObserver=null,this._onBeforeAnimationsObserver=t.onBeforeAnimationsObservable.add((function(){i._captureActiveMeshesEvaluationTime&&i._activeMeshesEvaluationTime.fetchNewFrame(),i._captureRenderTargetsRenderTime&&i._renderTargetsRenderTime.fetchNewFrame(),i._captureFrameTime&&(e.Tools.StartPerformanceCounter("Scene rendering"),i._frameTime.beginMonitoring()),i._captureInterFrameTime&&i._interFrameTime.endMonitoring(),i._captureParticlesRenderTime&&i._particlesRenderTime.fetchNewFrame(),i._captureSpritesRenderTime&&i._spritesRenderTime.fetchNewFrame(),i._captureAnimationsTime&&i._animationsTime.beginMonitoring(),i.scene.getEngine()._drawCalls.fetchNewFrame(),i.scene.getEngine()._textureCollisions.fetchNewFrame()})),this._onAfterRenderObserver=t.onAfterRenderObservable.add((function(){i._captureFrameTime&&(e.Tools.EndPerformanceCounter("Scene rendering"),i._frameTime.endMonitoring()),i._captureRenderTime&&i._renderTime.endMonitoring(!1),i._captureInterFrameTime&&i._interFrameTime.beginMonitoring()}))}return Object.defineProperty(t.prototype,"activeMeshesEvaluationTimeCounter",{get:function(){return this._activeMeshesEvaluationTime},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"captureActiveMeshesEvaluationTime",{get:function(){return this._captureActiveMeshesEvaluationTime},set:function(t){var i=this;t!==this._captureActiveMeshesEvaluationTime&&(this._captureActiveMeshesEvaluationTime=t,t?(this._onBeforeActiveMeshesEvaluationObserver=this.scene.onBeforeActiveMeshesEvaluationObservable.add((function(){e.Tools.StartPerformanceCounter("Active meshes evaluation"),i._activeMeshesEvaluationTime.beginMonitoring()})),this._onAfterActiveMeshesEvaluationObserver=this.scene.onAfterActiveMeshesEvaluationObservable.add((function(){e.Tools.EndPerformanceCounter("Active meshes evaluation"),i._activeMeshesEvaluationTime.endMonitoring()}))):(this.scene.onBeforeActiveMeshesEvaluationObservable.remove(this._onBeforeActiveMeshesEvaluationObserver),this._onBeforeActiveMeshesEvaluationObserver=null,this.scene.onAfterActiveMeshesEvaluationObservable.remove(this._onAfterActiveMeshesEvaluationObserver),this._onAfterActiveMeshesEvaluationObserver=null))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"renderTargetsRenderTimeCounter",{get:function(){return this._renderTargetsRenderTime},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"captureRenderTargetsRenderTime",{get:function(){return this._captureRenderTargetsRenderTime},set:function(t){var i=this;t!==this._captureRenderTargetsRenderTime&&(this._captureRenderTargetsRenderTime=t,t?(this._onBeforeRenderTargetsRenderObserver=this.scene.OnBeforeRenderTargetsRenderObservable.add((function(){e.Tools.StartPerformanceCounter("Render targets rendering"),i._renderTargetsRenderTime.beginMonitoring()})),this._onAfterRenderTargetsRenderObserver=this.scene.OnAfterRenderTargetsRenderObservable.add((function(){e.Tools.EndPerformanceCounter("Render targets rendering"),i._renderTargetsRenderTime.endMonitoring(!1)}))):(this.scene.OnBeforeRenderTargetsRenderObservable.remove(this._onBeforeRenderTargetsRenderObserver),this._onBeforeRenderTargetsRenderObserver=null,this.scene.OnAfterRenderTargetsRenderObservable.remove(this._onAfterRenderTargetsRenderObserver),this._onAfterRenderTargetsRenderObserver=null))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"particlesRenderTimeCounter",{get:function(){return this._particlesRenderTime},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"captureParticlesRenderTime",{get:function(){return this._captureParticlesRenderTime},set:function(t){var i=this;t!==this._captureParticlesRenderTime&&(this._captureParticlesRenderTime=t,t?(this._onBeforeParticlesRenderingObserver=this.scene.onBeforeParticlesRenderingObservable.add((function(){e.Tools.StartPerformanceCounter("Particles"),i._particlesRenderTime.beginMonitoring()})),this._onAfterParticlesRenderingObserver=this.scene.onAfterParticlesRenderingObservable.add((function(){e.Tools.EndPerformanceCounter("Particles"),i._particlesRenderTime.endMonitoring(!1)}))):(this.scene.onBeforeParticlesRenderingObservable.remove(this._onBeforeParticlesRenderingObserver),this._onBeforeParticlesRenderingObserver=null,this.scene.onAfterParticlesRenderingObservable.remove(this._onAfterParticlesRenderingObserver),this._onAfterParticlesRenderingObserver=null))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"spritesRenderTimeCounter",{get:function(){return this._spritesRenderTime},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"captureSpritesRenderTime",{get:function(){return this._captureSpritesRenderTime},set:function(t){var i=this;t!==this._captureSpritesRenderTime&&(this._captureSpritesRenderTime=t,t?(this._onBeforeSpritesRenderingObserver=this.scene.onBeforeSpritesRenderingObservable.add((function(){e.Tools.StartPerformanceCounter("Sprites"),i._spritesRenderTime.beginMonitoring()})),this._onAfterSpritesRenderingObserver=this.scene.onAfterSpritesRenderingObservable.add((function(){e.Tools.EndPerformanceCounter("Sprites"),i._spritesRenderTime.endMonitoring(!1)}))):(this.scene.onBeforeSpritesRenderingObservable.remove(this._onBeforeSpritesRenderingObserver),this._onBeforeSpritesRenderingObserver=null,this.scene.onAfterSpritesRenderingObservable.remove(this._onAfterSpritesRenderingObserver),this._onAfterSpritesRenderingObserver=null))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"physicsTimeCounter",{get:function(){return this._physicsTime},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"capturePhysicsTime",{get:function(){return this._capturePhysicsTime},set:function(t){var i=this;t!==this._capturePhysicsTime&&(this._capturePhysicsTime=t,t?(this._onBeforePhysicsObserver=this.scene.onBeforePhysicsObservable.add((function(){e.Tools.StartPerformanceCounter("Physics"),i._physicsTime.beginMonitoring()})),this._onAfterPhysicsObserver=this.scene.onAfterPhysicsObservable.add((function(){e.Tools.EndPerformanceCounter("Physics"),i._physicsTime.endMonitoring()}))):(this.scene.onBeforePhysicsObservable.remove(this._onBeforePhysicsObserver),this._onBeforePhysicsObserver=null,this.scene.onAfterPhysicsObservable.remove(this._onAfterPhysicsObserver),this._onAfterPhysicsObserver=null))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"animationsTimeCounter",{get:function(){return this._animationsTime},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"captureAnimationsTime",{get:function(){return this._captureAnimationsTime},set:function(e){var t=this;e!==this._captureAnimationsTime&&(this._captureAnimationsTime=e,e?this._onAfterAnimationsObserver=this.scene.onAfterAnimationsObservable.add((function(){t._animationsTime.endMonitoring()})):(this.scene.onAfterAnimationsObservable.remove(this._onAfterAnimationsObserver),this._onAfterAnimationsObserver=null))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"frameTimeCounter",{get:function(){return this._frameTime},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"captureFrameTime",{get:function(){return this._captureFrameTime},set:function(e){this._captureFrameTime=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"interFrameTimeCounter",{get:function(){return this._interFrameTime},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"captureInterFrameTime",{get:function(){return this._captureInterFrameTime},set:function(e){this._captureInterFrameTime=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"renderTimeCounter",{get:function(){return this._renderTime},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"captureRenderTime",{get:function(){return this._captureRenderTime},set:function(t){var i=this;t!==this._captureRenderTime&&(this._captureRenderTime=t,t?(this._onBeforeDrawPhaseObserver=this.scene.onBeforeDrawPhaseObservable.add((function(){i._renderTime.beginMonitoring(),e.Tools.StartPerformanceCounter("Main render")})),this._onAfterDrawPhaseObserver=this.scene.onAfterDrawPhaseObservable.add((function(){i._renderTime.endMonitoring(!1),e.Tools.EndPerformanceCounter("Main render")}))):(this.scene.onBeforeDrawPhaseObservable.remove(this._onBeforeDrawPhaseObserver),this._onBeforeDrawPhaseObserver=null,this.scene.onAfterDrawPhaseObservable.remove(this._onAfterDrawPhaseObserver),this._onAfterDrawPhaseObserver=null))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"drawCallsCounter",{get:function(){return this.scene.getEngine()._drawCalls},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"textureCollisionsCounter",{get:function(){return this.scene.getEngine()._textureCollisions},enumerable:!0,configurable:!0}),t.prototype.dispose=function(){this.scene.onAfterRenderObservable.remove(this._onAfterRenderObserver),this._onAfterRenderObserver=null,this.scene.onBeforeActiveMeshesEvaluationObservable.remove(this._onBeforeActiveMeshesEvaluationObserver),this._onBeforeActiveMeshesEvaluationObserver=null,this.scene.onAfterActiveMeshesEvaluationObservable.remove(this._onAfterActiveMeshesEvaluationObserver),this._onAfterActiveMeshesEvaluationObserver=null,this.scene.OnBeforeRenderTargetsRenderObservable.remove(this._onBeforeRenderTargetsRenderObserver),this._onBeforeRenderTargetsRenderObserver=null,this.scene.OnAfterRenderTargetsRenderObservable.remove(this._onAfterRenderTargetsRenderObserver),this._onAfterRenderTargetsRenderObserver=null,this.scene.onBeforeAnimationsObservable.remove(this._onBeforeAnimationsObserver),this._onBeforeAnimationsObserver=null,this.scene.onBeforeParticlesRenderingObservable.remove(this._onBeforeParticlesRenderingObserver),this._onBeforeParticlesRenderingObserver=null,this.scene.onAfterParticlesRenderingObservable.remove(this._onAfterParticlesRenderingObserver),this._onAfterParticlesRenderingObserver=null,this.scene.onBeforeSpritesRenderingObservable.remove(this._onBeforeSpritesRenderingObserver),this._onBeforeSpritesRenderingObserver=null,this.scene.onAfterSpritesRenderingObservable.remove(this._onAfterSpritesRenderingObserver),this._onAfterSpritesRenderingObserver=null,this.scene.onBeforeDrawPhaseObservable.remove(this._onBeforeDrawPhaseObserver),this._onBeforeDrawPhaseObserver=null,this.scene.onAfterDrawPhaseObservable.remove(this._onAfterDrawPhaseObserver),this._onAfterDrawPhaseObserver=null,this.scene.onBeforePhysicsObservable.remove(this._onBeforePhysicsObserver),this._onBeforePhysicsObserver=null,this.scene.onAfterPhysicsObservable.remove(this._onAfterPhysicsObserver),this._onAfterPhysicsObserver=null,this.scene.onAfterAnimationsObservable.remove(this._onAfterAnimationsObserver),this._onAfterAnimationsObserver=null,this.scene=null},t})();e.SceneInstrumentation=t})(e||(e={}));var e;!(function(e){var t=(function(){function e(){this._timeElapsedQueryEnded=!1}return e})();e._TimeToken=t})(e||(e={}));var e;!(function(e){var t=(function(e){function t(){var t=e.call(this)||this;return t.DIFFUSE=!1,t.DIFFUSEDIRECTUV=0,t.GAMMADIFFUSE=!1,t.DIFFUSEHASALPHA=!1,t.OPACITYFRESNEL=!1,t.REFLECTIONBLUR=!1,t.REFLECTIONFRESNEL=!1,t.REFLECTIONFALLOFF=!1,t.TEXTURELODSUPPORT=!1,t.PREMULTIPLYALPHA=!1,t.USERGBCOLOR=!1,t.NOISE=!1,t.REFLECTIONBGR=!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.GRAIN=!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.EQUIRECTANGULAR_RELFECTION_FOV=!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 __extends(t,e),t})(e.MaterialDefines),i=(function(i){function r(t,r){var n=i.call(this,t,r)||this;return n.primaryColor=e.Color3.White(),n.primaryLevel=1,n.secondaryColor=e.Color3.Gray(),n.secondaryLevel=1,n.tertiaryColor=e.Color3.Black(),n.tertiaryLevel=1,n.reflectionTexture=null,n.reflectionBlur=0,n.diffuseTexture=null,n._shadowLights=null,n.shadowLights=null,n.shadowBlurScale=1,n.shadowLevel=0,n.sceneCenter=e.Vector3.Zero(),n.opacityFresnel=!0,n.reflectionFresnel=!1,n.reflectionFalloffDistance=0,n.reflectionAmount=1,n.reflectionReflectance0=.05,n.reflectionReflectance90=.5,n.useRGBColor=!0,n.enableNoise=!1,n._fovMultiplier=1,n.useEquirectangularFOV=!1,n._maxSimultaneousLights=4,n.maxSimultaneousLights=4,n._imageProcessingObserver=null,n.switchToBGR=!1,n._renderTargets=new e.SmartArray(16),n._reflectionControls=e.Vector4.Zero(),n._attachImageProcessingConfiguration(null),n.getRenderTargetTextures=function(){return n._renderTargets.reset(),n._diffuseTexture&&n._diffuseTexture.isRenderTarget&&n._renderTargets.push(n._diffuseTexture),n._reflectionTexture&&n._reflectionTexture.isRenderTarget&&n._renderTargets.push(n._reflectionTexture),n._renderTargets},n}return __extends(r,i),Object.defineProperty(r.prototype,"reflectionStandardFresnelWeight",{set:function(e){var t=e;t<.5?(t*=2,this.reflectionReflectance0=r.StandardReflectance0*t,this.reflectionReflectance90=r.StandardReflectance90*t):(t=2*t-1,this.reflectionReflectance0=r.StandardReflectance0+(1-r.StandardReflectance0)*t,this.reflectionReflectance90=r.StandardReflectance90+(1-r.StandardReflectance90)*t)},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"fovMultiplier",{get:function(){return this._fovMultiplier},set:function(e){isNaN(e)&&(e=1),this._fovMultiplier=Math.max(0,Math.min(2,e))},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,"imageProcessingConfiguration",{get:function(){return this._imageProcessingConfiguration},set:function(e){this._attachImageProcessingConfiguration(e),this._markAllSubMeshesAsTexturesDirty()},enumerable:!0,configurable:!0}),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.needAlphaTesting=function(){return!0},r.prototype.needAlphaBlending=function(){return this.alpha<0||null!=this._diffuseTexture&&this._diffuseTexture.hasAlpha},r.prototype.isReadyForSubMesh=function(i,r,n){var o=this;if(void 0===n&&(n=!1),r.effect&&this.isFrozen&&this._wasPreviouslyReady)return!0;r._materialDefines||(r._materialDefines=new t);var s=this.getScene(),a=r._materialDefines;if(!this.checkReadyOnEveryCall&&r.effect&&a._renderId===s.getRenderId())return!0;var l=s.getEngine();if(e.MaterialHelper.PrepareDefinesForLights(s,i,a,!1,this._maxSimultaneousLights),a._needNormals=!0,a._areTexturesDirty){if(a._needUVs=!1,s.texturesEnabled){if(s.getEngine().getCaps().textureLOD&&(a.TEXTURELODSUPPORT=!0),this._diffuseTexture&&e.StandardMaterial.DiffuseTextureEnabled){if(!this._diffuseTexture.isReadyOrNotBlocking())return!1;e.MaterialHelper.PrepareDefinesForMergedUV(this._diffuseTexture,a,"DIFFUSE"),a.DIFFUSEHASALPHA=this._diffuseTexture.hasAlpha,a.GAMMADIFFUSE=this._diffuseTexture.gammaSpace,a.OPACITYFRESNEL=this._opacityFresnel}else a.DIFFUSE=!1,a.DIFFUSEHASALPHA=!1,a.GAMMADIFFUSE=!1,a.OPACITYFRESNEL=!1;var c=this._reflectionTexture;if(c&&e.StandardMaterial.ReflectionTextureEnabled){if(!c.isReadyOrNotBlocking())return!1;switch(a.REFLECTION=!0,a.GAMMAREFLECTION=c.gammaSpace,a.REFLECTIONBLUR=this._reflectionBlur>0,a.REFLECTIONMAP_OPPOSITEZ=this.getScene().useRightHandedSystem?!c.invertZ:c.invertZ,a.LODINREFLECTIONALPHA=c.lodLevelInAlpha,a.EQUIRECTANGULAR_RELFECTION_FOV=this.useEquirectangularFOV,a.REFLECTIONBGR=this.switchToBGR,c.coordinatesMode===e.Texture.INVCUBIC_MODE&&(a.INVERTCUBICMAP=!0),a.REFLECTIONMAP_3D=c.isCube,c.coordinatesMode){case e.Texture.CUBIC_MODE:case e.Texture.INVCUBIC_MODE:a.REFLECTIONMAP_CUBIC=!0;break;case e.Texture.EXPLICIT_MODE:a.REFLECTIONMAP_EXPLICIT=!0;break;case e.Texture.PLANAR_MODE:a.REFLECTIONMAP_PLANAR=!0;break;case e.Texture.PROJECTION_MODE:a.REFLECTIONMAP_PROJECTION=!0;break;case e.Texture.SKYBOX_MODE:a.REFLECTIONMAP_SKYBOX=!0;break;case e.Texture.SPHERICAL_MODE:a.REFLECTIONMAP_SPHERICAL=!0;break;case e.Texture.EQUIRECTANGULAR_MODE:a.REFLECTIONMAP_EQUIRECTANGULAR=!0;break;case e.Texture.FIXED_EQUIRECTANGULAR_MODE:a.REFLECTIONMAP_EQUIRECTANGULAR_FIXED=!0;break;case e.Texture.FIXED_EQUIRECTANGULAR_MIRRORED_MODE:a.REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED=!0}this.reflectionFresnel?(a.REFLECTIONFRESNEL=!0,a.REFLECTIONFALLOFF=this.reflectionFalloffDistance>0,this._reflectionControls.x=this.reflectionAmount,this._reflectionControls.y=this.reflectionReflectance0,this._reflectionControls.z=this.reflectionReflectance90,this._reflectionControls.w=1/this.reflectionFalloffDistance):(a.REFLECTIONFRESNEL=!1,a.REFLECTIONFALLOFF=!1)}else a.REFLECTION=!1,a.REFLECTIONFALLOFF=!1,a.REFLECTIONBLUR=!1,a.REFLECTIONMAP_3D=!1,a.REFLECTIONMAP_SPHERICAL=!1,a.REFLECTIONMAP_PLANAR=!1,a.REFLECTIONMAP_CUBIC=!1,a.REFLECTIONMAP_PROJECTION=!1,a.REFLECTIONMAP_SKYBOX=!1,a.REFLECTIONMAP_EXPLICIT=!1,a.REFLECTIONMAP_EQUIRECTANGULAR=!1,a.REFLECTIONMAP_EQUIRECTANGULAR_FIXED=!1,a.REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED=!1,a.INVERTCUBICMAP=!1,a.REFLECTIONMAP_OPPOSITEZ=!1,a.LODINREFLECTIONALPHA=!1,a.GAMMAREFLECTION=!1}a.PREMULTIPLYALPHA=this.alphaMode===e.Engine.ALPHA_PREMULTIPLIED||this.alphaMode===e.Engine.ALPHA_PREMULTIPLIED_PORTERDUFF,a.USERGBCOLOR=this._useRGBColor,a.NOISE=this._enableNoise}if(a._areImageProcessingDirty){if(!this._imageProcessingConfiguration.isReady())return!1;this._imageProcessingConfiguration.prepareDefines(a)}if(e.MaterialHelper.PrepareDefinesForMisc(i,s,!1,this.pointsCloud,this.fogEnabled,this._shouldTurnAlphaTestOn(i),a),e.MaterialHelper.PrepareDefinesForFrameBoundValues(s,l,a,n),e.MaterialHelper.PrepareDefinesForAttributes(i,a,!1,!0,!1)&&i&&(s.getEngine().getCaps().standardDerivatives||i.isVerticesDataPresent(e.VertexBuffer.NormalKind)||(i.createNormals(!0),e.Tools.Warn("BackgroundMaterial: Normals have been created for the mesh: "+i.name))),a.isDirty){a.markAsProcessed(),s.resetCachedMaterial();var h=new e.EffectFallbacks;a.FOG&&h.addFallback(0,"FOG"),a.POINTSIZE&&h.addFallback(1,"POINTSIZE"),e.MaterialHelper.HandleFallbacksForShadows(a,h,this._maxSimultaneousLights),a.NUM_BONE_INFLUENCERS>0&&h.addCPUSkinningFallback(0,i);var u=[e.VertexBuffer.PositionKind];a.NORMAL&&u.push(e.VertexBuffer.NormalKind),a.UV1&&u.push(e.VertexBuffer.UVKind),a.UV2&&u.push(e.VertexBuffer.UV2Kind),e.MaterialHelper.PrepareAttributesForBones(u,i,a,h),e.MaterialHelper.PrepareAttributesForInstances(u,a);var f=["world","view","viewProjection","vEyePosition","vLightsType","vFogInfos","vFogColor","pointSize","vClipPlane","mBones","vPrimaryColor","vSecondaryColor","vTertiaryColor","vReflectionInfos","reflectionMatrix","vReflectionMicrosurfaceInfos","fFovMultiplier","shadowLevel","alpha","vBackgroundCenter","vReflectionControl","vDiffuseInfos","diffuseMatrix"],d=["diffuseSampler","reflectionSampler","reflectionSamplerLow","reflectionSamplerHigh"],p=["Material","Scene"];e.ImageProcessingConfiguration.PrepareUniforms(f,a),e.ImageProcessingConfiguration.PrepareSamplers(d,a),e.MaterialHelper.PrepareUniformsAndSamplersList({uniformsNames:f,uniformBuffersNames:p,samplers:d,defines:a,maxSimultaneousLights:this._maxSimultaneousLights});var _=function(e){o.onCompiled&&o.onCompiled(e),o.bindSceneUniformBuffer(e,s.getSceneUniformBuffer())},m=a.toString();r.setEffect(s.getEngine().createEffect("background",{attributes:u,uniformsNames:f,uniformBuffersNames:p,samplers:d,defines:m,fallbacks:h,onCompiled:_,onError:this.onError,indexParameters:{maxSimultaneousLights:this._maxSimultaneousLights}},l),a),this.buildUniformLayout()}return!(!r.effect||!r.effect.isReady())&&(a._renderId=s.getRenderId(),this._wasPreviouslyReady=!0,!0)},r.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("fFovMultiplier",1),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()},r.prototype.unbind=function(){this._diffuseTexture&&this._diffuseTexture.isRenderTarget&&this._uniformBuffer.setTexture("diffuseSampler",null),this._reflectionTexture&&this._reflectionTexture.isRenderTarget&&this._uniformBuffer.setTexture("reflectionSampler",null),i.prototype.unbind.call(this)},r.prototype.bindOnlyWorldMatrix=function(e){this._activeEffect.setMatrix("world",e)},r.prototype.bindForSubMesh=function(t,i,r){var n=this.getScene(),o=r._materialDefines;if(o){var s=r.effect;if(s){this._activeEffect=s,this.bindOnlyWorldMatrix(t),e.MaterialHelper.BindBonesParameters(i,this._activeEffect);var a=this._mustRebind(n,s,i.visibility);if(a){this._uniformBuffer.bindToEffect(s,"Material"),this.bindViewProjection(s);var l=this._reflectionTexture;this._uniformBuffer.useUbo&&this.isFrozen&&this._uniformBuffer.isSync||(n.texturesEnabled&&(this._diffuseTexture&&e.StandardMaterial.DiffuseTextureEnabled&&(this._uniformBuffer.updateFloat2("vDiffuseInfos",this._diffuseTexture.coordinatesIndex,this._diffuseTexture.level),e.MaterialHelper.BindTextureMatrix(this._diffuseTexture,this._uniformBuffer,"diffuse")),l&&e.StandardMaterial.ReflectionTextureEnabled&&(this._uniformBuffer.updateMatrix("reflectionMatrix",l.getReflectionTextureMatrix()),this._uniformBuffer.updateFloat2("vReflectionInfos",l.level,this._reflectionBlur),this._uniformBuffer.updateFloat3("vReflectionMicrosurfaceInfos",l.getSize().width,l.lodGenerationScale,l.lodGenerationOffset))),this.shadowLevel>0&&this._uniformBuffer.updateFloat("shadowLevel",this.shadowLevel),this._uniformBuffer.updateFloat("alpha",this.alpha),this.pointsCloud&&this._uniformBuffer.updateFloat("pointSize",this.pointSize),this._uniformBuffer.updateColor4("vPrimaryColor",this._primaryColor,this._primaryLevel),this._uniformBuffer.updateColor4("vSecondaryColor",this._secondaryColor,this._secondaryLevel),this._uniformBuffer.updateColor4("vTertiaryColor",this._tertiaryColor,this._tertiaryLevel)),this._uniformBuffer.updateFloat("fFovMultiplier",this._fovMultiplier),n.texturesEnabled&&(this._diffuseTexture&&e.StandardMaterial.DiffuseTextureEnabled&&this._uniformBuffer.setTexture("diffuseSampler",this._diffuseTexture),l&&e.StandardMaterial.ReflectionTextureEnabled&&(o.REFLECTIONBLUR&&o.TEXTURELODSUPPORT?this._uniformBuffer.setTexture("reflectionSampler",l):o.REFLECTIONBLUR?(this._uniformBuffer.setTexture("reflectionSampler",l._lodTextureMid||l),this._uniformBuffer.setTexture("reflectionSamplerLow",l._lodTextureLow||l),this._uniformBuffer.setTexture("reflectionSamplerHigh",l._lodTextureHigh||l)):this._uniformBuffer.setTexture("reflectionSampler",l),o.REFLECTIONFRESNEL&&(this._uniformBuffer.updateFloat3("vBackgroundCenter",this.sceneCenter.x,this.sceneCenter.y,this.sceneCenter.z),this._uniformBuffer.updateFloat4("vReflectionControl",this._reflectionControls.x,this._reflectionControls.y,this._reflectionControls.z,this._reflectionControls.w)))),e.MaterialHelper.BindClipPlane(this._activeEffect,n),e.MaterialHelper.BindEyePosition(s,n)}!a&&this.isFrozen||(n.lightsEnabled&&e.MaterialHelper.BindLights(n,i,this._activeEffect,o,this._maxSimultaneousLights,!1),this.bindView(s),e.MaterialHelper.BindFogParameters(n,i,this._activeEffect),this._imageProcessingConfiguration.bind(this._activeEffect)),this._uniformBuffer.update(),this._afterBind(i)}}},r.prototype.dispose=function(e,t){void 0===e&&(e=!1),void 0===t&&(t=!1),t&&(this.diffuseTexture&&this.diffuseTexture.dispose(),this.reflectionTexture&&this.reflectionTexture.dispose()),this._renderTargets.dispose(),this._imageProcessingConfiguration&&this._imageProcessingObserver&&this._imageProcessingConfiguration.onUpdateParameters.remove(this._imageProcessingObserver),i.prototype.dispose.call(this,e)},r.prototype.clone=function(t){var i=this;return e.SerializationHelper.Clone((function(){return new r(t,i.getScene())}),this)},r.prototype.serialize=function(){var t=e.SerializationHelper.Serialize(this);return t.customType="BABYLON.BackgroundMaterial",t},r.prototype.getClassName=function(){return"BackgroundMaterial"},r.Parse=function(t,i,n){return e.SerializationHelper.Parse((function(){return new r(t.name,i)}),t,i,n)},r.StandardReflectance0=.05,r.StandardReflectance90=.5,__decorate([e.serializeAsColor3()],r.prototype,"_primaryColor",void 0),__decorate([e.expandToProperty("_markAllSubMeshesAsLightsDirty")],r.prototype,"primaryColor",void 0),__decorate([e.serialize()],r.prototype,"_primaryLevel",void 0),__decorate([e.expandToProperty("_markAllSubMeshesAsLightsDirty")],r.prototype,"primaryLevel",void 0),__decorate([e.serializeAsColor3()],r.prototype,"_secondaryColor",void 0),__decorate([e.expandToProperty("_markAllSubMeshesAsLightsDirty")],r.prototype,"secondaryColor",void 0),__decorate([e.serialize()],r.prototype,"_secondaryLevel",void 0),__decorate([e.expandToProperty("_markAllSubMeshesAsLightsDirty")],r.prototype,"secondaryLevel",void 0),__decorate([e.serializeAsColor3()],r.prototype,"_tertiaryColor",void 0),__decorate([e.expandToProperty("_markAllSubMeshesAsLightsDirty")],r.prototype,"tertiaryColor",void 0),__decorate([e.serialize()],r.prototype,"_tertiaryLevel",void 0),__decorate([e.expandToProperty("_markAllSubMeshesAsLightsDirty")],r.prototype,"tertiaryLevel",void 0),__decorate([e.serializeAsTexture()],r.prototype,"_reflectionTexture",void 0),__decorate([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"reflectionTexture",void 0),__decorate([e.serialize()],r.prototype,"_reflectionBlur",void 0),__decorate([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"reflectionBlur",void 0),__decorate([e.serializeAsTexture()],r.prototype,"_diffuseTexture",void 0),__decorate([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"diffuseTexture",void 0),__decorate([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"shadowLights",void 0),__decorate([e.serialize()],r.prototype,"_shadowBlurScale",void 0),__decorate([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"shadowBlurScale",void 0),__decorate([e.serialize()],r.prototype,"_shadowLevel",void 0),__decorate([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"shadowLevel",void 0),__decorate([e.serializeAsVector3()],r.prototype,"_sceneCenter",void 0),__decorate([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"sceneCenter",void 0),__decorate([e.serialize()],r.prototype,"_opacityFresnel",void 0),__decorate([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"opacityFresnel",void 0),__decorate([e.serialize()],r.prototype,"_reflectionFresnel",void 0),__decorate([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"reflectionFresnel",void 0),__decorate([e.serialize()],r.prototype,"_reflectionFalloffDistance",void 0),__decorate([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"reflectionFalloffDistance",void 0),__decorate([e.serialize()],r.prototype,"_reflectionAmount",void 0),__decorate([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"reflectionAmount",void 0),__decorate([e.serialize()],r.prototype,"_reflectionReflectance0",void 0),__decorate([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"reflectionReflectance0",void 0),__decorate([e.serialize()],r.prototype,"_reflectionReflectance90",void 0),__decorate([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"reflectionReflectance90",void 0),__decorate([e.serialize()],r.prototype,"_useRGBColor",void 0),__decorate([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"useRGBColor",void 0),__decorate([e.serialize()],r.prototype,"_enableNoise",void 0),__decorate([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"enableNoise",void 0),__decorate([e.serialize()],r.prototype,"_maxSimultaneousLights",void 0),__decorate([e.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"maxSimultaneousLights",void 0),__decorate([e.serializeAsImageProcessingConfiguration()],r.prototype,"_imageProcessingConfiguration",void 0),r})(e.PushMaterial);e.BackgroundMaterial=i})(e||(e={}));var e,t=this&&this.__assign||Object.assign||function(e){for(var t,i=1,r=arguments.length;ii&&(i=2*a,r=i),i*=1.1,r*=1.5,n=o.min.add(s.scale(.5)),n.y=o.min.y-this._options.groundYBias}return{groundSize:i,skyboxSize:r,rootPosition:n}},i.prototype._setupGround=function(t){var i=this;this._ground||(this._ground=e.Mesh.CreatePlane("BackgroundPlane",t.groundSize,this._scene),this._ground.rotation.x=Math.PI/2,this._ground.parent=this._rootMesh,this._ground.onDisposeObservable.add((function(){i._ground=null}))),this._ground.receiveShadows=this._options.enableGroundShadow},i.prototype._setupGroundMaterial=function(){this._groundMaterial||(this._groundMaterial=new e.BackgroundMaterial("BackgroundPlaneMaterial",this._scene)),this._groundMaterial.alpha=this._options.groundOpacity,this._groundMaterial.alphaMode=e.Engine.ALPHA_PREMULTIPLIED_PORTERDUFF,this._groundMaterial.shadowLevel=this._options.groundShadowLevel,this._groundMaterial.primaryLevel=1,this._groundMaterial.primaryColor=this._options.groundColor,this._groundMaterial.secondaryLevel=0,this._groundMaterial.tertiaryLevel=0,this._groundMaterial.useRGBColor=!1,this._groundMaterial.enableNoise=!0,this._ground&&(this._ground.material=this._groundMaterial)},i.prototype._setupGroundDiffuseTexture=function(){if(this._groundMaterial&&!this._groundTexture){if(this._options.groundTexture instanceof e.BaseTexture)return void(this._groundMaterial.diffuseTexture=this._options.groundTexture);var t=new e.Texture(this._options.groundTexture,this._scene,void 0,void 0,void 0,void 0,this._errorHandler);t.gammaSpace=!1,t.hasAlpha=!0,this._groundMaterial.diffuseTexture=t}},i.prototype._setupGroundMirrorTexture=function(t){var i=e.Texture.CLAMP_ADDRESSMODE;if(!this._groundMirror&&(this._groundMirror=new e.MirrorTexture("BackgroundPlaneMirrorTexture",{ratio:this._options.groundMirrorSizeRatio},this._scene,!1,this._options.groundMirrorTextureType,e.Texture.BILINEAR_SAMPLINGMODE,!0),this._groundMirror.mirrorPlane=new e.Plane(0,-1,0,t.rootPosition.y),this._groundMirror.anisotropicFilteringLevel=1,this._groundMirror.wrapU=i,this._groundMirror.wrapV=i,this._groundMirror.gammaSpace=!1,this._groundMirror.renderList))for(var r=0;r\n\n#define CUSTOM_VERTEX_BEGIN\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\n#endif\n#ifdef TANGENT\nattribute vec4 tangent;\n#endif\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#ifdef VERTEXCOLOR\nattribute vec4 color;\n#endif\n#include\n#include\n\n#include\n#ifdef MAINUV1\nvarying vec2 vMainUV1;\n#endif\n#ifdef MAINUV2\nvarying vec2 vMainUV2;\n#endif\n#if defined(DIFFUSE) && DIFFUSEDIRECTUV == 0\nvarying vec2 vDiffuseUV;\n#endif\n#if defined(AMBIENT) && AMBIENTDIRECTUV == 0\nvarying vec2 vAmbientUV;\n#endif\n#if defined(OPACITY) && OPACITYDIRECTUV == 0\nvarying vec2 vOpacityUV;\n#endif\n#if defined(EMISSIVE) && EMISSIVEDIRECTUV == 0\nvarying vec2 vEmissiveUV;\n#endif\n#if defined(LIGHTMAP) && LIGHTMAPDIRECTUV == 0\nvarying vec2 vLightmapUV;\n#endif\n#if defined(SPECULAR) && defined(SPECULARTERM) && SPECULARDIRECTUV == 0\nvarying vec2 vSpecularUV;\n#endif\n#if defined(BUMP) && BUMPDIRECTUV == 0\nvarying vec2 vBumpUV;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include\n#include\n#include\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include\n#include[0..maxSimultaneousMorphTargets]\n#ifdef REFLECTIONMAP_SKYBOX\nvarying vec3 vPositionUVW;\n#endif\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvarying vec3 vDirectionW;\n#endif\n#include\n#define CUSTOM_VERTEX_DEFINITIONS\nvoid main(void) {\n#define CUSTOM_VERTEX_MAIN_BEGIN\nvec3 positionUpdated=position;\n#ifdef NORMAL \nvec3 normalUpdated=normal;\n#endif\n#ifdef TANGENT\nvec4 tangentUpdated=tangent;\n#endif\n#include[0..maxSimultaneousMorphTargets]\n#ifdef REFLECTIONMAP_SKYBOX\nvPositionUVW=positionUpdated;\n#endif \n#define CUSTOM_VERTEX_UPDATE_POSITION\n#define CUSTOM_VERTEX_UPDATE_NORMAL\n#include\n#include\ngl_Position=viewProjection*finalWorld*vec4(positionUpdated,1.0);\nvec4 worldPos=finalWorld*vec4(positionUpdated,1.0);\nvPositionW=vec3(worldPos);\n#ifdef NORMAL\nmat3 normalWorld=mat3(finalWorld);\n#ifdef NONUNIFORMSCALING\nnormalWorld=transposeMat3(inverseMat3(normalWorld));\n#endif\nvNormalW=normalize(normalWorld*normalUpdated);\n#endif\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvDirectionW=normalize(vec3(finalWorld*vec4(positionUpdated,0.0)));\n#endif\n\n#ifndef UV1\nvec2 uv=vec2(0.,0.);\n#endif\n#ifndef UV2\nvec2 uv2=vec2(0.,0.);\n#endif\n#ifdef MAINUV1\nvMainUV1=uv;\n#endif\n#ifdef MAINUV2\nvMainUV2=uv2;\n#endif\n#if defined(DIFFUSE) && DIFFUSEDIRECTUV == 0\nif (vDiffuseInfos.x == 0.)\n{\nvDiffuseUV=vec2(diffuseMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvDiffuseUV=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(AMBIENT) && AMBIENTDIRECTUV == 0\nif (vAmbientInfos.x == 0.)\n{\nvAmbientUV=vec2(ambientMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvAmbientUV=vec2(ambientMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(OPACITY) && OPACITYDIRECTUV == 0\nif (vOpacityInfos.x == 0.)\n{\nvOpacityUV=vec2(opacityMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvOpacityUV=vec2(opacityMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(EMISSIVE) && EMISSIVEDIRECTUV == 0\nif (vEmissiveInfos.x == 0.)\n{\nvEmissiveUV=vec2(emissiveMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvEmissiveUV=vec2(emissiveMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(LIGHTMAP) && LIGHTMAPDIRECTUV == 0\nif (vLightmapInfos.x == 0.)\n{\nvLightmapUV=vec2(lightmapMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvLightmapUV=vec2(lightmapMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(SPECULAR) && defined(SPECULARTERM) && SPECULARDIRECTUV == 0\nif (vSpecularInfos.x == 0.)\n{\nvSpecularUV=vec2(specularMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvSpecularUV=vec2(specularMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(BUMP) && BUMPDIRECTUV == 0\nif (vBumpInfos.x == 0.)\n{\nvBumpUV=vec2(bumpMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvBumpUV=vec2(bumpMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#include\n#include\n#include\n#include[0..maxSimultaneousLights]\n#ifdef VERTEXCOLOR\n\nvColor=color;\n#endif\n#include\n#include\n#define CUSTOM_VERTEX_MAIN_END\n}\n", defaultPixelShader:"#include<__decl__defaultFragment>\n#if defined(BUMP) || !defined(NORMAL)\n#extension GL_OES_standard_derivatives : enable\n#endif\n#define CUSTOM_FRAGMENT_BEGIN\n#ifdef LOGARITHMICDEPTH\n#extension GL_EXT_frag_depth : enable\n#endif\n\n#define RECIPROCAL_PI2 0.15915494\nuniform vec3 vEyePosition;\nuniform vec3 vAmbientColor;\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#ifdef MAINUV1\nvarying vec2 vMainUV1;\n#endif\n#ifdef MAINUV2\nvarying vec2 vMainUV2;\n#endif\n\n#include\n\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include\n#include\n\n#ifdef DIFFUSE\n#if DIFFUSEDIRECTUV == 1\n#define vDiffuseUV vMainUV1\n#elif DIFFUSEDIRECTUV == 2\n#define vDiffuseUV vMainUV2\n#else\nvarying vec2 vDiffuseUV;\n#endif\nuniform sampler2D diffuseSampler;\n#endif\n#ifdef AMBIENT\n#if AMBIENTDIRECTUV == 1\n#define vAmbientUV vMainUV1\n#elif AMBIENTDIRECTUV == 2\n#define vAmbientUV vMainUV2\n#else\nvarying vec2 vAmbientUV;\n#endif\nuniform sampler2D ambientSampler;\n#endif\n#ifdef OPACITY \n#if OPACITYDIRECTUV == 1\n#define vOpacityUV vMainUV1\n#elif OPACITYDIRECTUV == 2\n#define vOpacityUV vMainUV2\n#else\nvarying vec2 vOpacityUV;\n#endif\nuniform sampler2D opacitySampler;\n#endif\n#ifdef EMISSIVE\n#if EMISSIVEDIRECTUV == 1\n#define vEmissiveUV vMainUV1\n#elif EMISSIVEDIRECTUV == 2\n#define vEmissiveUV vMainUV2\n#else\nvarying vec2 vEmissiveUV;\n#endif\nuniform sampler2D emissiveSampler;\n#endif\n#ifdef LIGHTMAP\n#if LIGHTMAPDIRECTUV == 1\n#define vLightmapUV vMainUV1\n#elif LIGHTMAPDIRECTUV == 2\n#define vLightmapUV vMainUV2\n#else\nvarying vec2 vLightmapUV;\n#endif\nuniform sampler2D lightmapSampler;\n#endif\n#ifdef REFRACTION\n#ifdef REFRACTIONMAP_3D\nuniform samplerCube refractionCubeSampler;\n#else\nuniform sampler2D refraction2DSampler;\n#endif\n#endif\n#if defined(SPECULAR) && defined(SPECULARTERM)\n#if SPECULARDIRECTUV == 1\n#define vSpecularUV vMainUV1\n#elif SPECULARDIRECTUV == 2\n#define vSpecularUV vMainUV2\n#else\nvarying vec2 vSpecularUV;\n#endif\nuniform sampler2D specularSampler;\n#endif\n\n#include\n\n#ifdef REFLECTION\n#ifdef REFLECTIONMAP_3D\nuniform samplerCube reflectionCubeSampler;\n#else\nuniform sampler2D reflection2DSampler;\n#endif\n#ifdef REFLECTIONMAP_SKYBOX\nvarying vec3 vPositionUVW;\n#else\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvarying vec3 vDirectionW;\n#endif\n#endif\n#include\n#endif\n#include\n#include\n#include\n#include\n#include\n#include\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void) {\n#define CUSTOM_FRAGMENT_MAIN_BEGIN\n#include\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\nvec4 baseColor=vec4(1.,1.,1.,1.);\nvec3 diffuseColor=vDiffuseColor.rgb;\n\nfloat alpha=vDiffuseColor.a;\n\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=normalize(-cross(dFdx(vPositionW),dFdy(vPositionW)));\n#endif\n#include\n#ifdef TWOSIDEDLIGHTING\nnormalW=gl_FrontFacing ? normalW : -normalW;\n#endif\n#ifdef DIFFUSE\nbaseColor=texture2D(diffuseSampler,vDiffuseUV+uvOffset);\n#ifdef ALPHATEST\nif (baseColor.a<0.4)\ndiscard;\n#endif\n#ifdef ALPHAFROMDIFFUSE\nalpha*=baseColor.a;\n#endif\n#define CUSTOM_FRAGMENT_UPDATE_ALPHA\nbaseColor.rgb*=vDiffuseInfos.y;\n#endif\n#include\n#ifdef VERTEXCOLOR\nbaseColor.rgb*=vColor.rgb;\n#endif\n#define CUSTOM_FRAGMENT_UPDATE_DIFFUSE\n\nvec3 baseAmbientColor=vec3(1.,1.,1.);\n#ifdef AMBIENT\nbaseAmbientColor=texture2D(ambientSampler,vAmbientUV+uvOffset).rgb*vAmbientInfos.y;\n#endif\n#define CUSTOM_FRAGMENT_BEFORE_LIGHTS\n\n#ifdef SPECULARTERM\nfloat glossiness=vSpecularColor.a;\nvec3 specularColor=vSpecularColor.rgb;\n#ifdef SPECULAR\nvec4 specularMapColor=texture2D(specularSampler,vSpecularUV+uvOffset);\nspecularColor=specularMapColor.rgb;\n#ifdef GLOSSINESS\nglossiness=glossiness*specularMapColor.a;\n#endif\n#endif\n#else\nfloat glossiness=0.;\n#endif\n\nvec3 diffuseBase=vec3(0.,0.,0.);\nlightingInfo info;\n#ifdef SPECULARTERM\nvec3 specularBase=vec3(0.,0.,0.);\n#endif\nfloat shadow=1.;\n#ifdef LIGHTMAP\nvec3 lightmapColor=texture2D(lightmapSampler,vLightmapUV+uvOffset).rgb*vLightmapInfos.y;\n#endif\n#include[0..maxSimultaneousLights]\n\nvec3 refractionColor=vec3(0.,0.,0.);\n#ifdef REFRACTION\nvec3 refractionVector=normalize(refract(-viewDirectionW,normalW,vRefractionInfos.y));\n#ifdef REFRACTIONMAP_3D\nrefractionVector.y=refractionVector.y*vRefractionInfos.w;\nif (dot(refractionVector,viewDirectionW)<1.0)\n{\nrefractionColor=textureCube(refractionCubeSampler,refractionVector).rgb*vRefractionInfos.x;\n}\n#else\nvec3 vRefractionUVW=vec3(refractionMatrix*(view*vec4(vPositionW+refractionVector*vRefractionInfos.z,1.0)));\nvec2 refractionCoords=vRefractionUVW.xy/vRefractionUVW.z;\nrefractionCoords.y=1.0-refractionCoords.y;\nrefractionColor=texture2D(refraction2DSampler,refractionCoords).rgb*vRefractionInfos.x;\n#endif\n#endif\n\nvec3 reflectionColor=vec3(0.,0.,0.);\n#ifdef REFLECTION\nvec3 vReflectionUVW=computeReflectionCoords(vec4(vPositionW,1.0),normalW);\n#ifdef REFLECTIONMAP_3D\n#ifdef ROUGHNESS\nfloat bias=vReflectionInfos.y;\n#ifdef SPECULARTERM\n#ifdef SPECULAR\n#ifdef GLOSSINESS\nbias*=(1.0-specularMapColor.a);\n#endif\n#endif\n#endif\nreflectionColor=textureCube(reflectionCubeSampler,vReflectionUVW,bias).rgb*vReflectionInfos.x;\n#else\nreflectionColor=textureCube(reflectionCubeSampler,vReflectionUVW).rgb*vReflectionInfos.x;\n#endif\n#else\nvec2 coords=vReflectionUVW.xy;\n#ifdef REFLECTIONMAP_PROJECTION\ncoords/=vReflectionUVW.z;\n#endif\ncoords.y=1.0-coords.y;\nreflectionColor=texture2D(reflection2DSampler,coords).rgb*vReflectionInfos.x;\n#endif\n#ifdef REFLECTIONFRESNEL\nfloat reflectionFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,reflectionRightColor.a,reflectionLeftColor.a);\n#ifdef REFLECTIONFRESNELFROMSPECULAR\n#ifdef SPECULARTERM\nreflectionColor*=specularColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*reflectionRightColor.rgb;\n#else\nreflectionColor*=reflectionLeftColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*reflectionRightColor.rgb;\n#endif\n#else\nreflectionColor*=reflectionLeftColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*reflectionRightColor.rgb;\n#endif\n#endif\n#endif\n#ifdef REFRACTIONFRESNEL\nfloat refractionFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,refractionRightColor.a,refractionLeftColor.a);\nrefractionColor*=refractionLeftColor.rgb*(1.0-refractionFresnelTerm)+refractionFresnelTerm*refractionRightColor.rgb;\n#endif\n#ifdef OPACITY\nvec4 opacityMap=texture2D(opacitySampler,vOpacityUV+uvOffset);\n#ifdef OPACITYRGB\nopacityMap.rgb=opacityMap.rgb*vec3(0.3,0.59,0.11);\nalpha*=(opacityMap.x+opacityMap.y+opacityMap.z)* vOpacityInfos.y;\n#else\nalpha*=opacityMap.a*vOpacityInfos.y;\n#endif\n#endif\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\n#ifdef OPACITYFRESNEL\nfloat opacityFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,opacityParts.z,opacityParts.w);\nalpha+=opacityParts.x*(1.0-opacityFresnelTerm)+opacityFresnelTerm*opacityParts.y;\n#endif\n\nvec3 emissiveColor=vEmissiveColor;\n#ifdef EMISSIVE\nemissiveColor+=texture2D(emissiveSampler,vEmissiveUV+uvOffset).rgb*vEmissiveInfos.y;\n#endif\n#ifdef EMISSIVEFRESNEL\nfloat emissiveFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,emissiveRightColor.a,emissiveLeftColor.a);\nemissiveColor*=emissiveLeftColor.rgb*(1.0-emissiveFresnelTerm)+emissiveFresnelTerm*emissiveRightColor.rgb;\n#endif\n\n#ifdef DIFFUSEFRESNEL\nfloat diffuseFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,diffuseRightColor.a,diffuseLeftColor.a);\ndiffuseBase*=diffuseLeftColor.rgb*(1.0-diffuseFresnelTerm)+diffuseFresnelTerm*diffuseRightColor.rgb;\n#endif\n\n#ifdef EMISSIVEASILLUMINATION\nvec3 finalDiffuse=clamp(diffuseBase*diffuseColor+vAmbientColor,0.0,1.0)*baseColor.rgb;\n#else\n#ifdef LINKEMISSIVEWITHDIFFUSE\nvec3 finalDiffuse=clamp((diffuseBase+emissiveColor)*diffuseColor+vAmbientColor,0.0,1.0)*baseColor.rgb;\n#else\nvec3 finalDiffuse=clamp(diffuseBase*diffuseColor+emissiveColor+vAmbientColor,0.0,1.0)*baseColor.rgb;\n#endif\n#endif\n#ifdef SPECULARTERM\nvec3 finalSpecular=specularBase*specularColor;\n#ifdef SPECULAROVERALPHA\nalpha=clamp(alpha+dot(finalSpecular,vec3(0.3,0.59,0.11)),0.,1.);\n#endif\n#else\nvec3 finalSpecular=vec3(0.0);\n#endif\n#ifdef REFLECTIONOVERALPHA\nalpha=clamp(alpha+dot(reflectionColor,vec3(0.3,0.59,0.11)),0.,1.);\n#endif\n\n#ifdef EMISSIVEASILLUMINATION\nvec4 color=vec4(clamp(finalDiffuse*baseAmbientColor+finalSpecular+reflectionColor+emissiveColor+refractionColor,0.0,1.0),alpha);\n#else\nvec4 color=vec4(finalDiffuse*baseAmbientColor+finalSpecular+reflectionColor+refractionColor,alpha);\n#endif\n\n#ifdef LIGHTMAP\n#ifndef LIGHTMAPEXCLUDED\n#ifdef USELIGHTMAPASSHADOWMAP\ncolor.rgb*=lightmapColor;\n#else\ncolor.rgb+=lightmapColor;\n#endif\n#endif\n#endif\n#define CUSTOM_FRAGMENT_BEFORE_FOG\ncolor.rgb=max(color.rgb,0.);\n#include\n#include\n\n\n#ifdef IMAGEPROCESSINGPOSTPROCESS\ncolor.rgb=toLinearSpace(color.rgb);\n#else\n#ifdef IMAGEPROCESSING\ncolor.rgb=toLinearSpace(color.rgb);\ncolor=applyImageProcessing(color);\n#endif\n#endif\n#ifdef PREMULTIPLYALPHA\n\ncolor.rgb*=color.a;\n#endif\n#define CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR\ngl_FragColor=color;\n}\n",pbrVertexShader:"precision highp float;\n#include<__decl__pbrVertex>\n\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\n#endif\n#ifdef TANGENT\nattribute vec4 tangent;\n#endif\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#ifdef MAINUV1\nvarying vec2 vMainUV1;\n#endif\n#ifdef MAINUV2\nvarying vec2 vMainUV2; \n#endif \n#ifdef VERTEXCOLOR\nattribute vec4 color;\n#endif\n#include\n#include\n\n#include\n#if defined(ALBEDO) && ALBEDODIRECTUV == 0\nvarying vec2 vAlbedoUV;\n#endif\n#if defined(AMBIENT) && AMBIENTDIRECTUV == 0\nvarying vec2 vAmbientUV;\n#endif\n#if defined(OPACITY) && OPACITYDIRECTUV == 0\nvarying vec2 vOpacityUV;\n#endif\n#if defined(EMISSIVE) && EMISSIVEDIRECTUV == 0\nvarying vec2 vEmissiveUV;\n#endif\n#if defined(LIGHTMAP) && LIGHTMAPDIRECTUV == 0\nvarying vec2 vLightmapUV;\n#endif\n#if defined(REFLECTIVITY) && REFLECTIVITYDIRECTUV == 0\nvarying vec2 vReflectivityUV;\n#endif\n#if defined(MICROSURFACEMAP) && MICROSURFACEMAPDIRECTUV == 0\nvarying vec2 vMicroSurfaceSamplerUV;\n#endif\n#if defined(BUMP) && BUMPDIRECTUV == 0\nvarying vec2 vBumpUV;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#if defined(USESPHERICALFROMREFLECTIONMAP) && defined(USESPHERICALINVERTEX)\nvarying vec3 vEnvironmentIrradiance;\n#include\n#endif\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include\n#include\n#include\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include\n#include[0..maxSimultaneousMorphTargets]\n#ifdef REFLECTIONMAP_SKYBOX\nvarying vec3 vPositionUVW;\n#endif\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvarying vec3 vDirectionW;\n#endif\n#include\nvoid main(void) {\nvec3 positionUpdated=position;\n#ifdef NORMAL\nvec3 normalUpdated=normal;\n#endif\n#ifdef TANGENT\nvec4 tangentUpdated=tangent;\n#endif\n#include[0..maxSimultaneousMorphTargets]\n#ifdef REFLECTIONMAP_SKYBOX\nvPositionUVW=positionUpdated;\n#endif \n#include\n#include\ngl_Position=viewProjection*finalWorld*vec4(positionUpdated,1.0);\nvec4 worldPos=finalWorld*vec4(positionUpdated,1.0);\nvPositionW=vec3(worldPos);\n#ifdef NORMAL\nmat3 normalWorld=mat3(finalWorld);\n#ifdef NONUNIFORMSCALING\nnormalWorld=transposeMat3(inverseMat3(normalWorld));\n#endif\nvNormalW=normalize(normalWorld*normalUpdated);\n#if defined(USESPHERICALFROMREFLECTIONMAP) && defined(USESPHERICALINVERTEX)\nvec3 reflectionVector=vec3(reflectionMatrix*vec4(vNormalW,0)).xyz;\n#ifdef REFLECTIONMAP_OPPOSITEZ\nreflectionVector.z*=-1.0;\n#endif\nvEnvironmentIrradiance=environmentIrradianceJones(reflectionVector);\n#endif\n#endif\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvDirectionW=normalize(vec3(finalWorld*vec4(positionUpdated,0.0)));\n#endif\n\n#ifndef UV1\nvec2 uv=vec2(0.,0.);\n#endif\n#ifndef UV2\nvec2 uv2=vec2(0.,0.);\n#endif\n#ifdef MAINUV1\nvMainUV1=uv;\n#endif \n#ifdef MAINUV2\nvMainUV2=uv2;\n#endif \n#if defined(ALBEDO) && ALBEDODIRECTUV == 0 \nif (vAlbedoInfos.x == 0.)\n{\nvAlbedoUV=vec2(albedoMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvAlbedoUV=vec2(albedoMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(AMBIENT) && AMBIENTDIRECTUV == 0 \nif (vAmbientInfos.x == 0.)\n{\nvAmbientUV=vec2(ambientMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvAmbientUV=vec2(ambientMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(OPACITY) && OPACITYDIRECTUV == 0 \nif (vOpacityInfos.x == 0.)\n{\nvOpacityUV=vec2(opacityMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvOpacityUV=vec2(opacityMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(EMISSIVE) && EMISSIVEDIRECTUV == 0 \nif (vEmissiveInfos.x == 0.)\n{\nvEmissiveUV=vec2(emissiveMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvEmissiveUV=vec2(emissiveMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(LIGHTMAP) && LIGHTMAPDIRECTUV == 0 \nif (vLightmapInfos.x == 0.)\n{\nvLightmapUV=vec2(lightmapMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvLightmapUV=vec2(lightmapMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(REFLECTIVITY) && REFLECTIVITYDIRECTUV == 0 \nif (vReflectivityInfos.x == 0.)\n{\nvReflectivityUV=vec2(reflectivityMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvReflectivityUV=vec2(reflectivityMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(MICROSURFACEMAP) && MICROSURFACEMAPDIRECTUV == 0 \nif (vMicroSurfaceSamplerInfos.x == 0.)\n{\nvMicroSurfaceSamplerUV=vec2(microSurfaceSamplerMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvMicroSurfaceSamplerUV=vec2(microSurfaceSamplerMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(BUMP) && BUMPDIRECTUV == 0 \nif (vBumpInfos.x == 0.)\n{\nvBumpUV=vec2(bumpMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvBumpUV=vec2(bumpMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n\n#include\n\n#include\n\n#include\n\n#include[0..maxSimultaneousLights]\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n\n#include\n}", pbrPixelShader:"#if defined(BUMP) || !defined(NORMAL) || defined(FORCENORMALFORWARD)\n#extension GL_OES_standard_derivatives : enable\n#endif\n#ifdef LODBASEDMICROSFURACE\n#extension GL_EXT_shader_texture_lod : enable\n#endif\n#ifdef LOGARITHMICDEPTH\n#extension GL_EXT_frag_depth : enable\n#endif\nprecision highp float;\n#include<__decl__pbrFragment>\nuniform vec4 vEyePosition;\nuniform vec3 vAmbientColor;\nuniform vec4 vCameraInfos;\n\nvarying vec3 vPositionW;\n#ifdef MAINUV1\nvarying vec2 vMainUV1;\n#endif \n#ifdef MAINUV2 \nvarying vec2 vMainUV2;\n#endif \n#ifdef NORMAL\nvarying vec3 vNormalW;\n#if defined(USESPHERICALFROMREFLECTIONMAP) && defined(USESPHERICALINVERTEX)\nvarying vec3 vEnvironmentIrradiance;\n#endif\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n\n#ifdef ALBEDO\n#if ALBEDODIRECTUV == 1\n#define vAlbedoUV vMainUV1\n#elif ALBEDODIRECTUV == 2\n#define vAlbedoUV vMainUV2\n#else\nvarying vec2 vAlbedoUV;\n#endif\nuniform sampler2D albedoSampler;\n#endif\n#ifdef AMBIENT\n#if AMBIENTDIRECTUV == 1\n#define vAmbientUV vMainUV1\n#elif AMBIENTDIRECTUV == 2\n#define vAmbientUV vMainUV2\n#else\nvarying vec2 vAmbientUV;\n#endif\nuniform sampler2D ambientSampler;\n#endif\n#ifdef OPACITY\n#if OPACITYDIRECTUV == 1\n#define vOpacityUV vMainUV1\n#elif OPACITYDIRECTUV == 2\n#define vOpacityUV vMainUV2\n#else\nvarying vec2 vOpacityUV;\n#endif\nuniform sampler2D opacitySampler;\n#endif\n#ifdef EMISSIVE\n#if EMISSIVEDIRECTUV == 1\n#define vEmissiveUV vMainUV1\n#elif EMISSIVEDIRECTUV == 2\n#define vEmissiveUV vMainUV2\n#else\nvarying vec2 vEmissiveUV;\n#endif\nuniform sampler2D emissiveSampler;\n#endif\n#ifdef LIGHTMAP\n#if LIGHTMAPDIRECTUV == 1\n#define vLightmapUV vMainUV1\n#elif LIGHTMAPDIRECTUV == 2\n#define vLightmapUV vMainUV2\n#else\nvarying vec2 vLightmapUV;\n#endif\nuniform sampler2D lightmapSampler;\n#endif\n#ifdef REFLECTIVITY\n#if REFLECTIVITYDIRECTUV == 1\n#define vReflectivityUV vMainUV1\n#elif REFLECTIVITYDIRECTUV == 2\n#define vReflectivityUV vMainUV2\n#else\nvarying vec2 vReflectivityUV;\n#endif\nuniform sampler2D reflectivitySampler;\n#endif\n#ifdef MICROSURFACEMAP\n#if MICROSURFACEMAPDIRECTUV == 1\n#define vMicroSurfaceSamplerUV vMainUV1\n#elif MICROSURFACEMAPDIRECTUV == 2\n#define vMicroSurfaceSamplerUV vMainUV2\n#else\nvarying vec2 vMicroSurfaceSamplerUV;\n#endif\nuniform sampler2D microSurfaceSampler;\n#endif\n\n#ifdef REFRACTION\n#ifdef REFRACTIONMAP_3D\n#define sampleRefraction(s,c) textureCube(s,c)\nuniform samplerCube refractionSampler;\n#ifdef LODBASEDMICROSFURACE\n#define sampleRefractionLod(s,c,l) textureCubeLodEXT(s,c,l)\n#else\nuniform samplerCube refractionSamplerLow;\nuniform samplerCube refractionSamplerHigh;\n#endif\n#else\n#define sampleRefraction(s,c) texture2D(s,c)\nuniform sampler2D refractionSampler;\n#ifdef LODBASEDMICROSFURACE\n#define sampleRefractionLod(s,c,l) texture2DLodEXT(s,c,l)\n#else\nuniform samplerCube refractionSamplerLow;\nuniform samplerCube refractionSamplerHigh;\n#endif\n#endif\n#endif\n\n#ifdef REFLECTION\n#ifdef REFLECTIONMAP_3D\n#define sampleReflection(s,c) textureCube(s,c)\nuniform samplerCube reflectionSampler;\n#ifdef LODBASEDMICROSFURACE\n#define sampleReflectionLod(s,c,l) textureCubeLodEXT(s,c,l)\n#else\nuniform samplerCube reflectionSamplerLow;\nuniform samplerCube reflectionSamplerHigh;\n#endif\n#else\n#define sampleReflection(s,c) texture2D(s,c)\nuniform sampler2D reflectionSampler;\n#ifdef LODBASEDMICROSFURACE\n#define sampleReflectionLod(s,c,l) texture2DLodEXT(s,c,l)\n#else\nuniform samplerCube reflectionSamplerLow;\nuniform samplerCube reflectionSamplerHigh;\n#endif\n#endif\n#ifdef REFLECTIONMAP_SKYBOX\nvarying vec3 vPositionUVW;\n#else\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvarying vec3 vDirectionW;\n#endif\n#endif\n#include\n#endif\n#ifdef ENVIRONMENTBRDF\nuniform sampler2D environmentBrdfSampler;\n#endif\n\n#ifndef FROMLINEARSPACE\n#define FROMLINEARSPACE;\n#endif\n#include\n#include\n#include\n\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n\n#include\nvoid main(void) {\n#include\n\n\nvec3 viewDirectionW=normalize(vEyePosition.xyz-vPositionW);\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=normalize(cross(dFdx(vPositionW),dFdy(vPositionW)))*vEyePosition.w;\n#endif\n#include\n#if defined(FORCENORMALFORWARD) && defined(NORMAL)\nvec3 faceNormal=normalize(cross(dFdx(vPositionW),dFdy(vPositionW)))*vEyePosition.w;\n#if defined(TWOSIDEDLIGHTING)\nfaceNormal=gl_FrontFacing ? faceNormal : -faceNormal;\n#endif\nnormalW*=sign(dot(normalW,faceNormal));\n#endif\n#if defined(TWOSIDEDLIGHTING) && defined(NORMAL)\nnormalW=gl_FrontFacing ? normalW : -normalW;\n#endif\n\n\nvec3 surfaceAlbedo=vAlbedoColor.rgb;\n\nfloat alpha=vAlbedoColor.a;\n#ifdef ALBEDO\nvec4 albedoTexture=texture2D(albedoSampler,vAlbedoUV+uvOffset);\n#if defined(ALPHAFROMALBEDO) || defined(ALPHATEST)\nalpha*=albedoTexture.a;\n#endif\nsurfaceAlbedo*=toLinearSpace(albedoTexture.rgb);\nsurfaceAlbedo*=vAlbedoInfos.y;\n#endif\n\n#ifdef OPACITY\nvec4 opacityMap=texture2D(opacitySampler,vOpacityUV+uvOffset);\n#ifdef OPACITYRGB\nalpha=getLuminance(opacityMap.rgb);\n#else\nalpha*=opacityMap.a;\n#endif\nalpha*=vOpacityInfos.y;\n#endif\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\n#if !defined(LINKREFRACTIONTOTRANSPARENCY) && !defined(ALPHAFRESNEL)\n#ifdef ALPHATEST\nif (alpha<=ALPHATESTVALUE)\ndiscard;\n#ifndef ALPHABLEND\n\nalpha=1.0;\n#endif\n#endif\n#endif\n#include\n#ifdef VERTEXCOLOR\nsurfaceAlbedo*=vColor.rgb;\n#endif\n\nvec3 ambientOcclusionColor=vec3(1.,1.,1.);\n#ifdef AMBIENT\nvec3 ambientOcclusionColorMap=texture2D(ambientSampler,vAmbientUV+uvOffset).rgb*vAmbientInfos.y;\n#ifdef AMBIENTINGRAYSCALE\nambientOcclusionColorMap=vec3(ambientOcclusionColorMap.r,ambientOcclusionColorMap.r,ambientOcclusionColorMap.r);\n#endif\nambientOcclusionColor=mix(ambientOcclusionColor,ambientOcclusionColorMap,vAmbientInfos.z);\n#endif\n\nfloat microSurface=vReflectivityColor.a;\nvec3 surfaceReflectivityColor=vReflectivityColor.rgb;\n#ifdef METALLICWORKFLOW\nvec2 metallicRoughness=surfaceReflectivityColor.rg;\n#ifdef REFLECTIVITY\nvec4 surfaceMetallicColorMap=texture2D(reflectivitySampler,vReflectivityUV+uvOffset);\n#ifdef AOSTOREINMETALMAPRED\nvec3 aoStoreInMetalMap=vec3(surfaceMetallicColorMap.r,surfaceMetallicColorMap.r,surfaceMetallicColorMap.r);\nambientOcclusionColor=mix(ambientOcclusionColor,aoStoreInMetalMap,vReflectivityInfos.z);\n#endif\n#ifdef METALLNESSSTOREINMETALMAPBLUE\nmetallicRoughness.r*=surfaceMetallicColorMap.b;\n#else\nmetallicRoughness.r*=surfaceMetallicColorMap.r;\n#endif\n#ifdef ROUGHNESSSTOREINMETALMAPALPHA\nmetallicRoughness.g*=surfaceMetallicColorMap.a;\n#else\n#ifdef ROUGHNESSSTOREINMETALMAPGREEN\nmetallicRoughness.g*=surfaceMetallicColorMap.g;\n#endif\n#endif\n#endif\n#ifdef MICROSURFACEMAP\nvec4 microSurfaceTexel=texture2D(microSurfaceSampler,vMicroSurfaceSamplerUV+uvOffset)*vMicroSurfaceSamplerInfos.y;\nmetallicRoughness.g*=microSurfaceTexel.r;\n#endif\n\nmicroSurface=1.0-metallicRoughness.g;\n\nvec3 baseColor=surfaceAlbedo;\n\n\nconst vec3 DefaultSpecularReflectanceDielectric=vec3(0.04,0.04,0.04);\n\nsurfaceAlbedo=mix(baseColor.rgb*(1.0-DefaultSpecularReflectanceDielectric.r),vec3(0.,0.,0.),metallicRoughness.r);\n\nsurfaceReflectivityColor=mix(DefaultSpecularReflectanceDielectric,baseColor,metallicRoughness.r);\n#else\n#ifdef REFLECTIVITY\nvec4 surfaceReflectivityColorMap=texture2D(reflectivitySampler,vReflectivityUV+uvOffset);\nsurfaceReflectivityColor*=toLinearSpace(surfaceReflectivityColorMap.rgb);\nsurfaceReflectivityColor*=vReflectivityInfos.y;\n#ifdef MICROSURFACEFROMREFLECTIVITYMAP\nmicroSurface*=surfaceReflectivityColorMap.a;\nmicroSurface*=vReflectivityInfos.z;\n#else\n#ifdef MICROSURFACEAUTOMATIC\nmicroSurface*=computeDefaultMicroSurface(microSurface,surfaceReflectivityColor);\n#endif\n#ifdef MICROSURFACEMAP\nvec4 microSurfaceTexel=texture2D(microSurfaceSampler,vMicroSurfaceSamplerUV+uvOffset)*vMicroSurfaceSamplerInfos.y;\nmicroSurface*=microSurfaceTexel.r;\n#endif\n#endif\n#endif\n#endif\n\nmicroSurface=clamp(microSurface,0.,1.);\n\nfloat roughness=1.-microSurface;\n\n#ifdef ALPHAFRESNEL\n#if defined(ALPHATEST) || defined(ALPHABLEND)\n\n\n\nfloat opacityPerceptual=alpha;\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=toLinearSpace(texture2D(lightmapSampler,vLightmapUV+uvOffset).rgb)*vLightmapInfos.y;\n#endif\nlightingInfo info;\nfloat shadow=1.; \nfloat NdotL=-1.;\n#include[0..maxSimultaneousLights]\n\n#if defined(ENVIRONMENTBRDF) && !defined(REFLECTIONMAP_SKYBOX)\n\nvec2 brdfSamplerUV=vec2(NdotV,roughness);\n\nvec4 environmentBrdf=texture2D(environmentBrdfSampler,brdfSamplerUV);\nvec3 specularEnvironmentReflectance=specularEnvironmentR0*environmentBrdf.x+environmentBrdf.y;\n#ifdef RADIANCEOCCLUSION\n#ifdef AMBIENTINGRAYSCALE\nfloat ambientMonochrome=ambientOcclusionColor.r;\n#else\nfloat ambientMonochrome=getLuminance(ambientOcclusionColor);\n#endif\nfloat seo=environmentRadianceOcclusion(ambientMonochrome,NdotVUnclamped);\nspecularEnvironmentReflectance*=seo;\n#endif\n#ifdef HORIZONOCCLUSION\n#ifdef BUMP\n#ifdef REFLECTIONMAP_3D\nfloat eho=environmentHorizonOcclusion(reflectionCoords,normalW);\nspecularEnvironmentReflectance*=eho;\n#endif\n#endif\n#endif\n#else\n\nvec3 specularEnvironmentReflectance=fresnelSchlickEnvironmentGGX(NdotV,specularEnvironmentR0,specularEnvironmentR90,sqrt(microSurface));\n#endif\n\n#ifdef REFRACTION\nvec3 refractance=vec3(0.0,0.0,0.0);\nvec3 transmission=vec3(1.0,1.0,1.0);\n#ifdef LINKREFRACTIONTOTRANSPARENCY\n\ntransmission*=(1.0-alpha);\n\n\nvec3 mixedAlbedo=surfaceAlbedo;\nfloat maxChannel=max(max(mixedAlbedo.r,mixedAlbedo.g),mixedAlbedo.b);\nvec3 tint=clamp(maxChannel*mixedAlbedo,0.0,1.0);\n\nsurfaceAlbedo*=alpha;\n\nenvironmentIrradiance*=alpha;\n\nenvironmentRefraction*=tint;\n\nalpha=1.0;\n#endif\n\nvec3 bounceSpecularEnvironmentReflectance=(2.0*specularEnvironmentReflectance)/(1.0+specularEnvironmentReflectance);\nspecularEnvironmentReflectance=mix(bounceSpecularEnvironmentReflectance,specularEnvironmentReflectance,alpha);\n\ntransmission*=1.0-specularEnvironmentReflectance;\n\nrefractance=transmission;\n#endif\n\n\n\n\nsurfaceAlbedo.rgb=(1.-reflectance)*surfaceAlbedo.rgb;\n\nvec3 finalDiffuse=diffuseBase;\nfinalDiffuse.rgb+=vAmbientColor;\nfinalDiffuse*=surfaceAlbedo.rgb;\nfinalDiffuse=max(finalDiffuse,0.0);\n\n#ifdef REFLECTION\nvec3 finalIrradiance=environmentIrradiance;\nfinalIrradiance*=surfaceAlbedo.rgb;\n#endif\n\n#ifdef SPECULARTERM\nvec3 finalSpecular=specularBase;\nfinalSpecular=max(finalSpecular,0.0);\n\nvec3 finalSpecularScaled=finalSpecular*vLightingIntensity.x*vLightingIntensity.w;\n#endif\n\n#ifdef REFLECTION\nvec3 finalRadiance=environmentRadiance;\nfinalRadiance*=specularEnvironmentReflectance;\n\nvec3 finalRadianceScaled=finalRadiance*vLightingIntensity.z;\n#endif\n\n#ifdef REFRACTION\nvec3 finalRefraction=environmentRefraction;\nfinalRefraction*=refractance;\n#endif\n\nvec3 finalEmissive=vEmissiveColor;\n#ifdef EMISSIVE\nvec3 emissiveColorTex=texture2D(emissiveSampler,vEmissiveUV+uvOffset).rgb;\nfinalEmissive*=toLinearSpace(emissiveColorTex.rgb);\nfinalEmissive*=vEmissiveInfos.y;\n#endif\n\n#ifdef ALPHABLEND\nfloat luminanceOverAlpha=0.0;\n#if defined(REFLECTION) && defined(RADIANCEOVERALPHA)\nluminanceOverAlpha+=getLuminance(finalRadianceScaled);\n#endif\n#if defined(SPECULARTERM) && defined(SPECULAROVERALPHA)\nluminanceOverAlpha+=getLuminance(finalSpecularScaled);\n#endif\n#if defined(RADIANCEOVERALPHA) || defined(SPECULAROVERALPHA)\nalpha=clamp(alpha+luminanceOverAlpha*luminanceOverAlpha,0.,1.);\n#endif\n#endif\n\n\n\nvec4 finalColor=vec4(finalDiffuse*ambientOcclusionColor*vLightingIntensity.x +\n#ifdef REFLECTION\nfinalIrradiance*ambientOcclusionColor*vLightingIntensity.z +\n#endif\n#ifdef SPECULARTERM\n\n\nfinalSpecularScaled +\n#endif\n#ifdef REFLECTION\n\n\nfinalRadianceScaled +\n#endif\n#ifdef REFRACTION\nfinalRefraction*vLightingIntensity.z +\n#endif\nfinalEmissive*vLightingIntensity.y,\nalpha);\n\n#ifdef LIGHTMAP\n#ifndef LIGHTMAPEXCLUDED\n#ifdef USELIGHTMAPASSHADOWMAP\nfinalColor.rgb*=lightmapColor;\n#else\nfinalColor.rgb+=lightmapColor;\n#endif\n#endif\n#endif\n\nfinalColor=max(finalColor,0.0);\n#include\n#include(color,finalColor)\n#ifdef IMAGEPROCESSINGPOSTPROCESS\n\n\nfinalColor.rgb=clamp(finalColor.rgb,0.,30.0);\n#else\n\nfinalColor=applyImageProcessing(finalColor);\n#endif\n#ifdef PREMULTIPLYALPHA\n\nfinalColor.rgb*=finalColor.a;\n#endif\ngl_FragColor=finalColor;\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n}",spritesVertexShader:"\nattribute vec4 position;\nattribute vec4 options;\nattribute vec4 cellInfo;\nattribute vec4 color;\n\nuniform vec2 textureInfos;\nuniform mat4 view;\nuniform mat4 projection;\n\nvarying vec2 vUV;\nvarying vec4 vColor;\n#include\nvoid main(void) { \nvec3 viewPos=(view*vec4(position.xyz,1.0)).xyz; \nvec2 cornerPos;\nfloat angle=position.w;\nvec2 size=vec2(options.x,options.y);\nvec2 offset=options.zw;\nvec2 uvScale=textureInfos.xy;\ncornerPos=vec2(offset.x-0.5,offset.y-0.5)*size;\n\nvec3 rotatedCorner;\nrotatedCorner.x=cornerPos.x*cos(angle)-cornerPos.y*sin(angle);\nrotatedCorner.y=cornerPos.x*sin(angle)+cornerPos.y*cos(angle);\nrotatedCorner.z=0.;\n\nviewPos+=rotatedCorner;\ngl_Position=projection*vec4(viewPos,1.0); \n\nvColor=color;\n\nvec2 uvOffset=vec2(abs(offset.x-cellInfo.x),1.0-abs(offset.y-cellInfo.y));\nvUV=(uvOffset+cellInfo.zw)*uvScale;\n\n#ifdef FOG\nvFogDistance=viewPos;\n#endif\n}",spritesPixelShader:"uniform bool alphaTest;\nvarying vec4 vColor;\n\nvarying vec2 vUV;\nuniform sampler2D diffuseSampler;\n\n#include\nvoid main(void) {\nvec4 color=texture2D(diffuseSampler,vUV);\nif (alphaTest) \n{\nif (color.a<0.95)\ndiscard;\n}\ncolor*=vColor;\n#include\ngl_FragColor=color;\n}",particlesVertexShader:"\nattribute vec3 position;\nattribute vec4 color;\nattribute vec4 options;\nattribute float cellIndex;\n\nuniform mat4 view;\nuniform mat4 projection;\nuniform vec3 particlesInfos; \n\nvarying vec2 vUV;\nvarying vec4 vColor;\n#ifdef CLIPPLANE\nuniform vec4 vClipPlane;\nuniform mat4 invView;\nvarying float fClipDistance;\n#endif\nvoid main(void) { \nvec3 viewPos=(view*vec4(position,1.0)).xyz; \nvec3 cornerPos;\nfloat size=options.y;\nfloat angle=options.x;\nvec2 offset=options.zw;\ncornerPos=vec3(offset.x-0.5,offset.y-0.5,0.)*size;\n\nvec3 rotatedCorner;\nrotatedCorner.x=cornerPos.x*cos(angle)-cornerPos.y*sin(angle);\nrotatedCorner.y=cornerPos.x*sin(angle)+cornerPos.y*cos(angle);\nrotatedCorner.z=0.;\n\nviewPos+=rotatedCorner;\ngl_Position=projection*vec4(viewPos,1.0); \nvColor=color;\n#ifdef ANIMATESHEET\nfloat rowOffset=floor(cellIndex/particlesInfos.z);\nfloat columnOffset=cellIndex-rowOffset*particlesInfos.z;\nvec2 uvScale=particlesInfos.xy;\nvec2 uvOffset=vec2(offset.x ,1.0-offset.y);\nvUV=(uvOffset+vec2(columnOffset,rowOffset))*uvScale;\n#else\nvUV=offset;\n#endif\n\n#ifdef CLIPPLANE\nvec4 worldPos=invView*vec4(viewPos,1.0);\nfClipDistance=dot(worldPos,vClipPlane);\n#endif\n}",particlesPixelShader:"\nvarying vec2 vUV;\nvarying vec4 vColor;\nuniform vec4 textureMask;\nuniform sampler2D diffuseSampler;\n#ifdef CLIPPLANE\nvarying float fClipDistance;\n#endif\nvoid main(void) {\n#ifdef CLIPPLANE\nif (fClipDistance>0.0)\ndiscard;\n#endif\nvec4 baseColor=texture2D(diffuseSampler,vUV);\ngl_FragColor=(baseColor*textureMask+(vec4(1.,1.,1.,1.)-textureMask))*vColor;\n}",colorVertexShader:"\nattribute vec3 position;\n#ifdef VERTEXCOLOR\nattribute vec4 color;\n#endif\n#include\n\nuniform mat4 viewProjection;\nuniform mat4 world;\n\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\nvoid main(void) {\nmat4 finalWorld=world;\n#include\ngl_Position=viewProjection*finalWorld*vec4(position,1.0);\n#ifdef VERTEXCOLOR\n\nvColor=color;\n#endif\n}",colorPixelShader:"#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#else\nuniform vec4 color;\n#endif\nvoid main(void) {\n#ifdef VERTEXCOLOR\ngl_FragColor=vColor;\n#else\ngl_FragColor=color;\n#endif\n}",postprocessVertexShader:"\nattribute vec2 position;\nuniform vec2 scale;\n\nvarying vec2 vUV;\nconst vec2 madd=vec2(0.5,0.5);\nvoid main(void) { \nvUV=(position*madd+madd)*scale;\ngl_Position=vec4(position,0.0,1.0);\n}",passPixelShader:"\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\nvoid main(void) \n{\ngl_FragColor=texture2D(textureSampler,vUV);\n}",shadowMapVertexShader:"\nattribute vec3 position;\n#include\n\n#include\nuniform mat4 viewProjection;\nuniform vec2 biasAndScale;\nuniform vec2 depthValues;\nvarying float vDepthMetric;\n#ifdef ALPHATEST\nvarying vec2 vUV;\nuniform mat4 diffuseMatrix;\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#endif\nvoid main(void)\n{\n#include\n#include\nvec4 worldPos=finalWorld*vec4(position,1.0);\ngl_Position=viewProjection*worldPos;\nvDepthMetric=((gl_Position.z+depthValues.x)/(depthValues.y))+biasAndScale.x;\n#ifdef ALPHATEST\n#ifdef UV1\nvUV=vec2(diffuseMatrix*vec4(uv,1.0,0.0));\n#endif\n#ifdef UV2\nvUV=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));\n#endif\n#endif\n}",shadowMapPixelShader:"#ifndef FLOAT\nvec4 pack(float depth)\n{\nconst vec4 bit_shift=vec4(255.0*255.0*255.0,255.0*255.0,255.0,1.0);\nconst vec4 bit_mask=vec4(0.0,1.0/255.0,1.0/255.0,1.0/255.0);\nvec4 res=fract(depth*bit_shift);\nres-=res.xxyz*bit_mask;\nreturn res;\n}\n#endif\nvarying float vDepthMetric;\n#ifdef ALPHATEST\nvarying vec2 vUV;\nuniform sampler2D diffuseSampler;\n#endif\nuniform vec2 biasAndScale;\nuniform vec2 depthValues;\nvoid main(void)\n{\n#ifdef ALPHATEST\nif (texture2D(diffuseSampler,vUV).a<0.4)\ndiscard;\n#endif\nfloat depth=vDepthMetric;\n#ifdef ESM\ndepth=clamp(exp(-min(87.,biasAndScale.y*depth)),0.,1.);\n#endif\n#ifdef FLOAT\ngl_FragColor=vec4(depth,1.0,1.0,1.0);\n#else\ngl_FragColor=pack(depth);\n#endif\n}",depthBoxBlurPixelShader:"\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\n\nuniform vec2 screenSize;\nvoid main(void)\n{\nvec4 colorDepth=vec4(0.0);\nfor (int x=-OFFSET; x<=OFFSET; x++)\nfor (int y=-OFFSET; y<=OFFSET; y++)\ncolorDepth+=texture2D(textureSampler,vUV+vec2(x,y)/screenSize);\ngl_FragColor=(colorDepth/float((OFFSET*2+1)*(OFFSET*2+1)));\n}",proceduralVertexShader:"\nattribute vec2 position;\n\nvarying vec2 vPosition;\nvarying vec2 vUV;\nconst vec2 madd=vec2(0.5,0.5);\nvoid main(void) { \nvPosition=position;\nvUV=position*madd+madd;\ngl_Position=vec4(position,0.0,1.0);\n}",depthVertexShader:"\nattribute vec3 position;\n#include\n\n#include\nuniform mat4 viewProjection;\nuniform vec2 depthValues;\n#if defined(ALPHATEST) || defined(NEED_UV)\nvarying vec2 vUV;\nuniform mat4 diffuseMatrix;\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#endif\nvarying float vDepthMetric;\nvoid main(void)\n{\n#include\n#include\ngl_Position=viewProjection*finalWorld*vec4(position,1.0);\nvDepthMetric=((gl_Position.z+depthValues.x)/(depthValues.y));\n#if defined(ALPHATEST) || defined(BASIC_RENDER)\n#ifdef UV1\nvUV=vec2(diffuseMatrix*vec4(uv,1.0,0.0));\n#endif\n#ifdef UV2\nvUV=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));\n#endif\n#endif\n}",depthPixelShader:"#ifdef ALPHATEST\nvarying vec2 vUV;\nuniform sampler2D diffuseSampler;\n#endif\nvarying float vDepthMetric;\nvoid main(void)\n{\n#ifdef ALPHATEST\nif (texture2D(diffuseSampler,vUV).a<0.4)\ndiscard;\n#endif\ngl_FragColor=vec4(vDepthMetric,vDepthMetric*vDepthMetric,0.0,1.0);\n}",ssaoPixelShader:"\nuniform sampler2D textureSampler;\nvarying vec2 vUV;\n#ifdef SSAO\nuniform sampler2D randomSampler;\nuniform float randTextureTiles;\nuniform float samplesFactor;\nuniform vec3 sampleSphere[SAMPLES];\nuniform float totalStrength;\nuniform float radius;\nuniform float area;\nuniform float fallOff;\nuniform float base;\nvec3 normalFromDepth(float depth,vec2 coords)\n{\nvec2 offset1=vec2(0.0,radius);\nvec2 offset2=vec2(radius,0.0);\nfloat depth1=texture2D(textureSampler,coords+offset1).r;\nfloat depth2=texture2D(textureSampler,coords+offset2).r;\nvec3 p1=vec3(offset1,depth1-depth);\nvec3 p2=vec3(offset2,depth2-depth);\nvec3 normal=cross(p1,p2);\nnormal.z=-normal.z;\nreturn normalize(normal);\n}\nvoid main()\n{\nvec3 random=normalize(texture2D(randomSampler,vUV*randTextureTiles).rgb);\nfloat depth=texture2D(textureSampler,vUV).r;\nvec3 position=vec3(vUV,depth);\nvec3 normal=normalFromDepth(depth,vUV);\nfloat radiusDepth=radius/depth;\nfloat occlusion=0.0;\nvec3 ray;\nvec3 hemiRay;\nfloat occlusionDepth;\nfloat difference;\nfor (int i=0; imaxZ) {\ngl_FragColor=vec4(1.0,1.0,1.0,1.0);\nreturn;\n}\nfor (int i=0; i1.0 || offset.y>1.0) {\ncontinue;\n}\n\nfloat sampleDepth=abs(texture2D(textureSampler,offset.xy).r);\n\nfloat rangeCheck=abs(depth-sampleDepth)=1e-5 ? 1.0 : 0.0)*rangeCheck;\n}\n\nfloat ao=1.0-totalStrength*occlusion*samplesFactor;\nfloat result=clamp(ao+base,0.0,1.0);\ngl_FragColor=vec4(vec3(result),1.0);\n}\n#endif\n#ifdef BILATERAL_BLUR\nuniform sampler2D depthSampler;\nuniform float outSize;\nuniform float samplerOffsets[SAMPLES];\nvec4 blur9(sampler2D image,vec2 uv,float resolution,vec2 direction) {\nvec4 color=vec4(0.0);\nvec2 off1=vec2(1.3846153846)*direction;\nvec2 off2=vec2(3.2307692308)*direction;\ncolor+=texture2D(image,uv)*0.2270270270;\ncolor+=texture2D(image,uv+(off1/resolution))*0.3162162162;\ncolor+=texture2D(image,uv-(off1/resolution))*0.3162162162;\ncolor+=texture2D(image,uv+(off2/resolution))*0.0702702703;\ncolor+=texture2D(image,uv-(off2/resolution))*0.0702702703;\nreturn color;\n}\nvec4 blur13(sampler2D image,vec2 uv,float resolution,vec2 direction) {\nvec4 color=vec4(0.0);\nvec2 off1=vec2(1.411764705882353)*direction;\nvec2 off2=vec2(3.2941176470588234)*direction;\nvec2 off3=vec2(5.176470588235294)*direction;\ncolor+=texture2D(image,uv)*0.1964825501511404;\ncolor+=texture2D(image,uv+(off1/resolution))*0.2969069646728344;\ncolor+=texture2D(image,uv-(off1/resolution))*0.2969069646728344;\ncolor+=texture2D(image,uv+(off2/resolution))*0.09447039785044732;\ncolor+=texture2D(image,uv-(off2/resolution))*0.09447039785044732;\ncolor+=texture2D(image,uv+(off3/resolution))*0.010381362401148057;\ncolor+=texture2D(image,uv-(off3/resolution))*0.010381362401148057;\nreturn color;\n}\nvec4 blur13Bilateral(sampler2D image,vec2 uv,float resolution,vec2 direction) {\nvec4 color=vec4(0.0);\nvec2 off1=vec2(1.411764705882353)*direction;\nvec2 off2=vec2(3.2941176470588234)*direction;\nvec2 off3=vec2(5.176470588235294)*direction;\nfloat compareDepth=abs(texture2D(depthSampler,uv).r);\nfloat sampleDepth;\nfloat weight;\nfloat weightSum=30.0;\ncolor+=texture2D(image,uv)*30.0;\nsampleDepth=abs(texture2D(depthSampler,uv+(off1/resolution)).r);\nweight=clamp(1.0/( 0.003+abs(compareDepth-sampleDepth)),0.0,30.0);\nweightSum+=weight;\ncolor+=texture2D(image,uv+(off1/resolution))*weight;\nsampleDepth=abs(texture2D(depthSampler,uv-(off1/resolution)).r);\nweight=clamp(1.0/( 0.003+abs(compareDepth-sampleDepth)),0.0,30.0);\nweightSum+=weight;\ncolor+=texture2D(image,uv-(off1/resolution))*weight;\nsampleDepth=abs(texture2D(depthSampler,uv+(off2/resolution)).r);\nweight=clamp(1.0/( 0.003+abs(compareDepth-sampleDepth)),0.0,30.0);\nweightSum+=weight;\ncolor+=texture2D(image,uv+(off2/resolution))*weight;\nsampleDepth=abs(texture2D(depthSampler,uv-(off2/resolution)).r);\nweight=clamp(1.0/( 0.003+abs(compareDepth-sampleDepth)),0.0,30.0);\nweightSum+=weight;\ncolor+=texture2D(image,uv-(off2/resolution))*weight;\nsampleDepth=abs(texture2D(depthSampler,uv+(off3/resolution)).r);\nweight=clamp(1.0/( 0.003+abs(compareDepth-sampleDepth)),0.0,30.0);\nweightSum+=weight;\ncolor+=texture2D(image,uv+(off3/resolution))*weight;\nsampleDepth=abs(texture2D(depthSampler,uv-(off3/resolution)).r);\nweight=clamp(1.0/( 0.003+abs(compareDepth-sampleDepth)),0.0,30.0);\nweightSum+=weight;\ncolor+=texture2D(image,uv-(off3/resolution))*weight;\nreturn color/weightSum;\n}\nvoid main()\n{\n#if EXPENSIVE\nfloat compareDepth=abs(texture2D(depthSampler,vUV).r);\nfloat texelsize=1.0/outSize;\nfloat result=0.0;\nfloat weightSum=0.0;\nfor (int i=0; i1.0) { lum_threshold=0.94+0.01*threshold; }\nelse { lum_threshold=0.5+0.44*threshold; }\nluminance=clamp((luminance-lum_threshold)*(1.0/(1.0-lum_threshold)),0.0,1.0);\nhighlight*=luminance*gain;\nhighlight.a=1.0;\nreturn highlight;\n}\nvoid main(void)\n{\nvec4 original=texture2D(textureSampler,vUV);\n\nif (gain == -1.0) {\ngl_FragColor=vec4(0.0,0.0,0.0,1.0);\nreturn;\n}\nfloat w=2.0/screen_width;\nfloat h=2.0/screen_height;\nfloat weight=1.0;\n\nvec4 blurred=vec4(0.0,0.0,0.0,0.0);\n#ifdef PENTAGON\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.84*w,0.43*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(0.48*w,-1.29*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(0.61*w,1.51*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.55*w,-0.74*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.71*w,-0.52*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.94*w,1.59*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.40*w,-1.87*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.62*w,1.16*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.09*w,0.25*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.46*w,-1.71*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(0.08*w,2.42*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.85*w,-1.89*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.89*w,0.16*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.29*w,1.88*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(0.40*w,-2.81*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.54*w,2.26*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.60*w,-0.61*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.31*w,-1.30*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.83*w,2.53*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.12*w,-2.48*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.60*w,1.11*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.82*w,0.99*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.50*w,-2.81*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(0.85*w,3.33*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.94*w,-1.92*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(3.27*w,-0.53*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.95*w,2.48*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.23*w,-3.04*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.17*w,2.05*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.97*w,-0.04*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.25*w,-2.00*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.31*w,3.08*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.94*w,-2.59*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(3.37*w,0.64*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-3.13*w,1.93*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.03*w,-3.65*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.60*w,3.17*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-3.14*w,-1.19*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(3.00*w,-1.19*h)));\n#else\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.85*w,0.36*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(0.52*w,-1.14*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(0.46*w,1.42*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.46*w,-0.83*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.79*w,-0.42*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.11*w,1.62*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.29*w,-2.07*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.69*w,1.39*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.28*w,0.12*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.65*w,-1.69*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.08*w,2.44*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.63*w,-1.90*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.55*w,0.31*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.13*w,1.52*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(0.56*w,-2.61*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.38*w,2.34*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.64*w,-0.81*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.53*w,-1.21*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.06*w,2.63*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.00*w,-2.69*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.59*w,1.32*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.82*w,0.78*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.57*w,-2.50*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(0.54*w,2.93*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.39*w,-1.81*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(3.01*w,-0.28*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.04*w,2.25*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.02*w,-3.05*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.09*w,2.25*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-3.07*w,-0.25*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.44*w,-1.90*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.52*w,3.05*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.68*w,-2.61*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(3.01*w,0.79*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.76*w,1.46*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.05*w,-2.94*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.21*w,2.88*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.84*w,-1.30*h)));\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.98*w,-0.96*h)));\n#endif\nblurred/=39.0;\ngl_FragColor=blurred;\n\n}",depthOfFieldPixelShader:"\n\n\n\n\nuniform sampler2D textureSampler;\nuniform sampler2D highlightsSampler;\nuniform sampler2D depthSampler;\nuniform sampler2D grainSampler;\n\nuniform float grain_amount;\nuniform bool blur_noise;\nuniform float screen_width;\nuniform float screen_height;\nuniform float distortion;\nuniform bool dof_enabled;\n\nuniform float screen_distance; \nuniform float aperture;\nuniform float darken;\nuniform float edge_blur;\nuniform bool highlights;\n\nuniform float near;\nuniform float far;\n\nvarying vec2 vUV;\n\n#define PI 3.14159265\n#define TWOPI 6.28318530\n#define inverse_focal_length 0.1 \n\nvec2 centered_screen_pos;\nvec2 distorted_coords;\nfloat radius2;\nfloat radius;\n\nvec2 rand(vec2 co)\n{\nfloat noise1=(fract(sin(dot(co,vec2(12.9898,78.233)))*43758.5453));\nfloat noise2=(fract(sin(dot(co,vec2(12.9898,78.233)*2.0))*43758.5453));\nreturn clamp(vec2(noise1,noise2),0.0,1.0);\n}\n\nvec2 getDistortedCoords(vec2 coords) {\nif (distortion == 0.0) { return coords; }\nvec2 direction=1.0*normalize(centered_screen_pos);\nvec2 dist_coords=vec2(0.5,0.5);\ndist_coords.x=0.5+direction.x*radius2*1.0;\ndist_coords.y=0.5+direction.y*radius2*1.0;\nfloat dist_amount=clamp(distortion*0.23,0.0,1.0);\ndist_coords=mix(coords,dist_coords,dist_amount);\nreturn dist_coords;\n}\n\nfloat sampleScreen(inout vec4 color,const in vec2 offset,const in float weight) {\n\nvec2 coords=distorted_coords;\nfloat angle=rand(coords*100.0).x*TWOPI;\ncoords+=vec2(offset.x*cos(angle)-offset.y*sin(angle),offset.x*sin(angle)+offset.y*cos(angle));\ncolor+=texture2D(textureSampler,coords)*weight;\nreturn weight;\n}\n\nfloat getBlurLevel(float size) {\nreturn min(3.0,ceil(size/1.0));\n}\n\nvec4 getBlurColor(float size) {\nvec4 col=texture2D(textureSampler,distorted_coords);\nif (size == 0.0) { return col; }\n\n\nfloat blur_level=getBlurLevel(size);\nfloat w=(size/screen_width);\nfloat h=(size/screen_height);\nfloat total_weight=1.0;\nvec2 sample_coords;\ntotal_weight+=sampleScreen(col,vec2(-0.50*w,0.24*h),0.93);\ntotal_weight+=sampleScreen(col,vec2(0.30*w,-0.75*h),0.90);\ntotal_weight+=sampleScreen(col,vec2(0.36*w,0.96*h),0.87);\ntotal_weight+=sampleScreen(col,vec2(-1.08*w,-0.55*h),0.85);\ntotal_weight+=sampleScreen(col,vec2(1.33*w,-0.37*h),0.83);\ntotal_weight+=sampleScreen(col,vec2(-0.82*w,1.31*h),0.80);\ntotal_weight+=sampleScreen(col,vec2(-0.31*w,-1.67*h),0.78);\ntotal_weight+=sampleScreen(col,vec2(1.47*w,1.11*h),0.76);\ntotal_weight+=sampleScreen(col,vec2(-1.97*w,0.19*h),0.74);\ntotal_weight+=sampleScreen(col,vec2(1.42*w,-1.57*h),0.72);\nif (blur_level>1.0) {\ntotal_weight+=sampleScreen(col,vec2(0.01*w,2.25*h),0.70);\ntotal_weight+=sampleScreen(col,vec2(-1.62*w,-1.74*h),0.67);\ntotal_weight+=sampleScreen(col,vec2(2.49*w,0.20*h),0.65);\ntotal_weight+=sampleScreen(col,vec2(-2.07*w,1.61*h),0.63);\ntotal_weight+=sampleScreen(col,vec2(0.46*w,-2.70*h),0.61);\ntotal_weight+=sampleScreen(col,vec2(1.55*w,2.40*h),0.59);\ntotal_weight+=sampleScreen(col,vec2(-2.88*w,-0.75*h),0.56);\ntotal_weight+=sampleScreen(col,vec2(2.73*w,-1.44*h),0.54);\ntotal_weight+=sampleScreen(col,vec2(-1.08*w,3.02*h),0.52);\ntotal_weight+=sampleScreen(col,vec2(-1.28*w,-3.05*h),0.49);\n}\nif (blur_level>2.0) {\ntotal_weight+=sampleScreen(col,vec2(3.11*w,1.43*h),0.46);\ntotal_weight+=sampleScreen(col,vec2(-3.36*w,1.08*h),0.44);\ntotal_weight+=sampleScreen(col,vec2(1.80*w,-3.16*h),0.41);\ntotal_weight+=sampleScreen(col,vec2(0.83*w,3.65*h),0.38);\ntotal_weight+=sampleScreen(col,vec2(-3.16*w,-2.19*h),0.34);\ntotal_weight+=sampleScreen(col,vec2(3.92*w,-0.53*h),0.31);\ntotal_weight+=sampleScreen(col,vec2(-2.59*w,3.12*h),0.26);\ntotal_weight+=sampleScreen(col,vec2(-0.20*w,-4.15*h),0.22);\ntotal_weight+=sampleScreen(col,vec2(3.02*w,3.00*h),0.15);\n}\ncol/=total_weight; \n\nif (darken>0.0) {\ncol.rgb*=clamp(0.3,1.0,1.05-size*0.5*darken);\n}\n\n\n\n\nreturn col;\n}\nvoid main(void)\n{\n\ncentered_screen_pos=vec2(vUV.x-0.5,vUV.y-0.5);\nradius2=centered_screen_pos.x*centered_screen_pos.x+centered_screen_pos.y*centered_screen_pos.y;\nradius=sqrt(radius2);\ndistorted_coords=getDistortedCoords(vUV); \nvec2 texels_coords=vec2(vUV.x*screen_width,vUV.y*screen_height); \nfloat depth=texture2D(depthSampler,distorted_coords).r; \nfloat distance=near+(far-near)*depth; \nvec4 color=texture2D(textureSampler,vUV); \n\n\nfloat coc=abs(aperture*(screen_distance*(inverse_focal_length-1.0/distance)-1.0));\n\nif (dof_enabled == false || coc<0.07) { coc=0.0; }\n\nfloat edge_blur_amount=0.0;\nif (edge_blur>0.0) {\nedge_blur_amount=clamp((radius*2.0-1.0+0.15*edge_blur)*1.5,0.0,1.0)*1.3;\n}\n\nfloat blur_amount=max(edge_blur_amount,coc);\n\nif (blur_amount == 0.0) {\ngl_FragColor=texture2D(textureSampler,distorted_coords);\n}\nelse {\n\ngl_FragColor=getBlurColor(blur_amount*1.7);\n\nif (highlights) {\ngl_FragColor.rgb+=clamp(coc,0.0,1.0)*texture2D(highlightsSampler,distorted_coords).rgb;\n}\nif (blur_noise) {\n\nvec2 noise=rand(distorted_coords)*0.01*blur_amount;\nvec2 blurred_coord=vec2(distorted_coords.x+noise.x,distorted_coords.y+noise.y);\ngl_FragColor=0.04*texture2D(textureSampler,blurred_coord)+0.96*gl_FragColor;\n}\n}\n\nif (grain_amount>0.0) {\nvec4 grain_color=texture2D(grainSampler,texels_coords*0.003);\ngl_FragColor.rgb+=(-0.5+grain_color.rgb)*0.30*grain_amount;\n}\n}\n",standardPixelShader:"uniform sampler2D textureSampler;\nvarying vec2 vUV;\n#if defined(PASS_POST_PROCESS)\nvoid main(void)\n{\nvec4 color=texture2D(textureSampler,vUV);\ngl_FragColor=color;\n}\n#endif\n#if defined(DOWN_SAMPLE_X4)\nuniform vec2 dsOffsets[16];\nvoid main(void)\n{\nvec4 average=vec4(0.0,0.0,0.0,0.0);\naverage=texture2D(textureSampler,vUV+dsOffsets[0]);\naverage+=texture2D(textureSampler,vUV+dsOffsets[1]);\naverage+=texture2D(textureSampler,vUV+dsOffsets[2]);\naverage+=texture2D(textureSampler,vUV+dsOffsets[3]);\naverage+=texture2D(textureSampler,vUV+dsOffsets[4]);\naverage+=texture2D(textureSampler,vUV+dsOffsets[5]);\naverage+=texture2D(textureSampler,vUV+dsOffsets[6]);\naverage+=texture2D(textureSampler,vUV+dsOffsets[7]);\naverage+=texture2D(textureSampler,vUV+dsOffsets[8]);\naverage+=texture2D(textureSampler,vUV+dsOffsets[9]);\naverage+=texture2D(textureSampler,vUV+dsOffsets[10]);\naverage+=texture2D(textureSampler,vUV+dsOffsets[11]);\naverage+=texture2D(textureSampler,vUV+dsOffsets[12]);\naverage+=texture2D(textureSampler,vUV+dsOffsets[13]);\naverage+=texture2D(textureSampler,vUV+dsOffsets[14]);\naverage+=texture2D(textureSampler,vUV+dsOffsets[15]);\naverage/=16.0;\ngl_FragColor=average;\n}\n#endif\n#if defined(BRIGHT_PASS)\nuniform vec2 dsOffsets[4];\nuniform float brightThreshold;\nvoid main(void)\n{\nvec4 average=vec4(0.0,0.0,0.0,0.0);\naverage=texture2D(textureSampler,vUV+vec2(dsOffsets[0].x,dsOffsets[0].y));\naverage+=texture2D(textureSampler,vUV+vec2(dsOffsets[1].x,dsOffsets[1].y));\naverage+=texture2D(textureSampler,vUV+vec2(dsOffsets[2].x,dsOffsets[2].y));\naverage+=texture2D(textureSampler,vUV+vec2(dsOffsets[3].x,dsOffsets[3].y));\naverage*=0.25;\nfloat luminance=length(average.rgb);\nif (luminanceshadowPixelDepth)\naccumFog+=sunColor*computeScattering(dot(rayDirection,sunDirection));\ncurrentPosition+=stepL;\n}\naccumFog/=NB_STEPS;\nvec3 color=accumFog*scatteringPower;\ngl_FragColor=vec4(color*exp(color) ,1.0);\n}\n#endif\n#if defined(VLSMERGE)\nuniform sampler2D originalSampler;\nvoid main(void)\n{\ngl_FragColor=texture2D(originalSampler,vUV)+texture2D(textureSampler,vUV);\n}\n#endif\n#if defined(LUMINANCE)\nuniform vec2 lumOffsets[4];\nvoid main()\n{\nfloat average=0.0;\nvec4 color=vec4(0.0);\nfloat maximum=-1e20;\nvec3 weight=vec3(0.299,0.587,0.114);\nfor (int i=0; i<4; i++)\n{\ncolor=texture2D(textureSampler,vUV+ lumOffsets[i]);\n\nfloat GreyValue=dot(color.rgb,vec3(0.33,0.33,0.33));\n\n#ifdef WEIGHTED_AVERAGE\nfloat GreyValue=dot(color.rgb,weight);\n#endif\n#ifdef BRIGHTNESS\nfloat GreyValue=max(color.r,max(color.g,color.b));\n#endif\n#ifdef HSL_COMPONENT\nfloat GreyValue=0.5*(max(color.r,max(color.g,color.b))+min(color.r,min(color.g,color.b)));\n#endif\n#ifdef MAGNITUDE\nfloat GreyValue=length(color.rgb);\n#endif\nmaximum=max(maximum,GreyValue);\naverage+=(0.25*log(1e-5+GreyValue));\n}\naverage=exp(average);\ngl_FragColor=vec4(average,maximum,0.0,1.0);\n}\n#endif\n#if defined(LUMINANCE_DOWN_SAMPLE)\nuniform vec2 dsOffsets[9];\nuniform float halfDestPixelSize;\n#ifdef FINAL_DOWN_SAMPLER\nvec4 pack(float value) {\nconst vec4 bit_shift=vec4(255.0*255.0*255.0,255.0*255.0,255.0,1.0);\nconst vec4 bit_mask=vec4(0.0,1.0/255.0,1.0/255.0,1.0/255.0);\nvec4 res=fract(value*bit_shift);\nres-=res.xxyz*bit_mask;\nreturn res;\n}\n#endif\nvoid main()\n{\nvec4 color=vec4(0.0);\nfloat average=0.0;\nfor (int i=0; i<9; i++)\n{\ncolor=texture2D(textureSampler,vUV+vec2(halfDestPixelSize,halfDestPixelSize)+dsOffsets[i]);\naverage+=color.r;\n}\naverage/=9.0;\n#ifdef FINAL_DOWN_SAMPLER\ngl_FragColor=pack(average);\n#else\ngl_FragColor=vec4(average,average,0.0,1.0);\n#endif\n}\n#endif\n#if defined(HDR)\nuniform sampler2D textureAdderSampler;\nuniform float averageLuminance;\nvoid main()\n{\nvec4 color=texture2D(textureAdderSampler,vUV);\nvec4 adjustedColor=color/averageLuminance;\ncolor=adjustedColor;\ncolor.a=1.0;\ngl_FragColor=color;\n}\n#endif\n#if defined(LENS_FLARE)\n#define GHOSTS 3\nuniform sampler2D lensColorSampler;\nuniform float strength;\nuniform float ghostDispersal;\nuniform float haloWidth;\nuniform vec2 resolution;\nuniform float distortionStrength;\nfloat hash(vec2 p)\n{\nfloat h=dot(p,vec2(127.1,311.7));\nreturn -1.0+2.0*fract(sin(h)*43758.5453123);\n}\nfloat noise(in vec2 p)\n{\nvec2 i=floor(p);\nvec2 f=fract(p);\nvec2 u=f*f*(3.0-2.0*f);\nreturn mix(mix(hash(i+vec2(0.0,0.0)),\nhash(i+vec2(1.0,0.0)),u.x),\nmix(hash(i+vec2(0.0,1.0)),\nhash(i+vec2(1.0,1.0)),u.x),u.y);\n}\nfloat fbm(vec2 p)\n{\nfloat f=0.0;\nf+=0.5000*noise(p); p*=2.02;\nf+=0.2500*noise(p); p*=2.03;\nf+=0.1250*noise(p); p*=2.01;\nf+=0.0625*noise(p); p*=2.04;\nf/=0.9375;\nreturn f;\n}\nvec3 pattern(vec2 uv)\n{\nvec2 p=-1.0+2.0*uv;\nfloat p2=dot(p,p);\nfloat f=fbm(vec2(15.0*p2))/2.0;\nfloat r=0.2+0.6*sin(12.5*length(uv-vec2(0.5)));\nfloat g=0.2+0.6*sin(20.5*length(uv-vec2(0.5)));\nfloat b=0.2+0.6*sin(17.2*length(uv-vec2(0.5)));\nreturn (1.0-f)*vec3(r,g,b);\n}\nfloat luminance(vec3 color)\n{\nreturn dot(color.rgb,vec3(0.2126,0.7152,0.0722));\n}\nvec4 textureDistorted(sampler2D tex,vec2 texcoord,vec2 direction,vec3 distortion)\n{\nreturn vec4(\ntexture2D(tex,texcoord+direction*distortion.r).r,\ntexture2D(tex,texcoord+direction*distortion.g).g,\ntexture2D(tex,texcoord+direction*distortion.b).b,\n1.0\n);\n}\nvoid main(void)\n{\nvec2 uv=-vUV+vec2(1.0);\nvec2 ghostDir=(vec2(0.5)-uv)*ghostDispersal;\nvec2 texelSize=1.0/resolution;\nvec3 distortion=vec3(-texelSize.x*distortionStrength,0.0,texelSize.x*distortionStrength);\nvec4 result=vec4(0.0);\nfloat ghostIndice=1.0;\nfor (int i=0; i=nSamples)\nbreak;\nvec2 offset1=vUV+velocity*(float(i)/float(nSamples-1)-0.5);\nresult+=texture2D(textureSampler,offset1);\n}\ngl_FragColor=result/float(nSamples);\n}\n#endif\n",fxaaVertexShader:"\nattribute vec2 position;\nuniform vec2 texelSize;\n\nvarying vec2 vUV;\nvarying vec2 sampleCoordS;\nvarying vec2 sampleCoordE;\nvarying vec2 sampleCoordN;\nvarying vec2 sampleCoordW;\nvarying vec2 sampleCoordNW;\nvarying vec2 sampleCoordSE;\nvarying vec2 sampleCoordNE;\nvarying vec2 sampleCoordSW;\nconst vec2 madd=vec2(0.5,0.5);\nvoid main(void) { \nvUV=(position*madd+madd);\nsampleCoordS=vUV+vec2( 0.0,1.0)*texelSize;\nsampleCoordE=vUV+vec2( 1.0,0.0)*texelSize;\nsampleCoordN=vUV+vec2( 0.0,-1.0)*texelSize;\nsampleCoordW=vUV+vec2(-1.0,0.0)*texelSize;\nsampleCoordNW=vUV+vec2(-1.0,-1.0)*texelSize;\nsampleCoordSE=vUV+vec2( 1.0,1.0)*texelSize;\nsampleCoordNE=vUV+vec2( 1.0,-1.0)*texelSize;\nsampleCoordSW=vUV+vec2(-1.0,1.0)*texelSize;\ngl_Position=vec4(position,0.0,1.0);\n}", fxaaPixelShader:"uniform sampler2D textureSampler;\nuniform vec2 texelSize;\nvarying vec2 vUV;\nvarying vec2 sampleCoordS;\nvarying vec2 sampleCoordE;\nvarying vec2 sampleCoordN;\nvarying vec2 sampleCoordW;\nvarying vec2 sampleCoordNW;\nvarying vec2 sampleCoordSE;\nvarying vec2 sampleCoordNE;\nvarying vec2 sampleCoordSW;\nconst float fxaaQualitySubpix=1.0;\nconst float fxaaQualityEdgeThreshold=0.166;\nconst float fxaaQualityEdgeThresholdMin=0.0833;\nconst vec3 kLumaCoefficients=vec3(0.2126,0.7152,0.0722);\n#define FxaaLuma(rgba) dot(rgba.rgb,kLumaCoefficients)\nvoid main(){\nvec2 posM;\nposM.x=vUV.x;\nposM.y=vUV.y;\nvec4 rgbyM=texture2D(textureSampler,vUV,0.0);\nfloat lumaM=FxaaLuma(rgbyM);\nfloat lumaS=FxaaLuma(texture2D(textureSampler,sampleCoordS,0.0));\nfloat lumaE=FxaaLuma(texture2D(textureSampler,sampleCoordE,0.0));\nfloat lumaN=FxaaLuma(texture2D(textureSampler,sampleCoordN,0.0));\nfloat lumaW=FxaaLuma(texture2D(textureSampler,sampleCoordW,0.0));\nfloat maxSM=max(lumaS,lumaM);\nfloat minSM=min(lumaS,lumaM);\nfloat maxESM=max(lumaE,maxSM);\nfloat minESM=min(lumaE,minSM);\nfloat maxWN=max(lumaN,lumaW);\nfloat minWN=min(lumaN,lumaW);\nfloat rangeMax=max(maxWN,maxESM);\nfloat rangeMin=min(minWN,minESM);\nfloat rangeMaxScaled=rangeMax*fxaaQualityEdgeThreshold;\nfloat range=rangeMax-rangeMin;\nfloat rangeMaxClamped=max(fxaaQualityEdgeThresholdMin,rangeMaxScaled);\nif(range=edgeVert;\nfloat subpixA=subpixNSWE*2.0+subpixNWSWNESE;\nif (!horzSpan)\n{\nlumaN=lumaW;\n}\nif (!horzSpan) \n{\nlumaS=lumaE;\n}\nif (horzSpan) \n{\nlengthSign=texelSize.y;\n}\nfloat subpixB=(subpixA*(1.0/12.0))-lumaM;\nfloat gradientN=lumaN-lumaM;\nfloat gradientS=lumaS-lumaM;\nfloat lumaNN=lumaN+lumaM;\nfloat lumaSS=lumaS+lumaM;\nbool pairN=abs(gradientN)>=abs(gradientS);\nfloat gradient=max(abs(gradientN),abs(gradientS));\nif (pairN)\n{\nlengthSign=-lengthSign;\n}\nfloat subpixC=clamp(abs(subpixB)*subpixRcpRange,0.0,1.0);\nvec2 posB;\nposB.x=posM.x;\nposB.y=posM.y;\nvec2 offNP;\noffNP.x=(!horzSpan) ? 0.0 : texelSize.x;\noffNP.y=(horzSpan) ? 0.0 : texelSize.y;\nif (!horzSpan) \n{\nposB.x+=lengthSign*0.5;\n}\nif (horzSpan)\n{\nposB.y+=lengthSign*0.5;\n}\nvec2 posN;\nposN.x=posB.x-offNP.x*1.5;\nposN.y=posB.y-offNP.y*1.5;\nvec2 posP;\nposP.x=posB.x+offNP.x*1.5;\nposP.y=posB.y+offNP.y*1.5;\nfloat subpixD=((-2.0)*subpixC)+3.0;\nfloat lumaEndN=FxaaLuma(texture2D(textureSampler,posN,0.0));\nfloat subpixE=subpixC*subpixC;\nfloat lumaEndP=FxaaLuma(texture2D(textureSampler,posP,0.0));\nif (!pairN) \n{\nlumaNN=lumaSS;\n}\nfloat gradientScaled=gradient*1.0/4.0;\nfloat lumaMM=lumaM-lumaNN*0.5;\nfloat subpixF=subpixD*subpixE;\nbool lumaMLTZero=lumaMM<0.0;\nlumaEndN-=lumaNN*0.5;\nlumaEndP-=lumaNN*0.5;\nbool doneN=abs(lumaEndN)>=gradientScaled;\nbool doneP=abs(lumaEndP)>=gradientScaled;\nif (!doneN) \n{\nposN.x-=offNP.x*3.0;\n}\nif (!doneN) \n{\nposN.y-=offNP.y*3.0;\n}\nbool doneNP=(!doneN) || (!doneP);\nif (!doneP) \n{\nposP.x+=offNP.x*3.0;\n}\nif (!doneP)\n{\nposP.y+=offNP.y*3.0;\n}\nif (doneNP)\n{\nif (!doneN) lumaEndN=FxaaLuma(texture2D(textureSampler,posN.xy,0.0));\nif (!doneP) lumaEndP=FxaaLuma(texture2D(textureSampler,posP.xy,0.0));\nif (!doneN) lumaEndN=lumaEndN-lumaNN*0.5;\nif (!doneP) lumaEndP=lumaEndP-lumaNN*0.5;\ndoneN=abs(lumaEndN)>=gradientScaled;\ndoneP=abs(lumaEndP)>=gradientScaled;\nif (!doneN) posN.x-=offNP.x*12.0;\nif (!doneN) posN.y-=offNP.y*12.0;\ndoneNP=(!doneN) || (!doneP);\nif (!doneP) posP.x+=offNP.x*12.0;\nif (!doneP) posP.y+=offNP.y*12.0;\n}\nfloat dstN=posM.x-posN.x;\nfloat dstP=posP.x-posM.x;\nif (!horzSpan)\n{\ndstN=posM.y-posN.y;\n}\nif (!horzSpan) \n{\ndstP=posP.y-posM.y;\n}\nbool goodSpanN=(lumaEndN<0.0) != lumaMLTZero;\nfloat spanLength=(dstP+dstN);\nbool goodSpanP=(lumaEndP<0.0) != lumaMLTZero;\nfloat spanLengthRcp=1.0/spanLength;\nbool directionN=dstN[0..varyingCount]\nconst vec2 madd=vec2(0.5,0.5);\nvoid main(void) { \nsampleCenter=(position*madd+madd);\n#include[0..varyingCount]\ngl_Position=vec4(position,0.0,1.0);\n}",kernelBlurPixelShader:"\nuniform sampler2D textureSampler;\nuniform vec2 delta;\n\nvarying vec2 sampleCenter;\n#ifdef DOF\nuniform sampler2D circleOfConfusionSampler;\nuniform vec2 cameraMinMaxZ;\nfloat sampleDistance(const in vec2 offset) {\nfloat depth=texture2D(circleOfConfusionSampler,offset).g; \nreturn cameraMinMaxZ.x+(cameraMinMaxZ.y-cameraMinMaxZ.x)*depth; \n}\n#endif\n#include[0..varyingCount]\n#ifdef PACKEDFLOAT\nvec4 pack(float depth)\n{\nconst vec4 bit_shift=vec4(255.0*255.0*255.0,255.0*255.0,255.0,1.0);\nconst vec4 bit_mask=vec4(0.0,1.0/255.0,1.0/255.0,1.0/255.0);\nvec4 res=fract(depth*bit_shift);\nres-=res.xxyz*bit_mask;\nreturn res;\n}\nfloat unpack(vec4 color)\n{\nconst vec4 bit_shift=vec4(1.0/(255.0*255.0*255.0),1.0/(255.0*255.0),1.0/255.0,1.0);\nreturn dot(color,bit_shift);\n}\n#endif\nvoid main(void)\n{\n#ifdef DOF\nfloat sumOfWeights=0.0; \nfloat sampleDepth=0.0;\nfloat factor=0.0;\nfloat centerSampleDepth=sampleDistance(sampleCenter);\n#endif\nfloat computedWeight=0.0;\n#ifdef PACKEDFLOAT \nfloat blend=0.;\n#else\nvec4 blend=vec4(0.);\n#endif\n#include[0..varyingCount]\n#include[0..depCount]\n#ifdef PACKEDFLOAT\ngl_FragColor=pack(blend);\n#else\ngl_FragColor=blend;\n#endif\n#ifdef DOF\n\nif(sumOfWeights == 0.0){\ngl_FragColor=vec4(0.0,0.0,0.0,1.0);\n}\ngl_FragColor/=sumOfWeights;\n#endif\n}",depthOfFieldMergePixelShader:"\nuniform sampler2D textureSampler;\nuniform sampler2D originalSampler;\nuniform sampler2D circleOfConfusionSampler;\n#if BLUR_LEVEL>0\nuniform sampler2D blurStep1;\n#endif\n#if BLUR_LEVEL>1\nuniform sampler2D blurStep2;\n#endif\n\nvarying vec2 vUV;\nvoid main(void)\n{\nfloat coc=texture2D(circleOfConfusionSampler,vUV).r;\nvec4 original=texture2D(originalSampler,vUV);\n#if BLUR_LEVEL == 0\nvec4 blurred1=texture2D(textureSampler,vUV);\ngl_FragColor=mix(original,blurred1,coc);\n#endif\n#if BLUR_LEVEL == 1\nvec4 blurred1=texture2D(blurStep1,vUV);\nvec4 blurred2=texture2D(textureSampler,vUV); \nif(coc<0.5){\ngl_FragColor=mix(original,blurred1,coc/0.5);\n}else{\ngl_FragColor=mix(blurred1,blurred2,(coc-0.5)/0.5);\n}\n#endif\n#if BLUR_LEVEL == 2\nvec4 blurred1=texture2D(blurStep1,vUV);\nvec4 blurred2=texture2D(blurStep2,vUV);\nvec4 blurred3=texture2D(textureSampler,vUV);\nif(coc<0.33){\ngl_FragColor=mix(original,blurred1,coc/0.33);\n}else if(coc<0.66){\ngl_FragColor=mix(blurred1,blurred2,(coc-0.33)/0.33);\n}else{\ngl_FragColor=mix(blurred2,blurred3,(coc-0.66)/0.34);\n}\n#endif\n}\n",circleOfConfusionPixelShader:"\nuniform sampler2D depthSampler;\n\nvarying vec2 vUV;\n\nuniform vec2 cameraMinMaxZ;\n\nuniform float focusDistance;\nuniform float cocPrecalculation;\nfloat sampleDistance(const in vec2 offset) {\nfloat depth=texture2D(depthSampler,offset).r; \nreturn (cameraMinMaxZ.x+(cameraMinMaxZ.y-cameraMinMaxZ.x)*depth)*1000.0; \n}\nvoid main(void)\n{\nfloat pixelDistance=sampleDistance(vUV);\nfloat coc=abs(cocPrecalculation* ((focusDistance-pixelDistance)/pixelDistance));\ncoc=clamp(coc,0.0,1.0);\ngl_FragColor=vec4(coc,texture2D(depthSampler,vUV).r,coc,1.0);\n}\n",geometryVertexShader:"precision highp float;\nprecision highp int;\n#include\n#include\nattribute vec3 position;\nattribute vec3 normal;\n#if defined(ALPHATEST) || defined(NEED_UV)\nvarying vec2 vUV;\nuniform mat4 diffuseMatrix;\n#ifdef UV1\nvarying vec2 uv;\n#endif\n#ifdef UV2\nvarying vec2 uv2;\n#endif\n#endif\n\nuniform mat4 viewProjection;\nuniform mat4 view;\nvarying vec3 vNormalV;\nvarying vec4 vViewPos;\n#ifdef POSITION\nvarying vec3 vPosition;\n#endif\nvoid main(void)\n{\n#include\n#include\nvec4 pos=vec4(finalWorld*vec4(position,1.0));\nvNormalV=normalize(vec3((view*finalWorld)*vec4(normal,0.0)));\nvViewPos=view*pos;\n#ifdef POSITION\nvPosition=pos.xyz/pos.w;\n#endif\ngl_Position=viewProjection*finalWorld*vec4(position,1.0);\n#if defined(ALPHATEST) || defined(BASIC_RENDER)\n#ifdef UV1\nvUV=vec2(diffuseMatrix*vec4(uv,1.0,0.0));\n#endif\n#ifdef UV2\nvUV=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));\n#endif\n#endif\n}",geometryPixelShader:"#extension GL_EXT_draw_buffers : require\nprecision highp float;\nprecision highp int;\nvarying vec3 vNormalV;\nvarying vec4 vViewPos;\n#ifdef POSITION\nvarying vec3 vPosition;\n#endif\n#ifdef ALPHATEST\nvarying vec2 vUV;\nuniform sampler2D diffuseSampler;\n#endif\n#ifdef POSITION\n#include[3]\n#else\n#include[2]\n#endif\nvoid main() {\n#ifdef ALPHATEST\nif (texture2D(diffuseSampler,vUV).a<0.4)\ndiscard;\n#endif\ngl_FragData[0]=vec4(vViewPos.z/vViewPos.w,0.0,0.0,1.0);\n\ngl_FragData[1]=vec4(normalize(vNormalV),1.0);\n\n#ifdef POSITION\ngl_FragData[2]=vec4(vPosition,1.0);\n#endif\n}",refractionPixelShader:"\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\nuniform sampler2D refractionSampler;\n\nuniform vec3 baseColor;\nuniform float depth;\nuniform float colorLevel;\nvoid main() {\nfloat ref=1.0-texture2D(refractionSampler,vUV).r;\nvec2 uv=vUV-vec2(0.5);\nvec2 offset=uv*depth*ref;\nvec3 sourceColor=texture2D(textureSampler,vUV-offset).rgb;\ngl_FragColor=vec4(sourceColor+sourceColor*ref*colorLevel,1.0);\n}",blackAndWhitePixelShader:"\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\nuniform float degree;\nvoid main(void) \n{\nvec3 color=texture2D(textureSampler,vUV).rgb;\nfloat luminance=dot(color,vec3(0.3,0.59,0.11)); \nvec3 blackAndWhite=vec3(luminance,luminance,luminance);\ngl_FragColor=vec4(color-((color-blackAndWhite)*degree),1.0);\n}",convolutionPixelShader:"\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\nuniform vec2 screenSize;\nuniform float kernel[9];\nvoid main(void)\n{\nvec2 onePixel=vec2(1.0,1.0)/screenSize;\nvec4 colorSum =\ntexture2D(textureSampler,vUV+onePixel*vec2(-1,-1))*kernel[0] +\ntexture2D(textureSampler,vUV+onePixel*vec2(0,-1))*kernel[1] +\ntexture2D(textureSampler,vUV+onePixel*vec2(1,-1))*kernel[2] +\ntexture2D(textureSampler,vUV+onePixel*vec2(-1,0))*kernel[3] +\ntexture2D(textureSampler,vUV+onePixel*vec2(0,0))*kernel[4] +\ntexture2D(textureSampler,vUV+onePixel*vec2(1,0))*kernel[5] +\ntexture2D(textureSampler,vUV+onePixel*vec2(-1,1))*kernel[6] +\ntexture2D(textureSampler,vUV+onePixel*vec2(0,1))*kernel[7] +\ntexture2D(textureSampler,vUV+onePixel*vec2(1,1))*kernel[8];\nfloat kernelWeight =\nkernel[0] +\nkernel[1] +\nkernel[2] +\nkernel[3] +\nkernel[4] +\nkernel[5] +\nkernel[6] +\nkernel[7] +\nkernel[8];\nif (kernelWeight<=0.0) {\nkernelWeight=1.0;\n}\ngl_FragColor=vec4((colorSum/kernelWeight).rgb,1);\n}",filterPixelShader:"\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\nuniform mat4 kernelMatrix;\nvoid main(void)\n{\nvec3 baseColor=texture2D(textureSampler,vUV).rgb;\nvec3 updatedColor=(kernelMatrix*vec4(baseColor,1.0)).rgb;\ngl_FragColor=vec4(updatedColor,1.0);\n}",volumetricLightScatteringPixelShader:"uniform sampler2D textureSampler;\nuniform sampler2D lightScatteringSampler;\nuniform float decay;\nuniform float exposure;\nuniform float weight;\nuniform float density;\nuniform vec2 meshPositionOnScreen;\nvarying vec2 vUV;\nvoid main(void) {\nvec2 tc=vUV;\nvec2 deltaTexCoord=(tc-meshPositionOnScreen.xy);\ndeltaTexCoord*=1.0/float(NUM_SAMPLES)*density;\nfloat illuminationDecay=1.0;\nvec4 color=texture2D(lightScatteringSampler,tc)*0.4;\nfor(int i=0; i\n#include\n#include\nvoid main(void)\n{\nvec4 result=texture2D(textureSampler,vUV);\n#ifdef IMAGEPROCESSING\n#ifndef FROMLINEARSPACE\n\nresult.rgb=toLinearSpace(result.rgb);\n#endif\n#ifdef GRAIN\nvec2 seed=vUV*(grainAnimatedSeed);\nfloat grain=dither(seed,grainVarianceAmount);\n\nfloat lum=getLuminance(result.rgb);\nfloat grainAmount=(cos(-PI+(lum*PI*2.))+1.)/2.;\nresult.rgb+=grain*grainAmount;\nresult.rgb=max(result.rgb,0.0);\n#endif\nresult=applyImageProcessing(result);\n#else\n\n#ifdef FROMLINEARSPACE\nresult=applyImageProcessing(result);\n#endif\n#endif\ngl_FragColor=result;\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)*color;\n#else\ngl_FragColor=color;\n#endif\n}",glowMapGenerationVertexShader:"\nattribute vec3 position;\n#include\n\n#include\nuniform mat4 viewProjection;\nvarying vec4 vPosition;\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#ifdef ALPHATEST\nvarying vec2 vUVDiffuse;\nuniform mat4 diffuseMatrix;\n#endif\n#ifdef EMISSIVE\nvarying vec2 vUVEmissive;\nuniform mat4 emissiveMatrix;\n#endif\nvoid main(void)\n{\n#include\n#include\n#ifdef CUBEMAP\nvPosition=finalWorld*vec4(position,1.0);\ngl_Position=viewProjection*finalWorld*vec4(position,1.0);\n#else\nvPosition=viewProjection*finalWorld*vec4(position,1.0);\ngl_Position=vPosition;\n#endif\n#ifdef ALPHATEST\n#ifdef DIFFUSEUV1\nvUVDiffuse=vec2(diffuseMatrix*vec4(uv,1.0,0.0));\n#endif\n#ifdef DIFFUSEUV2\nvUVDiffuse=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));\n#endif\n#endif\n#ifdef EMISSIVE\n#ifdef EMISSIVEUV1\nvUVEmissive=vec2(emissiveMatrix*vec4(uv,1.0,0.0));\n#endif\n#ifdef EMISSIVEUV2\nvUVEmissive=vec2(emissiveMatrix*vec4(uv2,1.0,0.0));\n#endif\n#endif\n}",glowMapMergePixelShader:"\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\n#ifdef EMISSIVE\nuniform sampler2D textureSampler2;\n#endif\n\nuniform float offset;\nvoid main(void) {\nvec4 baseColor=texture2D(textureSampler,vUV);\n#ifdef EMISSIVE\nbaseColor+=texture2D(textureSampler2,vUV);\nbaseColor*=offset;\n#else\nbaseColor.a=abs(offset-baseColor.a);\n#ifdef STROKE\nfloat alpha=smoothstep(.0,.1,baseColor.a);\nbaseColor.a=alpha;\nbaseColor.rgb=baseColor.rgb*alpha;\n#endif\n#endif\ngl_FragColor=baseColor;\n}",glowMapMergeVertexShader:"\nattribute vec2 position;\n\nvarying vec2 vUV;\nconst vec2 madd=vec2(0.5,0.5);\nvoid main(void) {\nvUV=position*madd+madd;\ngl_Position=vec4(position,0.0,1.0);\n}",lineVertexShader:"\nattribute vec3 position;\nattribute vec4 normal;\n\nuniform mat4 worldViewProjection;\nuniform float width;\nuniform float aspectRatio;\nvoid main(void) {\nvec4 viewPosition=worldViewProjection*vec4(position,1.0);\nvec4 viewPositionNext=worldViewProjection*vec4(normal.xyz,1.0);\nvec2 currentScreen=viewPosition.xy/viewPosition.w;\nvec2 nextScreen=viewPositionNext.xy/viewPositionNext.w;\ncurrentScreen.x*=aspectRatio;\nnextScreen.x*=aspectRatio;\nvec2 dir=normalize(nextScreen-currentScreen);\nvec2 normalDir=vec2(-dir.y,dir.x);\nnormalDir*=width/2.0;\nnormalDir.x/=aspectRatio;\nvec4 offset=vec4(normalDir*normal.w,0.0,0.0);\ngl_Position=viewPosition+offset;\n}",linePixelShader:"uniform vec4 color;\nvoid main(void) {\ngl_FragColor=color;\n}",outlineVertexShader:"\nattribute vec3 position;\nattribute vec3 normal;\n#include\n\nuniform float offset;\n#include\nuniform mat4 viewProjection;\n#ifdef ALPHATEST\nvarying vec2 vUV;\nuniform mat4 diffuseMatrix;\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#endif\n#include\nvoid main(void)\n{\nvec3 offsetPosition=position+normal*offset;\n#include\n#include\ngl_Position=viewProjection*finalWorld*vec4(offsetPosition,1.0);\n#ifdef ALPHATEST\n#ifdef UV1\nvUV=vec2(diffuseMatrix*vec4(uv,1.0,0.0));\n#endif\n#ifdef UV2\nvUV=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));\n#endif\n#endif\n#include\n}\n",outlinePixelShader:"#ifdef LOGARITHMICDEPTH\n#extension GL_EXT_frag_depth : enable\n#endif\nuniform vec4 color;\n#ifdef ALPHATEST\nvarying vec2 vUV;\nuniform sampler2D diffuseSampler;\n#endif\n#include\nvoid main(void) {\n#ifdef ALPHATEST\nif (texture2D(diffuseSampler,vUV).a<0.4)\ndiscard;\n#endif\n#include\ngl_FragColor=color;\n}",layerVertexShader:"\nattribute vec2 position;\n\nuniform vec2 scale;\nuniform vec2 offset;\nuniform mat4 textureMatrix;\n\nvarying vec2 vUV;\nconst vec2 madd=vec2(0.5,0.5);\nvoid main(void) { \nvec2 shiftedPosition=position*scale+offset;\nvUV=vec2(textureMatrix*vec4(shiftedPosition*madd+madd,1.0,0.0));\ngl_Position=vec4(shiftedPosition,0.0,1.0);\n}",layerPixelShader:"\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\n\nuniform vec4 color;\nvoid main(void) {\nvec4 baseColor=texture2D(textureSampler,vUV);\n#ifdef ALPHATEST\nif (baseColor.a<0.4)\ndiscard;\n#endif\ngl_FragColor=baseColor*color;\n}",backgroundVertexShader:"precision highp float;\n#include<__decl__backgroundVertex>\n#include\n\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\n#endif\n#include\n\n#include\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#ifdef MAINUV1\nvarying vec2 vMainUV1;\n#endif\n#ifdef MAINUV2\nvarying vec2 vMainUV2; \n#endif\n#if defined(DIFFUSE) && DIFFUSEDIRECTUV == 0\nvarying vec2 vDiffuseUV;\n#endif\n#include\n#include\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#ifdef REFLECTIONMAP_SKYBOX\nvarying vec3 vPositionUVW;\n#endif\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvarying vec3 vDirectionW;\n#endif\nvoid main(void) {\n#ifdef REFLECTIONMAP_SKYBOX\nvPositionUVW=position;\n#endif \n#include\n#include\ngl_Position=viewProjection*finalWorld*vec4(position,1.0);\nvec4 worldPos=finalWorld*vec4(position,1.0);\nvPositionW=vec3(worldPos);\n#ifdef NORMAL\nmat3 normalWorld=mat3(finalWorld);\n#ifdef NONUNIFORMSCALING\nnormalWorld=transposeMat3(inverseMat3(normalWorld));\n#endif\nvNormalW=normalize(normalWorld*normal);\n#endif\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvDirectionW=normalize(vec3(finalWorld*vec4(position,0.0)));\n#ifdef EQUIRECTANGULAR_RELFECTION_FOV\nmat3 screenToWorld=inverseMat3(mat3(finalWorld*viewProjection));\nvec3 segment=mix(vDirectionW,screenToWorld*vec3(0.0,0.0,1.0),abs(fFovMultiplier-1.0));\nif (fFovMultiplier<=1.0) {\nvDirectionW=normalize(segment);\n} else {\nvDirectionW=normalize(vDirectionW+(vDirectionW-segment));\n}\n#endif\n#endif\n#ifndef UV1\nvec2 uv=vec2(0.,0.);\n#endif\n#ifndef UV2\nvec2 uv2=vec2(0.,0.);\n#endif\n#ifdef MAINUV1\nvMainUV1=uv;\n#endif \n#ifdef MAINUV2\nvMainUV2=uv2;\n#endif\n#if defined(DIFFUSE) && DIFFUSEDIRECTUV == 0 \nif (vDiffuseInfos.x == 0.)\n{\nvDiffuseUV=vec2(diffuseMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvDiffuseUV=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n\n#include\n\n#include\n\n#include[0..maxSimultaneousLights]\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n}\n", backgroundPixelShader:"#ifdef TEXTURELODSUPPORT\n#extension GL_EXT_shader_texture_lod : enable\n#endif\nprecision highp float;\n#include<__decl__backgroundFragment>\n#define RECIPROCAL_PI2 0.15915494\n\nuniform vec3 vEyePosition;\n\nvarying vec3 vPositionW;\n#ifdef MAINUV1\nvarying vec2 vMainUV1;\n#endif \n#ifdef MAINUV2 \nvarying vec2 vMainUV2; \n#endif \n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef DIFFUSE\n#if DIFFUSEDIRECTUV == 1\n#define vDiffuseUV vMainUV1\n#elif DIFFUSEDIRECTUV == 2\n#define vDiffuseUV vMainUV2\n#else\nvarying vec2 vDiffuseUV;\n#endif\nuniform sampler2D diffuseSampler;\n#endif\n\n#ifdef REFLECTION\n#ifdef REFLECTIONMAP_3D\n#define sampleReflection(s,c) textureCube(s,c)\nuniform samplerCube reflectionSampler;\n#ifdef TEXTURELODSUPPORT\n#define sampleReflectionLod(s,c,l) textureCubeLodEXT(s,c,l)\n#else\nuniform samplerCube reflectionSamplerLow;\nuniform samplerCube reflectionSamplerHigh;\n#endif\n#else\n#define sampleReflection(s,c) texture2D(s,c)\nuniform sampler2D reflectionSampler;\n#ifdef TEXTURELODSUPPORT\n#define sampleReflectionLod(s,c,l) texture2DLodEXT(s,c,l)\n#else\nuniform samplerCube reflectionSamplerLow;\nuniform samplerCube reflectionSamplerHigh;\n#endif\n#endif\n#ifdef REFLECTIONMAP_SKYBOX\nvarying vec3 vPositionUVW;\n#else\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvarying vec3 vDirectionW;\n#endif\n#endif\n#include\n#endif\n\n#ifndef FROMLINEARSPACE\n#define FROMLINEARSPACE;\n#endif\n\n#ifndef SHADOWONLY\n#define SHADOWONLY;\n#endif\n#include\n\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include\n#include\n#include\n#include\n#include\n\n#include\n#ifdef REFLECTIONFRESNEL\n#define FRESNEL_MAXIMUM_ON_ROUGH 0.25\nvec3 fresnelSchlickEnvironmentGGX(float VdotN,vec3 reflectance0,vec3 reflectance90,float smoothness)\n{\n\nfloat weight=mix(FRESNEL_MAXIMUM_ON_ROUGH,1.0,smoothness);\nreturn reflectance0+weight*(reflectance90-reflectance0)*pow(clamp(1.0-VdotN,0.,1.),5.0);\n}\n#endif\nvoid main(void) {\n#include\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=vec3(0.0,1.0,0.0);\n#endif\n\nfloat shadow=1.;\nfloat globalShadow=0.;\nfloat shadowLightCount=0.;\n#include[0..maxSimultaneousLights]\n#ifdef SHADOWINUSE\nglobalShadow/=shadowLightCount;\n#else\nglobalShadow=1.0;\n#endif\n\nvec3 reflectionColor=vec3(1.,1.,1.);\n#ifdef REFLECTION\nvec3 reflectionVector=computeReflectionCoords(vec4(vPositionW,1.0),normalW);\n#ifdef REFLECTIONMAP_OPPOSITEZ\nreflectionVector.z*=-1.0;\n#endif\n\n#ifdef REFLECTIONMAP_3D\nvec3 reflectionCoords=reflectionVector;\n#else\nvec2 reflectionCoords=reflectionVector.xy;\n#ifdef REFLECTIONMAP_PROJECTION\nreflectionCoords/=reflectionVector.z;\n#endif\nreflectionCoords.y=1.0-reflectionCoords.y;\n#endif\n#ifdef REFLECTIONBLUR\nfloat reflectionLOD=vReflectionInfos.y;\n#ifdef TEXTURELODSUPPORT\n\nreflectionLOD=reflectionLOD*log2(vReflectionMicrosurfaceInfos.x)*vReflectionMicrosurfaceInfos.y+vReflectionMicrosurfaceInfos.z;\nreflectionColor=sampleReflectionLod(reflectionSampler,reflectionCoords,reflectionLOD).rgb;\n#else\nfloat lodReflectionNormalized=clamp(reflectionLOD,0.,1.);\nfloat lodReflectionNormalizedDoubled=lodReflectionNormalized*2.0;\nvec3 reflectionSpecularMid=sampleReflection(reflectionSampler,reflectionCoords).rgb;\nif(lodReflectionNormalizedDoubled<1.0){\nreflectionColor=mix(\nsampleReflection(reflectionSamplerHigh,reflectionCoords).rgb,\nreflectionSpecularMid,\nlodReflectionNormalizedDoubled\n);\n} else {\nreflectionColor=mix(\nreflectionSpecularMid,\nsampleReflection(reflectionSamplerLow,reflectionCoords).rgb,\nlodReflectionNormalizedDoubled-1.0\n);\n}\n#endif\n#else\nvec4 reflectionSample=sampleReflection(reflectionSampler,reflectionCoords);\nreflectionColor=reflectionSample.rgb;\n#endif\n#ifdef GAMMAREFLECTION\nreflectionColor=toLinearSpace(reflectionColor.rgb);\n#endif\n#ifdef REFLECTIONBGR\nreflectionColor=reflectionColor.bgr;\n#endif\n\nreflectionColor*=vReflectionInfos.x;\n#endif\n\nvec3 diffuseColor=vec3(1.,1.,1.);\nfloat finalAlpha=alpha;\n#ifdef DIFFUSE\nvec4 diffuseMap=texture2D(diffuseSampler,vDiffuseUV);\n#ifdef GAMMADIFFUSE\ndiffuseMap.rgb=toLinearSpace(diffuseMap.rgb);\n#endif\n\ndiffuseMap.rgb*=vDiffuseInfos.y;\n#ifdef DIFFUSEHASALPHA\nfinalAlpha*=diffuseMap.a;\n#endif\ndiffuseColor=diffuseMap.rgb;\n#endif\n\n#ifdef REFLECTIONFRESNEL\nvec3 colorBase=diffuseColor;\n#else\nvec3 colorBase=reflectionColor*diffuseColor;\n#endif\ncolorBase=max(colorBase,0.0);\n\n#ifdef USERGBCOLOR\nvec3 finalColor=colorBase;\n#else\nvec3 finalColor=colorBase.r*vPrimaryColor.rgb*vPrimaryColor.a;\nfinalColor+=colorBase.g*vSecondaryColor.rgb*vSecondaryColor.a;\nfinalColor+=colorBase.b*vTertiaryColor.rgb*vTertiaryColor.a;\n#endif\n\n#ifdef REFLECTIONFRESNEL\nvec3 reflectionAmount=vReflectionControl.xxx;\nvec3 reflectionReflectance0=vReflectionControl.yyy;\nvec3 reflectionReflectance90=vReflectionControl.zzz;\nfloat VdotN=dot(normalize(vEyePosition),normalW);\nvec3 planarReflectionFresnel=fresnelSchlickEnvironmentGGX(clamp(VdotN,0.0,1.0),reflectionReflectance0,reflectionReflectance90,1.0);\nreflectionAmount*=planarReflectionFresnel;\n#ifdef REFLECTIONFALLOFF\nfloat reflectionDistanceFalloff=1.0-clamp(length(vPositionW.xyz-vBackgroundCenter)*vReflectionControl.w,0.0,1.0);\nreflectionDistanceFalloff*=reflectionDistanceFalloff;\nreflectionAmount*=reflectionDistanceFalloff;\n#endif\nfinalColor=mix(finalColor,reflectionColor,clamp(reflectionAmount,0.,1.));\n#endif\n#ifdef OPACITYFRESNEL\nfloat viewAngleToFloor=dot(normalW,normalize(vEyePosition-vBackgroundCenter));\n\nconst float startAngle=0.1;\nfloat fadeFactor=clamp(viewAngleToFloor/startAngle,0.0,1.0);\nfinalAlpha*=fadeFactor*fadeFactor;\n#endif\n\n#ifdef SHADOWINUSE\nfinalColor=mix(finalColor*shadowLevel,finalColor,globalShadow);\n#endif\n\nvec4 color=vec4(finalColor,finalAlpha);\n#include\n#ifdef IMAGEPROCESSINGPOSTPROCESS\n\n\ncolor.rgb=clamp(color.rgb,0.,30.0);\n#else\n\ncolor=applyImageProcessing(color);\n#endif\n#ifdef PREMULTIPLYALPHA\n\ncolor.rgb*=color.a;\n#endif\n#ifndef GRAIN \n#ifdef NOISE\ncolor.rgb+=dither(vPositionW.xy,0.5);\ncolor=max(color,0.0);\n#endif\n#endif\ngl_FragColor=color;\n}\n"},e.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}\nfloat dither(vec2 seed,float varianceAmount) {\nfloat rand=getRand(seed);\nfloat dither=mix(-varianceAmount/255.0,varianceAmount/255.0,rand);\nreturn dither;\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#ifdef PROJECTEDLIGHTTEXTURE{X}\nuniform mat4 textureProjectionMatrix{X};\nuniform sampler2D projectionLightSampler{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}\nvec3 computeProjectionTextureDiffuseLighting(sampler2D projectionLightSampler,mat4 textureProjectionMatrix){\nvec4 strq=textureProjectionMatrix*vec4(vPositionW,1.0);\nstrq/=strq.w;\nvec3 textureColor=texture2D(projectionLightSampler,strq.xy).rgb;\n#ifdef PBR\ntextureColor=toLinearSpace(textureColor);\n#endif\nreturn textureColor;\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 PROJECTEDLIGHTTEXTURE{X}\nuniform mat4 textureProjectionMatrix{X};\nuniform sampler2D projectionLightSampler{X};\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\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#if defined(USE_LOCAL_REFLECTIONMAP_CUBIC) && defined(REFLECTIONMAP_CUBIC)\nuniform vec3 vReflectionPosition;\nuniform vec3 vReflectionSize; \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;\nvec3 vReflectionPosition;\nvec3 vReflectionSize;\nvec2 vEmissiveInfos;\nvec2 vLightmapInfos;\nvec2 vSpecularInfos;\nvec3 vBumpInfos;\nmat4 diffuseMatrix;\nmat4 ambientMatrix;\nmat4 opacityMatrix;\nmat4 reflectionMatrix;\nmat4 emissiveMatrix;\nmat4 lightmapMatrix;\nmat4 specularMatrix;\nmat4 bumpMatrix; \nvec4 vTangentSpaceParams;\nmat4 refractionMatrix;\nvec4 vRefractionInfos;\nvec4 vSpecularColor;\nvec3 vEmissiveColor;\nvec4 vDiffuseColor;\nfloat pointSize; \n};\nuniform Scene {\nmat4 viewProjection;\nmat4 view;\n};",shadowsFragmentFunctions:"#ifdef SHADOWS\n#ifndef SHADOWFLOAT\nfloat unpack(vec4 color)\n{\nconst vec4 bit_shift=vec4(1.0/(255.0*255.0*255.0),1.0/(255.0*255.0),1.0/255.0,1.0);\nreturn dot(color,bit_shift);\n}\n#endif\nfloat computeShadowCube(vec3 lightPosition,samplerCube shadowSampler,float darkness,vec2 depthValues)\n{\nvec3 directionToLight=vPositionW-lightPosition;\nfloat depth=length(directionToLight);\ndepth=(depth+depthValues.x)/(depthValues.y);\ndepth=clamp(depth,0.,1.0);\ndirectionToLight=normalize(directionToLight);\ndirectionToLight.y=-directionToLight.y;\n#ifndef SHADOWFLOAT\nfloat shadow=unpack(textureCube(shadowSampler,directionToLight));\n#else\nfloat shadow=textureCube(shadowSampler,directionToLight).x;\n#endif\nif (depth>shadow)\n{\nreturn darkness;\n}\nreturn 1.0;\n}\nfloat computeShadowWithPCFCube(vec3 lightPosition,samplerCube shadowSampler,float mapSize,float darkness,vec2 depthValues)\n{\nvec3 directionToLight=vPositionW-lightPosition;\nfloat depth=length(directionToLight);\ndepth=(depth+depthValues.x)/(depthValues.y);\ndepth=clamp(depth,0.,1.0);\ndirectionToLight=normalize(directionToLight);\ndirectionToLight.y=-directionToLight.y;\nfloat visibility=1.;\nvec3 poissonDisk[4];\npoissonDisk[0]=vec3(-1.0,1.0,-1.0);\npoissonDisk[1]=vec3(1.0,-1.0,-1.0);\npoissonDisk[2]=vec3(-1.0,-1.0,-1.0);\npoissonDisk[3]=vec3(1.0,-1.0,1.0);\n\n#ifndef SHADOWFLOAT\nif (unpack(textureCube(shadowSampler,directionToLight+poissonDisk[0]*mapSize))1.0 || uv.y<0. || uv.y>1.0)\n{\nreturn 1.0;\n}\nfloat shadowPixelDepth=clamp(depthMetric,0.,1.0);\n#ifndef SHADOWFLOAT\nfloat shadow=unpack(texture2D(shadowSampler,uv));\n#else\nfloat shadow=texture2D(shadowSampler,uv).x;\n#endif\nif (shadowPixelDepth>shadow)\n{\nreturn computeFallOff(darkness,clipSpace.xy,frustumEdgeFalloff);\n}\nreturn 1.;\n}\nfloat computeShadowWithPCF(vec4 vPositionFromLight,float depthMetric,sampler2D shadowSampler,float mapSize,float darkness,float frustumEdgeFalloff)\n{\nvec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;\nvec2 uv=0.5*clipSpace.xy+vec2(0.5);\nif (uv.x<0. || uv.x>1.0 || uv.y<0. || uv.y>1.0)\n{\nreturn 1.0;\n}\nfloat shadowPixelDepth=clamp(depthMetric,0.,1.0);\nfloat visibility=1.;\nvec2 poissonDisk[4];\npoissonDisk[0]=vec2(-0.94201624,-0.39906216);\npoissonDisk[1]=vec2(0.94558609,-0.76890725);\npoissonDisk[2]=vec2(-0.094184101,-0.92938870);\npoissonDisk[3]=vec2(0.34495938,0.29387760);\n\n#ifndef SHADOWFLOAT\nif (unpack(texture2D(shadowSampler,uv+poissonDisk[0]*mapSize))1.0 || uv.y<0. || uv.y>1.0)\n{\nreturn 1.0;\n}\nfloat shadowPixelDepth=clamp(depthMetric,0.,1.0);\n#ifndef SHADOWFLOAT\nfloat shadowMapSample=unpack(texture2D(shadowSampler,uv));\n#else\nfloat shadowMapSample=texture2D(shadowSampler,uv).x;\n#endif\nfloat esm=1.0-clamp(exp(min(87.,depthScale*shadowPixelDepth))*shadowMapSample,0.,1.-darkness);\nreturn computeFallOff(esm,clipSpace.xy,frustumEdgeFalloff);\n}\nfloat computeShadowWithCloseESM(vec4 vPositionFromLight,float depthMetric,sampler2D shadowSampler,float darkness,float depthScale,float frustumEdgeFalloff)\n{\nvec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;\nvec2 uv=0.5*clipSpace.xy+vec2(0.5);\nif (uv.x<0. || uv.x>1.0 || uv.y<0. || uv.y>1.0)\n{\nreturn 1.0;\n}\nfloat shadowPixelDepth=clamp(depthMetric,0.,1.0); \n#ifndef SHADOWFLOAT\nfloat shadowMapSample=unpack(texture2D(shadowSampler,uv));\n#else\nfloat shadowMapSample=texture2D(shadowSampler,uv).x;\n#endif\nfloat esm=clamp(exp(min(87.,-depthScale*(shadowPixelDepth-shadowMapSample))),darkness,1.);\nreturn computeFallOff(esm,clipSpace.xy,frustumEdgeFalloff);\n}\n#endif\n",fresnelFunction:"#ifdef FRESNEL\nfloat computeFresnelTerm(vec3 viewDirection,vec3 worldNormal,float bias,float power)\n{\nfloat fresnelTerm=pow(bias+abs(dot(viewDirection,worldNormal)),power);\nreturn clamp(fresnelTerm,0.,1.);\n}\n#endif",reflectionFunction:"#ifdef USE_LOCAL_REFLECTIONMAP_CUBIC\nvec3 parallaxCorrectNormal( vec3 vertexPos,vec3 origVec,vec3 cubeSize,vec3 cubePos ) {\n\nvec3 invOrigVec=vec3(1.0,1.0,1.0)/origVec;\nvec3 halfSize=cubeSize*0.5;\nvec3 intersecAtMaxPlane=(cubePos+halfSize-vertexPos)*invOrigVec;\nvec3 intersecAtMinPlane=(cubePos-halfSize-vertexPos)*invOrigVec;\n\nvec3 largestIntersec=max(intersecAtMaxPlane,intersecAtMinPlane);\n\nfloat distance=min(min(largestIntersec.x,largestIntersec.y),largestIntersec.z);\n\nvec3 intersectPositionWS=vertexPos+origVec*distance;\n\nreturn intersectPositionWS-cubePos;\n}\n#endif\nvec3 computeReflectionCoords(vec4 worldPos,vec3 worldNormal)\n{\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvec3 direction=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=normalize(worldPos.xyz-vEyePosition.xyz);\n\nvec3 coords=reflect(viewDir,worldNormal);\n#ifdef USE_LOCAL_REFLECTIONMAP_CUBIC\ncoords=parallaxCorrectNormal(worldPos.xyz,coords,vReflectionSize,vReflectionPosition);\n#endif\ncoords=vec3(reflectionMatrix*vec4(coords,0));\n#ifdef INVERTCUBICMAP\ncoords.y*=-1.0;\n#endif\nreturn coords;\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\n#ifdef GRAIN\nuniform float grainVarianceAmount;\nuniform float grainAnimatedSeed;\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#ifdef OBJECTSPACE_NORMALMAP\nuniform mat4 normalMatrix;\n#endif\n\nmat3 cotangent_frame(vec3 normal,vec3 p,vec2 uv)\n{\n\nuv=gl_FrontFacing ? uv : -uv;\n\nvec3 dp1=dFdx(p);\nvec3 dp2=dFdy(p);\nvec2 duv1=dFdx(uv);\nvec2 duv2=dFdy(uv);\n\nvec3 dp2perp=cross(dp2,normal);\nvec3 dp1perp=cross(normal,dp1);\nvec3 tangent=dp2perp*duv1.x+dp1perp*duv2.x;\nvec3 bitangent=dp2perp*duv1.y+dp1perp*duv2.y;\n\ntangent*=vTangentSpaceParams.x;\nbitangent*=vTangentSpaceParams.y;\n\nfloat invmax=inversesqrt(max(dot(tangent,tangent),dot(bitangent,bitangent)));\nreturn mat3(tangent*invmax,bitangent*invmax,normal);\n}\nvec3 perturbNormal(mat3 cotangentFrame,vec2 uv)\n{\nvec3 map=texture2D(bumpSampler,uv).xyz;\nmap=map*2.0-1.0;\n#ifdef NORMALXYSCALE\nmap=normalize(map*vec3(vBumpInfos.y,vBumpInfos.y,1.0));\n#endif\nreturn normalize(cotangentFrame*map);\n}\n#ifdef PARALLAX\nconst float minSamples=4.;\nconst float maxSamples=15.;\nconst int iMaxSamples=15;\n\nvec2 parallaxOcclusion(vec3 vViewDirCoT,vec3 vNormalCoT,vec2 texCoord,float parallaxScale) {\nfloat parallaxLimit=length(vViewDirCoT.xy)/vViewDirCoT.z;\nparallaxLimit*=parallaxScale;\nvec2 vOffsetDir=normalize(vViewDirCoT.xy);\nvec2 vMaxOffset=vOffsetDir*parallaxLimit;\nfloat numSamples=maxSamples+(dot(vViewDirCoT,vNormalCoT)*(minSamples-maxSamples));\nfloat stepSize=1.0/numSamples;\n\nfloat currRayHeight=1.0;\nvec2 vCurrOffset=vec2(0,0);\nvec2 vLastOffset=vec2(0,0);\nfloat lastSampledHeight=1.0;\nfloat currSampledHeight=1.0;\nfor (int i=0; icurrRayHeight)\n{\nfloat delta1=currSampledHeight-currRayHeight;\nfloat delta2=(currRayHeight+stepSize)-lastSampledHeight;\nfloat ratio=delta1/(delta1+delta2);\nvCurrOffset=(ratio)* vLastOffset+(1.0-ratio)*vCurrOffset;\n\nbreak;\n}\nelse\n{\ncurrRayHeight-=stepSize;\nvLastOffset=vCurrOffset;\nvCurrOffset+=stepSize*vMaxOffset;\nlastSampledHeight=currSampledHeight;\n}\n}\nreturn vCurrOffset;\n}\nvec2 parallaxOffset(vec3 viewDir,float heightScale)\n{\n\nfloat height=texture2D(bumpSampler,vBumpUV).w;\nvec2 texCoordOffset=heightScale*viewDir.xy*height;\nreturn -texCoordOffset;\n}\n#endif\n#endif",clipPlaneFragmentDeclaration:"#ifdef CLIPPLANE\nvarying float fClipDistance;\n#endif",fogFragmentDeclaration:"#ifdef FOG\n#define FOGMODE_NONE 0.\n#define FOGMODE_EXP 1.\n#define FOGMODE_EXP2 2.\n#define FOGMODE_LINEAR 3.\n#define E 2.71828\nuniform vec4 vFogInfos;\nuniform vec3 vFogColor;\nvarying vec3 vFogDistance;\nfloat CalcFogFactor()\n{\nfloat fogCoeff=1.0;\nfloat fogStart=vFogInfos.y;\nfloat fogEnd=vFogInfos.z;\nfloat fogDensity=vFogInfos.w;\nfloat fogDistance=length(vFogDistance);\nif (FOGMODE_LINEAR == vFogInfos.x)\n{\nfogCoeff=(fogEnd-fogDistance)/(fogEnd-fogStart);\n}\nelse if (FOGMODE_EXP == vFogInfos.x)\n{\nfogCoeff=1.0/pow(E,fogDistance*fogDensity);\n}\nelse if (FOGMODE_EXP2 == vFogInfos.x)\n{\nfogCoeff=1.0/pow(E,fogDistance*fogDistance*fogDensity*fogDensity);\n}\nreturn clamp(fogCoeff,0.0,1.0);\n}\n#endif",clipPlaneFragment:"#ifdef CLIPPLANE\nif (fClipDistance>0.0)\n{\ndiscard;\n}\n#endif",bumpFragment:"vec2 uvOffset=vec2(0.0,0.0);\n#if defined(BUMP) || defined(PARALLAX)\n#ifdef NORMALXYSCALE\nfloat normalScale=1.0;\n#else \nfloat normalScale=vBumpInfos.y;\n#endif\n#if defined(TANGENT) && defined(NORMAL)\nmat3 TBN=vTBN;\n#else\nmat3 TBN=cotangent_frame(normalW*normalScale,vPositionW,vBumpUV);\n#endif\n#endif\n#ifdef PARALLAX\nmat3 invTBN=transposeMat3(TBN);\n#ifdef PARALLAXOCCLUSION\nuvOffset=parallaxOcclusion(invTBN*-viewDirectionW,invTBN*normalW,vBumpUV,vBumpInfos.z);\n#else\nuvOffset=parallaxOffset(invTBN*viewDirectionW,vBumpInfos.z);\n#endif\n#endif\n#ifdef BUMP\n#ifdef OBJECTSPACE_NORMALMAP\nnormalW=normalize(texture2D(bumpSampler,vBumpUV).xyz*2.0-1.0);\nnormalW=normalize(mat3(normalMatrix)*normalW); \n#else\nnormalW=perturbNormal(TBN,vBumpUV+uvOffset);\n#endif\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#ifdef PROJECTEDLIGHTTEXTURE{X}\ninfo.diffuse*=computeProjectionTextureDiffuseLighting(projectionLightSampler{X},textureProjectionMatrix{X});\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#if defined(USE_LOCAL_REFLECTIONMAP_CUBIC) && defined(REFLECTIONMAP_CUBIC)\nuniform vec3 vReflectionPosition;\nuniform vec3 vReflectionSize; \n#endif\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 vReflectionPosition;\nuniform vec3 vReflectionSize; \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}",kernelBlurFragment:"#ifdef DOF\nsampleDepth=sampleDistance(sampleCoord{X});\nfactor=clamp(1.0-((centerSampleDepth-sampleDepth)/centerSampleDepth),0.0,1.0);\ncomputedWeight=KERNEL_WEIGHT{X}*factor;\nsumOfWeights+=computedWeight;\n#else\ncomputedWeight=KERNEL_WEIGHT{X};\n#endif\n#ifdef PACKEDFLOAT\nblend+=unpack(texture2D(textureSampler,sampleCoord{X}))*computedWeight;\n#else\nblend+=texture2D(textureSampler,sampleCoord{X})*computedWeight;\n#endif",kernelBlurFragment2:"#ifdef DOF\nsampleDepth=sampleDistance(sampleCoord{X});\nfactor=clamp(1.0-((centerSampleDepth-sampleDepth)/centerSampleDepth),0.0,1.0);\ncomputedWeight=KERNEL_DEP_WEIGHT{X}*factor;\nsumOfWeights+=computedWeight;\n#else\ncomputedWeight=KERNEL_DEP_WEIGHT{X};\n#endif\n#ifdef PACKEDFLOAT\nblend+=unpack(texture2D(textureSampler,sampleCenter+delta*KERNEL_DEP_OFFSET{X}))*computedWeight;\n#else\nblend+=texture2D(textureSampler,sampleCenter+delta*KERNEL_DEP_OFFSET{X})*computedWeight;\n#endif",kernelBlurVaryingDeclaration:"varying vec2 sampleCoord{X};",kernelBlurVertex:"sampleCoord{X}=sampleCenter+delta*KERNEL_OFFSET{X};",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",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;\nuniform float fFovMultiplier;\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 fFovMultiplier;\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};"};var e;!(function(e){var t=(function(e){function t(){var t=e.call(this)||this;return t.TRANSPARENT=!1,t.FOG=!1,t.PREMULTIPLYALPHA=!1,t.rebuild(),t}return __extends(t,e),t})(e.MaterialDefines),i=(function(i){function r(t,r){var n=i.call(this,t,r)||this;return n.mainColor=e.Color3.Black(),n.lineColor=e.Color3.Teal(),n.gridRatio=1,n.gridOffset=e.Vector3.Zero(),n.majorUnitFrequency=10,n.minorUnitVisibility=.33,n.opacity=1,n.preMultiplyAlpha=!1,n._gridControl=new e.Vector4(n.gridRatio,n.majorUnitFrequency,n.minorUnitVisibility,n.opacity),n}return __extends(r,i),r.prototype.needAlphaBlending=function(){return this.opacity<1},r.prototype.needAlphaBlendingForMesh=function(e){return this.needAlphaBlending()},r.prototype.isReadyForSubMesh=function(i,r,n){if(this.isFrozen&&this._wasPreviouslyReady&&r.effect)return!0;r._materialDefines||(r._materialDefines=new t);var o=r._materialDefines,s=this.getScene();if(!this.checkReadyOnEveryCall&&r.effect&&this._renderId===s.getRenderId())return!0;if(o.TRANSPARENT!==this.opacity<1&&(o.TRANSPARENT=!o.TRANSPARENT,o.markAsUnprocessed()),o.PREMULTIPLYALPHA!=this.preMultiplyAlpha&&(o.PREMULTIPLYALPHA=!o.PREMULTIPLYALPHA,o.markAsUnprocessed()),e.MaterialHelper.PrepareDefinesForMisc(i,s,!1,!1,this.fogEnabled,!1,o),o.isDirty){o.markAsProcessed(),s.resetCachedMaterial();var a=[e.VertexBuffer.PositionKind,e.VertexBuffer.NormalKind],l=o.toString();r.setEffect(s.getEngine().createEffect("grid",a,["projection","worldView","mainColor","lineColor","gridControl","gridOffset","vFogInfos","vFogColor","world","view"],[],l,void 0,this.onCompiled,this.onError),o)}return!(!r.effect||!r.effect.isReady())&&(this._renderId=s.getRenderId(),this._wasPreviouslyReady=!0,!0)},r.prototype.bindForSubMesh=function(t,i,r){var n=this.getScene();if(r._materialDefines){var o=r.effect;o&&(this._activeEffect=o,this.bindOnlyWorldMatrix(t),this._activeEffect.setMatrix("worldView",t.multiply(n.getViewMatrix())),this._activeEffect.setMatrix("view",n.getViewMatrix()),this._activeEffect.setMatrix("projection",n.getProjectionMatrix()),this._mustRebind(n,o)&&(this._activeEffect.setColor3("mainColor",this.mainColor),this._activeEffect.setColor3("lineColor",this.lineColor),this._activeEffect.setVector3("gridOffset",this.gridOffset),this._gridControl.x=this.gridRatio,this._gridControl.y=Math.round(this.majorUnitFrequency),this._gridControl.z=this.minorUnitVisibility,this._gridControl.w=this.opacity,this._activeEffect.setVector4("gridControl",this._gridControl)),e.MaterialHelper.BindFogParameters(n,i,this._activeEffect),this._afterBind(i,this._activeEffect))}},r.prototype.dispose=function(e){i.prototype.dispose.call(this,e)},r.prototype.clone=function(t){var i=this;return e.SerializationHelper.Clone((function(){return new r(t,i.getScene())}),this)},r.prototype.serialize=function(){var t=e.SerializationHelper.Serialize(this);return t.customType="BABYLON.GridMaterial",t},r.prototype.getClassName=function(){return"GridMaterial"},r.Parse=function(t,i,n){return e.SerializationHelper.Parse((function(){return new r(t.name,i)}),t,i,n)},__decorate([e.serializeAsColor3()],r.prototype,"mainColor",void 0),__decorate([e.serializeAsColor3()],r.prototype,"lineColor",void 0),__decorate([e.serialize()],r.prototype,"gridRatio",void 0),__decorate([e.serializeAsColor3()],r.prototype,"gridOffset",void 0),__decorate([e.serialize()],r.prototype,"majorUnitFrequency",void 0),__decorate([e.serialize()],r.prototype,"minorUnitVisibility",void 0),__decorate([e.serialize()],r.prototype,"opacity",void 0),__decorate([e.serialize()],r.prototype,"preMultiplyAlpha",void 0),r})(e.PushMaterial);e.GridMaterial=i})(e||(e={})),e.Effect.ShadersStore.gridVertexShader="precision highp float;\n\nattribute vec3 position;\nattribute vec3 normal;\n\nuniform mat4 projection;\nuniform mat4 world;\nuniform mat4 view;\nuniform mat4 worldView;\n\n#ifdef TRANSPARENT\nvarying vec4 vCameraSpacePosition;\n#endif\nvarying vec3 vPosition;\nvarying vec3 vNormal;\n#include\nvoid main(void) {\n#ifdef FOG\nvec4 worldPos=world*vec4(position,1.0);\n#endif\n#include\nvec4 cameraSpacePosition=worldView*vec4(position,1.0);\ngl_Position=projection*cameraSpacePosition;\n#ifdef TRANSPARENT\nvCameraSpacePosition=cameraSpacePosition;\n#endif\nvPosition=position;\nvNormal=normal;\n}", e.Effect.ShadersStore.gridPixelShader="#extension GL_OES_standard_derivatives : enable\n#define SQRT2 1.41421356\n#define PI 3.14159\nprecision highp float;\nuniform vec3 mainColor;\nuniform vec3 lineColor;\nuniform vec4 gridControl;\nuniform vec3 gridOffset;\n\n#ifdef TRANSPARENT\nvarying vec4 vCameraSpacePosition;\n#endif\nvarying vec3 vPosition;\nvarying vec3 vNormal;\n#include\nfloat getVisibility(float position) {\n\nfloat majorGridFrequency=gridControl.y;\nif (floor(position+0.5) == floor(position/majorGridFrequency+0.5)*majorGridFrequency)\n{\nreturn 1.0;\n} \nreturn gridControl.z;\n}\nfloat getAnisotropicAttenuation(float differentialLength) {\nconst float maxNumberOfLines=10.0;\nreturn clamp(1.0/(differentialLength+1.0)-1.0/maxNumberOfLines,0.0,1.0);\n}\nfloat isPointOnLine(float position,float differentialLength) {\nfloat fractionPartOfPosition=position-floor(position+0.5); \nfractionPartOfPosition/=differentialLength; \nfractionPartOfPosition=clamp(fractionPartOfPosition,-1.,1.);\nfloat result=0.5+0.5*cos(fractionPartOfPosition*PI); \nreturn result; \n}\nfloat contributionOnAxis(float position) {\nfloat differentialLength=length(vec2(dFdx(position),dFdy(position)));\ndifferentialLength*=SQRT2; \n\nfloat result=isPointOnLine(position,differentialLength);\n\nfloat visibility=getVisibility(position);\nresult*=visibility;\n\nfloat anisotropicAttenuation=getAnisotropicAttenuation(differentialLength);\nresult*=anisotropicAttenuation;\nreturn result;\n}\nfloat normalImpactOnAxis(float x) {\nfloat normalImpact=clamp(1.0-3.0*abs(x*x*x),0.0,1.0);\nreturn normalImpact;\n}\nvoid main(void) {\n\nfloat gridRatio=gridControl.x;\nvec3 gridPos=(vPosition+gridOffset)/gridRatio;\n\nfloat x=contributionOnAxis(gridPos.x);\nfloat y=contributionOnAxis(gridPos.y);\nfloat z=contributionOnAxis(gridPos.z);\n\nvec3 normal=normalize(vNormal);\nx*=normalImpactOnAxis(normal.x);\ny*=normalImpactOnAxis(normal.y);\nz*=normalImpactOnAxis(normal.z);\n\nfloat grid=clamp(x+y+z,0.,1.);\n\nvec3 color=mix(mainColor,lineColor,grid);\n#ifdef FOG\n#include\n#endif\n#ifdef TRANSPARENT\nfloat distanceToFragment=length(vCameraSpacePosition.xyz);\nfloat cameraPassThrough=clamp(distanceToFragment-0.25,0.0,1.0);\nfloat opacity=clamp(grid,0.08,cameraPassThrough*gridControl.w*grid);\ngl_FragColor=vec4(color.rgb,opacity);\n#ifdef PREMULTIPLYALPHA\ngl_FragColor.rgb*=opacity;\n#endif\n#else\n\ngl_FragColor=vec4(color.rgb,1.0);\n#endif\n}";var e;!(function(e){var t;!(function(e){e[e.AUTO=0]="AUTO",e[e.FORCE_RIGHT_HANDED=1]="FORCE_RIGHT_HANDED"})(t=e.GLTFLoaderCoordinateSystemMode||(e.GLTFLoaderCoordinateSystemMode={}));var i;!(function(e){e[e.NONE=0]="NONE",e[e.FIRST=1]="FIRST",e[e.ALL=2]="ALL"})(i=e.GLTFLoaderAnimationStartMode||(e.GLTFLoaderAnimationStartMode={}));!(function(e){e[e.Loading=0]="Loading",e[e.Ready=1]="Ready",e[e.Complete=2]="Complete"})(e.GLTFLoaderState||(e.GLTFLoaderState={}));var r=(function(){function r(){this.onParsedObservable=new e.Observable,this.coordinateSystemMode=t.AUTO,this.animationStartMode=i.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.onAnimationGroupLoadedObservable=new e.Observable,this.onCompleteObservable=new e.Observable,this.onDisposeObservable=new e.Observable,this.onExtensionLoadedObservable=new e.Observable,this._loader=null,this.name="gltf",this.extensions={".gltf":{isBinary:!1},".glb":{isBinary:!0}}}return Object.defineProperty(r.prototype,"onParsed",{set:function(e){this._onParsedObserver&&this.onParsedObservable.remove(this._onParsedObserver),this._onParsedObserver=this.onParsedObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"onMeshLoaded",{set:function(e){this._onMeshLoadedObserver&&this.onMeshLoadedObservable.remove(this._onMeshLoadedObserver),this._onMeshLoadedObserver=this.onMeshLoadedObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"onTextureLoaded",{set:function(e){this._onTextureLoadedObserver&&this.onTextureLoadedObservable.remove(this._onTextureLoadedObserver),this._onTextureLoadedObserver=this.onTextureLoadedObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"onMaterialLoaded",{set:function(e){this._onMaterialLoadedObserver&&this.onMaterialLoadedObservable.remove(this._onMaterialLoadedObserver),this._onMaterialLoadedObserver=this.onMaterialLoadedObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"onAnimationGroupLoaded",{set:function(e){this._onAnimationGroupLoadedObserver&&this.onAnimationGroupLoadedObservable.remove(this._onAnimationGroupLoadedObserver),this._onAnimationGroupLoadedObserver=this.onAnimationGroupLoadedObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"onComplete",{set:function(e){this._onCompleteObserver&&this.onCompleteObservable.remove(this._onCompleteObserver),this._onCompleteObserver=this.onCompleteObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"onDispose",{set:function(e){this._onDisposeObserver&&this.onDisposeObservable.remove(this._onDisposeObserver),this._onDisposeObserver=this.onDisposeObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"onExtensionLoaded",{set:function(e){this._onExtensionLoadedObserver&&this.onExtensionLoadedObservable.remove(this._onExtensionLoadedObserver),this._onExtensionLoadedObserver=this.onExtensionLoadedObservable.add(e)},enumerable:!0,configurable:!0}),r.prototype.whenCompleteAsync=function(){var e=this;return new Promise(function(t){e.onCompleteObservable.add((function(){t()}),void 0,void 0,void 0,!0)})},Object.defineProperty(r.prototype,"loaderState",{get:function(){return this._loader?this._loader.state:null},enumerable:!0,configurable:!0}),r.prototype.dispose=function(){this._loader&&(this._loader.dispose(),this._loader=null),this.onMeshLoadedObservable.clear(),this.onTextureLoadedObservable.clear(),this.onMaterialLoadedObservable.clear(),this.onDisposeObservable.notifyObservers(this),this.onDisposeObservable.clear()},r.prototype.importMeshAsync=function(e,t,i,r,n){var o=this;return Promise.resolve().then((function(){var s=o._parse(i);return o._loader=o._getLoader(s),o._loader.importMeshAsync(e,t,s,r,n)}))},r.prototype.loadAsync=function(e,t,i,r){var n=this;return Promise.resolve().then((function(){var o=n._parse(t);return n._loader=n._getLoader(o),n._loader.loadAsync(e,o,i,r)}))},r.prototype.loadAssetContainerAsync=function(t,i,r,n){var o=this;return Promise.resolve().then((function(){var s=o._parse(i);return o._loader=o._getLoader(s),o._loader.importMeshAsync(null,t,s,r,n).then((function(i){var r=new e.AssetContainer(t);return Array.prototype.push.apply(r.meshes,i.meshes),Array.prototype.push.apply(r.particleSystems,i.particleSystems),Array.prototype.push.apply(r.skeletons,i.skeletons),r.removeAllFromScene(),r}))}))},r.prototype.canDirectLoad=function(e){return-1!==e.indexOf("scene")&&-1!==e.indexOf("node")},r.prototype.createPlugin=function(){return new r},r.prototype._parse=function(e){var t;return t=e instanceof ArrayBuffer?r._parseBinary(e):{json:JSON.parse(e),bin:null},this.onParsedObservable.notifyObservers(t),this.onParsedObservable.clear(),t},r.prototype._getLoader=function(e){var t=this,i={major:2,minor:0},n=e.json.asset||{},o=r._parseVersion(n.version);if(!o)throw new Error("Invalid version: "+n.version);if(void 0!==n.minVersion){var s=r._parseVersion(n.minVersion);if(!s)throw new Error("Invalid minimum version: "+n.minVersion);if(r._compareVersion(s,i)>0)throw new Error("Incompatible minimum version: "+n.minVersion)}var a={1:r.CreateGLTFLoaderV1,2:r.CreateGLTFLoaderV2},l=a[o.major];if(!l)throw new Error("Unsupported version: "+n.version);var c=l();return c.coordinateSystemMode=this.coordinateSystemMode,c.animationStartMode=this.animationStartMode,c.compileMaterials=this.compileMaterials,c.useClipPlane=this.useClipPlane,c.compileShadowGenerators=this.compileShadowGenerators,c.onMeshLoadedObservable.add((function(e){return t.onMeshLoadedObservable.notifyObservers(e)})),c.onTextureLoadedObservable.add((function(e){return t.onTextureLoadedObservable.notifyObservers(e)})),c.onMaterialLoadedObservable.add((function(e){return t.onMaterialLoadedObservable.notifyObservers(e)})),c.onExtensionLoadedObservable.add((function(e){return t.onExtensionLoadedObservable.notifyObservers(e)})),c.onCompleteObservable.add((function(){t.onMeshLoadedObservable.clear(),t.onTextureLoadedObservable.clear(),t.onMaterialLoadedObservable.clear(),t.onCompleteObservable.notifyObservers(t),t.onCompleteObservable.clear()})),c},r._parseBinary=function(e){var t={Magic:1179937895},i=new n(e),o=i.readUint32();if(o!==t.Magic)throw new Error("Unexpected magic: "+o);var s=i.readUint32();switch(s){case 1:return r._parseV1(i);case 2:return r._parseV2(i)}throw new Error("Unsupported version: "+s)},r._parseV1=function(e){var t={JSON:0},i=e.readUint32();if(i!=e.getLength())throw new Error("Length in header does not match actual data length: "+i+" != "+e.getLength());var n,o=e.readUint32(),s=e.readUint32();switch(s){case t.JSON:n=JSON.parse(r._decodeBufferToText(e.readUint8Array(o)));break;default:throw new Error("Unexpected content format: "+s)}var a=e.getLength()-e.getPosition();return{json:n,bin:e.readUint8Array(a)}},r._parseV2=function(e){var t={JSON:1313821514,BIN:5130562},i=e.readUint32();if(i!==e.getLength())throw new Error("Length in header does not match actual data length: "+i+" != "+e.getLength());var n=e.readUint32();if(e.readUint32()!==t.JSON)throw new Error("First chunk format is not JSON");for(var o=JSON.parse(r._decodeBufferToText(e.readUint8Array(n))),s=null;e.getPosition()t.major?1:e.majort.minor?1:e.minor=this._maxPos},e})(),n=["MODEL","VIEW","PROJECTION","MODELVIEW","MODELVIEWPROJECTION","JOINTMATRIX"],o=["world","view","projection","worldView","worldViewProjection","mBones"],s=["translation","rotation","scale"],a=["position","rotationQuaternion","scaling"],l=function(e,t){for(var i in e){var r=e[i];t.buffers[i]=r,t.buffersCount++}},c=function(e,t){for(var i in e){var r=e[i];t.shaders[i]=r,t.shaderscount++}},h=function(e,t,i){for(var r in e){var n=e[r];i[t][r]=n}},u=function(e){if(e)for(var t=0;t0&&(d=m(s,o))&&-1===a.indexOf(d)&&a.push(d);new e.Bone(h.jointName||"",n,d,A).id=o}}else e.Tools.Warn("Joint named "+i.jointNames[l]+" does not exist")}}var P=n.bones;n.bones=[];for(var l=0;l1?(O=new e.MultiMaterial("multimat"+o,i.scene),O.subMaterials=a):O=new e.StandardMaterial("multimat"+o,i.scene),1===a.length&&(O=a[0]),s.material||(s.material=O),new e.Geometry(o,i.scene,l,!1,s),s.computeWorldMatrix(!0),s.subMeshes=[];for(var I=0,p=0;p0&&-1===t.importMeshesNames.indexOf(i.name||""))return null;if(i.skin){if(i.meshes){var s=t.skins[i.skin],a=x(t,i,i.meshes,r,i.babylonNode);a.skeleton=t.scene.getLastSkeletonByID(i.skin),null===a.skeleton&&(a.skeleton=b(t,s,0,s.babylonSkeleton,i.skin),s.babylonSkeleton||(s.babylonSkeleton=a.skeleton)),o=a}}else if(i.meshes){var a=x(t,i,i.mesh?[i.mesh]:i.meshes,r,i.babylonNode);o=a}else if(!i.light||i.babylonNode||t.importOnlyMeshes){if(i.camera&&!i.babylonNode&&!t.importOnlyMeshes){var l=t.cameras[i.camera];if(l)if("orthographic"===l.type){var c=new e.FreeCamera(i.camera,e.Vector3.Zero(),t.scene);c.name=i.name||"",c.mode=e.Camera.ORTHOGRAPHIC_CAMERA,c.attachControl(t.scene.getEngine().getRenderingCanvas()),o=c}else if("perspective"===l.type){var h=l[l.type],u=new e.FreeCamera(i.camera,e.Vector3.Zero(),t.scene);u.name=i.name||"",u.attachControl(t.scene.getEngine().getRenderingCanvas()),h.aspectRatio||(h.aspectRatio=t.scene.getEngine().getRenderWidth()/t.scene.getEngine().getRenderHeight()),h.znear&&h.zfar&&(u.maxZ=h.zfar,u.minZ=h.znear),o=u}}}else{var f=t.lights[i.light];if(f)if("ambient"===f.type){var d=f[f.type],p=new e.HemisphericLight(i.light,e.Vector3.Zero(),t.scene);p.name=i.name||"",d.color&&(p.diffuse=e.Color3.FromArray(d.color)),o=p}else if("directional"===f.type){var _=f[f.type],m=new e.DirectionalLight(i.light,e.Vector3.Zero(),t.scene);m.name=i.name||"",_.color&&(m.diffuse=e.Color3.FromArray(_.color)),o=m}else if("point"===f.type){var g=f[f.type],v=new e.PointLight(i.light,e.Vector3.Zero(),t.scene);v.name=i.name||"",g.color&&(v.diffuse=e.Color3.FromArray(g.color)),o=v}else if("spot"===f.type){var y=f[f.type],A=new e.SpotLight(i.light,e.Vector3.Zero(),e.Vector3.Zero(),0,0,t.scene);A.name=i.name||"",y.color&&(A.diffuse=e.Color3.FromArray(y.color)),y.fallOfAngle&&(A.angle=y.fallOfAngle),y.fallOffExponent&&(A.exponent=y.fallOffExponent),o=A}}if(!i.jointName){if(i.babylonNode)return i.babylonNode;if(null===o){var P=new e.Mesh(i.name||"",t.scene);i.babylonNode=P,o=P}}if(null!==o){if(i.matrix&&o instanceof e.Mesh)E(o,i);else{var M=i.translation||[0,0,0],S=i.rotation||[0,0,0,1],C=i.scale||[1,1,1];T(o,e.Vector3.FromArray(M),e.Quaternion.FromArray(S),e.Vector3.FromArray(C))}o.updateCache(!0),i.babylonNode=o}return o},P=function(e,t,i,r){void 0===r&&(r=!1);var n=e.nodes[t],o=null;if(r=!(e.importOnlyMeshes&&!r&&e.importMeshesNames)||(-1!==e.importMeshesNames.indexOf(n.name||"")||0===e.importMeshesNames.length),!n.jointName&&r&&null!==(o=A(e,n,t))&&(o.id=t,o.parent=i),n.children)for(var s=0;ss.byteLength)throw new Error("Buffer access is out of range");var a=s.buffer;switch(r+=s.byteOffset,o){case t.EComponentType.BYTE:return new Int8Array(a,r,n);case t.EComponentType.UNSIGNED_BYTE:return new Uint8Array(a,r,n);case t.EComponentType.SHORT:return new Int16Array(a,r,n);case t.EComponentType.UNSIGNED_SHORT:return new Uint16Array(a,r,n);default:return new Float32Array(a,r,n)}},i.GetBufferFromAccessor=function(e,t){var r=e.bufferViews[t.bufferView],n=t.count*i.GetByteStrideFromType(t);return i.GetBufferFromBufferView(e,r,t.byteOffset,n,t.componentType)},i.DecodeBufferToText=function(e){for(var t="",i=e.byteLength,r=0;rt.bin.byteLength)&&e.Tools.Warn("Binary buffer length ("+r.byteLength+") from JSON does not match chunk length ("+t.bin.byteLength+")"),r._data=Promise.resolve(t.bin)}else e.Tools.Warn("Unexpected BIN chunk")}},i.prototype._setupData=function(){if(t.ArrayItem.Assign(this._gltf.accessors),t.ArrayItem.Assign(this._gltf.animations),t.ArrayItem.Assign(this._gltf.buffers),t.ArrayItem.Assign(this._gltf.bufferViews),t.ArrayItem.Assign(this._gltf.cameras),t.ArrayItem.Assign(this._gltf.images),t.ArrayItem.Assign(this._gltf.materials),t.ArrayItem.Assign(this._gltf.meshes),t.ArrayItem.Assign(this._gltf.nodes),t.ArrayItem.Assign(this._gltf.samplers),t.ArrayItem.Assign(this._gltf.scenes),t.ArrayItem.Assign(this._gltf.skins),t.ArrayItem.Assign(this._gltf.textures),this._gltf.nodes){for(var e={},i=0,r=this._gltf.nodes;i=0;s--)if(o.push(t.GLTFLoader._GetProperty(e+"/ids/"+n[s],r,n[s])),o.length===this.maxLODsToLoad)return o;return o.push(i),o},n})(t.GLTFLoaderExtension);i.MSFT_lod=n,t.GLTFLoader._Register(r,(function(e){return new n(e)}))})(t.Extensions||(t.Extensions={}))})(e.GLTF2||(e.GLTF2={}))})(e||(e={}));var e;!(function(e){!(function(t){!(function(i){var r="KHR_draco_mesh_compression",n=(function(i){function n(t){var n=i.call(this,t)||this;return n.name=r,n._dracoCompression=null,e.DracoCompression.DecoderUrl||(n.enabled=!1),n}return __extends(n,i),n.prototype.dispose=function(){this._dracoCompression&&this._dracoCompression.dispose(),i.prototype.dispose.call(this)},n.prototype._loadVertexDataAsync=function(i,r,n){var o=this;return this._loadExtensionAsync(i,r,(function(s,a){if(void 0!=r.mode){if(5!==r.mode&&4!==r.mode)throw new Error(i+": Unsupported mode "+r.mode);if(5===r.mode)throw new Error(i+": Mode "+r.mode+" is not currently supported")}var l={},c=function(e,t){var i=a.attributes[e];void 0!=i&&(n._delayInfo=n._delayInfo||[],-1===n._delayInfo.indexOf(t)&&n._delayInfo.push(t),l[t]=i)};c("POSITION",e.VertexBuffer.PositionKind),c("NORMAL",e.VertexBuffer.NormalKind),c("TANGENT",e.VertexBuffer.TangentKind),c("TEXCOORD_0",e.VertexBuffer.UVKind),c("TEXCOORD_1",e.VertexBuffer.UV2Kind),c("JOINTS_0",e.VertexBuffer.MatricesIndicesKind),c("WEIGHTS_0",e.VertexBuffer.MatricesWeightsKind),c("COLOR_0",e.VertexBuffer.ColorKind);var h=t.GLTFLoader._GetProperty(s,o._loader._gltf.bufferViews,a.bufferView);return o._loader._loadBufferViewAsync("#/bufferViews/"+h._index,h).then((function(t){try{return o._dracoCompression||(o._dracoCompression=new e.DracoCompression),o._dracoCompression.decodeMeshAsync(t,l)}catch(e){throw new Error(i+": "+e.message)}}))}))},n})(t.GLTFLoaderExtension);i.KHR_draco_mesh_compression=n,t.GLTFLoader._Register(r,(function(e){return new n(e)}))})(t.Extensions||(t.Extensions={}))})(e.GLTF2||(e.GLTF2={}))})(e||(e={}));var e;!(function(e){!(function(t){!(function(i){var r="KHR_materials_pbrSpecularGlossiness",n=(function(t){function i(){var e=null!==t&&t.apply(this,arguments)||this;return e.name=r,e}return __extends(i,t),i.prototype._loadMaterialAsync=function(e,t,i,r){var n=this;return this._loadExtensionAsync(e,t,(function(e,o){if(t._babylonMeshes=t._babylonMeshes||[],t._babylonMeshes.push(i),!t._loaded){var s=new Array,a=n._loader._createMaterial(t);t._babylonMaterial=a,s.push(n._loader._loadMaterialBasePropertiesAsync(e,t)),s.push(n._loadSpecularGlossinessPropertiesAsync(e,t,o)),n._loader.onMaterialLoadedObservable.notifyObservers(a),t._loaded=Promise.all(s).then((function(){}))}return r(t._babylonMaterial),t._loaded}))},i.prototype._loadSpecularGlossinessPropertiesAsync=function(t,i,r){var n=new Array,o=i._babylonMaterial;return r.diffuseFactor?(o.albedoColor=e.Color3.FromArray(r.diffuseFactor),o.alpha=r.diffuseFactor[3]):o.albedoColor=e.Color3.White(),o.reflectivityColor=r.specularFactor?e.Color3.FromArray(r.specularFactor):e.Color3.White(),o.microSurface=void 0==r.glossinessFactor?1:r.glossinessFactor,r.diffuseTexture&&n.push(this._loader._loadTextureAsync(t+"/diffuseTexture",r.diffuseTexture,(function(e){o.albedoTexture=e}))),r.specularGlossinessTexture&&(n.push(this._loader._loadTextureAsync(t+"/specularGlossinessTexture",r.specularGlossinessTexture,(function(e){o.reflectivityTexture=e}))),o.reflectivityTexture.hasAlpha=!0,o.useMicroSurfaceFromReflectivityMapAlpha=!0),this._loader._loadMaterialAlphaProperties(t,i),Promise.all(n).then((function(){}))},i})(t.GLTFLoaderExtension);i.KHR_materials_pbrSpecularGlossiness=n,t.GLTFLoader._Register(r,(function(e){return new n(e)}))})(t.Extensions||(t.Extensions={}))})(e.GLTF2||(e.GLTF2={}))})(e||(e={}));var e;return (function(e){!(function(t){!(function(i){var r,n="KHR_lights";!(function(e){e.AMBIENT="ambient",e.DIRECTIONAL="directional",e.POINT="point",e.SPOT="spot"})(r||(r={}));var o=(function(i){function o(){var e=null!==i&&i.apply(this,arguments)||this;return e.name=n,e}return __extends(o,i),o.prototype._loadSceneAsync=function(i,n){var o=this;return this._loadExtensionAsync(i,n,(function(i,s){var a=o._loader._loadSceneAsync(i,n),l=t.GLTFLoader._GetProperty(i,o._lights,s.light);if(l.type!==r.AMBIENT)throw new Error(i+": Only ambient lights are allowed on a scene");return o._loader._babylonScene.ambientColor=l.color?e.Color3.FromArray(l.color):e.Color3.Black(),a}))},o.prototype._loadNodeAsync=function(i,n){var o=this;return this._loadExtensionAsync(i,n,(function(i,s){var a,l=o._loader._loadNodeAsync(i,n),c=t.GLTFLoader._GetProperty(i,o._lights,s.light),h=n._babylonMesh.name;switch(c.type){case r.AMBIENT:throw new Error(i+": Ambient lights are not allowed on a node");case r.DIRECTIONAL:a=new e.DirectionalLight(h,e.Vector3.Forward(),o._loader._babylonScene);break;case r.POINT:a=new e.PointLight(h,e.Vector3.Zero(),o._loader._babylonScene);break;case r.SPOT:var u=c,f=u.outerConeAngle||Math.PI/4;a=new e.SpotLight(h,e.Vector3.Zero(),e.Vector3.Forward(),f,2,o._loader._babylonScene);break;default:throw new Error(i+": Invalid light type ("+c.type+")")}return a.diffuse=c.color?e.Color3.FromArray(c.color):e.Color3.White(),a.intensity=void 0==c.intensity?1:c.intensity,a.parent=n._babylonMesh,l}))},Object.defineProperty(o.prototype,"_lights",{get:function(){var e=this._loader._gltf.extensions;if(!e||!e[this.name])throw new Error("#/extensions: '"+this.name+"' not found");return e[this.name].lights},enumerable:!0,configurable:!0}),o})(t.GLTFLoaderExtension);i.KHR_lights=o,t.GLTFLoader._Register(n,(function(e){return new o(e)}))})(t.Extensions||(t.Extensions={}))})(e.GLTF2||(e.GLTF2={}))})(e||(e={})),("undefined"!=typeof global?global:"undefined"!=typeof window?window:this).BABYLON=e,e}));