/* PlayCanvas Engine v1.31.0 revision ba9d634 Copyright 2011-2020 PlayCanvas Ltd. All rights reserved. */ (function(f,jd){"object"===typeof exports&&"undefined"!==typeof module?jd(exports):"function"===typeof define&&define.amd?define(["exports"],jd):(f=f||self,jd(f.pc={}))})(this,function(f){function jd(a){var b,c=[],d=a.length;for(b=0;bb||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 Hc(a,b,c){return a?(a=qh(a))?(a=a.code,a>=b&&a<=c):!1:!1}function N(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 rh(){this._list=[];this._index={}}function Gj(a){this._index={};this._key=a||null}function Ic(a){G.call(this);this._index={};this._list=[];this._parent=a}function sh(){this._isRunning=!1;this._b=this._a=0}function Qf(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 a= "";this.scheme&&(a+=this.scheme+":");this.authority&&(a+="//"+this.authority);a+=this.path;this.query&&(a+="?"+this.query);this.fragment&&(a+="#"+this.fragment);return a};this.getQuery=function(){var a,c={};if(this.query){var d=decodeURIComponent(this.query).split("&");d.forEach(function(b,d,k){a=b.split("=");c[a[0]]=a[1]},this)}return c};this.setQuery=function(a){var b="",d;for(d in a)a.hasOwnProperty(d)&&(""!==b&&(b+="&"),b+=encodeURIComponent(d)+"="+encodeURIComponent(a[d]));this.query=b}}function O(){} function th(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 Za(a){this.keys=[];this.type=1;this.tension=.5;this._eval=new th(this);if(a)for(var b=0;bc;c++)this.planes[c]=[];this.update(a,b)}function Jc(a,b){this.origin=a||new p(0,0,0);this.direction=b||new p(0,0,-1)}function vh(a,b){this.halfExtents=b||new p(.5,.5,.5);a=a||Hj.setIdentity();this._modelTransform=a.clone().invert();this._worldTransform=a.clone();this._aabb=new ia(new p,this.halfExtents)}function wh(a,b){this.normal=b||new p(0,0,1);this.point=a||new p(0,0,0)}function Ta(a,b,c,d,e){this.usage=d||0;this.format=b;this.numVertices= c;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 yh(a){a=a.node.worldTransform;a.getX(Vf);a.getY(Jj);a.getZ(Kj);Vf.cross(Vf,Jj);return 0<=Vf.dot(Kj)?1:-1}function Pa(){this._projection=0;this._nearClip=.1;this._farClip=1E4;this._shaderParams=new Float32Array(4);this._fov=45;this._orthoHeight=10;this._aspect=16/ 9;this._aspectRatioMode=0;this.frustumCulling=this._horizontalFov=!1;this.cullingMask=4294967295;this._renderDepthRequests=0;this._projMatDirty=!0;this._projMat=new C;this._projMatSkybox=new C;this._viewMatDirty=!0;this._viewMat=new C;this._viewProjMatDirty=!0;this._viewProjMat=new C;this.vrDisplay=null;this._rect={x:0,y:0,width:1,height:1};this._scissorRect={x:0,y:0,width:1,height:1};this.frustum=new uh(this._projMat,this._viewMat);this._depthTarget=this.renderTarget=null;this._clearOptions={color:[.5, .5,.5,1],depth:1,stencil:0,flags:7};this.calculateTransform=this._node=null;this.overrideCalculateTransform=!1;this.calculateProjection=null;this.overrideCalculateProjection=!1;this._cullFaces=!0;this._flipFaces=!1;this._component=null}function Z(a){G.call(this);this.name="string"===typeof a?a:"Untitled";this.tags=new Ic(this);this._labels={};this.localPosition=new p(0,0,0);this.localRotation=new U(0,0,0,1);this.localScale=new p(1,1,1);this.localEulerAngles=new p(0,0,0);this.position=new p(0,0,0); this.rotation=new U(0,0,0,1);this.eulerAngles=new p(0,0,0);this._scale=null;this.localTransform=new C;this._dirtyLocal=!1;this._aabbVer=0;this._frozen=!1;this.worldTransform=new C;this._dirtyWorld=!1;this.normalMatrix=new Db;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 Ym(a,b){return a.priority-b.priority}function Zm(a,b){return b.key-a.key}function Lj(){this.list= [];this.length=0;this.done=!1}function Mj(){this.opaqueMeshInstances=[];this.transparentMeshInstances=[];this.shadowCasters=[];this.visibleOpaque=[];this.visibleTransparent=[]}function fa(a){a=a||{};void 0!==a.id?(this.id=a.id,zh=Math.max(this.id+1,zh)):this.id=zh++;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 N(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 Mj;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 $m(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 Nj(a,b,c,d){var e=3===d? 14:2===d?12:4===d||0===d&&a.webgl2?16:7,g=$m(a,d);b=new M(a,{format:e,width:b,height:c,mipmaps:!1,minFilter:g,magFilter:g,addressU:1,addressV:1});b.name="shadowmap";return 4===d||0===d&&a.webgl2?(b.compareOnRead=!0,b.compareFunc=1,new ka({depthBuffer:b})):new ka({colorBuffer:b,depth:!0})}function Oj(a,b){a=new M(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 ka({colorBuffer:a,face:d,depth:!0}), b.push(c);return b}function Pj(a,b,c,d){d||(d=0);d=1E4*d+b;var e=Qj[c][d];e||(e=Nj(a,b,b,c?c:0),Qj[c][d]=e);return e}function Rj(a,b){if(1===b._type){0c.dot(G)?-1:1;return w}function Fb(a,b,c){var d=c&&void 0!==c.normals?c.normals:null,e=c&&void 0!==c.tangents?c.tangents:null,g=c&&void 0!==c.colors?c.colors:null,k=c&&void 0!== c.uvs?c.uvs:null,l=c&&void 0!==c.uvs1?c.uvs1:null,h=c&&void 0!==c.indices?c.indices:null,r=c&&void 0!==c.blendIndices?c.blendIndices:null,f=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!==g&&c.push({semantic:"COLOR",components:4,type:1,normalize:!0});null!==k&&c.push({semantic:"TEXCOORD0",components:2,type:6});null!==l&&c.push({semantic:"TEXCOORD1", components:2,type:6});null!==r&&c.push({semantic:"BLENDINDICES",components:2,type:1});null!==f&&c.push({semantic:"BLENDWEIGHT",components:2,type:6});var n=new Ha(a,c);c=b.length/3;n=new Ta(a,n,c);for(var q=new Eb(n),u=0;u=e)throw Error("Invalid PAX header data format.");var q=parseInt(d.decode(new Uint8Array(a,c+k,f-k)),10);f=d.decode(new Uint8Array(a,c+f+1,q-(f-k)-2)).split("=");if(2!==f.length)throw Error("Invalid PAX header data format.");0===f[1].length&&(f[1]=null); l.push({name:f[0],value:f[1]});k+=q}return new b(l)};b.prototype.applyHeader=function(a){for(var b=0;ba.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:gc.fromCodePoint(c);2>a.version&&(d.map=d.map||0);b[c]=d;return b},{}),a.version=3);return a}function Yh(a){this._loader=a;this.retryRequests=!1}function tb(a,b){G.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 V)this._assets=a;else for(var c=0;cc){var m=k.splice(d,1)[0],n=[];for(e=0;e=c?pb.APPLY_SHRINKING:pb.NONE;case 3:return b=c?pb.APPLY_SHRINKING:pb.NONE;default:throw Error("Unrecognized fitting mode: "+a);}}function d(a,b){return f(a,b.size)+(a.length-1)*x.spacing[b.axis]}function e(a,b,c){var d=n(a,c.maxSize),e=m(a,c.fittingProportion),g=t(e,d);b=vb[c.axis]-b;for(var h=0;hMath.abs(c)&&1E-5>Math.abs(a)?b:b*c/a}function l(a){for(var b= [],c=0;cvb[v.axis]&&0!==k[k.length-1].length&&(f=n,k.push([])); k[k.length-1].push(a[m]);r&&f>vb[v.axis]&&m!==a.length-1&&(f=0,k.push([]))}a=k}else a=[a];k=0===x.orientation&&x.reverseX||1===x.orientation&&x.reverseY;h=0===x.orientation&&x.reverseY||1===x.orientation&&x.reverseX;if(k)for(f=0;fr.largestSize[w.size]&&(r.largestElement=r[h],r.largestSize=q)}n.push(r.largestElement);m.push(r.largestSize)}h=d(m,w);f=c(x[w.fitting],h,vb[w.axis]);f===pb.APPLY_STRETCHING?e(m,h,w):f===pb.APPLY_SHRINKING&&g(m,h,w);for(f=0;fq)))for(q=(u=f[x])?n.instances.visibleTransparent[q]:n.instances.visibleOpaque[q],u=q.length,q=q.list, n=0;ng;g++){var h=a._levels[0][g],f=new M(d,{cubemap:!1,type:"default",format:a.format,width:c,height:c,mipmaps:!1});f.name="prefiltered-cube";f._levels[0]=h;f.upload();h=new M(d,{cubemap:!1,type:"default",format:a.format,width:c,height:c,mipmaps:!1});h.name="prefiltered-cube";h=new ka(d,h,{depth:!1});l.setValue(f);Ea(d,h,k);var m=new Uint8Array(c*c*4);e.bindFramebuffer(e.FRAMEBUFFER,h._glFrameBuffer);e.readPixels(0,0,f.width,f.height,e.RGBA,e.UNSIGNED_BYTE, m);a._levels[0][g]=m}}else{console.error("ERROR: SH: cubemap must be composed of arrays or images");return}k=[];for(e=0;eg;g++)for(e=0;ex;x++){var F=a._levels[0][g][4*f+x]/255;"rgbm"===a.type?(F*=8*u,F*=F):F=Math.pow(F,2.2);l[0+x]+=F*n;l[3+x]+=F*q*y;l[6+x]+=F*q*z;l[9+x]+=F*q*A;l[12+x]+=F*v*y*A;l[15+x]+= F*v*A*z;l[18+x]+=F*v*z*y;l[21+x]+=F*w*(3*A*A-1);l[24+x]+=F*t*(y*y-z*z);h+=m}}for(x=0;xb.deltaY&& (this.wheelDelta=-1));zb.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 zb(a){G.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(a){a.preventDefault()};this._target=null;this._attached=!1;this.attach(a)}function cb(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 Tn(a,b,c){se.sub2(b,a);zg.sub2(c[0],a);Pi.sub2(c[1],a);Yk.sub2(c[2],a);Ag.cross(Yk,se);if(0<=zg.dot(Ag)){if(0>-Pi.dot(Ag))return!1;a=zg;if(0>Zk.cross(se,Pi).dot(a))return!1}else{Qi.sub2(c[3],a);if(0>Qi.dot(Ag))return!1;a=Qi;if(0>Zk.cross(se,zg).dot(a))return!1}return 1E-8>se.sub2(c[0],c[2]).lengthSq()||1E-8>se.sub2(c[1],c[3]).lengthSq()?!1:!0}function Zc(a,b,c){this.event=a;this.element=b;this.camera=c;this._stopPropagation=!1}function $c(a,b,c,d, e,g,k){Zc.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;zb.isPointerLocked()?(this.dx=a.movementX||a.webkitMovementX||a.mozMovementX||0,this.dy=a.movementY||a.webkitMovementY||a.mozMovementY||0):(this.dx=d-g,this.dy=e-k);this.wheelDelta=0;"wheel"===a.type&&(0a.deltaY&&(this.wheelDelta=-1))}function Ac(a,b,c,d,e,g){Zc.call(this,a,b,c);this.touches=a.touches; this.changedTouches=a.changedTouches;this.x=d;this.y=e;this.touch=g}function Zb(a,b,c,d){Zc.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;va.touch&&(this._clickedEntities= {});this.attach(a)}function Ri(){this.gamepadsSupported=!!navigator.getGamepads||!!navigator.webkitGetGamepads;this.current=[];this.previous=[];this.deadZone=.25}function Bg(a){var b=Si(a);this.id=a.identifier;this.x=b.x;this.y=b.y;this.target=a.target;this.touch=a}function Fd(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,qb,null,this.renderTarget);else{var b=this._postEffectCombinedSrc?this._postEffectCombinedSrc:c.srcRenderTarget?c.srcRenderTarget:Da[this._backbufferRtId];1e;e++)Da[e]=new ka({depth:!0,stencil:d.supportsStencil,samples:b,autoResolve:!1}),Da[e].name="backbuffer"+e;a.on("prerender",function(){var b=a.scene.layers.layerList,c,e=0,h=0;Ui=Vi=nf=!1;var f=7;if(a.scene.layers._dirty){var m=0;for(c=0;c=e;n--)b[n].renderTarget||(b[n].renderTarget=Da[h]);b[c]._backbufferRtId=h;e=c;nf=!0;1===h&&(Vi=!0);b[c].postEffect.hdr&&(f=d.webgl2&&d.textureFloatRenderable?18:d.extTextureHalfFloatLinear&&d.textureHalfFloatRenderable?12:7);b[c].postEffect.shader&&!b[c].renderTarget&&(h=1-h)}else b[c].isPostEffect|| b[c].renderTarget||!nf||(b[c].renderTarget=Da[h]);b[c].isPostEffect&&!b[c].renderTarget&&(Ui=!0)}if(nf)if(!Da[0].colorBuffer)Cg(0,d,f);else if(Da[0].width!==d.width||Da[0].height!==d.height||Da[0]._colorBuffer._format!==f)Da[0].colorBuffer.destroy(),Da[0].destroy(),Cg(0,d,f);if(Vi)if(!Da[1].colorBuffer)Cg(1,d,f);else if(Da[1].width!==d.width||Da[1].height!==d.height||Da[1]._colorBuffer._format!==f)Da[1].colorBuffer.destroy(),Da[1].destroy(),Cg(1,d,f)},this);a.on("postrender",function(){var b=a.graphicsDevice; if(nf&&!Ui){for(var c=a.scene.layers.layerList,d,e=c.length-1;0<=e&&(d=c[e].renderTarget,d!==Da[0]&&d!==Da[1]);e--);d&&(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});var Fm=function(){for(var a= {},b="Array Object Function Date RegExp Float32Array".split(" "),c=0;c>10)+55296,c%1024+56320]:[b],a.push(String.fromCharCode.apply(null,b));return a.join("")}}, H={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)*H.clamp(c,0,1)},lerpAngle:function(a,b,c){180b-a&&(b+=360);return H.lerp(a,b,H.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,g=c>>23&255;return 103>g?d:142g?(e|=2048,d|(e>>114-g)+(e>>113-g&1)):d=(d|g-112<<10|e>>1)+(e&1)}}()};Object.assign(N.prototype,{clone:function(){return new N(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(Gj.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?H.lerp(this._p0,this._p1,a):1===b?H.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 g=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(g)?g:0)*(a[1]-c[1])}else g=(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(g)?g: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 g=e*e,k=e+e,l=1-e;l*=l;return a*(1+k)*l+c*e*l+b*g*(3-k)+d*g*(e-1)}});Object.assign(Za.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,g=0;g=k)d=k,e=b[g];else break}return e},clone:function(){var a=new Za;a.keys=tc(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(Db,{ZERO:{value:(new Db).set([0,0,0,0,0,0,0,0,0])},IDENTITY:{value:new Db}});Object.assign(p.prototype,{add:function(a){this.x+=a.x;this.y+=a.y;this.z+=a.z;return this},add2:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;this.z=a.z+b.z;return this},clone:function(){return(new p).copy(this)},copy:function(a){this.x=a.x;this.y= a.y;this.z=a.z;return this},cross:function(a,b){var c=a.x,d=a.y;a=a.z;var e=b.x,g=b.y;b=b.z;this.x=d*b-g*a;this.y=a*e-b*c;this.z=c*g-e*d;return this},distance:function(a){var b=this.x-a.x,c=this.y-a.y;a=this.z-a.z;return Math.sqrt(b*b+c*c+a*a)},dot:function(a){return this.x*a.x+this.y*a.y+this.z*a.z},equals:function(a){return this.x===a.x&&this.y===a.y&&this.z===a.z},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)},lengthSq:function(){return this.x*this.x+this.y*this.y+ this.z*this.z},lerp:function(a,b,c){this.x=a.x+c*(b.x-a.x);this.y=a.y+c*(b.y-a.y);this.z=a.z+c*(b.z-a.z);return this},mul:function(a){this.x*=a.x;this.y*=a.y;this.z*=a.z;return this},mul2:function(a,b){this.x=a.x*b.x;this.y=a.y*b.y;this.z=a.z*b.z;return this},normalize:function(){var a=this.x*this.x+this.y*this.y+this.z*this.z;0-l?(d= Math.atan2(g[6]/d,g[10]/e),c=Math.atan2(g[1]/c,g[0]/c)):(c=0,d=-Math.atan2(g[4]/d,g[5]/d)):(c=0,d=Math.atan2(g[4]/d,g[5]/d));return b.set(d,k,c).scale(H.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(C,{ZERO:{value:(new C).set([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])},IDENTITY:{value:new C}});Object.assign(U.prototype,{clone:function(){return new U(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*H.RAD_TO_DEG},getEulerAngles:function(a){a=void 0===a?new p:a;var b=this.x;var c=this.y;var d=this.z;var e= this.w;var g=2*(e*c-b*d);if(-.99999>=g){var k=2*Math.atan2(b,e);g=-Math.PI/2;b=0}else.99999<=g?(k=2*Math.atan2(b,e),g=Math.PI/2,b=0):(k=Math.atan2(2*(e*b+c*d),1-2*(b*b+c*c)),g=Math.asin(g),b=Math.atan2(2*(e*d+b*c),1-2*(c*c+d*d)));return a.set(k,g,b).scale(H.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 g=a.x;var k=a.y;var l=a.z;a=a.w;this.x=e*g+b*a+c*l-d*k;this.y=e*k+c*a+d*g-b*l;this.z=e*l+d*a+b*k-c*g;this.w=e*a-b*g-c*k-d*l;return this},mul2:function(a,b){var c=a.x;var d=a.y;var e=a.z;a=a.w;var g=b.x;var k=b.y;var l=b.z;b=b.w;this.x=a*g+c*b+d*l-e*k;this.y=a*k+d*b+e*g-c*l;this.z=a*l+e*b+c*k-d*g;this.w=a*b-c*g-d*k-e*l;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*H.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*H.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 g=Math.sin(c);c=Math.cos(c);this.x=d*b*c-a*e*g;this.y=a*e*c+d*b*g;this.z=a*b*g-d*e*c;this.w=a*b*c+d*e*g;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 g=a[5];var k=a[6];var l=a[8];var h=a[9];a=a[10];var f=b*b+c*c+d*d;if(0===f)return this;f=1/Math.sqrt(f);var m=e*e+g*g+k*k;if(0===m)return this;m=1/Math.sqrt(m);var n=l*l+h*h+a*a;if(0===n)return this;n=1/Math.sqrt(n);b*=f;c*=f;d*=f;e*=m;g*=m;k*=m;l*=n;h*=n;a*=n;f=b+g+a;0<=f?(b=Math.sqrt(f+1),this.w=.5*b,b=.5/b,this.x=(k-h)*b,this.y=(l-d)*b,this.z=(c-e)*b):b>g?b>a?(b=Math.sqrt(b-(g+a)+1),this.x=.5*b,b=.5/b,this.w=(k-h)* b,this.y=(c+e)*b,this.z=(d+l)*b):(b=Math.sqrt(a-(b+g)+1),this.z=.5*b,b=.5/b,this.w=(c-e)*b,this.x=(l+d)*b,this.y=(h+k)*b):g>a?(b=Math.sqrt(g-(a+b)+1),this.y=.5*b,b=.5/b,this.w=(l-d)*b,this.z=(k+h)*b,this.x=(e+c)*b):(b=Math.sqrt(a-(b+g)+1),this.z=.5*b,b=.5/b,this.w=(c-e)*b,this.x=(l+d)*b,this.y=(h+k)*b);return this},slerp:function(a,b,c){var d=a.x;var e=a.y;var g=a.z;a=a.w;var k=b.x;var l=b.y;var h=b.z;b=b.w;var f=a*b+d*k+e*l+g*h;0>f&&(b=-b,k=-k,l=-l,h=-h,f=-f);if(1<=Math.abs(f))return this.w=a,this.x= d,this.y=e,this.z=g,this;var m=Math.acos(f),n=Math.sqrt(1-f*f);if(.001>Math.abs(n))return this.w=.5*a+.5*b,this.x=.5*d+.5*k,this.y=.5*e+.5*l,this.z=.5*g+.5*h,this;f=Math.sin((1-c)*m)/n;c=Math.sin(c*m)/n;this.w=a*f+b*c;this.x=d*f+k*c;this.y=e*f+l*c;this.z=g*f+h*c;return this},transformVector:function(a,b){void 0===b&&(b=new p);var c=a.x,d=a.y,e=a.z;a=this.x;var g=this.y,k=this.z,l=this.w,h=l*c+g*e-k*d,f=l*d+k*c-a*e,m=l*e+a*d-g*c;c=-a*c-g*d-k*e;b.x=h*l+c*-a+f*-k-m*-g;b.y=f*l+c*-g+m*-a-h*-k;b.z=m*l+ c*-k+h*-g-f*-a;return b},toString:function(){return"["+this.x+", "+this.y+", "+this.z+", "+this.w+"]"}});Object.defineProperties(U,{ZERO:{value:new U(0,0,0,0)},IDENTITY:{value:new U(0,0,0,1)}});Object.assign(L.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 L).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;0c&&(c=m);qd&&(d=n);ue&&(e=h);b.x=.5*(f+c);b.y=.5*(k+d);b.z=.5*(l+e);g.x=.5*(c-f);g.y=.5*(d-k);g.z=.5*(e-l)},copy:function(a){this.center.copy(a.center);this.halfExtents.copy(a.halfExtents); this.type=a.type},clone:function(){return new ia(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=jc.copy(this.getMin()).sub(a.origin),d=Kb.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=qf.set(Math.min(c.x,d.x),Math.min(c.y,d.y),Math.min(c.z,d.z));c=rf.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;jc.sub2(a.origin,this.center);rf.set(Math.abs(jc.x),Math.abs(jc.y),Math.abs(jc.z));qf.mul2(jc,b);if(rf.x>this.halfExtents.x&&0<=qf.x||rf.y>this.halfExtents.y&&0<=qf.y||rf.z>this.halfExtents.z&&0<=qf.z)return!1;Gd.set(Math.abs(b.x),Math.abs(b.y),Math.abs(b.z));Kb.cross(b,jc);Kb.set(Math.abs(Kb.x),Math.abs(Kb.y),Math.abs(Kb.z));return Kb.x>this.halfExtents.y*Gd.z+this.halfExtents.z*Gd.y||Kb.y>this.halfExtents.x*Gd.z+this.halfExtents.z*Gd.x||Kb.z>this.halfExtents.x*Gd.y+this.halfExtents.y* Gd.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=this.center,d=this.halfExtents,e=a.center;a=a.halfExtents;b=b.data;var g=b[0],k=b[4],l=b[8],h=b[1],f=b[5],m=b[9],n=b[2],q=b[6],u=b[10],t=Math.abs(g),p=Math.abs(k),v=Math.abs(l),w=Math.abs(h),y=Math.abs(f),z=Math.abs(m),A=Math.abs(n),F=Math.abs(q),Q=Math.abs(u);c.set(b[12]+g*e.x+k*e.y+l*e.z,b[13]+h*e.x+f*e.y+m*e.z,b[14]+n*e.x+q*e.y+u*e.z);d.set(t*a.x+p*a.y+v*a.z,w*a.x+y*a.y+z*a.z,A*a.x+F*a.y+Q*a.z)},compute:function(a,b){b=void 0===b?a.length/3:b;if(0d.x&&(d.x=g);k>d.y&&(d.y=k);l>d.z&&(d.z=l)}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"],g=0;3>g;++g){var k=0,l=a.center[e[g]],h=b[e[g]],f=c[e[g]];lf&&(h=l-f,k+=h*h);d+=k}return d}, _expand:function(a,b){jc.add2(this.getMin(),a);Kb.add2(this.getMax(),b);this.setMinMax(jc,Kb)}});var ad=new p,Dg=new p,ue=new p,fl=new p;Object.assign(Td.prototype,{containsPoint:function(a){a=ad.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){ad.sub2(a.center,this.center);a=a.radius+this.radius;return ad.lengthSq()<=a*a?!0:!1}});var gl= new C;Object.assign(uh.prototype,{update:function(a,b){gl.mul2(a,b);a=gl.data;this.planes[0][0]=a[3]-a[0];this.planes[0][1]=a[7]-a[4];this.planes[0][2]=a[11]-a[8];this.planes[0][3]=a[15]-a[12];b=Math.sqrt(this.planes[0][0]*this.planes[0][0]+this.planes[0][1]*this.planes[0][1]+this.planes[0][2]*this.planes[0][2]);this.planes[0][0]/=b;this.planes[0][1]/=b;this.planes[0][2]/=b;this.planes[0][3]/=b;this.planes[1][0]=a[3]+a[0];this.planes[1][1]=a[7]+a[4];this.planes[1][2]=a[11]+a[8];this.planes[1][3]= a[15]+a[12];b=Math.sqrt(this.planes[1][0]*this.planes[1][0]+this.planes[1][1]*this.planes[1][1]+this.planes[1][2]*this.planes[1][2]);this.planes[1][0]/=b;this.planes[1][1]/=b;this.planes[1][2]/=b;this.planes[1][3]/=b;this.planes[2][0]=a[3]+a[1];this.planes[2][1]=a[7]+a[5];this.planes[2][2]=a[11]+a[9];this.planes[2][3]=a[15]+a[13];b=Math.sqrt(this.planes[2][0]*this.planes[2][0]+this.planes[2][1]*this.planes[2][1]+this.planes[2][2]*this.planes[2][2]);this.planes[2][0]/=b;this.planes[2][1]/=b;this.planes[2][2]/= b;this.planes[2][3]/=b;this.planes[3][0]=a[3]-a[1];this.planes[3][1]=a[7]-a[5];this.planes[3][2]=a[11]-a[9];this.planes[3][3]=a[15]-a[13];b=Math.sqrt(this.planes[3][0]*this.planes[3][0]+this.planes[3][1]*this.planes[3][1]+this.planes[3][2]*this.planes[3][2]);this.planes[3][0]/=b;this.planes[3][1]/=b;this.planes[3][2]/=b;this.planes[3][3]/=b;this.planes[4][0]=a[3]-a[2];this.planes[4][1]=a[7]-a[6];this.planes[4][2]=a[11]-a[10];this.planes[4][3]=a[15]-a[14];b=Math.sqrt(this.planes[4][0]*this.planes[4][0]+ this.planes[4][1]*this.planes[4][1]+this.planes[4][2]*this.planes[4][2]);this.planes[4][0]/=b;this.planes[4][1]/=b;this.planes[4][2]/=b;this.planes[4][3]/=b;this.planes[5][0]=a[3]+a[2];this.planes[5][1]=a[7]+a[6];this.planes[5][2]=a[11]+a[10];this.planes[5][3]=a[15]+a[14];b=Math.sqrt(this.planes[5][0]*this.planes[5][0]+this.planes[5][1]*this.planes[5][1]+this.planes[5][2]*this.planes[5][2]);this.planes[5][0]/=b;this.planes[5][1]/=b;this.planes[5][2]/=b;this.planes[5][3]/=b},containsPoint:function(a){for(var b= 0;6>b;b++)if(0>=this.planes[b][0]*a.x+this.planes[b][1]*a.y+this.planes[b][2]*a.z+this.planes[b][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,g=d.z,k=this.planes;for(d=0;6>d;d++){var l=k[d];l=l[0]*a+l[1]*e+l[2]*g+l[3];if(l<=-c)return 0;l>c&&b++}return 6===b?2:1}});Jc.prototype.set=function(a,b){this.origin.copy(a);this.direction.copy(b);return this};var Eg=new Jc,hl=new p,Yi=new Td,Hj=new C;Object.assign(vh.prototype,{intersectsRay:function(a, b){this._modelTransform.transformPoint(a.origin,Eg.origin);this._modelTransform.transformVector(a.direction,Eg.direction);return b?(a=this._aabb._intersectsRay(Eg,b),Hj.copy(this._modelTransform).invert().transformPoint(b,b),a):this._aabb._fastIntersectsRay(Eg)},containsPoint:function(a){this._modelTransform.transformPoint(a,hl);return this._aabb.containsPoint(hl)},intersectsBoundingSphere:function(a){this._modelTransform.transformPoint(a.center,Yi.center);Yi.radius=a.radius;return this._aabb.intersectsBoundingSphere(Yi)? !0:!1}});Object.defineProperty(vh.prototype,"worldTransform",{get:function(){return this._worldTransform},set:function(a){this._worldTransform.copy(a);this._modelTransform.copy(a).invert()}});var ko=new p;Object.assign(wh.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=ko.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 Sf=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array],Rf=[1,1,2,2,4,4,4],Zi={Int8Array:0,Uint8Array:1,Int16Array:2,Uint16Array:3,Int32Array:4,Uint32Array:5,Float32Array:6},il=[Uint8Array,Uint16Array,Uint32Array];Object.assign(Ta.prototype,{destroy:function(){var a=this.device,b=a.buffers.indexOf(this);-1!==b&&a.buffers.splice(b,1);if(this.bufferId){b=a.gl;b.deleteBuffer(this.bufferId);a._vram.vb-= this.storage.byteLength;this.bufferId=null;a.boundBuffer=null;a.vertexBuffers.length=0;a.vbOffsets.length=0;a.attributesInvalidated=!0;for(var c in a.enabledAttributes)b.disableVertexAttribArray(Number(c));a.enabledAttributes={}}},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}});Ha.init=function(a){this._defaultInstancingFormat=new Ha(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(Ha,"defaultInstancingFormat",{get:function(){return function(){return this._defaultInstancingFormat}}()});Object.assign(Ha.prototype,{_evaluateBatchingHash:function(){var a=[],b,c=this.elements.length;for(b=0;bthis.vertexBuffer.numVertices&&(c=this.vertexBuffer.numVertices);var d, e=a.numComponents;if(this.vertexBuffer.getFormat().interleaved){var g=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;db.length){var c=b.charAt(b.length-1);a=kc[a]-b.length;for(var d=0;d=b.pass;this.options=b;var h="",f="",m="",n=P,q={vertex_position:"POSITION"};if(b.chunks){var u={};for(A in n)if(n.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");u[A]=t}else u[A]=n[A];for(A in b.chunks)(n=this._oldChunkToNew[A])&&(u[n.n]=n.f(b.chunks[A],n.n,A));n=u}h=this._vsAddBaseCode(h,a,n,b);u=-1;if(!b.noShadow&&!b.twoSidedLighting){for(t=0;t=a.fragmentUniformsCount&&(h+=n.viewNormalVS,f+=" vNormalV\t= getViewNormal();\n"),(b.heightMap||b.normalMap||b.enableGGXSpecular)&&b.hasTangents?(q.vertex_tangent="TANGENT",h+=n.tangentBinormalVS,f+=" vTangentW = getTangent();\n vBinormalW = getBinormal();\n"): b.enableGGXSpecular&&(h+=n.tangentBinormalVS,f+=" vObjectSpaceUpW = getObjectSpaceUp();\n"),0<=u&&(p=b.lights[u]._type,f=(0===p?f+(" dLightDirNormW = light"+u+"_directionVS;\n"):f+(" getLightDirPoint(light"+u+"_positionVS);\n"))+this._nonPointShadowMapProjection(a,b.lights[u],"(light"+u+"_shadowMatrixVS, light"+u+"_shadowParamsVS);\n")));p=[];var v=[];for(A in kc){t=A+"Map";if(b[A+"VertexColor"]){var w=A+"VertexColorChannel";b[w]=this._correctChannel(A,b[w])}if(b[t]){w=t+"Channel";var y=t+ "Transform";var z=t+"Uv";b[z]=Math.min(b[z],1);b[w]=this._correctChannel(A,b[w]);z=b[z];p[z]=!0;v[z]=v[z]||b[t]&&!b[y]}}b.forceUv1&&(p[1]=!0);for(t=0;2>t;t++)p[t]&&(q["vertex_texCoord"+t]="TEXCOORD"+t,h+=n["uv"+t+"VS"],f+=" vec2 uv"+t+" = getUv"+t+"();\n"),v[t]&&(f+=" vUv"+t+" = uv"+t+";\n");p=[h,m,f,[]];for(A in kc)t=A+"Map",b[t]&&(y=t+"Transform",b[y]&&(z=t+"Uv",this._setMapTransform(p,A,b[y],b[z])));h=p[0];m=p[1];f=p[2];b.vertexColors&&(q.vertex_color="COLOR",f+=" 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="ATTR0",h+="attribute float morph_vertex_id;\n"):(h+="#define MORPHING\n",b.useMorphPosition?(q.morph_pos0="ATTR0",q.morph_pos1="ATTR1",q.morph_pos2="ATTR2",q.morph_pos3="ATTR3",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="ATTR0",q.morph_nrm1="ATTR1",q.morph_nrm2="ATTR2",q.morph_nrm3="ATTR3",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="ATTR4",q.morph_nrm5="ATTR5",q.morph_nrm6="ATTR6",q.morph_nrm7="ATTR7",h+="#define MORPHING_NRM47\nattribute vec3 morph_nrm4;\nattribute vec3 morph_nrm5;\nattribute vec3 morph_nrm6;\nattribute vec3 morph_nrm7;\n"):(q.morph_pos4= "ATTR4",q.morph_pos5="ATTR5",q.morph_pos6="ATTR6",q.morph_pos7="ATTR7",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+=aa.skinCode(a,n),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,n,b);k&& (h+=n.normalVS);h=h+"\n"+n.startVS;var A=h=h+f+"}";t=m;m=""+this._addVaryingIfNeeded(h,"vec4","vMainShadowUv");m+=this._addVaryingIfNeeded(h,"vec4","vVertexColor");m+=this._addVaryingIfNeeded(h,"vec3","vPositionW");m+=this._addVaryingIfNeeded(h,"vec3","vNormalV");m+=this._addVaryingIfNeeded(h,"vec3","vNormalW");m+=this._addVaryingIfNeeded(h,"vec3","vTangentW");m+=this._addVaryingIfNeeded(h,"vec3","vBinormalW");m+=this._addVaryingIfNeeded(h,"vec3","vObjectSpaceUpW");m+=this._addVaryingIfNeeded(h,"vec2", "vUv0");m+=this._addVaryingIfNeeded(h,"vec2","vUv1");m+=t;A=m+A;h="";a.webgl2?(h=aa.versionCode(a),n.extensionVS&&(h+=n.extensionVS+"\n"),A=h+n.gles3VS+A):(n.extensionVS&&(h=n.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+=aa.versionCode(a));a.extStandardDerivatives&&!a.webgl2&&(h+="#extension GL_OES_standard_derivatives : enable\n\n");n.extensionPS&&(h+=n.extensionPS+"\n");a.webgl2&&(h+=n.gles3PS);h+=b.forceFragmentPrecision?"precision "+b.forceFragmentPrecision+" float;\n\n":aa.precisionCode(a);if(18===b.pass)return h=h+"uniform vec4 uColor;\n"+m,b.alphaTest&&(h=h+"float dAlpha;\n"+this._addMap("opacity","opacityPS", b,n),h+=n.alphaTestPS),h+=aa.begin(),b.alphaTest&&(h+=" getOpacity();\n alphaTest(dAlpha);\n"),h=h+"\tgl_FragColor = uColor;\n"+aa.end(),{attributes:q,vshader:A,fshader:h};if(2===b.pass)return h=h+"varying float vDepth;\n"+m+n.packDepthPS,b.alphaTest&&(h+="float dAlpha;\n",h+=this._addMap("opacity","opacityPS",b,n),h+=n.alphaTestPS),h+=aa.begin(),b.alphaTest&&(h+=" getOpacity();\n",h+=" alphaTest(dAlpha);\n"),h+="\tgl_FragColor = packFloat(vDepth);\n",h+=aa.end(),{attributes:q,vshader:A,fshader:h}; if(l)return d=b.pass-3,p=Math.floor(d/5),d-=5*p,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!==p&&(h+="uniform vec3 view_position;\n",h+="uniform float light_radius;\n"),h+=m,b.alphaTest&&(h+="float dAlpha;\n",h+=this._addMap("opacity","opacityPS",b,n),h+=n.alphaTestPS),0!==d||a.webgl2&&1!==p?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+=n.packDepthPS,h+=aa.begin(),b.alphaTest&&(h+=" getOpacity();\n",h+=" alphaTest(dAlpha);\n"),h=1===p||(1===d||2===d||3===d)&&0!==p?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!==p?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+n.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+=aa.end(),{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+m,a,n,b);b.detailModes&&(h+=n.detailModesPS);m=h;h="";0 0.00001) {\n",2!==p||e&&!f._cookieFalloff||(h+="\t dAtten *= getSpotEffect(light"+t+"_direction, light"+t+"_innerConeAngle, light"+t+"_outerConeAngle);\n",z=!0));h+="\t dAtten *= getLightDiffuse();\n";if(f.castShadows&&!b.noShadow){if(1===f._shadowType){k= "VSM8";var Q="0.0"}else 2===f._shadowType?(k="VSM16",Q="5.54"):3===f._shadowType?(k="VSM32",Q=a.textureFloatHighPrecision?"15.0":"5.54"):k=4===f._shadowType?"PCF5x5":"PCF3x3";null!==k&&(1===p?(c="(light"+t+"_shadowMap, light"+t+"_shadowParams);\n",f._normalOffsetBias&&(h+="\t normalOffsetPointShadow(light"+t+"_shadowParams);\n"),h+="\t dAtten *= getShadowPoint"+k+c):(u===t?k+="VS":(c="(light"+t+"_shadowMatrix, light"+t+"_shadowParams);\n",h+=this._nonPointShadowMapProjection(a,b.lights[t],c)), 2===p&&(k="Spot"+k),h+="\t dAtten *= getShadow"+k+"(light"+t+"_shadowMap, light"+t+"_shadowParams"+(f._isVsm?", "+Q:"")+");\n"))}h+="\t dDiffuseLight += dAtten * light"+t+"_color"+(e?" * dAtten3":"")+";\n";0 0.5) {\n if (dAtten > 0.00001) {\n dirLm.xyz = dirLm.xyz * 2.0 - vec3(1.0);\n dAtten = saturate(dAtten);\n gl_FragColor.rgb = normalize(dLightDirNormW.xyz*dAtten + dirLm.xyz*dirLm.w) * 0.5 + vec3(0.5);\n gl_FragColor.a = dirLm.w + dAtten;\n gl_FragColor.a = max(gl_FragColor.a, 1.0 / 255.0);\n } else {\n gl_FragColor = dirLm;\n }\n } else {\n gl_FragColor.rgb = dirLm.xyz;\n gl_FragColor.a = max(dirLm.w, dAtten > 0.00001? (1.0/255.0) : 0.0);\n }\n\n", bakeLmEndPS:"\ngl_FragColor.rgb = dDiffuseLight;\ngl_FragColor.rgb = pow(gl_FragColor.rgb, vec3(0.5));\ngl_FragColor.rgb /= 8.0;\ngl_FragColor.a = clamp( max( max( gl_FragColor.r, gl_FragColor.g ), max( gl_FragColor.b, 1.0 / 255.0 ) ), 0.0,1.0 );\ngl_FragColor.a = ceil(gl_FragColor.a * 255.0) / 255.0;\ngl_FragColor.rgb /= gl_FragColor.a;\n\n",basePS:"\nuniform vec3 view_position;\n\nuniform vec3 light_globalAmbient;\n\nfloat square(float x) {\n return x*x;\n}\n\nfloat saturate(float x) {\n return clamp(x, 0.0, 1.0);\n}\n\nvec3 saturate(vec3 x) {\n return clamp(x, vec3(0.0), vec3(1.0));\n}\n\n", baseVS:"\nattribute vec3 vertex_position;\nattribute vec3 vertex_normal;\nattribute vec4 vertex_tangent;\nattribute vec2 vertex_texCoord0;\nattribute vec2 vertex_texCoord1;\nattribute vec4 vertex_color;\n\nuniform mat4 matrix_viewProjection;\nuniform mat4 matrix_model;\nuniform mat3 matrix_normal;\n\nvec3 dPositionW;\nmat4 dModelMatrix;\nmat3 dNormalMatrix;\nvec3 dLightPosW;\nvec3 dLightDirNormW;\nvec3 dNormalW;\n\n",baseNineSlicedPS:"#define NINESLICED\n\n\nvarying vec2 vMask;\nvarying vec2 vTiledUv;\nuniform mediump vec4 innerOffset;\nuniform mediump vec2 outerScale;\nuniform mediump vec4 atlasRect;\n\nvec2 nineSlicedUv;\n", baseNineSlicedVS:"#define NINESLICED\n\n\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\n\nvarying vec2 vMask;\nvarying vec2 vTiledUv;\nuniform mediump vec4 innerOffset;\nuniform mediump vec2 outerScale;\nuniform mediump vec4 atlasRect;\n\nvec2 nineSlicedUv;\n",biasConstPS:"#define SHADOWBIAS\nfloat getShadowBias(float resolution, float maxBias) {\n return maxBias;\n}\n\n", blurVSMPS:"\nvarying vec2 vUv0;\nuniform sampler2D source;\nuniform vec2 pixelOffset;\n\n#ifdef GAUSS\nuniform float weight[SAMPLES];\n#endif\n\n#ifdef PACKED\nfloat decodeFloatRG(vec2 rg) {\n return rg.y*(1.0/255.0) + rg.x;\n}\n\nvec2 encodeFloatRG( float v ) {\n vec2 enc = vec2(1.0, 255.0) * v;\n enc = fract(enc);\n enc -= enc.yy * vec2(1.0/255.0, 1.0/255.0);\n return enc;\n}\n#endif\n\nvoid main(void) {\n vec3 moments = vec3(0.0);\n vec2 uv = vUv0 - pixelOffset * (float(SAMPLES) * 0.5);\n for(int i=0; i 1.0 || projPos.y < 0.0 || projPos.y > 1.0 || projPos.z < 0.0) return vec4(0.0);\n return mix(vec4(1.0), texture2D(tex, projPos.xy), intensity);\n}\n\nvec4 getCookie2DXform(sampler2D tex, mat4 transform, float intensity, vec4 cookieMatrix, vec2 cookieOffset) {\n vec4 projPos = transform * vec4(vPositionW, 1.0);\n projPos.xy /= projPos.w;\n projPos.xy += cookieOffset;\n vec2 uv = mat2(cookieMatrix) * (projPos.xy-vec2(0.5)) + vec2(0.5);\n return mix(vec4(1.0), texture2D(tex, uv), intensity);\n}\n\nvec4 getCookie2DClipXform(sampler2D tex, mat4 transform, float intensity, vec4 cookieMatrix, vec2 cookieOffset) {\n vec4 projPos = transform * vec4(vPositionW, 1.0);\n projPos.xy /= projPos.w;\n projPos.xy += cookieOffset;\n if (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 vec2 uv = mat2(cookieMatrix) * (projPos.xy-vec2(0.5)) + vec2(0.5);\n return mix(vec4(1.0), texture2D(tex, uv), intensity);\n}\n\nvec4 getCookieCube(samplerCube tex, mat4 transform, float intensity) {\n return mix(vec4(1.0), textureCube(tex, dLightDirNormW * mat3(transform)), intensity);\n}\n\n", cubeMapProjectBoxPS:"uniform vec3 envBoxMin, envBoxMax;\n\nvec3 cubeMapProject(vec3 nrdir) {\n vec3 rbmax = (envBoxMax - vPositionW) / nrdir;\n vec3 rbmin = (envBoxMin - vPositionW) / nrdir;\n\n vec3 rbminmax;\n rbminmax.x = nrdir.x>0.0? rbmax.x : rbmin.x;\n rbminmax.y = nrdir.y>0.0? rbmax.y : rbmin.y;\n rbminmax.z = nrdir.z>0.0? rbmax.z : rbmin.z;\n\n float fa = min(min(rbminmax.x, rbminmax.y), rbminmax.z);\n\n vec3 posonbox = vPositionW + nrdir * fa;\n vec3 envBoxPos = (envBoxMin + envBoxMax) * 0.5;\n return posonbox - envBoxPos;\n}\n\n", cubeMapProjectNonePS:"vec3 cubeMapProject(vec3 dir) {\n return dir;\n}\n\n",detailModesPS:"vec3 detailMode_mul(vec3 c1, vec3 c2) {\n return c1 * c2;\n}\n\nvec3 detailMode_add(vec3 c1, vec3 c2) {\n return c1 + c2;\n}\n\n// https://en.wikipedia.org/wiki/Blend_modes#Screen\nvec3 detailMode_screen(vec3 c1, vec3 c2) {\n return 1.0 - (1.0 - c1)*(1.0 - c2);\n}\n\n// https://en.wikipedia.org/wiki/Blend_modes#Overlay\nvec3 detailMode_overlay(vec3 c1, vec3 c2) {\n return mix(1.0 - 2.0*(1.0 - c1)*(1.0 - c2), 2.0*c1*c2, step(c1, vec3(0.5)));\n}\n\nvec3 detailMode_min(vec3 c1, vec3 c2) {\n return min(c1, c2);\n}\n\nvec3 detailMode_max(vec3 c1, vec3 c2) {\n return max(c1, c2);\n}\n\n", diffusePS:"#ifdef MAPCOLOR\nuniform vec3 material_diffuse;\n#endif\n\n#ifdef MAPTEXTURE\nuniform sampler2D texture_diffuseMap;\n#endif\n\nvoid getAlbedo() {\n dAlbedo = vec3(1.0);\n\n #ifdef MAPCOLOR\n dAlbedo *= material_diffuse.rgb;\n #endif\n\n #ifdef MAPTEXTURE\n dAlbedo *= gammaCorrectInput(addAlbedoDetail(texture2D(texture_diffuseMap, $UV).$CH));\n #endif\n\n #ifdef MAPVERTEX\n dAlbedo *= gammaCorrectInput(saturate(vVertexColor.$VC));\n #endif\n}\n\n", diffuseDetailMapPS:"#ifdef MAPTEXTURE\nuniform sampler2D texture_diffuseDetailMap;\n#endif\n\nvec3 addAlbedoDetail(vec3 albedo) {\n #ifdef MAPTEXTURE\n vec3 albedoDetail = vec3(texture2D(texture_diffuseDetailMap, $UV).$CH);\n return detailMode_$DETAILMODE(albedo, albedoDetail);\n #else\n return albedo;\n #endif\n}\n\n",dilatePS:"varying vec2 vUv0;\nuniform sampler2D source;\nuniform vec2 pixelOffset;\nvoid main(void) {\n vec4 c = texture2D(source, vUv0);\n c = c.a>0.0? c : texture2D(source, vUv0 - pixelOffset);\n c = c.a>0.0? c : texture2D(source, vUv0 + vec2(0, -pixelOffset.y));\n c = c.a>0.0? c : texture2D(source, vUv0 + vec2(pixelOffset.x, -pixelOffset.y));\n c = c.a>0.0? c : texture2D(source, vUv0 + vec2(-pixelOffset.x, 0));\n c = c.a>0.0? c : texture2D(source, vUv0 + vec2(pixelOffset.x, 0));\n c = c.a>0.0? c : texture2D(source, vUv0 + vec2(-pixelOffset.x, pixelOffset.y));\n c = c.a>0.0? c : texture2D(source, vUv0 + vec2(0, pixelOffset.y));\n c = c.a>0.0? c : texture2D(source, vUv0 + pixelOffset);\n gl_FragColor = c;\n}\n\n", dpAtlasQuadPS:"varying vec2 vUv0;\nuniform sampler2D source;\nuniform vec4 params;\n\nvoid main(void) {\n vec2 uv = vUv0;\n uv = uv * 2.0 - vec2(1.0);\n uv *= params.xy;\n uv = uv * 0.5 + 0.5;\n gl_FragColor = texture2D(source, uv);\n}\n",emissivePS:"#ifdef MAPCOLOR\nuniform vec3 material_emissive;\n#endif\n\n#ifdef MAPFLOAT\nuniform float material_emissiveIntensity;\n#endif\n\n#ifdef MAPTEXTURE\nuniform sampler2D texture_emissiveMap;\n#endif\n\nvec3 getEmission() {\n vec3 emission = vec3(1.0);\n\n #ifdef MAPFLOAT\n emission *= material_emissiveIntensity;\n #endif\n\n #ifdef MAPCOLOR\n emission *= material_emissive;\n #endif\n\n #ifdef MAPTEXTURE\n emission *= $texture2DSAMPLE(texture_emissiveMap, $UV).$CH;\n #endif\n\n #ifdef MAPVERTEX\n emission *= gammaCorrectInput(saturate(vVertexColor.$VC));\n #endif\n\n return emission;\n}\n\n", endPS:" #ifdef CLEARCOAT\n gl_FragColor.rgb = combineColorCC();\n #else\n gl_FragColor.rgb = combineColor();\n #endif \n gl_FragColor.rgb += getEmission();\n gl_FragColor.rgb = addFog(gl_FragColor.rgb);\n #ifndef HDR\n gl_FragColor.rgb = toneMap(gl_FragColor.rgb);\n gl_FragColor.rgb = gammaCorrectOutput(gl_FragColor.rgb);\n #endif\n",envConstPS:"vec3 processEnvironment(vec3 color) {\n return color;\n}\n\n",envMultiplyPS:"uniform float skyboxIntensity;\nvec3 processEnvironment(vec3 color) {\n return color * skyboxIntensity;\n}\n\n", extensionPS:"",extensionVS:"\n",falloffInvSquaredPS:"float getFalloffInvSquared(float lightRadius) {\n float sqrDist = dot(dLightDirW, dLightDirW);\n float falloff = 1.0 / (sqrDist + 1.0);\n float invRadius = 1.0 / lightRadius;\n\n falloff *= 16.0;\n falloff *= square( saturate( 1.0 - square( sqrDist * square(invRadius) ) ) );\n\n return falloff;\n}\n\n",falloffLinearPS:"float getFalloffLinear(float lightRadius) {\n float d = length(dLightDirW);\n return max(((lightRadius - d) / lightRadius), 0.0);\n}\n\n", fixCubemapSeamsNonePS:"vec3 fixSeams(vec3 vec, float mipmapIndex) {\n return vec;\n}\n\nvec3 fixSeams(vec3 vec) {\n return vec;\n}\n\nvec3 fixSeamsStatic(vec3 vec, float invRecMipSize) {\n return vec;\n}\n",fixCubemapSeamsStretchPS:"vec3 fixSeams(vec3 vec, float mipmapIndex) {\n float scale = 1.0 - exp2(mipmapIndex) / 128.0;\n float M = max(max(abs(vec.x), abs(vec.y)), abs(vec.z));\n if (abs(vec.x) != M) vec.x *= scale;\n if (abs(vec.y) != M) vec.y *= scale;\n if (abs(vec.z) != M) vec.z *= scale;\n return vec;\n}\n\nvec3 fixSeams(vec3 vec) {\n float scale = 1.0 - 1.0 / 128.0;\n float M = max(max(abs(vec.x), abs(vec.y)), abs(vec.z));\n if (abs(vec.x) != M) vec.x *= scale;\n if (abs(vec.y) != M) vec.y *= scale;\n if (abs(vec.z) != M) vec.z *= scale;\n return vec;\n}\n\nvec3 fixSeamsStatic(vec3 vec, float invRecMipSize) {\n float scale = invRecMipSize;\n float M = max(max(abs(vec.x), abs(vec.y)), abs(vec.z));\n if (abs(vec.x) != M) vec.x *= scale;\n if (abs(vec.y) != M) vec.y *= scale;\n if (abs(vec.z) != M) vec.z *= scale;\n return vec;\n}\n\n", fogExpPS:"uniform vec3 fog_color;\nuniform float fog_density;\nvec3 addFog(vec3 color) {\n float depth = gl_FragCoord.z / gl_FragCoord.w;\n float fogFactor = exp(-depth * fog_density);\n fogFactor = clamp(fogFactor, 0.0, 1.0);\n return mix(fog_color, color, fogFactor);\n}\n",fogExp2PS:"uniform vec3 fog_color;\nuniform float fog_density;\nvec3 addFog(vec3 color) {\n float depth = gl_FragCoord.z / gl_FragCoord.w;\n float fogFactor = exp(-depth * depth * fog_density * fog_density);\n fogFactor = clamp(fogFactor, 0.0, 1.0);\n return mix(fog_color, color, fogFactor);\n}\n", fogLinearPS:"uniform vec3 fog_color;\nuniform float fog_start;\nuniform float fog_end;\nvec3 addFog(vec3 color) {\n float depth = gl_FragCoord.z / gl_FragCoord.w;\n float fogFactor = (fog_end - depth) / (fog_end - fog_start);\n fogFactor = clamp(fogFactor, 0.0, 1.0);\n fogFactor = gammaCorrectInput(fogFactor);\n return mix(fog_color, color, fogFactor);\n}\n",fogNonePS:"vec3 addFog(vec3 color) {\n return color;\n}\n\n\n",fresnelSchlickPS:"// Schlick's approximation\nuniform float material_fresnelFactor; // unused\nvoid getFresnel() {\n float fresnel = 1.0 - max(dot(dNormalW, dViewDirW), 0.0);\n float fresnel2 = fresnel * fresnel;\n fresnel *= fresnel2 * fresnel2;\n fresnel *= dGlossiness * dGlossiness;\n dSpecularity = dSpecularity + (1.0 - dSpecularity) * fresnel;\n #ifdef CLEARCOAT\n fresnel = 1.0 - max(dot(ccNormalW, dViewDirW), 0.0);\n fresnel2 = fresnel * fresnel;\n fresnel *= fresnel2 * fresnel2;\n fresnel *= ccGlossiness * ccGlossiness;\n ccSpecularity = ccSpecularity + (1.0 - ccSpecularity) * fresnel;\n #endif\n}\n", fullscreenQuadPS:"varying vec2 vUv0;\nuniform sampler2D source;\n\nvoid main(void) {\n gl_FragColor = texture2D(source, vUv0);\n}\n",fullscreenQuadVS:"attribute vec2 vertex_position;\n\nvarying vec2 vUv0;\n\nvoid main(void)\n{\n gl_Position = vec4(vertex_position, 0.5, 1.0);\n vUv0 = vertex_position.xy*0.5+0.5;\n}\n\n",gamma1_0PS:"vec4 texture2DSRGB(sampler2D tex, vec2 uv) {\n return texture2D(tex, uv);\n}\n\nvec4 texture2DSRGB(sampler2D tex, vec2 uv, float bias) {\n return texture2D(tex, uv, bias);\n}\n\nvec4 textureCubeSRGB(samplerCube tex, vec3 uvw) {\n return textureCube(tex, uvw);\n}\n\nvec3 gammaCorrectOutput(vec3 color) {\n return color;\n}\n\nvec3 gammaCorrectInput(vec3 color) {\n return color;\n}\n\nfloat gammaCorrectInput(float color) {\n return color;\n}\n\nvec4 gammaCorrectInput(vec4 color) {\n return color;\n}\n", gamma2_2PS:"vec3 gammaCorrectInput(vec3 color) {\n return pow(color, vec3(2.2));\n}\n\nfloat gammaCorrectInput(float color) {\n return pow(color, 2.2);\n}\n\nvec4 gammaCorrectInput(vec4 color) {\n return vec4(pow(color.rgb, vec3(2.2)), color.a);\n}\n\nvec4 texture2DSRGB(sampler2D tex, vec2 uv) {\n vec4 rgba = texture2D(tex, uv);\n rgba.rgb = gammaCorrectInput(rgba.rgb);\n return rgba;\n}\n\nvec4 texture2DSRGB(sampler2D tex, vec2 uv, float bias) {\n vec4 rgba = texture2D(tex, uv, bias);\n rgba.rgb = gammaCorrectInput(rgba.rgb);\n return rgba;\n}\n\nvec4 textureCubeSRGB(samplerCube tex, vec3 uvw) {\n vec4 rgba = textureCube(tex, uvw);\n rgba.rgb = gammaCorrectInput(rgba.rgb);\n return rgba;\n}\n\nvec3 gammaCorrectOutput(vec3 color) {\n#ifdef HDR\n return color;\n#else\n color += vec3(0.0000001);\n return pow(color, vec3(0.45));\n#endif\n}\n", genParaboloidPS:"varying vec2 vUv0;\n\nuniform samplerCube source;\nuniform vec4 params; // x = mip\n\nvoid main(void) {\n\n vec2 uv = vUv0;\n\n float side = uv.x < 0.5? 1.0 : -1.0;\n vec2 tc;\n tc.x = fract(uv.x * 2.0) * 2.0 - 1.0;\n tc.y = uv.y * 2.0 - 1.0;\n\n // scale projection a bit to have a little overlap for filtering\n const float scale = 1.1;\n tc *= scale;\n\n vec3 dir;\n dir.y = (dot(tc, tc) - 1.0) * side; // from 1.0 center to 0.0 borders quadratically\n dir.xz = tc * -2.0;\n\n dir.x *= -side * params.y; // flip original cubemap x instead of doing it at runtime\n\n dir = fixSeams(dir, params.x);\n\n vec4 color = textureCube(source, dir, -100.0);\n gl_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\n#ifdef MAPTEXTURE\nuniform sampler2D texture_glossMap;\n#endif\n\n#ifdef CLEARCOAT\nuniform float material_clearCoatGlossiness;\n#endif\n\nvoid getGlossiness() {\n dGlossiness = 1.0;\n\n #ifdef MAPFLOAT\n dGlossiness *= material_shininess;\n #endif\n\n #ifdef MAPTEXTURE\n dGlossiness *= texture2D(texture_glossMap, $UV).$CH;\n #endif\n\n #ifdef MAPVERTEX\n dGlossiness *= saturate(vVertexColor.$VC);\n #endif\n\n dGlossiness += 0.0000001;\n\n #ifdef CLEARCOAT\n ccGlossiness = 1.0;\n ccGlossiness *= material_clearCoatGlossiness;\n ccGlossiness += 0.0000001;\n #endif\n}\n\n", instancingVS:"\nattribute vec4 instance_line1;\nattribute vec4 instance_line2;\nattribute vec4 instance_line3;\nattribute vec4 instance_line4;\n\n",lightDiffuseLambertPS:"float getLightDiffuse() {\n return max(dot(dNormalW, -dLightDirNormW), 0.0);\n}\n\n",lightDirPointPS:"void getLightDirPoint(vec3 lightPosW) {\n dLightDirW = vPositionW - lightPosW;\n dLightDirNormW = normalize(dLightDirW);\n dLightPosW = lightPosW;\n}\n\n",lightmapDirPS:"uniform sampler2D texture_lightMap;\nuniform sampler2D texture_dirLightMap;\n\nvoid addLightMap() {\n\n vec3 color = $texture2DSAMPLE(texture_lightMap, $UV).$CH;\n vec4 dir = texture2D(texture_dirLightMap, $UV);\n\n if (dot(dir.xyz,vec3(1.0)) < 0.00001) {\n dDiffuseLight += color;\n return;\n }\n\n dLightDirNormW = normalize(dir.xyz * 2.0 - vec3(1.0));\n\n float vlight = saturate(dot(dLightDirNormW, -dVertexNormalW));\n float flight = saturate(dot(dLightDirNormW, -dNormalW));\n float nlight = (flight / max(vlight,0.01)) * 0.5;\n\n dDiffuseLight += color * nlight * 2.0;\n}\n\nvoid addDirLightMap() {\n vec4 dir = texture2D(texture_dirLightMap, $UV);\n if (dot(dir.xyz,vec3(1.0)) < 0.00001) return;\n vec3 color = $texture2DSAMPLE(texture_lightMap, $UV).$CH;\n\n dLightDirNormW = normalize(dir.xyz * 2.0 - vec3(1.0));\n dSpecularLight += vec3(getLightSpecular()) * color;\n}\n\n", lightmapSinglePS:"#ifdef MAPTEXTURE\nuniform sampler2D texture_lightMap;\n#endif\n\nvoid addLightMap() {\n vec3 lm = vec3(1.0);\n\n #ifdef MAPTEXTURE\n lm *= $texture2DSAMPLE(texture_lightMap, $UV).$CH;\n #endif\n\n #ifdef MAPVERTEX\n lm *= saturate(vVertexColor.$VC);\n #endif\n \n dDiffuseLight += lm;\n}\n\n",lightmapSingleVertPS:"void addLightMap() {\n dDiffuseLight += saturate(vVertexColor.$CH);\n}\n\n",lightSpecularAnisoGGXPS:"// Anisotropic GGX\nfloat calcLightSpecular(float tGlossiness, vec3 tNormalW) {\n float PI = 3.141592653589793;\n float roughness = max((1.0 - tGlossiness) * (1.0 - tGlossiness), 0.001);\n float anisotropy = material_anisotropy * roughness;\n \n float at = max((roughness + anisotropy), roughness / 4.0);\n float ab = max((roughness - anisotropy), roughness / 4.0);\n\n vec3 h = normalize(normalize(-dLightDirNormW) + normalize(dViewDirW));\n\n float NoH = dot(tNormalW, h);\n float ToH = dot(dTBN[0], h);\n float BoH = dot(dTBN[1], h);\n\n float a2 = at * ab;\n vec3 v = vec3(ab * ToH, at * BoH, a2 * NoH);\n float v2 = dot(v, v);\n float w2 = a2 / v2;\n float D = a2 * w2 * w2 * (1.0 / PI);\n\n float ToV = dot(dTBN[0], dViewDirW);\n float BoV = dot(dTBN[1], dViewDirW);\n float ToL = dot(dTBN[0], -dLightDirNormW);\n float BoL = dot(dTBN[1], -dLightDirNormW);\n float NoV = dot(tNormalW, dViewDirW);\n float NoL = dot(tNormalW, -dLightDirNormW);\n\n float lambdaV = NoL * length(vec3(at * ToV, ab * BoV, NoV));\n float lambdaL = NoV * length(vec3(at * ToL, ab * BoL, NoL));\n float G = 0.5 / (lambdaV + lambdaL);\n\n return D * G;\n}\n\nfloat getLightSpecular() {\n return calcLightSpecular(dGlossiness, dNormalW);\n}\n\nfloat getLightSpecularCC() {\n return calcLightSpecular(ccGlossiness, ccNormalW);\n}\n", lightSpecularBlinnPS:"// Energy-conserving (hopefully) Blinn-Phong\nfloat calcLightSpecular(float tGlossiness, vec3 tNormalW) {\n vec3 h = normalize( -dLightDirNormW + dViewDirW );\n float nh = max( dot( h, tNormalW ), 0.0 );\n\n float specPow = exp2(tGlossiness * 11.0); // glossiness is linear, power is not; 0 - 2048\n specPow = antiAliasGlossiness(specPow);\n\n // Hack: On Mac OS X, calling pow with zero for the exponent generates hideous artifacts so bias up a little\n specPow = max(specPow, 0.0001);\n\n return pow(nh, specPow) * (specPow + 2.0) / 8.0;\n}\n\nfloat getLightSpecular() {\n return calcLightSpecular(dGlossiness, dNormalW);\n}\n\nfloat getLightSpecularCC() {\n return calcLightSpecular(ccGlossiness, ccNormalW);\n}\n", lightSpecularPhongPS:"float calcLightSpecular(float tGlossiness, vec3 tReflDirW) {\n float specPow = tGlossiness;\n\n specPow = antiAliasGlossiness(specPow);\n\n // Hack: On Mac OS X, calling pow with zero for the exponent generates hideous artifacts so bias up a little\n return pow(max(dot(tReflDirW, -dLightDirNormW), 0.0), specPow + 0.0001);\n}\n\nfloat getLightSpecular() {\n return calcLightSpecular(dGlossiness, dReflDirW);\n}\n\nfloat getLightSpecularCC() {\n return calcLightSpecular(ccGlossiness, ccReflDirW);\n}\n", metalnessPS:"void processMetalness(float metalness) {\n const float dielectricF0 = 0.04;\n dSpecularity = mix(vec3(dielectricF0), dAlbedo, metalness);\n dAlbedo *= 1.0 - metalness;\n}\n\n#ifdef MAPFLOAT\nuniform float material_metalness;\n#endif\n\n#ifdef MAPTEXTURE\nuniform sampler2D texture_metalnessMap;\n#endif\n\n#ifdef CLEARCOAT\nuniform float material_clearCoatSpecularity;\n#endif\n\nvoid getSpecularity() {\n float metalness = 1.0;\n\n #ifdef MAPFLOAT\n metalness *= material_metalness;\n #endif\n\n #ifdef MAPTEXTURE\n metalness *= texture2D(texture_metalnessMap, $UV).$CH;\n #endif\n\n #ifdef MAPVERTEX\n metalness *= saturate(vVertexColor.$VC);\n #endif\n\n processMetalness(metalness);\n\n #ifdef CLEARCOAT\n ccSpecularity = vec3(1.0);\n ccSpecularity *= material_clearCoatSpecularity;\n #endif\n}\n\n", msdfPS:"uniform sampler2D texture_msdfMap;\n\n#ifdef GL_OES_standard_derivatives\n#define USE_FWIDTH\n#endif\n\n#ifdef GL2\n#define USE_FWIDTH\n#endif\n\nfloat median(float r, float g, float b) {\n return max(min(r, g), min(max(r, g), b));\n}\n\nfloat map (float min, float max, float v) {\n return (v - min) / (max - min);\n}\n\n\nuniform float font_sdfIntensity; // intensity is used to boost the value read from the SDF, 0 is no boost, 1.0 is max boost\nuniform float font_pxrange; // the number of pixels between inside and outside the font in SDF\nuniform float font_textureWidth; // the width of the texture atlas\n\nuniform vec4 outline_color;\nuniform float outline_thickness;\nuniform vec4 shadow_color;\nuniform vec2 shadow_offset;\n\nvec4 applyMsdf(vec4 color) {\n // sample the field\n vec3 tsample = texture2D(texture_msdfMap, vUv0).rgb;\n vec2 uvShdw = vUv0 - shadow_offset;\n vec3 ssample = texture2D(texture_msdfMap, uvShdw).rgb;\n // get the signed distance value\n float sigDist = median(tsample.r, tsample.g, tsample.b);\n float sigDistShdw = median(ssample.r, ssample.g, ssample.b);\n\n #ifdef USE_FWIDTH\n // smoothing depends on size of texture on screen\n vec2 w = fwidth(vUv0);\n float smoothing = clamp(w.x * font_textureWidth / font_pxrange, 0.0, 0.5);\n #else\n float font_size = 16.0; // TODO fix this\n // smoothing gets smaller as the font size gets bigger\n // don't have fwidth we can approximate from font size, this doesn't account for scaling\n // so a big font scaled down will be wrong...\n\n float smoothing = clamp(font_pxrange / font_size, 0.0, 0.5);\n #endif\n float mapMin = 0.05;\n float mapMax = clamp(1.0 - font_sdfIntensity, mapMin, 1.0);\n\n // remap to a smaller range (used on smaller font sizes)\n float sigDistInner = map(mapMin, mapMax, sigDist);\n float sigDistOutline = map(mapMin, mapMax, sigDist + outline_thickness);\n sigDistShdw = map(mapMin, mapMax, sigDistShdw + outline_thickness);\n\n float center = 0.5;\n // calculate smoothing and use to generate opacity\n float inside = smoothstep(center-smoothing, center+smoothing, sigDistInner);\n float outline = smoothstep(center-smoothing, center+smoothing, sigDistOutline);\n float shadow = smoothstep(center-smoothing, center+smoothing, sigDistShdw);\n\n vec4 tcolor = (outline > inside) ? outline * vec4(outline_color.a * outline_color.rgb, outline_color.a) : vec4(0.0);\n tcolor = mix(tcolor, color, inside);\n\n vec4 scolor = (shadow > outline) ? shadow * vec4(shadow_color.a * shadow_color.rgb, shadow_color.a) : tcolor;\n tcolor = mix(scolor, tcolor, outline);\n \n return tcolor;\n}", normalVS:"#ifdef MORPHING_TEXTURE_BASED_NORMAL\n uniform highp sampler2D morphNormalTex;\n#endif\n\nvec3 getNormal() {\n #ifdef SKIN\n dNormalMatrix = mat3(dModelMatrix[0].xyz, dModelMatrix[1].xyz, dModelMatrix[2].xyz);\n #elif defined(INSTANCING)\n dNormalMatrix = mat3(instance_line1.xyz, instance_line2.xyz, instance_line3.xyz);\n #else\n dNormalMatrix = matrix_normal;\n #endif\n\n vec3 tempNormal = vertex_normal;\n\n #ifdef MORPHING\n #ifdef MORPHING_NRM03\n tempNormal += morph_weights_a[0] * morph_nrm0;\n tempNormal += morph_weights_a[1] * morph_nrm1;\n tempNormal += morph_weights_a[2] * morph_nrm2;\n tempNormal += morph_weights_a[3] * morph_nrm3;\n #endif\n #ifdef MORPHING_NRM47\n tempNormal += morph_weights_b[0] * morph_nrm4;\n tempNormal += morph_weights_b[1] * morph_nrm5;\n tempNormal += morph_weights_b[2] * morph_nrm6;\n tempNormal += morph_weights_b[3] * morph_nrm7;\n #endif\n #endif\n\n #ifdef MORPHING_TEXTURE_BASED_NORMAL\n // apply morph offset from texture\n vec2 morphUV = getTextureMorphCoords();\n vec3 morphNormal = texture2D(morphNormalTex, morphUV).xyz;\n tempNormal += morphNormal;\n #endif\n\n return normalize(dNormalMatrix * tempNormal);\n}\n\n", normalDetailMapPS:"#ifdef MAPTEXTURE\nuniform sampler2D texture_normalDetailMap;\nuniform float material_normalDetailMapBumpiness;\n\nvec3 blendNormals(vec3 n1, vec3 n2) {\n // https://blog.selfshadow.com/publications/blending-in-detail/#detail-oriented\n n1 += vec3(0, 0, 1);\n n2 *= vec3(-1, -1, 1);\n return normalize(n1*dot(n1, n2)/n1.z - n2);\n}\n#endif\n\nvec3 addNormalDetail(vec3 normalMap) {\n #ifdef MAPTEXTURE\n vec3 normalDetailMap = unpackNormal(texture2D(texture_normalDetailMap, $UV));\n normalDetailMap = normalize(mix(vec3(0.0, 0.0, 1.0), normalDetailMap, material_normalDetailMapBumpiness));\n return blendNormals(normalMap, normalDetailMap);\n #else\n return normalMap;\n #endif\n}\n\n", normalInstancedVS:"vec3 getNormal() {\n dNormalMatrix = mat3(instance_line1.xyz, instance_line2.xyz, instance_line3.xyz);\n return normalize(dNormalMatrix * vertex_normal);\n}\n\n",normalMapPS:"uniform sampler2D texture_normalMap;\nuniform float material_bumpiness;\nvoid getNormal() {\n vec3 normalMap = unpackNormal(texture2D(texture_normalMap, $UV));\n normalMap = normalize(mix(vec3(0.0, 0.0, 1.0), normalMap, material_bumpiness));\n dNormalMap = addNormalDetail(normalMap);\n dNormalW = dTBN * dNormalMap;\n #ifdef CLEARCOAT\n ccNormalW = normalize(dVertexNormalW);\n #endif\n}\n", normalMapFastPS:"uniform sampler2D texture_normalMap;\nvoid getNormal() {\n vec3 normalMap = unpackNormal(texture2D(texture_normalMap, $UV));\n dNormalMap = addNormalDetail(normalMap);\n dNormalW = dTBN * dNormalMap;\n #ifdef CLEARCOAT\n ccNormalW = normalize(dVertexNormalW);\n #endif\n}\n",normalSkinnedVS:"vec3 getNormal() {\n dNormalMatrix = mat3(dModelMatrix[0].xyz, dModelMatrix[1].xyz, dModelMatrix[2].xyz);\n return normalize(dNormalMatrix * vertex_normal);\n}\n\n", normalVertexPS:"void getNormal() {\n dNormalW = normalize(dVertexNormalW);\n #ifdef CLEARCOAT\n ccNormalW = dNormalW;\n #endif\n}\n\n",normalXYPS:"vec3 unpackNormal(vec4 nmap) {\n vec3 normal;\n normal.xy = nmap.wy * 2.0 - 1.0;\n normal.z = sqrt(1.0 - saturate(dot(normal.xy, normal.xy)));\n return normal;\n}\n\n",normalXYZPS:"vec3 unpackNormal(vec4 nmap) {\n return nmap.xyz * 2.0 - 1.0;\n}\n\n",opacityPS:"#ifdef MAPFLOAT\nuniform float material_opacity;\n#endif\n\n#ifdef MAPTEXTURE\nuniform sampler2D texture_opacityMap;\n#endif\n\nvoid getOpacity() {\n dAlpha = 1.0;\n\n #ifdef MAPFLOAT\n dAlpha *= material_opacity;\n #endif\n\n #ifdef MAPTEXTURE\n dAlpha *= texture2D(texture_opacityMap, $UV).$CH;\n #endif\n\n #ifdef MAPVERTEX\n dAlpha *= clamp(vVertexColor.$VC, 0.0, 1.0);\n #endif\n}\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;\n\nuniform samplerCube source;\nuniform vec4 params;\n\nfloat saturate(float x) {\n return clamp(x, 0.0, 1.0);\n}\n\nvec4 encodeRGBM(vec4 color) { // modified RGBM\n color.rgb = pow(color.rgb, vec3(0.5));\n color.rgb *= 1.0 / 8.0;\n\n color.a = saturate( max( max( color.r, color.g ), max( color.b, 1.0 / 255.0 ) ) );\n color.a = ceil(color.a * 255.0) / 255.0;\n\n color.rgb /= color.a;\n return color;\n}\n\nvoid main(void) {\n\n vec2 st = vUv0 * 2.0 - 1.0;\n float face = params.x;\n\n vec3 vec;\n if (face==0.0) {\n vec = vec3(1, -st.y, -st.x);\n } else if (face==1.0) {\n vec = vec3(-1, -st.y, st.x);\n } else if (face==2.0) {\n vec = vec3(st.x, 1, st.y);\n } else if (face==3.0) {\n vec = vec3(st.x, -1, -st.y);\n } else if (face==4.0) {\n vec = vec3(st.x, -st.y, 1);\n } else {\n vec = vec3(-st.x, -st.y, -1);\n }\n\n gl_FragColor = textureCube(source, vec);\n if (params.w >= 2.0) gl_FragColor = encodeRGBM(gl_FragColor);\n}\n\n", outputTex2DPS:"varying vec2 vUv0;\n\nuniform sampler2D source;\n\nvoid main(void) {\n gl_FragColor = texture2D(source, vUv0);\n}\n\n",packDepthPS:"// Packing a float in GLSL with multiplication and mod\n// http://blog.gradientstudios.com/2012/08/23/shadow-map-improvement\nvec4 packFloat(float depth) {\n const vec4 bit_shift = vec4(256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0);\n const vec4 bit_mask = vec4(0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0);\n\n // combination of mod and multiplication and division works better\n vec4 res = mod(depth * bit_shift * vec4(255), vec4(256) ) / vec4(255);\n res -= res.xxyz * bit_mask;\n return res;\n}\n\n\n", packDepthMaskPS:"vec4 packFloat(float depth) {\n const vec4 bit_shift = vec4(256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0);\n const vec4 bit_mask = vec4(0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0);\n\n // combination of mod and multiplication and division works better\n vec4 res = mod(depth * bit_shift * vec4(255), vec4(256) ) / vec4(255);\n res.x = 0.0;\n res -= res.xxyz * bit_mask;\n return res;\n}\n\n",parallaxPS:"uniform sampler2D texture_heightMap;\nuniform float material_heightMapFactor;\nvoid getParallax() {\n float parallaxScale = material_heightMapFactor;\n\n float height = texture2D(texture_heightMap, $UV).$CH;\n height = height * parallaxScale - parallaxScale*0.5;\n vec3 viewDirT = dViewDirW * dTBN;\n\n viewDirT.z += 0.42;\n dUvOffset = height * (viewDirT.xy / viewDirT.z);\n}\n\n", particlePS:"varying vec4 texCoordsAlphaLife;\n\nuniform sampler2D colorMap;\nuniform sampler2D colorParam;\nuniform float graphSampleSize;\nuniform float graphNumSamples;\n\n#ifndef CAMERAPLANES\n#define CAMERAPLANES\nuniform vec4 camera_params;\n#endif\n\nuniform float softening;\nuniform float colorMult;\n\nfloat saturate(float x) {\n return clamp(x, 0.0, 1.0);\n}\n\n#ifndef UNPACKFLOAT\n#define UNPACKFLOAT\nfloat unpackFloat(vec4 rgbaDepth) {\n const vec4 bitShift = vec4(1.0 / (256.0 * 256.0 * 256.0), 1.0 / (256.0 * 256.0), 1.0 / 256.0, 1.0);\n float depth = dot(rgbaDepth, bitShift);\n return depth;\n}\n#endif\n\nvoid main(void) {\n vec4 tex = texture2DSRGB(colorMap, texCoordsAlphaLife.xy);\n vec4 ramp = texture2DSRGB(colorParam, vec2(texCoordsAlphaLife.w, 0.0));\n ramp.rgb *= colorMult;\n\n ramp.a += texCoordsAlphaLife.z;\n\n vec3 rgb = tex.rgb * ramp.rgb;\n float a = tex.a * ramp.a;\n", particleVS:"\nvec3 unpack3NFloats(float src) {\n float r = fract(src);\n float g = fract(src * 256.0);\n float b = fract(src * 65536.0);\n return vec3(r, g, b);\n}\n\nfloat saturate(float x) {\n return clamp(x, 0.0, 1.0);\n}\n\nvec4 tex1Dlod_lerp(highp sampler2D tex, vec2 tc) {\n return mix( texture2D(tex,tc), texture2D(tex,tc + graphSampleSize), fract(tc.x*graphNumSamples) );\n}\n\nvec4 tex1Dlod_lerp(highp sampler2D tex, vec2 tc, out vec3 w) {\n vec4 a = texture2D(tex,tc);\n vec4 b = texture2D(tex,tc + graphSampleSize);\n float c = fract(tc.x*graphNumSamples);\n\n vec3 unpackedA = unpack3NFloats(a.w);\n vec3 unpackedB = unpack3NFloats(b.w);\n w = mix(unpackedA, unpackedB, c);\n\n return mix(a, b, c);\n}\n\n\nvec2 rotate(vec2 quadXY, float pRotation, out mat2 rotMatrix) {\n float c = cos(pRotation);\n float s = sin(pRotation);\n\n mat2 m = mat2(c, -s, s, c);\n rotMatrix = m;\n\n return m * quadXY;\n}\n\nvec3 billboard(vec3 InstanceCoords, vec2 quadXY) {\n vec3 pos = -matrix_viewInverse[0].xyz * quadXY.x + -matrix_viewInverse[1].xyz * quadXY.y;\n return pos;\n}\n\nvec3 customFace(vec3 InstanceCoords, vec2 quadXY) {\n vec3 pos = faceTangent * quadXY.x + faceBinorm * quadXY.y;\n return pos;\n}\n\nvec2 safeNormalize(vec2 v) {\n float l = length(v);\n return (l > 1e-06) ? v / l : v;\n}\n\nvoid main(void) {\n vec3 meshLocalPos = particle_vertexData.xyz;\n float id = floor(particle_vertexData.w);\n\n float rndFactor = fract(sin(id + 1.0 + seed));\n vec3 rndFactor3 = vec3(rndFactor, fract(rndFactor*10.0), fract(rndFactor*100.0));\n\n float uv = id / numParticlesPot;\n readInput(uv);\n\n#ifdef LOCAL_SPACE\n inVel = mat3(matrix_model) * inVel;\n#endif\n vec2 velocityV = safeNormalize((mat3(matrix_view) * inVel).xy); // should be removed by compiler if align/stretch is not used\n\n float particleLifetime = lifetime;\n\n if (inLife <= 0.0 || inLife > particleLifetime || !inShow) meshLocalPos = vec3(0.0);\n vec2 quadXY = meshLocalPos.xy;\n float nlife = clamp(inLife / particleLifetime, 0.0, 1.0);\n\n vec3 paramDiv;\n vec4 params = tex1Dlod_lerp(internalTex2, vec2(nlife, 0), paramDiv);\n float scale = params.y;\n float scaleDiv = paramDiv.x;\n float alphaDiv = paramDiv.z;\n\n scale += (scaleDiv * 2.0 - 1.0) * scaleDivMult * fract(rndFactor*10000.0);\n\n#ifndef USE_MESH\n texCoordsAlphaLife = vec4(quadXY * -0.5 + 0.5, (alphaDiv * 2.0 - 1.0) * alphaDivMult * fract(rndFactor*1000.0), nlife);\n#else\n texCoordsAlphaLife = vec4(particle_uv, (alphaDiv * 2.0 - 1.0) * alphaDivMult * fract(rndFactor*1000.0), nlife);\n#endif\n\n vec3 particlePos = inPos;\n vec3 particlePosMoved = vec3(0.0);\n\n mat2 rotMatrix;\n", particleAnimFrameClampVS:"\n float animFrame = min(floor(texCoordsAlphaLife.w * animTexParams.y) + animTexParams.x, animTexParams.z);\n\n",particleAnimFrameLoopVS:"\n float animFrame = floor(mod(texCoordsAlphaLife.w * animTexParams.y + animTexParams.x, animTexParams.z + 1.0));\n\n",particleAnimTexVS:"\n float animationIndex;\n\n if (animTexIndexParams.y == 1.0) {\n animationIndex = floor((animTexParams.w + 1.0) * rndFactor3.z) * (animTexParams.z + 1.0);\n } else {\n animationIndex = animTexIndexParams.x * (animTexParams.z + 1.0);\n }\n\n float atlasX = (animationIndex + animFrame) * animTexTilesParams.x;\n float atlasY = 1.0 - floor(atlasX + 1.0) * animTexTilesParams.y;\n atlasX = fract(atlasX);\n\n texCoordsAlphaLife.xy *= animTexTilesParams.xy;\n texCoordsAlphaLife.xy += vec2(atlasX, atlasY);\n\n", particleInputFloatPS:"void readInput(float uv) {\n vec4 tex = texture2D(particleTexIN, vec2(uv, 0.25));\n vec4 tex2 = texture2D(particleTexIN, vec2(uv, 0.75));\n\n inPos = tex.xyz;\n inVel = tex2.xyz;\n inAngle = (tex.w < 0.0? -tex.w : tex.w) - 1000.0;\n inShow = tex.w >= 0.0;\n inLife = tex2.w;\n}\n\n",particleInputRgba8PS:"//RG=X, BA=Y\n//RG=Z, BA=A\n//RGB=V, A=visMode\n//RGBA=life\n\n#define PI2 6.283185307179586\n\nuniform vec3 inBoundsSize;\nuniform vec3 inBoundsCenter;\n\nuniform float maxVel;\n\nfloat decodeFloatRG(vec2 rg) {\n return rg.y*(1.0/255.0) + rg.x;\n}\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}\n\nvoid readInput(float uv) {\n vec4 tex0 = texture2D(particleTexIN, vec2(uv, 0.125));\n vec4 tex1 = texture2D(particleTexIN, vec2(uv, 0.375));\n vec4 tex2 = texture2D(particleTexIN, vec2(uv, 0.625));\n vec4 tex3 = texture2D(particleTexIN, vec2(uv, 0.875));\n\n inPos = vec3(decodeFloatRG(tex0.rg), decodeFloatRG(tex0.ba), decodeFloatRG(tex1.rg));\n inPos = (inPos - vec3(0.5)) * inBoundsSize + inBoundsCenter;\n\n inVel = tex2.xyz;\n inVel = (inVel - vec3(0.5)) * maxVel;\n\n inAngle = decodeFloatRG(tex1.ba) * PI2;\n inShow = tex2.a > 0.5;\n\n inLife = decodeFloatRGBA(tex3);\n float maxNegLife = max(lifetime, (numParticles - 1.0) * (rate+rateDiv));\n float maxPosLife = lifetime+1.0;\n inLife = inLife * (maxNegLife + maxPosLife) - maxNegLife;\n}\n\n", particleOutputFloatPS:"void writeOutput() {\n if (gl_FragCoord.y<1.0) {\n gl_FragColor = vec4(outPos, (outAngle + 1000.0) * visMode);\n } else {\n gl_FragColor = vec4(outVel, outLife);\n }\n}\n\n",particleOutputRgba8PS:"uniform vec3 outBoundsMul;\nuniform vec3 outBoundsAdd;\n\nvec2 encodeFloatRG( float v ) {\n vec2 enc = vec2(1.0, 255.0) * v;\n enc = fract(enc);\n enc -= enc.yy * vec2(1.0/255.0, 1.0/255.0);\n return enc;\n}\n\nvec4 encodeFloatRGBA( float v ) {\n vec4 enc = vec4(1.0, 255.0, 65025.0, 160581375.0) * v;\n enc = fract(enc);\n enc -= enc.yzww * vec4(1.0/255.0,1.0/255.0,1.0/255.0,0.0);\n return enc;\n}\n\nvoid writeOutput() {\n //outPos = (outPos - outBoundsCenter) / outBoundsSize + vec3(0.5);\n\n outPos = outPos * outBoundsMul + outBoundsAdd;\n outAngle = fract(outAngle / PI2);\n\n outVel = (outVel / maxVel) + vec3(0.5); // TODO: mul\n\n float maxNegLife = max(lifetime, (numParticles - 1.0) * (rate+rateDiv));\n float maxPosLife = lifetime+1.0;\n outLife = (outLife + maxNegLife) / (maxNegLife + maxPosLife);\n\n if (gl_FragCoord.y < 1.0) {\n gl_FragColor = vec4(encodeFloatRG(outPos.x), encodeFloatRG(outPos.y));\n } else if (gl_FragCoord.y < 2.0) {\n gl_FragColor = vec4(encodeFloatRG(outPos.z), encodeFloatRG(outAngle));\n } else if (gl_FragCoord.y < 3.0) {\n gl_FragColor = vec4(outVel, visMode*0.5+0.5);\n } else {\n gl_FragColor = encodeFloatRGBA(outLife);\n }\n}\n\n", particleUpdaterAABBPS:"uniform mat3 spawnBounds;\nuniform vec3 spawnPosInnerRatio;\nvec3 calcSpawnPosition(vec3 inBounds, float rndFactor) {\n vec3 pos = inBounds - vec3(0.5);\n\n vec3 posAbs = abs(pos);\n vec3 maxPos = vec3(max(posAbs.x, max(posAbs.y, posAbs.z)));\n\n vec3 edge = maxPos + (vec3(0.5) - maxPos) * spawnPosInnerRatio;\n\n //pos = edge * mix(2.0 * pos, sign(pos), equal(maxPos, posAbs));\n pos.x = edge.x * (maxPos.x == posAbs.x ? sign(pos.x) : 2.0 * pos.x);\n pos.y = edge.y * (maxPos.y == posAbs.y ? sign(pos.y) : 2.0 * pos.y);\n pos.z = edge.z * (maxPos.z == posAbs.z ? sign(pos.z) : 2.0 * pos.z);\n\n#ifndef LOCAL_SPACE\n return emitterPos + spawnBounds * pos;\n#else\n return spawnBounds * pos;\n#endif\n}\n\nvoid addInitialVelocity(inout vec3 localVelocity, vec3 inBounds) {\n localVelocity -= vec3(0, 0, initialVelocity);\n}\n\n", particleUpdaterEndPS:"\n writeOutput();\n}\n\n",particleUpdaterInitPS:"varying vec2 vUv0;\n\nuniform highp sampler2D particleTexIN;\nuniform highp sampler2D internalTex0;\nuniform highp sampler2D internalTex1;\nuniform highp sampler2D internalTex2;\nuniform highp sampler2D internalTex3;\n\nuniform mat3 emitterMatrix, emitterMatrixInv;\nuniform vec3 emitterScale;\n\nuniform vec3 emitterPos, frameRandom, localVelocityDivMult, velocityDivMult;\nuniform float delta, rate, rateDiv, lifetime, numParticles, rotSpeedDivMult, radialSpeedDivMult, seed;\nuniform float startAngle, startAngle2;\nuniform float initialVelocity;\n\nuniform float graphSampleSize;\nuniform float graphNumSamples;\n\n\nvec3 inPos;\nvec3 inVel;\nfloat inAngle;\nbool inShow;\nfloat inLife;\nfloat visMode;\n\nvec3 outPos;\nvec3 outVel;\nfloat outAngle;\nbool outShow;\nfloat outLife;\n", particleUpdaterNoRespawnPS:" if (outLife >= lifetime) {\n outLife -= max(lifetime, (numParticles - 1.0) * particleRate);\n visMode = -1.0;\n }\n",particleUpdaterOnStopPS:" visMode = outLife < 0.0? -1.0: visMode;\n\n",particleUpdaterRespawnPS:" if (outLife >= lifetime) {\n outLife -= max(lifetime, (numParticles - 1.0) * particleRate);\n visMode = 1.0;\n }\n visMode = outLife < 0.0? 1.0: visMode;\n\n",particleUpdaterSpherePS:"uniform float spawnBoundsSphere;\nuniform float spawnBoundsSphereInnerRatio;\nvec3 calcSpawnPosition(vec3 inBounds, float rndFactor) {\n float rnd4 = fract(rndFactor * 1000.0);\n vec3 norm = normalize(inBounds.xyz - vec3(0.5));\n float r = rnd4 * (1.0 - spawnBoundsSphereInnerRatio) + spawnBoundsSphereInnerRatio;\n#ifndef LOCAL_SPACE\n return emitterPos + norm * r * spawnBoundsSphere;\n#else\n return norm * r * spawnBoundsSphere;\n#endif\n}\n\nvoid addInitialVelocity(inout vec3 localVelocity, vec3 inBounds) {\n localVelocity += normalize(inBounds - vec3(0.5)) * initialVelocity;\n}\n\n", particleUpdaterStartPS:"float saturate(float x) {\n return clamp(x, 0.0, 1.0);\n}\n\nvec3 unpack3NFloats(float src) {\n float r = fract(src);\n float g = fract(src * 256.0);\n float b = fract(src * 65536.0);\n return vec3(r, g, b);\n}\n\nvec3 tex1Dlod_lerp(highp sampler2D tex, vec2 tc, out vec3 w) {\n vec4 a = texture2D(tex, tc);\n vec4 b = texture2D(tex, tc + graphSampleSize);\n float c = fract(tc.x * graphNumSamples);\n\n vec3 unpackedA = unpack3NFloats(a.w);\n vec3 unpackedB = unpack3NFloats(b.w);\n w = mix(unpackedA, unpackedB, c);\n\n return mix(a.xyz, b.xyz, c);\n}\n\n#define HASHSCALE4 vec4(1031, .1030, .0973, .1099)\nvec4 hash41(float p) {\n vec4 p4 = fract(vec4(p) * HASHSCALE4);\n p4 += dot(p4, p4.wzxy+19.19);\n return 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}\n\n\nvoid main(void)\n{\n if (gl_FragCoord.x > numParticles) discard;\n\n readInput(vUv0.x);\n visMode = inShow? 1.0 : -1.0;\n\n vec4 rndFactor = hash41(gl_FragCoord.x + seed);\n\n float particleRate = rate + rateDiv * rndFactor.x;\n\n outLife = inLife + delta;\n float nlife = clamp(outLife / lifetime, 0.0, 1.0);\n\n vec3 localVelocityDiv;\n vec3 velocityDiv;\n vec3 paramDiv;\n vec3 localVelocity = tex1Dlod_lerp(internalTex0, vec2(nlife, 0), localVelocityDiv);\n vec3 velocity = tex1Dlod_lerp(internalTex1, vec2(nlife, 0), velocityDiv);\n vec3 params = tex1Dlod_lerp(internalTex2, vec2(nlife, 0), paramDiv);\n float rotSpeed = params.x;\n float rotSpeedDiv = paramDiv.y;\n\n vec3 radialParams = tex1Dlod_lerp(internalTex3, vec2(nlife, 0), paramDiv);\n float radialSpeed = radialParams.x;\n float radialSpeedDiv = radialParams.y;\n\n bool respawn = inLife <= 0.0 || outLife >= lifetime;\n inPos = respawn ? calcSpawnPosition(rndFactor.xyz, rndFactor.x) : inPos;\n inAngle = respawn ? mix(startAngle, startAngle2, rndFactor.x) : inAngle;\n\n#ifndef LOCAL_SPACE\n vec3 radialVel = inPos - emitterPos;\n#else\n vec3 radialVel = inPos;\n#endif\n radialVel = (dot(radialVel, radialVel) > 1.0E-8) ? radialSpeed * normalize(radialVel) : vec3(0.0);\n radialVel += (radialSpeedDiv * vec3(2.0) - vec3(1.0)) * radialSpeedDivMult * rndFactor.xyz;\n\n localVelocity += (localVelocityDiv * vec3(2.0) - vec3(1.0)) * localVelocityDivMult * rndFactor.xyz;\n velocity += (velocityDiv * vec3(2.0) - vec3(1.0)) * velocityDivMult * rndFactor.xyz;\n rotSpeed += (rotSpeedDiv * 2.0 - 1.0) * rotSpeedDivMult * rndFactor.y;\n\n addInitialVelocity(localVelocity, rndFactor.xyz);\n\n#ifndef LOCAL_SPACE\n outVel = emitterMatrix * localVelocity + (radialVel + velocity) * emitterScale;\n#else\n outVel = (localVelocity + radialVel) / emitterScale + emitterMatrixInv * velocity;\n#endif\n\n outPos = inPos + outVel * delta;\n outAngle = inAngle + rotSpeed * delta;\n", particle_billboardVS:"\n quadXY = rotate(quadXY, inAngle, rotMatrix);\n vec3 localPos = billboard(particlePos, quadXY);\n\n",particle_blendAddPS:"\n rgb *= saturate(gammaCorrectInput(a));\n if ((rgb.r + rgb.g + rgb.b) < 0.000001) discard;\n\n",particle_blendMultiplyPS:"\n rgb = mix(vec3(1.0), rgb, vec3(a));\n if (rgb.r + rgb.g + rgb.b > 2.99) discard;\n\n",particle_blendNormalPS:"\n if (a < 0.01) discard;\n",particle_cpuVS:"attribute vec4 particle_vertexData; // XYZ = world pos, W = life\nattribute vec4 particle_vertexData2; // X = angle, Y = scale, Z = alpha, W = velocity.x\nattribute vec4 particle_vertexData3; // XYZ = particle local pos, W = velocity.y\nattribute float particle_vertexData4; // particle id\n#ifndef USE_MESH\n#define VDATA5TYPE vec2\n#else\n#define VDATA5TYPE vec4\n#endif\nattribute VDATA5TYPE particle_vertexData5; // VDATA4TYPE depends on useMesh property. Start with X = velocity.z, Y = particle ID and for mesh particles proceeds with Z = mesh UV.x, W = mesh UV.y\n\nuniform mat4 matrix_viewProjection;\nuniform mat4 matrix_model;\n\n#ifndef VIEWMATRIX\n#define VIEWMATRIX\nuniform mat4 matrix_view;\n#endif\n\nuniform mat3 matrix_normal;\nuniform mat4 matrix_viewInverse;\n\nuniform float numParticles;\nuniform float lifetime;\nuniform float stretch;\nuniform float seed;\n//uniform float graphSampleSize;\n//uniform float graphNumSamples;\nuniform vec3 wrapBounds, emitterScale, faceTangent, faceBinorm;\nuniform sampler2D texLifeAndSourcePosOUT;\nuniform highp sampler2D internalTex0;\nuniform highp sampler2D internalTex1;\nuniform highp sampler2D internalTex2;\nuniform vec3 emitterPos;\n\nvarying vec4 texCoordsAlphaLife;\n\n\nvec2 rotate(vec2 quadXY, float pRotation, out mat2 rotMatrix)\n{\n float c = cos(pRotation);\n float s = sin(pRotation);\n //vec4 rotationMatrix = vec4(c, -s, s, c);\n\n mat2 m = mat2(c, -s, s, c);\n rotMatrix = m;\n\n return m * quadXY;\n}\n\nvec3 billboard(vec3 InstanceCoords, vec2 quadXY)\n{\n vec3 pos = -matrix_viewInverse[0].xyz * quadXY.x + -matrix_viewInverse[1].xyz * quadXY.y;\n return pos;\n}\n\nvec3 customFace(vec3 InstanceCoords, vec2 quadXY)\n{\n vec3 pos = faceTangent * quadXY.x + faceBinorm * quadXY.y;\n return pos;\n}\n\nvoid main(void)\n{\n vec3 particlePos = particle_vertexData.xyz;\n vec3 inPos = particlePos;\n vec3 vertPos = particle_vertexData3.xyz;\n vec3 inVel = vec3(particle_vertexData2.w, particle_vertexData3.w, particle_vertexData5.x);\n\n float id = floor(particle_vertexData4);\n float rndFactor = fract(sin(id + 1.0 + seed));\n vec3 rndFactor3 = vec3(rndFactor, fract(rndFactor*10.0), fract(rndFactor*100.0));\n\n#ifdef LOCAL_SPACE\n inVel = mat3(matrix_model) * inVel;\n#endif\n vec2 velocityV = normalize((mat3(matrix_view) * inVel).xy); // should be removed by compiler if align/stretch is not used\n\n vec2 quadXY = vertPos.xy;\n \n#ifndef USE_MESH\n texCoordsAlphaLife = vec4(quadXY * -0.5 + 0.5, particle_vertexData2.z, particle_vertexData.w);\n#else\n texCoordsAlphaLife = vec4(particle_vertexData5.zw, particle_vertexData2.z, particle_vertexData.w);\n#endif\n mat2 rotMatrix;\n\n float inAngle = particle_vertexData2.x;\n vec3 particlePosMoved = vec3(0.0);\n vec3 meshLocalPos = particle_vertexData3.xyz;\n\n", particle_cpu_endVS:"\n localPos *= particle_vertexData2.y * emitterScale;\n localPos += particlePos;\n\n gl_Position = matrix_viewProjection * vec4(localPos, 1.0);\n",particle_customFaceVS:"\n quadXY = rotate(quadXY, inAngle, rotMatrix);\n vec3 localPos = customFace(particlePos, quadXY);\n",particle_endPS:" rgb = addFog(rgb);\n rgb = toneMap(rgb);\n rgb = gammaCorrectOutput(rgb);\n gl_FragColor = vec4(rgb, a);\n}\n",particle_endVS:"\n localPos *= scale * emitterScale;\n localPos += particlePos;\n\n #ifdef SCREEN_SPACE\n gl_Position = vec4(localPos.x, localPos.y, 0.0, 1.0);\n #else\n gl_Position = matrix_viewProjection * vec4(localPos.xyz, 1.0);\n #endif\n ", particle_halflambertPS:"\n vec3 negNormal = normal*0.5+0.5;\n vec3 posNormal = -normal*0.5+0.5;\n negNormal *= negNormal;\n posNormal *= posNormal;\n\n\n",particle_initVS:"attribute vec4 particle_vertexData; // XYZ = particle position, W = particle ID + random factor\n#ifdef USE_MESH\nattribute vec2 particle_uv; // mesh UV\n#endif\n\nuniform mat4 matrix_viewProjection;\nuniform mat4 matrix_model;\nuniform mat3 matrix_normal;\nuniform mat4 matrix_viewInverse;\n\n#ifndef VIEWMATRIX\n#define VIEWMATRIX\nuniform mat4 matrix_view;\n#endif\n\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\n#ifndef CAMERAPLANES\n#define CAMERAPLANES\nuniform vec4 camera_params;\n#endif\n\nvarying vec4 texCoordsAlphaLife;\n\nvec3 inPos;\nvec3 inVel;\nfloat inAngle;\nbool inShow;\nfloat inLife;\n\n", particle_lambertPS:"\n vec3 negNormal = max(normal, vec3(0.0));\n vec3 posNormal = max(-normal, vec3(0.0));\n\n\n",particle_lightingPS:"\n vec3 light = negNormal.x*lightCube[0] + posNormal.x*lightCube[1] +\n negNormal.y*lightCube[2] + posNormal.y*lightCube[3] +\n negNormal.z*lightCube[4] + posNormal.z*lightCube[5];\n\n\n rgb *= light;\n\n\n",particle_localShiftVS:" particlePos = (matrix_model * vec4(particlePos, 1.0)).xyz;\n\n",particle_meshVS:"\n vec3 localPos = meshLocalPos;\n localPos.xy = rotate(localPos.xy, inAngle, rotMatrix);\n localPos.yz = rotate(localPos.yz, inAngle, rotMatrix);\n\n billboard(particlePos, quadXY);\n\n\n", particle_normalVS:"\n Normal = normalize(localPos + matrix_viewInverse[2].xyz);\n",particle_normalMapPS:"\n vec3 normalMap = normalize( texture2D(normalMap, texCoordsAlphaLife.xy).xyz * 2.0 - 1.0 );\n vec3 normal = ParticleMat * normalMap;\n\n\n\n\n",particle_pointAlongVS:" inAngle = atan(velocityV.x, velocityV.y); // not the fastest way, but easier to plug in; TODO: create rot matrix right from vectors\n\n",particle_softPS:"\n float depth = getLinearScreenDepth();\n float particleDepth = vDepth;\n float depthDiff = saturate(abs(particleDepth - depth) * softening);\n a *= depthDiff;\n", particle_softVS:"\n vDepth = getLinearDepth(localPos);\n",particle_stretchVS:" vec3 moveDir = inVel * stretch;\n vec3 posPrev = particlePos - moveDir;\n posPrev += particlePosMoved;\n\n vec2 centerToVertexV = normalize((mat3(matrix_view) * localPos).xy);\n\n float interpolation = dot(-velocityV, centerToVertexV) * 0.5 + 0.5;\n\n particlePos = mix(particlePos, posPrev, interpolation);\n\n",particle_TBNVS:"\n mat3 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 ParticleMat = mat3(-matrix_viewInverse[0].xyz, -matrix_viewInverse[1].xyz, matrix_viewInverse[2].xyz) * rot3;\n\n", particle_wrapVS:"\n vec3 origParticlePos = particlePos;\n particlePos -= matrix_model[3].xyz;\n particlePos = mod(particlePos, wrapBounds) - wrapBounds * 0.5;\n particlePos += matrix_model[3].xyz;\n particlePosMoved = particlePos - origParticlePos;\n\n\n",precisionTestPS:"void main(void) {\n gl_FragColor = vec4(2147483648.0);\n}\n\n",precisionTest2PS:"uniform sampler2D source;\n\nvec4 packFloat(float depth) {\n const vec4 bit_shift = vec4(256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0);\n const vec4 bit_mask = vec4(0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0);\n\n vec4 res = mod(depth * bit_shift * vec4(255), vec4(256) ) / vec4(255);\n res -= res.xxyz * bit_mask;\n return res;\n}\n\nvoid main(void) {\n float c = texture2D(source, vec2(0.0)).r;\n float diff = abs(c - 2147483648.0) / 2147483648.0;\n gl_FragColor = packFloat(diff);\n}\n\n", prefilterCubemapPS:"varying vec2 vUv0;\n\nuniform samplerCube source;\nuniform vec4 params;\n\nfloat saturate(float x) {\n return clamp(x, 0.0, 1.0);\n}\n\nfloat rnd(vec2 uv) {\n return fract(sin(dot(uv, vec2(12.9898, 78.233) * 2.0)) * 43758.5453);\n}\n\nconst float PI = 3.14159265358979;\nvec3 hemisphereSample_cos(vec2 uv, mat3 vecSpace, vec3 cubeDir, float gloss) { // cos + lerped cone size (better than just lerped)\n float phi = uv.y * 2.0 * PI;\n float cosTheta = sqrt(1.0 - uv.x);\n float sinTheta = sqrt(1.0 - cosTheta * cosTheta);\n vec3 sampleDir = vec3(cos(phi) * sinTheta, sin(phi) * sinTheta, cosTheta);\n return normalize(mix(vecSpace * sampleDir, cubeDir, params.y));\n}\n\nvec3 hemisphereSample_phong(vec2 uv, mat3 vecSpace, vec3 cubeDir, float specPow) {\n float phi = uv.y * 2.0 * PI;\n float cosTheta = pow(1.0 - uv.x, 1.0 / (specPow + 1.0));\n float sinTheta = sqrt(1.0 - cosTheta * cosTheta);\n vec3 sampleDir = vec3(cos(phi) * sinTheta, sin(phi) * sinTheta, cosTheta);\n return vecSpace * sampleDir;\n}\n\nmat3 matrixFromVector(vec3 n) { // frisvad\n float a = 1.0 / (1.0 + n.z);\n float b = -n.x * n.y * a;\n vec3 b1 = vec3(1.0 - n.x * n.x * a, b, -n.x);\n vec3 b2 = vec3(b, 1.0 - n.y * n.y * a, -n.y);\n return mat3(b1, b2, n);\n}\n\nvec4 encodeRGBM(vec3 color) { // modified RGBM\n vec4 encoded;\n encoded.rgb = pow(color.rgb, vec3(0.5));\n encoded.rgb *= 1.0 / 8.0;\n\n encoded.a = saturate( max( max( encoded.r, encoded.g ), max( encoded.b, 1.0 / 255.0 ) ) );\n encoded.a = ceil(encoded.a * 255.0) / 255.0;\n\n encoded.rgb /= encoded.a;\n return encoded;\n}\n\nvoid main(void) {\n\n vec2 st = vUv0 * 2.0 - 1.0;\n\n if (params.w==1.0 || params.w==3.0) {\n st = 2.0 * floor(gl_FragCoord.xy) / (params.z - 1.0) - 1.0;\n }\n\n float face = params.x;\n\n vec3 vec;\n if (face==0.0) {\n vec = vec3(1, -st.y, -st.x);\n } else if (face==1.0) {\n vec = vec3(-1, -st.y, st.x);\n } else if (face==2.0) {\n vec = vec3(st.x, 1, st.y);\n } else if (face==3.0) {\n vec = vec3(st.x, -1, -st.y);\n } else if (face==4.0) {\n vec = vec3(st.x, -st.y, 1);\n } else {\n vec = vec3(-st.x, -st.y, -1);\n }\n\n mat3 vecSpace = matrixFromVector(normalize(vec));\n\n vec3 color = vec3(0.0);\n const int samples = $NUMSAMPLES;\n vec3 vect;\n for(int i=0; i= 0.0 ? dTBN[1] : dTBN[0];\n vec3 anisotropicTangent = cross(anisotropicDirection, dViewDirW);\n vec3 anisotropicNormal = cross(anisotropicTangent, anisotropicDirection);\n vec3 bentNormal = normalize(mix(normalize(dNormalW), normalize(anisotropicNormal), anisotropy));\n dReflDirW = reflect(-dViewDirW, bentNormal);\n #ifdef CLEARCOAT\n ccReflDirW = normalize(-reflect(dViewDirW, ccNormalW));\n #endif \n}\n\n", reflectionCCPS:"#ifdef CLEARCOAT\nuniform float material_clearCoatReflectivity;\nvoid addReflectionCC() { \n ccReflection += vec4(calcReflection(ccReflDirW, ccGlossiness), material_clearCoatReflectivity); \n}\n#endif\n",reflectionCubePS:"uniform samplerCube texture_cubeMap;\nvec3 calcReflection(vec3 tReflDirW, float tGlossiness) {\n vec3 lookupVec = fixSeams(cubeMapProject(tReflDirW));\n lookupVec.x *= -1.0;\n return $textureCubeSAMPLE(texture_cubeMap, lookupVec).rgb;\n}\n\nuniform float material_reflectivity;\nvoid addReflection() { \n dReflection += vec4(calcReflection(dReflDirW, dGlossiness), material_reflectivity);\n}\n", reflectionDpAtlasPS:"uniform sampler2D texture_sphereMap;\n\nvec2 getDpAtlasUv(vec2 uv, float mip) {\n\n vec4 rect;\n float sx = saturate(mip - 2.0);\n rect.x = sx * 0.5;\n\n float t = mip - rect.x * 6.0;\n float i = 1.0 - rect.x;\n rect.y = min(t * 0.5, 0.75) * i + rect.x;\n\n float st = saturate(t);\n rect.z = (1.0 - st * 0.5) * i;\n rect.w = rect.z * 0.5;\n\n float rcRectZ = 1.0 / rect.z;\n float scaleFactor = 0.00390625 * rcRectZ; // 0.0078125 = (256 + 2) / 256 - 1, 0.00390625 same for 512\n vec2 scale = vec2(scaleFactor, scaleFactor * 2.0);\n uv = uv * (vec2(1.0) - scale) + scale * 0.5;\n\n uv = uv * rect.zw + rect.xy;\n\n return uv;\n}\n\nvec3 calcReflection(vec3 tReflDirW, float tGlossiness) {\n vec3 reflDir = normalize(cubeMapProject(tReflDirW));\n\n // Convert vector to DP coords\n bool up = reflDir.y > 0.0;\n float scale = 0.90909090909090909090909090909091;// 1.0 / 1.1;\n vec3 reflDirWarp = reflDir.xzx * vec3(-0.25, 0.5, 0.25);\n float reflDirVer = abs(reflDir.y) + 1.0;\n reflDirWarp /= reflDirVer;\n reflDirWarp *= scale;\n reflDirWarp = vec3(0.75, 0.5, 0.25) - reflDirWarp;\n vec2 tc = up? reflDirWarp.xy : reflDirWarp.zy;\n\n float bias = saturate(1.0 - tGlossiness) * 5.0; // multiply by max mip level\n\n float mip = floor(bias);\n vec3 tex1 = $texture2DSAMPLE(texture_sphereMap, getDpAtlasUv(tc, mip)).rgb;\n\n mip = min(mip + 1.0, 5.0);\n vec3 tex2 = $texture2DSAMPLE(texture_sphereMap, getDpAtlasUv(tc, mip)).rgb;\n\n tex1 = mix(tex1, tex2, fract(bias));\n tex1 = processEnvironment(tex1);\n\n return tex1;\n}\n\nuniform float material_reflectivity;\nvoid addReflection() { \n dReflection += 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\nvec3 calcReflection(vec3 tReflDirW, float tGlossiness) {\n // Unfortunately, WebGL doesn't allow us using textureCubeLod. Therefore bunch of nasty workarounds is required.\n // We fix mip0 to 128x128, so code is rather static.\n // Mips smaller than 4x4 aren't great even for diffuse. Don't forget that we don't have bilinear filtering between different faces.\n\n float bias = saturate(1.0 - tGlossiness) * 5.0; // multiply by max mip level\n int index1 = int(bias);\n int index2 = int(min(bias + 1.0, 7.0));\n\n vec3 fixedReflDir = fixSeams(cubeMapProject(tReflDirW), bias);\n fixedReflDir.x *= -1.0;\n\n vec4 cubes[6];\n cubes[0] = textureCube(texture_prefilteredCubeMap128, fixedReflDir);\n cubes[1] = textureCube(texture_prefilteredCubeMap64, fixedReflDir);\n cubes[2] = textureCube(texture_prefilteredCubeMap32, fixedReflDir);\n cubes[3] = textureCube(texture_prefilteredCubeMap16, fixedReflDir);\n cubes[4] = textureCube(texture_prefilteredCubeMap8, fixedReflDir);\n cubes[5] = textureCube(texture_prefilteredCubeMap4, fixedReflDir);\n\n // Also we don't have dynamic indexing in PS, so...\n vec4 cube[2];\n for(int i = 0; i < 6; i++) {\n if (i == index1) {\n cube[0] = cubes[i];\n }\n if (i == index2) {\n cube[1] = cubes[i];\n }\n }\n\n // another variant\n /*if (index1==0){ cube[0]=cubes[0];\n }else if (index1==1){ cube[0]=cubes[1];\n }else if (index1==2){ cube[0]=cubes[2];\n }else if (index1==3){ cube[0]=cubes[3];\n }else if (index1==4){ cube[0]=cubes[4];\n }else if (index1==5){ cube[0]=cubes[5];}\n\n if (index2==0){ cube[1]=cubes[0];\n }else if (index2==1){ cube[1]=cubes[1];\n }else if (index2==2){ cube[1]=cubes[2];\n }else if (index2==3){ cube[1]=cubes[3];\n }else if (index2==4){ cube[1]=cubes[4];\n }else if (index2==5){ cube[1]=cubes[5];}*/\n\n vec4 cubeFinal = mix(cube[0], cube[1], fract(bias));\n vec3 refl = processEnvironment($DECODE(cubeFinal).rgb);\n\n return refl;\n}\n\nuniform float material_reflectivity;\nvoid addReflection() { \n dReflection += vec4(calcReflection(dReflDirW, dGlossiness), material_reflectivity);\n}\n", reflectionPrefilteredCubeLodPS:"\n#ifndef PMREM4\n#define PMREM4\n#extension GL_EXT_shader_texture_lod : enable\nuniform samplerCube texture_prefilteredCubeMap128;\n#endif\nvec3 calcReflection(vec3 tReflDirW, float tGlossiness) {\n float bias = saturate(1.0 - tGlossiness) * 5.0; // multiply by max mip level\n vec3 fixedReflDir = fixSeams(cubeMapProject(tReflDirW), bias);\n fixedReflDir.x *= -1.0;\n\n vec3 refl = processEnvironment($DECODE( textureCubeLodEXT(texture_prefilteredCubeMap128, fixedReflDir, bias) ).rgb);\n\n return refl;\n}\n\nuniform float material_reflectivity;\nvoid addReflection() { \n dReflection += vec4(calcReflection(dReflDirW, dGlossiness), material_reflectivity);\n}\n", reflectionSpherePS:"#ifndef VIEWMATRIX\n#define VIEWMATRIX\nuniform mat4 matrix_view;\n#endif\nuniform sampler2D texture_sphereMap;\nvec3 calcReflection(vec3 tReflDirW, float tGlossiness) {\n vec3 reflDirV = (mat3(matrix_view) * tReflDirW).xyz;\n\n float m = 2.0 * sqrt( dot(reflDirV.xy, reflDirV.xy) + (reflDirV.z+1.0)*(reflDirV.z+1.0) );\n vec2 sphereMapUv = reflDirV.xy / m + 0.5;\n\n return $texture2DSAMPLE(texture_sphereMap, sphereMapUv).rgb;\n}\n\nuniform float material_reflectivity;\nvoid addReflection() { \n dReflection += vec4(calcReflection(dReflDirW, dGlossiness), material_reflectivity);\n}\n", reflectionSphereLowPS:"uniform sampler2D texture_sphereMap;\n\nvec3 calcReflection(vec3 tReflDirW, float tGlossiness) {\n vec3 reflDirV = vNormalV;\n\n vec2 sphereMapUv = reflDirV.xy * 0.5 + 0.5;\n return $texture2DSAMPLE(texture_sphereMap, sphereMapUv).rgb;\n}\n\nuniform float material_reflectivity;\nvoid addReflection() { \n dReflection += vec4(calcReflection(dReflDirW, dGlossiness), material_reflectivity);\n}\n",refractionPS:"uniform float material_refraction, material_refractionIndex;\n\nvec3 refract2(vec3 viewVec, vec3 Normal, float IOR) {\n float vn = dot(viewVec, Normal);\n float k = 1.0 - IOR * IOR * (1.0 - vn * vn);\n vec3 refrVec = IOR * viewVec - (IOR * vn + sqrt(k)) * Normal;\n return refrVec;\n}\n\nvoid addRefraction() {\n\n // use same reflection code with refraction vector\n vec3 tmp = dReflDirW;\n vec4 tmp2 = dReflection;\n dReflection = vec4(0.0);\n dReflDirW = refract2(-dViewDirW, dNormalW, material_refractionIndex);\n\n addReflection();\n\n dDiffuseLight = mix(dDiffuseLight, dReflection.rgb * dAlbedo, material_refraction);\n dReflDirW = tmp;\n dReflection = tmp2;\n}\n\n", reprojectPS:"// This shader requires the following #DEFINEs:\n//\n// DECODE_FUNC - must be one of decodeRGBM, decodeRGBE, decodeGamma or decodeLinear\n// ENCODE_FUNC - must be one of encodeRGBM, encodeRGBE, encideGamma or encodeLinear\n// SOURCE_FUNC - must be one of sampleCubemap, sampleEquirect\n// TARGET_FUNC - must be one of getDirectionCubemap, getDirectionEquirect\n//\n// When filtering:\n// NUM_SAMPLES - number of samples\n\nvarying vec2 vUv0;\n\n// source\nuniform sampler2D sourceTex;\nuniform samplerCube sourceCube;\n\n// params:\n// x - target cubemap face 0..6\n// y - specular power\n// z - 0 for reproject, 1 for prefilter\nuniform vec4 params;\n\nfloat PI = 3.141592653589793;\n\nfloat saturate(float x) {\n return clamp(x, 0.0, 1.0);\n}\n\n//-- supported codings\n\nvec3 decodeLinear(vec4 source) {\n return source.rgb;\n}\n\nvec4 encodeLinear(vec3 source) {\n return vec4(source, 1.0);\n}\n\nvec3 decodeGamma(vec4 source) {\n return pow(source.xyz, vec3(2.2));\n}\n\nvec4 encodeGamma(vec3 source) {\n return vec4(pow(source + 0.0000001, vec3(1.0 / 2.2)), 1.0);\n}\n\nvec3 decodeRGBM(vec4 rgbm) {\n vec3 color = (8.0 * rgbm.a) * rgbm.rgb;\n return color * color;\n}\n\nvec4 encodeRGBM(vec3 source) { // modified RGBM\n vec4 result;\n result.rgb = pow(source.rgb, vec3(0.5));\n result.rgb *= 1.0 / 8.0;\n\n result.a = saturate( max( max( result.r, result.g ), max( result.b, 1.0 / 255.0 ) ) );\n result.a = ceil(result.a * 255.0) / 255.0;\n\n result.rgb /= result.a;\n return result;\n}\n\nvec3 decodeRGBE(vec4 source) {\n if (source.a == 0.0) {\n return vec3(0.0, 0.0, 0.0);\n } else {\n return source.xyz * pow(2.0, source.w * 255.0 - 128.0);\n }\n}\n\nvec4 encodeRGBE(vec3 source) {\n float maxVal = max(source.x, max(source.y, source.z));\n if (maxVal < 1e-32) {\n return vec4(0, 0, 0, 0);\n } else {\n float e = ceil(log2(maxVal));\n return vec4(source / pow(2.0, e), (e + 128.0) / 255.0);\n }\n}\n\n//-- supported projections\n\nvec2 toSpherical(vec3 dir) {\n return vec2(atan(dir.z, dir.x) * -1.0, asin(dir.y));\n}\n\nvec3 fromSpherical(vec2 uv) {\n return vec3(cos(uv.y) * cos(-uv.x),\n sin(uv.y),\n cos(uv.y) * sin(-uv.x));\n}\n\nvec4 sampleEquirect(vec2 sph) {\n return texture2D(sourceTex, sph / vec2(PI * 2.0, PI) + 0.5);\n}\n\nvec4 sampleEquirect(vec3 dir) {\n return sampleEquirect(toSpherical(dir));\n}\n\nvec4 sampleCubemap(vec3 dir) {\n return textureCube(sourceCube, dir);\n}\n\nvec4 sampleCubemap(vec2 sph) {\n return sampleCubemap(fromSpherical(sph));\n}\n\nvec3 getDirectionEquirect() {\n return fromSpherical((vUv0 * 2.0 - 1.0) * vec2(PI, PI * 0.5));\n}\n\nvec3 getDirectionCubemap() {\n vec2 st = vUv0 * 2.0 - 1.0;\n float face = params.x;\n\n vec3 vec;\n if (face==0.0) {\n vec = vec3(1, -st.y, -st.x);\n } else if (face==1.0) {\n vec = vec3(-1, -st.y, st.x);\n } else if (face==2.0) {\n vec = vec3(st.x, 1, st.y);\n } else if (face==3.0) {\n vec = vec3(st.x, -1, -st.y);\n } else if (face==4.0) {\n vec = vec3(st.x, -st.y, 1);\n } else {\n vec = vec3(-st.x, -st.y, -1);\n }\n\n return normalize(vec);\n}\n\nmat3 matrixFromVector(vec3 n) { // frisvad\n float a = 1.0 / (1.0 + n.z);\n float b = -n.x * n.y * a;\n vec3 b1 = vec3(1.0 - n.x * n.x * a, b, -n.x);\n vec3 b2 = vec3(b, 1.0 - n.y * n.y * a, -n.y);\n return mat3(b1, b2, n);\n}\n\nfloat rnd(int i) {\n float sini = sin(float(i));\n float cosi = cos(float(i));\n return fract(sin(dot(vec2(sini, cosi), vec2(12.9898, 78.233) * 2.0)) * 43758.5453);\n}\n\nvec3 hemisphereSamplePhong(vec2 uv, float specPow) {\n float phi = uv.y * 2.0 * PI;\n float cosTheta = pow(1.0 - uv.x, 1.0 / (specPow + 1.0));\n float sinTheta = sqrt(1.0 - cosTheta * cosTheta);\n return vec3(cos(phi) * sinTheta, sin(phi) * sinTheta, cosTheta);\n}\n\nvec4 reproject() {\n if (NUM_SAMPLES <= 1) {\n // single sample\n return ENCODE_FUNC(DECODE_FUNC(SOURCE_FUNC(TARGET_FUNC())));\n } else {\n // multi sample\n vec2 sph = toSpherical(TARGET_FUNC());\n vec2 sphu = dFdx(sph);\n vec2 sphv = dFdy(sph);\n\n const float num = sqrt(float(NUM_SAMPLES));\n vec3 result = vec3(0.0);\n for (float u=0.0; u tcAbs.y) && (tcAbs.x > tcAbs.z)) {\n dirX = vec4(0,0,1, tc.z);\n dirY = vec4(0,1,0, tc.y);\n majorAxisLength = tc.x;\n } else if ((tcAbs.y > tcAbs.x) && (tcAbs.y > tcAbs.z)) {\n dirX = vec4(1,0,0, tc.x);\n dirY = vec4(0,0,1, tc.z);\n majorAxisLength = tc.y;\n }\n\n float shadowParamsInFaceSpace = ((1.0/shadowParams.x) * 2.0) * abs(majorAxisLength);\n\n vec3 xoffset = (dirX.xyz * shadowParamsInFaceSpace);\n vec3 yoffset = (dirY.xyz * shadowParamsInFaceSpace);\n vec3 dx0 = -xoffset;\n vec3 dy0 = -yoffset;\n vec3 dx1 = xoffset;\n vec3 dy1 = yoffset;\n\n mat3 shadowKernel;\n mat3 depthKernel;\n\n depthKernel[0][0] = unpackFloat(textureCube(shadowMap, tc + dx0 + dy0));\n depthKernel[0][1] = unpackFloat(textureCube(shadowMap, tc + dx0));\n depthKernel[0][2] = unpackFloat(textureCube(shadowMap, tc + dx0 + dy1));\n depthKernel[1][0] = unpackFloat(textureCube(shadowMap, tc + dy0));\n depthKernel[1][1] = unpackFloat(textureCube(shadowMap, tc));\n depthKernel[1][2] = unpackFloat(textureCube(shadowMap, tc + dy1));\n depthKernel[2][0] = unpackFloat(textureCube(shadowMap, tc + dx1 + dy0));\n depthKernel[2][1] = unpackFloat(textureCube(shadowMap, tc + dx1));\n depthKernel[2][2] = unpackFloat(textureCube(shadowMap, tc + dx1 + dy1));\n\n vec3 shadowZ = vec3(length(dir) * shadowParams.w + shadowParams.z);\n\n shadowKernel[0] = vec3(lessThan2(depthKernel[0], shadowZ));\n shadowKernel[1] = vec3(lessThan2(depthKernel[1], shadowZ));\n shadowKernel[2] = vec3(lessThan2(depthKernel[2], shadowZ));\n\n vec2 uv = (vec2(dirX.w, dirY.w) / abs(majorAxisLength)) * 0.5;\n\n vec2 fractionalCoord = fract( uv * shadowParams.x );\n\n shadowKernel[0] = mix(shadowKernel[0], shadowKernel[1], fractionalCoord.x);\n shadowKernel[1] = mix(shadowKernel[1], shadowKernel[2], fractionalCoord.x);\n\n vec4 shadowValues;\n shadowValues.x = mix(shadowKernel[0][0], shadowKernel[0][1], fractionalCoord.y);\n shadowValues.y = mix(shadowKernel[0][1], shadowKernel[0][2], fractionalCoord.y);\n shadowValues.z = mix(shadowKernel[1][0], shadowKernel[1][1], fractionalCoord.y);\n shadowValues.w = mix(shadowKernel[1][1], shadowKernel[1][2], fractionalCoord.y);\n\n return 1.0 - dot( shadowValues, vec4( 1.0 ) ) * 0.25;\n}\n\nfloat getShadowPointPCF3x3(samplerCube shadowMap, vec4 shadowParams) {\n return _getShadowPoint(shadowMap, shadowParams, dLightDirW);\n}\n\n", shadowStandardGL2PS:"float _getShadowPCF5x5(sampler2DShadow shadowMap, vec3 shadowParams) {\n // http://the-witness.net/news/2013/09/shadow-mapping-summary-part-1/\n\n float z = dShadowCoord.z;\n vec2 uv = dShadowCoord.xy * shadowParams.x; // 1 unit - 1 texel\n float shadowMapSizeInv = 1.0 / shadowParams.x;\n vec2 base_uv = floor(uv + 0.5);\n float s = (uv.x + 0.5 - base_uv.x);\n float t = (uv.y + 0.5 - base_uv.y);\n base_uv -= vec2(0.5);\n base_uv *= shadowMapSizeInv;\n\n\n float uw0 = (4.0 - 3.0 * s);\n float uw1 = 7.0;\n float uw2 = (1.0 + 3.0 * s);\n\n float u0 = (3.0 - 2.0 * s) / uw0 - 2.0;\n float u1 = (3.0 + s) / uw1;\n float u2 = s / uw2 + 2.0;\n\n float vw0 = (4.0 - 3.0 * t);\n float vw1 = 7.0;\n float vw2 = (1.0 + 3.0 * t);\n\n float v0 = (3.0 - 2.0 * t) / vw0 - 2.0;\n float v1 = (3.0 + t) / vw1;\n float v2 = t / vw2 + 2.0;\n\n float sum = 0.0;\n\n u0 = u0 * shadowMapSizeInv + base_uv.x;\n v0 = v0 * shadowMapSizeInv + base_uv.y;\n\n u1 = u1 * shadowMapSizeInv + base_uv.x;\n v1 = v1 * shadowMapSizeInv + base_uv.y;\n\n u2 = u2 * shadowMapSizeInv + base_uv.x;\n v2 = v2 * shadowMapSizeInv + base_uv.y;\n\n sum += uw0 * vw0 * texture(shadowMap, vec3(u0, v0, z));\n sum += uw1 * vw0 * texture(shadowMap, vec3(u1, v0, z));\n sum += uw2 * vw0 * texture(shadowMap, vec3(u2, v0, z));\n\n sum += uw0 * vw1 * texture(shadowMap, vec3(u0, v1, z));\n sum += uw1 * vw1 * texture(shadowMap, vec3(u1, v1, z));\n sum += uw2 * vw1 * texture(shadowMap, vec3(u2, v1, z));\n\n sum += uw0 * vw2 * texture(shadowMap, vec3(u0, v2, z));\n sum += uw1 * vw2 * texture(shadowMap, vec3(u1, v2, z));\n sum += uw2 * vw2 * texture(shadowMap, vec3(u2, v2, z));\n\n sum *= 1.0f / 144.0;\n\n sum = gammaCorrectInput(sum); // gives softer gradient\n sum = saturate(sum);\n\n return sum;\n}\n\nfloat getShadowPCF5x5(sampler2DShadow shadowMap, vec3 shadowParams) {\n return _getShadowPCF5x5(shadowMap, shadowParams);\n}\n\nfloat getShadowSpotPCF5x5(sampler2DShadow shadowMap, vec4 shadowParams) {\n return _getShadowPCF5x5(shadowMap, shadowParams.xyz);\n}\n", shadowStandardGL2VSPS:"float getShadowPCF5x5VS(sampler2DShadow shadowMap, vec3 shadowParams) {\n dShadowCoord = vMainShadowUv.xyz;\n dShadowCoord.z = saturate(dShadowCoord.z) - 0.0001; // prevent going to dark after the far plane\n return _getShadowPCF5x5(shadowMap, shadowParams);\n}\n\n",shadowStandardVSPS:"#ifdef GL2\n#define SHADOW_SAMPLERVS sampler2DShadow\n#else\n#define SHADOW_SAMPLERVS sampler2D\n#endif\n\nfloat getShadowPCF3x3VS(SHADOW_SAMPLERVS shadowMap, vec3 shadowParams) {\n dShadowCoord = vMainShadowUv.xyz;\n dShadowCoord.z = saturate(dShadowCoord.z) - 0.0001;\n\n #ifdef SHADOWBIAS\n dShadowCoord.z += getShadowBias(shadowParams.x, shadowParams.z);\n #endif\n\n return _getShadowPCF3x3(shadowMap, shadowParams);\n}\n\n", shadowVSM8PS:"float calculateVSM8(vec3 moments, float Z, float vsmBias) {\n float VSMBias = vsmBias;//0.01 * 0.25;\n float depthScale = VSMBias * Z;\n float minVariance1 = depthScale * depthScale;\n return chebyshevUpperBound(moments.xy, Z, minVariance1, 0.1);\n}\n\nfloat decodeFloatRG(vec2 rg) {\n return rg.y*(1.0/255.0) + rg.x;\n}\n\nfloat VSM8(sampler2D tex, vec2 texCoords, float resolution, float Z, float vsmBias, float exponent) {\n vec4 c = texture2D(tex, texCoords);\n vec3 moments = vec3(decodeFloatRG(c.xy), decodeFloatRG(c.zw), 0.0);\n return calculateVSM8(moments, Z, vsmBias);\n}\n\nfloat getShadowVSM8(sampler2D shadowMap, vec3 shadowParams, float exponent) {\n return VSM8(shadowMap, dShadowCoord.xy, shadowParams.x, dShadowCoord.z, shadowParams.y, 0.0);\n}\n\nfloat getShadowSpotVSM8(sampler2D shadowMap, vec4 shadowParams, float exponent) {\n return 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 dShadowCoord = vMainShadowUv.xyz;\n dShadowCoord.z += shadowParams.z;\n dShadowCoord.xyz /= vMainShadowUv.w;\n dShadowCoord.z = min(dShadowCoord.z, 1.0);\n\n return $VSM(shadowMap, dShadowCoord.xy, shadowParams.x, dShadowCoord.z, shadowParams.y, exponent);\n}\n\n",shadowVSM_commonPS:"float linstep(float a, float b, float v) {\n return saturate((v - a) / (b - a));\n}\n\nfloat reduceLightBleeding(float pMax, float amount) {\n // Remove the [0, amount] tail and linearly rescale (amount, 1].\n return linstep(amount, 1.0, pMax);\n}\n\nfloat chebyshevUpperBound(vec2 moments, float mean, float minVariance, float lightBleedingReduction) {\n // Compute variance\n float variance = moments.y - (moments.x * moments.x);\n variance = max(variance, minVariance);\n\n // Compute probabilistic upper bound\n float d = mean - moments.x;\n float pMax = variance / (variance + (d * d));\n\n pMax = reduceLightBleeding(pMax, lightBleedingReduction);\n\n // One-tailed Chebyshev\n return (mean <= moments.x ? 1.0 : pMax);\n}\n\nfloat calculateEVSM(vec3 moments, float Z, float vsmBias, float exponent) {\n Z = 2.0 * Z - 1.0;\n float warpedDepth = exp(exponent * Z);\n\n moments.xy += vec2(warpedDepth, warpedDepth*warpedDepth) * (1.0 - moments.z);\n\n float VSMBias = vsmBias;//0.01 * 0.25;\n float depthScale = VSMBias * exponent * warpedDepth;\n float minVariance1 = depthScale * depthScale;\n return chebyshevUpperBound(moments.xy, warpedDepth, minVariance1, 0.1);\n}\n\n", skinBatchConstVS:"attribute float vertex_boneIndices;\nuniform vec4 matrix_pose[BONE_LIMIT * 3];\n\nmat4 getBoneMatrix(const in float i) {\n\n // read 4x3 matrix\n vec4 v1 = matrix_pose[int(3.0 * i)];\n vec4 v2 = matrix_pose[int(3.0 * i + 1.0)];\n vec4 v3 = matrix_pose[int(3.0 * i + 2.0)];\n\n // transpose to 4x4 matrix\n return mat4(\n v1.x, v2.x, v3.x, 0,\n v1.y, v2.y, v3.y, 0,\n v1.z, v2.z, v3.z, 0,\n v1.w, v2.w, v3.w, 1\n );\n}\n\n",skinBatchTexVS:"attribute float vertex_boneIndices;\nuniform highp sampler2D texture_poseMap;\nuniform vec4 texture_poseMapSize;\nmat4 getBoneMatrix(const in float i) {\n float j = i * 3.0;\n float dx = texture_poseMapSize.z;\n float dy = texture_poseMapSize.w;\n\n float x = mod(j, float(texture_poseMapSize.x));\n float y = floor(j * dx);\n y = dy * (y + 0.5);\n\n // read elements of 4x3 matrix\n vec4 v1 = texture2D(texture_poseMap, vec2(dx * (x + 0.5), y));\n vec4 v2 = texture2D(texture_poseMap, vec2(dx * (x + 1.5), y));\n vec4 v3 = texture2D(texture_poseMap, vec2(dx * (x + 2.5), y));\n\n // transpose to 4x4 matrix\n return mat4(\n v1.x, v2.x, v3.x, 0,\n v1.y, v2.y, v3.y, 0,\n v1.z, v2.z, v3.z, 0,\n v1.w, v2.w, v3.w, 1\n );\n}\n\n", skinConstVS:"attribute vec4 vertex_boneWeights;\nattribute vec4 vertex_boneIndices;\n\nuniform vec4 matrix_pose[BONE_LIMIT * 3];\n\nvoid getBoneMatrix(const in float i, out vec4 v1, out vec4 v2, out vec4 v3)\n{\n // read 4x3 matrix\n v1 = matrix_pose[int(3.0 * i)];\n v2 = matrix_pose[int(3.0 * i + 1.0)];\n v3 = matrix_pose[int(3.0 * i + 2.0)];\n}\n\nmat4 getSkinMatrix(const in vec4 indices, const in vec4 weights)\n{\n // get 4 bone matrices\n vec4 a1, a2, a3;\n getBoneMatrix(indices.x, a1, a2, a3);\n\n vec4 b1, b2, b3;\n getBoneMatrix(indices.y, b1, b2, b3);\n\n vec4 c1, c2, c3;\n getBoneMatrix(indices.z, c1, c2, c3);\n\n vec4 d1, d2, d3;\n getBoneMatrix(indices.w, d1, d2, d3);\n\n // multiply them by weights and add up to get final 4x3 matrix\n vec4 v1 = a1 * weights.x + b1 * weights.y + c1 * weights.z + d1 * weights.w;\n vec4 v2 = a2 * weights.x + b2 * weights.y + c2 * weights.z + d2 * weights.w;\n vec4 v3 = a3 * weights.x + b3 * weights.y + c3 * weights.z + d3 * weights.w;\n\n // add up weights\n float one = dot(weights, vec4(1.0));\n\n // transpose to 4x4 matrix\n return mat4(\n v1.x, v2.x, v3.x, 0,\n v1.y, v2.y, v3.y, 0,\n v1.z, v2.z, v3.z, 0,\n v1.w, v2.w, v3.w, one\n );\n}\n\n", skinTexVS:"attribute vec4 vertex_boneWeights;\nattribute vec4 vertex_boneIndices;\n\nuniform highp sampler2D texture_poseMap;\nuniform vec4 texture_poseMapSize;\n\nvoid getBoneMatrix(const in float i, out vec4 v1, out vec4 v2, out vec4 v3)\n{\n float j = i * 3.0;\n float dx = texture_poseMapSize.z;\n float dy = texture_poseMapSize.w;\n \n float x = mod(j, float(texture_poseMapSize.x));\n float y = floor(j * dx);\n y = dy * (y + 0.5);\n\n // read elements of 4x3 matrix\n v1 = texture2D(texture_poseMap, vec2(dx * (x + 0.5), y));\n v2 = texture2D(texture_poseMap, vec2(dx * (x + 1.5), y));\n v3 = texture2D(texture_poseMap, vec2(dx * (x + 2.5), y));\n}\n\nmat4 getSkinMatrix(const in vec4 indices, const in vec4 weights)\n{\n // get 4 bone matrices\n vec4 a1, a2, a3;\n getBoneMatrix(indices.x, a1, a2, a3);\n\n vec4 b1, b2, b3;\n getBoneMatrix(indices.y, b1, b2, b3);\n\n vec4 c1, c2, c3;\n getBoneMatrix(indices.z, c1, c2, c3);\n\n vec4 d1, d2, d3;\n getBoneMatrix(indices.w, d1, d2, d3);\n\n // multiply them by weights and add up to get final 4x3 matrix\n vec4 v1 = a1 * weights.x + b1 * weights.y + c1 * weights.z + d1 * weights.w;\n vec4 v2 = a2 * weights.x + b2 * weights.y + c2 * weights.z + d2 * weights.w;\n vec4 v3 = a3 * weights.x + b3 * weights.y + c3 * weights.z + d3 * weights.w;\n\n // add up weights\n float one = dot(weights, vec4(1.0));\n\n // transpose to 4x4 matrix\n return mat4(\n v1.x, v2.x, v3.x, 0,\n v1.y, v2.y, v3.y, 0,\n v1.z, v2.z, v3.z, 0,\n v1.w, v2.w, v3.w, one\n );\n}\n\n", skyboxPS:"varying vec3 vViewDir;\nuniform samplerCube texture_cubeMap;\n\nvoid main(void) {\n gl_FragColor = textureCube(texture_cubeMap, fixSeams(vViewDir));\n}\n\n",skyboxVS:"attribute vec3 aPosition;\n\n#ifndef VIEWMATRIX\n#define VIEWMATRIX\nuniform mat4 matrix_view;\n#endif\n\nuniform mat4 matrix_projectionSkybox;\n\nvarying vec3 vViewDir;\n\nvoid main(void)\n{\n mat4 view = matrix_view;\n view[3][0] = view[3][1] = view[3][2] = 0.0;\n gl_Position = matrix_projectionSkybox * view * vec4(aPosition, 1.0);\n\n // Force skybox to far Z, regardless of the clip planes on the camera\n // Subtract a tiny fudge factor to ensure floating point errors don't\n // still push pixels beyond far Z. See:\n // http://www.opengl.org/discussion_boards/showthread.php/171867-skybox-problem\n\n gl_Position.z = gl_Position.w - 0.00001;\n vViewDir = aPosition;\n vViewDir.x *= -1.0;\n}\n\n", skyboxHDRPS:"varying vec3 vViewDir;\nuniform samplerCube texture_cubeMap;\n\nvoid main(void) {\n vec3 color = processEnvironment($textureCubeSAMPLE(texture_cubeMap, fixSeamsStatic(vViewDir, $FIXCONST)).rgb);\n color = toneMap(color);\n color = gammaCorrectOutput(color);\n gl_FragColor = vec4(color, 1.0);\n}\n\n",skyboxPrefilteredCubePS:"varying vec3 vViewDir;\nuniform samplerCube texture_cubeMap;\n\nvec3 fixSeamsStretch(vec3 vec, float mipmapIndex, float cubemapSize) {\n float scale = 1.0 - exp2(mipmapIndex) / cubemapSize;\n float M = max(max(abs(vec.x), abs(vec.y)), abs(vec.z));\n if (abs(vec.x) != M) vec.x *= scale;\n if (abs(vec.y) != M) vec.y *= scale;\n if (abs(vec.z) != M) vec.z *= scale;\n return vec;\n}\n\nvoid main(void) {\n vec3 color = textureCubeRGBM(texture_cubeMap, fixSeamsStretch(vViewDir, 0.0, 128.0));\n color = toneMap(color);\n color = gammaCorrectOutput(color);\n gl_FragColor = vec4(color, 1.0);\n}\n\n", specularPS:"#ifdef MAPCOLOR\nuniform vec3 material_specular;\n#endif\n\n#ifdef MAPTEXTURE\nuniform sampler2D texture_specularMap;\n#endif\n\n#ifdef CLEARCOAT\nuniform float material_clearCoatSpecularity;\n#endif\n\nvoid getSpecularity() {\n dSpecularity = vec3(1.0);\n\n #ifdef MAPCOLOR\n dSpecularity *= material_specular;\n #endif\n\n #ifdef MAPTEXTURE\n dSpecularity *= texture2D(texture_specularMap, $UV).$CH;\n #endif\n\n #ifdef MAPVERTEX\n dSpecularity *= saturate(vVertexColor.$VC);\n #endif\n\n #ifdef CLEARCOAT\n ccSpecularity = vec3(1.0);\n ccSpecularity *= material_clearCoatSpecularity;\n #endif\n}\n\n", specularAaNonePS:"float antiAliasGlossiness(float power) {\n return power;\n}\n\n",specularAaToksvigPS:"float antiAliasGlossiness(float power) {\n float rlen = 1.0 / saturate(length(dNormalMap));\n float toksvig = 1.0 / (1.0 + power * (rlen - 1.0));\n return power * mix(1.0, toksvig, material_bumpiness);\n}\n\n",specularAaToksvigFastPS:"float antiAliasGlossiness(float power) {\n float rlen = 1.0 / saturate(length(dNormalMap));\n float toksvig = 1.0 / (1.0 + power * (rlen - 1.0));\n return power * toksvig;\n}\n\n", spotPS:"float getSpotEffect(vec3 lightSpotDirW, float lightInnerConeAngle, float lightOuterConeAngle) {\n float cosAngle = dot(dLightDirNormW, lightSpotDirW);\n return smoothstep(lightOuterConeAngle, lightInnerConeAngle, cosAngle);\n}\n\n",startPS:"\nvoid main(void) {\n dDiffuseLight = vec3(0);\n dSpecularLight = vec3(0);\n dReflection = vec4(0);\n dSpecularity = vec3(0);\n #ifdef CLEARCOAT\n ccSpecularLight = vec3(0);\n ccReflection = vec4(0);\n ccSpecularity = vec3(0);\n #endif\n ", startVS:"\nvoid main(void) {\n gl_Position = getPosition();\n",startNineSlicedPS:" nineSlicedUv = vUv0;\n\n",startNineSlicedTiledPS:"\n vec2 tileMask = step(vMask, vec2(0.99999));\n vec2 clampedUv = mix(innerOffset.xy*0.5, vec2(1.0) - innerOffset.zw*0.5, fract(vTiledUv));\n clampedUv = clampedUv * atlasRect.zw + atlasRect.xy;\n nineSlicedUv = vUv0 * tileMask + clampedUv * (vec2(1.0) - tileMask);\n\n",storeEVSMPS:"float exponent = VSM_EXPONENT;\n\ndepth = 2.0 * depth - 1.0;\ndepth = exp(exponent * depth);\ngl_FragColor = vec4(depth, depth*depth, 1.0, 1.0);\n\n", tangentBinormalVS:"\nvec3 getTangent() {\n return normalize(dNormalMatrix * vertex_tangent.xyz);\n}\n\nvec3 getBinormal() {\n return cross(vNormalW, vTangentW) * vertex_tangent.w;\n}\n\nvec3 getObjectSpaceUp() {\n return normalize(dNormalMatrix * vec3(0, 1, 0));\n}\n\n",TBNPS:"void getTBN() {\n dTBN = mat3(normalize(dTangentW), normalize(dBinormalW), normalize(dVertexNormalW));\n}\n\n",TBNderivativePS:"// http://www.thetenthplanet.de/archives/1180\nvoid getTBN() {\n vec2 uv = $UV;\n\n // get edge vectors of the pixel triangle\n vec3 dp1 = dFdx( vPositionW );\n vec3 dp2 = dFdy( vPositionW );\n vec2 duv1 = dFdx( uv );\n vec2 duv2 = dFdy( uv );\n\n // solve the linear system\n vec3 dp2perp = cross( dp2, dVertexNormalW );\n vec3 dp1perp = cross( dVertexNormalW, dp1 );\n vec3 T = dp2perp * duv1.x + dp1perp * duv2.x;\n vec3 B = dp2perp * duv1.y + dp1perp * duv2.y;\n\n // construct a scale-invariant frame\n float invmax = 1.0 / sqrt( max( dot(T,T), dot(B,B) ) );\n dTBN = mat3( T * invmax, B * invmax, dVertexNormalW );\n}\n\n", TBNfastPS:"void getTBN() {\n dTBN = mat3(dTangentW, dBinormalW, dVertexNormalW);\n}\n\n",TBNObjectSpacePS:"void getTBN() {\n\n vec3 B = cross(dVertexNormalW, vObjectSpaceUpW);\n vec3 T = cross(dVertexNormalW, B);\n\n if (dot(B,B)==0.0) // deal with case when vObjectSpaceUpW dVertexNormalW are parallel\n {\n float major=max(max(dVertexNormalW.x, dVertexNormalW.y),dVertexNormalW.z);\n\n if (dVertexNormalW.x==major)\n {\n B=cross(dVertexNormalW, vec3(0,1,0));\n T=cross(dVertexNormalW, B);\n }\n else if (dVertexNormalW.y==major)\n {\n B=cross(dVertexNormalW, vec3(0,0,1));\n T=cross(dVertexNormalW, B);\n }\n else if (dVertexNormalW.z==major)\n {\n B=cross(dVertexNormalW, vec3(1,0,0));\n T=cross(dVertexNormalW, B);\n }\n }\n\n dTBN = mat3(normalize(T), normalize(B), normalize(dVertexNormalW));\n}\n\n", tonemappingAcesPS:"uniform float exposure;\n\nvec3 toneMap(vec3 color) {\n float tA = 2.51;\n float tB = 0.03;\n float tC = 2.43;\n float tD = 0.59;\n float tE = 0.14;\n vec3 x = color * exposure;\n return (x*(tA*x+tB))/(x*(tC*x+tD)+tE);\n}\n",tonemappingAces2PS:"uniform float exposure;\n\n// ACES approximation by Stephen Hill\n\n// sRGB => XYZ => D65_2_D60 => AP1 => RRT_SAT\nconst mat3 ACESInputMat = mat3(\n 0.59719, 0.35458, 0.04823,\n 0.07600, 0.90834, 0.01566,\n 0.02840, 0.13383, 0.83777\n);\n\n// ODT_SAT => XYZ => D60_2_D65 => sRGB\nconst mat3 ACESOutputMat = mat3(\n 1.60475, -0.53108, -0.07367,\n -0.10208, 1.10813, -0.00605,\n -0.00327, -0.07276, 1.07602\n);\n\nvec3 RRTAndODTFit(vec3 v) {\n vec3 a = v * (v + 0.0245786) - 0.000090537;\n vec3 b = v * (0.983729 * v + 0.4329510) + 0.238081;\n return a / b;\n}\n\nvec3 toneMap(vec3 color) {\n color *= exposure;\n color = color * ACESInputMat;\n\n // Apply RRT and ODT\n color = RRTAndODTFit(color);\n color = color * ACESOutputMat;\n\n // Clamp to [0, 1]\n color = clamp(color, 0.0, 1.0);\n\n return 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;\n\nuniform float exposure;\n\nvec3 uncharted2Tonemap(vec3 x) {\n return ((x*(A*x+C*B)+D*E)/(x*(A*x+B)+D*F))-E/F;\n}\n\nvec3 toneMap(vec3 color) {\n color = uncharted2Tonemap(color * exposure);\n vec3 whiteScale = 1.0 / uncharted2Tonemap(vec3(W,W,W));\n color = color * whiteScale;\n\n return color;\n}\n\n", tonemappingHejlPS:"uniform float exposure;\n\nvec3 toneMap(vec3 color) {\n color *= exposure;\n const float A = 0.22, B = 0.3, C = .1, D = 0.2, E = .01, F = 0.3;\n const float Scl = 1.25;\n\n vec3 h = max( vec3(0.0), color - vec3(0.004) );\n return (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\n",tonemappingLinearPS:"uniform float exposure;\nvec3 toneMap(vec3 color) {\n return color * exposure;\n}\n\n", tonemappingNonePS:"vec3 toneMap(vec3 color) {\n return color;\n}\n\n",transformVS:"#ifdef PIXELSNAP\n uniform vec4 uScreenSize;\n#endif\n\n#ifdef MORPHING\n uniform vec4 morph_weights_a;\n uniform vec4 morph_weights_b;\n#endif\n\n#ifdef MORPHING_TEXTURE_BASED\n uniform vec4 morph_tex_params;\n\n vec2 getTextureMorphCoords() {\n float vertexId = morph_vertex_id;\n vec2 textureSize = morph_tex_params.xy;\n vec2 invTextureSize = morph_tex_params.zw;\n\n // turn vertexId into int grid coordinates\n float morphGridV = floor(vertexId * invTextureSize.x);\n float morphGridU = vertexId - (morphGridV * textureSize.x);\n\n // convert grid coordinates to uv coordinates with half pixel offset\n return (vec2(morphGridU, morphGridV) * invTextureSize) + (0.5 * invTextureSize);\n }\n#endif\n\n#ifdef MORPHING_TEXTURE_BASED_POSITION\n uniform highp sampler2D morphPositionTex;\n#endif\n\nmat4 getModelMatrix() {\n #ifdef DYNAMICBATCH\n return getBoneMatrix(vertex_boneIndices);\n #elif defined(SKIN)\n return matrix_model * getSkinMatrix(vertex_boneIndices, vertex_boneWeights);\n #elif defined(INSTANCING)\n return mat4(instance_line1, instance_line2, instance_line3, instance_line4);\n #else\n return matrix_model;\n #endif\n}\n\nvec4 getPosition() {\n dModelMatrix = getModelMatrix();\n vec3 localPos = vertex_position;\n\n #ifdef NINESLICED\n // outer and inner vertices are at the same position, scale both\n localPos.xz *= outerScale;\n\n // offset inner vertices inside\n // (original vertices must be in [-1;1] range)\n vec2 positiveUnitOffset = clamp(vertex_position.xz, vec2(0.0), vec2(1.0));\n vec2 negativeUnitOffset = clamp(-vertex_position.xz, vec2(0.0), vec2(1.0));\n localPos.xz += (-positiveUnitOffset * innerOffset.xy + negativeUnitOffset * innerOffset.zw) * vertex_texCoord0.xy;\n\n vTiledUv = (localPos.xz - outerScale + innerOffset.xy) * -0.5 + 1.0; // uv = local pos - inner corner\n\n localPos.xz *= -0.5; // move from -1;1 to -0.5;0.5\n localPos = localPos.xzy;\n #endif\n\n #ifdef MORPHING\n #ifdef MORPHING_POS03\n localPos.xyz += morph_weights_a[0] * morph_pos0;\n localPos.xyz += morph_weights_a[1] * morph_pos1;\n localPos.xyz += morph_weights_a[2] * morph_pos2;\n localPos.xyz += morph_weights_a[3] * morph_pos3;\n #endif\n #ifdef MORPHING_POS47\n localPos.xyz += morph_weights_b[0] * morph_pos4;\n localPos.xyz += morph_weights_b[1] * morph_pos5;\n localPos.xyz += morph_weights_b[2] * morph_pos6;\n localPos.xyz += morph_weights_b[3] * morph_pos7;\n #endif\n #endif\n\n #ifdef MORPHING_TEXTURE_BASED_POSITION\n // apply morph offset from texture\n vec2 morphUV = getTextureMorphCoords();\n vec3 morphPos = texture2D(morphPositionTex, morphUV).xyz;\n localPos += morphPos;\n #endif\n\n vec4 posW = dModelMatrix * vec4(localPos, 1.0);\n #ifdef SCREENSPACE\n posW.zw = vec2(0.0, 1.0);\n #endif\n dPositionW = posW.xyz;\n\n vec4 screenPos;\n #ifdef UV1LAYOUT\n screenPos = vec4(vertex_texCoord1.xy * 2.0 - 1.0, 0.5, 1);\n #else\n #ifdef SCREENSPACE\n screenPos = posW;\n #else\n screenPos = matrix_viewProjection * posW;\n #endif\n\n #ifdef PIXELSNAP\n // snap vertex to a pixel boundary\n screenPos.xy = (screenPos.xy * 0.5) + 0.5;\n screenPos.xy *= uScreenSize.xy;\n screenPos.xy = floor(screenPos.xy);\n screenPos.xy *= uScreenSize.zw;\n screenPos.xy = (screenPos.xy * 2.0) - 1.0;\n #endif\n #endif\n\n return screenPos;\n}\n\nvec3 getWorldPosition() {\n return dPositionW;\n}\n", transformDeclVS:"attribute vec3 vertex_position;\nuniform mat4 matrix_model;\nuniform mat4 matrix_viewProjection;\n\nvec3 dPositionW;\nmat4 dModelMatrix;\n\n",uv0VS:"#ifdef NINESLICED\nvec2 getUv0() {\n vec2 uv = vertex_position.xz;\n\n // offset inner vertices inside\n // (original vertices must be in [-1;1] range)\n vec2 positiveUnitOffset = clamp(vertex_position.xz, vec2(0.0), vec2(1.0));\n vec2 negativeUnitOffset = clamp(-vertex_position.xz, vec2(0.0), vec2(1.0));\n uv += (-positiveUnitOffset * innerOffset.xy + negativeUnitOffset * innerOffset.zw) * vertex_texCoord0.xy;\n\n uv = uv * -0.5 + 0.5;\n uv = uv * atlasRect.zw + atlasRect.xy;\n\n vMask = vertex_texCoord0.xy;\n\n return uv;\n}\n#else\nvec2 getUv0() {\n return vertex_texCoord0;\n}\n#endif\n\n", uv1VS:"\nvec2 getUv1() {\n return vertex_texCoord1;\n}\n",viewDirPS:"void getViewDir() {\n dViewDirW = normalize(view_position - vPositionW);\n}\n\n",viewNormalVS:"\n#ifndef VIEWMATRIX\n#define VIEWMATRIX\nuniform mat4 matrix_view;\n#endif\n\nvec3 getViewNormal() {\n return mat3(matrix_view) * vNormalW;\n}\n"},lo={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"};P.collectAttribs=function(a){for(var b={},c=0,d=a.indexOf("attribute");0<=d&&!(0c;c++){var k=a[c];if(!k||k.width!==e||k.height!==g||!this.device._isBrowserInterface(k)){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,g=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=g),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 x= u.array[u.index+d];if(0w&&(v.x=w);v.y>y&&(v.y=y);v.z>z&&(v.z=z);x.xQ?w+=Q:h+=Q;0>D?y+=D:f+=D;0>F?A+=F:m+=F}v.x>w&&(v.x=w);v.y>y&&(v.y=y);v.z>A&&(v.z=A);x.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 Sb(this.device,65535f;f++){var m=k[h+c[f][0]],n=k[h+c[f][1]],q=m>n?n<<16|m:m<<16|n;void 0===l[q]&&(l[q]=0,b.push(m,n))}c=g.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(na.prototype,"instancingCount",{get:function(){return this.instancingData?this.instancingData.count:0},set:function(a){this.instancingData&&(this.instancingData.count=a)}});Object.assign(na.prototype,{syncAabb:function(){},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 Vm(a.numVertices),this.instancingData.offset= 0,this.instancingData.vertexBuffer=a,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=f;k=!1;h=3;l=H.float2Half;this._textureFormat===sb.FORMAT_HALF_FLOAT&&(k=!0,h=4);a=this.morphTextureWidth*this.morphTextureHeight*h;var m=k?new Uint16Array(a):new Float32Array(a);for(a=0;a=this.maxSubmitCount&&(d(e,g),e=0,g=!0))}0a&&(this._activeTargets.sort(function(a,b){return a.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)};Ba.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};Ba.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))}; Ba.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)))};Ba.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,g;for(g in c)if(c.hasOwnProperty(g)&&(b=c[g],a=this._batchGroups[g])){var k=this.prepare(b,a.dynamic,a.maxAabbSize,a._ui||a._sprite);for(b=0;b=e){t=t.concat(u.slice(n));break}if(a!==C.material||v!==C.layer||E!==C.mesh.vertexBuffer.format.batchingHash||B!==C.mesh.primitive[0].indexed||w!==C._shaderDefs|| F+C.mesh.vertexBuffer.getNumVertices()>g)p(C);else if(l.copy(k),l.add(C.aabb),l.halfExtents.x>c||l.halfExtents.y>c||l.halfExtents.z>c)p(C);else if(!z||(f=C.stencilFront)&&z.func==f.func&&z.zpass==f.zpass)if(D!=yh(C))p(C);else if(Wm(y,C.parameters)){var G=C._staticLightList;if(A&&G){if(!Xm(A,G)){p(C);continue}}else if(A||G){p(C);continue}d&&h&&h.intersects(C.aabb)&&C.drawOrder!==Q?p(C):(k.add(C.aabb),F+=C.mesh.vertexBuffer.getNumVertices(),m[q].push(C))}else p(C);else p(C)}q++;u=t}return m};Ba.prototype.create= function(a,b,c){this._init||(this.transformVS="#define BONE_LIMIT "+this.device.getBoneLimit()+"\n#define DYNAMICBATCH\n"+P.transformVS,this.skinTexVS=P.skinBatchTexVS,this.skinConstVS=P.skinBatchConstVS,this.vertexFormats={},this._init=!0);var d,e,g=null,k=null,l=0,h=0,f=null;for(d=0;d=l?Uint16Array:Uint32Array)(h);for(q in g){var w=g[q];w.typeArrayType=Sf[w.dataType];w.elementByteSize=Rf[w.dataType];w.buffer=new w.typeArrayType(l*w.numComponents)}for(d=0;dyh(f.origMeshInstances[0]);f.meshInstance=a;this.update(f);b=new hb;b.meshInstances=[f.meshInstance];b.castShadows=f.origMeshInstances[0].castShadows;f.model=b}return f}; Ba.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>k.indexOf(d)&&k.push(d),!this.passThrough&&0<=c&&g._shaderVersion!==c&&(g.updateShader!==da.prototype.updateShader&& (g.clearVariants(),g.shader=null),g._shaderVersion=c);this.passThrough||(this._dirty=!0)};fa.prototype.removeMeshInstances=function(a,b){var c,d,e=this.opaqueMeshInstances,g=this.transparentMeshInstances,k=this.shadowCasters;for(c=0;ch&&(h=d),r++;else if(0<=h)break}0<=h&&e.splice(h,r);h=-1;r=0;m=g.length;for(d=0;dh&&(h=d),r++;else if(0<=h)break}0<=h&&g.splice(h,r);b||(d=k.indexOf(f),0<=d&&k.splice(d,1))}this._dirty=!0};fa.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)};fa.prototype.addLight=function(a){0<=this._lightComponents.indexOf(a)||(this._lightComponents.push(a), this._lights.push(a.light),this._dirtyLights=!0,this._generateLightHash())};fa.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())};fa.prototype.clearLights=function(){this._lightComponents.length=0;this._lights.length=0;this._dirtyLights=!0};fa.prototype.addShadowCasters=function(a){for(var b,c=this.shadowCasters,d=0;dc.indexOf(b)&&c.push(b);this._dirtyLights=!0};fa.prototype.removeShadowCasters=function(a){for(var b,c=this.shadowCasters,d=0;da||(this.cameras.splice(a, 1),this._generateCameraHash(),this.instances.clearVisibleLists(a))};fa.prototype.clearCameras=function(){this._cameraHash=this.cameras.length=0;this._dirtyCameras=!0};fa.prototype._sortCameras=function(){this._generateCameraHash()};fa.prototype._calculateSortDistances=function(a,b,c,d){var e;for(e=0;e=g.layer))if(g.calculateSortDistance)g.zdist=g.calculateSortDistance(g,c,d);else{var k=g.aabb.center;var f=k.x-c.x;var h=k.y-c.y;k=k.z-c.z;g.zdist=f*d.x+h*d.y+k*d.z}}}; fa.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)Kg=b.getPosition(),Lg=b.forward,this.customCalculateSortValues&&this.customCalculateSortValues(a.list,a.length,Kg,Lg),a.list.length!==a.length&&(a.list.length=a.length),this.customSortCallback&&a.list.sort(this.customSortCallback);else{if(3===e||4===e)Kg=b.getPosition(),Lg=b.forward,this._calculateSortDistances(a.list,a.length, Kg,Lg);a.list.length!==a.length&&(a.list.length=a.length);a.list.sort(oo[e])}};for(var ol=(new C).mul2((new C).setTranslate(.5,.5,.5),(new C).setScale(.5,.5,.5)),po={r:1,g:2,b:3,a:4},pl=[(new U).setFromEulerAngles(0,90,180),(new U).setFromEulerAngles(0,-90,180),(new U).setFromEulerAngles(90,0,0),(new U).setFromEulerAngles(-90,0,0),(new U).setFromEulerAngles(0,180,180),(new U).setFromEulerAngles(0,0,180)],Qj=[{},{},{},{},{}],Kd=new Float32Array(2),tf={x:1,y:1,z:0,w:0},Ld=new C,Mg=new C,ql=new C,Lb= new C,mb=new C,rl=new Db,sl=new C,Bb,Bc=new C,Cc=new C,ve=new C,we=new C,xe=new p,ye=new p,uf,vf,tl=new C,ul=new C,vl=new C,wl=new C,Ng=new p,xl=new p,yl=new p,zl=new p,mc={center:null,radius:0},Al,Og=new ia,wf=[0,0,0,0],ze,db,ij,Pg,Sj={},Ae,Be,Qg=null,ma=[],Bl=0;8>Bl;Bl++)ma.push(new p);var sa=[new p,new p,new p,new p,new p,new p,new p,new p];Object.assign(Wf.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}Ae=a._key[0];Be=b._key[0];return Ae===Be&&a.mesh&&b.mesh?b.mesh.id-a.mesh.id:Be-Ae},depthSortCompare:function(a,b){Ae=a._key[1];Be=b._key[1];return Ae===Be&&a.mesh&&b.mesh?b.mesh.id-a.mesh.id:Be-Ae},lightCompare:function(a,b){return a.key-b.key},_isVisible:function(a, b){if(!b.visible)return!1;if(b.isVisibleFunc)return b.isVisibleFunc(a);Al=b.aabb.center;b._aabb._radiusVer!==b._aabbVer&&(b._aabb._radius=b._aabb.halfExtents.length(),b._aabb._radiusVer=b._aabbVer);mc.radius=b._aabb._radius;mc.center=Al;return a.frustum.containsSphere(mc)},getShadowCamera:function(a,b){var c=b._shadowCamera;if(null===c){c=b._shadowType;var d=2;var e=4===c||0===c&&a.webgl2;1===b._type&&(e=!1);e||(d|=1);e=new Pa;1<=c&&3>=c?(e.clearColor[0]=0,e.clearColor[1]=0,e.clearColor[2]=0,e.clearColor[3]= 0):(e.clearColor[0]=1,e.clearColor[1]=1,e.clearColor[2]=1,e.clearColor[3]=1);e.clearDepth=1;e.clearFlags=d;e.clearStencil=null;e._node=new Z;c=b._shadowCamera=e;Rj(a,b)}else d=c.renderTarget,d.width===b._shadowResolution&&d.height===b._shadowResolution||Rj(a,b);return c},updateCameraFrustum:function(a){if(a.vrDisplay&&a.vrDisplay.presenting){Bb=a.vrDisplay.combinedProj;var b=a._node.parent;b?mb.copy(b.getWorldTransform()).mul(a.vrDisplay.combinedViewInv).invert():mb.copy(a.vrDisplay.combinedView); Lb.copy(mb).invert();this.viewInvId.setValue(Lb.data);a.frustum.update(Bb,mb)}else if(a.xr&&a.xr.views.length){b=a.xr.views[0];a.frustum.update(b.projMat,b.viewOffMat);return}Bb=a.getProjectionMatrix();a.overrideCalculateProjection&&a.calculateProjection(Bb,0);if(a.overrideCalculateTransform)a.calculateTransform(Lb,0);else{b=a._node.getPosition();var c=a._node.getRotation();Lb.setTRS(b,c,p.ONE);this.viewInvId.setValue(Lb.data)}mb.copy(Lb).invert();a.frustum.update(Bb,mb)},setCamera:function(a,b,c, d){var e=a.vrDisplay,g;if(e&&e.presenting){uf=e.leftProj;vf=e.rightProj;Bb=e.combinedProj;a.overrideCalculateProjection&&(a.calculateProjection(uf,1),a.calculateProjection(vf,2),a.calculateProjection(Bb,0));if(a.overrideCalculateTransform)a.calculateTransform(Bc,1),a.calculateTransform(Cc,2),a.calculateTransform(Lb,0),ve.copy(Bc).invert(),we.copy(Cc).invert(),mb.copy(Lb).invert();else if(g=a._node.parent){var k=g.getWorldTransform();Bc.mul2(k,e.leftViewInv);Cc.mul2(k,e.rightViewInv);ve.copy(Bc).invert(); we.copy(Cc).invert();mb.copy(g.getWorldTransform()).mul(e.combinedViewInv).invert()}else Bc.copy(e.leftViewInv),Cc.copy(e.rightViewInv),ve.copy(e.leftView),we.copy(e.rightView),mb.copy(e.combinedView);Xf(tl,ve);Xf(ul,we);vl.mul2(uf,ve);wl.mul2(vf,we);xe.x=Bc.data[12];xe.y=Bc.data[13];xe.z=Bc.data[14];ye.x=Cc.data[12];ye.y=Cc.data[13];ye.z=Cc.data[14];a.frustum.update(Bb,mb)}else if(a.xr&&a.xr.session){(g=a._node.parent)&&(k=g.getWorldTransform());e=a.xr.views;for(var f=0;fb;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,g=0;this.mainLight=-1;var k=this.device.scope;for(e=0;ethis.mainLight&&(this.lightShadowMatrixVsId[g].setValue(f._shadowMatrix.data),this.lightShadowParamsVsId[g].setValue(r),f._direction.normalize(),this.lightDirVs[g][0]=f._direction.x,this.lightDirVs[g][1]=f._direction.y,this.lightDirVs[g][2]=f._direction.z,this.lightDirVsId[g].setValue(this.lightDirVs[g]),this.mainLight=e)}g++}return g},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,Ld.setTRS(b.getPosition(),b.getRotation(),p.ONE).invert(),Mg.mul2(a.getProjectionMatrix(),Ld),c._shadowMatrix.mul2(ol,Mg)),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 g=a[1];a=a[2];var k=g.length,f=a.length,h=d,r=this.device.scope;for(d=0;dg._visibleLength[b])continue;r=g._visibleCameraSettings[b];h.setPosition(r.x,r.y,r.z);f.orthoHeight=r.orthoHeight; f.farClip=r.farClip;r=b}else if(2===k){var n=h.getPosition();this.viewPos[0]=n.x;this.viewPos[1]=n.y;this.viewPos[2]=n.z;this.viewPosId.setValue(this.viewPos);this.shadowMapLightRadiusId.setValue(g.attenuationEnd)}else 1===k&&(n=h.getPosition(),this.viewPos[0]=n.x,this.viewPos[1]=n.y,this.viewPos[2]=n.z,this.viewPosId.setValue(this.viewPos),this.shadowMapLightRadiusId.setValue(g.attenuationEnd),m=6);1!==k&&(Ld.setTRS(h.getPosition(),h.getRotation(),p.ONE).invert(),Mg.mul2(f.getProjectionMatrix(), Ld),g._shadowMatrix.mul2(ol,Mg));c.webgl2?1===k?c.setDepthBias(!1):(c.setDepthBias(!0),c.setDepthBiasValues(-1E3*g.shadowBias,-1E3*g.shadowBias)):c.extStandardDerivatives&&(1===k?(this.polygonOffset[0]=0,this.polygonOffset[1]=0):(this.polygonOffset[0]=-1E3*g.shadowBias,this.polygonOffset[1]=-1E3*g.shadowBias),this.polygonOffsetId.setValue(this.polygonOffset));1===g.shadowUpdateMode&&(g.shadowUpdateMode=0);this._shadowMapUpdates+=m;c.setBlending(!1);c.setDepthWrite(!0);c.setDepthTest(!0);g._isPcf&& c.webgl2&&1!==k?c.setColorWrite(!1,!1,!1,!1):c.setColorWrite(!0,!0,!0,!0);for(r?m=r+1:r=0;rd.cull&&(c.flipFaces&&(a*=-1),b&&(a*=-1),b=c.node.worldTransform,b.getX(Ng),b.getY(xl),b.getZ(yl),Ng.cross(Ng,xl),0>Ng.dot(yl)&& (a*=-1)),e=0>a?2===d.cull?1:2:d.cull);this.device.setCullMode(e)},setVertexBuffers:function(a,b){a.setVertexBuffer(b.vertexBuffer,0)},setMorphing:function(a,b){if(b)if(b.morph.useTextureMorph)a.setVertexBuffer(b.morph.vertexBufferIds,1),this.morphPositionTex.setValue(b.texturePositions),this.morphNormalTex.setValue(b.textureNormals),this.morphTexParams.setValue(b._textureParams);else{this.tempSemanticArray.length=0;for(var c,d=0;d=w;w++)for(d=0;dg;g++){d=E[3*e+g+G];d=d*I+r;var N=Q[d];var R=Q[d+1];d=Q[d+2];NP&&(P=N);R>W&&(W=R);d>L&&(L=d)}d=6*e;z[d]=m;z[d+1]=n;z[d+2]=K;z[d+3]=P;z[d+4]=W;z[d+5]=L}for(N=0;N=R.x&&z[d+1]<=m.y&&z[d+4]>=R.y&&z[d+2]<=m.z&&z[d+5]>=R.z&&(v[e]|=g,H=!0);if(H){H={};for(e=0;eP&&(P=N),R>W&&(W=R),d>L&&(L=d);q.set(m,n,K);u.set(P,W,L);e=new ia;e.setMinMax(q,u);B=new gb(k);B.vertexBuffer=w;B.indexBuffer[0]=E;B.primitive[0].type=4;B.primitive[0].base=0;B.primitive[0].count=g.length;B.primitive[0].indexed=!0;B.aabb=e;E=new na(F.node,B,F.material);E.isStatic=F.isStatic;E.visible=F.visible;E.layer=F.layer;E.castShadow=F.castShadow;E._receiveShadow=F._receiveShadow;E.cull=F.cull;E.pick=F.pick;E.mask=F.mask; E.parameters=F.parameters;E._shaderDefs=F._shaderDefs;E._staticSource=F;E._staticLightList=F._staticLightList?F._staticLightList:[];for(e=0;eE._staticLightList.indexOf(B)&&E._staticLightList.push(B));E._staticLightList.sort(this.lightCompare);h.push(E)}}else h.push(F)}}else h.push(F)}a.length=h.length;for(c=0;cr;r++)ql.transformPoint(ma[r],ma[r]);f=h=c=1E6;u=q=n=-1E6;for(r=0;8>r;r++){var t=ma[r];t.xu&&(u=t.x);t.yq&&(q=t.y);t.zn&&(n=t.z)}r=m/a._shadowResolution;f=Math.floor((f-.5*(m-(u-f)))/r)*r;h=Math.floor((h-.5*(m-(q-h)))/r)*r;f=.5*(f+m+f);h=.5*(h+m+h);g.translateLocal(f,h,1E5);e.projection=1;e.nearClip=0;e.farClip=2E5;e.aspectRatio=1;e.orthoHeight=.5*m;this.updateCameraFrustum(e);q=!0;(n=a._visibleList[d])|| (n=a._visibleList[d]=[]);r=m=a._visibleLength[d]=0;for(u=b.length;rn;++n)Ld.transformPoint(sa[n],sa[n]),m=sa[n].z,mb&&(b=m);n=b;r>c&&(c=r);g.setPosition(k.getPosition());g.translateLocal(f,h,n+.01);e.farClip=n-c;(k=a._visibleCameraSettings[d])||(k=a._visibleCameraSettings[d]={});a=g.getPosition();k.x=a.x;k.y=a.y;k.z=a.z;k.orthoHeight=e.orthoHeight;k.farClip=e.farClip},gpuUpdate:function(a){this.updateGpuSkinMatrices(a);this.updateMorphing(a)},clearView:function(a,b,c){a=a.camera;var d=this.device; d.setRenderTarget(b);d.updateBegin();d.setColorWrite(!0,!0,!0,!0);d.setDepthWrite(!0);var e=a.getRect(),g=b?b.width:d.width,k=b?b.height:d.height;b=Math.floor(e.x*g);var f=Math.floor(e.y*k);g=Math.floor(e.width*g);e=Math.floor(e.height*k);d.setViewport(b,f,g,e);d.setScissor(b,f,g,e);d.clear(c?c:a._clearOptions)},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, g=a._renderedLayer,k,f,h,r;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 m=0;for(k=0;kthis.layers.indexOf(a)&&this.layers.push(a)};Yf.prototype.getLayerIdx=function(a){return this.layerToBatch[a.id]};Yf.prototype.addLayerIdx=function(a,b){this.layerToBatch[b.id]=a};Object.assign(Tj.prototype,{init:function(a,b,c,d){this.mesh||(this.mesh=new gb(a),this.mesh.primitive[0].type=1,this.mesh.primitive[0].base=0,this.mesh.primitive[0].indexed=!1,this.material=new Lc,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 Ta(a,b,2*this.numLinesAllocated,1),this.mesh.vertexBuffer=this.vb,this.vbRam=new DataView(this.vb.lock()),this.meshInstance||(Rg.worldTransform=C.IDENTITY,Rg._dirtyWorld=Rg._dirtyNormal=!1,this.meshInstance=new na(Rg,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,g=0;gthis._meshInstances.indexOf(k)&&(this._meshInstances.push(k),k.material&&k.material._dirtyBlend&&(this._dirtyBlend=!0,k.material._dirtyBlend=!1))}g=e.transparentMeshInstances;for(b=0;bthis._meshInstances.indexOf(k)&&(this._meshInstances.push(k),k.material&&k.material._dirtyBlend&&(this._dirtyBlend=!0,k.material._dirtyBlend=!1))}for(a=0;ak&&(this._lights.push(f),k=this._lights.length-1), (f=this._lightShadowCasters[k])||(this._lightShadowCasters[k]=[]);this._sortLights(this);this._dirtyLights=!1;for(a=0;athis._meshInstances.indexOf(f[k])?(f[k]=f[f.length-1],--f.length):k++;for(k=0;kf.indexOf(h[k])&&f.push(h[k])}if(d&2||this._dirtyCameras)for(this._globalLightCameras.length= 0,g=this._sortedLights[0],b=0;be._sortedLights[0].indexOf(f)))for(k=0;kk&&this.cameras.push(g);this._renderList.length=0;for(a= k=this._renderListCamera.length=0;ak||g.push(k);this._globalLightCameraIds.push(g)}return d};qa.prototype._isLayerAdded=function(a){return 0<=this.layerList.indexOf(a)?!0:!1};qa.prototype._isSublayerAdded=function(a,b){for(var c=0;cthis.layerList.indexOf(a)&& this.fire("remove",a);break}};qa.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))};qa.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))};qa.prototype.removeTransparent=function(a){for(var b=0,c=this.layerList.length;bthis.layerList.indexOf(a)&&this.fire("remove",a);break}};qa.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};qa.prototype.getOpaqueIndex=function(a){return this._getSublayerIndex(a,!1)};qa.prototype.getTransparentIndex=function(a){return this._getSublayerIndex(a,!0)};qa.prototype.getLayerById=function(a){for(var b=0;bc;c++)Q.setValue(U),Ea(e,O,u),Q.setValue(aa),Ea(e,Y,u);for(c=0;cg;g++)kj.data[g]=l.data[g];lj.copy(kj);lj.invert();Ec=h.meshInstance.node.localScale;Dl=Math.max(Math.max(Ec.x,Ec.y),Ec.z)}g=null===h.meshInstance.node||h.localSpace?p.ZERO:h.meshInstance.node.getPosition();var m=h.camera?h.camera._node.getPosition():p.ZERO,n=h.useMesh?17:15,q=h.precision-1;for(l=0;l=w-k||w>=v)&&this.calcSpawnPosition(c,d,e,g,u);var F=0w&&(c[4*u+3+8*h.numParticlesPot]=-1):(w>=v&&(w-=Math.max(v,(h.numParticles-1)*x),c[4*u+3+8*h.numParticlesPot]=h.loop?1:-1),0>w&&h.loop&&(c[4*u+3+8*h.numParticlesPot]=1));0>c[4*u+3+8*h.numParticlesPot]&&(F=!1);c[4*u+3+4*h.numParticlesPot]=w;for(H=0;He;e++)for(d=0;16>d;d++){var g=d+1-8.5;var k=e+1-8.5;k=Math.max(Math.min(1-Math.max(Math.min(Math.sqrt(g*g+k*k)/16,1),0)-.5,1),0);g=16*e+d;c[4*g]=1;c[4*g+1]=1;c[4*g+2]=1;c[4*g+3]=k}Nb.DEFAULT_PARAM_TEXTURE=Mb(a,16,16,c,7,1,!0);Nb.DEFAULT_PARAM_TEXTURE.minFilter=1;Nb.DEFAULT_PARAM_TEXTURE.magFilter= 1}Vj=this;bg=b;J("numParticles",1);this.numParticles>a.maxTextureSize&&(console.warn("WARNING: can't create more than "+a.maxTextureSize+" particles on this device."),this.numParticles=a.maxTextureSize);J("rate",1);J("rate2",this.rate);J("lifetime",50);J("emitterExtents",new p(0,0,0));J("emitterExtentsInner",new p(0,0,0));J("emitterRadius",0);J("emitterRadiusInner",0);J("emitterShape",0);J("initialVelocity",1);J("wrap",!1);J("localSpace",!1);J("screenSpace",!1);J("wrapBounds",null);J("colorMap",Nb.DEFAULT_PARAM_TEXTURE); J("normalMap",null);J("loop",!0);J("preWarm",!1);J("sort",0);J("mode",0);J("scene",null);J("lighting",!1);J("halfLambert",!1);J("intensity",1);J("stretch",0);J("alignToMotion",!1);J("depthSoftening",0);J("mesh",null);J("particleNormal",new p(0,1,0));J("orientation",0);J("depthWrite",!1);J("noFog",!1);J("blendType",2);J("node",null);J("startAngle",0);J("startAngle2",this.startAngle);J("animTilesX",1);J("animTilesY",1);J("animStartFrame",0);J("animNumFrames",1);J("animNumAnimations",1);J("animIndex", 0);J("randomizeAnimIndex",!1);J("animSpeed",1);J("animLoop",!0);this._gpuUpdater=new ag(this,a);this._cpuUpdater=new Ch(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]);J("colorGraph",qo);J("colorGraph2",this.colorGraph);J("scaleGraph",Kl);J("scaleGraph2",this.scaleGraph);J("alphaGraph",Kl);J("alphaGraph2",this.alphaGraph);J("localVelocityGraph",Ll); J("localVelocityGraph2",this.localVelocityGraph);J("velocityGraph",Ll);J("velocityGraph2",this.velocityGraph);J("rotationSpeedGraph",Jl);J("rotationSpeedGraph2",this.rotationSpeedGraph);J("radialSpeedGraph",Jl);J("radialSpeedGraph2",this.radialSpeedGraph);this.lightCube=new Float32Array(18);this.lightCubeDir=Array(6);this.lightCubeDir[0]=new p(-1,0,0);this.lightCubeDir[1]=new p(1,0,0);this.lightCubeDir[2]=new p(0,-1,0);this.lightCubeDir[3]=new p(0,1,0);this.lightCubeDir[4]=new p(0,0,-1);this.lightCubeDir[5]= new p(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 ia;this.worldBoundsNoTrail=new ia;this.worldBoundsTrail=[new ia,new ia];this.worldBounds=new ia;this.worldBoundsSize=new p;this.prevWorldBoundsSize=new p; this.prevWorldBoundsCenter=new p;this.prevEmitterExtents=this.emitterExtents;this.prevEmitterRadius=this.emitterRadius;this.worldBoundsMul=new p;this.worldBoundsAdd=new p;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(Nb.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?C.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,g=-Number.MAX_VALUE,k=0,f=0,h=this.lifetime/this.precision,r=[this.qVelocity,this.qVelocity2],m=[this.qLocalVelocity,this.qLocalVelocity2],n=[0,0],q=[0,0],u=[0,0],t=[0,0],p=[0,0],v,w;for(v=0;vw;w++){var z= m[w][3*y]*h+n[w];var A=m[w][3*y+1]*h+q[w];var B=m[w][3*y+2]*h+u[w];a=Math.min(z,a);b=Math.min(A,b);c=Math.min(B,c);d=Math.max(z,d);e=Math.max(A,e);g=Math.max(B,g);n[w]=z;q[w]=A;u[w]=B}for(w=0;2>w;w++)p[w]+=h*Math.sqrt(r[w][3*y]*r[w][3*y]+r[w][3*y+1]*r[w][3*y+1]+r[w][3*y+2]*r[w][3*y+2]);t[0]+=this.qRadialSpeed[y]*h;t[1]+=this.qRadialSpeed2[y]*h;k=Math.max(k,Math.max(Math.abs(t[0]),Math.abs(t[1])));f=Math.max(f,this.qScale[y])}0===this.emitterShape?(z=.5*this.emitterExtents.x,A=.5*this.emitterExtents.y, B=.5*this.emitterExtents.z):B=A=z=this.emitterRadius;h=Math.max(p[0],p[1]);Tg.x=a-f-z-k-h;Tg.y=b-f-A-k-h;Tg.z=c-f-B-k-h;Ug.x=d+f+z+k+h;Ug.y=e+f+A+k+h;Ug.z=g+f+B+k+h;this.localBounds.setMinMax(Tg,Ug)},rebuild:function(){var a,b=this.graphicsDevice;null===this.colorMap&&(this.colorMap=Nb.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;Fc=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()}});la.prototype=Object.create(G.prototype);la.prototype.constructor=la;la.prototype.destroy=function(){this.root=null;this.defaultMaterial.destroy();this.defaultMaterial=null;this.off()};Object.defineProperty(la.prototype, "fog",{get:function(){return this._fog},set:function(a){a!==this._fog&&(this._fog=a,this.updateShaders=!0)}});Object.defineProperty(la.prototype,"gammaCorrection",{get:function(){return this._gammaCorrection},set:function(a){a!==this._gammaCorrection&&(this._gammaCorrection=a,this.updateShaders=!0)}});Object.defineProperty(la.prototype,"toneMapping",{get:function(){return this._toneMapping},set:function(a){a!==this._toneMapping&&(this._toneMapping=a,this.updateShaders=!0)}});Object.defineProperty(la.prototype, "skybox",{get:function(){return this._skyboxCubeMap},set:function(a){this._skyboxCubeMap=a;this._resetSkyboxModel();this.updateShaders=!0}});Object.defineProperty(la.prototype,"skyboxIntensity",{get:function(){return this._skyboxIntensity},set:function(a){this._skyboxIntensity=a;this._resetSkyboxModel();this.updateShaders=!0}});Object.defineProperty(la.prototype,"skyboxMip",{get:function(){return this._skyboxMip},set:function(a){this._skyboxMip=a;this._resetSkyboxModel();this.updateShaders=!0}}); Object.defineProperty(la.prototype,"skyboxPrefiltered128",{get:function(){return this._skyboxPrefiltered[0]},set:function(a){this._skyboxPrefiltered[0]!==a&&(this._skyboxPrefiltered[0]=a,this.updateShaders=!0)}});Object.defineProperty(la.prototype,"skyboxPrefiltered64",{get:function(){return this._skyboxPrefiltered[1]},set:function(a){this._skyboxPrefiltered[1]!==a&&(this._skyboxPrefiltered[1]=a,this.updateShaders=!0)}});Object.defineProperty(la.prototype,"skyboxPrefiltered32",{get:function(){return this._skyboxPrefiltered[2]}, set:function(a){this._skyboxPrefiltered[2]!==a&&(this._skyboxPrefiltered[2]=a,this.updateShaders=!0)}});Object.defineProperty(la.prototype,"skyboxPrefiltered16",{get:function(){return this._skyboxPrefiltered[3]},set:function(a){this._skyboxPrefiltered[3]!==a&&(this._skyboxPrefiltered[3]=a,this.updateShaders=!0)}});Object.defineProperty(la.prototype,"skyboxPrefiltered8",{get:function(){return this._skyboxPrefiltered[4]},set:function(a){this._skyboxPrefiltered[4]!==a&&(this._skyboxPrefiltered[4]=a, this.updateShaders=!0)}});Object.defineProperty(la.prototype,"skyboxPrefiltered4",{get:function(){return this._skyboxPrefiltered[5]},set:function(a){this._skyboxPrefiltered[5]!==a&&(this._skyboxPrefiltered[5]=a,this.updateShaders=!0)}});Object.defineProperty(la.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(la.prototype,"layers",{get:function(){return this._layers}, set:function(a){var b=this._layers;this._layers=a;this.fire("set:layers",b,a)}});la.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};la.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 da,e=this;d.updateShader=function(b,d,g,k,f){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===f?e.gammaCorrection?3:0:e.gammaCorrection,toneMapping:1=== f?0:e.toneMapping})};d.updateShader();d.setParameter("texture_cubeMap",c);d.cull=2;d.depthWrite=!1;if(b=this.layers.getLayerById(2)){var g=new Z,k=cg(a);d=new na(g,k,d);d.cull=!1;d._noDepthDrawGl1=!0;k=new hb;k.graph=g;k.meshInstances=[d];this.skyboxModel=k;b.addMeshInstances(k.meshInstances);this.skyLayer=b;this._firstUpdateSkybox&&(b.enabled=!0,this._firstUpdateSkybox=!1);this.fire("set:skybox",c)}}}};la.prototype._resetSkyboxModel=function(){this.skyboxModel&&(this.skyLayer.removeMeshInstances(this.skyboxModel.meshInstances), this.skyboxModel.destroy());this.skyboxModel=null;this.updateSkybox=!0};la.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]}};la.prototype.destroy=function(){this.skybox=null};la.prototype.addModel=function(a){if(!this.containsModel(a)){var b=this.layers.getLayerById(0);b&&(b.addMeshInstances(a.meshInstances), this._models.push(a))}};la.prototype.addShadowCaster=function(a){var b=this.layers.getLayerById(0);b&&b.addShadowCasters(a.meshInstances)};la.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))}};la.prototype.removeShadowCasters=function(a){var b=this.layers.getLayerById(0);b&&b.removeShadowCasters(a.meshInstances)};la.prototype.containsModel=function(a){return 0<=this._models.indexOf(a)}; la.prototype.getModels=function(a){return this._models};if(Mc()){var Ob=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(Ob.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=H.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 Wd()?(Ob=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(Ob.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=H.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}})):Ob=function(){};Object.assign(Ob.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 gf="inverse";if(Mc()){var Sa=function(a,b,c){Ob.call(this,a,b,c);this.position=new p;this.velocity=new p;this.panner=a.context.createPanner()};Sa.prototype=Object.create(Ob.prototype);Sa.prototype.constructor=Sa;Object.assign(Sa.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(Wd()){var mj=new p;Sa=function(a,b){Ob.call(this,a,b);this.position=new p;this.velocity=new p;this.maxDistance=1E4;this.rollOffFactor=this.minDistance=1;this.distanceModel=gf};Sa.prototype=Object.create(Ob.prototype); Sa.prototype.constructor=Sa;Object.assign(Sa.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;mj=mj.sub2(b,this.position);b=mj.length();if(bc)a=0;else{var g=0;"linear"===e?g=1-d*(b-a)/(c-a):e===gf?g=a/(a+d*(b-a)):"exponential"===e&&(g=Math.pow(b/a,-d));a=H.clamp(g,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 Sa=function(){};Object.assign(Jh.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}});Tb.prototype=Object.create(G.prototype);Tb.prototype.constructor=Tb;Object.assign(Tb.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;Ob&&(c=new Ob(this,a,b),c.play());return c},playSound3d:function(a,b,c){c=c||{};var d=null;Sa&&(d=new Sa(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(Tb.prototype,"volume",{get:function(){return this._volume}, set:function(a){this._volume=a=H.clamp(a,0,1);this.fire("volumechange",a)}});Gb.prototype.getDuration=function(){return this.duration};Gb.prototype.getName=function(){return this.name};Gb.prototype.getNode=function(a){return this._nodeDict[a]};Object.defineProperty(Gb.prototype,"nodes",{get:function(){return this._nodes}});Gb.prototype.getNodes=function(){return this._nodes};Gb.prototype.setDuration=function(a){this.duration=a};Gb.prototype.setName=function(a){this.name=a};Gb.prototype.addNode=function(a){this._nodes.push(a); this._nodeDict[a._name]=a};Object.defineProperties(Te.prototype,{morphPositions:{get:function(){return!!this._vertexBufferPositions||!!this.texturePositions}},morphNormals:{get:function(){return!!this._vertexBufferNormals||!!this.textureNormals}}});Object.assign(Te.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 Ta(a,new Ha(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(Ue.prototype,{encode:function(a){return fc.joinPath([fc.joinPath(a[0]),a[1],fc.joinPath(a[2])],"/")},decode:function(a){a=fc.splitPath(a,"/");return[fc.splitPath(a[0]),a[1],fc.splitPath(a[2])]}});S.prototype=Object.create(Z.prototype);S.prototype.constructor=S;S.prototype.addComponent=function(a,b){var c=this._app.systems[a]; return!c||this.c[a]?null:c.addComponent(this,b)};S.prototype.removeComponent=function(a){var b=this._app.systems[a];b&&this.c[a]&&b.removeComponent(this)};S.prototype.findComponent=function(a){var b=this.findOne(function(b){return b.c&&b.c[a]});return b&&b.c[a]};S.prototype.findComponents=function(a){return this.find(function(b){return b.c&&b.c[a]}).map(function(b){return b.c[a]})};S.prototype.getGuid=function(){this._guid||this.setGuid(dl.create());return this._guid};S.prototype.setGuid=function(a){var b= this._app._entityIndex;this._guid&&delete b[this._guid];this._guid=a;b[this._guid]=this};S.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 g=0;for(d=e.length;g=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,g;if(0===b)for(g=0;gc&&(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(ec.prototype,{func:{get:function(){return this._func}}, type:{get:function(){return this._type}},components:{get:function(){return this._components}}});fc.joinPath=function(a,b){b=b||".";return a.map(function(a){return a.replace(/\\/g,"\\\\").replace(new RegExp("\\"+b,"g"),"\\"+b)}).join(b)};fc.splitPath=function(a,b){b=b||".";for(var c=[],d="",e=0;eCa._dot(a,b)&&(c=-c);for(var g=0;g=a?0:1});bd(["fr","pt"],function(a){return 0<=a&&2>a?0:1});bd(["da"],function(a){return 1===a||!Number.isInteger(a)&&0<=a&&1>=a?0:1});bd("de en it el es tr fi sv nb no ur".split(" "),function(a){return 1===a?0:1});bd(["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});bd(["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});bd(["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 nj=Af[cd(gg)];Ia.prototype=Object.create(G.prototype);Ia.prototype.constructor=Ia;Ia.findAvailableLocale=function(a,b){if(b[a])return a;var c=Vg[a];if(c&&b[c])return c;a=cd(a);c=Vg[a];return b[c]?c:b[a]?a:gg};Ia.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=cd(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};Ia.prototype.getPluralText=function(a,b,c){var d=a;if(c){var e=cd(c);var g=Af[e]||nj}else c=this._locale,e=this._lang,g=this._pluralFn;var k=this._translations[c];k||(c=this._findFallbackLocale(c,e),e=cd(c),g=Af[e]||nj,k=this._translations[c]);k&&k[a]&&g&&(b=g(b),d=k[a][b],null===d||void 0===d)&&(d=a);return d};Ia.prototype.addData=function(a){try{var b=this._parser.parse(a)}catch(k){console.error(k);return}a=0;for(var c=b.length;a k[h+0]*k[h+4]+k[h+1]*k[h+5]+k[h+2]*k[h+6]+k[h+3]*k[h+7]&&(k[h+4]*=-1,k[h+5]*=-1,k[h+6]*=-1,k[h+7]*=-1);k=e}for(u=e=0;ul;l++)n[l]=f[16*g+l];l=new C;l.set(n);m.push(l)}}else for(g=0;gparseFloat(a.asset.version)?b("Invalid gltf version. Expected version 2.0 or above but found version '"+a.asset.version+"'."):b(null,a)},Tl=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), g=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>=g||g>b.byteLength)c("Invalid length found in glb header. Found "+g);else{d=[];for(e=12;eb.byteLength)throw Error("Invalid chunk length found in glb. Found "+f);var l=a.getUint32(e+4,!0),h=new Uint8Array(b,e+8,f);d.push({length:f,type:l,data:h}); e+=f+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,g=a._resources,f,l,h=[null,null,null,null,null,null,null],r=function(){return d.hasOwnProperty("type")? d.type:d.hasOwnProperty("rgbm")&&d.rgbm?"rgbm":"default"};if(c[0]!==e[0]){if(c[0]){var m=c[0].resource;for(l=0;6>l;++l){var n=[m._levels[l]];if(0===l&&this._device.useTexCubeLod)for(f=1;f>l),cubemap:!0,type:r(),width:m.width>>l,height:m.height>>l,format:m.format,levels:n,fixCubemapSeams:!0});h[l+1]=n}}}else h[1]=g[1]||null,h[2]=g[2]||null,h[3]=g[3]||null,h[4]=g[4]||null,h[5]=g[5]||null,h[6]=g[6]||null; m=c.slice(1);if(this.cmpArrays(m,e.slice(1)))h[0]=g[0]||null;else if(-1===m.indexOf(null)){l=m.map(function(a){return a.resource});n=[];for(f=0;fq;++q){var u=d[q];if(u)if(c.compareAssetIds(u,g[q]))h(q,f[q]);else if(parseInt(u,10)===u)if(n=m.get(u))n.loaded?h(q,n):(m.once("load:"+u,h.bind(c,q)),m.once("error:"+u,r.bind(c, q)),n.loading||m.load(n));else m.on("add:"+u,function(a,b,d){m.once("load:"+b,h.bind(c,a));m.once("error:"+b,r.bind(c,a));m.load(d)}.bind(null,q,u));else n=new V(a.name+"_part_"+q,"texture","string"===typeof u?{url:u,filename:u}:u),m.add(n),m.once("load:"+n.id,h.bind(c,q)),m.once("error:"+n.id,r.bind(c,q)),m.load(n);else h(q,null)}}});Object.assign(Wh.prototype,{load:function(a,b){b(null,null)},open:function(a,b){return b}});Object.defineProperty(ig.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(Yh.prototype,{load:function(a,b,c){"string"===typeof a&&(a={load:a,original:a});var d=this;".json"===X.getExtension(a.original)?oa.get(a.load, {retry:this.retryRequests},function(c,g){var e=Xh(g);c?b("Error loading font resource: "+a.original+" ["+c+"]"):d._loadTextures(a.load.replace(".json",".png"),e,function(a,c){if(a)return b(a);b(null,{data:e,textures:c})})}):(c&&c.data&&(c.data=Xh(c.data)),this._loadTextures(a.load,c&&c.data,b))},_loadTextures:function(a,b,c){var d=b.info.maps.length,e=0,g=null,f=Array(d),l=this._loader;b=function(b){var k=function(a,k){if(!g){if(a)return g=a,c(a);k.upload();f[b]=k;e++;e===d&&c(null,f)}};0===b?l.load(a, "texture",k):l.load(a.replace(".png",b+".png"),"texture",k)};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[Ko[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,g;for(g=0;gd;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,g,f=[],l=0,h=a.length;for(e=0;em;m++)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),g=this._parseMorphs(a,b,d);d=this._parseMeshes(a,c.skins,g.morphs,d,e.buffer,e.data);a=this._parseMeshInstances(a,b,d,c.skins,c.instances,g.morphs,g.instances);d=new hb;d.graph=b[0];d.meshInstances=a;d.skinInstances=c.instances; d.morphInstances=g.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 r=-a.x+2*a.x*(1>=b?0:3)/3;var m=-(-a.y+2*a.y*(1>=c?0:3)/3);var n=0===c||3===c?0:1;d.push(-r,0,m);e.push(0,1,0);g.push(h,n);3>b&&3>c&&(f.push(l+3+1,l+1,l),f.push(l+3+1,l+3+2,l+1));l++}}return Fb(this._device,d,{normals:e,uvs:g,indices:f})};Ma.prototype._onSetFrames=function(a){this._updatingProperties? this._meshesDirty=!0:this._createMeshes()};Ma.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"))};Ma.prototype._onFrameRemoved=function(a){a=this._frameKeys.indexOf(a);0>a||(this._meshes[a]=null,this.fire("set:meshes"))};Ma.prototype.startUpdate=function(){this._updatingProperties=!0;this._meshesDirty=!1};Ma.prototype.endUpdate=function(){this._updatingProperties= !1;this._meshesDirty&&this._atlas&&this._frameKeys&&this._createMeshes();this._meshesDirty=!1};Ma.prototype.destroy=function(){var a;var b=0;for(a=this._meshes.length;b=++g){var c=100*Math.pow(2, g);console.log("Error loading Texture from: '"+b+"' - Retrying in "+c+"ms...");var k=0<=a.indexOf("?")?"&":"?";f=setTimeout(function(){e.src=a+k+"retry="+Date.now();f=null},c)}else d("Error loading Texture from: '"+b+"'")};e.src=a},_loadImageBitmap:function(a,b,c,d){oa.get(a,{cache:!0,responseType:"blob",retry:this.retryRequests},function(a,b){a?d(a):createImageBitmap(b,{premultiplyAlpha:"none"}).then(function(a){d(null,a)}).catch(function(a){d(a)})})}});var tj=[1481919403,3140563232,169478669],Vl= {33776:8,33778:9,33779:10,36196:21,37492:22,37496:23,35840:26,35841:24,35842:27,35843:25};Object.assign(ui.prototype,{load:function(a,b,c){oa.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 M(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(tj[0]!== b[0]||tj[1]!==b[1]||tj[2]!==b[2])return null;var c=b[6],d=b[7],e=b[9],g=b[10],f=b[12],l=b[13],h=b[14];if(1>1),e=Math.max(1,b>>1),g=new c.constructor(d*e*4),f=Math.floor(a/d);b=Math.floor(b/e);for(var h=f*b,k=0;km;++m){for(var r=0,p=0;p>d-1),g=Math.max(1,a._height>>d-1);if(a._cubemap){for(var f=[],l=0;6>l;++l)f.push(c(e,g,a._levels[d-1][l]));a._levels.push(f)}else a._levels.push(c(e,g,a._levels[d-1]))}a._levelsUpdated=a._cubemap?[[!0,!0,!0,!0,!0,!0]]:[!0]}};Object.defineProperties(kg.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(kg.prototype,{_getUrlWithoutParams:function(a){return 0<=a.indexOf("?")?a.split("?")[0]:a},_getParser:function(a){a=X.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 M(this._device,{width:4,height:4,format:6}):Ro(a),a},patch:function(a,b){if(b=a.resource){a.name&&0this.views.length)for(d=0;d<=e-this.views.length;d++)(b=this.viewsPool.pop())||(b={viewport:new T,projMat:new C,viewMat:new C,viewOffMat:new C,viewInvMat:new C,viewInvOffMat:new C,projViewOffMat:new C,viewMat3:new Db,position:new Float32Array(3),rotation:new U}),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){f=(this._time-h.time)/(r.time-h.time);g._pos.lerp(h.position,r.position,f);g._quat.slerp(h.rotation,r.rotation,f);g._scale.lerp(h.scale,r.scale,f);g._written=!0;this._currKeyIndices[e]= l;f=!0;break}}if(1===d.length||!f&&0===this._time&&this.looping)g._pos.copy(d[0].position),g._quat.copy(d[0].rotation),g._scale.copy(d[0].scale),g._written=!0}}}}};Na.prototype.blend=function(a,b,c){for(var d=this._interpolatedKeys.length,e=0;ee.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 g=0;ga&&(a=c.animTrack.duration>a)}return a}}});Object.defineProperties(xi.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(mg.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}},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(c){return c.from===a&&c.to===b}),c.sort(function(a,b){return a.priority"+b]=c);return c},_findTransition:function(a,b){var c=[];if(a&&b)c.concat(this._findTransitionsBetweenStates(this._activeStateName));else if(this._isTransitioning)switch(this._transitionInterruptionSource){case "PREV_STATE":c= c.concat(this._findTransitionsFromState(this._previousStateName));break;case "NEXT_STATE":c=c.concat(this._findTransitionsFromState(this._activeStateName));break;case "PREV_STATE_NEXT_STATE":c=c.concat(this._findTransitionsFromState(this._previousStateName));c=c.concat(this._findTransitionsFromState(this._activeStateName));break;case "NEXT_STATE_PREV_STATE":c=c.concat(this._findTransitionsFromState(this._activeStateName)),c=c.concat(this._findTransitionsFromState(this._previousStateName))}else c= c.concat(this._findTransitionsFromState(this._activeStateName));c=c.filter(function(a){if(a.to===this.activeStateName)return!1;if(a.hasExitTime){var b=this._getActiveStateProgressForTime(this._timeInStateBefore),c=this._getActiveStateProgressForTime(this._timeInState);1>a.exitTime&&this.activeState.looping&&(b-=Math.floor(b),c-=Math.floor(c));if(!(a.exitTime>b&&a.exitTime<=c))return null}return a.hasConditionsMet}.bind(this));return 0a.transitionOffset;g=this.activeState;for(b=0;bb.indexOf(c[d])&&(c[d]instanceof V?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 Sa&&this.channel.setMaxDistance(c)},onSetMinDistance:function(a,b,c){b!=c&&this.channel instanceof Sa&&this.channel.setMinDistance(c)},onSetRollOffFactor:function(a,b,c){b!=c&&this.channel instanceof Sa&&this.channel.setRollOffFactor(c)},onSetDistanceModel:function(a, b,c){b!==c&&this.channel instanceof Sa&&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;cthis.layers.indexOf(a.id)||a.addCamera(this)},onLayerRemoved:function(a){0>this.layers.indexOf(a.id)||a.removeCamera(this)},updateClearFlags:function(){var a=0;this.clearColorBuffer&&(a|=1);this.clearDepthBuffer&&(a|=2);this.clearStencilBuffer&&(a|=4);this.data.camera.clearFlags=a},onSetRenderTarget:function(a,b,c){this.data.camera.renderTarget= c},onSetRect:function(a,b,c){this.data.camera.setRect(c.x,c.y,c.z,c.w)},onSetScissorRect:function(a,b,c){this.data.camera.setScissorRect(c.x,c.y,c.z,c.w)},onEnable:function(){this.system.addCamera(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));this.enabled&&this.entity.enabled&&this.addCameraToLayers();this.postEffects.enable()}, onDisable:function(){this.postEffects.disable();this.removeCameraFromLayers();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));this.system.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));this.data.isRendering=!0},frameEnd:function(){this.data.isRendering=!1},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(a){a.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 Me;Object.assign(og.prototype,{_createOffscreenTarget:function(a,b){var c=this.camera.rect, d=Math.floor(c.z*this.app.graphicsDevice.width*this.renderTargetScale);c=Math.floor(c.w*this.app.graphicsDevice.height*this.renderTargetScale);var e=this.app.graphicsDevice,g=b?e.getHdrFormat():7;b=this.app.graphicsDevice.supportsStencil;var f=a?e.samples:1;d=new M(e,{format:g,width:d,height:c});d.name="posteffect #"+this.effects.length;d.minFilter=0;d.magFilter=0;d.addressU=1;d.addressV=1;return new ka(this.app.graphicsDevice,d,{depth:a,stencil:b,samples:f})},_resizeOffscreenTarget:function(a){var b= this.camera.rect,c=Math.floor(b.z*this.app.graphicsDevice.width*this.renderTargetScale);b=Math.floor(b.w*this.app.graphicsDevice.height*this.renderTargetScale);var d=this.app.graphicsDevice,e=a.colorBuffer.format;a._colorBuffer.destroy();c=new M(d,{format:e,width:c,height:b});c.name="posteffect";c.minFilter=0;c.magFilter=0;c.addressU=1;c.addressV=1;a._colorBuffer=c;a.destroy()},_destroyOffscreenTarget:function(a){a._colorBuffer&&a._colorBuffer.destroy();a._depthBuffer&&a._depthBuffer.destroy();a.destroy()}, setRenderTargetScale:function(a){this.renderTargetScale=a;this.resizeRenderTargets()},addEffect:function(a){var b=this.effects,c={effect:a,inputTarget:this._createOffscreenTarget(0===this.effects.length,a.hdr),outputTarget:null};if(!this.layer){this.layer=new fa({opaqueSortMode:0,transparentSortMode:0,passThrough:!0,name:"PostEffectQueue",renderTarget:this.camera.renderTarget,clear:!1,onPostRender:function(){for(var a=0;ae&&(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;1b?b+1:t,t>b?t+1:b);if(w)for(d=a.length;d--&&0this._maxLines||nz&&0this._maxLines||n=this._meshInfo.length)R.lines[n-1]-=D,R.quad-=D;else for(R=E,C=p;Cthis._element.calculatedWidth&&(O=Math.floor(this._element.fontSize*this._element.calculatedWidth/(this.width||1E-4)),O=H.clamp(O,d,e),O!==this._element.fontSize)){this._fontSize= O;G=!0;break}this.height=Math.max(this.height,y-(h+A));if(this._shouldAutoFitHeight()&&this.height>this._element.calculatedHeight&&(O=H.clamp(this._fontSize-1,d,e),O!==this._element.fontSize)){this._fontSize=O;G=!0;break}l+=this._spacing*J;T||S||(m=l);Vo.test(C)&&(x++,q=m,p=E+1);v++;C=this._getUv(C);R.uvs[8*D]=C[0];R.uvs[8*D+1]=C[1];R.uvs[8*D+2]=C[2];R.uvs[8*D+3]=C[1];R.uvs[8*D+4]=C[2];R.uvs[8*D+5]=C[3];R.uvs[8*D+6]=C[0];R.uvs[8*D+7]=C[3];this._symbolColors&&(L=3*this._symbolColors[E],I=this._colorPalette[L], N=this._colorPalette[L+1],L=this._colorPalette[L+2]);R.colors[16*D]=I;R.colors[16*D+1]=N;R.colors[16*D+2]=L;R.colors[16*D+3]=255;R.colors[16*D+4]=I;R.colors[16*D+5]=N;R.colors[16*D+6]=L;R.colors[16*D+7]=255;R.colors[16*D+8]=I;R.colors[16*D+9]=N;R.colors[16*D+10]=L;R.colors[16*D+11]=255;R.colors[16*D+12]=I;R.colors[16*D+13]=N;R.colors[16*D+14]=L;R.colors[16*D+15]=255;R.quad++}}G||tr;++r)this._meshInfo[E].positions[M+3*r]=this._element.calculatedWidth-this._meshInfo[E].positions[M+3*r]+2*z;r=this._meshInfo[E].positions[M+3];m=this._meshInfo[E].positions[M+6];this._meshInfo[E].positions[M+ 3]=this._meshInfo[E].positions[M+0];this._meshInfo[E].positions[M+6]=this._meshInfo[E].positions[M+9];this._meshInfo[E].positions[M+0]=r;this._meshInfo[E].positions[M+9]=m}M=f+1}f=4*this._meshInfo[E].count;z=4*this._meshInfo[E].quad;D=new Eb(this._meshInfo[E].meshInstance.mesh.vertexBuffer);for(M=0;M=z?(D.element.POSITION.set(0,0,0),D.element.TEXCOORD0.set(0,0),D.element.COLOR.set(0,0,0,0)):(D.element.POSITION.set(this._meshInfo[E].positions[3*M],this._meshInfo[E].positions[3*M+1],this._meshInfo[E].positions[3* M+2]),D.element.TEXCOORD0.set(this._meshInfo[E].uvs[2*M],this._meshInfo[E].uvs[2*M+1]),D.element.COLOR.set(this._meshInfo[E].colors[4*M],this._meshInfo[E].colors[4*M+1],this._meshInfo[E].colors[4*M+2],this._meshInfo[E].colors[4*M+3])),D.next();D.end();this._meshInfo[E].meshInstance.mesh.aabb.compute(this._meshInfo[E].positions);this._meshInfo[E].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(ha.prototype,"alignment", {get:function(){return this._alignment},set:function(a){a instanceof L?this._alignment.set(a.x,a.y):this._alignment.set(a[0],a[1]);this._font&&this._updateText()}});Object.defineProperty(ha.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(ha.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(ha.prototype,"rtlReorder",{get:function(){return this._rtlReorder}, set:function(a){this._rtlReorder!==a&&(this._rtlReorder=a,this._font&&this._updateText())}});Object.defineProperty(ha.prototype,"unicodeConverter",{get:function(){return this._unicodeConverter},set:function(a){this._unicodeConverter!==a&&(this._unicodeConverter=a,this._setText(this._text))}});Object.defineProperty(ha.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(Ua.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(Ua.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||f>a||lc;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(ba.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(ba.prototype,"worldCorners",{get:function(){if(!this._worldCornersDirty)return this._worldCorners;if(this.screen){var a=this.screenCorners;if(!this.screen.screen.screenSpace){Qb.copy(this.screen.screen._screenMatrix);Qb.data[13]=-Qb.data[13];Qb.mul2(this.screen.getWorldTransform(), Qb);for(var b=0;4>b;b++)Qb.transformPoint(a[b],this._worldCorners[b])}}else a=this.entity.getLocalPosition(),Qb.setTranslate(-a.x,-a.y,-a.z),bh.setTRS(p.ZERO,this.entity.getLocalRotation(),this.entity.getLocalScale()),ch.setTranslate(a.x,a.y,a.z),Ne.copy(this.entity.parent.getWorldTransform()),Ne.mul(ch).mul(bh).mul(Qb),sc.set(a.x-this.pivot.x*this.calculatedWidth,a.y-this.pivot.y*this.calculatedHeight,a.z),Ne.transformPoint(sc,this._worldCorners[0]),sc.set(a.x+(1-this.pivot.x)*this.calculatedWidth, a.y-this.pivot.y*this.calculatedHeight,a.z),Ne.transformPoint(sc,this._worldCorners[1]),sc.set(a.x+(1-this.pivot.x)*this.calculatedWidth,a.y+(1-this.pivot.y)*this.calculatedHeight,a.z),Ne.transformPoint(sc,this._worldCorners[2]),sc.set(a.x-this.pivot.x*this.calculatedWidth,a.y+(1-this.pivot.y)*this.calculatedHeight,a.z),Ne.transformPoint(sc,this._worldCorners[3]);this._worldCornersDirty=!1;return this._worldCorners}});Object.defineProperty(ba.prototype,"textWidth",{get:function(){return this._text? this._text.width:0}});Object.defineProperty(ba.prototype,"textHeight",{get:function(){return this._text?this._text.height:0}});Object.defineProperty(ba.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(ba.prototype,"batchGroupId", {get:function(){return this._batchGroupId},set:function(a){this._batchGroupId!==a&&(this.entity.enabled&&0<=this._batchGroupId&&this.system.app.batcher.remove(Ua.ELEMENT,this.batchGroupId,this.entity),this.entity.enabled&&0<=a&&this.system.app.batcher.insert(Ua.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(ba.prototype,"maskedBy",{get:function(){return this._maskedBy}});var ca=function(a){Object.defineProperty(ba.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)}})};ca("fontSize");ca("minFontSize");ca("maxFontSize");ca("maxLines");ca("autoFitWidth");ca("autoFitHeight");ca("color");ca("font");ca("fontAsset");ca("spacing");ca("lineHeight"); ca("wrapLines");ca("lines");ca("alignment");ca("autoWidth");ca("autoHeight");ca("rtlReorder");ca("unicodeConverter");ca("text");ca("key");ca("texture");ca("textureAsset");ca("material");ca("materialAsset");ca("sprite");ca("spriteAsset");ca("spriteFrame");ca("pixelsPerUnit");ca("opacity");ca("rect");ca("mask");ca("outlineColor");ca("outlineThickness");ca("shadowColor");ca("shadowOffset");ca("enableMarkup");ca("rangeStart");ca("rangeEnd");var Ck=["enabled"];de.prototype=Object.create(B.prototype);de.prototype.constructor= de;I._buildAccessors(ba.prototype,Ck);Object.assign(de.prototype,{destroy:function(){this._defaultTexture.destroy()},initializeComponentData:function(a,b,c){a._beingInitialized=!0;void 0!==b.anchor&&(b.anchor instanceof T?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 L?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(Oa.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(Oa.prototype,"shadowResolution",{get:function(){return this._shadowResolution},set:function(a){if(this._shadowResolution!==a){var b=Y.getApplication().graphicsDevice;this._shadowResolution=a=1===this._type?Math.min(a,b.maxCubeMapSize):Math.min(a,b.maxTextureSize)}}}); Object.defineProperty(Oa.prototype,"vsmBlurSize",{get:function(){return this._vsmBlurSize},set:function(a){this._vsmBlurSize!==a&&(0===a%2&&a++,this._vsmBlurSize=a)}});Object.defineProperty(Oa.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(Oa.prototype,"falloffMode",{get:function(){return this._falloffMode}, set:function(a){this._falloffMode!==a&&(this._falloffMode=a,this.updateKey())}});Object.defineProperty(Oa.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(Oa.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(Oa.prototype,"intensity",{get:function(){return this._intensity},set:function(a){this._intensity!==a&&(this._intensity=a,this._updateFinalColor())}});Object.defineProperty(Oa.prototype,"cookie",{get:function(){return this._cookie},set:function(a){this._cookie!==a&&(this._cookie=a,this.updateKey())}});Object.defineProperty(Oa.prototype,"cookieFalloff",{get:function(){return this._cookieFalloff},set:function(a){this._cookieFalloff!==a&&(this._cookieFalloff=a,this.updateKey())}}); Object.defineProperty(Oa.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(Aa.prototype,"materialAsset",{get:function(){return this._materialAsset},set:function(a){var b=a;a instanceof V&&(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(Aa.prototype,"material",{get:function(){return this._material},set:function(a){this._material!==a&&(this.materialAsset=null,this._setMaterial(a))}});Object.defineProperty(Aa.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,g=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 V&&(c=this.data.colorMapAsset=c.id),b=a.get(c))d._bindColorMapAsset(b);else a.once("add:"+c,function(a){d._bindColorMapAsset(a)});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 V&&(c=this.data.normalMapAsset=c.id),b=a.get(c))d._bindNormalMapAsset(b);else a.once("add:"+c,function(a){d._bindNormalMapAsset(a)}); 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 V&&(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 V||"number"===typeof c?this.meshAsset=c:this._onMeshChanged(c)},_onMeshChanged:function(a){!a||a instanceof gb||(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||(Oe||(Oe=this.system.app.scene.layers.getLayerById(1)),Oe&&(Oe.incrementCounter(),this._requestedDepth=!0))},_releaseDepth:function(){this._requestedDepth&&Oe&&(Oe.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=gh.length;bf;f++)m[3*f]=this.app.scene.ambientLight.r,m[3*f+1]=this.app.scene.ambientLight.g,m[3*f+2]=this.app.scene.ambientLight.b; var n=g._sortedLights[0];for(c=0;cg;g++){var q=Math.max(h.lightCubeDir[g].dot(n[c]._direction),0)*n[c]._intensity;m[3*g]+=n[c]._color.r*q;m[3*g+1]+=n[c]._color.g*q;m[3*g+2]+=n[c]._color.b*q}}h.constantLightCube.setValue(m)}if(!l.paused){h.simTime+=a;if(h.simTime>h.fixedTimeStep){var p=Math.floor(h.simTime/h.fixedTimeStep);h.simTime-=p*h.fixedTimeStep}if(p){p=Math.min(p,h.maxSubSteps);for(f=0;fthis._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 Ib,ra,jf,Ei,Fi;Vb.prototype=Object.create(I.prototype);Vb.prototype.constructor=Vb;Object.defineProperty(Vb.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(),ra.setValue(a.x,a.y,a.z),b.setLinearVelocity(ra),this._linearVelocity.copy(a))}});Object.defineProperty(Vb.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(),ra.setValue(a.x,a.y,a.z),b.setAngularVelocity(ra),this._angularVelocity.copy(a))}});Object.assign(Vb.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(Ib);b=this.system.createBody(c, b,Ib);b.setRestitution(this.restitution);b.setFriction(this.friction);b.setDamping(this.linearDamping,this.angularDamping);"dynamic"===this.type?(c=this.linearFactor,ra.setValue(c.x,c.y,c.z),b.setLinearFactor(ra),c=this.angularFactor,ra.setValue(c.x,c.y,c.z),b.setAngularFactor(ra)):"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 ie: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 U?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,ra),a.setMassProps(c,ra),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&&(ra.setValue(c.x,c.y,c.z),a.setLinearFactor(ra))},onSetAngularFactor:function(a,b,c){(a=this.data.body)&&"dynamic"===this.type&&(ra.setValue(c.x,c.y,c.z),a.setAngularFactor(ra))},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=Gi,this.data.mask=qg),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 Qd,Rd,dd={},Mf={},Lk="enabled type mass linearDamping angularDamping linearFactor angularFactor friction restitution group mask body".split(" ");yd.prototype= Object.create(B.prototype);yd.prototype.constructor=yd;I._buildAccessors(Vb.prototype,Lk);Object.assign(yd.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)}Qd=new Ammo.btVector3;Rd=new Ammo.btVector3;this.contactPointPool=new pg(Jk,1);this.contactResultPool=new pg(Kk,1);this.singleContactResultPool=new pg(Ik,1);B.bind("update",this.onUpdate,this)}else B.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,g=c.length;edd[d].others.indexOf(b)&&(dd[d].others.push(b),c=!0);Mf[d]=Mf[d]||{others:[],entity:a};Mf[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 g=this.contactPointPool.allocate();g.localPoint.set(b.x(),b.y(),b.z());g.localPointOther.set(c.x(),c.y(),c.z());g.point.set(d.x(),d.y(),d.z());g.pointOther.set(e.x(),e.y(),e.z()); g.normal.set(a.x(),a.y(),a.z());return g},_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 g=this.contactPointPool.allocate();g.localPointOther.set(b.x(),b.y(),b.z());g.localPoint.set(c.x(),c.y(),c.z());g.pointOther.set(d.x(),d.y(),d.z());g.point.set(e.x(),e.y(),e.z());g.normal.set(a.x(),a.y(),a.z());return g},_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 dd)if(dd.hasOwnProperty(a)){var b=Mf[a],c=dd[a],d=c.entity,e=d.collision,g=d.rigidbody;c=c.others;for(var f=c.length;f--;){var l=c[f];if(!b||0>b.others.indexOf(l))c.splice(f,1),d.trigger?(e&&e.fire("triggerleave", l),l.rigidbody&&l.rigidbody.fire("triggerleave",d)):l.trigger||(g&&g.fire("collisionend",l),e&&e.fire("collisionend",l))}0===c.length&&delete dd[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(); Mf={};for(var c=0;c=c.length){for(a=0;aa&&(c=d-1);return b};Wb.prototype._doSort=function(a,b){var c=this._sortBy;return a[c]-b[c]};Wb.prototype.insert=function(a){var b=this._binarySearch(a);this.items.splice(b,0,a);this.length++;this.loopIndex>=b&&this.loopIndex++}; Wb.prototype.append=function(a){this.items.push(a);this.length++};Wb.prototype.remove=function(a){a=this.items.indexOf(a);0>a||(this.items.splice(a,1),this.length--,this.loopIndex>=a&&this.loopIndex--)};Wb.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))};Qa.prototype=Object.create(I.prototype);Qa.prototype.constructor=Qa;Qa.scriptMethods={initialize:"initialize",postInitialize:"postInitialize", update:"update",postUpdate:"postUpdate",swap:"swap"};Object.assign(Qa.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&&(g=b.ind);this._insertScriptInstance(a,g,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,Qa.scriptMethods.initialize)),a.enabled&&!a._postInitialized&&(a._postInitialized=!0,a.postInitialize&&this._scriptMethod(a,Qa.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,Qa.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;for(d in a._scriptsIndex){var e=this.system.app.scripts.get(d);if(e){var g=a._scriptsIndex[d];if(g&&g.instance){var f=c[d].__attributesRaw, l=c[d].__attributes;if(f||l){g=g.instance.__attributes;for(var h in g)if(g[h]){var r=e.attributes.get(h);if(r&&"entity"===r.type)if(r.array){var m=g[h];if(r=m.length){m=m.slice();for(var n=0;n=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(Qa.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(Qa.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(!xb.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 hh=0;ke.prototype=Object.create(B.prototype);ke.prototype.constructor=ke;Object.assign(ke.prototype,{initializeComponentData:function(a,b){a._executionOrder=hh++;this._components.append(a);hh>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-5this._getViewportSize(a)},_contentPositionToScrollValue:function(a){var b=this._getMaxOffset(0),c= this._getMaxOffset(1);zj.x=0===b?0:a.x/b;zj.y=0===c?0:a.y/-c;return zj},_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(c){c.element&&c.element.useInput&&(a._disabledContentInputEntities.push(c),c.element.useInput=!1);c=c.children;var d;var e=0;for(d=c.length;ea))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}})):Wd()?(f.SoundInstance=function(a,b,c){G.call(this);c=c||{};this._volume=void 0!==c.volume?H.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()},f.SoundInstance.prototype=Object.create(G.prototype),f.SoundInstance.prototype.constructor=f.SoundInstance,Object.assign(f.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(f.SoundInstance.prototype,"volume",{get:function(){return this._volume},set:function(a){this._volume=a=H.clamp(a,0,1);this.source&&(this.source.volume=a*this._manager.volume)}}),Object.defineProperty(f.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(f.SoundInstance.prototype,"loop",{get:function(){return this._loop},set:function(a){this._loop=!!a;this.source&&(this.source.loop=this._loop)}}),Object.defineProperty(f.SoundInstance.prototype,"sound",{get:function(){return this._sound},set:function(a){this.stop();this._sound=a}}),Object.defineProperty(f.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))}})):f.SoundInstance=function(){};Object.assign(f.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(f.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(f.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(f.SoundInstance.prototype,"isPlaying",{get:function(){return 0===this._state}});Object.defineProperty(f.SoundInstance.prototype,"isPaused",{get:function(){return 1===this._state}});Object.defineProperty(f.SoundInstance.prototype,"isStopped",{get:function(){return 2===this._state}});Object.defineProperty(f.SoundInstance.prototype,"isSuspended",{get:function(){return this._suspended}});if(Mc())f.SoundInstance3d= function(a,b,c){f.SoundInstance.call(this,a,b,c);c=c||{};this._position=new p;c.position&&(this.position=c.position);this._velocity=new p;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"},f.SoundInstance3d.prototype=Object.create(f.SoundInstance.prototype), f.SoundInstance3d.prototype.constructor=f.SoundInstance3d,Object.assign(f.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(f.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(f.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(f.SoundInstance3d.prototype,"maxDistance",{get:function(){return this.panner.maxDistance},set:function(a){this.panner.maxDistance=a}}),Object.defineProperty(f.SoundInstance3d.prototype,"refDistance",{get:function(){return this.panner.refDistance},set:function(a){this.panner.refDistance= a}}),Object.defineProperty(f.SoundInstance3d.prototype,"rollOffFactor",{get:function(){return this.panner.rolloffFactor},set:function(a){this.panner.rolloffFactor=a}}),Object.defineProperty(f.SoundInstance3d.prototype,"distanceModel",{get:function(){return this.panner.distanceModel},set:function(a){this.panner.distanceModel=a}});else if(Wd()){var Bj=new p;f.SoundInstance3d=function(a,b,c){f.SoundInstance.call(this,a,b,c);c=c||{};this._position=new p;c.position&&(this.position=c.position);this._velocity= new p;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"};f.SoundInstance3d.prototype=Object.create(f.SoundInstance.prototype);f.SoundInstance3d.prototype.constructor=f.SoundInstance3d;Object.defineProperty(f.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;Bj=Bj.sub2(b,this._position);b=Bj.length();if(bc)a=0;else{var g=0;"linear"===e?g=1-d*(b-a)/(c-a):e===gf?g=a/(a+d*(b-a)):"exponential"===e&&(g=Math.pow(b/a,-d));a=H.clamp(g,0,1)}this.source.volume=this.volume*a*this._manager.volume}}});Object.defineProperty(f.SoundInstance3d.prototype, "velocity",{get:function(){return this._velocity},set:function(a){this._velocity.copy(a)}});Object.defineProperty(f.SoundInstance3d.prototype,"maxDistance",{get:function(){return this._maxDistance},set:function(a){this._maxDistance=a}});Object.defineProperty(f.SoundInstance3d.prototype,"refDistance",{get:function(){return this._refDistance},set:function(a){this._refDistance=a}});Object.defineProperty(f.SoundInstance3d.prototype,"rollOffFactor",{get:function(){return this._rollOffFactor},set:function(a){this._rollOffFactor= a}});Object.defineProperty(f.SoundInstance3d.prototype,"distanceModel",{get:function(){return this._distanceModel},set:function(a){this._distanceModel=a}})}else f.SoundInstance3d=function(){};var Ya={volume:0,pitch:0,loop:!1,startTime:0,duration:0,position:new p,maxDistance:0,refDistance:0,rollOffFactor:0,distanceModel:0,onPlay:null,onPause:null,onResume:null,onStop:null,onEnd:null};Ka.prototype=Object.create(G.prototype);Ka.prototype.constructor=Ka;Object.assign(Ka.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(b){var c=a._playWhenLoaded;a.sound=b;c&&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?H.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(kb.prototype,"spriteAsset",{get:function(){return this._spriteAsset},set:function(a){var b=this._component.system.app.assets,c=a;a instanceof V&& (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(kb.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(kb.prototype, "frame",{get:function(){return this._frame},set:function(a){this._setFrame(a);this._setTime(this._frame/(this.fps||Number.MIN_VALUE))}});Object.defineProperty(kb.prototype,"isPlaying",{get:function(){return this._playing}});Object.defineProperty(kb.prototype,"isPaused",{get:function(){return this._paused}});Object.defineProperty(kb.prototype,"duration",{get:function(){return this._sprite?this._sprite.frameKeys.length/Math.abs(this.fps||Number.MIN_VALUE):0}});Object.defineProperty(kb.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 ua=function(a,b){I.call(this,a,b);this._type="simple";this._material=a.defaultMaterial;this._color=new N(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 L(1,1);this._outerScaleUniform=new Float32Array(2); this._innerOffset=new T;this._innerOffsetUniform=new Float32Array(4);this._atlasRect=new T;this._atlasRectUniform=new Float32Array(4);this._batchGroupId=-1;this._batchGroup=null;this._node=new Z;this._model=new hb;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 kb(this,{name:this.entity.name,fps:0, loop:!1,spriteAsset:null})};ua.prototype=Object.create(I.prototype);ua.prototype.constructor=ua;Object.assign(ua.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(Ua.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(Ua.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===sg){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 Oc(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],g[d]);this.renderLines([g[0],g[1],g[1],g[2],g[2],g[3],g[3],g[0],g[4],g[5],g[5],g[6],g[6],g[7],g[7],g[4],g[0],g[4],g[1],g[5],g[2],g[6],g[3],g[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();gd.worldTransform=c;gd._dirtyWorld=gd._dirtyNormal=!1;a=new na(gd,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 Ha(this.graphicsDevice,[{semantic:"POSITION", components:3,type:6}]);d=new Ta(this.graphicsDevice,d,4);var e=new Eb(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 gb(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}gd.worldTransform=a;gd._dirtyWorld=gd._dirtyNormal=!1;a=new na(gd,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;db.metalness?1:0;a.glossTint=1;a.emissiveTint=g;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&&!f;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=f;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};Jb.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,g=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),f=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,l=(!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=g;a.rgbmReflection=f;a.hdrReflection=l;a.useRgbm=f||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};Jb.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)};Jb.prototype._updateTexOptions=function(a,b,c,d,e,g,f){var k=c+"Map",h=c+"VertexColor",r=c+"VertexColorChannel",m=k+"Channel",n=k+"Transform",q=k+"Uv";"light"!==c&&(a[k]=!1,a[m]="",a[n]=0,a[q]=0);a[h]=!1;a[r]="";var p="opacity"===c;if(p&&3===b.blendType&&0===b.alphaTest&&!b.alphaToCoverage)return a;if(!f||p)"height"!==c&&b[h]&&g&&(a[h]=b[h],a[r]=b[r],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[n]=this._getMapTransformID(b[n],b[q]),a[m]=b[m],a[q]=b[q]))};Jb.prototype._collectLights=function(a,b,c,d,e){var g;for(g=0;gh;h++)e[h]=f?Math.pow(c.data[h],2.2):c.data[h],d&&(e[h]*= a[l]);return{name:"material_"+b,value:e}};d&&(a[l]=1,Object.defineProperty(ea.prototype,f,{get:function(){return this[l]},set:function(a){var b=this[l];(0===b||1===b)^(0===a||1===a)&&(this.dirtyShader=!0);this.dirtyColor=!0;this[l]=a}}),La.push(f),Sd[f]=function(a,c,d){c=d?a[g]:new Float32Array(3);d=!1;a.useGammaTonemap&&(d=(a._scene||Y.getApplication().scene).gammaCorrection);for(var f=0;3>f;f++)c[f]=d?Math.pow(a[e].data[f],2.2):a[e].data[f],c[f]*=a[l];return{name:"material_"+b,value:c}})},nb=function(a, b,c,d){var e="_"+b;a[e]=c;Object.defineProperty(ea.prototype,b,{get:function(){return this[e]},set:function(a){var b=this[e];b!==a&&(this[e]=a,0===b||1===b||0===a||1===a)&&(this.dirtyShader=!0)}});La.push(b);Sd[b]=void 0!==d?d:function(a,c,d){return{name:"material_"+b,value:c}}},cc=function(a,b,c){var d="_"+b;a[d]=null;Object.defineProperty(ea.prototype,b,{get:function(){return this[d]},set:function(a){!!this[d]^!!a&&(this.dirtyShader=!0);this[d]=a}});La.push(b);Sd[b]=c},dc=function(a,b,c){Object.defineProperty(ea.prototype, c,{get:function(){return this[b]},set:function(a){this[b]=a}})},dp=function(a){Object.defineProperty(ea.prototype,"chunks",{get:function(){this.dirtyShader=!0;return this._chunks},set:function(a){this.dirtyShader=!0;this._chunks=a}});La.push("chunks")},xa=function(a,b,c){var d="_"+b;a[d]=c;Object.defineProperty(ea.prototype,b,{get:function(){return this[d]},set:function(a){this[d]!==a&&(this.dirtyShader=!0);this[d]=a}});La.push(b)},tm=function(){};tm.prototype.copy=function(a){for(var b in a)a.hasOwnProperty(b)&& "copy"!==b&&(this[b]=a[b])};Object.assign(ea.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,g){!this._colorProcessed&&this._scene&&(this._colorProcessed=!0,this._processColor());var f=a.useTexCubeLod,l=!a.extTextureLod;if(this.useSkybox){var h=b._skyboxPrefiltered[0];var p=b._skyboxPrefiltered[1];var m=b._skyboxPrefiltered[2];var n= b._skyboxPrefiltered[3];var q=b._skyboxPrefiltered[4];var u=b._skyboxPrefiltered[5]}h=this.prefilteredCubeMap128||h;p=this.prefilteredCubeMap64||p;m=this.prefilteredCubeMap32||m;n=this.prefilteredCubeMap16||n;q=this.prefilteredCubeMap8||q;u=this.prefilteredCubeMap4||u;if(h){var t=h&&p&&m&&n&&q&&u;if(l&&t){if(!h.dpAtlas){f=[h,p,m,n,q,u];l=new T;u=new T;p=4*f[0].width;q=P;q=q.createShaderFromCode(a,q.fullscreenQuadVS,q.dpAtlasQuadPS,"dpAtlasQuad");m=a.scope.resolve("source");t=a.scope.resolve("params"); var x=new M(a,{type:f[0].type,format:f[0].format,width:p,height:p,mipmaps:!1});x.name="paraboloid";for(var v=new ka(a,x,{depth:!1}),w=(p+2)/p-1,y=0;6>y;y++){var z=a;var A=f[y],B=y,C=P;C=C.createShaderFromCode(z,C.fullscreenQuadVS,(A.fixCubemapSeams?C.fixCubemapSeamsStretchPS:C.fixCubemapSeamsNonePS)+C.genParaboloidPS,"genParaboloid");var D=z.scope.resolve("source"),E=z.scope.resolve("params"),G=new T,I=A.width,J=A.format;I=2*Math.max(I,8);I=new M(z,{type:A.type,format:J,width:2*I,height:I,mipmaps:!1}); I.name="paraboloid";J=new ka(z,I,{depth:!1});G.x=B;G.y=1;D.setValue(A);E.setValue(G.data);Ea(z,J,C);z=I;m.setValue(z);z=l;A=y;z.x=.5*H.clamp(A-2,0,1);A-=6*z.x;B=1-z.x;z.y=Math.min(.5*A,.75)*B+z.x;z.z=(1-.5*H.clamp(A,0,1))*B;z.w=.5*z.z;z=1/z.z;u.x=z*w;u.y=2*u.x;u.x+=1;u.y+=1;t.setValue(u.data);l.x*=p;l.y*=p;l.z*=p;l.w*=p;Ea(a,v,q,l)}h.dpAtlas=x;h.sh=Uk(n)}this.dpAtlas=h.dpAtlas;this.ambientSH=h.sh;this._setParameter("ambientSH[0]",this.ambientSH);this._setParameter("texture_sphereMap",this.dpAtlas)}else f? 6>h._levels.length?t?this._setParameter("texture_prefilteredCubeMap128",h):console.log("Can't use prefiltered cubemap: "+t+", "+f+", "+h._levels):this._setParameter("texture_prefilteredCubeMap128",h):t?(this._setParameter("texture_prefilteredCubeMap128",h),this._setParameter("texture_prefilteredCubeMap64",p),this._setParameter("texture_prefilteredCubeMap32",m),this._setParameter("texture_prefilteredCubeMap16",n),this._setParameter("texture_prefilteredCubeMap8",q),this._setParameter("texture_prefilteredCubeMap4", u)):console.log("Can't use prefiltered cubemap: "+t+", "+f+", "+h._levels)}f=aa.standard;f=(n=1=e)?f.optionsContextMin:f.optionsContext;n?this.shaderOptBuilder.updateMinRef(f,a,b,this,c,d,e,g,h):this.shaderOptBuilder.updateRef(f,a,b,this,c,d,e,g,h);this.onUpdateShader&&(f=this.onUpdateShader(f));this.shader=a.getProgramLibrary().getProgram("standard",f);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;lh(a,"ambient",new N(.7,.7,.7));lh(a,"diffuse",new N(1,1,1));lh(a,"specular",new N(0,0,0));lh(a,"emissive",new N(0,0,0),!0);nb(a,"shininess",25,function(a,b){return{name:"material_shininess",value:0===a.shadingModel?Math.pow(2,.11*b):.01*b}});nb(a,"heightMapFactor",1,function(a,b){return{name:"material_heightMapFactor",value:.025*b}});nb(a,"opacity",1);nb(a,"alphaTest",0);nb(a,"bumpiness",1);nb(a,"normalDetailMapBumpiness",1);nb(a,"reflectivity",1);nb(a,"occludeSpecularIntensity", 1);nb(a,"refraction",0);nb(a,"refractionIndex",1/1.5);nb(a,"metalness",1);nb(a,"anisotropy",0);nb(a,"clearCoat",0);nb(a,"clearCoatGlossiness",1);nb(a,"aoUvSet",0,null);cc(a,"ambientSH",function(a,b,e){return{name:"ambientSH[0]",value:b}});cc(a,"cubeMapProjectionBox",function(a,b,e){var c=e?a.cubeMapMinUniform:new Float32Array(3);a=e?a.cubeMapMaxUniform:new Float32Array(3);c[0]=b.center.x-b.halfExtents.x;c[1]=b.center.y-b.halfExtents.y;c[2]=b.center.z-b.halfExtents.z;a[0]=b.center.x+b.halfExtents.x; a[1]=b.center.y+b.halfExtents.y;a[2]=b.center.z+b.halfExtents.z;return[{name:"envBoxMin",value:c},{name:"envBoxMax",value:a}]});dp();xa(a,"ambientTint",!1);xa(a,"diffuseTint",!1);xa(a,"specularTint",!1);xa(a,"emissiveTint",!1);xa(a,"fastTbn",!1);xa(a,"specularAntialias",!1);xa(a,"useMetalness",!1);xa(a,"enableGGXSpecular",!1);xa(a,"occludeDirect",!1);xa(a,"normalizeNormalMap",!0);xa(a,"conserveEnergy",!0);xa(a,"occludeSpecular",1);xa(a,"shadingModel",1);xa(a,"fresnelModel",0);xa(a,"cubeMapProjection", 0);xa(a,"customFragmentShader",null);xa(a,"forceFragmentPrecision",null);xa(a,"useFog",!0);xa(a,"useLighting",!0);xa(a,"useGammaTonemap",!0);xa(a,"useSkybox",!0);xa(a,"forceUv1",!1);xa(a,"pixelSnap",!1);xa(a,"twoSidedLighting",!1);xa(a,"nineSlicedMode",void 0);Cb(a,"diffuse",0,3,"",!0);Cb(a,"specular",0,3,"",!0);Cb(a,"emissive",0,3,"",!0);Cb(a,"normal",0,-1,"",!1);Cb(a,"metalness",0,1,"",!0);Cb(a,"gloss",0,1,"",!0);Cb(a,"opacity",0,1,"a",!0);Cb(a,"height",0,1,"",!1);Cb(a,"ao",0,1,"",!0);Cb(a,"light", 1,3,"",!0);Cb(a,"msdf",0,3,"",!1);Cb(a,"diffuseDetail",0,3,"",!1,!0);Cb(a,"normalDetail",0,-1,"",!1);cc(a,"cubeMap");cc(a,"sphereMap");cc(a,"dpAtlas");cc(a,"prefilteredCubeMap128");cc(a,"prefilteredCubeMap64");cc(a,"prefilteredCubeMap32");cc(a,"prefilteredCubeMap16");cc(a,"prefilteredCubeMap8");cc(a,"prefilteredCubeMap4");dc(a,"diffuseTint","diffuseMapTint");dc(a,"specularTint","specularMapTint");dc(a,"emissiveTint","emissiveMapTint");dc(a,"aoVertexColor","aoMapVertexColor");dc(a,"diffuseVertexColor", "diffuseMapVertexColor");dc(a,"specularVertexColor","specularMapVertexColor");dc(a,"emissiveVertexColor","emissiveMapVertexColor");dc(a,"metalnessVertexColor","metalnessMapVertexColor");dc(a,"glossVertexColor","glossMapVertexColor");dc(a,"opacityVertexColor","opacityMapVertexColor");dc(a,"lightVertexColor","lightMapVertexColor");for(var b=0;b=a?this._defaultStdMatOptionMin:this._defaultStdMatOption};yb.prototype.precompile=function(a){if(a)for(var b=Array(a.length),c=0;cb||d>b){var e=b/Math.max(c,d),g=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 "+g+", "+e+".");b=document.createElement("canvas");b.width=g;b.height=e;b.getContext("2d").drawImage(a, 0,0,c,d,0,0,g,e);return b}return a},ab=function(a,b){G.call(this);var c;this.canvas=a;this.indexBuffer=this.shader=null;this.vertexBuffers=[];this.vbOffsets=[];this._enableAutoInstancing=!1;this.autoInstancingMaxObjects=16384;this.attributesInvalidated=!0;this.boundElementBuffer=this.boundBuffer=this.defaultFramebuffer=null;this.instancedAttribs={};this.enabledAttributes={};this.activeFramebuffer=this.transformFeedbackBuffer=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.contextLost=!1;this._contextLostHandler=function(a){a.preventDefault();this.contextLost=!0;this.fire("devicelost")}.bind(this);this._contextRestoredHandler=function(){this.initializeContext();this.contextLost=!1;this.fire("devicerestored")}.bind(this); a.addEventListener("webglcontextlost",this._contextLostHandler,!1);a.addEventListener("webglcontextrestored",this._contextRestoredHandler,!1);var d=b&&void 0!==b.preferWebGl2?b.preferWebGl2:!0,e=d?["webgl2","experimental-webgl2","webgl","experimental-webgl"]:["webgl","experimental-webgl"],g=null;b=b||{};b.stencil=!0;for(c=0;cc;break}}if(!g)throw Error("WebGL not supported");this.gl=g;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:Tk(g,g.FLOAT):!1;this.textureHalfFloatRenderable=this.extTextureHalfFloat?this.webgl2?!!this.extColorBufferFloat: Tk(g,this.extTextureHalfFloat.HALF_FLOAT_OES):!1;this.supportsMorphTargetTexturesCore="highp"===this.maxPrecision&&2<=this.maxVertexTextures;this._textureHalfFloatUpdatable=this._textureFloatHighPrecision=void 0;this.createGrabPass(b.alpha);Ha.init(this)};ab.prototype=Object.create(G.prototype);ab.prototype.constructor=ab;Object.assign(ab.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,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&&1f;f++)a._levelsUpdated[0][f]&&(e=d[f],e instanceof HTMLImageElement&&(e.width>this.maxCubeMapSize||e.height>this.maxCubeMapSize)&&(e=um(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+f,c,a._glInternalFormat,a._glFormat,a._glPixelType,e));else for(e=1/Math.pow(2,c),f=0;6>f;f++)if(a._levelsUpdated[0][f]){var l=d[f];a._compressed?b.compressedTexImage2D(b.TEXTURE_CUBE_MAP_POSITIVE_X+f,c,a._glInternalFormat,Math.max(a._width*e,1),Math.max(a._height*e,1),0,l):(this.setUnpackFlipY(!1),this.setUnpackPremultiplyAlpha(a._premultiplyAlpha),b.texImage2D(b.TEXTURE_CUBE_MAP_POSITIVE_X+f,c,a._glInternalFormat,Math.max(a._width*e,1),Math.max(a._height* e,1),0,a._glFormat,a._glPixelType,l))}}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=um(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]=(b>>8&255)/255;e.pickColor[2]=(b&255)/255;l.setValue(e.pickColor);d.setBlending(!1)}});this.layerComp=new qa;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,p=b.layers.subLayerList;for(b=0;bn)){m.overrideClear&&m._clearDepthBuffer&&!m._pickerCleared&&(this.meshInstances.push(this.clearDepthCommand),m._pickerCleared=!0);n=(n=p[b])?m.instances.transparentMeshInstances:m.instances.opaqueMeshInstances;var q=n.length;for(m=0;m=c+this._target.clientWidth||a.clientY=b+this._target.clientHeight?null:{x:a.clientX-c,y:a.clientY-b}}});cb.prototype.attach=function(a){this._element=a; this._keyboard&&this._keyboard.attach(a);this._mouse&&this._mouse.attach(a)};cb.prototype.detach=function(){this._keyboard&&this._keyboard.detach();this._mouse&&this._mouse.detach();this._element=null};cb.prototype.disableContextMenu=function(){this._mouse||this._enableMouse();this._mouse.disableContextMenu()};cb.prototype.enableContextMenu=function(){this._mouse||this._enableMouse();this._mouse.enableContextMenu()};cb.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]=[]};cb.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}]};cb.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}]};cb.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}]};cb.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(d,f,k,l){switch(f){case "mousex":d._mouse.on("mousemove",function(a){d._axesValues[b][c]=a.dx/10});break;case "mousey":d._mouse.on("mousemove",function(a){d._axesValues[b][c]=a.dy/10});break;case "key":d._axes[b].push(function(){return d._keyboard.isPressed(l)?k:0});break;case "padrx":d._axes[b].push(function(){return d._gamepads.getAxis(a.pad,2)});break;case "padry":d._axes[b].push(function(){return d._gamepads.getAxis(a.pad,3)});break;case "padlx":d._axes[b].push(function(){return d._gamepads.getAxis(a.pad, 0)});break;case "padly":d._axes[b].push(function(){return d._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)};cb.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};cb.prototype._enableMouse=function(){this._mouse=new zb;if(!this._element)throw Error("Controller must be attached to an Element"); this._mouse.attach(this._element)};cb.prototype._enableKeyboard=function(){this._keyboard=new bb;if(!this._element)throw Error("Controller must be attached to an Element");this._keyboard.attach(this._element)};var Rb,hd,wm=new p,xm=new p,id=new Jc,ym=new Jc,Ej=new Jc;id.end=new p;ym.end=new p;Ej.end=new p;var se=new p,zg=new p,Pi=new p,Yk=new p,Qi=new p,Ag=new p,Zk=new p,Fj=new L,Of=new p,mh=new p,nh=new p,Pf=new p,zm=new p,Am=new p,Bm=new p,Cm=new p,gp=new T;Object.assign(Zc.prototype,{stopPropagation:function(){this._stopPropagation= !0;this.event&&(this.event.stopImmediatePropagation(),this.event.stopPropagation())}});$c.prototype=Object.create(Zc.prototype);$c.prototype.constructor=$c;Ac.prototype=Object.create(Zc.prototype);Ac.prototype.constructor=Ac;Zb.prototype=Object.create(Zc.prototype);Zb.prototype.constructor=Zb;Object.assign(lf.prototype,{attach:function(a){this._attached&&(this._attached=!1,this.detach());this._target=a;this._attached=!0;a=va.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&&va.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=va.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&&!zb.isPointerLocked()&&(this._calcMouseCoords(a), null!==Rb&&this._onElementMouseEvent("mouseup",a))},_handleDown:function(a){this._enabled&&!zb.isPointerLocked()&&(this._calcMouseCoords(a),null!==Rb&&this._onElementMouseEvent("mousedown",a))},_handleMove:function(a){this._enabled&&(this._calcMouseCoords(a),null!==Rb&&(this._onElementMouseEvent("mousemove",a),this._lastX=Rb,this._lastY=hd))},_handleWheel:function(a){this._enabled&&(this._calcMouseCoords(a),null!==Rb&&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],k=0;var l=0;for(e=a.changedTouches.length;l=c+this._target.clientWidth||a.clientY=b+this._target.clientHeight?hd=Rb=null:(Rb=a.clientX-c,hd=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,k=0,l=this._elements.length;k=h&&a<=h+k&&b<=c&&b>=p?(d.origin.set(e*(a-h)/k,f-f*(b-p)/l,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,k=c.rect.z*e,l=c.rect.w*f,h=c.rect.x*e,p=(1-c.rect.y)* f,m=p-l,n=b;return a>=h&&a<=h+k&&b<=p&&n>=m?(a=e*(a-h)/k,n=f*(n-m)/l,c.screenToWorld(a,n,c.nearClip,wm),c.screenToWorld(a,n,c.farClip,xm),d.origin.copy(wm),d.direction.set(0,0,-1),d.end.copy(xm),!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 Tn(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||Y.getApplication()},set:function(a){this._app=a}});var Dm={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"]}},Em={"Product: 0268":"PS3"};Object.assign(Ri.prototype,{update:function(){var a,b;var c=0;for(b=this.current.length;cz&&(z=this.fontSize*this.fontSize/A,f.font=this.fontWeight+" "+z.toString()+"px "+this.fontName,A=this.fontSize);this.renderCharacter(f,b,v+t,w+x,e);this._addChar(this.data,b,y,v,w,p,u,this.padding+(this.glyphSize-A)/2,-this.padding+n[b].descent-m,A,a-1,c,d);v+=p;v+p>c&&(v=0,w+=u,w+u>d&&(this.textures[a-1].upload(),a++,w=0,a>h?(b=document.createElement("canvas"), b.height=d,b.width=c,f=this._getAndClearContext(b,k),y=new M(this.app.graphicsDevice,{format:7,autoMipmap:!0}),y.name="font-atlas",y.setSource(b),y.minFilter=5,y.magFilter=1,y.addressU=1,y.addressV=1,this.textures.push(y)):(b=this.textures[a-1].getSource(),f=this._getAndClearContext(b,k))))}this.textures[a-1].upload();if(aw;w++){var A=new ka(b,z,{face:w,depth:!1});q.x=w;q.y=0;m.setValue(c);n.setValue(q.data);Ea(b,A,p);vg(b,A,w)}c=z}if(128w;w++)A=new ka(b,z,{face:w,depth:!1}),q.x=w,q.y=C,q.z=u,q.w=h?3:0,m.setValue(c),n.setValue(q.data),Ea(b,A,p),y===B-1&&f&& vg(b,A,w);c=z}}a.sourceCubemap=c;z=null;if(!h&&a.filteredFixedRgbm)for(z=new M(b,{cubemap:!0,type:"rgbm",format:7,width:u,height:u,mipmaps:!1}),z.name="prefiltered-cube",w=0;6>w;w++)A=new ka(b,z,{face:w,depth:!1}),q.x=w,q.w=2,m.setValue(c),n.setValue(q.data),Ea(b,A,p),vg(b,A,w);u=0===d?1:2048;A=0===d?0:-1;t[A]=[];for(y=0;7>y;y++)for(p=A;pp?l:"rgbm",format:2>p?k:7,fixCubemapSeams:1===p||3===p,width:v[y],height:v[y],mipmaps:!1}),t[p][y].name= "prefiltered-cube");for(p=A;py;y++)for(w=0;6>w;w++)A=new ka(b,t[p][y],{face:w,depth:!1}),q.x=w,q.y=0>p?u:x[y],q.z=v[y],q.w=h?3:p,m.setValue(0===y?c:0===d?t[0][y-1]:t[-1][y-1]),n.setValue(q.data),Ea(b,A,e),f&&vg(b,A,w);a.filtered=t[0];if(f&&a.singleFilteredFixed){c=[c].concat(a.filteredFixed);l=new M(b,{cubemap:!0,type:l,fixCubemapSeams:!0,format:k,width:128,height:128,addressU:1,addressV:1});l.name="prefiltered-cube";for(y=0;y