/* PlayCanvas Engine v1.35.0 revision 100604b Copyright 2011-2020 PlayCanvas Ltd. All rights reserved. */ (function(m,Zc){"object"===typeof exports&&"undefined"!==typeof module?Zc(exports):"function"===typeof define&&define.amd?define(["exports"],Zc):(m="undefined"!==typeof globalThis?globalThis:m||self,Zc(m.pc={}))})(this,function(m){function Zc(a){if(null===a)return"null";var b=typeof a;return"undefined"===b||"number"===b||"string"===b||"boolean"===b?b:tn[Object.prototype.toString.call(a)]}function Gc(a,b){var c;for(c in b){var d=b[c];"object"==Zc(d)?a[c]=Gc({},d):"array"==Zc(d)?a[c]=Gc([],d):a[c]= d}return a}function Xh(a){return void 0!==a}function M(){this._callbacks={};this._callbackActive={}}function Yh(a,b){var c=a.length;b=b||0;if(0>b||b>=c)return null;var d=a.charCodeAt(b);return 1=d&&(a=a.charCodeAt(b+1),56320<=a&&57343>=a)?{code:1024*(d-55296)+a-56320+65536,long:!0}:{code:d,long:!1}}function $c(a,b,c){return a?(a=Yh(a))?(a=a.code,a>=b&&a<=c):!1:!1}function L(a,b,c,d){var e=a&&a.length;3===e||4===e?(this.r=a[0],this.g=a[1],this.b=a[2],this.a=void 0!==a[3]?a[3]:1): (this.r=a||0,this.g=b||0,this.b=c||0,this.a=void 0!==d?d:1)}function Zh(){this._list=[];this._index={}}function uk(a){this._index={};this._key=a||null}function ad(a){M.call(this);this._index={};this._list=[];this._parent=a}function $h(){this._isRunning=!1;this._b=this._a=0}function qg(a){a=a.match(/^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/);this.scheme=a[2];this.authority=a[4];this.path=a[5];this.query=a[7];this.fragment=a[9];this.toString=function(){var b="";this.scheme&&(b+= this.scheme+":");this.authority&&(b+="//"+this.authority);b+=this.path;this.query&&(b+="?"+this.query);this.fragment&&(b+="#"+this.fragment);return b};this.getQuery=function(){var b,c={};if(this.query){var d=decodeURIComponent(this.query).split("&");d.forEach(function(e,f,g){b=e.split("=");c[b[0]]=b[1]},this)}return c};this.setQuery=function(b){var c="",d;for(d in b)b.hasOwnProperty(d)&&(""!==c&&(c+="&"),c+=encodeURIComponent(d)+"="+encodeURIComponent(b[d]));this.query=c}}function da(){}function ai(a, b){this._curve=a;this._left=-Infinity;this._right=Infinity;this._m1=this._m0=this._p1=this._p0=this._recip=0;this._reset(b||0)}function gb(a){this.keys=[];this.type=1;this.tension=.5;this._eval=new ai(this);if(a)for(var b=0;ba;a++)this.planes[a]= []}function bd(a,b){this.origin=a||new z(0,0,0);this.direction=b||new z(0,0,-1)}function bi(a,b){this.halfExtents=b||new z(.5,.5,.5);a=a||vk.setIdentity();this._modelTransform=a.clone().invert();this._worldTransform=a.clone();this._aabb=new oa(new z,this.halfExtents)}function ci(a,b){this.normal=b||new z(0,0,1);this.point=a||new z(0,0,0)}function ab(a,b,c,d,e){this.usage=d||0;this.format=b;this.numVertices=c;this.id=un++;this.numBytes=b.verticesByteSize?b.verticesByteSize:b.size*c;a._vram.vb+=this.numBytes; this.device=a;e?this.setData(e):this.storage=new ArrayBuffer(this.numBytes);this.device.buffers.push(this)}function qe(a){for(var b=0,c=0,d=a.length;cb.indexOf(a[c]))return!1;for(c=0;ca.indexOf(b[c]))return!1;return!0}function gi(a){a=a.node.worldTransform;a.getX(wg);a.getY(yk);a.getZ(zk);wg.cross(wg,yk);return 0<=wg.dot(zk)?1:-1}function pa(){this._aspectRatio=16/9;this._aspectRatioMode=0;this._calculateTransform= this._calculateProjection=null;this._clearColor=new L(.75,.75,.75,1);this._clearColorBuffer=!0;this._clearDepth=1;this._clearDepthBuffer=!0;this._clearStencil=0;this._clearStencilBuffer=!0;this._cullingMask=4294967295;this._cullFaces=!0;this._farClip=1E3;this._flipFaces=!1;this._fov=45;this._horizontalFov=this._frustumCulling=!1;this._layers=[0,1,2,4,3];this._nearClip=.1;this._node=null;this._orthoHeight=10;this._projection=0;this._rect=new X(0,0,1,1);this._renderTarget=null;this._scissorRect=new X(0, 0,1,1);this._vrDisplay=null;this._projMat=new K;this._projMatDirty=!0;this._projMatSkybox=new K;this._viewMat=new K;this._viewMatDirty=!0;this._viewProjMat=new K;this._viewProjMatDirty=!0;this.frustum=new rg}function Z(a){M.call(this);this.name="string"===typeof a?a:"Untitled";this.tags=new ad(this);this._labels={};this.localPosition=new z(0,0,0);this.localRotation=new Y(0,0,0,1);this.localScale=new z(1,1,1);this.localEulerAngles=new z(0,0,0);this.position=new z(0,0,0);this.rotation=new Y(0,0,0,1); this.eulerAngles=new z(0,0,0);this._scale=null;this.localTransform=new K;this._dirtyLocal=!1;this._aabbVer=0;this._frozen=!1;this.worldTransform=new K;this._dirtyWorld=!1;this.normalMatrix=new xb;this._dirtyNormal=!0;this._parent=this._forward=this._up=this._right=null;this._children=[];this._graphDepth=0;this._enabled=!0;this.scaleCompensation=this._enabledInHierarchy=!1}function On(a,b){return a.priority-b.priority}function Pn(a,b){return b.key-a.key}function Ak(){this.list=[];this.length=0;this.done= !1}function Bk(){this.opaqueMeshInstances=[];this.transparentMeshInstances=[];this.shadowCasters=[];this.visibleOpaque=[];this.visibleTransparent=[]}function ma(a){a=a||{};void 0!==a.id?(this.id=a.id,hi=Math.max(this.id+1,hi)):this.id=hi++;this.name=a.name;this._refCounter=(this._enabled=void 0===a.enabled?!0:a.enabled)?1:0;this.opaqueSortMode=void 0===a.opaqueSortMode?2:a.opaqueSortMode;this.transparentSortMode=void 0===a.transparentSortMode?3:a.transparentSortMode;this.renderTarget=a.renderTarget; this.shaderPass=void 0===a.shaderPass?0:a.shaderPass;this.passThrough=void 0===a.passThrough?!1:a.passThrough;this.overrideClear=void 0===a.overrideClear?!1:a.overrideClear;this._clearColor=new L(0,0,0,1);a.clearColor&&this._clearColor.copy(a.clearColor);this._clearColorBuffer=void 0===a.clearColorBuffer?!1:a.clearColorBuffer;this._clearDepthBuffer=void 0===a.clearDepthBuffer?!1:a.clearDepthBuffer;this._clearStencilBuffer=void 0===a.clearStencilBuffer?!1:a.clearStencilBuffer;this._clearOptions={color:[this._clearColor.r, this._clearColor.g,this._clearColor.b,this._clearColor.a],depth:1,stencil:0,flags:(this._clearColorBuffer?1:0)|(this._clearDepthBuffer?2:0)|(this._clearStencilBuffer?4:0)};this.onPreCull=a.onPreCull;this.onPreRender=a.onPreRender;this.onPreRenderOpaque=a.onPreRenderOpaque;this.onPreRenderTransparent=a.onPreRenderTransparent;this.onPostCull=a.onPostCull;this.onPostRender=a.onPostRender;this.onPostRenderOpaque=a.onPostRenderOpaque;this.onPostRenderTransparent=a.onPostRenderTransparent;this.onDrawCall= a.onDrawCall;this.onEnable=a.onEnable;this.onDisable=a.onDisable;if(this._enabled&&this.onEnable)this.onEnable();this.instances=(this.layerReference=a.layerReference)?a.layerReference.instances:new Bk;this.cullingMask=a.cullingMask?a.cullingMask:4294967295;this.opaqueMeshInstances=this.instances.opaqueMeshInstances;this.transparentMeshInstances=this.instances.transparentMeshInstances;this.shadowCasters=this.instances.shadowCasters;this.customCalculateSortValues=this.customSortCallback=null;this._lightComponents= [];this._lights=[];this._sortedLights=[[],[],[]];this.cameras=[];this._dirtyCameras=this._dirtyLights=this._dirty=!1;this._staticLightHash=this._lightHash=this._cameraHash=0;this._needsStaticPrepare=!0;this._staticPrepareDone=!1;this._shaderVersion=-1;this._version=0;this._lightCube=null}function Qn(a,b){if(0!==b||a.webgl2){if(3===b)return a.extTextureFloatLinear?1:0;if(2===b)return a.extTextureHalfFloatLinear?1:0}else return 0;return 1}function Ck(a,b,c,d){var e=3===d?14:2===d?12:4===d||0===d&&a.webgl2? 16:7,f=Qn(a,d);b=new V(a,{format:e,width:b,height:c,mipmaps:!1,minFilter:f,magFilter:f,addressU:1,addressV:1});b.name="shadowmap";return 4===d||0===d&&a.webgl2?(b.compareOnRead=!0,b.compareFunc=1,new ra({depthBuffer:b})):new ra({colorBuffer:b,depth:!0})}function Dk(a,b){a=new V(a,{format:7,width:b,height:b,cubemap:!0,mipmaps:!1,minFilter:0,magFilter:0,addressU:1,addressV:1});a.name="shadowcube";b=[];for(var c,d=0;6>d;d++)c=new ra({colorBuffer:a,face:d,depth:!0}),b.push(c);return b}function Ek(a,b, c,d){d||(d=0);d=1E4*d+b;var e=Fk[c][d];e||(e=Ck(a,b,b,c?c:0),Fk[c][d]=e);return e}function Gk(a,b){if(1===b._type){0c.dot(S)?-1:1;return v}function Qb(a,b,c){var d=c&&void 0!==c.normals?c.normals:null,e=c&&void 0!==c.tangents?c.tangents:null,f=c&&void 0!== c.colors?c.colors:null,g=c&&void 0!==c.uvs?c.uvs:null,k=c&&void 0!==c.uvs1?c.uvs1:null,h=c&&void 0!==c.indices?c.indices:null,l=c&&void 0!==c.blendIndices?c.blendIndices:null,n=c&&void 0!==c.blendWeights?c.blendWeights:null;c=[{semantic:"POSITION",components:3,type:6}];null!==d&&c.push({semantic:"NORMAL",components:3,type:6});null!==e&&c.push({semantic:"TANGENT",components:4,type:6});null!==f&&c.push({semantic:"COLOR",components:4,type:1,normalize:!0});null!==g&&c.push({semantic:"TEXCOORD0",components:2, type:6});null!==k&&c.push({semantic:"TEXCOORD1",components:2,type:6});null!==l&&c.push({semantic:"BLENDINDICES",components:2,type:1});null!==n&&c.push({semantic:"BLENDWEIGHT",components:2,type:6});var p=new Na(a,c);c=b.length/3;p=new ab(a,p,c);for(var q=new Pb(p),r=0;r=k)throw Error("Invalid PAX header data format.");var q=parseInt(d.decode(new Uint8Array(f, g+l,p-l)),10);p=d.decode(new Uint8Array(f,g+p+1,q-(p-l)-2)).split("=");if(2!==p.length)throw Error("Invalid PAX header data format.");0===p[1].length&&(p[1]=null);n.push({name:p[0],value:p[1]});l+=q}return new b(n)};b.prototype.applyHeader=function(f){for(var g=0;ga.version&&(2>a.version&&(a.info.maps=a.info.maps||[{width:a.info.width,height:a.info.height}]),a.chars=Object.keys(a.chars||{}).reduce(function(b,c){var d=a.chars[c];c=void 0!==d.letter?d.letter:vc.fromCodePoint(c);2>a.version&&(d.map=d.map||0);b[c]=d;return b},{}),a.version=3);return a}function Gi(a){this._loader=a;this.retryRequests=!1}function Fb(a,b){M.call(this);this._assets=[];this._registry= b;this._loaded=!1;this._total=this._count=0;this._failed=[];this._waitingAssets=[];if(a.length&&a[0]instanceof aa)this._assets=a;else for(var c=0;c c){var n=g.splice(d,1)[0],p=[];for(e=0;e=A?zb.APPLY_SHRINKING:zb.NONE;case 3:return y=A?zb.APPLY_SHRINKING:zb.NONE;default:throw Error("Unrecognized fitting mode: "+w);}}function d(w,y){return l(w,y.size)+(w.length-1)*u.spacing[y.axis]}function e(w,y,A){var B=p(w,A.maxSize),E=n(w,A.fittingProportion),C=t(E,B);y=Hb[A.axis]-y;for(var D=0;DMath.abs(A)&&1E-5>Math.abs(w)?y:y*A/w}function k(w){for(var y= [],A=0;AHb[x.axis]&&0!==y[y.length-1].length&&(B=D,y.push([])); y[y.length-1].push(w[C]);E&&B>Hb[x.axis]&&C!==w.length-1&&(B=0,y.push([]))}w=y}else w=[w];y=0===u.orientation&&u.reverseX||1===u.orientation&&u.reverseY;A=0===u.orientation&&u.reverseY||1===u.orientation&&u.reverseX;if(y)for(B=0;BE.largestSize[v.size]&&(E.largestElement=E[A],E.largestSize=G)}D.push(E.largestElement);C.push(E.largestSize)}A=d(C,v);B=c(u[v.fitting],A,Hb[v.axis]);B===zb.APPLY_STRETCHING?e(C,A,v):B===zb.APPLY_SHRINKING&&f(C,A,v);for(B=0;Bq)))for(q=(r=l[u])?p.instances.visibleTransparent[q]:p.instances.visibleOpaque[q],r=q.length,q=q.list, p=0;pc;c++){var h=a._levels[0][c],l=new V(e,{cubemap:!1,type:"default",format:a.format,width:d,height:d,mipmaps:!1});l.name="prefiltered-cube";l._levels[0]=h;l.upload();h=new V(e,{cubemap:!1,type:"default",format:a.format,width:d,height:d,mipmaps:!1});h.name="prefiltered-cube";h=new ra(e,h,{depth:!1});k.setValue(l);La(e,h,g);var n=new Uint8Array(d*d*4);f.bindFramebuffer(f.FRAMEBUFFER,h._glFrameBuffer);f.readPixels(0,0,l.width,l.height,f.RGBA,f.UNSIGNED_BYTE,n);a._levels[0][c]= n}}else{console.error("ERROR: SH: cubemap must be composed of arrays or images");return}g=[];for(f=0;fc;c++)for(f=0;fu;u++){var B=a._levels[0][c][4*l+u]/255;"rgbm"===a.type?(B*=8*r,B*=B):B=Math.pow(B,2.2);k[0+u]+=B*p;k[3+u]+=B*q*w;k[6+u]+=B*q*y;k[9+u]+=B*q*A;k[12+u]+=B*x*w*A;k[15+u]+=B*x*A*y;k[18+u]+= B*x*y*w;k[21+u]+=B*v*(3*A*A-1);k[24+u]+=B*t*(w*w-y*y);h+=n}}for(u=0;ub.deltaY&&(this.wheelDelta=-1));Lb.isPointerLocked()?(this.dx=b.movementX||b.webkitMovementX|| b.mozMovementX||0,this.dy=b.movementY||b.webkitMovementY||b.mozMovementY||0):(this.dx=this.x-a._lastX,this.dy=this.y-a._lastY);this.button="mousedown"===b.type||"mouseup"===b.type?b.button:-1;this.buttons=a._buttons.slice(0);this.element=b.target;this.ctrlKey=b.ctrlKey||!1;this.altKey=b.altKey||!1;this.shiftKey=b.shiftKey||!1;this.metaKey=b.metaKey||!1;this.event=b}function Lb(a){M.call(this);this._lastY=this._lastX=0;this._buttons=[!1,!1,!1];this._lastbuttons=[!1,!1,!1];this._upHandler=this._handleUp.bind(this); this._downHandler=this._handleDown.bind(this);this._moveHandler=this._handleMove.bind(this);this._wheelHandler=this._handleWheel.bind(this);this._contextMenuHandler=function(b){b.preventDefault()};this._target=null;this._attached=!1;this.attach(a)}function kb(a,b){b=b||{};this._keyboard=b.keyboard||null;this._mouse=b.mouse||null;this._gamepads=b.gamepads||null;this._element=null;this._actions={};this._axes={};this._axesValues={};a&&this.attach(a)}function Jo(a,b,c){Re.sub2(b,a);eh.sub2(c[0],a);zj.sub2(c[1], a);Kl.sub2(c[2],a);fh.cross(Kl,Re);if(0<=eh.dot(fh)){if(0>-zj.dot(fh))return!1;a=eh;if(0>Ll.cross(Re,zj).dot(a))return!1}else{Aj.sub2(c[3],a);if(0>Aj.dot(fh))return!1;a=Aj;if(0>Ll.cross(Re,eh).dot(a))return!1}return 1E-8>Re.sub2(c[0],c[2]).lengthSq()||1E-8>Re.sub2(c[1],c[3]).lengthSq()?!1:!0}function rd(a,b,c){this.event=a;this.element=b;this.camera=c;this._stopPropagation=!1}function sd(a,b,c,d,e,f,g){rd.call(this,a,b,c);this.x=d;this.y=e;this.ctrlKey=a.ctrlKey||!1;this.altKey=a.altKey||!1;this.shiftKey= a.shiftKey||!1;this.metaKey=a.metaKey||!1;this.button=a.button;Lb.isPointerLocked()?(this.dx=a.movementX||a.webkitMovementX||a.mozMovementX||0,this.dy=a.movementY||a.webkitMovementY||a.mozMovementY||0):(this.dx=d-f,this.dy=e-g);this.wheelDelta=0;"wheel"===a.type&&(0a.deltaY&&(this.wheelDelta=-1))}function Oc(a,b,c,d,e,f){rd.call(this,a,b,c);this.touches=a.touches;this.changedTouches=a.changedTouches;this.x=d;this.y=e;this.touch=f}function lc(a,b,c,d){rd.call(this,a,b, c);this.inputSource=d}function Lf(a,b){this._app=null;this._attached=!1;this._target=null;this._enabled=!0;this._lastY=this._lastX=0;this._upHandler=this._handleUp.bind(this);this._downHandler=this._handleDown.bind(this);this._moveHandler=this._handleMove.bind(this);this._wheelHandler=this._handleWheel.bind(this);this._touchstartHandler=this._handleTouchStart.bind(this);this._touchcancelHandler=this._touchendHandler=this._handleTouchEnd.bind(this);this._touchmoveHandler=this._handleTouchMove.bind(this); this._sortHandler=this._sortElements.bind(this);this._elements=[];this._pressedElement=this._hoveredElement=null;this._touchedElements={};this._touchesForWhichTouchLeaveHasFired={};this._selectedElements={};this._selectedPressedElements={};this._useMouse=!b||!1!==b.useMouse;this._useTouch=!b||!1!==b.useTouch;this._useXr=!b||!1!==b.useXr;this._selectEventsAttached=!1;Ca.touch&&(this._clickedEntities={});this.attach(a)}function Bj(){this.gamepadsSupported=!!navigator.getGamepads||!!navigator.webkitGetGamepads; this.current=[];this.previous=[];this.deadZone=.25}function gh(a){var b=Cj(a);this.id=a.identifier;this.x=b.x;this.y=b.y;this.target=a.target;this.touch=a}function ae(a,b){this.element=b.target;this.event=b;this.touches=[];this.changedTouches=[];if(b){var c=b.touches.length;for(a=0;athis._postEffectCombined)c.setup&&c.setup(d,c,Ab,null,this.renderTarget);else{var f=this._postEffectCombinedSrc?this._postEffectCombinedSrc:c.srcRenderTarget? c.srcRenderTarget:Ka[this._backbufferRtId];1e;e++)Ka[e]=new ra({depth:!0,stencil:d.supportsStencil,samples:b,autoResolve:!1}),Ka[e].name="backbuffer"+ e;a.on("prerender",function(){var f=a.scene.layers.layerList,g,k=0,h=0;Ej=Fj=Nf=!1;var l=7;if(a.scene.layers._dirty){var n=0;for(g=0;g=k;p--)f[p].renderTarget||(f[p].renderTarget=Ka[h]);f[g]._backbufferRtId=h;k=g;Nf=!0;1===h&&(Fj=!0);f[g].postEffect.hdr&&(l=d.webgl2&&d.textureFloatRenderable?18:d.extTextureHalfFloatLinear&&d.textureHalfFloatRenderable?12:7);f[g].postEffect.shader&&!f[g].renderTarget&&(h=1-h)}else f[g].isPostEffect||f[g].renderTarget||!Nf||(f[g].renderTarget=Ka[h]);f[g].isPostEffect&&!f[g].renderTarget&&(Ej=!0)}if(Nf)if(!Ka[0].colorBuffer)hh(0,d,l);else if(Ka[0].width!== d.width||Ka[0].height!==d.height||Ka[0]._colorBuffer._format!==l)Ka[0].colorBuffer.destroy(),Ka[0].destroy(),hh(0,d,l);if(Fj)if(!Ka[1].colorBuffer)hh(1,d,l);else if(Ka[1].width!==d.width||Ka[1].height!==d.height||Ka[1]._colorBuffer._format!==l)Ka[1].colorBuffer.destroy(),Ka[1].destroy(),hh(1,d,l)},this);a.on("postrender",function(){var f=a.graphicsDevice;if(Nf&&!Ej){for(var g=a.scene.layers.layerList,k,h=g.length-1;0<=h&&(k=g[h].renderTarget,k!==Ka[0]&&k!==Ka[1]);h--);k&&(1>>0;if("function"!==typeof a)throw TypeError("predicate must be a function");for(var e=0;ea)||+a});"function"!=typeof Object.assign&&Object.defineProperty(Object,"assign",{value:function(a,b){if(null==a)throw new TypeError("Cannot convert undefined or null to object");for(var c=Object(a),d=1;dthis.length)b=this.length;return this.substring(b-a.length,b)===a});String.prototype.includes||(String.prototype.includes=function(a,b){"number"!==typeof b&&(b=0);return b+a.length>this.length?!1:-1!==this.indexOf(a,b)});String.prototype.startsWith||(String.prototype.startsWith=function(a,b){return this.substr(!b||0>b?0:+b,a.length)===a});(function(){function a(e){var f=e.getError;e.getError=function(){do{var g=f.apply(e);g!=e.NO_ERROR&&(b[g]=!0)}while(g!=e.NO_ERROR);for(g in b)if(b[g])return delete b[g], parseInt(g);return e.NO_ERROR}}var b={},c=function g(f){var k=f.gl;this.ext=f;this.isAlive=!0;this.hasBeenBound=!1;this.elementArrayBuffer=null;this.attribs=Array(f.maxVertexAttribs);for(f=0;f>10)+55296,c%1024+56320]:[b],a.push(String.fromCharCode.apply(null, b));return a.join("")}},N={DEG_TO_RAD:Math.PI/180,RAD_TO_DEG:180/Math.PI,clamp:function(a,b,c){return a>=c?c:a<=b?b:a},intToBytes24:function(a){return[a>>16&255,a>>8&255,a&255]},intToBytes32:function(a){return[a>>24&255,a>>16&255,a>>8&255,a&255]},bytesToInt24:function(a,b,c){a.length&&(c=a[2],b=a[1],a=a[0]);return a<<16|b<<8|c},bytesToInt32:function(a,b,c,d){a.length&&(d=a[3],c=a[2],b=a[1],a=a[0]);return(a<<24|b<<16|c<<8|d)>>>32},lerp:function(a,b,c){return a+(b-a)*N.clamp(c,0,1)},lerpAngle:function(a, b,c){180b-a&&(b+=360);return N.lerp(a,b,N.clamp(c,0,1))},powerOfTwo:function(a){return 0!==a&&!(a&a-1)},nextPowerOfTwo:function(a){a--;a|=a>>1;a|=a>>2;a|=a>>4;a|=a>>8;a|=a>>16;a++;return a},random:function(a,b){return Math.random()*(b-a)+a},smoothstep:function(a,b,c){if(c<=a)return 0;if(c>=b)return 1;c=(c-a)/(b-a);return c*c*(3-2*c)},smootherstep:function(a,b,c){if(c<=a)return 0;if(c>=b)return 1;c=(c-a)/(b-a);return c*c*c*(c*(6*c-15)+10)},roundUp:function(a,b){return 0===b?a:Math.ceil(a/ b)*b},float2Half:function(){var a=new Float32Array(1),b=new Int32Array(a.buffer);return function(c){a[0]=c;c=b[0];var d=c>>16&32768,e=c>>12&2047,f=c>>23&255;return 103>f?d:142f?(e|=2048,d|(e>>114-f)+(e>>113-f&1)):d=(d|f-112<<10|e>>1)+(e&1)}}()};Object.assign(L.prototype,{clone:function(){return new L(this.r,this.g,this.b,this.a)},copy:function(a){this.r=a.r;this.g=a.g;this.b=a.b;this.a=a.a;return this},equals:function(a){return this.r===a.r&&this.g===a.g&& this.b===a.b&&this.a===a.a},set:function(a,b,c,d){this.r=a;this.g=b;this.b=c;this.a=void 0===d?1:d;return this},lerp:function(a,b,c){this.r=a.r+c*(b.r-a.r);this.g=a.g+c*(b.g-a.g);this.b=a.b+c*(b.b-a.b);this.a=a.a+c*(b.a-a.a);return this},fromString:function(a){var b=parseInt(a.replace("#","0x"),16);7b&&(this._index[a]=c-1)}return!0}return!1},list:function(){return this._list},clear:function(){this._list.length=0;for(var a in this._index)delete this._index[a]}});Object.assign(uk.prototype,{addItem:function(a){for(var b=a.tags._list,c=0;c=this._right)&&this._reset(a);b=this._curve.type;5===b?a=this._p0:(a=0===this._recip?0:(a-this._left)*this._recip,a=0===b?N.lerp(this._p0,this._p1,a):1===b?N.lerp(this._p0,this._p1,a*a*(3-2*a)):this._evaluateHermite(this._p0,this._p1,this._m0,this._m1, a));return a},_reset:function(a){var b=this._curve.keys,c=b.length;if(c)if(a=b[c-1][0])this._left=b[c-1][0],this._right=Infinity,this._recip=0,this._p0=this._p1=b[c-1][1],this._m0=this._m1=0;else{for(c=0;a>=b[c+1][0];)c++;this._left=b[c][0];this._right=b[c+1][0];a=1/(this._right-this._left);this._recip=isFinite(a)?a:0;this._p0=b[c][1];this._p1=b[c+1][1];this._isHermite()&&this._calcTangents(b, c)}else this._left=-Infinity,this._right=Infinity,this._p0=this._p1=this._m0=this._m1=this._recip=0},_isHermite:function(){return 2===this._curve.type||3===this._curve.type||4===this._curve.type},_calcTangents:function(a,b){var c=a[b],d=a[b+1];var e=0===b?[a[0][0]+(a[0][0]-a[1][0]),a[0][1]+(a[0][1]-a[1][1])]:a[b-1];a=b==a.length-2?[a[b+1][0]+(a[b+1][0]-a[b][0]),a[b+1][1]+(a[b+1][1]-a[b][1])]:a[b+2];if(4===this._curve.type){b=2*(d[0]-c[0])/(d[0]-e[0]);var f=2*(d[0]-c[0])/(a[0]-c[0]);this._m0=this._curve.tension* (isFinite(b)?b:0)*(d[1]-e[1]);this._m1=this._curve.tension*(isFinite(f)?f:0)*(a[1]-c[1])}else f=(d[0]-c[0])/(c[0]-e[0]),b=(d[0]-c[0])/(a[0]-d[0]),e=c[1]+(e[1]-c[1])*(isFinite(f)?f:0),a=d[1]+(a[1]-d[1])*(isFinite(b)?b:0),b=2===this._curve.type?.5:this._curve.tension,this._m0=b*(d[1]-e),this._m1=b*(a-c[1])},_evaluateHermite:function(a,b,c,d,e){var f=e*e,g=e+e,k=1-e;k*=k;return a*(1+g)*k+c*e*k+b*f*(3-g)+d*f*(e-1)}});Object.assign(gb.prototype,{add:function(a,b){for(var c=this.keys,d=c.length,e=0;ea);e++);a=[a,b];this.keys.splice(e,0,a);return a},get:function(a){return this.keys[a]},sort:function(){this.keys.sort(function(a,b){return a[0]-b[0]})},value:function(a){return this._eval.evaluate(a,!0)},closest:function(a){for(var b=this.keys,c=b.length,d=2,e=null,f=0;f=g)d=g,e=b[f];else break}return e},clone:function(){var a=new gb;a.keys=Gc(a.keys,this.keys);a.type=this.type;a.tension=this.tension;return a},quantize:function(a){a=Math.max(a,2);var b= new Float32Array(a),c=1/(a-1);b[0]=this._eval.evaluate(0,!0);for(var d=1;db;b++)a+=this.data[b],a+=8!==b?", ":"";return a+"]"},transpose:function(){var a=this.data;var b=a[1];a[1]=a[3];a[3]=b;b=a[2];a[2]=a[6];a[6]=b;b=a[5];a[5]=a[7];a[7]=b;return this}});Object.defineProperties(xb,{ZERO:{value:(new xb).set([0,0,0,0,0,0,0,0,0])},IDENTITY:{value:new xb}});Object.freeze(xb.ZERO);Object.freeze(xb.IDENTITY);Object.assign(P.prototype,{add:function(a){this.x+=a.x;this.y+=a.y;return this},add2:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;return this},clone:function(){return(new P).copy(this)}, copy:function(a){this.x=a.x;this.y=a.y;return this},distance:function(a){var b=this.x-a.x;a=this.y-a.y;return Math.sqrt(b*b+a*a)},dot:function(a){return this.x*a.x+this.y*a.y},equals:function(a){return this.x===a.x&&this.y===a.y},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y)},lengthSq:function(){return this.x*this.x+this.y*this.y},lerp:function(a,b,c){this.x=a.x+c*(b.x-a.x);this.y=a.y+c*(b.y-a.y);return this},mul:function(a){this.x*=a.x;this.y*=a.y;return this},mul2:function(a,b){this.x= a.x*b.x;this.y=a.y*b.y;return this},normalize:function(){var a=this.x*this.x+this.y*this.y;0-k?(d=Math.atan2(f[6]/d,f[10]/e),c=Math.atan2(f[1]/c,f[0]/c)):(c=0,d=-Math.atan2(f[4]/d,f[5]/d)):(c=0,d=Math.atan2(f[4]/d,f[5]/d));return b.set(d, g,c).scale(N.RAD_TO_DEG)}}(),toString:function(){var a;var b="[";for(a=0;16>a;a+=1)b+=this.data[a],b+=15!==a?", ":"";return b+"]"}});Object.defineProperties(K,{ZERO:{value:(new K).set([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])},IDENTITY:{value:new K}});Object.freeze(K.ZERO);Object.freeze(K.IDENTITY);Object.assign(Y.prototype,{clone:function(){return new Y(this.x,this.y,this.z,this.w)},conjugate:function(){this.x*=-1;this.y*=-1;this.z*=-1;return this},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;this.w= a.w;return this},equals:function(a){return this.x===a.x&&this.y===a.y&&this.z===a.z&&this.w===a.w},getAxisAngle:function(a){var b=2*Math.acos(this.w),c=Math.sin(b/2);if(0!==c){if(a.x=this.x/c,a.y=this.y/c,a.z=this.z/c,0>a.x||0>a.y||0>a.z)a.x*=-1,a.y*=-1,a.z*=-1,b*=-1}else a.x=1,a.y=0,a.z=0;return b*N.RAD_TO_DEG},getEulerAngles:function(a){a=void 0===a?new z:a;var b=this.x;var c=this.y;var d=this.z;var e=this.w;var f=2*(e*c-b*d);if(-.99999>=f){var g=2*Math.atan2(b,e);f=-Math.PI/2;b=0}else.99999<=f? (g=2*Math.atan2(b,e),f=Math.PI/2,b=0):(g=Math.atan2(2*(e*b+c*d),1-2*(b*b+c*c)),f=Math.asin(f),b=Math.atan2(2*(e*d+b*c),1-2*(c*c+d*d)));return a.set(g,f,b).scale(N.RAD_TO_DEG)},invert:function(){return this.conjugate().normalize()},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},lengthSq:function(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w},mul:function(a){var b=this.x;var c=this.y;var d=this.z;var e=this.w;var f=a.x;var g=a.y;var k= a.z;a=a.w;this.x=e*f+b*a+c*k-d*g;this.y=e*g+c*a+d*f-b*k;this.z=e*k+d*a+b*g-c*f;this.w=e*a-b*f-c*g-d*k;return this},mul2:function(a,b){var c=a.x;var d=a.y;var e=a.z;a=a.w;var f=b.x;var g=b.y;var k=b.z;b=b.w;this.x=a*f+c*b+d*k-e*g;this.y=a*g+d*b+e*f-c*k;this.z=a*k+e*b+c*g-d*f;this.w=a*b-c*f-d*g-e*k;return this},normalize:function(){var a=this.length();0===a?(this.x=this.y=this.z=0,this.w=1):(a=1/a,this.x*=a,this.y*=a,this.z*=a,this.w*=a);return this},set:function(a,b,c,d){this.x=a;this.y=b;this.z=c; this.w=d;return this},setFromAxisAngle:function(a,b){b*=.5*N.DEG_TO_RAD;var c=Math.sin(b);b=Math.cos(b);this.x=c*a.x;this.y=c*a.y;this.z=c*a.z;this.w=b;return this},setFromEulerAngles:function(a,b,c){var d=.5*N.DEG_TO_RAD;a*=d;b*=d;c*=d;d=Math.sin(a);a=Math.cos(a);var e=Math.sin(b);b=Math.cos(b);var f=Math.sin(c);c=Math.cos(c);this.x=d*b*c-a*e*f;this.y=a*e*c+d*b*f;this.z=a*b*f-d*e*c;this.w=a*b*c+d*e*f;return this},setFromMat4:function(a){a=a.data;var b=a[0];var c=a[1];var d=a[2];var e=a[4];var f= a[5];var g=a[6];var k=a[8];var h=a[9];a=a[10];var l=b*b+c*c+d*d;if(0===l)return this;l=1/Math.sqrt(l);var n=e*e+f*f+g*g;if(0===n)return this;n=1/Math.sqrt(n);var p=k*k+h*h+a*a;if(0===p)return this;p=1/Math.sqrt(p);b*=l;c*=l;d*=l;e*=n;f*=n;g*=n;k*=p;h*=p;a*=p;l=b+f+a;0<=l?(b=Math.sqrt(l+1),this.w=.5*b,b=.5/b,this.x=(g-h)*b,this.y=(k-d)*b,this.z=(c-e)*b):b>f?b>a?(b=Math.sqrt(b-(f+a)+1),this.x=.5*b,b=.5/b,this.w=(g-h)*b,this.y=(c+e)*b,this.z=(d+k)*b):(b=Math.sqrt(a-(b+f)+1),this.z=.5*b,b=.5/b,this.w= (c-e)*b,this.x=(k+d)*b,this.y=(h+g)*b):f>a?(b=Math.sqrt(f-(a+b)+1),this.y=.5*b,b=.5/b,this.w=(k-d)*b,this.z=(g+h)*b,this.x=(e+c)*b):(b=Math.sqrt(a-(b+f)+1),this.z=.5*b,b=.5/b,this.w=(c-e)*b,this.x=(k+d)*b,this.y=(h+g)*b);return this},slerp:function(a,b,c){var d=a.x;var e=a.y;var f=a.z;a=a.w;var g=b.x;var k=b.y;var h=b.z;b=b.w;var l=a*b+d*g+e*k+f*h;0>l&&(b=-b,g=-g,k=-k,h=-h,l=-l);if(1<=Math.abs(l))return this.w=a,this.x=d,this.y=e,this.z=f,this;var n=Math.acos(l),p=Math.sqrt(1-l*l);if(.001>Math.abs(p))return this.w= .5*a+.5*b,this.x=.5*d+.5*g,this.y=.5*e+.5*k,this.z=.5*f+.5*h,this;l=Math.sin((1-c)*n)/p;c=Math.sin(c*n)/p;this.w=a*l+b*c;this.x=d*l+g*c;this.y=e*l+k*c;this.z=f*l+h*c;return this},transformVector:function(a,b){void 0===b&&(b=new z);var c=a.x,d=a.y,e=a.z;a=this.x;var f=this.y,g=this.z,k=this.w,h=k*c+f*e-g*d,l=k*d+g*c-a*e,n=k*e+a*d-f*c;c=-a*c-f*d-g*e;b.x=h*k+c*-a+l*-g-n*-f;b.y=l*k+c*-f+n*-a-h*-g;b.z=n*k+c*-g+h*-f-l*-a;return b},toString:function(){return"["+this.x+", "+this.y+", "+this.z+", "+this.w+ "]"}});Object.defineProperties(Y,{ZERO:{value:new Y(0,0,0,0)},IDENTITY:{value:new Y(0,0,0,1)}});Object.freeze(Y.ZERO);Object.freeze(Y.IDENTITY);var yc=new z,Wb=new z,Rf=new z,Sf=new z,be=new z;Object.assign(oa.prototype,{add:function(a){var b=this.center,c=b.x,d=b.y,e=b.z,f=this.halfExtents,g=f.x,k=f.y,h=f.z,l=c-g;c+=g;g=d-k;d+=k;k=e-h;e+=h;h=a.center;var n=h.x,p=h.y;h=h.z;a=a.halfExtents;var q=a.x,r=a.y,t=a.z;a=n-q;n+=q;q=p-r;p+=r;r=h-t;h+=t;ac&&(c=n);qd&&(d=p);re&&(e=h);b.x=.5*(l+c);b.y=.5*(g+d);b.z=.5*(k+e);f.x=.5*(c-l);f.y=.5*(d-g);f.z=.5*(e-k)},copy:function(a){this.center.copy(a.center);this.halfExtents.copy(a.halfExtents);this.type=a.type},clone:function(){return new oa(this.center.clone(),this.halfExtents.clone())},intersects:function(a){var b=this.getMax(),c=this.getMin(),d=a.getMax();a=a.getMin();return c.x<=d.x&&b.x>=a.x&&c.y<=d.y&&b.y>=a.y&&c.z<=d.z&&b.z>=a.z},_intersectsRay:function(a,b){var c=yc.copy(this.getMin()).sub(a.origin),d=Wb.copy(this.getMax()).sub(a.origin), e=a.direction;0===e.x?(c.x=0>c.x?-Number.MAX_VALUE:Number.MAX_VALUE,d.x=0>d.x?-Number.MAX_VALUE:Number.MAX_VALUE):(c.x/=e.x,d.x/=e.x);0===e.y?(c.y=0>c.y?-Number.MAX_VALUE:Number.MAX_VALUE,d.y=0>d.y?-Number.MAX_VALUE:Number.MAX_VALUE):(c.y/=e.y,d.y/=e.y);0===e.z?(c.z=0>c.z?-Number.MAX_VALUE:Number.MAX_VALUE,d.z=0>d.z?-Number.MAX_VALUE:Number.MAX_VALUE):(c.z/=e.z,d.z/=e.z);e=Rf.set(Math.min(c.x,d.x),Math.min(c.y,d.y),Math.min(c.z,d.z));c=Sf.set(Math.max(c.x,d.x),Math.max(c.y,d.y),Math.max(c.z,d.z)); d=Math.max(Math.max(e.x,e.y),e.z);(c=Math.min(Math.min(c.x,c.y),c.z)>=d&&0<=d)&&b.copy(a.direction).scale(d).add(a.origin);return c},_fastIntersectsRay:function(a){var b=a.direction;yc.sub2(a.origin,this.center);Sf.set(Math.abs(yc.x),Math.abs(yc.y),Math.abs(yc.z));Rf.mul2(yc,b);if(Sf.x>this.halfExtents.x&&0<=Rf.x||Sf.y>this.halfExtents.y&&0<=Rf.y||Sf.z>this.halfExtents.z&&0<=Rf.z)return!1;be.set(Math.abs(b.x),Math.abs(b.y),Math.abs(b.z));Wb.cross(b,yc);Wb.set(Math.abs(Wb.x),Math.abs(Wb.y),Math.abs(Wb.z)); return Wb.x>this.halfExtents.y*be.z+this.halfExtents.z*be.y||Wb.y>this.halfExtents.x*be.z+this.halfExtents.z*be.x||Wb.z>this.halfExtents.x*be.y+this.halfExtents.y*be.x?!1:!0},intersectsRay:function(a,b){return b?this._intersectsRay(a,b):this._fastIntersectsRay(a)},setMinMax:function(a,b){this.center.add2(b,a).scale(.5);this.halfExtents.sub2(b,a).scale(.5)},getMin:function(){return this._min.copy(this.center).sub(this.halfExtents)},getMax:function(){return this._max.copy(this.center).add(this.halfExtents)}, containsPoint:function(a){var b=this.getMin(),c=this.getMax();return a.xc.x||a.yc.y||a.zc.z?!1:!0},setFromTransformedAabb:function(a,b){var c=a.center;a=a.halfExtents;b=b.data;var d=b[0],e=b[4],f=b[8],g=b[1],k=b[5],h=b[9],l=b[2],n=b[6],p=b[10];this.center.set(b[12]+d*c.x+e*c.y+f*c.z,b[13]+g*c.x+k*c.y+h*c.z,b[14]+l*c.x+n*c.y+p*c.z);this.halfExtents.set(Math.abs(d)*a.x+Math.abs(e)*a.y+Math.abs(f)*a.z,Math.abs(g)*a.x+Math.abs(k)*a.y+Math.abs(h)*a.z,Math.abs(l)*a.x+Math.abs(n)* a.y+Math.abs(p)*a.z)},compute:function(a,b){b=void 0===b?a.length/3:b;if(0d.x&&(d.x=f);g>d.y&&(d.y=g);k>d.z&&(d.z=k)}this.setMinMax(c,d)}},intersectsBoundingSphere:function(a){return this._distanceToBoundingSphereSq(a)<=a.radius*a.radius?!0:!1},_distanceToBoundingSphereSq:function(a){for(var b=this.getMin(),c=this.getMax(),d=0,e=["x","y","z"], f=0;3>f;++f){var g=0,k=a.center[e[f]],h=b[e[f]],l=c[e[f]];kl&&(h=k-l,g+=h*h);d+=g}return d},_expand:function(a,b){yc.add2(this.getMin(),a);Wb.add2(this.getMax(),b);this.setMinMax(yc,Wb)}});var td=new z,ih=new z,Te=new z,Sl=new z;Object.assign(Cd.prototype,{containsPoint:function(a){a=td.sub2(a,this.center).lengthSq();var b=this.radius;return ac)return!1;d=Math.abs(-d-Math.sqrt(c));b&&b.copy(a.direction).scale(d).add(a.origin);return!0},intersectsBoundingSphere:function(a){td.sub2(a.center, this.center);a=a.radius+this.radius;return td.lengthSq()<=a*a?!0:!1}});Object.assign(rg.prototype,{setFromMat4:function(a){a=a.data;var b=this.planes;var c=b[0];c[0]=a[3]-a[0];c[1]=a[7]-a[4];c[2]=a[11]-a[8];c[3]=a[15]-a[12];var d=Math.sqrt(c[0]*c[0]+c[1]*c[1]+c[2]*c[2]);c[0]/=d;c[1]/=d;c[2]/=d;c[3]/=d;c=b[1];c[0]=a[3]+a[0];c[1]=a[7]+a[4];c[2]=a[11]+a[8];c[3]=a[15]+a[12];d=Math.sqrt(c[0]*c[0]+c[1]*c[1]+c[2]*c[2]);c[0]/=d;c[1]/=d;c[2]/=d;c[3]/=d;c=b[2];c[0]=a[3]+a[1];c[1]=a[7]+a[5];c[2]=a[11]+a[9]; c[3]=a[15]+a[13];d=Math.sqrt(c[0]*c[0]+c[1]*c[1]+c[2]*c[2]);c[0]/=d;c[1]/=d;c[2]/=d;c[3]/=d;c=b[3];c[0]=a[3]-a[1];c[1]=a[7]-a[5];c[2]=a[11]-a[9];c[3]=a[15]-a[13];d=Math.sqrt(c[0]*c[0]+c[1]*c[1]+c[2]*c[2]);c[0]/=d;c[1]/=d;c[2]/=d;c[3]/=d;c=b[4];c[0]=a[3]-a[2];c[1]=a[7]-a[6];c[2]=a[11]-a[10];c[3]=a[15]-a[14];d=Math.sqrt(c[0]*c[0]+c[1]*c[1]+c[2]*c[2]);c[0]/=d;c[1]/=d;c[2]/=d;c[3]/=d;c=b[5];c[0]=a[3]+a[2];c[1]=a[7]+a[6];c[2]=a[11]+a[10];c[3]=a[15]+a[14];d=Math.sqrt(c[0]*c[0]+c[1]*c[1]+c[2]*c[2]);c[0]/= d;c[1]/=d;c[2]/=d;c[3]/=d},containsPoint:function(a){var b;for(b=0;6>b;b++){var c=this.planes[b];if(0>=c[0]*a.x+c[1]*a.y+c[2]*a.z+c[3])return!1}return!0},containsSphere:function(a){var b=0,c=a.radius;var d=a.center;a=d.x;var e=d.y,f=d.z,g=this.planes;for(d=0;6>d;d++){var k=g[d];k=k[0]*a+k[1]*e+k[2]*f+k[3];if(k<=-c)return 0;k>c&&b++}return 6===b?2:1}});bd.prototype.set=function(a,b){this.origin.copy(a);this.direction.copy(b);return this};var jh=new bd,Tl=new z,Ij=new Cd,vk=new K;Object.assign(bi.prototype, {intersectsRay:function(a,b){this._modelTransform.transformPoint(a.origin,jh.origin);this._modelTransform.transformVector(a.direction,jh.direction);return b?(a=this._aabb._intersectsRay(jh,b),vk.copy(this._modelTransform).invert().transformPoint(b,b),a):this._aabb._fastIntersectsRay(jh)},containsPoint:function(a){this._modelTransform.transformPoint(a,Tl);return this._aabb.containsPoint(Tl)},intersectsBoundingSphere:function(a){this._modelTransform.transformPoint(a.center,Ij.center);Ij.radius=a.radius; return this._aabb.intersectsBoundingSphere(Ij)?!0:!1}});Object.defineProperty(bi.prototype,"worldTransform",{get:function(){return this._worldTransform},set:function(a){this._worldTransform.copy(a);this._modelTransform.copy(a).invert()}});var $o=new z;Object.assign(ci.prototype,{intersectsLine:function(a,b,c){var d=-this.normal.dot(this.point),e=this.normal.dot(a)+d;d=this.normal.dot(b)+d;e/=e-d;(d=0<=e&&1>=e)&&c&&c.lerp(a,b,e);return d},intersectsRay:function(a,b){var c=$o.sub2(this.point,a.origin); c=this.normal.dot(c)/this.normal.dot(a.direction);var d=0<=c;d&&b&&b.copy(a.direction).scale(c).add(a.origin);return d}});var Dd=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array],qf=[1,1,2,2,4,4,4],Ul=[Uint8Array,Uint16Array,Uint32Array],Jj={POSITION:0,NORMAL:1,BLENDWEIGHT:2,BLENDINDICES:3,COLOR:4,TEXCOORD0:5,TEXCOORD1:6,TEXCOORD2:7,TEXCOORD3:8,TEXCOORD4:9,TEXCOORD5:10,TEXCOORD6:11,TEXCOORD7:12,TANGENT:13,ATTR0:0,ATTR1:1,ATTR2:2,ATTR3:3,ATTR4:4,ATTR5:5,ATTR6:6,ATTR7:7, ATTR8:8,ATTR9:9,ATTR10:10,ATTR11:11,ATTR12:12,ATTR13:13,ATTR14:14,ATTR15:15},un=0;Object.assign(ab.prototype,{destroy:function(){var a=this.device,b=a.buffers.indexOf(this);-1!==b&&a.buffers.splice(b,1);this.bufferId&&(b=a.gl,a.boundVao=null,b.bindVertexArray(null),b.deleteBuffer(this.bufferId),a._vram.vb-=this.storage.byteLength,this.bufferId=null)},getFormat:function(){return this.format},getUsage:function(){return this.usage},getNumVertices:function(){return this.numVertices},lock:function(){return this.storage}, unlock:function(){var a=this.device.gl;this.bufferId||(this.bufferId=a.createBuffer());switch(this.usage){case 0:var b=a.STATIC_DRAW;break;case 1:b=a.DYNAMIC_DRAW;break;case 2:b=a.STREAM_DRAW;break;case 3:b=this.device.webgl2?a.DYNAMIC_COPY:a.STATIC_DRAW}a.bindBuffer(a.ARRAY_BUFFER,this.bufferId);a.bufferData(a.ARRAY_BUFFER,this.storage,b)},setData:function(a){if(a.byteLength!==this.numBytes)return console.error("VertexBuffer: wrong initial data size: expected "+this.numBytes+", got "+a.byteLength), !1;this.storage=a;this.unlock();return!0}});Na.init=function(a){this._defaultInstancingFormat=new Na(a,[{semantic:"TEXCOORD2",components:4,type:6},{semantic:"TEXCOORD3",components:4,type:6},{semantic:"TEXCOORD4",components:4,type:6},{semantic:"TEXCOORD5",components:4,type:6}])};Object.defineProperty(Na,"defaultInstancingFormat",{get:function(){return function(){return this._defaultInstancingFormat}}()});Object.assign(Na.prototype,{update:function(){this._evaluateHash()},_evaluateHash:function(){var a= [],b=[],c,d=this.elements.length;for(c=0;cthis.vertexBuffer.numVertices&&(c=this.vertexBuffer.numVertices);var d,e=a.numComponents;if(this.vertexBuffer.getFormat().interleaved){var f=0;for(d=0;dc*e)if(c*=e,ArrayBuffer.isView(b))b=b.subarray(0,c),a.array.set(b);else for(d=0;d 0.5) {\n\t\tif (dAtten > 0.00001) {\n\t\t\tdirLm.xyz = dirLm.xyz * 2.0 - vec3(1.0);\n\t\t\tdAtten = saturate(dAtten);\n\t\t\tgl_FragColor.rgb = normalize(dLightDirNormW.xyz*dAtten + dirLm.xyz*dirLm.w) * 0.5 + vec3(0.5);\n\t\t\tgl_FragColor.a = dirLm.w + dAtten;\n\t\t\tgl_FragColor.a = max(gl_FragColor.a, 1.0 / 255.0);\n\t\t} else {\n\t\t\tgl_FragColor = dirLm;\n\t\t}\n\t} else {\n\t\tgl_FragColor.rgb = dirLm.xyz;\n\t\tgl_FragColor.a = max(dirLm.w, dAtten > 0.00001? (1.0/255.0) : 0.0);\n\t}\n", bakeLmEndPS:"\tgl_FragColor.rgb = dDiffuseLight;\n\tgl_FragColor.rgb = pow(gl_FragColor.rgb, vec3(0.5));\n\tgl_FragColor.rgb /= 8.0;\n\tgl_FragColor.a = clamp( max( max( gl_FragColor.r, gl_FragColor.g ), max( gl_FragColor.b, 1.0 / 255.0 ) ), 0.0,1.0 );\n\tgl_FragColor.a = ceil(gl_FragColor.a * 255.0) / 255.0;\n\tgl_FragColor.rgb /= gl_FragColor.a;\n",basePS:"uniform vec3 view_position;\nuniform vec3 light_globalAmbient;\nfloat square(float x) {\n\treturn x*x;\n}\nfloat saturate(float x) {\n\treturn clamp(x, 0.0, 1.0);\n}\nvec3 saturate(vec3 x) {\n\treturn clamp(x, vec3(0.0), vec3(1.0));\n}\n", baseVS:"attribute vec3 vertex_position;\nattribute vec3 vertex_normal;\nattribute vec4 vertex_tangent;\nattribute vec2 vertex_texCoord0;\nattribute vec2 vertex_texCoord1;\nattribute vec4 vertex_color;\nuniform mat4 matrix_viewProjection;\nuniform mat4 matrix_model;\nuniform mat3 matrix_normal;\nvec3 dPositionW;\nmat4 dModelMatrix;\nmat3 dNormalMatrix;\nvec3 dLightPosW;\nvec3 dLightDirNormW;\nvec3 dNormalW;\n",baseNineSlicedPS:"#define NINESLICED\nvarying vec2 vMask;\nvarying vec2 vTiledUv;\nuniform mediump vec4 innerOffset;\nuniform mediump vec2 outerScale;\nuniform mediump vec4 atlasRect;\nvec2 nineSlicedUv;\n", baseNineSlicedVS:"#define NINESLICED\nvarying vec2 vMask;\nvarying vec2 vTiledUv;\nuniform mediump vec4 innerOffset;\nuniform mediump vec2 outerScale;\nuniform mediump vec4 atlasRect;\n",baseNineSlicedTiledPS:"#define NINESLICED\n#define NINESLICETILED\nvarying vec2 vMask;\nvarying vec2 vTiledUv;\nuniform mediump vec4 innerOffset;\nuniform mediump vec2 outerScale;\nuniform mediump vec4 atlasRect;\nvec2 nineSlicedUv;\n",biasConstPS:"#define SHADOWBIAS\nfloat getShadowBias(float resolution, float maxBias) {\n\treturn maxBias;\n}\n", blurVSMPS:"varying vec2 vUv0;\nuniform sampler2D source;\nuniform vec2 pixelOffset;\n#ifdef GAUSS\nuniform float weight[SAMPLES];\n#endif\n#ifdef PACKED\nfloat decodeFloatRG(vec2 rg) {\n\treturn rg.y*(1.0/255.0) + rg.x;\n}\nvec2 encodeFloatRG( float v ) {\n\tvec2 enc = vec2(1.0, 255.0) * v;\n\tenc = fract(enc);\n\tenc -= enc.yy * vec2(1.0/255.0, 1.0/255.0);\n\treturn enc;\n}\n#endif\nvoid main(void) {\n\tvec3 moments = vec3(0.0);\n\tvec2 uv = vUv0 - pixelOffset * (float(SAMPLES) * 0.5);\n\tfor (int i=0; i 1.0 || projPos.y < 0.0 || projPos.y > 1.0 || projPos.z < 0.0) return vec4(0.0);\n\treturn mix(vec4(1.0), texture2D(tex, projPos.xy), intensity);\n}\nvec4 getCookie2DXform(sampler2D tex, mat4 transform, float intensity, vec4 cookieMatrix, vec2 cookieOffset) {\n\tvec4 projPos = transform * vec4(vPositionW, 1.0);\n\tprojPos.xy /= projPos.w;\n\tprojPos.xy += cookieOffset;\n\tvec2 uv = mat2(cookieMatrix) * (projPos.xy-vec2(0.5)) + vec2(0.5);\n\treturn mix(vec4(1.0), texture2D(tex, uv), intensity);\n}\nvec4 getCookie2DClipXform(sampler2D tex, mat4 transform, float intensity, vec4 cookieMatrix, vec2 cookieOffset) {\n\tvec4 projPos = transform * vec4(vPositionW, 1.0);\n\tprojPos.xy /= projPos.w;\n\tprojPos.xy += cookieOffset;\n\tif (projPos.x < 0.0 || projPos.x > 1.0 || projPos.y < 0.0 || projPos.y > 1.0 || projPos.z < 0.0) return vec4(0.0);\n\tvec2 uv = mat2(cookieMatrix) * (projPos.xy-vec2(0.5)) + vec2(0.5);\n\treturn mix(vec4(1.0), texture2D(tex, uv), intensity);\n}\nvec4 getCookieCube(samplerCube tex, mat4 transform, float intensity) {\n\treturn mix(vec4(1.0), textureCube(tex, dLightDirNormW * mat3(transform)), intensity);\n}\n", cubeMapProjectBoxPS:"uniform vec3 envBoxMin, envBoxMax;\nvec3 cubeMapProject(vec3 nrdir) {\n\tvec3 rbmax = (envBoxMax - vPositionW) / nrdir;\n\tvec3 rbmin = (envBoxMin - vPositionW) / nrdir;\n\tvec3 rbminmax;\n\trbminmax.x = nrdir.x>0.0? rbmax.x : rbmin.x;\n\trbminmax.y = nrdir.y>0.0? rbmax.y : rbmin.y;\n\trbminmax.z = nrdir.z>0.0? rbmax.z : rbmin.z;\n\tfloat fa = min(min(rbminmax.x, rbminmax.y), rbminmax.z);\n\tvec3 posonbox = vPositionW + nrdir * fa;\n\tvec3 envBoxPos = (envBoxMin + envBoxMax) * 0.5;\n\treturn posonbox - envBoxPos;\n}\n", cubeMapProjectNonePS:"vec3 cubeMapProject(vec3 dir) {\n\treturn dir;\n}\n",detailModesPS:"vec3 detailMode_mul(vec3 c1, vec3 c2) {\n\treturn c1 * c2;\n}\nvec3 detailMode_add(vec3 c1, vec3 c2) {\n\treturn c1 + c2;\n}\nvec3 detailMode_screen(vec3 c1, vec3 c2) {\n\treturn 1.0 - (1.0 - c1)*(1.0 - c2);\n}\nvec3 detailMode_overlay(vec3 c1, vec3 c2) {\n\treturn mix(1.0 - 2.0*(1.0 - c1)*(1.0 - c2), 2.0*c1*c2, step(c1, vec3(0.5)));\n}\nvec3 detailMode_min(vec3 c1, vec3 c2) {\n\treturn min(c1, c2);\n}\nvec3 detailMode_max(vec3 c1, vec3 c2) {\n\treturn max(c1, c2);\n}\n", diffusePS:"#ifdef MAPCOLOR\nuniform vec3 material_diffuse;\n#endif\n#ifdef MAPTEXTURE\nuniform sampler2D texture_diffuseMap;\n#endif\nvoid getAlbedo() {\n\tdAlbedo = vec3(1.0);\n\t#ifdef MAPCOLOR\n\tdAlbedo *= material_diffuse.rgb;\n\t#endif\n\t#ifdef MAPTEXTURE\n\tdAlbedo *= gammaCorrectInput(addAlbedoDetail(texture2D(texture_diffuseMap, $UV).$CH));\n\t#endif\n\t#ifdef MAPVERTEX\n\tdAlbedo *= gammaCorrectInput(saturate(vVertexColor.$VC));\n\t#endif\n}\n",diffuseDetailMapPS:"#ifdef MAPTEXTURE\nuniform sampler2D texture_diffuseDetailMap;\n#endif\nvec3 addAlbedoDetail(vec3 albedo) {\n\t#ifdef MAPTEXTURE\n\tvec3 albedoDetail = vec3(texture2D(texture_diffuseDetailMap, $UV).$CH);\n\treturn detailMode_$DETAILMODE(albedo, albedoDetail);\n\t#else\n\treturn albedo;\n\t#endif\n}\n", dilatePS:"varying vec2 vUv0;\nuniform sampler2D source;\nuniform vec2 pixelOffset;\nvoid main(void) {\n\tvec4 c = texture2D(source, vUv0);\n\tc = c.a>0.0? c : texture2D(source, vUv0 - pixelOffset);\n\tc = c.a>0.0? c : texture2D(source, vUv0 + vec2(0, -pixelOffset.y));\n\tc = c.a>0.0? c : texture2D(source, vUv0 + vec2(pixelOffset.x, -pixelOffset.y));\n\tc = c.a>0.0? c : texture2D(source, vUv0 + vec2(-pixelOffset.x, 0));\n\tc = c.a>0.0? c : texture2D(source, vUv0 + vec2(pixelOffset.x, 0));\n\tc = c.a>0.0? c : texture2D(source, vUv0 + vec2(-pixelOffset.x, pixelOffset.y));\n\tc = c.a>0.0? c : texture2D(source, vUv0 + vec2(0, pixelOffset.y));\n\tc = c.a>0.0? c : texture2D(source, vUv0 + pixelOffset);\n\tgl_FragColor = c;\n}\n", dpAtlasQuadPS:"varying vec2 vUv0;\nuniform sampler2D source;\nuniform vec4 params;\nvoid main(void) {\n\tvec2 uv = vUv0;\n\tuv = uv * 2.0 - vec2(1.0);\n\tuv *= params.xy;\n\tuv = uv * 0.5 + 0.5;\n\tgl_FragColor = texture2D(source, uv);\n}\n",emissivePS:"#ifdef MAPCOLOR\nuniform vec3 material_emissive;\n#endif\n#ifdef MAPFLOAT\nuniform float material_emissiveIntensity;\n#endif\n#ifdef MAPTEXTURE\nuniform sampler2D texture_emissiveMap;\n#endif\nvec3 getEmission() {\n\tvec3 emission = vec3(1.0);\n\t#ifdef MAPFLOAT\n\temission *= material_emissiveIntensity;\n\t#endif\n\t#ifdef MAPCOLOR\n\temission *= material_emissive;\n\t#endif\n\t#ifdef MAPTEXTURE\n\temission *= $texture2DSAMPLE(texture_emissiveMap, $UV).$CH;\n\t#endif\n\t#ifdef MAPVERTEX\n\temission *= gammaCorrectInput(saturate(vVertexColor.$VC));\n\t#endif\n\treturn emission;\n}\n", endPS:"\t#ifdef CLEARCOAT\n\tgl_FragColor.rgb = combineColorCC();\n\t#else\n\tgl_FragColor.rgb = combineColor();\n\t#endif\n\tgl_FragColor.rgb += getEmission();\n\tgl_FragColor.rgb = addFog(gl_FragColor.rgb);\n\t#ifndef HDR\n\tgl_FragColor.rgb = toneMap(gl_FragColor.rgb);\n\tgl_FragColor.rgb = gammaCorrectOutput(gl_FragColor.rgb);\n\t#endif\n",envConstPS:"vec3 processEnvironment(vec3 color) {\n\treturn color;\n}\n",envMultiplyPS:"uniform float skyboxIntensity;\nvec3 processEnvironment(vec3 color) {\n\treturn color * skyboxIntensity;\n}\n", extensionPS:"\n",extensionVS:"\n",falloffInvSquaredPS:"float getFalloffInvSquared(float lightRadius) {\n\tfloat sqrDist = dot(dLightDirW, dLightDirW);\n\tfloat falloff = 1.0 / (sqrDist + 1.0);\n\tfloat invRadius = 1.0 / lightRadius;\n\tfalloff *= 16.0;\n\tfalloff *= square( saturate( 1.0 - square( sqrDist * square(invRadius) ) ) );\n\treturn falloff;\n}\n",falloffLinearPS:"float getFalloffLinear(float lightRadius) {\n\tfloat d = length(dLightDirW);\n\treturn max(((lightRadius - d) / lightRadius), 0.0);\n}\n", fixCubemapSeamsNonePS:"vec3 fixSeams(vec3 vec, float mipmapIndex) {\n\treturn vec;\n}\nvec3 fixSeams(vec3 vec) {\n\treturn vec;\n}\nvec3 fixSeamsStatic(vec3 vec, float invRecMipSize) {\n\treturn vec;\n}\n",fixCubemapSeamsStretchPS:"vec3 fixSeams(vec3 vec, float mipmapIndex) {\n\tfloat scale = 1.0 - exp2(mipmapIndex) / 128.0;\n\tfloat M = max(max(abs(vec.x), abs(vec.y)), abs(vec.z));\n\tif (abs(vec.x) != M) vec.x *= scale;\n\tif (abs(vec.y) != M) vec.y *= scale;\n\tif (abs(vec.z) != M) vec.z *= scale;\n\treturn vec;\n}\nvec3 fixSeams(vec3 vec) {\n\tfloat scale = 1.0 - 1.0 / 128.0;\n\tfloat M = max(max(abs(vec.x), abs(vec.y)), abs(vec.z));\n\tif (abs(vec.x) != M) vec.x *= scale;\n\tif (abs(vec.y) != M) vec.y *= scale;\n\tif (abs(vec.z) != M) vec.z *= scale;\n\treturn vec;\n}\nvec3 fixSeamsStatic(vec3 vec, float invRecMipSize) {\n\tfloat scale = invRecMipSize;\n\tfloat M = max(max(abs(vec.x), abs(vec.y)), abs(vec.z));\n\tif (abs(vec.x) != M) vec.x *= scale;\n\tif (abs(vec.y) != M) vec.y *= scale;\n\tif (abs(vec.z) != M) vec.z *= scale;\n\treturn vec;\n}\n", fogExpPS:"uniform vec3 fog_color;\nuniform float fog_density;\nfloat dBlendModeFogFactor = 1.0;\nvec3 addFog(vec3 color) {\n\tfloat depth = gl_FragCoord.z / gl_FragCoord.w;\n\tfloat fogFactor = exp(-depth * fog_density);\n\tfogFactor = clamp(fogFactor, 0.0, 1.0);\n\treturn mix(fog_color * dBlendModeFogFactor, color, fogFactor);\n}\n",fogExp2PS:"uniform vec3 fog_color;\nuniform float fog_density;\nfloat dBlendModeFogFactor = 1.0;\nvec3 addFog(vec3 color) {\n\tfloat depth = gl_FragCoord.z / gl_FragCoord.w;\n\tfloat fogFactor = exp(-depth * depth * fog_density * fog_density);\n\tfogFactor = clamp(fogFactor, 0.0, 1.0);\n\treturn mix(fog_color * dBlendModeFogFactor, color, fogFactor);\n}\n", fogLinearPS:"uniform vec3 fog_color;\nuniform float fog_start;\nuniform float fog_end;\nfloat dBlendModeFogFactor = 1.0;\nvec3 addFog(vec3 color) {\n\tfloat depth = gl_FragCoord.z / gl_FragCoord.w;\n\tfloat fogFactor = (fog_end - depth) / (fog_end - fog_start);\n\tfogFactor = clamp(fogFactor, 0.0, 1.0);\n\tfogFactor = gammaCorrectInput(fogFactor);\n\treturn mix(fog_color * dBlendModeFogFactor, color, fogFactor);\n}\n",fogNonePS:"float dBlendModeFogFactor = 1.0;\nvec3 addFog(vec3 color) {\n\treturn color;\n}\n", fresnelSchlickPS:"\nuniform float material_fresnelFactor;\nvoid getFresnel() {\n\tfloat fresnel = 1.0 - max(dot(dNormalW, dViewDirW), 0.0);\n\tfloat fresnel2 = fresnel * fresnel;\n\tfresnel *= fresnel2 * fresnel2;\n\tfresnel *= dGlossiness * dGlossiness;\n\tdSpecularity = dSpecularity + (1.0 - dSpecularity) * fresnel;\n\t#ifdef CLEARCOAT\n\tfresnel = 1.0 - max(dot(ccNormalW, dViewDirW), 0.0);\n\tfresnel2 = fresnel * fresnel;\n\tfresnel *= fresnel2 * fresnel2;\n\tfresnel *= ccGlossiness * ccGlossiness;\n\tccSpecularity = ccSpecularity + (1.0 - ccSpecularity) * fresnel;\n\t#endif\n}\n", fullscreenQuadPS:"varying vec2 vUv0;\nuniform sampler2D source;\nvoid main(void) {\n\tgl_FragColor = texture2D(source, vUv0);\n}\n",fullscreenQuadVS:"attribute vec2 vertex_position;\nvarying vec2 vUv0;\nvoid main(void)\n{\n\tgl_Position = vec4(vertex_position, 0.5, 1.0);\n\tvUv0 = vertex_position.xy*0.5+0.5;\n}\n",gamma1_0PS:"vec4 texture2DSRGB(sampler2D tex, vec2 uv) {\n\treturn texture2D(tex, uv);\n}\nvec4 texture2DSRGB(sampler2D tex, vec2 uv, float bias) {\n\treturn texture2D(tex, uv, bias);\n}\nvec4 textureCubeSRGB(samplerCube tex, vec3 uvw) {\n\treturn textureCube(tex, uvw);\n}\nvec3 gammaCorrectOutput(vec3 color) {\n\treturn color;\n}\nvec3 gammaCorrectInput(vec3 color) {\n\treturn color;\n}\nfloat gammaCorrectInput(float color) {\n\treturn color;\n}\nvec4 gammaCorrectInput(vec4 color) {\n\treturn color;\n}\n", gamma2_2PS:"vec3 gammaCorrectInput(vec3 color) {\n\treturn pow(color, vec3(2.2));\n}\nfloat gammaCorrectInput(float color) {\n\treturn pow(color, 2.2);\n}\nvec4 gammaCorrectInput(vec4 color) {\n\treturn vec4(pow(color.rgb, vec3(2.2)), color.a);\n}\nvec4 texture2DSRGB(sampler2D tex, vec2 uv) {\n\tvec4 rgba = texture2D(tex, uv);\n\trgba.rgb = gammaCorrectInput(rgba.rgb);\n\treturn rgba;\n}\nvec4 texture2DSRGB(sampler2D tex, vec2 uv, float bias) {\n\tvec4 rgba = texture2D(tex, uv, bias);\n\trgba.rgb = gammaCorrectInput(rgba.rgb);\n\treturn rgba;\n}\nvec4 textureCubeSRGB(samplerCube tex, vec3 uvw) {\n\tvec4 rgba = textureCube(tex, uvw);\n\trgba.rgb = gammaCorrectInput(rgba.rgb);\n\treturn rgba;\n}\nvec3 gammaCorrectOutput(vec3 color) {\n\t#ifdef HDR\n\treturn color;\n\t#else\n\tcolor += vec3(0.0000001);\n\treturn pow(color, vec3(0.45));\n\t#endif\n}\n", genParaboloidPS:"varying vec2 vUv0;\nuniform samplerCube source;\nuniform vec4 params;\nvoid main(void) {\n\tvec2 uv = vUv0;\n\tfloat side = uv.x < 0.5? 1.0 : -1.0;\n\tvec2 tc;\n\ttc.x = fract(uv.x * 2.0) * 2.0 - 1.0;\n\ttc.y = uv.y * 2.0 - 1.0;\n\tconst float scale = 1.1;\n\ttc *= scale;\n\tvec3 dir;\n\tdir.y = (dot(tc, tc) - 1.0) * side;\n\tdir.xz = tc * -2.0;\n\tdir.x *= -side * params.y;\n\tdir = fixSeams(dir, params.x);\n\tvec4 color = textureCube(source, dir, -100.0);\n\tgl_FragColor = color;\n}\n", gles3PS:"#define varying in\nout highp vec4 pc_fragColor;\n#define gl_FragColor pc_fragColor\n#define texture2D texture\n#define textureCube texture\n#define texture2DProj textureProj\n#define texture2DLodEXT textureLod\n#define texture2DProjLodEXT textureProjLod\n#define textureCubeLodEXT textureLod\n#define texture2DGradEXT textureGrad\n#define texture2DProjGradEXT textureProjGrad\n#define textureCubeGradEXT textureGrad\n#define GL2\n",gles3VS:"#define attribute in\n#define varying out\n#define texture2D texture\n#define GL2\n#define VERTEXSHADER\n", glossPS:"#ifdef MAPFLOAT\nuniform float material_shininess;\n#endif\n#ifdef MAPTEXTURE\nuniform sampler2D texture_glossMap;\n#endif\nvoid getGlossiness() {\n\tdGlossiness = 1.0;\n\t#ifdef MAPFLOAT\n\tdGlossiness *= material_shininess;\n\t#endif\n\t#ifdef MAPTEXTURE\n\tdGlossiness *= texture2D(texture_glossMap, $UV).$CH;\n\t#endif\n\t#ifdef MAPVERTEX\n\tdGlossiness *= saturate(vVertexColor.$VC);\n\t#endif\n\tdGlossiness += 0.0000001;\n}\n",instancingVS:"attribute vec4 instance_line1;\nattribute vec4 instance_line2;\nattribute vec4 instance_line3;\nattribute vec4 instance_line4;\n", lightDiffuseLambertPS:"float getLightDiffuse() {\n\treturn max(dot(dNormalW, -dLightDirNormW), 0.0);\n}\n",lightDirPointPS:"void getLightDirPoint(vec3 lightPosW) {\n\tdLightDirW = vPositionW - lightPosW;\n\tdLightDirNormW = normalize(dLightDirW);\n\tdLightPosW = lightPosW;\n}\n",lightmapDirPS:"uniform sampler2D texture_lightMap;\nuniform sampler2D texture_dirLightMap;\nvoid addLightMap() {\n\tvec3 color = $texture2DSAMPLE(texture_lightMap, $UV).$CH;\n\tvec4 dir = texture2D(texture_dirLightMap, $UV);\n\tif (dot(dir.xyz,vec3(1.0)) < 0.00001) {\n\t\tdDiffuseLight += color;\n\t\treturn;\n\t}\n\tdLightDirNormW = normalize(dir.xyz * 2.0 - vec3(1.0));\n\tfloat vlight = saturate(dot(dLightDirNormW, -dVertexNormalW));\n\tfloat flight = saturate(dot(dLightDirNormW, -dNormalW));\n\tfloat nlight = (flight / max(vlight,0.01)) * 0.5;\n\tdDiffuseLight += color * nlight * 2.0;\n}\nvoid addDirLightMap() {\n\tvec4 dir = texture2D(texture_dirLightMap, $UV);\n\tif (dot(dir.xyz,vec3(1.0)) < 0.00001) return;\n\tvec3 color = $texture2DSAMPLE(texture_lightMap, $UV).$CH;\n\tdLightDirNormW = normalize(dir.xyz * 2.0 - vec3(1.0));\n\tdSpecularLight += vec3(getLightSpecular()) * color;\n}\n", lightmapSinglePS:"#ifdef MAPTEXTURE\nuniform sampler2D texture_lightMap;\n#endif\nvoid addLightMap() {\n\tvec3 lm = vec3(1.0);\n\t#ifdef MAPTEXTURE\n\tlm *= $texture2DSAMPLE(texture_lightMap, $UV).$CH;\n\t#endif\n\t#ifdef MAPVERTEX\n\tlm *= saturate(vVertexColor.$VC);\n\t#endif\n\tdDiffuseLight += lm;\n}\n",lightmapSingleVertPS:"void addLightMap() {\n\tdDiffuseLight += saturate(vVertexColor.$CH);\n}\n",lightSpecularAnisoGGXPS:"\nfloat calcLightSpecular(float tGlossiness, vec3 tNormalW) {\n\tfloat PI = 3.141592653589793;\n\tfloat roughness = max((1.0 - tGlossiness) * (1.0 - tGlossiness), 0.001);\n\tfloat anisotropy = material_anisotropy * roughness;\n\tfloat at = max((roughness + anisotropy), roughness / 4.0);\n\tfloat ab = max((roughness - anisotropy), roughness / 4.0);\n\tvec3 h = normalize(normalize(-dLightDirNormW) + normalize(dViewDirW));\n\tfloat NoH = dot(tNormalW, h);\n\tfloat ToH = dot(dTBN[0], h);\n\tfloat BoH = dot(dTBN[1], h);\n\tfloat a2 = at * ab;\n\tvec3 v = vec3(ab * ToH, at * BoH, a2 * NoH);\n\tfloat v2 = dot(v, v);\n\tfloat w2 = a2 / v2;\n\tfloat D = a2 * w2 * w2 * (1.0 / PI);\n\tfloat ToV = dot(dTBN[0], dViewDirW);\n\tfloat BoV = dot(dTBN[1], dViewDirW);\n\tfloat ToL = dot(dTBN[0], -dLightDirNormW);\n\tfloat BoL = dot(dTBN[1], -dLightDirNormW);\n\tfloat NoV = dot(tNormalW, dViewDirW);\n\tfloat NoL = dot(tNormalW, -dLightDirNormW);\n\tfloat lambdaV = NoL * length(vec3(at * ToV, ab * BoV, NoV));\n\tfloat lambdaL = NoV * length(vec3(at * ToL, ab * BoL, NoL));\n\tfloat G = 0.5 / (lambdaV + lambdaL);\n\treturn D * G;\n}\nfloat getLightSpecular() {\n\treturn calcLightSpecular(dGlossiness, dNormalW);\n}\nfloat getLightSpecularCC() {\n\treturn calcLightSpecular(ccGlossiness, ccNormalW);\n}\n", lightSpecularBlinnPS:"\nfloat calcLightSpecular(float tGlossiness, vec3 tNormalW) {\n\tvec3 h = normalize( -dLightDirNormW + dViewDirW );\n\tfloat nh = max( dot( h, tNormalW ), 0.0 );\n\tfloat specPow = exp2(tGlossiness * 11.0);\n\tspecPow = antiAliasGlossiness(specPow);\n\tspecPow = max(specPow, 0.0001);\n\treturn pow(nh, specPow) * (specPow + 2.0) / 8.0;\n}\nfloat getLightSpecular() {\n\treturn calcLightSpecular(dGlossiness, dNormalW);\n}\nfloat getLightSpecularCC() {\n\treturn calcLightSpecular(ccGlossiness, ccNormalW);\n}\n", lightSpecularPhongPS:"float calcLightSpecular(float tGlossiness, vec3 tReflDirW) {\n\tfloat specPow = tGlossiness;\n\tspecPow = antiAliasGlossiness(specPow);\n\treturn pow(max(dot(tReflDirW, -dLightDirNormW), 0.0), specPow + 0.0001);\n}\nfloat getLightSpecular() {\n\treturn calcLightSpecular(dGlossiness, dReflDirW);\n}\nfloat getLightSpecularCC() {\n\treturn calcLightSpecular(ccGlossiness, ccReflDirW);\n}\n",metalnessPS:"void processMetalness(float metalness) {\n\tconst float dielectricF0 = 0.04;\n\tdSpecularity = mix(vec3(dielectricF0), dAlbedo, metalness);\n\tdAlbedo *= 1.0 - metalness;\n}\n#ifdef MAPFLOAT\nuniform float material_metalness;\n#endif\n#ifdef MAPTEXTURE\nuniform sampler2D texture_metalnessMap;\n#endif\nvoid getSpecularity() {\n\tfloat metalness = 1.0;\n\t#ifdef MAPFLOAT\n\tmetalness *= material_metalness;\n\t#endif\n\t#ifdef MAPTEXTURE\n\tmetalness *= texture2D(texture_metalnessMap, $UV).$CH;\n\t#endif\n\t#ifdef MAPVERTEX\n\tmetalness *= saturate(vVertexColor.$VC);\n\t#endif\n\tprocessMetalness(metalness);\n}\n", msdfPS:"uniform sampler2D texture_msdfMap;\n#ifdef GL_OES_standard_derivatives\n#define USE_FWIDTH\n#endif\n#ifdef GL2\n#define USE_FWIDTH\n#endif\nfloat median(float r, float g, float b) {\n\treturn max(min(r, g), min(max(r, g), b));\n}\nfloat map (float min, float max, float v) {\n\treturn (v - min) / (max - min);\n}\nuniform float font_sdfIntensity;\nuniform float font_pxrange;\nuniform float font_textureWidth;\nuniform vec4 outline_color;\nuniform float outline_thickness;\nuniform vec4 shadow_color;\nuniform vec2 shadow_offset;\nvec4 applyMsdf(vec4 color) {\n\tvec3 tsample = texture2D(texture_msdfMap, vUv0).rgb;\n\tvec2 uvShdw = vUv0 - shadow_offset;\n\tvec3 ssample = texture2D(texture_msdfMap, uvShdw).rgb;\n\tfloat sigDist = median(tsample.r, tsample.g, tsample.b);\n\tfloat sigDistShdw = median(ssample.r, ssample.g, ssample.b);\n\t#ifdef USE_FWIDTH\n\tvec2 w = fwidth(vUv0);\n\tfloat smoothing = clamp(w.x * font_textureWidth / font_pxrange, 0.0, 0.5);\n\t#else\n\tfloat font_size = 16.0;\n\tfloat smoothing = clamp(font_pxrange / font_size, 0.0, 0.5);\n\t#endif\n\tfloat mapMin = 0.05;\n\tfloat mapMax = clamp(1.0 - font_sdfIntensity, mapMin, 1.0);\n\tfloat sigDistInner = map(mapMin, mapMax, sigDist);\n\tfloat sigDistOutline = map(mapMin, mapMax, sigDist + outline_thickness);\n\tsigDistShdw = map(mapMin, mapMax, sigDistShdw + outline_thickness);\n\tfloat center = 0.5;\n\tfloat inside = smoothstep(center-smoothing, center+smoothing, sigDistInner);\n\tfloat outline = smoothstep(center-smoothing, center+smoothing, sigDistOutline);\n\tfloat shadow = smoothstep(center-smoothing, center+smoothing, sigDistShdw);\n\tvec4 tcolor = (outline > inside) ? outline * vec4(outline_color.a * outline_color.rgb, outline_color.a) : vec4(0.0);\n\ttcolor = mix(tcolor, color, inside);\n\tvec4 scolor = (shadow > outline) ? shadow * vec4(shadow_color.a * shadow_color.rgb, shadow_color.a) : tcolor;\n\ttcolor = mix(scolor, tcolor, outline);\n\treturn tcolor;\n}\n", normalVS:"#ifdef MORPHING_TEXTURE_BASED_NORMAL\nuniform highp sampler2D morphNormalTex;\n#endif\nvec3 getNormal() {\n\t#ifdef SKIN\n\tdNormalMatrix = mat3(dModelMatrix[0].xyz, dModelMatrix[1].xyz, dModelMatrix[2].xyz);\n\t#elif defined(INSTANCING)\n\tdNormalMatrix = mat3(instance_line1.xyz, instance_line2.xyz, instance_line3.xyz);\n\t#else\n\tdNormalMatrix = matrix_normal;\n\t#endif\n\tvec3 tempNormal = vertex_normal;\n\t#ifdef MORPHING\n\t#ifdef MORPHING_NRM03\n\ttempNormal += morph_weights_a[0] * morph_nrm0;\n\ttempNormal += morph_weights_a[1] * morph_nrm1;\n\ttempNormal += morph_weights_a[2] * morph_nrm2;\n\ttempNormal += morph_weights_a[3] * morph_nrm3;\n\t#endif\n\t#ifdef MORPHING_NRM47\n\ttempNormal += morph_weights_b[0] * morph_nrm4;\n\ttempNormal += morph_weights_b[1] * morph_nrm5;\n\ttempNormal += morph_weights_b[2] * morph_nrm6;\n\ttempNormal += morph_weights_b[3] * morph_nrm7;\n\t#endif\n\t#endif\n\t#ifdef MORPHING_TEXTURE_BASED_NORMAL\n\tvec2 morphUV = getTextureMorphCoords();\n\tvec3 morphNormal = texture2D(morphNormalTex, morphUV).xyz;\n\ttempNormal += morphNormal;\n\t#endif\n\treturn normalize(dNormalMatrix * tempNormal);\n}\n", normalDetailMapPS:"#ifdef MAPTEXTURE\nuniform sampler2D texture_normalDetailMap;\nuniform float material_normalDetailMapBumpiness;\nvec3 blendNormals(vec3 n1, vec3 n2) {\n\tn1 += vec3(0, 0, 1);\n\tn2 *= vec3(-1, -1, 1);\n\treturn normalize(n1*dot(n1, n2)/n1.z - n2);\n}\n#endif\nvec3 addNormalDetail(vec3 normalMap) {\n\t#ifdef MAPTEXTURE\n\tvec3 normalDetailMap = unpackNormal(texture2D(texture_normalDetailMap, $UV));\n\tnormalDetailMap = normalize(mix(vec3(0.0, 0.0, 1.0), normalDetailMap, material_normalDetailMapBumpiness));\n\treturn blendNormals(normalMap, normalDetailMap);\n\t#else\n\treturn normalMap;\n\t#endif\n}\n", normalInstancedVS:"vec3 getNormal() {\n\tdNormalMatrix = mat3(instance_line1.xyz, instance_line2.xyz, instance_line3.xyz);\n\treturn normalize(dNormalMatrix * vertex_normal);\n}\n",normalMapPS:"uniform sampler2D texture_normalMap;\nuniform float material_bumpiness;\nvoid getNormal() {\n\tvec3 normalMap = unpackNormal(texture2D(texture_normalMap, $UV));\n\tnormalMap = normalize(mix(vec3(0.0, 0.0, 1.0), normalMap, material_bumpiness));\n\tdNormalMap = addNormalDetail(normalMap);\n\tdNormalW = dTBN * dNormalMap;\n}\n", normalMapFastPS:"uniform sampler2D texture_normalMap;\nvoid getNormal() {\n\tvec3 normalMap = unpackNormal(texture2D(texture_normalMap, $UV));\n\tdNormalMap = addNormalDetail(normalMap);\n\tdNormalW = dTBN * dNormalMap;\n}\n",normalSkinnedVS:"vec3 getNormal() {\n\tdNormalMatrix = mat3(dModelMatrix[0].xyz, dModelMatrix[1].xyz, dModelMatrix[2].xyz);\n\treturn normalize(dNormalMatrix * vertex_normal);\n}\n",normalVertexPS:"void getNormal() {\n\tdNormalW = normalize(dVertexNormalW);\n}\n",normalXYPS:"vec3 unpackNormal(vec4 nmap) {\n\tvec3 normal;\n\tnormal.xy = nmap.wy * 2.0 - 1.0;\n\tnormal.z = sqrt(1.0 - saturate(dot(normal.xy, normal.xy)));\n\treturn normal;\n}\n", normalXYZPS:"vec3 unpackNormal(vec4 nmap) {\n\treturn nmap.xyz * 2.0 - 1.0;\n}\n",opacityPS:"#ifdef MAPFLOAT\nuniform float material_opacity;\n#endif\n#ifdef MAPTEXTURE\nuniform sampler2D texture_opacityMap;\n#endif\nvoid getOpacity() {\n\tdAlpha = 1.0;\n\t#ifdef MAPFLOAT\n\tdAlpha *= material_opacity;\n\t#endif\n\t#ifdef MAPTEXTURE\n\tdAlpha *= texture2D(texture_opacityMap, $UV).$CH;\n\t#endif\n\t#ifdef MAPVERTEX\n\tdAlpha *= clamp(vVertexColor.$VC, 0.0, 1.0);\n\t#endif\n}\n",outputAlphaPS:"gl_FragColor.a = dAlpha;\n", outputAlphaOpaquePS:"gl_FragColor.a = 1.0;\n",outputAlphaPremulPS:"gl_FragColor.rgb *= dAlpha;\ngl_FragColor.a = dAlpha;\n",outputCubemapPS:"varying vec2 vUv0;\nuniform samplerCube source;\nuniform vec4 params;\nfloat saturate(float x) {\n\treturn clamp(x, 0.0, 1.0);\n}\nvec4 encodeRGBM(vec4 color) {\n\tcolor.rgb = pow(color.rgb, vec3(0.5));\n\tcolor.rgb *= 1.0 / 8.0;\n\tcolor.a = saturate( max( max( color.r, color.g ), max( color.b, 1.0 / 255.0 ) ) );\n\tcolor.a = ceil(color.a * 255.0) / 255.0;\n\tcolor.rgb /= color.a;\n\treturn color;\n}\nvoid main(void) {\n\tvec2 st = vUv0 * 2.0 - 1.0;\n\tfloat face = params.x;\n\tvec3 vec;\n\tif (face==0.0) {\n\t\tvec = vec3(1, -st.y, -st.x);\n\t} else if (face==1.0) {\n\t\tvec = vec3(-1, -st.y, st.x);\n\t} else if (face==2.0) {\n\t\tvec = vec3(st.x, 1, st.y);\n\t} else if (face==3.0) {\n\t\tvec = vec3(st.x, -1, -st.y);\n\t} else if (face==4.0) {\n\t\tvec = vec3(st.x, -st.y, 1);\n\t} else {\n\t\tvec = vec3(-st.x, -st.y, -1);\n\t}\n\tgl_FragColor = textureCube(source, vec);\n\tif (params.w >= 2.0) gl_FragColor = encodeRGBM(gl_FragColor);\n}\n", outputTex2DPS:"varying vec2 vUv0;\nuniform sampler2D source;\nvoid main(void) {\n\tgl_FragColor = texture2D(source, vUv0);\n}\n",packDepthPS:"\nvec4 packFloat(float depth) {\n\tconst vec4 bit_shift = vec4(256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0);\n\tconst vec4 bit_mask = vec4(0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0);\n\tvec4 res = mod(depth * bit_shift * vec4(255), vec4(256) ) / vec4(255);\n\tres -= res.xxyz * bit_mask;\n\treturn res;\n}\n",packDepthMaskPS:"vec4 packFloat(float depth) {\n\tconst vec4 bit_shift = vec4(256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0);\n\tconst vec4 bit_mask = vec4(0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0);\n\tvec4 res = mod(depth * bit_shift * vec4(255), vec4(256) ) / vec4(255);\n\tres.x = 0.0;\n\tres -= res.xxyz * bit_mask;\n\treturn res;\n}\n", parallaxPS:"uniform sampler2D texture_heightMap;\nuniform float material_heightMapFactor;\nvoid getParallax() {\n\tfloat parallaxScale = material_heightMapFactor;\n\tfloat height = texture2D(texture_heightMap, $UV).$CH;\n\theight = height * parallaxScale - parallaxScale*0.5;\n\tvec3 viewDirT = dViewDirW * dTBN;\n\tviewDirT.z += 0.42;\n\tdUvOffset = height * (viewDirT.xy / viewDirT.z);\n}\n",particlePS:"varying vec4 texCoordsAlphaLife;\nuniform sampler2D colorMap;\nuniform sampler2D colorParam;\nuniform float graphSampleSize;\nuniform float graphNumSamples;\n#ifndef CAMERAPLANES\n#define CAMERAPLANES\nuniform vec4 camera_params;\n#endif\nuniform float softening;\nuniform float colorMult;\nfloat saturate(float x) {\n\treturn clamp(x, 0.0, 1.0);\n}\n#ifndef UNPACKFLOAT\n#define UNPACKFLOAT\nfloat unpackFloat(vec4 rgbaDepth) {\n\tconst vec4 bitShift = vec4(1.0 / (256.0 * 256.0 * 256.0), 1.0 / (256.0 * 256.0), 1.0 / 256.0, 1.0);\n\tfloat depth = dot(rgbaDepth, bitShift);\n\treturn depth;\n}\n#endif\nvoid main(void) {\n\tvec4 tex = texture2DSRGB(colorMap, texCoordsAlphaLife.xy);\n\tvec4 ramp = texture2DSRGB(colorParam, vec2(texCoordsAlphaLife.w, 0.0));\n\tramp.rgb *= colorMult;\n\tramp.a += texCoordsAlphaLife.z;\n\tvec3 rgb = tex.rgb * ramp.rgb;\n\tfloat a = tex.a * ramp.a;\n", particleVS:"vec3 unpack3NFloats(float src) {\n\tfloat r = fract(src);\n\tfloat g = fract(src * 256.0);\n\tfloat b = fract(src * 65536.0);\n\treturn vec3(r, g, b);\n}\nfloat saturate(float x) {\n\treturn clamp(x, 0.0, 1.0);\n}\nvec4 tex1Dlod_lerp(highp sampler2D tex, vec2 tc) {\n\treturn mix( texture2D(tex,tc), texture2D(tex,tc + graphSampleSize), fract(tc.x*graphNumSamples) );\n}\nvec4 tex1Dlod_lerp(highp sampler2D tex, vec2 tc, out vec3 w) {\n\tvec4 a = texture2D(tex,tc);\n\tvec4 b = texture2D(tex,tc + graphSampleSize);\n\tfloat c = fract(tc.x*graphNumSamples);\n\tvec3 unpackedA = unpack3NFloats(a.w);\n\tvec3 unpackedB = unpack3NFloats(b.w);\n\tw = mix(unpackedA, unpackedB, c);\n\treturn mix(a, b, c);\n}\nvec2 rotate(vec2 quadXY, float pRotation, out mat2 rotMatrix) {\n\tfloat c = cos(pRotation);\n\tfloat s = sin(pRotation);\n\tmat2 m = mat2(c, -s, s, c);\n\trotMatrix = m;\n\treturn m * quadXY;\n}\nvec3 billboard(vec3 InstanceCoords, vec2 quadXY) {\n\t#ifdef SCREEN_SPACE\n\t\tvec3 pos = vec3(-1, 0, 0) * quadXY.x + vec3(0, -1, 0) * quadXY.y;\n\t#else\n\t\tvec3 pos = -matrix_viewInverse[0].xyz * quadXY.x + -matrix_viewInverse[1].xyz * quadXY.y;\n\t#endif\n\treturn pos;\n}\nvec3 customFace(vec3 InstanceCoords, vec2 quadXY) {\n\tvec3 pos = faceTangent * quadXY.x + faceBinorm * quadXY.y;\n\treturn pos;\n}\nvec2 safeNormalize(vec2 v) {\n\tfloat l = length(v);\n\treturn (l > 1e-06) ? v / l : v;\n}\nvoid main(void) {\n\tvec3 meshLocalPos = particle_vertexData.xyz;\n\tfloat id = floor(particle_vertexData.w);\n\tfloat rndFactor = fract(sin(id + 1.0 + seed));\n\tvec3 rndFactor3 = vec3(rndFactor, fract(rndFactor*10.0), fract(rndFactor*100.0));\n\tfloat uv = id / numParticlesPot;\n\treadInput(uv);\n#ifdef LOCAL_SPACE\n\tinVel = mat3(matrix_model) * inVel;\n#endif\n\tvec2 velocityV = safeNormalize((mat3(matrix_view) * inVel).xy);\n\tfloat particleLifetime = lifetime;\n\tif (inLife <= 0.0 || inLife > particleLifetime || !inShow) meshLocalPos = vec3(0.0);\n\tvec2 quadXY = meshLocalPos.xy;\n\tfloat nlife = clamp(inLife / particleLifetime, 0.0, 1.0);\n\tvec3 paramDiv;\n\tvec4 params = tex1Dlod_lerp(internalTex2, vec2(nlife, 0), paramDiv);\n\tfloat scale = params.y;\n\tfloat scaleDiv = paramDiv.x;\n\tfloat alphaDiv = paramDiv.z;\n\tscale += (scaleDiv * 2.0 - 1.0) * scaleDivMult * fract(rndFactor*10000.0);\n#ifndef USE_MESH\n\ttexCoordsAlphaLife = vec4(quadXY * -0.5 + 0.5, (alphaDiv * 2.0 - 1.0) * alphaDivMult * fract(rndFactor*1000.0), nlife);\n#else\n\ttexCoordsAlphaLife = vec4(particle_uv, (alphaDiv * 2.0 - 1.0) * alphaDivMult * fract(rndFactor*1000.0), nlife);\n#endif\n\tvec3 particlePos = inPos;\n\tvec3 particlePosMoved = vec3(0.0);\n\tmat2 rotMatrix;\n", particleAnimFrameClampVS:"\tfloat animFrame = min(floor(texCoordsAlphaLife.w * animTexParams.y) + animTexParams.x, animTexParams.z);\n",particleAnimFrameLoopVS:"\tfloat animFrame = floor(mod(texCoordsAlphaLife.w * animTexParams.y + animTexParams.x, animTexParams.z + 1.0));\n",particleAnimTexVS:"\tfloat animationIndex;\n\tif (animTexIndexParams.y == 1.0) {\n\t\tanimationIndex = floor((animTexParams.w + 1.0) * rndFactor3.z) * (animTexParams.z + 1.0);\n\t} else {\n\t\tanimationIndex = animTexIndexParams.x * (animTexParams.z + 1.0);\n\t}\n\tfloat atlasX = (animationIndex + animFrame) * animTexTilesParams.x;\n\tfloat atlasY = 1.0 - floor(atlasX + 1.0) * animTexTilesParams.y;\n\tatlasX = fract(atlasX);\n\ttexCoordsAlphaLife.xy *= animTexTilesParams.xy;\n\ttexCoordsAlphaLife.xy += vec2(atlasX, atlasY);\n", particleInputFloatPS:"void readInput(float uv) {\n\tvec4 tex = texture2D(particleTexIN, vec2(uv, 0.25));\n\tvec4 tex2 = texture2D(particleTexIN, vec2(uv, 0.75));\n\tinPos = tex.xyz;\n\tinVel = tex2.xyz;\n\tinAngle = (tex.w < 0.0? -tex.w : tex.w) - 1000.0;\n\tinShow = tex.w >= 0.0;\n\tinLife = tex2.w;\n}\n",particleInputRgba8PS:"\n#define PI2 6.283185307179586\nuniform vec3 inBoundsSize;\nuniform vec3 inBoundsCenter;\nuniform float maxVel;\nfloat decodeFloatRG(vec2 rg) {\n\treturn rg.y*(1.0/255.0) + rg.x;\n}\nfloat decodeFloatRGBA( vec4 rgba ) {\n return dot( rgba, vec4(1.0, 1.0/255.0, 1.0/65025.0, 1.0/160581375.0) );\n}\nvoid readInput(float uv) {\n\tvec4 tex0 = texture2D(particleTexIN, vec2(uv, 0.125));\n\tvec4 tex1 = texture2D(particleTexIN, vec2(uv, 0.375));\n\tvec4 tex2 = texture2D(particleTexIN, vec2(uv, 0.625));\n\tvec4 tex3 = texture2D(particleTexIN, vec2(uv, 0.875));\n\tinPos = vec3(decodeFloatRG(tex0.rg), decodeFloatRG(tex0.ba), decodeFloatRG(tex1.rg));\n\tinPos = (inPos - vec3(0.5)) * inBoundsSize + inBoundsCenter;\n\tinVel = tex2.xyz;\n\tinVel = (inVel - vec3(0.5)) * maxVel;\n\tinAngle = decodeFloatRG(tex1.ba) * PI2;\n\tinShow = tex2.a > 0.5;\n\tinLife = decodeFloatRGBA(tex3);\n\tfloat maxNegLife = max(lifetime, (numParticles - 1.0) * (rate+rateDiv));\n\tfloat maxPosLife = lifetime+1.0;\n\tinLife = inLife * (maxNegLife + maxPosLife) - maxNegLife;\n}\n", particleOutputFloatPS:"void writeOutput() {\n\tif (gl_FragCoord.y<1.0) {\n\t\tgl_FragColor = vec4(outPos, (outAngle + 1000.0) * visMode);\n\t} else {\n\t\tgl_FragColor = vec4(outVel, outLife);\n\t}\n}\n",particleOutputRgba8PS:"uniform vec3 outBoundsMul;\nuniform vec3 outBoundsAdd;\nvec2 encodeFloatRG( float v ) {\n\tvec2 enc = vec2(1.0, 255.0) * v;\n\tenc = fract(enc);\n\tenc -= enc.yy * vec2(1.0/255.0, 1.0/255.0);\n\treturn enc;\n}\nvec4 encodeFloatRGBA( float v ) {\n\tvec4 enc = vec4(1.0, 255.0, 65025.0, 160581375.0) * v;\n\tenc = fract(enc);\n\tenc -= enc.yzww * vec4(1.0/255.0,1.0/255.0,1.0/255.0,0.0);\n\treturn enc;\n}\nvoid writeOutput() {\n\toutPos = outPos * outBoundsMul + outBoundsAdd;\n\toutAngle = fract(outAngle / PI2);\n\toutVel = (outVel / maxVel) + vec3(0.5);\n\tfloat maxNegLife = max(lifetime, (numParticles - 1.0) * (rate+rateDiv));\n\tfloat maxPosLife = lifetime+1.0;\n\toutLife = (outLife + maxNegLife) / (maxNegLife + maxPosLife);\n\tif (gl_FragCoord.y < 1.0) {\n\t\tgl_FragColor = vec4(encodeFloatRG(outPos.x), encodeFloatRG(outPos.y));\n\t} else if (gl_FragCoord.y < 2.0) {\n\t\tgl_FragColor = vec4(encodeFloatRG(outPos.z), encodeFloatRG(outAngle));\n\t} else if (gl_FragCoord.y < 3.0) {\n\t\tgl_FragColor = vec4(outVel, visMode*0.5+0.5);\n\t} else {\n\t\tgl_FragColor = encodeFloatRGBA(outLife);\n\t}\n}\n", particleUpdaterAABBPS:"uniform mat3 spawnBounds;\nuniform vec3 spawnPosInnerRatio;\nvec3 calcSpawnPosition(vec3 inBounds, float rndFactor) {\n\tvec3 pos = inBounds - vec3(0.5);\n\tvec3 posAbs = abs(pos);\n\tvec3 maxPos = vec3(max(posAbs.x, max(posAbs.y, posAbs.z)));\n\tvec3 edge = maxPos + (vec3(0.5) - maxPos) * spawnPosInnerRatio;\n\tpos.x = edge.x * (maxPos.x == posAbs.x ? sign(pos.x) : 2.0 * pos.x);\n\tpos.y = edge.y * (maxPos.y == posAbs.y ? sign(pos.y) : 2.0 * pos.y);\n\tpos.z = edge.z * (maxPos.z == posAbs.z ? sign(pos.z) : 2.0 * pos.z);\n#ifndef LOCAL_SPACE\n\treturn emitterPos + spawnBounds * pos;\n#else\n\treturn spawnBounds * pos;\n#endif\n}\nvoid addInitialVelocity(inout vec3 localVelocity, vec3 inBounds) {\n\tlocalVelocity -= vec3(0, 0, initialVelocity);\n}\n", particleUpdaterEndPS:"\twriteOutput();\n}\n",particleUpdaterInitPS:"varying vec2 vUv0;\nuniform highp sampler2D particleTexIN;\nuniform highp sampler2D internalTex0;\nuniform highp sampler2D internalTex1;\nuniform highp sampler2D internalTex2;\nuniform highp sampler2D internalTex3;\nuniform mat3 emitterMatrix, emitterMatrixInv;\nuniform vec3 emitterScale;\nuniform vec3 emitterPos, frameRandom, localVelocityDivMult, velocityDivMult;\nuniform float delta, rate, rateDiv, lifetime, numParticles, rotSpeedDivMult, radialSpeedDivMult, seed;\nuniform float startAngle, startAngle2;\nuniform float initialVelocity;\nuniform float graphSampleSize;\nuniform float graphNumSamples;\nvec3 inPos;\nvec3 inVel;\nfloat inAngle;\nbool inShow;\nfloat inLife;\nfloat visMode;\nvec3 outPos;\nvec3 outVel;\nfloat outAngle;\nbool outShow;\nfloat outLife;\n", particleUpdaterNoRespawnPS:"\tif (outLife >= lifetime) {\n\t\toutLife -= max(lifetime, (numParticles - 1.0) * particleRate);\n\t\tvisMode = -1.0;\n\t}\n",particleUpdaterOnStopPS:"\tvisMode = outLife < 0.0? -1.0: visMode;\n",particleUpdaterRespawnPS:"\tif (outLife >= lifetime) {\n\t\toutLife -= max(lifetime, (numParticles - 1.0) * particleRate);\n\t\tvisMode = 1.0;\n\t}\n\tvisMode = outLife < 0.0? 1.0: visMode;\n",particleUpdaterSpherePS:"uniform float spawnBoundsSphere;\nuniform float spawnBoundsSphereInnerRatio;\nvec3 calcSpawnPosition(vec3 inBounds, float rndFactor) {\n\tfloat rnd4 = fract(rndFactor * 1000.0);\n\tvec3 norm = normalize(inBounds.xyz - vec3(0.5));\n\tfloat r = rnd4 * (1.0 - spawnBoundsSphereInnerRatio) + spawnBoundsSphereInnerRatio;\n#ifndef LOCAL_SPACE\n\treturn emitterPos + norm * r * spawnBoundsSphere;\n#else\n\treturn norm * r * spawnBoundsSphere;\n#endif\n}\nvoid addInitialVelocity(inout vec3 localVelocity, vec3 inBounds) {\n\tlocalVelocity += normalize(inBounds - vec3(0.5)) * initialVelocity;\n}\n", particleUpdaterStartPS:"float saturate(float x) {\n\treturn clamp(x, 0.0, 1.0);\n}\nvec3 unpack3NFloats(float src) {\n\tfloat r = fract(src);\n\tfloat g = fract(src * 256.0);\n\tfloat b = fract(src * 65536.0);\n\treturn vec3(r, g, b);\n}\nvec3 tex1Dlod_lerp(highp sampler2D tex, vec2 tc, out vec3 w) {\n\tvec4 a = texture2D(tex, tc);\n\tvec4 b = texture2D(tex, tc + graphSampleSize);\n\tfloat c = fract(tc.x * graphNumSamples);\n\tvec3 unpackedA = unpack3NFloats(a.w);\n\tvec3 unpackedB = unpack3NFloats(b.w);\n\tw = mix(unpackedA, unpackedB, c);\n\treturn mix(a.xyz, b.xyz, c);\n}\n#define HASHSCALE4 vec4(1031, .1030, .0973, .1099)\nvec4 hash41(float p) {\n\tvec4 p4 = fract(vec4(p) * HASHSCALE4);\n\tp4 += dot(p4, p4.wzxy+19.19);\n\treturn fract(vec4((p4.x + p4.y)*p4.z, (p4.x + p4.z)*p4.y, (p4.y + p4.z)*p4.w, (p4.z + p4.w)*p4.x));\n}\nvoid main(void) {\n\tif (gl_FragCoord.x > numParticles) discard;\n\treadInput(vUv0.x);\n\tvisMode = inShow? 1.0 : -1.0;\n\tvec4 rndFactor = hash41(gl_FragCoord.x + seed);\n\tfloat particleRate = rate + rateDiv * rndFactor.x;\n\toutLife = inLife + delta;\n\tfloat nlife = clamp(outLife / lifetime, 0.0, 1.0);\n\tvec3 localVelocityDiv;\n\tvec3 velocityDiv;\n\tvec3 paramDiv;\n\tvec3 localVelocity = tex1Dlod_lerp(internalTex0, vec2(nlife, 0), localVelocityDiv);\n\tvec3 velocity =\t tex1Dlod_lerp(internalTex1, vec2(nlife, 0), velocityDiv);\n\tvec3 params =\t\ttex1Dlod_lerp(internalTex2, vec2(nlife, 0), paramDiv);\n\tfloat rotSpeed = params.x;\n\tfloat rotSpeedDiv = paramDiv.y;\n\tvec3 radialParams = tex1Dlod_lerp(internalTex3, vec2(nlife, 0), paramDiv);\n\tfloat radialSpeed = radialParams.x;\n\tfloat radialSpeedDiv = radialParams.y;\n\tbool respawn = inLife <= 0.0 || outLife >= lifetime;\n\tinPos = respawn ? calcSpawnPosition(rndFactor.xyz, rndFactor.x) : inPos;\n\tinAngle = respawn ? mix(startAngle, startAngle2, rndFactor.x) : inAngle;\n#ifndef LOCAL_SPACE\n\tvec3 radialVel = inPos - emitterPos;\n#else\n\tvec3 radialVel = inPos;\n#endif\n\tradialVel = (dot(radialVel, radialVel) > 1.0E-8) ? radialSpeed * normalize(radialVel) : vec3(0.0);\n\tradialVel += (radialSpeedDiv * vec3(2.0) - vec3(1.0)) * radialSpeedDivMult * rndFactor.xyz;\n\tlocalVelocity +=\t(localVelocityDiv * vec3(2.0) - vec3(1.0)) * localVelocityDivMult * rndFactor.xyz;\n\tvelocity +=\t\t (velocityDiv * vec3(2.0) - vec3(1.0)) * velocityDivMult * rndFactor.xyz;\n\trotSpeed +=\t\t (rotSpeedDiv * 2.0 - 1.0) * rotSpeedDivMult * rndFactor.y;\n\taddInitialVelocity(localVelocity, rndFactor.xyz);\n#ifndef LOCAL_SPACE\n\toutVel = emitterMatrix * localVelocity + (radialVel + velocity) * emitterScale;\n#else\n\toutVel = (localVelocity + radialVel) / emitterScale + emitterMatrixInv * velocity;\n#endif\n\toutPos = inPos + outVel * delta;\n\toutAngle = inAngle + rotSpeed * delta;\n", particle_billboardVS:"\tquadXY = rotate(quadXY, inAngle, rotMatrix);\n\tvec3 localPos = billboard(particlePos, quadXY);\n",particle_blendAddPS:"\tdBlendModeFogFactor = 0.0;\n\trgb *= saturate(gammaCorrectInput(max(a, 0.0)));\n\tif ((rgb.r + rgb.g + rgb.b) < 0.000001) discard;\n",particle_blendMultiplyPS:"\trgb = mix(vec3(1.0), rgb, vec3(a));\n\tif (rgb.r + rgb.g + rgb.b > 2.99) discard;\n",particle_blendNormalPS:"\tif (a < 0.01) discard;\n",particle_cpuVS:"attribute vec4 particle_vertexData;\nattribute vec4 particle_vertexData2;\nattribute vec4 particle_vertexData3;\nattribute float particle_vertexData4;\n#ifndef USE_MESH\n#define VDATA5TYPE vec2\n#else\n#define VDATA5TYPE vec4\n#endif\nattribute VDATA5TYPE particle_vertexData5;\nuniform mat4 matrix_viewProjection;\nuniform mat4 matrix_model;\n#ifndef VIEWMATRIX\n#define VIEWMATRIX\nuniform mat4 matrix_view;\n#endif\nuniform mat3 matrix_normal;\nuniform mat4 matrix_viewInverse;\nuniform float numParticles;\nuniform float lifetime;\nuniform float stretch;\nuniform float seed;\nuniform vec3 wrapBounds, emitterScale, faceTangent, faceBinorm;\nuniform sampler2D texLifeAndSourcePosOUT;\nuniform highp sampler2D internalTex0;\nuniform highp sampler2D internalTex1;\nuniform highp sampler2D internalTex2;\nuniform vec3 emitterPos;\nvarying vec4 texCoordsAlphaLife;\nvec2 rotate(vec2 quadXY, float pRotation, out mat2 rotMatrix)\n{\n\tfloat c = cos(pRotation);\n\tfloat s = sin(pRotation);\n\tmat2 m = mat2(c, -s, s, c);\n\trotMatrix = m;\n\treturn m * quadXY;\n}\nvec3 billboard(vec3 InstanceCoords, vec2 quadXY)\n{\n\tvec3 pos = -matrix_viewInverse[0].xyz * quadXY.x + -matrix_viewInverse[1].xyz * quadXY.y;\n\treturn pos;\n}\nvec3 customFace(vec3 InstanceCoords, vec2 quadXY)\n{\n\tvec3 pos = faceTangent * quadXY.x + faceBinorm * quadXY.y;\n\treturn pos;\n}\nvoid main(void)\n{\n\tvec3 particlePos = particle_vertexData.xyz;\n\tvec3 inPos = particlePos;\n\tvec3 vertPos = particle_vertexData3.xyz;\n\tvec3 inVel = vec3(particle_vertexData2.w, particle_vertexData3.w, particle_vertexData5.x);\n\tfloat id = floor(particle_vertexData4);\n\tfloat rndFactor = fract(sin(id + 1.0 + seed));\n\tvec3 rndFactor3 = vec3(rndFactor, fract(rndFactor*10.0), fract(rndFactor*100.0));\n#ifdef LOCAL_SPACE\n\tinVel = mat3(matrix_model) * inVel;\n#endif\n\tvec2 velocityV = normalize((mat3(matrix_view) * inVel).xy);\n\tvec2 quadXY = vertPos.xy;\n#ifndef USE_MESH\n\ttexCoordsAlphaLife = vec4(quadXY * -0.5 + 0.5, particle_vertexData2.z, particle_vertexData.w);\n#else\n\ttexCoordsAlphaLife = vec4(particle_vertexData5.zw, particle_vertexData2.z, particle_vertexData.w);\n#endif\n\tmat2 rotMatrix;\n\tfloat inAngle = particle_vertexData2.x;\n\tvec3 particlePosMoved = vec3(0.0);\n\tvec3 meshLocalPos = particle_vertexData3.xyz;\n", particle_cpu_endVS:"\tlocalPos *= particle_vertexData2.y * emitterScale;\n\tlocalPos += particlePos;\n\tgl_Position = matrix_viewProjection * vec4(localPos, 1.0);\n",particle_customFaceVS:"\tquadXY = rotate(quadXY, inAngle, rotMatrix);\n\tvec3 localPos = customFace(particlePos, quadXY);\n",particle_endPS:"\trgb = addFog(rgb);\n\trgb = toneMap(rgb);\n\trgb = gammaCorrectOutput(rgb);\n\tgl_FragColor = vec4(rgb, a);\n}\n",particle_endVS:"\tlocalPos *= scale * emitterScale;\n\tlocalPos += particlePos;\n\t#ifdef SCREEN_SPACE\n\tgl_Position = vec4(localPos.x, localPos.y, 0.0, 1.0);\n\t#else\n\tgl_Position = matrix_viewProjection * vec4(localPos.xyz, 1.0);\n\t#endif\n", particle_halflambertPS:"\tvec3 negNormal = normal*0.5+0.5;\n\tvec3 posNormal = -normal*0.5+0.5;\n\tnegNormal *= negNormal;\n\tposNormal *= posNormal;\n",particle_initVS:"attribute vec4 particle_vertexData;\n#ifdef USE_MESH\nattribute vec2 particle_uv;\n#endif\nuniform mat4 matrix_viewProjection;\nuniform mat4 matrix_model;\nuniform mat3 matrix_normal;\nuniform mat4 matrix_viewInverse;\n#ifndef VIEWMATRIX\n#define VIEWMATRIX\nuniform mat4 matrix_view;\n#endif\nuniform float numParticles, numParticlesPot;\nuniform float graphSampleSize;\nuniform float graphNumSamples;\nuniform float stretch;\nuniform vec3 wrapBounds;\nuniform vec3 emitterScale, emitterPos, faceTangent, faceBinorm;\nuniform float rate, rateDiv, lifetime, deltaRandomnessStatic, scaleDivMult, alphaDivMult, seed, delta;\nuniform sampler2D particleTexOUT, particleTexIN;\nuniform highp sampler2D internalTex0;\nuniform highp sampler2D internalTex1;\nuniform highp sampler2D internalTex2;\n#ifndef CAMERAPLANES\n#define CAMERAPLANES\nuniform vec4 camera_params;\n#endif\nvarying vec4 texCoordsAlphaLife;\nvec3 inPos;\nvec3 inVel;\nfloat inAngle;\nbool inShow;\nfloat inLife;\n", particle_lambertPS:"\tvec3 negNormal = max(normal, vec3(0.0));\n\tvec3 posNormal = max(-normal, vec3(0.0));\n",particle_lightingPS:"\tvec3 light = negNormal.x*lightCube[0] + posNormal.x*lightCube[1] +\n\t\t\t\t\t\tnegNormal.y*lightCube[2] + posNormal.y*lightCube[3] +\n\t\t\t\t\t\tnegNormal.z*lightCube[4] + posNormal.z*lightCube[5];\n\trgb *= light;\n",particle_localShiftVS:"\tparticlePos = (matrix_model * vec4(particlePos, 1.0)).xyz;\n",particle_meshVS:"\tvec3 localPos = meshLocalPos;\n\tlocalPos.xy = rotate(localPos.xy, inAngle, rotMatrix);\n\tlocalPos.yz = rotate(localPos.yz, inAngle, rotMatrix);\n\tbillboard(particlePos, quadXY);\n", particle_normalVS:"\tNormal = normalize(localPos + matrix_viewInverse[2].xyz);\n",particle_normalMapPS:"\tvec3 normalMap = normalize(texture2D(normalMap, texCoordsAlphaLife.xy).xyz * 2.0 - 1.0);\n\tvec3 normal = ParticleMat * normalMap;\n",particle_pointAlongVS:"\tinAngle = atan(velocityV.x, velocityV.y);\n",particle_softPS:"\tfloat depth = getLinearScreenDepth();\n\tfloat particleDepth = vDepth;\n\tfloat depthDiff = saturate(abs(particleDepth - depth) * softening);\n\ta *= depthDiff;\n",particle_softVS:"\tvDepth = getLinearDepth(localPos);\n", particle_stretchVS:"\tvec3 moveDir = inVel * stretch;\n\tvec3 posPrev = particlePos - moveDir;\n\tposPrev += particlePosMoved;\n\tvec2 centerToVertexV = normalize((mat3(matrix_view) * localPos).xy);\n\tfloat interpolation = dot(-velocityV, centerToVertexV) * 0.5 + 0.5;\n\tparticlePos = mix(particlePos, posPrev, interpolation);\n",particle_TBNVS:"\tmat3 rot3 = mat3(rotMatrix[0][0], rotMatrix[0][1], 0.0, rotMatrix[1][0], rotMatrix[1][1], 0.0, 0.0, 0.0, 1.0);\n\tParticleMat = mat3(-matrix_viewInverse[0].xyz, -matrix_viewInverse[1].xyz, matrix_viewInverse[2].xyz) * rot3;\n", particle_wrapVS:"\tvec3 origParticlePos = particlePos;\n\tparticlePos -= matrix_model[3].xyz;\n\tparticlePos = mod(particlePos, wrapBounds) - wrapBounds * 0.5;\n\tparticlePos += matrix_model[3].xyz;\n\tparticlePosMoved = particlePos - origParticlePos;\n",precisionTestPS:"void main(void) {\n\tgl_FragColor = vec4(2147483648.0);\n}\n",precisionTest2PS:"uniform sampler2D source;\nvec4 packFloat(float depth) {\n\tconst vec4 bit_shift = vec4(256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0);\n\tconst vec4 bit_mask = vec4(0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0);\n\tvec4 res = mod(depth * bit_shift * vec4(255), vec4(256) ) / vec4(255);\n\tres -= res.xxyz * bit_mask;\n\treturn res;\n}\nvoid main(void) {\n\tfloat c = texture2D(source, vec2(0.0)).r;\n\tfloat diff = abs(c - 2147483648.0) / 2147483648.0;\n\tgl_FragColor = packFloat(diff);\n}\n", prefilterCubemapPS:"varying vec2 vUv0;\nuniform samplerCube source;\nuniform vec4 params;\nfloat saturate(float x) {\n\treturn clamp(x, 0.0, 1.0);\n}\nfloat rnd(vec2 uv) {\n\treturn fract(sin(dot(uv, vec2(12.9898, 78.233) * 2.0)) * 43758.5453);\n}\nconst float PI = 3.14159265358979;\nvec3 hemisphereSample_cos(vec2 uv, mat3 vecSpace, vec3 cubeDir, float gloss) {\n\tfloat phi = uv.y * 2.0 * PI;\n\tfloat cosTheta = sqrt(1.0 - uv.x);\n\tfloat sinTheta = sqrt(1.0 - cosTheta * cosTheta);\n\tvec3 sampleDir = vec3(cos(phi) * sinTheta, sin(phi) * sinTheta, cosTheta);\n\treturn normalize(mix(vecSpace * sampleDir, cubeDir, params.y));\n}\nvec3 hemisphereSample_phong(vec2 uv, mat3 vecSpace, vec3 cubeDir, float specPow) {\n\tfloat phi = uv.y * 2.0 * PI;\n\tfloat cosTheta = pow(1.0 - uv.x, 1.0 / (specPow + 1.0));\n\tfloat sinTheta = sqrt(1.0 - cosTheta * cosTheta);\n\tvec3 sampleDir = vec3(cos(phi) * sinTheta, sin(phi) * sinTheta, cosTheta);\n\treturn vecSpace * sampleDir;\n}\nmat3 matrixFromVector(vec3 n) {\n\tfloat a = 1.0 / (1.0 + n.z);\n\tfloat b = -n.x * n.y * a;\n\tvec3 b1 = vec3(1.0 - n.x * n.x * a, b, -n.x);\n\tvec3 b2 = vec3(b, 1.0 - n.y * n.y * a, -n.y);\n\treturn mat3(b1, b2, n);\n}\nvec4 encodeRGBM(vec3 color) {\n\tvec4 encoded;\n\tencoded.rgb = pow(color.rgb, vec3(0.5));\n\tencoded.rgb *= 1.0 / 8.0;\n\tencoded.a = saturate( max( max( encoded.r, encoded.g ), max( encoded.b, 1.0 / 255.0 ) ) );\n\tencoded.a = ceil(encoded.a * 255.0) / 255.0;\n\tencoded.rgb /= encoded.a;\n\treturn encoded;\n}\nvoid main(void) {\n\tvec2 st = vUv0 * 2.0 - 1.0;\n\tif (params.w==1.0 || params.w==3.0) {\n\t\tst = 2.0 * floor(gl_FragCoord.xy) / (params.z - 1.0) - 1.0;\n\t}\n\tfloat face = params.x;\n\tvec3 vec;\n\tif (face==0.0) {\n\t\tvec = vec3(1, -st.y, -st.x);\n\t} else if (face==1.0) {\n\t\tvec = vec3(-1, -st.y, st.x);\n\t} else if (face==2.0) {\n\t\tvec = vec3(st.x, 1, st.y);\n\t} else if (face==3.0) {\n\t\tvec = vec3(st.x, -1, -st.y);\n\t} else if (face==4.0) {\n\t\tvec = vec3(st.x, -st.y, 1);\n\t} else {\n\t\tvec = vec3(-st.x, -st.y, -1);\n\t}\n\tmat3 vecSpace = matrixFromVector(normalize(vec));\n\tvec3 color = vec3(0.0);\n\tconst int samples = $NUMSAMPLES;\n\tvec3 vect;\n\tfor(int i=0; i= 0.0 ? dTBN[1] : dTBN[0];\n\tvec3 anisotropicTangent = cross(anisotropicDirection, dViewDirW);\n\tvec3 anisotropicNormal = cross(anisotropicTangent, anisotropicDirection);\n\tvec3 bentNormal = normalize(mix(normalize(dNormalW), normalize(anisotropicNormal), anisotropy));\n\tdReflDirW = reflect(-dViewDirW, bentNormal);\n}\n", reflectionCCPS:"#ifdef CLEARCOAT\nuniform float material_clearCoatReflectivity;\nvoid addReflectionCC() {\n\tccReflection += vec4(calcReflection(ccReflDirW, ccGlossiness), material_clearCoatReflectivity);\n}\n#endif\n",reflectionCubePS:"uniform samplerCube texture_cubeMap;\nuniform float material_reflectivity;\nvec3 calcReflection(vec3 tReflDirW, float tGlossiness) {\n\tvec3 lookupVec = fixSeams(cubeMapProject(tReflDirW));\n\tlookupVec.x *= -1.0;\n\treturn $textureCubeSAMPLE(texture_cubeMap, lookupVec).rgb;\n}\nvoid addReflection() {\n\tdReflection += vec4(calcReflection(dReflDirW, dGlossiness), material_reflectivity);\n}\n", reflectionDpAtlasPS:"uniform sampler2D texture_sphereMap;\nuniform float material_reflectivity;\nvec2 getDpAtlasUv(vec2 uv, float mip) {\n\tvec4 rect;\n\tfloat sx = saturate(mip - 2.0);\n\trect.x = sx * 0.5;\n\tfloat t = mip - rect.x * 6.0;\n\tfloat i = 1.0 - rect.x;\n\trect.y = min(t * 0.5, 0.75) * i + rect.x;\n\tfloat st = saturate(t);\n\trect.z = (1.0 - st * 0.5) * i;\n\trect.w = rect.z * 0.5;\n\tfloat rcRectZ = 1.0 / rect.z;\n\tfloat scaleFactor = 0.00390625 * rcRectZ;\n\tvec2 scale = vec2(scaleFactor, scaleFactor * 2.0);\n\tuv = uv * (vec2(1.0) - scale) + scale * 0.5;\n\tuv = uv * rect.zw + rect.xy;\n\treturn uv;\n}\nvec3 calcReflection(vec3 tReflDirW, float tGlossiness) {\n\tvec3 reflDir = normalize(cubeMapProject(tReflDirW));\n\tbool up = reflDir.y > 0.0;\n\tfloat scale = 0.90909090909090909090909090909091;\n\tvec3 reflDirWarp = reflDir.xzx * vec3(-0.25, 0.5, 0.25);\n\tfloat reflDirVer = abs(reflDir.y) + 1.0;\n\treflDirWarp /= reflDirVer;\n\treflDirWarp *= scale;\n\treflDirWarp = vec3(0.75, 0.5, 0.25) - reflDirWarp;\n\tvec2 tc = up? reflDirWarp.xy : reflDirWarp.zy;\n\tfloat bias = saturate(1.0 - tGlossiness) * 5.0;\n\tfloat mip = floor(bias);\n\tvec3 tex1 = $texture2DSAMPLE(texture_sphereMap, getDpAtlasUv(tc, mip)).rgb;\n\tmip = min(mip + 1.0, 5.0);\n\tvec3 tex2 = $texture2DSAMPLE(texture_sphereMap, getDpAtlasUv(tc, mip)).rgb;\n\ttex1 = mix(tex1, tex2, fract(bias));\n\ttex1 = processEnvironment(tex1);\n\treturn tex1;\n}\nvoid addReflection() {\n\tdReflection += vec4(calcReflection(dReflDirW, dGlossiness), material_reflectivity);\n}\n", reflectionPrefilteredCubePS:"uniform samplerCube texture_prefilteredCubeMap128;\nuniform samplerCube texture_prefilteredCubeMap64;\nuniform samplerCube texture_prefilteredCubeMap32;\nuniform samplerCube texture_prefilteredCubeMap16;\nuniform samplerCube texture_prefilteredCubeMap8;\n#ifndef PMREM4\n#define PMREM4\nuniform samplerCube texture_prefilteredCubeMap4;\n#endif\nuniform float material_reflectivity;\nvec3 calcReflection(vec3 tReflDirW, float tGlossiness) {\n\tfloat bias = saturate(1.0 - tGlossiness) * 5.0;\n\tint index1 = int(bias);\n\tint index2 = int(min(bias + 1.0, 7.0));\n\tvec3 fixedReflDir = fixSeams(cubeMapProject(tReflDirW), bias);\n\tfixedReflDir.x *= -1.0;\n\tvec4 cubes[6];\n\tcubes[0] = textureCube(texture_prefilteredCubeMap128, fixedReflDir);\n\tcubes[1] = textureCube(texture_prefilteredCubeMap64, fixedReflDir);\n\tcubes[2] = textureCube(texture_prefilteredCubeMap32, fixedReflDir);\n\tcubes[3] = textureCube(texture_prefilteredCubeMap16, fixedReflDir);\n\tcubes[4] = textureCube(texture_prefilteredCubeMap8, fixedReflDir);\n\tcubes[5] = textureCube(texture_prefilteredCubeMap4, fixedReflDir);\n\tvec4 cube[2];\n\tfor(int i = 0; i < 6; i++) {\n\t\tif (i == index1) {\n\t\t\tcube[0] = cubes[i];\n\t\t}\n\t\tif (i == index2) {\n\t\t\tcube[1] = cubes[i];\n\t\t}\n\t}\n\tvec4 cubeFinal = mix(cube[0], cube[1], fract(bias));\n\tvec3 refl = processEnvironment($DECODE(cubeFinal).rgb);\n\treturn refl;\n}\nvoid addReflection() {\n\tdReflection += vec4(calcReflection(dReflDirW, dGlossiness), material_reflectivity);\n}\n", reflectionPrefilteredCubeLodPS:"#ifndef PMREM4\n#define PMREM4\n#extension GL_EXT_shader_texture_lod : enable\nuniform samplerCube texture_prefilteredCubeMap128;\n#endif\nuniform float material_reflectivity;\nvec3 calcReflection(vec3 tReflDirW, float tGlossiness) {\n\tfloat bias = saturate(1.0 - tGlossiness) * 5.0;\n\tvec3 fixedReflDir = fixSeams(cubeMapProject(tReflDirW), bias);\n\tfixedReflDir.x *= -1.0;\n\tvec3 refl = processEnvironment($DECODE( textureCubeLodEXT(texture_prefilteredCubeMap128, fixedReflDir, bias) ).rgb);\n\treturn refl;\n}\nvoid addReflection() {\n\tdReflection += vec4(calcReflection(dReflDirW, dGlossiness), material_reflectivity);\n}\n", reflectionSpherePS:"#ifndef VIEWMATRIX\n#define VIEWMATRIX\nuniform mat4 matrix_view;\n#endif\nuniform sampler2D texture_sphereMap;\nuniform float material_reflectivity;\nvec3 calcReflection(vec3 tReflDirW, float tGlossiness) {\n\tvec3 reflDirV = (mat3(matrix_view) * tReflDirW).xyz;\n\tfloat m = 2.0 * sqrt( dot(reflDirV.xy, reflDirV.xy) + (reflDirV.z+1.0)*(reflDirV.z+1.0) );\n\tvec2 sphereMapUv = reflDirV.xy / m + 0.5;\n\treturn $texture2DSAMPLE(texture_sphereMap, sphereMapUv).rgb;\n}\nvoid addReflection() {\n\tdReflection += vec4(calcReflection(dReflDirW, dGlossiness), material_reflectivity);\n}\n", reflectionSphereLowPS:"uniform sampler2D texture_sphereMap;\nuniform float material_reflectivity;\nvec3 calcReflection(vec3 tReflDirW, float tGlossiness) {\n\tvec3 reflDirV = vNormalV;\n\tvec2 sphereMapUv = reflDirV.xy * 0.5 + 0.5;\n\treturn $texture2DSAMPLE(texture_sphereMap, sphereMapUv).rgb;\n}\nvoid addReflection() {\n\tdReflection += vec4(calcReflection(dReflDirW, dGlossiness), material_reflectivity);\n}\n",refractionPS:"uniform float material_refraction, material_refractionIndex;\nvec3 refract2(vec3 viewVec, vec3 Normal, float IOR) {\n\tfloat vn = dot(viewVec, Normal);\n\tfloat k = 1.0 - IOR * IOR * (1.0 - vn * vn);\n\tvec3 refrVec = IOR * viewVec - (IOR * vn + sqrt(k)) * Normal;\n\treturn refrVec;\n}\nvoid addRefraction() {\n\tvec3 tmp = dReflDirW;\n\tvec4 tmp2 = dReflection;\n\tdReflection = vec4(0.0);\n\tdReflDirW = refract2(-dViewDirW, dNormalW, material_refractionIndex);\n\taddReflection();\n\tdDiffuseLight = mix(dDiffuseLight, dReflection.rgb * dAlbedo, material_refraction);\n\tdReflDirW = tmp;\n\tdReflection = tmp2;\n}\n", reprojectPS:"\nvarying vec2 vUv0;\nuniform sampler2D sourceTex;\nuniform samplerCube sourceCube;\nuniform vec4 params;\nfloat PI = 3.141592653589793;\nfloat saturate(float x) {\n\treturn clamp(x, 0.0, 1.0);\n}\nvec3 decodeLinear(vec4 source) {\n\treturn source.rgb;\n}\nvec4 encodeLinear(vec3 source) {\n\treturn vec4(source, 1.0);\n}\nvec3 decodeGamma(vec4 source) {\n\treturn pow(source.xyz, vec3(2.2));\n}\nvec4 encodeGamma(vec3 source) {\n\treturn vec4(pow(source + 0.0000001, vec3(1.0 / 2.2)), 1.0);\n}\nvec3 decodeRGBM(vec4 rgbm) {\n\tvec3 color = (8.0 * rgbm.a) * rgbm.rgb;\n\treturn color * color;\n}\nvec4 encodeRGBM(vec3 source) {\n\tvec4 result;\n\tresult.rgb = pow(source.rgb, vec3(0.5));\n\tresult.rgb *= 1.0 / 8.0;\n\tresult.a = saturate( max( max( result.r, result.g ), max( result.b, 1.0 / 255.0 ) ) );\n\tresult.a = ceil(result.a * 255.0) / 255.0;\n\tresult.rgb /= result.a;\n\treturn result;\n}\nvec3 decodeRGBE(vec4 source) {\n\tif (source.a == 0.0) {\n\t\treturn vec3(0.0, 0.0, 0.0);\n\t} else {\n\t\treturn source.xyz * pow(2.0, source.w * 255.0 - 128.0);\n\t}\n}\nvec4 encodeRGBE(vec3 source) {\n\tfloat maxVal = max(source.x, max(source.y, source.z));\n\tif (maxVal < 1e-32) {\n\t\treturn vec4(0, 0, 0, 0);\n\t} else {\n\t\tfloat e = ceil(log2(maxVal));\n\t\treturn vec4(source / pow(2.0, e), (e + 128.0) / 255.0);\n\t}\n}\nvec2 toSpherical(vec3 dir) {\n\treturn vec2(atan(dir.z, dir.x) * -1.0, asin(dir.y));\n}\nvec3 fromSpherical(vec2 uv) {\n\treturn vec3(cos(uv.y) * cos(-uv.x),\n\t\t\t\tsin(uv.y),\n\t\t\t\tcos(uv.y) * sin(-uv.x));\n}\nvec4 sampleEquirect(vec2 sph) {\n\treturn texture2D(sourceTex, sph / vec2(PI * 2.0, PI) + 0.5);\n}\nvec4 sampleEquirect(vec3 dir) {\n\treturn sampleEquirect(toSpherical(dir));\n}\nvec4 sampleCubemap(vec3 dir) {\n\treturn textureCube(sourceCube, dir);\n}\nvec4 sampleCubemap(vec2 sph) {\n\treturn sampleCubemap(fromSpherical(sph));\n}\nvec3 getDirectionEquirect() {\n\treturn fromSpherical((vUv0 * 2.0 - 1.0) * vec2(PI, PI * 0.5));\n}\nvec3 getDirectionCubemap() {\n\tvec2 st = vUv0 * 2.0 - 1.0;\n\tfloat face = params.x;\n\tvec3 vec;\n\tif (face==0.0) {\n\t\tvec = vec3(1, -st.y, -st.x);\n\t} else if (face==1.0) {\n\t\tvec = vec3(-1, -st.y, st.x);\n\t} else if (face==2.0) {\n\t\tvec = vec3(st.x, 1, st.y);\n\t} else if (face==3.0) {\n\t\tvec = vec3(st.x, -1, -st.y);\n\t} else if (face==4.0) {\n\t\tvec = vec3(st.x, -st.y, 1);\n\t} else {\n\t\tvec = vec3(-st.x, -st.y, -1);\n\t}\n\treturn normalize(vec);\n}\nmat3 matrixFromVector(vec3 n) {\n\tfloat a = 1.0 / (1.0 + n.z);\n\tfloat b = -n.x * n.y * a;\n\tvec3 b1 = vec3(1.0 - n.x * n.x * a, b, -n.x);\n\tvec3 b2 = vec3(b, 1.0 - n.y * n.y * a, -n.y);\n\treturn mat3(b1, b2, n);\n}\nfloat rnd(int i) {\n\tfloat sini = sin(float(i));\n\tfloat cosi = cos(float(i));\n\treturn fract(sin(dot(vec2(sini, cosi), vec2(12.9898, 78.233) * 2.0)) * 43758.5453);\n}\nvec3 hemisphereSamplePhong(vec2 uv, float specPow) {\n\tfloat phi = uv.y * 2.0 * PI;\n\tfloat cosTheta = pow(1.0 - uv.x, 1.0 / (specPow + 1.0));\n\tfloat sinTheta = sqrt(1.0 - cosTheta * cosTheta);\n\treturn vec3(cos(phi) * sinTheta, sin(phi) * sinTheta, cosTheta);\n}\nvec4 reproject() {\n\tif (NUM_SAMPLES <= 1) {\n\t\treturn ENCODE_FUNC(DECODE_FUNC(SOURCE_FUNC(TARGET_FUNC())));\n\t} else {\n\t\tvec2 sph = toSpherical(TARGET_FUNC());\n\t\tvec2 sphu = dFdx(sph);\n\t\tvec2 sphv = dFdy(sph);\n\t\tconst float num = sqrt(float(NUM_SAMPLES));\n\t\tvec3 result = vec3(0.0);\n\t\tfor (float u=0.0; u tcAbs.y) && (tcAbs.x > tcAbs.z)) {\n\t\tdirX = vec4(0,0,1, tc.z);\n\t\tdirY = vec4(0,1,0, tc.y);\n\t\tmajorAxisLength = tc.x;\n\t} else if ((tcAbs.y > tcAbs.x) && (tcAbs.y > tcAbs.z)) {\n\t\tdirX = vec4(1,0,0, tc.x);\n\t\tdirY = vec4(0,0,1, tc.z);\n\t\tmajorAxisLength = tc.y;\n\t}\n\tfloat shadowParamsInFaceSpace = ((1.0/shadowParams.x) * 2.0) * abs(majorAxisLength);\n\tvec3 xoffset = (dirX.xyz * shadowParamsInFaceSpace);\n\tvec3 yoffset = (dirY.xyz * shadowParamsInFaceSpace);\n\tvec3 dx0 = -xoffset;\n\tvec3 dy0 = -yoffset;\n\tvec3 dx1 = xoffset;\n\tvec3 dy1 = yoffset;\n\tmat3 shadowKernel;\n\tmat3 depthKernel;\n\tdepthKernel[0][0] = unpackFloat(textureCube(shadowMap, tc + dx0 + dy0));\n\tdepthKernel[0][1] = unpackFloat(textureCube(shadowMap, tc + dx0));\n\tdepthKernel[0][2] = unpackFloat(textureCube(shadowMap, tc + dx0 + dy1));\n\tdepthKernel[1][0] = unpackFloat(textureCube(shadowMap, tc + dy0));\n\tdepthKernel[1][1] = unpackFloat(textureCube(shadowMap, tc));\n\tdepthKernel[1][2] = unpackFloat(textureCube(shadowMap, tc + dy1));\n\tdepthKernel[2][0] = unpackFloat(textureCube(shadowMap, tc + dx1 + dy0));\n\tdepthKernel[2][1] = unpackFloat(textureCube(shadowMap, tc + dx1));\n\tdepthKernel[2][2] = unpackFloat(textureCube(shadowMap, tc + dx1 + dy1));\n\tvec3 shadowZ = vec3(length(dir) * shadowParams.w + shadowParams.z);\n\tshadowKernel[0] = vec3(lessThan2(depthKernel[0], shadowZ));\n\tshadowKernel[1] = vec3(lessThan2(depthKernel[1], shadowZ));\n\tshadowKernel[2] = vec3(lessThan2(depthKernel[2], shadowZ));\n\tvec2 uv = (vec2(dirX.w, dirY.w) / abs(majorAxisLength)) * 0.5;\n\tvec2 fractionalCoord = fract( uv * shadowParams.x );\n\tshadowKernel[0] = mix(shadowKernel[0], shadowKernel[1], fractionalCoord.x);\n\tshadowKernel[1] = mix(shadowKernel[1], shadowKernel[2], fractionalCoord.x);\n\tvec4 shadowValues;\n\tshadowValues.x = mix(shadowKernel[0][0], shadowKernel[0][1], fractionalCoord.y);\n\tshadowValues.y = mix(shadowKernel[0][1], shadowKernel[0][2], fractionalCoord.y);\n\tshadowValues.z = mix(shadowKernel[1][0], shadowKernel[1][1], fractionalCoord.y);\n\tshadowValues.w = mix(shadowKernel[1][1], shadowKernel[1][2], fractionalCoord.y);\n\treturn 1.0 - dot( shadowValues, vec4( 1.0 ) ) * 0.25;\n}\nfloat getShadowPointPCF3x3(samplerCube shadowMap, vec4 shadowParams) {\n\treturn _getShadowPoint(shadowMap, shadowParams, dLightDirW);\n}\n", shadowStandardGL2PS:"float _getShadowPCF5x5(sampler2DShadow shadowMap, vec3 shadowParams) {\n\tfloat z = dShadowCoord.z;\n\tvec2 uv = dShadowCoord.xy * shadowParams.x;\n\tfloat shadowMapSizeInv = 1.0 / shadowParams.x;\n\tvec2 base_uv = floor(uv + 0.5);\n\tfloat s = (uv.x + 0.5 - base_uv.x);\n\tfloat t = (uv.y + 0.5 - base_uv.y);\n\tbase_uv -= vec2(0.5);\n\tbase_uv *= shadowMapSizeInv;\n\tfloat uw0 = (4.0 - 3.0 * s);\n\tfloat uw1 = 7.0;\n\tfloat uw2 = (1.0 + 3.0 * s);\n\tfloat u0 = (3.0 - 2.0 * s) / uw0 - 2.0;\n\tfloat u1 = (3.0 + s) / uw1;\n\tfloat u2 = s / uw2 + 2.0;\n\tfloat vw0 = (4.0 - 3.0 * t);\n\tfloat vw1 = 7.0;\n\tfloat vw2 = (1.0 + 3.0 * t);\n\tfloat v0 = (3.0 - 2.0 * t) / vw0 - 2.0;\n\tfloat v1 = (3.0 + t) / vw1;\n\tfloat v2 = t / vw2 + 2.0;\n\tfloat sum = 0.0;\n\tu0 = u0 * shadowMapSizeInv + base_uv.x;\n\tv0 = v0 * shadowMapSizeInv + base_uv.y;\n\tu1 = u1 * shadowMapSizeInv + base_uv.x;\n\tv1 = v1 * shadowMapSizeInv + base_uv.y;\n\tu2 = u2 * shadowMapSizeInv + base_uv.x;\n\tv2 = v2 * shadowMapSizeInv + base_uv.y;\n\tsum += uw0 * vw0 * texture(shadowMap, vec3(u0, v0, z));\n\tsum += uw1 * vw0 * texture(shadowMap, vec3(u1, v0, z));\n\tsum += uw2 * vw0 * texture(shadowMap, vec3(u2, v0, z));\n\tsum += uw0 * vw1 * texture(shadowMap, vec3(u0, v1, z));\n\tsum += uw1 * vw1 * texture(shadowMap, vec3(u1, v1, z));\n\tsum += uw2 * vw1 * texture(shadowMap, vec3(u2, v1, z));\n\tsum += uw0 * vw2 * texture(shadowMap, vec3(u0, v2, z));\n\tsum += uw1 * vw2 * texture(shadowMap, vec3(u1, v2, z));\n\tsum += uw2 * vw2 * texture(shadowMap, vec3(u2, v2, z));\n\tsum *= 1.0f / 144.0;\n\tsum = gammaCorrectInput(sum);\n\tsum = saturate(sum);\n\treturn sum;\n}\nfloat getShadowPCF5x5(sampler2DShadow shadowMap, vec3 shadowParams) {\n\treturn _getShadowPCF5x5(shadowMap, shadowParams);\n}\nfloat getShadowSpotPCF5x5(sampler2DShadow shadowMap, vec4 shadowParams) {\n\treturn _getShadowPCF5x5(shadowMap, shadowParams.xyz);\n}\n", shadowStandardGL2VSPS:"float getShadowPCF5x5VS(sampler2DShadow shadowMap, vec3 shadowParams) {\n\tdShadowCoord = vMainShadowUv.xyz;\n\tdShadowCoord.z = saturate(dShadowCoord.z) - 0.0001;\n\treturn _getShadowPCF5x5(shadowMap, shadowParams);\n}\n",shadowStandardVSPS:"#ifdef GL2\n#define SHADOW_SAMPLERVS sampler2DShadow\n#else\n#define SHADOW_SAMPLERVS sampler2D\n#endif\nfloat getShadowPCF3x3VS(SHADOW_SAMPLERVS shadowMap, vec3 shadowParams) {\n\tdShadowCoord = vMainShadowUv.xyz;\n\tdShadowCoord.z = saturate(dShadowCoord.z) - 0.0001;\n\t#ifdef SHADOWBIAS\n\tdShadowCoord.z += getShadowBias(shadowParams.x, shadowParams.z);\n\t#endif\n\treturn _getShadowPCF3x3(shadowMap, shadowParams);\n}\n", shadowVSM8PS:"float calculateVSM8(vec3 moments, float Z, float vsmBias) {\n\tfloat VSMBias = vsmBias;\n\tfloat depthScale = VSMBias * Z;\n\tfloat minVariance1 = depthScale * depthScale;\n\treturn chebyshevUpperBound(moments.xy, Z, minVariance1, 0.1);\n}\nfloat decodeFloatRG(vec2 rg) {\n\treturn rg.y*(1.0/255.0) + rg.x;\n}\nfloat VSM8(sampler2D tex, vec2 texCoords, float resolution, float Z, float vsmBias, float exponent) {\n\tvec4 c = texture2D(tex, texCoords);\n\tvec3 moments = vec3(decodeFloatRG(c.xy), decodeFloatRG(c.zw), 0.0);\n\treturn calculateVSM8(moments, Z, vsmBias);\n}\nfloat getShadowVSM8(sampler2D shadowMap, vec3 shadowParams, float exponent) {\n\treturn VSM8(shadowMap, dShadowCoord.xy, shadowParams.x, dShadowCoord.z, shadowParams.y, 0.0);\n}\nfloat getShadowSpotVSM8(sampler2D shadowMap, vec4 shadowParams, float exponent) {\n\treturn VSM8(shadowMap, dShadowCoord.xy, shadowParams.x, length(dLightDirW) * shadowParams.w + shadowParams.z, shadowParams.y, 0.0);\n}\n", shadowVSMVSPS:"float getShadowVSM$VS(sampler2D shadowMap, vec3 shadowParams, float exponent) {\n\tdShadowCoord = vMainShadowUv.xyz;\n\tdShadowCoord.z += shadowParams.z;\n\tdShadowCoord.xyz /= vMainShadowUv.w;\n\tdShadowCoord.z = min(dShadowCoord.z, 1.0);\n\treturn $VSM(shadowMap, dShadowCoord.xy, shadowParams.x, dShadowCoord.z, shadowParams.y, exponent);\n}\n",shadowVSM_commonPS:"float linstep(float a, float b, float v) {\n\treturn saturate((v - a) / (b - a));\n}\nfloat reduceLightBleeding(float pMax, float amount) {\n return linstep(amount, 1.0, pMax);\n}\nfloat chebyshevUpperBound(vec2 moments, float mean, float minVariance, float lightBleedingReduction) {\n\tfloat variance = moments.y - (moments.x * moments.x);\n\tvariance = max(variance, minVariance);\n\tfloat d = mean - moments.x;\n\tfloat pMax = variance / (variance + (d * d));\n\tpMax = reduceLightBleeding(pMax, lightBleedingReduction);\n\treturn (mean <= moments.x ? 1.0 : pMax);\n}\nfloat calculateEVSM(vec3 moments, float Z, float vsmBias, float exponent) {\n\tZ = 2.0 * Z - 1.0;\n\tfloat warpedDepth = exp(exponent * Z);\n\tmoments.xy += vec2(warpedDepth, warpedDepth*warpedDepth) * (1.0 - moments.z);\n\tfloat VSMBias = vsmBias;\n\tfloat depthScale = VSMBias * exponent * warpedDepth;\n\tfloat minVariance1 = depthScale * depthScale;\n\treturn chebyshevUpperBound(moments.xy, warpedDepth, minVariance1, 0.1);\n}\n", skinBatchConstVS:"attribute float vertex_boneIndices;\nuniform vec4 matrix_pose[BONE_LIMIT * 3];\nmat4 getBoneMatrix(const in float i) {\n\tvec4 v1 = matrix_pose[int(3.0 * i)];\n\tvec4 v2 = matrix_pose[int(3.0 * i + 1.0)];\n\tvec4 v3 = matrix_pose[int(3.0 * i + 2.0)];\n\treturn mat4(\n\t\tv1.x, v2.x, v3.x, 0,\n\t\tv1.y, v2.y, v3.y, 0,\n\t\tv1.z, v2.z, v3.z, 0,\n\t\tv1.w, v2.w, v3.w, 1\n\t);\n}\n",skinBatchTexVS:"attribute float vertex_boneIndices;\nuniform highp sampler2D texture_poseMap;\nuniform vec4 texture_poseMapSize;\nmat4 getBoneMatrix(const in float i) {\n\tfloat j = i * 3.0;\n\tfloat dx = texture_poseMapSize.z;\n\tfloat dy = texture_poseMapSize.w;\n\tfloat y = floor(j * dx);\n\tfloat x = j - (y * texture_poseMapSize.x);\n\ty = dy * (y + 0.5);\n\tvec4 v1 = texture2D(texture_poseMap, vec2(dx * (x + 0.5), y));\n\tvec4 v2 = texture2D(texture_poseMap, vec2(dx * (x + 1.5), y));\n\tvec4 v3 = texture2D(texture_poseMap, vec2(dx * (x + 2.5), y));\n\treturn mat4(\n\t\tv1.x, v2.x, v3.x, 0,\n\t\tv1.y, v2.y, v3.y, 0,\n\t\tv1.z, v2.z, v3.z, 0,\n\t\tv1.w, v2.w, v3.w, 1\n\t);\n}\n", skinConstVS:"attribute vec4 vertex_boneWeights;\nattribute vec4 vertex_boneIndices;\nuniform vec4 matrix_pose[BONE_LIMIT * 3];\nvoid getBoneMatrix(const in float i, out vec4 v1, out vec4 v2, out vec4 v3) {\n\tv1 = matrix_pose[int(3.0 * i)];\n\tv2 = matrix_pose[int(3.0 * i + 1.0)];\n\tv3 = matrix_pose[int(3.0 * i + 2.0)];\n}\nmat4 getSkinMatrix(const in vec4 indices, const in vec4 weights) {\n\tvec4 a1, a2, a3;\n\tgetBoneMatrix(indices.x, a1, a2, a3);\n\tvec4 b1, b2, b3;\n\tgetBoneMatrix(indices.y, b1, b2, b3);\n\tvec4 c1, c2, c3;\n\tgetBoneMatrix(indices.z, c1, c2, c3);\n\tvec4 d1, d2, d3;\n\tgetBoneMatrix(indices.w, d1, d2, d3);\n\tvec4 v1 = a1 * weights.x + b1 * weights.y + c1 * weights.z + d1 * weights.w;\n\tvec4 v2 = a2 * weights.x + b2 * weights.y + c2 * weights.z + d2 * weights.w;\n\tvec4 v3 = a3 * weights.x + b3 * weights.y + c3 * weights.z + d3 * weights.w;\n\tfloat one = dot(weights, vec4(1.0));\n\treturn mat4(\n\t\tv1.x, v2.x, v3.x, 0,\n\t\tv1.y, v2.y, v3.y, 0,\n\t\tv1.z, v2.z, v3.z, 0,\n\t\tv1.w, v2.w, v3.w, one\n\t);\n}\n", skinTexVS:"attribute vec4 vertex_boneWeights;\nattribute vec4 vertex_boneIndices;\nuniform highp sampler2D texture_poseMap;\nuniform vec4 texture_poseMapSize;\nvoid getBoneMatrix(const in float i, out vec4 v1, out vec4 v2, out vec4 v3) {\n\tfloat j = i * 3.0;\n\tfloat dx = texture_poseMapSize.z;\n\tfloat dy = texture_poseMapSize.w;\n\tfloat y = floor(j * dx);\n\tfloat x = j - (y * texture_poseMapSize.x);\n\ty = dy * (y + 0.5);\n\tv1 = texture2D(texture_poseMap, vec2(dx * (x + 0.5), y));\n\tv2 = texture2D(texture_poseMap, vec2(dx * (x + 1.5), y));\n\tv3 = texture2D(texture_poseMap, vec2(dx * (x + 2.5), y));\n}\nmat4 getSkinMatrix(const in vec4 indices, const in vec4 weights) {\n\tvec4 a1, a2, a3;\n\tgetBoneMatrix(indices.x, a1, a2, a3);\n\tvec4 b1, b2, b3;\n\tgetBoneMatrix(indices.y, b1, b2, b3);\n\tvec4 c1, c2, c3;\n\tgetBoneMatrix(indices.z, c1, c2, c3);\n\tvec4 d1, d2, d3;\n\tgetBoneMatrix(indices.w, d1, d2, d3);\n\tvec4 v1 = a1 * weights.x + b1 * weights.y + c1 * weights.z + d1 * weights.w;\n\tvec4 v2 = a2 * weights.x + b2 * weights.y + c2 * weights.z + d2 * weights.w;\n\tvec4 v3 = a3 * weights.x + b3 * weights.y + c3 * weights.z + d3 * weights.w;\n\tfloat one = dot(weights, vec4(1.0));\n\treturn mat4(\n\t\tv1.x, v2.x, v3.x, 0,\n\t\tv1.y, v2.y, v3.y, 0,\n\t\tv1.z, v2.z, v3.z, 0,\n\t\tv1.w, v2.w, v3.w, one\n\t);\n}\n", skyboxPS:"varying vec3 vViewDir;\nuniform samplerCube texture_cubeMap;\nvoid main(void) {\n\tgl_FragColor = textureCube(texture_cubeMap, fixSeams(vViewDir));\n}\n",skyboxVS:"attribute vec3 aPosition;\n#ifndef VIEWMATRIX\n#define VIEWMATRIX\nuniform mat4 matrix_view;\n#endif\nuniform mat4 matrix_projectionSkybox;\nvarying vec3 vViewDir;\nvoid main(void) {\n\tmat4 view = matrix_view;\n\tview[3][0] = view[3][1] = view[3][2] = 0.0;\n\tgl_Position = matrix_projectionSkybox * view * vec4(aPosition, 1.0);\n\tgl_Position.z = gl_Position.w - 0.00001;\n\tvViewDir = aPosition;\n\tvViewDir.x *= -1.0;\n}\n", skyboxHDRPS:"varying vec3 vViewDir;\nuniform samplerCube texture_cubeMap;\nvoid main(void) {\n\tvec3 color = processEnvironment($textureCubeSAMPLE(texture_cubeMap, fixSeamsStatic(vViewDir, $FIXCONST)).rgb);\n\tcolor = toneMap(color);\n\tcolor = gammaCorrectOutput(color);\n\tgl_FragColor = vec4(color, 1.0);\n}\n",skyboxPrefilteredCubePS:"varying vec3 vViewDir;\nuniform samplerCube texture_cubeMap;\nvec3 fixSeamsStretch(vec3 vec, float mipmapIndex, float cubemapSize) {\n\tfloat scale = 1.0 - exp2(mipmapIndex) / cubemapSize;\n\tfloat M = max(max(abs(vec.x), abs(vec.y)), abs(vec.z));\n\tif (abs(vec.x) != M) vec.x *= scale;\n\tif (abs(vec.y) != M) vec.y *= scale;\n\tif (abs(vec.z) != M) vec.z *= scale;\n\treturn vec;\n}\nvoid main(void) {\n\tvec3 color = textureCubeRGBM(texture_cubeMap, fixSeamsStretch(vViewDir, 0.0, 128.0));\n\tcolor = toneMap(color);\n\tcolor = gammaCorrectOutput(color);\n\tgl_FragColor = vec4(color, 1.0);\n}\n", specularPS:"#ifdef MAPCOLOR\nuniform vec3 material_specular;\n#endif\n#ifdef MAPTEXTURE\nuniform sampler2D texture_specularMap;\n#endif\nvoid getSpecularity() {\n\tdSpecularity = vec3(1.0);\n\t#ifdef MAPCOLOR\n\tdSpecularity *= material_specular;\n\t#endif\n\t#ifdef MAPTEXTURE\n\tdSpecularity *= texture2D(texture_specularMap, $UV).$CH;\n\t#endif\n\t#ifdef MAPVERTEX\n\tdSpecularity *= saturate(vVertexColor.$VC);\n\t#endif\n}\n",specularAaNonePS:"float antiAliasGlossiness(float power) {\n\treturn power;\n}\n", specularAaToksvigPS:"float antiAliasGlossiness(float power) {\n\tfloat rlen = 1.0 / saturate(length(dNormalMap));\n\tfloat toksvig = 1.0 / (1.0 + power * (rlen - 1.0));\n\treturn power * mix(1.0, toksvig, material_bumpiness);\n}\n",specularAaToksvigFastPS:"float antiAliasGlossiness(float power) {\n\tfloat rlen = 1.0 / saturate(length(dNormalMap));\n\tfloat toksvig = 1.0 / (1.0 + power * (rlen - 1.0));\n\treturn power * toksvig;\n}\n",spotPS:"float getSpotEffect(vec3 lightSpotDirW, float lightInnerConeAngle, float lightOuterConeAngle) {\n\tfloat cosAngle = dot(dLightDirNormW, lightSpotDirW);\n\treturn smoothstep(lightOuterConeAngle, lightInnerConeAngle, cosAngle);\n}\n", startPS:"void main(void) {\n\tdDiffuseLight = vec3(0);\n\tdSpecularLight = vec3(0);\n\tdReflection = vec4(0);\n\tdSpecularity = vec3(0);\n\t#ifdef CLEARCOAT\n\tccSpecularLight = vec3(0);\n\tccReflection = vec4(0);\n\t#endif\n",startVS:"void main(void) {\n\tgl_Position = getPosition();\n",startNineSlicedPS:"\tnineSlicedUv = vUv0;\n",startNineSlicedTiledPS:"\tvec2 tileMask = step(vMask, vec2(0.99999));\n\tvec2 clampedUv = mix(innerOffset.xy*0.5, vec2(1.0) - innerOffset.zw*0.5, fract(vTiledUv));\n\tclampedUv = clampedUv * atlasRect.zw + atlasRect.xy;\n\tnineSlicedUv = vUv0 * tileMask + clampedUv * (vec2(1.0) - tileMask);\n", storeEVSMPS:"float exponent = VSM_EXPONENT;\ndepth = 2.0 * depth - 1.0;\ndepth = exp(exponent * depth);\ngl_FragColor = vec4(depth, depth*depth, 1.0, 1.0);\n",tangentBinormalVS:"vec3 getTangent() {\n\treturn normalize(dNormalMatrix * vertex_tangent.xyz);\n}\nvec3 getBinormal() {\n\treturn cross(vNormalW, vTangentW) * vertex_tangent.w;\n}\nvec3 getObjectSpaceUp() {\n\treturn normalize(dNormalMatrix * vec3(0, 1, 0));\n}\n",TBNPS:"void getTBN() {\n\tdTBN = mat3(normalize(dTangentW), normalize(dBinormalW), normalize(dVertexNormalW));\n}\n", TBNderivativePS:"\nvoid getTBN() {\n\tvec2 uv = $UV;\n\tvec3 dp1 = dFdx( vPositionW );\n\tvec3 dp2 = dFdy( vPositionW );\n\tvec2 duv1 = dFdx( uv );\n\tvec2 duv2 = dFdy( uv );\n\tvec3 dp2perp = cross( dp2, dVertexNormalW );\n\tvec3 dp1perp = cross( dVertexNormalW, dp1 );\n\tvec3 T = dp2perp * duv1.x + dp1perp * duv2.x;\n\tvec3 B = dp2perp * duv1.y + dp1perp * duv2.y;\n\tfloat invmax = 1.0 / sqrt( max( dot(T,T), dot(B,B) ) );\n\tdTBN = mat3( T * invmax, B * invmax, dVertexNormalW );\n}\n",TBNfastPS:"void getTBN() {\n\tdTBN = mat3(dTangentW, dBinormalW, dVertexNormalW);\n}\n", TBNObjectSpacePS:"void getTBN() {\n\tvec3 B = cross(dVertexNormalW, vObjectSpaceUpW);\n\tvec3 T = cross(dVertexNormalW, B);\n\tif (dot(B,B)==0.0)\n\t{\n\t\tfloat major=max(max(dVertexNormalW.x, dVertexNormalW.y),dVertexNormalW.z);\n\t\tif (dVertexNormalW.x==major)\n\t\t{\n\t\t\tB=cross(dVertexNormalW, vec3(0,1,0));\n\t\t\tT=cross(dVertexNormalW, B);\n\t\t}\n\t\telse if (dVertexNormalW.y==major)\n\t\t{\n\t\t\tB=cross(dVertexNormalW, vec3(0,0,1));\n\t\t\tT=cross(dVertexNormalW, B);\n\t\t}\n\t\telse if (dVertexNormalW.z==major)\n\t\t{\n\t\t\tB=cross(dVertexNormalW, vec3(1,0,0));\n\t\t\tT=cross(dVertexNormalW, B);\n\t\t}\n\t}\n\tdTBN = mat3(normalize(T), normalize(B), normalize(dVertexNormalW));\n}\n", tonemappingAcesPS:"uniform float exposure;\nvec3 toneMap(vec3 color) {\n\tfloat tA = 2.51;\n\tfloat tB = 0.03;\n\tfloat tC = 2.43;\n\tfloat tD = 0.59;\n\tfloat tE = 0.14;\n\tvec3 x = color * exposure;\n\treturn (x*(tA*x+tB))/(x*(tC*x+tD)+tE);\n}\n",tonemappingAces2PS:"uniform float exposure;\nconst mat3 ACESInputMat = mat3(\n\t0.59719, 0.35458, 0.04823,\n\t0.07600, 0.90834, 0.01566,\n\t0.02840, 0.13383, 0.83777\n);\nconst mat3 ACESOutputMat = mat3(\n\t 1.60475, -0.53108, -0.07367,\n\t-0.10208, 1.10813, -0.00605,\n\t-0.00327, -0.07276, 1.07602\n);\nvec3 RRTAndODTFit(vec3 v) {\n\tvec3 a = v * (v + 0.0245786) - 0.000090537;\n\tvec3 b = v * (0.983729 * v + 0.4329510) + 0.238081;\n\treturn a / b;\n}\nvec3 toneMap(vec3 color) {\n\tcolor *= exposure;\n\tcolor = color * ACESInputMat;\n\tcolor = RRTAndODTFit(color);\n\tcolor = color * ACESOutputMat;\n\tcolor = clamp(color, 0.0, 1.0);\n\treturn color;\n}\n", tonemappingFilmicPS:"const float A = 0.15;\nconst float B = 0.50;\nconst float C = 0.10;\nconst float D = 0.20;\nconst float E = 0.02;\nconst float F = 0.30;\nconst float W = 11.2;\nuniform float exposure;\nvec3 uncharted2Tonemap(vec3 x) {\n return ((x*(A*x+C*B)+D*E)/(x*(A*x+B)+D*F))-E/F;\n}\nvec3 toneMap(vec3 color) {\n\tcolor = uncharted2Tonemap(color * exposure);\n\tvec3 whiteScale = 1.0 / uncharted2Tonemap(vec3(W,W,W));\n\tcolor = color * whiteScale;\n\treturn color;\n}\n",tonemappingHejlPS:"uniform float exposure;\nvec3 toneMap(vec3 color) {\n\tcolor *= exposure;\n\tconst float A = 0.22, B = 0.3, C = .1, D = 0.2, E = .01, F = 0.3;\n\tconst float Scl = 1.25;\n\tvec3 h = max( vec3(0.0), color - vec3(0.004) );\n\treturn (h*((Scl*A)*h+Scl*vec3(C*B,C*B,C*B))+Scl*vec3(D*E,D*E,D*E)) / (h*(A*h+vec3(B,B,B))+vec3(D*F,D*F,D*F)) - Scl*vec3(E/F,E/F,E/F);\n}\n", tonemappingLinearPS:"uniform float exposure;\nvec3 toneMap(vec3 color) {\n\treturn color * exposure;\n}\n",tonemappingNonePS:"vec3 toneMap(vec3 color) {\n\treturn color;\n}\n",transformVS:"#ifdef PIXELSNAP\nuniform vec4 uScreenSize;\n#endif\n#ifdef MORPHING\nuniform vec4 morph_weights_a;\nuniform vec4 morph_weights_b;\n#endif\n#ifdef MORPHING_TEXTURE_BASED\nuniform vec4 morph_tex_params;\nvec2 getTextureMorphCoords() {\n\tfloat vertexId = morph_vertex_id;\n\tvec2 textureSize = morph_tex_params.xy;\n\tvec2 invTextureSize = morph_tex_params.zw;\n\tfloat morphGridV = floor(vertexId * invTextureSize.x);\n\tfloat morphGridU = vertexId - (morphGridV * textureSize.x);\n\treturn (vec2(morphGridU, morphGridV) * invTextureSize) + (0.5 * invTextureSize);\n}\n#endif\n#ifdef MORPHING_TEXTURE_BASED_POSITION\nuniform highp sampler2D morphPositionTex;\n#endif\nmat4 getModelMatrix() {\n\t#ifdef DYNAMICBATCH\n\treturn getBoneMatrix(vertex_boneIndices);\n\t#elif defined(SKIN)\n\treturn matrix_model * getSkinMatrix(vertex_boneIndices, vertex_boneWeights);\n\t#elif defined(INSTANCING)\n\treturn mat4(instance_line1, instance_line2, instance_line3, instance_line4);\n\t#else\n\treturn matrix_model;\n\t#endif\n}\nvec4 getPosition() {\n\tdModelMatrix = getModelMatrix();\n\tvec3 localPos = vertex_position;\n\t#ifdef NINESLICED\n\tlocalPos.xz *= outerScale;\n\tvec2 positiveUnitOffset = clamp(vertex_position.xz, vec2(0.0), vec2(1.0));\n\tvec2 negativeUnitOffset = clamp(-vertex_position.xz, vec2(0.0), vec2(1.0));\n\tlocalPos.xz += (-positiveUnitOffset * innerOffset.xy + negativeUnitOffset * innerOffset.zw) * vertex_texCoord0.xy;\n\tvTiledUv = (localPos.xz - outerScale + innerOffset.xy) * -0.5 + 1.0;\n\tlocalPos.xz *= -0.5;\n\tlocalPos = localPos.xzy;\n\t#endif\n\t#ifdef MORPHING\n\t#ifdef MORPHING_POS03\n\tlocalPos.xyz += morph_weights_a[0] * morph_pos0;\n\tlocalPos.xyz += morph_weights_a[1] * morph_pos1;\n\tlocalPos.xyz += morph_weights_a[2] * morph_pos2;\n\tlocalPos.xyz += morph_weights_a[3] * morph_pos3;\n\t#endif\n\t#ifdef MORPHING_POS47\n\tlocalPos.xyz += morph_weights_b[0] * morph_pos4;\n\tlocalPos.xyz += morph_weights_b[1] * morph_pos5;\n\tlocalPos.xyz += morph_weights_b[2] * morph_pos6;\n\tlocalPos.xyz += morph_weights_b[3] * morph_pos7;\n\t#endif\n\t#endif\n\t#ifdef MORPHING_TEXTURE_BASED_POSITION\n\tvec2 morphUV = getTextureMorphCoords();\n\tvec3 morphPos = texture2D(morphPositionTex, morphUV).xyz;\n\tlocalPos += morphPos;\n\t#endif\n\tvec4 posW = dModelMatrix * vec4(localPos, 1.0);\n\t#ifdef SCREENSPACE\n\tposW.zw = vec2(0.0, 1.0);\n\t#endif\n\tdPositionW = posW.xyz;\n\tvec4 screenPos;\n\t#ifdef UV1LAYOUT\n\tscreenPos = vec4(vertex_texCoord1.xy * 2.0 - 1.0, 0.5, 1);\n\t#else\n\t#ifdef SCREENSPACE\n\tscreenPos = posW;\n\t#else\n\tscreenPos = matrix_viewProjection * posW;\n\t#endif\n\t#ifdef PIXELSNAP\n\tscreenPos.xy = (screenPos.xy * 0.5) + 0.5;\n\tscreenPos.xy *= uScreenSize.xy;\n\tscreenPos.xy = floor(screenPos.xy);\n\tscreenPos.xy *= uScreenSize.zw;\n\tscreenPos.xy = (screenPos.xy * 2.0) - 1.0;\n\t#endif\n\t#endif\n\treturn screenPos;\n}\nvec3 getWorldPosition() {\n\treturn dPositionW;\n}\n", transformDeclVS:"attribute vec3 vertex_position;\nuniform mat4 matrix_model;\nuniform mat4 matrix_viewProjection;\nvec3 dPositionW;\nmat4 dModelMatrix;\n",uv0VS:"#ifdef NINESLICED\nvec2 getUv0() {\n\tvec2 uv = vertex_position.xz;\n\tvec2 positiveUnitOffset = clamp(vertex_position.xz, vec2(0.0), vec2(1.0));\n\tvec2 negativeUnitOffset = clamp(-vertex_position.xz, vec2(0.0), vec2(1.0));\n\tuv += (-positiveUnitOffset * innerOffset.xy + negativeUnitOffset * innerOffset.zw) * vertex_texCoord0.xy;\n\tuv = uv * -0.5 + 0.5;\n\tuv = uv * atlasRect.zw + atlasRect.xy;\n\tvMask = vertex_texCoord0.xy;\n\treturn uv;\n}\n#else\nvec2 getUv0() {\n\treturn vertex_texCoord0;\n}\n#endif\n", uv1VS:"vec2 getUv1() {\n\treturn vertex_texCoord1;\n}\n",viewDirPS:"void getViewDir() {\n\tdViewDirW = normalize(view_position - vPositionW);\n}\n",viewNormalVS:"#ifndef VIEWMATRIX\n#define VIEWMATRIX\nuniform mat4 matrix_view;\n#endif\nvec3 getViewNormal() {\n\treturn mat3(matrix_view) * vNormalW;\n}\n"},In={vertex_position:"POSITION",vertex_normal:"NORMAL",vertex_tangent:"TANGENT",vertex_texCoord0:"TEXCOORD0",vertex_texCoord1:"TEXCOORD1",vertex_texCoord2:"TEXCOORD2",vertex_texCoord3:"TEXCOORD3", vertex_texCoord4:"TEXCOORD4",vertex_texCoord5:"TEXCOORD5",vertex_texCoord6:"TEXCOORD6",vertex_texCoord7:"TEXCOORD7",vertex_color:"COLOR",vertex_boneIndices:"BLENDINDICES",vertex_boneWeights:"BLENDWEIGHT"};F.collectAttribs=ug;F.createShader=function(a,b,c,d){b=F[b];c=Fd(a)+"\n"+F[c];var e=ug(b);a.webgl2&&(b=Gd(a)+F.gles3VS+b,c=Gd(a)+F.gles3PS+c);return new re(a,{attributes:e,vshader:b,fshader:c,useTransformFeedback:d})};F.createShaderFromCode=Wa;var Kj=function(a,b,c){return"\n#ifdef MAPFLOAT\n"+a+ "\n#else\n"+F[b]+"\n#endif\n"},Lj=function(a,b,c){return"\n#ifdef MAPCOLOR\n"+a+"\n#else\n"+F[b]+"\n#endif\n"},ce=function(a,b,c){return"\n#ifdef MAPTEXTURE\n"+a+"\n#else\n"+F[b]+"\n#endif\n"},Mj=function(a,b,c){return"#undef MAPTEXTURECOLOR\n#ifdef MAPTEXTURE\n#ifdef MAPCOLOR\n#define MAPTEXTURECOLOR\n#endif\n#endif\n#ifdef MAPTEXTURECOLOR\n"+a+"\n#else\n"+F[b]+"\n#endif\n"},kh=function(a,b,c){return"#undef MAPTEXTUREFLOAT\n#ifdef MAPTEXTURE\n#ifdef MAPFLOAT\n#define MAPTEXTUREFLOAT\n#endif\n#endif\n#ifdef MAPTEXTUREFLOAT\n"+ a+"\n#else\n"+F[b]+"\n#endif\n"},de=function(a,b,c){return"\n#ifdef MAPVERTEX\n"+a+"\n#else\n"+F[b]+"\n#endif\n"},Nj=function(a,b,c){return"#undef MAPVERTEXCOLOR\n#ifdef MAPVERTEX\n#ifdef MAPCOLOR\n#define MAPVERTEXCOLOR\n#endif\n#endif\n#ifdef MAPVERTEXCOLOR\n"+a+"\n#else\n"+F[b]+"\n#endif\n"},lh=function(a,b,c){return"#undef MAPVERTEXFLOAT\n#ifdef MAPVERTEX\n#ifdef MAPFLOAT\n#define MAPVERTEXFLOAT\n#endif\n#endif\n#ifdef MAPVERTEXFLOAT\n"+a+"\n#else\n"+F[b]+"\n#endif\n"},zc=[],Oj={_oldChunkToNew:{aoTexPS:{n:"aoPS", f:ce},aoVertPS:{n:"aoPS",f:de},diffuseConstPS:{n:"diffusePS",f:Lj},diffuseTexPS:{n:"diffusePS",f:ce},diffuseTexConstPS:{n:"diffusePS",f:Mj},diffuseVertPS:{n:"diffusePS",f:de},diffuseVertConstPS:{n:"diffusePS",f:Nj},emissiveConstPS:{n:"emissivePS",f:Lj},emissiveTexPS:{n:"emissivePS",f:ce},emissiveTexConstPS:{n:"emissivePS",f:Mj},emissiveTexConstFloatPS:{n:"emissivePS",f:kh},emissiveVertPS:{n:"emissivePS",f:de},emissiveVertConstPS:{n:"emissivePS",f:Nj},emissiveVertConstFloatPS:{n:"emissivePS",f:lh}, glossConstPS:{n:"glossPS",f:Kj},glossTexPS:{n:"glossPS",f:ce},glossTexConstPS:{n:"glossPS",f:kh},glossVertPS:{n:"glossPS",f:de},glossVertConstPS:{n:"glossPS",f:lh},metalnessConstPS:{n:"metalnessPS",f:Kj},metalnessTexPS:{n:"metalnessPS",f:ce},metalnessTexConstPS:{n:"metalnessPS",f:kh},metalnessVertPS:{n:"metalnessPS",f:de},metalnessVertConstPS:{n:"metalnessPS",f:lh},opacityConstPS:{n:"opacityPS",f:Kj},opacityTexPS:{n:"opacityPS",f:ce},opacityTexConstPS:{n:"opacityPS",f:kh},opacityVertPS:{n:"opacityPS", f:de},opacityVertConstPS:{n:"opacityPS",f:lh},specularConstPS:{n:"specularPS",f:Lj},specularTexPS:{n:"specularPS",f:ce},specularTexConstPS:{n:"specularPS",f:Mj},specularVertPS:{n:"specularPS",f:de},specularVertConstPS:{n:"specularPS",f:Nj},transformBatchSkinnedVS:{n:"transformVS",f:function(a,b,c){return"\n#ifdef DYNAMICBATCH\n"+a+"\n#else\n"+F[b]+"\n#endif\n"}},transformInstancedVS:{n:"transformVS",f:function(a,b,c){return"\n#ifdef INSTANCING\n"+a+"\n#else\n"+F[b]+"\n#endif\n"}},transformPixelSnapVS:{n:"transformVS", f:function(a,b,c){return"\n#ifdef PIXELSNAP\n"+a+"\n#else\n"+F[b]+"\n#endif\n"}},transformScreenSpaceVS:{n:"transformVS",f:function(a,b,c){return"\n#ifdef SCREENSPACE\n"+a+"\n#else\n"+F[b]+"\n#endif\n"}},transformScreenSpaceBatchSkinned:{n:"transformVS",f:function(a,b,c){return"#undef SCREENSPACEBATCH\n#ifdef SCREENSPACE\n#ifdef BATCH\n#define SCREENSPACEBATCH\n#endif\n#endif\n#ifdef SCREENSPACEBATCH\n"+a+"\n#else\n"+F[b]+"\n#endif\n"}},transformSkinned:{n:"transformVS",f:function(a,b,c){return"\n#ifdef SKIN\n"+ a+"\n#else\n"+F[b]+"\n#endif\n"}},transformUv1:{n:"transformVS",f:function(a,b,c){return"\n#ifdef UV1LAYOUT\n"+a+"\n#else\n"+F[b]+"\n#endif\n"}}},optionsContext:{},optionsContextMin:{},generateKey:function(a){var b=function(f){var g=[],k;for(k in f)f.hasOwnProperty(k)&&"chunks"!==k&&"lights"!==k&&g.push(k);return g.sort()};if(a===this.optionsContextMin){this.propsMin||(this.propsMin=b(a));var c=this.propsMin}else a===this.optionsContext?(this.props||(this.props=b(a)),c=this.props):c=b(a);b="standard"; var d;for(d=0;db.length){var c=b.charAt(b.length-1);a=zc[a]-b.length;for(var d=0;d=b.pass;this.options=b;var h="",l="",n="",p=F,q={vertex_position:"POSITION"};if(b.chunks){var r={};for(A in p)if(p.hasOwnProperty(A))if(b.chunks[A]){var t=b.chunks[A];0<=t.indexOf("vertex_normal")&&(q.vertex_normal="NORMAL");0<=t.indexOf("vertex_tangent")&&(q.vertex_tangent= "TANGENT");0<=t.indexOf("vertex_texCoord0")&&(q.vertex_texCoord0="TEXCOORD0");0<=t.indexOf("vertex_texCoord1")&&(q.vertex_texCoord1="TEXCOORD1");0<=t.indexOf("vertex_color")&&(q.vertex_color="COLOR");0<=t.indexOf("vertex_boneWeights")&&(q.vertex_boneWeights="BLENDWEIGHT");0<=t.indexOf("vertex_boneIndices")&&(q.vertex_boneIndices="BLENDINDICES");r[A]=t}else r[A]=p[A];for(A in b.chunks)(p=this._oldChunkToNew[A])&&(r[p.n]=p.f(b.chunks[A],p.n,A));p=r}h=this._vsAddBaseCode(h,a,p,b);r=-1;if(!b.noShadow&& !b.twoSidedLighting){for(t=0;t=a.fragmentUniformsCount&&(h+=p.viewNormalVS,l+=" vNormalV\t= getViewNormal();\n"),(b.heightMap||b.normalMap||b.enableGGXSpecular)&&b.hasTangents?(q.vertex_tangent="TANGENT",h+= p.tangentBinormalVS,l+=" vTangentW = getTangent();\n vBinormalW = getBinormal();\n"):b.enableGGXSpecular&&(h+=p.tangentBinormalVS,l+=" vObjectSpaceUpW = getObjectSpaceUp();\n"),0<=r&&(u=b.lights[r]._type,l=(0===u?l+(" dLightDirNormW = light"+r+"_directionVS;\n"):l+(" getLightDirPoint(light"+r+"_positionVS);\n"))+this._nonPointShadowMapProjection(a,b.lights[r],"(light"+r+"_shadowMatrixVS, light"+r+"_shadowParamsVS);\n")));u=[];var x=[];for(A in zc){t=A+"Map";if(b[A+"VertexColor"]){var v= A+"VertexColorChannel";b[v]=this._correctChannel(A,b[v])}if(b[t]){v=t+"Channel";var w=t+"Transform";var y=t+"Uv";b[y]=Math.min(b[y],1);b[v]=this._correctChannel(A,b[v]);y=b[y];u[y]=!0;x[y]=x[y]||b[t]&&!b[w]}}b.forceUv1&&(u[1]=!0);for(t=0;2>t;t++)u[t]&&(q["vertex_texCoord"+t]="TEXCOORD"+t,h+=p["uv"+t+"VS"],l+=" vec2 uv"+t+" = getUv"+t+"();\n"),x[t]&&(l+=" vUv"+t+" = uv"+t+";\n");u=[h,n,l,[]];for(A in zc)t=A+"Map",b[t]&&(w=t+"Transform",b[w]&&(y=t+"Uv",this._setMapTransform(u,A,b[w],b[y])));h=u[0]; n=u[1];l=u[2];b.vertexColors&&(q.vertex_color="COLOR",l+=" vVertexColor = vertex_color;\n");if(b.useMorphPosition||b.useMorphNormal)b.useMorphTextureBased?(h+="#define MORPHING_TEXTURE_BASED\n",b.useMorphPosition&&(h+="#define MORPHING_TEXTURE_BASED_POSITION\n"),b.useMorphNormal&&(h+="#define MORPHING_TEXTURE_BASED_NORMAL\n"),q.morph_vertex_id="ATTR15",h+="attribute float morph_vertex_id;\n"):(h+="#define MORPHING\n",b.useMorphPosition?(q.morph_pos0="ATTR8",q.morph_pos1="ATTR9",q.morph_pos2="ATTR10", q.morph_pos3="ATTR11",h+="#define MORPHING_POS03\nattribute vec3 morph_pos0;\nattribute vec3 morph_pos1;\nattribute vec3 morph_pos2;\nattribute vec3 morph_pos3;\n"):b.useMorphNormal&&(q.morph_nrm0="ATTR8",q.morph_nrm1="ATTR9",q.morph_nrm2="ATTR10",q.morph_nrm3="ATTR11",h+="#define MORPHING_NRM03\nattribute vec3 morph_nrm0;\nattribute vec3 morph_nrm1;\nattribute vec3 morph_nrm2;\nattribute vec3 morph_nrm3;\n"),b.useMorphNormal?(q.morph_nrm4="ATTR12",q.morph_nrm5="ATTR13",q.morph_nrm6="ATTR14",q.morph_nrm7= "ATTR15",h+="#define MORPHING_NRM47\nattribute vec3 morph_nrm4;\nattribute vec3 morph_nrm5;\nattribute vec3 morph_nrm6;\nattribute vec3 morph_nrm7;\n"):(q.morph_pos4="ATTR12",q.morph_pos5="ATTR13",q.morph_pos6="ATTR14",q.morph_pos7="ATTR15",h+="#define MORPHING_POS47\nattribute vec3 morph_pos4;\nattribute vec3 morph_pos5;\nattribute vec3 morph_pos6;\nattribute vec3 morph_pos7;\n"));b.skin?(q.vertex_boneWeights="BLENDWEIGHT",q.vertex_boneIndices="BLENDINDICES",h+=ei(a,p),h+="#define SKIN\n"):b.useInstancing&& (h+="#define INSTANCING\n");b.screenSpace&&(h+="#define SCREENSPACE\n");b.pixelSnap&&(h+="#define PIXELSNAP\n");h=this._vsAddTransformCode(h,a,p,b);g&&(h+=p.normalVS);h=h+"\n"+p.startVS;var A=h=h+l+"}";t=n;n=""+this._addVaryingIfNeeded(h,"vec4","vMainShadowUv");n+=this._addVaryingIfNeeded(h,"vec4","vVertexColor");n+=this._addVaryingIfNeeded(h,"vec3","vPositionW");n+=this._addVaryingIfNeeded(h,"vec3","vNormalV");n+=this._addVaryingIfNeeded(h,"vec3","vNormalW");n+=this._addVaryingIfNeeded(h,"vec3", "vTangentW");n+=this._addVaryingIfNeeded(h,"vec3","vBinormalW");n+=this._addVaryingIfNeeded(h,"vec3","vObjectSpaceUpW");n+=this._addVaryingIfNeeded(h,"vec2","vUv0");n+=this._addVaryingIfNeeded(h,"vec2","vUv1");n+=t;A=n+A;h="";a.webgl2?(h=Gd(a),p.extensionVS&&(h+=p.extensionVS+"\n"),A=h+p.gles3VS+A):(p.extensionVS&&(h=p.extensionVS+"\n"),A=h+A);b.forceFragmentPrecision&&"highp"!=b.forceFragmentPrecision&&"mediump"!==b.forceFragmentPrecision&&"lowp"!==b.forceFragmentPrecision&&(b.forceFragmentPrecision= null);b.forceFragmentPrecision&&("highp"===b.forceFragmentPrecision&&"highp"!==a.maxPrecision&&(b.forceFragmentPrecision="mediump"),"mediump"===b.forceFragmentPrecision&&"lowp"===a.maxPrecision&&(b.forceFragmentPrecision="lowp"));h="";a.webgl2&&(h+=Gd(a));a.extStandardDerivatives&&!a.webgl2&&(h+="#extension GL_OES_standard_derivatives : enable\n\n");p.extensionPS&&(h+=p.extensionPS+"\n");a.webgl2&&(h+=p.gles3PS);h+=b.forceFragmentPrecision?"precision "+b.forceFragmentPrecision+" float;\n\n":Fd(a); if(18===b.pass)return h=h+"uniform vec4 uColor;\n"+n,b.alphaTest&&(h=h+"float dAlpha;\n"+this._addMap("opacity","opacityPS",b,p),h+=p.alphaTestPS),h+=se(),b.alphaTest&&(h+=" getOpacity();\n alphaTest(dAlpha);\n"),{attributes:q,vshader:A,fshader:h+"\tgl_FragColor = uColor;\n}\n"};if(2===b.pass)return h=h+"varying float vDepth;\n"+n+p.packDepthPS,b.alphaTest&&(h+="float dAlpha;\n",h+=this._addMap("opacity","opacityPS",b,p),h+=p.alphaTestPS),h+=se(),b.alphaTest&&(h+=" getOpacity();\n",h+=" alphaTest(dAlpha);\n"), h+="\tgl_FragColor = packFloat(vDepth);\n",h+="}\n",{attributes:q,vshader:A,fshader:h};if(k)return d=b.pass-3,u=Math.floor(d/5),d-=5*u,a.extStandardDerivatives&&!a.webgl2&&(h+="uniform vec2 polygonOffset;\n"),3===d?h=a.textureFloatHighPrecision?h+"#define VSM_EXPONENT 15.0\n\n":h+"#define VSM_EXPONENT 5.54\n\n":2===d&&(h+="#define VSM_EXPONENT 5.54\n\n"),0!==u&&(h+="uniform vec3 view_position;\n",h+="uniform float light_radius;\n"),h+=n,b.alphaTest&&(h+="float dAlpha;\n",h+=this._addMap("opacity", "opacityPS",b,p),h+=p.alphaTestPS),0!==d||a.webgl2&&1!==u?1===d&&(h+="vec2 encodeFloatRG( float v ) {\n",h+="\tvec2 enc = vec2(1.0, 255.0) * v;\n",h+="\tenc = fract(enc);\n",h+="\tenc -= enc.yy * vec2(1.0/255.0, 1.0/255.0);\n",h+="\treturn enc;\n",h+="}\n\n"):h+=p.packDepthPS,h+=se(),b.alphaTest&&(h+=" getOpacity();\n",h+=" alphaTest(dAlpha);\n"),h=1===u||(1===d||2===d||3===d)&&0!==u?h+" float depth = min(distance(view_position, vPositionW) / light_radius, 0.99999);\n":h+" float depth = gl_FragCoord.z;\n", 0!==d||a.webgl2&&1!==u?h=0===d||4===d?h+" gl_FragColor = vec4(1.0);\n":1===d?h+" gl_FragColor = vec4(encodeFloatRG(depth), encodeFloatRG(depth*depth));\n":h+p.storeEVSMPS:(a.extStandardDerivatives&&!a.webgl2&&(h+=" float minValue = 2.3374370500153186e-10; //(1.0 / 255.0) / (256.0 * 256.0 * 256.0);\n",h+=" depth += polygonOffset.x * max(abs(dFdx(depth)), abs(dFdy(depth))) + minValue * polygonOffset.y;\n"),h+=" gl_FragColor = packFloat(depth);\n"),h+="}\n",{attributes:q,vshader:A,fshader:h}; if(b.customFragmentShader)return a=h+b.customFragmentShader,{attributes:q,vshader:A,fshader:a,tag:1};h=this._fsAddBaseCode(h+n,a,p,b);b.detailModes&&(h+=p.detailModesPS);n=h;h="";0 0.00001) {\n",2!==u||e&&!l._cookieFalloff||(h+="\t dAtten *= getSpotEffect(light"+t+"_direction, light"+t+"_innerConeAngle, light"+t+"_outerConeAngle);\n",y=!0));h+="\t dAtten *= getLightDiffuse();\n";if(l.castShadows&&!b.noShadow){if(1===l._shadowType){g="VSM8";var E="0.0"}else 2===l._shadowType?(g="VSM16",E="5.54"):3=== l._shadowType?(g="VSM32",E=a.textureFloatHighPrecision?"15.0":"5.54"):g=4===l._shadowType?"PCF5x5":"PCF3x3";null!==g&&(1===u?(c="(light"+t+"_shadowMap, light"+t+"_shadowParams);\n",l._normalOffsetBias&&(h+="\t normalOffsetPointShadow(light"+t+"_shadowParams);\n"),h+="\t dAtten *= getShadowPoint"+g+c):(r===t?g+="VS":(c="(light"+t+"_shadowMatrix, light"+t+"_shadowParams);\n",h+=this._nonPointShadowMapProjection(a,b.lights[t],c)),2===u&&(g="Spot"+g),h+="\t dAtten *= getShadow"+g+"(light"+t+"_shadowMap, light"+ t+"_shadowParams"+(l._isVsm?", "+E:"")+");\n"))}h+="\t dDiffuseLight += dAtten * light"+t+"_color"+(e?" * dAtten3":"")+";\n";0c;c++){var g=a[c]; if(!g||g.width!==e||g.height!==f||!this.device._isBrowserInterface(g)){d=!0;break}}}else d=!0;if(!d)for(c=0;6>c;c++)this._levels[b][c]!==a[c]&&(this._levelsUpdated[b][c]=!0)}else this.device._isBrowserInterface(a)||(d=!0),d||(a!==this._levels[b]&&(this._levelsUpdated[b]=!0),e=a.width,f=a.height);if(d)if(this._height=this._width=4,this._cubemap)for(c=0;6>c;c++)this._levels[b][c]=null,this._levelsUpdated[b][c]=!0;else this._levels[b]=null,this._levelsUpdated[b]=!0;else 0===b&&(this._width=e,this._height= f),this._levels[b]=a;this._invalid===d&&d||(this._invalid=d,this.upload())},getSource:function(a){return this._levels[a||0]},unlock:function(){this.upload();this._lockedLevel=-1},upload:function(){this._needsUpload=!0;this._needsMipmapsUpload=this._mipmaps},getDds:function(){7!==this.format&&console.error("This format is not implemented yet");for(var a=128,b=0,c,d;this._levels[b];){if(this.cubemap)for(d=0;6>d;d++){if(!this._levels[b][d]){console.error("No level data for mip "+b+", face "+d);return}c= this._levels[b][d].length;if(!c){console.error("No byte array for mip "+b+", face "+d);return}a+=c}else{c=this._levels[b].length;if(!c){console.error("No byte array for mip "+b);return}a+=c}a+=this._levels[b].length;b++}a=new ArrayBuffer(a);d=new Uint32Array(a,0,32);b=528391;1b;b++)d[8+b]=0;d[19]=32;d[20]=65;d[21]=0;d[22]=32;d[23]=16711680;d[24]=65280;d[25]=255;d[26]=4278190080;d[27]=c;d[28]=e;d[29]=0;d[30]=0;d[31]=0;e=128;if(this.cubemap)for(d=0;6>d;d++)for(b=0;bb)if(ArrayBuffer.isView(a))a=a.subarray(0,b),c.set(a);else{var d;for(d=0;dd;d++){var u=r.array[r.index+d];if(0v&&(x.x=v);x.y>w&&(x.y=w);x.z>y&&(x.z=y);u.xE?v+=E:h+=E;0>C?w+=C:l+=C;0>B?A+=B:n+=B}x.x>v&&(x.x=v);x.y>w&&(x.y=w);x.z>A&&(x.z=A);u.xthis._geometryData.maxVertices&&(b=!0,this._geometryData.maxVertices=this._geometryData.vertexCount),b&&this.vertexBuffer&&(this.vertexBuffer.destroy(),this.vertexBuffer=null),b=this._geometryData.recreate,this._geometryData.indexCount>this._geometryData.maxIndices&&(b=!0,this._geometryData.maxIndices=this._geometryData.indexCount),b&&0=this.indexBuffer.length||!this.indexBuffer[0])this.indexBuffer[0]=new dc(this.device,65535l;l++){var n=g[h+c[l][0]],p=g[h+c[l][1]],q=n>p?p<<16|n:n<<16|p;void 0===k[q]&&(k[q]=0,b.push(n,p))}c=f.format}else{for(c=0;c>16},set:function(a){this._shaderDefs=this._shaderDefs&65535|a<<16;this._shader[0]=null;this._shader[1]=null}});Object.defineProperty(va.prototype,"instancingCount",{get:function(){return this.instancingData?this.instancingData.count:0},set:function(a){this.instancingData&&(this.instancingData.count= a)}});Object.assign(va.prototype,{syncAabb:function(){},_isVisible:function(a){if(this.visible){if(this.isVisibleFunc)return this.isVisibleFunc(a);var b=this.aabb.center;this._aabb._radiusVer!==this._aabbVer&&(this._aabb._radius=this._aabb.halfExtents.length(),this._aabb._radiusVer=this._aabbVer);Pj.radius=this._aabb._radius;Pj.center=b;return a.frustum.containsSphere(Pj)}return!1},updateKey:function(){var a=this.material;this._key[0]=(this.layer&15)<<27|(3===(a.alphaToCoverage||a.alphaTest?2:a.blendType)? 1:0)<<26|0|(a.id&33554431)<<0},setInstancing:function(a){a?(this.instancingData=new Ln(a.numVertices),this.instancingData.vertexBuffer=a,a.instancing=!0,this.cull=!1):(this.instancingData=null,this.cull=!0)},clearParameters:function(){this.parameters={}},getParameters:function(){return this.parameters},getParameter:function(a){return this.parameters[a]},setParameter:function(a,b,c){void 0===c&&(c=-524285);if(void 0===b&&"object"===typeof a){b=a;if(b.length){for(a=0;aa)return!1;this.morphTextureWidth=d;this.morphTextureHeight=l;g=!1;h=3;k=N.float2Half;this._textureFormat===Eb.FORMAT_HALF_FLOAT&&(g=!0,h=4);a=this.morphTextureWidth*this.morphTextureHeight*h;var n=g?new Uint16Array(a):new Float32Array(a); for(a=0;a=this.maxSubmitCount&&(d(e,f),e=0,f=!0))}(0a&&(this._activeTargets.sort(function(f,g){return f.absWeightc.refCount&&c.destroy();(c=b.skinInstance)&&(c=c.boneTexture)&&c.destroy();b.skinInstance=null;(c=b.morphInstance)&&c.destroy();b.morphInstance=null;b.material=null}},generateWireframe:function(){var a, b=[];for(a=0;athis._dirtyGroups.indexOf(a)&&this._dirtyGroups.push(a)};Ia.prototype.getGroupByName=function(a){var b=this._batchGroups,c;for(c in b)if(b.hasOwnProperty(c)&& b[c].name===a)return b[c];return null};Ia.prototype.getBatches=function(a){for(var b=[],c=this._batchList.length,d=0;dd._obj[a].indexOf(c)&&(d._obj[a].push(c),this.markGroupDirty(b))};Ia.prototype.remove=function(a,b,c){var d=this._batchGroups[b];d&&(c=d._obj[a].indexOf(c),0<=c&&(d._obj[a].splice(c,1),this.markGroupDirty(b)))};Ia.prototype._extractModel=function(a,b,c,d){if(!a.model||!a.model.model)return b;if(a.model.isStatic){d=this.scene.drawCalls;var e=a.model.meshInstances;for(c=0;ce.indexOf(d[c]._staticSource)|| b.push(d[c]));for(c=0;ca.indexOf(this._batchList[b].batchGroupId)? d.push(this._batchList[b]):this.destroy(this._batchList[b]);this._batchList=d;this._collectAndRemoveModels(c,a);if(a===this._dirtyGroups)this._dirtyGroups.length=0;else{d=[];for(b=0;ba.indexOf(this._dirtyGroups[b])&&d.push(this._dirtyGroups[b]);this._dirtyGroups=d}var e,f;for(f in c)if(c.hasOwnProperty(f)&&(b=c[f],a=this._batchGroups[f])){var g=this.prepare(b,a.dynamic,a.maxAabbSize,a._ui||a._sprite);for(b=0;b=e){t=t.concat(r.slice(p)); break}if(a!==J.material||x!==J.layer||D!==J.mesh.vertexBuffer.format.batchingHash||G!==J.mesh.primitive[0].indexed||v!==J._shaderDefs||B+J.mesh.vertexBuffer.getNumVertices()>f)u(J);else if(k.copy(g),k.add(J.aabb),k.halfExtents.x>c||k.halfExtents.y>c||k.halfExtents.z>c)u(J);else if(!y||(l=J.stencilFront)&&y.func==l.func&&y.zpass==l.zpass)if(C!=gi(J))u(J);else if(Mn(w,J.parameters)){var R=J._staticLightList;if(A&&R){if(!Nn(A,R)){u(J);continue}}else if(A||R){u(J);continue}d&&h&&h.intersects(J.aabb)&& J.drawOrder!==E?u(J):(g.add(J.aabb),B+=J.mesh.vertexBuffer.getNumVertices(),n[q].push(J))}else u(J);else u(J)}q++;r=t}return n};Ia.prototype.create=function(a,b,c){this._init||(this.transformVS="#define BONE_LIMIT "+this.device.getBoneLimit()+"\n#define DYNAMICBATCH\n"+F.transformVS,this.skinTexVS=F.skinBatchTexVS,this.skinConstVS=F.skinBatchConstVS,this.vertexFormats={},this._init=!0);var d,e,f=null,g=null,k=0,h=0,l=null;for(d=0;d=k?Uint16Array:Uint32Array)(h);for(q in f){var v= f[q];v.typeArrayType=Dd[v.dataType];v.elementByteSize=qf[v.dataType];v.buffer=new v.typeArrayType(k*v.numComponents)}for(d=0;dgi(l.origMeshInstances[0]);l.meshInstance=a;this.update(l);b=new sb;b.meshInstances=[l.meshInstance];b.castShadows=l.origMeshInstances[0].castShadows;l.model=b}return l};Ia.prototype.update=function(a){a._aabb.copy(a.origMeshInstances[0].aabb);for(var b=1;be.indexOf(d)&&e.push(d),!b&&d.castShadow&&0>g.indexOf(d)&&g.push(d),!this.passThrough&&0<=c&&f._shaderVersion!==c&&(f.updateShader!==ka.prototype.updateShader&&(f.clearVariants(),f.shader=null),f._shaderVersion=c);this.passThrough||(this._dirty=!0)};ma.prototype.removeMeshInstances=function(a,b){var c,d,e=this.opaqueMeshInstances,f=this.transparentMeshInstances,g=this.shadowCasters;for(c=0;ch&&(h=d),l++;else if(0<=h)break}0<=h&&e.splice(h,l);h=-1;l=0;n=f.length;for(d=0;dh&&(h=d),l++;else if(0<=h)break}0<=h&&f.splice(h,l);b||(d=g.indexOf(k),0<=d&&g.splice(d,1))}this._dirty=!0};ma.prototype.clearMeshInstances=function(a){if(0!==this.opaqueMeshInstances.length||0!==this.transparentMeshInstances.length||!a&&0!== this.shadowCasters.length)this.opaqueMeshInstances.length=0,this.transparentMeshInstances.length=0,a||(this.shadowCasters.length=0),this.passThrough||(this._dirty=!0)};ma.prototype.addLight=function(a){0<=this._lightComponents.indexOf(a)||(this._lightComponents.push(a),this._lights.push(a.light),this._dirtyLights=!0,this._generateLightHash())};ma.prototype.removeLight=function(a){var b=this._lightComponents.indexOf(a);0>b||(this._lightComponents.splice(b,1),b=this._lights.indexOf(a.light),this._lights.splice(b, 1),this._dirtyLights=!0,this._generateLightHash())};ma.prototype.clearLights=function(){this._lightComponents.length=0;this._lights.length=0;this._dirtyLights=!0};ma.prototype.addShadowCasters=function(a){for(var b,c=this.shadowCasters,d=0;dc.indexOf(b)&&c.push(b);this._dirtyLights=!0};ma.prototype.removeShadowCasters=function(a){for(var b,c=this.shadowCasters,d=0;da||(this.cameras.splice(a,1),this._generateCameraHash(),this.instances.clearVisibleLists(a))};ma.prototype.clearCameras=function(){this._cameraHash=this.cameras.length=0;this._dirtyCameras=!0};ma.prototype._sortCameras=function(){this._generateCameraHash()};ma.prototype._calculateSortDistances=function(a, b,c,d){var e;for(e=0;e=f.layer))if(f.calculateSortDistance)f.zdist=f.calculateSortDistance(f,c,d);else{var g=f.aabb.center;var k=g.x-c.x;var h=g.y-c.y;g=g.z-c.z;f.zdist=k*d.x+h*d.y+g*d.z}}};ma.prototype._sortVisible=function(a,b,c){var d=this.instances,e=a?this.transparentSortMode:this.opaqueSortMode;if(0!==e)if(a=a?d.visibleTransparent[c]:d.visibleOpaque[c],5===e)ph=b.getPosition(),qh=b.forward,this.customCalculateSortValues&&this.customCalculateSortValues(a.list, a.length,ph,qh),a.list.length!==a.length&&(a.list.length=a.length),this.customSortCallback&&a.list.sort(this.customSortCallback);else{if(3===e||4===e)ph=b.getPosition(),qh=b.forward,this._calculateSortDistances(a.list,a.length,ph,qh);a.list.length!==a.length&&(a.list.length=a.length);a.list.sort(cp[e])}};for(var bm=(new K).mul2((new K).setTranslate(.5,.5,.5),(new K).setScale(.5,.5,.5)),dp={r:1,g:2,b:3,a:4},cm=[(new Y).setFromEulerAngles(0,90,180),(new Y).setFromEulerAngles(0,-90,180),(new Y).setFromEulerAngles(90, 0,0),(new Y).setFromEulerAngles(-90,0,0),(new Y).setFromEulerAngles(0,180,180),(new Y).setFromEulerAngles(0,0,180)],Fk=[{},{},{},{},{}],fe=new Float32Array(2),Tf={x:1,y:1,z:0,w:0},ge=new K,rh=new K,dm=new K,Xb=new K,Bb=new K,em=new xb,nc=new K,Yb,Pc=new K,Qc=new K,Ve=new K,We=new K,Xe=new z,Ye=new z,Uf,Vf,fm=new K,gm=new K,hm=new K,im=new K,sh=new z,jm=new z,km=new z,lm=new z,he={center:null,radius:0},th=new oa,Wf=[0,0,0,0],Ze,Cb,Uj,uh,Hk={},$e,af,vh=null,ua=[],mm=0;8>mm;mm++)ua.push(new z);var za= [new z,new z,new z,new z,new z,new z,new z,new z];Object.assign(xg.prototype,{sortCompare:function(a,b){if(a.layer===b.layer){if(a.drawOrder&&b.drawOrder)return a.drawOrder-b.drawOrder;if(a.zdist&&b.zdist)return b.zdist-a.zdist;if(a.zdist2&&b.zdist2)return a.zdist2-b.zdist2}return b._key[0]-a._key[0]},sortCompareMesh:function(a,b){if(a.layer===b.layer){if(a.drawOrder&&b.drawOrder)return a.drawOrder-b.drawOrder;if(a.zdist&&b.zdist)return b.zdist-a.zdist}$e=a._key[0];af=b._key[0];return $e===af&&a.mesh&& b.mesh?b.mesh.id-a.mesh.id:af-$e},depthSortCompare:function(a,b){$e=a._key[1];af=b._key[1];return $e===af&&a.mesh&&b.mesh?b.mesh.id-a.mesh.id:af-$e},lightCompare:function(a,b){return a.key-b.key},getShadowCamera:function(a,b){var c=b._shadowCamera;if(null===c){c=b._shadowType;var d=4===c||0===c&&a.webgl2;1===b._type&&(d=!1);var e=new pa;e.clearColor=1<=c&&3>=c?new L(0,0,0,0):new L(1,1,1,1);e.clearColorBuffer=!d;e.clearDepthBuffer=!0;e.clearStencilBuffer=!1;e.node=new Z;c=b._shadowCamera=e;Gk(a,b)}else d= c.renderTarget,d.width===b._shadowResolution&&d.height===b._shadowResolution||Gk(a,b);return c},updateCameraFrustum:function(a){if(a.vrDisplay&&a.vrDisplay.presenting){Yb=a.vrDisplay.combinedProj;var b=a._node.parent;b?Bb.copy(b.getWorldTransform()).mul(a.vrDisplay.combinedViewInv).invert():Bb.copy(a.vrDisplay.combinedView);Xb.copy(Bb).invert();this.viewInvId.setValue(Xb.data);nc.mul2(Yb,Bb);a.frustum.setFromMat4(nc)}else if(a.xr&&a.xr.views.length){b=a.xr.views[0];nc.mul2(b.projMat,b.viewOffMat); a.frustum.setFromMat4(nc);return}Yb=a.projectionMatrix;a.calculateProjection&&a.calculateProjection(Yb,0);if(a.calculateTransform)a.calculateTransform(Xb,0);else{b=a._node.getPosition();var c=a._node.getRotation();Xb.setTRS(b,c,z.ONE);this.viewInvId.setValue(Xb.data)}Bb.copy(Xb).invert();nc.mul2(Yb,Bb);a.frustum.setFromMat4(nc)},setCamera:function(a,b,c,d){var e=a.vrDisplay,f;if(e&&e.presenting){Uf=e.leftProj;Vf=e.rightProj;Yb=e.combinedProj;a.calculateProjection&&(a.calculateProjection(Uf,1),a.calculateProjection(Vf, 2),a.calculateProjection(Yb,0));if(a.calculateTransform)a.calculateTransform(Pc,1),a.calculateTransform(Qc,2),a.calculateTransform(Xb,0),Ve.copy(Pc).invert(),We.copy(Qc).invert(),Bb.copy(Xb).invert();else if(f=a._node.parent){var g=f.getWorldTransform();Pc.mul2(g,e.leftViewInv);Qc.mul2(g,e.rightViewInv);Ve.copy(Pc).invert();We.copy(Qc).invert();Bb.copy(f.getWorldTransform()).mul(e.combinedViewInv).invert()}else Pc.copy(e.leftViewInv),Qc.copy(e.rightViewInv),Ve.copy(e.leftView),We.copy(e.rightView), Bb.copy(e.combinedView);yg(fm,Ve);yg(gm,We);hm.mul2(Uf,Ve);im.mul2(Vf,We);Xe.x=Pc.data[12];Xe.y=Pc.data[13];Xe.z=Pc.data[14];Ye.x=Qc.data[12];Ye.y=Qc.data[13];Ye.z=Qc.data[14];nc.mul2(Yb,Bb);a.frustum.setFromMat4(nc)}else if(a.xr&&a.xr.session){(f=a._node.parent)&&(g=f.getWorldTransform());e=a.xr.views;for(var k=0;kb;b++)this.ambientColor[b]=Math.pow(this.ambientColor[b],2.2);this.ambientId.setValue(this.ambientColor);this.exposureId.setValue(a.exposure);a.skyboxModel&&this.skyboxIntensityId.setValue(a.skyboxIntensity)},_resolveLight:function(a,b){var c="light"+b;this.lightColorId[b]=a.resolve(c+"_color");this.lightDir[b]=new Float32Array(3);this.lightDirId[b]=a.resolve(c+"_direction");this.lightShadowMapId[b]=a.resolve(c+"_shadowMap");this.lightShadowMatrixId[b]=a.resolve(c+"_shadowMatrix"); this.lightShadowParamsId[b]=a.resolve(c+"_shadowParams");this.lightShadowMatrixVsId[b]=a.resolve(c+"_shadowMatrixVS");this.lightShadowParamsVsId[b]=a.resolve(c+"_shadowParamsVS");this.lightDirVs[b]=new Float32Array(3);this.lightDirVsId[b]=a.resolve(c+"_directionVS");this.lightRadiusId[b]=a.resolve(c+"_radius");this.lightPos[b]=new Float32Array(3);this.lightPosId[b]=a.resolve(c+"_position");this.lightInAngleId[b]=a.resolve(c+"_innerConeAngle");this.lightOutAngleId[b]=a.resolve(c+"_outerConeAngle"); this.lightPosVsId[b]=a.resolve(c+"_positionVS");this.lightCookieId[b]=a.resolve(c+"_cookie");this.lightCookieIntId[b]=a.resolve(c+"_cookieIntensity");this.lightCookieMatrixId[b]=a.resolve(c+"_cookieMatrix");this.lightCookieOffsetId[b]=a.resolve(c+"_cookieOffset")},dispatchDirectLights:function(a,b,c){var d=a.length,e,f=0;this.mainLight=-1;var g=this.device.scope;for(e=0;ethis.mainLight&&(this.lightShadowMatrixVsId[f].setValue(k._shadowMatrix.data),this.lightShadowParamsVsId[f].setValue(l),k._direction.normalize(),this.lightDirVs[f][0]=k._direction.x,this.lightDirVs[f][1]= k._direction.y,this.lightDirVs[f][2]=k._direction.z,this.lightDirVsId[f].setValue(this.lightDirVs[f]),this.mainLight=e)}f++}return f},dispatchPointLight:function(a,b,c,d){var e=c._node.getWorldTransform();this.lightColorId[d]||this._resolveLight(b,d);this.lightRadiusId[d].setValue(c.attenuationEnd);this.lightColorId[d].setValue(a.gammaCorrection?c._linearFinalColor:c._finalColor);e.getTranslation(c._position);this.lightPos[d][0]=c._position.x;this.lightPos[d][1]=c._position.y;this.lightPos[d][2]= c._position.z;this.lightPosId[d].setValue(this.lightPos[d]);c.castShadows&&(this.lightShadowMapId[d].setValue(c._shadowCamera.renderTarget.colorBuffer),a=c._rendererParams,4!==a.length&&(a.length=4),a[0]=c._shadowResolution,a[1]=c._normalOffsetBias,a[2]=c.shadowBias,a[3]=1/c.attenuationEnd,this.lightShadowParamsId[d].setValue(a));c._cookie&&(this.lightCookieId[d].setValue(c._cookie),this.lightShadowMatrixId[d].setValue(e.data),this.lightCookieIntId[d].setValue(c.cookieIntensity))},dispatchSpotLight:function(a, b,c,d){var e=c._node.getWorldTransform();this.lightColorId[d]||this._resolveLight(b,d);this.lightInAngleId[d].setValue(c._innerConeAngleCos);this.lightOutAngleId[d].setValue(c._outerConeAngleCos);this.lightRadiusId[d].setValue(c.attenuationEnd);this.lightColorId[d].setValue(a.gammaCorrection?c._linearFinalColor:c._finalColor);e.getTranslation(c._position);this.lightPos[d][0]=c._position.x;this.lightPos[d][1]=c._position.y;this.lightPos[d][2]=c._position.z;this.lightPosId[d].setValue(this.lightPos[d]); e.getY(c._direction).scale(-1);c._direction.normalize();this.lightDir[d][0]=c._direction.x;this.lightDir[d][1]=c._direction.y;this.lightDir[d][2]=c._direction.z;this.lightDirId[d].setValue(this.lightDir[d]);c.castShadows&&(c._isVsm?a=-2E-4:(a=20*c.shadowBias,!this.device.webgl2&&this.device.extStandardDerivatives&&(a*=-100)),b=c._isVsm?c.vsmBias/(c.attenuationEnd/7):c._normalOffsetBias,this.lightShadowMapId[d].setValue(c._isPcf&&this.device.webgl2?c._shadowCamera.renderTarget.depthBuffer:c._shadowCamera.renderTarget.colorBuffer), this.lightShadowMatrixId[d].setValue(c._shadowMatrix.data),e=c._rendererParams,4!==e.length&&(e.length=4),e[0]=c._shadowResolution,e[1]=b,e[2]=a,e[3]=1/c.attenuationEnd,this.lightShadowParamsId[d].setValue(e));c._cookie&&(this.lightCookieId[d].setValue(c._cookie),c.castShadows||(a=this.getShadowCamera(this.device,c),b=a._node,b.setPosition(c._node.getPosition()),b.setRotation(c._node.getRotation()),b.rotateLocal(-90,0,0),a.projection=0,a.aspectRatio=1,a.fov=2*c._outerConeAngle,ge.setTRS(b.getPosition(), b.getRotation(),z.ONE).invert(),rh.mul2(a.projectionMatrix,ge),c._shadowMatrix.mul2(bm,rh)),this.lightShadowMatrixId[d].setValue(c._shadowMatrix.data),this.lightCookieIntId[d].setValue(c.cookieIntensity),c._cookieTransform&&(c._cookieTransformUniform[0]=c._cookieTransform.x,c._cookieTransformUniform[1]=c._cookieTransform.y,c._cookieTransformUniform[2]=c._cookieTransform.z,c._cookieTransformUniform[3]=c._cookieTransform.w,this.lightCookieMatrixId[d].setValue(c._cookieTransformUniform),c._cookieOffsetUniform[0]= c._cookieOffset.x,c._cookieOffsetUniform[1]=c._cookieOffset.y,this.lightCookieOffsetId[d].setValue(c._cookieOffsetUniform)))},dispatchLocalLights:function(a,b,c,d,e){var f=a[1];a=a[2];var g=f.length,k=a.length,h=d,l=this.device.scope;for(d=0;de._visibleLength[b])continue;h=e._visibleCameraSettings[b];k.setPosition(h.x,h.y,h.z);g.orthoHeight=h.orthoHeight;g.farClip=h.farClip;h=b}else if(2===f){var n=k.getPosition();this.viewPos[0]=n.x;this.viewPos[1]=n.y;this.viewPos[2]=n.z;this.viewPosId.setValue(this.viewPos);this.shadowMapLightRadiusId.setValue(e.attenuationEnd)}else 1=== f&&(n=k.getPosition(),this.viewPos[0]=n.x,this.viewPos[1]=n.y,this.viewPos[2]=n.z,this.viewPosId.setValue(this.viewPos),this.shadowMapLightRadiusId.setValue(e.attenuationEnd),l=6);1!==f&&(ge.setTRS(k.getPosition(),k.getRotation(),z.ONE).invert(),rh.mul2(g.projectionMatrix,ge),e._shadowMatrix.mul2(bm,rh));c.webgl2?1===f?c.setDepthBias(!1):(c.setDepthBias(!0),c.setDepthBiasValues(-1E3*e.shadowBias,-1E3*e.shadowBias)):c.extStandardDerivatives&&(1===f?(this.polygonOffset[0]=0,this.polygonOffset[1]=0): (this.polygonOffset[0]=-1E3*e.shadowBias,this.polygonOffset[1]=-1E3*e.shadowBias),this.polygonOffsetId.setValue(this.polygonOffset));1===e.shadowUpdateMode&&(e.shadowUpdateMode=0);this._shadowMapUpdates+=l;c.setBlending(!1);c.setDepthWrite(!0);c.setDepthTest(!0);e._isPcf&&c.webgl2&&1!==f?c.setColorWrite(!1,!1,!1,!1):c.setColorWrite(!0,!0,!0,!0);for(h?l=h+1:h=0;hd.cull&&(c.flipFaces&&(a*=-1),b&&(a*=-1),b=c.node.worldTransform, b.getX(sh),b.getY(jm),b.getZ(km),sh.cross(sh,jm),0>sh.dot(km)&&(a*=-1)),e=0>a?2===d.cull?1:2:d.cull);this.device.setCullMode(e)},setVertexBuffers:function(a,b){a.setVertexBuffer(b.vertexBuffer)},setMorphing:function(a,b){if(b)if(b.morph.useTextureMorph)a.setVertexBuffer(b.morph.vertexBufferIds),this.morphPositionTex.setValue(b.texturePositions),this.morphNormalTex.setValue(b.textureNormals),this.morphTexParams.setValue(b._textureParams);else{for(var c,d,e=0;e=v;v++)for(d=0;df;f++){d=D[3*e+f+J];d=d*I+l;var W=E[d];var Q=E[d+1];d=E[d+2];WS&&(S= W);Q>ba&&(ba=Q);d>ha&&(ha=d)}d=6*e;y[d]=n;y[d+1]=p;y[d+2]=T;y[d+3]=S;y[d+4]=ba;y[d+5]=ha}for(W=0;W=Q.x&&y[d+1]<=n.y&&y[d+4]>=Q.y&&y[d+2]<=n.z&&y[d+5]>=Q.z&&(x[e]|=f,R=!0);if(R){R={};for(e=0;eS&&(S=W),Q>ba&&(ba=Q),d>ha&&(ha=d);q.set(n,p,T);r.set(S,ba,ha);e=new oa;e.setMinMax(q,r);G=new rb(g);G.vertexBuffer=v;G.indexBuffer[0]=D;G.primitive[0].type=4;G.primitive[0].base=0;G.primitive[0].count=f.length;G.primitive[0].indexed= !0;G.aabb=e;D=new va(B.node,G,B.material);D.isStatic=B.isStatic;D.visible=B.visible;D.layer=B.layer;D.castShadow=B.castShadow;D._receiveShadow=B._receiveShadow;D.cull=B.cull;D.pick=B.pick;D.mask=B.mask;D.parameters=B.parameters;D._shaderDefs=B._shaderDefs;D._staticSource=B;D._staticLightList=B._staticLightList?B._staticLightList:[];for(e=0;eD._staticLightList.indexOf(G)&&D._staticLightList.push(G));D._staticLightList.sort(this.lightCompare);h.push(D)}}else h.push(B)}}else h.push(B)}a.length= h.length;for(c=0;cl;l++)dm.transformPoint(ua[l],ua[l]);k=h=c=1E6;r=q=p=-1E6;for(l=0;8>l;l++){var t=ua[l];t.xr&&(r=t.x);t.yq&&(q=t.y);t.zp&&(p=t.z)}l=n/a._shadowResolution;k=Math.floor((k-.5*(n-(r-k)))/l)*l;h=Math.floor((h-.5*(n-(q-h)))/l)*l;k= .5*(k+n+k);h=.5*(h+n+h);f.translateLocal(k,h,1E5);e.projection=1;e.nearClip=0;e.farClip=2E5;e.aspectRatio=1;e.orthoHeight=.5*n;this.updateCameraFrustum(e);q=!0;(p=a._visibleList[d])||(p=a._visibleList[d]=[]);l=n=a._visibleLength[d]=0;for(r=b.length;lp;++p)ge.transformPoint(za[p],za[p]),n=za[p].z,nb&&(b=n);p=b;l>c&&(c=l);f.setPosition(g.getPosition());f.translateLocal(k,h,p+.01);e.farClip=p-c;(g=a._visibleCameraSettings[d])||(g=a._visibleCameraSettings[d]={});a=f.getPosition();g.x=a.x;g.y=a.y;g.z=a.z; g.orthoHeight=e.orthoHeight;g.farClip=e.farClip},gpuUpdate:function(a){this.updateGpuSkinMatrices(a);this.updateMorphing(a)},setSceneConstants:function(){var a,b=this.device,c=this.scene;this.dispatchGlobalLights(c);if("none"!==c.fog){this.fogColor[0]=c.fogColor.r;this.fogColor[1]=c.fogColor.g;this.fogColor[2]=c.fogColor.b;if(c.gammaCorrection)for(a=0;3>a;a++)this.fogColor[a]=Math.pow(this.fogColor[a],2.2);this.fogColorId.setValue(this.fogColor);"linear"===c.fog?(this.fogStartId.setValue(c.fogStart), this.fogEndId.setValue(c.fogEnd)):this.fogDensityId.setValue(c.fogDensity)}this._screenSize[0]=b.width;this._screenSize[1]=b.height;this._screenSize[2]=1/b.width;this._screenSize[3]=1/b.height;this.screenSizeId.setValue(this._screenSize)},renderComposition:function(a){var b=this.device,c,d=a._renderedRt,e=a._renderedByCam,f=a._renderedLayer,g,k,h,l;this.scene.updateSkybox&&(this.scene._updateSkybox(b),this.scene.updateSkybox=!1);this.beginLayers(a);a._update()&2&&(this.scene.updateLitShaders=!0); this.beginFrame(a);this.setSceneConstants();var n=0;for(g=0;gthis.layers.indexOf(a)&& this.layers.push(a)};zg.prototype.getLayerIdx=function(a){return this.layerToBatch[a.id]};zg.prototype.addLayerIdx=function(a,b){this.layerToBatch[b.id]=a};Object.assign(Ik.prototype,{init:function(a,b,c,d){this.mesh||(this.mesh=new rb(a),this.mesh.primitive[0].type=1,this.mesh.primitive[0].base=0,this.mesh.primitive[0].indexed=!1,this.material=new dd,this.material.vertexColors=!0,this.material.blend=!0,this.material.blendType=2,this.material.update());for(this.layer=c;this.linesUsed+d>this.numLinesAllocated;)this.vb&& (this.vb.destroy(),this.vb=null),this.numLinesAllocated*=2;this.vertexFormat=b;this.vb||(this.vb=new ab(a,b,2*this.numLinesAllocated,1),this.mesh.vertexBuffer=this.vb,this.vbRam=new DataView(this.vb.lock()),this.meshInstance||(wh.worldTransform=K.IDENTITY,wh._dirtyWorld=wh._dirtyNormal=!1,this.meshInstance=new va(wh,this.mesh,this.material),this.meshInstance.cull=!1))},addLines:function(a,b){for(var c=!!b.length,d=2*this.linesUsed*this.vertexFormat.size,e,f=0;fthis._meshInstances.indexOf(g)&&(this._meshInstances.push(g),g.material&&g.material._dirtyBlend&&(this._dirtyBlend=!0,g.material._dirtyBlend=!1))}f=e.transparentMeshInstances;for(b=0;bthis._meshInstances.indexOf(g)&&(this._meshInstances.push(g),g.material&&g.material._dirtyBlend&&(this._dirtyBlend=!0,g.material._dirtyBlend= !1))}for(a=0;ag&&(this._lights.push(k),g=this._lights.length-1),(k=this._lightShadowCasters[g])||(this._lightShadowCasters[g]=[]);this._sortLights(this);this._dirtyLights=!1;for(a=0;athis._meshInstances.indexOf(k[g])?(k[g]=k[k.length-1],--k.length):g++;for(g=0;gk.indexOf(h[g])&&k.push(h[g])}if(d&2||this._dirtyCameras)for(this._globalLightCameras.length=0,f=this._sortedLights[0],b=0;be._sortedLights[0].indexOf(k)))for(g=0;gg&&this.cameras.push(f);this._renderList.length=0;for(a=g=this._renderListCamera.length=0;ag||f.push(g);this._globalLightCameraIds.push(f)}return d};xa.prototype._isLayerAdded=function(a){return 0<=this.layerList.indexOf(a)?!0:!1};xa.prototype._isSublayerAdded=function(a,b){for(var c=0;cthis.layerList.indexOf(a)&&this.fire("remove",a);break}};xa.prototype.pushTransparent=function(a){this._isSublayerAdded(a,!0)||(this.layerList.push(a),this._transparentOrder[a.id]= this.subLayerList.push(!0)-1,this.subLayerEnabled.push(!0),this._dirtyCameras=this._dirtyLights=this._dirty=!0,this.fire("add",a))};xa.prototype.insertTransparent=function(a,b){this._isSublayerAdded(a,!0)||(this.layerList.splice(b,0,a),this.subLayerList.splice(b,0,!0),this._updateTransparentOrder(b,this.subLayerList.length-1),this.subLayerEnabled.splice(b,0,!0),this._dirtyCameras=this._dirtyLights=this._dirty=!0,this.fire("add",a))};xa.prototype.removeTransparent=function(a){for(var b=0,c=this.layerList.length;b< c;b++)if(this.layerList[b]===a&&this.subLayerList[b]){this.layerList.splice(b,1);this.subLayerList.splice(b,1);c--;this._updateTransparentOrder(b,c-1);this.subLayerEnabled.splice(b,1);this._dirtyCameras=this._dirtyLights=this._dirty=!0;0>this.layerList.indexOf(a)&&this.fire("remove",a);break}};xa.prototype._getSublayerIndex=function(a,b){var c=this.layerList.indexOf(a);return 0>c||this.subLayerList[c]!==b&&(c=this.layerList.indexOf(a,c+1),0>c||this.subLayerList[c]!==b)?-1:c};xa.prototype.getOpaqueIndex= function(a){return this._getSublayerIndex(a,!1)};xa.prototype.getTransparentIndex=function(a){return this._getSublayerIndex(a,!0)};xa.prototype.getLayerById=function(a){for(var b=0;bc;c++)B.setValue(lb),La(e,Da,r),B.setValue(qc),La(e,Cc,r);for(c=0;cf;f++)Wj.data[f]=l.data[f];Xj.copy(Wj);Xj.invert();Uc=h.meshInstance.node.localScale;om=Math.max(Math.max(Uc.x,Uc.y),Uc.z)}f=null===h.meshInstance.node||h.localSpace?z.ZERO:h.meshInstance.node.getPosition();var n=h.camera?h.camera._node.getPosition():z.ZERO,p=h.useMesh?17:15,q=h.precision-1;for(l=0;l=v-g||v>=x)&&this.calcSpawnPosition(c,d,e,f,r);var B=0v&&(c[4*r+3+8*h.numParticlesPot]=-1):(v>=x&&(v-=Math.max(x,(h.numParticles-1)*u),c[4*r+3+8*h.numParticlesPot]=h.loop?1:-1),0>v&&h.loop&&(c[4*r+3+8*h.numParticlesPot]=1));0>c[4*r+3+8*h.numParticlesPot]&&(B=!1);c[4*r+3+4*h.numParticlesPot]=v;for(J=0;Je;e++)for(d=0;16>d;d++){var f=d+1-8.5;var g=e+1-8.5;g=Math.max(Math.min(1-Math.max(Math.min(Math.sqrt(f*f+g*g)/16,1),0)-.5,1),0);f=16*e+d;c[4*f]=1;c[4*f+1]=1;c[4*f+2]=1;c[4*f+3]=g}$b.DEFAULT_PARAM_TEXTURE=Zb(a,16,16,c,7,1,!0);$b.DEFAULT_PARAM_TEXTURE.minFilter=1;$b.DEFAULT_PARAM_TEXTURE.magFilter= 1}Kk=this;Dg=b;U("numParticles",1);this.numParticles>a.maxTextureSize&&(console.warn("WARNING: can't create more than "+a.maxTextureSize+" particles on this device."),this.numParticles=a.maxTextureSize);U("rate",1);U("rate2",this.rate);U("lifetime",50);U("emitterExtents",new z(0,0,0));U("emitterExtentsInner",new z(0,0,0));U("emitterRadius",0);U("emitterRadiusInner",0);U("emitterShape",0);U("initialVelocity",1);U("wrap",!1);U("localSpace",!1);U("screenSpace",!1);U("wrapBounds",null);U("colorMap",$b.DEFAULT_PARAM_TEXTURE); U("normalMap",null);U("loop",!0);U("preWarm",!1);U("sort",0);U("mode",0);U("scene",null);U("lighting",!1);U("halfLambert",!1);U("intensity",1);U("stretch",0);U("alignToMotion",!1);U("depthSoftening",0);U("mesh",null);U("particleNormal",new z(0,1,0));U("orientation",0);U("depthWrite",!1);U("noFog",!1);U("blendType",2);U("node",null);U("startAngle",0);U("startAngle2",this.startAngle);U("animTilesX",1);U("animTilesY",1);U("animStartFrame",0);U("animNumFrames",1);U("animNumAnimations",1);U("animIndex", 0);U("randomizeAnimIndex",!1);U("animSpeed",1);U("animLoop",!0);this._gpuUpdater=new Cg(this,a);this._cpuUpdater=new ki(this);this.constantLightCube=a.scope.resolve("lightCube[0]");this.emitterPosUniform=new Float32Array(3);this.wrapBoundsUniform=new Float32Array(3);this.emitterScaleUniform=new Float32Array([1,1,1]);U("colorGraph",ep);U("colorGraph2",this.colorGraph);U("scaleGraph",vm);U("scaleGraph2",this.scaleGraph);U("alphaGraph",vm);U("alphaGraph2",this.alphaGraph);U("localVelocityGraph",wm); U("localVelocityGraph2",this.localVelocityGraph);U("velocityGraph",wm);U("velocityGraph2",this.velocityGraph);U("rotationSpeedGraph",um);U("rotationSpeedGraph2",this.rotationSpeedGraph);U("radialSpeedGraph",um);U("radialSpeedGraph2",this.radialSpeedGraph);this.lightCube=new Float32Array(18);this.lightCubeDir=Array(6);this.lightCubeDir[0]=new z(-1,0,0);this.lightCubeDir[1]=new z(1,0,0);this.lightCubeDir[2]=new z(0,-1,0);this.lightCubeDir[3]=new z(0,1,0);this.lightCubeDir[4]=new z(0,0,-1);this.lightCubeDir[5]= new z(0,0,1);this.animTilesParams=new Float32Array(2);this.animParams=new Float32Array(4);this.animIndexParams=new Float32Array(2);this.camera=this.particleDistance=this.vbOld=this.vbToSort=this.colorParam=this.internalTex2=this.internalTex1=this.internalTex0=null;this.swapTex=!1;this.useMesh=!0;this.useCpu=!1;this.pack8=!0;this.localBounds=new oa;this.worldBoundsNoTrail=new oa;this.worldBoundsTrail=[new oa,new oa];this.worldBounds=new oa;this.worldBoundsSize=new z;this.prevWorldBoundsSize=new z; this.prevWorldBoundsCenter=new z;this.prevEmitterExtents=this.emitterExtents;this.prevEmitterRadius=this.emitterRadius;this.worldBoundsMul=new z;this.worldBoundsAdd=new z;this.timeToSwitchBounds=0;this.shaderParticleUpdateOnStop=this.shaderParticleUpdateNoRespawn=this.shaderParticleUpdateRespawn=null;this.numParticleIndices=this.numParticleVerts=0;this.meshInstance=this.material=null;this.drawOrder=0;this.seed=Math.random();this.fixedTimeStep=1/60;this.maxSubSteps=10;this.simTimeTotal=this.simTime= 0;this.beenReset=!1;this._layer=null;this.rebuild()};Object.assign($b.prototype,{onChangeCamera:function(){this.regenShader();this.resetMaterial()},calculateBoundsMad:function(){this.worldBoundsMul.x=1/this.worldBoundsSize.x;this.worldBoundsMul.y=1/this.worldBoundsSize.y;this.worldBoundsMul.z=1/this.worldBoundsSize.z;this.worldBoundsAdd.copy(this.worldBounds.center).mul(this.worldBoundsMul).scale(-1);this.worldBoundsAdd.x+=.5;this.worldBoundsAdd.y+=.5;this.worldBoundsAdd.z+=.5},calculateWorldBounds:function(){if(this.node){this.prevWorldBoundsSize.copy(this.worldBoundsSize); this.prevWorldBoundsCenter.copy(this.worldBounds.center);this.useCpu||(0===this.emitterShape?!this.emitterExtents.equals(this.prevEmitterExtents):this.emitterRadius!==this.prevEmitterRadius)&&this.calculateLocalBounds();var a=this.node.getWorldTransform();this.localSpace?this.worldBoundsNoTrail.copy(this.localBounds):this.worldBoundsNoTrail.setFromTransformedAabb(this.localBounds,a);this.worldBoundsTrail[0].add(this.worldBoundsNoTrail);this.worldBoundsTrail[1].add(this.worldBoundsNoTrail);var b=this.simTimeTotal; b>=this.timeToSwitchBounds&&(this.worldBoundsTrail[0].copy(this.worldBoundsTrail[1]),this.worldBoundsTrail[1].copy(this.worldBoundsNoTrail),this.timeToSwitchBounds=b+this.lifetime);this.worldBounds.copy(this.worldBoundsTrail[0]);this.worldBoundsSize.copy(this.worldBounds.halfExtents).scale(2);this.localSpace?(this.meshInstance.aabb.setFromTransformedAabb(this.worldBounds,a),this.meshInstance.mesh.aabb.setFromTransformedAabb(this.worldBounds,a)):(this.meshInstance.aabb.copy(this.worldBounds),this.meshInstance.mesh.aabb.copy(this.worldBounds)); this.meshInstance._aabbVer=1-this.meshInstance._aabbVer;this.pack8&&this.calculateBoundsMad()}},resetWorldBounds:function(){this.node&&(this.worldBoundsNoTrail.setFromTransformedAabb(this.localBounds,this.localSpace?K.IDENTITY:this.node.getWorldTransform()),this.worldBoundsTrail[0].copy(this.worldBoundsNoTrail),this.worldBoundsTrail[1].copy(this.worldBoundsNoTrail),this.worldBounds.copy(this.worldBoundsTrail[0]),this.worldBoundsSize.copy(this.worldBounds.halfExtents).scale(2),this.prevWorldBoundsSize.copy(this.worldBoundsSize), this.prevWorldBoundsCenter.copy(this.worldBounds.center),this.timeToSwitchBounds=this.simTimeTotal=0)},calculateLocalBounds:function(){var a=Number.MAX_VALUE,b=Number.MAX_VALUE,c=Number.MAX_VALUE,d=-Number.MAX_VALUE,e=-Number.MAX_VALUE,f=-Number.MAX_VALUE,g=0,k=0,h=this.lifetime/this.precision,l=[this.qVelocity,this.qVelocity2],n=[this.qLocalVelocity,this.qLocalVelocity2],p=[0,0],q=[0,0],r=[0,0],t=[0,0],u=[0,0],x,v;for(x=0;xv;v++){var y= n[v][3*w]*h+p[v];var A=n[v][3*w+1]*h+q[v];var B=n[v][3*w+2]*h+r[v];a=Math.min(y,a);b=Math.min(A,b);c=Math.min(B,c);d=Math.max(y,d);e=Math.max(A,e);f=Math.max(B,f);p[v]=y;q[v]=A;r[v]=B}for(v=0;2>v;v++)u[v]+=h*Math.sqrt(l[v][3*w]*l[v][3*w]+l[v][3*w+1]*l[v][3*w+1]+l[v][3*w+2]*l[v][3*w+2]);t[0]+=this.qRadialSpeed[w]*h;t[1]+=this.qRadialSpeed2[w]*h;g=Math.max(g,Math.max(Math.abs(t[0]),Math.abs(t[1])));k=Math.max(k,this.qScale[w])}0===this.emitterShape?(y=.5*this.emitterExtents.x,A=.5*this.emitterExtents.y, B=.5*this.emitterExtents.z):B=A=y=this.emitterRadius;h=Math.max(u[0],u[1]);yh.x=a-k-y-g-h;yh.y=b-k-A-g-h;yh.z=c-k-B-g-h;zh.x=d+k+y+g+h;zh.y=e+k+A+g+h;zh.z=f+k+B+g+h;this.localBounds.setMinMax(yh,zh)},rebuild:function(){var a,b=this.graphicsDevice;null===this.colorMap&&(this.colorMap=$b.DEFAULT_PARAM_TEXTURE);this.spawnBounds=0===this.emitterShape?this.emitterExtents:this.emitterRadius;this.useCpu=this.useCpu||0=b.maxVertexTextures||64>b.fragmentUniformsCount||b.forceCpuParticles||!b.extTextureFloat; this._destroyResources();this.pack8=(this.pack8||!b.textureFloatRenderable)&&!this.useCpu;Vc=this.useCpu||this.pack8?4:2;this.useMesh=!1;this.mesh&&(65535this.endTime){if(this.onFinished)this.onFinished();this.meshInstance.visible=!1}this.meshInstance&&(this.meshInstance.drawOrder=this.drawOrder)},_destroyResources:function(){this.particleTexIN&&(this.particleTexIN.destroy(),this.particleTexIN=null);this.particleTexOUT&&(this.particleTexOUT.destroy(),this.particleTexOUT=null);this.particleTexStart&&this.particleTexStart.destroy&&(this.particleTexStart.destroy(),this.particleTexStart= null);this.rtParticleTexIN&&(this.rtParticleTexIN.destroy(),this.rtParticleTexIN=null);this.rtParticleTexOUT&&(this.rtParticleTexOUT.destroy(),this.rtParticleTexOUT=null);this.internalTex0&&(this.internalTex0.destroy(),this.internalTex0=null);this.internalTex1&&(this.internalTex1.destroy(),this.internalTex1=null);this.internalTex2&&(this.internalTex2.destroy(),this.internalTex2=null);this.internalTex3&&(this.internalTex3.destroy(),this.internalTex3=null);this.colorParam&&(this.colorParam.destroy(), this.colorParam=null);this.vertexBuffer&&(this.vertexBuffer.destroy(),this.vertexBuffer=void 0);this.indexBuffer&&(this.indexBuffer.destroy(),this.indexBuffer=void 0);this.material&&(this.material.destroy(),this.material=null)},destroy:function(){this.camera=null;this._destroyResources()}});sa.prototype=Object.create(M.prototype);sa.prototype.constructor=sa;sa.prototype.destroy=function(){this.root=null;this.defaultMaterial.destroy();this.defaultMaterial=null;this.off()};Object.defineProperty(sa.prototype, "fog",{get:function(){return this._fog},set:function(a){a!==this._fog&&(this._fog=a,this.updateShaders=!0)}});Object.defineProperty(sa.prototype,"gammaCorrection",{get:function(){return this._gammaCorrection},set:function(a){a!==this._gammaCorrection&&(this._gammaCorrection=a,this.updateShaders=!0)}});Object.defineProperty(sa.prototype,"toneMapping",{get:function(){return this._toneMapping},set:function(a){a!==this._toneMapping&&(this._toneMapping=a,this.updateShaders=!0)}});Object.defineProperty(sa.prototype, "skybox",{get:function(){return this._skyboxCubeMap},set:function(a){this._skyboxCubeMap=a;this._resetSkyboxModel();this.updateShaders=!0}});Object.defineProperty(sa.prototype,"skyboxIntensity",{get:function(){return this._skyboxIntensity},set:function(a){this._skyboxIntensity=a;this._resetSkyboxModel();this.updateShaders=!0}});Object.defineProperty(sa.prototype,"skyboxMip",{get:function(){return this._skyboxMip},set:function(a){this._skyboxMip=a;this._resetSkyboxModel();this.updateShaders=!0}}); Object.defineProperty(sa.prototype,"skyboxPrefiltered128",{get:function(){return this._skyboxPrefiltered[0]},set:function(a){this._skyboxPrefiltered[0]!==a&&(this._skyboxPrefiltered[0]=a,this.updateShaders=!0)}});Object.defineProperty(sa.prototype,"skyboxPrefiltered64",{get:function(){return this._skyboxPrefiltered[1]},set:function(a){this._skyboxPrefiltered[1]!==a&&(this._skyboxPrefiltered[1]=a,this.updateShaders=!0)}});Object.defineProperty(sa.prototype,"skyboxPrefiltered32",{get:function(){return this._skyboxPrefiltered[2]}, set:function(a){this._skyboxPrefiltered[2]!==a&&(this._skyboxPrefiltered[2]=a,this.updateShaders=!0)}});Object.defineProperty(sa.prototype,"skyboxPrefiltered16",{get:function(){return this._skyboxPrefiltered[3]},set:function(a){this._skyboxPrefiltered[3]!==a&&(this._skyboxPrefiltered[3]=a,this.updateShaders=!0)}});Object.defineProperty(sa.prototype,"skyboxPrefiltered8",{get:function(){return this._skyboxPrefiltered[4]},set:function(a){this._skyboxPrefiltered[4]!==a&&(this._skyboxPrefiltered[4]=a, this.updateShaders=!0)}});Object.defineProperty(sa.prototype,"skyboxPrefiltered4",{get:function(){return this._skyboxPrefiltered[5]},set:function(a){this._skyboxPrefiltered[5]!==a&&(this._skyboxPrefiltered[5]=a,this.updateShaders=!0)}});Object.defineProperty(sa.prototype,"drawCalls",{get:function(){var a=this.layers._meshInstances;a.length||(this.layers._update(),a=this.layers._meshInstances);return a},set:function(a){}});Object.defineProperty(sa.prototype,"layers",{get:function(){return this._layers}, set:function(a){var b=this._layers;this._layers=a;this.fire("set:layers",b,a)}});sa.prototype.applySettings=function(a){this._gravity.set(a.physics.gravity[0],a.physics.gravity[1],a.physics.gravity[2]);this.ambientLight.set(a.render.global_ambient[0],a.render.global_ambient[1],a.render.global_ambient[2]);this._fog=a.render.fog;this.fogColor.set(a.render.fog_color[0],a.render.fog_color[1],a.render.fog_color[2]);this.fogStart=a.render.fog_start;this.fogEnd=a.render.fog_end;this.fogDensity=a.render.fog_density; this._gammaCorrection=a.render.gamma_correction;this._toneMapping=a.render.tonemapping;this.lightmapSizeMultiplier=a.render.lightmapSizeMultiplier;this.lightmapMaxResolution=a.render.lightmapMaxResolution;this.lightmapMode=a.render.lightmapMode;this.exposure=a.render.exposure;this._skyboxIntensity=void 0===a.render.skyboxIntensity?1:a.render.skyboxIntensity;this._skyboxMip=void 0===a.render.skyboxMip?0:a.render.skyboxMip;this._resetSkyboxModel();this.updateShaders=!0};sa.prototype._updateSkybox=function(a){if(!this.skyboxModel){var b= [0,1,3,4,5,6],c=this._skyboxMip?this._skyboxPrefiltered[b[this._skyboxMip]]||this._skyboxPrefiltered[0]||this._skyboxCubeMap:this._skyboxCubeMap||this._skyboxPrefiltered[0];if(c){var d=new ka,e=this;d.updateShader=function(k,h,l,n,p){this.shader=a.getProgramLibrary().getProgram("skybox",{rgbm:"rgbm"===c.type,hdr:"rgbm"===c.type||14===c.format,useIntensity:1!==e.skyboxIntensity,mip:c.fixCubemapSeams?e.skyboxMip:0,fixSeams:c.fixCubemapSeams,gamma:1===p?e.gammaCorrection?3:0:e.gammaCorrection,toneMapping:1=== p?0:e.toneMapping})};d.updateShader();d.setParameter("texture_cubeMap",c);d.cull=2;d.depthWrite=!1;if(b=this.layers.getLayerById(2)){var f=new Z,g=Eg(a);d=new va(f,g,d);d.cull=!1;d._noDepthDrawGl1=!0;g=new sb;g.graph=f;g.meshInstances=[d];this.skyboxModel=g;b.addMeshInstances(g.meshInstances);this.skyLayer=b;this._firstUpdateSkybox&&(b.enabled=!0,this._firstUpdateSkybox=!1);this.fire("set:skybox",c)}}}};sa.prototype._resetSkyboxModel=function(){this.skyboxModel&&(this.skyLayer.removeMeshInstances(this.skyboxModel.meshInstances), this.skyboxModel.destroy());this.skyboxModel=null;this.updateSkybox=!0};sa.prototype.setSkybox=function(a){var b;a||(a=[null,null,null,null,null,null,null]);var c=!1;this._skyboxCubeMap!==a[0]&&(c=!0);if(!c)for(b=0;6>b&&!c;b++)this._skyboxPrefiltered[b]!==a[b+1]&&(c=!0);if(c){for(b=0;6>b;b++)this._skyboxPrefiltered[b]=a[b+1];this.skybox=a[0]}};sa.prototype.destroy=function(){this.skybox=null};sa.prototype.addModel=function(a){if(!this.containsModel(a)){var b=this.layers.getLayerById(0);b&&(b.addMeshInstances(a.meshInstances), this._models.push(a))}};sa.prototype.addShadowCaster=function(a){var b=this.layers.getLayerById(0);b&&b.addShadowCasters(a.meshInstances)};sa.prototype.removeModel=function(a){var b=this._models.indexOf(a);if(-1!==b){var c=this.layers.getLayerById(0);c&&(c.removeMeshInstances(a.meshInstances),this._models.splice(b,1))}};sa.prototype.removeShadowCasters=function(a){var b=this.layers.getLayerById(0);b&&b.removeShadowCasters(a.meshInstances)};sa.prototype.containsModel=function(a){return 0<=this._models.indexOf(a)}; sa.prototype.getModels=function(a){return this._models};if(ed()){var ac=function(a,b,c){c=c||{};this.volume=void 0===c.volume?1:c.volume;this.loop=void 0===c.loop?!1:c.loop;this.pitch=void 0===c.pitch?1:c.pitch;this.sound=b;this.suspended=this.paused=!1;this.startOffset=this.startTime=0;this.manager=a;this.source=null;this.gain=a.context.createGain()};Object.assign(ac.prototype,{play:function(){if(this.source)throw Error("Call stop() before calling play()");this._createSource();if(this.source&&(this.startTime= this.manager.context.currentTime,this.source.start(0,this.startOffset%this.source.buffer.duration),this.setVolume(this.volume),this.setLoop(this.loop),this.setPitch(this.pitch),this.manager.on("volumechange",this.onManagerVolumeChange,this),this.manager.on("suspend",this.onManagerSuspend,this),this.manager.on("resume",this.onManagerResume,this),this.manager.suspended))this.onManagerSuspend()},pause:function(){this.source&&(this.paused=!0,this.startOffset+=this.manager.context.currentTime-this.startTime, this.source.stop(0),this.source=null)},unpause:function(){this.source||!this.paused?console.warn("Call pause() before unpausing."):(this._createSource(),this.source&&(this.startTime=this.manager.context.currentTime,this.source.start(0,this.startOffset%this.source.buffer.duration),this.setVolume(this.volume),this.setLoop(this.loop),this.setPitch(this.pitch),this.paused=!1))},stop:function(){this.source&&(this.source.stop(0),this.source=null);this.manager.off("volumechange",this.onManagerVolumeChange, this);this.manager.off("suspend",this.onManagerSuspend,this);this.manager.off("resume",this.onManagerResume,this)},setLoop:function(a){this.loop=a;this.source&&(this.source.loop=a)},setVolume:function(a){this.volume=a=N.clamp(a,0,1);this.gain&&(this.gain.gain.value=a*this.manager.volume)},setPitch:function(a){this.pitch=a;this.source&&(this.source.playbackRate.value=a)},isPlaying:function(){return!this.paused&&this.source.playbackState===this.source.PLAYING_STATE},getDuration:function(){return this.source? this.source.buffer.duration:0},_createSource:function(){var a=this.manager.context;this.sound.buffer&&(this.source=a.createBufferSource(),this.source.buffer=this.sound.buffer,this.source.connect(this.gain),this.gain.connect(a.destination),this.loop||(this.source.onended=this.pause.bind(this)))}})}else ue()?(ac=function(a,b,c){this.volume=c.volume||1;this.loop=c.loop||!1;this.sound=b;this.pitch=void 0!==c.pitch?c.pitch:1;this.suspended=this.paused=!1;this.manager=a;b.audio&&(this.source=b.audio.cloneNode(!1), this.source.pause())},Object.assign(ac.prototype,{play:function(){this.source&&(this.paused=!1,this.setVolume(this.volume),this.setLoop(this.loop),this.setPitch(this.pitch),this.source.play());this.manager.on("volumechange",this.onManagerVolumeChange,this);this.manager.on("suspend",this.onManagerSuspend,this);this.manager.on("resume",this.onManagerResume,this);if(this.manager.suspended)this.onManagerSuspend()},pause:function(){this.source&&(this.paused=!0,this.source.pause())},unpause:function(){this.source&& (this.paused=!1,this.source.play())},stop:function(){this.source&&this.source.pause();this.manager.off("volumechange",this.onManagerVolumeChange,this);this.manager.off("suspend",this.onManagerSuspend,this);this.manager.off("resume",this.onManagerResume,this)},setVolume:function(a){this.volume=a=N.clamp(a,0,1);this.source&&(this.source.volume=a*this.manager.volume)},setLoop:function(a){this.loop=a;this.source&&(this.source.loop=a)},setPitch:function(a){this.pitch=a;this.source&&(this.source.playbackRate= a)},getDuration:function(){return this.source&&!isNaN(this.source.duration)?this.source.duration:0},isPlaying:function(){return!this.source.paused}})):ac=function(){};Object.assign(ac.prototype,{getVolume:function(){return this.volume},getLoop:function(){return this.loop},getPitch:function(){return this.pitch},onManagerVolumeChange:function(){this.setVolume(this.getVolume())},onManagerSuspend:function(){this.isPlaying()&&!this.suspended&&(this.suspended=!0,this.pause())},onManagerResume:function(){this.suspended&& (this.suspended=!1,this.unpause())}});var Hf="inverse";if(ed()){var $a=function(a,b,c){ac.call(this,a,b,c);this.position=new z;this.velocity=new z;this.panner=a.context.createPanner()};$a.prototype=Object.create(ac.prototype);$a.prototype.constructor=$a;Object.assign($a.prototype,{getPosition:function(){return this.position},setPosition:function(a){this.position.copy(a);this.panner.setPosition(a.x,a.y,a.z)},getVelocity:function(){return this.velocity},setVelocity:function(a){this.velocity.copy(a); this.panner.setVelocity(a.x,a.y,a.z)},getMaxDistance:function(){return this.panner.maxDistance},setMaxDistance:function(a){this.panner.maxDistance=a},getMinDistance:function(){return this.panner.refDistance},setMinDistance:function(a){this.panner.refDistance=a},getRollOffFactor:function(){return this.panner.rolloffFactor},setRollOffFactor:function(a){this.panner.rolloffFactor=a},getDistanceModel:function(){return this.pannel.distanceModel},setDistanceModel:function(a){this.panner.distanceModel=a}, _createSource:function(){var a=this.manager.context;this.source=a.createBufferSource();this.source.buffer=this.sound.buffer;this.source.connect(this.panner);this.panner.connect(this.gain);this.gain.connect(a.destination);this.loop||(this.source.onended=this.pause.bind(this))}})}else if(ue()){var Yj=new z;$a=function(a,b){ac.call(this,a,b);this.position=new z;this.velocity=new z;this.maxDistance=1E4;this.rollOffFactor=this.minDistance=1;this.distanceModel=Hf};$a.prototype=Object.create(ac.prototype); $a.prototype.constructor=$a;Object.assign($a.prototype,{getPosition:function(){return this.position},setPosition:function(a){this.position.copy(a);if(this.source){var b=this.manager.listener.getPosition();a=this.minDistance;var c=this.maxDistance,d=this.rollOffFactor,e=this.distanceModel;Yj=Yj.sub2(b,this.position);b=Yj.length();if(bc)a=0;else{var f=0;"linear"===e?f=1-d*(b-a)/(c-a):e===Hf?f=a/(a+d*(b-a)):"exponential"===e&&(f=Math.pow(b/a,-d));a=N.clamp(f,0,1)}c=this.getVolume(); this.source.volume=c*a}},getVelocity:function(){return this.velocity},setVelocity:function(a){this.velocity.copy(a)},getMaxDistance:function(){return this.maxDistance},setMaxDistance:function(a){this.maxDistance=a},getMinDistance:function(){return this.minDistance},setMinDistance:function(a){this.minDistance=a},getRollOffFactor:function(){return this.rollOffFactor},setRollOffFactor:function(a){this.rollOffFactor=a},getDistanceModel:function(){return this.distanceModel},setDistanceModel:function(a){this.distanceModel= a}})}else $a=function(){};Object.assign(ri.prototype,{getPosition:function(){return this.position},setPosition:function(a){this.position.copy(a);this.listener&&this.listener.setPosition(a.x,a.y,a.z)},getVelocity:function(){return this.velocity},setVelocity:function(a){this.velocity.copy(a);this.listener&&this.listener.setPosition(a.x,a.y,a.z)},setOrientation:function(a){this.orientation.copy(a);this.listener&&this.listener.setOrientation(-a.data[8],-a.data[9],-a.data[10],a.data[4],a.data[5],a.data[6])}, getOrientation:function(){return this.orientation}});ec.prototype=Object.create(M.prototype);ec.prototype.constructor=ec;Object.assign(ec.prototype,{suspend:function(){this.suspended=!0;this.fire("suspend")},resume:function(){this.suspended=!1;this.fire("resume")},destroy:function(){window.removeEventListener("mousedown",this.resumeContext);window.removeEventListener("touchend",this.resumeContext);this.fire("destroy");this.context&&this.context.close&&(this.context.close(),this.context=null)},playSound:function(a, b){b=b||{};var c=null;ac&&(c=new ac(this,a,b),c.play());return c},playSound3d:function(a,b,c){c=c||{};var d=null;$a&&(d=new $a(this,a,c),d.setPosition(b),c.volume&&d.setVolume(c.volume),c.loop&&d.setLoop(c.loop),c.maxDistance&&d.setMaxDistance(c.maxDistance),c.minDistance&&d.setMinDistance(c.minDistance),c.rollOffFactor&&d.setRollOffFactor(c.rollOffFactor),c.distanceModel&&d.setDistanceModel(c.distanceModel),d.play());return d}});Object.defineProperty(ec.prototype,"volume",{get:function(){return this._volume}, set:function(a){this._volume=a=N.clamp(a,0,1);this.fire("volumechange",a)}});Rb.prototype.getDuration=function(){return this.duration};Rb.prototype.getName=function(){return this.name};Rb.prototype.getNode=function(a){return this._nodeDict[a]};Object.defineProperty(Rb.prototype,"nodes",{get:function(){return this._nodes}});Rb.prototype.getNodes=function(){return this._nodes};Rb.prototype.setDuration=function(a){this.duration=a};Rb.prototype.setName=function(a){this.name=a};Rb.prototype.addNode=function(a){this._nodes.push(a); this._nodeDict[a._name]=a};Object.defineProperties(tf.prototype,{morphPositions:{get:function(){return!!this._vertexBufferPositions||!!this.texturePositions}},morphNormals:{get:function(){return!!this._vertexBufferNormals||!!this.textureNormals}}});Object.assign(tf.prototype,{_postInit:function(){this.options=null},_initVertexBuffers:function(a){var b=this.options;this._vertexBufferPositions=this._createVertexBuffer(a,b.deltaPositions,b.deltaPositionsType);this._vertexBufferNormals=this._createVertexBuffer(a, b.deltaNormals,b.deltaNormalsType);this._vertexBufferPositions&&(this.deltaPositions=this._vertexBufferPositions.lock())},_createVertexBuffer:function(a,b,c){return b?new ab(a,new Na(a,[{semantic:"ATTR0",components:3,type:c||6}]),b.length/3,0,b):null},_setTexture:function(a,b){this[a]=b},destroy:function(){this._vertexBufferPositions&&(this._vertexBufferPositions.destroy(),this._vertexBufferPositions=null);this._vertexBufferNormals&&(this._vertexBufferNormals.destroy(),this._vertexBufferNormals=null); this.texturePositions&&(this.texturePositions.destroy(),this.texturePositions=null);this.textureNormals&&(this.textureNormals.destroy(),this.textureNormals=null)}});Object.assign(uf.prototype,{encode:function(a){return uc.joinPath([uc.joinPath(a[0]),a[1],uc.joinPath(a[2])],"/")},decode:function(a){a=uc.splitPath(a,"/");return[uc.splitPath(a[0]),a[1],uc.splitPath(a[2])]}});fa.prototype=Object.create(Z.prototype);fa.prototype.constructor=fa;fa.prototype.addComponent=function(a,b){var c=this._app.systems[a]; return!c||this.c[a]?null:c.addComponent(this,b)};fa.prototype.removeComponent=function(a){var b=this._app.systems[a];b&&this.c[a]&&b.removeComponent(this)};fa.prototype.findComponent=function(a){var b=this.findOne(function(c){return c.c&&c.c[a]});return b&&b.c[a]};fa.prototype.findComponents=function(a){return this.find(function(b){return b.c&&b.c[a]}).map(function(b){return b.c[a]})};fa.prototype.getGuid=function(){this._guid||this.setGuid(Ql.create());return this._guid};fa.prototype.setGuid=function(a){var b= this._app._entityIndex;this._guid&&delete b[this._guid];this._guid=a;b[this._guid]=this};fa.prototype._notifyHierarchyStateChanged=function(a,b){var c=!1;a===this&&0===this._app._enableList.length&&(c=!0);a._beingEnabled=!0;a._onHierarchyStateChanged(b);a._onHierarchyStatePostChanged&&this._app._enableList.push(a);var d,e=a._children;var f=0;for(d=e.length;f=this._right){var c=b.length;c?a=b[c-1]?(this._left=b[c-1],this._right=Infinity,this._recip=this._len=0,this._p0=this._p1=c-1):(c=this._findKey(a,b),this._left=b[c],this._right=b[c+1],this._len=this._right-this._left,b=1/this._len,this._recip=isFinite(b)?b:0,this._p0=c,this._p1=c+1):(this._left=-Infinity,this._right=Infinity,this._p0=this._p1=this._recip=this._len=0)}this._t=0===this._recip? 0:(a-this._left)*this._recip;this._hermite.valid=!1},_findKey:function(a,b){for(var c=0;a>=b[c+1];)c++;return c},eval:function(a,b,c){var d=c._data;c=c._components;var e=this._p0*c,f;if(0===b)for(f=0;fc&&(e?b=b%c||0:(b=this._track.duration,this.pause())):0>b&&(e?b=c+(b%c||0):(b=0,this.pause()));this._time=b}this._time!=this._snapshot._time&&this._track.eval(this._time,this._snapshot)},play:function(){this._playing=!0;this._time=0},stop:function(){this._playing=!1;this._time=0},pause:function(){this._playing=!1},resume:function(){this._playing=!0},reset:function(){this._time=0}});Object.defineProperties(Ic.prototype,{func:{get:function(){return this._func}}, type:{get:function(){return this._type}},components:{get:function(){return this._components}}});uc.joinPath=function(a,b){b=b||".";return a.map(function(c){return c.replace(/\\/g,"\\\\").replace(new RegExp("\\"+b,"g"),"\\"+b)}).join(b)};uc.splitPath=function(a,b){b=b||".";for(var c=[],d="",e=0;eJa._dot(a,b)&&(c=-c);for(var f=0;f=a?0:1});ud(["fr","pt"],function(a){return 0<=a&&2>a?0:1});ud(["da"],function(a){return 1===a||!Number.isInteger(a)&&0<=a&&1>=a?0:1});ud("de en it el es tr fi sv nb no ur".split(" "),function(a){return 1===a?0:1});ud(["ru", "uk"],function(a){if(Number.isInteger(a)){var b=a%10;a%=100;if(1===b&&11!==a)return 0;if(2<=b&&4>=b&&(12>a||14=b||11<=a&&14>=a)return 2}return 3});ud(["pl"],function(a){if(Number.isInteger(a)){if(1===a)return 0;var b=a%10;a%=100;if(2<=b&&4>=b&&(12>a||14=b||5<=b&&9>=b||12<=a&&14>=a)return 2}return 3});ud(["ar"],function(a){if(0===a)return 0;if(1===a)return 1;if(2===a)return 2;if(Number.isInteger(a)){a%=100;if(3<=a&&10>=a)return 3;if(11<=a&&99>= a)return 4}return 5});var Zj=$f[vd(Jg)];Oa.prototype=Object.create(M.prototype);Oa.prototype.constructor=Oa;Oa.findAvailableLocale=function(a,b){if(b[a])return a;var c=Ah[a];if(c&&b[c])return c;a=vd(a);c=Ah[a];return b[c]?c:b[a]?a:Jg};Oa.prototype.getText=function(a,b){var c=a;if(!b){b=this._locale;var d=this._lang}var e=this._translations[b];e||(d||(d=vd(b)),b=this._findFallbackLocale(b,d),e=this._translations[b]);e&&e.hasOwnProperty(a)&&(c=e[a],Array.isArray(c)&&(c=c[0]),null===c||void 0===c)&& (c=a);return c};Oa.prototype.getPluralText=function(a,b,c){var d=a;if(c){var e=vd(c);var f=$f[e]||Zj}else c=this._locale,e=this._lang,f=this._pluralFn;var g=this._translations[c];g||(c=this._findFallbackLocale(c,e),e=vd(c),f=$f[e]||Zj,g=this._translations[c]);g&&g[a]&&f&&(b=f(b),d=g[a][b],null===d||void 0===d)&&(d=a);return d};Oa.prototype.addData=function(a){try{var b=this._parser.parse(a)}catch(g){console.error(g);return}a=0;for(var c=b.length;af[k+0]*f[k+4]+f[k+1]*f[k+5]+f[k+2]*f[k+6]+f[k+3]*f[k+7]&&(f[k+4]*=-1,f[k+5]*=-1,f[k+6]*=-1,f[k+7]*=-1);f=e}for(q=e=0;qg;g++)p[g]=n[16*f+g];g=new K;g.set(p);l.push(g)}}else for(f=0;fT;++T)I.push(D._levels[R][T]);else I=D._levels[R];J.push(I)}G._levels=J;C.resource=G;E.registry.add(C);E=C}wp(E.resource,(a.samplers||[])[a.textures[A].sampler]);v[A]=E;h&&h(a.textures[B],E)})});f(null,v)}},r=0;rparseFloat(a.asset.version)?b("Invalid gltf version. Expected version 2.0 or above but found version '"+a.asset.version+"'."):b(null,a)},Dm=function(a,b,c){if(a&&a.toLowerCase().endsWith(".glb")){a=new DataView(b);var d=a.getUint32(0,!0),e=a.getUint32(4,!0),f=a.getUint32(8,!0);if(1179937895!==d)c("Invalid magic number found in glb header. Expected 0x46546C67, found 0x"+ d.toString(16));else if(2!==e)c("Invalid version number found in glb header. Expected 2, found "+e);else if(0>=f||f>b.byteLength)c("Invalid length found in glb header. Found "+f);else{d=[];for(e=12;eb.byteLength)throw Error("Invalid chunk length found in glb. Found "+g);var k=a.getUint32(e+4,!0),h=new Uint8Array(b,e+8,g);d.push({length:g,type:k,data:h});e+=g+8}1!==d.length&&2!==d.length?c("Invalid number of chunks found in glb file."):1313821514!==d[0].type?c("Invalid chunk type found in glb file. Expected 0x4E4F534A, found 0x"+ d[0].type.toString(16)):1c;++c)b[c+1]=a.data.textures[c];else b[1]=b[2]=b[3]=b[4]=b[5]=b[6]=null;return b},compareAssetIds:function(a,b){return a&&b?parseInt(a,10)===a||"string"===typeof a?a===b:a.url===b.url:null!==a===(null!==b)},update:function(a,b,c){var d=a.data||{},e=a._handlerState.assets,f=a._resources, g,k,h=[null,null,null,null,null,null,null],l=function(){return d.hasOwnProperty("type")?d.type:d.hasOwnProperty("rgbm")?d.rgbm?"rgbm":"default":null};if(a.loaded&&c[0]===e[0])h[1]=f[1]||null,h[2]=f[2]||null,h[3]=f[3]||null,h[4]=f[4]||null,h[5]=f[5]||null,h[6]=f[6]||null;else if(c[0]){var n=c[0].resource;for(k=0;6>k;++k){var p=[n._levels[k]];if(0===k&&this._device.useTexCubeLod)for(g=1;g>k),cubemap:!0, type:l()||n.type,width:n.width>>k,height:n.height>>k,format:n.format,levels:p,fixCubemapSeams:!0,addressU:1,addressV:1});h[k+1]=p}}n=c.slice(1);if(a.loaded&&this.cmpArrays(n,e.slice(1)))h[0]=f[0]||null;else if(-1===n.indexOf(null)){n=n.map(function(q){return q.resource});k=[];for(g=0;gt;++t){var u=d[t];u?c.compareAssetIds(u,f[t])?l(t,g[t]):parseInt(u,10)===u?(r=k.get(u))?q(t,r):setTimeout(function(x,v){var w=k.get(v);w?q(x,w):b("failed to find dependent cubemap asset="+ v)}.bind(null,t,u)):(r=new aa(a.name+"_part_"+t,"texture","string"===typeof u?{url:u,filename:u}:u),k.add(r),k.once("load:"+r.id,n.bind(c,t)),k.once("error:"+r.id,p.bind(c,t)),k.load(r)):l(t,null)}}});Object.assign(Ei.prototype,{load:function(a,b){b(null,null)},open:function(a,b){return b}});Object.defineProperty(Lg.prototype,"data",{get:function(){return this._data},set:function(a){if(this._data=a)if(void 0!==this._data.intensity&&(this.intensity=this._data.intensity),this._data.info||(this._data.info= {}),!this._data.version||2>this._data.version)if(this._data.info.maps=[{width:this._data.info.width,height:this._data.info.height}],this._data.chars)for(var b in this._data.chars)this._data.chars[b].map=0}});Object.assign(Gi.prototype,{load:function(a,b,c){"string"===typeof a&&(a={load:a,original:a});var d=this;".json"===ca.getExtension(a.original)?wa.get(a.load,{retry:this.retryRequests},function(e,f){var g=Fi(f);e?b("Error loading font resource: "+a.original+" ["+e+"]"):d._loadTextures(a.load.replace(".json", ".png"),g,function(k,h){if(k)return b(k);b(null,{data:g,textures:h})})}):(c&&c.data&&(c.data=Fi(c.data)),this._loadTextures(a.load,c&&c.data,b))},_loadTextures:function(a,b,c){var d=b.info.maps.length,e=0,f=null,g=Array(d),k=this._loader;b=function(l){var n=function(p,q){if(!f){if(p)return f=p,c(p);q.upload();g[l]=q;e++;e===d&&c(null,g)}};0===l?k.load(a,"texture",n):k.load(a.replace(".png",l+".png"),"texture",n)};for(var h=0;hd;d++)for(var e=0;4>e;e++)c[4*d+e]=a[b][e];this._placeholderTextures[b].unlock()}}, patch:function(a,b){a.resource._data&&(a._data=a.resource._data,delete a.resource._data);a.data.name=a.name;a.resource.name=a.name;this._bindAndAssignAssets(a,b);a.off("unload",this._onAssetUnload,this);a.on("unload",this._onAssetUnload,this)},_onAssetUnload:function(a){delete a.data.parameters;delete a.data.chunks;delete a.data.name},_assignTexture:function(a,b,c){b.data[a]=c;b.resource[a]=c},_assignPlaceholderTexture:function(a,b){this._placeholderTextures||this._createPlaceholders();b.resource[a]= this._placeholderTextures[Ap[a]]},_onTextureLoad:function(a,b,c){this._assignTexture(a,b,c.resource);b.resource.update()},_onTextureAdd:function(a,b,c){this._assets.load(c)},_onTextureRemove:function(a,b,c){var d=b.resource;d[a]===c.resource&&(this._assignTexture(a,b,null),d.update())},_assignCubemap:function(a,b,c){b.data[a]=c[0];7===c.length&&(b.data.prefilteredCubeMap128=c[1],b.data.prefilteredCubeMap64=c[2],b.data.prefilteredCubeMap32=c[3],b.data.prefilteredCubeMap16=c[4],b.data.prefilteredCubeMap8= c[5],b.data.prefilteredCubeMap4=c[6])},_onCubemapLoad:function(a,b,c){this._assignCubemap(a,b,c.resources);this._parser.initialize(b.resource,b.data)},_onCubemapAdd:function(a,b,c){0===b.data.shadingModel&&(b.loadFaces=!0);this._assets.load(c)},_onCubemapRemove:function(a,b,c){var d=b.resource;d[a]===c.resource&&(this._assignCubemap(a,b,[null,null,null,null,null,null,null]),d.update())},_bindAndAssignAssets:function(a,b){var c=this._parser.migrate(a.data),d=a.resource,e="path"===c.mappingFormat,f; for(f=0;fd;d++)0!==c.blendWeight.data[4*b+d]&&(a.boneIndices[d]=this.getBoneRemap(c.blendIndices.data[4*a.index+d]));c=this.vertices.length;this.indices.push(c);this.vertices.push(a);this.indexMap[b]=c}},addPrimitive:function(a,b,c,d){var e,f,g=[],k=0,h=a.length;for(e=0;en;n++)if(0d)return!1;for(e=0;e=b.version)return null;b=this._parseNodes(a);var c= this._parseSkins(a,b),d=this._parseVertexBuffers(a),e=this._parseIndexBuffers(a,d),f=this._parseMorphs(a,b,d);d=this._parseMeshes(a,c.skins,f.morphs,d,e.buffer,e.data);a=this._parseMeshInstances(a,b,d,c.skins,c.instances,f.morphs,f.instances);d=new sb;d.graph=b[0];d.meshInstances=a;d.skinInstances=c.instances;d.morphInstances=f.instances;d.getGraph().syncHierarchy();return d},_parseNodes:function(a){a=a.model;var b=[],c;for(c=0;c=b;b++){var h= 0===b||3===b?0:1;for(c=0;3>=c;c++){var l=-a.x+2*a.x*(1>=b?0:3)/3;var n=-(-a.y+2*a.y*(1>=c?0:3)/3);var p=0===c||3===c?0:1;d.push(-l,0,n);e.push(0,1,0);f.push(h,p);3>b&&3>c&&(g.push(k+3+1,k+1,k),g.push(k+3+1,k+3+2,k+1));k++}}return Qb(this._device,d,{normals:e,uvs:f,indices:g})};Sa.prototype._onSetFrames=function(a){this._updatingProperties?this._meshesDirty=!0:this._createMeshes()};Sa.prototype._onFrameChanged=function(a,b){a=this._frameKeys.indexOf(a);0>a||(b?0===this.renderMode&&(this._meshes[a]= this._createSimpleMesh(b)):this._meshes[a]=null,this.fire("set:meshes"))};Sa.prototype._onFrameRemoved=function(a){a=this._frameKeys.indexOf(a);0>a||(this._meshes[a]=null,this.fire("set:meshes"))};Sa.prototype.startUpdate=function(){this._updatingProperties=!0;this._meshesDirty=!1};Sa.prototype.endUpdate=function(){this._updatingProperties=!1;this._meshesDirty&&this._atlas&&this._frameKeys&&this._createMeshes();this._meshesDirty=!1};Sa.prototype.destroy=function(){var a;var b=0;for(a=this._meshes.length;b< a;b++){var c=this._meshes[b];if(c){c.vertexBuffer.destroy();for(var d=0,e=c.indexBuffer.length;d=++f){var h=100*Math.pow(2,f);console.log("Error loading Texture from: '"+b+"' - Retrying in "+h+"ms...");var l=0<=a.indexOf("?")?"&":"?";g=setTimeout(function(){e.src=a+l+"retry="+Date.now();g=null},h)}else d("Error loading Texture from: '"+b+"'")};e.src=a},_loadImageBitmap:function(a,b,c,d){wa.get(a,{cache:!0,responseType:"blob",retry:this.retryRequests},function(e,f){e?d(e):createImageBitmap(f,{premultiplyAlpha:"none",imageOrientation:"flipY"}).then(function(g){d(null, g)}).catch(function(g){d(g)})})}});var gk=[1481919403,3140563232,169478669],Gm={33776:8,33778:9,33779:10,36196:21,37492:22,37496:23,35840:26,35841:24,35842:27,35843:25};Object.assign(dj.prototype,{load:function(a,b,c){wa.get(a.load,{cache:!0,responseType:"arraybuffer",retry:this.retryRequests},b)},open:function(a,b,c){b=this.parse(b);if(!b)return null;a=new V(c,{name:a,addressU:b.cubemap?1:0,addressV:b.cubemap?1:0,width:b.width,height:b.height,format:b.format,cubemap:b.cubemap,levels:b.levels});a.upload(); return a},parse:function(a){var b=new Uint32Array(a,0,16);if(gk[0]!==b[0]||gk[1]!==b[1]||gk[2]!==b[2])return null;var c=b[6],d=b[7],e=b[9],f=b[10],g=b[12],k=b[13],h=b[14];if(1>1),q=Math.max(1,l>>1),r=new n.constructor(p*q*4),t=Math.floor(h/p);l=Math.floor(l/q);for(var u= t*l,x=0;xw;++w){for(var y=0,A=0;A>d-1),f=Math.max(1,a._height>>d-1);if(a._cubemap){for(var g=[],k=0;6>k;++k)g.push(c(e,f,a._levels[d-1][k]));a._levels.push(g)}else a._levels.push(c(e,f,a._levels[d-1]))}a._levelsUpdated=a._cubemap?[[!0,!0,!0,!0,!0,!0]]:[!0]}};Object.defineProperties(Pg.prototype,{crossOrigin:{get:function(){return this.imgParser.crossOrigin}, set:function(a){this.imgParser.crossOrigin=a}},retryRequests:{get:function(){return this.imgParser.retryRequests},set:function(a){this.imgParser.retryRequests=a;for(var b in this.parsers)this.parsers.hasOwnProperty(b)&&(this.parsers[b].retryRequests=a)}}});Object.assign(Pg.prototype,{_getUrlWithoutParams:function(a){return 0<=a.indexOf("?")?a.split("?")[0]:a},_getParser:function(a){a=ca.getExtension(this._getUrlWithoutParams(a)).toLowerCase().replace(".","");return this.parsers[a]||this.imgParser}, load:function(a,b,c){"string"===typeof a&&(a={load:a,original:a});this._getParser(a.original).load(a,b,c)},open:function(a,b,c){if(a)return a=this._getParser(a).open(a,b,this._device),null===a?a=new V(this._device,{width:4,height:4,format:6}):Hp(a),a},patch:function(a,b){if(b=a.resource){a.name&&0ke.distance(c._localPosition)?this._inputSource._selecting||(this._inputSource._selecting=!0,this._inputSource.fire("selectstart"),this._manager.input.fire("selectstart", this._inputSource)):this._inputSource._selecting&&(this._inputSource._selecting=!1,this._inputSource.fire("select"),this._manager.input.fire("select",this._inputSource),this._inputSource.fire("selectend"),this._manager.input.fire("selectend",this._inputSource)))};gc.prototype.getJointById=function(a){return this._jointsById[a]||null};Object.defineProperty(gc.prototype,"fingers",{get:function(){return this._fingers}});Object.defineProperty(gc.prototype,"joints",{get:function(){return this._joints}}); Object.defineProperty(gc.prototype,"tips",{get:function(){return this._tips}});Object.defineProperty(gc.prototype,"wrist",{get:function(){return this._wrist}});Object.defineProperty(gc.prototype,"tracking",{get:function(){return this._tracking}});var Om=new Y,Yn=0;ta.prototype=Object.create(M.prototype);ta.prototype.constructor=ta;ta.prototype.update=function(a){if(this._hand)this._hand.update(a);else{if(this._xrInputSource.gripSpace){var b=a.getPose(this._xrInputSource.gripSpace,this._manager._referenceSpace); b&&(this._grip||(this._grip=!0,this._localTransform=new K,this._worldTransform=new K,this._localPosition=new z,this._localRotation=new Y),this._dirtyLocal=!0,this._localPosition.copy(b.transform.position),this._localRotation.copy(b.transform.orientation))}if(a=a.getPose(this._xrInputSource.targetRaySpace,this._manager._referenceSpace))this._dirtyRay=!0,this._rayLocal.origin.copy(a.transform.position),this._rayLocal.direction.set(0,0,-1),Om.copy(a.transform.orientation),Om.transformVector(this._rayLocal.direction, this._rayLocal.direction)}};ta.prototype._updateTransforms=function(){this._dirtyLocal&&(this._dirtyLocal=!1,this._localTransform.setTRS(this._localPosition,this._localRotation,z.ONE));var a=this._manager.camera.parent;a?this._worldTransform.mul2(a.getWorldTransform(),this._localTransform):this._worldTransform.copy(this._localTransform)};ta.prototype._updateRayTransforms=function(){var a=this._dirtyRay;this._dirtyRay=!1;this._manager.camera.parent?(a=this._manager.camera.parent.getWorldTransform(), a.getTranslation(this._position),this._rotation.setFromMat4(a),this._rotation.transformVector(this._rayLocal.origin,this._ray.origin),this._ray.origin.add(this._position),this._rotation.transformVector(this._rayLocal.direction,this._ray.direction)):a&&(this._ray.origin.copy(this._rayLocal.origin),this._ray.direction.copy(this._rayLocal.direction))};ta.prototype.getPosition=function(){if(!this._position)return null;this._updateTransforms();this._worldTransform.getTranslation(this._position);return this._position}; ta.prototype.getLocalPosition=function(){return this._localPosition};ta.prototype.getRotation=function(){if(!this._rotation)return null;this._updateTransforms();this._rotation.setFromMat4(this._worldTransform);return this._rotation};ta.prototype.getLocalRotation=function(){return this._localRotation};ta.prototype.getOrigin=function(){this._updateRayTransforms();return this._ray.origin};ta.prototype.getDirection=function(){this._updateRayTransforms();return this._ray.direction};ta.prototype.hitTestStart= function(a){var b=this;a=a||{};a.profile=this._xrInputSource.profiles[0];var c=a.callback;a.callback=function(d,e){if(e)b.onHitTestSourceAdd(e);c&&c(d,e)};this._manager.hitTest.start(a)};ta.prototype.onHitTestSourceAdd=function(a){this._hitTestSources.push(a);this.fire("hittest:add",a);a.on("result",function(b,c,d){d===this&&this.fire("hittest:result",a,b,c)},this);a.once("remove",function(){this.onHitTestSourceRemove(a);this.fire("hittest:remove",a)},this)};ta.prototype.onHitTestSourceRemove=function(a){a= this._hitTestSources.indexOf(a);-1!==a&&this._hitTestSources.splice(a,1)};Object.defineProperty(ta.prototype,"id",{get:function(){return this._id}});Object.defineProperty(ta.prototype,"inputSource",{get:function(){return this._xrInputSource}});Object.defineProperty(ta.prototype,"targetRayMode",{get:function(){return this._xrInputSource.targetRayMode}});Object.defineProperty(ta.prototype,"handedness",{get:function(){return this._xrInputSource.handedness}});Object.defineProperty(ta.prototype,"profiles", {get:function(){return this._xrInputSource.profiles}});Object.defineProperty(ta.prototype,"grip",{get:function(){return this._grip}});Object.defineProperty(ta.prototype,"hand",{get:function(){return this._hand}});Object.defineProperty(ta.prototype,"gamepad",{get:function(){return this._xrInputSource.gamepad||null}});Object.defineProperty(ta.prototype,"selecting",{get:function(){return this._selecting}});Object.defineProperty(ta.prototype,"elementInput",{get:function(){return this._elementInput},set:function(a){this._elementInput!== a&&(this._elementInput=a,this._elementInput||(this._elementEntity=null))}});Object.defineProperty(ta.prototype,"elementEntity",{get:function(){return this._elementEntity}});Object.defineProperty(ta.prototype,"hitTestSources",{get:function(){return this._hitTestSources}});Gb.prototype=Object.create(M.prototype);Gb.prototype.constructor=Gb;Gb.prototype._onSessionStart=function(){this._session=this.manager.session;this._session.addEventListener("inputsourceschange",this._onInputSourcesChangeEvt);var a= this;this._session.addEventListener("select",function(d){var e=a._getByInputSource(d.inputSource);e.update(d.frame);e.fire("select",d);a.fire("select",e,d)});this._session.addEventListener("selectstart",function(d){var e=a._getByInputSource(d.inputSource);e.update(d.frame);e._selecting=!0;e.fire("selectstart",d);a.fire("selectstart",e,d)});this._session.addEventListener("selectend",function(d){var e=a._getByInputSource(d.inputSource);e.update(d.frame);e._selecting=!1;e.fire("selectend",d);a.fire("selectend", e,d)});for(var b=this._session.inputSources,c=0;cthis.views.length)for(d=0;d<=e-this.views.length;d++)(b=this.viewsPool.pop())||(b={viewport:new X,projMat:new K,viewMat:new K,viewOffMat:new K,viewInvMat:new K,viewInvOffMat:new K,projViewOffMat:new K,viewMat3:new xb,position:new Float32Array(3),rotation:new Y}),this.views.push(b); else if(e<=this.views.length)for(d=0;dc)for(this._time=this.looping?0:c,c=0;cthis._time)for(this._time=this.looping?c:0,c= 0;c=this._time){g=(this._time-h.time)/(l.time-h.time);f._pos.lerp(h.position,l.position,g);f._quat.slerp(h.rotation,l.rotation,g);f._scale.lerp(h.scale,l.scale,g);f._written=!0;this._currKeyIndices[e]= k;g=!0;break}}if(1===d.length||!g&&0===this._time&&this.looping)f._pos.copy(d[0].position),f._quat.copy(d[0].rotation),f._scale.copy(d[0].scale),f._written=!0}}}}};Ta.prototype.blend=function(a,b,c){for(var d=this._interpolatedKeys.length,e=0;e e.speed&&0===d._time&&!e.loop&&(e.playing=!1)),e.blending&&1===e.blend&&(d.animation=e.toSkel._animation),d.updateGraph()));if(d=e.animEvaluator){for(var f=0;fa&&(a=c.animTrack.duration>a)}return a}}});Object.defineProperties(hj.prototype,{from:{get:function(){return this._from}},to:{get:function(){return this._to}},time:{get:function(){return this._time}},priority:{get:function(){return this._priority}},conditions:{get:function(){return this._conditions}},exitTime:{get:function(){return this._exitTime}},transitionOffset:{get:function(){return this._transitionOffset}}, interruptionSource:{get:function(){return this._interruptionSource}},hasExitTime:{get:function(){return!!this.exitTime}},hasConditionsMet:{get:function(){var a=!0,b;for(b=0;bc.value;break;case "LESS_THAN":a=a&&d.value=c.value;break;case "LESS_THAN_EQUAL_TO":a=a&&d.value<=c.value;break;case "EQUAL_TO":a= a&&d.value===c.value;break;case "NOT_EQUAL_TO":a=a&&d.value!==c.value}if(!a)break}return a}}});Object.defineProperties(Sg.prototype,{animEvaluator:{get:function(){return this._animEvaluator}},activeState:{get:function(){return this._findState(this._activeStateName)},set:function(a){this._activeStateName=a}},activeStateName:{get:function(){return this._activeStateName}},activeStateAnimations:{get:function(){return this.activeState.animations}},previousState:{get:function(){return this._findState(this._previousStateName)}, set:function(a){this._previousStateName=a}},previousStateName:{get:function(){return this._previousStateName}},playable:{get:function(){var a=!0,b;for(b=0;b"+b];c||(c=this._transitions.filter(function(d){return d.from===a&&d.to===b}),c.sort(function(d,e){return d.priority"+b]=c);return c},_findTransition:function(a,b){var c=[];if(a&&b)c.concat(this._findTransitionsBetweenStates(a, b));else if(this._isTransitioning)switch(this._transitionInterruptionSource){case "PREV_STATE":c=c.concat(this._findTransitionsFromState(this._previousStateName));c=c.concat(this._findTransitionsFromState("ANY"));break;case "NEXT_STATE":c=c.concat(this._findTransitionsFromState(this._activeStateName));c=c.concat(this._findTransitionsFromState("ANY"));break;case "PREV_STATE_NEXT_STATE":c=c.concat(this._findTransitionsFromState(this._previousStateName));c=c.concat(this._findTransitionsFromState(this._activeStateName)); c=c.concat(this._findTransitionsFromState("ANY"));break;case "NEXT_STATE_PREV_STATE":c=c.concat(this._findTransitionsFromState(this._activeStateName)),c=c.concat(this._findTransitionsFromState(this._previousStateName)),c=c.concat(this._findTransitionsFromState("ANY"))}else c=c.concat(this._findTransitionsFromState(this._activeStateName)),c=c.concat(this._findTransitionsFromState("ANY"));c=c.filter(function(d){if(d.to===this.activeStateName)return!1;if(d.hasExitTime){var e=this._getActiveStateProgressForTime(this._timeInStateBefore), f=this._getActiveStateProgressForTime(this._timeInState);1>d.exitTime&&this.activeState.looping&&(e-=Math.floor(e),f-=Math.floor(f));if(!(d.exitTime>e&&d.exitTime<=f))return null}return d.hasConditionsMet}.bind(this));return 0a.transitionOffset;f=this.activeState;for(b=0;bb.indexOf(c[d])&&(c[d]instanceof aa?a.push(c[d].id):a.push(c[d]));!this.system._inTools&&a.length&&this.loadAudioSourceAssets(a)},onAssetChanged:function(a,b,c,d){"resource"=== b&&this.data.sources&&(this.data.sources[a.name]=c,this.data.currentSource===a.name&&this.channel&&(this.channel.paused?(this.play(a.name),this.pause()):this.play(a.name)))},onAssetRemoved:function(a){a.off("remove",this.onAssetRemoved,this);this.data.sources[a.name]&&(delete this.data.sources[a.name],this.data.currentSource===a.name&&(this.stop(),this.data.currentSource=null))},onSetLoop:function(a,b,c){b!=c&&this.channel&&this.channel.setLoop(c)},onSetVolume:function(a,b,c){b!=c&&this.channel&& this.channel.setVolume(c)},onSetPitch:function(a,b,c){b!=c&&this.channel&&this.channel.setPitch(c)},onSetMaxDistance:function(a,b,c){b!=c&&this.channel instanceof $a&&this.channel.setMaxDistance(c)},onSetMinDistance:function(a,b,c){b!=c&&this.channel instanceof $a&&this.channel.setMinDistance(c)},onSetRollOffFactor:function(a,b,c){b!=c&&this.channel instanceof $a&&this.channel.setRollOffFactor(c)},onSetDistanceModel:function(a,b,c){b!==c&&this.channel instanceof $a&&this.channel.setDistanceModel(c)}, onSet3d:function(a,b,c){b!==c&&this.system.initialized&&this.currentSource&&(b=a=!1,this.channel&&(a=this.channel.paused,b=this.channel.suspended),this.play(this.currentSource),this.channel&&(this.channel.paused=a,this.channel.suspended=b))},onEnable:function(){var a=this.data.assets;if(a)for(var b=this.system.app.assets,c=0,d=a.length;ce&&(e=h))}this.app.scene.layers.insertOpaque(this.layer,e+1);this._sourceTarget=c.inputTarget;this.layer._commandList=[];this.layer.isPostEffect=!0}b.push(c);e=b.length;1this.layers.indexOf(a.id)||a.addCamera(this)},onLayerRemoved:function(a){0>this.layers.indexOf(a.id)||a.removeCamera(this)},onEnable:function(){var a=this.system,b=a.app.scene,c=b.layers;a.addCamera(this);b.on("set:layers",this.onLayersChanged,this);c&&(c.on("add",this.onLayerAdded,this),c.on("remove",this.onLayerRemoved,this));this.enabled&&this.entity.enabled&&this.addCameraToLayers();this.postEffects.enable()},onDisable:function(){var a=this.system,b=a.app.scene, c=b.layers;this.postEffects.disable();this.removeCameraFromLayers();b.off("set:layers",this.onLayersChanged,this);c&&(c.off("add",this.onLayerAdded,this),c.off("remove",this.onLayerRemoved,this));a.removeCamera(this)},onRemove:function(){this.onDisable();this.off()},calculateAspectRatio:function(a){a=a?a:this.system.app.graphicsDevice;var b=this.rect;return a.width*b.z/(a.height*b.w)},frameBegin:function(a){0===this.aspectRatioMode&&(this.aspectRatio=this.calculateAspectRatio(a))},frameEnd:function(){}, enterVr:function(a,b){a instanceof Function&&!b&&(b=a,a=null);if(this.system.app.vr)if(a||(a=this.system.app.vr.display),a){var c=this;a.capabilities.canPresent?a.requestPresent(function(d){d||(c.vrDisplay=a,c.vrDisplay.once("beforepresentchange",function(e){e.presenting||(c.vrDisplay=null)}));b(d)}):(c.vrDisplay=a,b())}else b("No pc.VrDisplay to present");else b("VrManager not created. Enable VR in project settings.")},exitVr:function(a){if(this.vrDisplay)if(this.vrDisplay.capabilities.canPresent){var b= this.vrDisplay;this.vrDisplay=null;b.exitPresent(a)}else this.vrDisplay=null,a();else a("Not presenting VR")},startXr:function(a,b,c){this.system.app.xr.start(this,a,b,c)},endXr:function(a){this._camera.xr?this._camera.xr.end(a):a&&a(Error("Camera is not in XR"))}});var Rm=["enabled"],Me=function(a){H.call(this,a);this.id="camera";this.ComponentType=Ob;this.DataType=fo;this.schema=Rm;this.cameras=[];this.on("beforeremove",this.onBeforeRemove,this);this.app.on("prerender",this.onPrerender,this);H.bind("update", this.onUpdate,this)};Me.prototype=Object.create(H.prototype);Me.prototype.constructor=Me;O._buildAccessors(Ob.prototype,Rm);Object.assign(Me.prototype,{initializeComponentData:function(a,b,c){c="aspectRatio aspectRatioMode calculateProjection calculateTransform clearColor clearColorBuffer clearDepthBuffer clearStencilBuffer cullFaces farClip flipFaces fov frustumCulling horizontalFov layers renderTarget nearClip orthoHeight projection priority rect scissorRect".split(" ");for(var d=0;dTc?Tc+1:t,t>Tc?t+1:Tc);if(v)for(lg=qc.length;lg--&&0this._maxLines||py&&0 this._maxLines||p=this._meshInfo.length)Q.lines[p-1]-=C,Q.quad-=C;else for(Q=D,E=r;Ethis._element.calculatedWidth&&(ha=Math.floor(this._element.fontSize*this._element.calculatedWidth/(this.width||1E-4)),ha=N.clamp(ha,d,e),ha!==this._element.fontSize)){this._fontSize=ha;G=!0;break}this.height=Math.max(this.height,w-(h+A));if(this._shouldAutoFitHeight()&& this.height>this._element.calculatedHeight&&(ha=N.clamp(this._fontSize-1,d,e),ha!==this._element.fontSize)){this._fontSize=ha;G=!0;break}k+=this._spacing*ba;bf||Nb||(n=k);Lp.test(E)&&(u++,q=n,r=D+1);x++;E=this._getUv(E);Q.uvs[8*C]=E[0];Q.uvs[8*C+1]=E[1];Q.uvs[8*C+2]=E[2];Q.uvs[8*C+3]=E[1];Q.uvs[8*C+4]=E[2];Q.uvs[8*C+5]=E[3];Q.uvs[8*C+6]=E[0];Q.uvs[8*C+7]=E[3];this._symbolColors&&(I=3*this._symbolColors[D],J=this._colorPalette[I],R=this._colorPalette[I+1],I=this._colorPalette[I+2]);Q.colors[16*C]= J;Q.colors[16*C+1]=R;Q.colors[16*C+2]=I;Q.colors[16*C+3]=255;Q.colors[16*C+4]=J;Q.colors[16*C+5]=R;Q.colors[16*C+6]=I;Q.colors[16*C+7]=255;Q.colors[16*C+8]=J;Q.colors[16*C+9]=R;Q.colors[16*C+10]=I;Q.colors[16*C+11]=255;Q.colors[16*C+12]=J;Q.colors[16*C+13]=R;Q.colors[16*C+14]=I;Q.colors[16*C+15]=255;Q.quad++}}G||tl;++l)this._meshInfo[D].positions[W+3*l]=this._element.calculatedWidth-this._meshInfo[D].positions[W+3*l]+2*y;l=this._meshInfo[D].positions[W+3];n=this._meshInfo[D].positions[W+6];this._meshInfo[D].positions[W+3]=this._meshInfo[D].positions[W+0];this._meshInfo[D].positions[W+ 6]=this._meshInfo[D].positions[W+9];this._meshInfo[D].positions[W+0]=l;this._meshInfo[D].positions[W+9]=n}W=g+1}g=4*this._meshInfo[D].count;y=4*this._meshInfo[D].quad;C=new Pb(this._meshInfo[D].meshInstance.mesh.vertexBuffer);for(W=0;W=y?(C.element.POSITION.set(0,0,0),C.element.TEXCOORD0.set(0,0),C.element.COLOR.set(0,0,0,0)):(C.element.POSITION.set(this._meshInfo[D].positions[3*W],this._meshInfo[D].positions[3*W+1],this._meshInfo[D].positions[3*W+2]),C.element.TEXCOORD0.set(this._meshInfo[D].uvs[2* W],this._meshInfo[D].uvs[2*W+1]),C.element.COLOR.set(this._meshInfo[D].colors[4*W],this._meshInfo[D].colors[4*W+1],this._meshInfo[D].colors[4*W+2],this._meshInfo[D].colors[4*W+3])),C.next();C.end();this._meshInfo[D].meshInstance.mesh.aabb.compute(this._meshInfo[D].positions);this._meshInfo[D].meshInstance._aabbVer=-1}this._aabbDirty=!0},_onFontRender:function(){this.font=this._font},_onFontLoad:function(a){this.font!==a.resource&&(this.font=a.resource)},_onFontChange:function(a,b,c,d){if("data"=== b)for(this._font.data=c,a=this._font.data.info.maps.length,b=0;bthis._font.textures.length&&(this._meshInfo.length=this._font.textures.length);this._updateText()}}});Object.defineProperty(na.prototype,"alignment", {get:function(){return this._alignment},set:function(a){a instanceof P?this._alignment.set(a.x,a.y):this._alignment.set(a[0],a[1]);this._font&&this._updateText()}});Object.defineProperty(na.prototype,"autoWidth",{get:function(){return this._autoWidth},set:function(a){var b=this._autoWidth;(this._autoWidth=a)&&1E-4>Math.abs(this._element.anchor.x-this._element.anchor.z)&&(this._element.width=this.width);b!==a&&(a=this._shouldAutoFit()?this._maxFontSize:this._originalFontSize,a!==this._fontSize&&(this._fontSize= a,this._font&&this._updateText()))}});Object.defineProperty(na.prototype,"autoHeight",{get:function(){return this._autoHeight},set:function(a){var b=this._autoHeight;(this._autoHeight=a)&&1E-4>Math.abs(this._element.anchor.y-this._element.anchor.w)&&(this._element.height=this.height);b!==a&&(a=this._shouldAutoFit()?this._maxFontSize:this._originalFontSize,a!==this._fontSize&&(this._fontSize=a,this._font&&this._updateText()))}});Object.defineProperty(na.prototype,"rtlReorder",{get:function(){return this._rtlReorder}, set:function(a){this._rtlReorder!==a&&(this._rtlReorder=a,this._font&&this._updateText())}});Object.defineProperty(na.prototype,"unicodeConverter",{get:function(){return this._unicodeConverter},set:function(a){this._unicodeConverter!==a&&(this._unicodeConverter=a,this._setText(this._text))}});Object.defineProperty(na.prototype,"aabb",{get:function(){if(this._aabbDirty){for(var a=!1,b=0;bthis.system._prerender.indexOf(a)&&this.system._prerender.push(a)}a=b}},_onPrerender:function(){for(var a=0;athis.layers.indexOf(a.id)||(this._image?a.addMeshInstances(this._image._model.meshInstances):this._text&&a.addMeshInstances(this._text._model.meshInstances))},onLayerRemoved:function(a){0>this.layers.indexOf(a.id)||(this._image?a.removeMeshInstances(this._image._model.meshInstances):this._text&&a.removeMeshInstances(this._text._model.meshInstances))},onEnable:function(){if(this._image)this._image.onEnable();if(this._text)this._text.onEnable(); if(this._group)this._group.onEnable();this.useInput&&this.system.app.elementInput&&this.system.app.elementInput.addElement(this);this.system.app.scene.on("set:layers",this.onLayersChanged,this);this.system.app.scene.layers&&(this.system.app.scene.layers.on("add",this.onLayerAdded,this),this.system.app.scene.layers.on("remove",this.onLayerRemoved,this));0<=this._batchGroupId&&this.system.app.batcher.insert(bb.ELEMENT,this.batchGroupId,this.entity);this.fire("enableelement")},onDisable:function(){this.system.app.scene.off("set:layers", this.onLayersChanged,this);this.system.app.scene.layers&&(this.system.app.scene.layers.off("add",this.onLayerAdded,this),this.system.app.scene.layers.off("remove",this.onLayerRemoved,this));if(this._image)this._image.onDisable();if(this._text)this._text.onDisable();if(this._group)this._group.onDisable();this.system.app.elementInput&&this.useInput&&this.system.app.elementInput.removeElement(this);0<=this._batchGroupId&&this.system.app.batcher.remove(bb.ELEMENT,this.batchGroupId,this.entity);this.fire("disableelement")}, onRemove:function(){this.entity.off("insert",this._onInsert,this);this._unpatch();this._image&&this._image.destroy();this._text&&this._text.destroy();this.system.app.elementInput&&this.useInput&&this.system.app.elementInput.removeElement(this);this.screen&&this.screen.screen&&(this._unbindScreen(this.screen.screen),this.screen.screen.syncDrawOrder());this.off()},_calculateSize:function(a,b){if(this.entity._parent||this.screen){this._calculateLocalAnchors();var c=this._absRight-this._absLeft,d=this._absTop- this._absBottom;a?this._setWidth(c):this._setCalculatedWidth(c,!1);b?this._setHeight(d):this._setCalculatedHeight(d,!1);a=this.entity.getLocalPosition();a.x=this._margin.x+this._calculatedWidth*this._pivot.x;a.y=this._margin.y+this._calculatedHeight*this._pivot.y;this.entity.setLocalPosition(a);this._sizeDirty=!1}},_setWidth:function(a){this._width=a;this._setCalculatedWidth(a,!1);this.fire("set:width",this._width)},_setHeight:function(a){this._height=a;this._setCalculatedHeight(a,!1);this.fire("set:height", this._height)},_setCalculatedWidth:function(a,b){1E-4>=Math.abs(a-this._calculatedWidth)||(this._calculatedWidth=a,this.entity._dirtifyLocal(),b&&(a=this.entity.getLocalPosition(),this._margin.x=a.x-this._calculatedWidth*this._pivot.x,this._margin.z=this._localAnchor.z-this._localAnchor.x-this._calculatedWidth-this._margin.x),this._flagChildrenAsDirty(),this.fire("set:calculatedWidth",this._calculatedWidth),this.fire("resize",this._calculatedWidth,this._calculatedHeight))},_setCalculatedHeight:function(a, b){1E-4>=Math.abs(a-this._calculatedHeight)||(this._calculatedHeight=a,this.entity._dirtifyLocal(),b&&(a=this.entity.getLocalPosition(),this._margin.y=a.y-this._calculatedHeight*this._pivot.y,this._margin.w=this._localAnchor.w-this._localAnchor.y-this._calculatedHeight-this._margin.y),this._flagChildrenAsDirty(),this.fire("set:calculatedHeight",this._calculatedHeight),this.fire("resize",this._calculatedWidth,this._calculatedHeight))},_flagChildrenAsDirty:function(){var a,b=this.entity._children;var c= 0;for(a=b.length;cc||g>a||kc;c++)this._screenTransform.transformPoint(this._screenCorners[c],this._screenCorners[c]),b&&this._screenCorners[c].scale(this.screen.screen.scale),a&&this._screenCorners[c].add(a);this._cornersDirty=!1;this._worldCornersDirty=this._canvasCornersDirty=!0;return this._screenCorners}});Object.defineProperty(ia.prototype,"canvasCorners",{get:function(){if(!this._canvasCornersDirty||!this.screen||!this.screen.screen.screenSpace)return this._canvasCorners;for(var a=this.system.app.graphicsDevice, b=this.screenCorners,c=a.canvas.clientWidth/a.width,d=a.canvas.clientHeight/a.height,e=0;4>e;e++)this._canvasCorners[e].set(b[e].x*c,(a.height-b[e].y)*d);this._canvasCornersDirty=!1;return this._canvasCorners}});Object.defineProperty(ia.prototype,"worldCorners",{get:function(){if(!this._worldCornersDirty)return this._worldCorners;if(this.screen){var a=this.screenCorners;if(!this.screen.screen.screenSpace){bc.copy(this.screen.screen._screenMatrix);bc.data[13]=-bc.data[13];bc.mul2(this.screen.getWorldTransform(), bc);for(var b=0;4>b;b++)bc.transformPoint(a[b],this._worldCorners[b])}}else a=this.entity.getLocalPosition(),bc.setTranslate(-a.x,-a.y,-a.z),Ih.setTRS(z.ZERO,this.entity.getLocalRotation(),this.entity.getLocalScale()),Jh.setTranslate(a.x,a.y,a.z),nf.copy(this.entity.parent.getWorldTransform()),nf.mul(Jh).mul(Ih).mul(bc),Fc.set(a.x-this.pivot.x*this.calculatedWidth,a.y-this.pivot.y*this.calculatedHeight,a.z),nf.transformPoint(Fc,this._worldCorners[0]),Fc.set(a.x+(1-this.pivot.x)*this.calculatedWidth, a.y-this.pivot.y*this.calculatedHeight,a.z),nf.transformPoint(Fc,this._worldCorners[1]),Fc.set(a.x+(1-this.pivot.x)*this.calculatedWidth,a.y+(1-this.pivot.y)*this.calculatedHeight,a.z),nf.transformPoint(Fc,this._worldCorners[2]),Fc.set(a.x-this.pivot.x*this.calculatedWidth,a.y+(1-this.pivot.y)*this.calculatedHeight,a.z),nf.transformPoint(Fc,this._worldCorners[3]);this._worldCornersDirty=!1;return this._worldCorners}});Object.defineProperty(ia.prototype,"textWidth",{get:function(){return this._text? this._text.width:0}});Object.defineProperty(ia.prototype,"textHeight",{get:function(){return this._text?this._text.height:0}});Object.defineProperty(ia.prototype,"useInput",{get:function(){return this._useInput},set:function(a){this._useInput!==a&&(this._useInput=a,this.system.app.elementInput&&(a?this.enabled&&this.entity.enabled&&this.system.app.elementInput.addElement(this):this.system.app.elementInput.removeElement(this)),this.fire("set:useInput",a))}});Object.defineProperty(ia.prototype,"batchGroupId", {get:function(){return this._batchGroupId},set:function(a){this._batchGroupId!==a&&(this.entity.enabled&&0<=this._batchGroupId&&this.system.app.batcher.remove(bb.ELEMENT,this.batchGroupId,this.entity),this.entity.enabled&&0<=a&&this.system.app.batcher.insert(bb.ELEMENT,a,this.entity),0>a&&0<=this._batchGroupId&&this.enabled&&this.entity.enabled&&(this._image&&this._image._renderable.model?this.addModelToLayers(this._image._renderable.model):this._text&&this._text._model&&this.addModelToLayers(this._text._model)), this._batchGroupId=a)}});Object.defineProperty(ia.prototype,"maskedBy",{get:function(){return this._maskedBy}});var ja=function(a){Object.defineProperty(ia.prototype,a,{get:function(){return this._text?this._text[a]:this._image?this._image[a]:null},set:function(b){this._text?this._text[a]=b:this._image&&(this._image[a]=b)}})};ja("fontSize");ja("minFontSize");ja("maxFontSize");ja("maxLines");ja("autoFitWidth");ja("autoFitHeight");ja("color");ja("font");ja("fontAsset");ja("spacing");ja("lineHeight"); ja("wrapLines");ja("lines");ja("alignment");ja("autoWidth");ja("autoHeight");ja("rtlReorder");ja("unicodeConverter");ja("text");ja("key");ja("texture");ja("textureAsset");ja("material");ja("materialAsset");ja("sprite");ja("spriteAsset");ja("spriteFrame");ja("pixelsPerUnit");ja("opacity");ja("rect");ja("mask");ja("outlineColor");ja("outlineThickness");ja("shadowColor");ja("shadowOffset");ja("enableMarkup");ja("rangeStart");ja("rangeEnd");var ol=["enabled"];Ce.prototype=Object.create(H.prototype);Ce.prototype.constructor= Ce;O._buildAccessors(ia.prototype,ol);Object.assign(Ce.prototype,{destroy:function(){this._defaultTexture.destroy()},initializeComponentData:function(a,b,c){a._beingInitialized=!0;void 0!==b.anchor&&(b.anchor instanceof X?a.anchor.copy(b.anchor):a.anchor.set(b.anchor[0],b.anchor[1],b.anchor[2],b.anchor[3]));void 0!==b.pivot&&(b.pivot instanceof P?a.pivot.copy(b.pivot):a.pivot.set(b.pivot[0],b.pivot[1]));var d=.001=a;this._isPcf=4===a||0===a;this._shadowType=a;this._destroyShadowMap(); this.updateKey()}}});Object.defineProperty(Va.prototype,"castShadows",{get:function(){return this._castShadows&&4!==this.mask&&0!==this.mask},set:function(a){this._castShadows!==a&&(this._castShadows=a,this.updateKey())}});Object.defineProperty(Va.prototype,"shadowResolution",{get:function(){return this._shadowResolution},set:function(a){if(this._shadowResolution!==a){var b=ea.getApplication().graphicsDevice;this._shadowResolution=a=1===this._type?Math.min(a,b.maxCubeMapSize):Math.min(a,b.maxTextureSize)}}}); Object.defineProperty(Va.prototype,"vsmBlurSize",{get:function(){return this._vsmBlurSize},set:function(a){this._vsmBlurSize!==a&&(0===a%2&&a++,this._vsmBlurSize=a)}});Object.defineProperty(Va.prototype,"normalOffsetBias",{get:function(){return this._normalOffsetBias},set:function(a){this._normalOffsetBias!==a&&((!this._normalOffsetBias&&a||this._normalOffsetBias&&!a)&&this.updateKey(),this._normalOffsetBias=a)}});Object.defineProperty(Va.prototype,"falloffMode",{get:function(){return this._falloffMode}, set:function(a){this._falloffMode!==a&&(this._falloffMode=a,this.updateKey())}});Object.defineProperty(Va.prototype,"innerConeAngle",{get:function(){return this._innerConeAngle},set:function(a){this._innerConeAngle!==a&&(this._innerConeAngle=a,this._innerConeAngleCos=Math.cos(a*Math.PI/180))}});Object.defineProperty(Va.prototype,"outerConeAngle",{get:function(){return this._outerConeAngle},set:function(a){this._outerConeAngle!==a&&(this._outerConeAngle=a,this._outerConeAngleCos=Math.cos(a*Math.PI/ 180))}});Object.defineProperty(Va.prototype,"intensity",{get:function(){return this._intensity},set:function(a){this._intensity!==a&&(this._intensity=a,this._updateFinalColor())}});Object.defineProperty(Va.prototype,"cookie",{get:function(){return this._cookie},set:function(a){this._cookie!==a&&(this._cookie=a,this.updateKey())}});Object.defineProperty(Va.prototype,"cookieFalloff",{get:function(){return this._cookieFalloff},set:function(a){this._cookieFalloff!==a&&(this._cookieFalloff=a,this.updateKey())}}); Object.defineProperty(Va.prototype,"cookieChannel",{get:function(){return this._cookieChannel},set:function(a){if(this._cookieChannel!==a){if(3>a.length)for(var b=a.charAt(a.length-1),c=3-a.length,d=0;dthis.layers.indexOf(a.id)||this.enabled&&this.entity.enabled&&a.addLight(this)},onLayerRemoved:function(a){0>this.layers.indexOf(a.id)||a.removeLight(this)},refreshProperties:function(){for(var a,b=0;bthis.layers.indexOf(a.id)|| a.addMeshInstances(this.meshInstances)},onLayerRemoved:function(a){0>this.layers.indexOf(a.id)||a.removeMeshInstances(this.meshInstances)},_setMaterialEvent:function(a,b,c,d){b=b+":"+c;this.system.app.assets.on(b,d,this);this._materialEvents||(this._materialEvents=[]);this._materialEvents[a]||(this._materialEvents[a]={});this._materialEvents[a][b]={id:c,handler:d}},_unsetMaterialEvents:function(){var a=this.system.app.assets,b=this._materialEvents;if(b){for(var c=0,d=b.length;ca&&0<=this._batchGroupId&&this.enabled&&this.entity.enabled&& this.addModelToLayers();this._batchGroupId=a}}});Object.defineProperty(Ha.prototype,"materialAsset",{get:function(){return this._materialAsset},set:function(a){var b=a;a instanceof aa&&(b=a.id);a=this.system.app.assets;if(b!==this._materialAsset){if(this._materialAsset){a.off("add:"+this._materialAsset,this._onMaterialAssetAdd,this);var c=a.get(this._materialAsset);c&&this._unbindMaterialAsset(c)}(this._materialAsset=b)?(b=a.get(this._materialAsset))?this._bindMaterialAsset(b):(this._setMaterial(this.system.defaultMaterial), a.on("add:"+this._materialAsset,this._onMaterialAssetAdd,this)):this._setMaterial(this.system.defaultMaterial)}}});Object.defineProperty(Ha.prototype,"material",{get:function(){return this._material},set:function(a){this._material!==a&&(this.materialAsset=null,this._setMaterial(a))}});Object.defineProperty(Ha.prototype,"mapping",{get:function(){return this._mapping},set:function(a){if("asset"===this._type&&(this._unsetMaterialEvents(),a||(a={}),this._mapping=a,this._model)){var b=this._model.meshInstances, c=this.asset?this.system.app.assets.get(this.asset):null;c=c?c.data.mapping:null;for(var d=null,e=0,f=b.length;ethis.layers.indexOf(a.id)||a.addMeshInstances(this.data.model.meshInstances))},onLayerRemoved:function(a){this.data.model&&(0>this.layers.indexOf(a.id)||a.removeMeshInstances(this.data.model.meshInstances))},_bindColorMapAsset:function(a){a.on("load",this._onColorMapAssetLoad, this);a.on("unload",this._onColorMapAssetUnload,this);a.on("remove",this._onColorMapAssetRemove,this);a.on("change",this._onColorMapAssetChange,this);a.resource?this._onColorMapAssetLoad(a):this.enabled&&this.entity.enabled&&this.system.app.assets.load(a)},_unbindColorMapAsset:function(a){a.off("load",this._onColorMapAssetLoad,this);a.off("unload",this._onColorMapAssetUnload,this);a.off("remove",this._onColorMapAssetRemove,this);a.off("change",this._onColorMapAssetChange,this)},_onColorMapAssetLoad:function(a){this.colorMap= a.resource},_onColorMapAssetUnload:function(a){this.colorMap=null},_onColorMapAssetRemove:function(a){this._onColorMapAssetUnload(a)},_onColorMapAssetChange:function(a){},onSetColorMapAsset:function(a,b,c){var d=this;a=this.system.app.assets;b&&(b=a.get(b))&&this._unbindColorMapAsset(b);if(c)if(c instanceof aa&&(c=this.data.colorMapAsset=c.id),b=a.get(c))d._bindColorMapAsset(b);else a.once("add:"+c,function(e){d._bindColorMapAsset(e)});else this.colorMap=null},_bindNormalMapAsset:function(a){a.on("load", this._onNormalMapAssetLoad,this);a.on("unload",this._onNormalMapAssetUnload,this);a.on("remove",this._onNormalMapAssetRemove,this);a.on("change",this._onNormalMapAssetChange,this);a.resource?this._onNormalMapAssetLoad(a):this.enabled&&this.entity.enabled&&this.system.app.assets.load(a)},_unbindNormalMapAsset:function(a){a.off("load",this._onNormalMapAssetLoad,this);a.off("unload",this._onNormalMapAssetUnload,this);a.off("remove",this._onNormalMapAssetRemove,this);a.off("change",this._onNormalMapAssetChange, this)},_onNormalMapAssetLoad:function(a){this.normalMap=a.resource},_onNormalMapAssetUnload:function(a){this.normalMap=null},_onNormalMapAssetRemove:function(a){this._onNormalMapAssetUnload(a)},_onNormalMapAssetChange:function(a){},onSetNormalMapAsset:function(a,b,c){var d=this;a=this.system.app.assets;b&&(b=a.get(b))&&this._unbindNormalMapAsset(b);if(c)if(c instanceof aa&&(c=this.data.normalMapAsset=c.id),b=a.get(c))d._bindNormalMapAsset(b);else a.once("add:"+c,function(e){d._bindNormalMapAsset(e)}); else this.normalMap=null},_bindMeshAsset:function(a){a.on("load",this._onMeshAssetLoad,this);a.on("unload",this._onMeshAssetUnload,this);a.on("remove",this._onMeshAssetRemove,this);a.on("change",this._onMeshAssetChange,this);a.resource?this._onMeshAssetLoad(a):this.enabled&&this.entity.enabled&&this.system.app.assets.load(a)},_unbindMeshAsset:function(a){a.off("load",this._onMeshAssetLoad,this);a.off("unload",this._onMeshAssetUnload,this);a.off("remove",this._onMeshAssetRemove,this);a.off("change", this._onMeshAssetChange,this)},_onMeshAssetLoad:function(a){this._onMeshChanged(a.resource)},_onMeshAssetUnload:function(a){this.mesh=null},_onMeshAssetRemove:function(a){this._onMeshAssetUnload(a)},_onMeshAssetChange:function(a){},onSetMeshAsset:function(a,b,c){a=this.system.app.assets;b&&(b=a.get(b))&&this._unbindMeshAsset(b);if(c){if(c instanceof aa&&(c=this.data.meshAsset=c.id),b=a.get(c))this._bindMeshAsset(b),b.resource?this._onMeshChanged(b.resource):a.load(b)}else this._onMeshChanged(null)}, onSetMesh:function(a,b,c){!c||c instanceof aa||"number"===typeof c?this.meshAsset=c:this._onMeshChanged(c)},_onMeshChanged:function(a){!a||a instanceof rb||(a=a.meshInstances[0]?a.meshInstances[0].mesh:null);this.data.mesh=a;this.emitter&&(this.emitter.mesh=a,this.emitter.resetMaterial(),this.rebuild())},onSetLoop:function(a,b,c){this.emitter&&(this.emitter[a]=c,this.emitter.resetTime())},onSetBlendType:function(a,b,c){this.emitter&&(this.emitter[a]=c,this.emitter.material.blendType=c,this.emitter.resetMaterial(), this.rebuild())},_requestDepth:function(){this._requestedDepth||(of||(of=this.system.app.scene.layers.getLayerById(1)),of&&(of.incrementCounter(),this._requestedDepth=!0))},_releaseDepth:function(){this._requestedDepth&&of&&(of.decrementCounter(),this._requestedDepth=!1)},onSetDepthSoftening:function(a,b,c){b!==c&&(c?this.enabled&&this.entity.enabled&&this._requestDepth():this.enabled&&this.entity.enabled&&this._releaseDepth(),this.emitter&&(this.emitter[a]=c),this.emitter&&(this.reset(),this.emitter.resetMaterial(), this.rebuild()))},onSetSimpleProperty:function(a,b,c){this.emitter&&(this.emitter[a]=c,this.emitter.resetMaterial())},onSetComplexProperty:function(a,b,c){this.emitter&&(this.emitter[a]=c,this.emitter.resetMaterial(),this.rebuild(),this.reset())},onSetGraphProperty:function(a,b,c){this.emitter&&(this.emitter[a]=c,this.emitter.rebuildGraphs(),this.emitter.resetMaterial())},onEnable:function(){for(var a=this.data,b=0,c=Nh.length;bg;g++)n[3*g]=this.app.scene.ambientLight.r,n[3*g+1]=this.app.scene.ambientLight.g,n[3*g+2]=this.app.scene.ambientLight.b; var p=f._sortedLights[0];for(c=0;cf;f++){var q=Math.max(h.lightCubeDir[f].dot(p[c]._direction),0)*p[c]._intensity;n[3*f]+=p[c]._color.r*q;n[3*f+1]+=p[c]._color.g*q;n[3*f+2]+=p[c]._color.b*q}}h.constantLightCube.setValue(n)}if(!k.paused){h.simTime+=a;if(h.simTime>h.fixedTimeStep){var r=Math.floor(h.simTime/h.fixedTimeStep);h.simTime-=r*h.fixedTimeStep}if(r){r=Math.min(r,h.maxSubSteps);for(g=0;gthis._pool.length)for(var b=this._pool.length;b=this._pool.length&&this._resize(2*this._pool.length);return this._pool[this._count++]},freeAll:function(){this._count=0}});var Ub,ya,Jf,oj,pj;hc.prototype=Object.create(O.prototype);hc.prototype.constructor=hc;Object.defineProperty(hc.prototype, "linearVelocity",{get:function(){var a=this.body;a&&"dynamic"===this.type&&(a=a.getLinearVelocity(),this._linearVelocity.set(a.x(),a.y(),a.z()));return this._linearVelocity},set:function(a){var b=this.body;b&&"dynamic"===this.type&&(b.activate(),ya.setValue(a.x,a.y,a.z),b.setLinearVelocity(ya),this._linearVelocity.copy(a))}});Object.defineProperty(hc.prototype,"angularVelocity",{get:function(){var a=this.body;a&&"dynamic"===this.type&&(a=a.getAngularVelocity(),this._angularVelocity.set(a.x(),a.y(), a.z()));return this._angularVelocity},set:function(a){var b=this.body;b&&"dynamic"===this.type&&(b.activate(),ya.setValue(a.x,a.y,a.z),b.setAngularVelocity(ya),this._angularVelocity.copy(a))}});Object.assign(hc.prototype,{createBody:function(){var a=this.entity;if(a.collision){var b=a.collision.shape;a.trigger&&(a.trigger.destroy(),delete a.trigger)}if(b){if(this.body)this.system.onRemove(this.entity,this);var c="dynamic"===this.type?this.mass:0;this._getEntityTransform(Ub);b=this.system.createBody(c, b,Ub);b.setRestitution(this.restitution);b.setFriction(this.friction);b.setDamping(this.linearDamping,this.angularDamping);"dynamic"===this.type?(c=this.linearFactor,ya.setValue(c.x,c.y,c.z),b.setLinearFactor(ya),c=this.angularFactor,ya.setValue(c.x,c.y,c.z),b.setAngularFactor(ya)):"kinematic"===this.type&&(b.setCollisionFlags(b.getCollisionFlags()|2),b.setActivationState(4));b.entity=a;a.rigidbody.body=b;this.enabled&&this.entity.enabled&&this.enableSimulation()}},isActive:function(){var a=this.body; return a?a.isActive():!1},activate:function(){var a=this.body;a&&a.activate()},enableSimulation:function(){if(this.entity.collision&&this.entity.collision.enabled&&!this.data.simulationEnabled){var a=this.body;if(a){this.system.addBody(a,this.group,this.mask);switch(this.type){case "dynamic":this.system._dynamic.push(this);a.forceActivationState(1);this.syncEntityToBody();break;case "kinematic":this.system._kinematic.push(this);a.forceActivationState(4);break;case He:a.forceActivationState(1),this.syncEntityToBody()}"compound"=== this.entity.collision.type&&this.system._compounds.push(this.entity.collision);a.activate();this.data.simulationEnabled=!0}}},disableSimulation:function(){var a=this.body;if(a&&this.data.simulationEnabled){var b=this.system._compounds.indexOf(this.entity.collision);-1arguments.length?(arguments[0]&&this.entity.setPosition(arguments[0]),arguments[1]&&(arguments[1]instanceof Y?this.entity.setRotation(arguments[1]):this.entity.setEulerAngles(arguments[1]))):(6===arguments.length&&this.entity.setEulerAngles(arguments[3],arguments[4],arguments[5]),this.entity.setPosition(arguments[0],arguments[1],arguments[2]));this.syncEntityToBody()},onEnable:function(){this.body||this.createBody(); this.enableSimulation()},onDisable:function(){this.disableSimulation()},onSetMass:function(a,b,c){(a=this.data.body)&&"dynamic"===this.type&&((b=this.enabled&&this.entity.enabled)&&this.disableSimulation(),a.getCollisionShape().calculateLocalInertia(c,ya),a.setMassProps(c,ya),a.updateInertiaTensor(),b&&this.enableSimulation())},onSetLinearDamping:function(a,b,c){(a=this.data.body)&&a.setDamping(c,this.data.angularDamping)},onSetAngularDamping:function(a,b,c){(a=this.data.body)&&a.setDamping(this.data.linearDamping, c)},onSetLinearFactor:function(a,b,c){(a=this.data.body)&&"dynamic"===this.type&&(ya.setValue(c.x,c.y,c.z),a.setLinearFactor(ya))},onSetAngularFactor:function(a,b,c){(a=this.data.body)&&"dynamic"===this.type&&(ya.setValue(c.x,c.y,c.z),a.setAngularFactor(ya))},onSetFriction:function(a,b,c){(a=this.data.body)&&a.setFriction(c)},onSetRestitution:function(a,b,c){(a=this.data.body)&&a.setRestitution(c)},onSetType:function(a,b,c){c!==b&&(this.disableSimulation(),"dynamic"===c?(this.data.group=1,this.data.mask= 65535):"kinematic"===c?(this.data.group=4,this.data.mask=65535):(this.data.group=qj,this.data.mask=Wg),this.createBody())},onSetGroupOrMask:function(a,b,c){c!==b&&this.enabled&&this.entity.enabled&&(this.disableSimulation(),this.enableSimulation())},onSetBody:function(a,b,c){this.body&&this.data.simulationEnabled&&this.body.activate()}});var ne,oe,wd={},mg={},xl="enabled type mass linearDamping angularDamping linearFactor angularFactor friction restitution group mask body".split(" ");Ud.prototype= Object.create(H.prototype);Ud.prototype.constructor=Ud;O._buildAccessors(hc.prototype,xl);Object.assign(Ud.prototype,{onLibraryLoaded:function(){if("undefined"!==typeof Ammo){this.collisionConfiguration=new Ammo.btDefaultCollisionConfiguration;this.dispatcher=new Ammo.btCollisionDispatcher(this.collisionConfiguration);this.overlappingPairCache=new Ammo.btDbvtBroadphase;this.solver=new Ammo.btSequentialImpulseConstraintSolver;this.dynamicsWorld=new Ammo.btDiscreteDynamicsWorld(this.dispatcher,this.overlappingPairCache, this.solver,this.collisionConfiguration);if(this.dynamicsWorld.setInternalTickCallback){var a=Ammo.addFunction(this._checkForCollisions.bind(this),"vif");this.dynamicsWorld.setInternalTickCallback(a)}ne=new Ammo.btVector3;oe=new Ammo.btVector3;this.contactPointPool=new Vg(vl,1);this.contactResultPool=new Vg(wl,1);this.singleContactResultPool=new Vg(ul,1);H.bind("update",this.onUpdate,this)}else H.unbind("update",this.onUpdate,this)},initializeComponentData:function(a,b,c){c="enabled mass linearDamping angularDamping linearFactor angularFactor friction restitution type group mask".split(" "); for(var d={},e=0,f=c.length;ewd[d].others.indexOf(b)&&(wd[d].others.push(b),c=!0);mg[d]=mg[d]||{others:[],entity:a};mg[d].others.push(b);return c},_createContactPointFromAmmo:function(a){var b=a.get_m_localPointA(),c=a.get_m_localPointB(),d=a.getPositionWorldOnA(),e=a.getPositionWorldOnB();a=a.get_m_normalWorldOnB();var f=this.contactPointPool.allocate();f.localPoint.set(b.x(),b.y(),b.z());f.localPointOther.set(c.x(),c.y(),c.z());f.point.set(d.x(),d.y(),d.z());f.pointOther.set(e.x(),e.y(),e.z()); f.normal.set(a.x(),a.y(),a.z());return f},_createReverseContactPointFromAmmo:function(a){var b=a.get_m_localPointA(),c=a.get_m_localPointB(),d=a.getPositionWorldOnA(),e=a.getPositionWorldOnB();a=a.get_m_normalWorldOnB();var f=this.contactPointPool.allocate();f.localPointOther.set(b.x(),b.y(),b.z());f.localPoint.set(c.x(),c.y(),c.z());f.pointOther.set(d.x(),d.y(),d.z());f.point.set(e.x(),e.y(),e.z());f.normal.set(a.x(),a.y(),a.z());return f},_createSingleContactResult:function(a,b,c){var d=this.singleContactResultPool.allocate(); d.a=a;d.b=b;d.localPointA=c.localPoint;d.localPointB=c.localPointOther;d.pointA=c.point;d.pointB=c.pointOther;d.normal=c.normal;return d},_createContactResult:function(a,b){var c=this.contactResultPool.allocate();c.other=a;c.contacts=b;return c},_cleanOldCollisions:function(){for(var a in wd)if(wd.hasOwnProperty(a)){var b=mg[a],c=wd[a],d=c.entity,e=d.collision,f=d.rigidbody;c=c.others;for(var g=c.length;g--;){var k=c[g];if(!b||0>b.others.indexOf(k))c.splice(g,1),d.trigger?(e&&e.fire("triggerleave", k),k.rigidbody&&k.rigidbody.fire("triggerleave",d)):k.trigger||(f&&f.fire("collisionend",k),e&&e.fire("collisionend",k))}0===c.length&&delete wd[a]}},_hasContactEvent:function(a){var b=a.collision;return b&&(b.hasEvent("collisionstart")||b.hasEvent("collisionend")||b.hasEvent("contact"))?!0:(a=a.rigidbody)&&(a.hasEvent("collisionstart")||a.hasEvent("collisionend")||a.hasEvent("contact"))},_checkForCollisions:function(a,b){a=Ammo.wrapPointer(a,Ammo.btDynamicsWorld).getDispatcher();b=a.getNumManifolds(); mg={};for(var c=0;c=c.length){for(e=0;ea&&(c=d-1);return b};ic.prototype._doSort=function(a,b){var c=this._sortBy;return a[c]-b[c]};ic.prototype.insert=function(a){var b=this._binarySearch(a);this.items.splice(b,0,a);this.length++;this.loopIndex>=b&&this.loopIndex++};ic.prototype.append=function(a){this.items.push(a);this.length++};ic.prototype.remove=function(a){a=this.items.indexOf(a);0>a||(this.items.splice(a,1),this.length--,this.loopIndex>=a&&this.loopIndex--)}; ic.prototype.sort=function(){var a=0<=this.loopIndex?this.items[this.loopIndex]:null;this.items.sort(this._sortHandler);null!==a&&(this.loopIndex=this.items.indexOf(a))};Xa.prototype=Object.create(O.prototype);Xa.prototype.constructor=Xa;Xa.scriptMethods={initialize:"initialize",postInitialize:"postInitialize",update:"update",postUpdate:"postUpdate",swap:"swap"};Object.assign(Xa.prototype,{onEnable:function(){this._beingEnabled=!0;this._checkState();if(!this.entity._beingEnabled)this.onPostStateChange(); this._beingEnabled=!1},onDisable:function(){this._checkState()},onPostStateChange:function(){for(var a,b=this._beginLooping(),c=0,d=this.scripts.length;cb.ind&&(f=b.ind);this._insertScriptInstance(a, f,d);this._scriptsIndex[e]={instance:a,onSwap:function(){c.swap(e)}};this[e]=a;b.preloading||a.__initializeAttributes();this.fire("create",e,a);this.fire("create:"+e,a);this.system.app.scripts.on("swap:"+e,this._scriptsIndex[e].onSwap);b.preloading||(a.enabled&&!a._initialized&&(a._initialized=!0,a.initialize&&this._scriptMethod(a,Xa.scriptMethods.initialize)),a.enabled&&!a._postInitialized&&(a._postInitialized=!0,a.postInitialize&&this._scriptMethod(a,Xa.scriptMethods.postInitialize)));return a}console.warn("script '"+ e+"' is already added to entity '"+this.entity.name+"'")}else this._scriptsIndex[e]={awaiting:!0,ind:this._scripts.length},console.warn("script '"+e+"' is not found, awaiting it to be added to registry");return null},destroy:function(a){var b=a;"string"===typeof a?this.system.app.scripts.get(a):a&&(b=a.__name);a=this._scriptsIndex[b];delete this._scriptsIndex[b];if(!a)return!1;var c=a.instance;if(c&&!c._destroyed)if(c.enabled=!1,c._destroyed=!0,this._isLoopingThroughScripts)this._destroyedScripts.push(c); else{var d=this._removeScriptInstance(c);0<=d&&this._resetExecutionOrder(d,this._scripts.length)}this.system.app.scripts.off("swap:"+b,a.onSwap);delete this[b];this.fire("destroy",b,c||null);this.fire("destroy:"+b,c||null);c&&c.fire("destroy");return!0},swap:function(a){var b=a;"string"===typeof a?a=this.system.app.scripts.get(a):a&&(b=a.__name);var c=this._scriptsIndex[b];if(!c||!c.instance)return!1;c=c.instance;var d=this._scripts.indexOf(c);a=new a({app:this.system.app,entity:this.entity,enabled:c.enabled, attributes:c.__attributes});if(!a.swap)return!1;a.__initializeAttributes();this._scripts[d]=a;this._scriptsIndex[b].instance=a;this[b]=a;a.__executionOrder=d;c.update&&this._updateList.remove(c);c.postUpdate&&this._postUpdateList.remove(c);a.update&&this._updateList.insert(a);a.postUpdate&&this._postUpdateList.insert(a);this._scriptMethod(a,Xa.scriptMethods.swap,c);this.fire("swap",b,a);this.fire("swap:"+b,a);return!0},resolveDuplicatedEntityReferenceProperties:function(a,b){var c=this.entity.script, d,e,f;for(f in a._scriptsIndex){var g=this.system.app.scripts.get(f);if(g&&(d=a._scriptsIndex[f])&&d.instance){var k=c[f].__attributesRaw,h=c[f].__attributes;if(k||h){var l=!!k,n=d.instance.__attributes,p;for(p in n)if(n[p]){var q=g.attributes.get(p);if(q)if("entity"===q.type)this._resolveEntityScriptAttribute(q,p,n[p],l,k||h,b);else if("json"===q.type&&Array.isArray(q.schema)){var r=n[p],t=k?k[p]:h[p];for(d=0;d=c||0>b)return!1;var d=a,e=a;"string"!==typeof e?e=a.__name:d=null;a=this._scriptsIndex[e];if(!a||!a.instance)return!1;a=a.instance;if(d&&!(a instanceof d))return!1;d=this._scripts.indexOf(a);if(-1===d||d===b)return!1;this._scripts.splice(b,0,this._scripts.splice(d,1)[0]);this._resetExecutionOrder(0,c);this._updateList.sort();this._postUpdateList.sort(); this.fire("move",e,a,b,d);this.fire("move:"+e,a,b,d);return!0}});Object.defineProperty(Xa.prototype,"enabled",{get:function(){return this._enabled},set:function(a){var b=this._enabled;this._enabled=a;this.fire("set","enabled",b,a)}});Object.defineProperty(Xa.prototype,"scripts",{get:function(){return this._scripts},set:function(a){this._scriptsData=a;for(var b in a)if(a.hasOwnProperty(b)){var c=this._scriptsIndex[b];if(c){if("boolean"===typeof a[b].enabled&&(c.enabled=!!a[b].enabled),"object"===typeof a[b].attributes)for(var d in a[b].attributes)if(!Jb.reservedAttributes[d]){if(!c.__attributes.hasOwnProperty(d)){var e= this.system.app.scripts.get(b);e&&e.attributes.add(d,{})}c[d]=a[b].attributes[d]}}else console.log(this.order)}}});var Ph=0;Je.prototype=Object.create(H.prototype);Je.prototype.constructor=Je;Object.assign(Je.prototype,{initializeComponentData:function(a,b){a._executionOrder=Ph++;this._components.append(a);Ph>Number.MAX_SAFE_INTEGER&&this._resetExecutionOrder();a.enabled=b.hasOwnProperty("enabled")?!!b.enabled:!0;a.enabled&&a.entity.enabled&&this._enabledComponents.append(a);if(b.hasOwnProperty("order")&& b.hasOwnProperty("scripts")){a._scriptsData=b.scripts;for(var c=0;cthis.dragThreshold||Math.abs(b)>this.dragThreshold)&&this._disableContentInput()}},_onSetContentOrViewportSize:function(){this._syncAll()},_onSetHorizontalScrollbarValue:function(a){!this._scrollbarUpdateFlags[0]&& this.enabled&&this.entity.enabled&&this._onSetScroll(a,null)},_onSetVerticalScrollbarValue:function(a){!this._scrollbarUpdateFlags[1]&&this.enabled&&this.entity.enabled&&this._onSetScroll(null,a)},_onSetHorizontalScrollingEnabled:function(){this._syncScrollbarEnabledState(0)},_onSetVerticalScrollingEnabled:function(){this._syncScrollbarEnabledState(1)},_onHorizontalScrollbarGain:function(){this._syncScrollbarEnabledState(0);this._syncScrollbarPosition(0)},_onVerticalScrollbarGain:function(){this._syncScrollbarEnabledState(1); this._syncScrollbarPosition(1)},_onSetScroll:function(a,b,c){!1!==c&&this._velocity.set(0,0,0);a=0|this._updateAxis(a,"x",0);(a|=this._updateAxis(b,"y",1))&&this.fire("set:scroll",this._scroll)},_updateAxis:function(a,b,c){var d=null!==a&&1E-5 this._getViewportSize(a)},_contentPositionToScrollValue:function(a){var b=this._getMaxOffset(0),c=this._getMaxOffset(1);nk.x=0===b?0:a.x/b;nk.y=0===c?0:a.y/-c;return nk},_getMaxOffset:function(a,b){b=void 0===b?this._getContentSize(a):b;var c=this._getViewportSize(a);return bMath.abs(d))return 1; c=Math.min(c/d,1);a=this._toOvershoot(this._scroll[a],b);return 0===a?c:c/(1+Math.abs(a))},_getViewportSize:function(a){return this._getSize(a,this._viewportReference)},_getContentSize:function(a){return this._getSize(a,this._contentReference)},_getSize:function(a,b){return b.entity&&b.entity.element?b.entity.element[this._getCalculatedDimension(a)]:0},_getScrollingEnabled:function(a){if(0===a)return this.horizontal;if(1===a)return this.vertical;console.warn("Unrecognized orientation: "+a)},_getScrollbarVisibility:function(a){if(0=== a)return this.horizontalScrollbarVisibility;if(1===a)return this.verticalScrollbarVisibility;console.warn("Unrecognized orientation: "+a)},_getSign:function(a){return 0===a?1:-1},_getAxis:function(a){return 0===a?"x":"y"},_getCalculatedDimension:function(a){return 0===a?"calculatedWidth":"calculatedHeight"},_destroyDragHelper:function(){this._contentDragHelper&&this._contentDragHelper.destroy()},onUpdate:function(){this._contentReference.entity&&(this._updateVelocity(),this._syncScrollbarEnabledState(0), this._syncScrollbarEnabledState(1))},_updateVelocity:function(){if(!this._isDragging()&&(1===this.scrollMode&&(this._hasOvershoot("x",0)&&this._setVelocityFromOvershoot(this.scroll.x,"x",0),this._hasOvershoot("y",1)&&this._setVelocityFromOvershoot(this.scroll.y,"y",1)),this._velocity.x*=1-this.friction,this._velocity.y*=1-this.friction,1E-4a?a:a>b?a-b:0},_setVelocityFromOvershoot:function(a,b,c){a=this._toOvershoot(a,c)*this._getMaxOffset(c)*this._getSign(c);0c&&(a.x=-1*Math.log10(1-c));b=this._getMaxScrollValue(1); c=this._toOvershoot(a.y,1);0c&&(a.y=-1*Math.log10(1-c));return a},_isDragging:function(){return this._contentDragHelper&&this._contentDragHelper.isDragging},_setScrollbarComponentsEnabled:function(a){this._scrollbarReferences[0].hasComponent("scrollbar")&&(this._scrollbarReferences[0].entity.scrollbar.enabled=a);this._scrollbarReferences[1].hasComponent("scrollbar")&&(this._scrollbarReferences[1].entity.scrollbar.enabled=a)},_setContentDraggingEnabled:function(a){this._contentDragHelper&& (this._contentDragHelper.enabled=a)},_enableContentInput:function(){for(;this._disabledContentInputEntities.length;){var a=this._disabledContentInputEntities.pop();a.element&&(a.element.useInput=!0)}this._disabledContentInput=!1},_disableContentInput:function(){var a=this,b=function(f){f.element&&f.element.useInput&&(a._disabledContentInputEntities.push(f),f.element.useInput=!1);f=f.children;var g;var k=0;for(g=f.length;ka))if(0===this._state){this.stop();var b=this._suspendInstanceEvents;this._suspendInstanceEvents=!0;this._startOffset=a;this.play();this._suspendInstanceEvents=b}else this._currentTime=this._startOffset=a}})): ue()?(m.SoundInstance=function(a,b,c){M.call(this);c=c||{};this._volume=void 0!==c.volume?N.clamp(Number(c.volume)||0,0,1):1;this._pitch=void 0!==c.pitch?Math.max(.01,Number(c.pitch)||0):1;this._loop=!(void 0===c.loop||!c.loop);this._sound=b;this._state=2;this._suspendInstanceEvents=this._suspendEndEvent=this._suspended=!1;this._playWhenLoaded=!0;this._startTime=Math.max(0,Number(c.startTime)||0);this._duration=Math.max(0,Number(c.duration)||0);this._startOffset=null;this._isReady=!1;this._manager= a;this._loadedMetadataHandler=this._onLoadedMetadata.bind(this);this._timeUpdateHandler=this._onTimeUpdate.bind(this);this._endedHandler=this._onEnded.bind(this);this._onPlayCallback=c.onPlay;this._onPauseCallback=c.onPause;this._onResumeCallback=c.onResume;this._onStopCallback=c.onStop;this._onEndCallback=c.onEnd;this.source=null;this._createSource()},m.SoundInstance.prototype=Object.create(M.prototype),m.SoundInstance.prototype.constructor=m.SoundInstance,Object.assign(m.SoundInstance.prototype, {play:function(){2!==this._state&&this.stop();if(!this.source&&!this._createSource())return!1;this.volume=this._volume;this.pitch=this._pitch;this.loop=this._loop;this.source.play();this._state=0;this._playWhenLoaded=!1;this._manager.on("volumechange",this._onManagerVolumeChange,this);this._manager.on("suspend",this._onManagerSuspend,this);this._manager.on("resume",this._onManagerResume,this);this._manager.on("destroy",this._onManagerDestroy,this);this._manager.suspended&&this._onManagerSuspend(); this._suspendInstanceEvents||this._onPlay();return!0},pause:function(){if(!this.source||0!==this._state)return!1;this._suspendEndEvent=!0;this.source.pause();this._playWhenLoaded=!1;this._state=1;this._startOffset=null;this._suspendInstanceEvents||this._onPause();return!0},resume:function(){if(!this.source||1!==this._state)return!1;this._state=0;this._playWhenLoaded=!1;this.source.paused&&(this.source.play(),this._suspendInstanceEvents||this._onResume());return!0},stop:function(){if(!this.source|| 2===this._state)return!1;this._manager.off("volumechange",this._onManagerVolumeChange,this);this._manager.off("suspend",this._onManagerSuspend,this);this._manager.off("resume",this._onManagerResume,this);this._manager.off("destroy",this._onManagerDestroy,this);this._suspendEndEvent=!0;this.source.pause();this._playWhenLoaded=!1;this._state=2;this._startOffset=null;this._suspendInstanceEvents||this._onStop();return!0},setExternalNodes:function(){},clearExternalNodes:function(){},getExternalNodes:function(){return[null, null]},_onLoadedMetadata:function(){this.source.removeEventListener("loadedmetadata",this._loadedMetadataHandler);this._isReady=!0;var a=this._startOffset%this.duration||0;a=(this._startTime+a)%this._sound.duration||0;this._startOffset=null;this.source.currentTime=a},_createSource:function(){this._sound&&this._sound.audio&&(this._isReady=!1,this.source=this._sound.audio.cloneNode(!0),this.source.addEventListener("loadedmetadata",this._loadedMetadataHandler),this.source.addEventListener("timeupdate", this._timeUpdateHandler),this.source.onended=this._endedHandler);return this.source},_onTimeUpdate:function(){this._duration&&this.source.currentTime>((this._startTime+this._duration)%this.source.duration||0)&&(this.loop?this.source.currentTime=this._startTime%this.source.duration||0:(this.source.removeEventListener("timeupdate",this._timeUpdateHandler),this.source.pause(),this._onEnded()))},_onManagerDestroy:function(){this.source&&this.source.pause()}}),Object.defineProperty(m.SoundInstance.prototype, "volume",{get:function(){return this._volume},set:function(a){this._volume=a=N.clamp(a,0,1);this.source&&(this.source.volume=a*this._manager.volume)}}),Object.defineProperty(m.SoundInstance.prototype,"pitch",{get:function(){return this._pitch},set:function(a){this._pitch=Math.max(Number(a)||0,.01);this.source&&(this.source.playbackRate=this._pitch)}}),Object.defineProperty(m.SoundInstance.prototype,"loop",{get:function(){return this._loop},set:function(a){this._loop=!!a;this.source&&(this.source.loop= this._loop)}}),Object.defineProperty(m.SoundInstance.prototype,"sound",{get:function(){return this._sound},set:function(a){this.stop();this._sound=a}}),Object.defineProperty(m.SoundInstance.prototype,"currentTime",{get:function(){return null!==this._startOffset?this._startOffset:2!==this._state&&this.source?this.source.currentTime-this._startTime:0},set:function(a){0>a||(this._startOffset=a,this.source&&this._isReady&&(this.source.currentTime=(this._startTime+(a%this.duration||0))%this._sound.duration|| 0,this._startOffset=null))}})):m.SoundInstance=function(){};Object.assign(m.SoundInstance.prototype,{_onPlay:function(){this.fire("play");this._onPlayCallback&&this._onPlayCallback(this)},_onPause:function(){this.fire("pause");this._onPauseCallback&&this._onPauseCallback(this)},_onResume:function(){this.fire("resume");this._onResumeCallback&&this._onResumeCallback(this)},_onStop:function(){this.fire("stop");this._onStopCallback&&this._onStopCallback(this)},_onEnded:function(){this._suspendEndEvent? this._suspendEndEvent=!1:(this.fire("end"),this._onEndCallback&&this._onEndCallback(this),this.stop())},_onManagerVolumeChange:function(){this.volume=this._volume},_onManagerSuspend:function(){0!==this._state||this._suspended||(this._suspended=!0,this.pause())},_onManagerResume:function(){this._suspended&&(this._suspended=!1,this.resume())}});Object.defineProperty(m.SoundInstance.prototype,"startTime",{get:function(){return this._startTime},set:function(a){this._startTime=Math.max(0,Number(a)||0); a=0===this._state;this.stop();a&&this.play()}});Object.defineProperty(m.SoundInstance.prototype,"duration",{get:function(){return this._sound?this._duration?this._duration%this._sound.duration||0:this._sound.duration:0},set:function(a){this._duration=Math.max(0,Number(a)||0);a=0===this._state;this.stop();a&&this.play()}});Object.defineProperty(m.SoundInstance.prototype,"isPlaying",{get:function(){return 0===this._state}});Object.defineProperty(m.SoundInstance.prototype,"isPaused",{get:function(){return 1=== this._state}});Object.defineProperty(m.SoundInstance.prototype,"isStopped",{get:function(){return 2===this._state}});Object.defineProperty(m.SoundInstance.prototype,"isSuspended",{get:function(){return this._suspended}});if(ed())m.SoundInstance3d=function(a,b,c){m.SoundInstance.call(this,a,b,c);c=c||{};this._position=new z;c.position&&(this.position=c.position);this._velocity=new z;c.velocity&&(this.velocity=c.velocity);this.maxDistance=void 0!==c.maxDistance?Number(c.maxDistance):1E4;this.refDistance= void 0!==c.refDistance?Number(c.refDistance):1;this.rollOffFactor=void 0!==c.rollOffFactor?Number(c.rollOffFactor):1;this.distanceModel=void 0!==c.distanceModel?c.distanceModel:"linear"},m.SoundInstance3d.prototype=Object.create(m.SoundInstance.prototype),m.SoundInstance3d.prototype.constructor=m.SoundInstance3d,Object.assign(m.SoundInstance3d.prototype,{_initializeNodes:function(){this.gain=this._manager.context.createGain();this.panner=this._manager.context.createPanner();this.panner.connect(this.gain); this._inputNode=this.panner;this._connectorNode=this.gain;this._connectorNode.connect(this._manager.context.destination)}}),Object.defineProperty(m.SoundInstance3d.prototype,"position",{get:function(){return this._position},set:function(a){this._position.copy(a);this.panner.setPosition(a.x,a.y,a.z)}}),Object.defineProperty(m.SoundInstance3d.prototype,"velocity",{get:function(){return this._velocity},set:function(a){this._velocity.copy(a);this.panner.setVelocity(a.x,a.y,a.z)}}),Object.defineProperty(m.SoundInstance3d.prototype, "maxDistance",{get:function(){return this.panner.maxDistance},set:function(a){this.panner.maxDistance=a}}),Object.defineProperty(m.SoundInstance3d.prototype,"refDistance",{get:function(){return this.panner.refDistance},set:function(a){this.panner.refDistance=a}}),Object.defineProperty(m.SoundInstance3d.prototype,"rollOffFactor",{get:function(){return this.panner.rolloffFactor},set:function(a){this.panner.rolloffFactor=a}}),Object.defineProperty(m.SoundInstance3d.prototype,"distanceModel",{get:function(){return this.panner.distanceModel}, set:function(a){this.panner.distanceModel=a}});else if(ue()){var pk=new z;m.SoundInstance3d=function(a,b,c){m.SoundInstance.call(this,a,b,c);c=c||{};this._position=new z;c.position&&(this.position=c.position);this._velocity=new z;c.velocity&&(this.velocity=c.velocity);this._maxDistance=void 0!==c.maxDistance?Number(c.maxDistance):1E4;this._refDistance=void 0!==c.refDistance?Number(c.refDistance):1;this._rollOffFactor=void 0!==c.rollOffFactor?Number(c.rollOffFactor):1;this._distanceModel=void 0!== c.distanceModel?c.distanceModel:"linear"};m.SoundInstance3d.prototype=Object.create(m.SoundInstance.prototype);m.SoundInstance3d.prototype.constructor=m.SoundInstance3d;Object.defineProperty(m.SoundInstance3d.prototype,"position",{get:function(){return this._position},set:function(a){this._position.copy(a);if(this.source){var b=this._manager.listener.getPosition();a=this.refDistance;var c=this.maxDistance,d=this.rollOffFactor,e=this.distanceModel;pk=pk.sub2(b,this._position);b=pk.length();if(bc)a=0;else{var f=0;"linear"===e?f=1-d*(b-a)/(c-a):e===Hf?f=a/(a+d*(b-a)):"exponential"===e&&(f=Math.pow(b/a,-d));a=N.clamp(f,0,1)}this.source.volume=this.volume*a*this._manager.volume}}});Object.defineProperty(m.SoundInstance3d.prototype,"velocity",{get:function(){return this._velocity},set:function(a){this._velocity.copy(a)}});Object.defineProperty(m.SoundInstance3d.prototype,"maxDistance",{get:function(){return this._maxDistance},set:function(a){this._maxDistance=a}});Object.defineProperty(m.SoundInstance3d.prototype, "refDistance",{get:function(){return this._refDistance},set:function(a){this._refDistance=a}});Object.defineProperty(m.SoundInstance3d.prototype,"rollOffFactor",{get:function(){return this._rollOffFactor},set:function(a){this._rollOffFactor=a}});Object.defineProperty(m.SoundInstance3d.prototype,"distanceModel",{get:function(){return this._distanceModel},set:function(a){this._distanceModel=a}})}else m.SoundInstance3d=function(){};var fb={volume:0,pitch:0,loop:!1,startTime:0,duration:0,position:new z, maxDistance:0,refDistance:0,rollOffFactor:0,distanceModel:0,onPlay:null,onPause:null,onResume:null,onStop:null,onEnd:null};Qa.prototype=Object.create(M.prototype);Qa.prototype.constructor=Qa;Object.assign(Qa.prototype,{play:function(){this.overlap||this.stop();if(this.isLoaded||this._hasAsset()){var a=this._createInstance();this.instances.push(a);if(this.isLoaded)a.play();else{var b=function(c){var d=a._playWhenLoaded;a.sound=c;d&&a.play()};this.off("load",b);this.once("load",b);this.load()}return a}}, pause:function(){for(var a=!1,b=this.instances,c=0,d=b.length;cthis.fps?-1:1),c=this.duration;a=b>c||0>b;this._setTime(b);b=this._sprite?Math.floor(this._sprite.frameKeys.length*this._time/c):0;b!==this._frame&&this._setFrame(b);a&&(this.loop?(this.fire("loop"),this._component.fire("loop",this)):(this._paused=this._playing=!1,this.fire("end"),this._component.fire("end",this)))}},_setTime:function(a){this._time=a;a=this.duration;0>this._time?this._time=this.loop?this._time%a+a:0:this._time>a&&(this._time=this.loop?this._time% a:a)},_setFrame:function(a){this._frame=this._sprite?N.clamp(a,0,this._sprite.frameKeys.length-1):a;this._component.currentClip===this&&this._component._showFrame(this._frame)},_destroy:function(){this._sprite&&(this.sprite=null);this._spriteAsset&&(this.spriteAsset=null)},play:function(){this._playing||(this._playing=!0,this._paused=!1,this.frame=0,this.fire("play"),this._component.fire("play",this))},pause:function(){this._playing&&!this._paused&&(this._paused=!0,this.fire("pause"),this._component.fire("pause", this))},resume:function(){this._paused&&(this._paused=!1,this.fire("resume"),this._component.fire("resume",this))},stop:function(){this._playing&&(this._paused=this._playing=!1,this.frame=this._time=0,this.fire("stop"),this._component.fire("stop",this))}});Object.defineProperty(vb.prototype,"spriteAsset",{get:function(){return this._spriteAsset},set:function(a){var b=this._component.system.app.assets,c=a;a instanceof aa&&(c=a.id);this._spriteAsset!==c&&(this._spriteAsset&&(a=b.get(this._spriteAsset))&& this._unbindSpriteAsset(a),(this._spriteAsset=c)?(c=b.get(this._spriteAsset))?this._bindSpriteAsset(c):(this.sprite=null,b.on("add:"+this._spriteAsset,this._onSpriteAssetAdded,this)):this.sprite=null)}});Object.defineProperty(vb.prototype,"sprite",{get:function(){return this._sprite},set:function(a){this._sprite&&(this._sprite.off("set:meshes",this._onSpriteMeshesChange,this),this._sprite.off("set:pixelsPerUnit",this._onSpritePpuChanged,this),this._sprite.off("set:atlas",this._onSpriteMeshesChange, this),this._sprite.atlas&&this._sprite.atlas.off("set:texture",this._onSpriteMeshesChange,this));if(this._sprite=a)if(this._sprite.on("set:meshes",this._onSpriteMeshesChange,this),this._sprite.on("set:pixelsPerUnit",this._onSpritePpuChanged,this),this._sprite.on("set:atlas",this._onSpriteMeshesChange,this),this._sprite.atlas)this._sprite.atlas.on("set:texture",this._onSpriteMeshesChange,this);if(this._component.currentClip===this){var b;if(a&&a.atlas){if(a.atlas.texture){if(b=this._component._meshInstance)b.setParameter("texture_emissiveMap", a.atlas.texture),b.setParameter("texture_opacityMap",a.atlas.texture);this._component.enabled&&this._component.entity.enabled&&this._component._showModel()}this.time&&this.fps?this.time=this.time:this.frame=this.frame}else{if(b=this._component._meshInstance)b.deleteParameter("texture_emissiveMap"),b.deleteParameter("texture_opacityMap");this._component._hideModel()}}}});Object.defineProperty(vb.prototype,"frame",{get:function(){return this._frame},set:function(a){this._setFrame(a);this._setTime(this._frame/ (this.fps||Number.MIN_VALUE))}});Object.defineProperty(vb.prototype,"isPlaying",{get:function(){return this._playing}});Object.defineProperty(vb.prototype,"isPaused",{get:function(){return this._paused}});Object.defineProperty(vb.prototype,"duration",{get:function(){return this._sprite?this._sprite.frameKeys.length/Math.abs(this.fps||Number.MIN_VALUE):0}});Object.defineProperty(vb.prototype,"time",{get:function(){return this._time},set:function(a){this._setTime(a);this.frame=this._sprite?Math.min(this._sprite.frameKeys.length- 1,Math.floor(this._time*Math.abs(this.fps))):0}});var Ba=function(a,b){O.call(this,a,b);this._type="simple";this._material=a.defaultMaterial;this._color=new L(1,1,1,1);this._colorUniform=new Float32Array(3);this._speed=1;this._flipY=this._flipX=!1;this._height=this._width=1;this._drawOrder=0;this._layers=[0];this._outerScale=new P(1,1);this._outerScaleUniform=new Float32Array(2);this._innerOffset=new X;this._innerOffsetUniform=new Float32Array(4);this._atlasRect=new X;this._atlasRectUniform=new Float32Array(4); this._batchGroupId=-1;this._batchGroup=null;this._node=new Z;this._model=new sb;this._model.graph=this._node;this._meshInstance=null;b.addChild(this._model.graph);this._model._entity=b;this._updateAabbFunc=this._updateAabb.bind(this);this._addedModel=!1;this._autoPlayClip=null;this._clips={};this._currentClip=this._defaultClip=new vb(this,{name:this.entity.name,fps:0,loop:!1,spriteAsset:null})};Ba.prototype=Object.create(O.prototype);Ba.prototype.constructor=Ba;Object.assign(Ba.prototype,{onEnable:function(){var a= this.system.app,b=a.scene;b.on("set:layers",this._onLayersChanged,this);b.layers&&(b.layers.on("add",this._onLayerAdded,this),b.layers.on("remove",this._onLayerRemoved,this));this._showModel();this._autoPlayClip&&this._tryAutoPlay();0<=this._batchGroupId&&a.batcher.insert(bb.SPRITE,this._batchGroupId,this.entity)},onDisable:function(){var a=this.system.app,b=a.scene;b.off("set:layers",this._onLayersChanged,this);b.layers&&(b.layers.off("add",this._onLayerAdded,this),b.layers.off("remove",this._onLayerRemoved, this));this.stop();this._hideModel();0<=this._batchGroupId&&a.batcher.remove(bb.SPRITE,this._batchGroupId,this.entity)},onDestroy:function(){this._currentClip=null;this._defaultClip&&(this._defaultClip._destroy(),this._defaultClip=null);for(var a in this._clips)this._clips[a]._destroy();this._clips=null;this._hideModel();this._model=null;this._node&&(this._node.parent&&this._node.parent.removeChild(this._node),this._node=null);this._meshInstance&&(this._meshInstance.material=null,this._meshInstance= this._meshInstance.mesh=null)},_showModel:function(){if(!this._addedModel&&this._meshInstance){var a,b=[this._meshInstance];var c=0;for(a=this._layers.length;cthis.layers.indexOf(a.id)||this._addedModel&&this.enabled&&this.entity.enabled&& this._meshInstance&&a.addMeshInstances([this._meshInstance])},_onLayerRemoved:function(a){this._meshInstance&&(0>this.layers.indexOf(a.id)||a.removeMeshInstances([this._meshInstance]))},removeModelFromLayers:function(){for(var a,b=0;bd._timeToCountFrames?(d.fps=d._fpsAccum, d._fpsAccum=0,d._timeToCountFrames=a+1E3):d._fpsAccum++;d.cameras=this.renderer._camerasRendered;d.materials=this.renderer._materialSwitches;d.shaders=this.graphicsDevice._shaderSwitchesPerFrame;d.shadowMapUpdates=this.renderer._shadowMapUpdates;d.shadowMapTime=this.renderer._shadowMapTime;d.depthMapTime=this.renderer._depthMapTime;d.forwardTime=this.renderer._forwardTime;a=this.graphicsDevice._primsPerFrame;d.triangles=a[4]/3+Math.max(a[5]-2,0)+Math.max(a[6]-2,0);d.cullTime=this.renderer._cullTime; d.sortTime=this.renderer._sortTime;d.skinTime=this.renderer._skinTime;d.morphTime=this.renderer._morphTime;d.instancingTime=this.renderer._instancingTime;for(b=d.otherPrimitives=0;bb&&(d.otherPrimitives+=a[b]),a[b]=0;this.renderer._camerasRendered=0;this.renderer._materialSwitches=0;this.renderer._shadowMapUpdates=0;this.graphicsDevice._shaderSwitchesPerFrame=0;this.renderer._cullTime=0;this.renderer._sortTime=0;this.renderer._skinTime=0;this.renderer._morphTime=0;this.renderer._instancingTime= 0;this.renderer._shadowMapTime=0;this.renderer._depthMapTime=0;this.renderer._forwardTime=0;d=this.stats.drawCalls;d.forward=this.renderer._forwardDrawCalls;d.culled=this.renderer._numDrawCallsCulled;d.depth=0;d.shadow=this.renderer._shadowDrawCalls;d.skinned=this.renderer._skinDrawCalls;d.immediate=0;d.instanced=0;d.removedByInstancing=0;d.total=this.graphicsDevice._drawCallsPerFrame;d.misc=d.total-(d.forward+d.shadow);this.renderer._depthDrawCalls=0;this.renderer._shadowDrawCalls=0;this.renderer._forwardDrawCalls= 0;this.renderer._numDrawCallsCulled=0;this.renderer._skinDrawCalls=0;this.renderer._immediateRendered=0;this.renderer._instancedDrawCalls=0;this.renderer._removedByInstancing=0;this.graphicsDevice._drawCallsPerFrame=0;this.stats.misc.renderTargetCreationTime=this.graphicsDevice.renderTargetCreationTime;d=this.stats.particles;d.updatesPerFrame=d._updatesPerFrame;d.frameTime=d._frameTime;d._updatesPerFrame=0;d._frameTime=0},setCanvasFillMode:function(a,b,c){this._fillMode=a;this.resizeCanvas(b,c)}, setCanvasResolution:function(a,b,c){this._resolutionMode=a;"AUTO"===a&&void 0===b&&(b=this.graphicsDevice.canvas.clientWidth,c=this.graphicsDevice.canvas.clientHeight);this.graphicsDevice.resizeCanvas(b,c)},isHidden:function(){return document[this._hiddenAttr]},onVisibilityChange:function(){this.isHidden()?this._soundManager.suspend():this._soundManager.resume()},resizeCanvas:function(a,b){if(this._allowResize&&(!this.xr||!this.xr.session)){var c=window.innerWidth,d=window.innerHeight;if(this._fillMode=== Yg){var e=this.graphicsDevice.canvas.width/this.graphicsDevice.canvas.height;e>c/d?(a=c,b=a/e):(b=d,a=b*e)}else"FILL_WINDOW"===this._fillMode&&(a=c,b=d);this.graphicsDevice.canvas.style.width=a+"px";this.graphicsDevice.canvas.style.height=b+"px";"AUTO"===this._resolutionMode&&this.setCanvasResolution("AUTO");return{width:a,height:b}}},onLibrariesLoaded:function(){this._librariesLoaded=!0;this.systems.rigidbody.onLibraryLoaded()},applySceneSettings:function(a){if(this.systems.rigidbody&&"undefined"!== typeof Ammo){var b=a.physics.gravity;this.systems.rigidbody.gravity.set(b[0],b[1],b[2])}this.scene.applySettings(a);if(a.render.hasOwnProperty("skybox"))if(a.render.skybox)if(b=this.assets.get(a.render.skybox))this.setSkybox(b);else this.assets.once("add:"+a.render.skybox,this.setSkybox,this);else this.setSkybox(null)},setSkybox:function(a){a?this._skyboxLast===a.id?0!==this.scene.skyboxMip||a.loadFaces?this._onSkyboxChange(a):this._skyboxLoad(a):(this._skyboxLast&&(this.assets.off("add:"+this._skyboxLast, this.setSkybox,this),this.assets.off("load:"+this._skyboxLast,this._onSkyboxChange,this),this.assets.off("remove:"+this._skyboxLast,this._skyboxRemove,this)),this._skyboxLast=a.id,this.assets.on("load:"+a.id,this._onSkyboxChange,this),this.assets.once("remove:"+a.id,this._skyboxRemove,this),a.resource&&this.scene.setSkybox(a.resources),this._skyboxLoad(a)):this._skyboxLast&&this._skyboxRemove({id:this._skyboxLast})},enableVr:function(){this.vr||(this.vr=new gd(this))},disableVr:function(){this.vr&& (this.vr.destroy(),this.vr=null)},_onSkyboxChange:function(a){this.scene.setSkybox(a.resources)},_skyboxLoad:function(a){0===this.scene.skyboxMip&&(a.loadFaces=!0);this.assets.load(a);this._onSkyboxChange(a)},_skyboxRemove:function(a){this._skyboxLast&&(this.assets.off("add:"+a.id,this.setSkybox,this),this.assets.off("load:"+a.id,this._onSkyboxChange,this),this.assets.off("remove:"+a.id,this._skyboxRemove,this),this.scene.setSkybox(null),this._skyboxLast=null)},_firstBake:function(){this.lightmapper.bake(null, this.scene.lightmapMode)},_firstBatch:function(){this.scene._needsStaticPrepare&&(this.renderer.prepareStaticMeshes(this.graphicsDevice,this.scene),this.scene._needsStaticPrepare=!1);this.batcher.generate()},_processTimestamp:function(a){return a},_preRenderImmediate:function(){for(var a=0;ad;d++)a.transformPoint(e[d],f[d]);this.renderLines([f[0],f[1],f[1],f[2],f[2],f[3],f[3],f[0],f[4],f[5],f[5],f[6],f[6],f[7],f[7],f[4],f[0],f[4],f[1],f[5],f[2],f[6],f[3],f[7]],b,c)},renderMeshInstance:function(a,b){b||(b={layer:this.scene.layers.getLayerById(3)});this._initImmediate();this._immediateData.addLayer(b.layer);this.meshInstanceArray[0]=a;b.layer.addMeshInstances(this.meshInstanceArray,!0)},renderMesh:function(a,b,c,d){d||(d={layer:this.scene.layers.getLayerById(3)});this._initImmediate(); zd.worldTransform=c;zd._dirtyWorld=zd._dirtyNormal=!1;a=new va(zd,a,b);a.cull=!1;d.mask&&(a.mask=d.mask);this._immediateData.addLayer(d.layer);this.meshInstanceArray[0]=a;d.layer.addMeshInstances(this.meshInstanceArray,!0)},renderQuad:function(a,b,c){c||(c={layer:this.scene.layers.getLayerById(3)});this._initImmediate();if(!this._immediateData.quadMesh){var d=new Na(this.graphicsDevice,[{semantic:"POSITION",components:3,type:6}]);d=new ab(this.graphicsDevice,d,4);var e=new Pb(d);e.element.POSITION.set(-.5, -.5,0);e.next();e.element.POSITION.set(.5,-.5,0);e.next();e.element.POSITION.set(-.5,.5,0);e.next();e.element.POSITION.set(.5,.5,0);e.end();this._immediateData.quadMesh=new rb(this.graphicsDevice);this._immediateData.quadMesh.vertexBuffer=d;this._immediateData.quadMesh.primitive[0].type=5;this._immediateData.quadMesh.primitive[0].base=0;this._immediateData.quadMesh.primitive[0].count=4;this._immediateData.quadMesh.primitive[0].indexed=!1}zd.worldTransform=a;zd._dirtyWorld=zd._dirtyNormal=!1;a=new va(zd, this._immediateData.quadMesh,b);a.cull=!1;this.meshInstanceArray[0]=a;this._immediateData.addLayer(c.layer);c.layer.addMeshInstances(this.meshInstanceArray,!0)},destroy:function(){var a,b=this.graphicsDevice.canvas.id;this.off("librariesloaded");document.removeEventListener("visibilitychange",this._visibilityChangeHandler,!1);document.removeEventListener("mozvisibilitychange",this._visibilityChangeHandler,!1);document.removeEventListener("msvisibilitychange",this._visibilityChangeHandler,!1);document.removeEventListener("webkitvisibilitychange", this._visibilityChangeHandler,!1);this.onVisibilityChange=this._visibilityChangeHandler=null;this.root.destroy();this.root=null;this.mouse&&(this.mouse.off(),this.mouse.detach(),this.mouse=null);this.keyboard&&(this.keyboard.off(),this.keyboard.detach(),this.keyboard=null);this.touch&&(this.touch.off(),this.touch.detach(),this.touch=null);this.elementInput&&(this.elementInput.detach(),this.elementInput=null);this.controller&&(this.controller=null);var c=this.systems.list;var d=0;for(a=c.length;d< a;d++)c[d].destroy();H.destroy();a=this.assets.list();for(d=0;db.metalness?1:0;a.glossTint=1;a.emissiveTint=f;a.alphaToCoverage=b.alphaToCoverage;a.normalizeNormalMap=b.normalizeNormalMap;a.sphereMap=!!b.sphereMap;a.cubeMap=!!b.cubeMap;a.dpAtlas=!!b.dpAtlas;a.ambientSH=!!b.ambientSH;a.useSpecular=e;a.emissiveFormat=b.emissiveMap?"rgbm"===b.emissiveMap.type?1:14===b.emissiveMap.format?2:0:null;a.lightMapFormat=b.lightMap?"rgbm"===b.lightMap.type?1:14===b.lightMap.format? 2:0:null;a.specularAntialias=b.specularAntialias&&!!b.normalMap&&!!b.normalMap.mipmaps&&!g;a.conserveEnergy=b.conserveEnergy;a.occludeSpecular=b.occludeSpecular;a.occludeSpecularFloat=1!==b.occludeSpecularIntensity;a.occludeDirect=b.occludeDirect;a.shadingModel=b.shadingModel;a.fresnelModel=b.fresnelModel;a.packedNormal=g;a.fastTbn=b.fastTbn;a.cubeMapProjection=b.cubeMapProjection;a.customFragmentShader=b.customFragmentShader;a.refraction=!!b.refraction;a.useMetalness=b.useMetalness;a.enableGGXSpecular= b.enableGGXSpecular;a.msdf=!!b.msdfMap;a.twoSidedLighting=b.twoSidedLighting;a.pixelSnap=b.pixelSnap;a.aoMapUv=b.aoUvSet;a.diffuseDetail=!!b.diffuseMap;a.normalDetail=!!b.normalMap;a.diffuseDetailMode=b.diffuseDetailMode;a.detailModes=!!a.diffuseDetail;a.clearCoatTint=1!==b.clearCoat?1:0;a.clearCoatGlossTint=1!==b.clearCoatGlossiness?1:0};Vb.prototype._updateEnvOptions=function(a,b,c,d){var e=d&&"rgbm"===d.type||b.cubeMap&&"rgbm"===b.cubeMap.type||b.dpAtlas&&"rgbm"===b.dpAtlas.type,f=d&&("rgbm"=== d.type||14===d.format)||b.cubeMap&&("rgbm"===b.cubeMap.type||14===b.cubeMap.format)||b.dpAtlas&&("rgbm"===b.dpAtlas.type||14===b.dpAtlas.format),g=d&&!b.cubeMap&&!b.sphereMap&&!b.dpAtlas&&"rgbm"===d.type||b.cubeMap&&"rgbm"===b.cubeMap.type||b.sphereMap&&"rgbm"===b.sphereMap.type||b.dpAtlas&&"rgbm"===b.dpAtlas.type,k=(!d||b.cubeMap||b.sphereMap||b.dpAtlas?!1:"rgbm"===d.type||14===d.format)||b.cubeMap&&("rgbm"===b.cubeMap.type||14===b.cubeMap.format)||b.sphereMap&&("rgbm"===b.sphereMap.type||14===b.sphereMap.format)|| b.dpAtlas&&("rgbm"===b.dpAtlas.type||14===b.dpAtlas.format),h;b.useSkybox&&c._skyboxPrefiltered&&(h=c._skyboxPrefiltered[0]);a.fog=b.useFog?c.fog:"none";a.gamma=b.useGammaTonemap?c.gammaCorrection:0;a.toneMap=b.useGammaTonemap?c.toneMapping:-1;a.rgbmAmbient=e;a.hdrAmbient=f;a.rgbmReflection=g;a.hdrReflection=k;a.useRgbm=g||e||b.emissiveMap&&"rgbm"===b.emissiveMap.type||b.lightMap&&"rgbm"===b.lightMap.type;a.fixSeams=d?d.fixCubemapSeams:b.cubeMap?b.cubeMap.fixCubemapSeams:!1;a.prefilteredCubemap=!!d; a.skyboxIntensity=d&&h&&d===h&&1!==c.skyboxIntensity};Vb.prototype._updateLightOptions=function(a,b,c,d,e){a.lightMap=!1;a.lightMapChannel="";a.lightMapUv=0;a.lightMapTransform=0;a.lightMapWithoutAmbient=!1;a.dirLightMap=!1;c&&(a.noShadow=0!==(c&1),0!==(c&64)&&(a.lightMapFormat=1,a.lightMap=!0,a.lightMapChannel="rgb",a.lightMapUv=1,a.lightMapTransform=0,a.lightMapWithoutAmbient=!b.lightMap,a.useRgbm=!0,0!==(c&128)&&(a.dirLightMap=!0)));b.useLighting?(b=[],c=c?c>>16:1,d&&(this._collectLights(0,d[0], b,c),this._collectLights(1,d[1],b,c,e),this._collectLights(2,d[2],b,c,e)),a.lights=b):a.lights=[];0===a.lights.length&&(a.noShadow=!0)};Vb.prototype._updateTexOptions=function(a,b,c,d,e,f,g){var k=c+"Map",h=c+"VertexColor",l=c+"VertexColorChannel",n=k+"Channel",p=k+"Transform",q=k+"Uv";"light"!==c&&(a[k]=!1,a[n]="",a[p]=0,a[q]=0);a[h]=!1;a[l]="";var r="opacity"===c;if(r&&3===b.blendType&&0===b.alphaTest&&!b.alphaToCoverage)return a;if(!g||r)"height"!==c&&b[h]&&f&&(a[h]=b[h],a[l]=b[l],a.vertexColors= !0),b[k]&&(c=!0,0!==b[q]||d||(c=!1),1!==b[q]||e||(c=!1),c&&(a[k]=!!b[k],a[p]=this._getMapTransformID(b[p],b[q]),a[n]=b[n],a[q]=b[q]))};Vb.prototype._collectLights=function(a,b,c,d,e){var f;for(f=0;fq;q++)n[q]=p?Math.pow(l.data[q], 2.2):l.data[q],d&&(n[q]*=h[k]);return{name:"material_"+b,value:n}};d&&(a[k]=1,Object.defineProperty(la.prototype,g,{get:function(){return this[k]},set:function(h){var l=this[k];(0===l||1===l)^(0===h||1===h)&&(this.dirtyShader=!0);this.dirtyColor=!0;this[k]=h}}),Ra.push(g),pe[g]=function(h,l,n){l=n?h[f]:new Float32Array(3);n=!1;h.useGammaTonemap&&(n=(h._scene||ea.getApplication().scene).gammaCorrection);for(var p=0;3>p;p++)l[p]=n?Math.pow(h[e].data[p],2.2):h[e].data[p],l[p]*=h[k];return{name:"material_"+ b,value:l}})},qb=function(a,b,c,d){var e="_"+b;a[e]=c;Object.defineProperty(la.prototype,b,{get:function(){return this[e]},set:function(f){var g=this[e];g!==f&&(this[e]=f,0===g||1===g||0===f||1===f)&&(this.dirtyShader=!0)}});Ra.push(b);pe[b]=void 0!==d?d:function(f,g,k){return{name:"material_"+b,value:g}}},sc=function(a,b,c){var d="_"+b;a[d]=null;Object.defineProperty(la.prototype,b,{get:function(){return this[d]},set:function(e){!!this[d]^!!e&&(this.dirtyShader=!0);this[d]=e}});Ra.push(b);pe[b]= c},tc=function(a,b,c){Object.defineProperty(la.prototype,c,{get:function(){return this[b]},set:function(d){this[b]=d}})},Up=function(a){Object.defineProperty(la.prototype,"chunks",{get:function(){this.dirtyShader=!0;return this._chunks},set:function(b){this.dirtyShader=!0;this._chunks=b}});Ra.push("chunks")},Fa=function(a,b,c){var d="_"+b;a[d]=c;Object.defineProperty(la.prototype,b,{get:function(){return this[d]},set:function(e){this[d]!==e&&(this.dirtyShader=!0);this[d]=e}});Ra.push(b)},gn=function(){}; gn.prototype.copy=function(a){for(var b in a)a.hasOwnProperty(b)&&"copy"!==b&&(this[b]=a[b])};Object.assign(la.prototype,{reset:function(){var a;for(a=0;athis.metalness)&&this._setParameter("material_metalness",this.metalness),this.enableGGXSpecular&&this._setParameter("material_anisotropy",this.anisotropy)):this.specularMap&&!this.specularTint||this._setParameter("material_specular",this.specularUniform);0a;a++)this.emissiveUniform[a]*=this.emissiveIntensity;this.dirtyColor=!1}},updateShader:function(a,b,c,d,e,f){!this._colorProcessed&&this._scene&&(this._colorProcessed=!0,this._processColor());var g=a.useTexCubeLod,k=!a.extTextureLod;if(this.useSkybox){var h=b._skyboxPrefiltered[0]; var l=b._skyboxPrefiltered[1];var n=b._skyboxPrefiltered[2];var p=b._skyboxPrefiltered[3];var q=b._skyboxPrefiltered[4];var r=b._skyboxPrefiltered[5]}h=this.prefilteredCubeMap128||h;l=this.prefilteredCubeMap64||l;n=this.prefilteredCubeMap32||n;p=this.prefilteredCubeMap16||p;q=this.prefilteredCubeMap8||q;r=this.prefilteredCubeMap4||r;if(h){var t=h&&l&&n&&p&&q&&r;if(k&&t){if(!h.dpAtlas){g=[h,l,n,p,q,r];k=new X;r=new X;l=4*g[0].width;q=Wa(a,F.fullscreenQuadVS,F.dpAtlasQuadPS,"dpAtlasQuad");n=a.scope.resolve("source"); t=a.scope.resolve("params");var u=new V(a,{type:g[0].type,format:g[0].format,width:l,height:l,mipmaps:!1});u.name="paraboloid";for(var x=new ra(a,u,{depth:!1}),v=(l+2)/l-1,w=0;6>w;w++){var y=a;var A=g[w],B=w,E=Wa(y,F.fullscreenQuadVS,(A.fixCubemapSeams?F.fixCubemapSeamsStretchPS:F.fixCubemapSeamsNonePS)+F.genParaboloidPS,"genParaboloid"),C=y.scope.resolve("source"),D=y.scope.resolve("params"),G=new X,J=A.width,R=A.format;J=2*Math.max(J,8);J=new V(y,{type:A.type,format:R,width:2*J,height:J,mipmaps:!1}); J.name="paraboloid";R=new ra(y,J,{depth:!1});G.x=B;G.y=1;C.setValue(A);D.setValue(G.data);La(y,R,E);y=J;n.setValue(y);y=k;A=w;y.x=.5*N.clamp(A-2,0,1);A-=6*y.x;B=1-y.x;y.y=Math.min(.5*A,.75)*B+y.x;y.z=(1-.5*N.clamp(A,0,1))*B;y.w=.5*y.z;y=1/y.z;r.x=y*v;r.y=2*r.x;r.x+=1;r.y+=1;t.setValue(r.data);k.x*=l;k.y*=l;k.z*=l;k.w*=l;La(a,x,q,k)}h.dpAtlas=u;h.sh=Gl(p)}this.dpAtlas=h.dpAtlas;this.ambientSH=h.sh;this._setParameter("ambientSH[0]",this.ambientSH);this._setParameter("texture_sphereMap",this.dpAtlas)}else g? 6>h._levels.length?t?this._setParameter("texture_prefilteredCubeMap128",h):console.log("Can't use prefiltered cubemap: "+t+", "+g+", "+h._levels):this._setParameter("texture_prefilteredCubeMap128",h):t?(this._setParameter("texture_prefilteredCubeMap128",h),this._setParameter("texture_prefilteredCubeMap64",l),this._setParameter("texture_prefilteredCubeMap32",n),this._setParameter("texture_prefilteredCubeMap16",p),this._setParameter("texture_prefilteredCubeMap8",q),this._setParameter("texture_prefilteredCubeMap4", r)):console.log("Can't use prefiltered cubemap: "+t+", "+g+", "+h._levels)}g=(p=1=e)?Oj.optionsContextMin:Oj.optionsContext;p?this.shaderOptBuilder.updateMinRef(g,a,b,this,c,d,e,f,h):this.shaderOptBuilder.updateRef(g,a,b,this,c,d,e,f,h);this.onUpdateShader&&(g=this.onUpdateShader(g));this.shader=a.getProgramLibrary().getProgram("standard",g);c||(this.clearVariants(),this.variants[0]=this.shader);this.dirtyShader=!1}});(function(a){a.dirtyShader=!0;a.dirtyColor=!0;a._scene=null;a._colorProcessed= !1;Th(a,"ambient",new L(.7,.7,.7));Th(a,"diffuse",new L(1,1,1));Th(a,"specular",new L(0,0,0));Th(a,"emissive",new L(0,0,0),!0);qb(a,"shininess",25,function(c,d){return{name:"material_shininess",value:0===c.shadingModel?Math.pow(2,.11*d):.01*d}});qb(a,"heightMapFactor",1,function(c,d){return{name:"material_heightMapFactor",value:.025*d}});qb(a,"opacity",1);qb(a,"alphaTest",0);qb(a,"bumpiness",1);qb(a,"normalDetailMapBumpiness",1);qb(a,"reflectivity",1);qb(a,"occludeSpecularIntensity",1);qb(a,"refraction", 0);qb(a,"refractionIndex",1/1.5);qb(a,"metalness",1);qb(a,"anisotropy",0);qb(a,"clearCoat",0);qb(a,"clearCoatGlossiness",1);qb(a,"clearCoatBumpiness",1);qb(a,"aoUvSet",0,null);sc(a,"ambientSH",function(c,d,e){return{name:"ambientSH[0]",value:d}});sc(a,"cubeMapProjectionBox",function(c,d,e){var f=e?c.cubeMapMinUniform:new Float32Array(3);c=e?c.cubeMapMaxUniform:new Float32Array(3);f[0]=d.center.x-d.halfExtents.x;f[1]=d.center.y-d.halfExtents.y;f[2]=d.center.z-d.halfExtents.z;c[0]=d.center.x+d.halfExtents.x; c[1]=d.center.y+d.halfExtents.y;c[2]=d.center.z+d.halfExtents.z;return[{name:"envBoxMin",value:f},{name:"envBoxMax",value:c}]});Up();Fa(a,"ambientTint",!1);Fa(a,"diffuseTint",!1);Fa(a,"specularTint",!1);Fa(a,"emissiveTint",!1);Fa(a,"fastTbn",!1);Fa(a,"specularAntialias",!1);Fa(a,"useMetalness",!1);Fa(a,"enableGGXSpecular",!1);Fa(a,"occludeDirect",!1);Fa(a,"normalizeNormalMap",!0);Fa(a,"conserveEnergy",!0);Fa(a,"occludeSpecular",1);Fa(a,"shadingModel",1);Fa(a,"fresnelModel",0);Fa(a,"cubeMapProjection", 0);Fa(a,"customFragmentShader",null);Fa(a,"forceFragmentPrecision",null);Fa(a,"useFog",!0);Fa(a,"useLighting",!0);Fa(a,"useGammaTonemap",!0);Fa(a,"useSkybox",!0);Fa(a,"forceUv1",!1);Fa(a,"pixelSnap",!1);Fa(a,"twoSidedLighting",!1);Fa(a,"nineSlicedMode",void 0);pb(a,"diffuse",0,3,"",!0);pb(a,"specular",0,3,"",!0);pb(a,"emissive",0,3,"",!0);pb(a,"normal",0,-1,"",!1);pb(a,"metalness",0,1,"",!0);pb(a,"gloss",0,1,"",!0);pb(a,"opacity",0,1,"a",!0);pb(a,"height",0,1,"",!1);pb(a,"ao",0,1,"",!0);pb(a,"light", 1,3,"",!0);pb(a,"msdf",0,3,"",!1);pb(a,"diffuseDetail",0,3,"",!1,!0);pb(a,"normalDetail",0,-1,"",!1);pb(a,"clearCoat",0,1,"",!0);pb(a,"clearCoatGloss",0,1,"",!0);pb(a,"clearCoatNormal",0,-1,"",!1);sc(a,"cubeMap");sc(a,"sphereMap");sc(a,"dpAtlas");sc(a,"prefilteredCubeMap128");sc(a,"prefilteredCubeMap64");sc(a,"prefilteredCubeMap32");sc(a,"prefilteredCubeMap16");sc(a,"prefilteredCubeMap8");sc(a,"prefilteredCubeMap4");tc(a,"diffuseTint","diffuseMapTint");tc(a,"specularTint","specularMapTint");tc(a, "emissiveTint","emissiveMapTint");tc(a,"aoVertexColor","aoMapVertexColor");tc(a,"diffuseVertexColor","diffuseMapVertexColor");tc(a,"specularVertexColor","specularMapVertexColor");tc(a,"emissiveVertexColor","emissiveMapVertexColor");tc(a,"metalnessVertexColor","metalnessMapVertexColor");tc(a,"glossVertexColor","glossMapVertexColor");tc(a,"opacityVertexColor","opacityMapVertexColor");tc(a,"lightVertexColor","lightMapVertexColor");for(var b=0;b=a?this._defaultStdMatOptionMin:this._defaultStdMatOption};Kb.prototype.precompile=function(a){if(a)for(var b=Array(a.length),c=0;cb||d>b){var e=b/Math.max(c,d),f=Math.floor(c*e);e=Math.floor(d*e);console.warn("Image dimensions larger than max supported texture size of "+b+". Resizing from "+c+", "+d+" to "+f+", "+e+".");b= document.createElement("canvas");b.width=f;b.height=e;b.getContext("2d").drawImage(a,0,0,c,d,0,0,f,e);return b}return a},ib=function(a,b){M.call(this);var c;this.canvas=a;this.indexBuffer=this.shader=null;this.vertexBuffers=[];this._enableAutoInstancing=!1;this.autoInstancingMaxObjects=16384;this.activeFramebuffer=this.transformFeedbackBuffer=this.boundVao=this.defaultFramebuffer=null;this.textureUnit=0;this.textureUnits=[];this._maxPixelRatio=1;this.feedback=this.renderTarget=null;this._tempEnableSafariTextureUnitWorkaround= !!window.safari;this._height=this._width=0;this.updateClientRect();this.vertexShaderCache={};this.fragmentShaderCache={};this.shaders=[];this.buffers=[];this.textures=[];this.targets=[];this._vaoMap=new Map;this.contextLost=!1;this._contextLostHandler=function(q){q.preventDefault();this.contextLost=!0;this.fire("devicelost")}.bind(this);this._contextRestoredHandler=function(){this.initializeContext();this.contextLost=!1;this.fire("devicerestored")}.bind(this);var d=b&&void 0!==b.preferWebGl2?b.preferWebGl2: !0,e=d?["webgl2","experimental-webgl2","webgl","experimental-webgl"]:["webgl","experimental-webgl"],f=null;b=b||{};b.stencil=!0;for(c=0;cc;break}}if(!f)throw Error("WebGL not supported");this.gl=f;window.setupVertexArrayObject(f);a.addEventListener("webglcontextlost",this._contextLostHandler,!1);a.addEventListener("webglcontextrestored",this._contextRestoredHandler,!1);this.initializeExtensions();this.initializeCapabilities(); this.initializeRenderState();for(c=0;cthis.maxTextures;this.boneLimit=Math.floor((this.vertexUniformsCount-16-8-1-16)/3);this.boneLimit=Math.min(this.boneLimit,128);"Mali-450 MP"===this.unmaskedRenderer&&(this.boneLimit= 34);this._shaderSwitchesPerFrame=this._drawCallsPerFrame=0;this._primsPerFrame=[];for(c=0;6>=c;c++)this._primsPerFrame[c]=0;this._renderTargetCreationTime=0;this._vram={tex:0,vb:0,ib:0};this._shaderStats={vsCompiled:0,fsCompiled:0,linked:0,materialShaders:0,compileTime:0};this.constantTexSource=this.scope.resolve("source");this.textureFloatRenderable=this.extTextureFloat?this.webgl2?!!this.extColorBufferFloat:Fl(f,f.FLOAT):!1;this.textureHalfFloatRenderable=this.extTextureHalfFloat?this.webgl2?!!this.extColorBufferFloat: Fl(f,this.extTextureHalfFloat.HALF_FLOAT_OES):!1;this.supportsMorphTargetTexturesCore="highp"===this.maxPrecision&&2<=this.maxVertexTextures;this._textureHalfFloatUpdatable=this._textureFloatHighPrecision=void 0;this.createGrabPass(b.alpha);Na.init(this)};ib.prototype=Object.create(M.prototype);ib.prototype.constructor=ib;Object.assign(ib.prototype,{getPrecision:function(){var a=this.gl,b="highp";if(a.getShaderPrecisionFormat){var c=a.getShaderPrecisionFormat(a.VERTEX_SHADER,a.HIGH_FLOAT),d=a.getShaderPrecisionFormat(a.VERTEX_SHADER, a.MEDIUM_FLOAT),e=a.getShaderPrecisionFormat(a.FRAGMENT_SHADER,a.HIGH_FLOAT);a=a.getShaderPrecisionFormat(a.FRAGMENT_SHADER,a.MEDIUM_FLOAT);d=0b;++b)this.textureUnits[a][b]=null;(a=this.renderTarget)?a._glFrameBuffer?this.setFramebuffer(a._glFrameBuffer):this.initRenderTarget(a):this.setFramebuffer(this.defaultFramebuffer)},updateEnd:function(){var a=this.gl;this.boundVao=null;this.gl.bindVertexArray(null);var b=this.renderTarget;if(b){var c=b._colorBuffer;c&&c._glTexture&&c.mipmaps&&c.pot&&(this.activeTexture(this.maxCombinedTextures-1),this.bindTexture(c),a.generateMipmap(c._glTarget));this.webgl2&& 1g;g++)a._levelsUpdated[0][g]&&(e=d[g],e instanceof HTMLImageElement&&(e.width>this.maxCubeMapSize||e.height>this.maxCubeMapSize)&&(e=hn(e,this.maxCubeMapSize),0===c&&(a._width=e.width,a._height=e.height)),this.setUnpackFlipY(!1),this.setUnpackPremultiplyAlpha(a._premultiplyAlpha), b.texImage2D(b.TEXTURE_CUBE_MAP_POSITIVE_X+g,c,a._glInternalFormat,a._glFormat,a._glPixelType,e));else for(e=1/Math.pow(2,c),g=0;6>g;g++)if(a._levelsUpdated[0][g]){var k=d[g];a._compressed?b.compressedTexImage2D(b.TEXTURE_CUBE_MAP_POSITIVE_X+g,c,a._glInternalFormat,Math.max(a._width*e,1),Math.max(a._height*e,1),0,k):(this.setUnpackFlipY(!1),this.setUnpackPremultiplyAlpha(a._premultiplyAlpha),b.texImage2D(b.TEXTURE_CUBE_MAP_POSITIVE_X+g,c,a._glInternalFormat,Math.max(a._width*e,1),Math.max(a._height* e,1),0,a._glFormat,a._glPixelType,k))}}else a._volume?(e=1/Math.pow(2,c),a._compressed?b.compressedTexImage3D(b.TEXTURE_3D,c,a._glInternalFormat,Math.max(a._width*e,1),Math.max(a._height*e,1),Math.max(a._depth*e,1),0,d):(this.setUnpackFlipY(!1),this.setUnpackPremultiplyAlpha(a._premultiplyAlpha),b.texImage3D(b.TEXTURE_3D,c,a._glInternalFormat,Math.max(a._width*e,1),Math.max(a._height*e,1),Math.max(a._depth*e,1),0,a._glFormat,a._glPixelType,d))):(this._isBrowserInterface(d)?(d instanceof HTMLImageElement&& (d.width>this.maxTextureSize||d.height>this.maxTextureSize)&&(d=hn(d,this.maxTextureSize),0===c&&(a._width=d.width,a._height=d.height)),this.setUnpackFlipY(a._flipY),this.setUnpackPremultiplyAlpha(a._premultiplyAlpha),b.texImage2D(b.TEXTURE_2D,c,a._glInternalFormat,a._glFormat,a._glPixelType,d)):(e=1/Math.pow(2,c),a._compressed?b.compressedTexImage2D(b.TEXTURE_2D,c,a._glInternalFormat,Math.max(a._width*e,1),Math.max(a._height*e,1),0,d):(this.setUnpackFlipY(!1),this.setUnpackPremultiplyAlpha(a._premultiplyAlpha), b.texImage2D(b.TEXTURE_2D,c,a._glInternalFormat,Math.max(a._width*e,1),Math.max(a._height*e,1),0,a._glFormat,a._glPixelType,d))),a._mipmapsUploaded=0===c?!1:!0)}c++}if(a._needsUpload)if(a._cubemap)for(c=0;6>c;c++)a._levelsUpdated[0][c]=!1;else a._levelsUpdated[0]=!1;!a._compressed&&a._mipmaps&&a._needsMipmapsUpload&&a.pot&&1===a._levels.length&&(b.generateMipmap(a._glTarget),a._mipmapsUploaded=!0);a._gpuSize&&(this._vram.tex-=a._gpuSize);a._gpuSize=a.gpuSize;this._vram.tex+=a._gpuSize}},activeTexture:function(a){this.textureUnit!== a&&(this.gl.activeTexture(this.gl.TEXTURE0+a),this.textureUnit=a)},bindTexture:function(a){var b=a._glTarget;a=a._glTexture;var c=this.textureUnit,d=this.targetToSlot[b];this.textureUnits[c][d]!==a&&(this.gl.bindTexture(b,a),this.textureUnits[c][d]=a)},bindTextureOnUnit:function(a,b){var c=a._glTarget;a=a._glTexture;var d=this.targetToSlot[c];this.textureUnits[b][d]!==a&&(this.activeTexture(b),this.gl.bindTexture(c,a),this.textureUnits[b][d]=a)},setTextureParameters:function(a){var b=this.gl,c=a._parameterFlags, d=a._glTarget;if(c&1){var e=a._minFilter;if(!a.pot||!a._mipmaps||a._compressed&&1===a._levels.length)if(2===e||3===e)e=0;else if(4===e||5===e)e=1;b.texParameteri(d,b.TEXTURE_MIN_FILTER,this.glFilter[e])}c&2&&b.texParameteri(d,b.TEXTURE_MAG_FILTER,this.glFilter[a._magFilter]);c&4&&(this.webgl2?b.texParameteri(d,b.TEXTURE_WRAP_S,this.glAddress[a._addressU]):b.texParameteri(d,b.TEXTURE_WRAP_S,this.glAddress[a.pot?a._addressU:1]));c&8&&(this.webgl2?b.texParameteri(d,b.TEXTURE_WRAP_T,this.glAddress[a._addressV]): b.texParameteri(d,b.TEXTURE_WRAP_T,this.glAddress[a.pot?a._addressV:1]));c&16&&this.webgl2&&b.texParameteri(d,b.TEXTURE_WRAP_R,this.glAddress[a._addressW]);c&32&&this.webgl2&&b.texParameteri(d,b.TEXTURE_COMPARE_MODE,a._compareOnRead?b.COMPARE_REF_TO_TEXTURE:b.NONE);c&64&&this.webgl2&&b.texParameteri(d,b.TEXTURE_COMPARE_FUNC,this.glComparison[a._compareFunc]);c&128&&(c=this.extTextureFilterAnisotropic)&&b.texParameterf(d,c.TEXTURE_MAX_ANISOTROPY_EXT,Math.max(1,Math.min(Math.round(a._anisotropy),this.maxAnisotropy)))}, setTexture:function(a,b){a._glTexture||this.initializeTexture(a);if(0>16&255)/255;e.pickColor[1]=(u>>8&255)/255;e.pickColor[2]=(u&255)/255;k.setValue(e.pickColor); d.setBlending(!1)}});this.layerComp=new xa;this.layerComp.pushOpaque(this.layer);this.meshInstances=this.layer.opaqueMeshInstances;this._instancesVersion=-1}if(!f){this.layer.clearMeshInstances();c=b.layers.layerList;var h=b.layers.subLayerEnabled,l=b.layers.subLayerList;for(b=0;bp)){n.overrideClear&&n._clearDepthBuffer&& !n._pickerCleared&&(this.meshInstances.push(this.clearDepthCommand),n._pickerCleared=!0);p=(p=l[b])?n.instances.transparentMeshInstances:n.instances.opaqueMeshInstances;var q=p.length;for(n=0;n=c+this._target.clientWidth||a.clientY=b+this._target.clientHeight?null:{x:a.clientX-c,y:a.clientY-b}}});kb.prototype.attach=function(a){this._element=a;this._keyboard&&this._keyboard.attach(a);this._mouse&&this._mouse.attach(a)}; kb.prototype.detach=function(){this._keyboard&&this._keyboard.detach();this._mouse&&this._mouse.detach();this._element=null};kb.prototype.disableContextMenu=function(){this._mouse||this._enableMouse();this._mouse.disableContextMenu()};kb.prototype.enableContextMenu=function(){this._mouse||this._enableMouse();this._mouse.enableContextMenu()};kb.prototype.update=function(a){this._keyboard&&this._keyboard.update(a);this._mouse&&this._mouse.update(a);this._gamepads&&this._gamepads.update(a);this._axesValues= {};for(var b in this._axes)this._axesValues[b]=[]};kb.prototype.registerKeys=function(a,b){this._keyboard||this._enableKeyboard();if(this._actions[a])throw Error("Action: "+a+" already registered");if(void 0===b)throw Error("Invalid button");b.length||(b=[b]);this._actions[a]?this._actions[a].push({type:"keyboard",keys:b}):this._actions[a]=[{type:"keyboard",keys:b}]};kb.prototype.registerMouse=function(a,b){this._mouse||this._enableMouse();if(void 0===b)throw Error("Invalid button");this._actions[a]? this._actions[a].push({type:"mouse",button:b}):this._actions[a]=[{type:"mouse",button:-b}]};kb.prototype.registerPadButton=function(a,b,c){if(void 0===c)throw Error("Invalid button");this._actions[a]?this._actions[a].push({type:"gamepad",button:c,pad:b}):this._actions[a]=[{type:"gamepad",button:c,pad:b}]};kb.prototype.registerAxis=function(a){var b=a.name;this._axes[b]||(this._axes[b]=[]);var c=this._axes[b].push(b);a=a||{};a.pad=a.pad||0;var d=function(e,f,g,k){switch(f){case "mousex":e._mouse.on("mousemove", function(h){e._axesValues[b][c]=h.dx/10});break;case "mousey":e._mouse.on("mousemove",function(h){e._axesValues[b][c]=h.dy/10});break;case "key":e._axes[b].push(function(){return e._keyboard.isPressed(k)?g:0});break;case "padrx":e._axes[b].push(function(){return e._gamepads.getAxis(a.pad,2)});break;case "padry":e._axes[b].push(function(){return e._gamepads.getAxis(a.pad,3)});break;case "padlx":e._axes[b].push(function(){return e._gamepads.getAxis(a.pad,0)});break;case "padly":e._axes[b].push(function(){return e._gamepads.getAxis(a.pad, 1)});break;default:throw Error("Unknown axis");}};d(this,a.positive,1,a.positiveKey);(a.negativeKey||a.negative!==a.positive)&&d(this,a.negative,-1,a.negativeKey)};kb.prototype.isPressed=function(a){if(!this._actions[a])return!1;var b,c=this._actions[a].length;for(b=0;bMath.abs(b)&&(b=e)}else this._axesValues[a]&&Math.abs(this._axesValues[a][c])>Math.abs(b)&&(b=this._axesValues[a][c])}return b};kb.prototype._enableMouse=function(){this._mouse=new Lb;if(!this._element)throw Error("Controller must be attached to an Element");this._mouse.attach(this._element)}; kb.prototype._enableKeyboard=function(){this._keyboard=new jb;if(!this._element)throw Error("Controller must be attached to an Element");this._keyboard.attach(this._element)};var cc,Ad,kn=new z,ln=new z,Bd=new bd,mn=new bd,sk=new bd;Bd.end=new z;mn.end=new z;sk.end=new z;var Re=new z,eh=new z,zj=new z,Kl=new z,Aj=new z,fh=new z,Ll=new z,tk=new P,og=new z,Uh=new z,Vh=new z,pg=new z,nn=new z,on=new z,pn=new z,qn=new z,Xp=new X;Object.assign(rd.prototype,{stopPropagation:function(){this._stopPropagation= !0;this.event&&(this.event.stopImmediatePropagation(),this.event.stopPropagation())}});sd.prototype=Object.create(rd.prototype);sd.prototype.constructor=sd;Oc.prototype=Object.create(rd.prototype);Oc.prototype.constructor=Oc;lc.prototype=Object.create(rd.prototype);lc.prototype.constructor=lc;Object.assign(Lf.prototype,{attach:function(a){this._attached&&(this._attached=!1,this.detach());this._target=a;this._attached=!0;a=Ca.passiveEvents?{passive:!0}:!1;this._useMouse&&(window.addEventListener("mouseup", this._upHandler,a),window.addEventListener("mousedown",this._downHandler,a),window.addEventListener("mousemove",this._moveHandler,a),window.addEventListener("wheel",this._wheelHandler,a));this._useTouch&&Ca.touch&&(this._target.addEventListener("touchstart",this._touchstartHandler,a),this._target.addEventListener("touchend",this._touchendHandler,!1),this._target.addEventListener("touchmove",this._touchmoveHandler,!1),this._target.addEventListener("touchcancel",this._touchcancelHandler,!1));this.attachSelectEvents()}, attachSelectEvents:function(){!this._selectEventsAttached&&this._useXr&&this.app&&this.app.xr&&this.app.xr.supported&&(this._clickedEntities||(this._clickedEntities={}),this._selectEventsAttached=!0,this.app.xr.on("start",this._onXrStart,this))},detach:function(){if(this._attached){this._attached=!1;var a=Ca.passiveEvents?{passive:!0}:!1;this._useMouse&&(window.removeEventListener("mouseup",this._upHandler,a),window.removeEventListener("mousedown",this._downHandler,a),window.removeEventListener("mousemove", this._moveHandler,a),window.removeEventListener("wheel",this._wheelHandler,a));this._useTouch&&(this._target.removeEventListener("touchstart",this._touchstartHandler,a),this._target.removeEventListener("touchend",this._touchendHandler,!1),this._target.removeEventListener("touchmove",this._touchmoveHandler,!1),this._target.removeEventListener("touchcancel",this._touchcancelHandler,!1));this._selectEventsAttached&&(this._selectEventsAttached=!1,this.app.xr.off("start",this._onXrStart,this),this.app.xr.off("end", this._onXrEnd,this),this.app.xr.off("update",this._onXrUpdate,this),this.app.xr.input.off("selectstart",this._onSelectStart,this),this.app.xr.input.off("selectend",this._onSelectEnd,this),this.app.xr.input.off("remove",this._onXrInputRemove,this));this._target=null}},addElement:function(a){-1===this._elements.indexOf(a)&&this._elements.push(a)},removeElement:function(a){a=this._elements.indexOf(a);-1!==a&&this._elements.splice(a,1)},_handleUp:function(a){this._enabled&&!Lb.isPointerLocked()&&(this._calcMouseCoords(a), null!==cc&&this._onElementMouseEvent("mouseup",a))},_handleDown:function(a){this._enabled&&!Lb.isPointerLocked()&&(this._calcMouseCoords(a),null!==cc&&this._onElementMouseEvent("mousedown",a))},_handleMove:function(a){this._enabled&&(this._calcMouseCoords(a),null!==cc&&(this._onElementMouseEvent("mousemove",a),this._lastX=cc,this._lastY=Ad))},_handleWheel:function(a){this._enabled&&(this._calcMouseCoords(a),null!==cc&&this._onElementMouseEvent("mousewheel",a))},_determineTouchedElements:function(a){var b= {},c=this.app.systems.camera.cameras,d,e;for(d=c.length-1;0<=d;d--){var f=c[d],g=0;var k=0;for(e=a.changedTouches.length;k=c+this._target.clientWidth||a.clientY=b+this._target.clientHeight?Ad=cc=null:(cc=a.clientX-c,Ad=a.clientY-b)},_calcTouchCoords:function(a){for(var b=0,c=0,d=a.target;!(d instanceof HTMLElement);)d=d.parentNode;do b+=d.offsetLeft-d.scrollLeft,c+=d.offsetTop-d.scrollTop,d=d.offsetParent;while(d);return{x:a.pageX-b,y:a.pageY-c}},_sortElements:function(a,b){var c=this.app.scene.layers.sortTransparentLayers(a.layers,b.layers);return 0!==c?c:a.screen&&!b.screen?-1:!a.screen&& b.screen?1:a.screen||b.screen?a.screen.screen.screenSpace&&!b.screen.screen.screenSpace?-1:b.screen.screen.screenSpace&&!a.screen.screen.screenSpace?1:b.drawOrder-a.drawOrder:0},_getTargetElement:function(a,b,c){var d=null;this._elements.sort(this._sortHandler);for(var e,f,g=0,k=this._elements.length;g=h&&a<=h+g&&b<=c&&b>=l?(d.origin.set(e*(a-h)/g,f-f*(b-l)/k,1),d.direction.set(0,0,-1),d.end.copy(d.direction).scale(2).add(d.origin),!0):!1},_calculateRay3d:function(a,b,c,d){var e=this._target.clientWidth,f=this._target.clientHeight,g=c.rect.z*e,k=c.rect.w*f,h=c.rect.x*e,l=(1-c.rect.y)* f,n=l-k,p=b;return a>=h&&a<=h+g&&b<=l&&p>=n?(a=e*(a-h)/g,p=f*(p-n)/k,c.screenToWorld(a,p,c.nearClip,kn),c.screenToWorld(a,p,c.farClip,ln),d.origin.copy(kn),d.direction.set(0,0,-1),d.end.copy(ln),!0):!1},_checkElement:function(a,b,c){if(b.maskedBy&&!this._checkElement(a,b.maskedBy.element,c))return!1;var d=c?this._calculateScaleToScreen(b):b.entity.getWorldTransform().getScale();b=this._buildHitCorners(b,c?b.screenCorners:b.worldCorners,d.x,d.y);return Jo(a.origin,a.end,b)?!0:!1}});Object.defineProperty(Lf.prototype, "enabled",{get:function(){return this._enabled},set:function(a){this._enabled=a}});Object.defineProperty(Lf.prototype,"app",{get:function(){return this._app||ea.getApplication()},set:function(a){this._app=a}});var rn={DEFAULT:{buttons:"PAD_FACE_1 PAD_FACE_2 PAD_FACE_3 PAD_FACE_4 PAD_L_SHOULDER_1 PAD_R_SHOULDER_1 PAD_L_SHOULDER_2 PAD_R_SHOULDER_2 PAD_SELECT PAD_START PAD_L_STICK_BUTTON PAD_R_STICK_BUTTON PAD_UP PAD_DOWN PAD_LEFT PAD_RIGHT PAD_VENDOR".split(" "),axes:["PAD_L_STICK_X","PAD_L_STICK_Y", "PAD_R_STICK_X","PAD_R_STICK_Y"]},PS3:{buttons:"PAD_FACE_1 PAD_FACE_2 PAD_FACE_4 PAD_FACE_3 PAD_L_SHOULDER_1 PAD_R_SHOULDER_1 PAD_L_SHOULDER_2 PAD_R_SHOULDER_2 PAD_SELECT PAD_START PAD_L_STICK_BUTTON PAD_R_STICK_BUTTON PAD_UP PAD_DOWN PAD_LEFT PAD_RIGHT PAD_VENDOR".split(" "),axes:["PAD_L_STICK_X","PAD_L_STICK_Y","PAD_R_STICK_X","PAD_R_STICK_Y"]}},sn={"Product: 0268":"PS3"};Object.assign(Bj.prototype,{update:function(){var a,b;var c=0;for(b=this.current.length;cy&&(y=this.fontSize*this.fontSize/A,f.font=this.fontWeight+" "+y.toString()+"px "+this.fontName,A=this.fontSize);this.renderCharacter(f,b,x+t,v+u,e);this._addChar(this.data,b,w,x,v,l,r,this.padding+(this.glyphSize-A)/2,-this.padding+p[b].descent-n,A,a-1,c,d);x+=l;x+l>c&&(x=0,v+=r,v+r>d&&(this.textures[a-1].upload(),a++,v=0,a>h?(b=document.createElement("canvas"), b.height=d,b.width=c,f=this._getAndClearContext(b,g),w=new V(this.app.graphicsDevice,{format:7,autoMipmap:!0}),w.name="font-atlas",w.setSource(b),w.minFilter=5,w.magFilter=1,w.addressU=1,w.addressV=1,this.textures.push(w)):(b=this.textures[a-1].getSource(),f=this._getAndClearContext(b,g))))}this.textures[a-1].upload();if(av;v++){var A=new ra(b,y,{face:v,depth:!1});q.x=v;q.y=0;n.setValue(c);p.setValue(q.data);La(b,A,l);ah(b,A,v)}c=y}if(128v;v++)A=new ra(b,y,{face:v,depth:!1}),q.x=v,q.y=E,q.z=r,q.w=k?3:0,n.setValue(c),p.setValue(q.data),La(b,A,l),w===B-1&&f&&ah(b,A,v);c=y}}a.sourceCubemap=c;y=null;if(!k&&a.filteredFixedRgbm)for(y=new V(b,{cubemap:!0,type:"rgbm",format:7,width:r,height:r,mipmaps:!1}),y.name="prefiltered-cube",v=0;6>v;v++)A=new ra(b,y,{face:v,depth:!1}),q.x=v,q.w=2,n.setValue(c),p.setValue(q.data),La(b,A,l),ah(b,A,v);r=0===d?1:2048;A=0===d?0:-1;t[A]=[]; for(w=0;7>w;w++)for(l=A;ll?g:"rgbm",format:2>l?e:7,fixCubemapSeams:1===l||3===l,width:x[w],height:x[w],mipmaps:!1}),t[l][w].name="prefiltered-cube");for(l=A;lw;w++)for(v=0;6>v;v++)A=new ra(b,t[l][w],{face:v,depth:!1}),q.x=v,q.y=0>l?r:u[w],q.z=x[w],q.w=k?3:l,n.setValue(0===w?c:0===d?t[0][w-1]:t[-1][w-1]),p.setValue(q.data),La(b,A,h),f&&ah(b,A,v);a.filtered=t[0];if(f&&a.singleFilteredFixed){c= [c].concat(a.filteredFixed);g=new V(b,{cubemap:!0,type:g,fixCubemapSeams:!0,format:e,width:128,height:128,addressU:1,addressV:1});g.name="prefiltered-cube";for(w=0;w