12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757 |
- ;(function (root, factory) {
- if (typeof define === 'function' && define.amd) {
- define([], factory);
- } else if (typeof module === 'object' && module.exports) {
- try {
- var JSDOM = require("jsdom").JSDOM;
- var DOM = new JSDOM();
- var window = DOM.window;
- var navigator = window.navigator;
- module.exports = factory(window, navigator);
- } catch (error) {
- module.exports = factory();
- }
- } else {
- root.pc = factory(root, root.navigator);
- }
- }(this, function (_window, _navigator) {
- window = _window || window;
- navigator = _navigator || navigator;
- /*
- PlayCanvas Engine v1.14.0 revision b9681f3
- http://playcanvas.com
- Copyright 2011-2018 PlayCanvas Ltd. All rights reserved.
- */
- var _typeLookup=function(){for(var f={},b="Array Object Function Date RegExp Float32Array".split(" "),a=0;a<b.length;a++)f["[object "+b[a]+"]"]=b[a].toLowerCase();return f}(),pc={version:"1.14.0",revision:"b9681f3",config:{},common:{},apps:{},data:{},unpack:function(){console.warn("pc.unpack has been deprecated and will be removed shortly. Please update your code.")},makeArray:function(f){var b,a=[],c=f.length;for(b=0;b<c;++b)a.push(f[b]);return a},type:function(f){if(null===
- f)return"null";var b=typeof f;return"undefined"===b||"number"===b||"string"===b||"boolean"===b?b:_typeLookup[Object.prototype.toString.call(f)]},extend:function(f,b){var a,c;for(a in b)c=b[a],"object"==pc.type(c)?f[a]=pc.extend({},c):"array"==pc.type(c)?f[a]=pc.extend([],c):f[a]=c;return f},isDefined:function(f){return void 0!==f}};"undefined"!==typeof exports&&(exports.pc=pc);(function(){if("undefined"!==typeof document){var f=function(a){var c=document.createEvent("CustomEvent");c.initCustomEvent("fullscreenchange",!0,!1,null);a.target.dispatchEvent(c)},b=function(a){var c=document.createEvent("CustomEvent");c.initCustomEvent("fullscreenerror",!0,!1,null);a.target.dispatchEvent(c)};document.addEventListener("webkitfullscreenchange",f,!1);document.addEventListener("mozfullscreenchange",f,!1);document.addEventListener("MSFullscreenChange",f,!1);document.addEventListener("webkitfullscreenerror",
- b,!1);document.addEventListener("mozfullscreenerror",b,!1);document.addEventListener("MSFullscreenError",b,!1);Element.prototype.requestFullscreen=Element.prototype.mozRequestFullScreen?function(){this.mozRequestFullScreen()}:Element.prototype.requestFullscreen||Element.prototype.webkitRequestFullscreen||Element.prototype.msRequestFullscreen;document.exitFullscreen=document.exitFullscreen||document.webkitExitFullscreen||document.mozCancelFullScreen||document.msExitFullscreen;document.hasOwnProperty("fullscreenElement")||
- Object.defineProperty(document,"fullscreenElement",{enumerable:!0,configurable:!1,get:function(){return document.webkitCurrentFullScreenElement||document.webkitFullscreenElement||document.mozFullScreenElement||document.msFullscreenElement}});document.hasOwnProperty("fullscreenEnabled")||Object.defineProperty(document,"fullscreenEnabled",{enumerable:!0,configurable:!1,get:function(){return document.webkitFullscreenEnabled||document.mozFullScreenEnabled||document.msFullscreenEnabled}})}})();Math.log2=Math.log2||function(f){return Math.log(f)*Math.LOG2E};"function"!=typeof Object.assign&&Object.defineProperty(Object,"assign",{value:function(f,b){if(null==f)throw new TypeError("Cannot convert undefined or null to object");for(var a=Object(f),c=1;c<arguments.length;c++){var d=arguments[c];if(null!=d)for(var e in d)Object.prototype.hasOwnProperty.call(d,e)&&(a[e]=d[e])}return a},writable:!0,configurable:!0});(function(){if("undefined"!==typeof navigator&&"undefined"!==typeof document){navigator.pointer=navigator.pointer||navigator.webkitPointer||navigator.mozPointer;var f=function(){var a=document.createEvent("CustomEvent");a.initCustomEvent("pointerlockchange",!0,!1,null);document.dispatchEvent(a)},b=function(){var a=document.createEvent("CustomEvent");a.initCustomEvent("pointerlockerror",!0,!1,null);document.dispatchEvent(a)};document.addEventListener("webkitpointerlockchange",f,!1);document.addEventListener("webkitpointerlocklost",
- f,!1);document.addEventListener("mozpointerlockchange",f,!1);document.addEventListener("mozpointerlocklost",f,!1);document.addEventListener("webkitpointerlockerror",b,!1);document.addEventListener("mozpointerlockerror",b,!1);Element.prototype.requestPointerLock=Element.prototype.mozRequestPointerLock?function(){this.mozRequestPointerLock()}:Element.prototype.requestPointerLock||Element.prototype.webkitRequestPointerLock||Element.prototype.mozRequestPointerLock;!Element.prototype.requestPointerLock&&
- navigator.pointer&&(Element.prototype.requestPointerLock=function(){document.pointerLockElement=this;navigator.pointer.lock(this,f,b)});document.exitPointerLock=document.exitPointerLock||document.webkitExitPointerLock||document.mozExitPointerLock;document.exitPointerLock||(document.exitPointerLock=function(){navigator.pointer&&(document.pointerLockElement=null,navigator.pointer.unlock())})}})();(function(){for(var f=0,b=["ms","moz","webkit","o"],a=0;a<b.length&&!window.requestAnimationFrame;++a)window.requestAnimationFrame=window[b[a]+"RequestAnimationFrame"],window.cancelAnimationFrame=window[b[a]+"CancelAnimationFrame"]||window[b[a]+"CancelRequestAnimationFrame"];window.requestAnimationFrame||(window.requestAnimationFrame=function(a,b){var c=(new Date).getTime(),d=Math.max(0,16-(c-f)),l=window.setTimeout(function(){a(c+d)},d);f=c+d;return l});window.cancelAnimationFrame||(window.cancelAnimationFrame=
- function(a){clearTimeout(a)})})();String.prototype.endsWith||(String.prototype.endsWith=function(f,b){if(void 0===b||b>this.length)b=this.length;return this.substring(b-f.length,b)===f});String.prototype.includes||(String.prototype.includes=function(f,b){"number"!==typeof b&&(b=0);return b+f.length>this.length?!1:-1!==this.indexOf(f,b)});String.prototype.startsWith||(String.prototype.startsWith=function(f,b){return this.substr(!b||0>b?0:+b,f.length)===f});Object.assign(pc,function(){var f=function(b,a,c,d){var e=b&&b.length;3===e||4===e?(this.r=b[0],this.g=b[1],this.b=b[2],this.a=void 0!==b[3]?b[3]:1):(this.r=b||0,this.g=a||0,this.b=c||0,this.a=void 0!==d?d:1)};Object.assign(f.prototype,{clone:function(){return new pc.Color(this.r,this.g,this.b,this.a)},copy:function(b){this.r=b.r;this.g=b.g;this.b=b.b;this.a=b.a;return this},set:function(b,a,c,d){this.r=b;this.g=a;this.b=c;this.a=void 0===d?1:d;return this},lerp:function(b,a,c){this.r=b.r+c*(a.r-
- b.r);this.g=b.g+c*(a.g-b.g);this.b=b.b+c*(a.b-b.b);this.a=b.a+c*(a.a-b.a);return this},fromString:function(b){var a=parseInt(b.replace("#","0x"),16);7<b.length?b=pc.math.intToBytes32(a):(b=pc.math.intToBytes24(a),b[3]=255);this.set(b[0]/255,b[1]/255,b[2]/255,b[3]/255);return this},toString:function(b){var a="#"+(16777216+(Math.round(255*this.r)<<16)+(Math.round(255*this.g)<<8)+Math.round(255*this.b)).toString(16).slice(1);!0===b&&(b=Math.round(255*this.a).toString(16),a=this.a<16/255?a+("0"+b):a+
- b);return a}});return{Color:f}}());pc.guid=function(){return{create:function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(f){var b=16*Math.random()|0;return("x"==f?b:b&3|8).toString(16)})}}}();Object.assign(pc,function(){var f=function(){this._isRunning=!1;this._b=this._a=0};Object.assign(f.prototype,{start:function(){this._isRunning=!0;this._a=pc.now()},stop:function(){this._isRunning=!1;this._b=pc.now()},getMilliseconds:function(){return this._b-this._a}});return{Timer:f,now:window.performance&&window.performance.now&&window.performance.timing?function(){return window.performance.now()}:Date.now}}());Object.assign(pc,function(){return{hashCode:function(f){for(var b=0,a=0,c=f.length;a<c;a++)b=(b<<5)-b+f.charCodeAt(a),b|=0;return b}}}());Object.assign(pc,function(){return{createURI:function(f){var b="";if((f.authority||f.scheme)&&(f.host||f.hostpath))throw Error("Can't have 'scheme' or 'authority' and 'host' or 'hostpath' option");if(f.host&&f.hostpath)throw Error("Can't have 'host' and 'hostpath' option");if(f.path&&f.hostpath)throw Error("Can't have 'path' and 'hostpath' option");f.scheme&&(b+=f.scheme+":");f.authority&&(b+="//"+f.authority);f.host&&(b+=f.host);f.path&&(b+=f.path);f.hostpath&&(b+=f.hostpath);f.query&&(b+="?"+f.query);
- f.fragment&&(b+="#"+f.fragment);return b},URI:function(f){f=f.match(/^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/);this.scheme=f[2];this.authority=f[4];this.path=f[5];this.query=f[7];this.fragment=f[9];this.toString=function(){var b="";this.scheme&&(b+=this.scheme+":");this.authority&&(b+="//"+this.authority);b+=this.path;this.query&&(b+="?"+this.query);this.fragment&&(b+="#"+this.fragment);return b};this.getQuery=function(){var b,a,c={};this.query&&(b=decodeURIComponent(this.query).split("&"),
- b.forEach(function(b,e,g){a=b.split("=");c[a[0]]=a[1]},this));return c};this.setQuery=function(b){var a="",c;for(c in b)b.hasOwnProperty(c)&&(""!==a&&(a+="&"),a+=encodeURIComponent(c)+"="+encodeURIComponent(b[c]));this.query=a}}}}());Object.assign(pc,function(){return{log:{write:function(f){console.log(f)},open:function(){pc.log.write("Powered by PlayCanvas "+pc.version+" "+pc.revision)},info:function(f){console.info("INFO: "+f)},debug:function(f){console.debug("DEBUG: "+f)},error:function(f){console.error("ERROR: "+f)},warning:function(f){console.warn("WARNING: "+f)},alert:function(f){pc.log.write("ALERT: "+f);alert(f)},assert:function(f,b){!1===f&&pc.log.write("ASSERT: "+b)}}}}());
- var logINFO=pc.log.info,logDEBUG=pc.log.debug,logWARNING=pc.log.warning,logERROR=pc.log.error,logALERT=pc.log.alert,logASSERT=pc.log.assert;pc.path=function(){return{delimiter:"/",join:function(){var f,b=arguments.length,a=arguments[0];for(f=0;f<b-1;++f){var c=arguments[f],d=arguments[f+1];if(!pc.isDefined(c)||!pc.isDefined(d))throw Error("undefined argument to pc.path.join");a=d[0]===pc.path.delimiter?d:c&&d&&c[c.length-1]!==pc.path.delimiter&&d[0]!==pc.path.delimiter?a+(pc.path.delimiter+d):a+d}return a},normalize:function(f){var b=f.startsWith(pc.path.delimiter),a=f.endsWith(pc.path.delimiter);f=f.split("/");for(var c=[],d=0;d<f.length;d++)""!==
- f[d]&&"."!==f[d]&&(".."===f[d]&&0<c.length?c=c.slice(0,c.length-2):(0<d&&c.push(pc.path.delimiter),c.push(f[d])));f=c.join("");b||f[0]!==pc.path.delimiter||(f=f.slice(1));a&&f[f.length-1]!==pc.path.delimiter&&(f+=pc.path.delimiter);return f},split:function(f){f=f.split(pc.path.delimiter);var b=f.slice(f.length-1)[0];return[f.slice(0,f.length-1).join(pc.path.delimiter),b]},getBasename:function(f){return pc.path.split(f)[1]},getDirectory:function(f){f=f.split(pc.path.delimiter);return f.slice(0,f.length-
- 1).join(pc.path.delimiter)},getExtension:function(f){var b=f.split("?")[0].split(".").pop();return b!==f?"."+b:""},isRelativePath:function(f){return"/"!==f.charAt(0)&&null===f.match(/:\/\//)},extractPath:function(f){var b=".",a=f.split("/");if(1<a.length)for(!1===pc.path.isRelativePath(f)&&(b=""),f=0;f<a.length-1;++f)b+="/"+a[f];return b}}}();pc.string=function(){function f(a,c){var b=a.length;c=c||0;if(0>c||c>=b)return null;var e=a.charCodeAt(c);return 1<b&&55296<=e&&56319>=e&&(b=a.charCodeAt(c+1),56320<=b&&57343>=b)?{code:1024*(e-55296)+b-56320+65536,"long":!0}:{code:e,"long":!1}}function b(a,c,b){return a?(a=f(a))?(a=a.code,a>=c&&a<=b):!1:!1}return{ASCII_LOWERCASE:"abcdefghijklmnopqrstuvwxyz",ASCII_UPPERCASE:"ABCDEFGHIJKLMNOPQRSTUVWXYZ",ASCII_LETTERS:"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",format:function(a){var c,b,
- e=pc.makeArray(arguments);e.shift();for(c=0;c<e.length;c++)b=new RegExp("\\{"+c+"\\}","gi"),a=a.replace(b,e[c]);return a},startsWith:function(a,c){console.warn("WARNING: startsWith: Function is deprecated. Use String.startsWith instead.");return a.startsWith(c)},endsWith:function(a,c){console.warn("WARNING: endsWith: Function is deprecated. Use String.endsWith instead.");return a.endsWith(c)},toBool:function(a,c){if("true"===a)return!0;if(c){if("false"===a)return!1;throw new TypeError("Not a boolean string");
- }return!1},getCodePoint:function(a,c){var b=f(a,c);return b&&b.code},getCodePoints:function(a){if("string"!==typeof a)throw new TypeError("Not a string");for(var c=0,b=[],e;e=f(a,c);)b.push(e.code),c+=e["long"]?2:1;return b},getSymbols:function(a){if("string"!==typeof a)throw new TypeError("Not a string");for(var c=0,d=a.length,e=[],g=0,l;c<d;){l=g;var k=a,f=c+g;f===k.length-1?g=1:b(k[f],55296,56319)?(g=k.substring(f,f+2),k=k.substring(f+2,f+4),g=b(k,127995,127999)||b(g,127462,127487)&&b(k,127462,
- 127487)?4:2):g=1;g=l+g;l=a[c+g];b(l,8400,8447)&&(l=a[c+g++]);b(l,65024,65039)&&(l=a[c+g++]);l&&8205===l.charCodeAt(0)?g++:(l=a.substring(c,c+g),e.push(l),c+=g,g=0)}return e},fromCodePoint:function(){for(var a=[],c,b,e=0;e<arguments.length;++e)c=Number(arguments[e]),b=c-65536,c=65535<c?[(b>>10)+55296,b%1024+56320]:[c],a.push(String.fromCharCode.apply(null,c));return a.join("")}}}();pc.debug=function(){var f=null,b=null,a=null,c=null;return{display:function(d){f||(f=document.createElement("table"),b=document.createElement("tr"),a=document.createElement("td"),c=document.createElement("td"),f.style.cssText="position:absolute;font-family:sans-serif;font-size:12px;color:#cccccc",f.style.top="0px",f.style.left="0px",f.style.border="thin solid #cccccc",document.body.appendChild(f));f.innerHTML="";for(var e in d){var g=b.cloneNode(),l=a.cloneNode(),k=c.cloneNode();l.textContent=e;k.textContent=
- d[e];g.appendChild(l);g.appendChild(k);f.appendChild(g)}}}}();pc.events={attach:function(f){var b=pc.events;f.on=b.on;f.off=b.off;f.fire=b.fire;f.once=b.once;f.hasEvent=b.hasEvent;f._callbackActive={};return f},on:function(f,b,a){if(!f||"string"!==typeof f||!b)return this;this._callbacks||(this._callbacks={});this._callbacks[f]||(this._callbacks[f]=[]);this._callbackActive||(this._callbackActive={});this._callbackActive[f]&&this._callbackActive[f]===this._callbacks[f]&&(this._callbackActive[f]=this._callbackActive[f].slice());this._callbacks[f].push({callback:b,
- scope:a||this});return this},off:function(f,b,a){if(!this._callbacks)return this;if(this._callbackActive)if(f)this._callbackActive[f]&&this._callbackActive[f]===this._callbacks[f]&&(this._callbackActive[f]=this._callbackActive[f].slice());else for(var c in this._callbackActive)this._callbacks[c]&&this._callbacks[c]===this._callbackActive[c]&&(this._callbackActive[c]=this._callbackActive[c].slice());if(f)if(b){f=this._callbacks[f];if(!f)return this;for(c=f.length;c--;)f[c].callback===b&&(a&&f[c].scope!==
- a||f.splice(c,1))}else this._callbacks[f]&&delete this._callbacks[f];else this._callbacks=null;return this},fire:function(f,b,a,c,d,e,g,l,k){if(!f||!this._callbacks||!this._callbacks[f])return this;var p;this._callbackActive||(this._callbackActive={});this._callbackActive[f]?(this._callbackActive[f]===this._callbacks[f]&&(this._callbackActive[f]=this._callbackActive[f].slice()),p=this._callbacks[f].slice()):this._callbackActive[f]=this._callbacks[f];for(var h=0;(p||this._callbackActive[f])&&h<(p||
- this._callbackActive[f]).length;h++){var n=(p||this._callbackActive[f])[h];n.callback.call(n.scope,b,a,c,d,e,g,l,k);n.callback.once&&(n=this._callbacks[f].indexOf(n),-1!==n&&(this._callbackActive[f]===this._callbacks[f]&&(this._callbackActive[f]=this._callbackActive[f].slice()),this._callbacks[f].splice(n,1)))}p||(this._callbackActive[f]=null);return this},once:function(f,b,a){b.once=!0;this.on(f,b,a);return this},hasEvent:function(f){return this._callbacks&&this._callbacks[f]&&0!==this._callbacks[f].length||
- !1}};Object.assign(pc,function(){var f=function(a){this._index={};this._key=a||null};Object.assign(f.prototype,{addItem:function(a){for(var c=a.tags._list,b=0;b<c.length;b++)this.add(c[b],a)},removeItem:function(a){for(var c=a.tags._list,b=0;b<c.length;b++)this.remove(c[b],a)},add:function(a,c){this._index[a]&&-1!==this._index[a].list.indexOf(c)||(this._index[a]||(this._index[a]={list:[]},this._key&&(this._index[a].keys={})),this._index[a].list.push(c),this._key&&(this._index[a].keys[c[this._key]]=c))},
- remove:function(a,c){if(this._index[a]&&(!this._key||this._index[a].keys[c[this._key]])){var b=this._index[a].indexOf(c);-1!==b&&(this._index[a].list.splice(b,1),this._key&&delete this._index[a].keys[c[this._key]],0===this._index[a].list.length&&delete this._index[a])}},find:function(a){var c=this,b={},e=[],g,l,k,f,h,n=function(a,b){return c._index[a].list.length-c._index[b].list.length};for(g=0;g<a.length;g++){f=a[g];if(f instanceof Array){if(0===f.length)continue;if(1===f.length)f=f[0];else{k=!1;
- for(l=0;l<f.length;l++)if(!this._index[f[l]]){k=!0;break}if(k)continue;f=f.slice(0).sort(n);h=f.slice(1);1===h.length&&(h=h[0]);for(l=0;l<this._index[f[0]].list.length;l++)k=this._index[f[0]].list[l],(this._key?!b[k[this._key]]:-1===e.indexOf(k))&&k.tags.has(h)&&(this._key&&(b[k[this._key]]=!0),e.push(k));continue}}if(f&&"string"===typeof f&&this._index[f])for(l=0;l<this._index[f].list.length;l++)k=this._index[f].list[l],this._key?b[k[this._key]]||(b[k[this._key]]=!0,e.push(k)):-1===e.indexOf(k)&&
- e.push(k)}return e}});var b=function(a){this._index={};this._list=[];this._parent=a;pc.events.attach(this)};Object.assign(b.prototype,{add:function(){var a=!1,c=this._processArguments(arguments,!0);if(!c.length)return a;for(var b=0;b<c.length;b++)this._index[c[b]]||(a=!0,this._index[c[b]]=!0,this._list.push(c[b]),this.fire("add",c[b],this._parent));a&&this.fire("change",this._parent);return a},remove:function(){var a=!1;if(!this._list.length)return a;var c=this._processArguments(arguments,!0);if(!c.length)return a;
- for(var b=0;b<c.length;b++)this._index[c[b]]&&(a=!0,delete this._index[c[b]],this._list.splice(this._list.indexOf(c[b]),1),this.fire("remove",c[b],this._parent));a&&this.fire("change",this._parent);return a},clear:function(){if(this._list.length){var a=this._list.slice(0);this._list=[];this._index={};for(var c=0;c<a.length;c++)this.fire("remove",a[c],this._parent);this.fire("change",this._parent)}},has:function(){return this._list.length?this._has(this._processArguments(arguments)):!1},_has:function(a){if(!this._list.length||
- !a.length)return!1;for(var c=0;c<a.length;c++)if(1===a[c].length){if(this._index[a[c][0]])return!0}else{for(var b=!0,e=0;e<a[c].length;e++)if(!this._index[a[c][e]]){b=!1;break}if(b)return!0}return!1},list:function(){return this._list.slice(0)},_processArguments:function(a,c){var b=[],e=[];if(!a||!a.length)return b;for(var g=0;g<a.length;g++)if(a[g]instanceof Array){c||(e=[]);for(var l=0;l<a[g].length;l++)"string"===typeof a[g][l]&&(c?b.push(a[g][l]):e.push(a[g][l]));!c&&e.length&&b.push(e)}else"string"===
- typeof a[g]&&(c?b.push(a[g]):b.push([a[g]]));return b}});Object.defineProperty(b.prototype,"size",{get:function(){return this._list.length}});return{TagsCache:f,Tags:b}}());Object.assign(pc,function(){var f=function(b,a){this._constructor=b;this._pool=[];this._count=0;this._resize(a)};Object.assign(f.prototype,{_resize:function(b){if(b>this._pool.length)for(var a=this._pool.length;a<b;a++)this._pool[a]=new this._constructor},allocate:function(){this._count>=this._pool.length&&this._resize(2*this._pool.length);return this._pool[this._count++]},freeAll:function(){this._count=0}});return{AllocatePool:f}}());Object.assign(pc,function(){var f={desktop:!1,mobile:!1,ios:!1,android:!1,windows:!1,cocoonjs:!1,xbox:!1,gamepads:!1,touch:!1,workers:!1},b=navigator.userAgent;/(windows|mac os|linux|cros)/i.test(b)&&(f.desktop=!0);/xbox/i.test(b)&&(f.xbox=!0);/(windows phone|iemobile|wpdesktop)/i.test(b)?(f.desktop=!1,f.mobile=!0,f.windows=!0):/android/i.test(b)?(f.desktop=!1,f.mobile=!0,f.android=!0):/ip([ao]d|hone)/i.test(b)&&(f.desktop=!1,f.mobile=!0,f.ios=!0);navigator.isCocoonJS&&(f.cocoonjs=!0);f.touch="ontouchstart"in
- window||"maxTouchPoints"in navigator&&0<navigator.maxTouchPoints;f.gamepads="getGamepads"in navigator;f.workers="undefined"!==typeof Worker;return{platform:f}}());Object.assign(pc,function(){var f=function(){this._list=[];this._index={}};Object.assign(f.prototype,{push:function(b,a){if(this._index[b])throw Error("Key already in index "+b);var c=this._list.push(a)-1;this._index[b]=c},has:function(b){return void 0!==this._index[b]},get:function(b){b=this._index[b];return void 0!==b?this._list[b]:null},remove:function(b){var a=this._index[b];if(void 0!==a){this._list.splice(a,1);delete this._index[b];for(b in this._index){var c=this._index[b];c>a&&(this._index[b]=
- c-1)}return!0}return!1},list:function(){return this._list},clear:function(){this._list.length=0;for(var b in this._index)delete this._index[b]}});return{IndexedList:f}}());pc.math={DEG_TO_RAD:Math.PI/180,RAD_TO_DEG:180/Math.PI,clamp:function(f,b,a){return f>=a?a:f<=b?b:f},intToBytes24:function(f){return[f>>16&255,f>>8&255,f&255]},intToBytes32:function(f){return[f>>24&255,f>>16&255,f>>8&255,f&255]},bytesToInt24:function(f,b,a){f.length&&(a=f[2],b=f[1],f=f[0]);return f<<16|b<<8|a},bytesToInt32:function(f,b,a,c){f.length&&(c=f[3],a=f[2],b=f[1],f=f[0]);return(f<<24|b<<16|a<<8|c)>>>32},lerp:function(f,b,a){return f+(b-f)*pc.math.clamp(a,0,1)},lerpAngle:function(f,b,a){180<
- b-f&&(b-=360);-180>b-f&&(b+=360);return pc.math.lerp(f,b,pc.math.clamp(a,0,1))},powerOfTwo:function(f){return 0!==f&&!(f&f-1)},nextPowerOfTwo:function(f){f--;f|=f>>1;f|=f>>2;f|=f>>4;f|=f>>8;f|=f>>16;f++;return f},random:function(f,b){return Math.random()*(b-f)+f},smoothstep:function(f,b,a){if(a<=f)return 0;if(a>=b)return 1;a=(a-f)/(b-f);return a*a*(3-2*a)},smootherstep:function(f,b,a){if(a<=f)return 0;if(a>=b)return 1;a=(a-f)/(b-f);return a*a*a*(a*(6*a-15)+10)}};Object.assign(pc,function(){var f=function(b,a){b&&2===b.length?(this.x=b[0],this.y=b[1]):(this.x=b||0,this.y=a||0)};Object.assign(f.prototype,{add:function(b){this.x+=b.x;this.y+=b.y;return this},add2:function(b,a){this.x=b.x+a.x;this.y=b.y+a.y;return this},clone:function(){return(new f).copy(this)},copy:function(b){this.x=b.x;this.y=b.y;return this},dot:function(b){return this.x*b.x+this.y*b.y},equals:function(b){return this.x===b.x&&this.y===b.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(b,a,c){this.x=b.x+c*(a.x-b.x);this.y=b.y+c*(a.y-b.y);return this},mul:function(b){this.x*=b.x;this.y*=b.y;return this},mul2:function(b,a){this.x=b.x*a.x;this.y=b.y*a.y;return this},normalize:function(){var b=this.x*this.x+this.y*this.y;0<b&&(b=1/Math.sqrt(b),this.x*=b,this.y*=b);return this},scale:function(b){this.x*=b;this.y*=b;return this},set:function(b,a){this.x=b;this.y=a;return this},sub:function(b){this.x-=
- b.x;this.y-=b.y;return this},sub2:function(b,a){this.x=b.x-a.x;this.y=b.y-a.y;return this},toString:function(){return"["+this.x+", "+this.y+"]"}});Object.defineProperty(f,"ONE",{get:function(){var b=new f(1,1);return function(){return b}}()});Object.defineProperty(f,"RIGHT",{get:function(){var b=new f(1,0);return function(){return b}}()});Object.defineProperty(f,"UP",{get:function(){var b=new f(0,1);return function(){return b}}()});Object.defineProperty(f,"ZERO",{get:function(){var b=new f(0,0);return function(){return b}}()});
- return{Vec2:f}}());Object.assign(pc,function(){var f=function(b,a,c){b&&3===b.length?(this.x=b[0],this.y=b[1],this.z=b[2]):(this.x=b||0,this.y=a||0,this.z=c||0)};Object.assign(f.prototype,{add:function(b){this.x+=b.x;this.y+=b.y;this.z+=b.z;return this},add2:function(b,a){this.x=b.x+a.x;this.y=b.y+a.y;this.z=b.z+a.z;return this},clone:function(){return(new f).copy(this)},copy:function(b){this.x=b.x;this.y=b.y;this.z=b.z;return this},cross:function(b,a){var c=b.x,d=b.y,e=b.z,g=a.x,l=a.y,k=a.z;this.x=d*k-l*e;this.y=e*
- g-k*c;this.z=c*l-g*d;return this},dot:function(b){return this.x*b.x+this.y*b.y+this.z*b.z},equals:function(b){return this.x===b.x&&this.y===b.y&&this.z===b.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(b,a,c){this.x=b.x+c*(a.x-b.x);this.y=b.y+c*(a.y-b.y);this.z=b.z+c*(a.z-b.z);return this},mul:function(b){this.x*=b.x;this.y*=b.y;this.z*=b.z;return this},mul2:function(b,a){this.x=
- b.x*a.x;this.y=b.y*a.y;this.z=b.z*a.z;return this},normalize:function(){var b=this.x*this.x+this.y*this.y+this.z*this.z;0<b&&(b=1/Math.sqrt(b),this.x*=b,this.y*=b,this.z*=b);return this},project:function(b){var a=(this.x*b.x+this.y*b.y+this.z*b.z)/(b.x*b.x+b.y*b.y+b.z*b.z);this.x=b.x*a;this.y=b.y*a;this.z=b.z*a;return this},scale:function(b){this.x*=b;this.y*=b;this.z*=b;return this},set:function(b,a,c){this.x=b;this.y=a;this.z=c;return this},sub:function(b){this.x-=b.x;this.y-=b.y;this.z-=b.z;return this},
- sub2:function(b,a){this.x=b.x-a.x;this.y=b.y-a.y;this.z=b.z-a.z;return this},toString:function(){return"["+this.x+", "+this.y+", "+this.z+"]"}});Object.defineProperty(f,"BACK",{get:function(){var b=new f(0,0,1);return function(){return b}}()});Object.defineProperty(f,"DOWN",{get:function(){var b=new f(0,-1,0);return function(){return b}}()});Object.defineProperty(f,"FORWARD",{get:function(){var b=new f(0,0,-1);return function(){return b}}()});Object.defineProperty(f,"LEFT",{get:function(){var b=new f(-1,
- 0,0);return function(){return b}}()});Object.defineProperty(f,"ONE",{get:function(){var b=new f(1,1,1);return function(){return b}}()});Object.defineProperty(f,"RIGHT",{get:function(){var b=new f(1,0,0);return function(){return b}}()});Object.defineProperty(f,"UP",{get:function(){var b=new f(0,1,0);return function(){return b}}()});Object.defineProperty(f,"ZERO",{get:function(){var b=new f(0,0,0);return function(){return b}}()});return{Vec3:f}}());Object.assign(pc,function(){var f=function(b,a,c,d){b&&4===b.length?(this.x=b[0],this.y=b[1],this.z=b[2],this.w=b[3]):(this.x=b||0,this.y=a||0,this.z=c||0,this.w=d||0)};Object.assign(f.prototype,{add:function(b){this.x+=b.x;this.y+=b.y;this.z+=b.z;this.w+=b.w;return this},add2:function(b,a){this.x=b.x+a.x;this.y=b.y+a.y;this.z=b.z+a.z;this.w=b.w+a.w;return this},clone:function(){return(new f).copy(this)},copy:function(b){this.x=b.x;this.y=b.y;this.z=b.z;this.w=b.w;return this},dot:function(b){return this.x*
- b.x+this.y*b.y+this.z*b.z+this.w*b.w},equals:function(b){return this.x===b.x&&this.y===b.y&&this.z===b.z&&this.w===b.w},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},lerp:function(b,a,c){this.x=b.x+c*(a.x-b.x);this.y=b.y+c*(a.y-b.y);this.z=b.z+c*(a.z-b.z);this.w=b.w+c*(a.w-b.w);return this},mul:function(b){this.x*=b.x;this.y*=b.y;this.z*=b.z;this.w*=b.w;return this},mul2:function(b,
- a){this.x=b.x*a.x;this.y=b.y*a.y;this.z=b.z*a.z;this.w=b.w*a.w;return this},normalize:function(){var b=this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w;0<b&&(b=1/Math.sqrt(b),this.x*=b,this.y*=b,this.z*=b,this.w*=b);return this},scale:function(b){this.x*=b;this.y*=b;this.z*=b;this.w*=b;return this},set:function(b,a,c,d){this.x=b;this.y=a;this.z=c;this.w=d;return this},sub:function(b){this.x-=b.x;this.y-=b.y;this.z-=b.z;this.w-=b.w;return this},sub2:function(b,a){this.x=b.x-a.x;this.y=b.y-a.y;
- this.z=b.z-a.z;this.w=b.w-a.w;return this},toString:function(){return"["+this.x+", "+this.y+", "+this.z+", "+this.w+"]"}});Object.defineProperty(f,"ONE",{get:function(){var b=new f(1,1,1,1);return function(){return b}}()});Object.defineProperty(f,"ZERO",{get:function(){var b=new f(0,0,0,0);return function(){return b}}()});return{Vec4:f}}());Object.assign(pc,function(){var f=function(){var b;b=new Float32Array(9);b[0]=b[4]=b[8]=1;this.data=b};Object.assign(f.prototype,{clone:function(){return(new pc.Mat3).copy(this)},copy:function(b){b=b.data;var a=this.data;a[0]=b[0];a[1]=b[1];a[2]=b[2];a[3]=b[3];a[4]=b[4];a[5]=b[5];a[6]=b[6];a[7]=b[7];a[8]=b[8];return this},set:function(b){var a=this.data;a[0]=b[0];a[1]=b[1];a[2]=b[2];a[3]=b[3];a[4]=b[4];a[5]=b[5];a[6]=b[6];a[7]=b[7];a[8]=b[8];return this},equals:function(b){var a=this.data;b=b.data;
- return a[0]===b[0]&&a[1]===b[1]&&a[2]===b[2]&&a[3]===b[3]&&a[4]===b[4]&&a[5]===b[5]&&a[6]===b[6]&&a[7]===b[7]&&a[8]===b[8]},isIdentity:function(){var b=this.data;return 1===b[0]&&0===b[1]&&0===b[2]&&0===b[3]&&1===b[4]&&0===b[5]&&0===b[6]&&0===b[7]&&1===b[8]},setIdentity:function(){var b=this.data;b[0]=1;b[1]=0;b[2]=0;b[3]=0;b[4]=1;b[5]=0;b[6]=0;b[7]=0;b[8]=1;return this},toString:function(){for(var b="[",a=0;9>a;a++)b+=this.data[a],b+=9!==a?", ":"";return b+"]"},transpose:function(){var b=this.data,
- a;a=b[1];b[1]=b[3];b[3]=a;a=b[2];b[2]=b[6];b[6]=a;a=b[5];b[5]=b[7];b[7]=a;return this}});Object.defineProperty(f,"IDENTITY",{get:function(){var b=new f;return function(){return b}}()});Object.defineProperty(f,"ZERO",{get:function(){var b=(new f).set([0,0,0,0,0,0,0,0,0]);return function(){return b}}()});return{Mat3:f}}());Object.assign(pc,function(){var f=function(){var b=new Float32Array(16);b[0]=b[5]=b[10]=b[15]=1;this.data=b};Object.assign(f.prototype,{add2:function(b,a){var c=b.data,d=a.data,e=this.data;e[0]=c[0]+d[0];e[1]=c[1]+d[1];e[2]=c[2]+d[2];e[3]=c[3]+d[3];e[4]=c[4]+d[4];e[5]=c[5]+d[5];e[6]=c[6]+d[6];e[7]=c[7]+d[7];e[8]=c[8]+d[8];e[9]=c[9]+d[9];e[10]=c[10]+d[10];e[11]=c[11]+d[11];e[12]=c[12]+d[12];e[13]=c[13]+d[13];e[14]=c[14]+d[14];e[15]=c[15]+d[15];return this},add:function(b){return this.add2(this,b)},
- clone:function(){return(new pc.Mat4).copy(this)},copy:function(b){b=b.data;var a=this.data;a[0]=b[0];a[1]=b[1];a[2]=b[2];a[3]=b[3];a[4]=b[4];a[5]=b[5];a[6]=b[6];a[7]=b[7];a[8]=b[8];a[9]=b[9];a[10]=b[10];a[11]=b[11];a[12]=b[12];a[13]=b[13];a[14]=b[14];a[15]=b[15];return this},equals:function(b){var a=this.data;b=b.data;return a[0]===b[0]&&a[1]===b[1]&&a[2]===b[2]&&a[3]===b[3]&&a[4]===b[4]&&a[5]===b[5]&&a[6]===b[6]&&a[7]===b[7]&&a[8]===b[8]&&a[9]===b[9]&&a[10]===b[10]&&a[11]===b[11]&&a[12]===b[12]&&
- a[13]===b[13]&&a[14]===b[14]&&a[15]===b[15]},isIdentity:function(){var b=this.data;return 1===b[0]&&0===b[1]&&0===b[2]&&0===b[3]&&0===b[4]&&1===b[5]&&0===b[6]&&0===b[7]&&0===b[8]&&0===b[9]&&1===b[10]&&0===b[11]&&0===b[12]&&0===b[13]&&0===b[14]&&1===b[15]},mul2:function(b,a){var c,d,e,g,l,k,f,h,n,q,m,r,t,v,y,u,w,x,D,z;u=b.data;var C=a.data,A=this.data;c=u[0];d=u[1];e=u[2];g=u[3];l=u[4];k=u[5];f=u[6];h=u[7];n=u[8];q=u[9];m=u[10];r=u[11];t=u[12];v=u[13];y=u[14];u=u[15];w=C[0];x=C[1];D=C[2];z=C[3];A[0]=
- c*w+l*x+n*D+t*z;A[1]=d*w+k*x+q*D+v*z;A[2]=e*w+f*x+m*D+y*z;A[3]=g*w+h*x+r*D+u*z;w=C[4];x=C[5];D=C[6];z=C[7];A[4]=c*w+l*x+n*D+t*z;A[5]=d*w+k*x+q*D+v*z;A[6]=e*w+f*x+m*D+y*z;A[7]=g*w+h*x+r*D+u*z;w=C[8];x=C[9];D=C[10];z=C[11];A[8]=c*w+l*x+n*D+t*z;A[9]=d*w+k*x+q*D+v*z;A[10]=e*w+f*x+m*D+y*z;A[11]=g*w+h*x+r*D+u*z;w=C[12];x=C[13];D=C[14];z=C[15];A[12]=c*w+l*x+n*D+t*z;A[13]=d*w+k*x+q*D+v*z;A[14]=e*w+f*x+m*D+y*z;A[15]=g*w+h*x+r*D+u*z;return this},mul:function(b){return this.mul2(this,b)},transformPoint:function(b,
- a){var c,d,e,g;g=this.data;c=b.x;d=b.y;e=b.z;a=void 0===a?new pc.Vec3:a;a.x=c*g[0]+d*g[4]+e*g[8]+g[12];a.y=c*g[1]+d*g[5]+e*g[9]+g[13];a.z=c*g[2]+d*g[6]+e*g[10]+g[14];return a},transformVector:function(b,a){var c,d,e,g;g=this.data;c=b.x;d=b.y;e=b.z;a=void 0===a?new pc.Vec3:a;a.x=c*g[0]+d*g[4]+e*g[8];a.y=c*g[1]+d*g[5]+e*g[9];a.z=c*g[2]+d*g[6]+e*g[10];return a},transformVec4:function(b,a){var c,d,e,g,l;l=this.data;c=b.x;d=b.y;e=b.z;g=b.w;a=void 0===a?new pc.Vec4:a;a.x=c*l[0]+d*l[4]+e*l[8]+g*l[12];a.y=
- c*l[1]+d*l[5]+e*l[9]+g*l[13];a.z=c*l[2]+d*l[6]+e*l[10]+g*l[14];a.w=c*l[3]+d*l[7]+e*l[11]+g*l[15];return a},setLookAt:function(){var b,a,c;b=new pc.Vec3;a=new pc.Vec3;c=new pc.Vec3;return function(d,e,g){c.sub2(d,e).normalize();a.copy(g).normalize();b.cross(a,c).normalize();a.cross(c,b);e=this.data;e[0]=b.x;e[1]=b.y;e[2]=b.z;e[3]=0;e[4]=a.x;e[5]=a.y;e[6]=a.z;e[7]=0;e[8]=c.x;e[9]=c.y;e[10]=c.z;e[11]=0;e[12]=d.x;e[13]=d.y;e[14]=d.z;e[15]=1;return this}}(),setFrustum:function(b,a,c,d,e,g){var l,k,f,h,
- n;l=2*e;k=a-b;f=d-c;h=g-e;n=this.data;n[0]=l/k;n[1]=0;n[2]=0;n[3]=0;n[4]=0;n[5]=l/f;n[6]=0;n[7]=0;n[8]=(a+b)/k;n[9]=(d+c)/f;n[10]=(-g-e)/h;n[11]=-1;n[12]=0;n[13]=0;n[14]=-l*g/h;n[15]=0;return this},setPerspective:function(b,a,c,d,e){e?(b=c*Math.tan(b*Math.PI/360),e=b/a):(e=c*Math.tan(b*Math.PI/360),b=e*a);return this.setFrustum(-b,b,-e,e,c,d)},setOrtho:function(b,a,c,d,e,g){var l=this.data;l[0]=2/(a-b);l[1]=0;l[2]=0;l[3]=0;l[4]=0;l[5]=2/(d-c);l[6]=0;l[7]=0;l[8]=0;l[9]=0;l[10]=-2/(g-e);l[11]=0;l[12]=
- -(a+b)/(a-b);l[13]=-(d+c)/(d-c);l[14]=-(g+e)/(g-e);l[15]=1;return this},setFromAxisAngle:function(b,a){var c,d,e,g,l,k,f,h,n;a*=pc.math.DEG_TO_RAD;c=b.x;d=b.y;e=b.z;g=Math.cos(a);l=Math.sin(a);k=1-g;f=k*c;h=k*d;n=this.data;n[0]=f*c+g;n[1]=f*d+l*e;n[2]=f*e-l*d;n[3]=0;n[4]=f*d-l*e;n[5]=h*d+g;n[6]=h*e+l*c;n[7]=0;n[8]=f*e+l*d;n[9]=h*e-c*l;n[10]=k*e*e+g;n[11]=0;n[12]=0;n[13]=0;n[14]=0;n[15]=1;return this},setTranslate:function(b,a,c){var d=this.data;d[0]=1;d[1]=0;d[2]=0;d[3]=0;d[4]=0;d[5]=1;d[6]=0;d[7]=
- 0;d[8]=0;d[9]=0;d[10]=1;d[11]=0;d[12]=b;d[13]=a;d[14]=c;d[15]=1;return this},setScale:function(b,a,c){var d=this.data;d[0]=b;d[1]=0;d[2]=0;d[3]=0;d[4]=0;d[5]=a;d[6]=0;d[7]=0;d[8]=0;d[9]=0;d[10]=c;d[11]=0;d[12]=0;d[13]=0;d[14]=0;d[15]=1;return this},invert:function(){var b,a,c,d,e,g,l,k,f,h,n,q,m,r,t,v,y,u,w,x,D,z,C,A,B,J,F,H,E,G;G=this.data;b=G[0];a=G[1];c=G[2];d=G[3];e=G[4];g=G[5];l=G[6];k=G[7];f=G[8];h=G[9];n=G[10];q=G[11];m=G[12];r=G[13];t=G[14];v=G[15];y=b*g-a*e;u=b*l-c*e;w=b*k-d*e;x=a*l-c*g;
- D=a*k-d*g;z=c*k-d*l;C=f*r-h*m;A=f*t-n*m;B=f*v-q*m;J=h*t-n*r;F=h*v-q*r;H=n*v-q*t;E=y*H-u*F+w*J+x*B-D*A+z*C;0===E?this.setIdentity():(E=1/E,G[0]=(g*H-l*F+k*J)*E,G[1]=(-a*H+c*F-d*J)*E,G[2]=(r*z-t*D+v*x)*E,G[3]=(-h*z+n*D-q*x)*E,G[4]=(-e*H+l*B-k*A)*E,G[5]=(b*H-c*B+d*A)*E,G[6]=(-m*z+t*w-v*u)*E,G[7]=(f*z-n*w+q*u)*E,G[8]=(e*F-g*B+k*C)*E,G[9]=(-b*F+a*B-d*C)*E,G[10]=(m*D-r*w+v*y)*E,G[11]=(-f*D+h*w-q*y)*E,G[12]=(-e*J+g*A-l*C)*E,G[13]=(b*J-a*A+c*C)*E,G[14]=(-m*x+r*u-t*y)*E,G[15]=(f*x-h*u+n*y)*E);return this},
- set:function(b){var a=this.data;a[0]=b[0];a[1]=b[1];a[2]=b[2];a[3]=b[3];a[4]=b[4];a[5]=b[5];a[6]=b[6];a[7]=b[7];a[8]=b[8];a[9]=b[9];a[10]=b[10];a[11]=b[11];a[12]=b[12];a[13]=b[13];a[14]=b[14];a[15]=b[15];return this},setIdentity:function(){var b=this.data;b[0]=1;b[1]=0;b[2]=0;b[3]=0;b[4]=0;b[5]=1;b[6]=0;b[7]=0;b[8]=0;b[9]=0;b[10]=1;b[11]=0;b[12]=0;b[13]=0;b[14]=0;b[15]=1;return this},setTRS:function(b,a,c){var d,e,g,l,k,f,h,n,q,m,r,t,v;d=b.x;e=b.y;b=b.z;g=a.x;l=a.y;k=a.z;f=a.w;a=c.x;h=c.y;c=c.z;n=
- g+g;q=l+l;m=k+k;r=g*n;t=g*q;g*=m;v=l*q;l*=m;k*=m;n*=f;q*=f;f*=m;m=this.data;m[0]=(1-(v+k))*a;m[1]=(t+f)*a;m[2]=(g-q)*a;m[3]=0;m[4]=(t-f)*h;m[5]=(1-(r+k))*h;m[6]=(l+n)*h;m[7]=0;m[8]=(g+q)*c;m[9]=(l-n)*c;m[10]=(1-(r+v))*c;m[11]=0;m[12]=d;m[13]=e;m[14]=b;m[15]=1;return this},transpose:function(){var b,a=this.data;b=a[1];a[1]=a[4];a[4]=b;b=a[2];a[2]=a[8];a[8]=b;b=a[3];a[3]=a[12];a[12]=b;b=a[6];a[6]=a[9];a[9]=b;b=a[7];a[7]=a[13];a[13]=b;b=a[11];a[11]=a[14];a[14]=b;return this},invertTo3x3:function(b){var a,
- c,d,e;a=this.data;b=b.data;var g=a[0],l=a[1],k=a[2],f=a[4],h=a[5],n=a[6],q=a[8],m=a[9],r=a[10];a=r*h-n*m;c=-r*f+n*q;d=m*f-h*q;e=g*a+l*c+k*d;if(0===e)return this;e=1/e;b[0]=e*a;b[1]=e*(-r*l+k*m);b[2]=e*(n*l-k*h);b[3]=e*c;b[4]=e*(r*g-k*q);b[5]=e*(-n*g+k*f);b[6]=e*d;b[7]=e*(-m*g+l*q);b[8]=e*(h*g-l*f);return this},getTranslation:function(b){b=void 0===b?new pc.Vec3:b;return b.set(this.data[12],this.data[13],this.data[14])},getX:function(b){b=void 0===b?new pc.Vec3:b;return b.set(this.data[0],this.data[1],
- this.data[2])},getY:function(b){b=void 0===b?new pc.Vec3:b;return b.set(this.data[4],this.data[5],this.data[6])},getZ:function(b){b=void 0===b?new pc.Vec3:b;return b.set(this.data[8],this.data[9],this.data[10])},getScale:function(){var b,a,c;b=new pc.Vec3;a=new pc.Vec3;c=new pc.Vec3;return function(d){d=void 0===d?new pc.Vec3:d;this.getX(b);this.getY(a);this.getZ(c);d.set(b.length(),a.length(),c.length());return d}}(),setFromEulerAngles:function(b,a,c){var d,e,g,l;b*=pc.math.DEG_TO_RAD;a*=pc.math.DEG_TO_RAD;
- c*=pc.math.DEG_TO_RAD;d=Math.sin(-b);b=Math.cos(-b);e=Math.sin(-a);a=Math.cos(-a);g=Math.sin(-c);c=Math.cos(-c);l=this.data;l[0]=a*c;l[1]=-a*g;l[2]=e;l[3]=0;l[4]=b*g+c*d*e;l[5]=b*c-d*e*g;l[6]=-a*d;l[7]=0;l[8]=d*g-b*c*e;l[9]=c*d+b*e*g;l[10]=b*a;l[11]=0;l[12]=0;l[13]=0;l[14]=0;l[15]=1;return this},getEulerAngles:function(){var b=new pc.Vec3;return function(a){var c,d,e,g,l,k;a=void 0===a?new pc.Vec3:a;this.getScale(b);e=b.x;c=b.y;g=b.z;l=this.data;d=Math.asin(-l[2]/e);k=.5*Math.PI;d<k?d>-k?(c=Math.atan2(l[6]/
- c,l[10]/g),e=Math.atan2(l[1]/e,l[0]/e)):(e=0,c=-Math.atan2(l[4]/c,l[5]/c)):(e=0,c=Math.atan2(l[4]/c,l[5]/c));return a.set(c,d,e).scale(pc.math.RAD_TO_DEG)}}(),toString:function(){var b,a;a="[";for(b=0;16>b;b+=1)a+=this.data[b],a+=15!==b?", ":"";return a+"]"}});Object.defineProperty(f,"IDENTITY",{get:function(){var b=new f;return function(){return b}}()});Object.defineProperty(f,"ZERO",{get:function(){var b=(new f).set([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]);return function(){return b}}()});return{Mat4:f}}());Object.assign(pc,function(){var f=function(b,a,c,d){b&&4===b.length?(this.x=b[0],this.y=b[1],this.z=b[2],this.w=b[3]):(this.x=void 0===b?0:b,this.y=void 0===a?0:a,this.z=void 0===c?0:c,this.w=void 0===d?1:d)};Object.assign(f.prototype,{clone:function(){return new pc.Quat(this.x,this.y,this.z,this.w)},conjugate:function(){this.x*=-1;this.y*=-1;this.z*=-1;return this},copy:function(b){this.x=b.x;this.y=b.y;this.z=b.z;this.w=b.w;return this},equals:function(b){return this.x===b.x&&this.y===b.y&&this.z===
- b.z&&this.w===b.w},getAxisAngle:function(b){var a=2*Math.acos(this.w),c=Math.sin(a/2);if(0!==c){if(b.x=this.x/c,b.y=this.y/c,b.z=this.z/c,0>b.x||0>b.y||0>b.z)b.x*=-1,b.y*=-1,b.z*=-1,a*=-1}else b.x=1,b.y=0,b.z=0;return a*pc.math.RAD_TO_DEG},getEulerAngles:function(b){var a,c,d,e,g,l;b=void 0===b?new pc.Vec3:b;d=this.x;e=this.y;g=this.z;l=this.w;c=2*(l*e-d*g);-.99999>=c?(a=2*Math.atan2(d,l),c=-Math.PI/2,d=0):.99999<=c?(a=2*Math.atan2(d,l),c=Math.PI/2,d=0):(a=Math.atan2(2*(l*d+e*g),1-2*(d*d+e*e)),c=
- Math.asin(c),d=Math.atan2(2*(l*g+d*e),1-2*(e*e+g*g)));return b.set(a,c,d).scale(pc.math.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(b){var a,c,d,e,g,l,k;a=this.x;c=this.y;d=this.z;e=this.w;g=b.x;l=b.y;k=b.z;b=b.w;this.x=e*g+a*b+c*k-d*l;this.y=e*l+c*b+d*g-a*k;this.z=e*k+d*b+a*l-c*g;this.w=
- e*b-a*g-c*l-d*k;return this},mul2:function(b,a){var c,d,e,g,l,k,f,h;c=b.x;d=b.y;e=b.z;g=b.w;l=a.x;k=a.y;f=a.z;h=a.w;this.x=g*l+c*h+d*f-e*k;this.y=g*k+d*h+e*l-c*f;this.z=g*f+e*h+c*k-d*l;this.w=g*h-c*l-d*k-e*f;return this},normalize:function(){var b=this.length();0===b?(this.x=this.y=this.z=0,this.w=1):(b=1/b,this.x*=b,this.y*=b,this.z*=b,this.w*=b);return this},set:function(b,a,c,d){this.x=b;this.y=a;this.z=c;this.w=d;return this},setFromAxisAngle:function(b,a){var c,d;a*=.5*pc.math.DEG_TO_RAD;c=Math.sin(a);
- d=Math.cos(a);this.x=c*b.x;this.y=c*b.y;this.z=c*b.z;this.w=d;return this},setFromEulerAngles:function(b,a,c){var d,e,g;d=.5*pc.math.DEG_TO_RAD;b*=d;a*=d;c*=d;d=Math.sin(b);b=Math.cos(b);e=Math.sin(a);a=Math.cos(a);g=Math.sin(c);c=Math.cos(c);this.x=d*a*c-b*e*g;this.y=b*e*c+d*a*g;this.z=b*a*g-d*e*c;this.w=b*a*c+d*e*g;return this},setFromMat4:function(b){var a,c,d,e,g,l,k,f,h,n,q;b=b.data;a=b[0];c=b[1];d=b[2];e=b[4];g=b[5];l=b[6];k=b[8];f=b[9];b=b[10];h=1/Math.sqrt(a*a+c*c+d*d);n=1/Math.sqrt(e*e+g*
- g+l*l);q=1/Math.sqrt(k*k+f*f+b*b);a*=h;c*=h;d*=h;e*=n;g*=n;l*=n;k*=q;f*=q;b*=q;h=a+g+b;0<=h?(a=Math.sqrt(h+1),this.w=.5*a,a=.5/a,this.x=(l-f)*a,this.y=(k-d)*a,this.z=(c-e)*a):a>g?a>b?(a=Math.sqrt(a-(g+b)+1),this.x=.5*a,a=.5/a,this.w=(l-f)*a,this.y=(c+e)*a,this.z=(d+k)*a):(a=Math.sqrt(b-(a+g)+1),this.z=.5*a,a=.5/a,this.w=(c-e)*a,this.x=(k+d)*a,this.y=(f+l)*a):g>b?(a=Math.sqrt(g-(b+a)+1),this.y=.5*a,a=.5/a,this.w=(k-d)*a,this.z=(l+f)*a,this.x=(e+c)*a):(a=Math.sqrt(b-(a+g)+1),this.z=.5*a,a=.5/a,this.w=
- (c-e)*a,this.x=(k+d)*a,this.y=(f+l)*a);return this},slerp:function(b,a,c){var d,e,g,l,k,f;d=b.x;e=b.y;g=b.z;b=b.w;l=a.x;k=a.y;f=a.z;a=a.w;var h=b*a+d*l+e*k+g*f;0>h&&(a=-a,l=-l,k=-k,f=-f,h=-h);if(1<=Math.abs(h))return this.w=b,this.x=d,this.y=e,this.z=g,this;var n=Math.acos(h),q=Math.sqrt(1-h*h);if(.001>Math.abs(q))return this.w=.5*b+.5*a,this.x=.5*d+.5*l,this.y=.5*e+.5*k,this.z=.5*g+.5*f,this;h=Math.sin((1-c)*n)/q;c=Math.sin(c*n)/q;this.w=b*h+a*c;this.x=d*h+l*c;this.y=e*h+k*c;this.z=g*h+f*c;return this},
- transformVector:function(b,a){void 0===a&&(a=new pc.Vec3);var c=b.x,d=b.y,e=b.z,g=this.x,l=this.y,k=this.z,f=this.w,h=f*c+l*e-k*d,n=f*d+k*c-g*e,q=f*e+g*d-l*c,c=-g*c-l*d-k*e;a.x=h*f+c*-g+n*-k-q*-l;a.y=n*f+c*-l+q*-g-h*-k;a.z=q*f+c*-k+h*-l-n*-g;return a},toString:function(){return"["+this.x+", "+this.y+", "+this.z+", "+this.w+"]"}});Object.defineProperty(f,"IDENTITY",{get:function(){var b=new f;return function(){return b}}()});Object.defineProperty(f,"ZERO",{get:function(){var b=new f(0,0,0,0);return function(){return b}}()});
- return{Quat:f}}());Object.assign(pc,function(){var f=function(b){this.keys=[];this.type=1;this.tension=.5;if(b)for(var a=0;a<b.length-1;a+=2)this.keys.push([b[a],b[a+1]]);this.sort()};Object.assign(f.prototype,{add:function(b,a){for(var c=this.keys,d=c.length,e=0;e<d&&!(c[e][0]>b);e++);c=[b,a];this.keys.splice(e,0,c);return c},get:function(b){return this.keys[b]},sort:function(){this.keys.sort(function(b,a){return b[0]-a[0]})},value:function(b){var a,c,d=this.keys;if(!d.length)return 0;if(b<d[0][0])return d[0][1];if(b>
- d[d.length-1][0])return d[d.length-1][1];var e=0,g=d.length?d[0][1]:0,l=1,k=0;a=0;for(c=d.length;a<c;a++){if(d[a][0]===b)return d[a][1];k=d[a][1];if(b<d[a][0]){l=d[a][0];break}e=d[a][0];g=d[a][1]}c=l-e;b=0===c?0:(b-e)/c;if(1===this.type)b*=b*(3-2*b);else if(2===this.type||3===this.type){c=g+(g-k);var f=k+(k-g),h=l=e=l-e;0<a&&a--;0<a&&(c=d[a-1][1],l=d[a][0]-d[a-1][0]);d.length>a+1&&(e=d[a+1][0]-d[a][0]);d.length>a+2&&(h=d[a+2][0]-d[a+1][0],f=d[a+2][1]);c=g+(c-g)*e/l;f=k+(f-k)*e/h;return 2===this.type?
- this._interpolateCatmullRom(c,g,k,f,b):this._interpolateCardinal(c,g,k,f,b,this.tension)}return pc.math.lerp(g,k,b)},_interpolateHermite:function(b,a,c,d,e){var g=e*e,l=e*e*e;return b*(2*l-3*g+1)+a*(-2*l+3*g)+c*(l-2*g+e)+d*(l-g)},_interpolateCardinal:function(b,a,c,d,e,g){return this._interpolateHermite(a,c,g*(c-b),g*(d-a),e)},_interpolateCatmullRom:function(b,a,c,d,e){return this._interpolateCardinal(b,a,c,d,e,.5)},closest:function(b){for(var a=this.keys,c=a.length,d=2,e=null,g=0;g<c;g++){var l=
- Math.abs(b-a[g][0]);if(d>=l)d=l,e=a[g];else break}return e},clone:function(){var b=new pc.Curve;b.keys=pc.extend(b.keys,this.keys);b.type=this.type;return b},quantize:function(b){b=Math.max(b,2);for(var a=new Float32Array(b),c=1/(b-1),d=0;d<b;d++){var e=this.value(c*d);a[d]=e}return a}});Object.defineProperty(f.prototype,"length",{get:function(){return this.keys.length}});return{Curve:f,CURVE_LINEAR:0,CURVE_SMOOTHSTEP:1,CURVE_CATMULL:2,CURVE_CARDINAL:3}}());Object.assign(pc,function(){var f=function(){var b;this.curves=[];this._type=pc.CURVE_SMOOTHSTEP;if(1<arguments.length)for(b=0;b<arguments.length;b++)this.curves.push(new pc.Curve(arguments[b]));else if(0===arguments.length)this.curves.push(new pc.Curve);else{var a=arguments[0];if("number"===pc.type(a))for(b=0;b<a;b++)this.curves.push(new pc.Curve);else for(b=0;b<a.length;b++)this.curves.push(new pc.Curve(a[b]))}};Object.assign(f.prototype,{get:function(b){return this.curves[b]},value:function(b,
- a){var c=this.curves.length;a=a||[];a.length=c;for(var d=0;d<c;d++)a[d]=this.curves[d].value(b);return a},clone:function(){var b=new pc.CurveSet;b.curves=[];for(var a=0;a<this.curves.length;a++)b.curves.push(this.curves[a].clone());b._type=this._type;return b},quantize:function(b){b=Math.max(b,2);for(var a=this.curves.length,c=new Float32Array(b*a),d=1/(b-1),e=[],g=0;g<b;g++){var l=this.value(d*g,e);if(1==a)c[g]=l[0];else for(var k=0;k<a;k++)c[g*a+k]=l[k]}return c}});Object.defineProperty(f.prototype,
- "length",{get:function(){return this.curves.length}});Object.defineProperty(f.prototype,"type",{get:function(){return this._type},set:function(b){this._type=b;for(var a=0;a<this.curves.length;a++)this.curves[a].type=b}});return{CurveSet:f}}());Object.assign(pc,function(){var f=new pc.Vec3,b=new pc.Vec3,a=new pc.Vec3,c=new pc.Vec3,d=new pc.Vec3,e=function(a,c){this.center=a||new pc.Vec3(0,0,0);this.halfExtents=c||new pc.Vec3(.5,.5,.5);this._min=new pc.Vec3;this._max=new pc.Vec3};Object.assign(e.prototype,{add:function(a){var c=this.center,b=c.x,d=c.y,e=c.z,g=this.halfExtents,f=g.x,m=g.y,r=g.z,t=b-f,b=b+f,f=d-m,d=d+m,m=e-r,e=e+r,r=a.center,v=r.x,y=r.y,r=r.z;a=a.halfExtents;var u=a.x,w=a.y,x=a.z;a=v-u;v+=u;u=y-w;y+=w;w=r-x;r+=x;a<t&&(t=a);
- v>b&&(b=v);u<f&&(f=u);y>d&&(d=y);w<m&&(m=w);r>e&&(e=r);c.x=.5*(t+b);c.y=.5*(f+d);c.z=.5*(m+e);g.x=.5*(b-t);g.y=.5*(d-f);g.z=.5*(e-m)},copy:function(a){this.center.copy(a.center);this.halfExtents.copy(a.halfExtents);this.type=a.type},clone:function(){return new pc.BoundingBox(this.center.clone(),this.halfExtents.clone())},intersects:function(a){var c=this.getMax(),b=this.getMin(),d=a.getMax();a=a.getMin();return b.x<=d.x&&c.x>=a.x&&b.y<=d.y&&c.y>=a.y&&b.z<=d.z&&c.z>=a.z},_intersectsRay:function(d,
- e){var g=f.copy(this.getMin()).sub(d.origin),l=b.copy(this.getMax()).sub(d.origin),h=d.direction;0===h.x?(g.x=0>g.x?-Number.MAX_VALUE:Number.MAX_VALUE,l.x=0>l.x?-Number.MAX_VALUE:Number.MAX_VALUE):(g.x/=h.x,l.x/=h.x);0===h.y?(g.y=0>g.y?-Number.MAX_VALUE:Number.MAX_VALUE,l.y=0>l.y?-Number.MAX_VALUE:Number.MAX_VALUE):(g.y/=h.y,l.y/=h.y);0===h.z?(g.z=0>g.z?-Number.MAX_VALUE:Number.MAX_VALUE,l.z=0>l.z?-Number.MAX_VALUE:Number.MAX_VALUE):(g.z/=h.z,l.z/=h.z);h=a.set(Math.min(g.x,l.x),Math.min(g.y,l.y),
- Math.min(g.z,l.z));g=c.set(Math.max(g.x,l.x),Math.max(g.y,l.y),Math.max(g.z,l.z));l=Math.max(Math.max(h.x,h.y),h.z);(g=Math.min(Math.min(g.x,g.y),g.z)>=l&&0<=l)&&e.copy(d.direction).scale(l).add(d.origin);return g},_fastIntersectsRay:function(e){var g=e.direction;f.sub2(e.origin,this.center);c.set(Math.abs(f.x),Math.abs(f.y),Math.abs(f.z));a.mul2(f,g);if(c.x>this.halfExtents.x&&0<=a.x||c.y>this.halfExtents.y&&0<=a.y||c.z>this.halfExtents.z&&0<=a.z)return!1;d.set(Math.abs(g.x),Math.abs(g.y),Math.abs(g.z));
- b.cross(g,f);b.set(Math.abs(b.x),Math.abs(b.y),Math.abs(b.z));return b.x>this.halfExtents.y*d.z+this.halfExtents.z*d.y||b.y>this.halfExtents.x*d.z+this.halfExtents.z*d.x||b.z>this.halfExtents.x*d.y+this.halfExtents.y*d.x?!1:!0},intersectsRay:function(a,c){return c?this._intersectsRay(a,c):this._fastIntersectsRay(a)},setMinMax:function(a,c){this.center.add2(c,a).scale(.5);this.halfExtents.sub2(c,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 c=this.getMin(),b=this.getMax();return a.x<c.x||a.x>b.x||a.y<c.y||a.y>b.y||a.z<c.z||a.z>b.z?!1:!0},setFromTransformedAabb:function(a,c){var b=this.center,d=this.halfExtents,e=a.center,g=a.halfExtents;c=c.data;var l=c[0],f=c[4],r=c[8],t=c[1],v=c[5],y=c[9],u=c[2],w=c[6],x=c[10],D=Math.abs(l),z=Math.abs(f),C=Math.abs(r),A=Math.abs(t),B=Math.abs(v),J=Math.abs(y),F=Math.abs(u),H=Math.abs(w),E=Math.abs(x);b.set(c[12]+l*e.x+f*e.y+r*e.z,c[13]+t*e.x+v*e.y+y*e.z,c[14]+u*e.x+w*
- e.y+x*e.z);d.set(D*g.x+z*g.y+C*g.z,A*g.x+B*g.y+J*g.z,F*g.x+H*g.y+E*g.z)},compute:function(a){for(var c=f.set(a[0],a[1],a[2]),d=b.set(a[0],a[1],a[2]),e=a.length/3,g=1;g<e;g++){var n=a[3*g+0],q=a[3*g+1],m=a[3*g+2];n<c.x&&(c.x=n);q<c.y&&(c.y=q);m<c.z&&(c.z=m);n>d.x&&(d.x=n);q>d.y&&(d.y=q);m>d.z&&(d.z=m)}this.setMinMax(c,d)},intersectsBoundingSphere:function(a){return this._distanceToBoundingSphereSq(a)<=a.radius*a.radius?!0:!1},_distanceToBoundingSphereSq:function(a){for(var c=this.getMin(),b=this.getMax(),
- d=0,e=["x","y","z"],g=0;3>g;++g){var f=0,m=a.center[e[g]],r=c[e[g]],t=b[e[g]];m<r&&(r-=m,f+=r*r);m>t&&(r=m-t,f+=r*r);d+=f}return d}});return{BoundingBox:e}}());Object.assign(pc,function(){function f(a,c){this.center=a||new pc.Vec3(0,0,0);this.radius=void 0===c?.5:c}var b=new pc.Vec3,a=new pc.Vec3,c=new pc.Vec3,d=new pc.Vec3;Object.assign(f.prototype,{containsPoint:function(a){a=b.sub2(a,this.center).lengthSq();var c=this.radius;return a<c*c},compute:function(e){var g,l=e.length/3;for(g=0;g<l;g++)b.set(e[3*g],e[3*g+1],e[3*g+2]),c.addSelf(b),0===g%100&&(c.scale(1/l),a.add(c),c.set(0,0,0));c.scale(1/l);a.add(c);this.center.copy(a);var k=0;for(g=0;g<l;g++)b.set(e[3*
- g],e[3*g+1],e[3*g+2]),d.sub2(b,this.center),k=Math.max(d.lengthSq(),k);this.radius=Math.sqrt(k)},intersectsRay:function(c,d){var e=b.copy(c.origin).sub(this.center),g=e.dot(a.copy(c.direction).normalize()),e=e.dot(e)-this.radius*this.radius;if(0<e&&0<g)return null;e=g*g-e;if(0>e)return!1;g=Math.abs(-g-Math.sqrt(e));d&&d.copy(c.direction).scale(g).add(c.origin);return!0},intersectsBoundingSphere:function(a){b.sub2(a.center,this.center);a=a.radius+this.radius;return b.lengthSq()<=a*a?!0:!1}});return{BoundingSphere:f}}());Object.assign(pc,function(){var f=new pc.Mat4,b=function(a,c){a=a||(new pc.Mat4).setPerspective(90,16/9,.1,1E3);c=c||new pc.Mat4;this.planes=[];for(var b=0;6>b;b++)this.planes[b]=[];this.update(a,c)};Object.assign(b.prototype,{update:function(a,c){f.mul2(a,c);var b=f.data;this.planes[0][0]=b[3]-b[0];this.planes[0][1]=b[7]-b[4];this.planes[0][2]=b[11]-b[8];this.planes[0][3]=b[15]-b[12];var e=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]/=e;this.planes[0][1]/=e;this.planes[0][2]/=e;this.planes[0][3]/=e;this.planes[1][0]=b[3]+b[0];this.planes[1][1]=b[7]+b[4];this.planes[1][2]=b[11]+b[8];this.planes[1][3]=b[15]+b[12];e=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]/=e;this.planes[1][1]/=e;this.planes[1][2]/=e;this.planes[1][3]/=e;this.planes[2][0]=b[3]+b[1];this.planes[2][1]=b[7]+b[5];this.planes[2][2]=b[11]+b[9];this.planes[2][3]=
- b[15]+b[13];e=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]/=e;this.planes[2][1]/=e;this.planes[2][2]/=e;this.planes[2][3]/=e;this.planes[3][0]=b[3]-b[1];this.planes[3][1]=b[7]-b[5];this.planes[3][2]=b[11]-b[9];this.planes[3][3]=b[15]-b[13];e=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]/=e;this.planes[3][1]/=e;this.planes[3][2]/=
- e;this.planes[3][3]/=e;this.planes[4][0]=b[3]-b[2];this.planes[4][1]=b[7]-b[6];this.planes[4][2]=b[11]-b[10];this.planes[4][3]=b[15]-b[14];e=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]/=e;this.planes[4][1]/=e;this.planes[4][2]/=e;this.planes[4][3]/=e;this.planes[5][0]=b[3]+b[2];this.planes[5][1]=b[7]+b[6];this.planes[5][2]=b[11]+b[10];this.planes[5][3]=b[15]+b[14];e=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]/=e;this.planes[5][1]/=e;this.planes[5][2]/=e;this.planes[5][3]/=e},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,d,e,g=a.radius;e=a.center;a=e.x;var l=e.y,k=e.z,f=this.planes;for(e=0;6>e;e++){d=f[e];d=d[0]*a+d[1]*l+d[2]*k+d[3];if(d<=-g)return 0;d>g&&b++}return 6===b?
- 2:1}});return{Frustum:b}}());Object.assign(pc,function(){var f=new pc.Vec3,b=function(a,b){this.normal=b||new pc.Vec3(0,0,1);this.point=a||new pc.Vec3(0,0,0)};Object.assign(b.prototype,{intersectsLine:function(a,b,d){var c=-this.normal.dot(this.point),g=this.normal.dot(a)+c,c=this.normal.dot(b)+c,g=g/(g-c);(c=0<=g&&1>=g)&&d&&d.lerp(a,b,g);return c},intersectsRay:function(a,b){var c=f.sub2(this.point,a.origin),c=this.normal.dot(c)/this.normal.dot(a.direction),e=0<=c;e&&b&&b.copy(a.direction).scale(c).add(a.origin);return e}});
- return{Plane:b}}());Object.assign(pc,function(){return{Ray:function(f,b){this.origin=f||new pc.Vec3(0,0,0);this.direction=b||new pc.Vec3(0,0,-1)}}}());Object.assign(pc,function(){var f=new pc.Ray,b=new pc.Vec3,a=new pc.BoundingSphere,c=new pc.Mat4,d=function(a,b){this.halfExtents=b||new pc.Vec3(.5,.5,.5);a=a||c.setIdentity();this._modelTransform=a.clone().invert();this._worldTransform=a.clone();this._aabb=new pc.BoundingBox(new pc.Vec3,this.halfExtents)};Object.assign(d.prototype,{intersectsRay:function(a,b){this._modelTransform.transformPoint(a.origin,f.origin);this._modelTransform.transformVector(a.direction,f.direction);if(b){var d=this._aabb._intersectsRay(f,
- b);c.copy(this._modelTransform).invert().transformPoint(b,b);return d}return this._aabb._fastIntersectsRay(f)},containsPoint:function(a){this._modelTransform.transformPoint(a,b);return this._aabb.containsPoint(b)},intersectsBoundingSphere:function(b){this._modelTransform.transformPoint(b.center,a.center);a.radius=b.radius;return this._aabb.intersectsBoundingSphere(a)?!0:!1}});Object.defineProperty(d.prototype,"worldTransform",{get:function(){return this._worldTransform},set:function(a){this._worldTransform.copy(a);
- this._modelTransform.copy(a).invert()}});return{OrientedBox:d}}());(function(){var f={ADDRESS_REPEAT:0,ADDRESS_CLAMP_TO_EDGE:1,ADDRESS_MIRRORED_REPEAT:2,BLENDMODE_ZERO:0,BLENDMODE_ONE:1,BLENDMODE_SRC_COLOR:2,BLENDMODE_ONE_MINUS_SRC_COLOR:3,BLENDMODE_DST_COLOR:4,BLENDMODE_ONE_MINUS_DST_COLOR:5,BLENDMODE_SRC_ALPHA:6,BLENDMODE_SRC_ALPHA_SATURATE:7,BLENDMODE_ONE_MINUS_SRC_ALPHA:8,BLENDMODE_DST_ALPHA:9,BLENDMODE_ONE_MINUS_DST_ALPHA:10,BLENDEQUATION_ADD:0,BLENDEQUATION_SUBTRACT:1,BLENDEQUATION_REVERSE_SUBTRACT:2,BLENDEQUATION_MIN:3,BLENDEQUATION_MAX:4,BUFFER_STATIC:0,
- BUFFER_DYNAMIC:1,BUFFER_STREAM:2,BUFFER_GPUDYNAMIC:3,CLEARFLAG_COLOR:1,CLEARFLAG_DEPTH:2,CLEARFLAG_STENCIL:4,CUBEFACE_POSX:0,CUBEFACE_NEGX:1,CUBEFACE_POSY:2,CUBEFACE_NEGY:3,CUBEFACE_POSZ:4,CUBEFACE_NEGZ:5,CULLFACE_NONE:0,CULLFACE_BACK:1,CULLFACE_FRONT:2,CULLFACE_FRONTANDBACK:3,TYPE_INT8:0,TYPE_UINT8:1,TYPE_INT16:2,TYPE_UINT16:3,TYPE_INT32:4,TYPE_UINT32:5,TYPE_FLOAT32:6,FILTER_NEAREST:0,FILTER_LINEAR:1,FILTER_NEAREST_MIPMAP_NEAREST:2,FILTER_NEAREST_MIPMAP_LINEAR:3,FILTER_LINEAR_MIPMAP_NEAREST:4,FILTER_LINEAR_MIPMAP_LINEAR:5,
- FUNC_NEVER:0,FUNC_LESS:1,FUNC_EQUAL:2,FUNC_LESSEQUAL:3,FUNC_GREATER:4,FUNC_NOTEQUAL:5,FUNC_GREATEREQUAL:6,FUNC_ALWAYS:7,INDEXFORMAT_UINT8:0,INDEXFORMAT_UINT16:1,INDEXFORMAT_UINT32:2,PIXELFORMAT_A8:0,PIXELFORMAT_L8:1,PIXELFORMAT_L8_A8:2,PIXELFORMAT_R5_G6_B5:3,PIXELFORMAT_R5_G5_B5_A1:4,PIXELFORMAT_R4_G4_B4_A4:5,PIXELFORMAT_R8_G8_B8:6,PIXELFORMAT_R8_G8_B8_A8:7,PIXELFORMAT_DXT1:8,PIXELFORMAT_DXT3:9,PIXELFORMAT_DXT5:10,PIXELFORMAT_RGB16F:11,PIXELFORMAT_RGBA16F:12,PIXELFORMAT_RGB32F:13,PIXELFORMAT_RGBA32F:14,
- PIXELFORMAT_R32F:15,PIXELFORMAT_DEPTH:16,PIXELFORMAT_DEPTHSTENCIL:17,PIXELFORMAT_111110F:18,PIXELFORMAT_SRGB:19,PIXELFORMAT_SRGBA:20,PIXELFORMAT_ETC1:21,PIXELFORMAT_ETC2_RGB:22,PIXELFORMAT_ETC2_RGBA:23,PIXELFORMAT_PVRTC_2BPP_RGB_1:24,PIXELFORMAT_PVRTC_2BPP_RGBA_1:25,PIXELFORMAT_PVRTC_4BPP_RGB_1:26,PIXELFORMAT_PVRTC_4BPP_RGBA_1:27,PRIMITIVE_POINTS:0,PRIMITIVE_LINES:1,PRIMITIVE_LINELOOP:2,PRIMITIVE_LINESTRIP:3,PRIMITIVE_TRIANGLES:4,PRIMITIVE_TRISTRIP:5,PRIMITIVE_TRIFAN:6,SEMANTIC_POSITION:"POSITION",
- SEMANTIC_NORMAL:"NORMAL",SEMANTIC_TANGENT:"TANGENT",SEMANTIC_BLENDWEIGHT:"BLENDWEIGHT",SEMANTIC_BLENDINDICES:"BLENDINDICES",SEMANTIC_COLOR:"COLOR",SEMANTIC_TEXCOORD0:"TEXCOORD0",SEMANTIC_TEXCOORD1:"TEXCOORD1",SEMANTIC_TEXCOORD2:"TEXCOORD2",SEMANTIC_TEXCOORD3:"TEXCOORD3",SEMANTIC_TEXCOORD4:"TEXCOORD4",SEMANTIC_TEXCOORD5:"TEXCOORD5",SEMANTIC_TEXCOORD6:"TEXCOORD6",SEMANTIC_TEXCOORD7:"TEXCOORD7",SEMANTIC_ATTR0:"ATTR0",SEMANTIC_ATTR1:"ATTR1",SEMANTIC_ATTR2:"ATTR2",SEMANTIC_ATTR3:"ATTR3",SEMANTIC_ATTR4:"ATTR4",
- SEMANTIC_ATTR5:"ATTR5",SEMANTIC_ATTR6:"ATTR6",SEMANTIC_ATTR7:"ATTR7",SEMANTIC_ATTR8:"ATTR8",SEMANTIC_ATTR9:"ATTR9",SEMANTIC_ATTR10:"ATTR10",SEMANTIC_ATTR11:"ATTR11",SEMANTIC_ATTR12:"ATTR12",SEMANTIC_ATTR13:"ATTR13",SEMANTIC_ATTR14:"ATTR14",SEMANTIC_ATTR15:"ATTR15",SHADERTAG_MATERIAL:1,STENCILOP_KEEP:0,STENCILOP_ZERO:1,STENCILOP_REPLACE:2,STENCILOP_INCREMENT:3,STENCILOP_INCREMENTWRAP:4,STENCILOP_DECREMENT:5,STENCILOP_DECREMENTWRAP:6,STENCILOP_INVERT:7,TEXTURELOCK_READ:1,TEXTURELOCK_WRITE:2,TEXHINT_NONE:0,
- TEXHINT_SHADOWMAP:1,TEXHINT_ASSET:2,TEXHINT_LIGHTMAP:3,UNIFORMTYPE_BOOL:0,UNIFORMTYPE_INT:1,UNIFORMTYPE_FLOAT:2,UNIFORMTYPE_VEC2:3,UNIFORMTYPE_VEC3:4,UNIFORMTYPE_VEC4:5,UNIFORMTYPE_IVEC2:6,UNIFORMTYPE_IVEC3:7,UNIFORMTYPE_IVEC4:8,UNIFORMTYPE_BVEC2:9,UNIFORMTYPE_BVEC3:10,UNIFORMTYPE_BVEC4:11,UNIFORMTYPE_MAT2:12,UNIFORMTYPE_MAT3:13,UNIFORMTYPE_MAT4:14,UNIFORMTYPE_TEXTURE2D:15,UNIFORMTYPE_TEXTURECUBE:16,UNIFORMTYPE_FLOATARRAY:17,UNIFORMTYPE_TEXTURE2D_SHADOW:18,UNIFORMTYPE_TEXTURECUBE_SHADOW:19,UNIFORMTYPE_TEXTURE3D:20};
- Object.assign(pc,f);pc.gfx={};Object.assign(pc.gfx,f)})();Object.assign(pc,function(){var f=function(b){this.name=b;this.value=null;this.versionObject=new pc.VersionedObject};Object.assign(f.prototype,{setValue:function(b){this.value=b;this.versionObject.increment()},getValue:function(b){return this.value}});return{ScopeId:f}}());Object.assign(pc,function(){var f=function(b){this.name=b;this.variables={};this.namespaces={}};Object.assign(f.prototype,{resolve:function(b){this.variables.hasOwnProperty(b)||(this.variables[b]=new pc.ScopeId(b));return this.variables[b]},getSubSpace:function(b){this.namespaces.hasOwnProperty(b)||(this.namespaces[b]=new pc.ScopeSpace(b));return this.namespaces[b]}});return{ScopeSpace:f}}());Object.assign(pc,function(){var f=function(){this.revision=this.globalId=0};Object.assign(f.prototype,{equals:function(b){return this.globalId===b.globalId&&this.revision===b.revision},notequals:function(b){return this.globalId!==b.globalId||this.revision!==b.revision},copy:function(b){this.globalId=b.globalId;this.revision=b.revision},reset:function(){this.revision=this.globalId=0}});return{Version:f}}());Object.assign(pc,function(){var f=0,b=function(){f++;this.version=new pc.Version;this.version.globalId=f};Object.assign(b.prototype,{increment:function(){this.version.revision++}});return{VersionedObject:b}}());Object.assign(pc,function(){function f(e,l){this.index=0;switch(l.dataType){case pc.TYPE_INT8:this.array=new Int8Array(e,l.offset);break;case pc.TYPE_UINT8:this.array=new Uint8Array(e,l.offset);break;case pc.TYPE_INT16:this.array=new Int16Array(e,l.offset);break;case pc.TYPE_UINT16:this.array=new Uint16Array(e,l.offset);break;case pc.TYPE_INT32:this.array=new Int32Array(e,l.offset);break;case pc.TYPE_UINT32:this.array=new Uint32Array(e,l.offset);break;case pc.TYPE_FLOAT32:this.array=new Float32Array(e,
- l.offset)}switch(l.numComponents){case 1:this.set=b;break;case 2:this.set=a;break;case 3:this.set=c;break;case 4:this.set=d}}function b(a){this.array[this.index]=a}function a(a,b){this.array[this.index]=a;this.array[this.index+1]=b}function c(a,b,c){this.array[this.index]=a;this.array[this.index+1]=b;this.array[this.index+2]=c}function d(a,b,c,d){this.array[this.index]=a;this.array[this.index+1]=b;this.array[this.index+2]=c;this.array[this.index+3]=d}function e(a){this.vertexBuffer=a;this.buffer=
- this.vertexBuffer.lock();this.accessors=[];this.element={};a=this.vertexBuffer.getFormat();for(var b=0;b<a.elements.length;b++){var c=a.elements[b];this.accessors[b]=new f(this.buffer,c);this.element[c.name]=this.accessors[b]}}f.prototype.get=function(a){return this.array[this.index+a]};Object.assign(e.prototype,{next:function(a){void 0===a&&(a=1);for(var b=0,c=this.accessors,d=this.accessors.length,e=this.vertexBuffer.getFormat();b<d;){var g=c[b++];g.index+=a*e.size/g.array.constructor.BYTES_PER_ELEMENT}},
- end:function(){this.vertexBuffer.unlock()}});return{VertexIterator:e}}());Object.assign(pc,function(){var f=[];f[pc.TYPE_INT8]=1;f[pc.TYPE_UINT8]=1;f[pc.TYPE_INT16]=2;f[pc.TYPE_UINT16]=2;f[pc.TYPE_INT32]=4;f[pc.TYPE_UINT32]=4;f[pc.TYPE_FLOAT32]=4;return{VertexFormat:function(b,a){var c,d,e;this.elements=[];this.hasTangents=this.hasColor=this.hasUv1=this.hasUv0=!1;c=this.size=0;for(d=a.length;c<d;c++){var g=a[c];e={name:g.semantic,offset:0,stride:0,stream:-1,scopeId:b.scope.resolve(g.semantic),dataType:g.type,numComponents:g.components,normalize:void 0===g.normalize?!1:
- g.normalize,size:g.components*f[g.type]};this.elements.push(e);this.size+=4*Math.ceil(e.size/4);g.semantic===pc.SEMANTIC_TEXCOORD0?this.hasUv0=!0:g.semantic===pc.SEMANTIC_TEXCOORD1?this.hasUv1=!0:g.semantic===pc.SEMANTIC_COLOR?this.hasColor=!0:g.semantic===pc.SEMANTIC_TANGENT&&(this.hasTangents=!0)}c=g=0;for(d=this.elements.length;c<d;c++)e=this.elements[c],e.offset=g,e.stride=this.size,g+=e.size}}}());Object.assign(pc,function(){var f=function(b,a,c,d,e){this.usage=d||pc.BUFFER_STATIC;this.format=a;this.numVertices=c;this.numBytes=a.size*c;b._vram.vb+=this.numBytes;this.device=b;e?this.setData(e):this.storage=new ArrayBuffer(this.numBytes);this.device.buffers.push(this)};Object.assign(f.prototype,{destroy:function(){var b=this.device,a=b.buffers.indexOf(this);-1!==a&&b.buffers.splice(a,1);if(this.bufferId){a=b.gl;a.deleteBuffer(this.bufferId);b._vram.vb-=this.storage.byteLength;this.bufferId=null;
- b.boundBuffer=null;b.vertexBuffers.length=0;b.vbOffsets.length=0;b.attributesInvalidated=!0;for(var c in b.enabledAttributes)a.disableVertexAttribArray(c);b.enabledAttributes={}}},getFormat:function(){return this.format},getUsage:function(){return this.usage},getNumVertices:function(){return this.numVertices},lock:function(){return this.storage},unlock:function(){var b=this.device.gl;this.bufferId||(this.bufferId=b.createBuffer());var a;switch(this.usage){case pc.BUFFER_STATIC:a=b.STATIC_DRAW;break;
- case pc.BUFFER_DYNAMIC:a=b.DYNAMIC_DRAW;break;case pc.BUFFER_STREAM:a=b.STREAM_DRAW;break;case pc.BUFFER_GPUDYNAMIC:a=this.device.webgl2?b.DYNAMIC_COPY:b.STATIC_DRAW}b.bindBuffer(b.ARRAY_BUFFER,this.bufferId);b.bufferData(b.ARRAY_BUFFER,this.storage,a)},setData:function(b){if(b.byteLength!==this.numBytes)return console.error("VertexBuffer: wrong initial data size: expected "+this.numBytes+", got "+b.byteLength),!1;this.storage=b;this.unlock();return!0}});return{VertexBuffer:f}}());Object.assign(pc,function(){var f=function(b,a,c,d,e){this.usage=d||pc.BUFFER_STATIC;this.format=a;this.numIndices=c;this.device=b;c=this.device.gl;var g;a===pc.INDEXFORMAT_UINT8?(g=1,this.glFormat=c.UNSIGNED_BYTE):a===pc.INDEXFORMAT_UINT16?(g=2,this.glFormat=c.UNSIGNED_SHORT):a===pc.INDEXFORMAT_UINT32&&(g=4,this.glFormat=c.UNSIGNED_INT);this.bytesPerIndex=g;this.numBytes=this.numIndices*g;e?this.setData(e):this.storage=new ArrayBuffer(this.numBytes);b._vram.ib+=this.numBytes;this.device.buffers.push(this)};
- Object.assign(f.prototype,{destroy:function(){var b=this.device,a=b.buffers.indexOf(this);-1!==a&&b.buffers.splice(a,1);this.bufferId&&(this.device.gl.deleteBuffer(this.bufferId),this.device._vram.ib-=this.storage.byteLength,this.bufferId=null,this.device.indexBuffer===this&&(this.device.indexBuffer=null))},getFormat:function(){return this.format},getNumIndices:function(){return this.numIndices},lock:function(){return this.storage},unlock:function(){var b=this.device.gl;this.bufferId||(this.bufferId=
- b.createBuffer());var a;switch(this.usage){case pc.BUFFER_STATIC:a=b.STATIC_DRAW;break;case pc.BUFFER_DYNAMIC:a=b.DYNAMIC_DRAW;break;case pc.BUFFER_STREAM:a=b.STREAM_DRAW;break;case pc.BUFFER_GPUDYNAMIC:a=this.device.webgl2?b.DYNAMIC_COPY:b.STATIC_DRAW}b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,this.bufferId);b.bufferData(b.ELEMENT_ARRAY_BUFFER,this.storage,a)},setData:function(b){if(b.byteLength!==this.numBytes)return console.error("IndexBuffer: wrong initial data size: expected "+this.numBytes+", got "+
- b.byteLength),!1;this.storage=b;this.unlock();return!0}});return{IndexBuffer:f}}());Object.assign(pc,function(){var f=function(b,a){a=a||pc.BUFFER_GPUDYNAMIC;this.device=b.device;var c=this.device.gl;this._inputBuffer=b;a===pc.BUFFER_GPUDYNAMIC&&b.usage!==a&&(c.bindBuffer(c.ARRAY_BUFFER,b.bufferId),c.bufferData(c.ARRAY_BUFFER,b.storage,c.DYNAMIC_COPY));this._outputBuffer=new pc.VertexBuffer(b.device,b.format,b.numVertices,a,b.storage)};f.createShader=function(b,a,c){return pc.shaderChunks.createShaderFromCode(b,a,null,c,!0)};Object.assign(f.prototype,{destroy:function(){this._outputBuffer.destroy()},
- process:function(b,a){void 0===a&&(a=!0);var c=this.device;c.setRenderTarget(null);c.updateBegin();c.setVertexBuffer(this._inputBuffer,0);c.setRaster(!1);c.setTransformFeedbackBuffer(this._outputBuffer);c.setShader(b);c.draw({type:pc.PRIMITIVE_POINTS,base:0,count:this._inputBuffer.numVertices,indexed:!1});c.setTransformFeedbackBuffer(null);c.setRaster(!0);c.updateEnd();a&&(c=this._inputBuffer.bufferId,this._inputBuffer.bufferId=this._outputBuffer.bufferId,this._outputBuffer.bufferId=c)}});Object.defineProperty(f.prototype,
- "inputBuffer",{get:function(){return this._inputBuffer}});Object.defineProperty(f.prototype,"outputBuffer",{get:function(){return this._outputBuffer}});return{TransformFeedback:f}}());Object.assign(pc,function(){var f=function(a,b){this.device=a;this.name=null;this._height=this._width=4;this._depth=1;this._pot=!0;this._format=pc.PIXELFORMAT_R8_G8_B8_A8;this.fixCubemapSeams=this._volume=this._cubemap=this.rgbm=!1;this._flipY=!0;this._premultiplyAlpha=!1;this._mipmaps=!0;this._minFilter=pc.FILTER_LINEAR_MIPMAP_LINEAR;this._magFilter=pc.FILTER_LINEAR;this._anisotropy=1;this._addressW=this._addressV=this._addressU=pc.ADDRESS_REPEAT;this._compareOnRead=!1;this._compareFunc=pc.FUNC_LESS;
- void 0!==b&&(this._width=void 0!==b.width?b.width:this._width,this._height=void 0!==b.height?b.height:this._height,this._pot=pc.math.powerOfTwo(this._width)&&pc.math.powerOfTwo(this._height),this._format=void 0!==b.format?b.format:this._format,this.rgbm=void 0!==b.rgbm?b.rgbm:this.rgbm,this._mipmaps=void 0!==b.mipmaps?b.mipmaps:void 0!==b.autoMipmap?b.autoMipmap:this._mipmaps,this._levels=b.levels,this._cubemap=void 0!==b.cubemap?b.cubemap:this._cubemap,this.fixCubemapSeams=void 0!==b.fixCubemapSeams?
- b.fixCubemapSeams:this.fixCubemapSeams,this._minFilter=void 0!==b.minFilter?b.minFilter:this._minFilter,this._magFilter=void 0!==b.magFilter?b.magFilter:this._magFilter,this._anisotropy=void 0!==b.anisotropy?b.anisotropy:this._anisotropy,this._addressU=void 0!==b.addressU?b.addressU:this._addressU,this._addressV=void 0!==b.addressV?b.addressV:this._addressV,this._compareOnRead=void 0!==b.compareOnRead?b.compareOnRead:this._compareOnRead,this._compareFunc=void 0!==b._compareFunc?b._compareFunc:this._compareFunc,
- this._flipY=void 0!==b.flipY?b.flipY:this._flipY,this._premultiplyAlpha=void 0!==b.premultiplyAlpha?b.premultiplyAlpha:this._premultiplyAlpha,a.webgl2&&(this._depth=void 0!==b.depth?b.depth:this._depth,this._volume=void 0!==b.volume?b.volume:this._volume,this._addressW=void 0!==b.addressW?b.addressW:this._addressW));this._compressed=this._format===pc.PIXELFORMAT_DXT1||this._format===pc.PIXELFORMAT_DXT3||this._format===pc.PIXELFORMAT_DXT5||this._format>=pc.PIXELFORMAT_ETC1;this._invalid=!1;this._lockedLevel=
- -1;this._levels||(this._levels=this._cubemap?[[null,null,null,null,null,null]]:[null]);this.dirtyAll();this._gpuSize=0};Object.defineProperty(f.prototype,"minFilter",{get:function(){return this._minFilter},set:function(a){this._minFilter!==a&&(this._minFilter=a,this._parameterFlags|=1)}});Object.defineProperty(f.prototype,"magFilter",{get:function(){return this._magFilter},set:function(a){this._magFilter!==a&&(this._magFilter=a,this._parameterFlags|=2)}});Object.defineProperty(f.prototype,"addressU",
- {get:function(){return this._addressU},set:function(a){this._addressU!==a&&(this._addressU=a,this._parameterFlags|=4)}});Object.defineProperty(f.prototype,"addressV",{get:function(){return this._addressV},set:function(a){this._addressV!==a&&(this._addressV=a,this._parameterFlags|=8)}});Object.defineProperty(f.prototype,"addressW",{get:function(){return this._addressW},set:function(a){this.device.webgl2&&this._volume&&a!==this._addressW&&(this._addressW=a,this._parameterFlags|=16)}});Object.defineProperty(f.prototype,
- "compareOnRead",{get:function(){return this._compareOnRead},set:function(a){this._compareOnRead!==a&&(this._compareOnRead=a,this._parameterFlags|=32)}});Object.defineProperty(f.prototype,"compareFunc",{get:function(){return this._compareFunc},set:function(a){this._compareFunc!==a&&(this._compareFunc=a,this._parameterFlags|=64)}});Object.defineProperty(f.prototype,"anisotropy",{get:function(){return this._anisotropy},set:function(a){this._anisotropy!==a&&(this._anisotropy=a,this._parameterFlags|=128)}});
- Object.defineProperty(f.prototype,"autoMipmap",{get:function(){return this._mipmaps},set:function(a){this._mipmaps=a}});Object.defineProperty(f.prototype,"mipmaps",{get:function(){return this._mipmaps},set:function(a){this._mipmaps!==a&&(this._mipmaps=a,this._minFilterDirty=!0,a&&(this._needsMipmapsUpload=!0))}});Object.defineProperty(f.prototype,"width",{get:function(){return this._width}});Object.defineProperty(f.prototype,"height",{get:function(){return this._height}});Object.defineProperty(f.prototype,
- "depth",{get:function(){return this._depth}});Object.defineProperty(f.prototype,"format",{get:function(){return this._format}});Object.defineProperty(f.prototype,"cubemap",{get:function(){return this._cubemap}});var b=null;Object.defineProperty(f.prototype,"gpuSize",{get:function(){b||(b=[],b[pc.PIXELFORMAT_A8]=1,b[pc.PIXELFORMAT_L8]=1,b[pc.PIXELFORMAT_L8_A8]=1,b[pc.PIXELFORMAT_R5_G6_B5]=2,b[pc.PIXELFORMAT_R5_G5_B5_A1]=2,b[pc.PIXELFORMAT_R4_G4_B4_A4]=2,b[pc.PIXELFORMAT_R8_G8_B8]=4,b[pc.PIXELFORMAT_R8_G8_B8_A8]=
- 4,b[pc.PIXELFORMAT_RGB16F]=8,b[pc.PIXELFORMAT_RGBA16F]=8,b[pc.PIXELFORMAT_RGB32F]=16,b[pc.PIXELFORMAT_RGBA32F]=16,b[pc.PIXELFORMAT_R32F]=4,b[pc.PIXELFORMAT_DEPTH]=4,b[pc.PIXELFORMAT_DEPTHSTENCIL]=4,b[pc.PIXELFORMAT_111110F]=4,b[pc.PIXELFORMAT_SRGB]=4,b[pc.PIXELFORMAT_SRGBA]=4);var a=1;!this._pot||!this._mipmaps&&this._minFilter!==pc.FILTER_NEAREST_MIPMAP_NEAREST&&this._minFilter!==pc.FILTER_NEAREST_MIPMAP_LINEAR&&this._minFilter!==pc.FILTER_LINEAR_MIPMAP_NEAREST&&this._minFilter!==pc.FILTER_LINEAR_MIPMAP_LINEAR||
- this._compressed&&1===this._levels.length||(a=Math.round(Math.log2(Math.max(this._width,this._height))+1));for(var c=this._width,d=this._height,e=this._depth,g=0,l=0;l<a;l++)g=this._compressed?this._format===pc.PIXELFORMAT_ETC1?g+Math.floor((c+3)/4)*Math.floor((d+3)/4)*8*e:this._format===pc.PIXELFORMAT_PVRTC_2BPP_RGB_1||this._format===pc.PIXELFORMAT_PVRTC_2BPP_RGBA_1?g+Math.max(c,16)*Math.max(d,8)/4*e:this._format===pc.PIXELFORMAT_PVRTC_4BPP_RGB_1||this._format===pc.PIXELFORMAT_PVRTC_4BPP_RGBA_1?
- g+Math.max(c,8)*Math.max(d,8)/2*e:g+Math.floor((c+4-1)/4)*Math.floor((d+4-1)/4)*(this._format===pc.PIXELFORMAT_DXT1?8:16)*e:g+c*d*e*b[this._format],c=Math.max(.5*c,1),d=Math.max(.5*d,1),e=Math.max(.5*e,1);this._cubemap&&(g*=6);return g}});Object.defineProperty(f.prototype,"volume",{get:function(){return this._volume}});Object.defineProperty(f.prototype,"flipY",{get:function(){return this._flipY},set:function(a){this._flipY!==a&&(this._flipY=a,this._needsUpload=!0)}});Object.defineProperty(f.prototype,
- "premultiplyAlpha",{get:function(){return this._premultiplyAlpha},set:function(a){this._premultiplyAlpha!==a&&(this._premultiplyAlpha=a,this._needsUpload=!0)}});Object.assign(f.prototype,{destroy:function(){this.device&&this.device.destroyTexture(this);this._levels=this.device=null},dirtyAll:function(){this._levelsUpdated=this._cubemap?[[!0,!0,!0,!0,!0,!0]]:[!0];this._needsUpload=!0;this._needsMipmapsUpload=this._mipmaps;this._mipmapsUploaded=!1;this._parameterFlags=255},lock:function(a){a=a||{level:0,
- face:0,mode:pc.TEXTURELOCK_WRITE};void 0===a.level&&(a.level=0);void 0===a.face&&(a.face=0);void 0===a.mode&&(a.mode=pc.TEXTURELOCK_WRITE);this._lockedLevel=a.level;if(null===this._levels[a.level])switch(this._format){case pc.PIXELFORMAT_A8:case pc.PIXELFORMAT_L8:this._levels[a.level]=new Uint8Array(this._width*this._height*this._depth);break;case pc.PIXELFORMAT_L8_A8:this._levels[a.level]=new Uint8Array(this._width*this._height*this._depth*2);break;case pc.PIXELFORMAT_R5_G6_B5:case pc.PIXELFORMAT_R5_G5_B5_A1:case pc.PIXELFORMAT_R4_G4_B4_A4:this._levels[a.level]=
- new Uint16Array(this._width*this._height*this._depth);break;case pc.PIXELFORMAT_R8_G8_B8:this._levels[a.level]=new Uint8Array(this._width*this._height*this._depth*3);break;case pc.PIXELFORMAT_R8_G8_B8_A8:this._levels[a.level]=new Uint8Array(this._width*this._height*this._depth*4);break;case pc.PIXELFORMAT_DXT1:this._levels[a.level]=new Uint8Array(Math.floor((this._width+3)/4)*Math.floor((this._height+3)/4)*8*this._depth);break;case pc.PIXELFORMAT_DXT3:case pc.PIXELFORMAT_DXT5:this._levels[a.level]=
- new Uint8Array(Math.floor((this._width+3)/4)*Math.floor((this._height+3)/4)*16*this._depth);break;case pc.PIXELFORMAT_RGB16F:this._levels[a.level]=new Uint16Array(this._width*this._height*this._depth*3);break;case pc.PIXELFORMAT_RGB32F:this._levels[a.level]=new Float32Array(this._width*this._height*this._depth*3);break;case pc.PIXELFORMAT_RGBA16F:this._levels[a.level]=new Uint16Array(this._width*this._height*this._depth*4);break;case pc.PIXELFORMAT_RGBA32F:this._levels[a.level]=new Float32Array(this._width*
- this._height*this._depth*4)}return this._levels[a.level]},setSource:function(a){var b,d=!1,e,g;if(this._cubemap){if(a[0])for(e=a[0].width||0,g=a[0].height||0,b=0;6>b;b++){if(!a[b]||a[b].width!==e||a[b].height!==g||!(a[b]instanceof HTMLImageElement||a[b]instanceof HTMLCanvasElement||a[b]instanceof HTMLVideoElement)){d=!0;break}}else d=!0;if(!d)for(b=0;6>b;b++)this._levels[0][b]!==a[b]&&(this._levelsUpdated[0][b]=!0)}else a instanceof HTMLImageElement||a instanceof HTMLCanvasElement||a instanceof HTMLVideoElement||
- (d=!0),d||(a!==this._levels[0]&&(this._levelsUpdated[0]=!0),e=a.width,g=a.height);if(d)if(this._height=this._width=4,this._pot=!0,this._cubemap)for(b=0;6>b;b++)this._levels[0][b]=null,this._levelsUpdated[0][b]=!0;else this._levels[0]=null,this._levelsUpdated[0]=!0;else this._width=e,this._height=g,this._pot=pc.math.powerOfTwo(this._width)&&pc.math.powerOfTwo(this._height),this._levels[0]=a;this._invalid===d&&d||(this._invalid=d,this.upload())},getSource:function(){return this._levels[0]},unlock:function(){this.upload();
- this._lockedLevel=-1},upload:function(){this._needsUpload=!0;this._needsMipmapsUpload=this._mipmaps},getDds:function(){this.format!==pc.PIXELFORMAT_R8_G8_B8_A8&&console.error("This format is not implemented yet");for(var a=128,b=0,d,e;this._levels[b];){if(this.cubemap)for(e=0;6>e;e++){if(!this._levels[b][e]){console.error("No level data for mip "+b+", face "+e);return}d=this._levels[b][e].length;if(!d){console.error("No byte array for mip "+b+", face "+e);return}a+=d}else{d=this._levels[b].length;
- if(!d){console.error("No byte array for mip "+b);return}a+=d}a+=this._levels[b].length;b++}a=new ArrayBuffer(a);e=new Uint32Array(a,0,32);b=528391;1<this._levels.length&&(b|=131072);d=4096;1<this._levels.length&&(d|=4194304);if(1<this._levels.length||this.cubemap)d|=8;var g=this.cubemap?65024:0;e[0]=542327876;e[1]=124;e[2]=b;e[3]=this.height;e[4]=this.width;e[5]=this.width*this.height*4;e[6]=0;e[7]=this._levels.length;for(b=0;11>b;b++)e[8+b]=0;e[19]=32;e[20]=65;e[21]=0;e[22]=32;e[23]=16711680;e[24]=
- 65280;e[25]=255;e[26]=4278190080;e[27]=d;e[28]=g;e[29]=0;e[30]=0;e[31]=0;var g=128,l,k;if(this.cubemap)for(e=0;6>e;e++)for(b=0;b<this._levels.length;b++){l=this._levels[b][e];k=new Uint8Array(a,g,l.length);for(d=0;d<l.length;d++)k[d]=l[d];g+=l.length}else for(b=0;b<this._levels.length;b++){l=this._levels[b];k=new Uint8Array(a,g,l.length);for(d=0;d<l.length;d++)k[d]=l[d];g+=l.length}return a}});return{Texture:f}}());Object.assign(pc,function(){var f={depth:!0,face:0},b=function(a,b,d){a instanceof pc.GraphicsDevice?(this._colorBuffer=b,a=d):this._colorBuffer=a.colorBuffer;this._glDepthBuffer=this._glFrameBuffer=null;a=void 0!==a?a:f;this._depthBuffer=a.depthBuffer;this._face=void 0!==a.face?a.face:0;this._depthBuffer?(b=this._depthBuffer._format,b===pc.PIXELFORMAT_DEPTH?(this._depth=!0,this._stencil=!1):this._stencil=b===pc.PIXELFORMAT_DEPTHSTENCIL?this._depth=!0:this._depth=!1):(this._depth=void 0!==a.depth?
- a.depth:!0,this._stencil=void 0!==a.stencil?a.stencil:!1);this._samples=void 0!==a.samples?a.samples:1;this.autoResolve=void 0!==a.autoResolve?a.autoResolve:!0;this._glMsaaDepthBuffer=this._glMsaaColorBuffer=this._glResolveFrameBuffer=null};Object.assign(b.prototype,{destroy:function(){if(this._device){var a=this._device,b=a.targets.indexOf(this);-1!==b&&a.targets.splice(b,1);a=a.gl;this._glFrameBuffer&&(a.deleteFramebuffer(this._glFrameBuffer),this._glFrameBuffer=null);this._glDepthBuffer&&(a.deleteRenderbuffer(this._glDepthBuffer),
- this._glDepthBuffer=null);this._glResolveFrameBuffer&&(a.deleteFramebuffer(this._glResolveFrameBuffer),this._glResolveFrameBuffer=null);this._glMsaaColorBuffer&&(a.deleteRenderbuffer(this._glMsaaColorBuffer),this._glMsaaColorBuffer=null);this._glMsaaDepthBuffer&&(a.deleteRenderbuffer(this._glMsaaDepthBuffer),this._glMsaaDepthBuffer=null)}},resolve:function(a,b){if(this._device&&this._device.webgl2){var c=this._device.gl;void 0===a&&(a=!0);void 0===b&&this._depthBuffer&&(b=!0);c.bindFramebuffer(c.READ_FRAMEBUFFER,
- this._glFrameBuffer);c.bindFramebuffer(c.DRAW_FRAMEBUFFER,this._glResolveFrameBuffer);c.blitFramebuffer(0,0,this.width,this.height,0,0,this.width,this.height,(a?c.COLOR_BUFFER_BIT:0)|(b?c.DEPTH_BUFFER_BIT:0),c.NEAREST);c.bindFramebuffer(c.FRAMEBUFFER,this._glFrameBuffer)}},copy:function(a,b,d){if(!this._device)if(a._device)this._device=a._device;else return!1;return this._device.copyRenderTarget(a,this,b,d)}});Object.defineProperty(b.prototype,"colorBuffer",{get:function(){return this._colorBuffer}});
- Object.defineProperty(b.prototype,"depthBuffer",{get:function(){return this._depthBuffer}});Object.defineProperty(b.prototype,"face",{get:function(){return this._face}});Object.defineProperty(b.prototype,"width",{get:function(){return this._colorBuffer?this._colorBuffer.width:this._depthBuffer.width}});Object.defineProperty(b.prototype,"height",{get:function(){return this._colorBuffer?this._colorBuffer.height:this._depthBuffer.height}});return{RenderTarget:b}}());Object.assign(pc,function(){return{ShaderInput:function(f,b,a,c){this.locationId=c;this.scopeId=f.scope.resolve(b);this.version=new pc.Version;a===pc.UNIFORMTYPE_FLOAT&&"[0]"===b.substr(b.length-3)&&(a=pc.UNIFORMTYPE_FLOATARRAY);this.dataType=a;this.value=[null,null,null,null];this.array=[]}}}());Object.assign(pc,function(){var f=function(b,a){this.device=b;this.definition=a;this.attributes=[];this.uniforms=[];this.samplers=[];this.ready=!1;this._refCount=0;this.device.createShader(this)};Object.assign(f.prototype,{destroy:function(){this.device.destroyShader(this)}});return{Shader:f}}());Object.assign(pc,function(){var f=function(b){this._device=b;this._cache={};this._generators={};this._precached=this._isClearingCache=!1;this._programsCollection=[];this._defaultStdMatOption={};this._defaultStdMatOptionMin={};var a=new pc.StandardMaterial;a.shaderOptBuilder.updateRef(this._defaultStdMatOption,b,{},a,null,[],pc.SHADER_FORWARD,null,null);a.shaderOptBuilder.updateMinRef(this._defaultStdMatOptionMin,b,{},a,null,[],pc.SHADER_SHADOW,null,null)};f.prototype.register=function(b,a){this.isRegistered(b)||
- (this._generators[b]=a)};f.prototype.unregister=function(b){this.isRegistered(b)&&delete this._generators[b]};f.prototype.isRegistered=function(b){return void 0!==this._generators[b]};f.prototype.getProgram=function(b,a){var c=this._generators[b];if(void 0===c)return null;var d=this._device,e=c.generateKey(a),g=this._cache[e];if(!g){var l;a.lights&&(l=a.lights,a.lights=l.map(function(a){var b=a.clone?a.clone():a;b.key=a.key;return b}));this.storeNewProgram(b,a);a.lights&&(a.lights=l);this._precached&&
- console.warn("ProgramLibrary#getProgram: Cache miss for shader",b,"key",e,"after shaders precaching");c=c.createShaderDefinition(d,a);g=this._cache[e]=new pc.Shader(d,c)}return g};f.prototype.storeNewProgram=function(b,a){var c={};if("standard"===b){var d=this._getDefaultStdMatOptions(a.pass),e;for(e in a)if(a.hasOwnProperty(e)&&d[e]!==a[e]||"pass"===e)c[e]=a[e]}else c=a;this._programsCollection.push(JSON.stringify({name:b,options:c}))};f.prototype.dumpPrograms=function(){var b;b="var device = pc.app ? pc.app.graphicsDevice : pc.Application.getApplication().graphicsDevice;\nvar shaders = [";
- this._programsCollection[0]&&(b+="\n\t"+this._programsCollection[0]);for(var a=1;a<this._programsCollection.length;++a)b+=",\n\t"+this._programsCollection[a];b=b+"\n];\ndevice.programLib.precompile(shaders);\n"+('if (pc.version != "'+pc.version+'" || pc.revision != "'+pc.revision+'")\n');b+='\tconsole.warn("precompile-shaders.js: engine version mismatch, rebuild shaders lib with current engine");';a=document.createElement("a");a.setAttribute("href","data:text/plain;charset=utf-8,"+encodeURIComponent(b));
- a.setAttribute("download","precompile-shaders.js");a.style.display="none";document.body.appendChild(a);a.click();document.body.removeChild(a)};f.prototype.clearCache=function(){var b=this._cache;this._isClearingCache=!0;for(var a in b)b.hasOwnProperty(a)&&b[a].destroy();this._cache={};this._isClearingCache=!1};f.prototype.removeFromCache=function(b){if(!this._isClearingCache){var a=this._cache,c;for(c in a)if(a.hasOwnProperty(c)&&a[c]===b){delete a[c];break}}};f.prototype._getDefaultStdMatOptions=
- function(b){return b>pc.SHADER_FORWARDHDR&&b<=pc.SHADER_PICK?this._defaultStdMatOptionMin:this._defaultStdMatOption};f.prototype.precompile=function(b){if(b)for(var a=Array(b.length),c=0;c<b.length;c++){if("standard"===b[c].name){var d=b[c].options,e=this._getDefaultStdMatOptions(d.pass),g;for(g in e)e.hasOwnProperty(g)&&void 0===d[g]&&(d[g]=e[g]);d.useTexCubeLod=this._device.useTexCubeLod}a[c]=this.getProgram(b[c].name,b[c].options)}this._precached=!0};return{ProgramLibrary:f}}());Object.assign(pc,function(){function f(a,b){var c=!0,d=a.createTexture();a.bindTexture(a.TEXTURE_2D,d);a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MIN_FILTER,a.NEAREST);a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MAG_FILTER,a.NEAREST);a.texParameteri(a.TEXTURE_2D,a.TEXTURE_WRAP_S,a.CLAMP_TO_EDGE);a.texParameteri(a.TEXTURE_2D,a.TEXTURE_WRAP_T,a.CLAMP_TO_EDGE);a.texImage2D(a.TEXTURE_2D,0,a.RGBA,2,2,0,a.RGBA,b,null);var l=a.createFramebuffer();a.bindFramebuffer(a.FRAMEBUFFER,l);a.framebufferTexture2D(a.FRAMEBUFFER,
- a.COLOR_ATTACHMENT0,a.TEXTURE_2D,d,0);a.checkFramebufferStatus(a.FRAMEBUFFER)!==a.FRAMEBUFFER_COMPLETE&&(c=!1);a.bindTexture(a.TEXTURE_2D,null);a.deleteTexture(d);a.bindFramebuffer(a.FRAMEBUFFER,null);a.deleteFramebuffer(l);return c}var b=function(a,b){var c=a.width,d=a.height;if(c>b||d>b){var l=b/Math.max(c,d),k=Math.floor(c*l),l=Math.floor(d*l);console.warn("Image dimensions larger than max supported texture size of "+b+". Resizing from "+c+", "+d+" to "+k+", "+l+".");var f=document.createElement("canvas");
- f.width=k;f.height=l;f.getContext("2d").drawImage(a,0,0,c,d,0,0,k,l);return f}return a},a=function(a,b){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=null;this.instancedAttribs={};this.enabledAttributes={};this.activeFramebuffer=this.transformFeedbackBuffer=null;this.textureUnit=0;this.textureUnits=[];this._maxPixelRatio=
- 1;this.feedback=this.renderTarget=null;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,l=d?["webgl2","experimental-webgl2","webgl","experimental-webgl"]:["webgl","experimental-webgl"],k=null;b=b||{};b.stencil=!0;for(c=0;c<l.length;c++){try{k=a.getContext(l[c],b)}catch(t){}if(k){this.webgl2=d&&2>c;break}}if(!k)throw Error("WebGL not supported");this.gl=k;this.initializeExtensions();this.initializeCapabilities();this.initializeRenderState();
- for(c=0;c<this.maxCombinedTextures;c++)this.textureUnits.push([null,null,null]);this.defaultClearOptions={color:[0,0,0,1],depth:1,stencil:0,flags:pc.CLEARFLAG_COLOR|pc.CLEARFLAG_DEPTH};this.glAddress=[k.REPEAT,k.CLAMP_TO_EDGE,k.MIRRORED_REPEAT];this.glBlendEquation=[k.FUNC_ADD,k.FUNC_SUBTRACT,k.FUNC_REVERSE_SUBTRACT,this.webgl2?k.MIN:this.extBlendMinmax?this.extBlendMinmax.MIN_EXT:k.FUNC_ADD,this.webgl2?k.MAX:this.extBlendMinmax?this.extBlendMinmax.MAX_EXT:k.FUNC_ADD];this.glBlendFunction=[k.ZERO,
- k.ONE,k.SRC_COLOR,k.ONE_MINUS_SRC_COLOR,k.DST_COLOR,k.ONE_MINUS_DST_COLOR,k.SRC_ALPHA,k.SRC_ALPHA_SATURATE,k.ONE_MINUS_SRC_ALPHA,k.DST_ALPHA,k.ONE_MINUS_DST_ALPHA];this.glComparison=[k.NEVER,k.LESS,k.EQUAL,k.LEQUAL,k.GREATER,k.NOTEQUAL,k.GEQUAL,k.ALWAYS];this.glStencilOp=[k.KEEP,k.ZERO,k.REPLACE,k.INCR,k.INCR_WRAP,k.DECR,k.DECR_WRAP,k.INVERT];this.glClearFlag=[0,k.COLOR_BUFFER_BIT,k.DEPTH_BUFFER_BIT,k.COLOR_BUFFER_BIT|k.DEPTH_BUFFER_BIT,k.STENCIL_BUFFER_BIT,k.STENCIL_BUFFER_BIT|k.COLOR_BUFFER_BIT,
- k.STENCIL_BUFFER_BIT|k.DEPTH_BUFFER_BIT,k.STENCIL_BUFFER_BIT|k.COLOR_BUFFER_BIT|k.DEPTH_BUFFER_BIT];this.glCull=[0,k.BACK,k.FRONT,k.FRONT_AND_BACK];this.glFilter=[k.NEAREST,k.LINEAR,k.NEAREST_MIPMAP_NEAREST,k.NEAREST_MIPMAP_LINEAR,k.LINEAR_MIPMAP_NEAREST,k.LINEAR_MIPMAP_LINEAR];this.glPrimitive=[k.POINTS,k.LINES,k.LINE_LOOP,k.LINE_STRIP,k.TRIANGLES,k.TRIANGLE_STRIP,k.TRIANGLE_FAN];this.glType=[k.BYTE,k.UNSIGNED_BYTE,k.SHORT,k.UNSIGNED_SHORT,k.INT,k.UNSIGNED_INT,k.FLOAT];this.pcUniformType={};this.pcUniformType[k.BOOL]=
- pc.UNIFORMTYPE_BOOL;this.pcUniformType[k.INT]=pc.UNIFORMTYPE_INT;this.pcUniformType[k.FLOAT]=pc.UNIFORMTYPE_FLOAT;this.pcUniformType[k.FLOAT_VEC2]=pc.UNIFORMTYPE_VEC2;this.pcUniformType[k.FLOAT_VEC3]=pc.UNIFORMTYPE_VEC3;this.pcUniformType[k.FLOAT_VEC4]=pc.UNIFORMTYPE_VEC4;this.pcUniformType[k.INT_VEC2]=pc.UNIFORMTYPE_IVEC2;this.pcUniformType[k.INT_VEC3]=pc.UNIFORMTYPE_IVEC3;this.pcUniformType[k.INT_VEC4]=pc.UNIFORMTYPE_IVEC4;this.pcUniformType[k.BOOL_VEC2]=pc.UNIFORMTYPE_BVEC2;this.pcUniformType[k.BOOL_VEC3]=
- pc.UNIFORMTYPE_BVEC3;this.pcUniformType[k.BOOL_VEC4]=pc.UNIFORMTYPE_BVEC4;this.pcUniformType[k.FLOAT_MAT2]=pc.UNIFORMTYPE_MAT2;this.pcUniformType[k.FLOAT_MAT3]=pc.UNIFORMTYPE_MAT3;this.pcUniformType[k.FLOAT_MAT4]=pc.UNIFORMTYPE_MAT4;this.pcUniformType[k.SAMPLER_2D]=pc.UNIFORMTYPE_TEXTURE2D;this.pcUniformType[k.SAMPLER_CUBE]=pc.UNIFORMTYPE_TEXTURECUBE;this.webgl2&&(this.pcUniformType[k.SAMPLER_2D_SHADOW]=pc.UNIFORMTYPE_TEXTURE2D_SHADOW,this.pcUniformType[k.SAMPLER_CUBE_SHADOW]=pc.UNIFORMTYPE_TEXTURECUBE_SHADOW,
- this.pcUniformType[k.SAMPLER_3D]=pc.UNIFORMTYPE_TEXTURE3D);this.targetToSlot={};this.targetToSlot[k.TEXTURE_2D]=0;this.targetToSlot[k.TEXTURE_CUBE_MAP]=1;this.targetToSlot[k.TEXTURE_3D]=2;var p,h,n,q,m;this.commitFunction=[];this.commitFunction[pc.UNIFORMTYPE_BOOL]=function(a,b){a.value!==b&&(k.uniform1i(a.locationId,b),a.value=b)};this.commitFunction[pc.UNIFORMTYPE_INT]=this.commitFunction[pc.UNIFORMTYPE_BOOL];this.commitFunction[pc.UNIFORMTYPE_FLOAT]=function(a,b){a.value!==b&&(k.uniform1f(a.locationId,
- b),a.value=b)};this.commitFunction[pc.UNIFORMTYPE_VEC2]=function(a,b){m=a.value;p=b[0];h=b[1];if(m[0]!==p||m[1]!==h)k.uniform2fv(a.locationId,b),m[0]=p,m[1]=h};this.commitFunction[pc.UNIFORMTYPE_VEC3]=function(a,b){m=a.value;p=b[0];h=b[1];n=b[2];if(m[0]!==p||m[1]!==h||m[2]!==n)k.uniform3fv(a.locationId,b),m[0]=p,m[1]=h,m[2]=n};this.commitFunction[pc.UNIFORMTYPE_VEC4]=function(a,b){m=a.value;p=b[0];h=b[1];n=b[2];q=b[3];if(m[0]!==p||m[1]!==h||m[2]!==n||m[3]!==q)k.uniform4fv(a.locationId,b),m[0]=p,m[1]=
- h,m[2]=n,m[3]=q};this.commitFunction[pc.UNIFORMTYPE_IVEC2]=function(a,b){m=a.value;p=b[0];h=b[1];if(m[0]!==p||m[1]!==h)k.uniform2iv(a.locationId,b),m[0]=p,m[1]=h};this.commitFunction[pc.UNIFORMTYPE_BVEC2]=this.commitFunction[pc.UNIFORMTYPE_IVEC2];this.commitFunction[pc.UNIFORMTYPE_IVEC3]=function(a,b){m=a.value;p=b[0];h=b[1];n=b[2];if(m[0]!==p||m[1]!==h||m[2]!==n)k.uniform3iv(a.locationId,b),m[0]=p,m[1]=h,m[2]=n};this.commitFunction[pc.UNIFORMTYPE_BVEC3]=this.commitFunction[pc.UNIFORMTYPE_IVEC3];
- this.commitFunction[pc.UNIFORMTYPE_IVEC4]=function(a,b){m=a.value;p=b[0];h=b[1];n=b[2];q=b[3];if(m[0]!==p||m[1]!==h||m[2]!==n||m[3]!==q)k.uniform4iv(a.locationId,b),m[0]=p,m[1]=h,m[2]=n,m[3]=q};this.commitFunction[pc.UNIFORMTYPE_BVEC4]=this.commitFunction[pc.UNIFORMTYPE_IVEC4];this.commitFunction[pc.UNIFORMTYPE_MAT2]=function(a,b){k.uniformMatrix2fv(a.locationId,!1,b)};this.commitFunction[pc.UNIFORMTYPE_MAT3]=function(a,b){k.uniformMatrix3fv(a.locationId,!1,b)};this.commitFunction[pc.UNIFORMTYPE_MAT4]=
- function(a,b){k.uniformMatrix4fv(a.locationId,!1,b)};this.commitFunction[pc.UNIFORMTYPE_FLOATARRAY]=function(a,b){k.uniform1fv(a.locationId,b)};this.scope=new pc.ScopeSpace("Device");this.programLib=new pc.ProgramLibrary(this);for(var r in pc.programlib)this.programLib.register(r,pc.programlib[r]);pc.events.attach(this);this.supportsBoneTextures=this.extTextureFloat&&0<this.maxVertexTextures;this.useTexCubeLod=this.extTextureLod&&16>this.maxTextures;this.boneLimit=Math.floor((this.vertexUniformsCount-
- 16-8-1-16)/4);this.boneLimit=Math.min(this.boneLimit,128);"Mali-450 MP"===this.unmaskedRenderer&&(this.boneLimit=34);"Apple A8 GPU"===this.unmaskedRenderer&&(this.forceCpuParticles=!0);this._shaderSwitchesPerFrame=this._drawCallsPerFrame=0;this._primsPerFrame=[];for(c=pc.PRIMITIVE_POINTS;c<=pc.PRIMITIVE_TRIFAN;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:f(k,k.FLOAT):!1;this.textureHalfFloatRenderable=this.extTextureHalfFloat?this.webgl2?!!this.extColorBufferFloat:f(k,this.extTextureHalfFloat.HALF_FLOAT_OES):!1;this._textureFloatHighPrecision=void 0;this.initializeGrabPassTexture()};Object.assign(a.prototype,{getPrecision:function(){var a=this.gl,b="highp";if(a.getShaderPrecisionFormat){var e=a.getShaderPrecisionFormat(a.VERTEX_SHADER,
- a.HIGH_FLOAT),g=a.getShaderPrecisionFormat(a.VERTEX_SHADER,a.MEDIUM_FLOAT),l=a.getShaderPrecisionFormat(a.FRAGMENT_SHADER,a.HIGH_FLOAT),a=a.getShaderPrecisionFormat(a.FRAGMENT_SHADER,a.MEDIUM_FLOAT),g=0<g.precision&&0<a.precision;0<e.precision&&0<l.precision||(b=g?"mediump":"lowp")}return b},initializeExtensions:function(){var a=this.gl,b,e=a.getSupportedExtensions(),g=function(){for(var b=null,c=0;c<arguments.length;c++)-1!==e.indexOf(arguments[c])&&(b=a.getExtension(arguments[c]));return b};if(this.webgl2)this.extVertexArrayObject=
- this.extUintElement=this.extTextureLod=this.extTextureHalfFloatLinear=this.extTextureHalfFloat=this.extTextureFloat=this.extStandardDerivatives=this.extInstancing=this.extDrawBuffers=this.extBlendMinmax=!0,this.extColorBufferFloat=g("EXT_color_buffer_float");else{this.extBlendMinmax=g("EXT_blend_minmax");this.extDrawBuffers=g("EXT_draw_buffers");if(this.extInstancing=g("ANGLE_instanced_arrays"))b=this.extInstancing,a.drawArraysInstanced=b.drawArraysInstancedANGLE.bind(b),a.drawElementsInstanced=b.drawElementsInstancedANGLE.bind(b),
- a.vertexAttribDivisor=b.vertexAttribDivisorANGLE.bind(b);this.extStandardDerivatives=g("OES_standard_derivatives");this.extTextureFloat=g("OES_texture_float");this.extTextureHalfFloat=g("OES_texture_half_float");this.extTextureHalfFloatLinear=g("OES_texture_half_float_linear");this.extTextureLod=g("EXT_shader_texture_lod");this.extUintElement=g("OES_element_index_uint");if(this.extVertexArrayObject=g("OES_vertex_array_object"))b=this.extVertexArrayObject,a.createVertexArray=b.createVertexArrayOES.bind(b),
- a.deleteVertexArray=b.deleteVertexArrayOES.bind(b),a.isVertexArray=b.isVertexArrayOES.bind(b),a.bindVertexArray=b.bindVertexArrayOES.bind(b);this.extColorBufferFloat=null}this.extDebugRendererInfo=g("WEBGL_debug_renderer_info");this.extTextureFloatLinear=g("OES_texture_float_linear");this.extTextureFilterAnisotropic=g("EXT_texture_filter_anisotropic","WEBKIT_EXT_texture_filter_anisotropic");this.extCompressedTextureETC1=g("WEBGL_compressed_texture_etc1");this.extCompressedTextureETC=g("WEBGL_compressed_texture_etc");
- this.extCompressedTexturePVRTC=g("WEBGL_compressed_texture_pvrtc","WEBKIT_WEBGL_compressed_texture_pvrtc");this.extCompressedTextureS3TC=g("WEBGL_compressed_texture_s3tc","WEBKIT_WEBGL_compressed_texture_s3tc");this.extParallelShaderCompile=g("KHR_parallel_shader_compile")},initializeCapabilities:function(){var a=this.gl,b;this.maxPrecision=this.precision=this.getPrecision();b=a.getContextAttributes();this.supportsMsaa=b.antialias;this.supportsStencil=b.stencil;this.maxTextureSize=a.getParameter(a.MAX_TEXTURE_SIZE);
- this.maxCubeMapSize=a.getParameter(a.MAX_CUBE_MAP_TEXTURE_SIZE);this.maxRenderBufferSize=a.getParameter(a.MAX_RENDERBUFFER_SIZE);this.maxTextures=a.getParameter(a.MAX_TEXTURE_IMAGE_UNITS);this.maxCombinedTextures=a.getParameter(a.MAX_COMBINED_TEXTURE_IMAGE_UNITS);this.maxVertexTextures=a.getParameter(a.MAX_VERTEX_TEXTURE_IMAGE_UNITS);this.vertexUniformsCount=a.getParameter(a.MAX_VERTEX_UNIFORM_VECTORS);this.fragmentUniformsCount=a.getParameter(a.MAX_FRAGMENT_UNIFORM_VECTORS);this.webgl2?(this.maxDrawBuffers=
- a.getParameter(a.MAX_DRAW_BUFFERS),this.maxColorAttachments=a.getParameter(a.MAX_COLOR_ATTACHMENTS),this.maxVolumeSize=a.getParameter(a.MAX_3D_TEXTURE_SIZE)):(this.maxDrawBuffers=(b=this.extDrawBuffers)?a.getParameter(b.MAX_DRAW_BUFFERS_EXT):1,this.maxColorAttachments=b?a.getParameter(b.MAX_COLOR_ATTACHMENTS_EXT):1,this.maxVolumeSize=1);this.unmaskedRenderer=(b=this.extDebugRendererInfo)?a.getParameter(b.UNMASKED_RENDERER_WEBGL):"";this.unmaskedVendor=b?a.getParameter(b.UNMASKED_VENDOR_WEBGL):"";
- this.maxAnisotropy=(b=this.extTextureFilterAnisotropic)?a.getParameter(b.MAX_TEXTURE_MAX_ANISOTROPY_EXT):1},initializeRenderState:function(){var a=this.gl;this.blending=!1;a.disable(a.BLEND);this.blendSrc=pc.BLENDMODE_ONE;this.blendDst=pc.BLENDMODE_ZERO;this.blendSrcAlpha=pc.BLENDMODE_ONE;this.blendDstAlpha=pc.BLENDMODE_ZERO;this.separateAlphaBlend=!1;this.blendAlphaEquation=this.blendEquation=pc.BLENDEQUATION_ADD;this.separateAlphaEquation=!1;a.blendFunc(a.ONE,a.ZERO);a.blendEquation(a.FUNC_ADD);
- this.writeAlpha=this.writeBlue=this.writeGreen=this.writeRed=!0;a.colorMask(!0,!0,!0,!0);this.cullMode=pc.CULLFACE_BACK;a.enable(a.CULL_FACE);a.cullFace(a.BACK);this.depthTest=!0;a.enable(a.DEPTH_TEST);this.depthFunc=pc.FUNC_LESSEQUAL;a.depthFunc(a.LEQUAL);this.depthWrite=!0;a.depthMask(!0);this.stencil=!1;a.disable(a.STENCIL_TEST);this.stencilFuncFront=this.stencilFuncBack=pc.FUNC_ALWAYS;this.stencilRefFront=this.stencilRefBack=0;this.stencilMaskFront=this.stencilMaskBack=255;a.stencilFunc(a.ALWAYS,
- 0,255);this.stencilZpassFront=this.stencilZpassBack=this.stencilZfailFront=this.stencilZfailBack=this.stencilFailFront=this.stencilFailBack=pc.STENCILOP_KEEP;this.stencilWriteMaskBack=this.stencilWriteMaskFront=255;a.stencilOp(a.KEEP,a.KEEP,a.KEEP);a.stencilMask(255);this.alphaToCoverage=!1;this.raster=!0;this.webgl2&&(a.disable(a.SAMPLE_ALPHA_TO_COVERAGE),a.disable(a.RASTERIZER_DISCARD));this.depthBiasEnabled=!1;a.disable(a.POLYGON_OFFSET_FILL);this.clearDepth=1;a.clearDepth(1);this.clearAlpha=this.clearGreen=
- this.clearBlue=this.clearRed=0;a.clearColor(0,0,0,0);this.clearStencil=0;a.clearStencil(0);this.sx=this.sy=this.sw=this.sh=this.vx=this.vy=this.vw=this.vh=0;this.webgl2?a.hint(a.FRAGMENT_SHADER_DERIVATIVE_HINT,a.NICEST):this.extStandardDerivatives&&a.hint(this.extStandardDerivatives.FRAGMENT_SHADER_DERIVATIVE_HINT_OES,a.NICEST);a.enable(a.SCISSOR_TEST);a.pixelStorei(a.UNPACK_COLORSPACE_CONVERSION_WEBGL,a.NONE);this.unpackFlipY=!1;a.pixelStorei(a.UNPACK_FLIP_Y_WEBGL,!1);this.unpackPremultiplyAlpha=
- !1;a.pixelStorei(a.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1)},initializeContext:function(){this.initializeExtensions();this.initializeCapabilities();this.initializeRenderState();var a,b;a=0;for(b=this.shaders.length;a<b;a++)this.compileAndLinkShader(this.shaders[a]);this.shader=null;a=0;for(b=this.buffers.length;a<b;a++)this.buffers[a].bufferId=void 0,this.buffers[a].unlock();this.indexBuffer=this.boundElementBuffer=this.boundBuffer=null;this.attributesInvalidated=!0;this.enabledAttributes={};this.vertexBuffers=
- [];a=0;for(b=this.textures.length;a<b;a++){var e=this.textures[a];this.destroyTexture(e);e.dirtyAll()}this.textureUnit=0;for(a=this.textureUnits.length=0;a<this.maxCombinedTextures;a++)this.textureUnits.push([null,null,null]);a=0;for(b=this.targets.length;a<b;a++)this.targets[a]._glFrameBuffer=void 0,this.targets[a]._glDepthBuffer=void 0,this.targets[a]._glResolveFrameBuffer=void 0,this.targets[a]._glMsaaColorBuffer=void 0,this.targets[a]._glMsaaDepthBuffer=void 0;this.transformFeedbackBuffer=this.feedback=
- this.activeFramebuffer=this.renderTarget=null},initializeGrabPassTexture:function(){if(!this.grabPassTexture){var a=new pc.Texture(this,{format:pc.PIXELFORMAT_R8_G8_B8_A8,autoMipmap:!1});a.minFilter=pc.FILTER_LINEAR;a.magFilter=pc.FILTER_LINEAR;a.addressU=pc.ADDRESS_CLAMP_TO_EDGE;a.addressV=pc.ADDRESS_CLAMP_TO_EDGE;a.name="texture_grabPass";a.setSource(this.canvas);var b=this.scope.resolve(a.name);b.setValue(a);this.grabPassTextureId=b;this.grabPassTexture=a}},updateClientRect:function(){this.clientRect=
- this.canvas.getBoundingClientRect()},setViewport:function(a,b,e,g){if(this.vx!==a||this.vy!==b||this.vw!==e||this.vh!==g)this.gl.viewport(a,b,e,g),this.vx=a,this.vy=b,this.vw=e,this.vh=g},setScissor:function(a,b,e,g){if(this.sx!==a||this.sy!==b||this.sw!==e||this.sh!==g)this.gl.scissor(a,b,e,g),this.sx=a,this.sy=b,this.sw=e,this.sh=g},getProgramLibrary:function(){return this.programLib},setProgramLibrary:function(a){this.programLib=a},setFramebuffer:function(a){this.activeFramebuffer!==a&&(this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,
- a),this.activeFramebuffer=a)},_checkFbo:function(){var a=this.gl;switch(a.checkFramebufferStatus(a.FRAMEBUFFER)){case a.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:console.error("ERROR: FRAMEBUFFER_INCOMPLETE_ATTACHMENT");break;case a.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:console.error("ERROR: FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT");break;case a.FRAMEBUFFER_INCOMPLETE_DIMENSIONS:console.error("ERROR: FRAMEBUFFER_INCOMPLETE_DIMENSIONS");break;case a.FRAMEBUFFER_UNSUPPORTED:console.error("ERROR: FRAMEBUFFER_UNSUPPORTED")}},
- copyRenderTarget:function(a,b,e,g){var c=this.gl;if(!this.webgl2&&g)return!1;if(e)if(!b){if(!a._colorBuffer)return!1}else if(!a._colorBuffer||!b._colorBuffer||a._colorBuffer._format!==b._colorBuffer._format)return!1;if(g&&(!a._depthBuffer||!b._depthBuffer||a._depthBuffer._format!==b._depthBuffer._format))return!1;if(this.webgl2&&b){var d=this.renderTarget;this.renderTarget=b;this.updateBegin();c.bindFramebuffer(c.READ_FRAMEBUFFER,a?a._glFrameBuffer:null);c.bindFramebuffer(c.DRAW_FRAMEBUFFER,b._glFrameBuffer);
- var f=a?a.width:b.width;a=a?a.height:b.height;c.blitFramebuffer(0,0,f,a,0,0,f,a,(e?c.COLOR_BUFFER_BIT:0)|(g?c.DEPTH_BUFFER_BIT:0),c.NEAREST);this.renderTarget=d;c.bindFramebuffer(c.FRAMEBUFFER,d?d._glFrameBuffer:null)}else this._copyShader||(e=pc.shaderChunks,this._copyShader=e.createShaderFromCode(this,e.fullscreenQuadVS,e.outputTex2DPS,"outputTex2D")),this.constantTexSource.setValue(a._colorBuffer),pc.drawQuadWithShader(this,b,this._copyShader);return!0},updateBegin:function(){var a=this.gl;this.boundElementBuffer=
- this.boundBuffer=null;var b=this.renderTarget;if(b)if(b._glFrameBuffer)this.setFramebuffer(b._glFrameBuffer);else{b._device=this;b._glFrameBuffer=a.createFramebuffer();this.setFramebuffer(b._glFrameBuffer);var e=b._colorBuffer;e&&(e._glTexture||(e._width=Math.min(e.width,this.maxRenderBufferSize),e._height=Math.min(e.height,this.maxRenderBufferSize),this.setTexture(e,0)),a.framebufferTexture2D(a.FRAMEBUFFER,a.COLOR_ATTACHMENT0,e._cubemap?a.TEXTURE_CUBE_MAP_POSITIVE_X+b._face:a.TEXTURE_2D,e._glTexture,
- 0));var g=b._depthBuffer;g&&this.webgl2?(g._glTexture||(g._width=Math.min(g.width,this.maxRenderBufferSize),g._height=Math.min(g.height,this.maxRenderBufferSize),this.setTexture(g,0)),b._stencil?a.framebufferTexture2D(a.FRAMEBUFFER,a.DEPTH_STENCIL_ATTACHMENT,g._cubemap?a.TEXTURE_CUBE_MAP_POSITIVE_X+b._face:a.TEXTURE_2D,b._depthBuffer._glTexture,0):a.framebufferTexture2D(a.FRAMEBUFFER,a.DEPTH_ATTACHMENT,g._cubemap?a.TEXTURE_CUBE_MAP_POSITIVE_X+b._face:a.TEXTURE_2D,b._depthBuffer._glTexture,0)):!b._depth||
- 1<b._samples&&this.webgl2||(b._glDepthBuffer||(b._glDepthBuffer=a.createRenderbuffer()),a.bindRenderbuffer(a.RENDERBUFFER,b._glDepthBuffer),b._stencil?(a.renderbufferStorage(a.RENDERBUFFER,a.DEPTH_STENCIL,b.width,b.height),a.framebufferRenderbuffer(a.FRAMEBUFFER,a.DEPTH_STENCIL_ATTACHMENT,a.RENDERBUFFER,b._glDepthBuffer)):(a.renderbufferStorage(a.RENDERBUFFER,a.DEPTH_COMPONENT16,b.width,b.height),a.framebufferRenderbuffer(a.FRAMEBUFFER,a.DEPTH_ATTACHMENT,a.RENDERBUFFER,b._glDepthBuffer)),a.bindRenderbuffer(a.RENDERBUFFER,
- null));this.webgl2&&1<b._samples&&(b._glResolveFrameBuffer=b._glFrameBuffer,b._glFrameBuffer=a.createFramebuffer(),this.setFramebuffer(b._glFrameBuffer),e&&(b._glMsaaColorBuffer||(b._glMsaaColorBuffer=a.createRenderbuffer()),a.bindRenderbuffer(a.RENDERBUFFER,b._glMsaaColorBuffer),a.renderbufferStorageMultisample(a.RENDERBUFFER,b._samples,e._glInternalFormat,b.width,b.height),a.framebufferRenderbuffer(a.FRAMEBUFFER,a.COLOR_ATTACHMENT0,a.RENDERBUFFER,b._glMsaaColorBuffer)),b._depth&&(b._glMsaaDepthBuffer||
- (b._glMsaaDepthBuffer=a.createRenderbuffer()),a.bindRenderbuffer(a.RENDERBUFFER,b._glMsaaDepthBuffer),b._stencil?(a.renderbufferStorageMultisample(a.RENDERBUFFER,b._samples,a.DEPTH24_STENCIL8,b.width,b.height),a.framebufferRenderbuffer(a.FRAMEBUFFER,a.DEPTH_STENCIL_ATTACHMENT,a.RENDERBUFFER,b._glMsaaDepthBuffer)):(a.renderbufferStorageMultisample(a.RENDERBUFFER,b._samples,a.DEPTH_COMPONENT32F,b.width,b.height),a.framebufferRenderbuffer(a.FRAMEBUFFER,a.DEPTH_ATTACHMENT,a.RENDERBUFFER,b._glMsaaDepthBuffer))));
- this.targets.push(b)}else this.setFramebuffer(null)},updateEnd:function(){var a=this.gl,b=this.renderTarget;if(b){var e=b._colorBuffer;e&&e._glTexture&&e.mipmaps&&e._pot&&(this.activeTexture(this.maxCombinedTextures-1),this.bindTexture(e),a.generateMipmap(e._glTarget));this.webgl2&&1<b._samples&&b.autoResolve&&b.resolve()}},initializeTexture:function(a){var b=this.gl,c;a._glTexture=b.createTexture();a._glTarget=a._cubemap?b.TEXTURE_CUBE_MAP:a._volume?b.TEXTURE_3D:b.TEXTURE_2D;switch(a._format){case pc.PIXELFORMAT_A8:a._glFormat=
- b.ALPHA;a._glInternalFormat=b.ALPHA;a._glPixelType=b.UNSIGNED_BYTE;break;case pc.PIXELFORMAT_L8:a._glFormat=b.LUMINANCE;a._glInternalFormat=b.LUMINANCE;a._glPixelType=b.UNSIGNED_BYTE;break;case pc.PIXELFORMAT_L8_A8:a._glFormat=b.LUMINANCE_ALPHA;a._glInternalFormat=b.LUMINANCE_ALPHA;a._glPixelType=b.UNSIGNED_BYTE;break;case pc.PIXELFORMAT_R5_G6_B5:a._glFormat=b.RGB;a._glInternalFormat=b.RGB;a._glPixelType=b.UNSIGNED_SHORT_5_6_5;break;case pc.PIXELFORMAT_R5_G5_B5_A1:a._glFormat=b.RGBA;a._glInternalFormat=
- b.RGBA;a._glPixelType=b.UNSIGNED_SHORT_5_5_5_1;break;case pc.PIXELFORMAT_R4_G4_B4_A4:a._glFormat=b.RGBA;a._glInternalFormat=b.RGBA;a._glPixelType=b.UNSIGNED_SHORT_4_4_4_4;break;case pc.PIXELFORMAT_R8_G8_B8:a._glFormat=b.RGB;a._glInternalFormat=this.webgl2?b.RGB8:b.RGB;a._glPixelType=b.UNSIGNED_BYTE;break;case pc.PIXELFORMAT_R8_G8_B8_A8:a._glFormat=b.RGBA;a._glInternalFormat=this.webgl2?b.RGBA8:b.RGBA;a._glPixelType=b.UNSIGNED_BYTE;break;case pc.PIXELFORMAT_DXT1:c=this.extCompressedTextureS3TC;a._glFormat=
- b.RGB;a._glInternalFormat=c.COMPRESSED_RGB_S3TC_DXT1_EXT;break;case pc.PIXELFORMAT_DXT3:c=this.extCompressedTextureS3TC;a._glFormat=b.RGBA;a._glInternalFormat=c.COMPRESSED_RGBA_S3TC_DXT3_EXT;break;case pc.PIXELFORMAT_DXT5:c=this.extCompressedTextureS3TC;a._glFormat=b.RGBA;a._glInternalFormat=c.COMPRESSED_RGBA_S3TC_DXT5_EXT;break;case pc.PIXELFORMAT_ETC1:c=this.extCompressedTextureETC1;a._glFormat=b.RGB;a._glInternalFormat=c.COMPRESSED_RGB_ETC1_WEBGL;break;case pc.PIXELFORMAT_PVRTC_2BPP_RGB_1:c=this.extCompressedTexturePVRTC;
- a._glFormat=b.RGB;a._glInternalFormat=c.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;break;case pc.PIXELFORMAT_PVRTC_2BPP_RGBA_1:c=this.extCompressedTexturePVRTC;a._glFormat=b.RGBA;a._glInternalFormat=c.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;break;case pc.PIXELFORMAT_PVRTC_4BPP_RGB_1:c=this.extCompressedTexturePVRTC;a._glFormat=b.RGB;a._glInternalFormat=c.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;break;case pc.PIXELFORMAT_PVRTC_4BPP_RGBA_1:c=this.extCompressedTexturePVRTC;a._glFormat=b.RGBA;a._glInternalFormat=c.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
- break;case pc.PIXELFORMAT_ETC2_RGB:c=this.extCompressedTextureETC;a._glFormat=b.RGB;a._glInternalFormat=c.COMPRESSED_RGB8_ETC2;break;case pc.PIXELFORMAT_ETC2_RGBA:c=this.extCompressedTextureETC;a._glFormat=b.RGBA;a._glInternalFormat=c.COMPRESSED_RGBA8_ETC2_EAC;break;case pc.PIXELFORMAT_RGB16F:c=this.extTextureHalfFloat;a._glFormat=b.RGB;this.webgl2?(a._glInternalFormat=b.RGB16F,a._glPixelType=b.HALF_FLOAT):(a._glInternalFormat=b.RGB,a._glPixelType=c.HALF_FLOAT_OES);break;case pc.PIXELFORMAT_RGBA16F:c=
- this.extTextureHalfFloat;a._glFormat=b.RGBA;this.webgl2?(a._glInternalFormat=b.RGBA16F,a._glPixelType=b.HALF_FLOAT):(a._glInternalFormat=b.RGBA,a._glPixelType=c.HALF_FLOAT_OES);break;case pc.PIXELFORMAT_RGB32F:a._glFormat=b.RGB;a._glInternalFormat=this.webgl2?b.RGB32F:b.RGB;a._glPixelType=b.FLOAT;break;case pc.PIXELFORMAT_RGBA32F:a._glFormat=b.RGBA;a._glInternalFormat=this.webgl2?b.RGBA32F:b.RGBA;a._glPixelType=b.FLOAT;break;case pc.PIXELFORMAT_R32F:a._glFormat=b.RED;a._glInternalFormat=b.R32F;a._glPixelType=
- b.FLOAT;break;case pc.PIXELFORMAT_DEPTH:this.webgl2?(a._glFormat=b.DEPTH_COMPONENT,a._glInternalFormat=b.DEPTH_COMPONENT32F,a._glPixelType=b.FLOAT):(a._glFormat=b.DEPTH_COMPONENT,a._glInternalFormat=b.DEPTH_COMPONENT,a._glPixelType=b.UNSIGNED_SHORT);break;case pc.PIXELFORMAT_DEPTHSTENCIL:a._glFormat=b.DEPTH_STENCIL;a._glInternalFormat=b.DEPTH24_STENCIL8;a._glPixelType=b.UNSIGNED_INT_24_8;break;case pc.PIXELFORMAT_111110F:a._glFormat=b.RGB;a._glInternalFormat=b.R11F_G11F_B10F;a._glPixelType=b.FLOAT;
- break;case pc.PIXELFORMAT_SRGB:a._glFormat=b.RGB;a._glInternalFormat=b.SRGB8;a._glPixelType=b.UNSIGNED_BYTE;break;case pc.PIXELFORMAT_SRGBA:a._glFormat=b.RGBA,a._glInternalFormat=b.SRGB8_ALPHA8,a._glPixelType=b.UNSIGNED_BYTE}this.textures.push(a)},destroyTexture:function(a){if(a._glTexture){var b=this.textures.indexOf(a);-1!==b&&this.textures.splice(b,1);for(var c in this.scope.variables)b=this.scope.variables[c],b.value===a&&(b.value=null);for(c=0;c<this.textureUnits.length;c++)for(var b=this.textureUnits[c],
- g=0;g<b.length;g++)b[g]===a._glTexture&&(b[g]=null);this.gl.deleteTexture(a._glTexture);delete a._glTexture;delete a._glTarget;delete a._glFormat;delete a._glInternalFormat;delete a._glPixelType;this._vram.tex-=a._gpuSize}},setUnpackFlipY:function(a){if(this.unpackFlipY!==a){this.unpackFlipY=a;var b=this.gl;b.pixelStorei(b.UNPACK_FLIP_Y_WEBGL,a)}},setUnpackPremultiplyAlpha:function(a){if(this.unpackPremultiplyAlpha!==a){this.unpackPremultiplyAlpha=a;var b=this.gl;b.pixelStorei(b.UNPACK_PREMULTIPLY_ALPHA_WEBGL,
- a)}},uploadTexture:function(a){var c=this.gl;if(a._needsUpload||!(a._needsMipmapsUpload&&a._mipmapsUploaded||!a._pot)){for(var e=0,g,l;a._levels[e]||0===e;){if(a._needsUpload||0!==e){if(e&&(!a._needsMipmapsUpload||!a._mipmaps))break;g=a._levels[e];1!=e||a._compressed||(c.generateMipmap(a._glTarget),a._mipmapsUploaded=!0);if(a._cubemap){var k;if(g[0]instanceof HTMLCanvasElement||g[0]instanceof HTMLImageElement||g[0]instanceof HTMLVideoElement)for(k=0;6>k;k++)a._levelsUpdated[0][k]&&(l=g[k],l instanceof
- HTMLImageElement&&(l.width>this.maxCubeMapSize||l.height>this.maxCubeMapSize)&&(l=b(l,this.maxCubeMapSize),0===e&&(a.width=l.width,a.height=l.height)),this.setUnpackFlipY(!1),this.setUnpackPremultiplyAlpha(a._premultiplyAlpha),c.texImage2D(c.TEXTURE_CUBE_MAP_POSITIVE_X+k,e,a._glInternalFormat,a._glFormat,a._glPixelType,l));else for(l=1/Math.pow(2,e),k=0;6>k;k++)if(a._levelsUpdated[0][k]){var f=g[k];a._compressed?c.compressedTexImage2D(c.TEXTURE_CUBE_MAP_POSITIVE_X+k,e,a._glInternalFormat,Math.max(a._width*
- l,1),Math.max(a._height*l,1),0,f):(this.setUnpackFlipY(!1),this.setUnpackPremultiplyAlpha(a._premultiplyAlpha),c.texImage2D(c.TEXTURE_CUBE_MAP_POSITIVE_X+k,e,a._glInternalFormat,Math.max(a._width*l,1),Math.max(a._height*l,1),0,a._glFormat,a._glPixelType,f))}}else a._volume?(l=1/Math.pow(2,e),a._compressed?c.compressedTexImage3D(c.TEXTURE_3D,e,a._glInternalFormat,Math.max(a._width*l,1),Math.max(a._height*l,1),Math.max(a._depth*l,1),0,g):(this.setUnpackFlipY(!1),this.setUnpackPremultiplyAlpha(a._premultiplyAlpha),
- c.texImage3D(c.TEXTURE_3D,e,a._glInternalFormat,Math.max(a._width*l,1),Math.max(a._height*l,1),Math.max(a._depth*l,1),0,a._glFormat,a._glPixelType,g))):(g instanceof HTMLCanvasElement||g instanceof HTMLImageElement||g instanceof HTMLVideoElement?(g instanceof HTMLImageElement&&(g.width>this.maxTextureSize||g.height>this.maxTextureSize)&&(g=b(g,this.maxTextureSize),0===e&&(a.width=g.width,a.height=g.height)),this.setUnpackFlipY(a._flipY),this.setUnpackPremultiplyAlpha(a._premultiplyAlpha),c.texImage2D(c.TEXTURE_2D,
- e,a._glInternalFormat,a._glFormat,a._glPixelType,g)):(l=1/Math.pow(2,e),a._compressed?c.compressedTexImage2D(c.TEXTURE_2D,e,a._glInternalFormat,Math.max(a._width*l,1),Math.max(a._height*l,1),0,g):(this.setUnpackFlipY(!1),this.setUnpackPremultiplyAlpha(a._premultiplyAlpha),c.texImage2D(c.TEXTURE_2D,e,a._glInternalFormat,Math.max(a._width*l,1),Math.max(a._height*l,1),0,a._glFormat,a._glPixelType,g))),a._mipmapsUploaded=0===e?!1:!0)}e++}if(a._needsUpload)if(a._cubemap)for(e=0;6>e;e++)a._levelsUpdated[0][e]=
- !1;else a._levelsUpdated[0]=!1;!a._compressed&&a._mipmaps&&a._needsMipmapsUpload&&a._pot&&1===a._levels.length&&(c.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,g=this.targetToSlot[b];this.textureUnits[c][g]!==a&&
- (this.gl.bindTexture(b,a),this.textureUnits[c][g]=a)},bindTextureOnUnit:function(a,b){var c=a._glTarget,d=a._glTexture,l=this.targetToSlot[c];this.textureUnits[b][l]!==d&&(this.activeTexture(b),this.gl.bindTexture(c,d),this.textureUnits[b][l]=d)},setTextureParameters:function(a){var b=this.gl,c=a._parameterFlags,g=a._glTarget;if(c&1){var l=a._minFilter;if(!a._pot||!a._mipmaps||a._compressed&&1===a._levels.length)if(l===pc.FILTER_NEAREST_MIPMAP_NEAREST||l===pc.FILTER_NEAREST_MIPMAP_LINEAR)l=pc.FILTER_NEAREST;
- else if(l===pc.FILTER_LINEAR_MIPMAP_NEAREST||l===pc.FILTER_LINEAR_MIPMAP_LINEAR)l=pc.FILTER_LINEAR;b.texParameteri(g,b.TEXTURE_MIN_FILTER,this.glFilter[l])}c&2&&b.texParameteri(g,b.TEXTURE_MAG_FILTER,this.glFilter[a._magFilter]);c&4&&(this.webgl2?b.texParameteri(g,b.TEXTURE_WRAP_S,this.glAddress[a._addressU]):b.texParameteri(g,b.TEXTURE_WRAP_S,this.glAddress[a._pot?a._addressU:pc.ADDRESS_CLAMP_TO_EDGE]));c&8&&(this.webgl2?b.texParameteri(g,b.TEXTURE_WRAP_T,this.glAddress[a._addressV]):b.texParameteri(g,
- b.TEXTURE_WRAP_T,this.glAddress[a._pot?a._addressV:pc.ADDRESS_CLAMP_TO_EDGE]));c&16&&this.webgl2&&b.texParameteri(g,b.TEXTURE_WRAP_R,this.glAddress[a._addressW]);c&32&&this.webgl2&&b.texParameteri(g,b.TEXTURE_COMPARE_MODE,a._compareOnRead?b.COMPARE_REF_TO_TEXTURE:b.NONE);c&64&&this.webgl2&&b.texParameteri(g,b.TEXTURE_COMPARE_FUNC,this.glComparison[a._compareFunc]);c&128&&(c=this.extTextureFilterAnisotropic)&&b.texParameterf(g,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<a._parameterFlags||a._needsUpload||a._needsMipmapsUpload){if(this.activeTexture(b),this.bindTexture(a),a._parameterFlags&&(this.setTextureParameters(a),a._parameterFlags=0),a._needsUpload||a._needsMipmapsUpload)this.uploadTexture(a),a!==this.grabPassTexture&&(a._needsUpload=!1,a._needsMipmapsUpload=!1)}else this.bindTextureOnUnit(a,b)},setBuffers:function(a){var b=this.gl,c,g,l,k,f=this.shader.attributes;
- if(this.attributesInvalidated){for(var h=0,n=f.length;h<n;h++)c=f[h],g=c.scopeId.value,null!==g&&(l=this.vertexBuffers[g.stream],k=this.vbOffsets[g.stream]||0,l=l.bufferId,this.boundBuffer!==l&&(b.bindBuffer(b.ARRAY_BUFFER,l),this.boundBuffer=l),c=c.locationId,this.enabledAttributes[c]||(b.enableVertexAttribArray(c),this.enabledAttributes[c]=!0),b.vertexAttribPointer(c,g.numComponents,this.glType[g.dataType],g.normalize,g.stride,g.offset+k),1===g.stream&&1<a?this.instancedAttribs[c]||(b.vertexAttribDivisor(c,
- 1),this.instancedAttribs[c]=!0):this.instancedAttribs[c]&&(b.vertexAttribDivisor(c,0),this.instancedAttribs[c]=!1));this.attributesInvalidated=!1}l=this.indexBuffer?this.indexBuffer.bufferId:null;this.boundElementBuffer!==l&&(b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,l),this.boundElementBuffer=l)},draw:function(a,b){var c=this.gl,d,l,k,f,h,n,q,m;d=this.shader;m=d.samplers;var r=d.uniforms;1<b&&(this.boundBuffer=null,this.attributesInvalidated=!0);this.setBuffers(b);var t=0;d=0;for(k=m.length;d<k;d++)if(f=
- m[d],h=f.scopeId.value)if(h instanceof pc.Texture)n=h,this.setTexture(n,t),f.slot!==t&&(c.uniform1i(f.locationId,t),f.slot=t),t++;else{f.array.length=0;q=h.length;for(l=0;l<q;l++)n=h[l],this.setTexture(n,t),f.array[l]=t,t++;c.uniform1iv(f.locationId,f.array)}d=0;for(k=r.length;d<k;d++)if(m=r[d],l=m.scopeId,f=m.version,h=l.versionObject.version,f.globalId!==h.globalId||f.revision!==h.revision)if(f.globalId=h.globalId,f.revision=h.revision,null!==l.value)this.commitFunction[m.dataType](m,l.value);this.webgl2&&
- this.transformFeedbackBuffer&&(c.bindBufferBase(c.TRANSFORM_FEEDBACK_BUFFER,0,this.transformFeedbackBuffer.bufferId),c.beginTransformFeedback(c.POINTS));d=this.glPrimitive[a.type];k=a.count;a.indexed?(m=this.indexBuffer,r=m.glFormat,m=a.base*m.bytesPerIndex,1<b?c.drawElementsInstanced(d,k,r,m,b):c.drawElements(d,k,r,m)):(r=a.base,1<b?c.drawArraysInstanced(d,r,k,b):c.drawArrays(d,r,k));this.webgl2&&this.transformFeedbackBuffer&&(c.endTransformFeedback(),c.bindBufferBase(c.TRANSFORM_FEEDBACK_BUFFER,
- 0,null))},clear:function(a){var b=this.defaultClearOptions;a=a||b;var c=void 0==a.flags?b.flags:a.flags;if(0!==c){var g=this.gl;if(c&pc.CLEARFLAG_COLOR){var l=void 0==a.color?b.color:a.color;this.setClearColor(l[0],l[1],l[2],l[3])}c&pc.CLEARFLAG_DEPTH&&(this.setClearDepth(void 0==a.depth?b.depth:a.depth),this.depthWrite||g.depthMask(!0));c&pc.CLEARFLAG_STENCIL&&this.setClearStencil(void 0==a.stencil?b.stencil:a.stencil);g.clear(this.glClearFlag[c]);c&pc.CLEARFLAG_DEPTH&&(this.depthWrite||g.depthMask(!1))}},
- readPixels:function(a,b,e,g,l){var c=this.gl;c.readPixels(a,b,e,g,c.RGBA,c.UNSIGNED_BYTE,l)},setClearDepth:function(a){a!==this.clearDepth&&(this.gl.clearDepth(a),this.clearDepth=a)},setClearColor:function(a,b,e,g){if(a!==this.clearRed||b!==this.clearGreen||e!==this.clearBlue||g!==this.clearAlpha)this.gl.clearColor(a,b,e,g),this.clearRed=a,this.clearGreen=b,this.clearBlue=e,this.clearAlpha=g},setClearStencil:function(a){a!==this.clearStencil&&(this.gl.clearStencil(a),this.clearStencil=a)},setRenderTarget:function(a){this.renderTarget=
- a},getRenderTarget:function(){return this.renderTarget},getDepthTest:function(){return this.depthTest},setDepthTest:function(a){if(this.depthTest!==a){var b=this.gl;a?b.enable(b.DEPTH_TEST):b.disable(b.DEPTH_TEST);this.depthTest=a}},setDepthFunc:function(a){this.depthFunc!==a&&(this.gl.depthFunc(this.glComparison[a]),this.depthFunc=a)},getDepthWrite:function(){return this.depthWrite},setDepthWrite:function(a){this.depthWrite!==a&&(this.gl.depthMask(a),this.depthWrite=a)},setColorWrite:function(a,
- b,e,g){if(this.writeRed!==a||this.writeGreen!==b||this.writeBlue!==e||this.writeAlpha!==g)this.gl.colorMask(a,b,e,g),this.writeRed=a,this.writeGreen=b,this.writeBlue=e,this.writeAlpha=g},setAlphaToCoverage:function(a){this.webgl2&&this.alphaToCoverage!==a&&((this.alphaToCoverage=a)?this.gl.enable(this.gl.SAMPLE_ALPHA_TO_COVERAGE):this.gl.disable(this.gl.SAMPLE_ALPHA_TO_COVERAGE))},setTransformFeedbackBuffer:function(a){if(this.transformFeedbackBuffer!==a&&(this.transformFeedbackBuffer=a,this.webgl2)){var b=
- this.gl;a?(this.feedback||(this.feedback=b.createTransformFeedback()),b.bindTransformFeedback(b.TRANSFORM_FEEDBACK,this.feedback)):b.bindTransformFeedback(b.TRANSFORM_FEEDBACK,null)}},setRaster:function(a){this.raster!==a&&(this.raster=a,this.webgl2&&(a?this.gl.disable(this.gl.RASTERIZER_DISCARD):this.gl.enable(this.gl.RASTERIZER_DISCARD)))},setDepthBias:function(a){this.depthBiasEnabled!==a&&((this.depthBiasEnabled=a)?this.gl.enable(this.gl.POLYGON_OFFSET_FILL):this.gl.disable(this.gl.POLYGON_OFFSET_FILL))},
- setDepthBiasValues:function(a,b){this.gl.polygonOffset(b,a)},getBlending:function(){return this.blending},setBlending:function(a){if(this.blending!==a){var b=this.gl;a?b.enable(b.BLEND):b.disable(b.BLEND);this.blending=a}},setStencilTest:function(a){if(this.stencil!==a){var b=this.gl;a?b.enable(b.STENCIL_TEST):b.disable(b.STENCIL_TEST);this.stencil=a}},setStencilFunc:function(a,b,e){if(this.stencilFuncFront!==a||this.stencilRefFront!==b||this.stencilMaskFront!==e||this.stencilFuncBack!==a||this.stencilRefBack!==
- b||this.stencilMaskBack!==e)this.gl.stencilFunc(this.glComparison[a],b,e),this.stencilFuncFront=this.stencilFuncBack=a,this.stencilRefFront=this.stencilRefBack=b,this.stencilMaskFront=this.stencilMaskBack=e},setStencilFuncFront:function(a,b,e){if(this.stencilFuncFront!==a||this.stencilRefFront!==b||this.stencilMaskFront!==e){var c=this.gl;c.stencilFuncSeparate(c.FRONT,this.glComparison[a],b,e);this.stencilFuncFront=a;this.stencilRefFront=b;this.stencilMaskFront=e}},setStencilFuncBack:function(a,b,
- e){if(this.stencilFuncBack!==a||this.stencilRefBack!==b||this.stencilMaskBack!==e){var c=this.gl;c.stencilFuncSeparate(c.BACK,this.glComparison[a],b,e);this.stencilFuncBack=a;this.stencilRefBack=b;this.stencilMaskBack=e}},setStencilOperation:function(a,b,e,g){if(this.stencilFailFront!==a||this.stencilZfailFront!==b||this.stencilZpassFront!==e||this.stencilFailBack!==a||this.stencilZfailBack!==b||this.stencilZpassBack!==e)this.gl.stencilOp(this.glStencilOp[a],this.glStencilOp[b],this.glStencilOp[e]),
- this.stencilFailFront=this.stencilFailBack=a,this.stencilZfailFront=this.stencilZfailBack=b,this.stencilZpassFront=this.stencilZpassBack=e;if(this.stencilWriteMaskFront!==g||this.stencilWriteMaskBack!==g)this.gl.stencilMask(g),this.stencilWriteMaskBack=this.stencilWriteMaskFront=g},setStencilOperationFront:function(a,b,e,g){if(this.stencilFailFront!==a||this.stencilZfailFront!==b||this.stencilZpassFront!==e)this.gl.stencilOpSeparate(this.gl.FRONT,this.glStencilOp[a],this.glStencilOp[b],this.glStencilOp[e]),
- this.stencilFailFront=a,this.stencilZfailFront=b,this.stencilZpassFront=e;this.stencilWriteMaskFront!==g&&(this.gl.stencilMaskSeparate(this.gl.FRONT,g),this.stencilWriteMaskFront=g)},setStencilOperationBack:function(a,b,e,g){if(this.stencilFailBack!==a||this.stencilZfailBack!==b||this.stencilZpassBack!==e)this.gl.stencilOpSeparate(this.gl.BACK,this.glStencilOp[a],this.glStencilOp[b],this.glStencilOp[e]),this.stencilFailBack=a,this.stencilZfailBack=b,this.stencilZpassBack=e;this.stencilWriteMaskBack!==
- g&&(this.gl.stencilMaskSeparate(this.gl.BACK,g),this.stencilWriteMaskBack=g)},setBlendFunction:function(a,b){if(this.blendSrc!==a||this.blendDst!==b||this.separateAlphaBlend)this.gl.blendFunc(this.glBlendFunction[a],this.glBlendFunction[b]),this.blendSrc=a,this.blendDst=b,this.separateAlphaBlend=!1},setBlendFunctionSeparate:function(a,b,e,g){this.blendSrc===a&&this.blendDst===b&&this.blendSrcAlpha===e&&this.blendDstAlpha===g&&this.separateAlphaBlend||(this.gl.blendFuncSeparate(this.glBlendFunction[a],
- this.glBlendFunction[b],this.glBlendFunction[e],this.glBlendFunction[g]),this.blendSrc=a,this.blendDst=b,this.blendSrcAlpha=e,this.blendDstAlpha=g,this.separateAlphaBlend=!0)},setBlendEquation:function(a){if(this.blendEquation!==a||this.separateAlphaEquation)this.gl.blendEquation(this.glBlendEquation[a]),this.blendEquation=a,this.separateAlphaEquation=!1},setBlendEquationSeparate:function(a,b){this.blendEquation===a&&this.blendAlphaEquation===b&&this.separateAlphaEquation||(this.gl.blendEquationSeparate(this.glBlendEquation[a],
- this.glBlendEquation[b]),this.blendEquation=a,this.blendAlphaEquation=b,this.separateAlphaEquation=!0)},setCullMode:function(a){if(this.cullMode!==a){if(a===pc.CULLFACE_NONE)this.gl.disable(this.gl.CULL_FACE);else{this.cullMode===pc.CULLFACE_NONE&&this.gl.enable(this.gl.CULL_FACE);var b=this.glCull[a];this.cullFace!==b&&(this.gl.cullFace(b),this.cullFace=b)}this.cullMode=a}},getCullMode:function(){return this.cullMode},setIndexBuffer:function(a){this.indexBuffer=a},setVertexBuffer:function(a,b,e){if(this.vertexBuffers[b]!==
- a||this.vbOffsets[b]!==e){this.vertexBuffers[b]=a;this.vbOffsets[b]=e;e=0;a=a.getFormat().elements;for(var c=a.length;e<c;){var d=a[e++];d.stream=b;d.scopeId.setValue(d)}this.attributesInvalidated=!0}},compileShaderSource:function(a,b){var c=this.gl,d=b?this.vertexShaderCache[a]:this.fragmentShaderCache[a];d||(d=c.createShader(b?c.VERTEX_SHADER:c.FRAGMENT_SHADER),c.shaderSource(d,a),c.compileShader(d),b?this.vertexShaderCache[a]=d:this.fragmentShaderCache[a]=d);return d},compileAndLinkShader:function(a){var b=
- this.gl,c=a.definition,g=this.compileShaderSource(c.vshader,!0),l=this.compileShaderSource(c.fshader,!1),k=b.createProgram();b.attachShader(k,g);b.attachShader(k,l);if(this.webgl2&&c.useTransformFeedback){var c=c.attributes,f=[],h;for(h in c)c.hasOwnProperty(h)&&f.push("out_"+h);b.transformFeedbackVaryings(k,f,b.INTERLEAVED_ATTRIBS)}b.linkProgram(k);a._glVertexShader=g;a._glFragmentShader=l;a._glProgram=k},createShader:function(a){this.compileAndLinkShader(a);this.shaders.push(a)},destroyShader:function(a){var b=
- this.shaders.indexOf(a);-1!==b&&this.shaders.splice(b,1);a._glProgram&&(this.gl.deleteProgram(a._glProgram),a._glProgram=null,this.removeShaderFromCache(a))},_addLineNumbers:function(a){a=a.split("\n");for(var b=0,c=a.length;b<c;b++)a[b]=b+1+":\t"+a[b];return a.join("\n")},postLink:function(a){var b=this.gl,c=a._glVertexShader,g=a._glFragmentShader,l=a._glProgram,k=a.definition;if(!b.getShaderParameter(c,b.COMPILE_STATUS))return console.error("Failed to compile vertex shader:\n\n"+this._addLineNumbers(k.vshader)+
- "\n\n"+b.getShaderInfoLog(c)),!1;if(!b.getShaderParameter(g,b.COMPILE_STATUS))return console.error("Failed to compile fragment shader:\n\n"+this._addLineNumbers(k.fshader)+"\n\n"+b.getShaderInfoLog(g)),!1;if(!b.getProgramParameter(l,b.LINK_STATUS))return console.error("Failed to link shader program. Error: "+b.getProgramInfoLog(l)),!1;for(var f,c=0,h=b.getProgramParameter(l,b.ACTIVE_ATTRIBUTES);c<h;)g=b.getActiveAttrib(l,c++),f=b.getAttribLocation(l,g.name),void 0===k.attributes[g.name]&&console.error('Vertex shader attribute "'+
- g.name+'" is not mapped to a semantic in shader definition.'),f=new pc.ShaderInput(this,k.attributes[g.name],this.pcUniformType[g.type],f),a.attributes.push(f);c=0;for(k=b.getProgramParameter(l,b.ACTIVE_UNIFORMS);c<k;)g=b.getActiveUniform(l,c++),f=b.getUniformLocation(l,g.name),f=new pc.ShaderInput(this,g.name,this.pcUniformType[g.type],f),g.type===b.SAMPLER_2D||g.type===b.SAMPLER_CUBE||this.webgl2&&(g.type===b.SAMPLER_2D_SHADOW||g.type===b.SAMPLER_CUBE_SHADOW||g.type===b.SAMPLER_3D)?a.samplers.push(f):
- a.uniforms.push(f);return a.ready=!0},setShader:function(a){if(a!==this.shader){if(!a.ready&&!this.postLink(a))return!1;this.shader=a;this.gl.useProgram(a._glProgram);this.attributesInvalidated=!0}return!0},getHdrFormat:function(){return this.textureHalfFloatRenderable?pc.PIXELFORMAT_RGB16F:this.textureFloatRenderable?pc.PIXELFORMAT_RGB32F:pc.PIXELFORMAT_R8_G8_B8_A8},getBoneLimit:function(){return this.boneLimit},setBoneLimit:function(a){this.boneLimit=a},resizeCanvas:function(a,b){this._width=a;
- this._height=b;var c=Math.min(this._maxPixelRatio,window.devicePixelRatio);a*=c;b*=c;this.canvas.width=a;this.canvas.height=b;this.fire("resizecanvas",a,b)},setResolution:function(a,b){this._width=a;this._height=b;this.canvas.width=a;this.canvas.height=b;this.fire("resizecanvas",a,b)},clearShaderCache:function(){var a=this.gl,b;for(b in this.fragmentShaderCache)a.deleteShader(this.fragmentShaderCache[b]),delete this.fragmentShaderCache[b];for(b in this.vertexShaderCache)a.deleteShader(this.vertexShaderCache[b]),
- delete this.vertexShaderCache[b];this.programLib.clearCache()},removeShaderFromCache:function(a){this.programLib.removeFromCache(a)},destroy:function(){var a=this.gl;this.grabPassTexture.destroy();this.webgl2&&this.feedback&&a.deleteTransformFeedback(this.feedback);this.clearShaderCache();this.canvas.removeEventListener("webglcontextlost",this._contextLostHandler,!1);this.canvas.removeEventListener("webglcontextrestored",this._contextRestoredHandler,!1);this.gl=this.canvas=this._contextRestoredHandler=
- this._contextLostHandler=null}});Object.defineProperty(a.prototype,"width",{get:function(){return this.gl.drawingBufferWidth||this.canvas.width}});Object.defineProperty(a.prototype,"height",{get:function(){return this.gl.drawingBufferHeight||this.canvas.height}});Object.defineProperty(a.prototype,"fullscreen",{get:function(){return!!document.fullscreenElement},set:function(a){a?this.gl.canvas.requestFullscreen():document.exitFullscreen()}});Object.defineProperty(a.prototype,"enableAutoInstancing",
- {get:function(){return this._enableAutoInstancing},set:function(a){this._enableAutoInstancing=a&&this.extInstancing}});Object.defineProperty(a.prototype,"maxPixelRatio",{get:function(){return this._maxPixelRatio},set:function(a){this._maxPixelRatio=a;this.resizeCanvas(this._width,this._height)}});Object.defineProperty(a.prototype,"textureFloatHighPrecision",{get:function(){if(void 0===this._textureFloatHighPrecision){var a;if(this.textureFloatRenderable){a=pc.shaderChunks;var b=a.createShaderFromCode(this,
- a.fullscreenQuadVS,a.precisionTestPS,"ptest1"),e=a.createShaderFromCode(this,a.fullscreenQuadVS,a.precisionTest2PS,"ptest2"),g={format:pc.PIXELFORMAT_RGBA32F,width:1,height:1,mipmaps:!1,minFilter:pc.FILTER_NEAREST,magFilter:pc.FILTER_NEAREST};a=new pc.Texture(this,g);a.name="testFHP";var l=new pc.RenderTarget(this,a,{depth:!1});pc.drawQuadWithShader(this,l,b);g.format=pc.PIXELFORMAT_R8_G8_B8_A8;b=new pc.Texture(this,g);b.name="testFHP";g=new pc.RenderTarget(this,b,{depth:!1});this.constantTexSource.setValue(a);
- pc.drawQuadWithShader(this,g,e);e=this.activeFramebuffer;this.setFramebuffer(g._glFrameBuffer);var k=new Uint8Array(4);this.readPixels(0,0,1,1,k);this.setFramebuffer(e);e=k[0]/255/16777216+k[1]/255/65536+k[2]/255/256+k[3]/255;a.destroy();l.destroy();b.destroy();g.destroy();a=0===e}else a=!1;this._textureFloatHighPrecision=a}return this._textureFloatHighPrecision}});return{GraphicsDevice:a}}());Object.assign(pc,function(){var f={},b={vertex_position:pc.SEMANTIC_POSITION,vertex_normal:pc.SEMANTIC_NORMAL,vertex_tangent:pc.SEMANTIC_TANGENT,vertex_texCoord0:pc.SEMANTIC_TEXCOORD0,vertex_texCoord1:pc.SEMANTIC_TEXCOORD1,vertex_texCoord2:pc.SEMANTIC_TEXCOORD2,vertex_texCoord3:pc.SEMANTIC_TEXCOORD3,vertex_texCoord4:pc.SEMANTIC_TEXCOORD4,vertex_texCoord5:pc.SEMANTIC_TEXCOORD5,vertex_texCoord6:pc.SEMANTIC_TEXCOORD6,vertex_texCoord7:pc.SEMANTIC_TEXCOORD7,vertex_color:pc.SEMANTIC_COLOR,vertex_boneIndices:pc.SEMANTIC_BLENDINDICES,
- vertex_boneWeights:pc.SEMANTIC_BLENDWEIGHT};f.collectAttribs=function(a){for(var c={},d=0,e=a.indexOf("attribute");0<=e&&!(0<e&&"/"===a[e-1]);){var g=a.indexOf(";",e),l=a.lastIndexOf(" ",g),g=a.substr(l+1,g-(l+1)),l=b[g];void 0!==l?c[g]=l:(c[g]="ATTR"+d,d++);e=a.indexOf("attribute",e+1)}return c};f.createShader=function(a,b,d,e){b=f[b];d=pc.programlib.precisionCode(a)+"\n"+f[d];var c=this.collectAttribs(b);a.webgl2&&(b=pc.programlib.versionCode(a)+this.gles3VS+b,d=pc.programlib.versionCode(a)+this.gles3PS+
- d);return new pc.Shader(a,{attributes:c,vshader:b,fshader:d,useTransformFeedback:e})};f.createShaderFromCode=function(a,b,d,e,g){var c=a.programLib._cache,k=c[e];if(void 0!==k)return k;d=pc.programlib.precisionCode(a)+"\n"+(d||pc.programlib.dummyFragmentCode());k=this.collectAttribs(b);a.webgl2&&(b=pc.programlib.versionCode(a)+this.gles3VS+b,d=pc.programlib.versionCode(a)+this.gles3PS+d);c[e]=new pc.Shader(a,{attributes:k,vshader:b,fshader:d,useTransformFeedback:g});return c[e]};return{shaderChunks:f}}());Object.assign(pc,function(){var f=null,b={type:pc.PRIMITIVE_TRISTRIP,base:0,count:4,indexed:!1};return{drawQuadWithShader:function(a,c,d,e,g,l){if(null===f){var k=new pc.VertexFormat(a,[{semantic:pc.SEMANTIC_POSITION,components:2,type:pc.TYPE_FLOAT32}]);f=new pc.VertexBuffer(a,k,4);k=new pc.VertexIterator(f);k.element[pc.SEMANTIC_POSITION].set(-1,-1);k.next();k.element[pc.SEMANTIC_POSITION].set(1,-1);k.next();k.element[pc.SEMANTIC_POSITION].set(-1,1);k.next();k.element[pc.SEMANTIC_POSITION].set(1,
- 1);k.end()}k=a.renderTarget;a.setRenderTarget(c);a.updateBegin();var p,h,n,q,m,r,t,v;e?(p=e.x,h=e.y,n=e.z,q=e.w):(n=c?c.width:a.width,q=c?c.height:a.height,h=p=0);g?(m=g.x,r=g.y,t=g.z,v=g.w):(m=p,r=h,t=n,v=q);g=a.vx;e=a.vy;c=a.vw;var y=a.vh;a.setViewport(p,h,n,q);n=a.sx;p=a.sy;h=a.sw;q=a.sh;a.setScissor(m,r,t,v);m=a.getDepthTest();r=a.getDepthWrite();t=a.getCullMode();v=a.writeRed;var u=a.writeGreen,w=a.writeBlue,x=a.writeAlpha;a.setDepthTest(!1);a.setDepthWrite(!1);a.setCullMode(pc.CULLFACE_NONE);
- a.setColorWrite(!0,!0,!0,!0);l||a.setBlending(!1);a.setVertexBuffer(f,0);a.setShader(d);a.draw(b);a.setDepthTest(m);a.setDepthWrite(r);a.setCullMode(t);a.setColorWrite(v,u,w,x);a.updateEnd();a.setRenderTarget(k);a.updateBegin();a.setViewport(g,e,c,y);a.setScissor(n,p,h,q)},destroyPostEffectQuad:function(){f&&(f.destroy(),f=null)}}}());Object.assign(pc,function(){function f(a,b,d){var c=b._colorBuffer;if(c.format==pc.PIXELFORMAT_R8_G8_B8_A8){var g=new Uint8Array(c.width*c.height*4),l=a.gl;a.setFramebuffer(b._glFrameBuffer);l.readPixels(0,0,c.width,c.height,l.RGBA,l.UNSIGNED_BYTE,g);c._levels||(c._levels=[]);c._levels[0]||(c._levels[0]=[]);c._levels[0][d]=g}}function b(a,b){return Math.atan2(a*b,Math.sqrt(a*a+b*b+1))}return{prefilterCubemap:function(a){var b=a.device,d=a.sourceCubemap,e=a.method,g=a.samples,l=a.cpuSync;if(l&&!d._levels[0])console.error("ERROR: prefilter: cubemap must have _levels");
- else{var k=pc.shaderChunks,p=d.rgbm,g=k.createShaderFromCode(b,k.fullscreenQuadVS,k.rgbmPS+k.prefilterCubemapPS.replace(/\$METHOD/g,0===e?"cos":"phong").replace(/\$NUMSAMPLES/g,g).replace(/\$textureCube/g,p?"textureCubeRGBM":"textureCube"),"prefilter"+e+""+g+""+p),h=k.createShaderFromCode(b,k.fullscreenQuadVS,k.outputCubemapPS,"outputCubemap"),n=b.scope.resolve("source"),q=b.scope.resolve("params"),m=new pc.Vec4,r=d.width,k=d.format,t=[[],a.filteredFixed,a.filteredRgbm,a.filteredFixedRgbm],v=0===
- e?[.9,.85,.7,.4,.25]:[512,128,32,8,2],y=[64,32,16,8,4],u,w,x;w=k===pc.PIXELFORMAT_R8_G8_B8;u=!1;var D;l&&(u=d._levels[0][0]instanceof HTMLImageElement);if((w||u)&&l){k=pc.PIXELFORMAT_R8_G8_B8_A8;D=new pc.Texture(b,{cubemap:!0,rgbm:p,format:k,width:r,height:r,mipmaps:!1});D.name="prefiltered-cube";for(x=0;6>x;x++)u=new pc.RenderTarget(b,D,{face:x,depth:!1}),m.x=x,m.y=0,n.setValue(d),q.setValue(m.data),pc.drawQuadWithShader(b,u,h),f(b,u,x);d=D}if(128<r){var z=Math.round(Math.log2(r))-Math.round(Math.log2(128));
- for(w=0;w<z;w++){var r=.5*d.width,C=0===e?1:Math.pow(2,Math.round(Math.log2(v[0])+2*(z-w)));D=new pc.Texture(b,{cubemap:!0,rgbm:p,format:k,width:r,height:r,mipmaps:!1});D.name="prefiltered-cube";for(x=0;6>x;x++)u=new pc.RenderTarget(b,D,{face:x,depth:!1}),m.x=x,m.y=C,m.z=r,m.w=p?3:0,n.setValue(d),q.setValue(m.data),pc.drawQuadWithShader(b,u,h),w===z-1&&l&&f(b,u,x);d=D}}a.sourceCubemap=d;D=null;if(!p&&a.filteredFixedRgbm)for(D=new pc.Texture(b,{cubemap:!0,rgbm:!0,format:pc.PIXELFORMAT_R8_G8_B8_A8,
- width:r,height:r,mipmaps:!1}),D.name="prefiltered-cube",x=0;6>x;x++)u=new pc.RenderTarget(b,D,{face:x,depth:!1}),m.x=x,m.w=2,n.setValue(d),q.setValue(m.data),pc.drawQuadWithShader(b,u,h),f(b,u,x);r=0===e?1:2048;u=0===e?0:-1;t[u]=[];for(w=0;5>w;w++)for(h=u;h<t.length;h++)null!=t[h]&&(t[h][w]=new pc.Texture(b,{cubemap:!0,rgbm:2>h?p:!0,format:2>h?k:pc.PIXELFORMAT_R8_G8_B8_A8,fixCubemapSeams:1===h||3===h,width:y[w],height:y[w],mipmaps:!1}),t[h][w].name="prefiltered-cube");for(h=u;h<t.length;h++)if(null!=
- t[h])if(1<h&&p)t[h]=t[h-2];else for(w=0;5>w;w++)for(x=0;6>x;x++)u=new pc.RenderTarget(b,t[h][w],{face:x,depth:!1}),m.x=x,m.y=0>h?r:v[w],m.z=y[w],m.w=p?3:h,n.setValue(0===w?d:0===e?t[0][w-1]:t[-1][w-1]),q.setValue(m.data),pc.drawQuadWithShader(b,u,g),l&&f(b,u,x);a.filtered=t[0];if(l&&a.singleFilteredFixed){d=[d,a.filteredFixed[0],a.filteredFixed[1],a.filteredFixed[2],a.filteredFixed[3],a.filteredFixed[4],a.filteredFixed[5]];p=new pc.Texture(b,{cubemap:!0,rgbm:p,fixCubemapSeams:!0,format:k,width:128,
- height:128,addressU:pc.ADDRESS_CLAMP_TO_EDGE,addressV:pc.ADDRESS_CLAMP_TO_EDGE});p.name="prefiltered-cube";for(w=0;6>w;w++)p._levels[w]=d[w]._levels[0];p.upload();p._prefilteredMips=!0;a.singleFilteredFixed=p}if(l&&a.singleFilteredFixedRgbm&&a.filteredFixedRgbm){d=[D,a.filteredFixedRgbm[0],a.filteredFixedRgbm[1],a.filteredFixedRgbm[2],a.filteredFixedRgbm[3],a.filteredFixedRgbm[4],a.filteredFixedRgbm[5]];p=new pc.Texture(b,{cubemap:!0,rgbm:!0,fixCubemapSeams:!0,format:pc.PIXELFORMAT_R8_G8_B8_A8,width:128,
- height:128,addressU:pc.ADDRESS_CLAMP_TO_EDGE,addressV:pc.ADDRESS_CLAMP_TO_EDGE});p.name="prefiltered-cube";for(w=0;6>w;w++)p._levels[w]=d[w]._levels[0];p.upload();p._prefilteredMips=!0;a.singleFilteredFixedRgbm=p}}},shFromCubemap:function(a,c){var d,e=a.width,g,l;if(a.format!=pc.PIXELFORMAT_R8_G8_B8_A8)console.error("ERROR: SH: cubemap must be RGBA8");else{if(a._levels[0]){if(!a._levels[0][0].length)if(a._levels[0][0]instanceof HTMLImageElement){g=pc.Application.getApplication().graphicsDevice;l=
- g.gl;d=pc.shaderChunks;var k=d.createShaderFromCode(g,d.fullscreenQuadVS,d.fullscreenQuadPS,"fsQuadSimple"),f=g.scope.resolve("source");for(d=0;6>d;d++){var h=a._levels[0][d],n=new pc.Texture(g,{cubemap:!1,rgbm:!1,format:a.format,width:e,height:e,mipmaps:!1});n.name="prefiltered-cube";n._levels[0]=h;n.upload();h=new pc.Texture(g,{cubemap:!1,rgbm:!1,format:a.format,width:e,height:e,mipmaps:!1});h.name="prefiltered-cube";h=new pc.RenderTarget(g,h,{depth:!1});f.setValue(n);pc.drawQuadWithShader(g,h,
- k);var q=new Uint8Array(e*e*4);l.bindFramebuffer(l.FRAMEBUFFER,h._glFrameBuffer);l.readPixels(0,0,n.width,n.height,l.RGBA,l.UNSIGNED_BYTE,q);a._levels[0][d]=q}}else{console.error("ERROR: SH: cubemap must be composed of arrays or images");return}k=[];for(l=0;l<e;l++)for(g=0;g<e;g++)k[l*e+g]=(new pc.Vec3(g/(e-1)*2-1,l/(e-1)*2-1,1)).normalize();var f=new Float32Array(27),m,r,t,v,y,u,w,x,D,z,C;for(d=h=0;6>d;d++)for(l=0;l<e;l++)for(g=0;g<e;g++){n=l*e+g;q=g;w=l;x=e;r=(2*(q+.5)/x-1)*(1-1/x);C=(2*(w+.5)/
- x-1)*(1-1/x);m=1/x;D=r-m;z=C-m;r+=m;C+=m;D=b(D,z)-b(D,C)-b(r,z)+b(r,C);if(0===q&&0===w||q===x-1&&0===w||0===q&&w===x-1||q===x-1&&w===x-1)D/=3;else if(0===q||0===w||q===x-1||w===x-1)D*=.5;q=D;w=4*q/17;x=8*q/17;D=15*q/17;z=5*q/68;C=15*q/68;m=k[n];0==d?(v=m.z,y=-m.y,u=-m.x):1==d?(v=-m.z,y=-m.y,u=m.x):2==d?(v=m.x,y=m.z,u=m.y):3==d?(v=m.x,y=-m.z,u=-m.y):4==d?(v=m.x,y=-m.y,u=m.z):5==d&&(v=-m.x,y=-m.y,u=-m.z);c||(v=-v);r=a._levels[0][d][4*n+3]/255;for(m=0;3>m;m++)t=a._levels[0][d][4*n+m]/255,a.rgbm?(t*=
- 8*r,t*=t):t=Math.pow(t,2.2),f[0+m]+=t*w,f[3+m]+=t*x*v,f[6+m]+=t*x*y,f[9+m]+=t*x*u,f[12+m]+=t*D*v*u,f[15+m]+=t*D*u*y,f[18+m]+=t*D*y*v,f[21+m]+=t*z*(3*u*u-1),f[24+m]+=t*C*(v*v-y*y),h+=q}for(m=0;m<f.length;m++)f[m]*=4*Math.PI/h;return f}console.error("ERROR: SH: cubemap must be synced to CPU")}}}}());Object.assign(pc,function(){return{paraboloidFromCubemap:function(f,b,a,c){var d=pc.shaderChunks,d=d.createShaderFromCode(f,d.fullscreenQuadVS,(b.fixCubemapSeams?d.fixCubemapSeamsStretchPS:d.fixCubemapSeamsNonePS)+d.genParaboloidPS,"genParaboloid"),e=f.scope.resolve("source"),g=f.scope.resolve("params"),l=new pc.Vec4,k=b.width,p=b.rgbm,h=b.format,k=2*Math.max(k,8),k=new pc.Texture(f,{rgbm:p,format:h,width:2*k,height:k,mipmaps:!1});k.name="paraboloid";p=new pc.RenderTarget(f,k,{depth:!1});l.x=a;l.y=
- c?-1:1;e.setValue(b);g.setValue(l.data);pc.drawQuadWithShader(f,p,d);return k},generateDpAtlas:function(f,b,a){var c,d;d=new pc.Vec4;var e=new pc.Vec4,g=4*b[0].width,l=pc.shaderChunks,l=l.createShaderFromCode(f,l.fullscreenQuadVS,l.dpAtlasQuadPS,"dpAtlasQuad"),k=f.scope.resolve("source"),p=f.scope.resolve("params"),h=new pc.Texture(f,{rgbm:b[0].rgbm,format:b[0].format,width:g,height:g,mipmaps:!1});h.name="paraboloid";for(var n=new pc.RenderTarget(f,h,{depth:!1}),q=(g+2)/g-1,m=0;6>m;m++){c=pc.paraboloidFromCubemap(f,
- b[m],m,a);k.setValue(c);c=d;var r=m;c.x=.5*pc.math.clamp(r-2,0,1);var r=r-6*c.x,t=1-c.x;c.y=Math.min(.5*r,.75)*t+c.x;c.z=(1-.5*pc.math.clamp(r,0,1))*t;c.w=.5*c.z;c=1/c.z;e.x=c*q;e.y=2*e.x;e.x+=1;e.y+=1;p.setValue(e.data);d.x*=g;d.y*=g;d.z*=g;d.w*=g;pc.drawQuadWithShader(f,n,l,d)}return h}}}());pc.shaderChunks.TBNPS="void getTBN() {\n dTBN = mat3(normalize(dTangentW), normalize(dBinormalW), normalize(dVertexNormalW));\n}\n";pc.shaderChunks.TBNderivativePS="// http://www.thetenthplanet.de/archives/1180\nvoid getTBN() {\n vec2 uv = $UV;\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 // 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 // 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";
- pc.shaderChunks.TBNfastPS="void getTBN() {\n dTBN = mat3(dTangentW, dBinormalW, dVertexNormalW);\n}\n";pc.shaderChunks.alphaTestPS="uniform float alpha_ref;\nvoid alphaTest(float a) {\n if (a < alpha_ref) discard;\n}\n";pc.shaderChunks.ambientConstantPS="\nvoid addAmbient() {\n dDiffuseLight += light_globalAmbient;\n}\n";pc.shaderChunks.ambientPrefilteredCubePS="#ifndef PMREM4\n#define PMREM4\nuniform samplerCube texture_prefilteredCubeMap4;\n#endif\nvoid addAmbient() {\n vec3 fixedReflDir = fixSeamsStatic(dNormalW, 1.0 - 1.0 / 4.0);\n fixedReflDir.x *= -1.0;\n dDiffuseLight += processEnvironment($DECODE(textureCube(texture_prefilteredCubeMap4, fixedReflDir)).rgb);\n}\n";
- pc.shaderChunks.ambientPrefilteredCubeLodPS="#ifndef PMREM4\n#define PMREM4\n#extension GL_EXT_shader_texture_lod : enable\nuniform samplerCube texture_prefilteredCubeMap128;\n#endif\nvoid addAmbient() {\n vec3 fixedReflDir = fixSeamsStatic(dNormalW, 1.0 - 1.0 / 4.0);\n fixedReflDir.x *= -1.0;\n dDiffuseLight += processEnvironment($DECODE( textureCubeLodEXT(texture_prefilteredCubeMap128, fixedReflDir, 5.0) ).rgb);\n}\n";pc.shaderChunks.ambientSHPS="uniform vec3 ambientSH[9];\nvoid addAmbient() {\n vec3 n = dNormalW;\n vec3 color =\n ambientSH[0] +\n ambientSH[1] * n.x +\n ambientSH[2] * n.y +\n ambientSH[3] * n.z +\n ambientSH[4] * n.x * n.z +\n ambientSH[5] * n.z * n.y +\n ambientSH[6] * n.y * n.x +\n ambientSH[7] * (3.0 * n.z * n.z - 1.0) +\n ambientSH[8] * (n.x * n.x - n.y * n.y);\n dDiffuseLight += processEnvironment(max(color, vec3(0.0)));\n}\n";
- pc.shaderChunks.aoPS="#ifdef MAPTEXTURE\nuniform sampler2D texture_aoMap;\n#endif\nvoid applyAO() {\n dAo = 1.0;\n #ifdef MAPTEXTURE\n dAo *= texture2D(texture_aoMap, $UV).$CH;\n #endif\n #ifdef MAPVERTEX\n dAo *= saturate(vVertexColor.$VC);\n #endif\n dDiffuseLight *= dAo;\n}\n";pc.shaderChunks.aoSpecOccPS="uniform float material_occludeSpecularIntensity;\nvoid occludeSpecular() {\n // approximated specular occlusion from AO\n float specPow = exp2(dGlossiness * 11.0);\n // http://research.tri-ace.com/Data/cedec2011_RealtimePBR_Implementation_e.pptx\n float specOcc = saturate(pow(dot(dNormalW, dViewDirW) + dAo, 0.01*specPow) - 1.0 + dAo);\n specOcc = mix(1.0, specOcc, material_occludeSpecularIntensity);\n dSpecularLight *= specOcc;\n dReflection *= specOcc;\n}\n";
- pc.shaderChunks.aoSpecOccConstPS="void occludeSpecular() {\n // approximated specular occlusion from AO\n float specPow = exp2(dGlossiness * 11.0);\n // http://research.tri-ace.com/Data/cedec2011_RealtimePBR_Implementation_e.pptx\n float specOcc = saturate(pow(dot(dNormalW, dViewDirW) + dAo, 0.01*specPow) - 1.0 + dAo);\n dSpecularLight *= specOcc;\n dReflection *= specOcc;\n}\n";pc.shaderChunks.aoSpecOccConstSimplePS="void occludeSpecular() {\n float specOcc = dAo;\n dSpecularLight *= specOcc;\n dReflection *= specOcc;\n}\n";
- pc.shaderChunks.aoSpecOccSimplePS="uniform float material_occludeSpecularIntensity;\nvoid occludeSpecular() {\n float specOcc = mix(1.0, dAo, material_occludeSpecularIntensity);\n dSpecularLight *= specOcc;\n dReflection *= specOcc;\n}\n";pc.shaderChunks.bakeDirLmEndPS="\n vec4 dirLm = texture2D(texture_dirLightMap, vUv1);\n if (bakeDir > 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";
- pc.shaderChunks.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";pc.shaderChunks.basePS="\nuniform vec3 view_position;\nuniform vec3 light_globalAmbient;\nfloat square(float x) {\n return x*x;\n}\nfloat saturate(float x) {\n return clamp(x, 0.0, 1.0);\n}\nvec3 saturate(vec3 x) {\n return clamp(x, vec3(0.0), vec3(1.0));\n}\n";
- pc.shaderChunks.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;\nuniform mat4 matrix_viewProjection;\nuniform mat4 matrix_model;\nuniform mat3 matrix_normal;\nvec3 dPositionW;\nmat4 dModelMatrix;\nmat3 dNormalMatrix;\nvec3 dLightPosW;\nvec3 dLightDirNormW;\nvec3 dNormalW;\n";pc.shaderChunks.baseNineSlicedPS="#define NINESLICED\nvarying vec2 vMask;\nvarying vec2 vTiledUv;\nuniform mediump vec4 innerOffset;\nuniform mediump vec2 outerScale;\nuniform mediump vec4 atlasRect;\nvec2 nineSlicedUv;\n";
- pc.shaderChunks.baseNineSlicedVS="#define NINESLICED\nvarying vec2 vMask;\nvarying vec2 vTiledUv;\nuniform mediump vec4 innerOffset;\nuniform mediump vec2 outerScale;\nuniform mediump vec4 atlasRect;\n";pc.shaderChunks.baseNineSlicedTiledPS="#define NINESLICED\n#define NINESLICETILED\nvarying vec2 vMask;\nvarying vec2 vTiledUv;\nuniform mediump vec4 innerOffset;\nuniform mediump vec2 outerScale;\nuniform mediump vec4 atlasRect;\nvec2 nineSlicedUv;\n";pc.shaderChunks.biasConstPS="#define SHADOWBIAS\nfloat getShadowBias(float resolution, float maxBias) {\n return maxBias;\n}\n";
- pc.shaderChunks.blurVSMPS="\nvarying vec2 vUv0;\nuniform sampler2D source;\nuniform vec2 pixelOffset;\n#ifdef GAUSS\nuniform float weight[SAMPLES];\n#endif\n#ifdef PACKED\nfloat decodeFloatRG(vec2 rg) {\n return rg.y*(1.0/255.0) + rg.x;\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\nvoid main(void) {\n vec3 moments = vec3(0.0);\n vec2 uv = vUv0 - pixelOffset * (float(SAMPLES) * 0.5);\n for(int i=0; i<SAMPLES; i++) {\n vec4 c = texture2D(source, uv + pixelOffset * float(i));\n #ifdef PACKED\n c.xy = vec2(decodeFloatRG(c.xy), decodeFloatRG(c.zw));\n #endif\n #ifdef GAUSS\n moments += c.xyz * weight[i];\n #else\n moments += c.xyz;\n #endif\n }\n #ifndef GAUSS\n moments /= float(SAMPLES);\n #endif\n #ifdef PACKED\n gl_FragColor = vec4(encodeFloatRG(moments.x), encodeFloatRG(moments.y));\n #else\n gl_FragColor = vec4(moments.x, moments.y, moments.z, 1.0);\n #endif\n}\n";
- pc.shaderChunks.combineDiffusePS="vec3 combineColor() {\n return dAlbedo * dDiffuseLight;\n}\n";pc.shaderChunks.combineDiffuseSpecularPS="vec3 combineColor() {\n return mix(dAlbedo * dDiffuseLight, dSpecularLight + dReflection.rgb * dReflection.a, dSpecularity);\n}\n";pc.shaderChunks.combineDiffuseSpecularNoConservePS="vec3 combineColor() {\n return dAlbedo * dDiffuseLight + (dSpecularLight + dReflection.rgb * dReflection.a) * dSpecularity;\n}\n";
- pc.shaderChunks.combineDiffuseSpecularNoReflPS="vec3 combineColor() {\n return dAlbedo * dDiffuseLight + dSpecularLight * dSpecularity;\n}\n";pc.shaderChunks.combineDiffuseSpecularNoReflSeparateAmbientPS="uniform vec3 material_ambient;\nvec3 combineColor() {\n return (dDiffuseLight - light_globalAmbient) * dAlbedo + dSpecularLight * dSpecularity + material_ambient * light_globalAmbient;\n}\n";pc.shaderChunks.combineDiffuseSpecularOldPS="vec3 combineColor() {\n return mix(dAlbedo * dDiffuseLight + dSpecularLight * dSpecularity, dReflection.rgb, dReflection.a);\n}\n";
- pc.shaderChunks.cookiePS="vec4 getCookie2D(sampler2D tex, mat4 transform, float intensity) {\n vec4 projPos = transform * vec4(vPositionW, 1.0);\n projPos.xy /= projPos.w;\n return mix(vec4(1.0), texture2D(tex, projPos.xy), intensity);\n}\nvec4 getCookie2DClip(sampler2D tex, mat4 transform, float intensity) {\n vec4 projPos = transform * vec4(vPositionW, 1.0);\n projPos.xy /= projPos.w;\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 return mix(vec4(1.0), texture2D(tex, projPos.xy), intensity);\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}\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}\nvec4 getCookieCube(samplerCube tex, mat4 transform, float intensity) {\n return mix(vec4(1.0), textureCube(tex, dLightDirNormW * mat3(transform)), intensity);\n}\n";
- pc.shaderChunks.cubeMapProjectBoxPS="uniform vec3 envBoxMin, envBoxMax;\nvec3 cubeMapProject(vec3 nrdir) {\n vec3 rbmax = (envBoxMax - vPositionW) / nrdir;\n vec3 rbmin = (envBoxMin - vPositionW) / nrdir;\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 float fa = min(min(rbminmax.x, rbminmax.y), rbminmax.z);\n vec3 posonbox = vPositionW + nrdir * fa;\n vec3 envBoxPos = (envBoxMin + envBoxMax) * 0.5;\n return posonbox - envBoxPos;\n}\n";
- pc.shaderChunks.cubeMapProjectNonePS="vec3 cubeMapProject(vec3 dir) {\n return dir;\n}\n";pc.shaderChunks.diffusePS="#ifdef MAPCOLOR\nuniform vec3 material_diffuse;\n#endif\n#ifdef MAPTEXTURE\nuniform sampler2D texture_diffuseMap;\n#endif\nvoid getAlbedo() {\n dAlbedo = vec3(1.0);\n #ifdef MAPCOLOR\n dAlbedo *= material_diffuse.rgb;\n #endif\n #ifdef MAPTEXTURE\n dAlbedo *= texture2DSRGB(texture_diffuseMap, $UV).$CH;\n #endif\n #ifdef MAPVERTEX\n dAlbedo *= gammaCorrectInput(saturate(vVertexColor.$VC));\n #endif\n}\n";
- pc.shaderChunks.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";
- pc.shaderChunks.dpAtlasQuadPS="varying vec2 vUv0;\nuniform sampler2D source;\nuniform vec4 params;\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";pc.shaderChunks.emissivePS="#ifdef MAPCOLOR\nuniform vec3 material_emissive;\n#endif\n#ifdef MAPFLOAT\nuniform float material_emissiveIntensity;\n#endif\n#ifdef MAPTEXTURE\nuniform sampler2D texture_emissiveMap;\n#endif\nvec3 getEmission() {\n vec3 emission = vec3(1.0);\n #ifdef MAPFLOAT\n emission *= material_emissiveIntensity;\n #endif\n #ifdef MAPCOLOR\n emission *= material_emissive;\n #endif\n #ifdef MAPTEXTURE\n emission *= $texture2DSAMPLE(texture_emissiveMap, $UV).$CH;\n #endif\n #ifdef MAPVERTEX\n emission *= gammaCorrectInput(saturate(vVertexColor.$VC));\n #endif\n return emission;\n}\n";
- pc.shaderChunks.endPS=" gl_FragColor.rgb = combineColor();\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";pc.shaderChunks.envConstPS="vec3 processEnvironment(vec3 color) {\n return color;\n}\n";pc.shaderChunks.envMultiplyPS="uniform float skyboxIntensity;\nvec3 processEnvironment(vec3 color) {\n return color * skyboxIntensity;\n}\n";
- pc.shaderChunks.extensionPS="";pc.shaderChunks.extensionVS="\n";pc.shaderChunks.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 falloff *= 16.0;\n falloff *= square( saturate( 1.0 - square( sqrDist * square(invRadius) ) ) );\n return falloff;\n}\n";pc.shaderChunks.falloffLinearPS="float getFalloffLinear(float lightRadius) {\n float d = length(dLightDirW);\n return max(((lightRadius - d) / lightRadius), 0.0);\n}\n";
- pc.shaderChunks.fixCubemapSeamsNonePS="vec3 fixSeams(vec3 vec, float mipmapIndex) {\n return vec;\n}\nvec3 fixSeams(vec3 vec) {\n return vec;\n}\nvec3 fixSeamsStatic(vec3 vec, float invRecMipSize) {\n return vec;\n}\n";pc.shaderChunks.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}\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}\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";
- pc.shaderChunks.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";pc.shaderChunks.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";
- pc.shaderChunks.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";pc.shaderChunks.fogNonePS="vec3 addFog(vec3 color) {\n return color;\n}\n";
- pc.shaderChunks.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}\n";pc.shaderChunks.fullscreenQuadPS="varying vec2 vUv0;\nuniform sampler2D source;\nvoid main(void) {\n gl_FragColor = texture2D(source, vUv0);\n}\n";
- pc.shaderChunks.fullscreenQuadVS="attribute vec2 vertex_position;\nvarying vec2 vUv0;\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";pc.shaderChunks.gamma1_0PS="vec4 texture2DSRGB(sampler2D tex, vec2 uv) {\n return texture2D(tex, uv);\n}\nvec4 texture2DSRGB(sampler2D tex, vec2 uv, float bias) {\n return texture2D(tex, uv, bias);\n}\nvec4 textureCubeSRGB(samplerCube tex, vec3 uvw) {\n return textureCube(tex, uvw);\n}\nvec3 gammaCorrectOutput(vec3 color) {\n return color;\n}\nvec3 gammaCorrectInput(vec3 color) {\n return color;\n}\nfloat gammaCorrectInput(float color) {\n return color;\n}\nvec4 gammaCorrectInput(vec4 color) {\n return color;\n}\n";
- pc.shaderChunks.gamma2_2PS="vec3 gammaCorrectInput(vec3 color) {\n return pow(color, vec3(2.2));\n}\nfloat gammaCorrectInput(float color) {\n return pow(color, 2.2);\n}\nvec4 gammaCorrectInput(vec4 color) {\n return vec4(pow(color.rgb, vec3(2.2)), color.a);\n}\nvec4 texture2DSRGB(sampler2D tex, vec2 uv) {\n vec4 rgba = texture2D(tex, uv);\n rgba.rgb = gammaCorrectInput(rgba.rgb);\n return rgba;\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}\nvec4 textureCubeSRGB(samplerCube tex, vec3 uvw) {\n vec4 rgba = textureCube(tex, uvw);\n rgba.rgb = gammaCorrectInput(rgba.rgb);\n return rgba;\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";
- pc.shaderChunks.genParaboloidPS="varying vec2 vUv0;\nuniform samplerCube source;\nuniform vec4 params; // x = mip\nvoid main(void) {\n vec2 uv = vUv0;\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 // scale projection a bit to have a little overlap for filtering\n const float scale = 1.1;\n tc *= scale;\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 dir.x *= -side * params.y; // flip original cubemap x instead of doing it at runtime\n dir = fixSeams(dir, params.x);\n vec4 color = textureCube(source, dir, -100.0);\n gl_FragColor = color;\n}\n";
- pc.shaderChunks.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";pc.shaderChunks.gles3VS="#define attribute in\n#define varying out\n#define texture2D texture\n#define GL2\n#define VERTEXSHADER\n";
- pc.shaderChunks.glossPS="#ifdef MAPFLOAT\nuniform float material_shininess;\n#endif\n#ifdef MAPTEXTURE\nuniform sampler2D texture_glossMap;\n#endif\nvoid getGlossiness() {\n dGlossiness = 1.0;\n #ifdef MAPFLOAT\n dGlossiness *= material_shininess;\n #endif\n #ifdef MAPTEXTURE\n dGlossiness *= texture2D(texture_glossMap, $UV).$CH;\n #endif\n #ifdef MAPVERTEX\n dGlossiness *= saturate(vVertexColor.$VC);\n #endif\n dGlossiness += 0.0000001;\n}\n";
- pc.shaderChunks.instancingVS="\nattribute vec4 instance_line1;\nattribute vec4 instance_line2;\nattribute vec4 instance_line3;\nattribute vec4 instance_line4;\n";pc.shaderChunks.lightDiffuseLambertPS="float getLightDiffuse() {\n return max(dot(dNormalW, -dLightDirNormW), 0.0);\n}\n";pc.shaderChunks.lightDirPointPS="void getLightDirPoint(vec3 lightPosW) {\n dLightDirW = vPositionW - lightPosW;\n dLightDirNormW = normalize(dLightDirW);\n dLightPosW = lightPosW;\n}\n";
- pc.shaderChunks.lightSpecularBlinnPS="// Energy-conserving (hopefully) Blinn-Phong\nfloat getLightSpecular() {\n vec3 h = normalize( -dLightDirNormW + dViewDirW );\n float nh = max( dot( h, dNormalW ), 0.0 );\n float specPow = exp2(dGlossiness * 11.0); // glossiness is linear, power is not; 0 - 2048\n specPow = antiAliasGlossiness(specPow);\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 return pow(nh, specPow) * (specPow + 2.0) / 8.0;\n}\n";
- pc.shaderChunks.lightSpecularPhongPS="float getLightSpecular() {\n float specPow = dGlossiness;\n specPow = antiAliasGlossiness(specPow);\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(dReflDirW, -dLightDirNormW), 0.0), specPow + 0.0001);\n}\n";pc.shaderChunks.lightmapDirPS="uniform sampler2D texture_lightMap;\nuniform sampler2D texture_dirLightMap;\nvoid addLightMap() {\n vec3 color = $texture2DSAMPLE(texture_lightMap, $UV).$CH;\n vec4 dir = texture2D(texture_dirLightMap, $UV);\n if (dot(dir.xyz,vec3(1.0)) < 0.00001) {\n dDiffuseLight += color;\n return;\n }\n dLightDirNormW = normalize(dir.xyz * 2.0 - vec3(1.0));\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 dDiffuseLight += color * nlight * 2.0;\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 dLightDirNormW = normalize(dir.xyz * 2.0 - vec3(1.0));\n dSpecularLight += vec3(getLightSpecular()) * color;\n}\n";
- pc.shaderChunks.lightmapSinglePS="#ifdef MAPTEXTURE\nuniform sampler2D texture_lightMap;\n#endif\nvoid addLightMap() {\n vec3 lm = vec3(1.0);\n #ifdef MAPTEXTURE\n lm *= $texture2DSAMPLE(texture_lightMap, $UV).$CH;\n #endif\n #ifdef MAPVERTEX\n lm *= saturate(vVertexColor.$VC);\n #endif\n \n dDiffuseLight += lm;\n}\n";pc.shaderChunks.lightmapSingleVertPS="void addLightMap() {\n dDiffuseLight += saturate(vVertexColor.$CH);\n}\n";pc.shaderChunks.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#ifdef MAPFLOAT\nuniform float material_metalness;\n#endif\n#ifdef MAPTEXTURE\nuniform sampler2D texture_metalnessMap;\n#endif\nvoid getSpecularity() {\n float metalness = 1.0;\n #ifdef MAPFLOAT\n metalness *= material_metalness;\n #endif\n #ifdef MAPTEXTURE\n metalness *= texture2D(texture_metalnessMap, $UV).$CH;\n #endif\n #ifdef MAPVERTEX\n metalness *= saturate(vVertexColor.$VC);\n #endif\n processMetalness(metalness);\n}\n";
- pc.shaderChunks.msdfPS="uniform sampler2D texture_msdfMap;\n#ifdef GL_OES_standard_derivatives\n#define USE_FWIDTH\n#endif\n#ifdef GL2\n#define USE_FWIDTH\n#endif\nfloat median(float r, float g, float b) {\n return max(min(r, g), min(max(r, g), b));\n}\nfloat map (float min, float max, float v) {\n return (v - min) / (max - min);\n}\n// msdf way\n// vec4 applyMsdf(vec4 color) {\n// vec3 tsample = texture(texture_msdfMap, vUv0).rgb;\n \n// // separate\n// vec2 msdfUnit = 4.0 / vec2(512.0, 256.0);\n// float sigDist = median(tsample.r, tsample.g, tsample.b) - 0.5;\n// sigDist *= dot(msdfUnit, 0.5/fwidth(vUv0));\n// float distance = clamp(sigDist + 0.5, 0.0, 1.0);\n// return mix(vec4(0.0), color, distance);\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\nuniform vec4 outline_color;\nuniform float outline_thickness;\nuniform vec4 shadow_color;\nuniform vec2 shadow_offset;\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 #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 float smoothing = clamp(2.0 * font_pxrange / font_size, 0.0, 0.5);\n // for small fonts we remap the distance field to intensify it\n // float mapMin = 0.05;\n // float mapMax = clamp(((font_size * 0.4 / 40.0) + 0.52), mapMin, 1.0);\n #endif\n float mapMin = 0.05;\n float mapMax = clamp(1.0 - font_sdfIntensity, mapMin, 1.0);\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 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 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 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}";
- pc.shaderChunks.normalVS="vec3 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 return normalize(dNormalMatrix * vertex_normal);\n}\n";pc.shaderChunks.normalInstancedVS="vec3 getNormal() {\n dNormalMatrix = mat3(instance_line1.xyz, instance_line2.xyz, instance_line3.xyz);\n return normalize(dNormalMatrix * vertex_normal);\n}\n";
- pc.shaderChunks.normalMapPS="uniform sampler2D texture_normalMap;\nuniform float material_bumpiness;\nvoid getNormal() {\n vec3 normalMap = unpackNormal(texture2D(texture_normalMap, $UV));\n dNormalMap = normalMap;\n dNormalW = dTBN * normalMap;\n}\n";pc.shaderChunks.normalMapFloatPS="uniform sampler2D texture_normalMap;\nuniform float material_bumpiness;\nvoid getNormal() {\n vec3 normalMap = unpackNormal(texture2D(texture_normalMap, $UV));\n dNormalMap = normalMap;\n normalMap = normalize(mix(vec3(0.0, 0.0, 1.0), normalMap, material_bumpiness));\n dNormalW = dTBN * normalMap;\n}\n";
- pc.shaderChunks.normalMapFloatTBNfastPS="uniform sampler2D texture_normalMap;\nuniform float material_bumpiness;\nvoid getNormal() {\n vec3 normalMap = unpackNormal(texture2D(texture_normalMap, $UV));\n dNormalMap = normalMap;\n normalMap = mix(vec3(0.0, 0.0, 1.0), normalMap, material_bumpiness);\n dNormalW = normalize(dTBN * normalMap);\n}\n";pc.shaderChunks.normalSkinnedVS="vec3 getNormal() {\n dNormalMatrix = mat3(dModelMatrix[0].xyz, dModelMatrix[1].xyz, dModelMatrix[2].xyz);\n return normalize(dNormalMatrix * vertex_normal);\n}\n";
- pc.shaderChunks.normalVertexPS="void getNormal() {\n dNormalW = normalize(dVertexNormalW);\n}\n";pc.shaderChunks.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";pc.shaderChunks.normalXYZPS="vec3 unpackNormal(vec4 nmap) {\n return nmap.xyz * 2.0 - 1.0;\n}\n";pc.shaderChunks.opacityPS="#ifdef MAPFLOAT\nuniform float material_opacity;\n#endif\n#ifdef MAPTEXTURE\nuniform sampler2D texture_opacityMap;\n#endif\nvoid getOpacity() {\n dAlpha = 1.0;\n #ifdef MAPFLOAT\n dAlpha *= material_opacity;\n #endif\n #ifdef MAPTEXTURE\n dAlpha *= texture2D(texture_opacityMap, $UV).$CH;\n #endif\n #ifdef MAPVERTEX\n dAlpha *= saturate(vVertexColor.$VC);\n #endif\n}\n";
- pc.shaderChunks.outputAlphaPS="gl_FragColor.a = dAlpha;\n";pc.shaderChunks.outputAlphaOpaquePS="gl_FragColor.a = 1.0;\n";pc.shaderChunks.outputAlphaPremulPS="gl_FragColor.rgb *= dAlpha;\ngl_FragColor.a = dAlpha;\n";pc.shaderChunks.outputCubemapPS="varying vec2 vUv0;\nuniform samplerCube source;\nuniform vec4 params;\nfloat saturate(float x) {\n return clamp(x, 0.0, 1.0);\n}\nvec4 encodeRGBM(vec4 color) { // modified RGBM\n color.rgb = pow(color.rgb, vec3(0.5));\n color.rgb *= 1.0 / 8.0;\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 color.rgb /= color.a;\n return color;\n}\nvoid main(void) {\n vec2 st = vUv0 * 2.0 - 1.0;\n float face = params.x;\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 gl_FragColor = textureCube(source, vec);\n if (params.w >= 2.0) gl_FragColor = encodeRGBM(gl_FragColor);\n}\n";
- pc.shaderChunks.outputTex2DPS="varying vec2 vUv0;\nuniform sampler2D source;\nvoid main(void) {\n gl_FragColor = texture2D(source, vUv0);\n}\n";pc.shaderChunks.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 // 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";
- pc.shaderChunks.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 // 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";pc.shaderChunks.parallaxPS="uniform sampler2D texture_heightMap;\nuniform float material_heightMapFactor;\nvoid getParallax() {\n float parallaxScale = material_heightMapFactor;\n float height = texture2D(texture_heightMap, $UV).$CH;\n height = height * parallaxScale - parallaxScale*0.5;\n vec3 viewDirT = dViewDirW * dTBN;\n viewDirT.z += 0.42;\n dUvOffset = height * (viewDirT.xy / viewDirT.z);\n}\n";
- pc.shaderChunks.particlePS="varying vec4 texCoordsAlphaLife;\nuniform sampler2D colorMap;\nuniform sampler2D internalTex3;\nuniform float graphSampleSize;\nuniform float graphNumSamples;\n#ifndef CAMERAPLANES\n#define CAMERAPLANES\nuniform vec4 camera_params;\n#endif\nuniform float softening;\nuniform float colorMult;\nfloat saturate(float x) {\n return clamp(x, 0.0, 1.0);\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\nvoid main(void) {\n vec4 tex = texture2DSRGB(colorMap, texCoordsAlphaLife.xy);\n vec4 ramp = texture2DSRGB(internalTex3, vec2(texCoordsAlphaLife.w, 0.0));\n ramp.rgb *= colorMult;\n ramp.a += texCoordsAlphaLife.z;\n vec3 rgb = tex.rgb * ramp.rgb;\n float a = tex.a * ramp.a;\n";
- pc.shaderChunks.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}\nfloat saturate(float x) {\n return clamp(x, 0.0, 1.0);\n}\nvec4 tex1Dlod_lerp(sampler2D tex, vec2 tc) {\n return mix( texture2D(tex,tc), texture2D(tex,tc + graphSampleSize), fract(tc.x*graphNumSamples) );\n}\nvec4 tex1Dlod_lerp(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 vec3 unpackedA = unpack3NFloats(a.w);\n vec3 unpackedB = unpack3NFloats(b.w);\n w = mix(unpackedA, unpackedB, c);\n return mix(a, b, c);\n}\nvec2 rotate(vec2 quadXY, float pRotation, out mat2 rotMatrix) {\n float c = cos(pRotation);\n float s = sin(pRotation);\n mat2 m = mat2(c, -s, s, c);\n rotMatrix = m;\n return m * quadXY;\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}\nvoid main(void) {\n vec3 meshLocalPos = particle_vertexData.xyz;\n float id = floor(particle_vertexData.w);\n float rndFactor = fract(sin(id + 1.0 + seed));\n vec3 rndFactor3 = vec3(rndFactor, fract(rndFactor*10.0), fract(rndFactor*100.0));\n float uv = id / numParticlesPot;\n readInput(uv);\n vec2 velocityV = normalize((mat3(matrix_view) * inVel).xy); // should be removed by compiler if align/stretch is not used\n float particleLifetime = lifetime;\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 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 scale += (scaleDiv * 2.0 - 1.0) * scaleDivMult * fract(rndFactor*10000.0);\n texCoordsAlphaLife = vec4(quadXY * -0.5 + 0.5, (alphaDiv * 2.0 - 1.0) * alphaDivMult * fract(rndFactor*1000.0), nlife);\n vec3 particlePos = inPos;\n vec3 particlePosMoved = vec3(0.0);\n mat2 rotMatrix;\n";
- pc.shaderChunks.particleAnimFrameClampVS="\n float animFrame = min(floor(texCoordsAlphaLife.w * animTexParams.z), animTexParams.w);\n";pc.shaderChunks.particleAnimFrameLoopVS="\n float animFrame = floor(texCoordsAlphaLife.w * animTexParams.z);\n";pc.shaderChunks.particleAnimTexVS="\n float atlasX = animFrame * animTexParams.x;\n float atlasY = floor(atlasX) * animTexParams.y;\n atlasX = fract(atlasX);\n texCoordsAlphaLife.xy *= animTexParams.xy;\n texCoordsAlphaLife.xy += vec2(atlasX, atlasY);\n texCoordsAlphaLife.y = 1.0 - texCoordsAlphaLife.y;\n";
- pc.shaderChunks.particleInputFloatPS="void readInput(float uv) {\n vec4 tex = texture2D(particleTexIN, vec2(uv, 0.25));\n vec4 tex2 = texture2D(particleTexIN, vec2(uv, 0.75));\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";pc.shaderChunks.particleInputRgba8PS="//RG=X, BA=Y\n//RG=Z, BA=A\n//RGB=V, A=visMode\n//RGBA=life\n#define PI2 6.283185307179586\nuniform vec3 inBoundsSize;\nuniform vec3 inBoundsCenter;\nuniform float maxVel;\nfloat decodeFloatRG(vec2 rg) {\n return rg.y*(1.0/255.0) + rg.x;\n}\nfloat decodeFloatRGBA( vec4 rgba ) {\n return dot( rgba, vec4(1.0, 1.0/255.0, 1.0/65025.0, 1.0/160581375.0) );\n}\nvoid readInput(float uv) {\n 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 inPos = vec3(decodeFloatRG(tex0.rg), decodeFloatRG(tex0.ba), decodeFloatRG(tex1.rg));\n inPos = (inPos - vec3(0.5)) * inBoundsSize + inBoundsCenter;\n inVel = tex2.xyz;\n inVel = (inVel - vec3(0.5)) * maxVel;\n inAngle = decodeFloatRG(tex1.ba) * PI2;\n inShow = tex2.a > 0.5;\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";
- pc.shaderChunks.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";pc.shaderChunks.particleOutputRgba8PS="uniform vec3 outBoundsMul;\nuniform vec3 outBoundsAdd;\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}\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}\nvoid writeOutput() {\n //outPos = (outPos - outBoundsCenter) / outBoundsSize + vec3(0.5);\n outPos = outPos * outBoundsMul + outBoundsAdd;\n outAngle = fract(outAngle / PI2);\n outVel = (outVel / maxVel) + vec3(0.5); // TODO: mul\n float maxNegLife = max(lifetime, (numParticles - 1.0) * (rate+rateDiv));\n float maxPosLife = lifetime+1.0;\n outLife = (outLife + maxNegLife) / (maxNegLife + maxPosLife);\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";
- pc.shaderChunks.particleUpdaterAABBPS="uniform mat3 spawnBounds;\nvec3 calcSpawnPosition(vec3 inBounds, float rndFactor) {\n return emitterPos + spawnBounds * (inBounds - vec3(0.5));\n}\nvoid addInitialVelocity(inout vec3 localVelocity, vec3 inBounds) {\n localVelocity -= vec3(0, 0, initialVelocity);\n}\n";pc.shaderChunks.particleUpdaterEndPS="\n writeOutput();\n}\n";pc.shaderChunks.particleUpdaterInitPS="varying vec2 vUv0;\nuniform sampler2D particleTexIN;\nuniform sampler2D internalTex0;\nuniform sampler2D internalTex1;\nuniform sampler2D internalTex2;\nuniform mat3 emitterMatrix;\nuniform vec3 emitterScale;\nuniform vec3 emitterPos, frameRandom, localVelocityDivMult, velocityDivMult;\nuniform float delta, rate, rateDiv, lifetime, numParticles, rotSpeedDivMult, seed;\nuniform float startAngle, startAngle2;\nuniform float initialVelocity;\nuniform float graphSampleSize;\nuniform float graphNumSamples;\nvec3 inPos;\nvec3 inVel;\nfloat inAngle;\nbool inShow;\nfloat inLife;\nfloat visMode;\nvec3 outPos;\nvec3 outVel;\nfloat outAngle;\nbool outShow;\nfloat outLife;\n";
- pc.shaderChunks.particleUpdaterNoRespawnPS=" if (outLife >= lifetime) {\n outLife -= max(lifetime, (numParticles - 1.0) * particleRate);\n visMode = -1.0;\n }\n";pc.shaderChunks.particleUpdaterOnStopPS=" visMode = outLife < 0.0? -1.0: visMode;\n";pc.shaderChunks.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";
- pc.shaderChunks.particleUpdaterSpherePS="uniform float spawnBoundsSphere;\nvec3 calcSpawnPosition(vec3 inBounds, float rndFactor) {\n float rnd4 = fract(rndFactor * 1000.0);\n return emitterPos + normalize(inBounds.xyz - vec3(0.5)) * rnd4 * spawnBoundsSphere;\n}\nvoid addInitialVelocity(inout vec3 localVelocity, vec3 inBounds) {\n localVelocity += normalize(inBounds - vec3(0.5)) * initialVelocity;\n}\n";pc.shaderChunks.particleUpdaterStartPS="float saturate(float x) {\n return clamp(x, 0.0, 1.0);\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}\nvec3 tex1Dlod_lerp(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 vec3 unpackedA = unpack3NFloats(a.w);\n vec3 unpackedB = unpack3NFloats(b.w);\n w = mix(unpackedA, unpackedB, c);\n return mix(a.xyz, b.xyz, c);\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}\nvoid main(void)\n{\n if (gl_FragCoord.x > numParticles) discard;\n readInput(vUv0.x);\n visMode = inShow? 1.0 : -1.0;\n vec4 rndFactor = hash41(gl_FragCoord.x + seed);\n float particleRate = rate + rateDiv * rndFactor.x;\n outLife = inLife + delta;\n float nlife = clamp(outLife / lifetime, 0.0, 1.0);\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 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 addInitialVelocity(localVelocity, rndFactor.xyz);\n outVel = emitterMatrix * localVelocity.xyz + velocity.xyz * emitterScale;\n outPos = inPos + outVel * delta;\n outAngle = inAngle + rotSpeed * delta;\n bool respawn = outLife <= 0.0 || outLife >= lifetime;\n outPos = respawn? calcSpawnPosition(rndFactor.xyz, rndFactor.x) : outPos;\n outAngle = respawn? mix(startAngle, startAngle2, rndFactor.x) : outAngle;\n outVel = respawn? vec3(0.0) : outVel;\n";
- pc.shaderChunks.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";pc.shaderChunks.particle_billboardVS="\n quadXY = rotate(quadXY, inAngle, rotMatrix);\n vec3 localPos = billboard(particlePos, quadXY);\n";pc.shaderChunks.particle_blendAddPS="\n rgb *= saturate(gammaCorrectInput(a));\n if ((rgb.r + rgb.g + rgb.b) < 0.000001) discard;\n";
- pc.shaderChunks.particle_blendMultiplyPS="\n rgb = mix(vec3(1.0), rgb, vec3(a));\n if (rgb.r + rgb.g + rgb.b > 2.99) discard;\n";pc.shaderChunks.particle_blendNormalPS="\n if (a < 0.01) discard;\n";pc.shaderChunks.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 vec2 particle_vertexData4; // X = velocity.z, W = particle ID\nuniform mat4 matrix_viewProjection;\nuniform mat4 matrix_model;\n#ifndef VIEWMATRIX\n#define VIEWMATRIX\nuniform mat4 matrix_view;\n#endif\nuniform mat3 matrix_normal;\nuniform mat4 matrix_viewInverse;\nuniform float numParticles;\nuniform float lifetime;\nuniform float stretch;\n//uniform float graphSampleSize;\n//uniform float graphNumSamples;\nuniform vec3 wrapBounds, emitterScale;\nuniform sampler2D texLifeAndSourcePosOUT;\nuniform sampler2D internalTex0;\nuniform sampler2D internalTex1;\nuniform sampler2D internalTex2;\nuniform vec3 emitterPos;\nvarying vec4 texCoordsAlphaLife;\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 mat2 m = mat2(c, -s, s, c);\n rotMatrix = m;\n return m * quadXY;\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}\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_vertexData4.x);\n vec2 velocityV = normalize((mat3(matrix_view) * inVel).xy); // should be removed by compiler if align/stretch is not used\n vec2 quadXY = vertPos.xy;\n texCoordsAlphaLife = vec4(quadXY * -0.5 + 0.5, particle_vertexData2.z, particle_vertexData.w);\n mat2 rotMatrix;\n float inAngle = particle_vertexData2.x;\n vec3 particlePosMoved = vec3(0.0);\n vec3 meshLocalPos = particle_vertexData3.xyz;\n";
- pc.shaderChunks.particle_cpu_endVS="\n localPos *= particle_vertexData2.y * emitterScale;\n localPos += particlePos;\n gl_Position = matrix_viewProjection * vec4(localPos, 1.0);\n";pc.shaderChunks.particle_endPS=" rgb = addFog(rgb);\n rgb = toneMap(rgb);\n rgb = gammaCorrectOutput(rgb);\n gl_FragColor = vec4(rgb, a);\n}\n";pc.shaderChunks.particle_endVS="\n localPos *= scale * emitterScale;\n localPos += particlePos;\n gl_Position = matrix_viewProjection * vec4(localPos.xyz, 1.0);\n";
- pc.shaderChunks.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";pc.shaderChunks.particle_initVS="attribute vec4 particle_vertexData; // XYZ = particle position, W = particle ID + random factor\nuniform mat4 matrix_viewProjection;\nuniform mat4 matrix_model;\nuniform mat3 matrix_normal;\nuniform mat4 matrix_viewInverse;\n#ifndef VIEWMATRIX\n#define VIEWMATRIX\nuniform mat4 matrix_view;\n#endif\nuniform float numParticles, numParticlesPot;\nuniform float graphSampleSize;\nuniform float graphNumSamples;\nuniform float stretch;\nuniform vec3 wrapBounds;\nuniform vec3 emitterScale, emitterPos;\nuniform float rate, rateDiv, lifetime, deltaRandomnessStatic, scaleDivMult, alphaDivMult, seed, delta;\nuniform sampler2D particleTexOUT, particleTexIN;\nuniform sampler2D internalTex0;\nuniform sampler2D internalTex1;\nuniform sampler2D internalTex2;\n#ifndef CAMERAPLANES\n#define CAMERAPLANES\nuniform vec4 camera_params;\n#endif\nvarying vec4 texCoordsAlphaLife;\nvec3 inPos;\nvec3 inVel;\nfloat inAngle;\nbool inShow;\nfloat inLife;\n";
- pc.shaderChunks.particle_lambertPS="\n vec3 negNormal = max(normal, vec3(0.0));\n vec3 posNormal = max(-normal, vec3(0.0));\n";pc.shaderChunks.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 rgb *= light;\n";pc.shaderChunks.particle_localShiftVS=" particlePos += emitterPos;\n";
- pc.shaderChunks.particle_meshVS="\n vec3 localPos = meshLocalPos;\n localPos.xy = rotate(localPos.xy, inAngle, rotMatrix);\n localPos.yz = rotate(localPos.yz, inAngle, rotMatrix);\n billboard(particlePos, quadXY);\n";pc.shaderChunks.particle_normalVS="\n Normal = normalize(localPos + matrix_viewInverse[2].xyz);\n";pc.shaderChunks.particle_normalMapPS="\n vec3 normalMap = normalize( texture2D(normalMap, texCoordsAlphaLife.xy).xyz * 2.0 - 1.0 );\n vec3 normal = ParticleMat * normalMap;\n";
- pc.shaderChunks.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";pc.shaderChunks.particle_softPS="\n float depth = getLinearScreenDepth();\n float particleDepth = vDepth;\n float depthDiff = saturate(abs(particleDepth - depth) * softening);\n a *= depthDiff;\n";pc.shaderChunks.particle_softVS="\n vDepth = getLinearDepth(localPos);\n";pc.shaderChunks.particle_stretchVS=" vec3 moveDir = inVel * stretch;\n vec3 posPrev = inPos - moveDir;\n posPrev += particlePosMoved;\n vec2 centerToVertexV = normalize((mat3(matrix_view) * localPos).xy);\n float interpolation = dot(-velocityV, centerToVertexV) * 0.5 + 0.5;\n particlePos = mix(particlePos, posPrev, interpolation);\n";
- pc.shaderChunks.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";pc.shaderChunks.precisionTestPS="void main(void) {\n gl_FragColor = vec4(2147483648.0);\n}\n";pc.shaderChunks.precisionTest2PS="uniform sampler2D source;\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 vec4 res = mod(depth * bit_shift * vec4(255), vec4(256) ) / vec4(255);\n res -= res.xxyz * bit_mask;\n return res;\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";
- pc.shaderChunks.prefilterCubemapPS="varying vec2 vUv0;\nuniform samplerCube source;\nuniform vec4 params;\nfloat saturate(float x) {\n return clamp(x, 0.0, 1.0);\n}\nfloat rnd(vec2 uv) {\n return fract(sin(dot(uv, vec2(12.9898, 78.233) * 2.0)) * 43758.5453);\n}\nconst float PI = 3.14159265358979;\nvec3 hemisphereSample_cos(vec2 uv, mat3 vecSpace, vec3 cubeDir, float gloss) { // 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}\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}\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}\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 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 encoded.rgb /= encoded.a;\n return encoded;\n}\nvoid main(void) {\n vec2 st = vUv0 * 2.0 - 1.0;\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 float face = params.x;\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 mat3 vecSpace = matrixFromVector(normalize(vec));\n vec3 color = vec3(0.0);\n const int samples = $NUMSAMPLES;\n vec3 vect;\n for(int i=0; i<samples; i++) {\n float sini = sin(float(i));\n float cosi = cos(float(i));\n float rand = rnd(vec2(sini, cosi));\n vect = hemisphereSample_$METHOD(vec2(float(i) / float(samples), rand), vecSpace, vec, params.y);\n color += $textureCube(source, vect).rgb;\n }\n color /= float(samples);\n gl_FragColor = params.w < 2.0? vec4(color, 1.0) : encodeRGBM(color);\n}\n";
- pc.shaderChunks.reflDirPS="void getReflDir() {\n dReflDirW = normalize(-reflect(dViewDirW, dNormalW));\n}\n";pc.shaderChunks.reflectionCubePS="uniform samplerCube texture_cubeMap;\nuniform float material_reflectivity;\nvoid addReflection() {\n vec3 lookupVec = fixSeams(cubeMapProject(dReflDirW));\n lookupVec.x *= -1.0;\n dReflection += vec4($textureCubeSAMPLE(texture_cubeMap, lookupVec).rgb, material_reflectivity);\n}\n";pc.shaderChunks.reflectionDpAtlasPS="uniform sampler2D texture_sphereMap;\nuniform float material_reflectivity;\nvec2 getDpAtlasUv(vec2 uv, float mip) {\n vec4 rect;\n float sx = saturate(mip - 2.0);\n rect.x = sx * 0.5;\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 float st = saturate(t);\n rect.z = (1.0 - st * 0.5) * i;\n rect.w = rect.z * 0.5;\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 uv = uv * rect.zw + rect.xy;\n return uv;\n}\nvoid addReflection() {\n vec3 reflDir = normalize(cubeMapProject(dReflDirW));\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 float bias = saturate(1.0 - dGlossiness) * 5.0; // multiply by max mip level\n float mip = floor(bias);\n vec3 tex1 = $texture2DSAMPLE(texture_sphereMap, getDpAtlasUv(tc, mip)).rgb;\n mip = min(mip + 1.0, 5.0);\n vec3 tex2 = $texture2DSAMPLE(texture_sphereMap, getDpAtlasUv(tc, mip)).rgb;\n tex1 = mix(tex1, tex2, fract(bias));\n tex1 = processEnvironment(tex1);\n dReflection += vec4(tex1, material_reflectivity);\n}\n";
- pc.shaderChunks.reflectionPrefilteredCubePS="uniform samplerCube texture_prefilteredCubeMap128;\nuniform samplerCube texture_prefilteredCubeMap64;\nuniform samplerCube texture_prefilteredCubeMap32;\nuniform samplerCube texture_prefilteredCubeMap16;\nuniform samplerCube texture_prefilteredCubeMap8;\n#ifndef PMREM4\n#define PMREM4\nuniform samplerCube texture_prefilteredCubeMap4;\n#endif\nuniform float material_reflectivity;\nvoid addReflection() {\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 float bias = saturate(1.0 - dGlossiness) * 5.0; // multiply by max mip level\n int index1 = int(bias);\n int index2 = int(min(bias + 1.0, 7.0));\n vec3 fixedReflDir = fixSeams(cubeMapProject(dReflDirW), bias);\n fixedReflDir.x *= -1.0;\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 // 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 // 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 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 vec4 cubeFinal = mix(cube[0], cube[1], fract(bias));\n vec3 refl = processEnvironment($DECODE(cubeFinal).rgb);\n dReflection += vec4(refl, material_reflectivity);\n}\n";
- pc.shaderChunks.reflectionPrefilteredCubeLodPS="\n#ifndef PMREM4\n#define PMREM4\n#extension GL_EXT_shader_texture_lod : enable\nuniform samplerCube texture_prefilteredCubeMap128;\n#endif\nuniform float material_reflectivity;\nvoid addReflection() {\n float bias = saturate(1.0 - dGlossiness) * 5.0; // multiply by max mip level\n vec3 fixedReflDir = fixSeams(cubeMapProject(dReflDirW), bias);\n fixedReflDir.x *= -1.0;\n vec3 refl = processEnvironment($DECODE( textureCubeLodEXT(texture_prefilteredCubeMap128, fixedReflDir, bias) ).rgb);\n dReflection += vec4(refl, material_reflectivity);\n}\n";
- pc.shaderChunks.reflectionSpherePS="#ifndef VIEWMATRIX\n#define VIEWMATRIX\nuniform mat4 matrix_view;\n#endif\nuniform sampler2D texture_sphereMap;\nuniform float material_reflectivity;\nvoid addReflection() {\n vec3 reflDirV = (mat3(matrix_view) * dReflDirW).xyz;\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 dReflection += vec4($texture2DSAMPLE(texture_sphereMap, sphereMapUv).rgb, material_reflectivity);\n}\n";
- pc.shaderChunks.reflectionSphereLowPS="uniform sampler2D texture_sphereMap;\nuniform float material_reflectivity;\nvoid addReflection() {\n vec3 reflDirV = vNormalV;\n vec2 sphereMapUv = reflDirV.xy * 0.5 + 0.5;\n dReflection += vec4($texture2DSAMPLE(texture_sphereMap, sphereMapUv).rgb, material_reflectivity);\n}\n";pc.shaderChunks.refractionPS="uniform float material_refraction, material_refractionIndex;\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}\nvoid addRefraction() {\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 addReflection();\n dDiffuseLight = mix(dDiffuseLight, dReflection.rgb * dAlbedo, material_refraction);\n dReflDirW = tmp;\n dReflection = tmp2;\n}\n";
- pc.shaderChunks.rgbmPS="vec3 decodeRGBM(vec4 rgbm) {\n vec3 color = (8.0 * rgbm.a) * rgbm.rgb;\n return color * color;\n}\nvec3 texture2DRGBM(sampler2D tex, vec2 uv) {\n return decodeRGBM(texture2D(tex, uv));\n}\nvec3 textureCubeRGBM(samplerCube tex, vec3 uvw) {\n return decodeRGBM(textureCube(tex, uvw));\n}\n";pc.shaderChunks.screenDepthPS="uniform sampler2D uDepthMap;\n#ifndef SCREENSIZE\n#define SCREENSIZE\nuniform vec4 uScreenSize;\n#endif\n#ifndef VIEWMATRIX\n#define VIEWMATRIX\nuniform mat4 matrix_view;\n#endif\n#ifndef CAMERAPLANES\n#define CAMERAPLANES\nuniform vec4 camera_params; // 1 / camera_far, camera_far, (1 - f / n) / 2, (1 + f / n) / 2\n#endif\n#ifdef GL2\n float linearizeDepth(float z) {\n z = z * 2.0 - 1.0;\n return 1.0 / (camera_params.z * z + camera_params.w);\n }\n#else\n #ifndef UNPACKFLOAT\n #define UNPACKFLOAT\n float 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 return dot(rgbaDepth, bitShift);\n }\n #endif\n#endif\n// Retrieves rendered linear camera depth by UV\nfloat getLinearScreenDepth(vec2 uv) {\n #ifdef GL2\n return linearizeDepth(texture2D(uDepthMap, uv).r) * camera_params.y;\n #else\n return unpackFloat(texture2D(uDepthMap, uv)) * camera_params.y;\n #endif\n}\n#ifndef VERTEXSHADER\n// Retrieves rendered linear camera depth under the current pixel\nfloat getLinearScreenDepth() {\n vec2 uv = gl_FragCoord.xy * uScreenSize.zw;\n return getLinearScreenDepth(uv);\n}\n#endif\n// Generates linear camera depth for the given world position\nfloat getLinearDepth(vec3 pos) {\n return -(matrix_view * vec4(pos, 1.0)).z;\n}\n";
- pc.shaderChunks.shadowCommonPS="void normalOffsetPointShadow(vec4 shadowParams) {\n float distScale = length(dLightDirW);\n vec3 wPos = vPositionW + dVertexNormalW * shadowParams.y * clamp(1.0 - dot(dVertexNormalW, -dLightDirNormW), 0.0, 1.0) * distScale; //0.02\n vec3 dir = wPos - dLightPosW;\n dLightDirW = dir;\n}\n";pc.shaderChunks.shadowCoordPS="void _getShadowCoordOrtho(mat4 shadowMatrix, vec3 shadowParams, vec3 wPos) {\n dShadowCoord = (shadowMatrix * vec4(wPos, 1.0)).xyz;\n dShadowCoord.z = saturate(dShadowCoord.z) - 0.0001;\n #ifdef SHADOWBIAS\n dShadowCoord.z += getShadowBias(shadowParams.x, shadowParams.z);\n #endif\n}\nvoid _getShadowCoordPersp(mat4 shadowMatrix, vec4 shadowParams, vec3 wPos) {\n vec4 projPos = shadowMatrix * vec4(wPos, 1.0);\n projPos.xy /= projPos.w;\n dShadowCoord.xy = projPos.xy;\n dShadowCoord.z = length(dLightDirW) * shadowParams.w;\n #ifdef SHADOWBIAS\n dShadowCoord.z += getShadowBias(shadowParams.x, shadowParams.z);\n #endif\n}\nvoid getShadowCoordOrtho(mat4 shadowMatrix, vec3 shadowParams) {\n _getShadowCoordOrtho(shadowMatrix, shadowParams, vPositionW);\n}\nvoid getShadowCoordPersp(mat4 shadowMatrix, vec4 shadowParams) {\n _getShadowCoordPersp(shadowMatrix, shadowParams, vPositionW);\n}\nvoid getShadowCoordPerspNormalOffset(mat4 shadowMatrix, vec4 shadowParams) {\n float distScale = abs(dot(vPositionW - dLightPosW, dLightDirNormW)); // fov?\n vec3 wPos = vPositionW + dVertexNormalW * shadowParams.y * clamp(1.0 - dot(dVertexNormalW, -dLightDirNormW), 0.0, 1.0) * distScale;\n _getShadowCoordPersp(shadowMatrix, shadowParams, wPos);\n}\nvoid getShadowCoordOrthoNormalOffset(mat4 shadowMatrix, vec3 shadowParams) {\n vec3 wPos = vPositionW + dVertexNormalW * shadowParams.y * clamp(1.0 - dot(dVertexNormalW, -dLightDirNormW), 0.0, 1.0); //0.08\n _getShadowCoordOrtho(shadowMatrix, shadowParams, wPos);\n}\n";
- pc.shaderChunks.shadowCoordVS="void getLightDirPoint(vec3 lightPosW) {\n vec3 lightDirW = vPositionW - lightPosW;\n dLightDirNormW = normalize(lightDirW);\n dLightPosW = lightPosW;\n}\nvoid _getShadowCoordOrtho(mat4 shadowMatrix, vec3 shadowParams, vec3 wPos) {\n vec4 projPos = shadowMatrix * vec4(wPos, 1.0);\n vMainShadowUv = projPos;\n}\nvoid _getShadowCoordPersp(mat4 shadowMatrix, vec3 shadowParams, vec3 wPos) {\n vec4 projPos = shadowMatrix * vec4(wPos, 1.0);\n vMainShadowUv = projPos;\n}\nvoid getShadowCoordOrtho(mat4 shadowMatrix, vec3 shadowParams) {\n _getShadowCoordOrtho(shadowMatrix, shadowParams, vPositionW);\n}\nvoid getShadowCoordPersp(mat4 shadowMatrix, vec3 shadowParams) {\n _getShadowCoordPersp(shadowMatrix, shadowParams, vPositionW);\n}\nvoid getShadowCoordPerspNormalOffset(mat4 shadowMatrix, vec3 shadowParams) {\n float distScale = abs(dot(vPositionW - dLightPosW, dLightDirNormW)); // fov?\n vec3 wPos = vPositionW + dNormalW * shadowParams.y * clamp(1.0 - dot(dNormalW, -dLightDirNormW), 0.0, 1.0) * distScale;\n _getShadowCoordPersp(shadowMatrix, shadowParams, wPos);\n}\nvoid getShadowCoordOrthoNormalOffset(mat4 shadowMatrix, vec3 shadowParams) {\n vec3 wPos = vPositionW + dNormalW * shadowParams.y * clamp(1.0 - dot(dNormalW, -dLightDirNormW), 0.0, 1.0); //0.08\n _getShadowCoordOrtho(shadowMatrix, shadowParams, wPos);\n}\n";
- pc.shaderChunks.shadowCoordPerspZbufferPS="void _getShadowCoordPerspZbuffer(mat4 shadowMatrix, vec4 shadowParams, vec3 wPos) {\n vec4 projPos = shadowMatrix * vec4(wPos, 1.0);\n projPos.xyz /= projPos.w;\n dShadowCoord = projPos.xyz;\n // depth bias is already applied on render\n}\nvoid getShadowCoordPerspZbufferNormalOffset(mat4 shadowMatrix, vec4 shadowParams) {\n float distScale = abs(dot(vPositionW - dLightPosW, dLightDirNormW)); // fov?\n vec3 wPos = vPositionW + dVertexNormalW * shadowParams.y * clamp(1.0 - dot(dVertexNormalW, -dLightDirNormW), 0.0, 1.0) * distScale;\n _getShadowCoordPerspZbuffer(shadowMatrix, shadowParams, wPos);\n}\nvoid getShadowCoordPerspZbuffer(mat4 shadowMatrix, vec4 shadowParams) {\n _getShadowCoordPerspZbuffer(shadowMatrix, shadowParams, vPositionW);\n}\n";
- pc.shaderChunks.shadowEVSMPS="float VSM$(sampler2D tex, vec2 texCoords, float resolution, float Z, float vsmBias, float exponent) {\n vec3 moments = texture2D(tex, texCoords).xyz;\n return calculateEVSM(moments, Z, vsmBias, exponent);\n}\nfloat getShadowVSM$(sampler2D shadowMap, vec3 shadowParams, float exponent) {\n return VSM$(shadowMap, dShadowCoord.xy, shadowParams.x, dShadowCoord.z, shadowParams.y, exponent);\n}\nfloat getShadowSpotVSM$(sampler2D shadowMap, vec4 shadowParams, float exponent) {\n return VSM$(shadowMap, dShadowCoord.xy, shadowParams.x, length(dLightDirW) * shadowParams.w + shadowParams.z, shadowParams.y, exponent);\n}\n";
- pc.shaderChunks.shadowEVSMnPS="float VSM$(sampler2D tex, vec2 texCoords, float resolution, float Z, float vsmBias, float exponent) {\n float pixelSize = 1.0 / resolution;\n texCoords -= vec2(pixelSize);\n vec3 s00 = texture2D(tex, texCoords).xyz;\n vec3 s10 = texture2D(tex, texCoords + vec2(pixelSize, 0)).xyz;\n vec3 s01 = texture2D(tex, texCoords + vec2(0, pixelSize)).xyz;\n vec3 s11 = texture2D(tex, texCoords + vec2(pixelSize)).xyz;\n vec2 fr = fract(texCoords * resolution);\n vec3 h0 = mix(s00, s10, fr.x);\n vec3 h1 = mix(s01, s11, fr.x);\n vec3 moments = mix(h0, h1, fr.y);\n return calculateEVSM(moments, Z, vsmBias, exponent);\n}\nfloat getShadowVSM$(sampler2D shadowMap, vec3 shadowParams, float exponent) {\n return VSM$(shadowMap, dShadowCoord.xy, shadowParams.x, dShadowCoord.z, shadowParams.y, exponent);\n}\nfloat getShadowSpotVSM$(sampler2D shadowMap, vec4 shadowParams, float exponent) {\n return VSM$(shadowMap, dShadowCoord.xy, shadowParams.x, length(dLightDirW) * shadowParams.w + shadowParams.z, shadowParams.y, exponent);\n}\n";
- pc.shaderChunks.shadowStandardPS="vec3 lessThan2(vec3 a, vec3 b) {\n return clamp((b - a)*1000.0, 0.0, 1.0); // softer version\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 return dot(rgbaDepth, bitShift);\n}\n#endif\n// ----- Direct/Spot Sampling -----\n#ifdef GL2\n float _getShadowPCF3x3(sampler2DShadow shadowMap, vec3 shadowParams) {\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 float sum = 0.0;\n float uw0 = (3.0 - 2.0 * s);\n float uw1 = (1.0 + 2.0 * s);\n float u0 = (2.0 - s) / uw0 - 1.0;\n float u1 = s / uw1 + 1.0;\n float vw0 = (3.0 - 2.0 * t);\n float vw1 = (1.0 + 2.0 * t);\n float v0 = (2.0 - t) / vw0 - 1.0;\n float v1 = t / vw1 + 1.0;\n u0 = u0 * shadowMapSizeInv + base_uv.x;\n v0 = v0 * shadowMapSizeInv + base_uv.y;\n u1 = u1 * shadowMapSizeInv + base_uv.x;\n v1 = v1 * shadowMapSizeInv + base_uv.y;\n sum += uw0 * vw0 * texture(shadowMap, vec3(u0, v0, z));\n sum += uw1 * vw0 * texture(shadowMap, vec3(u1, v0, z));\n sum += uw0 * vw1 * texture(shadowMap, vec3(u0, v1, z));\n sum += uw1 * vw1 * texture(shadowMap, vec3(u1, v1, z));\n sum *= 1.0f / 16.0;\n return sum;\n }\n float getShadowPCF3x3(sampler2DShadow shadowMap, vec3 shadowParams) {\n return _getShadowPCF3x3(shadowMap, shadowParams);\n }\n float getShadowSpotPCF3x3(sampler2DShadow shadowMap, vec4 shadowParams) {\n return _getShadowPCF3x3(shadowMap, shadowParams.xyz);\n }\n#else\n float _xgetShadowPCF3x3(mat3 depthKernel, sampler2D shadowMap, vec3 shadowParams) {\n mat3 shadowKernel;\n vec3 shadowCoord = dShadowCoord;\n vec3 shadowZ = vec3(shadowCoord.z);\n shadowKernel[0] = vec3(greaterThan(depthKernel[0], shadowZ));\n shadowKernel[1] = vec3(greaterThan(depthKernel[1], shadowZ));\n shadowKernel[2] = vec3(greaterThan(depthKernel[2], shadowZ));\n vec2 fractionalCoord = fract( shadowCoord.xy * shadowParams.x );\n shadowKernel[0] = mix(shadowKernel[0], shadowKernel[1], fractionalCoord.x);\n shadowKernel[1] = mix(shadowKernel[1], shadowKernel[2], fractionalCoord.x);\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 return dot( shadowValues, vec4( 1.0 ) ) * 0.25;\n }\n float _getShadowPCF3x3(sampler2D shadowMap, vec3 shadowParams) {\n vec3 shadowCoord = dShadowCoord;\n float xoffset = 1.0 / shadowParams.x; // 1/shadow map width\n float dx0 = -xoffset;\n float dx1 = xoffset;\n mat3 depthKernel;\n depthKernel[0][0] = unpackFloat(texture2D(shadowMap, shadowCoord.xy + vec2(dx0, dx0)));\n depthKernel[0][1] = unpackFloat(texture2D(shadowMap, shadowCoord.xy + vec2(dx0, 0.0)));\n depthKernel[0][2] = unpackFloat(texture2D(shadowMap, shadowCoord.xy + vec2(dx0, dx1)));\n depthKernel[1][0] = unpackFloat(texture2D(shadowMap, shadowCoord.xy + vec2(0.0, dx0)));\n depthKernel[1][1] = unpackFloat(texture2D(shadowMap, shadowCoord.xy));\n depthKernel[1][2] = unpackFloat(texture2D(shadowMap, shadowCoord.xy + vec2(0.0, dx1)));\n depthKernel[2][0] = unpackFloat(texture2D(shadowMap, shadowCoord.xy + vec2(dx1, dx0)));\n depthKernel[2][1] = unpackFloat(texture2D(shadowMap, shadowCoord.xy + vec2(dx1, 0.0)));\n depthKernel[2][2] = unpackFloat(texture2D(shadowMap, shadowCoord.xy + vec2(dx1, dx1)));\n return _xgetShadowPCF3x3(depthKernel, shadowMap, shadowParams);\n }\n float getShadowPCF3x3(sampler2D shadowMap, vec3 shadowParams) {\n return _getShadowPCF3x3(shadowMap, shadowParams);\n }\n float getShadowSpotPCF3x3(sampler2D shadowMap, vec4 shadowParams) {\n return _getShadowPCF3x3(shadowMap, shadowParams.xyz);\n }\n#endif\n// ----- Point Sampling -----\nfloat _getShadowPoint(samplerCube shadowMap, vec4 shadowParams, vec3 dir) {\n vec3 tc = normalize(dir);\n vec3 tcAbs = abs(tc);\n vec4 dirX = vec4(1,0,0, tc.x);\n vec4 dirY = vec4(0,1,0, tc.y);\n float majorAxisLength = tc.z;\n if ((tcAbs.x > 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 float shadowParamsInFaceSpace = ((1.0/shadowParams.x) * 2.0) * abs(majorAxisLength);\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 mat3 shadowKernel;\n mat3 depthKernel;\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 vec3 shadowZ = vec3(length(dir) * shadowParams.w + shadowParams.z);\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 vec2 uv = (vec2(dirX.w, dirY.w) / abs(majorAxisLength)) * 0.5;\n vec2 fractionalCoord = fract( uv * shadowParams.x );\n shadowKernel[0] = mix(shadowKernel[0], shadowKernel[1], fractionalCoord.x);\n shadowKernel[1] = mix(shadowKernel[1], shadowKernel[2], fractionalCoord.x);\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 return 1.0 - dot( shadowValues, vec4( 1.0 ) ) * 0.25;\n}\nfloat getShadowPointPCF3x3(samplerCube shadowMap, vec4 shadowParams) {\n return _getShadowPoint(shadowMap, shadowParams, dLightDirW);\n}\n";
- pc.shaderChunks.shadowStandardGL2PS="float _getShadowPCF5x5(sampler2DShadow shadowMap, vec3 shadowParams) {\n // http://the-witness.net/news/2013/09/shadow-mapping-summary-part-1/\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 float uw0 = (4.0 - 3.0 * s);\n float uw1 = 7.0;\n float uw2 = (1.0 + 3.0 * s);\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 float vw0 = (4.0 - 3.0 * t);\n float vw1 = 7.0;\n float vw2 = (1.0 + 3.0 * t);\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 float sum = 0.0;\n u0 = u0 * shadowMapSizeInv + base_uv.x;\n v0 = v0 * shadowMapSizeInv + base_uv.y;\n u1 = u1 * shadowMapSizeInv + base_uv.x;\n v1 = v1 * shadowMapSizeInv + base_uv.y;\n u2 = u2 * shadowMapSizeInv + base_uv.x;\n v2 = v2 * shadowMapSizeInv + base_uv.y;\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 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 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 sum *= 1.0f / 144.0;\n sum = gammaCorrectInput(sum); // gives softer gradient\n sum = saturate(sum);\n return sum;\n}\nfloat getShadowPCF5x5(sampler2DShadow shadowMap, vec3 shadowParams) {\n return _getShadowPCF5x5(shadowMap, shadowParams);\n}\nfloat getShadowSpotPCF5x5(sampler2DShadow shadowMap, vec4 shadowParams) {\n return _getShadowPCF5x5(shadowMap, shadowParams.xyz);\n}\n";
- pc.shaderChunks.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";pc.shaderChunks.shadowStandardVSPS="#ifdef GL2\n#define SHADOW_SAMPLERVS sampler2DShadow\n#else\n#define SHADOW_SAMPLERVS sampler2D\n#endif\nfloat getShadowPCF3x3VS(SHADOW_SAMPLERVS shadowMap, vec3 shadowParams) {\n dShadowCoord = vMainShadowUv.xyz;\n dShadowCoord.z = saturate(dShadowCoord.z) - 0.0001;\n #ifdef SHADOWBIAS\n dShadowCoord.z += getShadowBias(shadowParams.x, shadowParams.z);\n #endif\n return _getShadowPCF3x3(shadowMap, shadowParams);\n}\n";
- pc.shaderChunks.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}\nfloat decodeFloatRG(vec2 rg) {\n return rg.y*(1.0/255.0) + rg.x;\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}\nfloat getShadowVSM8(sampler2D shadowMap, vec3 shadowParams, float exponent) {\n return VSM8(shadowMap, dShadowCoord.xy, shadowParams.x, dShadowCoord.z, shadowParams.y, 0.0);\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";
- pc.shaderChunks.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 return $VSM(shadowMap, dShadowCoord.xy, shadowParams.x, dShadowCoord.z, shadowParams.y, exponent);\n}\n";pc.shaderChunks.shadowVSM_commonPS="float linstep(float a, float b, float v) {\n return saturate((v - a) / (b - a));\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}\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 // Compute probabilistic upper bound\n float d = mean - moments.x;\n float pMax = variance / (variance + (d * d));\n pMax = reduceLightBleeding(pMax, lightBleedingReduction);\n // One-tailed Chebyshev\n return (mean <= moments.x ? 1.0 : pMax);\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 moments.xy += vec2(warpedDepth, warpedDepth*warpedDepth) * (1.0 - moments.z);\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";
- pc.shaderChunks.skinBatchConstVS="attribute float vertex_boneIndices;\nuniform mat4 matrix_pose[BONE_LIMIT];\nmat4 getBoneMatrix(const in float i) {\n mat4 bone = matrix_pose[int(i)];\n return bone;\n}\n";pc.shaderChunks.skinBatchTexVS="attribute float vertex_boneIndices;\nuniform sampler2D texture_poseMap;\nuniform vec2 texture_poseMapSize;\nmat4 getBoneMatrix(const in float i) {\n float j = i * 4.0;\n float x = mod(j, float(texture_poseMapSize.x));\n float y = floor(j / float(texture_poseMapSize.x));\n float dx = 1.0 / float(texture_poseMapSize.x);\n float dy = 1.0 / float(texture_poseMapSize.y);\n y = dy * (y + 0.5);\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 vec4 v4 = texture2D(texture_poseMap, vec2(dx * (x + 3.5), y));\n mat4 bone = mat4(v1, v2, v3, v4);\n return bone;\n}\n";
- pc.shaderChunks.skinConstVS="attribute vec4 vertex_boneWeights;\nattribute vec4 vertex_boneIndices;\nuniform mat4 matrix_pose[BONE_LIMIT];\nmat4 getBoneMatrix(const in float i)\n{\n mat4 bone = matrix_pose[int(i)];\n return bone;\n}\n";pc.shaderChunks.skinTexVS="attribute vec4 vertex_boneWeights;\nattribute vec4 vertex_boneIndices;\nuniform sampler2D texture_poseMap;\nuniform vec2 texture_poseMapSize;\nmat4 getBoneMatrix(const in float i)\n{\n float j = i * 4.0;\n float x = mod(j, float(texture_poseMapSize.x));\n float y = floor(j / float(texture_poseMapSize.x));\n float dx = 1.0 / float(texture_poseMapSize.x);\n float dy = 1.0 / float(texture_poseMapSize.y);\n y = dy * (y + 0.5);\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 vec4 v4 = texture2D(texture_poseMap, vec2(dx * (x + 3.5), y));\n mat4 bone = mat4(v1, v2, v3, v4);\n return bone;\n}\n";
- pc.shaderChunks.skyboxPS="varying vec3 vViewDir;\nuniform samplerCube texture_cubeMap;\nvoid main(void) {\n gl_FragColor = textureCube(texture_cubeMap, fixSeams(vViewDir));\n}\n";pc.shaderChunks.skyboxVS="attribute vec3 aPosition;\n#ifndef VIEWMATRIX\n#define VIEWMATRIX\nuniform mat4 matrix_view;\n#endif\nuniform mat4 matrix_projection;\nvarying vec3 vViewDir;\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_projection * view * vec4(aPosition, 1.0);\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 gl_Position.z = gl_Position.w - 0.00001;\n vViewDir = aPosition;\n vViewDir.x *= -1.0;\n}\n";
- pc.shaderChunks.skyboxHDRPS="varying vec3 vViewDir;\nuniform samplerCube texture_cubeMap;\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";pc.shaderChunks.skyboxPrefilteredCubePS="varying vec3 vViewDir;\nuniform samplerCube texture_cubeMap;\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}\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";
- pc.shaderChunks.specularPS="#ifdef MAPCOLOR\nuniform vec3 material_specular;\n#endif\n#ifdef MAPTEXTURE\nuniform sampler2D texture_specularMap;\n#endif\nvoid getSpecularity() {\n dSpecularity = vec3(1.0);\n #ifdef MAPCOLOR\n dSpecularity *= material_specular;\n #endif\n #ifdef MAPTEXTURE\n dSpecularity *= texture2D(texture_specularMap, $UV).$CH;\n #endif\n #ifdef MAPVERTEX\n dSpecularity *= saturate(vVertexColor.$VC);\n #endif\n}\n";
- pc.shaderChunks.specularAaNonePS="float antiAliasGlossiness(float power) {\n return power;\n}\n";pc.shaderChunks.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 * toksvig;\n}\n";pc.shaderChunks.specularAaToksvigFloatPS="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";
- pc.shaderChunks.spotPS="float getSpotEffect(vec3 lightSpotDirW, float lightInnerConeAngle, float lightOuterConeAngle) {\n float cosAngle = dot(dLightDirNormW, lightSpotDirW);\n return smoothstep(lightOuterConeAngle, lightInnerConeAngle, cosAngle);\n}\n";pc.shaderChunks.startPS="\nvoid main(void) {\n dDiffuseLight = vec3(0);\n dSpecularLight = vec3(0);\n dReflection = vec4(0);\n dSpecularity = vec3(0);\n";pc.shaderChunks.startVS="\nvoid main(void) {\n gl_Position = getPosition();\n";
- pc.shaderChunks.startNineSlicedPS=" nineSlicedUv = vUv0;\n";pc.shaderChunks.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";pc.shaderChunks.storeEVSMPS="float exponent = VSM_EXPONENT;\ndepth = 2.0 * depth - 1.0;\ndepth = exp(exponent * depth);\ngl_FragColor = vec4(depth, depth*depth, 1.0, 1.0);\n";
- pc.shaderChunks.tangentBinormalVS="\nvec3 getTangent() {\n return normalize(dNormalMatrix * vertex_tangent.xyz);\n}\nvec3 getBinormal() {\n return cross(vNormalW, vTangentW) * vertex_tangent.w;\n}\n";pc.shaderChunks.tonemappingAcesPS="uniform float exposure;\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";
- pc.shaderChunks.tonemappingAces2PS="uniform float exposure;\n// ACES approximation by Stephen Hill\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// 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);\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}\nvec3 toneMap(vec3 color) {\n color *= exposure;\n color = color * ACESInputMat;\n // Apply RRT and ODT\n color = RRTAndODTFit(color);\n color = color * ACESOutputMat;\n // Clamp to [0, 1]\n color = clamp(color, 0.0, 1.0);\n return color;\n}\n";
- pc.shaderChunks.tonemappingFilmicPS="const float A = 0.15;\nconst float B = 0.50;\nconst float C = 0.10;\nconst float D = 0.20;\nconst float E = 0.02;\nconst float F = 0.30;\nconst float W = 11.2;\nuniform float exposure;\nvec3 uncharted2Tonemap(vec3 x) {\n return ((x*(A*x+C*B)+D*E)/(x*(A*x+B)+D*F))-E/F;\n}\nvec3 toneMap(vec3 color) {\n color = uncharted2Tonemap(color * exposure);\n vec3 whiteScale = 1.0 / uncharted2Tonemap(vec3(W,W,W));\n color = color * whiteScale;\n return color;\n}\n";
- pc.shaderChunks.tonemappingHejlPS="uniform float exposure;\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 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";pc.shaderChunks.tonemappingLinearPS="uniform float exposure;\nvec3 toneMap(vec3 color) {\n return color * exposure;\n}\n";
- pc.shaderChunks.tonemappingNonePS="vec3 toneMap(vec3 color) {\n return color;\n}\n";pc.shaderChunks.transformVS="#ifdef PIXELSNAP\n uniform vec4 uScreenSize;\n#endif\nmat4 getModelMatrix() {\n #ifdef DYNAMICBATCH\n return getBoneMatrix(vertex_boneIndices);\n #elif defined(SKIN)\n return matrix_model * (getBoneMatrix(vertex_boneIndices.x) * vertex_boneWeights.x +\n getBoneMatrix(vertex_boneIndices.y) * vertex_boneWeights.y +\n getBoneMatrix(vertex_boneIndices.z) * vertex_boneWeights.z +\n getBoneMatrix(vertex_boneIndices.w) * vertex_boneWeights.w);\n #elif defined(INSTANCING)\n return mat4(instance_line1, instance_line2, instance_line3, instance_line4);\n #else\n return matrix_model;\n #endif\n}\nvec4 getPosition() {\n dModelMatrix = getModelMatrix();\n vec3 localPos = vertex_position;\n #ifdef NINESLICED\n // outer and inner vertices are at the same position, scale both\n localPos.xz *= outerScale;\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 vTiledUv = (localPos.xz - outerScale + innerOffset.xy) * -0.5 + 1.0; // uv = local pos - inner corner\n localPos.xz *= -0.5; // move from -1;1 to -0.5;0.5\n localPos = localPos.xzy;\n #endif\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 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 #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 return screenPos;\n}\nvec3 getWorldPosition() {\n return dPositionW;\n}\n";
- pc.shaderChunks.transformDeclVS="attribute vec3 vertex_position;\nuniform mat4 matrix_model;\nuniform mat4 matrix_viewProjection;\nvec3 dPositionW;\nmat4 dModelMatrix;\n";pc.shaderChunks.uv0VS="#ifdef NINESLICED\nvec2 getUv0() {\n vec2 uv = vertex_position.xz;\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 uv = uv * -0.5 + 0.5;\n uv = uv * atlasRect.zw + atlasRect.xy;\n vMask = vertex_texCoord0.xy;\n return uv;\n}\n#else\nvec2 getUv0() {\n return vertex_texCoord0;\n}\n#endif\n";
- pc.shaderChunks.uv1VS="\nvec2 getUv1() {\n return vertex_texCoord1;\n}\n";pc.shaderChunks.viewDirPS="void getViewDir() {\n dViewDirW = normalize(view_position - vPositionW);\n}\n";pc.shaderChunks.viewNormalVS="\n#ifndef VIEWMATRIX\n#define VIEWMATRIX\nuniform mat4 matrix_view;\n#endif\nvec3 getViewNormal() {\n return mat3(matrix_view) * vNormalW;\n}\n";pc.programlib={gammaCode:function(f){return f===pc.GAMMA_SRGB||f===pc.GAMMA_SRGBFAST?pc.shaderChunks.gamma2_2PS:f===pc.GAMMA_SRGBHDR?"#define HDR\n"+pc.shaderChunks.gamma2_2PS:pc.shaderChunks.gamma1_0PS},tonemapCode:function(f){return f===pc.TONEMAP_FILMIC?pc.shaderChunks.tonemappingFilmicPS:f===pc.TONEMAP_LINEAR?pc.shaderChunks.tonemappingLinearPS:f===pc.TONEMAP_HEJL?pc.shaderChunks.tonemappingHejlPS:f===pc.TONEMAP_ACES?pc.shaderChunks.tonemappingAcesPS:f===pc.TONEMAP_ACES2?pc.shaderChunks.tonemappingAces2PS:
- pc.shaderChunks.tonemappingNonePS},fogCode:function(f){return"linear"===f?pc.shaderChunks.fogLinearPS:"exp"===f?pc.shaderChunks.fogExpPS:"exp2"===f?pc.shaderChunks.fogExp2PS:pc.shaderChunks.fogNonePS},skinCode:function(f,b){b||(b=pc.shaderChunks);return f.supportsBoneTextures?b.skinTexVS:"#define BONE_LIMIT "+f.getBoneLimit()+"\n"+b.skinConstVS},precisionCode:function(f){var b="precision "+f.precision+" float;\n";f.webgl2&&(b+="#ifdef GL2\nprecision "+f.precision+" sampler2DShadow;\n#endif\n");return b},
- versionCode:function(f){return f.webgl2?"#version 300 es\n":""},dummyFragmentCode:function(){return"void main(void) {gl_FragColor = vec4(0.0);}"},begin:function(){return"void main(void)\n{\n"},end:function(){return"}\n"}};pc.programlib.basic={generateKey:function(f){var b="basic";f.fog&&(b+="_fog");f.alphaTest&&(b+="_atst");f.vertexColors&&(b+="_vcol");f.diffuseMap&&(b+="_diff");return b+="_"+f.pass},createShaderDefinition:function(f,b){var a={vertex_position:pc.SEMANTIC_POSITION};b.skin&&(a.vertex_boneWeights=pc.SEMANTIC_BLENDWEIGHT,a.vertex_boneIndices=pc.SEMANTIC_BLENDINDICES);b.vertexColors&&(a.vertex_color=pc.SEMANTIC_COLOR);b.diffuseMap&&(a.vertex_texCoord0=pc.SEMANTIC_TEXCOORD0);var c=pc.shaderChunks,d;d=""+
- c.transformDeclVS;b.skin?(d+=pc.programlib.skinCode(f),d+=c.transformSkinnedVS):d+=c.transformVS;b.vertexColors&&(d+="attribute vec4 vertex_color;\nvarying vec4 vColor;\n");b.diffuseMap&&(d+="attribute vec2 vertex_texCoord0;\nvarying vec2 vUv0;\n");b.pass===pc.SHADER_DEPTH&&(d+="varying float vDepth;\n#ifndef VIEWMATRIX\n#define VIEWMATRIX\nuniform mat4 matrix_view;\n#endif\n#ifndef CAMERAPLANES\n#define CAMERAPLANES\nuniform vec4 camera_params;\n\n#endif\n");d+=pc.programlib.begin();d+=" gl_Position = getPosition();\n";
- b.pass===pc.SHADER_DEPTH&&(d+=" vDepth = -(matrix_view * vec4(getWorldPosition(),1.0)).z * camera_params.x;\n");b.vertexColors&&(d+=" vColor = vertex_color;\n");b.diffuseMap&&(d+=" vUv0 = vertex_texCoord0;\n");var e=d+=pc.programlib.end();d=pc.programlib.precisionCode(f);d=b.vertexColors?d+"varying vec4 vColor;\n":d+"uniform vec4 uColor;\n";b.diffuseMap&&(d+="varying vec2 vUv0;\nuniform sampler2D texture_diffuseMap;\n");b.fog&&(d+=pc.programlib.fogCode(b.fog));b.alphatest&&(d+=c.alphaTestPS);
- b.pass===pc.SHADER_DEPTH&&(d=d+"varying float vDepth;\n"+c.packDepthPS);d+=pc.programlib.begin();d=b.vertexColors?d+" gl_FragColor = vColor;\n":d+" gl_FragColor = uColor;\n";b.diffuseMap&&(d+=" gl_FragColor *= texture2D(texture_diffuseMap, vUv0);\n");b.alphatest&&(d+=" alphaTest(gl_FragColor.a);\n");b.pass!==pc.SHADER_PICK&&(b.pass===pc.SHADER_DEPTH?d+=" gl_FragColor = packFloat(vDepth);\n":b.fog&&(d+=" glFragColor.rgb = addFog(gl_FragColor.rgb);\n"));d+=pc.programlib.end();return{attributes:a,
- vshader:e,fshader:d}}};pc.programlib.particle={generateKey:function(f){var b="particle",a;for(a in f)f.hasOwnProperty(a)&&(b+=f[a]);return b},_animTex:function(f,b){var a;a=""+(f.animTexLoop?b.particleAnimFrameLoopVS:b.particleAnimFrameClampVS);return a+=b.particleAnimTexVS},createShaderDefinition:function(f,b){var a=pc.shaderChunks,c="",d=pc.programlib.precisionCode(f)+"\n";f.webgl2&&(c+="#define GL2\n",d+="#define GL2\n");c+="#define VERTEXSHADER\n";b.animTex&&(c+="\nuniform vec4 animTexParams;\n");2==b.normal&&(c+="\nvarying mat3 ParticleMat;\n");
- 1==b.normal&&(c+="\nvarying vec3 Normal;\n");b.soft&&(c+="\nvarying float vDepth;\n");b.useCpu?(0<b.soft&&(c+=a.screenDepthPS),c+=a.particle_cpuVS,b.localSpace&&(c+=a.particle_localShiftVS),b.animTex&&(c+=this._animTex(b,a)),b.alignToMotion&&(c+=a.particle_pointAlongVS),c+=b.mesh?a.particle_meshVS:a.particle_billboardVS,1==b.normal&&(c+=a.particle_normalVS),2==b.normal&&(c+=a.particle_TBNVS),0<b.stretch&&(c+=a.particle_stretchVS),c+=a.particle_cpu_endVS):(c+=a.particle_initVS,c+=b.pack8?a.particleInputRgba8PS:
- a.particleInputFloatPS,0<b.soft&&(c+=a.screenDepthPS),c+=a.particleVS,b.localSpace&&(c+=a.particle_localShiftVS),b.animTex&&(c+=this._animTex(b,a)),b.wrap&&(c+=a.particle_wrapVS),b.alignToMotion&&(c+=a.particle_pointAlongVS),c+=b.mesh?a.particle_meshVS:a.particle_billboardVS,1==b.normal&&(c+=a.particle_normalVS),2==b.normal&&(c+=a.particle_TBNVS),0<b.stretch&&(c+=a.particle_stretchVS),c+=a.particle_endVS);0<b.soft&&(c+=a.particle_softVS);c+="}\n";0<b.normal&&(1==b.normal?d+="\nvarying vec3 Normal;\n":
- 2==b.normal&&(d+="\nvarying mat3 ParticleMat;\n"),d+="\nuniform vec3 lightCube[6];\n");b.soft&&(d+="\nvarying float vDepth;\n");0===b.normal&&"none"===b.fog&&(b.srgb=!1);d+=pc.programlib.gammaCode(b.gamma);d+=pc.programlib.tonemapCode(b.toneMap);d="linear"===b.fog?d+a.fogLinearPS:"exp"===b.fog?d+a.fogExpPS:"exp2"===b.fog?d+a.fogExp2PS:d+a.fogNonePS;2==b.normal&&(d+="\nuniform sampler2D normalMap;\n");0<b.soft&&(d+=a.screenDepthPS);d+=a.particlePS;0<b.soft&&(d+=a.particle_softPS);1==b.normal&&(d+=
- "\nvec3 normal = Normal;\n");2==b.normal&&(d+=a.particle_normalMapPS);0<b.normal&&(d+=b.halflambert?a.particle_halflambertPS:a.particle_lambertPS);0<b.normal&&(d+=a.particle_lightingPS);b.blend==pc.BLEND_NORMAL?d+=a.particle_blendNormalPS:b.blend==pc.BLEND_ADDITIVE?d+=a.particle_blendAddPS:b.blend==pc.BLEND_MULTIPLICATIVE&&(d+=a.particle_blendMultiplyPS);d+=a.particle_endPS;return{attributes:pc.shaderChunks.collectAttribs(c),vshader:c,fshader:d}}};var _oldChunkWarn=function(f,b){},_oldChunkFloat=function(f,b,a){_oldChunkWarn(a,b);return"\n#ifdef MAPFLOAT\n"+f+"\n#else\n"+pc.shaderChunks[b]+"\n#endif\n"},_oldChunkColor=function(f,b,a){_oldChunkWarn(a,b);return"\n#ifdef MAPCOLOR\n"+f+"\n#else\n"+pc.shaderChunks[b]+"\n#endif\n"},_oldChunkTex=function(f,b,a){_oldChunkWarn(a,b);return"\n#ifdef MAPTEXTURE\n"+f+"\n#else\n"+pc.shaderChunks[b]+"\n#endif\n"},_oldChunkTexColor=function(f,b,a){_oldChunkWarn(a,b);return"#undef MAPTEXTURECOLOR\n#ifdef MAPTEXTURE\n#ifdef MAPCOLOR\n#define MAPTEXTURECOLOR\n#endif\n#endif\n#ifdef MAPTEXTURECOLOR\n"+
- f+"\n#else\n"+pc.shaderChunks[b]+"\n#endif\n"},_oldChunkTexFloat=function(f,b,a){_oldChunkWarn(a,b);return"#undef MAPTEXTUREFLOAT\n#ifdef MAPTEXTURE\n#ifdef MAPFLOAT\n#define MAPTEXTUREFLOAT\n#endif\n#endif\n#ifdef MAPTEXTUREFLOAT\n"+f+"\n#else\n"+pc.shaderChunks[b]+"\n#endif\n"},_oldChunkVert=function(f,b,a){_oldChunkWarn(a,b);return"\n#ifdef MAPVERTEX\n"+f+"\n#else\n"+pc.shaderChunks[b]+"\n#endif\n"},_oldChunkVertColor=function(f,b,a){_oldChunkWarn(a,b);return"#undef MAPVERTEXCOLOR\n#ifdef MAPVERTEX\n#ifdef MAPCOLOR\n#define MAPVERTEXCOLOR\n#endif\n#endif\n#ifdef MAPVERTEXCOLOR\n"+
- f+"\n#else\n"+pc.shaderChunks[b]+"\n#endif\n"},_oldChunkVertFloat=function(f,b,a){_oldChunkWarn(a,b);return"#undef MAPVERTEXFLOAT\n#ifdef MAPVERTEX\n#ifdef MAPFLOAT\n#define MAPVERTEXFLOAT\n#endif\n#endif\n#ifdef MAPVERTEXFLOAT\n"+f+"\n#else\n"+pc.shaderChunks[b]+"\n#endif\n"},_oldChunkTransformSkin=function(f,b,a){_oldChunkWarn(a,b);return"\n#ifdef SKIN\n"+f+"\n#else\n"+pc.shaderChunks[b]+"\n#endif\n"},_oldChunkTransformDynbatch=function(f,b,a){_oldChunkWarn(a,b);return"\n#ifdef DYNAMICBATCH\n"+
- f+"\n#else\n"+pc.shaderChunks[b]+"\n#endif\n"},_oldChunkTransformInstanced=function(f,b,a){_oldChunkWarn(a,b);return"\n#ifdef INSTANCING\n"+f+"\n#else\n"+pc.shaderChunks[b]+"\n#endif\n"},_oldChunkTransformPixelSnap=function(f,b,a){_oldChunkWarn(a,b);return"\n#ifdef PIXELSNAP\n"+f+"\n#else\n"+pc.shaderChunks[b]+"\n#endif\n"},_oldChunkTransformScreenSpace=function(f,b,a){_oldChunkWarn(a,b);return"\n#ifdef SCREENSPACE\n"+f+"\n#else\n"+pc.shaderChunks[b]+"\n#endif\n"},_oldChunkTransformScreenSpaceBatch=
- function(f,b,a){_oldChunkWarn(a,b);return"#undef SCREENSPACEBATCH\n#ifdef SCREENSPACE\n#ifdef BATCH\n#define SCREENSPACEBATCH\n#endif\n#endif\n#ifdef SCREENSPACEBATCH\n"+f+"\n#else\n"+pc.shaderChunks[b]+"\n#endif\n"},_oldChunkTransformUv1=function(f,b,a){_oldChunkWarn(a,b);return"\n#ifdef UV1LAYOUT\n"+f+"\n#else\n"+pc.shaderChunks[b]+"\n#endif\n"};
- pc.programlib.standard={_oldChunkToNew:{aoTexPS:{n:"aoPS",f:_oldChunkTex},aoVertPS:{n:"aoPS",f:_oldChunkVert},diffuseConstPS:{n:"diffusePS",f:_oldChunkColor},diffuseTexPS:{n:"diffusePS",f:_oldChunkTex},diffuseTexConstPS:{n:"diffusePS",f:_oldChunkTexColor},diffuseVertPS:{n:"diffusePS",f:_oldChunkVert},diffuseVertConstPS:{n:"diffusePS",f:_oldChunkVertColor},emissiveConstPS:{n:"emissivePS",f:_oldChunkColor},emissiveTexPS:{n:"emissivePS",f:_oldChunkTex},emissiveTexConstPS:{n:"emissivePS",f:_oldChunkTexColor},
- emissiveTexConstFloatPS:{n:"emissivePS",f:_oldChunkTexFloat},emissiveVertPS:{n:"emissivePS",f:_oldChunkVert},emissiveVertConstPS:{n:"emissivePS",f:_oldChunkVertColor},emissiveVertConstFloatPS:{n:"emissivePS",f:_oldChunkVertFloat},glossConstPS:{n:"glossPS",f:_oldChunkFloat},glossTexPS:{n:"glossPS",f:_oldChunkTex},glossTexConstPS:{n:"glossPS",f:_oldChunkTexFloat},glossVertPS:{n:"glossPS",f:_oldChunkVert},glossVertConstPS:{n:"glossPS",f:_oldChunkVertFloat},metalnessConstPS:{n:"metalnessPS",f:_oldChunkFloat},
- metalnessTexPS:{n:"metalnessPS",f:_oldChunkTex},metalnessTexConstPS:{n:"metalnessPS",f:_oldChunkTexFloat},metalnessVertPS:{n:"metalnessPS",f:_oldChunkVert},metalnessVertConstPS:{n:"metalnessPS",f:_oldChunkVertFloat},opacityConstPS:{n:"opacityPS",f:_oldChunkFloat},opacityTexPS:{n:"opacityPS",f:_oldChunkTex},opacityTexConstPS:{n:"opacityPS",f:_oldChunkTexFloat},opacityVertPS:{n:"opacityPS",f:_oldChunkVert},opacityVertConstPS:{n:"opacityPS",f:_oldChunkVertFloat},specularConstPS:{n:"specularPS",f:_oldChunkColor},
- specularTexPS:{n:"specularPS",f:_oldChunkTex},specularTexConstPS:{n:"specularPS",f:_oldChunkTexColor},specularVertPS:{n:"specularPS",f:_oldChunkVert},specularVertConstPS:{n:"specularPS",f:_oldChunkVertColor},transformBatchSkinnedVS:{n:"transformVS",f:_oldChunkTransformDynbatch},transformInstancedVS:{n:"transformVS",f:_oldChunkTransformInstanced},transformPixelSnapVS:{n:"transformVS",f:_oldChunkTransformPixelSnap},transformScreenSpaceVS:{n:"transformVS",f:_oldChunkTransformScreenSpace},transformScreenSpaceBatchSkinned:{n:"transformVS",
- f:_oldChunkTransformScreenSpaceBatch},transformSkinned:{n:"transformVS",f:_oldChunkTransformSkin},transformUv1:{n:"transformVS",f:_oldChunkTransformUv1}},optionsContext:{},optionsContextMin:{},generateKey:function(f){var b=function(a){var b=[],c;for(c in a)a.hasOwnProperty(c)&&"chunks"!==c&&"lights"!==c&&b.push(c);return b.sort()},a;f===this.optionsContextMin?(this.propsMin||(this.propsMin=b(f)),a=this.propsMin):f===this.optionsContext?(this.props||(this.props=b(f)),a=this.props):a=b(f);var b="standard",
- c;for(c=0;c<a.length;c++)f[a[c]]&&(b+=a[c]+f[a[c]]);if(f.chunks){a=[];for(var d in f.chunks)f.chunks.hasOwnProperty(d)&&a.push(d+f.chunks[d]);a.sort();b+=a}if(f.lights)for(c=0;c<f.lights.length;c++)b+=f.lights[c].key;return pc.hashCode(b)},_correctChannel:function(f,b){if(0<pc._matTex2D[f]){if(pc._matTex2D[f]<b.length)return b.substring(0,pc._matTex2D[f]);if(pc._matTex2D[f]>b.length){for(var a=b,c=a.charAt(a.length-1),d=pc._matTex2D[f]-a.length,e=0;e<d;e++)a+=c;return a}return b}},_setMapTransform:function(f,
- b,a,c){f[0]+="uniform vec4 texture_"+b+"MapTransform;\n";var d=a+100*c;f[3][d]||(f[1]+="varying vec2 vUV"+c+"_"+a+";\n",f[2]+=" vUV"+c+"_"+a+" = uv"+c+" * texture_"+b+"MapTransform.xy + texture_"+b+"MapTransform.zw;\n",f[3][d]=!0);return f},_getUvSourceExpression:function(f,b,a){var c=a[f];b=a[b];a.nineSlicedMode===pc.SPRITE_RENDERMODE_SLICED?c="nineSlicedUv":a.nineSlicedMode===pc.SPRITE_RENDERMODE_TILED?c="nineSlicedUv, -1000.0":(c=0===c?"vUv"+b:"vUV"+b+"_"+c,a.heightMap&&"heightMapTransform"!==
- f&&(c+=" + dUvOffset"));return c},_addMapDef:function(f,b){var a="\n#undef "+f+"\n";b&&(a+=" #define "+f+"\n");return a},_addMapDefs:function(f,b,a,c){f=""+this._addMapDef("MAPFLOAT",f);f+=this._addMapDef("MAPCOLOR",b);f+=this._addMapDef("MAPVERTEX",a);return f+=this._addMapDef("MAPTEXTURE",c)},_addMap:function(f,b,a,c,d){var e=f+"Map",g=e+"Uv",l=e+"Transform",k=e+"Channel",p=f+"VertexColorChannel",h=a[f+"Tint"];f=a[f+"VertexColor"];e=a[e];b=c[b];e&&(g=this._getUvSourceExpression(l,g,a),b=b.replace(/\$UV/g,
- g).replace(/\$CH/g,a[k]),void 0!==d&&(b=b.replace(/\$texture2DSAMPLE/g,0===d?"texture2DSRGB":1===d?"texture2DRGBM":"texture2D")));f&&(b=b.replace(/\$VC/g,a[p]));b=this._addMapDefs(1===h,3===h,f,e)+b;return b.replace(/\$/g,"")},_nonPointShadowMapProjection:function(f,b,a){return!b._normalOffsetBias||b._isVsm?b._type===pc.LIGHTTYPE_SPOT?b._isPcf&&(f.webgl2||f.extStandardDerivatives)?" getShadowCoordPerspZbuffer"+a:" getShadowCoordPersp"+a:" getShadowCoordOrtho"+a:b._type===pc.LIGHTTYPE_SPOT?
- b._isPcf&&(f.webgl2||f.extStandardDerivatives)?" getShadowCoordPerspZbufferNormalOffset"+a:" getShadowCoordPerspNormalOffset"+a:" getShadowCoordOrthoNormalOffset"+a},_addVaryingIfNeeded:function(f,b,a){return 0<=f.indexOf(a)?"varying "+b+" "+a+";\n":""},_vsAddTransformCode:function(f,b,a,c){return f+=a.transformVS},_vsAddBaseCode:function(f,b,a,c){f+=a.baseVS;if(c.nineSlicedMode===pc.SPRITE_RENDERMODE_SLICED||c.nineSlicedMode===pc.SPRITE_RENDERMODE_TILED)f+=a.baseNineSlicedVS;return f},
- _fsAddBaseCode:function(f,b,a,c){f+=a.basePS;c.nineSlicedMode===pc.SPRITE_RENDERMODE_SLICED?f+=a.baseNineSlicedPS:c.nineSlicedMode===pc.SPRITE_RENDERMODE_TILED&&(f+=a.baseNineSlicedTiledPS);return f},_fsAddStartCode:function(f,b,a,c){f+=a.startPS;c.nineSlicedMode===pc.SPRITE_RENDERMODE_SLICED?f+=a.startNineSlicedPS:c.nineSlicedMode===pc.SPRITE_RENDERMODE_TILED&&(f+=a.startNineSlicedTiledPS);return f},createShaderDefinition:function(f,b){var a,c,d=0<b.lights.length;b.dirLightMap&&(d=!0,b.useSpecular=
- !0);b.shadingModel===pc.SPECULAR_PHONG?(b.fresnelModel=0,b.specularAntialias=!1,b.prefilteredCubemap=!1,b.dpAtlas=!1,b.ambientSH=!1):b.fresnelModel=0===b.fresnelModel?pc.FRESNEL_SCHLICK:b.fresnelModel;var e=(b.cubeMap||b.prefilteredCubemap&&b.useSpecular)&&!b.sphereMap&&!b.dpAtlas,g=b.sphereMap||e||b.dpAtlas,l=b.useTexCubeLod;b.cubeMap&&(b.sphereMap=null);b.dpAtlas&&(b.prefilteredCubemap=null);b.useSpecular||(b.specularMap=b.glossMap=null);var k=d||g||b.ambientSH||b.prefilteredCubemap||b.heightMap,
- p=b.pass>=pc.SHADER_SHADOW&&17>=b.pass;this.options=b;var h="",n="",q="",m=pc.shaderChunks,r,t={vertex_position:pc.SEMANTIC_POSITION};if(b.chunks){var v={};for(c in m)m.hasOwnProperty(c)&&(b.chunks[c]?(r=b.chunks[c],0<=r.indexOf("vertex_normal")&&(t.vertex_normal=pc.SEMANTIC_NORMAL),0<=r.indexOf("vertex_tangent")&&(t.vertex_tangent=pc.SEMANTIC_TANGENT),0<=r.indexOf("vertex_texCoord0")&&(t.vertex_texCoord0=pc.SEMANTIC_TEXCOORD0),0<=r.indexOf("vertex_texCoord1")&&(t.vertex_texCoord1=pc.SEMANTIC_TEXCOORD1),
- 0<=r.indexOf("vertex_color")&&(t.vertex_color=pc.SEMANTIC_COLOR),0<=r.indexOf("vertex_boneWeights")&&(t.vertex_boneWeights=pc.SEMANTIC_BLENDWEIGHT),0<=r.indexOf("vertex_boneIndices")&&(t.vertex_boneIndices=pc.SEMANTIC_BLENDINDICES),v[c]=r):v[c]=m[c]);for(c in b.chunks)(m=this._oldChunkToNew[c])&&(v[m.n]=m.f(b.chunks[c],m.n,c));m=v}h=this._vsAddBaseCode(h,f,m,b);v=-1;if(!b.noShadow&&!b.twoSidedLighting){for(a=0;a<b.lights.length;a++)if(r=b.lights[a]._type,b.lights[a].castShadows&&r===pc.LIGHTTYPE_DIRECTIONAL){h+=
- "uniform mat4 light"+a+"_shadowMatrixVS;\n";h+="uniform vec3 light"+a+"_shadowParamsVS;\n";h+="uniform vec3 light"+a+(r===pc.LIGHTTYPE_DIRECTIONAL?"_directionVS":"_positionVS")+";\n";v=a;break}0<=v&&(h+=m.shadowCoordVS)}n+=" vPositionW = getWorldPosition();\n";b.pass===pc.SHADER_DEPTH&&(h+="varying float vDepth;\n#ifndef VIEWMATRIX\n#define VIEWMATRIX\nuniform mat4 matrix_view;\n#endif\n#ifndef CAMERAPLANES\n#define CAMERAPLANES\nuniform vec4 camera_params;\n\n#endif\n",n+=" vDepth = -(matrix_view * vec4(vPositionW,1.0)).z * camera_params.x;\n");
- b.useInstancing&&(t.instance_line1=pc.SEMANTIC_TEXCOORD2,t.instance_line2=pc.SEMANTIC_TEXCOORD3,t.instance_line3=pc.SEMANTIC_TEXCOORD4,t.instance_line4=pc.SEMANTIC_TEXCOORD5,h+=m.instancingVS);k&&(t.vertex_normal=pc.SEMANTIC_NORMAL,n+=" vNormalW = dNormalW = getNormal();\n",b.sphereMap&&16>=f.fragmentUniformsCount&&(h+=m.viewNormalVS,n+=" vNormalV = getViewNormal();\n"),(b.heightMap||b.normalMap)&&b.hasTangents&&(t.vertex_tangent=pc.SEMANTIC_TANGENT,h+=m.tangentBinormalVS,n+=" vTangentW = getTangent();\n vBinormalW = getBinormal();\n"),
- 0<=v&&(r=b.lights[v]._type,n=r===pc.LIGHTTYPE_DIRECTIONAL?n+(" dLightDirNormW = light"+v+"_directionVS;\n"):n+(" getLightDirPoint(light"+v+"_positionVS);\n"),n+=this._nonPointShadowMapProjection(f,b.lights[v],"(light"+v+"_shadowMatrixVS, light"+v+"_shadowParamsVS);\n")));r=[];var y=[],u,w,x;for(c in pc._matTex2D)a=c+"Map",b[c+"VertexColor"]&&(u=c+"VertexColorChannel",b[u]=this._correctChannel(c,b[u])),b[a]&&(u=a+"Channel",w=a+"Transform",x=a+"Uv",b[x]=Math.min(b[x],1),b[u]=this._correctChannel(c,
- b[u]),x=b[x],r[x]=!0,y[x]=y[x]||b[a]&&!b[w]);b.forceUv1&&(r[1]=!0);for(a=0;2>a;a++)r[a]&&(t["vertex_texCoord"+a]=pc["SEMANTIC_TEXCOORD"+a],h+=m["uv"+a+"VS"],n+=" vec2 uv"+a+" = getUv"+a+"();\n"),y[a]&&(n+=" vUv"+a+" = uv"+a+";\n");r=[h,q,n,[]];for(c in pc._matTex2D)a=c+"Map",b[a]&&(w=a+"Transform",b[w]&&(x=a+"Uv",this._setMapTransform(r,c,b[w],b[x])));h=r[0];q=r[1];n=r[2];b.vertexColors&&(t.vertex_color=pc.SEMANTIC_COLOR,n+=" vVertexColor = vertex_color;\n");b.skin?(t.vertex_boneWeights=pc.SEMANTIC_BLENDWEIGHT,
- t.vertex_boneIndices=pc.SEMANTIC_BLENDINDICES,h+=pc.programlib.skinCode(f,m),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,f,m,b);k&&(h+=m.normalVS);h=h+"\n"+m.startVS;c=h=h+n+"}";r=q;q=""+this._addVaryingIfNeeded(h,"vec4","vMainShadowUv");q+=this._addVaryingIfNeeded(h,"vec4","vVertexColor");q+=this._addVaryingIfNeeded(h,"vec3","vPositionW");q+=this._addVaryingIfNeeded(h,
- "vec3","vNormalV");q+=this._addVaryingIfNeeded(h,"vec3","vNormalW");q+=this._addVaryingIfNeeded(h,"vec3","vTangentW");q+=this._addVaryingIfNeeded(h,"vec3","vBinormalW");q+=this._addVaryingIfNeeded(h,"vec2","vUv0");q+=this._addVaryingIfNeeded(h,"vec2","vUv1");q+=r;c=q+c;h="";f.webgl2?(h=pc.programlib.versionCode(f),m.extensionVS&&(h+=m.extensionVS+"\n"),c=h+m.gles3VS+c):(m.extensionVS&&(h=m.extensionVS+"\n"),c=h+c);b.forceFragmentPrecision&&"highp"!=b.forceFragmentPrecision&&"mediump"!==b.forceFragmentPrecision&&
- "lowp"!==b.forceFragmentPrecision&&(b.forceFragmentPrecision=null);b.forceFragmentPrecision&&("highp"===b.forceFragmentPrecision&&"highp"!==f.maxPrecision&&(b.forceFragmentPrecision="mediump"),"mediump"===b.forceFragmentPrecision&&"lowp"===f.maxPrecision&&(b.forceFragmentPrecision="lowp"));h="";f.webgl2&&(h+=pc.programlib.versionCode(f));f.extStandardDerivatives&&!f.webgl2&&(h+="#extension GL_OES_standard_derivatives : enable\n\n");m.extensionPS&&(h+=m.extensionPS+"\n");f.webgl2&&(h+=m.gles3PS);h+=
- b.forceFragmentPrecision?"precision "+b.forceFragmentPrecision+" float;\n\n":pc.programlib.precisionCode(f);if(b.pass===pc.SHADER_PICK)return h=h+"uniform vec4 uColor;"+q,b.alphaTest&&(h=h+"float dAlpha;\n"+this._addMap("opacity","opacityPS",b,m),h+=m.alphaTestPS),h+=pc.programlib.begin(),b.alphaTest&&(h+=" getOpacity();\n alphaTest(dAlpha);\n"),h=h+" gl_FragColor = uColor;\n"+pc.programlib.end(),{attributes:t,vshader:c,fshader:h};if(b.pass===pc.SHADER_DEPTH)return h=h+"varying float vDepth;\n"+
- q+m.packDepthPS,b.alphaTest&&(h+="float dAlpha;\n",h+=this._addMap("opacity","opacityPS",b,m),h+=m.alphaTestPS),h+=pc.programlib.begin(),b.alphaTest&&(h+=" getOpacity();\n",h+=" alphaTest(dAlpha);\n"),h+=" gl_FragColor = packFloat(vDepth);\n",h+=pc.programlib.end(),{attributes:t,vshader:c,fshader:h};if(p){e=b.pass-pc.SHADER_SHADOW;r=Math.floor(e/5);e-=5*r;f.extStandardDerivatives&&!f.webgl2&&(h+="uniform vec2 polygonOffset;\n");e===pc.SHADOW_VSM32?h=f.textureFloatHighPrecision?h+"#define VSM_EXPONENT 15.0\n\n":
- h+"#define VSM_EXPONENT 5.54\n\n":e===pc.SHADOW_VSM16&&(h+="#define VSM_EXPONENT 5.54\n\n");r!==pc.LIGHTTYPE_DIRECTIONAL&&(h+="uniform vec3 view_position;\n",h+="uniform float light_radius;\n");h+=q;b.alphaTest&&(h+="float dAlpha;\n",h+=this._addMap("opacity","opacityPS",b,m),h+=m.alphaTestPS);e!==pc.SHADOW_PCF3||f.webgl2&&r!==pc.LIGHTTYPE_POINT?e===pc.SHADOW_VSM8&&(h+="vec2 encodeFloatRG( float v ) {\n",h+=" vec2 enc = vec2(1.0, 255.0) * v;\n",h+=" enc = fract(enc);\n",h+=" enc -= enc.yy * vec2(1.0/255.0, 1.0/255.0);\n",
- h+=" return enc;\n",h+="}\n\n"):h+=m.packDepthPS;h+=pc.programlib.begin();b.alphaTest&&(h+=" getOpacity();\n",h+=" alphaTest(dAlpha);\n");var D=e===pc.SHADOW_VSM8||e===pc.SHADOW_VSM16||e===pc.SHADOW_VSM32,h=r===pc.LIGHTTYPE_POINT||D&&r!==pc.LIGHTTYPE_DIRECTIONAL?h+" float depth = min(distance(view_position, vPositionW) / light_radius, 0.99999);\n":h+" float depth = gl_FragCoord.z;\n";e!==pc.SHADOW_PCF3||f.webgl2&&r!==pc.LIGHTTYPE_POINT?h=e===pc.SHADOW_PCF3||e===pc.SHADOW_PCF5?h+" gl_FragColor = vec4(1.0);\n":
- e===pc.SHADOW_VSM8?h+" gl_FragColor = vec4(encodeFloatRG(depth), encodeFloatRG(depth*depth));\n":h+m.storeEVSMPS:(f.extStandardDerivatives&&!f.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+=pc.programlib.end();return{attributes:t,vshader:c,fshader:h}}if(b.customFragmentShader)return h+=b.customFragmentShader,
- {attributes:t,vshader:c,fshader:h,tag:pc.SHADERTAG_MATERIAL};q=h=this._fsAddBaseCode(h+q,f,m,b);h="";y=0;w=[];u=x=!1;for(a=0;a<b.lights.length;a++)if(n=b.lights[a],r=n._type,h+="uniform vec3 light"+a+"_color;\n",r===pc.LIGHTTYPE_DIRECTIONAL?h+="uniform vec3 light"+a+"_direction;\n":(h+="uniform vec3 light"+a+"_position;\n",h+="uniform float light"+a+"_radius;\n",r===pc.LIGHTTYPE_SPOT&&(h+="uniform vec3 light"+a+"_direction;\n",h+="uniform float light"+a+"_innerConeAngle;\n",h+="uniform float light"+
- a+"_outerConeAngle;\n")),n.castShadows&&!b.noShadow&&(h+="uniform mat4 light"+a+"_shadowMatrix;\n",h=r!==pc.LIGHTTYPE_DIRECTIONAL?h+("uniform vec4 light"+a+"_shadowParams;\n"):h+("uniform vec3 light"+a+"_shadowParams;\n"),h=r===pc.LIGHTTYPE_POINT?h+("uniform samplerCube light"+a+"_shadowMap;\n"):n._isPcf&&f.webgl2?h+("uniform sampler2DShadow light"+a+"_shadowMap;\n"):h+("uniform sampler2D light"+a+"_shadowMap;\n"),y++,w[n._shadowType]=!0,n._isVsm&&(x=!0),n._isPcf&&(f.webgl2||f.extStandardDerivatives)&&
- r===pc.LIGHTTYPE_SPOT&&(u=!0)),n._cookie)if(n._cookie._cubemap)r===pc.LIGHTTYPE_POINT&&(h+="uniform samplerCube light"+a+"_cookie;\n",h+="uniform float light"+a+"_cookieIntensity;\n",!n.castShadows||b.noShadow)&&(h+="uniform mat4 light"+a+"_shadowMatrix;\n");else if(r===pc.LIGHTTYPE_SPOT){h+="uniform sampler2D light"+a+"_cookie;\n";h+="uniform float light"+a+"_cookieIntensity;\n";if(!n.castShadows||b.noShadow)h+="uniform mat4 light"+a+"_shadowMatrix;\n";n._cookieTransform&&(h+="uniform vec4 light"+
- a+"_cookieMatrix;\n",h+="uniform vec2 light"+a+"_cookieOffset;\n")}h+="\n";r=b.hasTangents?b.fastTbn?m.TBNfastPS:m.TBNPS:m.TBNderivativePS;k&&(b.normalMap?(h+=b.packedNormal?m.normalXYPS:m.normalXYZPS,a=this._getUvSourceExpression("normalMapTransform","normalMapUv",b),h=b.needsNormalFloat?h+(b.fastTbn?m.normalMapFloatTBNfastPS:m.normalMapFloatPS).replace(/\$UV/g,a):h+m.normalMapPS.replace(/\$UV/g,a),b.hasTangents||(r=r.replace(/\$UV/g,a)),h+=r):h+=m.normalVertexPS);h+=pc.programlib.gammaCode(b.gamma);
- h+=pc.programlib.tonemapCode(b.toneMap);h+=pc.programlib.fogCode(b.fog);b.useRgbm&&(h+=m.rgbmPS);if(e||b.prefilteredCubemap)h+=b.fixSeams?m.fixCubemapSeamsStretchPS:m.fixCubemapSeamsNonePS;k&&(h+=0<b.cubeMapProjection?m.cubeMapProjectBoxPS:m.cubeMapProjectNonePS,h+=b.skyboxIntensity?m.envMultiplyPS:m.envConstPS);h+=this._addMap("diffuse","diffusePS",b,m);if(b.blendType!==pc.BLEND_NONE||b.alphaTest||b.alphaToCoverage)h+=this._addMap("opacity","opacityPS",b,m);h+=this._addMap("emissive","emissivePS",
- b,m,b.emissiveFormat);b.useSpecular&&(d||g)&&(h=b.specularAntialias&&b.normalMap?b.needsNormalFloat&&k?h+m.specularAaToksvigFloatPS:h+m.specularAaToksvigPS:h+m.specularAaNonePS,a=b.useMetalness?"metalness":"specular",h+=this._addMap(a,a+"PS",b,m),h+=this._addMap("gloss","glossPS",b,m),0<b.fresnelModel&&(b.fresnelModel===pc.FRESNEL_SIMPLE?h+=m.fresnelSimplePS:b.fresnelModel===pc.FRESNEL_SCHLICK?h+=m.fresnelSchlickPS:b.fresnelModel===pc.FRESNEL_COMPLEX&&(h+=m.fresnelComplexPS)));b.heightMap&&(b.normalMap||
- (a=this._getUvSourceExpression("heightMapTransform","heightMapUv",b),b.hasTangents||(r=r.replace(/\$UV/g,a)),h+=r),h+=this._addMap("height","parallaxPS",b,m));if(p=b.aoMap||b.aoVertexColor)h+=this._addMap("ao","aoPS",b,m),b.occludeSpecular&&(h=b.occludeSpecular===pc.SPECOCC_AO?h+(b.occludeSpecularFloat?m.aoSpecOccSimplePS:m.aoSpecOccConstSimplePS):h+(b.occludeSpecularFloat?m.aoSpecOccPS:m.aoSpecOccConstPS));r=b.rgbmReflection?"decodeRGBM":b.hdrReflection?"":"gammaCorrectInput";b.sphereMap?(r=16<f.fragmentUniformsCount?
- m.reflectionSpherePS:m.reflectionSphereLowPS,r=r.replace(/\$texture2DSAMPLE/g,b.rgbmReflection?"texture2DRGBM":b.hdrReflection?"texture2D":"texture2DSRGB"),h+=r):e?h=b.prefilteredCubemap?l?h+m.reflectionPrefilteredCubeLodPS.replace(/\$DECODE/g,r):h+m.reflectionPrefilteredCubePS.replace(/\$DECODE/g,r):h+m.reflectionCubePS.replace(/\$textureCubeSAMPLE/g,b.rgbmReflection?"textureCubeRGBM":b.hdrReflection?"textureCube":"textureCubeSRGB"):b.dpAtlas&&(h+=m.reflectionDpAtlasPS.replace(/\$texture2DSAMPLE/g,
- b.rgbmReflection?"texture2DRGBM":b.hdrReflection?"texture2D":"texture2DSRGB"));(e||b.sphereMap||b.dpAtlas)&&b.refraction&&(h+=m.refractionPS);0<y&&(w[pc.SHADOW_PCF3]&&(h+=m.shadowStandardPS),w[pc.SHADOW_PCF5]&&(h+=m.shadowStandardGL2PS),x&&(h+=m.shadowVSM_commonPS,w[pc.SHADOW_VSM8]&&(h+=m.shadowVSM8PS),w[pc.SHADOW_VSM16]&&(h+=f.extTextureHalfFloatLinear?m.shadowEVSMPS.replace(/\$/g,"16"):m.shadowEVSMnPS.replace(/\$/g,"16")),w[pc.SHADOW_VSM32]&&(h+=f.extTextureFloatLinear?m.shadowEVSMPS.replace(/\$/g,
- "32"):m.shadowEVSMnPS.replace(/\$/g,"32"))),f.webgl2||f.extStandardDerivatives||(h+=m.biasConstPS),h+=m.shadowCoordPS+m.shadowCommonPS,u&&(h+=m.shadowCoordPerspZbufferPS),0<=v&&(w[pc.SHADOW_PCF3]&&(h+=m.shadowStandardVSPS),w[pc.SHADOW_PCF5]&&(h+=m.shadowStandardGL2VSPS),x&&(w[pc.SHADOW_VSM8]&&(h+=m.shadowVSMVSPS.replace(/\$VSM/g,"VSM8").replace(/\$/g,"8")),w[pc.SHADOW_VSM16]&&(h+=m.shadowVSMVSPS.replace(/\$VSM/g,"VSM16").replace(/\$/g,"16")),w[pc.SHADOW_VSM32]&&(h+=m.shadowVSMVSPS.replace(/\$VSM/g,
- "VSM32").replace(/\$/g,"32")))));d&&(h+=m.lightDiffuseLambertPS);r=!1;b.useSpecular?(d&&(h+=b.shadingModel===pc.SPECULAR_PHONG?m.lightSpecularPhongPS:m.lightSpecularBlinnPS),b.sphereMap||e||b.dpAtlas||0<b.fresnelModel?h=0<b.fresnelModel?b.conserveEnergy?h+m.combineDiffuseSpecularPS:h+m.combineDiffuseSpecularNoConservePS:h+m.combineDiffuseSpecularOldPS:b.diffuseMap?h+=m.combineDiffuseSpecularNoReflPS:(h+=m.combineDiffuseSpecularNoReflSeparateAmbientPS,r=!0)):h+=m.combineDiffusePS;a=!0;if(b.lightMap||
- b.lightVertexColor)h+=this._addMap("light",b.dirLightMap?"lightmapDirPS":"lightmapSinglePS",b,m,b.lightMapFormat),a=b.lightMapWithoutAmbient;a&&(n=b.rgbmAmbient?"decodeRGBM":b.hdrAmbient?"":"gammaCorrectInput",h=b.ambientSH?h+m.ambientSHPS:b.prefilteredCubemap?l?h+m.ambientPrefilteredCubeLodPS.replace(/\$DECODE/g,n):h+m.ambientPrefilteredCubePS.replace(/\$DECODE/g,n):h+m.ambientConstantPS);b.ambientTint&&!r&&(h+="uniform vec3 material_ambient;\n");b.alphaTest&&(h+=m.alphaTestPS);b.msdf&&(h+=m.msdfPS);
- k&&(h+=m.viewDirPS,b.useSpecular&&(h+=m.reflDirPS));u=x=w=y=l=!1;h=this._fsAddStartCode(h,f,m,b);k&&(h=b.twoSidedLighting?h+" dVertexNormalW = gl_FrontFacing ? vNormalW : -vNormalW;\n":h+" dVertexNormalW = vNormalW;\n",(b.heightMap||b.normalMap)&&b.hasTangents&&(b.twoSidedLighting?(h+=" dTangentW = gl_FrontFacing ? vTangentW : -vTangentW;\n",h+=" dBinormalW = gl_FrontFacing ? vBinormalW : -vBinormalW;\n"):(h+=" dTangentW = vTangentW;\n",h+=" dBinormalW = vBinormalW;\n")));n=!1;b.blendType!==
- pc.BLEND_NONE||b.alphaTest||b.alphaToCoverage?b.heightMap&&b.opacityMap?n=!0:(h+=" getOpacity();\n",b.alphaTest&&(h+=" alphaTest(dAlpha);\n")):h+=" dAlpha = 1.0;\n";if(k){h+=" getViewDir();\n";if(b.heightMap||b.normalMap)h+=" getTBN();\n";b.heightMap&&(h+=" getParallax();\n");n&&(h+=" getOpacity();\n",b.alphaTest&&(h+=" alphaTest(dAlpha);\n"));h+=" getNormal();\n";b.useSpecular&&(h+=" getReflDir();\n")}h+=" getAlbedo();\n";if(d&&b.useSpecular||g)h+=" getSpecularity();\n",h+=
- " getGlossiness();\n",0<b.fresnelModel&&(h+=" getFresnel();\n");a&&(h+=" addAmbient();\n");b.ambientTint&&!r&&(h+=" dDiffuseLight *= material_ambient;\n");p&&!b.occludeDirect&&(h+=" applyAO();\n");if(b.lightMap||b.lightVertexColor)h+=" addLightMap();\n";if(d||g){if(e||b.sphereMap||b.dpAtlas)h+=" addReflection();\n";b.dirLightMap&&(h+=" addDirLightMap();\n");for(a=0;a<b.lights.length;a++)n=b.lights[a],r=n._type,g=!1,r===pc.LIGHTTYPE_DIRECTIONAL?(h+=" dLightDirNormW = light"+a+"_direction;\n",
- h+=" dAtten = 1.0;\n"):(n._cookie&&(r!==pc.LIGHTTYPE_SPOT||n._cookie._cubemap?r===pc.LIGHTTYPE_POINT&&n._cookie._cubemap&&(g=u=!0):g=u=!0),h+=" getLightDirPoint(light"+a+"_position);\n",l=!0,g&&(h=r===pc.LIGHTTYPE_SPOT?h+(" dAtten3 = getCookie2D"+(n._cookieFalloff?"":"Clip")+(n._cookieTransform?"Xform":"")+"(light"+a+"_cookie, light"+a+"_shadowMatrix, light"+a+"_cookieIntensity"+(n._cookieTransform?", light"+a+"_cookieMatrix, light"+a+"_cookieOffset":"")+")."+n._cookieChannel+";\n"):h+(" dAtten3 = getCookieCube(light"+
- a+"_cookie, light"+a+"_shadowMatrix, light"+a+"_cookieIntensity)."+n._cookieChannel+";\n")),n._falloffMode===pc.LIGHTFALLOFF_LINEAR?(h+=" dAtten = getFalloffLinear(light"+a+"_radius);\n",y=!0):(h+=" dAtten = getFalloffInvSquared(light"+a+"_radius);\n",w=!0),h+=" if (dAtten > 0.00001) {\n",r!==pc.LIGHTTYPE_SPOT||g&&!n._cookieFalloff||(h+=" dAtten *= getSpotEffect(light"+a+"_direction, light"+a+"_innerConeAngle, light"+a+"_outerConeAngle);\n",x=!0)),h+=" dAtten *= getLightDiffuse();\n",
- n.castShadows&&!b.noShadow&&(n._shadowType===pc.SHADOW_VSM8?(k="VSM8",D="0.0"):n._shadowType===pc.SHADOW_VSM16?(k="VSM16",D="5.54"):n._shadowType===pc.SHADOW_VSM32?(k="VSM32",D=f.textureFloatHighPrecision?"15.0":"5.54"):k=n._shadowType===pc.SHADOW_PCF5?"PCF5x5":"PCF3x3",null!==k&&(r===pc.LIGHTTYPE_POINT?(d="(light"+a+"_shadowMap, light"+a+"_shadowParams);\n",n._normalOffsetBias&&(h+=" normalOffsetPointShadow(light"+a+"_shadowParams);\n"),h+=" dAtten *= getShadowPoint"+k+d):(v===a?k+="VS":
- (d="(light"+a+"_shadowMatrix, light"+a+"_shadowParams);\n",h+=this._nonPointShadowMapProjection(f,b.lights[a],d)),r===pc.LIGHTTYPE_SPOT&&(k="Spot"+k),h+=" dAtten *= getShadow"+k+"(light"+a+"_shadowMap, light"+a+"_shadowParams"+(n._isVsm?", "+D:"")+");\n"))),h+=" dDiffuseLight += dAtten * light"+a+"_color"+(g?" * dAtten3":"")+";\n",b.useSpecular&&(h+=" dAtten *= getLightSpecular();\n",h+=" dSpecularLight += dAtten * light"+a+"_color"+(g?" * dAtten3":"")+";\n"),r!==pc.LIGHTTYPE_DIRECTIONAL&&
- (h+=" }\n"),h+="\n";(e||b.sphereMap||b.dpAtlas)&&b.refraction&&(h+=" addRefraction();\n")}h+="\n";p&&(b.occludeDirect&&(h+=" applyAO();\n"),b.occludeSpecular&&(h+=" occludeSpecular();\n"));h+=m.endPS;h=b.blendType===pc.BLEND_NORMAL||b.blendType===pc.BLEND_ADDITIVEALPHA||b.alphaToCoverage?h+m.outputAlphaPS:b.blendType===pc.BLEND_PREMULTIPLIED?h+m.outputAlphaPremulPS:h+m.outputAlphaOpaquePS;b.msdf&&(h+=" gl_FragColor = applyMsdf(gl_FragColor);\n");h+="\n";h+=pc.programlib.end();l&&(h=m.lightDirPointPS+
- h);y&&(h=m.falloffLinearPS+h);w&&(h=m.falloffInvSquaredPS+h);x&&(h=m.spotPS+h);u&&(h=m.cookiePS+h);m="";h.includes("dReflection")&&(m+="vec4 dReflection;\n");h.includes("dTBN")&&(m+="mat3 dTBN;\n");h.includes("dAlbedo")&&(m+="vec3 dAlbedo;\n");h.includes("dEmission")&&(m+="vec3 dEmission;\n");h.includes("dNormalW")&&(m+="vec3 dNormalW;\n");h.includes("dVertexNormalW")&&(m+="vec3 dVertexNormalW;\n");h.includes("dTangentW")&&(m+="vec3 dTangentW;\n");h.includes("dBinormalW")&&(m+="vec3 dBinormalW;\n");
- h.includes("dViewDirW")&&(m+="vec3 dViewDirW;\n");h.includes("dReflDirW")&&(m+="vec3 dReflDirW;\n");h.includes("dDiffuseLight")&&(m+="vec3 dDiffuseLight;\n");h.includes("dSpecularLight")&&(m+="vec3 dSpecularLight;\n");h.includes("dLightDirNormW")&&(m+="vec3 dLightDirNormW;\n");h.includes("dLightDirW")&&(m+="vec3 dLightDirW;\n");h.includes("dLightPosW")&&(m+="vec3 dLightPosW;\n");h.includes("dShadowCoord")&&(m+="vec3 dShadowCoord;\n");h.includes("dNormalMap")&&(m+="vec3 dNormalMap;\n");h.includes("dSpecularity")&&
- (m+="vec3 dSpecularity;\n");h.includes("dUvOffset")&&(m+="vec2 dUvOffset;\n");h.includes("dGlossiness")&&(m+="float dGlossiness;\n");h.includes("dAlpha")&&(m+="float dAlpha;\n");h.includes("dAtten")&&(m+="float dAtten;\n");h.includes("dAtten3")&&(m+="vec3 dAtten3;\n");h.includes("dAo")&&(m+="float dAo;\n");h.includes("dMsdf")&&(m+="vec4 dMsdf;\n");h=q+m+h;return{attributes:t,vshader:c,fshader:h,tag:pc.SHADERTAG_MATERIAL}}};pc.programlib.skybox={generateKey:function(f){return"skybox"+f.rgbm+" "+f.hdr+" "+f.fixSeams+""+f.toneMapping+""+f.gamma+""+f.useIntensity+""+f.mip},createShaderDefinition:function(f,b){var a=pc.shaderChunks;return{attributes:{aPosition:pc.SEMANTIC_POSITION},vshader:a.skyboxVS,fshader:pc.programlib.precisionCode(f)+(b.mip?a.fixCubemapSeamsStretchPS:a.fixCubemapSeamsNonePS)+(b.useIntensity?a.envMultiplyPS:a.envConstPS)+pc.programlib.gammaCode(b.gamma)+pc.programlib.tonemapCode(b.toneMapping)+a.rgbmPS+
- a.skyboxHDRPS.replace(/\$textureCubeSAMPLE/g,b.rgbm?"textureCubeRGBM":b.hdr?"textureCube":"textureCubeSRGB").replace(/\$FIXCONST/g,1-1/[128,64,16,8,4,2][b.mip]+"")}}};Object.assign(pc,function(){var f={type:pc.PRIMITIVE_TRISTRIP,base:0,count:4,indexed:!1},b=function(a){this.device=a;this.depthMap=this.shader=null;this.vertexBuffer=pc.createFullscreenQuad(a);this.needsDepthBuffer=!1};Object.assign(b.prototype,{render:function(a,b,d){}});return{PostEffect:b,createFullscreenQuad:function(a){var b=new pc.VertexFormat(a,[{semantic:pc.SEMANTIC_POSITION,components:2,type:pc.TYPE_FLOAT32}]);a=new pc.VertexBuffer(a,b,4);b=new pc.VertexIterator(a);b.element[pc.SEMANTIC_POSITION].set(-1,
- -1);b.next();b.element[pc.SEMANTIC_POSITION].set(1,-1);b.next();b.element[pc.SEMANTIC_POSITION].set(-1,1);b.next();b.element[pc.SEMANTIC_POSITION].set(1,1);b.end();return a},drawFullscreenQuad:function(a,b,d,e,g){var c=a.getRenderTarget();a.setRenderTarget(b);a.updateBegin();var k=null!==b?b.width:a.width,p=null!==b?b.height:a.height,h=0,n=0;g&&(h=g.x*k,n=g.y*p,k*=g.z,p*=g.w);g=a.vx;b=a.vy;var q=a.vw,m=a.vh;a.setViewport(h,n,k,p);var r=a.sx,t=a.sy,v=a.sw,y=a.sh;a.setScissor(h,n,k,p);var k=a.getBlending(),
- p=a.getDepthTest(),h=a.getDepthWrite(),n=a.getCullMode(),u=a.writeRed,w=a.writeGreen,x=a.writeBlue,D=a.writeAlpha;a.setBlending(!1);a.setDepthTest(!1);a.setDepthWrite(!1);a.setCullMode(pc.CULLFACE_NONE);a.setColorWrite(!0,!0,!0,!0);a.setVertexBuffer(d,0);a.setShader(e);a.draw(f);a.setBlending(k);a.setDepthTest(p);a.setDepthWrite(h);a.setCullMode(n);a.setColorWrite(u,w,x,D);a.updateEnd();a.setRenderTarget(c);a.updateBegin();a.setViewport(g,b,q,m);a.setScissor(r,t,v,y)}}}());(function(){var f={BLEND_SUBTRACTIVE:0,BLEND_ADDITIVE:1,BLEND_NORMAL:2,BLEND_NONE:3,BLEND_PREMULTIPLIED:4,BLEND_MULTIPLICATIVE:5,BLEND_ADDITIVEALPHA:6,BLEND_MULTIPLICATIVE2X:7,BLEND_SCREEN:8,BLEND_MIN:9,BLEND_MAX:10,FOG_NONE:"none",FOG_LINEAR:"linear",FOG_EXP:"exp",FOG_EXP2:"exp2",FRESNEL_NONE:0,FRESNEL_SCHLICK:2,LAYER_HUD:0,LAYER_GIZMO:1,LAYER_FX:2,LAYER_WORLD:15,LAYERID_WORLD:0,LAYERID_DEPTH:1,LAYERID_SKYBOX:2,LAYERID_IMMEDIATE:3,LAYERID_UI:4,LIGHTTYPE_DIRECTIONAL:0,LIGHTTYPE_POINT:1,LIGHTTYPE_SPOT:2,
- LIGHTFALLOFF_LINEAR:0,LIGHTFALLOFF_INVERSESQUARED:1,SHADOW_PCF3:0,SHADOW_DEPTH:0,SHADOW_VSM8:1,SHADOW_VSM16:2,SHADOW_VSM32:3,SHADOW_PCF5:4,BLUR_BOX:0,BLUR_GAUSSIAN:1,PARTICLESORT_NONE:0,PARTICLESORT_DISTANCE:1,PARTICLESORT_NEWER_FIRST:2,PARTICLESORT_OLDER_FIRST:3,PARTICLEMODE_GPU:0,PARTICLEMODE_CPU:1,EMITTERSHAPE_BOX:0,EMITTERSHAPE_SPHERE:1,PROJECTION_PERSPECTIVE:0,PROJECTION_ORTHOGRAPHIC:1,RENDERSTYLE_SOLID:0,RENDERSTYLE_WIREFRAME:1,RENDERSTYLE_POINTS:2,CUBEPROJ_NONE:0,CUBEPROJ_BOX:1,SPECULAR_PHONG:0,
- SPECULAR_BLINN:1,GAMMA_NONE:0,GAMMA_SRGB:1,GAMMA_SRGBFAST:2,GAMMA_SRGBHDR:3,TONEMAP_LINEAR:0,TONEMAP_FILMIC:1,TONEMAP_HEJL:2,TONEMAP_ACES:3,TONEMAP_ACES2:4,SPECOCC_NONE:0,SPECOCC_AO:1,SPECOCC_GLOSSDEPENDENT:2,SHADERDEF_NOSHADOW:1,SHADERDEF_SKIN:2,SHADERDEF_UV0:4,SHADERDEF_UV1:8,SHADERDEF_VCOLOR:16,SHADERDEF_INSTANCING:32,SHADERDEF_LM:64,SHADERDEF_DIRLM:128,SHADERDEF_SCREENSPACE:256,SHADERDEF_TANGENTS:512,LINEBATCH_WORLD:0,LINEBATCH_OVERLAY:1,LINEBATCH_GIZMO:2,SHADOWUPDATE_NONE:0,SHADOWUPDATE_THISFRAME:1,
- SHADOWUPDATE_REALTIME:2,SORTKEY_FORWARD:0,SORTKEY_DEPTH:1,MASK_DYNAMIC:1,MASK_BAKED:2,MASK_LIGHTMAP:4,SHADER_FORWARD:0,SHADER_FORWARDHDR:1,SHADER_DEPTH:2,SHADER_SHADOW:3,SHADER_PICK:18,BAKE_COLOR:0,BAKE_COLORDIR:1,VIEW_CENTER:0,VIEW_LEFT:1,VIEW_RIGHT:2,SORTMODE_NONE:0,SORTMODE_MANUAL:1,SORTMODE_MATERIALMESH:2,SORTMODE_BACK2FRONT:3,SORTMODE_FRONT2BACK:4,SORTMODE_CUSTOM:5,COMPUPDATED_INSTANCES:1,COMPUPDATED_LIGHTS:2,COMPUPDATED_CAMERAS:4,COMPUPDATED_BLEND:8,ASPECT_AUTO:0,ASPECT_MANUAL:1,ORIENTATION_HORIZONTAL:0,
- ORIENTATION_VERTICAL:1};Object.assign(pc,f);pc.scene={};Object.assign(pc.scene,f)})();
- Object.assign(pc,function(){var f=function(){this.root=null;this._gravity=new pc.Vec3(0,-9.8,0);this._layers=null;this._fog=pc.FOG_NONE;this.fogColor=new pc.Color(0,0,0);this.fogStart=1;this.fogEnd=1E3;this.fogDensity=0;this.ambientLight=new pc.Color(0,0,0);this._gammaCorrection=pc.GAMMA_NONE;this._toneMapping=0;this.exposure=1;this._skyboxPrefiltered=[null,null,null,null,null,null];this.skyboxModel=this._skyboxCubeMap=null;this._skyboxIntensity=1;this._skyboxMip=0;this.lightmapSizeMultiplier=1;this.lightmapMaxResolution=
- 2048;this.lightmapMode=pc.BAKE_COLORDIR;this._stats={meshInstances:0,lights:0,dynamicLights:0,bakedLights:0,lastStaticPrepareFullTime:0,lastStaticPrepareSearchTime:0,lastStaticPrepareWriteTime:0,lastStaticPrepareTriAabbTime:0,lastStaticPrepareCombineTime:0,updateShadersTime:0};this.updateSkybox=this.updateShaders=!0;this._shaderVersion=0;this._statsUpdated=!1;this._models=[];this.defaultMaterial=new pc.StandardMaterial;this.defaultMaterial.name="Default Material";this.defaultMaterial.shadingModel=
- pc.SPECULAR_BLINN;pc.events.attach(this)};f.prototype.destroy=function(){this.root=null;this.defaultMaterial.destroy();this.defaultMaterial=null;this.off()};Object.defineProperty(f.prototype,"fog",{get:function(){return this._fog},set:function(b){b!==this._fog&&(this._fog=b,this.updateShaders=!0)}});Object.defineProperty(f.prototype,"gammaCorrection",{get:function(){return this._gammaCorrection},set:function(b){b!==this._gammaCorrection&&(this._gammaCorrection=b,this.updateShaders=!0)}});Object.defineProperty(f.prototype,
- "toneMapping",{get:function(){return this._toneMapping},set:function(b){b!==this._toneMapping&&(this._toneMapping=b,this.updateShaders=!0)}});Object.defineProperty(f.prototype,"skybox",{get:function(){return this._skyboxCubeMap},set:function(b){this._skyboxCubeMap=b;this._resetSkyboxModel();this.updateShaders=!0}});Object.defineProperty(f.prototype,"skyboxIntensity",{get:function(){return this._skyboxIntensity},set:function(b){this._skyboxIntensity=b;this._resetSkyboxModel();this.updateShaders=!0}});
- Object.defineProperty(f.prototype,"skyboxMip",{get:function(){return this._skyboxMip},set:function(b){this._skyboxMip=b;this._resetSkyboxModel();this.updateShaders=!0}});Object.defineProperty(f.prototype,"skyboxPrefiltered128",{get:function(){return this._skyboxPrefiltered[0]},set:function(b){this._skyboxPrefiltered[0]!==b&&(this._skyboxPrefiltered[0]=b,this.updateShaders=!0)}});Object.defineProperty(f.prototype,"skyboxPrefiltered64",{get:function(){return this._skyboxPrefiltered[1]},set:function(b){this._skyboxPrefiltered[1]!==
- b&&(this._skyboxPrefiltered[1]=b,this.updateShaders=!0)}});Object.defineProperty(f.prototype,"skyboxPrefiltered32",{get:function(){return this._skyboxPrefiltered[2]},set:function(b){this._skyboxPrefiltered[2]!==b&&(this._skyboxPrefiltered[2]=b,this.updateShaders=!0)}});Object.defineProperty(f.prototype,"skyboxPrefiltered16",{get:function(){return this._skyboxPrefiltered[3]},set:function(b){this._skyboxPrefiltered[3]!==b&&(this._skyboxPrefiltered[3]=b,this.updateShaders=!0)}});Object.defineProperty(f.prototype,
- "skyboxPrefiltered8",{get:function(){return this._skyboxPrefiltered[4]},set:function(b){this._skyboxPrefiltered[4]!==b&&(this._skyboxPrefiltered[4]=b,this.updateShaders=!0)}});Object.defineProperty(f.prototype,"skyboxPrefiltered4",{get:function(){return this._skyboxPrefiltered[5]},set:function(b){this._skyboxPrefiltered[5]!==b&&(this._skyboxPrefiltered[5]=b,this.updateShaders=!0)}});Object.defineProperty(f.prototype,"drawCalls",{get:function(){var b=this.layers._meshInstances;b.length||(this.layers._update(),
- b=this.layers._meshInstances);return b},set:function(b){}});Object.defineProperty(f.prototype,"layers",{get:function(){return this._layers},set:function(b){var a=this._layers;this._layers=b;this.fire("set:layers",a,b)}});f.prototype.applySettings=function(b){this._gravity.set(b.physics.gravity[0],b.physics.gravity[1],b.physics.gravity[2]);this.ambientLight.set(b.render.global_ambient[0],b.render.global_ambient[1],b.render.global_ambient[2]);this._fog=b.render.fog;this.fogColor.set(b.render.fog_color[0],
- b.render.fog_color[1],b.render.fog_color[2]);this.fogStart=b.render.fog_start;this.fogEnd=b.render.fog_end;this.fogDensity=b.render.fog_density;this._gammaCorrection=b.render.gamma_correction;this._toneMapping=b.render.tonemapping;this.lightmapSizeMultiplier=b.render.lightmapSizeMultiplier;this.lightmapMaxResolution=b.render.lightmapMaxResolution;this.lightmapMode=b.render.lightmapMode;this.exposure=b.render.exposure;this._skyboxIntensity=void 0===b.render.skyboxIntensity?1:b.render.skyboxIntensity;
- this._skyboxMip=void 0===b.render.skyboxMip?0:b.render.skyboxMip;this._resetSkyboxModel();this.updateShaders=!0};f.prototype._updateSkybox=function(b){if(this._skyboxCubeMap&&!this.skyboxModel){var a=new pc.Material,c=this;a.updateShader=function(a,d,e,g,l){this.shader=b.getProgramLibrary().getProgram("skybox",{rgbm:c._skyboxCubeMap.rgbm,hdr:c._skyboxCubeMap.rgbm||c._skyboxCubeMap.format===pc.PIXELFORMAT_RGBA32F,useIntensity:1!==c.skyboxIntensity,mip:c._skyboxCubeMap.fixCubemapSeams?c.skyboxMip:0,
- fixSeams:c._skyboxCubeMap.fixCubemapSeams,gamma:l===pc.SHADER_FORWARDHDR?c.gammaCorrection?pc.GAMMA_SRGBHDR:pc.GAMMA_NONE:c.gammaCorrection,toneMapping:l===pc.SHADER_FORWARDHDR?pc.TONEMAP_LINEAR:c.toneMapping})};a.updateShader();var d;if(this._skyboxCubeMap.fixCubemapSeams&&c._skyboxMip){var e=this["skyboxPrefiltered"+[null,"64","16","8","4"][c._skyboxMip]];e&&(d=e)}else d=this._skyboxCubeMap;a.setParameter("texture_cubeMap",d);a.cull=pc.CULLFACE_NONE;if(e=this.layers.getLayerById(pc.LAYERID_SKYBOX)){var g=
- new pc.GraphNode,l=pc.createBox(b),a=new pc.MeshInstance(g,l,a);a.cull=!1;a._noDepthDrawGl1=!0;l=new pc.Model;l.graph=g;l.meshInstances=[a];this.skyboxModel=l;e.addMeshInstances(l.meshInstances);e.enabled=!0;this.skyLayer=e;this.fire("set:skybox",d)}}};f.prototype._resetSkyboxModel=function(){this.skyboxModel&&(this.skyLayer.removeMeshInstances(this.skyboxModel.meshInstances),this.skyLayer.enabled=!1);this.skyboxModel=null;this.updateSkybox=!0};f.prototype.setSkybox=function(b){var a;b||(b=[null,
- null,null,null,null,null,null]);var c=!1;this._skyboxCubeMap!==b[0]&&(c=!0);if(!c)for(a=0;6>a&&!c;a++)this._skyboxPrefiltered[a]!==b[a+1]&&(c=!0);if(c){for(a=0;6>a;a++)this._skyboxPrefiltered[a]=b[a+1];this.skybox=b[0]}};f.prototype.destroy=function(){this.skybox=null};f.prototype.addModel=function(b){if(!this.containsModel(b)){var a=this.layers.getLayerById(pc.LAYERID_WORLD);a&&(a.addMeshInstances(b.meshInstances),this._models.push(b))}};f.prototype.addShadowCaster=function(b){var a=this.layers.getLayerById(pc.LAYERID_WORLD);
- a&&a.addShadowCasters(b.meshInstances)};f.prototype.removeModel=function(b){var a=this._models.indexOf(b);if(-1!==a){var c=this.layers.getLayerById(pc.LAYERID_WORLD);c&&(c.removeMeshInstances(b.meshInstances),this._models.splice(a,1))}};f.prototype.removeShadowCasters=function(b){var a=this.layers.getLayerById(pc.LAYERID_WORLD);a&&a.removeShadowCasters(b.meshInstances)};f.prototype.containsModel=function(b){return 0<=this._models.indexOf(b)};f.prototype.getModels=function(b){return this._models};
- return{Scene:f}}());Object.assign(pc,function(){function f(a,b){if(b!==pc.SHADOW_PCF3||a.webgl2){if(b===pc.SHADOW_VSM32)return a.extTextureFloatLinear?pc.FILTER_LINEAR:pc.FILTER_NEAREST;if(b===pc.SHADOW_VSM16)return a.extTextureHalfFloatLinear?pc.FILTER_LINEAR:pc.FILTER_NEAREST}else return pc.FILTER_NEAREST;return pc.FILTER_LINEAR}function b(a,b,c,d){var e=d===pc.SHADOW_VSM32?pc.PIXELFORMAT_RGBA32F:d===pc.SHADOW_VSM16?pc.PIXELFORMAT_RGBA16F:d===pc.SHADOW_PCF5||d===pc.SHADOW_PCF3&&a.webgl2?pc.PIXELFORMAT_DEPTH:pc.PIXELFORMAT_R8_G8_B8_A8,
- g=f(a,d);b=new pc.Texture(a,{format:e,width:b,height:c,mipmaps:!1,minFilter:g,magFilter:g,addressU:pc.ADDRESS_CLAMP_TO_EDGE,addressV:pc.ADDRESS_CLAMP_TO_EDGE});b.name="shadowmap";return d===pc.SHADOW_PCF5||d===pc.SHADOW_PCF3&&a.webgl2?(b.compareOnRead=!0,b.compareFunc=pc.FUNC_LESS,new pc.RenderTarget({depthBuffer:b})):new pc.RenderTarget({colorBuffer:b,depth:!0})}function a(a,b){var c=new pc.Texture(a,{format:pc.PIXELFORMAT_R8_G8_B8_A8,width:b,height:b,cubemap:!0,mipmaps:!1,minFilter:pc.FILTER_NEAREST,
- magFilter:pc.FILTER_NEAREST,addressU:pc.ADDRESS_CLAMP_TO_EDGE,addressV:pc.ADDRESS_CLAMP_TO_EDGE});c.name="shadowcube";for(var d=[],e,g=0;6>g;g++)e=new pc.RenderTarget({colorBuffer:c,face:g,depth:!0}),d.push(e);return d}function c(a){25<a&&(a=25);var b=(a-1)/6,c,d,e,g;g=.5*(a-1);d=Array(a);for(c=e=0;c<a;++c){var l=c-g;d[c]=Math.exp(-(l*l)/(2*b*b));e+=d[c]}for(c=0;c<a;++c)d[c]/=e;return d}function d(a,c,d,e){e||(e=0);e=1E4*e+c;var g=n[d][e];g||(g=b(a,c,c,d?d:pc.SHADOW_PCF3),n[d][e]=g);return g}function e(c,
- e){var g;e._type===pc.LIGHTTYPE_POINT?(e._shadowType>pc.SHADOW_PCF3&&(e._shadowType=pc.SHADOW_PCF3),e._cacheShadowMap?(g=O[e._shadowResolution],g||(g=a(c,e._shadowResolution),O[e._shadowResolution]=g)):g=a(c,e._shadowResolution),e._shadowCamera.renderTarget=g[0],e._shadowCubeMap=g):(g=e._cacheShadowMap?d(c,e._shadowResolution,e._shadowType):b(c,e._shadowResolution,e._shadowResolution,e._shadowType),e._shadowCamera.renderTarget=g);e._isCachedShadowMap=e._cacheShadowMap}function g(a){a=this.device=
- a;this._instancingTime=this._morphTime=this._skinTime=this._sortTime=this._cullTime=this._forwardTime=this._depthMapTime=this._shadowMapTime=this._shadowMapUpdates=this._materialSwitches=this._camerasRendered=this._skinDrawCalls=this._forwardDrawCalls=this._shadowDrawCalls=0;this.library=a.getProgramLibrary();a=a.scope;this.projId=a.resolve("matrix_projection");this.viewId=a.resolve("matrix_view");this.viewId3=a.resolve("matrix_view3");this.viewInvId=a.resolve("matrix_viewInverse");this.viewProjId=
- a.resolve("matrix_viewProjection");this.viewPos=new Float32Array(3);this.viewPosId=a.resolve("view_position");this.nearClipId=a.resolve("camera_near");this.farClipId=a.resolve("camera_far");this.cameraParamsId=a.resolve("camera_params");this.shadowMapLightRadiusId=a.resolve("light_radius");this.fogColorId=a.resolve("fog_color");this.fogStartId=a.resolve("fog_start");this.fogEndId=a.resolve("fog_end");this.fogDensityId=a.resolve("fog_density");this.modelMatrixId=a.resolve("matrix_model");this.normalMatrixId=
- a.resolve("matrix_normal");this.poseMatrixId=a.resolve("matrix_pose[0]");this.boneTextureId=a.resolve("texture_poseMap");this.boneTextureSizeId=a.resolve("texture_poseMapSize");this.alphaTestId=a.resolve("alpha_ref");this.opacityMapId=a.resolve("texture_opacityMap");this.ambientId=a.resolve("light_globalAmbient");this.exposureId=a.resolve("exposure");this.skyboxIntensityId=a.resolve("skyboxIntensity");this.lightColorId=[];this.lightDir=[];this.lightDirId=[];this.lightShadowMapId=[];this.lightShadowMatrixId=
- [];this.lightShadowParamsId=[];this.lightShadowMatrixVsId=[];this.lightShadowParamsVsId=[];this.lightDirVs=[];this.lightDirVsId=[];this.lightRadiusId=[];this.lightPos=[];this.lightPosId=[];this.lightInAngleId=[];this.lightOutAngleId=[];this.lightPosVsId=[];this.lightCookieId=[];this.lightCookieIntId=[];this.lightCookieMatrixId=[];this.lightCookieOffsetId=[];this.depthMapId=a.resolve("uDepthMap");this.screenSizeId=a.resolve("uScreenSize");this._screenSize=new Float32Array(4);this.sourceId=a.resolve("source");
- this.pixelOffsetId=a.resolve("pixelOffset");this.weightId=a.resolve("weight[0]");var b=pc.shaderChunks;this.blurVsmShaderCode=[b.blurVSMPS,"#define GAUSS\n"+b.blurVSMPS];this.blurPackedVsmShaderCode=["#define PACKED\n"+this.blurVsmShaderCode[0],"#define PACKED\n"+this.blurVsmShaderCode[1]];this.blurVsmShader=[{},{}];this.blurPackedVsmShader=[{},{}];this.blurVsmWeights={};this.polygonOffsetId=a.resolve("polygonOffset");this.polygonOffset=new Float32Array(2);this.fogColor=new Float32Array(3);this.ambientColor=
- new Float32Array(3)}function l(a,b){a.data[0]=b.data[0];a.data[1]=b.data[1];a.data[2]=b.data[2];a.data[3]=b.data[4];a.data[4]=b.data[5];a.data[5]=b.data[6];a.data[6]=b.data[8];a.data[7]=b.data[9];a.data[8]=b.data[10]}for(var k=(new pc.Mat4).mul2((new pc.Mat4).setTranslate(.5,.5,.5),(new pc.Mat4).setScale(.5,.5,.5)),p={r:1,g:2,b:3,a:4},h=[(new pc.Quat).setFromEulerAngles(0,90,180),(new pc.Quat).setFromEulerAngles(0,-90,180),(new pc.Quat).setFromEulerAngles(90,0,0),(new pc.Quat).setFromEulerAngles(-90,
- 0,0),(new pc.Quat).setFromEulerAngles(0,180,180),(new pc.Quat).setFromEulerAngles(0,0,180)],n=[{},{},{},{},{}],q=new Float32Array(2),m={x:1,y:1,z:0,w:0},r=new pc.Mat4,t=new pc.Mat4,v=new pc.Mat4,y=new pc.Mat4,u=new pc.Mat4,w=new pc.Mat3,x=new pc.Mat4,D,z=new pc.Mat4,C=new pc.Mat4,A=new pc.Mat4,B=new pc.Mat4,J=new pc.Vec3,F=new pc.Vec3,H,E,G=new pc.Mat4,I=new pc.Mat4,Q=new pc.Mat4,V=new pc.Mat4,W=new pc.Vec3,U={center:null,radius:0},Z,T=new pc.BoundingBox,L=[0,0],R,P,K,da,O={},S,aa,N=[],ba=0;8>ba;ba++)N.push(new pc.Vec3);
- var M=[new pc.Vec3,new pc.Vec3,new pc.Vec3,new pc.Vec3,new pc.Vec3,new pc.Vec3,new pc.Vec3,new pc.Vec3];Object.assign(g.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[pc.SORTKEY_FORWARD]-a._key[pc.SORTKEY_FORWARD]},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}S=a._key[pc.SORTKEY_FORWARD];aa=b._key[pc.SORTKEY_FORWARD];return S===aa&&a.mesh&&b.mesh?b.mesh.id-a.mesh.id:aa-S},depthSortCompare:function(a,b){S=a._key[pc.SORTKEY_DEPTH];aa=b._key[pc.SORTKEY_DEPTH];return S===aa&&a.mesh&&b.mesh?b.mesh.id-a.mesh.id:aa-S},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);Z=b.aabb.center;b._aabb._radiusVer!==b._aabbVer&&(b._aabb._radius=
- b._aabb.halfExtents.length(),b._aabb._radiusVer=b._aabbVer);U.radius=b._aabb._radius;U.center=Z;return a.frustum.containsSphere(U)},getShadowCamera:function(a,b){var c=b._shadowCamera,d;if(null===c){c=b._shadowType;d=pc.CLEARFLAG_DEPTH;var g=c===pc.SHADOW_PCF5||c===pc.SHADOW_PCF3&&a.webgl2;b._type===pc.LIGHTTYPE_POINT&&(g=!1);g||(d|=pc.CLEARFLAG_COLOR);g=new pc.Camera;c>=pc.SHADOW_VSM8&&c<=pc.SHADOW_VSM32?(g.clearColor[0]=0,g.clearColor[1]=0,g.clearColor[2]=0,g.clearColor[3]=0):(g.clearColor[0]=1,
- g.clearColor[1]=1,g.clearColor[2]=1,g.clearColor[3]=1);g.clearDepth=1;g.clearFlags=d;g.clearStencil=null;g._node=new pc.GraphNode;c=b._shadowCamera=g;e(a,b)}else d=c.renderTarget,d.width===b._shadowResolution&&d.height===b._shadowResolution||e(a,b);return c},updateCameraFrustum:function(a){if(a.vrDisplay&&a.vrDisplay.presenting){D=a.vrDisplay.combinedProj;var b=a._node.getParent();b?u.copy(b.getWorldTransform()).mul(a.vrDisplay.combinedViewInv).invert():u.copy(a.vrDisplay.combinedView);y.copy(u).invert();
- this.viewInvId.setValue(y.data)}else{D=a.getProjectionMatrix();a.overrideCalculateProjection&&a.calculateProjection(D,pc.VIEW_CENTER);if(a.overrideCalculateTransform)a.calculateTransform(y,pc.VIEW_CENTER);else{var b=a._node.getPosition(),c=a._node.getRotation();y.setTRS(b,c,pc.Vec3.ONE);this.viewInvId.setValue(y.data)}u.copy(y).invert()}a.frustum.update(D,u)},setCamera:function(a,b,c,d){var e=a.vrDisplay;if(e&&e.presenting){H=e.leftProj;E=e.rightProj;D=e.combinedProj;a.overrideCalculateProjection&&
- (a.calculateProjection(H,pc.VIEW_LEFT),a.calculateProjection(E,pc.VIEW_RIGHT),a.calculateProjection(D,pc.VIEW_CENTER));if(a.overrideCalculateTransform)a.calculateTransform(z,pc.VIEW_LEFT),a.calculateTransform(C,pc.VIEW_RIGHT),a.calculateTransform(y,pc.VIEW_CENTER),A.copy(z).invert(),B.copy(C).invert(),u.copy(y).invert();else{var g=a._node.getParent();if(g){var k=g.getWorldTransform();z.mul2(k,e.leftViewInv);C.mul2(k,e.rightViewInv);A.copy(z).invert();B.copy(C).invert();u.copy(g.getWorldTransform()).mul(e.combinedViewInv).invert()}else z.copy(e.leftViewInv),
- C.copy(e.rightViewInv),A.copy(e.leftView),B.copy(e.rightView),u.copy(e.combinedView)}l(G,A);l(I,B);Q.mul2(H,A);V.mul2(E,B);J.x=z.data[12];J.y=z.data[13];J.z=z.data[14];F.x=C.data[12];F.y=C.data[13];F.z=C.data[14]}else D=a.getProjectionMatrix(),a.overrideCalculateProjection&&a.calculateProjection(D,pc.VIEW_CENTER),this.projId.setValue(D.data),a.overrideCalculateTransform?a.calculateTransform(y,pc.VIEW_CENTER):(e=a._node.getPosition(),g=a._node.getRotation(),y.setTRS(e,g,pc.Vec3.ONE)),this.viewInvId.setValue(y.data),
- u.copy(y).invert(),this.viewId.setValue(u.data),l(w,u),this.viewId3.setValue(w.data),x.mul2(D,u),this.viewProjId.setValue(x.data),e=a._node.getPosition(),this.viewPos[0]=e.x,this.viewPos[1]=e.y,this.viewPos[2]=e.z,this.viewPosId.setValue(this.viewPos);a.frustum.update(D,u);this.nearClipId.setValue(a._nearClip);this.farClipId.setValue(a._farClip);this.cameraParamsId.setValue(a._shaderParams);e=this.device;e.setRenderTarget(b);e.updateBegin();k=a.getRect();g=b?b.width:e.width;b=b?b.height:e.height;
- var f=Math.floor(k.x*g),h=Math.floor(k.y*b),p=Math.floor(k.width*g),k=Math.floor(k.height*b);e.setViewport(f,h,p,k);e.setScissor(f,h,p,k);c&&e.clear(a._clearOptions);k=a._scissorRect;f=Math.floor(k.x*g);h=Math.floor(k.y*b);p=Math.floor(k.width*g);k=Math.floor(k.height*b);e.setScissor(f,h,p,k);d&&e.setScissor(1,1,g-2,b-2)},dispatchGlobalLights:function(a){var b;this.mainLight=-1;this.ambientColor[0]=a.ambientLight.r;this.ambientColor[1]=a.ambientLight.g;this.ambientColor[2]=a.ambientLight.b;if(a.gammaCorrection)for(b=
- 0;3>b;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,l,k=0;this.mainLight=-1;var f=this.device.scope;for(e=0;e<d;e++)if(a[e]._mask&c){g=a[e];l=g._node.getWorldTransform();this.lightColorId[k]||this._resolveLight(f,k);this.lightColorId[k].setValue(b.gammaCorrection?g._linearFinalColor:
- g._finalColor);l.getY(g._direction).scale(-1);g._direction.normalize();this.lightDir[k][0]=g._direction.x;this.lightDir[k][1]=g._direction.y;this.lightDir[k][2]=g._direction.z;this.lightDirId[k].setValue(this.lightDir[k]);if(g.castShadows){var h=g._isPcf&&this.device.webgl2?g._shadowCamera.renderTarget.depthBuffer:g._shadowCamera.renderTarget.colorBuffer;g._isVsm?l=-2E-4:(l=g.shadowBias/g._shadowCamera._farClip*100,!this.device.webgl2&&this.device.extStandardDerivatives&&(l*=-100));var p=g._isVsm?
- g.vsmBias/(g._shadowCamera._farClip/7):g._normalOffsetBias;this.lightShadowMapId[k].setValue(h);this.lightShadowMatrixId[k].setValue(g._shadowMatrix.data);h=g._rendererParams;3!==h.length&&(h.length=3);h[0]=g._shadowResolution;h[1]=p;h[2]=l;this.lightShadowParamsId[k].setValue(h);0>this.mainLight&&(this.lightShadowMatrixVsId[k].setValue(g._shadowMatrix.data),this.lightShadowParamsVsId[k].setValue(h),g._direction.normalize(),this.lightDirVs[k][0]=g._direction.x,this.lightDirVs[k][1]=g._direction.y,
- this.lightDirVs[k][2]=g._direction.z,this.lightDirVsId[k].setValue(this.lightDirVs[k]),this.mainLight=e)}k++}return k},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=pc.PROJECTION_PERSPECTIVE,a.aspectRatio=1,a.fov=2*c._outerConeAngle,r.setTRS(b.getPosition(),b.getRotation(),pc.Vec3.ONE).invert(),
- t.mul2(a.getProjectionMatrix(),r),c._shadowMatrix.mul2(k,t)),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,l=a[pc.LIGHTTYPE_POINT];a=a[pc.LIGHTTYPE_SPOT];var k=l.length,f=a.length,h=d,p=this.device.scope;for(d=0;d<k;d++)g=l[d],g._mask&c&&!g.isStatic&&(this.dispatchPointLight(b,p,g,h),h++);l=0;if(e)for(g=e[l];g&&g._type===pc.LIGHTTYPE_POINT;)this.dispatchPointLight(b,p,g,h),h++,l++,g=e[l];for(d=0;d<f;d++)g=a[d],g._mask&c&&!g.isStatic&&(this.dispatchSpotLight(b,
- p,g,h),h++);if(e)for(g=e[l];g&&g._type===pc.LIGHTTYPE_SPOT;)this.dispatchSpotLight(b,p,g,h),h++,l++,g=e[l]},cull:function(a,b,c){var d=0,e,g,l,k=b.length,f=a.cullingMask||4294967295;if(!a.frustumCulling){for(e=0;e<k;e++)if(g=b[e],g.visible||g.command)g.mask&&0===(g.mask&f)||(c[d]=g,d++,g.visibleThisFrame=!0);return d}for(e=0;e<k;e++)g=b[e],g.command?(c[d]=g,d++,g.visibleThisFrame=!0):g.visible&&(l=!0,g.mask&&0===(g.mask&f)||(g.cull&&(l=this._isVisible(a,g)),l&&(c[d]=g,d++,g.visibleThisFrame=!0)));
- return d},cullLights:function(a,b){var c,d,e;for(c=0;c<b.length;c++)d=b[c],e=d._type,d.castShadows&&d._enabled&&d.shadowUpdateMode!==pc.SHADOWUPDATE_NONE&&e!==pc.LIGHTTYPE_DIRECTIONAL&&(d.getBoundingSphere(U),a.frustum.containsSphere(U)&&(d.visibleThisFrame=!0))},updateCpuSkinMatrices:function(a){var b=a.length;if(0!==b){var c,d;for(c=0;c<b;c++)if(d=a[c].skinInstance)d.updateMatrices(a[c].node),d._dirty=!0}},updateGpuSkinMatrices:function(a){var b,c,d=a.length;for(b=0;b<d;b++)a[b].visibleThisFrame&&
- (c=a[b].skinInstance)&&c._dirty&&(c.updateMatrixPalette(),c._dirty=!1)},updateMorphedBounds:function(a){var b,c,d=a.length;for(b=0;b<d;b++)(c=a[b].morphInstance)&&c._dirty&&c.updateBounds(a[b].mesh)},updateMorphing:function(a){var b,c,d=a.length;for(b=0;b<d;b++)a[b].visibleThisFrame&&(c=a[b].morphInstance)&&c._dirty&&(c.update(a[b].mesh),c._dirty=!1)},setBaseConstants:function(a,b){a.setCullMode(b.cull);b.opacityMap&&(this.opacityMapId.setValue(b.opacityMap),this.alphaTestId.setValue(b.alphaTest))},
- setSkinning:function(a,b,c){b.skinInstance&&(this._skinDrawCalls++,a.supportsBoneTextures?(R=b.skinInstance.boneTexture,this.boneTextureId.setValue(R),L[0]=R.width,L[1]=R.height,this.boneTextureSizeId.setValue(L)):this.poseMatrixId.setValue(b.skinInstance.matrixPalette))},drawInstance:function(a,b,c,d,e){if(P=b.instancingData){if(this._instancedDrawCalls++,this._removedByInstancing+=P.count,a.setVertexBuffer(P._buffer,1,P.offset),a.draw(c.primitive[d],P.count),P._buffer===pc._autoInstanceBuffer)return b.instancingData=
- null,P.count-1}else return K=b.node.worldTransform,this.modelMatrixId.setValue(K.data),e&&(da=b.node.normalMatrix,b.node._dirtyNormal&&(K.invertTo3x3(da),da.transpose(),b.node._dirtyNormal=!1),this.normalMatrixId.setValue(da.data)),a.draw(c.primitive[d]),0},drawInstance2:function(a,b,c,d){if(P=b.instancingData){if(this._instancedDrawCalls++,this._removedByInstancing+=P.count,a.setVertexBuffer(P._buffer,1,P.offset),a.draw(c.primitive[d],P.count),P._buffer===pc._autoInstanceBuffer)return b.instancingData=
- null,P.count-1}else return a.draw(c.primitive[d]),0},renderShadows:function(a,b){var e=this.device,g,l,f,n,v,u,w,y,E,x,J,H,G,F,C=1<<pc.SHADER_SHADOW,z,A;for(g=0;g<a.length;g++)if(f=a[g],v=f._type,f.castShadows&&f._enabled&&(f._shadowCamera||this.getShadowCamera(e,f),f.shadowUpdateMode!==pc.SHADOWUPDATE_NONE&&f.visibleThisFrame)){u=this.getShadowCamera(e,f);w=u._node;y=0;E=1;if(v===pc.LIGHTTYPE_DIRECTIONAL){if(0>f._visibleLength[b])continue;y=f._visibleCameraSettings[b];w.setPosition(y.x,y.y,y.z);
- u.orthoHeight=y.orthoHeight;u.farClip=y.farClip;y=b}else v===pc.LIGHTTYPE_SPOT?(F=w.getPosition(),this.viewPos[0]=F.x,this.viewPos[1]=F.y,this.viewPos[2]=F.z,this.viewPosId.setValue(this.viewPos),this.shadowMapLightRadiusId.setValue(f.attenuationEnd)):v===pc.LIGHTTYPE_POINT&&(F=w.getPosition(),this.viewPos[0]=F.x,this.viewPos[1]=F.y,this.viewPos[2]=F.z,this.viewPosId.setValue(this.viewPos),this.shadowMapLightRadiusId.setValue(f.attenuationEnd),E=6);v!==pc.LIGHTTYPE_POINT&&(r.setTRS(w.getPosition(),
- w.getRotation(),pc.Vec3.ONE).invert(),t.mul2(u.getProjectionMatrix(),r),f._shadowMatrix.mul2(k,t));e.webgl2?v===pc.LIGHTTYPE_POINT?e.setDepthBias(!1):(e.setDepthBias(!0),e.setDepthBiasValues(-1E3*f.shadowBias,-1E3*f.shadowBias)):e.extStandardDerivatives&&(v===pc.LIGHTTYPE_POINT?(this.polygonOffset[0]=0,this.polygonOffset[1]=0):(this.polygonOffset[0]=-1E3*f.shadowBias,this.polygonOffset[1]=-1E3*f.shadowBias),this.polygonOffsetId.setValue(this.polygonOffset));f.shadowUpdateMode===pc.SHADOWUPDATE_THISFRAME&&
- (f.shadowUpdateMode=pc.SHADOWUPDATE_NONE);this._shadowMapUpdates+=E;e.setBlending(!1);e.setDepthWrite(!0);e.setDepthTest(!0);f._isPcf&&e.webgl2&&v!==pc.LIGHTTYPE_POINT?e.setColorWrite(!1,!1,!1,!1):e.setColorWrite(!0,!0,!0,!0);for(y?E=y+1:y=0;y<E;){v===pc.LIGHTTYPE_POINT&&(w.setRotation(h[y]),u.renderTarget=f._shadowCubeMap[y]);this.setCamera(u,u.renderTarget,!0,v!==pc.LIGHTTYPE_POINT);F=f._visibleList[y];J=f._visibleLength[y];l=f._shadowType;x=l+5*v;for(l=0;l<J;l++){H=F[l];G=H.mesh;n=H.material;this.setBaseConstants(e,
- n);this.setSkinning(e,H,n);n.dirty&&(n.updateUniforms(),n.dirty=!1);if(n.chunks){A=n.parameters;for(z in A)n=A[z],n.passFlags&C&&(n.scopeId||(n.scopeId=e.scope.resolve(z)),n.scopeId.setValue(n.data));A=H.parameters;for(z in A)n=A[z],n.passFlags&C&&(n.scopeId||(n.scopeId=e.scope.resolve(z)),n.scopeId.setValue(n.data))}n=H._shader[pc.SHADER_SHADOW+x];if(!n){this.updateShader(H,H._shaderDefs,null,pc.SHADER_SHADOW+x);n=H._shader[pc.SHADER_SHADOW+x];A=H._key;var B=pc.SORTKEY_DEPTH,L=H.material,K=H.skinInstance?
- 10:0,D=0;L.opacityMap&&(L=L.opacityMapChannel)&&(D=p[L]);A[B]=K+D}e.setShader(n);n=H.renderStyle;e.setVertexBuffer(H.morphInstance&&H.morphInstance._vertexBuffer?H.morphInstance._vertexBuffer:G.vertexBuffer,0);e.setIndexBuffer(G.indexBuffer[n]);l+=this.drawInstance(e,H,G,n);this._shadowDrawCalls++}y++;v===pc.LIGHTTYPE_DIRECTIONAL&&(f._visibleLength[b]=-1)}f._isVsm&&(v=f._vsmBlurSize,1<v&&(u=u.renderTarget,w=d(e,f._shadowResolution,f._shadowType,1),E=f._shadowType===pc.SHADOW_VSM8,y=f.vsmBlurMode,
- F=(E?this.blurPackedVsmShader:this.blurVsmShader)[y][v],F||(this.blurVsmWeights[v]=c(v),F=pc.shaderChunks.fullscreenQuadVS,l="#define SAMPLES "+v+"\n",l=E?l+this.blurPackedVsmShaderCode[y]:l+this.blurVsmShaderCode[y],F=pc.shaderChunks.createShaderFromCode(this.device,F,l,"blurVsm"+y+""+v+""+E),E?this.blurPackedVsmShader[y][v]=F:this.blurVsmShader[y][v]=F),m.z=f._shadowResolution-2,m.w=m.z,this.sourceId.setValue(u.colorBuffer),q[0]=1/f._shadowResolution,q[1]=0,this.pixelOffsetId.setValue(q),y===pc.BLUR_GAUSSIAN&&
- this.weightId.setValue(this.blurVsmWeights[v]),pc.drawQuadWithShader(e,w,F,null,m),this.sourceId.setValue(w.colorBuffer),q[1]=q[0],q[0]=0,this.pixelOffsetId.setValue(q),pc.drawQuadWithShader(e,u,F,null,m)))}e.webgl2?e.setDepthBias(!1):e.extStandardDerivatives&&(this.polygonOffset[0]=0,this.polygonOffset[1]=0,this.polygonOffsetId.setValue(this.polygonOffset))},updateShader:function(a,b,c,d,e){a.material._scene=this.scene;a.material.updateShader(this.device,this.scene,b,c,d,e);a._shader[d]=a.material.shader},
- renderForward:function(a,b,c,d,e,g,l,k){var f=this.device,h=this.scene,p=a.vrDisplay,n=1<<e;k=k?k._lightHash:0;var m,q,t,r,v,u,y,w,x=null,L,K,D=.5*f.width;for(m=0;m<c;m++)if(q=b[m],!g||!q.mask||g&q.mask)if(q.command)q.command();else{t=q.mesh;r=q.material;v=q._shaderDefs;y=q.mask;this.setSkinning(f,q,r);r&&r===x&&v!==u&&(x=null);if(q.isStatic||L)x=null;if(r!==x){this._materialSwitches++;r.dirty&&(r.updateUniforms(),r.dirty=!1);q._shader[e]&&q._shaderDefs===v&&q._lightHash===k||(q.isStatic?this.updateShader(q,
- v,q._staticLightList,e,d):(u=e+"_"+v+"_"+k,q._shader[e]=r.variants[u],q._shader[e]||(this.updateShader(q,v,null,e,d),r.variants[u]=q._shader[e])),q._shaderDefs=v,q._lightHash=k);f.setShader(q._shader[e]);u=r.parameters;for(K in u)L=u[K],L.passFlags&n&&(L.scopeId||(L.scopeId=f.scope.resolve(K)),L.scopeId.setValue(L.data));x&&y===w||(w=this.dispatchDirectLights(d[pc.LIGHTTYPE_DIRECTIONAL],h,y),this.dispatchLocalLights(d,h,y,w,q._staticLightList));this.alphaTestId.setValue(r.alphaTest);f.setBlending(r.blend);
- r.blend&&(r.separateAlphaBlend?(f.setBlendFunctionSeparate(r.blendSrc,r.blendDst,r.blendSrcAlpha,r.blendDstAlpha),f.setBlendEquationSeparate(r.blendEquation,r.blendAlphaEquation)):(f.setBlendFunction(r.blendSrc,r.blendDst),f.setBlendEquation(r.blendEquation)));f.setColorWrite(r.redWrite,r.greenWrite,r.blueWrite,r.alphaWrite);a._cullFaces?a._flipFaces?f.setCullMode(0<r.cull?r.cull===pc.CULLFACE_FRONT?pc.CULLFACE_BACK:pc.CULLFACE_FRONT:0):f.setCullMode(r.cull):f.setCullMode(pc.CULLFACE_NONE);f.setDepthWrite(r.depthWrite);
- f.setDepthTest(r.depthTest);f.setAlphaToCoverage(r.alphaToCoverage);r.depthBias||r.slopeDepthBias?(f.setDepthBias(!0),f.setDepthBiasValues(r.depthBias,r.slopeDepthBias)):f.setDepthBias(!1)}w=q.stencilFront||r.stencilFront;x=q.stencilBack||r.stencilBack;w||x?(f.setStencilTest(!0),w===x?(f.setStencilFunc(w.func,w.ref,w.readMask),f.setStencilOperation(w.fail,w.zfail,w.zpass,w.writeMask)):(w?(f.setStencilFuncFront(w.func,w.ref,w.readMask),f.setStencilOperationFront(w.fail,w.zfail,w.zpass,w.writeMask)):
- (f.setStencilFuncFront(pc.FUNC_ALWAYS,0,255),f.setStencilOperationFront(pc.STENCILOP_KEEP,pc.STENCILOP_KEEP,pc.STENCILOP_KEEPP,255)),x?(f.setStencilFuncBack(x.func,x.ref,x.readMask),f.setStencilOperationBack(x.fail,x.zfail,x.zpass,x.writeMask)):(f.setStencilFuncBack(pc.FUNC_ALWAYS,0,255),f.setStencilOperationBack(pc.STENCILOP_KEEP,pc.STENCILOP_KEEP,pc.STENCILOP_KEEP,255)))):f.setStencilTest(!1);u=q.parameters;for(K in u)L=u[K],L.passFlags&n&&(L.scopeId||(L.scopeId=f.scope.resolve(K)),L.scopeId.setValue(L.data));
- f.setVertexBuffer(q.morphInstance&&q.morphInstance._vertexBuffer?q.morphInstance._vertexBuffer:t.vertexBuffer,0);w=q.renderStyle;f.setIndexBuffer(t.indexBuffer[w]);l&&l(q,m);p&&p.presenting?(f.setViewport(0,0,D,f.height),this.projId.setValue(H.data),this.viewInvId.setValue(z.data),this.viewId.setValue(A.data),this.viewId3.setValue(G.data),this.viewProjId.setValue(Q.data),this.viewPos[0]=J.x,this.viewPos[1]=J.y,this.viewPos[2]=J.z,this.viewPosId.setValue(this.viewPos),m+=this.drawInstance(f,q,t,w,
- !0),this._forwardDrawCalls++,f.setViewport(D,0,D,f.height),this.projId.setValue(E.data),this.viewInvId.setValue(C.data),this.viewId.setValue(B.data),this.viewId3.setValue(I.data),this.viewProjId.setValue(V.data),this.viewPos[0]=F.x,this.viewPos[1]=F.y,this.viewPos[2]=F.z,this.viewPosId.setValue(this.viewPos),m+=this.drawInstance2(f,q,t,w)):m+=this.drawInstance(f,q,t,w,!0);this._forwardDrawCalls++;if(m<c-1&&b[m+1].material===r)for(K in u)if(L=r.parameters[K])L.scopeId||(L.scopeId=f.scope.resolve(K)),
- L.scopeId.setValue(L.data);x=r;u=v;w=y;L=q.isStatic}f.updateEnd()},setupInstancing:function(a){pc._instanceVertexFormat||(pc._instanceVertexFormat=new pc.VertexFormat(a,[{semantic:pc.SEMANTIC_TEXCOORD2,components:4,type:pc.TYPE_FLOAT32},{semantic:pc.SEMANTIC_TEXCOORD3,components:4,type:pc.TYPE_FLOAT32},{semantic:pc.SEMANTIC_TEXCOORD4,components:4,type:pc.TYPE_FLOAT32},{semantic:pc.SEMANTIC_TEXCOORD5,components:4,type:pc.TYPE_FLOAT32}]));a.enableAutoInstancing&&!pc._autoInstanceBuffer&&(pc._autoInstanceBuffer=
- new pc.VertexBuffer(a,pc._instanceVertexFormat,a.autoInstancingMaxObjects,pc.BUFFER_DYNAMIC),pc._autoInstanceBufferData=new Float32Array(pc._autoInstanceBuffer.lock()))},revertStaticMeshes:function(a){var b,c=a.length,d,e=[],g;for(b=0;b<c;b++)d=a[b],d._staticSource?d._staticSource!==g&&(e.push(d._staticSource),g=d._staticSource):e.push(d);a.length=e.length;for(b=0;b<e.length;b++)a[b]=e[b]},prepareStaticMeshes:function(a,b){var c,d,e,g,l,k=this.device,f=a.length,h,p,n=[],m,q,r,t,v,u,w,y,x,E,J,H,F,
- G,C=new pc.Vec3,z=new pc.Vec3,A=new pc.BoundingBox,L=new pc.Mat4,B=[],K,D,I=[],P=[],R=[];for(c=0;c<f;c++)if(h=a[c],h.isStatic){m=h.aabb;R.length=0;for(K=pc.LIGHTTYPE_POINT;K<=pc.LIGHTTYPE_SPOT;K++)for(d=0;d<b.length;d++)p=b[d],p._type===K&&p._enabled&&p._mask&h.mask&&p.isStatic&&(I[d]||(I[d]=new pc.BoundingBox,p._node.getWorldTransform(),p.getBoundingSphere(U),I[d].center.copy(U.center),I[d].halfExtents.x=U.radius,I[d].halfExtents.y=U.radius,I[d].halfExtents.z=U.radius),I[d].intersects(m)&&R.push(d));
- if(0===R.length)n.push(h);else{m=h.mesh;K=m.vertexBuffer;p=m.indexBuffer[h.renderStyle];q=2===p.bytesPerIndex?new Uint16Array(p.lock()):new Uint32Array(p.lock());r=m.primitive[h.renderStyle].count/3;w=m.primitive[h.renderStyle].base;t=K.format.elements;v=K.format.size/4;m=new Float32Array(K.storage);for(e=0;e<t.length;e++)t[e].name===pc.SEMANTIC_POSITION&&(u=t[e].offset/4);B.length=r;for(e=0;e<r;e++)B[e]=0;t=!1;P.length=6*r;for(e=0;e<r;e++){J=E=x=Number.MAX_VALUE;H=-Number.MAX_VALUE;F=-Number.MAX_VALUE;
- G=-Number.MAX_VALUE;for(g=0;3>g;g++)d=q[3*e+g+w],d=d*v+u,l=m[d],y=m[d+1],d=m[d+2],l<x&&(x=l),y<E&&(E=y),d<J&&(J=d),l>H&&(H=l),y>F&&(F=y),d>G&&(G=d);d=6*e;P[d]=x;P[d+1]=E;P[d+2]=J;P[d+3]=H;P[d+4]=F;P[d+5]=G}for(l=0;l<R.length;l++)for(d=R[l],L.copy(h.node.worldTransform).invert(),A.setFromTransformedAabb(I[d],L),y=A.getMin(),x=A.getMax(),g=1<<l,e=0;e<r;e++)d=6*e,P[d]<=x.x&&P[d+3]>=y.x&&P[d+1]<=x.y&&P[d+4]>=y.y&&P[d+2]<=x.z&&P[d+5]>=y.z&&(B[e]|=g,t=!0);if(t){t={};for(e=0;e<r;e++)d=3*e+w,D=B[e],t[D]||
- (t[D]=[]),g=t[D],g.push(q[d]),g.push(q[d+1]),g.push(q[d+2]);for(D in t){g=t[D];q=new pc.IndexBuffer(k,p.format,g.length,p.usage);(2===q.bytesPerIndex?new Uint16Array(q.lock()):new Uint32Array(q.lock())).set(g);q.unlock();J=E=x=Number.MAX_VALUE;H=-Number.MAX_VALUE;F=-Number.MAX_VALUE;G=-Number.MAX_VALUE;for(e=0;e<g.length;e++)d=g[e],l=m[d*v+u],y=m[d*v+u+1],d=m[d*v+u+2],l<x&&(x=l),y<E&&(E=y),d<J&&(J=d),l>H&&(H=l),y>F&&(F=y),d>G&&(G=d);C.set(x,E,J);z.set(H,F,G);e=new pc.BoundingBox;e.setMinMax(C,z);
- r=new pc.Mesh;r.vertexBuffer=K;r.indexBuffer[0]=q;r.primitive[0].type=pc.PRIMITIVE_TRIANGLES;r.primitive[0].base=0;r.primitive[0].count=g.length;r.primitive[0].indexed=!0;r.aabb=e;q=new pc.MeshInstance(h.node,r,h.material);q.isStatic=h.isStatic;q.visible=h.visible;q.layer=h.layer;q.castShadow=h.castShadow;q._receiveShadow=h._receiveShadow;q.cull=h.cull;q.pick=h.pick;q.mask=h.mask;q.parameters=h.parameters;q._shaderDefs=h._shaderDefs;q._staticSource=h;q._staticLightList=h._staticLightList?h._staticLightList:
- [];for(e=0;e<R.length;e++)g=1<<e,D&g&&(r=b[R[e]],0>q._staticLightList.indexOf(r)&&q._staticLightList.push(r));q._staticLightList.sort(this.lightCompare);n.push(q)}}else n.push(h)}}else n.push(h);a.length=n.length;for(c=0;c<n.length;c++)a[c]=n[c]},updateShaders:function(a){var b,c=[];for(b=0;b<a.length;b++){var d=a[b];void 0!==d.material&&-1===c.indexOf(d.material)&&c.push(d.material)}for(b=0;b<c.length;b++)a=c[b],a.updateShader!==pc.Material.prototype.updateShader&&(a.clearVariants(),a.shader=null)},
- updateLitShaders:function(a){for(var b=0;b<a.length;b++){var c=a[b];void 0!==c.material&&(c=c.material,c.updateShader===pc.Material.prototype.updateShader||!1===c.useLighting||c.emitter&&!c.emitter.lighting||(c.clearVariants(),c.shader=null))}},beginFrame:function(a){var b=this.device,c=this.scene,d=a._meshInstances;a=a._lights;c.updateSkybox&&(c._updateSkybox(b),c.updateSkybox=!1);c.updateShaders?(this.updateShaders(d),c.updateShaders=!1,c.updateLitShaders=!1,c._shaderVersion++):c.updateLitShaders&&
- (this.updateLitShaders(d),c.updateLitShaders=!1,c._shaderVersion++);this.updateCpuSkinMatrices(d);this.updateMorphedBounds(d);c=d.length;for(b=0;b<c;b++)d[b].visibleThisFrame=!1;c=a.length;for(b=0;b<c;b++)a[b].visibleThisFrame=a[b]._type===pc.LIGHTTYPE_DIRECTIONAL},beginLayers:function(a){var b=this.scene,c=a.layerList.length,d,e,g,l=this.scene._shaderVersion;for(e=0;e<c;e++)a.layerList[e]._postRenderCounter=0;for(e=0;e<c;e++){d=a.layerList[e];d._shaderVersion=l;d._preRenderCalledForCameras=0;d._postRenderCalledForCameras=
- 0;g=a.subLayerList[e];d._postRenderCounter=g?d._postRenderCounter|2:d._postRenderCounter|1;d._postRenderCounterMax=d._postRenderCounter;for(g=0;g<d.cameras.length;g++)d.instances.visibleOpaque[g]||(d.instances.visibleOpaque[g]=new pc.VisibleInstanceList),d.instances.visibleTransparent[g]||(d.instances.visibleTransparent[g]=new pc.VisibleInstanceList),d.instances.visibleOpaque[g].done=!1,d.instances.visibleTransparent[g].done=!1;d.cameras.length<d.instances.visibleOpaque.length&&d.instances.visibleOpaque.splice(d.cameras.length,
- 1);d.cameras.length<d.instances.visibleTransparent.length&&d.instances.visibleTransparent.splice(d.cameras.length,1);d._needsStaticPrepare&&d._staticLightHash&&(d._staticPrepareDone&&(this.revertStaticMeshes(d.opaqueMeshInstances),this.revertStaticMeshes(d.transparentMeshInstances)),this.prepareStaticMeshes(d.opaqueMeshInstances,d._lights),this.prepareStaticMeshes(d.transparentMeshInstances,d._lights),a._dirty=!0,b.updateShaders=!0,d._needsStaticPrepare=!1,d._staticPrepareDone=!0)}},cullLocalShadowmap:function(a,
- b){var c,d,e,g,l,k,f,p,n,m,q;d=a._type;if(d!==pc.LIGHTTYPE_DIRECTIONAL)for(a.visibleThisFrame=!0,e=this.getShadowCamera(this.device,a),e.projection=pc.PROJECTION_PERSPECTIVE,e.nearClip=a.attenuationEnd/1E3,e.farClip=a.attenuationEnd,e.aspectRatio=1,d===pc.LIGHTTYPE_SPOT?(e.fov=2*a._outerConeAngle,l=1):(e.fov=90,l=6),g=e._node,c=a._node,g.setPosition(c.getPosition()),d===pc.LIGHTTYPE_SPOT&&(g.setRotation(c.getRotation()),g.rotateLocal(-90,0,0)),k=0;k<l;k++){d===pc.LIGHTTYPE_POINT&&(g.setRotation(h[k]),
- e.renderTarget=a._shadowCubeMap[k]);this.updateCameraFrustum(e);(n=a._visibleList[k])||(n=a._visibleList[k]=[]);c=m=a._visibleLength[k]=0;for(f=b.length;c<f;c++)p=b[c],q=!0,p.cull&&(q=this._isVisible(e,p)),q&&(n[m]=p,m++,p.visibleThisFrame=!0);a._visibleLength[k]=m;n.length!==m&&(n.length=m);n.sort(this.depthSortCompare)}},cullDirectionalShadowmap:function(a,b,c,d){var e,g,l,k,f,h,p,n,m,q,t,u;g=this.device;a.visibleThisFrame=!0;g=this.getShadowCamera(g,a);l=g._node;k=a._node;l.setPosition(k.getPosition());
- l.setRotation(k.getRotation());l.rotateLocal(-90,0,0);n=a.shadowDistance||c._farClip;m=c._nearClip;e=c._fov*Math.PI/180;f=c._aspect;h=c._projection;t=h===pc.PROJECTION_PERSPECTIVE?Math.tan(e/2)*m:c._orthoHeight;q=t*f;N[0].x=q;N[0].y=-t;N[0].z=-m;N[1].x=q;N[1].y=t;N[1].z=-m;N[2].x=-q;N[2].y=t;N[2].z=-m;N[3].x=-q;N[3].y=-t;N[3].z=-m;h===pc.PROJECTION_PERSPECTIVE&&(t=Math.tan(e/2)*n,q=t*f);N[4].x=q;N[4].y=-t;N[4].z=-n;N[5].x=q;N[5].y=t;N[5].z=-n;N[6].x=-q;N[6].y=t;N[6].z=-n;N[7].x=-q;N[7].y=-t;N[7].z=
- -n;f=W.sub2(N[0],N[6]).length();f=Math.max(f,W.sub2(N[4],N[6]).length());r.copy(l.getWorldTransform()).invert();v.copy(r).mul(c._node.worldTransform);for(e=0;8>e;e++)v.transformPoint(N[e],N[e]);n=m=c=1E6;q=t=h=-1E6;for(e=0;8>e;e++)p=N[e],p.x<n&&(n=p.x),p.x>q&&(q=p.x),p.y<m&&(m=p.y),p.y>t&&(t=p.y),p.z<c&&(c=p.z),p.z>h&&(h=p.z);e=f/a._shadowResolution;n=Math.floor((n-.5*(f-(q-n)))/e)*e;m=Math.floor((m-.5*(f-(t-m)))/e)*e;n=.5*(n+f+n);m=.5*(m+f+m);l.translateLocal(n,m,1E5);g.projection=pc.PROJECTION_ORTHOGRAPHIC;
- g.nearClip=0;g.farClip=2E5;g.aspectRatio=1;g.orthoHeight=.5*f;this.updateCameraFrustum(g);t=!0;(h=a._visibleList[d])||(h=a._visibleList[d]=[]);e=f=a._visibleLength[d]=0;for(q=b.length;e<q;e++)u=b[e],p=!0,u.cull&&(p=this._isVisible(g,u)),p&&(h[f]=u,f++,u.visibleThisFrame=!0,p=u.aabb,t?(T.copy(p),t=!1):T.add(p));a._visibleLength[d]=f;h.length!==f&&(h.length=f);h.sort(this.depthSortCompare);b=T.getMin();e=T.getMax();M[0].x=M[1].x=M[2].x=M[3].x=b.x;M[1].y=M[3].y=M[7].y=M[5].y=b.y;M[2].z=M[3].z=M[6].z=
- M[7].z=b.z;M[4].x=M[5].x=M[6].x=M[7].x=e.x;M[0].y=M[2].y=M[4].y=M[6].y=e.y;M[0].z=M[1].z=M[4].z=M[5].z=e.z;e=9999999999;b=-9999999999;for(h=0;8>h;++h)r.transformPoint(M[h],M[h]),f=M[h].z,f<e&&(e=f),f>b&&(b=f);h=b;e>c&&(c=e);l.setPosition(k.getPosition());l.translateLocal(n,m,h+.01);g.farClip=h-c;(k=a._visibleCameraSettings[d])||(k=a._visibleCameraSettings[d]={});a=l.getPosition();k.x=a.x;k.y=a.y;k.z=a.z;k.orthoHeight=g.orthoHeight;k.farClip=g.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,l=b?b.height:d.height;b=Math.floor(e.x*g);var k=Math.floor(e.y*l),g=Math.floor(e.width*g),e=Math.floor(e.height*l);d.setViewport(b,k,g,e);d.setScissor(b,k,g,e);d.clear(c?c:a._clearOptions)},setSceneConstants:function(){var a,b=this.device,c=this.scene;this.dispatchGlobalLights(c);if(c.fog!==pc.FOG_NONE){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);c.fog===pc.FOG_LINEAR?(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,l,k,f,h,p,n,m,q;this.beginLayers(a);a._update()&pc.COMPUPDATED_LIGHTS&&(this.scene.updateLitShaders=!0);this.beginFrame(a);this.setSceneConstants();var t=0,r,v;for(l=0;l<a.layerList.length;l++)if(k=a.layerList[l],k.enabled&&a.subLayerEnabled[l])for(f=a.subLayerList[l],r=k.instances,h=k.cameras,p=0;p<h.length;p++)if(c=h[p]){c.frameBegin(k.renderTarget);v=f?k.transparentMeshInstances:k.opaqueMeshInstances;q=m=!1;for(n=0;n<t;n++)if(e[n]===
- c&&(m=!0,g[n]===k)){q=!0;break}m||(this.updateCameraFrustum(c.camera),this._camerasRendered++);q||this.cullLights(c.camera,k._lights);m&&q||(e[t]=c,g[t]=k,t++);n=f?r.visibleTransparent[p]:r.visibleOpaque[p];if(!n.done){if(k.onPreCull)k.onPreCull(p);n.length=this.cull(c.camera,v,n.list);n.done=!0;if(k.onPostCull)k.onPostCull(p)}c.frameEnd()}for(l=0;l<a._lights.length;l++)c=a._lights[l],c.visibleThisFrame&&c._type!==pc.LIGHTTYPE_DIRECTIONAL&&c.castShadows&&c._enabled&&c.shadowUpdateMode!==pc.SHADOWUPDATE_NONE&&
- (k=a._lightShadowCasters[l],this.cullLocalShadowmap(c,k));f=-1;for(l=0;l<a._lights.length;l++)if(c=a._lights[l],c._type===pc.LIGHTTYPE_DIRECTIONAL&&(f++,c.castShadows&&c._enabled&&c.shadowUpdateMode!==pc.SHADOWUPDATE_NONE))for(k=a._lightShadowCasters[l],h=a._globalLightCameras[f],p=0;p<h.length;p++)this.cullDirectionalShadowmap(c,k,h[p].camera,a._globalLightCameraIds[f][p]);this.gpuUpdate(a._meshInstances);this.renderShadows(a._sortedLights[pc.LIGHTTYPE_SPOT]);this.renderShadows(a._sortedLights[pc.LIGHTTYPE_POINT]);
- for(l=t=0;l<a._renderList.length;l++)if(k=a.layerList[a._renderList[l]],k.enabled&&a.subLayerEnabled[a._renderList[l]]){r=k.instances;f=a.subLayerList[a._renderList[l]];h=a._renderListCamera[l];(c=k.cameras[h])&&c.frameBegin(k.renderTarget);if(!f&&k.onPreRenderOpaque)k.onPreRenderOpaque(h);else if(f&&k.onPreRenderTransparent)k.onPreRenderTransparent(h);if(!(k._preRenderCalledForCameras&1<<h)){if(k.onPreRender)k.onPreRender(h);k._preRenderCalledForCameras|=1<<h;k.overrideClear&&this.clearView(c,k.renderTarget,
- k._clearOptions)}if(c){p=k.renderTarget;g=!1;for(n=0;n<t;n++)if(d[n]===p&&e[n]===c){g=!0;break}g||(k.overrideClear||this.clearView(c,k.renderTarget),d[t]=p,e[t]=c,t++);this.renderShadows(k._sortedLights[pc.LIGHTTYPE_DIRECTIONAL],h);k._sortVisible(f,c.node,h);n=f?r.visibleTransparent[h]:r.visibleOpaque[h];this.scene._activeCamera=c.camera;this.setCamera(c.camera,k.renderTarget);this.renderForward(c.camera,n.list,n.length,k._sortedLights,k.shaderPass,k.cullingMask,k.onDrawCall,k);b.setColorWrite(!0,
- !0,!0,!0);b.setStencilTest(!1);b.setAlphaToCoverage(!1);b.setDepthBias(!1);c.frameEnd()}if(!f&&k.onPostRenderOpaque)k.onPostRenderOpaque(h);else if(f&&k.onPostRenderTransparent)k.onPostRenderTransparent(h);!k.onPostRender||k._postRenderCalledForCameras&1<<h||(k._postRenderCounter&=~(f?2:1),0===k._postRenderCounter&&(k.onPostRender(h),k._postRenderCalledForCameras|=1<<h,k._postRenderCounter=k._postRenderCounterMax))}}});return{ForwardRenderer:g,gaussWeights:c}}());Object.assign(pc,function(){var f=new pc.Mat4,b=new pc.Vec3,a=new pc.Quat,c=new pc.Quat,d=new pc.Vec3,e=new pc.Vec3,g=function(a){this.name="string"===typeof a?a:"Untitled";this.tags=new pc.Tags(this);this._labels={};this.localPosition=new pc.Vec3(0,0,0);this.localRotation=new pc.Quat(0,0,0,1);this.localScale=new pc.Vec3(1,1,1);this.localEulerAngles=new pc.Vec3(0,0,0);this.position=new pc.Vec3(0,0,0);this.rotation=new pc.Quat(0,0,0,1);this.eulerAngles=new pc.Vec3(0,0,0);this.localTransform=new pc.Mat4;
- this._dirtyLocal=!1;this._aabbVer=0;this.worldTransform=new pc.Mat4;this._dirtyWorld=!1;this.normalMatrix=new pc.Mat3;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};Object.defineProperty(g.prototype,"right",{get:function(){this._right||(this._right=new pc.Vec3);return this.getWorldTransform().getX(this._right).normalize()}});Object.defineProperty(g.prototype,"up",{get:function(){this._up||
- (this._up=new pc.Vec3);return this.getWorldTransform().getY(this._up).normalize()}});Object.defineProperty(g.prototype,"forward",{get:function(){this._forward||(this._forward=new pc.Vec3);return this.getWorldTransform().getZ(this._forward).normalize().scale(-1)}});Object.defineProperty(g.prototype,"enabled",{get:function(){return this._enabled&&this._enabledInHierarchy},set:function(a){this._enabled!==a&&(this._enabled=a,this._parent&&!this._parent.enabled||this._notifyHierarchyStateChanged(this,
- a))}});Object.defineProperty(g.prototype,"parent",{get:function(){return this._parent}});Object.defineProperty(g.prototype,"root",{get:function(){var a=this._parent;if(!a)return this;for(;a._parent;)a=a._parent;return a}});Object.defineProperty(g.prototype,"children",{get:function(){return this._children}});Object.defineProperty(g.prototype,"graphDepth",{get:function(){return this._graphDepth}});Object.assign(g.prototype,{_notifyHierarchyStateChanged:function(a,b){a._onHierarchyStateChanged(b);for(var c=
- a._children,d=0,e=c.length;d<e;d++)c[d]._enabled&&this._notifyHierarchyStateChanged(c[d],b)},_onHierarchyStateChanged:function(a){this._enabledInHierarchy=a},_cloneInternal:function(a){a.name=this.name;for(var b=this.tags._list,c=0;c<b.length;c++)a.tags.add(b[c]);a._labels=Object.assign({},this._labels);a.localPosition.copy(this.localPosition);a.localRotation.copy(this.localRotation);a.localScale.copy(this.localScale);a.localEulerAngles.copy(this.localEulerAngles);a.position.copy(this.position);a.rotation.copy(this.rotation);
- a.eulerAngles.copy(this.eulerAngles);a.localTransform.copy(this.localTransform);a._dirtyLocal=this._dirtyLocal;a.worldTransform.copy(this.worldTransform);a._dirtyWorld=this._dirtyWorld;a._dirtyNormal=this._dirtyNormal;a._aabbVer=this._aabbVer+1;a._enabled=this._enabled;a.scaleCompensation=this.scaleCompensation;a._enabledInHierarchy=!1},clone:function(){var a=new pc.GraphNode;this._cloneInternal(a);return a},find:function(a,b){var c=[],d=this._children.length,e,g;if(a instanceof Function)for(e=0;e<
- d;e++)a(this._children[e])&&c.push(this._children[e]),g=this._children[e].find(a),g.length&&(c=c.concat(g));else for(this[a]&&(e=this[a]instanceof Function?this[a]():this[a],e===b&&c.push(this)),e=0;e<d;++e)g=this._children[e].find(a,b),g.length&&(c=c.concat(g));return c},findOne:function(a,b){var c,d=this._children.length,e;if(a instanceof Function){if(e=a(this))return this;for(c=0;c<d;c++)if(e=this._children[c].findOne(a))return this._children[c]}else{if(this[a]&&(c=this[a]instanceof Function?this[a]():
- this[a],c===b))return this;for(c=0;c<d;c++)if(e=this._children[c].findOne(a,b),null!==e)return e}return null},findByTag:function(){var a=this.tags._processArguments(arguments);return this._findByTag(a)},_findByTag:function(a){var b=[],c,d=this._children.length,e;for(c=0;c<d;c++)this._children[c].tags._has(a)&&b.push(this._children[c]),e=this._children[c]._findByTag(a),e.length&&(b=b.concat(e));return b},findByName:function(a){if(this.name===a)return this;for(var b=0;b<this._children.length;b++){var c=
- this._children[b].findByName(a);if(null!==c)return c}return null},findByPath:function(a){a=a.split("/");for(var b=this,c=null,d=0,e=a.length;d<e&&b;d++){for(var g=a[d],c=null,b=b._children,l=0,f=b.length;l<f;l++)if(b[l].name==g){c=b[l];break}b=c}return c},getPath:function(){var a=this._parent;if(a){for(var b=this.name;a&&a._parent;)b=pc.string.format("{0}/{1}",a.name,b),a=a._parent;return b}return""},getRoot:function(){var a=this._parent;if(!a)return this;for(;a._parent;)a=a._parent;return a},getParent:function(){return this._parent},
- isDescendantOf:function(a){for(var b=this._parent;b;){if(b===a)return!0;b=b._parent}return!1},isAncestorOf:function(a){return a.isDescendantOf(this)},getChildren:function(){return this._children},getEulerAngles:function(){this.getWorldTransform().getEulerAngles(this.eulerAngles);return this.eulerAngles},getLocalEulerAngles:function(){this.localRotation.getEulerAngles(this.localEulerAngles);return this.localEulerAngles},getLocalPosition:function(){return this.localPosition},getLocalRotation:function(){return this.localRotation},
- getLocalScale:function(){return this.localScale},getLocalTransform:function(){this._dirtyLocal&&(this.localTransform.setTRS(this.localPosition,this.localRotation,this.localScale),this._dirtyLocal=!1);return this.localTransform},getName:function(){return this.name},getPosition:function(){this.getWorldTransform().getTranslation(this.position);return this.position},getRotation:function(){this.rotation.setFromMat4(this.getWorldTransform());return this.rotation},getWorldTransform:function(){if(!this._dirtyLocal&&
- !this._dirtyWorld)return this.worldTransform;this._parent&&this._parent.getWorldTransform();this._sync();return this.worldTransform},reparent:function(a,b){var c=this._parent;c&&c.removeChild(this);a&&(0<=b?a.insertChild(this,b):a.addChild(this))},setLocalEulerAngles:function(a,b,c){a instanceof pc.Vec3?this.localRotation.setFromEulerAngles(a.x,a.y,a.z):this.localRotation.setFromEulerAngles(a,b,c);this._dirtyLocal||this._dirtifyLocal()},setLocalPosition:function(a,b,c){a instanceof pc.Vec3?this.localPosition.copy(a):
- this.localPosition.set(a,b,c);this._dirtyLocal||this._dirtifyLocal()},setLocalRotation:function(a,b,c,d){a instanceof pc.Quat?this.localRotation.copy(a):this.localRotation.set(a,b,c,d);this._dirtyLocal||this._dirtifyLocal()},setLocalScale:function(a,b,c){a instanceof pc.Vec3?this.localScale.copy(a):this.localScale.set(a,b,c);this._dirtyLocal||this._dirtifyLocal()},setName:function(a){this.name=a},_dirtifyLocal:function(){this._dirtyLocal||(this._dirtyLocal=!0,this._dirtyWorld||this._dirtifyWorld())},
- _dirtifyWorld:function(){if(!this._dirtyWorld){this._dirtyWorld=!0;for(var a=0;a<this._children.length;a++)this._children[a]._dirtyWorld||this._children[a]._dirtifyWorld()}this._dirtyNormal=!0;this._aabbVer++},setPosition:function(){var a=new pc.Vec3,b=new pc.Mat4;return function(c,d,e){c instanceof pc.Vec3?a.copy(c):a.set(c,d,e);null===this._parent?this.localPosition.copy(a):(b.copy(this._parent.getWorldTransform()).invert(),b.transformPoint(a,this.localPosition));this._dirtyLocal||this._dirtifyLocal()}}(),
- setRotation:function(){var a=new pc.Quat,b=new pc.Quat;return function(c,d,e,g){c instanceof pc.Quat?a.copy(c):a.set(c,d,e,g);null===this._parent?this.localRotation.copy(a):(c=this._parent.getRotation(),b.copy(c).invert(),this.localRotation.copy(b).mul(a));this._dirtyLocal||this._dirtifyLocal()}}(),setEulerAngles:function(){var a=new pc.Quat;return function(b,c,d){b instanceof pc.Vec3?this.localRotation.setFromEulerAngles(b.x,b.y,b.z):this.localRotation.setFromEulerAngles(b,c,d);null!==this._parent&&
- (b=this._parent.getRotation(),a.copy(b).invert(),this.localRotation.mul2(a,this.localRotation));this._dirtyLocal||this._dirtifyLocal()}}(),addChild:function(a){if(null!==a._parent)throw Error("GraphNode is already parented");this._children.push(a);this._onInsertChild(a)},addChildAndSaveTransform:function(a){var b=a.getPosition(),c=a.getRotation(),d=a._parent;d&&d.removeChild(a);void 0===this.tmpMat4&&(this.tmpMat4=new pc.Mat4,this.tmpQuat=new pc.Quat);a.setPosition(this.tmpMat4.copy(this.worldTransform).invert().transformPoint(b));
- a.setRotation(this.tmpQuat.copy(this.getRotation()).invert().mul(c));this._children.push(a);this._onInsertChild(a)},insertChild:function(a,b){if(null!==a._parent)throw Error("GraphNode is already parented");this._children.splice(b,0,a);this._onInsertChild(a)},_onInsertChild:function(a){a._parent=this;var b=a._enabled&&this.enabled;a._enabledInHierarchy!==b&&(a._enabledInHierarchy=b,a._notifyHierarchyStateChanged(a,b));a._updateGraphDepth();a._dirtifyWorld();a.fire&&a.fire("insert",this);this.fire&&
- this.fire("childinsert",a)},_updateGraphDepth:function(){this._graphDepth=this._parent?this._parent._graphDepth+1:0;for(var a=0,b=this._children.length;a<b;a++)this._children[a]._updateGraphDepth()},removeChild:function(a){var b,c=this._children.length;for(b=0;b<c;++b)if(this._children[b]===a){this._children.splice(b,1);a._parent=null;this.fire&&this.fire("childremove",a);break}},addLabel:function(a){this._labels[a]=!0},getLabels:function(){return Object.keys(this._labels)},hasLabel:function(a){return!!this._labels[a]},
- removeLabel:function(a){delete this._labels[a]},findByLabel:function(a,b){var c,d=this._children.length;b=b||[];this.hasLabel(a)&&b.push(this);for(c=0;c<d;++c)b=this._children[c].findByLabel(a,b);return b},_sync:function(){this._dirtyLocal&&(this.localTransform.setTRS(this.localPosition,this.localRotation,this.localScale),this._dirtyLocal=!1);if(this._dirtyWorld){if(null===this._parent)this.worldTransform.copy(this.localTransform);else if(this.scaleCompensation){var g,k=this._parent,p=this.localScale,
- h=k;if(h){for(;h&&h.scaleCompensation;)h=h._parent;h&&(h=h._parent)&&(g=h.worldTransform.getScale(),d.mul2(g,this.localScale),p=d)}c.setFromMat4(k.worldTransform);a.mul2(c,this.localRotation);h=k.worldTransform;k.scaleCompensation&&(e.mul2(g,k.getLocalScale()),f.setTRS(k.worldTransform.getTranslation(b),c,e),h=f);h.transformPoint(this.localPosition,b);this.worldTransform.setTRS(b,a,p)}else this.worldTransform.mul2(this._parent.worldTransform,this.localTransform);this._dirtyWorld=!1}},syncHierarchy:function(){if(this._enabled){(this._dirtyLocal||
- this._dirtyWorld)&&this._sync();for(var a=this._children,b=0,c=a.length;b<c;b++)a[b].syncHierarchy()}},lookAt:function(){var a=new pc.Mat4,b=new pc.Vec3,c=new pc.Vec3,d=new pc.Quat;return function(e,g,l,f,k,h){if(e instanceof pc.Vec3)b.copy(e),g instanceof pc.Vec3?c.copy(g):c.copy(pc.Vec3.UP);else{if(void 0===l)return;b.set(e,g,l);void 0!==f?c.set(f,k,h):c.copy(pc.Vec3.UP)}a.setLookAt(this.getPosition(),b,c);d.setFromMat4(a);this.setRotation(d)}}(),translate:function(){var a=new pc.Vec3;return function(b,
- c,d){b instanceof pc.Vec3?a.copy(b):a.set(b,c,d);a.add(this.getPosition());this.setPosition(a)}}(),translateLocal:function(){var a=new pc.Vec3;return function(b,c,d){b instanceof pc.Vec3?a.copy(b):a.set(b,c,d);this.localRotation.transformVector(a,a);this.localPosition.add(a);this._dirtyLocal||this._dirtifyLocal()}}(),rotate:function(){var a=new pc.Quat,b=new pc.Quat;return function(c,d,e){c instanceof pc.Vec3?a.setFromEulerAngles(c.x,c.y,c.z):a.setFromEulerAngles(c,d,e);null===this._parent?this.localRotation.mul2(a,
- this.localRotation):(c=this.getRotation(),d=this._parent.getRotation(),b.copy(d).invert(),a.mul2(b,a),this.localRotation.mul2(a,c));this._dirtyLocal||this._dirtifyLocal()}}(),rotateLocal:function(){var a=new pc.Quat;return function(b,c,d){b instanceof pc.Vec3?a.setFromEulerAngles(b.x,b.y,b.z):a.setFromEulerAngles(b,c,d);this.localRotation.mul(a);this._dirtyLocal||this._dirtifyLocal()}}()});return{GraphNode:g}}());Object.assign(pc,function(){var f=new pc.Vec3,b=new pc.Vec3,a=new pc.Vec3,c=new pc.Mat4,d=function(){this._projection=pc.PROJECTION_PERSPECTIVE;this._nearClip=.1;this._farClip=1E4;this._shaderParams=new Float32Array(4);this._fov=45;this._orthoHeight=10;this._aspect=16/9;this._aspectRatioMode=pc.ASPECT_AUTO;this.frustumCulling=this._horizontalFov=!1;this.cullingMask=4294967295;this._renderDepthRequests=0;this._projMatDirty=!0;this._projMat=new pc.Mat4;this._viewMat=new pc.Mat4;this._viewProjMat=new pc.Mat4;
- 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 pc.Frustum(this._projMat,this._viewMat);this._depthTarget=this.renderTarget=null;this._clearOptions={color:[.5,.5,.5,1],depth:1,stencil:0,flags:pc.CLEARFLAG_COLOR|pc.CLEARFLAG_DEPTH|pc.CLEARFLAG_STENCIL};this.calculateTransform=this._node=null;this.overrideCalculateTransform=!1;this.calculateProjection=null;this.overrideCalculateProjection=!1;this._cullFaces=!0;this._flipFaces=!1;
- this._component=null};Object.assign(d.prototype,{clone:function(){var a=new pc.Camera;a.projection=this._projection;a.nearClip=this._nearClip;a.farClip=this._farClip;a._shaderParams=this._shaderParams.slice();a.fov=this._fov;a.aspectRatio=this._aspect;a._aspectRatioMode=this._aspectRatioMode;a.renderTarget=this.renderTarget;a.setClearOptions(this.getClearOptions());a.frustumCulling=this.frustumCulling;a.cullingMask=this.cullingMask;return a},worldToScreen:function(a,b,c,d){void 0===d&&(d=new pc.Vec3);
- var e=this.getProjectionMatrix(),g=this._node.getWorldTransform();this._viewMat.copy(g).invert();this._viewProjMat.mul2(e,this._viewMat);this._viewProjMat.transformPoint(a,d);e=this._viewProjMat.data;a=a.x*e[3]+a.y*e[7]+a.z*e[11]+1*e[15];d.x=.5*(d.x/a+1)*b;d.y=.5*(1-d.y/a)*c;return d},screenToWorld:function(d,g,l,k,p,h){void 0===h&&(h=new pc.Vec3);var e=this.getProjectionMatrix(),q=this._node.getWorldTransform();this._viewMat.copy(q).invert();this._viewProjMat.mul2(e,this._viewMat);c.copy(this._viewProjMat).invert();
- this._projection===pc.PROJECTION_PERSPECTIVE?(b.set(d/k*2-1,(p-g)/p*2-1,1),c.transformPoint(b,a),a.scale(1/(b.x*c.data[3]+b.y*c.data[7]+b.z*c.data[11]+c.data[15])),d=l/this._farClip,h.lerp(this._node.getPosition(),a,d)):(f.set(d/k,(p-g)/p,l/(this._farClip-this._nearClip)),f.scale(2),f.sub(pc.Vec3.ONE),c.transformPoint(f,h));return h},getClearOptions:function(){return this._clearOptions},getProjectionMatrix:function(){if(this._projMatDirty){if(this._projection===pc.PROJECTION_PERSPECTIVE)this._projMat.setPerspective(this._fov,
- this._aspect,this._nearClip,this._farClip,this._horizontalFov);else{var a=this._orthoHeight,b=a*this._aspect;this._projMat.setOrtho(-b,b,-a,a,this._nearClip,this._farClip)}a=this._nearClip;b=this._farClip;this._shaderParams[0]=1/b;this._shaderParams[1]=b;this._shaderParams[2]=(1-b/a)/2;this._shaderParams[3]=(1+b/a)/2;this._projMatDirty=!1}return this._projMat},getRect:function(){return this._rect},setClearOptions:function(a){this._clearOptions.color[0]=a.color[0];this._clearOptions.color[1]=a.color[1];
- this._clearOptions.color[2]=a.color[2];this._clearOptions.color[3]=a.color[3];this._clearOptions.depth=a.depth;this._clearOptions.stencil=a.stencil;this._clearOptions.flags=a.flags},setRect:function(a,b,c,d){this._rect.x=a;this._rect.y=b;this._rect.width=c;this._rect.height=d},setScissorRect:function(a,b,c,d){this._scissorRect.x=a;this._scissorRect.y=b;this._scissorRect.width=c;this._scissorRect.height=d},requestDepthMap:function(){this._renderDepthRequests++},releaseDepthMap:function(){this._renderDepthRequests--}});
- Object.defineProperty(d.prototype,"aspectRatio",{get:function(){return this._aspect},set:function(a){this._aspect!==a&&(this._aspect=a,this._projMatDirty=!0)}});Object.defineProperty(d.prototype,"projection",{get:function(){return this._projection},set:function(a){this._projection!==a&&(this._projection=a,this._projMatDirty=!0)}});Object.defineProperty(d.prototype,"nearClip",{get:function(){return this._nearClip},set:function(a){this._nearClip!==a&&(this._nearClip=a,this._projMatDirty=!0)}});Object.defineProperty(d.prototype,
- "farClip",{get:function(){return this._farClip},set:function(a){this._farClip!==a&&(this._farClip=a,this._projMatDirty=!0)}});Object.defineProperty(d.prototype,"fov",{get:function(){return this._fov},set:function(a){this._fov!==a&&(this._fov=a,this._projMatDirty=!0)}});Object.defineProperty(d.prototype,"horizontalFov",{get:function(){return this._horizontalFov},set:function(a){this._horizontalFov!==a&&(this._horizontalFov=a,this._projMatDirty=!0)}});Object.defineProperty(d.prototype,"orthoHeight",
- {get:function(){return this._orthoHeight},set:function(a){this._orthoHeight!==a&&(this._orthoHeight=a,this._projMatDirty=!0)}});Object.defineProperty(d.prototype,"clearColor",{get:function(){return this._clearOptions.color},set:function(a){this._clearOptions.color[0]=a[0];this._clearOptions.color[1]=a[1];this._clearOptions.color[2]=a[2];this._clearOptions.color[3]=a[3]}});Object.defineProperty(d.prototype,"clearDepth",{get:function(){return this._clearOptions.depth},set:function(a){this._clearOptions.depth=
- a}});Object.defineProperty(d.prototype,"clearStencil",{get:function(){return this._clearOptions.stencil},set:function(a){this._clearOptions.stencil=a}});Object.defineProperty(d.prototype,"clearFlags",{get:function(){return this._clearOptions.flags},set:function(a){this._clearOptions.flags=a}});return{Camera:d}}());Object.assign(pc,function(){var f=new pc.Vec3,b=new pc.Vec3,a=new pc.Vec3,c={r:0,g:1,b:2,a:3},d=function(){this._type=pc.LIGHTTYPE_DIRECTIONAL;this._color=new pc.Color(.8,.8,.8);this._intensity=1;this._enabled=this._castShadows=!1;this._mask=1;this.isStatic=!1;this.key=0;this.bakeDir=!0;this.attenuationEnd=this.attenuationStart=10;this._falloffMode=0;this._shadowType=pc.SHADOW_PCF3;this._vsmBlurSize=11;this.vsmBlurMode=pc.BLUR_GAUSSIAN;this.vsmBias=.0025;this._cookie=null;this.cookieIntensity=1;this._cookieFalloff=
- !0;this._cookieChannel="rgb";this._cookieTransform=null;this._cookieTransformUniform=new Float32Array(4);this._cookieOffset=null;this._cookieOffsetUniform=new Float32Array(2);this._cookieOffsetSet=this._cookieTransformSet=!1;this._innerConeAngle=40;this._outerConeAngle=45;this._finalColor=new Float32Array([.8,.8,.8]);var a=Math.pow(this._finalColor[0],2.2);this._linearFinalColor=new Float32Array([a,a,a]);this._position=new pc.Vec3(0,0,0);this._direction=new pc.Vec3(0,0,0);this._innerConeAngleCos=
- Math.cos(this._innerConeAngle*Math.PI/180);this._outerConeAngleCos=Math.cos(this._outerConeAngle*Math.PI/180);this._shadowCamera=null;this._shadowMatrix=new pc.Mat4;this.shadowDistance=40;this._shadowResolution=1024;this.shadowBias=-5E-4;this._normalOffsetBias=0;this.shadowUpdateMode=pc.SHADOWUPDATE_REALTIME;this._node=this._scene=null;this._rendererParams=[];this._isVsm=!1;this._isPcf=!0;this._isCachedShadowMap=this._cacheShadowMap=!1;this._visibleLength=[0];this._visibleList=[[]];this._visibleCameraSettings=
- []};Object.assign(d.prototype,{destroy:function(){this._destroyShadowMap()},clone:function(){var a=new pc.Light;a.type=this._type;a.setColor(this._color);a.intensity=this._intensity;a.castShadows=this.castShadows;a.enabled=this._enabled;a.attenuationStart=this.attenuationStart;a.attenuationEnd=this.attenuationEnd;a.falloffMode=this._falloffMode;a.shadowType=this._shadowType;a.vsmBlurSize=this._vsmBlurSize;a.vsmBlurMode=this.vsmBlurMode;a.vsmBias=this.vsmBias;a.shadowUpdateMode=this.shadowUpdateMode;
- a.mask=this._mask;a.innerConeAngle=this._innerConeAngle;a.outerConeAngle=this._outerConeAngle;a.shadowBias=this.shadowBias;a.normalOffsetBias=this._normalOffsetBias;a.shadowResolution=this._shadowResolution;a.shadowDistance=this.shadowDistance;return a},getColor:function(){return this._color},getBoundingSphere:function(c){if(this._type===pc.LIGHTTYPE_SPOT){var d=this.attenuationEnd,e=this._outerConeAngle,k=Math.cos(e*pc.math.DEG_TO_RAD),p=this._node;f.copy(p.up);f.scale(.5*-d*k);f.add(p.getPosition());
- c.center=f;b.copy(p.up);b.scale(-d);a.copy(p.right);a.scale(Math.sin(e*pc.math.DEG_TO_RAD)*d);b.add(a);c.radius=.5*b.length()}else this._type===pc.LIGHTTYPE_POINT&&(c.center=this._node.getPosition(),c.radius=this.attenuationEnd)},getBoundingBox:function(a){if(this._type===pc.LIGHTTYPE_SPOT){var b=this.attenuationEnd,c=this._node,d=Math.abs(Math.sin(this._outerConeAngle*pc.math.DEG_TO_RAD)*b);a.center.set(0,.5*-b,0);a.halfExtents.set(d,.5*b,d);a.setFromTransformedAabb(a,c.getWorldTransform())}else this._type===
- pc.LIGHTTYPE_POINT&&(a.center.copy(this._node.getPosition()),a.halfExtents.set(this.attenuationEnd,this.attenuationEnd,this.attenuationEnd))},_updateFinalColor:function(){var a=this._color,b=a.r,c=a.g,a=a.b,d=this._intensity,f=this._finalColor,h=this._linearFinalColor;f[0]=b*d;f[1]=c*d;f[2]=a*d;1<=d?(h[0]=Math.pow(b,2.2)*d,h[1]=Math.pow(c,2.2)*d,h[2]=Math.pow(a,2.2)*d):(h[0]=Math.pow(f[0],2.2),h[1]=Math.pow(f[1],2.2),h[2]=Math.pow(f[2],2.2))},setColor:function(){var a,b,c;1===arguments.length?(a=
- arguments[0].r,b=arguments[0].g,c=arguments[0].b):3===arguments.length&&(a=arguments[0],b=arguments[1],c=arguments[2]);this._color.set(a,b,c);this._updateFinalColor()},_destroyShadowMap:function(){if(this._shadowCamera){if(!this._isCachedShadowMap){var a=this._shadowCamera.renderTarget,b;if(a)if(a.length)for(b=0;b<a.length;b++)a[b].colorBuffer&&a[b].colorBuffer.destroy(),a[b].destroy();else a.colorBuffer&&a.colorBuffer.destroy(),a.depthBuffer&&a.depthBuffer.destroy(),a.destroy()}this._shadowCubeMap=
- this._shadowCamera=this._shadowCamera.renderTarget=null;this.shadowUpdateMode===pc.SHADOWUPDATE_NONE&&(this.shadowUpdateMode=pc.SHADOWUPDATE_THISFRAME)}},updateShadow:function(){this.shadowUpdateMode!==pc.SHADOWUPDATE_REALTIME&&(this.shadowUpdateMode=pc.SHADOWUPDATE_THISFRAME)},updateKey:function(){var a=this._type<<29|(this._castShadows?1:0)<<28|this._shadowType<<25|this._falloffMode<<23|(0!==this._normalOffsetBias?1:0)<<22|(this._cookie?1:0)<<21|(this._cookieFalloff?1:0)<<20|c[this._cookieChannel.charAt(0)]<<
- 18|(this._cookieTransform?1:0)<<12;3===this._cookieChannel.length&&(a|=c[this._cookieChannel.charAt(1)]<<16,a|=c[this._cookieChannel.charAt(2)]<<14);a!==this.key&&null!==this._scene&&(this._scene.layers._dirtyLights=!0);this.key=a}});Object.defineProperty(d.prototype,"enabled",{get:function(){return this._type},set:function(a){this._type!==a&&(this._enabled=a)}});Object.defineProperty(d.prototype,"type",{get:function(){return this._type},set:function(a){this._type!==a&&(this._type=a,this._destroyShadowMap(),
- this.updateKey(),a=this._shadowType,this._shadowType=null,this.shadowType=a)}});Object.defineProperty(d.prototype,"mask",{get:function(){return this._mask},set:function(a){this._mask!==a&&(this._mask=a)}});Object.defineProperty(d.prototype,"shadowType",{get:function(){return this._shadowType},set:function(a){if(this._shadowType!==a){var b=pc.Application.getApplication().graphicsDevice;this._type===pc.LIGHTTYPE_POINT&&(a=pc.SHADOW_PCF3);a!==pc.SHADOW_PCF5||b.webgl2||(a=pc.SHADOW_PCF3);a!==pc.SHADOW_VSM32||
- b.textureFloatRenderable||(a=pc.SHADOW_VSM16);a!==pc.SHADOW_VSM16||b.textureHalfFloatRenderable||(a=pc.SHADOW_VSM8);this._isVsm=a>=pc.SHADOW_VSM8&&a<=pc.SHADOW_VSM32;this._isPcf=a===pc.SHADOW_PCF5||a===pc.SHADOW_PCF3;this._shadowType=a;this._destroyShadowMap();this.updateKey()}}});Object.defineProperty(d.prototype,"castShadows",{get:function(){return this._castShadows&&this._mask!==pc.MASK_LIGHTMAP&&0!==this._mask},set:function(a){this._castShadows!==a&&(this._castShadows=a,this.updateKey())}});Object.defineProperty(d.prototype,
- "shadowResolution",{get:function(){return this._shadowResolution},set:function(a){if(this._shadowResolution!==a){var b=pc.Application.getApplication().graphicsDevice;this._shadowResolution=a=this._type===pc.LIGHTTYPE_POINT?Math.min(a,b.maxCubeMapSize):Math.min(a,b.maxTextureSize)}}});Object.defineProperty(d.prototype,"vsmBlurSize",{get:function(){return this._vsmBlurSize},set:function(a){this._vsmBlurSize!==a&&(0===a%2&&a++,this._vsmBlurSize=a)}});Object.defineProperty(d.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(d.prototype,"falloffMode",{get:function(){return this._falloffMode},set:function(a){this._falloffMode!==a&&(this._falloffMode=a,this.updateKey())}});Object.defineProperty(d.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(d.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(d.prototype,"intensity",{get:function(){return this._intensity},set:function(a){this._intensity!==a&&(this._intensity=a,this._updateFinalColor())}});Object.defineProperty(d.prototype,"cookie",
- {get:function(){return this._cookie},set:function(a){this._cookie!==a&&(this._cookie=a,this.updateKey())}});Object.defineProperty(d.prototype,"cookieFalloff",{get:function(){return this._cookieFalloff},set:function(a){this._cookieFalloff!==a&&(this._cookieFalloff=a,this.updateKey())}});Object.defineProperty(d.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;d<c;d++)a+=b;this._cookieChannel=
- a;this.updateKey()}}});Object.defineProperty(d.prototype,"cookieTransform",{get:function(){return this._cookieTransform},set:function(a){this._cookieTransform!==a&&(this._cookieTransform=a,this._cookieTransformSet=!!a,a&&!this._cookieOffset&&(this.cookieOffset=new pc.Vec2,this._cookieOffsetSet=!1),this.updateKey())}});Object.defineProperty(d.prototype,"cookieOffset",{get:function(){return this._cookieOffset},set:function(a){this._cookieOffset!==a&&((this._cookieTransformSet||a)&&!a&&this._cookieOffset?
- this._cookieOffset.set(0,0):this._cookieOffset=a,this._cookieOffsetSet=!!a,a&&!this._cookieTransform&&(this.cookieTransform=new pc.Vec4(1,1,0,0),this._cookieTransformSet=!1),this.updateKey())}});return{Light:d}}());Object.assign(pc,function(){var f=0,b=function(){this.name="Untitled";this.id=f++;this._shader=null;this.variants={};this.parameters={};this.alphaTest=0;this.blend=this.alphaToCoverage=!1;this.blendSrc=pc.BLENDMODE_ONE;this.blendDst=pc.BLENDMODE_ZERO;this.blendEquation=pc.BLENDEQUATION_ADD;this.separateAlphaBlend=!1;this.blendSrcAlpha=pc.BLENDMODE_ONE;this.blendDstAlpha=pc.BLENDMODE_ZERO;this.blendAlphaEquation=pc.BLENDEQUATION_ADD;this.cull=pc.CULLFACE_BACK;this.depthWrite=this.depthTest=!0;this.stencilBack=
- this.stencilFront=null;this.slopeDepthBias=this.depthBias=0;this.alphaWrite=this.blueWrite=this.greenWrite=this.redWrite=!0;this.meshInstances=[];this._shaderVersion=0;this._scene=null;this._dirtyBlend=!1;this.dirty=!0};Object.defineProperty(b.prototype,"shader",{get:function(){return this._shader},set:function(a){this._shader&&this._shader._refCount--;(this._shader=a)&&a._refCount++}});Object.defineProperty(b.prototype,"blendType",{get:function(){if(!this.blend&&this.blendSrc===pc.BLENDMODE_ONE&&
- this.blendDst===pc.BLENDMODE_ZERO&&this.blendEquation===pc.BLENDEQUATION_ADD)return pc.BLEND_NONE;if(!this.blend||this.blendSrc!==pc.BLENDMODE_SRC_ALPHA||this.blendDst!==pc.BLENDMODE_ONE_MINUS_SRC_ALPHA||this.blendEquation!==pc.BLENDEQUATION_ADD){if(this.blend&&this.blendSrc===pc.BLENDMODE_ONE&&this.blendDst===pc.BLENDMODE_ONE&&this.blendEquation===pc.BLENDEQUATION_ADD)return pc.BLEND_ADDITIVE;if(this.blend&&this.blendSrc===pc.BLENDMODE_SRC_ALPHA&&this.blendDst===pc.BLENDMODE_ONE&&this.blendEquation===
- pc.BLENDEQUATION_ADD)return pc.BLEND_ADDITIVEALPHA;if(this.blend&&this.blendSrc===pc.BLENDMODE_DST_COLOR&&this.blendDst===pc.BLENDMODE_SRC_COLOR&&this.blendEquation===pc.BLENDEQUATION_ADD)return pc.BLEND_MULTIPLICATIVE2X;if(this.blend&&this.blendSrc===pc.BLENDMODE_ONE_MINUS_DST_COLOR&&this.blendDst===pc.BLENDMODE_ONE&&this.blendEquation===pc.BLENDEQUATION_ADD)return pc.BLEND_SCREEN;if(this.blend&&this.blendSrc===pc.BLENDMODE_ONE&&this.blendDst===pc.BLENDMODE_ONE&&this.blendEquation===pc.BLENDEQUATION_MIN)return pc.BLEND_MIN;
- if(this.blend&&this.blendSrc===pc.BLENDMODE_ONE&&this.blendDst===pc.BLENDMODE_ONE&&this.blendEquation===pc.BLENDEQUATION_MAX)return pc.BLEND_MAX;if(this.blend&&this.blendSrc===pc.BLENDMODE_DST_COLOR&&this.blendDst===pc.BLENDMODE_ZERO&&this.blendEquation===pc.BLENDEQUATION_ADD)return pc.BLEND_MULTIPLICATIVE;if(this.blend&&this.blendSrc===pc.BLENDMODE_ONE&&this.blendDst===pc.BLENDMODE_ONE_MINUS_SRC_ALPHA&&this.blendEquation===pc.BLENDEQUATION_ADD)return pc.BLEND_PREMULTIPLIED}return pc.BLEND_NORMAL},
- set:function(a){var b=this.blend!==pc.BLEND_NONE;switch(a){case pc.BLEND_NONE:this.blend=!1;this.blendSrc=pc.BLENDMODE_ONE;this.blendDst=pc.BLENDMODE_ZERO;this.blendEquation=pc.BLENDEQUATION_ADD;break;case pc.BLEND_NORMAL:this.blend=!0;this.blendSrc=pc.BLENDMODE_SRC_ALPHA;this.blendDst=pc.BLENDMODE_ONE_MINUS_SRC_ALPHA;this.blendEquation=pc.BLENDEQUATION_ADD;break;case pc.BLEND_PREMULTIPLIED:this.blend=!0;this.blendSrc=pc.BLENDMODE_ONE;this.blendDst=pc.BLENDMODE_ONE_MINUS_SRC_ALPHA;this.blendEquation=
- pc.BLENDEQUATION_ADD;break;case pc.BLEND_ADDITIVE:this.blend=!0;this.blendDst=this.blendSrc=pc.BLENDMODE_ONE;this.blendEquation=pc.BLENDEQUATION_ADD;break;case pc.BLEND_ADDITIVEALPHA:this.blend=!0;this.blendSrc=pc.BLENDMODE_SRC_ALPHA;this.blendDst=pc.BLENDMODE_ONE;this.blendEquation=pc.BLENDEQUATION_ADD;break;case pc.BLEND_MULTIPLICATIVE2X:this.blend=!0;this.blendSrc=pc.BLENDMODE_DST_COLOR;this.blendDst=pc.BLENDMODE_SRC_COLOR;this.blendEquation=pc.BLENDEQUATION_ADD;break;case pc.BLEND_SCREEN:this.blend=
- !0;this.blendSrc=pc.BLENDMODE_ONE_MINUS_DST_COLOR;this.blendDst=pc.BLENDMODE_ONE;this.blendEquation=pc.BLENDEQUATION_ADD;break;case pc.BLEND_MULTIPLICATIVE:this.blend=!0;this.blendSrc=pc.BLENDMODE_DST_COLOR;this.blendDst=pc.BLENDMODE_ZERO;this.blendEquation=pc.BLENDEQUATION_ADD;break;case pc.BLEND_MIN:this.blend=!0;this.blendDst=this.blendSrc=pc.BLENDMODE_ONE;this.blendEquation=pc.BLENDEQUATION_MIN;break;case pc.BLEND_MAX:this.blend=!0,this.blendDst=this.blendSrc=pc.BLENDMODE_ONE,this.blendEquation=
- pc.BLENDEQUATION_MAX}b!==(this.blend!==pc.BLEND_NONE)&&(this._scene?this._scene.layers._dirtyBlend=!0:this._dirtyBlend=!0);this._updateMeshInstanceKeys()}});b.prototype._cloneInternal=function(a){a.name=this.name;a.shader=this.shader;a.alphaTest=this.alphaTest;a.alphaToCoverage=this.alphaToCoverage;a.blend=this.blend;a.blendSrc=this.blendSrc;a.blendDst=this.blendDst;a.blendEquation=this.blendEquation;a.separateAlphaBlend=this.separateAlphaBlend;a.blendSrcAlpha=this.blendSrcAlpha;a.blendDstAlpha=this.blendDstAlpha;
- a.blendAlphaEquation=this.blendAlphaEquation;a.cull=this.cull;a.depthTest=this.depthTest;a.depthWrite=this.depthWrite;a.depthBias=this.depthBias;a.slopeDepthBias=this.slopeDepthBias;this.stencilFront&&(a.stencilFront=this.stencilFront.clone());this.stencilBack&&(a.stencilBack=this.stencilFront===this.stencilBack?a.stencilFront:this.stencilBack.clone());a.redWrite=this.redWrite;a.greenWrite=this.greenWrite;a.blueWrite=this.blueWrite;a.alphaWrite=this.alphaWrite};b.prototype.clone=function(){var a=
- new pc.Material;this._cloneInternal(a);return a};b.prototype._updateMeshInstanceKeys=function(){var a,b=this.meshInstances;for(a=0;a<b.length;a++)b[a].updateKey()};b.prototype.updateUniforms=function(){};b.prototype.updateShader=function(a,b,d){};b.prototype.update=function(){this.dirty=!0};b.prototype.clearParameters=function(){this.parameters={}};b.prototype.getParameters=function(){return this.parameters};b.prototype.clearVariants=function(){for(var a in this.variants)this.variants.hasOwnProperty(a)&&
- this.variants[a]._refCount--;this.variants={};for(var b,d=0;d<this.meshInstances.length;d++)for(a=this.meshInstances[d],b=0;b<a._shader.length;b++)a._shader[b]=null};b.prototype.getParameter=function(a){return this.parameters[a]};b.prototype.setParameter=function(a,b,d){void 0===d&&(d=-524285);if(void 0===b&&"object"===typeof a){b=a;if(b.length){for(a=0;a<b.length;a++)this.setParameter(b[a]);return}a=b.name;b=b.value}var c=this.parameters[a];c?(c.data=b,c.passFlags=d):this.parameters[a]={scopeId:null,
- data:b,passFlags:d}};b.prototype.deleteParameter=function(a){this.parameters[a]&&delete this.parameters[a]};b.prototype.setParameters=function(){for(var a in this.parameters){var b=this.parameters[a];b.scopeId.setValue(b.data)}};b.prototype.destroy=function(){this.shader&&(this.shader._refCount--,1>this.shader._refCount&&this.shader.destroy());var a,b;for(b in this.variants)this.variants.hasOwnProperty(b)&&(a=this.variants[b],a!==this.shader&&(a._refCount--,1>a._refCount&&a.destroy()));this.variants=
- {};this.shader=null;var d;for(b=0;b<this.meshInstances.length;b++){a=this.meshInstances[b];for(d=0;d<a._shader.length;d++)a._shader[d]=null;a._material=null;d=pc.getDefaultMaterial();this!==d&&(a.material=d)}};return{Material:b}}());Object.assign(pc,function(){var f=function(){pc.Material.call(this);this.color=new pc.Color(1,1,1,1);this.colorUniform=new Float32Array(4);this.colorMap=null;this.vertexColors=!1};f.prototype=Object.create(pc.Material.prototype);f.prototype.constructor=f;Object.assign(f.prototype,{clone:function(){var b=new pc.BasicMaterial;pc.Material.prototype._cloneInternal.call(this,b);b.color.copy(this.color);b.colorMap=this.colorMap;b.vertexColors=this.vertexColors;return b},updateUniforms:function(){this.clearParameters();
- this.colorUniform[0]=this.color.r;this.colorUniform[1]=this.color.g;this.colorUniform[2]=this.color.b;this.colorUniform[3]=this.color.a;this.setParameter("uColor",this.colorUniform);this.colorMap&&this.setParameter("texture_diffuseMap",this.colorMap)},updateShader:function(b,a,c,d,e,g){a={skin:!!this.meshInstances[0].skinInstance,vertexColors:this.vertexColors,diffuseMap:this.colorMap,pass:e};this.shader=b.getProgramLibrary().getProgram("basic",a)}});return{BasicMaterial:f}}());Object.assign(pc,function(){var f=function(){pc.Material.call(this)};f.prototype=Object.create(pc.Material.prototype);f.prototype.constructor=f;Object.assign(f.prototype,{clone:function(){var b=new pc.DepthMaterial;pc.Material.prototype._cloneInternal.call(this,b);return b},updateShader:function(b){var a={skin:!!this.meshInstances[0].skinInstance};this.shader=b.getProgramLibrary().getProgram("depth",a)}});return{DepthMaterial:f}}());Object.assign(pc,function(){var f=function(){pc.Material.call(this);this._assetReferences={};this._validator=null;this.shaderOptBuilder=new pc.StandardMaterialOptionsBuilder;this.reset()};f.prototype=Object.create(pc.Material.prototype);f.prototype.constructor=f;var b=[],a=[],c=[],d=[],e={},g=function(a,d,g,l,k){var h="_"+d+"Map",p=h+"Tiling",n=h+"Offset",m=h.substring(1)+"Transform",q=m+"Uniform",t=h+"Uv",r=h+"Channel",v="_"+d+"VertexColor",u="_"+d+"VertexColorChannel";a[h]=null;a[p]=new pc.Vec2(1,
- 1);a[n]=new pc.Vec2(0,0);a[m]=null;a[q]=null;a[t]=g;0<l&&(g=k?k:1<l?"rgb":"g",a[r]=g,a[u]=g);a[v]=!1;pc._matTex2D||(pc._matTex2D=[]);pc._matTex2D[d]=l;Object.defineProperty(f.prototype,h.substring(1),{get:function(){return this[h]},set:function(a){var b=this[h];!!b^!!a&&(this.dirtyShader=!0);b&&a&&(b.rgbm!==a.rgbm||b.fixCubemapSeams!==a.fixCubemapSeams||b.format!==a.format)&&(this.dirtyShader=!0);this[h]=a}});a=p.substring(1);d=n.substring(1);Object.defineProperty(f.prototype,a,{get:function(){return this[p]},
- set:function(a){this.dirtyShader=!0;this[p]=a}});e[a]=function(a,b,c){a=a._updateMapTransform(c?a[m]:null,b,a[n]);return{name:"texture_"+m,value:a.data}};Object.defineProperty(f.prototype,d,{get:function(){return this[n]},set:function(a){this.dirtyShader=!0;this[n]=a}});e[d]=function(a,b,c){a=a._updateMapTransform(c?a[m]:null,a[p],b);return{name:"texture_"+m,value:a.data}};Object.defineProperty(f.prototype,t.substring(1),{get:function(){return this[t]},set:function(a){this[t]!==a&&(this.dirtyShader=
- !0);this[t]=a}});Object.defineProperty(f.prototype,r.substring(1),{get:function(){return this[r]},set:function(a){this[r]!==a&&(this.dirtyShader=!0);this[r]=a}});Object.defineProperty(f.prototype,v.substring(1),{get:function(){return this[v]},set:function(a){this.dirtyShader=!0;this[v]=a}});Object.defineProperty(f.prototype,u.substring(1),{get:function(){return this[u]},set:function(a){this[u]!==a&&(this.dirtyShader=!0);this[u]=a}});b.push(h.substring(1));b.push(p.substring(1));b.push(n.substring(1));
- b.push(t.substring(1));b.push(r.substring(1));b.push(v.substring(1));b.push(u.substring(1));c.push(m)},l=[],k=function(a,c,g,k){var h="_"+c,p=c+"Uniform",n=c+"Intensity",m="_"+n;a[h]=g;a[p]=new Float32Array(3);Object.defineProperty(f.prototype,c,{get:function(){this.dirtyShader=this.dirtyColor=!0;return this[h]},set:function(a){var b=this[h];(0===b.r&&0===b.g&&0===b.b||1===b.r&&1===b.g&&1===b.b)^(0===a.r&&0===a.g&&0===a.b||1===a.r&&1===a.g&&1===a.b)&&(this.dirtyShader=!0);this.dirtyColor=!0;this[h]=
- a}});b.push(c);d.push(p);l.push(c);e[c]=function(a,b,d){d=d?a[p]:new Float32Array(3);var e=!1;a.useGammaTonemap&&(e=(a._scene||pc.Application.getApplication().scene).gammaCorrection);for(var g=0;3>g;g++)d[g]=e?Math.pow(b.data[g],2.2):b.data[g],k&&(d[g]*=a[m]);return{name:"material_"+c,value:d}};k&&(a[m]=1,Object.defineProperty(f.prototype,n,{get:function(){return this[m]},set:function(a){var b=this[m];(0===b||1===b)^(0===a||1===a)&&(this.dirtyShader=!0);this.dirtyColor=!0;this[m]=a}}),b.push(n),e[n]=
- function(a,b,d){b=d?a[p]:new Float32Array(3);d=!1;a.useGammaTonemap&&(d=(a._scene||pc.Application.getApplication().scene).gammaCorrection);for(var e=0;3>e;e++)b[e]=d?Math.pow(a[h].data[e],2.2):a[h].data[e],b[e]*=a[m];return{name:"material_"+c,value:b}})},p=function(a,c,d,g){var l="_"+c;a[l]=d;Object.defineProperty(f.prototype,c,{get:function(){return this[l]},set:function(a){var b=this[l];b!==a&&(this[l]=a,0===b||1===b||0===a||1===a)&&(this.dirtyShader=!0)}});b.push(c);e[c]=void 0!==g?g:function(a,
- b,d){return{name:"material_"+c,value:b}}},h=function(a,c,d){var g="_"+c;a[g]=null;Object.defineProperty(f.prototype,c,{get:function(){return this[g]},set:function(a){!!this[g]^!!a&&(this.dirtyShader=!0);this[g]=a}});b.push(c);e[c]=d},n=function(a,b,c){Object.defineProperty(f.prototype,c,{get:function(){return this[b]},set:function(a){this[b]=a}})},q=function(a){Object.defineProperty(f.prototype,"chunks",{get:function(){this.dirtyShader=!0;return this._chunks},set:function(a){this.dirtyShader=!0;this._chunks=
- a}});b.push("chunks")},m=function(a,c,d){var e="_"+c;a[e]=d;Object.defineProperty(f.prototype,c,{get:function(){return this[e]},set:function(a){this[e]!==a&&(this.dirtyShader=!0);this[e]=a}});b.push(c)},r=function(){};r.prototype.copy=function(a){for(var b in a)a.hasOwnProperty(b)&&"copy"!==b&&(this[b]=a[b])};Object.assign(f.prototype,{reset:function(){var e;for(e=0;e<b.length;e++){var g=a[e];this[b[e]]=g?g.clone?g.clone():g:g}for(e=0;e<c.length;e++)this[c[e]]=null;for(e=0;e<d.length;e++)this[d[e]]=
- new Float32Array(3);this._chunks=new r;this.cubeMapMinUniform=new Float32Array(3);this.cubeMapMaxUniform=new Float32Array(3)},clone:function(){var a=new pc.StandardMaterial;pc.Material.prototype._cloneInternal.call(this,a);for(var c,d=0;d<b.length;d++)c=b[d],void 0!==this[c]&&(this[c]&&this[c].copy?a[c]?a[c].copy(this[c]):a[c]=this[c].clone():a[c]=this[c]);return a},_updateMapTransform:function(a,b,c){a=a||new pc.Vec4;a.set(b.x,b.y,c.x,c.y);return 1===a.x&&1===a.y&&0===a.z&&0===a.w?null:a},_setParameter:function(a,
- b){this.parameters[a]||this._propsSet.push(a);this.setParameter(a,b)},_clearParameters:function(){for(var a=this._propsSet,b=0;b<a.length;b++)delete this.parameters[a[b]];this._propsSet=[]},_updateMap:function(a){a+="Map";if(this[a]){this._setParameter("texture_"+a,this[a]);var b=a+"Transform",c=a+"TransformUniform";this[b]||(this[c]=new Float32Array(4));this[b]=this._updateMapTransform(this[b],this[a+"Tiling"],this[a+"Offset"]);this[b]&&(this[c][0]=this[b].x,this[c][1]=this[b].y,this[c][2]=this[b].z,
- this[c][3]=this[b].w,this._setParameter("texture_"+b,this[c]))}},getUniform:function(a,b,c){return(a=e[a])?a(this,b,c):null},updateUniforms:function(){var a;this._clearParameters();this._setParameter("material_ambient",this.ambientUniform);this.diffuseMap&&!this.diffuseTint||this._setParameter("material_diffuse",this.diffuseUniform);this.useMetalness?(!this.metalnessMap||1>this.metalness)&&this._setParameter("material_metalness",this.metalness):this.specularMap&&!this.specularTint||this._setParameter("material_specular",
- this.specularUniform);a=this.getUniform("shininess",this.shininess,!0);this._setParameter(a.name,a.value);this.emissiveMap&&!this.emissiveTint||this._setParameter("material_emissive",this.emissiveUniform);this.emissiveMap&&this._setParameter("material_emissiveIntensity",this.emissiveIntensity);0<this.refraction&&(this._setParameter("material_refraction",this.refraction),this._setParameter("material_refractionIndex",this.refractionIndex));this._setParameter("material_opacity",this.opacity);this.occludeSpecular&&
- this._setParameter("material_occludeSpecularIntensity",this.occludeSpecularIntensity);this.cubeMapProjection===pc.CUBEPROJ_BOX&&this._setParameter(this.getUniform("cubeMapProjectionBox",this.cubeMapProjectionBox,!0));for(var b in pc._matTex2D)this._updateMap(b);this.ambientSH&&this._setParameter("ambientSH[0]",this.ambientSH);this.normalMap&&this._setParameter("material_bumpiness",this.bumpiness);this.heightMap&&(a=this.getUniform("heightMapFactor",this.heightMapFactor,!0),this._setParameter(a.name,
- a.value));this.cubeMap&&this._setParameter("texture_cubeMap",this.cubeMap);this.prefilteredCubeMap128?this._setParameter("texture_prefilteredCubeMap128",this.prefilteredCubeMap128):this._scene&&this._scene._skyboxPrefiltered[0]&&this._setParameter("texture_prefilteredCubeMap128",this._scene._skyboxPrefiltered[0]);this.prefilteredCubeMap64?this._setParameter("texture_prefilteredCubeMap64",this.prefilteredCubeMap64):this._scene&&this._scene._skyboxPrefiltered[1]&&this._setParameter("texture_prefilteredCubeMap64",
- this._scene._skyboxPrefiltered[1]);this.prefilteredCubeMap32?this._setParameter("texture_prefilteredCubeMap32",this.prefilteredCubeMap32):this._scene&&this._scene._skyboxPrefiltered[2]&&this._setParameter("texture_prefilteredCubeMap32",this._scene._skyboxPrefiltered[2]);this.prefilteredCubeMap16?this._setParameter("texture_prefilteredCubeMap16",this.prefilteredCubeMap16):this._scene&&this._scene._skyboxPrefiltered[3]&&this._setParameter("texture_prefilteredCubeMap16",this._scene._skyboxPrefiltered[3]);
- this.prefilteredCubeMap8?this._setParameter("texture_prefilteredCubeMap8",this.prefilteredCubeMap8):this._scene&&this._scene._skyboxPrefiltered[4]&&this._setParameter("texture_prefilteredCubeMap8",this._scene._skyboxPrefiltered[4]);this.prefilteredCubeMap4?this._setParameter("texture_prefilteredCubeMap4",this.prefilteredCubeMap4):this._scene&&this._scene._skyboxPrefiltered[5]&&this._setParameter("texture_prefilteredCubeMap4",this._scene._skyboxPrefiltered[5]);this.sphereMap&&this._setParameter("texture_sphereMap",
- this.sphereMap);this.dpAtlas&&this._setParameter("texture_sphereMap",this.dpAtlas);this._setParameter("material_reflectivity",this.reflectivity);if(this.dirtyShader||!this._scene)this.shader=null,this.clearVariants();this._processColor()},_processColor:function(){var a;if(this.dirtyColor&&(this._scene||!this.useGammaTonemap)){var b=!1;this.useGammaTonemap&&(b=this._scene.gammaCorrection);for(a=0;a<l.length;a++){var c=this["_"+l[a]],d=this[l[a]+"Uniform"];b?(d[0]=Math.pow(c.r,2.2),d[1]=Math.pow(c.g,
- 2.2),d[2]=Math.pow(c.b,2.2)):(d[0]=c.r,d[1]=c.g,d[2]=c.b)}for(a=0;3>a;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 l=a.useTexCubeLod,f=!a.extTextureLod,k,h,p,n,m,q;this.useSkybox&&(k=b._skyboxPrefiltered[0],h=b._skyboxPrefiltered[1],p=b._skyboxPrefiltered[2],n=b._skyboxPrefiltered[3],m=b._skyboxPrefiltered[4],q=b._skyboxPrefiltered[5]);k=this.prefilteredCubeMap128||
- k;h=this.prefilteredCubeMap64||h;p=this.prefilteredCubeMap32||p;n=this.prefilteredCubeMap16||n;m=this.prefilteredCubeMap8||m;q=this.prefilteredCubeMap4||q;if(k){var r=k&&h&&p&&n&&m&&q;f&&r?(k.dpAtlas||(k.dpAtlas=pc.generateDpAtlas(a,[k,h,p,n,m,q]),k.sh=pc.shFromCubemap(n)),this.dpAtlas=k.dpAtlas,this.ambientSH=k.sh,this._setParameter("ambientSH[0]",this.ambientSH),this._setParameter("texture_sphereMap",this.dpAtlas)):l?6>k._levels.length?r?this._setParameter("texture_prefilteredCubeMap128",k):console.log("Can't use prefiltered cubemap: "+
- r+", "+l+", "+k._levels):this._setParameter("texture_prefilteredCubeMap128",k):r?(this._setParameter("texture_prefilteredCubeMap128",k),this._setParameter("texture_prefilteredCubeMap64",h),this._setParameter("texture_prefilteredCubeMap32",p),this._setParameter("texture_prefilteredCubeMap16",n),this._setParameter("texture_prefilteredCubeMap8",m),this._setParameter("texture_prefilteredCubeMap4",q)):console.log("Can't use prefiltered cubemap: "+r+", "+l+", "+k._levels)}f=pc.programlib.standard;f=(l=
- e>pc.SHADER_FORWARDHDR&&e<=pc.SHADER_PICK)?f.optionsContextMin:f.optionsContext;l?this.shaderOptBuilder.updateMinRef(f,a,b,this,c,d,e,g,k):this.shaderOptBuilder.updateRef(f,a,b,this,c,d,e,g,k);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(c){c.dirtyShader=!0;c.dirtyColor=!0;c._scene=null;c._colorProcessed=!1;k(c,"ambient",new pc.Color(.7,.7,.7));k(c,
- "diffuse",new pc.Color(1,1,1));k(c,"specular",new pc.Color(0,0,0));k(c,"emissive",new pc.Color(0,0,0),!0);p(c,"shininess",25,function(a,b){return{name:"material_shininess",value:a.shadingModel===pc.SPECULAR_PHONG?Math.pow(2,.11*b):.01*b}});p(c,"heightMapFactor",1,function(a,b){return{name:"material_heightMapFactor",value:.025*b}});p(c,"opacity",1);p(c,"alphaTest",0);p(c,"bumpiness",1);p(c,"reflectivity",1);p(c,"occludeSpecularIntensity",1);p(c,"refraction",0);p(c,"refractionIndex",1/1.5);p(c,"metalness",
- 1);p(c,"aoUvSet",0,null);h(c,"ambientSH",function(a,b,c){return{name:"ambientSH[0]",value:b}});h(c,"cubeMapProjectionBox",function(a,b,c){var d=c?a.cubeMapMinUniform:new Float32Array(3);a=c?a.cubeMapMaxUniform:new Float32Array(3);d[0]=b.center.x-b.halfExtents.x;d[1]=b.center.y-b.halfExtents.y;d[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:d},{name:"envBoxMax",value:a}]});q(c);m(c,"ambientTint",
- !1);m(c,"diffuseTint",!1);m(c,"specularTint",!1);m(c,"emissiveTint",!1);m(c,"fastTbn",!1);m(c,"specularAntialias",!1);m(c,"useMetalness",!1);m(c,"occludeDirect",!1);m(c,"normalizeNormalMap",!0);m(c,"conserveEnergy",!0);m(c,"occludeSpecular",pc.SPECOCC_AO);m(c,"shadingModel",pc.SPECULAR_BLINN);m(c,"fresnelModel",pc.FRESNEL_NONE);m(c,"cubeMapProjection",pc.CUBEPROJ_NONE);m(c,"customFragmentShader",null);m(c,"forceFragmentPrecision",null);m(c,"useFog",!0);m(c,"useLighting",!0);m(c,"useGammaTonemap",
- !0);m(c,"useSkybox",!0);m(c,"forceUv1",!1);m(c,"pixelSnap",!1);m(c,"twoSidedLighting",!1);m(c,"nineSlicedMode",pc.SPRITE_RENDERMODE_SLICED);g(c,"diffuse",0,3);g(c,"specular",0,3);g(c,"emissive",0,3);g(c,"normal",0,-1);g(c,"metalness",0,1);g(c,"gloss",0,1);g(c,"opacity",0,1,"a");g(c,"height",0,1);g(c,"ao",0,1);g(c,"light",1,3);g(c,"msdf",0,3);h(c,"cubeMap");h(c,"sphereMap");h(c,"dpAtlas");h(c,"prefilteredCubeMap128");h(c,"prefilteredCubeMap64");h(c,"prefilteredCubeMap32");h(c,"prefilteredCubeMap16");
- h(c,"prefilteredCubeMap8");h(c,"prefilteredCubeMap4");n(c,"diffuseTint","diffuseMapTint");n(c,"specularTint","specularMapTint");n(c,"emissiveTint","emissiveMapTint");n(c,"aoVertexColor","aoMapVertexColor");n(c,"diffuseVertexColor","diffuseMapVertexColor");n(c,"specularVertexColor","specularMapVertexColor");n(c,"emissiveVertexColor","emissiveMapVertexColor");n(c,"metalnessVertexColor","metalnessMapVertexColor");n(c,"glossVertexColor","glossMapVertexColor");n(c,"opacityVertexColor","opacityMapVertexColor");
- n(c,"lightVertexColor","lightMapVertexColor");for(var d=0;d<b.length;d++)a[d]=c[b[d]];c._propsSet=[]})(f.prototype);return{StandardMaterial:f}}());(function(){pc.StandardMaterial.PARAMETER_TYPES={name:"string",chunks:"chunks",mappingFormat:"string",_engine:"boolean",ambient:"rgb",ambientTint:"boolean",aoVertexColor:"boolean",aoVertexColorChannel:"string",aoMap:"texture",aoMapChannel:"string",aoMapUv:"number",aoMapTiling:"vec2",aoMapOffset:"vec2",diffuse:"rgb",diffuseTint:"boolean",diffuseVertexColor:"boolean",diffuseVertexColorChannel:"string",diffuseMap:"texture",diffuseMapChannel:"string",diffuseMapUv:"number",diffuseMapTiling:"vec2",diffuseMapOffset:"vec2",
- specular:"rgb",specularTint:"boolean",specularVertexColor:"boolean",specularVertexColorChannel:"string",specularMap:"texture",specularMapChannel:"string",specularMapUv:"number",specularMapTiling:"vec2",specularMapOffset:"vec2",specularAntialias:"boolean",occludeSpecular:"enum:occludeSpecular",useMetalness:"boolean",metalness:"number",metalnessTint:"boolean",metalnessVertexColor:"boolean",metalnessVertexColorChannel:"string",metalnessMap:"texture",metalnessMapChannel:"string",metalnessMapUv:"number",
- metalnessMapTiling:"vec2",metalnessMapOffset:"vec2",conserveEnergy:"boolean",shininess:"number",glossVertexColor:"boolean",glossVertexColorChannel:"string",glossMap:"texture",glossMapChannel:"string",glossMapUv:"number",glossMapTiling:"vec2",glossMapOffset:"vec2",fresnelModel:"number",emissive:"rgb",emissiveTint:"boolean",emissiveVertexColor:"boolean",emissiveVertexColorChannel:"string",emissiveMap:"texture",emissiveMapChannel:"string",emissiveMapUv:"number",emissiveMapTiling:"vec2",emissiveMapOffset:"vec2",
- emissiveIntensity:"number",normalMap:"texture",normalMapTiling:"vec2",normalMapOffset:"vec2",normalMapUv:"number",bumpiness:"number",heightMap:"texture",heightMapChannel:"string",heightMapUv:"number",heightMapTiling:"vec2",heightMapOffset:"vec2",heightMapFactor:"number",alphaToCoverage:"boolean",alphaTest:"number",opacity:"number",opacityVertexColor:"boolean",opacityVertexColorChannel:"string",opacityMap:"texture",opacityMapChannel:"string",opacityMapUv:"number",opacityMapTiling:"vec2",opacityMapOffset:"vec2",
- reflectivity:"number",refraction:"number",refractionIndex:"number",sphereMap:"texture",cubeMap:"cubemap",cubeMapProjection:"number",cubeMapProjectionBox:"boundingbox",lightVertexColor:"boolean",lightVertexColorChannel:"string",lightMap:"texture",lightMapChannel:"string",lightMapUv:"number",lightMapTiling:"vec2",lightMapOffset:"vec2",depthTest:"boolean",depthWrite:"boolean",depthBias:"number",slopeDepthBias:"number",cull:"enum:cull",blendType:"enum:blendType",shadingModel:"enum:shadingModel",useFog:"boolean",
- useLighting:"boolean",useSkybox:"boolean",useGammaTonemap:"boolean",prefilteredCubeMap128:"texture",prefilteredCubeMap64:"texture",prefilteredCubeMap32:"texture",prefilteredCubeMap16:"texture",prefilteredCubeMap8:"texture",prefilteredCubeMap4:"texture"};var f,b;pc.StandardMaterial.TEXTURE_PARAMETERS=[];for(f in pc.StandardMaterial.PARAMETER_TYPES)b=pc.StandardMaterial.PARAMETER_TYPES[f],"texture"===b&&pc.StandardMaterial.TEXTURE_PARAMETERS.push(f);pc.StandardMaterial.CUBEMAP_PARAMETERS=[];for(f in pc.StandardMaterial.PARAMETER_TYPES)b=
- pc.StandardMaterial.PARAMETER_TYPES[f],"cubemap"===b&&pc.StandardMaterial.CUBEMAP_PARAMETERS.push(f)})();Object.assign(pc,function(){var f=function(){this.valid=this.removeInvalid=!0;this.enumValidators={occludeSpecular:this._createEnumValidator([pc.SPECOCC_NONE,pc.SPECOCC_AO,pc.SPECOCC_GLOSSDEPENDENT]),cull:this._createEnumValidator([pc.CULLFACE_NONE,pc.CULLFACE_BACK,pc.CULLFACE_FRONT,pc.CULLFACE_FRONTANDBACK]),blendType:this._createEnumValidator([pc.BLEND_SUBTRACTIVE,pc.BLEND_ADDITIVE,pc.BLEND_NORMAL,pc.BLEND_NONE,pc.BLEND_PREMULTIPLIED,pc.BLEND_MULTIPLICATIVE,pc.BLEND_ADDITIVEALPHA,pc.BLEND_MULTIPLICATIVE2X,
- pc.BLEND_SCREEN,pc.BLEND_MIN,pc.BLEND_MAX]),shadingModel:this._createEnumValidator([pc.SPECULAR_PHONG,pc.SPECULAR_BLINN])}};f.prototype.setInvalid=function(b,a){this.valid=!1;this.removeInvalid&&delete a[b]};f.prototype.validate=function(b){var a=pc.StandardMaterial.PARAMETER_TYPES,c,d="path"===b.mappingFormat,e;for(e in b)if(c=a[e])if(c.startsWith("enum"))c=c.split(":")[1],this.enumValidators[c]&&(this.enumValidators[c](b[e])||this.setInvalid(e,b));else if("number"===c)"number"!==typeof b[e]&&this.setInvalid(e,
- b);else if("boolean"===c)"boolean"!==typeof b[e]&&this.setInvalid(e,b);else if("string"===c)"string"!==typeof b[e]&&this.setInvalid(e,b);else if("vec2"===c)b[e]instanceof Array&&2===b[e].length||this.setInvalid(e,b);else if("rgb"===c)b[e]instanceof Array&&3===b[e].length||this.setInvalid(e,b);else if("texture"===c)d?"string"===typeof b[e]||b[null===e]||b[e]instanceof pc.Texture||this.setInvalid(e,b):"number"!==typeof b[e]&&null!==b[e]&&(b[e]instanceof pc.Texture||this.setInvalid(e,b));else if("boundingbox"===
- c)b[e].center&&b[e].center instanceof Array&&3===b[e].center.length||this.setInvalid(e,b),b[e].halfExtents&&b[e].halfExtents instanceof Array&&3===b[e].halfExtents.length||this.setInvalid(e,b);else if("cubemap"===c)"number"!==typeof b[e]&&null!==b[e]&&void 0!==b[e]&&(b[e]instanceof pc.Texture&&b[e].cubemap||this.setInvalid(e,b));else if("chunks"===c){var g=Object.keys(b[e]);for(c=0;c<g.length;c++)"string"!==typeof b[e][g[c]]&&this.setInvalid(g[c],b[e])}else console.error("Unknown material type: "+
- c);else this.valid=!1;b.validated=!0;return this.valid};f.prototype._createEnumValidator=function(b){return function(a){return 0<=b.indexOf(a)}};return{StandardMaterialValidator:f}}());Object.assign(pc,function(){var f=function(){this._mapXForms=null};f.prototype.updateMinRef=function(b,a,c,d,e,g,l,f,p){this._updateSharedOptions(b,d,e,l);this._updateMinOptions(b,d);this._updateUVOptions(b,d,e,!0)};f.prototype.updateRef=function(b,a,c,d,e,g,l,f,p){this._updateSharedOptions(b,d,e,l);b.useTexCubeLod=a.useTexCubeLod;this._updateEnvOptions(b,d,c,p);this._updateMaterialOptions(b,d);l===pc.SHADER_FORWARDHDR&&(b.gamma&&(b.gamma=pc.GAMMA_SRGBHDR),b.toneMap=pc.TONEMAP_LINEAR);b.hasTangents=
- e&&d.normalMap&&0!==(e&pc.SHADERDEF_TANGENTS);this._updateLightOptions(b,d,e,f,g);this._updateUVOptions(b,d,e,!1)};f.prototype._updateSharedOptions=function(b,a,c,d){b.pass=d;b.alphaTest=0<a.alphaTest;b.forceFragmentPrecision=a.forceFragmentPrecision||"";b.chunks=a.chunks||"";b.blendType=a.blendType;b.forceUv1=a.forceUv1;b.screenSpace=c&&0!==(c&pc.SHADERDEF_SCREENSPACE);b.skin=c&&0!==(c&pc.SHADERDEF_SKIN);b.useInstancing=c&&0!==(c&pc.SHADERDEF_INSTANCING)};f.prototype._updateUVOptions=function(b,
- a,c,d){var e=!1,g=!1,l=!1;c&&(e=0!==(c&pc.SHADERDEF_UV0),g=0!==(c&pc.SHADERDEF_UV1),l=0!==(c&pc.SHADERDEF_VCOLOR));b.vertexColors=!1;this._mapXForms=[];for(var f in pc._matTex2D)this._updateTexOptions(b,a,f,e,g,l,d);this._mapXForms=null};f.prototype._updateMinOptions=function(b,a){b.opacityTint=1!==a.opacity&&a.blendType!==pc.BLEND_NONE;b.lights=[]};f.prototype._updateMaterialOptions=function(b,a){var c=1===a.diffuse.r&&1===a.diffuse.g&&1===a.diffuse.b||!a.diffuseTint&&(a.diffuseMap||a.diffuseVertexColor)?
- 0:3,d=!1,e=(a.useMetalness?!0:!!a.specularMap)||!!a.sphereMap||!!a.cubeMap||!!a.dpAtlas;(e=e||(a.useMetalness?!0:!(0===a.specular.r&&0===a.specular.g&&0===a.specular.b)))&&(!a.specularTint&&(a.specularMap||a.specularVertexColor)||a.useMetalness||(d=1!==a.specular.r||1!==a.specular.g||1!==a.specular.b));var g=a.emissiveMap?0:3;g||(g=(g=(1!==a.emissive.r||1!==a.emissive.g||1!==a.emissive.b||1!==a.emissiveIntensity)&&a.emissiveTint)?3:1!==a.emissiveIntensity?1:0);b.opacityTint=1!==a.opacity&&a.blendType!==
- pc.BLEND_NONE?1:0;b.blendMapsWithColors=!0;b.ambientTint=a.ambientTint;b.diffuseTint=c;b.specularTint=d?3:0;b.metalnessTint=a.useMetalness&&1>a.metalness?1:0;b.glossTint=1;b.emissiveTint=g;b.alphaToCoverage=a.alphaToCoverage;b.needsNormalFloat=a.normalizeNormalMap;b.sphereMap=!!a.sphereMap;b.cubeMap=!!a.cubeMap;b.dpAtlas=!!a.dpAtlas;b.ambientSH=!!a.ambientSH;b.useSpecular=e;b.emissiveFormat=a.emissiveMap?a.emissiveMap.rgbm?1:a.emissiveMap.format===pc.PIXELFORMAT_RGBA32F?2:0:null;b.lightMapFormat=
- a.lightMap?a.lightMap.rgbm?1:a.lightMap.format===pc.PIXELFORMAT_RGBA32F?2:0:null;b.specularAntialias=a.specularAntialias;b.conserveEnergy=a.conserveEnergy;b.occludeSpecular=a.occludeSpecular;b.occludeSpecularFloat=1!==a.occludeSpecularIntensity;b.occludeDirect=a.occludeDirect;b.shadingModel=a.shadingModel;b.fresnelModel=a.fresnelModel;b.packedNormal=a.normalMap?a.normalMap.format===pc.PIXELFORMAT_DXT5:!1;b.fastTbn=a.fastTbn;b.cubeMapProjection=a.cubeMapProjection;b.customFragmentShader=a.customFragmentShader;
- b.refraction=!!a.refraction;b.useMetalness=a.useMetalness;b.msdf=!!a.msdfMap;b.twoSidedLighting=a.twoSidedLighting;b.pixelSnap=a.pixelSnap;b.nineSlicedMode=a.nineSlicedMode||0;b.aoMapUv=a.aoUvSet};f.prototype._updateEnvOptions=function(b,a,c,d){var e=(d?d.rgbm:!1)||(a.cubeMap?a.cubeMap.rgbm:!1)||(a.dpAtlas?a.dpAtlas.rgbm:!1),g=(d?d.rgbm||d.format===pc.PIXELFORMAT_RGBA32F:!1)||(a.cubeMap?a.cubeMap.rgbm||a.cubeMap.format===pc.PIXELFORMAT_RGBA32F:!1)||(a.dpAtlas?a.dpAtlas.rgbm||a.dpAtlas.format===pc.PIXELFORMAT_RGBA32F:
- !1),l=(!d||a.cubeMap||a.sphereMap||a.dpAtlas?!1:d.rgbm)||(a.cubeMap?a.cubeMap.rgbm:!1)||(a.sphereMap?a.sphereMap.rgbm:!1)||(a.dpAtlas?a.dpAtlas.rgbm:!1),f=(!d||a.cubeMap||a.sphereMap||a.dpAtlas?!1:d.rgbm||d.format===pc.PIXELFORMAT_RGBA32F)||(a.cubeMap?a.cubeMap.rgbm||a.cubeMap.format===pc.PIXELFORMAT_RGBA32F:!1)||(a.sphereMap?a.sphereMap.rgbm||a.sphereMap.format===pc.PIXELFORMAT_RGBA32F:!1)||(a.dpAtlas?a.dpAtlas.rgbm||a.dpAtlas.format===pc.PIXELFORMAT_RGBA32F:!1),p;a.useSkybox&&c._skyboxPrefiltered&&
- (p=c._skyboxPrefiltered[0]);b.fog=a.useFog?c.fog:"none";b.gamma=a.useGammaTonemap?c.gammaCorrection:pc.GAMMA_NONE;b.toneMap=a.useGammaTonemap?c.toneMapping:-1;b.rgbmAmbient=e;b.hdrAmbient=g;b.rgbmReflection=l;b.hdrReflection=f;b.useRgbm=l||e||(a.emissiveMap?a.emissiveMap.rgbm:!1)||(a.lightMap?a.lightMap.rgbm:!1);b.fixSeams=d?d.fixCubemapSeams:a.cubeMap?a.cubeMap.fixCubemapSeams:!1;b.prefilteredCubemap=!!d;b.skyboxIntensity=d&&p&&d===p&&1!==c.skyboxIntensity};f.prototype._updateLightOptions=function(b,
- a,c,d,e){b.lightMap=!1;b.lightMapChannel="";b.lightMapUv=0;b.lightMapTransform=0;b.lightMapWithoutAmbient=!1;b.dirLightMap=!1;c&&(b.noShadow=0!==(c&pc.SHADERDEF_NOSHADOW),0!==(c&pc.SHADERDEF_LM)&&(b.lightMapFormat=1,b.lightMap=!0,b.lightMapChannel="rgb",b.lightMapUv=1,b.lightMapTransform=0,b.lightMapWithoutAmbient=!a.lightMap,b.useRgbm=!0,0!==(c&pc.SHADERDEF_DIRLM)&&(b.dirLightMap=!0)));a.useLighting?(a=[],c=c?c>>16:1,d&&(this._collectLights(pc.LIGHTTYPE_DIRECTIONAL,d[pc.LIGHTTYPE_DIRECTIONAL],a,
- c),this._collectLights(pc.LIGHTTYPE_POINT,d[pc.LIGHTTYPE_POINT],a,c,e),this._collectLights(pc.LIGHTTYPE_SPOT,d[pc.LIGHTTYPE_SPOT],a,c,e)),b.lights=a):b.lights=[];0===b.lights.length&&(b.noShadow=!0)};f.prototype._updateTexOptions=function(b,a,c,d,e,g,l){var f=c+"Map",p=c+"VertexColor",h=c+"VertexColorChannel",n=f+"Channel",q=f+"Transform",m=f+"Uv";"light"!==c&&(b[f]=!1,b[n]="",b[q]=0,b[m]=0);b[p]=!1;b[h]="";var r="opacity"===c;if(r&&a.blendType===pc.BLEND_NONE&&0===a.alphaTest&&!a.alphaToCoverage)return b;
- if(!l||r)"height"!==c&&a[p]&&g&&(b[p]=a[p],b[h]=a[h],b.vertexColors=!0),a[f]&&(c=!0,0!==a[m]||d||(c=!1),1!==a[m]||e||(c=!1),c&&(b[f]=!!a[f],b[q]=this._getMapTransformID(a[q],a[m]),b[n]=a[n],b[m]=a[m]))};f.prototype._collectLights=function(b,a,c,d,e){var g,l;for(l=0;l<a.length;l++)g=a[l],g._enabled&&g._mask&d&&(b===pc.LIGHTTYPE_DIRECTIONAL||!g.isStatic)&&c.push(g);if(e)for(l=0;l<e.length;l++)g=e[l],g._type===b&&c.push(g)};f.prototype._getMapTransformID=function(b,a){if(!b)return 0;this._mapXForms[a]||
- (this._mapXForms[a]=[]);var c;for(c=0;c<this._mapXForms[a].length&&this._mapXForms[a][c][0]==b.x&&this._mapXForms[a][c][1]==b.y&&this._mapXForms[a][c][2]==b.z&&this._mapXForms[a][c][3]==b.w;)return c+1;c=this._mapXForms[a].length;this._mapXForms[a][c]=[];this._mapXForms[a][c][0]=b.x;this._mapXForms[a][c][1]=b.y;this._mapXForms[a][c][2]=b.z;this._mapXForms[a][c][3]=b.w;return c+1};return{StandardMaterialOptionsBuilder:f}}());Object.assign(pc,function(){function f(a,b,c,d){return(a&15)<<27|(b===pc.BLEND_NONE?1:0)<<26|(c?1:0)<<25|(d&33554431)<<0}var b=0,a=new pc.BoundingBox,c=function(){this._refCount=0;this.id=b++;this.vertexBuffer=null;this.indexBuffer=[null];this.primitive=[{type:0,base:0,count:0}];this.morph=this.skin=null;this._aabb=new pc.BoundingBox;this.boneAabb=null};Object.defineProperty(c.prototype,"aabb",{get:function(){return this.morph?this.morph.aabb:this._aabb},set:function(a){this.morph?(this._aabb=this.morph._baseAabb=
- a,this.morph._calculateAabb()):this._aabb=a}});var d=function(a,b,c){this._key=[0,0];this._shader=[null,null,null];this.isStatic=!1;this._staticSource=this._staticLightList=null;this.node=a;this._mesh=b;b._refCount++;this.material=c;this._shaderDefs=pc.MASK_DYNAMIC<<16;this._shaderDefs|=b.vertexBuffer.format.hasUv0?pc.SHADERDEF_UV0:0;this._shaderDefs|=b.vertexBuffer.format.hasUv1?pc.SHADERDEF_UV1:0;this._shaderDefs|=b.vertexBuffer.format.hasColor?pc.SHADERDEF_VCOLOR:0;this._shaderDefs|=b.vertexBuffer.format.hasTangents?
- pc.SHADERDEF_TANGENTS:0;this._lightHash=0;this.visible=!0;this.layer=pc.LAYER_WORLD;this.renderStyle=pc.RENDERSTYLE_SOLID;this.castShadow=!1;this._receiveShadow=!0;this._noDepthDrawGl1=this._screenSpace=!1;this._updateAabb=this.pick=this.cull=!0;this._updateAabbFunc=null;this.updateKey();this.instancingData=this.morphInstance=this._skinInstance=null;this.aabb=new pc.BoundingBox;this._boneAabb=null;this._aabbVer=-1;this.visibleThisFrame=this.drawOrder=0;this.isVisibleFunc=null;this.parameters={};this.stencilBack=
- this.stencilFront=null};Object.defineProperty(d.prototype,"mesh",{get:function(){return this._mesh},set:function(a){this._mesh&&this._mesh._refCount--;(this._mesh=a)&&a._refCount++}});Object.defineProperty(d.prototype,"aabb",{get:function(){var b;if(!this._updateAabb)return this._aabb;if(this._updateAabbFunc)return this._updateAabbFunc(this._aabb);if(this.skinInstance){var c=this.mesh.skin.boneNames.length,d,e;if(!this.mesh.boneAabb){this.mesh.boneAabb=[];this.mesh.boneUsed=[];var g=this.mesh.vertexBuffer.format.elements,
- f=this.mesh.vertexBuffer.numVertices;b=this.mesh.vertexBuffer.format.size;var m,r,t,v,y;for(e=0;e<g.length;e++)g[e].name===pc.SEMANTIC_POSITION?r=g[e].offset:g[e].name===pc.SEMANTIC_BLENDINDICES?t=g[e].offset:g[e].name===pc.SEMANTIC_BLENDWEIGHT&&(v=g[e].offset);var g=new Uint8Array(this.mesh.vertexBuffer.storage),u=new Float32Array(this.mesh.vertexBuffer.storage),w=r/4,x=v/4,D=b/4,z,C,A,B,J;v=[];r=[];d=this.mesh.boneUsed;for(e=0;e<c;e++)v[e]=new pc.Vec3(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),
- r[e]=new pc.Vec3(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE);for(y=0;y<f;y++)for(e=0;4>e;e++)0<u[y*D+x+e]&&(m=g[y*b+t+e],A=u[y*D+w],B=u[y*D+w+1],J=u[y*D+w+2],z=r[m],C=v[m],C.x>A&&(C.x=A),C.y>B&&(C.y=B),C.z>J&&(C.z=J),z.x<A&&(z.x=A),z.y<B&&(z.y=B),z.z<J&&(z.z=J),d[m]=!0);if(this.morphInstance){var F;d=this.morphInstance.morph._targets;var H=new Float32Array(3*f),E=new Float32Array(3*f),G;for(y=0;y<f;y++)H[3*y]=E[3*y]=u[y*D+w],H[3*y+1]=E[3*y+1]=u[y*D+w+1],H[3*y+2]=E[3*y+2]=u[y*D+w+2];for(f=
- 0;f<d.length;f++)for(e=d[f],w=e.indices,y=w.length,A=e.deltaPositions,e=0;e<y;e++)F=w[e],m=A[3*e],z=A[3*e+1],C=A[3*e+2],0>m?H[3*F]+=m:E[3*F]+=m,0>z?H[3*F+1]+=z:E[3*F+1]+=z,0>C?H[3*F+2]+=C:E[3*F+2]+=C;for(f=0;f<d.length;f++)for(e=d[f],w=e.indices,y=w.length,e=0;e<y;e++)for(F=w[e],G=0;4>G;G++)0<u[F*D+x+G]&&(m=g[F*b+t+G],z=r[m],C=v[m],A=H[3*F],B=H[3*F+1],J=H[3*F+2],C.x>A&&(C.x=A),C.y>B&&(C.y=B),C.z>J&&(C.z=J),A=E[3*F],B=E[3*F+1],J=E[3*F+2],z.x<A&&(z.x=A),z.y<B&&(z.y=B),z.z<J&&(z.z=J))}for(e=0;e<c;e++)b=
- new pc.BoundingBox,b.setMinMax(v[e],r[e]),this.mesh.boneAabb.push(b)}if(!this._boneAabb)for(this._boneAabb=[],e=0;e<this.mesh.boneAabb.length;e++)this._boneAabb[e]=new pc.BoundingBox;d=this.mesh.boneUsed;for(e=0;e<this.mesh.boneAabb.length;e++)d[e]&&this._boneAabb[e].setFromTransformedAabb(this.mesh.boneAabb[e],this.skinInstance.matrices[e]);c=this.node.getWorldTransform();b=!0;for(e=0;e<this.mesh.boneAabb.length;e++)d[e]&&(b?(a.center.copy(this._boneAabb[e].center),a.halfExtents.copy(this._boneAabb[e].halfExtents),
- b=!1):a.add(this._boneAabb[e]));this._aabb.setFromTransformedAabb(a,c)}else this.node._aabbVer!==this._aabbVer&&(b=this.mesh?this.mesh.aabb:this._aabb,this.mesh||(b.center.set(0,0,0),b.halfExtents.set(0,0,0)),this._aabb.setFromTransformedAabb(b,this.node.getWorldTransform()),this._aabbVer=this.node._aabbVer);return this._aabb},set:function(a){this._aabb=a}});Object.defineProperty(d.prototype,"material",{get:function(){return this._material},set:function(a){var b;for(b=0;b<this._shader.length;b++)this._shader[b]=
- null;if(this._material){var c=this._material.meshInstances;b=c.indexOf(this);-1!==b&&c.splice(b,1)}c=this._material?this._material.blendType!==pc.BLEND_NONE:!1;b=this._material;if(this._material=a)this._material.meshInstances.push(this),this.updateKey();a&&a.blendType!==pc.BLEND_NONE!==c&&(c=a._scene,!c&&b&&b._scene&&(c=b._scene),c?c.layers._dirtyBlend=!0:a._dirtyBlend=!0)}});Object.defineProperty(d.prototype,"layer",{get:function(){return this._layer},set:function(a){this._layer=a;this.updateKey()}});
- Object.defineProperty(d.prototype,"receiveShadow",{get:function(){return this._receiveShadow},set:function(a){this._shaderDefs=(this._receiveShadow=a)?this._shaderDefs&~pc.SHADERDEF_NOSHADOW:this._shaderDefs|pc.SHADERDEF_NOSHADOW;this._shader[pc.SHADER_FORWARD]=null;this._shader[pc.SHADER_FORWARDHDR]=null}});Object.defineProperty(d.prototype,"skinInstance",{get:function(){return this._skinInstance},set:function(a){this._shaderDefs=(this._skinInstance=a)?this._shaderDefs|pc.SHADERDEF_SKIN:this._shaderDefs&
- ~pc.SHADERDEF_SKIN;for(a=0;a<this._shader.length;a++)this._shader[a]=null}});Object.defineProperty(d.prototype,"screenSpace",{get:function(){return this._screenSpace},set:function(a){this._shaderDefs=(this._screenSpace=a)?this._shaderDefs|pc.SHADERDEF_SCREENSPACE:this._shaderDefs&~pc.SHADERDEF_SCREENSPACE;this._shader[pc.SHADER_FORWARD]=null}});Object.defineProperty(d.prototype,"key",{get:function(){return this._key[pc.SORTKEY_FORWARD]},set:function(a){this._key[pc.SORTKEY_FORWARD]=a}});Object.defineProperty(d.prototype,
- "mask",{get:function(){return this._shaderDefs>>16},set:function(a){this._shaderDefs=this._shaderDefs&65535|a<<16;this._shader[pc.SHADER_FORWARD]=null;this._shader[pc.SHADER_FORWARDHDR]=null}});Object.assign(d.prototype,{syncAabb:function(){},updateKey:function(){var a=this.material;this._key[pc.SORTKEY_FORWARD]=f(this.layer,a.alphaToCoverage||a.alphaTest?pc.BLEND_NORMAL:a.blendType,!1,a.id)},setParameter:pc.Material.prototype.setParameter,setParameters:pc.Material.prototype.setParameters,deleteParameter:pc.Material.prototype.deleteParameter,
- getParameter:pc.Material.prototype.getParameter,getParameters:pc.Material.prototype.getParameters,clearParameters:pc.Material.prototype.clearParameters});var e=function(a,b,c){this._key=[];this._key[pc.SORTKEY_FORWARD]=f(a,b,!0,0);this.command=c};Object.defineProperty(e.prototype,"key",{get:function(){return this._key[pc.SORTKEY_FORWARD]},set:function(a){this._key[pc.SORTKEY_FORWARD]=a}});var g=function(a,b,c){this.buffer=new Float32Array(a*(c||16));this.count=a;this.offset=0;this.usage=b?pc.BUFFER_DYNAMIC:
- pc.BUFFER_STATIC;this._buffer=null};Object.assign(g.prototype,{update:function(){this._buffer&&this._buffer.setData(this.buffer)}});return{Command:e,Mesh:c,MeshInstance:d,InstancingData:g,_getDrawcallSortKey:f}}());Object.assign(pc,function(){var f=new pc.Mat4,b=function(a){this.skin=a;this._dirty=!0;this.bones=[];var b=a.inverseBindPose.length;a=a.device;if(a.supportsBoneTextures){var d;d=256<b?64:64<b?32:16<b?16:8;this.boneTexture=new pc.Texture(a,{width:d,height:d,format:pc.PIXELFORMAT_RGBA32F,mipmaps:!1,minFilter:pc.FILTER_NEAREST,magFilter:pc.FILTER_NEAREST});this.boneTexture.name="skin";this.matrixPalette=this.boneTexture.lock()}else this.matrixPalette=new Float32Array(16*b);this.matrices=[];for(a=0;a<
- b;a++)this.matrices[a]=new pc.Mat4};Object.assign(b.prototype,{updateMatrices:function(a){f.copy(a.getWorldTransform()).invert();for(a=this.bones.length-1;0<=a;a--)this.matrices[a].mul2(f,this.bones[a].getWorldTransform()),this.matrices[a].mul2(this.matrices[a],this.skin.inverseBindPose[a])},updateMatrixPalette:function(){for(var a,b=this.matrixPalette,d,e=this.bones.length-1;0<=e;e--)a=this.matrices[e].data,d=16*e,b[d]=a[0],b[d+1]=a[1],b[d+2]=a[2],b[d+3]=a[3],b[d+4]=a[4],b[d+5]=a[5],b[d+6]=a[6],
- b[d+7]=a[7],b[d+8]=a[8],b[d+9]=a[9],b[d+10]=a[10],b[d+11]=a[11],b[d+12]=a[12],b[d+13]=a[13],b[d+14]=a[14],b[d+15]=a[15];this.skin.device.supportsBoneTextures&&(this.boneTexture.lock(),this.boneTexture.unlock())}});return{Skin:function(a,b,d){this.device=a;this.inverseBindPose=b;this.boneNames=d},SkinInstance:b}}());Object.assign(pc,function(){function f(){this.index=0;this.boneIndices=[0,0,0,0]}function b(){this.indexCount=this.indexStart=this.vertexCount=this.vertexStart=this.partition=0;this.boneIndices=[];this.vertices=[];this.indices=[];this.indexMap={}}function a(a){var b=a.vertices,c=a.skins,d=a.meshes,f=a.meshInstances;for(a=0;a<d.length;a++)d[a].vertices=b[d[a].vertices],void 0!==d[a].skin&&(d[a].skin=c[d[a].skin]);for(a=0;a<f.length;a++)f[a].mesh=d[f[a].mesh]}function c(a){var b=a.vertices,c=a.skins,
- d=a.meshes,f=a.meshInstances;for(a=0;a<d.length;a++)d[a].vertices=b.indexOf(d[a].vertices),void 0!==d[a].skin&&(d[a].skin=c.indexOf(d[a].skin));for(a=0;a<f.length;a++)f[a].mesh=d.indexOf(f[a].mesh)}Object.assign(b.prototype,{addVertex:function(a,b,c){if(void 0!==this.indexMap[b])c=this.indexMap[b],this.indices.push(c);else{for(var d=0;4>d;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,f){var d,e,g=[],l=0,q=a.length;for(d=0;d<q;d++)for(var m=a[d].index,r=0;4>r;r++)if(0<c.blendWeight.data[4*m+r]){var t=c.blendIndices.data[4*m+r],v=!0;for(e=0;e<l;e++)if(g[e]==t){v=!1;break}v&&(g[l]=t,e=this.getBoneRemap(t),l+=-1===e?1:0)}if(this.boneIndices.length+l>f)return!1;for(d=0;d<l;d++)this.boneIndices.push(g[d]);for(d=0;d<q;d++)this.addVertex(a[d],b[d],c);return!0},getBoneRemap:function(a){for(var b=0;b<this.boneIndices.length;b++)if(this.boneIndices[b]===
- a)return b;return-1}});return{partitionSkin:function(d,e,g){var l,k,p,h;a(d);var n=d.vertices,q=d.skins,m,r=d.meshes,t=d.meshInstances,v=function(a){var b=new f;b.index=a;return b};for(l=q.length-1;0<=l;l--)if(q[l].boneNames.length>g){var y=q.splice(l,1)[0],u=[];for(k=0;k<r.length;k++)r[k].skin===y&&u.push(r[k]);for(k=0;k<u.length;k++)h=r.indexOf(u[k]),-1!==h&&r.splice(h,1);if(0===u.length)throw Error("partitionSkin: There should be at least one mesh that references a skin");var w=u[0].vertices;for(k=
- 1;k<u.length;k++)if(u[k].vertices!==w)throw Error("partitionSkin: All meshes that share a skin should also share the same vertex buffer");var x=[],D=[];p=[];var z=0;for(k=0;k<u.length;k++){m=u[k];for(var C=m.indices,A=m.base;A<m.base+m.count;){h=C[A++];D[0]=v(h);p[0]=h;h=C[A++];D[1]=v(h);p[1]=h;h=C[A++];D[2]=v(h);p[2]=h;for(var B=!1,J=z;J<x.length;J++)if(h=x[J],h.addPrimitive(D,p,w,g)){B=!0;break}B||(h=new b,h.originalMesh=m,h.addPrimitive(D,p,w,g),x.push(h))}z=x.length}m=[];u=[];for(k=0;k<x.length;k++)if(h=
- x[k],h.vertices.length&&h.indices.length){D=m.length;p=h.vertices.length;z=u.length;C=h.indices.length;h.partition=k;h.vertexStart=D;h.vertexCount=p;h.indexStart=z;h.indexCount=C;A=0;for(B=D;A<p;)m[B++]=h.vertices[A++];A=0;for(B=z;A<C;)u[B++]=h.indices[A++]+D}D=[];for(k=0;k<x.length;k++){h=x[k];z=[];C=[];for(p=0;p<h.boneIndices.length;p++)z.push(y.inverseBindMatrices[h.boneIndices[p]]),C.push(y.boneNames[h.boneIndices[p]]);h={inverseBindMatrices:z,boneNames:C};D.push(h);q.push(h)}var F,y={};for(F in w)y[F]=
- {components:w[F].components,data:[],type:w[F].type};for(F in w)if("blendIndices"===F)for(h=y[F].data,k=0;k<m.length;k++)p=m[k].boneIndices,h.push(p[0],p[1],p[2],p[3]);else for(k=w[F],z=k.data,C=k.components,k=0;k<m.length;k++)for(h=m[k].index,p=0;p<C;p++)y[F].data.push(z[h*C+p]);n[n.indexOf(w)]=y;for(k=0;k<x.length;k++)for(h=x[k],m={aabb:{min:[0,0,0],max:[0,0,0]},vertices:y,skin:D[k],indices:u.splice(0,h.indexCount),type:"triangles",base:0,count:h.indexCount},r.push(m),p=t.length-1;0<=p;p--)t[p].mesh===
- h.originalMesh&&(t.push({mesh:m,node:t[p].node}),e&&e.push({material:e[p].material,path:e[p].path}));for(k=0;k<x.length;k++)for(h=x[k],p=t.length-1;0<=p;p--)t[p].mesh===h.originalMesh&&(t.splice(p,1),e&&e.splice(p,1))}c(d)}}}());Object.assign(pc,function(){var f=new pc.Vec3,b=new pc.Vec3,a=function(a){this.aabb=new pc.BoundingBox;this._baseAabb=this._baseBuffer=null;this._targets=a;this._aabbDirty=this._dirty=!0;this._baseData=null;this._vertSizeF=this._offsetTF=this._offsetNF=this._offsetPF=0};Object.assign(a.prototype,{_setBaseMesh:function(a){this._baseBuffer=a.vertexBuffer;this._baseAabb=a._aabb;this._baseData=new Float32Array(this._baseBuffer.storage);for(var b=a=-1,c=-1,d=this._baseBuffer.format.elements,f=this._baseBuffer.format.size,
- p=0;p<d.length;p++)d[p].name===pc.SEMANTIC_POSITION?a=d[p].offset:d[p].name===pc.SEMANTIC_NORMAL?b=d[p].offset:d[p].name===pc.SEMANTIC_TANGENT&&(c=d[p].offset);this._offsetPF=a/4;this._offsetNF=b/4;this._offsetTF=c/4;this._vertSizeF=f/4;this._dirty=!0},_calculateAabb:function(){if(this._baseBuffer){this.aabb.copy(this._baseAabb);var a,c,g,l,k,p,h,n=this._vertSizeF,q=this._offsetPF,m=this._baseData;for(c=0;c<this._targets.length;c++){l=this._targets[c];if(!l.aabb&&0<l.indices.length){l.aabb=this.aabb.clone();
- f.set(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE);b.set(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE);a=l.indices.length;for(g=0;g<a;g++)k=l.indices[g],p=k*n+q,k=m[p]+l.deltaPositions[3*g],h=m[p+1]+l.deltaPositions[3*g+1],p=m[p+2]+l.deltaPositions[3*g+2],f.x>k&&(f.x=k),f.y>h&&(f.y=h),f.z>p&&(f.z=p),b.x<k&&(b.x=k),b.y<h&&(b.y=h),b.z<p&&(b.z=p);l.aabb.setMinMax(f,b)}l.aabb&&this.aabb.add(l.aabb)}this._aabbDirty=!1}},addTarget:function(a){this._targets.push(a);this._aabbDirty=!0},removeTarget:function(a){a=
- this._targets.indexOf(a);-1!==a&&(this._targets.splice(a,1),this._aabbDirty=!0)},getTarget:function(a){return this._targets[a]}});var c=function(a){this.morph=a;this._vertexData=this._vertexBuffer=null;this._weights=[];this._dirty=!0};Object.assign(c.prototype,{_setBaseMesh:function(a){this.destroy();this._vertexBuffer=new pc.VertexBuffer(this.morph._baseBuffer.device,this.morph._baseBuffer.format,this.morph._baseBuffer.numVertices,pc.BUFFER_DYNAMIC,this.morph._baseBuffer.storage.slice(0));this._vertexData=
- new Float32Array(this._vertexBuffer.storage);this._weights=[];this._weights.length=this.morph._targets.length;for(a=0;a<this.morph._targets.length;a++)this._weights[a]=0;this._dirty=!0},destroy:function(){this._vertexBuffer&&(this._vertexBuffer.destroy(),this._vertexBuffer=null)},getWeight:function(a){return this._weights[a]},setWeight:function(a,b){this._weights[a]=b;this._dirty=!0},updateBounds:function(a){this.morph._baseBuffer!==a.vertexBuffer&&this.morph._setBaseMesh(a);this._vertexData||this._setBaseMesh(a);
- this.morph._aabbDirty&&this.morph._calculateAabb()},update:function(a){this.morph._baseBuffer!==a.vertexBuffer&&this.morph._setBaseMesh(a);this._vertexData||this._setBaseMesh(a);var b,c=this.morph._targets,d=this._weights,f,p,h,n,q,m=this.morph._vertSizeF,r=this.morph._offsetPF,t=this.morph._offsetNF,v=this.morph._offsetTF,y=this._vertexData;y.set(this.morph._baseData);for(var u=0;u<c.length;u++)if(p=d[u],0!==p)for(f=c[u],a=f.indices.length,h=0;h<a;h++)q=3*h,b=f.indices[h],n=b*m+r,y[n]+=f.deltaPositions[q]*
- p,y[n+1]+=f.deltaPositions[q+1]*p,y[n+2]+=f.deltaPositions[q+2]*p,f.deltaNormals&&(n=b*m+t,y[n]+=f.deltaNormals[q]*p,y[n+1]+=f.deltaNormals[q+1]*p,y[n+2]+=f.deltaNormals[q+2]*p,f.deltaTangents&&(q=4*h,n=b*m+v,y[n]+=f.deltaTangents[q]*p,y[n+1]+=f.deltaTangents[q+1]*p,y[n+2]+=f.deltaTangents[q+2]*p,y[n+3]+=f.deltaTangents[q+3]*p,y[n+3]=0<y[n+3]?1:-1));this._vertexBuffer.unlock()}});return{MorphTarget:function(a){if(a.indices)this.indices=a.indices;else{var b=a.deltaPositions;this.indices=[];this.indices.length=
- b.length;for(var c=0;c<b.length;c++)this.indices[c]=c}this.deltaPositions=a.deltaPositions;this.deltaNormals=a.deltaNormals;this.deltaTangents=a.deltaTangents;this.name=a.name;this.aabb=a.aabb},Morph:a,MorphInstance:c}}());Object.assign(pc,function(){var f=function(){this.graph=null;this.meshInstances=[];this.skinInstances=[];this.morphInstances=[];this.cameras=[];this.lights=[];this._shadersVersion=0};Object.assign(f.prototype,{getGraph:function(){return this.graph},setGraph:function(b){this.graph=b},getCameras:function(){return this.cameras},setCameras:function(b){this.cameras=b},getLights:function(){return this.lights},setLights:function(b){this.lights=b},getMaterials:function(){var b,a=[];for(b=0;b<this.meshInstances.length;b++){var c=
- this.meshInstances[b];-1===a.indexOf(c.material)&&a.push(c.material)}return a},clone:function(){var b,a,c=[],d=[],e=function(a){var b=a.clone();c.push(a);d.push(b);for(var g=0;g<a._children.length;g++)b.addChild(e(a._children[g]));return b},g=e(this.graph),f=[],k=[],p=[];for(b=0;b<this.skinInstances.length;b++){var h=this.skinInstances[b].skin,n=new pc.SkinInstance(h),q=[];for(a=0;a<h.boneNames.length;a++){var m=g.findByName(h.boneNames[a]);q.push(m)}n.bones=q;k.push(n)}for(b=0;b<this.morphInstances.length;b++)a=
- new pc.MorphInstance(this.morphInstances[b].morph),p.push(a);for(b=0;b<this.meshInstances.length;b++)a=this.meshInstances[b],h=c.indexOf(a.node),h=new pc.MeshInstance(d[h],a.mesh,a.material),a.skinInstance&&(n=this.skinInstances.indexOf(a.skinInstance),h.skinInstance=k[n]),a.morphInstance&&(a=this.morphInstances.indexOf(a.morphInstance),h.morphInstance=p[a]),f.push(h);b=new pc.Model;b.graph=g;b.meshInstances=f;b.skinInstances=k;b.morphInstances=p;b.getGraph().syncHierarchy();return b},destroy:function(){for(var b=
- this.meshInstances,a,c,d,e,g=0;g<b.length;g++){a=b[g];if(c=a.mesh)if(c._refCount--,1>c._refCount){c.vertexBuffer&&(c.vertexBuffer.destroy(),c.vertexBuffer=null);for(e=0;e<c.indexBuffer.length;e++)(d=c.indexBuffer[e])&&d.destroy();c.indexBuffer.length=0}(c=a.skinInstance)&&(c=c.boneTexture)&&c.destroy();a.skinInstance=null;(c=a.morphInstance)&&c.destroy();a.morphInstance=null;a.material=null}},generateWireframe:function(){var b,a,c,d,e,g,f,k,p,h,n=[];for(b=0;b<this.meshInstances.length;b++)g=this.meshInstances[b].mesh,
- -1===n.indexOf(g)&&n.push(g);var q=[[0,1],[1,2],[2,0]];for(b=0;b<n.length;b++){g=n[b];f=g.primitive[pc.RENDERSTYLE_SOLID].base;k=g.primitive[pc.RENDERSTYLE_SOLID].count;p=g.indexBuffer[pc.RENDERSTYLE_SOLID];h=new Uint16Array(p.lock());var m={},r=[];for(a=f;a<f+k;a+=3)for(c=0;3>c;c++){d=h[a+q[c][0]];e=h[a+q[c][1]];var t=d>e?e<<16|d:d<<16|e;void 0===m[t]&&(m[t]=0,r.push(d,e))}p.unlock();a=new pc.IndexBuffer(p.device,pc.INDEXFORMAT_UINT16,r.length);c=new Uint16Array(a.lock());c.set(r);a.unlock();g.primitive[pc.RENDERSTYLE_WIREFRAME]=
- {type:pc.PRIMITIVE_LINES,base:0,count:r.length,indexed:!0};g.indexBuffer[pc.RENDERSTYLE_WIREFRAME]=a}}});return{Model:f}}());Object.assign(pc,function(){function f(a){return a-Math.floor(a)}function b(a){var b=f(a);a=f(255*a);return[b-a/255,a-a/255]}function a(a,b){return a-b*Math.floor(a/b)}function c(a,b){U[a]=void 0!==Z[a]&&null!==Z[a]?Z[a]:b}function d(a,b){for(var c=a.length/3,d=Array(4*c),e=0;e<c;e++)d[4*e]=a[3*e],d[4*e+1]=a[3*e+1],d[4*e+2]=a[3*e+2],d[4*e+3]=(255*b[3*e]<<16|255*b[3*e+1]<<8|255*b[3*e+2])/16777216;return d}function e(a,b){var c,d,e=b.length,g=a.length/e;for(c=0;c<g;c++)for(d=0;d<e;d++)b[d]=Math.max(b[d],
- Math.abs(a[c*e+d]))}function g(a,b,c){for(var d=new Float32Array(b.length),g=0;g<b.length;g++)d[g]=b[g]-a[g];e(d,c);a=c.length;var f=d.length/a;for(b=0;b<f;b++)for(g=0;g<a;g++)d[b*a+g]/=c[g],d[b*a+g]*=.5,d[b*a+g]+=.5;return d}function l(a,b){b.data[0]=a.data[0];b.data[1]=a.data[1];b.data[2]=a.data[2];b.data[3]=a.data[4];b.data[4]=a.data[5];b.data[5]=a.data[6];b.data[6]=a.data[8];b.data[7]=a.data[9];b.data[8]=a.data[10]}var k=[[-1,-1],[1,-1],[1,1],[-1,1]],p=function(a,b,c,d,e,g,f){e||(e=pc.PIXELFORMAT_RGBA32F);
- var l=pc.FILTER_NEAREST;f&&e===pc.PIXELFORMAT_R8_G8_B8_A8&&(l=pc.FILTER_LINEAR);a=new pc.Texture(a,{width:b,height:c,format:e,cubemap:!1,mipmaps:!1,minFilter:l,magFilter:l,addressU:pc.ADDRESS_CLAMP_TO_EDGE,addressV:pc.ADDRESS_CLAMP_TO_EDGE});a.name="PSTexture";b=a.lock();if(e===pc.PIXELFORMAT_R8_G8_B8_A8){e=new Uint8Array(d.length);for(c=0;c<d.length;c++)e[c]=d[c]*g*255;d=e}b.set(d);a.unlock();return a},h=new pc.Curve([0,0,1,0]),n=new pc.Curve([0,1,1,1]),q=new pc.CurveSet([0,0,1,0],[0,0,1,0],[0,0,
- 1,0]),m=new pc.CurveSet([0,1,1,1],[0,1,1,1],[0,1,1,1]),r=2,t=new pc.Vec3,v=new pc.Vec3,y=new pc.Vec3,u=new pc.Vec3,w=new pc.Vec3,x=new pc.Vec3,D=new pc.Vec3,z=new pc.Vec3,C=new pc.Vec3,A=new pc.Mat4,B=new pc.Mat3,J=new pc.Mat3,F=1,H,E=new pc.Mat4,G=new pc.Vec3,I=new pc.Vec3,Q=new pc.Vec3,V=new pc.Vec3,W=new pc.Vec3,U,Z,T=function(a,b){this.graphicsDevice=a;this.precision=32;this._addTimeTime=0;if(!T.DEFAULT_PARAM_TEXTURE){var d=new Float32Array(1024),e,g,f,l;for(g=0;16>g;g++)for(e=0;16>e;e++)f=e+
- 1-8.5,l=g+1-8.5,l=Math.max(Math.min(1-Math.max(Math.min(Math.sqrt(f*f+l*l)/16,1),0)-.5,1),0),f=16*g+e,d[4*f]=1,d[4*f+1]=1,d[4*f+2]=1,d[4*f+3]=l;T.DEFAULT_PARAM_TEXTURE=p(a,16,16,d,pc.PIXELFORMAT_R8_G8_B8_A8,1,!0);T.DEFAULT_PARAM_TEXTURE.minFilter=pc.FILTER_LINEAR;T.DEFAULT_PARAM_TEXTURE.magFilter=pc.FILTER_LINEAR}U=this;Z=b;c("numParticles",1);this.numParticles>a.maxTextureSize&&(console.warn("WARNING: can't create more than "+a.maxTextureSize+" particles on this device."),this.numParticles=a.maxTextureSize);
- c("rate",1);c("rate2",this.rate);c("lifetime",50);c("emitterExtents",new pc.Vec3(0,0,0));c("emitterRadius",0);c("emitterShape",pc.EMITTERSHAPE_BOX);c("initialVelocity",1);c("wrap",!1);c("localSpace",!1);c("wrapBounds",null);c("colorMap",T.DEFAULT_PARAM_TEXTURE);c("normalMap",null);c("loop",!0);c("preWarm",!1);c("sort",pc.PARTICLESORT_NONE);c("mode",pc.PARTICLEMODE_GPU);c("scene",null);c("lighting",!1);c("halfLambert",!1);c("intensity",1);c("stretch",0);c("alignToMotion",!1);c("depthSoftening",0);
- c("mesh",null);c("depthWrite",!1);c("noFog",!1);c("blendType",pc.BLEND_NORMAL);c("node",null);c("startAngle",0);c("startAngle2",this.startAngle);c("animTilesX",1);c("animTilesY",1);c("animNumFrames",1);c("animSpeed",1);c("animLoop",!0);this.frameRandomUniform=new Float32Array(3);this.emitterPosUniform=new Float32Array(3);this.wrapBoundsUniform=new Float32Array(3);this.emitterScaleUniform=new Float32Array([1,1,1]);c("colorGraph",m);c("colorGraph2",this.colorGraph);c("scaleGraph",n);c("scaleGraph2",
- this.scaleGraph);c("alphaGraph",n);c("alphaGraph2",this.alphaGraph);c("localVelocityGraph",q);c("localVelocityGraph2",this.localVelocityGraph);c("velocityGraph",q);c("velocityGraph2",this.velocityGraph);c("rotationSpeedGraph",h);c("rotationSpeedGraph2",this.rotationSpeedGraph);this.constantParticleTexIN=a.scope.resolve("particleTexIN");this.constantParticleTexOUT=a.scope.resolve("particleTexOUT");this.constantEmitterPos=a.scope.resolve("emitterPos");this.constantEmitterScale=a.scope.resolve("emitterScale");
- this.constantSpawnBounds=a.scope.resolve("spawnBounds");this.constantSpawnBoundsSphere=a.scope.resolve("spawnBoundsSphere");this.constantInitialVelocity=a.scope.resolve("initialVelocity");this.constantFrameRandom=a.scope.resolve("frameRandom");this.constantDelta=a.scope.resolve("delta");this.constantRate=a.scope.resolve("rate");this.constantRateDiv=a.scope.resolve("rateDiv");this.constantLifetime=a.scope.resolve("lifetime");this.constantLightCube=a.scope.resolve("lightCube[0]");this.constantGraphSampleSize=
- a.scope.resolve("graphSampleSize");this.constantGraphNumSamples=a.scope.resolve("graphNumSamples");this.constantInternalTex0=a.scope.resolve("internalTex0");this.constantInternalTex1=a.scope.resolve("internalTex1");this.constantInternalTex2=a.scope.resolve("internalTex2");this.constantEmitterMatrix=a.scope.resolve("emitterMatrix");this.constantNumParticles=a.scope.resolve("numParticles");this.constantNumParticlesPot=a.scope.resolve("numParticlesPot");this.constantLocalVelocityDivMult=a.scope.resolve("localVelocityDivMult");
- this.constantVelocityDivMult=a.scope.resolve("velocityDivMult");this.constantRotSpeedDivMult=a.scope.resolve("rotSpeedDivMult");this.constantSeed=a.scope.resolve("seed");this.constantStartAngle=a.scope.resolve("startAngle");this.constantStartAngle2=a.scope.resolve("startAngle2");this.constantOutBoundsMul=a.scope.resolve("outBoundsMul");this.constantOutBoundsAdd=a.scope.resolve("outBoundsAdd");this.constantInBoundsSize=a.scope.resolve("inBoundsSize");this.constantInBoundsCenter=a.scope.resolve("inBoundsCenter");
- this.constantMaxVel=a.scope.resolve("maxVel");this.lightCube=new Float32Array(18);this.lightCubeDir=Array(6);this.lightCubeDir[0]=new pc.Vec3(-1,0,0);this.lightCubeDir[1]=new pc.Vec3(1,0,0);this.lightCubeDir[2]=new pc.Vec3(0,-1,0);this.lightCubeDir[3]=new pc.Vec3(0,1,0);this.lightCubeDir[4]=new pc.Vec3(0,0,-1);this.lightCubeDir[5]=new pc.Vec3(0,0,1);this.animParams=new Float32Array(4);this.camera=this.particleDistance=this.vbOld=this.vbToSort=this.internalTex3=this.internalTex2=this.internalTex1=
- this.internalTex0=null;this.swapTex=!1;this.useMesh=!0;this.useCpu=!1;this.pack8=!0;this.localBounds=new pc.BoundingBox;this.worldBoundsNoTrail=new pc.BoundingBox;this.worldBoundsTrail=[new pc.BoundingBox,new pc.BoundingBox];this.worldBounds=new pc.BoundingBox;this.inBoundsCenterUniform=new Float32Array(3);this.worldBoundsSize=new pc.Vec3;this.inBoundsSizeUniform=new Float32Array(3);this.prevWorldBoundsSize=new pc.Vec3;this.prevWorldBoundsCenter=new pc.Vec3;this.worldBoundsMul=new pc.Vec3;this.worldBoundsMulUniform=
- new Float32Array(3);this.worldBoundsAdd=new pc.Vec3;this.worldBoundsAddUniform=new Float32Array(3);this.timeToSwitchBounds=0;this.shaderParticleUpdateOnStop=this.shaderParticleUpdateNoRespawn=this.shaderParticleUpdateRespawn=null;this.numParticleIndices=this.numParticleVerts=0;this.meshInstance=this.material=null;this.seed=0;this.fixedTimeStep=1/60;this.maxSubSteps=10;this.simTimeTotal=this.simTime=0;this.beenReset=!1;this._layer=null;this.rebuild()};Object.assign(T.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.worldBoundsNoTrail.setFromTransformedAabb(this.localBounds,this.node.getWorldTransform());this.worldBoundsTrail[0].add(this.worldBoundsNoTrail);var a=this.simTimeTotal;if(a>this.timeToSwitchBounds){var b=this.worldBoundsTrail[0];this.worldBoundsTrail[0]=this.worldBoundsTrail[1];this.worldBoundsTrail[1]=b;this.worldBoundsTrail[0].copy(this.worldBoundsNoTrail);this.timeToSwitchBounds=a+this.lifetime}this.worldBounds.copy(this.worldBoundsTrail[0]);this.worldBounds.add(this.worldBoundsTrail[1]);
- this.worldBoundsSize.copy(this.worldBounds.halfExtents).scale(2);this.meshInstance.mesh.aabb=this.worldBounds;this.meshInstance._aabbVer=1-this.meshInstance._aabbVer;this.pack8&&this.calculateBoundsMad()}},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,f=0,l=this.lifetime/this.precision,k=[this.qVelocity,this.qVelocity2,this.qLocalVelocity,this.qLocalVelocity2],h=[0,0,0,0],p=[0,0,0,0],m=[0,0,
- 0,0],n,q,r,t,v,u;for(n=0;n<this.precision+1;n++){r=Math.min(n,this.precision-1);for(q=0;4>q;q++)t=k[q][3*r]*l+h[q],v=k[q][3*r+1]*l+p[q],u=k[q][3*r+2]*l+m[q],a>t&&(a=t),b>v&&(b=v),c>u&&(c=u),d<t&&(d=t),e<v&&(e=v),g<u&&(g=u),h[q]=t,p[q]=v,m[q]=u;f=Math.max(f,this.qScale[r])}this.emitterShape===pc.EMITTERSHAPE_BOX?(t=.5*this.emitterExtents.x,v=.5*this.emitterExtents.y,u=.5*this.emitterExtents.z):u=v=t=this.emitterRadius;d<t&&(d=t);e<v&&(e=v);g<u&&(g=u);t=-t;v=-v;u=-u;a>t&&(a=t);b>v&&(b=v);c>u&&(c=u);
- V.x=a-f;V.y=b-f;V.z=c-f;W.x=d+f;W.y=e+f;W.z=g+f;this.localBounds.setMinMax(V,W)},rebuild:function(){var a,b=this.graphicsDevice;null===this.colorMap&&(this.colorMap=T.DEFAULT_PARAM_TEXTURE);this.spawnBounds=this.emitterShape===pc.EMITTERSHAPE_BOX?this.emitterExtents:this.emitterRadius;this.useCpu=this.useCpu||this.sort>pc.PARTICLESORT_NONE||1>=b.maxVertexTextures||64>b.fragmentUniformsCount||b.forceCpuParticles||!b.extTextureFloat;this._destroyResources();this.pack8=(this.pack8||!b.textureFloatRenderable)&&
- !this.useCpu;r=this.useCpu||this.pack8?4:2;this.useMesh=!1;this.mesh&&(65535<this.numParticles*this.mesh.vertexBuffer.numVertices?console.warn("WARNING: particle system can't render mesh particles because numParticles * numVertices is more than 65k. Reverting to quad particles."):this.useMesh=!0);this.numParticlesPot=pc.math.nextPowerOfTwo(this.numParticles);this.rebuildGraphs();this.calculateLocalBounds();this.node&&(this.worldBounds.setFromTransformedAabb(this.localBounds,this.node.getWorldTransform()),
- this.worldBoundsTrail[0].copy(this.worldBounds),this.worldBoundsTrail[1].copy(this.worldBounds),this.worldBoundsSize.copy(this.worldBounds.halfExtents).scale(2),this.prevWorldBoundsSize.copy(this.worldBoundsSize),this.prevWorldBoundsCenter.copy(this.worldBounds.center),this.pack8&&this.calculateBoundsMad());this.vbToSort=Array(this.numParticles);this.particleDistance=new Float32Array(this.numParticles);this.frameRandomUniform[0]=Math.random();this.frameRandomUniform[1]=Math.random();this.frameRandomUniform[2]=
- Math.random();this.particleTex=new Float32Array(this.numParticlesPot*r*4);var c=null===this.node||this.localSpace?pc.Vec3.ZERO:this.node.getPosition();this.emitterShape===pc.EMITTERSHAPE_BOX&&(null===this.node?E.setTRS(pc.Vec3.ZERO,pc.Quat.IDENTITY,this.spawnBounds):E.setTRS(pc.Vec3.ZERO,this.node.getRotation(),Q.copy(this.spawnBounds).mul(this.node.localScale)));for(a=0;a<this.numParticles;a++)this.calcSpawnPosition(c,a),this.useCpu&&(this.particleTex[4*a+3+8*this.numParticlesPot]=1);this.particleTexStart=
- new Float32Array(this.numParticlesPot*r*4);for(a=0;a<this.particleTexStart.length;a++)this.particleTexStart[a]=this.particleTex[a];this.useCpu||(this.pack8?(this.particleTexIN=p(b,this.numParticlesPot,r,this.particleTex,pc.PIXELFORMAT_R8_G8_B8_A8,1,!1),this.particleTexOUT=p(b,this.numParticlesPot,r,this.particleTex,pc.PIXELFORMAT_R8_G8_B8_A8,1,!1),this.particleTexStart=p(b,this.numParticlesPot,r,this.particleTexStart,pc.PIXELFORMAT_R8_G8_B8_A8,1,!1)):(this.particleTexIN=p(b,this.numParticlesPot,r,
- this.particleTex),this.particleTexOUT=p(b,this.numParticlesPot,r,this.particleTex),this.particleTexStart=p(b,this.numParticlesPot,r,this.particleTexStart)),this.rtParticleTexIN=new pc.RenderTarget(b,this.particleTexIN,{depth:!1}),this.rtParticleTexOUT=new pc.RenderTarget(b,this.particleTexOUT,{depth:!1}),this.swapTex=!1);a=pc.shaderChunks;var c=a.particleUpdaterInitPS+(this.pack8?a.particleInputRgba8PS+a.particleOutputRgba8PS:a.particleInputFloatPS+a.particleOutputFloatPS)+(this.emitterShape===pc.EMITTERSHAPE_BOX?
- a.particleUpdaterAABBPS:a.particleUpdaterSpherePS)+a.particleUpdaterStartPS,d=c+a.particleUpdaterNoRespawnPS+a.particleUpdaterEndPS,e=c+a.particleUpdaterOnStopPS+a.particleUpdaterEndPS;this.shaderParticleUpdateRespawn=a.createShaderFromCode(b,a.fullscreenQuadVS,c+a.particleUpdaterRespawnPS+a.particleUpdaterEndPS,"fsQuad0"+this.emitterShape+""+this.pack8);this.shaderParticleUpdateNoRespawn=a.createShaderFromCode(b,a.fullscreenQuadVS,d,"fsQuad1"+this.emitterShape+""+this.pack8);this.shaderParticleUpdateOnStop=
- a.createShaderFromCode(b,a.fullscreenQuadVS,e,"fsQuad2"+this.emitterShape+""+this.pack8);this.numParticleVerts=this.useMesh?this.mesh.vertexBuffer.numVertices:4;this.numParticleIndices=this.useMesh?this.mesh.indexBuffer[0].numIndices:6;this._allocate(this.numParticles);b=new pc.Mesh;b.vertexBuffer=this.vertexBuffer;b.indexBuffer[0]=this.indexBuffer;b.primitive[0].type=pc.PRIMITIVE_TRIANGLES;b.primitive[0].base=0;b.primitive[0].count=this.numParticles*this.numParticleIndices;b.primitive[0].indexed=
- !0;this.material=new pc.Material;this.material.cullMode=pc.CULLFACE_NONE;this.material.alphaWrite=!1;this.material.blend=!0;this.material.blendType=this.blendType;this.material.depthWrite=this.depthWrite;this.material.emitter=this;this.regenShader();this.resetMaterial();a=this.meshInstance?this.meshInstance.visible:!0;this.meshInstance=new pc.MeshInstance(this.node,b,this.material);this.meshInstance.pick=!1;this.meshInstance.updateKey();this.meshInstance.cull=!0;this.meshInstance._noDepthDrawGl1=
- !0;this.meshInstance.aabb=this.worldBounds;this.meshInstance._updateAabb=!1;this.meshInstance.visible=a;this._initializeTextures();this.addTime(0);this.preWarm&&this.prewarm(this.lifetime);this.resetTime()},_isAnimated:function(){return 1<=this.animNumFrames&&(1<this.animTilesX||1<this.animTilesY)&&(this.colorMap&&this.colorMap!==T.DEFAULT_PARAM_TEXTURE||this.normalMap)},calcSpawnPosition:function(a,c){var d=Math.random(),e=Math.random(),g=Math.random(),l=Math.random();this.useCpu&&(this.particleTex[4*
- c+0+8*this.numParticlesPot]=d,this.particleTex[4*c+1+8*this.numParticlesPot]=e,this.particleTex[4*c+2+8*this.numParticlesPot]=g);G.x=d-.5;G.y=e-.5;G.z=g-.5;this.emitterShape===pc.EMITTERSHAPE_BOX?I.copy(a).add(E.transformPoint(G)):(G.normalize(),I.copy(a).add(G.scale(l*this.spawnBounds)));if(this.pack8){var k=(I.x-this.worldBounds.center.x)/this.worldBoundsSize.x+.5,l=(I.y-this.worldBounds.center.y)/this.worldBoundsSize.y+.5,g=(I.z-this.worldBounds.center.z)/this.worldBoundsSize.z+.5,e=pc.math.lerp(this.startAngle*
- pc.math.DEG_TO_RAD,this.startAngle2*pc.math.DEG_TO_RAD,d),e=e%(2*Math.PI)/(2*Math.PI),k=b(k);this.particleTex[4*c]=k[0];this.particleTex[4*c+1]=k[1];l=b(l);this.particleTex[4*c+2]=l[0];this.particleTex[4*c+3]=l[1];g=b(g);this.particleTex[4*c+0+4*this.numParticlesPot]=g[0];this.particleTex[4*c+1+4*this.numParticlesPot]=g[1];e=b(e);this.particleTex[4*c+2+4*this.numParticlesPot]=e[0];this.particleTex[4*c+3+4*this.numParticlesPot]=e[1];this.particleTex[4*c+3+8*this.numParticlesPot]=1;d=pc.math.lerp(this.rate,
- this.rate2,d);e=Math.max(this.lifetime,(this.numParticles-1)*Math.max(this.rate,this.rate2));l=(-d*c+e)/(e+(this.lifetime+1));d=f(l);e=f(255*l);g=f(65025*l);l=f(160581375*l);d-=e/255;e-=g/255;d=[d,e,g-l/255,l-l/255];this.particleTex[4*c+0+12*this.numParticlesPot]=d[0];this.particleTex[4*c+1+12*this.numParticlesPot]=d[1];this.particleTex[4*c+2+12*this.numParticlesPot]=d[2];this.particleTex[4*c+3+12*this.numParticlesPot]=d[3]}else this.particleTex[4*c]=I.x,this.particleTex[4*c+1]=I.y,this.particleTex[4*
- c+2]=I.z,this.particleTex[4*c+3]=pc.math.lerp(this.startAngle*pc.math.DEG_TO_RAD,this.startAngle2*pc.math.DEG_TO_RAD,d),d=pc.math.lerp(this.rate,this.rate2,d),this.particleTex[4*c+3+4*this.numParticlesPot]=-d*c},rebuildGraphs:function(){var a=this.precision,b=this.graphicsDevice,c;this.qLocalVelocity=this.localVelocityGraph.quantize(a);this.qVelocity=this.velocityGraph.quantize(a);this.qColor=this.colorGraph.quantize(a);this.qRotSpeed=this.rotationSpeedGraph.quantize(a);this.qScale=this.scaleGraph.quantize(a);
- this.qAlpha=this.alphaGraph.quantize(a);this.qLocalVelocity2=this.localVelocityGraph2.quantize(a);this.qVelocity2=this.velocityGraph2.quantize(a);this.qColor2=this.colorGraph2.quantize(a);this.qRotSpeed2=this.rotationSpeedGraph2.quantize(a);this.qScale2=this.scaleGraph2.quantize(a);this.qAlpha2=this.alphaGraph2.quantize(a);for(c=0;c<a;c++)this.qRotSpeed[c]*=pc.math.DEG_TO_RAD,this.qRotSpeed2[c]*=pc.math.DEG_TO_RAD;this.localVelocityUMax=new Float32Array(3);this.velocityUMax=new Float32Array(3);this.colorUMax=
- new Float32Array(3);this.rotSpeedUMax=[0];this.scaleUMax=[0];this.alphaUMax=[0];this.qLocalVelocityDiv=g(this.qLocalVelocity,this.qLocalVelocity2,this.localVelocityUMax);this.qVelocityDiv=g(this.qVelocity,this.qVelocity2,this.velocityUMax);this.qColorDiv=g(this.qColor,this.qColor2,this.colorUMax);this.qRotSpeedDiv=g(this.qRotSpeed,this.qRotSpeed2,this.rotSpeedUMax);this.qScaleDiv=g(this.qScale,this.qScale2,this.scaleUMax);this.qAlphaDiv=g(this.qAlpha,this.qAlpha2,this.alphaUMax);if(this.pack8){var f=
- [0,0,0];e(this.qVelocity,f);var l=[0,0,0];e(this.qVelocity2,l);c=[0,0,0];e(this.qLocalVelocity,c);var k=[0,0,0];e(this.qLocalVelocity2,k);var h=Math.max(f[0],l[0]),h=Math.max(h,f[1]),h=Math.max(h,l[1]),h=Math.max(h,f[2]),h=Math.max(h,l[2]),f=Math.max(c[0],k[0]),f=Math.max(f,c[1]),f=Math.max(f,k[1]),f=Math.max(f,c[2]),f=Math.max(f,k[2]);this.maxVel=h+f}if(!this.useCpu){this.internalTex0=p(b,a,1,d(this.qLocalVelocity,this.qLocalVelocityDiv));this.internalTex1=p(b,a,1,d(this.qVelocity,this.qVelocityDiv));
- c=this.qRotSpeed;for(var k=this.qScale,h=this.qScaleDiv,f=this.qRotSpeedDiv,l=this.qAlphaDiv,m=Array(4*c.length),n=0;n<c.length;n++)m[4*n]=c[n],m[4*n+1]=k[n],m[4*n+2]=0,m[4*n+3]=(255*h[n]<<16|255*f[n]<<8|255*l[n])/16777216;this.internalTex2=p(b,a,1,m)}c=this.qColor;k=this.qAlpha;h=Array(4*k.length);for(f=0;f<k.length;f++)h[4*f]=c[3*f],h[4*f+1]=c[3*f+1],h[4*f+2]=c[3*f+2],h[4*f+3]=k[f];this.internalTex3=p(b,a,1,h,pc.PIXELFORMAT_R8_G8_B8_A8,1,!0)},_initializeTextures:function(){this.colorMap&&(this.material.setParameter("colorMap",
- this.colorMap),this.lighting&&this.normalMap&&this.material.setParameter("normalMap",this.normalMap))},regenShader:function(){var a=this.graphicsDevice.getProgramLibrary(),b=null!==this.normalMap;this.normalOption=0;this.lighting&&(this.normalOption=b?2:1);this.material.updateShader=function(){this.emitter.scene&&this.emitter.camera!=this.emitter.scene._activeCamera&&(this.emitter.camera=this.emitter.scene._activeCamera,this.emitter.onChangeCamera());this.shader=a.getProgram("particle",{useCpu:this.emitter.useCpu,
- normal:this.emitter.normalOption,halflambert:this.emitter.halfLambert,stretch:this.emitter.stretch,alignToMotion:this.emitter.alignToMotion,soft:this.emitter.depthSoftening,mesh:this.emitter.useMesh,gamma:this.emitter.scene?this.emitter.scene.gammaCorrection:0,toneMap:this.emitter.scene?this.emitter.scene.toneMapping:0,fog:this.emitter.scene&&!this.emitter.noFog?this.emitter.scene.fog:"none",wrap:this.emitter.wrap&&this.emitter.wrapBounds,localSpace:this.emitter.localSpace,blend:this.blendType,animTex:this.emitter._isAnimated(),
- animTexLoop:this.emitter.animLoop,pack8:this.emitter.pack8})};this.material.updateShader()},resetMaterial:function(){var a=this.material;a.setParameter("stretch",this.stretch);this._isAnimated()&&a.setParameter("animTexParams",this.animParams);a.setParameter("colorMult",this.intensity);this.useCpu||(a.setParameter("internalTex0",this.internalTex0),a.setParameter("internalTex1",this.internalTex1),a.setParameter("internalTex2",this.internalTex2));a.setParameter("internalTex3",this.internalTex3);a.setParameter("numParticles",
- this.numParticles);a.setParameter("numParticlesPot",this.numParticlesPot);a.setParameter("lifetime",this.lifetime);a.setParameter("rate",this.rate);a.setParameter("rateDiv",this.rate2-this.rate);a.setParameter("seed",this.seed);a.setParameter("scaleDivMult",this.scaleUMax[0]);a.setParameter("alphaDivMult",this.alphaUMax[0]);a.setParameter("graphNumSamples",this.precision);a.setParameter("graphSampleSize",1/this.precision);a.setParameter("emitterScale",new Float32Array([1,1,1]));this.pack8&&(this.inBoundsSizeUniform[0]=
- this.worldBoundsSize.x,this.inBoundsSizeUniform[1]=this.worldBoundsSize.y,this.inBoundsSizeUniform[2]=this.worldBoundsSize.z,a.setParameter("inBoundsSize",this.inBoundsSizeUniform),this.inBoundsCenterUniform[0]=this.worldBounds.center.x,this.inBoundsCenterUniform[1]=this.worldBounds.center.y,this.inBoundsCenterUniform[2]=this.worldBounds.center.z,a.setParameter("inBoundsCenter",this.inBoundsCenterUniform),a.setParameter("maxVel",this.maxVel));this.wrap&&this.wrapBounds&&(this.wrapBoundsUniform[0]=
- this.wrapBounds.x,this.wrapBoundsUniform[1]=this.wrapBounds.y,this.wrapBoundsUniform[2]=this.wrapBounds.z,a.setParameter("wrapBounds",this.wrapBoundsUniform));this.colorMap&&a.setParameter("colorMap",this.colorMap);this.lighting&&this.normalMap&&a.setParameter("normalMap",this.normalMap);0<this.depthSoftening&&a.setParameter("softening",1/(this.depthSoftening*this.depthSoftening*100));0<this.stretch&&(a.cull=pc.CULLFACE_NONE)},_allocate:function(a){var b=a*this.numParticleVerts,c=a*this.numParticleIndices,
- d;if(void 0===this.vertexBuffer||this.vertexBuffer.getNumVertices()!==b){d=this.useCpu?[{semantic:pc.SEMANTIC_ATTR0,components:4,type:pc.TYPE_FLOAT32},{semantic:pc.SEMANTIC_ATTR1,components:4,type:pc.TYPE_FLOAT32},{semantic:pc.SEMANTIC_ATTR2,components:4,type:pc.TYPE_FLOAT32},{semantic:pc.SEMANTIC_ATTR3,components:2,type:pc.TYPE_FLOAT32}]:[{semantic:pc.SEMANTIC_ATTR0,components:4,type:pc.TYPE_FLOAT32}];d=new pc.VertexFormat(this.graphicsDevice,d);this.vertexBuffer=new pc.VertexBuffer(this.graphicsDevice,
- d,b,pc.BUFFER_DYNAMIC);this.indexBuffer=new pc.IndexBuffer(this.graphicsDevice,pc.INDEXFORMAT_UINT16,c);d=new Float32Array(this.vertexBuffer.lock());var e,g;this.useMesh&&(e=new Float32Array(this.mesh.vertexBuffer.lock()),g=e.length/this.mesh.vertexBuffer.numVertices);for(var f,c=0;c<b;c++){f=Math.floor(c/this.numParticleVerts);if(this.useMesh){var l=c%this.numParticleVerts;d[4*c]=e[l*g];d[4*c+1]=e[l*g+1];d[4*c+2]=e[l*g+2]}else l=c%4,d[4*c]=k[l][0],d[4*c+1]=k[l][1],d[4*c+2]=0;d[4*c+3]=f}this.useCpu&&
- (this.vbCPU=new Float32Array(d),this.vbOld=new Float32Array(this.vbCPU.length));this.vertexBuffer.unlock();this.useMesh&&this.mesh.vertexBuffer.unlock();b=0;g=new Uint16Array(this.indexBuffer.lock());this.useMesh&&(e=new Uint16Array(this.mesh.indexBuffer[0].lock()));for(c=0;c<a;c++)if(this.useMesh)for(d=0;d<this.numParticleIndices;d++)g[c*this.numParticleIndices+d]=e[d]+c*this.numParticleVerts;else d=4*c,g[b++]=d,g[b++]=d+1,g[b++]=d+2,g[b++]=d,g[b++]=d+2,g[b++]=d+3;this.indexBuffer.unlock();this.useMesh&&
- this.mesh.indexBuffer[0].unlock()}},reset:function(){this.beenReset=!0;this.seed=Math.random();this.material.setParameter("seed",this.seed);if(this.useCpu)for(var a=0;a<this.particleTexStart.length;a++)this.particleTex[a]=this.particleTexStart[a];else this._initializeTextures();this.resetTime();a=this.loop;this.loop=!0;this.addTime(0);this.loop=a;this.preWarm&&this.prewarm(this.lifetime)},prewarm:function(a){var b=Math.min(Math.floor(a/this.lifetime*this.precision),this.precision);a/=b;for(var c=
- 0;c<b;c++)this.addTime(a)},resetTime:function(){var a=Math.max(this.rate,this.rate2)*this.numParticles+this.lifetime;this.endTime=Date.now()+1E3*a},finishFrame:function(){this.useCpu&&this.vertexBuffer.unlock()},addTime:function(b,c){var d,e,g,f,k;f=this.graphicsDevice;this.simTimeTotal+=b;this.calculateWorldBounds();this._isAnimated()&&(k=this.animParams,k[0]=1/this.animTilesX,k[1]=1/this.animTilesY,k[2]=this.animNumFrames*this.animSpeed,k[3]=this.animNumFrames-1);this.scene&&this.camera!=this.scene._activeCamera&&
- (this.camera=this.scene._activeCamera,this.onChangeCamera());this.emitterShape===pc.EMITTERSHAPE_BOX&&(null===this.meshInstance.node?E.setTRS(pc.Vec3.ZERO,pc.Quat.IDENTITY,this.emitterExtents):E.setTRS(pc.Vec3.ZERO,this.meshInstance.node.getRotation(),Q.copy(this.emitterExtents).mul(this.meshInstance.node.localScale)));var h=null===this.meshInstance.node?pc.Vec3.ONE:this.meshInstance.node.localScale;this.emitterScaleUniform[0]=h.x;this.emitterScaleUniform[1]=h.y;this.emitterScaleUniform[2]=h.z;this.material.setParameter("emitterScale",
- this.emitterScaleUniform);this.localSpace&&this.meshInstance.node&&(k=this.meshInstance.node.getPosition(),this.emitterPosUniform[0]=k.x,this.emitterPosUniform[1]=k.y,this.emitterPosUniform[2]=k.z,this.material.setParameter("emitterPos",this.emitterPosUniform));if(this.useCpu){h=new Float32Array(this.vertexBuffer.lock());if(this.meshInstance.node){f=this.meshInstance.node.worldTransform;for(k=0;12>k;k++)A.data[k]=f.data[k];H=this.meshInstance.node.localScale;F=Math.max(Math.max(H.x,H.y),H.z)}k=null===
- this.meshInstance.node||this.localSpace?pc.Vec3.ZERO:this.meshInstance.node.getPosition();var p=this.camera?this.camera._node.getPosition():pc.Vec3.ZERO,m,n,q,r,I,V,W,U=this.precision-1;for(f=0;f<this.numParticles;f++){var L=Math.floor(this.vbCPU[f*this.numParticleVerts*4+3]),Z=this.particleTex[4*L+0+8*this.numParticlesPot];w.x=Z;w.y=this.particleTex[4*L+1+8*this.numParticlesPot];w.z=this.particleTex[4*L+2+8*this.numParticlesPot];var T=this.rate+(this.rate2-this.rate)*Z,R=this.lifetime,X=this.particleTex[4*
- L+3+4*this.numParticlesPot]+b,la=Math.max(Math.min(X/R,1),0),ha=0;d=0;var ka=0<X&&X<R;ka?(g=la*U,m=Math.floor(g),n=Math.ceil(g),g%=1,d=this.qRotSpeed[m],e=this.qRotSpeed[n],q=d+(e-d)*g,d=this.qRotSpeed2[m],e=this.qRotSpeed2[n],r=d+(e-d)*g,d=this.qScale[m],e=this.qScale[n],ha=d+(e-d)*g,d=this.qScale2[m],e=this.qScale2[n],I=d+(e-d)*g,d=this.qAlpha[m],e=this.qAlpha[n],V=d+(e-d)*g,d=this.qAlpha2[m],e=this.qAlpha2[n],W=d+(e-d)*g,m*=3,n*=3,d=this.qLocalVelocity[m],e=this.qLocalVelocity[n],v.x=d+(e-d)*g,
- d=this.qLocalVelocity[m+1],e=this.qLocalVelocity[n+1],v.y=d+(e-d)*g,d=this.qLocalVelocity[m+2],e=this.qLocalVelocity[n+2],v.z=d+(e-d)*g,d=this.qLocalVelocity2[m],e=this.qLocalVelocity2[n],u.x=d+(e-d)*g,d=this.qLocalVelocity2[m+1],e=this.qLocalVelocity2[n+1],u.y=d+(e-d)*g,d=this.qLocalVelocity2[m+2],e=this.qLocalVelocity2[n+2],u.z=d+(e-d)*g,d=this.qVelocity[m],e=this.qVelocity[n],t.x=d+(e-d)*g,d=this.qVelocity[m+1],e=this.qVelocity[n+1],t.y=d+(e-d)*g,d=this.qVelocity[m+2],e=this.qVelocity[n+2],t.z=
- d+(e-d)*g,d=this.qVelocity2[m],e=this.qVelocity2[n],y.x=d+(e-d)*g,d=this.qVelocity2[m+1],e=this.qVelocity2[n+1],y.y=d+(e-d)*g,d=this.qVelocity2[m+2],e=this.qVelocity2[n+2],y.z=d+(e-d)*g,v.x+=(u.x-v.x)*w.x,v.y+=(u.y-v.y)*w.y,v.z+=(u.z-v.z)*w.z,0<this.initialVelocity&&(this.emitterShape===pc.EMITTERSHAPE_SPHERE?(G.copy(w).scale(2).sub(pc.Vec3.ONE).normalize(),v.add(G.scale(this.initialVelocity))):v.add(pc.Vec3.FORWARD.scale(this.initialVelocity))),t.x+=(y.x-t.x)*w.x,t.y+=(y.y-t.y)*w.y,t.z+=(y.z-t.z)*
- w.z,q+=(r-q)*w.y,ha=(ha+1E4*Z%1*(I-ha))*F,d=1E3*Z%1*(W-V),this.meshInstance.node&&A.transformPoint(v,v),v.add(t.mul(H)),C.copy(v),x.x=this.particleTex[4*L],x.y=this.particleTex[4*L+1],x.z=this.particleTex[4*L+2],D.copy(x).add(v.scale(b)),z.copy(D),this.particleTex[4*L]=z.x,this.particleTex[4*L+1]=z.y,this.particleTex[4*L+2]=z.z,this.particleTex[4*L+3]+=q*b,this.wrap&&this.wrapBounds&&(z.sub(k),z.x=a(z.x,this.wrapBounds.x)-.5*this.wrapBounds.x,z.y=a(z.y,this.wrapBounds.y)-.5*this.wrapBounds.y,z.z=
- a(z.z,this.wrapBounds.z)-.5*this.wrapBounds.z,z.add(k)),0<this.sort&&(1===this.sort?(Q.copy(z).sub(p),this.particleDistance[L]=-(Q.x*Q.x+Q.y*Q.y+Q.z*Q.z)):2===this.sort?this.particleDistance[L]=X:3===this.sort&&(this.particleDistance[L]=-X))):this.calcSpawnPosition(k,L);c?0>X&&(this.particleTex[4*L+3+8*this.numParticlesPot]=-1):(X>=R&&(X-=Math.max(R,(this.numParticles-1)*T),this.particleTex[4*L+3+8*this.numParticlesPot]=this.loop?1:-1),0>X&&this.loop&&(this.particleTex[4*L+3+8*this.numParticlesPot]=
- 1));0>this.particleTex[4*L+3+8*this.numParticlesPot]&&(ka=!1);this.particleTex[4*L+3+4*this.numParticlesPot]=X;for(q=0;q<this.numParticleVerts;q++)Z=this.vbCPU[f*this.numParticleVerts*4+4*q],T=this.vbCPU[f*this.numParticleVerts*4+4*q+1],R=this.vbCPU[f*this.numParticleVerts*4+4*q+2],ka||(Z=T=R=0),X=f*this.numParticleVerts*14+14*q,h[X]=z.x,h[X+1]=z.y,h[X+2]=z.z,h[X+3]=la,h[X+4]=this.alignToMotion?0:this.particleTex[4*L+3],h[X+5]=ha,h[X+6]=d,h[X+7]=C.x,h[X+8]=Z,h[X+9]=T,h[X+10]=R,h[X+11]=C.y,h[X+12]=
- C.z}if(this.sort>pc.PARTICLESORT_NONE&&this.camera){k=this.particleDistance;for(f=0;f<this.numParticles;f++)this.vbToSort[f]=[f,k[Math.floor(this.vbCPU[f*this.numParticleVerts*4+3])]];this.vbOld.set(this.vbCPU);this.vbToSort.sort(function(a,b){return a[1]-b[1]});for(f=0;f<this.numParticles;f++)for(h=this.vbToSort[f][0]*this.numParticleVerts*4,p=f*this.numParticleVerts*4,k=0;k<4*this.numParticleVerts;k++)this.vbCPU[p+k]=this.vbOld[h+k]}}else f.setBlending(!1),f.setColorWrite(!0,!0,!0,!0),f.setCullMode(pc.CULLFACE_NONE),
- f.setDepthTest(!1),f.setDepthWrite(!1),this.frameRandomUniform[0]=Math.random(),this.frameRandomUniform[1]=Math.random(),this.frameRandomUniform[2]=Math.random(),this.constantGraphSampleSize.setValue(1/this.precision),this.constantGraphNumSamples.setValue(this.precision),this.constantNumParticles.setValue(this.numParticles),this.constantNumParticlesPot.setValue(this.numParticlesPot),this.constantInternalTex0.setValue(this.internalTex0),this.constantInternalTex1.setValue(this.internalTex1),this.constantInternalTex2.setValue(this.internalTex2),
- this.pack8&&(this.worldBoundsMulUniform[0]=this.worldBoundsMul.x,this.worldBoundsMulUniform[1]=this.worldBoundsMul.y,this.worldBoundsMulUniform[2]=this.worldBoundsMul.z,this.constantOutBoundsMul.setValue(this.worldBoundsMulUniform),this.worldBoundsAddUniform[0]=this.worldBoundsAdd.x,this.worldBoundsAddUniform[1]=this.worldBoundsAdd.y,this.worldBoundsAddUniform[2]=this.worldBoundsAdd.z,this.constantOutBoundsAdd.setValue(this.worldBoundsAddUniform),this.inBoundsSizeUniform[0]=this.prevWorldBoundsSize.x,
- this.inBoundsSizeUniform[1]=this.prevWorldBoundsSize.y,this.inBoundsSizeUniform[2]=this.prevWorldBoundsSize.z,this.constantInBoundsSize.setValue(this.inBoundsSizeUniform),this.inBoundsCenterUniform[0]=this.prevWorldBoundsCenter.x,this.inBoundsCenterUniform[1]=this.prevWorldBoundsCenter.y,this.inBoundsCenterUniform[2]=this.prevWorldBoundsCenter.z,this.constantInBoundsCenter.setValue(this.inBoundsCenterUniform),k=this.maxVel*Math.max(Math.max(h.x,h.y),h.z),k=Math.max(k,1),this.constantMaxVel.setValue(k)),
- k=null===this.meshInstance.node||this.localSpace?pc.Vec3.ZERO:this.meshInstance.node.getPosition(),p=null===this.meshInstance.node?pc.Mat4.IDENTITY:this.meshInstance.node.getWorldTransform(),this.emitterShape===pc.EMITTERSHAPE_BOX?(l(E,B),this.constantSpawnBounds.setValue(B.data)):this.constantSpawnBoundsSphere.setValue(this.emitterRadius),this.constantInitialVelocity.setValue(this.initialVelocity),l(p,J),this.emitterPosUniform[0]=k.x,this.emitterPosUniform[1]=k.y,this.emitterPosUniform[2]=k.z,this.constantEmitterPos.setValue(this.emitterPosUniform),
- this.constantFrameRandom.setValue(this.frameRandomUniform),this.constantDelta.setValue(b),this.constantRate.setValue(this.rate),this.constantRateDiv.setValue(this.rate2-this.rate),this.constantStartAngle.setValue(this.startAngle*pc.math.DEG_TO_RAD),this.constantStartAngle2.setValue(this.startAngle2*pc.math.DEG_TO_RAD),this.constantSeed.setValue(this.seed),this.constantLifetime.setValue(this.lifetime),this.emitterScaleUniform[0]=h.x,this.emitterScaleUniform[1]=h.y,this.emitterScaleUniform[2]=h.z,this.constantEmitterScale.setValue(this.emitterScaleUniform),
- this.constantEmitterMatrix.setValue(J.data),this.constantLocalVelocityDivMult.setValue(this.localVelocityUMax),this.constantVelocityDivMult.setValue(this.velocityUMax),this.constantRotSpeedDivMult.setValue(this.rotSpeedUMax[0]),k=this.swapTex?this.particleTexOUT:this.particleTexIN,k=this.beenReset?this.particleTexStart:k,h=this.swapTex?this.particleTexIN:this.particleTexOUT,this.constantParticleTexIN.setValue(k),c?pc.drawQuadWithShader(f,this.swapTex?this.rtParticleTexIN:this.rtParticleTexOUT,this.shaderParticleUpdateOnStop):
- pc.drawQuadWithShader(f,this.swapTex?this.rtParticleTexIN:this.rtParticleTexOUT,this.loop?this.shaderParticleUpdateRespawn:this.shaderParticleUpdateNoRespawn),this.constantParticleTexOUT.setValue(h),this.material.setParameter("particleTexOUT",k),this.material.setParameter("particleTexIN",h),this.beenReset=!1,this.swapTex=!this.swapTex,f.setDepthTest(!0),f.setDepthWrite(!0);if(!this.loop&&Date.now()>this.endTime){if(this.onFinished)this.onFinished();this.meshInstance.visible=!1}},_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.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()}});return{ParticleEmitter:T}}());Object.assign(pc,function(){var f=!1,b=function(a,b,d){a instanceof pc.GraphicsDevice&&(a=pc.Application.getApplication(),f||(f=!0));this.app=a;var c=this.device=a.graphicsDevice;this.library=c.getProgramLibrary();this.pickColor=new Float32Array(4);this.pickColor[3]=1;this.scene=null;this.drawCalls=[];this.layerComp=this.layer=null;this.clearOptions={color:[1,1,1,1],depth:1,flags:pc.CLEARFLAG_COLOR|pc.CLEARFLAG_DEPTH};var g=this;this._clearDepthOptions={depth:1,flags:pc.CLEARFLAG_DEPTH};this.clearDepthCommand=
- new pc.Command(0,0,function(){c.clear(g._clearDepthOptions)});this.resize(b,d);this._ignoreOpacityFor=null};b.prototype.getSelection=function(a,b,d,e){var c=this.device;"object"===typeof a?(e=a,a=e.x,b=e.y,d=e.width,e=e.height):b=this.layer.renderTarget.height-(b+(e||1));d=d||1;e=e||1;var f=c.renderTarget;c.setRenderTarget(this.layer.renderTarget);c.updateBegin();var k=new Uint8Array(4*d*e);c.readPixels(a,b,d,e,k);c.updateEnd();c.setRenderTarget(f);a=[];b=this.layer.instances.visibleOpaque[0].list;
- for(var p,h,c=0;c<d*e;c++)f=k[4*c+0],p=k[4*c+1],h=k[4*c+2],f=f<<16|p<<8|h,16777215!==f&&(f=b[f],-1===a.indexOf(f)&&a.push(f));return a};b.prototype.prepare=function(a,b,d){var c=this.device,g,f=this;a instanceof pc.Camera&&(a=a._component);this.scene=b;var k=null,p=null;d instanceof pc.Layer?k=d:p=d;if(!this.layer){var h=c.scope.resolve("uColor");this.layer=new pc.Layer({name:"Picker",shaderPass:pc.SHADER_PICK,opaqueSortMode:pc.SORTMODE_NONE,onEnable:function(){if(!this.renderTarget){var a=new pc.Texture(c,
- {format:pc.PIXELFORMAT_R8_G8_B8_A8,width:f.width,height:f.height});a.name="pick";a.minFilter=pc.FILTER_NEAREST;a.magFilter=pc.FILTER_NEAREST;a.addressU=pc.ADDRESS_CLAMP_TO_EDGE;a.addressV=pc.ADDRESS_CLAMP_TO_EDGE;this.renderTarget=new pc.RenderTarget(c,a,{depth:!0})}},onDisable:function(){this.renderTarget&&(this.renderTarget._colorBuffer.destroy(),this.renderTarget.destroy(),this.renderTarget=null)},onDrawCall:function(a,b){f.pickColor[0]=(b>>16&255)/255;f.pickColor[1]=(b>>8&255)/255;f.pickColor[2]=
- (b&255)/255;h.setValue(f.pickColor);c.setBlending(!1)}});this.layerComp=new pc.LayerComposition;this.layerComp.pushOpaque(this.layer);this.meshInstances=this.layer.opaqueMeshInstances;this._instancesVersion=-1}var n,q,m;if(!k){this.layer.clearMeshInstances();d=b.layers.layerList;var r=b.layers.subLayerEnabled,t=b.layers.subLayerList;for(b=0;b<d.length;b++)d[b].overrideClear&&d[b]._clearDepthBuffer&&(d[b]._pickerCleared=!1);for(b=0;b<d.length;b++)if(g=d[b],g.renderTarget===p&&g.enabled&&r[b]&&(n=g.cameras.indexOf(a),
- !(0>n)))for(g.overrideClear&&g._clearDepthBuffer&&!g._pickerCleared&&(this.meshInstances.push(this.clearDepthCommand),g._pickerCleared=!0),n=(n=t[b])?g.instances.transparentMeshInstances:g.instances.opaqueMeshInstances,q=n.length,g=0;g<q;g++)m=n[g],m.pick&&this.meshInstances.push(m)}else if(this._instancesVersion!==k._version){this.layer.clearMeshInstances();n=k.instances.opaqueMeshInstances;q=n.length;for(g=0;g<q;g++)m=n[g],m.pick&&this.meshInstances.push(m);n=k.instances.transparentMeshInstances;
- q=n.length;for(g=0;g<q;g++)m=n[g],m.pick&&this.meshInstances.push(m);this._instancesVersion=k._version}this.layer.cameras[0]!==a&&(this.layer.clearCameras(),this.layer.addCamera(a));this.onLayerPreRender(this.layer,k,p);this.app.renderer.renderComposition(this.layerComp);this.onLayerPostRender(this.layer)};b.prototype.onLayerPreRender=function(a,b,d){if(this.width!==a.renderTarget.width||this.height!==a.renderTarget.height)a.onDisable(),a.onEnable();a.oldClear=a.cameras[0].camera._clearOptions;a.oldAspectMode=
- a.cameras[0].aspectRatioMode;a.oldAspect=a.cameras[0].aspectRatio;a.cameras[0].camera._clearOptions=this.clearOptions;a.cameras[0].aspectRatioMode=pc.ASPECT_MANUAL;a.cameras[0].aspectRatio=a.cameras[0].calculateAspectRatio(d?d:b?b.renderTarget:null);this.app.renderer.updateCameraFrustum(a.cameras[0].camera)};b.prototype.onLayerPostRender=function(a){a.cameras[0].camera._clearOptions=a.oldClear;a.cameras[0].aspectRatioMode=a.oldAspectMode;a.cameras[0].aspectRatio=a.oldAspect};b.prototype.resize=function(a,
- b){this.width=a;this.height=b};Object.defineProperty(b.prototype,"renderTarget",{get:function(){return this.layer.renderTarget}});return{Picker:b}}());var primitiveUv1Padding=.0625,primitiveUv1PaddingScale=1-2*primitiveUv1Padding;
- pc.calculateNormals=function(f,b){var a=b.length/3,c=f.length/3,d,e,g,l,k=new pc.Vec3,p=new pc.Vec3,h=new pc.Vec3,n=new pc.Vec3,q=new pc.Vec3,m=new pc.Vec3,r=[];for(l=0;l<f.length;l++)r[l]=0;for(l=0;l<a;l++)d=b[3*l],e=b[3*l+1],g=b[3*l+2],k.set(f[3*d],f[3*d+1],f[3*d+2]),p.set(f[3*e],f[3*e+1],f[3*e+2]),h.set(f[3*g],f[3*g+1],f[3*g+2]),n.sub2(p,k),q.sub2(h,k),m.cross(n,q).normalize(),r[3*d]+=m.x,r[3*d+1]+=m.y,r[3*d+2]+=m.z,r[3*e]+=m.x,r[3*e+1]+=m.y,r[3*e+2]+=m.z,r[3*g]+=m.x,r[3*g+1]+=m.y,r[3*g+2]+=m.z;
- for(l=0;l<c;l++)a=r[3*l],d=r[3*l+1],e=r[3*l+2],a=1/Math.sqrt(a*a+d*d+e*e),r[3*l]*=a,r[3*l+1]*=a,r[3*l+2]*=a;return r};
- pc.calculateTangents=function(f,b,a,c){var d=c.length/3,e=f.length/3,g,l,k,p,h,n,q,m,r,t,v,y,u,w,x=new pc.Vec3,D=new pc.Vec3,z=new pc.Vec3,C=new pc.Vec3,A=new pc.Vec3,B=new pc.Vec2,J=new pc.Vec2,F=new pc.Vec2,H,E=new Float32Array(3*e),G=new Float32Array(3*e),I=[];for(H=0;H<d;H++)g=c[3*H],l=c[3*H+1],k=c[3*H+2],z.set(f[3*g],f[3*g+1],f[3*g+2]),C.set(f[3*l],f[3*l+1],f[3*l+2]),A.set(f[3*k],f[3*k+1],f[3*k+2]),B.set(a[2*g],a[2*g+1]),J.set(a[2*l],a[2*l+1]),F.set(a[2*k],a[2*k+1]),p=C.x-z.x,h=A.x-z.x,n=C.y-
- z.y,q=A.y-z.y,m=C.z-z.z,r=A.z-z.z,t=J.x-B.x,v=F.x-B.x,y=J.y-B.y,u=F.y-B.y,w=t*u-v*y,0==w?(x.set(0,1,0),D.set(1,0,0)):(w=1/w,x.set((u*p-y*h)*w,(u*n-y*q)*w,(u*m-y*r)*w),D.set((t*h-v*p)*w,(t*q-v*n)*w,(t*r-v*m)*w)),E[3*g+0]+=x.x,E[3*g+1]+=x.y,E[3*g+2]+=x.z,E[3*l+0]+=x.x,E[3*l+1]+=x.y,E[3*l+2]+=x.z,E[3*k+0]+=x.x,E[3*k+1]+=x.y,E[3*k+2]+=x.z,G[3*g+0]+=D.x,G[3*g+1]+=D.y,G[3*g+2]+=D.z,G[3*l+0]+=D.x,G[3*l+1]+=D.y,G[3*l+2]+=D.z,G[3*k+0]+=D.x,G[3*k+1]+=D.y,G[3*k+2]+=D.z;y=new pc.Vec3;u=new pc.Vec3;f=new pc.Vec3;
- a=new pc.Vec3;for(H=0;H<e;H++)f.set(b[3*H],b[3*H+1],b[3*H+2]),y.set(E[3*H],E[3*H+1],E[3*H+2]),u.set(G[3*H],G[3*H+1],G[3*H+2]),c=f.dot(y),a.copy(f).scale(c),a.sub2(y,a).normalize(),I[4*H]=a.x,I[4*H+1]=a.y,I[4*H+2]=a.z,a.cross(f,y),I[4*H+3]=0>a.dot(u)?-1:1;return I};
- pc.createMesh=function(f,b,a){var c=a&&void 0!==a.normals?a.normals:null,d=a&&void 0!==a.tangents?a.tangents:null,e=a&&void 0!==a.colors?a.colors:null,g=a&&void 0!==a.uvs?a.uvs:null,l=a&&void 0!==a.uvs1?a.uvs1:null,k=a&&void 0!==a.indices?a.indices:null,p=a&&void 0!==a.blendIndices?a.blendIndices:null,h=a&&void 0!==a.blendWeights?a.blendWeights:null;a=[{semantic:pc.SEMANTIC_POSITION,components:3,type:pc.TYPE_FLOAT32}];null!==c&&a.push({semantic:pc.SEMANTIC_NORMAL,components:3,type:pc.TYPE_FLOAT32});
- null!==d&&a.push({semantic:pc.SEMANTIC_TANGENT,components:4,type:pc.TYPE_FLOAT32});null!==e&&a.push({semantic:pc.SEMANTIC_COLOR,components:4,type:pc.TYPE_UINT8,normalize:!0});null!==g&&a.push({semantic:pc.SEMANTIC_TEXCOORD0,components:2,type:pc.TYPE_FLOAT32});null!==l&&a.push({semantic:pc.SEMANTIC_TEXCOORD1,components:2,type:pc.TYPE_FLOAT32});null!==p&&a.push({semantic:pc.SEMANTIC_BLENDINDICES,components:2,type:pc.TYPE_UINT8});null!==h&&a.push({semantic:pc.SEMANTIC_BLENDWEIGHT,components:2,type:pc.TYPE_FLOAT32});
- var n=new pc.VertexFormat(f,a);a=b.length/3;for(var n=new pc.VertexBuffer(f,n,a),q=new pc.VertexIterator(n),m=0;m<a;m++)q.element[pc.SEMANTIC_POSITION].set(b[3*m],b[3*m+1],b[3*m+2]),null!==c&&q.element[pc.SEMANTIC_NORMAL].set(c[3*m],c[3*m+1],c[3*m+2]),null!==d&&q.element[pc.SEMANTIC_TANGENT].set(d[4*m],d[4*m+1],d[4*m+2],d[4*m+3]),null!==e&&q.element[pc.SEMANTIC_COLOR].set(e[4*m],e[4*m+1],e[4*m+2],e[4*m+3]),null!==g&&q.element[pc.SEMANTIC_TEXCOORD0].set(g[2*m],g[2*m+1]),null!==l&&q.element[pc.SEMANTIC_TEXCOORD1].set(l[2*
- m],l[2*m+1]),null!==p&&q.element[pc.SEMANTIC_BLENDINDICES].set(p[2*m],p[2*m+1]),null!==h&&q.element[pc.SEMANTIC_BLENDWEIGHT].set(h[2*m],h[2*m+1]),q.next();q.end();c=null;if(d=null!==k)c=new pc.IndexBuffer(f,pc.INDEXFORMAT_UINT16,k.length),(new Uint16Array(c.lock())).set(k),c.unlock();f=new pc.BoundingBox;f.compute(b);b=new pc.Mesh;b.vertexBuffer=n;b.indexBuffer[0]=c;b.primitive[0].type=pc.PRIMITIVE_TRIANGLES;b.primitive[0].base=0;b.primitive[0].count=d?k.length:a;b.primitive[0].indexed=d;b.aabb=f;
- return b};
- pc.createTorus=function(f,b){var a=b&&void 0!==b.tubeRadius?b.tubeRadius:.2,c=b&&void 0!==b.ringRadius?b.ringRadius:.3,d=b&&void 0!==b.segments?b.segments:30,e=b&&void 0!==b.sides?b.sides:20,g=b&&void 0!==b.calculateTangents?b.calculateTangents:!1,l,k,p,h,n,q,m,r,t,v,y=[],u=[],w=[],x=[];for(l=0;l<=e;l++)for(k=0;k<=d;k++)p=Math.cos(2*Math.PI*k/d)*(c+a*Math.cos(2*Math.PI*l/e)),h=Math.sin(2*Math.PI*l/e)*a,n=Math.sin(2*Math.PI*k/d)*(c+a*Math.cos(2*Math.PI*l/e)),q=Math.cos(2*Math.PI*k/d)*Math.cos(2*Math.PI*
- l/e),m=Math.sin(2*Math.PI*l/e),r=Math.sin(2*Math.PI*k/d)*Math.cos(2*Math.PI*l/e),t=l/e,v=1-k/d,y.push(p,h,n),u.push(q,m,r),w.push(t,v),l<e&&k<d&&(p=l*(d+1)+k,h=(l+1)*(d+1)+k,n=l*(d+1)+(k+1),q=(l+1)*(d+1)+(k+1),x.push(p,h,n),x.push(h,q,n));a={normals:u,uvs:w,indices:x};g&&(a.tangents=pc.calculateTangents(y,u,w,x));return pc.createMesh(f,y,a)};
- pc._createConeData=function(f,b,a,c,d,e){var g,l,k,p,h,n=new pc.Vec3,q=new pc.Vec3;k=new pc.Vec3;var m,r=[],t=[],v=[],y=[],u=[],w;if(0<a)for(g=0;g<=c;g++)for(l=0;l<=d;l++)w=l/d*2*Math.PI-Math.PI,m=Math.sin(w),w=Math.cos(w),h=new pc.Vec3(m*f,-a/2,w*f),p=new pc.Vec3(m*b,a/2,w*b),n.lerp(h,p,g/c),q.sub2(p,h).normalize(),m=new pc.Vec3(w,0,-m),k.cross(m,q).normalize(),r.push(n.x,n.y,n.z),t.push(k.x,k.y,k.z),p=l/d,h=g/c,v.push(p,h),m=h,h=p,p=m,p/=3,p=p*primitiveUv1PaddingScale+primitiveUv1Padding,h=h*primitiveUv1PaddingScale+
- primitiveUv1Padding,y.push(p,h),g<c&&l<d&&(m=g*(d+1)+l,w=g*(d+1)+(l+1),p=(g+1)*(d+1)+l,h=(g+1)*(d+1)+(l+1),u.push(m,w,p),u.push(w,h,p));if(e){f=Math.floor(d/2);g=a/2;for(a=0;a<=f;a++)for(w=a*Math.PI*.5/f,m=Math.sin(w),w=Math.cos(w),n=0;n<=d;n++)e=2*n*Math.PI/d-Math.PI/2,p=Math.sin(e),e=Math.cos(e),e*=m,l=w,k=p*m,p=1-n/d,h=1-a/f,r.push(e*b,l*b+g,k*b),t.push(e,l,k),v.push(p,h),p/=3,h/=3,p=p*primitiveUv1PaddingScale+primitiveUv1Padding,h=h*primitiveUv1PaddingScale+primitiveUv1Padding,p+=1/3,y.push(p,
- h);q=(c+1)*(d+1);for(a=0;a<f;++a)for(n=0;n<d;++n)m=a*(d+1)+n,w=m+d+1,u.push(q+m+1,q+w,q+m),u.push(q+m+1,q+w+1,q+w);for(a=0;a<=f;a++)for(w=.5*Math.PI+a*Math.PI*.5/f,m=Math.sin(w),w=Math.cos(w),n=0;n<=d;n++)e=2*n*Math.PI/d-Math.PI/2,p=Math.sin(e),e=Math.cos(e),e*=m,l=w,k=p*m,p=1-n/d,h=1-a/f,r.push(e*b,l*b-g,k*b),t.push(e,l,k),v.push(p,h),p/=3,h/=3,p=p*primitiveUv1PaddingScale+primitiveUv1Padding,h=h*primitiveUv1PaddingScale+primitiveUv1Padding,p+=2/3,y.push(p,h);q=(c+1)*(d+1)+(d+1)*(f+1);for(a=0;a<
- f;++a)for(n=0;n<d;++n)m=a*(d+1)+n,w=m+d+1,u.push(q+m+1,q+w,q+m),u.push(q+m+1,q+w+1,q+w)}else{q=(c+1)*(d+1);if(0<f)for(g=0;g<d;g++)w=g/d*2*Math.PI,e=Math.sin(w),l=-a/2,k=Math.cos(w),p=1-(e+1)/2,h=(k+1)/2,r.push(e*f,l,k*f),t.push(0,-1,0),v.push(p,h),p/=3,h/=3,p=p*primitiveUv1PaddingScale+primitiveUv1Padding,h=h*primitiveUv1PaddingScale+primitiveUv1Padding,p+=1/3,y.push(p,h),1<g&&u.push(q,q+g,q+g-1);q+=d;if(0<b)for(g=0;g<d;g++)w=g/d*2*Math.PI,e=Math.sin(w),l=a/2,k=Math.cos(w),p=1-(e+1)/2,h=(k+1)/2,r.push(e*
- b,l,k*b),t.push(0,1,0),v.push(p,h),p/=3,h/=3,p=p*primitiveUv1PaddingScale+primitiveUv1Padding,h=h*primitiveUv1PaddingScale+primitiveUv1Padding,p+=2/3,y.push(p,h),1<g&&u.push(q,q+g-1,q+g)}return{positions:r,normals:t,uvs:v,uvs1:y,indices:u}};
- pc.createCylinder=function(f,b){var a=b&&(b.radius||b.baseRadius),a=void 0!==a?a:.5,c=b&&void 0!==b.calculateTangents?b.calculateTangents:!1,a=pc._createConeData(a,a,b&&void 0!==b.height?b.height:1,b&&void 0!==b.heightSegments?b.heightSegments:5,b&&void 0!==b.capSegments?b.capSegments:20,!1);c&&(a.tangents=pc.calculateTangents(a.positions,a.normals,a.uvs,a.indices));return pc.createMesh(f,a.positions,a)};
- pc.createCapsule=function(f,b){var a=b&&void 0!==b.radius?b.radius:.3,c=b&&void 0!==b.calculateTangents?b.calculateTangents:!1,a=pc._createConeData(a,a,(b&&void 0!==b.height?b.height:1)-2*a,b&&void 0!==b.heightSegments?b.heightSegments:1,b&&void 0!==b.sides?b.sides:20,!0);c&&(a.tangents=pc.calculateTangents(a.positions,a.normals,a.uvs,a.indices));return pc.createMesh(f,a.positions,a)};
- pc.createCone=function(f,b){var a=b&&void 0!==b.calculateTangents?b.calculateTangents:!1,c=pc._createConeData(b&&void 0!==b.baseRadius?b.baseRadius:.5,b&&void 0!==b.peakRadius?b.peakRadius:0,b&&void 0!==b.height?b.height:1,b&&void 0!==b.heightSegments?b.heightSegments:5,b&&void 0!==b.capSegments?b.capSegments:18,!1);a&&(c.tangents=pc.calculateTangents(c.positions,c.normals,c.uvs,c.indices));return pc.createMesh(f,c.positions,c)};
- pc.createSphere=function(f,b){var a=b&&void 0!==b.radius?b.radius:.5,c=b&&void 0!==b.latitudeBands?b.latitudeBands:16,d=b&&void 0!==b.longitudeBands?b.longitudeBands:16,e=b&&void 0!==b.calculateTangents?b.calculateTangents:!1,g,l,k,p,h,n,q,m,r,t=[],v=[],y=[],u=[];for(l=0;l<=c;l++)for(g=l*Math.PI/c,k=Math.sin(g),p=Math.cos(g),g=0;g<=d;g++)h=2*g*Math.PI/d-Math.PI/2,n=Math.sin(h),h=Math.cos(h),h*=k,q=p,n*=k,m=1-g/d,r=1-l/c,t.push(h*a,q*a,n*a),v.push(h,q,n),y.push(m,r);for(l=0;l<c;++l)for(g=0;g<d;++g)a=
- l*(d+1)+g,k=a+d+1,u.push(a+1,k,a),u.push(a+1,k+1,k);c={normals:v,uvs:y,uvs1:y,indices:u};e&&(c.tangents=pc.calculateTangents(t,v,y,u));return pc.createMesh(f,t,c)};
- pc.createPlane=function(f,b){var a=b&&void 0!==b.halfExtents?b.halfExtents:new pc.Vec2(.5,.5),c=b&&void 0!==b.widthSegments?b.widthSegments:5,d=b&&void 0!==b.lengthSegments?b.lengthSegments:5,e=b&&void 0!==b.calculateTangents?b.calculateTangents:!1,g,l,k,p,h,n,q=[],m=[],r=[],t=[],v=0;for(g=0;g<=c;g++)for(l=0;l<=d;l++)k=-a.x+2*a.x*g/c,p=-(-a.y+2*a.y*l/d),h=g/c,n=l/d,q.push(k,0,p),m.push(0,1,0),r.push(h,n),g<c&&l<d&&(t.push(v+d+1,v+1,v),t.push(v+d+1,v+d+2,v+1)),v++;a={normals:m,uvs:r,uvs1:r,indices:t};
- e&&(a.tangents=pc.calculateTangents(q,m,r,t));return pc.createMesh(f,q,a)};
- pc.createBox=function(f,b){var a=b&&void 0!==b.halfExtents?b.halfExtents:new pc.Vec3(.5,.5,.5),c=b&&void 0!==b.widthSegments?b.widthSegments:1,d=b&&void 0!==b.lengthSegments?b.lengthSegments:1,e=b&&void 0!==b.heightSegments?b.heightSegments:1,g=b&&void 0!==b.calculateTangents?b.calculateTangents:!1,l=[new pc.Vec3(-a.x,-a.y,a.z),new pc.Vec3(a.x,-a.y,a.z),new pc.Vec3(a.x,a.y,a.z),new pc.Vec3(-a.x,a.y,a.z),new pc.Vec3(a.x,-a.y,-a.z),new pc.Vec3(-a.x,-a.y,-a.z),new pc.Vec3(-a.x,a.y,-a.z),new pc.Vec3(a.x,
- a.y,-a.z)],k=[[0,1,3],[4,5,7],[3,2,6],[1,0,4],[1,4,2],[5,0,6]],p=[[0,0,1],[0,0,-1],[0,1,0],[0,-1,0],[1,0,0],[-1,0,0]],h=[],n=[],q=[],m=[],r=[],t=0,a=function(a,b,c){var d,e,g,f;for(g=0;g<=b;g++)for(f=0;f<=c;f++){d=new pc.Vec3;e=new pc.Vec3;var v=new pc.Vec3,u=new pc.Vec3;d.lerp(l[k[a][0]],l[k[a][1]],g/b);e.lerp(l[k[a][0]],l[k[a][2]],f/c);v.sub2(e,l[k[a][0]]);u.add2(d,v);d=g/b;e=f/c;h.push(u.x,u.y,u.z);n.push(p[a][0],p[a][1],p[a][2]);q.push(d,e);d/=3;e/=3;d=d*primitiveUv1PaddingScale+primitiveUv1Padding;
- e=e*primitiveUv1PaddingScale+primitiveUv1Padding;d+=a%3/3;e+=Math.floor(a/3)/3;m.push(d,e);g<b&&f<c&&(r.push(t+c+1,t+1,t),r.push(t+c+1,t+c+2,t+1));t++}};a(0,c,e);a(1,c,e);a(2,c,d);a(3,c,d);a(4,d,e);a(5,d,e);c={normals:n,uvs:q,uvs1:m,indices:r};g&&(c.tangents=pc.calculateTangents(h,n,q,r));return pc.createMesh(f,h,c)};pc.getDefaultMaterial=function(){return pc.Application.getApplication().scene.defaultMaterial};Object.assign(pc,function(){function f(a,b){return a.priority-b.priority}function b(a,b){return b.key-a.key}var a,c,d,e,g=[null,function(a,b){return a.drawOrder-b.drawOrder},function(b,d){a=b._key[pc.SORTKEY_FORWARD];c=d._key[pc.SORTKEY_FORWARD];return a===c&&b.mesh&&d.mesh?d.mesh.id-b.mesh.id:c-a},function(a,b){return b.zdist-a.zdist},function(a,b){return a.zdist-b.zdist}],l=0,k=function(){this.opaqueMeshInstances=[];this.transparentMeshInstances=[];this.shadowCasters=[];this.visibleOpaque=[];this.visibleTransparent=
- []};k.prototype.clearVisibleLists=function(a){this.visibleOpaque[a]&&(this.visibleOpaque[a].length=0,this.visibleOpaque[a].list.length=0);this.visibleTransparent[a]&&(this.visibleTransparent[a].length=0,this.visibleTransparent[a].list.length=0)};var p=function(a){a=a||{};void 0!==a.id?(this.id=a.id,l=Math.max(this.id+1,l)):this.id=l++;this.name=a.name;this._refCounter=(this._enabled=void 0===a.enabled?!0:a.enabled)?1:0;this.opaqueSortMode=void 0===a.opaqueSortMode?pc.SORTMODE_MATERIALMESH:a.opaqueSortMode;
- this.transparentSortMode=void 0===a.transparentSortMode?pc.SORTMODE_BACK2FRONT:a.transparentSortMode;this.renderTarget=a.renderTarget;this.shaderPass=void 0===a.shaderPass?pc.SHADER_FORWARD:a.shaderPass;this.passThrough=void 0===a.passThrough?!1:a.passThrough;this.overrideClear=void 0===a.overrideClear?!1:a.overrideClear;this._clearColor=new pc.Color(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?pc.CLEARFLAG_COLOR:0)|(this._clearDepthBuffer?pc.CLEARFLAG_DEPTH:0)|(this._clearStencilBuffer?pc.CLEARFLAG_STENCIL: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 k;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};Object.defineProperty(p.prototype,"enabled",{get:function(){return this._enabled},set:function(a){if(a!==this._enabled)if(this._enabled=a){if(this.incrementCounter(),this.onEnable)this.onEnable()}else if(this.decrementCounter(),this.onDisable)this.onDisable()}});Object.defineProperty(p.prototype,"clearColor",{get:function(){return this._clearColor},set:function(a){this._clearColor.copy(a)}});p.prototype._updateClearFlags=function(){var a=0;this._clearColorBuffer&&(a|=pc.CLEARFLAG_COLOR);
- this._clearDepthBuffer&&(a|=pc.CLEARFLAG_DEPTH);this._clearStencilBuffer&&(a|=pc.CLEARFLAG_STENCIL);this._clearOptions.flags=a};Object.defineProperty(p.prototype,"clearColorBuffer",{get:function(){return this._clearColorBuffer},set:function(a){this._clearColorBuffer=a;this._updateClearFlags()}});Object.defineProperty(p.prototype,"clearDepthBuffer",{get:function(){return this._clearDepthBuffer},set:function(a){this._clearDepthBuffer=a;this._updateClearFlags()}});Object.defineProperty(p.prototype,"clearStencilBuffer",
- {get:function(){return this._clearStencilBuffer},set:function(a){this._clearStencilBuffer=a;this._updateClearFlags()}});p.prototype.incrementCounter=function(){if(0===this._refCounter&&(this._enabled=!0,this.onEnable))this.onEnable();this._refCounter++};p.prototype.decrementCounter=function(){if(1===this._refCounter){if(this._enabled=!1,this.onDisable)this.onDisable()}else if(0===this._refCounter)return;this._refCounter--};p.prototype.addMeshInstances=function(a,b){for(var c=this._shaderVersion,d,
- e,g,f=this.shadowCasters,l=0;l<a.length;l++)d=a[l],g=d.material,e=g.blendType===pc.BLEND_NONE?this.opaqueMeshInstances:this.transparentMeshInstances,0>e.indexOf(d)&&e.push(d),!b&&d.castShadow&&0>f.indexOf(d)&&f.push(d),!this.passThrough&&0<=c&&g._shaderVersion!==c&&(g.updateShader!==pc.Material.prototype.updateShader&&(g.clearVariants(),g.shader=null),g._shaderVersion=c);this.passThrough||(this._dirty=!0)};p.prototype.removeMeshInstances=function(a,b){var c,d,e,g,f,l,k,h=this.opaqueMeshInstances,
- p=this.transparentMeshInstances,n=this.shadowCasters;for(c=0;c<a.length;c++){e=a[c];g=-1;f=0;l=h.length;for(d=0;d<l;d++){k=h[d];if(k===e){g=d;f=1;break}if(k._staticSource===e)0>g&&(g=d),f++;else if(0<=g)break}0<=g&&h.splice(g,f);g=-1;f=0;l=p.length;for(d=0;d<l;d++){k=p[d];if(k===e){g=d;f=1;break}if(k._staticSource===e)0>g&&(g=d),f++;else if(0<=g)break}0<=g&&p.splice(g,f);b||(d=n.indexOf(e),0<=d&&n.splice(d,1))}this._dirty=!0};p.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)};p.prototype.addLight=function(a){0<=this._lightComponents.indexOf(a)||(this._lightComponents.push(a),this._lights.push(a.light),this._dirtyLights=!0,this._generateLightHash())};p.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())};p.prototype.clearLights=function(){this._lightComponents.length=0;this._lights.length=0;this._dirtyLights=!0};p.prototype.addShadowCasters=function(a){for(var b,c=this.shadowCasters,d=0;d<a.length;d++)b=a[d],b.castShadow&&0>c.indexOf(b)&&c.push(b);this._dirtyLights=!0};p.prototype.removeShadowCasters=function(a){for(var b,c=this.shadowCasters,d=0;d<a.length;d++)b=c.indexOf(a[d]),0<=b&&c.splice(b,
- 1);this._dirtyLights=!0};p.prototype._generateLightHash=function(){if(0<this._lights.length){this._lights.sort(b);for(var a="",c="",d=0;d<this._lights.length;d++)this._lights[d].isStatic?c+=this._lights[d].key:a+=this._lights[d].key;this._lightHash=0===a.length?0:pc.hashCode(a);this._staticLightHash=0===c.length?0:pc.hashCode(c)}else this._staticLightHash=this._lightHash=0};p.prototype._generateCameraHash=function(){if(1<this.cameras.length){this.cameras.sort(f);for(var a="",b=0;b<this.cameras.length;b++)a+=
- this.cameras[b].entity.getGuid();this._cameraHash=pc.hashCode(a)}else this._cameraHash=0;this._dirtyCameras=!0};p.prototype.addCamera=function(a){0<=this.cameras.indexOf(a)||(this.cameras.push(a),this._generateCameraHash())};p.prototype.removeCamera=function(a){a=this.cameras.indexOf(a);0>a||(this.cameras.splice(a,1),this._generateCameraHash(),this.instances.clearVisibleLists(a))};p.prototype.clearCameras=function(){this._cameraHash=this.cameras.length=0;this._dirtyCameras=!0};p.prototype._sortCameras=
- function(){this._generateCameraHash()};p.prototype._calculateSortDistances=function(a,b,c,d){var e,g,f,l,k;for(e=0;e<b;e++)g=a[e],g.command||g.layer<=pc.LAYER_FX||(f=g.aabb.center,l=f.x-c.x,k=f.y-c.y,f=f.z-c.z,g.zdist=l*d.x+k*d.y+f*d.z)};p.prototype._sortVisible=function(a,b,c){var f=this.instances,l=a?this.transparentSortMode:this.opaqueSortMode;if(l!==pc.SORTMODE_NONE)if(a=a?f.visibleTransparent[c]:f.visibleOpaque[c],l===pc.SORTMODE_CUSTOM)d=b.getPosition(),e=b.forward,this.customCalculateSortValues&&
- this.customCalculateSortValues(a.list,a.length,d,e),a.list.length!==a.length&&(a.list.length=a.length),this.customSortCallback&&a.list.sort(this.customSortCallback);else{if(l===pc.SORTMODE_BACK2FRONT||l===pc.SORTMODE_FRONT2BACK)d=b.getPosition(),e=b.forward,this._calculateSortDistances(a.list,a.length,d,e);a.list.length!==a.length&&(a.list.length=a.length);a.list.sort(g[l])}};return{Layer:p,InstanceList:k,VisibleInstanceList:function(){this.list=[];this.length=0;this.done=!1}}}());Object.assign(pc,function(){var f=function(){this.layerList=[];this.subLayerList=[];this.subLayerEnabled=[];this._opaqueOrder={};this._transparentOrder={};this._dirtyCameras=this._dirtyLights=this._dirtyBlend=this._dirty=!1;this._meshInstances=[];this._lights=[];this.cameras=[];this._sortedLights=[[],[],[]];this._lightShadowCasters=[];this._globalLightCameras=[];this._globalLightCameraIds=[];this._renderedRt=[];this._renderedByCam=[];this._renderedLayer=[];this._renderList=[];this._renderListCamera=
- [];pc.events.attach(this)};f.prototype._sortLights=function(b){var a,c=b._lights;b._sortedLights[pc.LIGHTTYPE_DIRECTIONAL].length=0;b._sortedLights[pc.LIGHTTYPE_POINT].length=0;for(var d=b._sortedLights[pc.LIGHTTYPE_SPOT].length=0;d<c.length;d++)a=c[d],a._enabled&&b._sortedLights[a._type].push(a)};f.prototype._update=function(){var b,a,c,d,e=this.layerList.length,g=0;if(!this._dirty||!this._dirtyLights||!this._dirtyCameras)for(b=0;b<e;b++)d=this.layerList[b],d._dirty&&(this._dirty=!0),d._dirtyLights&&
- (this._dirtyLights=!0),d._dirtyCameras&&(this._dirtyCameras=!0);var f;if(this._dirty){g|=pc.COMPUPDATED_INSTANCES;for(b=this._meshInstances.length=0;b<e;b++)if(d=this.layerList[b],!d.passThrough){f=d.opaqueMeshInstances;for(a=0;a<f.length;a++)c=f[a],0>this._meshInstances.indexOf(c)&&(this._meshInstances.push(c),c.material&&c.material._dirtyBlend&&(this._dirtyBlend=!0,c.material._dirtyBlend=!1));f=d.transparentMeshInstances;for(a=0;a<f.length;a++)c=f[a],0>this._meshInstances.indexOf(c)&&(this._meshInstances.push(c),
- c.material&&c.material._dirtyBlend&&(this._dirtyBlend=!0,c.material._dirtyBlend=!1))}for(b=0;b<e;b++)this.layerList[b]._dirty=!1,this.layerList[b]._version++}if(this._dirtyBlend){var g=g|pc.COMPUPDATED_BLEND,k,p;for(b=0;b<e;b++)if(d=this.layerList[b],!d.passThrough){f=d.opaqueMeshInstances;c=d.transparentMeshInstances;k=[];p=[];for(a=0;a<f.length;a++)f[a].material&&f[a].material.blendType!==pc.BLEND_NONE?p.push(f[a]):k.push(f[a]);for(a=0;a<c.length;a++)c[a].material&&c[a].material.blendType!==pc.BLEND_NONE?
- p.push(c[a]):k.push(c[a]);d.opaqueMeshInstances.length=k.length;for(a=0;a<k.length;a++)d.opaqueMeshInstances[a]=k[a];d.transparentMeshInstances.length=p.length;for(a=0;a<p.length;a++)d.transparentMeshInstances[a]=p[a]}this._dirtyBlend=!1}this._dirty=!1;if(this._dirtyLights)for(g|=pc.COMPUPDATED_LIGHTS,this._lights.length=0,b=this._lightShadowCasters.length=0;b<e;b++)for(d=this.layerList[b],f=d._lights,a=0;a<f.length;a++)k=f[a],c=this._lights.indexOf(k),0>c&&(this._lights.push(k),c=this._lights.length-
- 1),(k=this._lightShadowCasters[c])||(this._lightShadowCasters[c]=[]);if(this._dirtyLights)for(this._sortLights(this),this._dirtyLights=!1,b=0;b<e;b++)d=this.layerList[b],this._sortLights(d),d._dirtyLights=!1;if(g)for(b=0;b<e;b++)for(d=this.layerList[b],f=d._lights,a=0;a<f.length;a++){k=f[a];c=this._lights.indexOf(k);k=this._lightShadowCasters[c];p=d.shadowCasters;for(c=0;c<k.length;)0>this._meshInstances.indexOf(k[c])?(k[c]=k[k.length-1],--k.length):c++;for(c=0;c<p.length;c++)0>k.indexOf(p[c])&&k.push(p[c])}if(g&
- pc.COMPUPDATED_LIGHTS||this._dirtyCameras)for(this._globalLightCameras.length=0,f=this._sortedLights[pc.LIGHTTYPE_DIRECTIONAL],a=0;a<f.length;a++)for(k=f[a],this._globalLightCameras[a]=[],b=0;b<e;b++)if(d=this.layerList[b],!(0>d._sortedLights[pc.LIGHTTYPE_DIRECTIONAL].indexOf(k)))for(c=0;c<d.cameras.length;c++)0<=this._globalLightCameras[a].indexOf(d.cameras[c])||this._globalLightCameras[a].push(d.cameras[c]);if(this._dirtyCameras){g|=pc.COMPUPDATED_CAMERAS;for(b=this.cameras.length=0;b<e;b++)for(d=
- this.layerList[b],a=0;a<d.cameras.length;a++)f=d.cameras[a],c=this.cameras.indexOf(f),0>c&&this.cameras.push(f);this._renderList.length=0;for(b=c=this._renderListCamera.length=0;b<e;b++)if(c)c--;else if(d=this.layerList[b],0!==d.cameras.length||d.isPostEffect)if(k=d._cameraHash,0===k)this._renderList.push(b),this._renderListCamera.push(0);else{f=1;for(a=b+1;a<e;a++)if(p=this.layerList[a]._cameraHash,k!==p){f=a-b-1;break}else a===e-1&&(f=a-b);if(1===f)for(k=0;k<d.cameras.length;k++)this._renderList.push(b),
- this._renderListCamera.push(k);else{for(k=0;k<d.cameras.length;k++)for(a=0;a<=f;a++)this._renderList.push(b+a),this._renderListCamera.push(k);c=f}}this._dirtyCameras=!1;for(b=0;b<e;b++)this.layerList[b]._dirtyCameras=!1}if(g&pc.COMPUPDATED_LIGHTS||g&pc.COMPUPDATED_CAMERAS)for(a=this._globalLightCameraIds.length=0;a<this._globalLightCameras.length;a++){f=[];for(b=0;b<this._globalLightCameras[a].length;b++)c=this.cameras.indexOf(this._globalLightCameras[a][b]),0>c||f.push(c);this._globalLightCameraIds.push(f)}return g};
- f.prototype._isLayerAdded=function(b){return 0<=this.layerList.indexOf(b)?!0:!1};f.prototype._isSublayerAdded=function(b,a){for(var c=0;c<this.layerList.length;c++)if(this.layerList[c]===b&&this.subLayerList[c]===a)return!0;return!1};f.prototype.push=function(b){this._isLayerAdded(b)||(this.layerList.push(b),this.layerList.push(b),this._opaqueOrder[b.id]=this.subLayerList.push(!1)-1,this._transparentOrder[b.id]=this.subLayerList.push(!0)-1,this.subLayerEnabled.push(!0),this.subLayerEnabled.push(!0),
- this._dirtyCameras=this._dirtyLights=this._dirty=!0,this.fire("add",b))};f.prototype.insert=function(b,a){if(!this._isLayerAdded(b)){this.layerList.splice(a,0,b,b);this.subLayerList.splice(a,0,!1,!0);var c=this.layerList.length;this._updateOpaqueOrder(a,c-1);this._updateTransparentOrder(a,c-1);this.subLayerEnabled.splice(a,0,!0,!0);this._dirtyCameras=this._dirtyLights=this._dirty=!0;this.fire("add",b)}};f.prototype.remove=function(b){var a=this.layerList.indexOf(b);delete this._opaqueOrder[a];for(delete this._transparentOrder[a];0<=
- a;)this.layerList.splice(a,1),this.subLayerList.splice(a,1),this.subLayerEnabled.splice(a,1),a=this.layerList.indexOf(b),this._dirtyCameras=this._dirtyLights=this._dirty=!0,this.fire("remove",b);b=this.layerList.length;this._updateOpaqueOrder(0,b-1);this._updateTransparentOrder(0,b-1)};f.prototype.pushOpaque=function(b){this._isSublayerAdded(b,!1)||(this.layerList.push(b),this._opaqueOrder[b.id]=this.subLayerList.push(!1)-1,this.subLayerEnabled.push(!0),this._dirtyCameras=this._dirtyLights=this._dirty=
- !0,this.fire("add",b))};f.prototype.insertOpaque=function(b,a){this._isSublayerAdded(b,!1)||(this.layerList.splice(a,0,b),this.subLayerList.splice(a,0,!1),this._updateOpaqueOrder(a,this.subLayerList.length-1),this.subLayerEnabled.splice(a,0,!0),this._dirtyCameras=this._dirtyLights=this._dirty=!0,this.fire("add",b))};f.prototype.removeOpaque=function(b){for(var a=0,c=this.layerList.length;a<c;a++)if(this.layerList[a]===b&&!this.subLayerList[a]){this.layerList.splice(a,1);this.subLayerList.splice(a,
- 1);c--;this._updateOpaqueOrder(a,c-1);this.subLayerEnabled.splice(a,1);this._dirtyCameras=this._dirtyLights=this._dirty=!0;0>this.layerList.indexOf(b)&&this.fire("remove",b);break}};f.prototype.pushTransparent=function(b){this._isSublayerAdded(b,!0)||(this.layerList.push(b),this._transparentOrder[b.id]=this.subLayerList.push(!0)-1,this.subLayerEnabled.push(!0),this._dirtyCameras=this._dirtyLights=this._dirty=!0,this.fire("add",b))};f.prototype.insertTransparent=function(b,a){this._isSublayerAdded(b,
- !0)||(this.layerList.splice(a,0,b),this.subLayerList.splice(a,0,!0),this._updateTransparentOrder(a,this.subLayerList.length-1),this.subLayerEnabled.splice(a,0,!0),this._dirtyCameras=this._dirtyLights=this._dirty=!0,this.fire("add",b))};f.prototype.removeTransparent=function(b){for(var a=0,c=this.layerList.length;a<c;a++)if(this.layerList[a]===b&&this.subLayerList[a]){this.layerList.splice(a,1);this.subLayerList.splice(a,1);c--;this._updateTransparentOrder(a,c-1);this.subLayerEnabled.splice(a,1);this._dirtyCameras=
- this._dirtyLights=this._dirty=!0;0>this.layerList.indexOf(b)&&this.fire("remove",b);break}};f.prototype._getSublayerIndex=function(b,a){var c=this.layerList.indexOf(b);return 0>c||this.subLayerList[c]!==a&&(c=this.layerList.indexOf(b,c+1),0>c||this.subLayerList[c]!==a)?-1:c};f.prototype.getOpaqueIndex=function(b){return this._getSublayerIndex(b,!1)};f.prototype.getTransparentIndex=function(b){return this._getSublayerIndex(b,!0)};f.prototype.getLayerById=function(b){for(var a=0;a<this.layerList.length;a++)if(this.layerList[a].id===
- b)return this.layerList[a];return null};f.prototype.getLayerByName=function(b){for(var a=0;a<this.layerList.length;a++)if(this.layerList[a].name===b)return this.layerList[a];return null};f.prototype._updateOpaqueOrder=function(b,a){for(var c=b;c<=a;c++)!1===this.subLayerList[c]&&(this._opaqueOrder[this.layerList[c].id]=c)};f.prototype._updateTransparentOrder=function(b,a){for(var c=b;c<=a;c++)!0===this.subLayerList[c]&&(this._transparentOrder[this.layerList[c].id]=c)};f.prototype._sortLayersDescending=
- function(b,a,c){var d,e,g,f=-1,k=-1;d=0;for(e=b.length;d<e;d++)g=b[d],c.hasOwnProperty(g)&&(f=Math.max(f,c[g]));d=0;for(e=a.length;d<e;d++)g=a[d],c.hasOwnProperty(g)&&(k=Math.max(k,c[g]));return-1===f&&-1!==k?1:-1===k&&-1!==f?-1:k-f};f.prototype.sortTransparentLayers=function(b,a){return this._sortLayersDescending(b,a,this._transparentOrder)};f.prototype.sortOpaqueLayers=function(b,a){return this._sortLayersDescending(b,a,this._opaqueOrder)};return{LayerComposition:f}}());Object.assign(pc,function(){pc.SPRITE_RENDERMODE_SIMPLE=0;pc.SPRITE_RENDERMODE_SLICED=1;pc.SPRITE_RENDERMODE_TILED=2;var f=[0,0,1,0,0,1,0,0,1,0,0,1],b=[0,1,3,2,3,1],a=function(a,b){this._device=a;this._pixelsPerUnit=b&&void 0!==b.pixelsPerUnit?b.pixelsPerUnit:1;this._renderMode=b&&void 0!==b.renderMode?b.renderMode:pc.SPRITE_RENDERMODE_SIMPLE;this._atlas=b&&void 0!==b.atlas?b.atlas:null;this._frameKeys=b&&void 0!==b.frameKeys?b.frameKeys:null;this._meshes=[];this._meshesDirty=this._updatingProperties=
- !1;pc.events.attach(this);this._atlas&&this._frameKeys&&this._createMeshes()};a.prototype._createMeshes=function(){var a,b;a=0;for(b=this._meshes.length;a<b;a++){var e=this._meshes[a];if(e){e.vertexBuffer.destroy();for(var g=0,f=e.indexBuffer.length;g<f;g++)e.indexBuffer[g].destroy()}}b=this._frameKeys.length;this._meshes=Array(b);e=this.renderMode===pc.SPRITE_RENDERMODE_SLICED||this._renderMode===pc.SPRITE_RENDERMODE_TILED?this._create9SliceMesh:this._createSimpleMesh;for(a=0;a<b;a++)g=this._atlas.frames[this._frameKeys[a]],
- this._meshes[a]=g?e.call(this,g):null;this.fire("set:meshes")};a.prototype._createSimpleMesh=function(a){var c=a.rect,e=this._atlas.texture.width,g=this._atlas.texture.height,l=c.z/this._pixelsPerUnit,k=c.w/this._pixelsPerUnit,p=a.pivot.x;a=a.pivot.y;var h=c.x/e,n=c.y/g,e=(c.x+c.z)/e,c=(c.y+c.w)/g;return pc.createMesh(this._device,[-p*l,-a*k,0,(1-p)*l,-a*k,0,(1-p)*l,(1-a)*k,0,-p*l,(1-a)*k,0],{uvs:[h,n,e,n,e,c,h,c],normals:f,indices:b})};a.prototype._create9SliceMesh=function(){var a=pc.Vec2.ONE,b,
- e,g,f,k,p,h=[],n=[],q=[],m=[],r=0;for(b=0;3>=b;b++)for(k=0===b||3===b?0:1,e=0;3>=e;e++)g=-a.x+2*a.x*(1>=b?0:3)/3,f=-(-a.y+2*a.y*(1>=e?0:3)/3),p=0===e||3===e?0:1,h.push(-g,0,f),n.push(0,1,0),q.push(k,p),3>b&&3>e&&(m.push(r+3+1,r+1,r),m.push(r+3+1,r+3+2,r+1)),r++;return pc.createMesh(this._device,h,{normals:n,uvs:q,indices:m})};a.prototype._onSetFrames=function(a){this._updatingProperties?this._meshesDirty=!0:this._createMeshes()};a.prototype._onFrameChanged=function(a,b){var c=this._frameKeys.indexOf(a);
- 0>c||(b?this.renderMode===pc.SPRITE_RENDERMODE_SIMPLE&&(this._meshes[c]=this._createSimpleMesh(b)):this._meshes[c]=null,this.fire("set:meshes"))};a.prototype._onFrameRemoved=function(a){a=this._frameKeys.indexOf(a);0>a||(this._meshes[a]=null,this.fire("set:meshes"))};a.prototype.startUpdate=function(){this._updatingProperties=!0;this._meshesDirty=!1};a.prototype.endUpdate=function(){this._updatingProperties=!1;this._meshesDirty&&this._atlas&&this._frameKeys&&this._createMeshes();this._meshesDirty=
- !1};a.prototype.destroy=function(){var a,b;a=0;for(b=this._meshes.length;a<b;a++){var e=this._meshes[a];if(e){e.vertexBuffer.destroy();for(var g=0,f=e.indexBuffer.length;g<f;g++)e.indexBuffer[g].destroy()}}this._meshes.length=0};Object.defineProperty(a.prototype,"frameKeys",{get:function(){return this._frameKeys},set:function(a){this._frameKeys=a;this._atlas&&this._frameKeys&&(this._updatingProperties?this._meshesDirty=!0:this._createMeshes());this.fire("set:frameKeys",a)}});Object.defineProperty(a.prototype,
- "atlas",{get:function(){return this._atlas},set:function(a){a!==this._atlas&&(this._atlas&&(this._atlas.off("set:frames",this._onSetFrames,this),this._atlas.off("set:frame",this._onFrameChanged,this),this._atlas.off("remove:frame",this._onFrameRemoved,this)),(this._atlas=a)&&this._frameKeys&&(this._atlas.on("set:frames",this._onSetFrames,this),this._atlas.on("set:frame",this._onFrameChanged,this),this._atlas.on("remove:frame",this._onFrameRemoved,this),this._updatingProperties?this._meshesDirty=!0:
- this._createMeshes()),this.fire("set:atlas",a))}});Object.defineProperty(a.prototype,"pixelsPerUnit",{get:function(){return this._pixelsPerUnit},set:function(a){this._pixelsPerUnit!==a&&(this._pixelsPerUnit=a,this.fire("set:pixelsPerUnit",a),this._atlas&&this._frameKeys&&this.renderMode===pc.SPRITE_RENDERMODE_SIMPLE&&(this._updatingProperties?this._meshesDirty=!0:this._createMeshes()))}});Object.defineProperty(a.prototype,"renderMode",{get:function(){return this._renderMode},set:function(a){if(this._renderMode!==
- a){var b=this._renderMode;this._renderMode=a;this.fire("set:renderMode",a);(b===pc.SPRITE_RENDERMODE_SIMPLE||a===pc.SPRITE_RENDERMODE_SIMPLE)&&this._atlas&&this._frameKeys&&(this._updatingProperties?this._meshesDirty=!0:this._createMeshes())}}});Object.defineProperty(a.prototype,"meshes",{get:function(){return this._meshes}});return{Sprite:a}}());Object.assign(pc,function(){var f=function(){this._index=[];this._values=[]};f.prototype.runSync=function(){for(var a=0,b=this._values.length;a<b;a++)this._values[a].syncHierarchy();this._values.length=0;this._index.length=0};f.prototype.erase=function(a){a=this._values.indexOf(a);0<=a&&(this._index.splice(a,1),this._values.splice(a,1))};var b=function(a,c,d,e){if(c===d)return c;var g=Math.floor((c+d)/2);return a[g]>e?b(a,c,g,e):a[g]<e?b(a,g+1,d,e):g};f.prototype.push=function(a,c){var d=b(this._index,
- 0,this._index.length,a);this._values.splice(d,0,c);this._index.splice(d,0,a)};return{SyncQueue:f}}());Object.assign(pc,function(){var f=function(){this._frames=this._texture=null;pc.events.attach(this)};f.prototype.setFrame=function(b,a){var c=this._frames[b];c?(c.rect.copy(a.rect),c.pivot.copy(a.pivot),c.border.copy(a.border)):(c={rect:a.rect.clone(),pivot:a.pivot.clone(),border:a.border.clone()},this._frames[b]=c);this.fire("set:frame",b.toString(),c)};f.prototype.removeFrame=function(b){var a=this._frames[b];a&&(delete this._frames[b],this.fire("remove:frame",b.toString(),a))};f.prototype.destroy=
- function(){this._texture&&this._texture.destroy()};Object.defineProperty(f.prototype,"texture",{get:function(){return this._texture},set:function(b){this._texture=b;this.fire("set:texture",b)}});Object.defineProperty(f.prototype,"frames",{get:function(){return this._frames},set:function(b){this._frames=b;this.fire("set:frames",b)}});return{TextureAtlas:f}}());Object.assign(pc,function(){var f=function(b){this.func=void 0===b.func?pc.FUNC_ALWAYS:b.func;this.ref=b.ref||0;this.readMask=void 0===b.readMask?255:b.readMask;this.writeMask=void 0===b.writeMask?255:b.writeMask;this.fail=b.fail||pc.STENCILOP_KEEP;this.zfail=b.zfail||pc.STENCILOP_KEEP;this.zpass=b.zpass||pc.STENCILOP_KEEP};f.prototype.clone=function(){return new pc.StencilParameters({func:this.func,ref:this.ref,readMask:this.readMask,writeMask:this.writeMask,fail:this.fail,zfail:this.zfail,zpass:this.zpass})};
- return{StencilParameters:f}}());Object.assign(pc,function(){var f=function(){this.name="";this.duration=0;this._nodes=[];this._nodeDict={}};f.prototype.getDuration=function(){return this.duration};f.prototype.getName=function(){return this.name};f.prototype.getNode=function(b){return this._nodeDict[b]};Object.defineProperty(f.prototype,"nodes",{get:function(){return this._nodes}});f.prototype.getNodes=function(){return this._nodes};f.prototype.setDuration=function(b){this.duration=b};f.prototype.setName=function(b){this.name=b};
- f.prototype.addNode=function(b){this._nodes.push(b);this._nodeDict[b._name]=b};return{Animation:f,Key:function(b,a,c,d){this.time=b;this.position=a;this.rotation=c;this.scale=d},Node:function(){this._name="";this._keys=[]}}}());Object.assign(pc,function(){function f(){this._written=!1;this._name="";this._keyFrames=[];this._quat=new pc.Quat;this._pos=new pc.Vec3;this._scale=new pc.Vec3;this._targetNode=null}Object.assign(f.prototype,{getTarget:function(){return this._targetNode},setTarget:function(a){this._targetNode=a}});var b=function(a){function b(a){var c=new f;c._name=a.name;d._interpolatedKeys.push(c);d._interpolatedKeyDict[a.name]=c;for(c=d._currKeyIndices[a.name]=0;c<a._children.length;c++)b(a._children[c])}this._animation=
- null;this._time=0;this.looping=!0;this._interpolatedKeys=[];this._interpolatedKeyDict={};this._currKeyIndices={};this.graph=null;var d=this;b(a)};b.prototype.addTime=function(a){if(null!==this._animation){var b,d,e,g,f,k,p,h=this._animation._nodes;b=this._animation.duration;if(this._time!==b||this.looping){this._time+=a;if(this._time>b)for(this._time=this.looping?0:b,b=0;b<h.length;b++)d=h[b],e=d._name,this._currKeyIndices[e]=0;else if(0>this._time)for(this._time=this.looping?b:0,b=0;b<h.length;b++)d=
- h[b],e=d._name,this._currKeyIndices[e]=d._keys.length-2;a=0<=a?1:-1;for(b=0;b<h.length;b++)if(d=h[b],e=d._name,d=d._keys,g=this._interpolatedKeyDict[e],void 0!==g){p=!1;if(1!==d.length)for(var n=this._currKeyIndices[e];n<d.length-1&&0<=n;n+=a)if(f=d[n],k=d[n+1],f.time<=this._time&&k.time>=this._time){p=(this._time-f.time)/(k.time-f.time);g._pos.lerp(f.position,k.position,p);g._quat.slerp(f.rotation,k.rotation,p);g._scale.lerp(f.scale,k.scale,p);g._written=!0;this._currKeyIndices[e]=n;p=!0;break}if(1===
- d.length||!p&&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}}}};b.prototype.blend=function(a,b,d){for(var c=this._interpolatedKeys.length,g=0;g<c;g++){var f=a._interpolatedKeys[g],k=b._interpolatedKeys[g],p=this._interpolatedKeys[g];f._written&&k._written?(p._quat.slerp(f._quat,b._interpolatedKeys[g]._quat,d),p._pos.lerp(f._pos,b._interpolatedKeys[g]._pos,d),p._scale.lerp(f._scale,k._scale,d),p._written=!0):f._written?(p._quat.copy(f._quat),
- p._pos.copy(f._pos),p._scale.copy(f._scale),p._written=!0):k._written&&(p._quat.copy(k._quat),p._pos.copy(k._pos),p._scale.copy(k._scale),p._written=!0)}};Object.defineProperty(b.prototype,"animation",{get:function(){return this._animation},set:function(a){this._animation=a;this.currentTime=0}});b.prototype.getAnimation=function(){return this._animation};Object.defineProperty(b.prototype,"currentTime",{get:function(){return this._time},set:function(a){this._time=a;a=this._interpolatedKeys.length;
- for(var b=0;b<a;b++)this._currKeyIndices[this._interpolatedKeys[b]._name]=0;this.addTime(0);this.updateGraph()}});b.prototype.getCurrentTime=function(){return this._time};b.prototype.setCurrentTime=function(a){this.currentTime=a};Object.defineProperty(b.prototype,"numNodes",{get:function(){return this._interpolatedKeys.length}});b.prototype.getNumNodes=function(){return this._interpolatedKeys.length};b.prototype.setAnimation=function(a){this.animation=a};b.prototype.setGraph=function(a){var b;if(this.graph=
- a)for(b=0;b<this._interpolatedKeys.length;b++){var d=a.findByName(this._interpolatedKeys[b]._name);this._interpolatedKeys[b].setTarget(d)}else for(b=0;b<this._interpolatedKeys.length;b++)this._interpolatedKeys[b].setTarget(null)};b.prototype.updateGraph=function(){if(this.graph)for(var a=0;a<this._interpolatedKeys.length;a++){var b=this._interpolatedKeys[a];if(b._written){var d=b.getTarget();d.localPosition.copy(b._pos);d.localRotation.copy(b._quat);d.localScale.copy(b._scale);d._dirtyLocal||d._dirtifyLocal();
- b._written=!1}}};b.prototype.setLooping=function(a){this.looping=a};b.prototype.getLooping=function(){return this.looping};return{Skeleton:b}}());Object.assign(pc,function(){function f(){return"undefined"!==typeof Audio}function b(){return!("undefined"===typeof AudioContext&&"undefined"===typeof webkitAudioContext)}var a=function(a){if(b()||a.forceWebAudioApi){if("undefined"!==typeof AudioContext?this.context=new AudioContext:"undefined"!==typeof webkitAudioContext&&(this.context=new webkitAudioContext),this.context){var c=this.context;this.resumeContext=function(){this.context.resume();window.removeEventListener("mousedown",this.resumeContext);
- window.removeEventListener("touchend",this.resumeContext)}.bind(this);window.addEventListener("mousedown",this.resumeContext);window.addEventListener("touchend",this.resumeContext);if(pc.platform.ios){var e=function(){var a=c.createBuffer(1,1,44100),b=c.createBufferSource();b.buffer=a;b.connect(c.destination);b.start(0);b.disconnect();window.removeEventListener("touchend",e)};window.addEventListener("touchend",e)}}}else console.warn("No support for 3D audio found");f()||console.warn("No support for 2D audio found");
- this.listener=new pc.Listener(this);this._volume=1;this.suspended=!1;pc.events.attach(this)};a.hasAudio=f;a.hasAudioContext=b;Object.assign(a.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)},
- getListener:function(){console.warn('DEPRECATED: getListener is deprecated. Get the "listener" field instead.');return this.listener},getVolume:function(){console.warn('DEPRECATED: getVolume is deprecated. Get the "volume" property instead.');return this.volume},setVolume:function(a){console.warn('DEPRECATED: setVolume is deprecated. Set the "volume" property instead.');this.volume=a},playSound:function(a,b){b=b||{};var c=null;pc.Channel&&(c=new pc.Channel(this,a,b),c.play());return c},playSound3d:function(a,
- b,e){e=e||{};var c=null;pc.Channel3d&&(c=new pc.Channel3d(this,a,e),c.setPosition(b),e.volume&&c.setVolume(e.volume),e.loop&&c.setLoop(e.loop),e.maxDistance&&c.setMaxDistance(e.maxDistance),e.minDistance&&c.setMinDistance(e.minDistance),e.rollOffFactor&&c.setRollOffFactor(e.rollOffFactor),e.distanceModel&&c.setDistanceModel(e.distanceModel),c.play());return c}});Object.defineProperty(a.prototype,"volume",{get:function(){return this._volume},set:function(a){this._volume=a=pc.math.clamp(a,0,1);this.fire("volumechange",
- a)}});pc.AudioManager=a;return{SoundManager:a}}());Object.assign(pc,function(){var f=function(b){b instanceof Audio?this.audio=b:this.buffer=b};Object.defineProperty(f.prototype,"duration",{get:function(){var b=0;this.buffer?b=this.buffer.duration:this.audio&&(b=this.audio.duration);return b||0}});return{Sound:f}}());Object.assign(pc,function(){var f=function(b){this.position=new pc.Vec3;this.velocity=new pc.Vec3;this.orientation=new pc.Mat4;pc.AudioManager.hasAudioContext()&&(this.listener=b.context.listener)};Object.assign(f.prototype,{getPosition:function(){return this.position},setPosition:function(b){this.position.copy(b);this.listener&&this.listener.setPosition(b.x,b.y,b.z)},getVelocity:function(){return this.velocity},setVelocity:function(b){this.velocity.copy(b);this.listener&&this.listener.setPosition(b.x,
- b.y,b.z)},setOrientation:function(b){this.orientation.copy(b);this.listener&&this.listener.setOrientation(-b.data[8],-b.data[9],-b.data[10],b.data[4],b.data[5],b.data[6])},getOrientation:function(){return this.orientation}});return{Listener:f}}());Object.assign(pc,function(){var f;pc.SoundManager.hasAudioContext()?(f=function(b,a,c){pc.events.attach(this);c=c||{};this._volume=void 0!==c.volume?pc.math.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=a;this._state=2;this._suspendInstanceEvents=this._suspendEndEvent=this._suspended=!1;this._startTime=Math.max(0,Number(c.startTime)||0);this._duration=Math.max(0,Number(c.duration)||0);this._startedAt=
- 0;this._startOffset=null;this._currentOffset=this._currentTime=0;this._playWhenLoaded=!0;this._manager=b;this._lastNode=this._firstNode=this._connectorNode=this._inputNode=null;this._initializeNodes();this._onPlayCallback=c.onPlay;this._onPauseCallback=c.onPause;this._onResumeCallback=c.onResume;this._onStopCallback=c.onStop;this._onEndCallback=c.onEnd;this._endedHandler=this._onEnded.bind(this);this.source=null},Object.assign(f.prototype,{_initializeNodes:function(){this._connectorNode=this._inputNode=
- this.gain=this._manager.context.createGain();this._connectorNode.connect(this._manager.context.destination)},play:function(){2!==this._state&&this.stop();this.source||this._createSource();var b=this._startOffset%this.duration||0,b=(this._startTime+b)%this._sound.duration||0;this._startOffset=null;this._duration?this.source.start(0,b,this._duration):this.source.start(0,b);this._startedAt=this._manager.context.currentTime;this._currentTime=0;this._currentOffset=b;this._state=0;this._playWhenLoaded=
- !1;this.volume=this._volume;this.loop=this._loop;this.pitch=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.on("destroy",this._onManagerDestroy,this);this._manager.suspended&&this._onManagerSuspend();this._suspendInstanceEvents||this._onPlay();return!0},pause:function(){if(0!==this._state||!this.source)return!1;this._updateCurrentTime();this._state=
- 1;this._suspendEndEvent=!0;this.source.stop(0);this.source=null;this._playWhenLoaded=!1;this._startOffset=null;this._suspendInstanceEvents||this._onPause();return!0},resume:function(){if(1!==this._state)return!1;this.source||this._createSource();var b=this.currentTime;null!==this._startOffset&&(b=this._startOffset%this.duration||0,b=(this._startTime+b)%this._sound.duration||0,this._startOffset=null);this._duration?this.source.start(0,b,this._duration):this.source.start(0,b);this._state=0;this._startedAt=
- this._manager.context.currentTime;this._currentOffset=b;this.volume=this._volume;this.loop=this._loop;this.pitch=this._pitch;this._playWhenLoaded=!1;this._suspendInstanceEvents||this._onResume();return!0},stop:function(){if(2===this._state||!this.source)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._currentOffset=
- this._currentTime=this._startedAt=0;this._startOffset=null;this._playWhenLoaded=!1;this._suspendEndEvent=!0;0===this._state&&this.source.stop(0);this.source=null;this._state=2;this._suspendInstanceEvents||this._onStop();return!0},setExternalNodes:function(b,a){if(b){a||(a=b);var c=this._manager.context.destination;this._firstNode!==b&&(this._firstNode?this._connectorNode.disconnect(this._firstNode):this._connectorNode.disconnect(c),this._firstNode=b,this._connectorNode.connect(b));this._lastNode!==
- a&&(this._lastNode&&this._lastNode.disconnect(c),this._lastNode=a,this._lastNode.connect(c))}else console.error("The firstNode must be a valid Audio Node")},clearExternalNodes:function(){var b=this._manager.context.destination;this._firstNode&&(this._connectorNode.disconnect(this._firstNode),this._firstNode=null);this._lastNode&&(this._lastNode.disconnect(b),this._lastNode=null);this._connectorNode.connect(b)},getExternalNodes:function(){return[this._firstNode,this._lastNode]},_createSource:function(){if(!this._sound)return null;
- var b=this._manager.context;this._sound.buffer&&(this.source=b.createBufferSource(),this.source.buffer=this._sound.buffer,this.source.connect(this._inputNode),this.source.onended=this._endedHandler,this.source.loopStart=this._startTime%this.source.buffer.duration||0,this._duration&&(this.source.loopEnd=Math.max(this.source.loopStart,(this._startTime+this._duration)%this.source.buffer.duration||0)));return this.source},_updateCurrentTime:function(){this._currentTime=((this._manager.context.currentTime-
- this._startedAt)*this._pitch+this._currentOffset)%this.duration||0},_onManagerDestroy:function(){this.source&&0===this._state&&(this.source.stop(0),this.source=null)}}),Object.defineProperty(f.prototype,"volume",{get:function(){return this._volume},set:function(b){this._volume=b=pc.math.clamp(b,0,1);this.gain&&(this.gain.gain.value=b*this._manager.volume)}}),Object.defineProperty(f.prototype,"pitch",{get:function(){return this._pitch},set:function(b){this._currentOffset=this.currentTime;this._startedAt=
- this._manager.context.currentTime;this._pitch=Math.max(Number(b)||0,.01);this.source&&(this.source.playbackRate.value=this._pitch)}}),Object.defineProperty(f.prototype,"loop",{get:function(){return this._loop},set:function(b){this._loop=!!b;this.source&&(this.source.loop=this._loop)}}),Object.defineProperty(f.prototype,"sound",{get:function(){return this._sound},set:function(b){this._sound=b;2!==this._state?this.stop():this._createSource()}}),Object.defineProperty(f.prototype,"currentTime",{get:function(){if(null!==
- this._startOffset)return this._startOffset;if(1===this._state)return this._currentTime;if(2===this._state||!this.source)return 0;this._updateCurrentTime();return this._currentTime},set:function(b){if(!(0>b))if(0===this._state){this.stop();var a=this._suspendInstanceEvents;this._suspendInstanceEvents=!0;this._startOffset=b;this.play();this._suspendInstanceEvents=a}else this._currentTime=this._startOffset=b}})):pc.SoundManager.hasAudio()?(f=function(b,a,c){pc.events.attach(this);c=c||{};this._volume=
- void 0!==c.volume?pc.math.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=a;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=b;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()},Object.assign(f.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 b=this._startOffset%this.duration||0,b=(this._startTime+
- b)%this._sound.duration||0;this._startOffset=null;this.source.currentTime=b},_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.prototype,"volume",{get:function(){return this._volume},set:function(b){this._volume=b=pc.math.clamp(b,0,1);this.source&&(this.source.volume=b*this._manager.volume)}}),Object.defineProperty(f.prototype,"pitch",{get:function(){return this._pitch},
- set:function(b){this._pitch=Math.max(Number(b)||0,.01);this.source&&(this.source.playbackRate=this._pitch)}}),Object.defineProperty(f.prototype,"loop",{get:function(){return this._loop},set:function(b){this._loop=!!b;this.source&&(this.source.loop=this._loop)}}),Object.defineProperty(f.prototype,"sound",{get:function(){return this._sound},set:function(b){this.stop();this._sound=b}}),Object.defineProperty(f.prototype,"currentTime",{get:function(){return null!==this._startOffset?this._startOffset:2!==
- this._state&&this.source?this.source.currentTime-this._startTime:0},set:function(b){0>b||(this._startOffset=b,this.source&&this._isReady&&(this.source.currentTime=(this._startTime+(b%this.duration||0))%this._sound.duration||0,this._startOffset=null))}})):f=function(){};Object.assign(f.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.prototype,"startTime",{get:function(){return this._startTime},set:function(b){this._startTime=Math.max(0,Number(b)||0);b=0===this._state;this.stop();b&&this.play()}});Object.defineProperty(f.prototype,"duration",{get:function(){return this._sound?this._duration?this._duration%this._sound.duration||0:this._sound.duration:0},set:function(b){this._duration=Math.max(0,Number(b)||0);b=0===this._state;this.stop();b&&this.play()}});Object.defineProperty(f.prototype,
- "isPlaying",{get:function(){return 0===this._state}});Object.defineProperty(f.prototype,"isPaused",{get:function(){return 1===this._state}});Object.defineProperty(f.prototype,"isStopped",{get:function(){return 2===this._state}});Object.defineProperty(f.prototype,"isSuspended",{get:function(){return this._suspended}});return{SoundInstance:f}}());Object.assign(pc,function(){var f;if(pc.SoundManager.hasAudioContext())f=function(a,b,d){pc.SoundInstance.call(this,a,b,d);d=d||{};this._position=new pc.Vec3;d.position&&(this.position=d.position);this._velocity=new pc.Vec3;d.velocity&&(this.velocity=d.velocity);this.maxDistance=void 0!==d.maxDistance?Number(d.maxDistance):1E4;this.refDistance=void 0!==d.refDistance?Number(d.refDistance):1;this.rollOffFactor=void 0!==d.rollOffFactor?Number(d.rollOffFactor):1;this.distanceModel=void 0!==d.distanceModel?
- d.distanceModel:pc.DISTANCE_LINEAR},f.prototype=Object.create(pc.SoundInstance.prototype),f.prototype.constructor=f,Object.assign(f.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.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.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.prototype,"maxDistance",{get:function(){return this.panner.maxDistance},set:function(a){this.panner.maxDistance=a}}),Object.defineProperty(f.prototype,"refDistance",{get:function(){return this.panner.refDistance},set:function(a){this.panner.refDistance=
- a}}),Object.defineProperty(f.prototype,"rollOffFactor",{get:function(){return this.panner.rolloffFactor},set:function(a){this.panner.rolloffFactor=a}}),Object.defineProperty(f.prototype,"distanceModel",{get:function(){return this.panner.distanceModel},set:function(a){this.panner.distanceModel=a}});else if(pc.SoundManager.hasAudio()){var b=new pc.Vec3;f=function(a,b,d){pc.SoundInstance.call(this,a,b,d);d=d||{};this._position=new pc.Vec3;d.position&&(this.position=d.position);this._velocity=new pc.Vec3;
- d.velocity&&(this.velocity=d.velocity);this._maxDistance=void 0!==d.maxDistance?Number(d.maxDistance):1E4;this._refDistance=void 0!==d.refDistance?Number(d.refDistance):1;this._rollOffFactor=void 0!==d.rollOffFactor?Number(d.rollOffFactor):1;this._distanceModel=void 0!==d.distanceModel?d.distanceModel:pc.DISTANCE_LINEAR};f.prototype=Object.create(pc.SoundInstance.prototype);f.prototype.constructor=f;Object.defineProperty(f.prototype,"position",{get:function(){return this._position},set:function(a){this._position.copy(a);
- if(this.source){var c=this._manager.listener.getPosition();a=this.refDistance;var d=this.maxDistance,e=this.rollOffFactor,g=this.distanceModel;b=b.sub2(c,this._position);c=b.length();if(c<a)a=1;else if(c>d)a=0;else{var f=0;g===pc.DISTANCE_LINEAR?f=1-e*(c-a)/(d-a):g===pc.DISTANCE_INVERSE?f=a/(a+e*(c-a)):g===pc.DISTANCE_EXPONENTIAL&&(f=Math.pow(c/a,-e));a=pc.math.clamp(f,0,1)}this.source.volume=this.volume*a*this._manager.volume}}});Object.defineProperty(f.prototype,"velocity",{get:function(){return this._velocity},
- set:function(a){this._velocity.copy(a)}});Object.defineProperty(f.prototype,"maxDistance",{get:function(){return this._maxDistance},set:function(a){this._maxDistance=a}});Object.defineProperty(f.prototype,"refDistance",{get:function(){return this._refDistance},set:function(a){this._refDistance=a}});Object.defineProperty(f.prototype,"rollOffFactor",{get:function(){return this._rollOffFactor},set:function(a){this._rollOffFactor=a}});Object.defineProperty(f.prototype,"distanceModel",{get:function(){return this._distanceModel},
- set:function(a){this._distanceModel=a}})}else f=function(){};return{SoundInstance3d:f}}());Object.assign(pc,function(){var f;pc.AudioManager.hasAudioContext()?(f=function(b,a,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=a;this.suspended=this.paused=!1;this.startOffset=this.startTime=0;this.manager=b;this.source=null;this.gain=b.context.createGain()},Object.assign(f.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(b){this.loop=b;this.source&&(this.source.loop=b)},setVolume:function(b){this.volume=b=pc.math.clamp(b,0,1);this.gain&&(this.gain.gain.value=b*this.manager.volume)},setPitch:function(b){this.pitch=b;this.source&&(this.source.playbackRate.value=b)},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 b=this.manager.context;this.sound.buffer&&(this.source=b.createBufferSource(),this.source.buffer=this.sound.buffer,this.source.connect(this.gain),this.gain.connect(b.destination),this.loop||(this.source.onended=this.pause.bind(this)))}})):pc.AudioManager.hasAudio()?(f=function(b,a,c){this.volume=c.volume||1;this.loop=c.loop||!1;this.sound=a;this.pitch=void 0!==c.pitch?c.pitch:1;this.suspended=this.paused=!1;this.manager=b;a.audio&&(this.source=
- a.audio.cloneNode(!1),this.source.pause())},Object.assign(f.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(b){this.volume=b=pc.math.clamp(b,0,1);this.source&&(this.source.volume=b*this.manager.volume)},setLoop:function(b){this.loop=b;this.source&&(this.source.loop=b)},setPitch:function(b){this.pitch=
- b;this.source&&(this.source.playbackRate=b)},getDuration:function(){return this.source&&!isNaN(this.source.duration)?this.source.duration:0},isPlaying:function(){return!this.source.paused}})):f=function(){};Object.assign(f.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())}});return{Channel:f}}());Object.assign(pc,function(){var f;if(pc.AudioManager.hasAudioContext())f=function(a,b,d){pc.Channel.call(this,a,b,d);this.position=new pc.Vec3;this.velocity=new pc.Vec3;this.panner=a.context.createPanner()},f.prototype=Object.create(pc.Channel.prototype),f.prototype.constructor=f,Object.assign(f.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(pc.AudioManager.hasAudio()){var b=new pc.Vec3;f=function(a,b){pc.Channel.call(this,a,b);this.position=new pc.Vec3;this.velocity=new pc.Vec3;this.maxDistance=1E4;this.rollOffFactor=this.minDistance=1;this.distanceModel=
- pc.DISTANCE_INVERSE};f.prototype=Object.create(pc.Channel.prototype);f.prototype.constructor=f;Object.assign(f.prototype,{getPosition:function(){return this.position},setPosition:function(a){this.position.copy(a);if(this.source){var c=this.manager.listener.getPosition();a=this.minDistance;var d=this.maxDistance,e=this.rollOffFactor,g=this.distanceModel;b=b.sub2(c,this.position);c=b.length();if(c<a)a=1;else if(c>d)a=0;else{var f=0;g===pc.DISTANCE_LINEAR?f=1-e*(c-a)/(d-a):g===pc.DISTANCE_INVERSE?f=
- a/(a+e*(c-a)):g===pc.DISTANCE_EXPONENTIAL&&(f=Math.pow(c/a,-e));a=pc.math.clamp(f,0,1)}d=this.getVolume();this.source.volume=d*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 f=function(){};return{Channel3d:f}}());(function(){var f={ACTION_MOUSE:"mouse",ACTION_KEYBOARD:"keyboard",ACTION_GAMEPAD:"gamepad",AXIS_MOUSE_X:"mousex",AXIS_MOUSE_Y:"mousey",AXIS_PAD_L_X:"padlx",AXIS_PAD_L_Y:"padly",AXIS_PAD_R_X:"padrx",AXIS_PAD_R_Y:"padry",AXIS_KEY:"key",EVENT_KEYDOWN:"keydown",EVENT_KEYUP:"keyup",EVENT_MOUSEDOWN:"mousedown",EVENT_MOUSEMOVE:"mousemove",EVENT_MOUSEUP:"mouseup",EVENT_MOUSEWHEEL:"mousewheel",EVENT_TOUCHSTART:"touchstart",EVENT_TOUCHEND:"touchend",EVENT_TOUCHMOVE:"touchmove",EVENT_TOUCHCANCEL:"touchcancel",
- KEY_BACKSPACE:8,KEY_TAB:9,KEY_RETURN:13,KEY_ENTER:13,KEY_SHIFT:16,KEY_CONTROL:17,KEY_ALT:18,KEY_PAUSE:19,KEY_CAPS_LOCK:20,KEY_ESCAPE:27,KEY_SPACE:32,KEY_PAGE_UP:33,KEY_PAGE_DOWN:34,KEY_END:35,KEY_HOME:36,KEY_LEFT:37,KEY_UP:38,KEY_RIGHT:39,KEY_DOWN:40,KEY_PRINT_SCREEN:44,KEY_INSERT:45,KEY_DELETE:46,KEY_0:48,KEY_1:49,KEY_2:50,KEY_3:51,KEY_4:52,KEY_5:53,KEY_6:54,KEY_7:55,KEY_8:56,KEY_9:57,KEY_SEMICOLON:59,KEY_EQUAL:61,KEY_A:65,KEY_B:66,KEY_C:67,KEY_D:68,KEY_E:69,KEY_F:70,KEY_G:71,KEY_H:72,KEY_I:73,KEY_J:74,
- KEY_K:75,KEY_L:76,KEY_M:77,KEY_N:78,KEY_O:79,KEY_P:80,KEY_Q:81,KEY_R:82,KEY_S:83,KEY_T:84,KEY_U:85,KEY_V:86,KEY_W:87,KEY_X:88,KEY_Y:89,KEY_Z:90,KEY_WINDOWS:91,KEY_CONTEXT_MENU:93,KEY_NUMPAD_0:96,KEY_NUMPAD_1:97,KEY_NUMPAD_2:98,KEY_NUMPAD_3:99,KEY_NUMPAD_4:100,KEY_NUMPAD_5:101,KEY_NUMPAD_6:102,KEY_NUMPAD_7:103,KEY_NUMPAD_8:104,KEY_NUMPAD_9:105,KEY_MULTIPLY:106,KEY_ADD:107,KEY_SEPARATOR:108,KEY_SUBTRACT:109,KEY_DECIMAL:110,KEY_DIVIDE:111,KEY_F1:112,KEY_F2:113,KEY_F3:114,KEY_F4:115,KEY_F5:116,KEY_F6:117,
- KEY_F7:118,KEY_F8:119,KEY_F9:120,KEY_F10:121,KEY_F11:122,KEY_F12:123,KEY_COMMA:188,KEY_PERIOD:190,KEY_SLASH:191,KEY_OPEN_BRACKET:219,KEY_BACK_SLASH:220,KEY_CLOSE_BRACKET:221,KEY_META:224,MOUSEBUTTON_NONE:-1,MOUSEBUTTON_LEFT:0,MOUSEBUTTON_MIDDLE:1,MOUSEBUTTON_RIGHT:2,PAD_1:0,PAD_2:1,PAD_3:2,PAD_4:3,PAD_FACE_1:0,PAD_FACE_2:1,PAD_FACE_3:2,PAD_FACE_4:3,PAD_L_SHOULDER_1:4,PAD_R_SHOULDER_1:5,PAD_L_SHOULDER_2:6,PAD_R_SHOULDER_2:7,PAD_SELECT:8,PAD_START:9,PAD_L_STICK_BUTTON:10,PAD_R_STICK_BUTTON:11,PAD_UP:12,
- PAD_DOWN:13,PAD_LEFT:14,PAD_RIGHT:15,PAD_VENDOR:16,PAD_L_STICK_X:0,PAD_L_STICK_Y:1,PAD_R_STICK_X:2,PAD_R_STICK_Y:3};Object.assign(pc,f);pc.input={};Object.assign(pc.input,f)})();Object.assign(pc,function(){var f=function(a,b){var c={x:0,y:0};if(b){if(b instanceof f)throw Error("Expected MouseEvent");c=a._getTargetCoords(b)}else b={};if(c)this.x=c.x,this.y=c.y;else if(pc.Mouse.isPointerLocked())this.y=this.x=0;else return;this.wheel=b.detail?-1*b.detail:b.wheelDelta?b.wheelDelta/120:0;pc.Mouse.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:pc.MOUSEBUTTON_NONE;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},b=function(a){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);pc.events.attach(this)};b.isPointerLocked=function(){return!!(document.pointerLockElement||document.mozPointerLockElement||document.webkitPointerLockElement)};Object.assign(b.prototype,{attach:function(a){this._target=a;this._attached||(this._attached=!0,window.addEventListener("mouseup",this._upHandler,!1),window.addEventListener("mousedown",this._downHandler,!1),
- window.addEventListener("mousemove",this._moveHandler,!1),window.addEventListener("mousewheel",this._wheelHandler,!1),window.addEventListener("DOMMouseScroll",this._wheelHandler,!1))},detach:function(){this._attached&&(this._attached=!1,this._target=null,window.removeEventListener("mouseup",this._upHandler),window.removeEventListener("mousedown",this._downHandler),window.removeEventListener("mousemove",this._moveHandler),window.removeEventListener("mousewheel",this._wheelHandler),window.removeEventListener("DOMMouseScroll",
- this._wheelHandler))},disableContextMenu:function(){this._target&&this._target.addEventListener("contextmenu",this._contextMenuHandler)},enableContextMenu:function(){this._target&&this._target.removeEventListener("contextmenu",this._contextMenuHandler)},enablePointerLock:function(a,b){if(document.body.requestPointerLock){var c=function(){a();document.removeEventListener("pointerlockchange",c)},e=function(){b();document.removeEventListener("pointerlockerror",e)};a&&document.addEventListener("pointerlockchange",
- c,!1);b&&document.addEventListener("pointerlockerror",e,!1);document.body.requestPointerLock()}else b&&b()},disablePointerLock:function(a){if(document.exitPointerLock){var b=function(){a();document.removeEventListener("pointerlockchange",b)};a&&document.addEventListener("pointerlockchange",b,!1);document.exitPointerLock()}},update:function(){this._lastbuttons[0]=this._buttons[0];this._lastbuttons[1]=this._buttons[1];this._lastbuttons[2]=this._buttons[2]},isPressed:function(a){return this._buttons[a]},
- wasPressed:function(a){return this._buttons[a]&&!this._lastbuttons[a]},wasReleased:function(a){return!this._buttons[a]&&this._lastbuttons[a]},_handleUp:function(a){this._buttons[a.button]=!1;a=new f(this,a);a.event&&this.fire(pc.EVENT_MOUSEUP,a)},_handleDown:function(a){this._buttons[a.button]=!0;a=new f(this,a);a.event&&this.fire(pc.EVENT_MOUSEDOWN,a)},_handleMove:function(a){a=new f(this,a);a.event&&(this.fire(pc.EVENT_MOUSEMOVE,a),this._lastX=a.x,this._lastY=a.y)},_handleWheel:function(a){a=new f(this,
- a);a.event&&this.fire(pc.EVENT_MOUSEWHEEL,a)},_getTargetCoords:function(a){var b=this._target.getBoundingClientRect(),d=Math.floor(b.left),b=Math.floor(b.top);return a.clientX<d||a.clientX>=d+this._target.clientWidth||a.clientY<b||a.clientY>=b+this._target.clientHeight?null:{x:a.clientX-d,y:a.clientY-b}}});return{Mouse:b,MouseEvent:f}}());Object.assign(pc,function(){function f(a){c.key=a.keyCode;c.element=a.target;c.event=a;return c}function b(a){return"string"===typeof a?a.toUpperCase().charCodeAt(0):a}var a=function(a,b){b?(this.key=b.keyCode,this.element=b.target,this.event=b):this.event=this.element=this.key=null},c=new a,d={9:"Tab",13:"Enter",16:"Shift",17:"Control",18:"Alt",27:"Escape",37:"Left",38:"Up",39:"Right",40:"Down",46:"Delete",91:"Win"},e=function(a,b){b=b||{};this._element=null;this._keyDownHandler=this._handleKeyDown.bind(this);
- this._keyUpHandler=this._handleKeyUp.bind(this);this._keyPressHandler=this._handleKeyPress.bind(this);pc.events.attach(this);this._keymap={};this._lastmap={};a&&this.attach(a);this.preventDefault=b.preventDefault||!1;this.stopPropagation=b.stopPropagation||!1};e.prototype.attach=function(a){this._element&&this.detach();this._element=a;this._element.addEventListener("keydown",this._keyDownHandler,!1);this._element.addEventListener("keypress",this._keyPressHandler,!1);this._element.addEventListener("keyup",
- this._keyUpHandler,!1)};e.prototype.detach=function(){this._element.removeEventListener("keydown",this._keyDownHandler);this._element.removeEventListener("keypress",this._keyPressHandler);this._element.removeEventListener("keyup",this._keyUpHandler);this._element=null};e.prototype.toKeyIdentifier=function(a){a=b(a);var c,e;if(c=d[a.toString()])return c;c=a.toString(16).toUpperCase();e=c.length;for(a=0;a<4-e;a++)c="0"+c;return"U+"+c};e.prototype._handleKeyDown=function(a){var b=a.keyCode||a.charCode;
- void 0!==b&&(b=this.toKeyIdentifier(b),this._keymap[b]=!0,this.fire("keydown",f(a)),this.preventDefault&&a.preventDefault(),this.stopPropagation&&a.stopPropagation())};e.prototype._handleKeyUp=function(a){var b=a.keyCode||a.charCode;void 0!==b&&(b=this.toKeyIdentifier(b),delete this._keymap[b],this.fire("keyup",f(a)),this.preventDefault&&a.preventDefault(),this.stopPropagation&&a.stopPropagation())};e.prototype._handleKeyPress=function(a){this.fire("keypress",f(a));this.preventDefault&&a.preventDefault();
- this.stopPropagation&&a.stopPropagation()};e.prototype.update=function(){for(var a in this._lastmap)delete this._lastmap[a];for(a in this._keymap)this._keymap.hasOwnProperty(a)&&(this._lastmap[a]=this._keymap[a])};e.prototype.isPressed=function(a){a=b(a);a=this.toKeyIdentifier(a);return!!this._keymap[a]};e.prototype.wasPressed=function(a){a=b(a);a=this.toKeyIdentifier(a);return!!this._keymap[a]&&!this._lastmap[a]};e.prototype.wasReleased=function(a){a=b(a);a=this.toKeyIdentifier(a);return!this._keymap[a]&&
- !!this._lastmap[a]};return{Keyboard:e,KeyboardEvent:a}}());Object.assign(pc,function(){var f=function(){this.gamepadsSupported=!!navigator.getGamepads||!!navigator.webkitGetGamepads;this.current=[];this.previous=[];this.deadZone=.25},b={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"]}},a={"Product: 0268":"PS3"};Object.assign(f.prototype,{update:function(){var a,b,e,g,f;a=0;for(e=this.current.length;a<e;a++)for(g=this.current[a].pad.buttons,f=g.length,b=0;b<f;b++)void 0===this.previous[a]&&(this.previous[a]=[]),this.previous[a][b]=g[b].pressed;b=this.poll();a=0;for(e=b.length;a<e;a++)this.current[a]=b[a]},poll:function(){var a=[];if(this.gamepadsSupported){var b=navigator.getGamepads?navigator.getGamepads():
- navigator.webkitGetGamepads(),e,g=b.length;for(e=0;e<g;e++)b[e]&&a.push({map:this.getMap(b[e]),pad:b[e]})}return a},getMap:function(c){for(var d in a)if(0<=c.id.indexOf(d))return b[a[d]];return b.DEFAULT},isPressed:function(a,b){return this.current[a]?this.current[a].pad.buttons[pc[this.current[a].map.buttons[b]]].pressed:!1},wasPressed:function(a,b){if(!this.current[a])return!1;var c=pc[this.current[a].map.buttons[b]];return this.current[a].pad.buttons[c].pressed&&!this.previous[a][c]},getAxis:function(a,
- b){if(!this.current[a])return!1;var c=this.current[a].pad.axes[pc[this.current[a].map.axes[b]]];Math.abs(c)<this.deadZone&&(c=0);return c}});return{GamePads:f}}());Object.assign(pc,function(){var f=function(a){var b=pc.getTouchTargetCoords(a);this.id=a.identifier;this.x=b.x;this.y=b.y;this.target=a.target;this.touch=a},b=function(a,b){this.element=b.target;this.event=b;this.touches=[];this.changedTouches=[];if(b){var c,d=b.touches.length;for(c=0;c<d;c++)this.touches.push(new f(b.touches[c]));d=b.changedTouches.length;for(c=0;c<d;c++)this.changedTouches.push(new f(b.changedTouches[c]))}};Object.assign(b.prototype,{getTouchById:function(a,b){var c,d=b.length;
- for(c=0;c<d;c++)if(b[c].id===a)return b[c];return null}});var a=function(a){this._element=null;this._startHandler=this._handleTouchStart.bind(this);this._endHandler=this._handleTouchEnd.bind(this);this._moveHandler=this._handleTouchMove.bind(this);this._cancelHandler=this._handleTouchCancel.bind(this);this.attach(a);pc.events.attach(this)};Object.assign(a.prototype,{attach:function(a){this._element&&this.detach();this._element=a;this._element.addEventListener("touchstart",this._startHandler,!1);this._element.addEventListener("touchend",
- this._endHandler,!1);this._element.addEventListener("touchmove",this._moveHandler,!1);this._element.addEventListener("touchcancel",this._cancelHandler,!1)},detach:function(){this._element&&(this._element.removeEventListener("touchstart",this._startHandler,!1),this._element.removeEventListener("touchend",this._endHandler,!1),this._element.removeEventListener("touchmove",this._moveHandler,!1),this._element.removeEventListener("touchcancel",this._cancelHandler,!1));this._element=null},_handleTouchStart:function(a){this.fire("touchstart",
- new b(this,a))},_handleTouchEnd:function(a){this.fire("touchend",new b(this,a))},_handleTouchMove:function(a){a.preventDefault();this.fire("touchmove",new b(this,a))},_handleTouchCancel:function(a){this.fire("touchcancel",new b(this,a))}});return{getTouchTargetCoords:function(a){for(var b=0,c=0,g=a.target;!(g instanceof HTMLElement);)g=g.parentNode;do b+=g.offsetLeft-g.scrollLeft,c+=g.offsetTop-g.scrollTop,g=g.offsetParent;while(g);return{x:a.pageX-b,y:a.pageY-c}},TouchDevice:a,TouchEvent:b}}());Object.assign(pc,function(){var f=function(b,a){a=a||{};this._keyboard=a.keyboard||null;this._mouse=a.mouse||null;this._gamepads=a.gamepads||null;this._element=null;this._actions={};this._axes={};this._axesValues={};b&&this.attach(b)};f.prototype.attach=function(b){this._element=b;this._keyboard&&this._keyboard.attach(b);this._mouse&&this._mouse.attach(b)};f.prototype.detach=function(){this._keyboard&&this._keyboard.detach();this._mouse&&this._mouse.detach();this._element=null};f.prototype.disableContextMenu=
- function(){this._mouse||this._enableMouse();this._mouse.disableContextMenu()};f.prototype.enableContextMenu=function(){this._mouse||this._enableMouse();this._mouse.enableContextMenu()};f.prototype.update=function(b){this._keyboard&&this._keyboard.update(b);this._mouse&&this._mouse.update(b);this._gamepads&&this._gamepads.update(b);this._axesValues={};for(var a in this._axes)this._axesValues[a]=[]};f.prototype.registerKeys=function(b,a){this._keyboard||this._enableKeyboard();if(this._actions[b])throw Error(pc.string.format("Action: {0} already registered",
- b));if(void 0===a)throw Error("Invalid button");a.length||(a=[a]);this._actions[b]?this._actions[b].push({type:pc.ACTION_KEYBOARD,keys:a}):this._actions[b]=[{type:pc.ACTION_KEYBOARD,keys:a}]};f.prototype.registerMouse=function(b,a){this._mouse||this._enableMouse();if(void 0===a)throw Error("Invalid button");this._actions[b]?this._actions[b].push({type:pc.ACTION_MOUSE,button:a}):this._actions[b]=[{type:pc.ACTION_MOUSE,button:-a}]};f.prototype.registerPadButton=function(b,a,c){if(void 0===c)throw Error("Invalid button");
- this._actions[b]?this._actions[b].push({type:pc.ACTION_GAMEPAD,button:c,pad:a}):this._actions[b]=[{type:pc.ACTION_GAMEPAD,button:c,pad:a}]};f.prototype.registerAxis=function(b){var a=b.name;this._axes[a]||(this._axes[a]=[]);var c=this._axes[a].push(a);b=b||{};b.pad=b.pad||pc.PAD_1;var d=function(d,g,f,k){switch(g){case "mousex":d._mouse.on(pc.EVENT_MOUSEMOVE,function(b){d._axesValues[a][c]=b.dx/10});break;case "mousey":d._mouse.on(pc.EVENT_MOUSEMOVE,function(b){d._axesValues[a][c]=b.dy/10});break;
- case "key":d._axes[a].push(function(){return d._keyboard.isPressed(k)?f:0});break;case "padrx":d._axes[a].push(function(){return d._gamepads.getAxis(b.pad,pc.PAD_R_STICK_X)});break;case "padry":d._axes[a].push(function(){return d._gamepads.getAxis(b.pad,pc.PAD_R_STICK_Y)});break;case "padlx":d._axes[a].push(function(){return d._gamepads.getAxis(b.pad,pc.PAD_L_STICK_X)});break;case "padly":d._axes[a].push(function(){return d._gamepads.getAxis(b.pad,pc.PAD_L_STICK_Y)});break;default:throw Error("Unknown axis");
- }};d(this,b.positive,1,b.positiveKey);(b.negativeKey||b.negative!==b.positive)&&d(this,b.negative,-1,b.negativeKey)};f.prototype.isPressed=function(b){if(!this._actions[b])return!1;var a,c,d=this._actions[b].length;for(c=0;c<d;++c)switch(a=this._actions[b][c],a.type){case pc.ACTION_KEYBOARD:if(this._keyboard){var e,g=a.keys.length;for(e=0;e<g;e++)if(this._keyboard.isPressed(a.keys[e]))return!0}break;case pc.ACTION_MOUSE:if(this._mouse&&this._mouse.isPressed(a.button))return!0;break;case pc.ACTION_GAMEPAD:if(this._gamepads&&
- this._gamepads.isPressed(a.pad,a.button))return!0}return!1};f.prototype.wasPressed=function(b){if(!this._actions[b])return!1;var a,c=this._actions[b].length;for(a=0;a<c;++a){var d=this._actions[b][a];switch(d.type){case pc.ACTION_KEYBOARD:if(this._keyboard){var e,g=d.keys.length;for(e=0;e<g;e++)if(this._keyboard.wasPressed(d.keys[e]))return!0}break;case pc.ACTION_MOUSE:if(this._mouse&&this._mouse.wasPressed(d.button))return!0;break;case pc.ACTION_GAMEPAD:if(this._gamepads&&this._gamepads.wasPressed(d.pad,
- d.button))return!0}}return!1};f.prototype.getAxis=function(b){var a=0;if(this._axes[b]){var c,d=this._axes[b].length;for(c=0;c<d;c++)if("function"===pc.type(this._axes[b][c])){var e=this._axes[b][c]();Math.abs(e)>Math.abs(a)&&(a=e)}else this._axesValues[b]&&Math.abs(this._axesValues[b][c])>Math.abs(a)&&(a=this._axesValues[b][c])}return a};f.prototype._enableMouse=function(){this._mouse=new pc.Mouse;if(!this._element)throw Error("Controller must be attached to an Element");this._mouse.attach(this._element)};
- f.prototype._enableKeyboard=function(){this._keyboard=new pc.Keyboard;if(!this._element)throw Error("Controller must be attached to an Element");this._keyboard.attach(this._element)};return{Controller:f}}());Object.assign(pc,function(){var f,b,a=new pc.Vec3,c=new pc.Vec3,d=new pc.Vec3,e=new pc.Vec3,g=new pc.Vec3,l=new pc.Vec3,k=new pc.Vec3,p=new pc.Vec3,h=new pc.Vec3,n=new pc.Vec2,q=new pc.Vec3,m=new pc.Vec3,r=new pc.Vec3,t=new pc.Vec3,v=new pc.Vec3,y=new pc.Vec3,u=new pc.Vec3,w=new pc.Vec3,x=new pc.Vec4,D=function(a,b,c){d.sub2(b,a);e.sub2(c[0],a);g.sub2(c[1],a);l.sub2(c[2],a);p.cross(l,d);if(0<=e.dot(p)){if(0>-g.dot(p)||0>h.cross(d,g).dot(e))return!1}else if(k.sub2(c[3],a),0>k.dot(p)||0>h.cross(d,e).dot(k))return!1;
- return 1E-8>d.sub2(c[0],c[2]).lengthSq()||1E-8>d.sub2(c[1],c[3]).lengthSq()?!1:!0},z=function(a,b,c){this.event=a;this.element=b;this.camera=c;this._stopPropagation=!1};Object.assign(z.prototype,{stopPropagation:function(){this._stopPropagation=!0;this.event.stopImmediatePropagation();this.event.stopPropagation()}});var C=function(a,b,c,d,e,g,f){z.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;pc.Mouse.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-f);this.wheel=a.detail?-1*a.detail:a.wheelDelta?a.wheelDelta/120:0};C.prototype=Object.create(z.prototype);C.prototype.constructor=C;var A=function(a,b,c,d,e,g){z.call(this,a,b,c);this.touches=a.touches;this.changedTouches=a.changedTouches;this.x=d;this.y=e};A.prototype=Object.create(z.prototype);A.prototype.constructor=A;
- var B=function(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._useMouse=!b||!1!==b.useMouse;this._useTouch=!b||!1!==b.useTouch;pc.platform.touch&&(this._clickedEntities={});this.attach(a,b)};Object.assign(B.prototype,{attach:function(a){this._attached&&(this._attached=!1,this.detach());this._target=a;this._attached=!0;this._useMouse&&(window.addEventListener("mouseup",this._upHandler,{passive:!0}),
- window.addEventListener("mousedown",this._downHandler,{passive:!0}),window.addEventListener("mousemove",this._moveHandler,{passive:!0}),window.addEventListener("mousewheel",this._wheelHandler,{passive:!0}),window.addEventListener("DOMMouseScroll",this._wheelHandler,{passive:!0}));this._useTouch&&pc.platform.touch&&(this._target.addEventListener("touchstart",this._touchstartHandler,{passive:!0}),this._target.addEventListener("touchend",this._touchendHandler,!1),this._target.addEventListener("touchmove",
- this._touchmoveHandler,!1),this._target.addEventListener("touchcancel",this._touchcancelHandler,!1))},detach:function(){this._attached&&(this._attached=!1,this._useMouse&&(window.removeEventListener("mouseup",this._upHandler,!1),window.removeEventListener("mousedown",this._downHandler,!1),window.removeEventListener("mousemove",this._moveHandler,!1),window.removeEventListener("mousewheel",this._wheelHandler,!1),window.removeEventListener("DOMMouseScroll",this._wheelHandler,!1)),this._useTouch&&(this._target.removeEventListener("touchstart",
- this._touchstartHandler,!1),this._target.removeEventListener("touchend",this._touchendHandler,!1),this._target.removeEventListener("touchmove",this._touchmoveHandler,!1),this._target.removeEventListener("touchcancel",this._touchcancelHandler,!1)),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&&!pc.Mouse.isPointerLocked()&&
- (this._calcMouseCoords(a),null!==f&&this._onElementMouseEvent(a))},_handleDown:function(a){this._enabled&&!pc.Mouse.isPointerLocked()&&(this._calcMouseCoords(a),null!==f&&this._onElementMouseEvent(a))},_handleMove:function(a){this._enabled&&(this._calcMouseCoords(a),null!==f&&(this._onElementMouseEvent(a),this._lastX=f,this._lastY=b))},_handleWheel:function(a){this._enabled&&(this._calcMouseCoords(a),null!==f&&this._onElementMouseEvent(a))},_determineTouchedElements:function(a){var b={},c=this.app.systems.camera.cameras,
- d,e,g;for(d=c.length-1;0<=d;d--){var f=c[d],l=0;e=0;for(g=a.changedTouches.length;e<g;e++)if(b[a.changedTouches[e].identifier])l++;else{var k=this._calcTouchCoords(a.changedTouches[e]),h=this._getTargetElement(f,k.x,k.y);h&&(l++,b[a.changedTouches[e].identifier]={element:h,camera:f,x:k.x,y:k.y})}if(l===g)break}return b},_handleTouchStart:function(a){if(this._enabled){for(var b=this._determineTouchedElements(a),c=0,d=a.changedTouches.length;c<d;c++){var e=a.changedTouches[c],g=b[e.identifier],f=this._touchedElements[e.identifier];
- !g||f&&g.element===f.element||(this._fireEvent(a.type,new A(a,g.element,g.camera,g.x,g.y,this)),this._touchesForWhichTouchLeaveHasFired[e.identifier]=!1)}for(var l in b)this._touchedElements[l]=b[l]}},_handleTouchEnd:function(a){if(this._enabled){var b=this.app.systems.camera.cameras,c;for(c in this._clickedEntities)delete this._clickedEntities[c];c=0;for(var d=a.changedTouches.length;c<d;c++){var e=a.changedTouches[c],g=this._touchedElements[e.identifier];if(g){var f=g.element,l=g.camera,k=g.x,g=
- g.y;delete this._touchedElements[e.identifier];delete this._touchesForWhichTouchLeaveHasFired[e.identifier];this._fireEvent(a.type,new A(a,f,l,k,g,this));if(0===a.touches.length)for(var e=this._calcTouchCoords(e),h=b.length-1;0<=h;h--)this._getTargetElement(b[h],e.x,e.y)!==f||this._clickedEntities[f.entity.getGuid()]||(this._fireEvent("click",new A(a,f,l,k,g,this)),this._clickedEntities[f.entity.getGuid()]=!0)}}}},_handleTouchMove:function(a){a.preventDefault();if(this._enabled)for(var b=this._determineTouchedElements(a),
- c=0,d=a.changedTouches.length;c<d;c++){var e=a.changedTouches[c],g=b[e.identifier],f=this._touchedElements[e.identifier];if(f){var l=this._calcTouchCoords(e);g&&g.element===f.element||this._touchesForWhichTouchLeaveHasFired[e.identifier]||(this._fireEvent("touchleave",new A(a,f.element,f.camera,l.x,l.y,this)),this._touchesForWhichTouchLeaveHasFired[e.identifier]=!0);this._fireEvent("touchmove",new A(a,f.element,f.camera,l.x,l.y,this))}}},_onElementMouseEvent:function(a){var c,d=this._hoveredElement;
- this._hoveredElement=null;for(var e=this.app.systems.camera.cameras,g,l=e.length-1;0<=l&&!(g=e[l],c=this._getTargetElement(g,f,b));l--);c&&(this._fireEvent(a.type,new C(a,c,g,f,b,this._lastX,this._lastY)),this._hoveredElement=c,a.type===pc.EVENT_MOUSEDOWN&&(this._pressedElement=c));d!==this._hoveredElement&&(d&&this._fireEvent("mouseleave",new C(a,d,g,f,b,this._lastX,this._lastY)),this._hoveredElement&&this._fireEvent("mouseenter",new C(a,this._hoveredElement,g,f,b,this._lastX,this._lastY)));a.type===
- pc.EVENT_MOUSEUP&&this._pressedElement&&(this._pressedElement===this._hoveredElement?(this._pressedElement=null,this._clickedEntities&&this._clickedEntities[this._hoveredElement.entity.getGuid()]||this._fireEvent("click",new C(a,this._hoveredElement,g,f,b,this._lastX,this._lastY))):this._pressedElement=null)},_fireEvent:function(a,b){for(var c=b.element;;){c.fire(a,b);if(b._stopPropagation)break;if(!c.entity.parent)break;c=c.entity.parent.element;if(!c)break}},_calcMouseCoords:function(a){var c=this._target.getBoundingClientRect(),
- d=Math.floor(c.left),c=Math.floor(c.top);a.clientX<d||a.clientX>=d+this._target.clientWidth||a.clientY<c||a.clientY>=c+this._target.clientHeight?b=f=null:(f=a.clientX-d,b=a.clientY-c)},_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=0,g=this._elements.length;e<g;e++){var f=this._elements[e];if(f.screen&&f.screen.screen.screenSpace){if(this._checkElement2d(b,c,f,a)){d=f;break}}else if(this._checkElement3d(b,c,f,a)){d=f;break}}return d},
- _buildHitCorners:function(a,b,c,d){if(a.entity&&a.entity.button){var e=a.entity.button.hitPadding||x;q.copy(a.entity.up);m.copy(q).scale(-1);t.copy(a.entity.right);r.copy(t).scale(-1);q.scale(e.w*d);m.scale(e.y*d);t.scale(e.z*c);r.scale(e.x*c);v.copy(b[0]).add(m).add(r);y.copy(b[1]).add(m).add(t);u.copy(b[2]).add(q).add(t);w.copy(b[3]).add(q).add(r);b=[v,y,u,w]}return b},_calculateScaleToScreen:function(a){var b=a.entity;a=a.screen.screen.scale;for(n.set(a,a);b&&!b.screen;)n.mul(b.getLocalScale()),
- b=b.parent;return n},_checkElement2d:function(b,d,e,g){if(e.maskedBy&&!this._checkElement2d(b,d,e.maskedBy.element,g))return!1;var f=this.app.graphicsDevice.width,l=this.app.graphicsDevice.height,k=g.rect.z*f,h=g.rect.w*l,p=g.rect.x*f;g=(1-g.rect.y)*l;var m=g-h;b=b*f/this._target.clientWidth;d=d*l/this._target.clientHeight;return b>=p&&b<=p+k&&d<=g&&d>=m&&(b=f*(b-p)/k,d=l-l*(d-m)/h,f=this._calculateScaleToScreen(e),e=this._buildHitCorners(e,e.screenCorners,f.x,f.y),a.set(b,d,1),c.set(b,d,-1),D(a,
- c,e))?!0:!1},_checkElement3d:function(b,d,e,g){if(e.maskedBy&&!this._checkElement3d(b,d,e.maskedBy.element,g))return!1;var f=this._target.clientWidth,l=this._target.clientHeight,k=g.rect.z*f,h=g.rect.w*l,p=g.rect.x*f,m=(1-g.rect.y)*l,n=m-h,q=d;return b>=p&&b<=p+k&&d<=m&&q>=n&&(b=f*(b-p)/k,q=l*(q-n)/h,l=e.entity.getWorldTransform().getScale(),e=this._buildHitCorners(e,e.worldCorners,l.x,l.y),g.screenToWorld(b,q,g.nearClip,a),g.screenToWorld(b,q,g.farClip,c),D(a,c,e))?!0:!1}});Object.defineProperty(B.prototype,
- "enabled",{get:function(){return this._enabled},set:function(a){this._enabled=a}});Object.defineProperty(B.prototype,"app",{get:function(){return this._app||pc.app},set:function(a){this._app=a}});return{ElementInput:B,ElementInputEvent:z,ElementMouseEvent:C,ElementTouchEvent:A}}());Object.assign(pc,function(){var f=function(b){pc.events.attach(this);var a=this;this.isSupported=f.isSupported;this.usesPolyfill=f.usesPolyfill;window.InitializeWebVRPolyfill&&window.InitializeWebVRPolyfill();this._index={};this.displays=[];this.display=null;this._app=b;this._onDisplayConnect=this._onDisplayConnect.bind(this);this._onDisplayDisconnect=this._onDisplayDisconnect.bind(this);a._attach();this._getDisplays(function(b,d){if(b)a.fire("error",b);else{for(var c=0;c<d.length;c++)a._addDisplay(d[c]);
- a.fire("ready",a.displays)}})};f.isSupported=!!navigator.getVRDisplays;f.usesPolyfill=!!window.InitializeWebVRPolyfill;Object.assign(f.prototype,{_attach:function(){window.addEventListener("vrdisplayconnect",this._onDisplayConnect);window.addEventListener("vrdisplaydisconnect",this._onDisplayDisconnect)},_detach:function(){window.removeEventListener("vrdisplayconnect",this._onDisplayConnect);window.removeEventListener("vrdisplaydisconnect",this._onDisplayDisconnect)},destroy:function(){this._detach()},
- poll:function(){var b=this.displays.length;if(b)for(var a=0;a<b;a++)this.displays[a]._camera&&this.displays[a].poll()},_getDisplays:function(b){navigator.getVRDisplays?navigator.getVRDisplays().then(function(a){b&&b(null,a)}):b&&b(Error("WebVR not supported"))},_addDisplay:function(b){this._index[b.displayId]||(b=new pc.VrDisplay(this._app,b),this._index[b.id]=b,this.displays.push(b),this.display||(this.display=b),this.fire("displayconnect",b))},_onDisplayConnect:function(b){b.detail&&b.detail.display?
- this._addDisplay(b.detail.display):this._addDisplay(b.display)},_onDisplayDisconnect:function(b){if(b=this._index[b.detail&&b.detail.display?b.detail.display.displayId:b.display.displayId]){b.destroy();delete this._index[b.id];var a=this.displays.indexOf(b);this.displays.splice(a,1);this.display===b&&(this.display=this.displays.length?this.displays[0]:null);this.fire("displaydisconnect",b)}}});return{VrManager:f}}());Object.assign(pc,function(){var f=function(b,a){var c=this;this._app=b;this._device=b.graphicsDevice;this.id=a.displayId;this._frameData=null;window.VRFrameData&&(this._frameData=new window.VRFrameData);this.display=a;this._camera=null;this.sitToStandInv=new pc.Mat4;this.leftView=new pc.Mat4;this.leftProj=new pc.Mat4;this.leftViewInv=new pc.Mat4;this.leftPos=new pc.Vec3;this.rightView=new pc.Mat4;this.rightProj=new pc.Mat4;this.rightViewInv=new pc.Mat4;this.rightPos=new pc.Vec3;this.combinedPos=new pc.Vec3;
- this.combinedView=new pc.Mat4;this.combinedProj=new pc.Mat4;this.combinedViewInv=new pc.Mat4;this.combinedAspect=this.combinedFov=0;this.presenting=!1;c._presentChange=function(a){if((a.display?a.display:a.detail&&a.detail.display?a.detail.display:a.detail&&a.detail.vrdisplay?a.detail.vrdisplay:c.display)===c.display){c.presenting=c.display&&c.display.isPresenting;if(c.presenting){a=c.display.getEyeParameters("left");var b=c.display.getEyeParameters("right");c._app.graphicsDevice.setResolution(2*
- Math.max(a.renderWidth,b.renderWidth),Math.max(a.renderHeight,b.renderHeight));c._app._allowResize=!1}else c._app.setCanvasResolution(pc.RESOLUTION_AUTO),c._app._allowResize=!0;c.fire("beforepresentchange",c);c.fire("presentchange",c)}};window.addEventListener("vrdisplaypresentchange",c._presentChange,!1);pc.events.attach(this)};Object.assign(f.prototype,{destroy:function(){window.removeEventListener("vrdisplaypresentchange",self._presentChange);this._camera&&(this._camera.vrDisplay=null);this._camera=
- null},poll:function(){if(this.display){this.display.getFrameData(this._frameData);this.leftProj.data=this._frameData.leftProjectionMatrix;this.rightProj.data=this._frameData.rightProjectionMatrix;var b=this.display.stageParameters;b?(this.sitToStandInv.set(b.sittingToStandingTransform).invert(),this.combinedView.set(this._frameData.leftViewMatrix),this.leftView.mul2(this.combinedView,this.sitToStandInv),this.combinedView.set(this._frameData.rightViewMatrix),this.rightView.mul2(this.combinedView,this.sitToStandInv)):
- (this.leftView.set(this._frameData.leftViewMatrix),this.rightView.set(this._frameData.rightViewMatrix));var a=this.leftProj.data[3]+this.leftProj.data[0],c=this.leftProj.data[11]+this.leftProj.data[8],d=1/Math.sqrt(a*a+c*c),b=-Math.atan2(c*d,a*d),a=this.rightProj.data[3]+this.rightProj.data[0],c=this.rightProj.data[11]+this.rightProj.data[8],d=1/Math.sqrt(a*a+c*c),b=Math.max(b,-Math.atan2(c*d,a*d));this.combinedFov=b*=2;this.combinedAspect=a=this.rightProj.data[5]/this.rightProj.data[0];c=this.combinedView;
- c.copy(this.leftView);c.invert();this.leftViewInv.copy(c);d=this.combinedPos;d.x=this.leftPos.x=c.data[12];d.y=this.leftPos.y=c.data[13];d.z=this.leftPos.z=c.data[14];c.copy(this.rightView);c.invert();this.rightViewInv.copy(c);var e=d.x-c.data[12],g=d.y-c.data[13],f=d.z-c.data[14],e=Math.sqrt(e*e+g*g+f*f);this.rightPos.x=c.data[12];this.rightPos.y=c.data[13];this.rightPos.z=c.data[14];d.x+=c.data[12];d.y+=c.data[13];d.z+=c.data[14];d.x*=.5;d.y*=.5;d.z*=.5;e=.5*e*Math.sin(Math.PI-(.5*Math.PI+.5*b));
- g=c.data[9];f=c.data[10];c.data[12]=d.x+c.data[8]*e;c.data[13]=d.y+g*e;c.data[14]=d.z+f*e;this.combinedViewInv.copy(c);c.invert();this.combinedProj.setPerspective(b*pc.math.RAD_TO_DEG,a,this.display.depthNear+e,this.display.depthFar+e,!0)}},requestPresent:function(b){this.display?this.presenting?b&&b(Error("VrDisplay already presenting")):this.display.requestPresent([{source:this._device.canvas}]).then(function(){b&&b()},function(a){b&&b(a)}):b&&b(Error("No VrDisplay to requestPresent"))},exitPresent:function(b){this.display||
- b&&b(Error("No VrDisplay to exitPresent"));this.presenting?this.display.exitPresent().then(function(){b&&b()},function(){b&&b(Error("exitPresent failed"))}):b&&b(Error("VrDisplay not presenting"))},requestAnimationFrame:function(b){this.display&&this.display.requestAnimationFrame(b)},submitFrame:function(){this.display&&this.display.submitFrame()},reset:function(){this.display&&this.display.resetPose()},setClipPlanes:function(b,a){this.display&&(this.display.depthNear=b,this.display.depthFar=a)},
- getFrameData:function(){if(this.display)return this._frameData}});Object.defineProperty(f.prototype,"capabilities",{get:function(){return this.display?this.display.capabilities:{}}});return{VrDisplay:f}}());Object.assign(pc,function(){var f=function(){};f.ContentType={FORM_URLENCODED:"application/x-www-form-urlencoded",GIF:"image/gif",JPEG:"image/jpeg",DDS:"image/dds",JSON:"application/json",PNG:"image/png",TEXT:"text/plain",XML:"application/xml",WAV:"audio/x-wav",OGG:"audio/ogg",MP3:"audio/mpeg",MP4:"audio/mp4",AAC:"audio/aac",BIN:"application/octet-stream"};f.ResponseType={TEXT:"text",ARRAY_BUFFER:"arraybuffer",BLOB:"blob",DOCUMENT:"document",JSON:"json"};f.binaryExtensions=".model .wav .ogg .mp3 .mp4 .m4a .aac .dds".split(" ");
- Object.assign(f.prototype,{ContentType:f.ContentType,ResponseType:f.ResponseType,binaryExtensions:f.binaryExtensions,get:function(b,a,c){"function"===typeof a&&(c=a,a={});return this.request("GET",b,a,c)},post:function(b,a,c,d){"function"===typeof c&&(d=c,c={});c.postdata=a;return this.request("POST",b,c,d)},put:function(b,a,c,d){"function"===typeof c&&(d=c,c={});c.postdata=a;return this.request("PUT",b,c,d)},del:function(b,a,c){"function"===typeof a&&(c=a,a={});return this.request("DELETE",b,a,c)},
- request:function(b,a,c,d){var e,g,l,k=!1;"function"===typeof c&&(d=c,c={});c.callback=d;null==c.async&&(c.async=!0);null==c.headers&&(c.headers={});if(null!=c.postdata)if(c.postdata instanceof Document)g=c.postdata;else if(c.postdata instanceof FormData)g=c.postdata;else if(c.postdata instanceof Object)switch(g=c.headers["Content-Type"],void 0===g&&(c.headers["Content-Type"]=f.ContentType.FORM_URLENCODED,g=c.headers["Content-Type"]),g){case f.ContentType.FORM_URLENCODED:g="";d=!0;for(e in c.postdata)c.postdata.hasOwnProperty(e)&&
- (d?d=!1:g+="&",g+=escape(e)+"="+escape(c.postdata[e]));break;default:case f.ContentType.JSON:null==g&&(c.headers["Content-Type"]=f.ContentType.JSON),g=JSON.stringify(c.postdata)}else g=c.postdata;l||(l=new XMLHttpRequest);!1===c.cache&&(d=pc.time.now(),e=new pc.URI(a),e.query=e.query?e.query+"&ts="+d:"ts="+d,a=e.toString());c.query&&(e=new pc.URI(a),d=pc.extend(e.getQuery(),c.query),e.setQuery(d),a=e.toString());l.open(b,a,c.async);l.withCredentials=void 0!==c.withCredentials?c.withCredentials:!1;
- l.responseType=c.responseType||this._guessResponseType(a);for(var p in c.headers)c.headers.hasOwnProperty(p)&&l.setRequestHeader(p,c.headers[p]);l.onreadystatechange=function(){this._onReadyStateChange(b,a,c,l)}.bind(this);l.onerror=function(){this._onError(b,a,c,l);k=!0}.bind(this);try{l.send(g)}catch(h){k||c.error(l.status,l,h)}return l},_guessResponseType:function(b){b=new pc.URI(b);b=pc.path.getExtension(b.path);return 0<=f.binaryExtensions.indexOf(b)?f.ResponseType.ARRAY_BUFFER:".xml"===b?f.ResponseType.DOCUMENT:
- f.ResponseType.TEXT},_isBinaryContentType:function(b){return 0<=[f.ContentType.MP4,f.ContentType.WAV,f.ContentType.OGG,f.ContentType.MP3,f.ContentType.BIN,f.ContentType.DDS].indexOf(b)?!0:!1},_onReadyStateChange:function(b,a,c,d){if(4===d.readyState)switch(d.status){case 0:"/"!=a[0]&&this._onSuccess(b,a,c,d);break;case 200:case 201:case 206:case 304:this._onSuccess(b,a,c,d);break;default:this._onError(b,a,c,d)}},_onSuccess:function(b,a,c,d){var e,g;if(b=d.getResponseHeader("Content-Type"))g=b.split(";"),
- g=g[0].trim();try{g===this.ContentType.JSON||a.split("?")[0].endsWith(".json")?e=JSON.parse(d.responseText):this._isBinaryContentType(g)?e=d.response:(g&&logWARNING(pc.string.format("responseType: {0} being served with Content-Type: {1}",d.responseType,g)),e=d.responseType===f.ResponseType.ARRAY_BUFFER?d.response:d.responseType===f.ResponseType.BLOB||d.responseType===f.ResponseType.JSON?d.response:d.responseType===f.ResponseType.DOCUMENT||g===this.ContentType.XML?d.responseXML:d.responseText),c.callback(null,
- e)}catch(l){c.callback(l)}},_onError:function(b,a,c,d){c.callback(d.status,null)}});return{Http:f,http:new f}}());Object.assign(pc,function(){var f=function(b){pc.events.attach(this);this.app=b;this._scripts={};this._list=[]};f.prototype.destroy=function(){this.app=null;this.off()};f.prototype.add=function(b){var a=this;if(this._scripts.hasOwnProperty(b.__name))return setTimeout(function(){if(b.prototype.swap){var c=a._list.indexOf(a._scripts[b.__name]);a._list[c]=b;a._scripts[b.__name]=b;a.fire("swap",b.__name,b);a.fire("swap:"+b.__name,b)}else console.warn("script registry already has '"+b.__name+"' script, define 'swap' method for new script type to enable code hot swapping")}),
- !1;this._scripts[b.__name]=b;this._list.push(b);this.fire("add",b.__name,b);this.fire("add:"+b.__name,b);setTimeout(function(){if(a._scripts.hasOwnProperty(b.__name)&&a.app&&a.app.systems&&a.app.systems.script){var c=a.app.systems.script._components,d,e,g=[],f=[];for(c.loopIndex=0;c.loopIndex<c.length;c.loopIndex++)d=c.items[c.loopIndex],d._scriptsIndex[b.__name]&&d._scriptsIndex[b.__name].awaiting&&(d._scriptsData&&d._scriptsData[b.__name]&&(e=d._scriptsData[b.__name].attributes),(d=d.create(b.__name,
- {preloading:!0,ind:d._scriptsIndex[b.__name].ind,attributes:e}))&&g.push(d));for(c=0;c<g.length;c++)g[c].__initializeAttributes();for(c=0;c<g.length;c++)g[c].enabled&&(g[c]._initialized=!0,f.push(g[c]),g[c].initialize&&g[c].initialize());for(c=0;c<f.length;c++)f[c].enabled&&!f[c]._postInitialized&&(f[c]._postInitialized=!0,f[c].postInitialize&&f[c].postInitialize())}});return!0};f.prototype.remove=function(b){"function"===typeof b&&(b=b.__name);if(!this._scripts.hasOwnProperty(b))return!1;var a=this._scripts[b];
- delete this._scripts[b];var c=this._list.indexOf(a);this._list.splice(c,1);this.fire("remove",b,a);this.fire("remove:"+b,a);return!0};f.prototype.get=function(b){return this._scripts[b]||null};f.prototype.has=function(b){return this._scripts.hasOwnProperty(b)};f.prototype.list=function(){return this._list};return{ScriptRegistry:f}}());Object.assign(pc,function(){var f=["x","y","z","w"],b=function(a,b,c,d){switch(b.type){case "boolean":return!!c;case "number":if("number"===typeof c)break;else{if("string"===typeof c)return c=parseInt(c,10),isNaN(c)?null:c;if("boolean"===typeof c)return 0+c}return null;case "json":if("object"===typeof c)break;try{return JSON.parse(c)}catch(h){return null}case "asset":if(c instanceof pc.Asset)break;else{if("number"===typeof c)return a.assets.get(c)||null;if("string"===typeof c)return a.assets.get(parseInt(c,
- 10))||null}return null;case "entity":if(c instanceof pc.GraphNode)break;else if("string"===typeof c)return a.root.findByGuid(c);return null;case "rgb":case "rgba":if(c instanceof pc.Color)return d instanceof pc.Color?(d.copy(c),d):c.clone();if(c instanceof Array&&3<=c.length&&4>=c.length){for(a=0;a<c.length;a++)if("number"!==typeof c[a])return null;d||(d=new pc.Color);d.r=c[0];d.g=c[1];d.b=c[2];d.a=3===c.length?1:c[3];return d}return"string"===typeof c&&/#([0-9abcdef]{2}){3,4}/i.test(c)?(d||(d=new pc.Color),
- d.fromString(c),d):null;case "vec2":case "vec3":case "vec4":b=parseInt(b.type.slice(3),10);if(c instanceof pc["Vec"+b])return d instanceof pc["Vec"+b]?(d.copy(c),d):c.clone();if(c instanceof Array&&c.length===b){for(a=0;a<c.length;a++)if("number"!==typeof c[a])return null;d||(d=new pc["Vec"+b]);for(a=0;a<b;a++)d[f[a]]=c[a];return d}return null;case "curve":if(c)return c instanceof pc.Curve||c instanceof pc.CurveSet?d=c.clone():(d=new (c.keys[0]instanceof Array?pc.CurveSet:pc.Curve)(c.keys),d.type=
- c.type),d}return c},a=function(a){this.scriptType=a;this.index={}};a.prototype.add=function(a,c){this.index[a]||pc.createScript.reservedAttributes[a]||(this.index[a]=c,Object.defineProperty(this.scriptType.prototype,a,{get:function(){return this.__attributes[a]},set:function(d){var e=this.__attributes[a];if(c.array){if(this.__attributes[a]=[],d){var g,f;g=0;for(f=d.length;g<f;g++)this.__attributes[a].push(b(this.app,c,d[g],e?e[g]:null))}}else this.__attributes[a]=b(this.app,c,d,e);this.fire("attr",
- a,this.__attributes[a],e);this.fire("attr:"+a,this.__attributes[a],e)}}))};a.prototype.remove=function(a){if(!this.index[a])return!1;delete this.index[a];delete this.scriptType.prototype[a];return!0};a.prototype.has=function(a){return!!this.index[a]};a.prototype.get=function(a){return this.index[a]||null};var c=function(b,d){if(pc.script.legacy)return null;if(c.reservedScripts[b])throw Error("script name: '"+b+"' is reserved, please change script name");var e=function(a){pc.events.attach(this);this.app=
- a.app;this.entity=a.entity;this._enabled="boolean"===typeof a.enabled?a.enabled:!0;this._enabledOld=this.enabled;this.__destroyed=!1;this.__attributes={};this.__attributesRaw=a.attributes||null;this.__scriptType=e;this.__executionOrder=-1};e.__name=b;e.attributes=new a(e);e.prototype.__initializeAttributes=function(a){if(a||this.__attributesRaw){for(var b in e.attributes.index)this.__attributesRaw&&this.__attributesRaw.hasOwnProperty(b)?this[b]=this.__attributesRaw[b]:this.__attributes.hasOwnProperty(b)||
- (e.attributes.index[b].hasOwnProperty("default")?this[b]=e.attributes.index[b]["default"]:this[b]=null);this.__attributesRaw=null}};e.extend=function(a){for(var b in a)a.hasOwnProperty(b)&&(e.prototype[b]=a[b])};Object.defineProperty(e.prototype,"enabled",{get:function(){return this._enabled&&!this._destroyed&&this.entity.script.enabled&&this.entity.enabled},set:function(a){this._enabled=!!a;this.enabled!==this._enabledOld&&(this._enabledOld=this.enabled,this.fire(this.enabled?"enable":"disable"),
- this.fire("state",this.enabled),!this._initialized&&this.enabled&&(this._initialized=!0,this.__initializeAttributes(!0),this.initialize&&this.entity.script._scriptMethod(this,pc.ScriptComponent.scriptMethods.initialize)),this._initialized&&!this._postInitialized&&this.enabled&&!this.entity.script._beingEnabled&&(this._postInitialized=!0,this.postInitialize&&this.entity.script._scriptMethod(this,pc.ScriptComponent.scriptMethods.postInitialize)))}});(d?d.scripts:pc.Application.getApplication().scripts).add(e);
- pc.ScriptHandler._push(e);return e};c.reservedScripts="system entity create destroy swap move scripts _scripts _scriptsIndex _scriptsData enabled _oldState onEnable onDisable onPostStateChange _onSetEnabled _checkState _onBeforeRemove _onInitializeAttributes _onInitialize _onPostInitialize _onUpdate _onPostUpdate _callbacks has on off fire once hasEvent".split(" ");var d={},e;for(e=0;e<c.reservedScripts.length;e++)d[c.reservedScripts[e]]=1;c.reservedScripts=d;c.reservedAttributes="app entity enabled _enabled _enabledOld _destroyed __attributes __attributesRaw __scriptType __executionOrder _callbacks has on off fire once hasEvent".split(" ");
- d={};for(e=0;e<c.reservedAttributes.length;e++)d[c.reservedAttributes[e]]=1;c.reservedAttributes=d;return{createScript:c}}());Object.assign(pc,function(){var f=function(b){this._blobUrls={};for(var a=0,c=b.length;a<c;a++)b[a].url&&(this._blobUrls[b[a].name]=b[a].url)};f.prototype.hasBlobUrl=function(b){return!!this._blobUrls[b]};f.prototype.getBlobUrl=function(b){return this._blobUrls[b]};f.prototype.destroy=function(){for(var b in this._blobUrls)URL.revokeObjectURL(this._blobUrls[b]);this._blobUrls=null};return{Bundle:f}}());Object.assign(pc,function(){var f=function(b){this._assets=b;this._bundleAssets={};this._assetsInBundles={};this._urlsInBundles={};this._fileRequests={};this._assets.on("add",this._onAssetAdded,this);this._assets.on("remove",this._onAssetRemoved,this)};Object.assign(f.prototype,{_onAssetAdded:function(b){if("bundle"===b.type){this._bundleAssets[b.id]=b;this._registerBundleEventListeners(b.id);for(var a=0,c=b.data.assets.length;a<c;a++)this._indexAssetInBundle(b.data.assets[a],b)}else this._assetsInBundles[b.id]&&
- this._indexAssetFileUrls(b)},_registerBundleEventListeners:function(b){this._assets.on("load:"+b,this._onBundleLoaded,this);this._assets.on("error:"+b,this._onBundleError,this)},_unregisterBundleEventListeners:function(b){this._assets.off("load:"+b,this._onBundleLoaded,this);this._assets.off("error:"+b,this._onBundleError,this)},_indexAssetInBundle:function(b,a){if(this._assetsInBundles[b]){var c=this._assetsInBundles[b];-1===c.indexOf(a)&&c.push(a)}else this._assetsInBundles[b]=[a];(c=this._assets.get(b))&&
- this._indexAssetFileUrls(c)},_indexAssetFileUrls:function(b){var a=this._getAssetFileUrls(b);if(a)for(var c=0,d=a.length;c<d;c++)this._urlsInBundles[a[c]]=this._assetsInBundles[b.id]},_getAssetFileUrls:function(b){var a=b.getFileUrl();if(!a)return null;var a=this._normalizeUrl(a),c=[a];if("font"===b.type){b=b.data.info.maps.length;for(var d=1;d<b;d++)c.push(a.replace(".png",d+".png"))}return c},_normalizeUrl:function(b){return b&&b.split("?")[0]},_onAssetRemoved:function(b){if("bundle"===b.type){delete this._bundleAssets[b.id];
- this._unregisterBundleEventListeners(b.id);var a,c;for(c in this._assetsInBundles){var d=this._assetsInBundles[c];a=d.indexOf(b);if(-1!==a&&(d.splice(a,1),!d.length)){delete this._assetsInBundles[c];for(var e in this._urlsInBundles)this._urlsInBundles[e]===d&&delete this._urlsInBundles[e]}}this._onBundleError("Bundle "+b.id+" was removed",b)}else if(this._assetsInBundles[b.id])for(delete this._assetsInBundles[b.id],b=this._getAssetFileUrls(b),a=0,c=b.length;a<c;a++)delete this._urlsInBundles[b[a]]},
- _onBundleLoaded:function(b){b.resource?requestAnimationFrame(function(){if(this._fileRequests)for(var a in this._fileRequests){var c=this._urlsInBundles[a];if(c&&-1!==c.indexOf(b)){var c=decodeURIComponent(a),d=null;b.resource.hasBlobUrl(c)||(d="Bundle "+b.id+" does not contain URL "+a);for(var e=this._fileRequests[a],g=0,f=e.length;g<f;g++)if(d)e[g](d);else e[g](null,b.resource.getBlobUrl(c));delete this._fileRequests[a]}}}.bind(this)):this._onBundleError("Bundle "+b.id+" failed to load",b)},_onBundleError:function(b,
- a){for(var c in this._fileRequests)if(!this._findLoadedOrLoadingBundleForUrl(c)){for(var d=this._fileRequests[c],e=0,g=d.length;e<g;e++)d[e](b);delete this._fileRequests[c]}},_findLoadedOrLoadingBundleForUrl:function(b){b=this._urlsInBundles[b];if(!b)return null;var a=b.length,c;for(c=0;c<a;c++)if(b[c].loaded&&b[c].resource)return b[c];for(c=0;c<a;c++)if(b[c].loading)return b[c];return null},listBundlesForAsset:function(b){return this._assetsInBundles[b.id]||null},list:function(){var b=[],a;for(a in this._bundleAssets)b.push(this._bundleAssets[a]);
- return b},hasUrl:function(b){return!!this._urlsInBundles[b]},canLoadUrl:function(b){return!!this._findLoadedOrLoadingBundleForUrl(b)},loadUrl:function(b,a){var c=this._findLoadedOrLoadingBundleForUrl(b);if(c)if(c.loaded){var d=decodeURIComponent(b);c.resource.hasBlobUrl(d)?a(null,c.resource.getBlobUrl(d)):a("Bundle "+c.id+" does not contain URL "+b)}else this._fileRequests.hasOwnProperty(b)?this._fileRequests[b].push(a):this._fileRequests[b]=[a];else a("URL "+b+" not found in any bundles")},destroy:function(){this._assets.off("add",
- this._onAssetAdded,this);this._assets.off("remove",this._onAssetRemoved,this);for(var b in this._bundleAssets)this._unregisterBundleEventListeners(b);this._fileRequests=this._urlsInBundles=this._assetsInBundles=this._bundleAssets=this._assets=null}});return{BundleRegistry:f}}());Object.assign(pc,function(){var f=function(){};f.prototype._validate=function(b){if(!b.header)throw Error('pc.I18n#addData: Missing "header" field');if(!b.header.version)throw Error('pc.I18n#addData: Missing "header.version" field');if(1!==b.header.version)throw Error('pc.I18n#addData: Invalid "header.version" field');if(!b.data)throw Error('pc.I18n#addData: Missing "data" field');if(!Array.isArray(b.data))throw Error('pc.I18n#addData: "data" field must be an array');for(var a=0,c=b.data.length;a<
- c;a++){var d=b.data[a];if(!d.info)throw Error('pc.I18n#addData: missing "data['+a+'].info" field');if(!d.info.locale)throw Error('pc.I18n#addData: missing "data['+a+'].info.locale" field');if("string"!==typeof d.info.locale)throw Error('pc.I18n#addData: "data['+a+'].info.locale" must be a string');if(!d.messages)throw Error('pc.I18n#addData: missing "data['+a+'].messages" field');}};f.prototype.parse=function(b){return b.data};return{I18nParser:f}}());Object.assign(pc,function(){var f={},b=function(a,b){for(var c=0,d=a.length;c<d;c++)f[a[c]]=b},a=function(a){var b=a.indexOf("-");return-1!==b?a.substring(0,b):a},c=f[a("en-US")],d={en:"en-US",es:"en-ES",zh:"zh-CN",fr:"fr-FR",de:"de-DE",it:"it-IT",ru:"ru-RU",ja:"ja-JP"};b(["ja","ko","th","vi","zh"],function(a){return 0});b(["fa","hi"],function(a){return 0<=a&&1>=a?0:1});b(["fr"],function(a){return 0<=a&&2>a?0:1});b("de en it el es tr".split(" "),function(a){return 1===a?0:1});b(["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<a))return 1;if(0===b||5<=b&&9>=b||11<=a&&14>=a)return 2}return 3});b(["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});b=function(a){pc.events.attach(this);this.locale="en-US";this._translations={};this._availableLangs={};this._app=a;this._assets=[];this._parser=new pc.I18nParser};b.prototype.getText=function(b,c){var d=b,
- e;c||(c=this._locale,e=this._lang);var g=this._translations[c];g||(e||(e=a(c)),c=this._findFallbackLocale(e),g=this._translations[c]);g&&((d=g[b])?Array.isArray(d)&&(d=d[0]||""):d=b);return d};b.prototype.getPluralText=function(b,d,l){var e=b,g,h;l?(h=a(l),g=f[h]||c):(l=this._locale,h=this._lang,g=this._pluralFn);l=this._translations[l];l||(l=this._findFallbackLocale(h),g=f[h]||c,l=this._translations[l]);l&&l[b]&&(d=g(d),e=l[b][d]||b);return e};b.prototype.addData=function(b){var c;try{c=this._parser.parse(b)}catch(n){console.error(n);
- return}b=0;for(var d=c.length;b<d;b++){var e=c[b],f=e.info.locale,e=e.messages;if(!this._translations[f]){this._translations[f]={};var h=a(f);this._availableLangs[h]||(this._availableLangs[h]=f)}Object.assign(this._translations[f],e);this.fire("data:add",f,e)}};b.prototype.removeData=function(b){var c,d;try{c=this._parser.parse(b)}catch(m){console.error(m);return}b=0;for(var e=c.length;b<e;b++){var f=c[b],h=f.info.locale,n=this._translations[h];if(n){f=f.messages;for(d in f)delete n[d];var q=!1;for(d in n){q=
- !0;break}q||(delete this._translations[h],delete this._availableLangs[a(h)]);this.fire("data:remove",h,f)}}};b.prototype.destroy=function(){this._parser=this._assets=this._availableLangs=this._translations=null;this.off()};Object.defineProperty(b.prototype,"locale",{get:function(){return this._locale},set:function(b){if(this._locale!==b){var d=this._locale;this._locale=b;this._lang=a(b);this._pluralFn=f[this._lang]||c;this.fire("set:locale",b,d)}}});Object.defineProperty(b.prototype,"assets",{get:function(){return this._assets},
- set:function(a){var b,c,d,e={};b=0;for(c=a.length;b<c;b++)d=a[b]instanceof pc.Asset?a[b].id:a[b],e[d]=!0;for(b=this._assets.length;b--;)d=this._assets[b],e[d]||(this._app.assets.off("add:"+d,this._onAssetAdd,this),(a=this._app.assets.get(d))&&this._onAssetRemove(a),this._assets.splice(b,1));for(d in e)if(d=parseInt(d,10),-1===this._assets.indexOf(d))if(this._assets.push(d),a=this._app.assets.get(d))this._onAssetAdd(a);else this._app.assets.once("add:"+d,this._onAssetAdd,this)}});b.prototype._findFallbackLocale=
- function(a){var b=d[a];return b&&this._translations[b]?b:(b=this._availableLangs[a])&&this._translations[b]?b:"en-US"};b.prototype._onAssetAdd=function(a){a.on("load",this._onAssetLoad,this);a.on("change",this._onAssetChange,this);a.on("remove",this._onAssetRemove,this);a.on("unload",this._onAssetUnload,this);a.resource&&this._onAssetLoad(a)};b.prototype._onAssetLoad=function(a){this.addData(a.resource)};b.prototype._onAssetChange=function(a){a.resource&&this.addData(a.resource)};b.prototype._onAssetRemove=
- function(a){a.off("load",this._onAssetLoad,this);a.off("change",this._onAssetChange,this);a.off("remove",this._onAssetRemove,this);a.off("unload",this._onAssetUnload,this);a.resource&&this.removeData(a.resource);this._app.assets.once("add:"+a.id,this._onAssetAdd,this)};b.prototype._onAssetUnload=function(a){a.resource&&this.removeData(a.resource)};return{I18n:b}}());pc.script=function(){var f=!1,b=!1,a={app:null,create:function(a,b){if(f){var c=b(pc.script.app);c._pcScriptName=a;pc.ScriptHandler._push(c);this.fire("created",a,b)}},attribute:function(a,b,e,g){},createLoadingScreen:function(a){if(!b){b=!0;var c=pc.Application.getApplication();a(c)}}};Object.defineProperty(a,"legacy",{get:function(){return f},set:function(a){f=a}});pc.events.attach(a);return a}();Object.assign(pc,function(){var f=function(a,b){b=b||{};pc.log.open();pc.events.attach(this);f._applications[a.id]=this;f._currentApplication=this;this._time=0;this.timeScale=1;this.maxDeltaTime=.1;this.frame=0;this.autoRender=!0;this.renderNextFrame=!1;this.useLegacyScriptAttributeCloning=pc.script.legacy;this._librariesLoaded=!1;this._fillMode=pc.FILLMODE_KEEP_ASPECT;this._resolutionMode=pc.RESOLUTION_FIXED;this._allowResize=!0;this.context=this;this.graphicsDevice=new pc.GraphicsDevice(a,b.graphicsDeviceOptions);
- this.stats=new pc.ApplicationStats(this.graphicsDevice);this._audioManager=new pc.SoundManager(b);this.loader=new pc.ResourceLoader(this);this._entityIndex={};this.scene=new pc.Scene;this.root=new pc.Entity(this);this.root._enabledInHierarchy=!0;this._enableList=[];this._enableList.size=0;this.assets=new pc.AssetRegistry(this.loader);b.assetPrefix&&(this.assets.prefix=b.assetPrefix);this.bundles=new pc.BundleRegistry(this.assets);this.enableBundles="undefined"!==typeof TextDecoder;this.scriptsOrder=
- b.scriptsOrder||[];this.scripts=new pc.ScriptRegistry(this);this.i18n=new pc.I18n(this);this._sceneRegistry=new pc.SceneRegistry(this);var d=this;this.defaultLayerWorld=new pc.Layer({name:"World",id:pc.LAYERID_WORLD});this.graphicsDevice.webgl2?(this.defaultLayerDepth=new pc.Layer({enabled:!1,name:"Depth",id:pc.LAYERID_DEPTH,onEnable:function(){if(!this.renderTarget){var a=new pc.Texture(d.graphicsDevice,{format:pc.PIXELFORMAT_DEPTHSTENCIL,width:d.graphicsDevice.width,height:d.graphicsDevice.height});
- a.name="rt-depth2";a.minFilter=pc.FILTER_NEAREST;a.magFilter=pc.FILTER_NEAREST;a.addressU=pc.ADDRESS_CLAMP_TO_EDGE;a.addressV=pc.ADDRESS_CLAMP_TO_EDGE;this.renderTarget=new pc.RenderTarget({colorBuffer:null,depthBuffer:a,autoResolve:!1});d.graphicsDevice.scope.resolve("uDepthMap").setValue(a)}},onDisable:function(){this.renderTarget&&(this.renderTarget._depthBuffer.destroy(),this.renderTarget.destroy(),this.renderTarget=null)},onPreRenderOpaque:function(a){var b=d.graphicsDevice.gl;this.srcFbo=b.getParameter(b.FRAMEBUFFER_BINDING);
- this.renderTarget&&this.renderTarget.width===d.graphicsDevice.width&&this.renderTarget.height===d.graphicsDevice.height||(this.onDisable(),this.onEnable());this.oldClear=this.cameras[a].camera._clearOptions;this.cameras[a].camera._clearOptions=this.depthClearOptions},onPostRenderOpaque:function(a){this.renderTarget&&(this.cameras[a].camera._clearOptions=this.oldClear,a=d.graphicsDevice.gl,d.graphicsDevice.setRenderTarget(this.renderTarget),d.graphicsDevice.updateBegin(),a.bindFramebuffer(a.READ_FRAMEBUFFER,
- this.srcFbo),a.bindFramebuffer(a.DRAW_FRAMEBUFFER,this.renderTarget._glFrameBuffer),a.blitFramebuffer(0,0,this.renderTarget.width,this.renderTarget.height,0,0,this.renderTarget.width,this.renderTarget.height,a.DEPTH_BUFFER_BIT,a.NEAREST))}}),this.defaultLayerDepth.depthClearOptions={flags:0}):(this.defaultLayerDepth=new pc.Layer({enabled:!1,name:"Depth",id:pc.LAYERID_DEPTH,shaderPass:pc.SHADER_DEPTH,onEnable:function(){if(!this.renderTarget){var a=new pc.Texture(d.graphicsDevice,{format:pc.PIXELFORMAT_R8_G8_B8_A8,
- width:d.graphicsDevice.width,height:d.graphicsDevice.height});a.name="rt-depth1";a.minFilter=pc.FILTER_NEAREST;a.magFilter=pc.FILTER_NEAREST;a.addressU=pc.ADDRESS_CLAMP_TO_EDGE;a.addressV=pc.ADDRESS_CLAMP_TO_EDGE;this.renderTarget=new pc.RenderTarget(d.graphicsDevice,a,{depth:!0,stencil:d.graphicsDevice.supportsStencil});d.graphicsDevice.scope.resolve("uDepthMap").setValue(a)}},onDisable:function(){this.renderTarget&&(this.renderTarget._colorBuffer.destroy(),this.renderTarget.destroy(),this.renderTarget=
- null)},onPostCull:function(a){var b=this.instances.visibleOpaque[a],c=b.list,e=0,g=d.scene.layers.layerList,f=d.scene.layers.subLayerEnabled,l=d.scene.layers.subLayerList,r=d.defaultLayerWorld.renderTarget;a=this.cameras[a];for(var t,v,y,u,w=0;w<g.length;w++){t=g[w];if(t===this)break;if(t.renderTarget===r&&t.enabled&&f[w]&&(v=t.cameras.indexOf(a),!(0>v)))for(v=(y=l[w])?t.instances.visibleTransparent[v]:t.instances.visibleOpaque[v],y=v.length,v=v.list,t=0;t<y;t++)u=v[t],u.material&&u.material.depthWrite&&
- !u._noDepthDrawGl1&&(c[e]=u,e++)}b.length=e},onPreRenderOpaque:function(a){this.renderTarget&&this.renderTarget.width===d.graphicsDevice.width&&this.renderTarget.height===d.graphicsDevice.height||(this.onDisable(),this.onEnable());this.oldClear=this.cameras[a].camera._clearOptions;this.cameras[a].camera._clearOptions=this.rgbaDepthClearOptions},onDrawCall:function(){d.graphicsDevice.setColorWrite(!0,!0,!0,!0)},onPostRenderOpaque:function(a){this.renderTarget&&(this.cameras[a].camera._clearOptions=
- this.oldClear)}}),this.defaultLayerDepth.rgbaDepthClearOptions={color:[254/255,254/255,254/255,254/255],depth:1,flags:pc.CLEARFLAG_COLOR|pc.CLEARFLAG_DEPTH});this.defaultLayerSkybox=new pc.Layer({enabled:!1,name:"Skybox",id:pc.LAYERID_SKYBOX,opaqueSortMode:pc.SORTMODE_NONE});this.defaultLayerUi=new pc.Layer({enabled:!0,name:"UI",id:pc.LAYERID_UI,transparentSortMode:pc.SORTMODE_MANUAL,passThrough:!0});this.defaultLayerImmediate=new pc.Layer({enabled:!0,name:"Immediate",id:pc.LAYERID_IMMEDIATE,opaqueSortMode:pc.SORTMODE_NONE,
- passThrough:!0});this.defaultLayerComposition=new pc.LayerComposition;this.defaultLayerComposition.pushOpaque(this.defaultLayerWorld);this.defaultLayerComposition.pushOpaque(this.defaultLayerDepth);this.defaultLayerComposition.pushOpaque(this.defaultLayerSkybox);this.defaultLayerComposition.pushTransparent(this.defaultLayerWorld);this.defaultLayerComposition.pushOpaque(this.defaultLayerImmediate);this.defaultLayerComposition.pushTransparent(this.defaultLayerImmediate);this.defaultLayerComposition.pushTransparent(this.defaultLayerUi);
- this.scene.layers=this.defaultLayerComposition;this._immediateLayer=this.defaultLayerImmediate;this.scene.on("set:layers",function(a,b){for(var c=b.layerList,e,g=0;g<c.length;g++)switch(e=c[g],e.id){case pc.LAYERID_DEPTH:e.onEnable=d.defaultLayerDepth.onEnable;e.onDisable=d.defaultLayerDepth.onDisable;e.onPreRenderOpaque=d.defaultLayerDepth.onPreRenderOpaque;e.onPostRenderOpaque=d.defaultLayerDepth.onPostRenderOpaque;e.depthClearOptions=d.defaultLayerDepth.depthClearOptions;e.rgbaDepthClearOptions=
- d.defaultLayerDepth.rgbaDepthClearOptions;e.shaderPass=d.defaultLayerDepth.shaderPass;e.onPostCull=d.defaultLayerDepth.onPostCull;e.onDrawCall=d.defaultLayerDepth.onDrawCall;break;case pc.LAYERID_UI:e.passThrough=d.defaultLayerUi.passThrough;break;case pc.LAYERID_IMMEDIATE:e.passThrough=d.defaultLayerImmediate.passThrough}});this.renderer=new pc.ForwardRenderer(this.graphicsDevice);this.renderer.scene=this.scene;this.lightmapper=new pc.Lightmapper(this.graphicsDevice,this.root,this.scene,this.renderer,
- this.assets);this.once("prerender",this._firstBake,this);this.batcher=new pc.BatchManager(this.graphicsDevice,this.root,this.scene);this.once("prerender",this._firstBatch,this);this.keyboard=b.keyboard||null;this.mouse=b.mouse||null;this.touch=b.touch||null;this.gamepads=b.gamepads||null;if(this.elementInput=b.elementInput||null)this.elementInput.app=this;this.vr=null;b.vr&&this._onVrChange(b.vr);this._inTools=!1;this._skyboxLast=0;this._scriptPrefix=b.scriptPrefix||"";this.enableBundles&&this.loader.addHandler("bundle",
- new pc.BundleHandler(this.assets));this.loader.addHandler("animation",new pc.AnimationHandler);this.loader.addHandler("model",new pc.ModelHandler(this.graphicsDevice,this.scene.defaultMaterial));this.loader.addHandler("material",new pc.MaterialHandler(this));this.loader.addHandler("texture",new pc.TextureHandler(this.graphicsDevice,this.assets,this.loader));this.loader.addHandler("text",new pc.TextHandler);this.loader.addHandler("json",new pc.JsonHandler);this.loader.addHandler("audio",new pc.AudioHandler(this._audioManager));
- this.loader.addHandler("script",new pc.ScriptHandler(this));this.loader.addHandler("scene",new pc.SceneHandler(this));this.loader.addHandler("cubemap",new pc.CubemapHandler(this.graphicsDevice,this.assets,this.loader));this.loader.addHandler("html",new pc.HtmlHandler);this.loader.addHandler("css",new pc.CssHandler);this.loader.addHandler("shader",new pc.ShaderHandler);this.loader.addHandler("hierarchy",new pc.HierarchyHandler(this));this.loader.addHandler("scenesettings",new pc.SceneSettingsHandler(this));
- this.loader.addHandler("folder",new pc.FolderHandler);this.loader.addHandler("font",new pc.FontHandler(this.loader));this.loader.addHandler("binary",new pc.BinaryHandler);this.loader.addHandler("textureatlas",new pc.TextureAtlasHandler(this.loader));this.loader.addHandler("sprite",new pc.SpriteHandler(this.assets,this.graphicsDevice));this.systems=new pc.ComponentSystemRegistry;this.systems.add(new pc.RigidBodyComponentSystem(this));this.systems.add(new pc.CollisionComponentSystem(this));this.systems.add(new pc.AnimationComponentSystem(this));
- this.systems.add(new pc.ModelComponentSystem(this));this.systems.add(new pc.CameraComponentSystem(this));this.systems.add(new pc.LightComponentSystem(this));pc.script.legacy?this.systems.add(new pc.ScriptLegacyComponentSystem(this)):this.systems.add(new pc.ScriptComponentSystem(this));this.systems.add(new pc.AudioSourceComponentSystem(this,this._audioManager));this.systems.add(new pc.SoundComponentSystem(this,this._audioManager));this.systems.add(new pc.AudioListenerComponentSystem(this,this._audioManager));
- this.systems.add(new pc.ParticleSystemComponentSystem(this));this.systems.add(new pc.ScreenComponentSystem(this));this.systems.add(new pc.ElementComponentSystem(this));this.systems.add(new pc.ButtonComponentSystem(this));this.systems.add(new pc.ScrollViewComponentSystem(this));this.systems.add(new pc.ScrollbarComponentSystem(this));this.systems.add(new pc.SpriteComponentSystem(this));this.systems.add(new pc.LayoutGroupComponentSystem(this));this.systems.add(new pc.LayoutChildComponentSystem(this));
- this.systems.add(new pc.ZoneComponentSystem(this));this._visibilityChangeHandler=this.onVisibilityChange.bind(this);void 0!==document.hidden?(this._hiddenAttr="hidden",document.addEventListener("visibilitychange",this._visibilityChangeHandler,!1)):void 0!==document.mozHidden?(this._hiddenAttr="mozHidden",document.addEventListener("mozvisibilitychange",this._visibilityChangeHandler,!1)):void 0!==document.msHidden?(this._hiddenAttr="msHidden",document.addEventListener("msvisibilitychange",this._visibilityChangeHandler,
- !1)):void 0!==document.webkitHidden&&(this._hiddenAttr="webkitHidden",document.addEventListener("webkitvisibilitychange",this._visibilityChangeHandler,!1));this.tick=c(this)};f._currentApplication=null;f._applications={};f.getApplication=function(a){return a?f._applications[a]:f._currentApplication};var b=function(a){this.length=a;this.count=0;this.inc=function(){this.count++};this.done=function(){return this.count===this.length}};Object.assign(f.prototype,{configure:function(a,b){var c=this;pc.http.get(a,
- function(a,d){if(a)b(a);else{var e=d.application_properties,g=d.scenes,f=d.assets;c._parseApplicationProperties(e,function(a){c._onVrChange(e.vr);c._parseScenes(g);c._parseAssets(f);a?b(a):b(null)})}})},preload:function(a){var c=this,d,f;c.fire("preload:start");var k=this.assets.list({preload:!0}),p=new b(k.length),h=!1,n=function(){c.graphicsDevice&&!h&&p.done()&&(h=!0,c.fire("preload:end"),a())};f=k.length;if(p.length){var q=function(a){p.inc();c.fire("preload:progress",p.count/f);p.done()&&n()},
- m=function(a,b){p.inc();c.fire("preload:progress",p.count/f);p.done()&&n()};for(d=0;d<k.length;d++)k[d].loaded?(p.inc(),c.fire("preload:progress",p.count/f),p.done()&&n()):(k[d].once("load",q),k[d].once("error",m),this.assets.load(k[d]))}else n()},getSceneUrl:function(a){return(a=this._sceneRegistry.find(a))?a.url:null},loadSceneHierarchy:function(a,b){this._sceneRegistry.loadSceneHierarchy(a,b)},loadSceneSettings:function(a,b){this._sceneRegistry.loadSceneSettings(a,b)},loadScene:function(a,b){this._sceneRegistry.loadScene(a,
- b)},_preloadScripts:function(a,c){if(pc.script.legacy){var d=this;d.systems.script.preloading=!0;var e=this._getScriptReferences(a),f=0,p=e.length,h=new b(p),n,q=/^http(s)?:\/\//;if(p)for(var m=function(a,b){a&&console.error(a);h.inc();h.done()&&(d.systems.script.preloading=!1,c())},f=0;f<p;f++)n=e[f],!q.test(n.toLowerCase())&&d._scriptPrefix&&(n=pc.path.join(d._scriptPrefix,e[f])),this.loader.load(n,"script",m);else d.systems.script.preloading=!1,c()}else c()},_parseApplicationProperties:function(a,
- b){var c,d;a.useDevicePixelRatio||(a.useDevicePixelRatio=a.use_device_pixel_ratio);a.resolutionMode||(a.resolutionMode=a.resolution_mode);a.fillMode||(a.fillMode=a.fill_mode);a.vrPolyfillUrl||(a.vrPolyfillUrl=a.vr_polyfill_url);this._width=a.width;this._height=a.height;a.useDevicePixelRatio&&(this.graphicsDevice.maxPixelRatio=window.devicePixelRatio);this.setCanvasResolution(a.resolutionMode,this._width,this._height);this.setCanvasFillMode(a.fillMode,this._width,this._height);a.vr&&a.vrPolyfillUrl&&
- (pc.VrManager.isSupported&&!pc.platform.android||a.libraries.push(a.vrPolyfillUrl));if(a.layers&&a.layerOrder){var e=new pc.LayerComposition,f={};for(c in a.layers)d=a.layers[c],d.id=parseInt(c,10),d.enabled=d.id!==pc.LAYERID_DEPTH,f[c]=new pc.Layer(d);c=0;for(d=a.layerOrder.length;c<d;c++){var h=a.layerOrder[c],n=f[h.layer];n&&(h.transparent?e.pushTransparent(n):e.pushOpaque(n),e.subLayerEnabled[c]=h.enabled)}this.scene.layers=e}if(a.batchGroups)for(c=0,d=a.batchGroups.length;c<d;c++)e=a.batchGroups[c],
- this.batcher.addGroup(e.name,e.dynamic,e.maxAabbSize,e.id,e.layers);a.i18nAssets&&(this.i18n.assets=a.i18nAssets);this._loadLibraries(a.libraries,b)},_loadLibraries:function(a,b){var c=a.length,d=c,e=this,f=/^http(s)?:\/\//;if(c)for(var h=function(a,c){d--;a?b(a):0===d&&(e.onLibrariesLoaded(),b(null))},n=0;n<c;++n){var q=a[n];!f.test(q.toLowerCase())&&e._scriptPrefix&&(q=pc.path.join(e._scriptPrefix,q));this.loader.load(q,"script",h)}else b(null)},_parseScenes:function(a){if(a)for(var b=0;b<a.length;b++)this._sceneRegistry.add(a[b].name,
- a[b].url)},_parseAssets:function(a){var b,c,d=[],f={},p={};if(pc.script.legacy){if(this.enableBundles)for(c in a)"bundle"===a[c].type&&(p[c]=!0,d.push(a[c]));for(c in a)p[c]||d.push(a[c])}else{for(b=0;b<this.scriptsOrder.length;b++)c=this.scriptsOrder[b],a[c]&&(f[c]=!0,d.push(a[c]));if(this.enableBundles)for(c in a)"bundle"===a[c].type&&(p[c]=!0,d.push(a[c]));for(c in a)f[c]||p[c]||d.push(a[c])}for(b=0;b<d.length;b++)a=d[b],c=new pc.Asset(a.name,a.type,a.file,a.data),c.id=parseInt(a.id,10),c.preload=
- a.preload?a.preload:!1,c.tags.add(a.tags),this.assets.add(c)},_getScriptReferences:function(a){var b,c,d=[];a.settings.priority_scripts&&(d=a.settings.priority_scripts);var f=[],p={};for(b=0;b<d.length;b++)f.push(d[b]),p[d[b]]=!0;a=a.entities;for(c in a)if(a[c].components.script)for(d=a[c].components.script.scripts,b=0;b<d.length;b++)p[d[b].url]||(f.push(d[b].url),p[d[b].url]=!0);return f},start:function(){this.frame=0;this.fire("start",{timestamp:pc.now(),target:this});if(!this._librariesLoaded)this.onLibrariesLoaded();
- pc.ComponentSystem.initialize(this.root);this.fire("initialize");pc.ComponentSystem.postInitialize(this.root);this.fire("postinitialize");this.tick()},update:function(a){this.frame++;this.graphicsDevice.updateClientRect();this.vr&&this.vr.poll();pc.script.legacy&&pc.ComponentSystem.fixedUpdate(1/60,this._inTools);pc.ComponentSystem.update(a,this._inTools);pc.ComponentSystem.postUpdate(a,this._inTools);this.fire("update",a);this.controller&&this.controller.update(a);this.mouse&&this.mouse.update(a);
- this.keyboard&&this.keyboard.update(a);this.gamepads&&this.gamepads.update(a)},render:function(){this.fire("prerender");this.root.syncHierarchy();this.batcher.updateAll();pc._skipRenderCounter=0;this.renderer.renderComposition(this.scene.layers);this.fire("postrender")},_fillFrameStats:function(a,b,c){var d=this.stats.frame;d.dt=b;d.ms=c;a>d._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[pc.PRIMITIVE_TRIANGLES]/3+Math.max(a[pc.PRIMITIVE_TRISTRIP]-2,0)+Math.max(a[pc.PRIMITIVE_TRIFAN]-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;b<a.length;b++)b<pc.PRIMITIVE_TRIANGLES&&(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;a===pc.RESOLUTION_AUTO&&
- void 0===b&&(b=this.graphicsDevice.canvas.clientWidth,c=this.graphicsDevice.canvas.clientHeight);this.graphicsDevice.resizeCanvas(b,c)},isFullscreen:function(){return!!document.fullscreenElement},enableFullscreen:function(a,b,c){a=a||this.graphicsDevice.canvas;var d=function(){b();document.removeEventListener("fullscreenchange",d)},e=function(){c();document.removeEventListener("fullscreenerror",e)};b&&document.addEventListener("fullscreenchange",d,!1);c&&document.addEventListener("fullscreenerror",
- e,!1);a.requestFullscreen?a.requestFullscreen(Element.ALLOW_KEYBOARD_INPUT):c()},disableFullscreen:function(a){var b=function(){a();document.removeEventListener("fullscreenchange",b)};a&&document.addEventListener("fullscreenchange",b,!1);document.exitFullscreen()},isHidden:function(){return document[this._hiddenAttr]},onVisibilityChange:function(){this.isHidden()?this._audioManager.suspend():this._audioManager.resume()},resizeCanvas:function(a,b){if(this._allowResize){var c=window.innerWidth,d=window.innerHeight;
- if(navigator.isCocoonJS)a=c,b=d,this.graphicsDevice.resizeCanvas(a,b);else{if(this._fillMode===pc.FILLMODE_KEEP_ASPECT){var e=this.graphicsDevice.canvas.width/this.graphicsDevice.canvas.height;e>c/d?(a=c,b=a/e):(b=d,a=b*e)}else this._fillMode===pc.FILLMODE_FILL_WINDOW&&(a=c,b=d);this.graphicsDevice.canvas.style.width=a+"px";this.graphicsDevice.canvas.style.height=b+"px";this._resolutionMode===pc.RESOLUTION_AUTO&&this.setCanvasResolution(pc.RESOLUTION_AUTO)}return{width:a,height:b}}},onLibrariesLoaded:function(){this._librariesLoaded=
- !0;this.systems.rigidbody.onLibraryLoaded();this.systems.collision.onLibraryLoaded()},applySceneSettings:function(a){var b;this.systems.rigidbody&&"undefined"!==typeof Ammo&&(b=a.physics.gravity,this.systems.rigidbody.setGravity(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})},_onVrChange:function(a){a?this.vr||(this.vr=new pc.VrManager(this)):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()},destroy:function(){var a,b,c=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 l=this.systems.list;a=0;for(b=l.length;a<b;a++)l[a].destroy();pc.ComponentSystem.destroy();b=this.assets.list();for(a=0;a<b.length;a++)b[a].unload(),b[a].off();this.assets.off();this.bundles.destroy();this.bundles=null;this.i18n.destroy();this.i18n=null;for(var k in this.loader.getHandler("script")._cache)a=
- this.loader.getHandler("script")._cache[k],(b=a.parentNode)&&b.removeChild(a);this.loader.getHandler("script")._cache={};this.loader.destroy();this.loader=null;this.scene.destroy();this.scene=null;this.systems=[];this.context=null;this.scripts.destroy();this.scripts=null;this._sceneRegistry.destroy();this._sceneRegistry=null;this.lightmapper.destroy();this.lightmapper=null;this.batcher.destroyManager();this.batcher=null;this._entityIndex={};this.defaultLayerDepth.onPreRenderOpaque=null;this.defaultLayerDepth.onPostRenderOpaque=
- null;this.defaultLayerDepth.onDisable=null;this.defaultLayerWorld=this.defaultLayerDepth=this.defaultLayerDepth.onEnable=null;pc.destroyPostEffectQuad();this.graphicsDevice.destroy();this.tick=this.renderer=this.graphicsDevice=null;this.off();this._audioManager&&(this._audioManager.destroy(),this._audioManager=null);pc.http=new pc.Http;pc.script.app=null;pc.ParticleEmitter.DEFAULT_PARAM_TEXTURE=null;f._applications[c]=null;f._currentApplication===this&&(f._currentApplication=null)}});var a={},c=function(b){return function(c){if(b.graphicsDevice){f._currentApplication=
- b;pc.app=b;c=c||pc.now();var d;d=pc.math.clamp((c-(b._time||c))/1E3,0,b.maxDeltaTime);d*=b.timeScale;b._time=c;b.vr&&b.vr.display?b.vr.display.requestAnimationFrame(b.tick):window.requestAnimationFrame(b.tick);if(!b.graphicsDevice.contextLost){b.update(d);if(b.autoRender||b.renderNextFrame)b.render(),b.renderNextFrame=!1;a.timestamp=pc.now();a.target=b;b.fire("frameend",a);b.fire("frameEnd",a);b.vr&&b.vr.display&&b.vr.display.presenting&&b.vr.display.submitFrame()}}}};return{FILLMODE_NONE:"NONE",
- FILLMODE_FILL_WINDOW:"FILL_WINDOW",FILLMODE_KEEP_ASPECT:"KEEP_ASPECT",RESOLUTION_AUTO:"AUTO",RESOLUTION_FIXED:"FIXED",Application:f}}());pc.ApplicationStats=function(f){this.frame={fps:0,ms:0,dt:0,updateStart:0,updateTime:0,renderStart:0,renderTime:0,physicsStart:0,physicsTime:0,cullTime:0,sortTime:0,skinTime:0,morphTime:0,instancingTime:0,triangles:0,otherPrimitives:0,shaders:0,materials:0,cameras:0,shadowMapUpdates:0,shadowMapTime:0,depthMapTime:0,forwardTime:0,_timeToCountFrames:0,_fpsAccum:0};this.drawCalls={forward:0,depth:0,shadow:0,immediate:0,misc:0,total:0,skinned:0,instanced:0,removedByInstancing:0};this.misc={renderTargetCreationTime:0};
- this.particles={updatesPerFrame:0,_updatesPerFrame:0,frameTime:0,_frameTime:0};this.vram=f._vram;this.shaders=f._shaderStats;Object.defineProperty(this.vram,"totalUsed",{get:function(){return this.tex+this.vb+this.ib}});Object.defineProperty(this,"scene",{get:function(){return pc.Application._currentApplication.scene._stats}});Object.defineProperty(this,"lightmapper",{get:function(){return pc.Application._currentApplication.lightmapper._stats}});Object.defineProperty(this,"batcher",{get:function(){return pc.Application._currentApplication.batcher._stats}});
- pc.events.attach(this)};Object.assign(pc,function(){var f=function(b){this._app=b;this._list=[];this._index={};this._urlIndex={}};f.prototype.destroy=function(){this._app=null};f.prototype.list=function(){return this._list};f.prototype.add=function(b,a){if(this._index.hasOwnProperty(b))return!1;var c=new pc.SceneRegistryItem(b,a),d=this._list.push(c);this._index[c.name]=d-1;this._urlIndex[c.url]=d-1;return!0};f.prototype.find=function(b){return this._index.hasOwnProperty(b)?this._list[this._index[b]]:null};f.prototype.findByUrl=
- function(b){return this._urlIndex.hasOwnProperty(b)?this._list[this._urlIndex[b]]:null};f.prototype.remove=function(b){if(this._index.hasOwnProperty(b)){var a=this._index[b],c=this._list[a];delete this._urlIndex[c.url];delete this._index[b];this._list.splice(a,1);for(a=0;a<this._list.length;a++)c=this._list[a],this._index[c.name]=a,this._urlIndex[c.url]=a}};f.prototype.loadSceneHierarchy=function(b,a){var c=this,d=this._app.loader.getHandler("hierarchy");this._app.assets&&this._app.assets.prefix&&
- !pc.ABSOLUTE_URL.test(b)&&(b=pc.path.join(this._app.assets.prefix,b));d.load(b,function(e,g){e?a&&a(e):c._app._preloadScripts(g,function(){c._app.systems.script.preloading=!0;var f=d.open(b,g);c._app.systems.script.preloading=!1;c._app.loader.clearCache(b,"hierarchy");c._app.root.addChild(f);pc.ComponentSystem.initialize(f);pc.ComponentSystem.postInitialize(f);a&&a(e,f)})})};f.prototype.loadSceneSettings=function(b,a){var c=this;this._app.assets&&this._app.assets.prefix&&!pc.ABSOLUTE_URL.test(b)&&
- (b=pc.path.join(this._app.assets.prefix,b));this._app.loader.load(b,"scenesettings",function(b,e){b?a&&a(b):(c._app.applySceneSettings(e),a&&a(null))})};f.prototype.loadScene=function(b,a){var c=this,d=this._app.loader.getHandler("scene");this._app.assets&&this._app.assets.prefix&&!pc.ABSOLUTE_URL.test(b)&&(b=pc.path.join(this._app.assets.prefix,b));d.load(b,function(e,g){e?a&&a(e):c._app._preloadScripts(g,function(){c._app.systems.script.preloading=!0;var e=d.open(b,g);c._app.systems.script.preloading=
- !1;c._app.loader.clearCache(b,"scene");c._app.loader.patch({resource:e,type:"scene"},c._app.assets);c._app.root.addChild(e.root);c._app.systems.rigidbody&&"undefined"!==typeof Ammo&&c._app.systems.rigidbody.setGravity(e._gravity.x,e._gravity.y,e._gravity.z);a&&a(null,e)})})};return{SceneRegistry:f,SceneRegistryItem:function(b,a){this.name=b;this.url=a}}}());Object.assign(pc,function(){var f=function(){this.list=[]};Object.assign(f.prototype,{add:function(b){var a=b.id;if(this[a])throw Error(pc.string.format("ComponentSystem name '{0}' already registered or not allowed",a));this[a]=b;this.list.push(b)},remove:function(b){b=b.id;if(!this[b])throw Error(pc.string.format("No ComponentSystem named '{0}' registered",b));delete this[b];b=this.list.indexOf(this[b]);-1!==b&&this.list.splice(b,1)}});return{ComponentSystemRegistry:f}}());Object.assign(pc,function(){function f(a,b){if(!a)return a;switch(b){case "rgb":return a instanceof pc.Color?a.clone():new pc.Color(a[0],a[1],a[2]);case "rgba":return a instanceof pc.Color?a.clone():new pc.Color(a[0],a[1],a[2],a[3]);case "vec2":return a instanceof pc.Vec2?a.clone():new pc.Vec2(a[0],a[1]);case "vec3":return a instanceof pc.Vec3?a.clone():new pc.Vec3(a[0],a[1],a[2]);case "vec4":return a instanceof pc.Vec4?a.clone():new pc.Vec4(a[0],a[1],a[2],a[3]);case "boolean":case "number":case "string":return a;
- case "entity":return a;default:throw Error("Could not convert unhandled type: "+b);}}var b=function(a){this.app=a;this.store={};this.schema=[];pc.events.attach(this)};Object.assign(b,{_helper:function(a,b){for(var c=0,e=a.length;c<e;c++)a[c].f.call(a[c].s,b)},initialize:function(a){this._helper(this._init,a)},postInitialize:function(a){this._helper(this._postInit,a);this.fire("postinitialize",a)},update:function(a,b){this._helper(b?this._toolsUpdate:this._update,a)},fixedUpdate:function(a,b){this._helper(this._fixedUpdate,
- a)},postUpdate:function(a,b){this._helper(this._postUpdate,a)},_init:[],_postInit:[],_toolsUpdate:[],_update:[],_fixedUpdate:[],_postUpdate:[],bind:function(a,b,d){switch(a){case "initialize":this._init.push({f:b,s:d});break;case "postInitialize":this._postInit.push({f:b,s:d});break;case "update":this._update.push({f:b,s:d});break;case "postUpdate":this._postUpdate.push({f:b,s:d});break;case "fixedUpdate":this._fixedUpdate.push({f:b,s:d});break;case "toolsUpdate":this._toolsUpdate.push({f:b,s:d});
- break;default:console.error("Component System does not support event",a)}},_erase:function(a,b,d){for(var c=0;c<a.length;c++)a[c].f===b&&a[c].s===d&&a.splice(c--,1)},unbind:function(a,b,d){switch(a){case "initialize":this._erase(this._init,b,d);break;case "postInitialize":this._erase(this._postInit,b,d);break;case "update":this._erase(this._update,b,d);break;case "postUpdate":this._erase(this._postUpdate,b,d);break;case "fixedUpdate":this._erase(this._fixedUpdate,b,d);break;case "toolsUpdate":this._erase(this._toolsUpdate,
- b,d);break;default:console.error("Component System does not support event",a)}}});b.prototype={addComponent:function(a,b){var c=new this.ComponentType(this,a),e=new this.DataType;b=b||{};this.store[a.getGuid()]={entity:a,data:e};a[this.id]=c;a.c[this.id]=c;this.initializeComponentData(c,b,[]);this.fire("add",a,c);return c},removeComponent:function(a){var b=this.store[a.getGuid()];this.fire("beforeremove",a,a.c[this.id]);delete this.store[a.getGuid()];delete a[this.id];delete a.c[this.id];this.fire("remove",
- a,b.data)},cloneComponent:function(a,b){var c=this.store[a.getGuid()];return this.addComponent(b,c.data)},initializeComponentData:function(a,b,d){b=b||{};for(var c,g,l,k=0,p=d.length;k<p;k++)c=d[k],"object"===typeof c?(g=c.name,c=c.type):(g=c,c=void 0),l=b[g],void 0!==l?(void 0!==c&&(l=f(l,c)),a[g]=l):a[g]=a.data[g];if(a.enabled&&a.entity.enabled)a.onEnable()},getPropertiesOfType:function(a){var b=[];(this.schema||[]).forEach(function(c){c&&"object"===typeof c&&c.type===a&&b.push(c)});return b},destroy:function(){this.off()}};
- pc.events.attach(b);b.destroy=function(){b.off("initialize");b.off("postInitialize");b.off("toolsUpdate");b.off("update");b.off("fixedUpdate");b.off("postUpdate")};return{ComponentSystem:b}}());Object.assign(pc,function(){var f=function(b,a){this.system=b;this.entity=a;pc.events.attach(this);this.system.schema&&!this._accessorsBuilt&&this.buildAccessors(this.system.schema);this.on("set",function(a,b,e){this.fire("set_"+a,a,b,e)});this.on("set_enabled",this.onSetEnabled,this)};f._buildAccessors=function(b,a){a.forEach(function(a){var c="object"===typeof a?a.name:a;Object.defineProperty(b,c,{get:function(){return this.data[c]},set:function(a){var b=this.data,d=b[c];b[c]=a;this.fire("set",
- c,d,a)},configurable:!0})});b._accessorsBuilt=!0};f.prototype={buildAccessors:function(b){f._buildAccessors(this,b)},onSetEnabled:function(b,a,c){if(a!==c&&this.entity.enabled)if(c)this.onEnable();else this.onDisable()},onEnable:function(){},onDisable:function(){},onPostStateChange:function(){}};Object.defineProperty(f.prototype,"data",{get:function(){var b=this.system.store[this.entity.getGuid()];return b?b.data:null}});return{Component:f}}());Object.assign(pc,function(){return{ComponentData:function(){}}}());Object.assign(pc,function(){var f=function(b,a){pc.Component.call(this,b,a);this.animationsIndex={};this.on("set_animations",this.onSetAnimations,this);this.on("set_assets",this.onSetAssets,this);this.on("set_loop",this.onSetLoop,this)};f.prototype=Object.create(pc.Component.prototype);f.prototype.constructor=f;Object.assign(f.prototype,{play:function(b,a){if(!this.data.animations[b])console.error(pc.string.format("Trying to play animation '{0}' which doesn't exist",b));else if(this.enabled&&this.entity.enabled){a=
- a||0;var c=this.data;c.prevAnim=c.currAnim;c.currAnim=b;c.model&&(c.blending=0<a&&c.prevAnim,c.blending?(c.blendTime=a,c.blendTimeRemaining=a,c.fromSkel.animation=c.animations[c.prevAnim],c.fromSkel.addTime(c.skeleton._time),c.toSkel.animation=c.animations[c.currAnim]):c.skeleton.animation=c.animations[c.currAnim]);c.playing=!0}},getAnimation:function(b){return this.data.animations[b]},setModel:function(b){var a=this.data;if(b){var c=b.getGraph();a.fromSkel=new pc.Skeleton(c);a.toSkel=new pc.Skeleton(c);
- a.skeleton=new pc.Skeleton(c);a.skeleton.looping=a.loop;a.skeleton.setGraph(c)}a.model=b;a.animations&&a.currAnim&&a.animations[a.currAnim]&&this.play(a.currAnim)},loadAnimationAssets:function(b){if(b&&b.length){var a=this,c=this.system.app.assets,d,e=b.length,g=function(b){a.animations[b.name]=b.resource;a.animationsIndex[b.id]=b.name;a.animations=a.animations},f=function(b){b.off("change",a.onAssetChanged,a);b.on("change",a.onAssetChanged,a);b.off("remove",a.onAssetRemoved,a);b.on("remove",a.onAssetRemoved,
- a);b.resource?g(b):(b.once("load",g,a),a.enabled&&a.entity.enabled&&c.load(b))};for(d=0;d<e;d++){var k=c.get(b[d]);if(k)f(k);else c.on("add:"+b[d],f)}}},onAssetChanged:function(b,a,c,d){"resource"===a&&(c?(this.animations[b.name]=c,this.animationsIndex[b.id]=b.name,this.data.currAnim===b.name&&this.data.playing&&this.data.enabled&&this.entity.enabled&&this.play(b.name,0)):(delete this.animations[b.name],delete this.animationsIndex[b.id]))},onAssetRemoved:function(b){b.off("remove",this.onAssetRemoved,
- this);this.animations&&this.animations[b.name]&&(delete this.animations[b.name],delete this.animationsIndex[b.id],this.data.currAnim===b.name&&this._stopCurrentAnimation())},_stopCurrentAnimation:function(){this.data.currAnim=null;this.data.playing=!1;this.data.skeleton&&(this.data.skeleton.currentTime=0,this.data.skeleton.animation=null)},onSetAnimations:function(b,a,c){b=this.data;(a=this.entity.model)&&(a=a.model)&&a!==b.model&&this.entity.animation.setModel(a);if(!b.currAnim&&b.activate&&b.enabled&&
- this.entity.enabled)for(var d in b.animations){this.play(d,0);break}},onSetAssets:function(b,a,c){if(a&&a.length)for(b=0;b<a.length;b++)if(a[b]){var d=this.system.app.assets.get(a[b]);if(d){d.off("change",this.onAssetChanged,this);d.off("remove",this.onAssetRemoved,this);var e=this.animationsIndex[d.id];this.data.currAnim===e&&this._stopCurrentAnimation();delete this.animations[e];delete this.animationsIndex[d.id]}}a=c.map(function(a){return a instanceof pc.Asset?a.id:a});this.loadAnimationAssets(a)},
- onSetLoop:function(b,a,c){this.data.skeleton&&(this.data.skeleton.looping=this.data.loop)},onSetCurrentTime:function(b,a,c){this.data.skeleton.currentTime=c;this.data.skeleton.addTime(0);this.data.skeleton.updateGraph()},onEnable:function(){pc.Component.prototype.onEnable.call(this);var b=this.data.assets,a=this.system.app.assets;if(b)for(var c=0,d=b.length;c<d;c++){var e=b[c];e instanceof pc.Asset||(e=a.get(e));e&&!e.resource&&a.load(e)}if(this.data.activate&&!this.data.currAnim)for(var g in this.data.animations){this.play(g,
- 0);break}},onBeforeRemove:function(){for(var b=0;b<this.assets.length;b++){var a=this.system.app.assets.get(this.assets[b]);a&&(a.off("change",this.onAssetChanged,this),a.off("remove",this.onAssetRemoved,this))}delete this.data.animation;delete this.data.skeleton;delete this.data.fromSkel;delete this.data.toSkel}});Object.defineProperties(f.prototype,{currentTime:{get:function(){return this.data.skeleton._time},set:function(b){this.data.skeleton.currentTime=b;this.data.skeleton.addTime(0);this.data.skeleton.updateGraph()}},
- duration:{get:function(){return this.data.animations[this.data.currAnim].duration}}});return{AnimationComponent:f}}());Object.assign(pc,function(){var f="enabled assets speed loop activate animations skeleton model prevAnim currAnim fromSkel toSkel blending blendTimeRemaining playing".split(" "),b=function(a){pc.ComponentSystem.call(this,a);this.id="animation";this.description="Specifies the animation assets that can run on the model specified by the Entity's model Component.";this.ComponentType=pc.AnimationComponent;this.DataType=pc.AnimationComponentData;this.schema=f;this.on("beforeremove",this.onBeforeRemove,
- this);this.on("update",this.onUpdate,this);pc.ComponentSystem.bind("update",this.onUpdate,this)};b.prototype=Object.create(pc.ComponentSystem.prototype);b.prototype.constructor=b;pc.Component._buildAccessors(pc.AnimationComponent.prototype,f);Object.assign(b.prototype,{initializeComponentData:function(a,b,d){d=["activate","enabled","loop","speed","assets"];pc.ComponentSystem.prototype.initializeComponentData.call(this,a,b,d)},cloneComponent:function(a,b){var c;this.addComponent(b,{});b.animation.assets=
- a.animation.assets.slice();b.animation.data.speed=a.animation.speed;b.animation.data.loop=a.animation.loop;b.animation.data.activate=a.animation.activate;b.animation.data.enabled=a.animation.enabled;var e={},g=a.animation.animations;for(c in g)g.hasOwnProperty(c)&&(e[c]=g[c]);b.animation.animations=e;e={};g=a.animation.animationsIndex;for(c in g)g.hasOwnProperty(c)&&(e[c]=g[c]);b.animation.animationsIndex=e},onBeforeRemove:function(a,b){b.onBeforeRemove()},onUpdate:function(a){var b=this.store,d;
- for(d in b)if(b.hasOwnProperty(d)){var e=b[d],g=e.data;g.enabled&&g.playing&&e.entity.enabled&&(e=g.skeleton,null!==e&&null!==g.model&&(g.blending?(g.blendTimeRemaining-=a,0>g.blendTimeRemaining&&(g.blendTimeRemaining=0),e.blend(g.fromSkel,g.toSkel,1-g.blendTimeRemaining/g.blendTime)):(e.addTime(a*g.speed),e._time!==e._animation.duration||g.loop||(g.playing=!1)),g.blending&&0===g.blendTimeRemaining&&(g.blending=!1,e.animation=g.toSkel._animation),e.updateGraph()))}}});return{AnimationComponentSystem:b}}());Object.assign(pc,function(){return{AnimationComponentData:function(){this.assets=[];this.speed=1;this.enabled=this.activate=this.loop=!0;this.animations={};this.toSkel=this.fromSkel=this.currAnim=this.prevAnim=this.model=this.skeleton=null;this.blending=!1;this.blendTimeRemaining=this.blendTime=0;this.playing=!1}}}());Object.assign(pc,function(){var f=function(b,a){pc.Component.call(this,b,a);this._type="asset";this._model=this._asset=null;this._mapping={};this._receiveShadows=this._castShadows=!0;this._materialAsset=null;this._material=b.defaultMaterial;this._castShadowsLightmap=!0;this._lightmapped=!1;this._lightmapSizeMultiplier=1;this._isStatic=!1;this._layers=[pc.LAYERID_WORLD];this._batchGroupId=-1;this._area=null;this._assetOld=0;this._materialEvents=null;this._clonedModel=this._dirtyMaterialAsset=this._dirtyModelAsset=
- !1};f.prototype=Object.create(pc.Component.prototype);f.prototype.constructor=f;Object.assign(f.prototype,{setVisible:function(b){console.warn("WARNING: setVisible: Function is deprecated. Set enabled property instead.");this.enabled=b},addModelToLayers:function(){for(var b,a=this.system.app.scene.layers,c=0;c<this._layers.length;c++)(b=a.getLayerById(this._layers[c]))&&b.addMeshInstances(this.meshInstances)},removeModelFromLayers:function(b){for(var a,c=this.system.app.scene.layers,d=0;d<this._layers.length;d++)(a=
- c.getLayerById(this._layers[d]))&&a.removeMeshInstances(b.meshInstances)},onRemove:function(){this.materialAsset=this.asset=null;this._unsetMaterialEvents()},onLayersChanged:function(b,a){this.addModelToLayers();b.off("add",this.onLayerAdded,this);b.off("remove",this.onLayerRemoved,this);a.on("add",this.onLayerAdded,this);a.on("remove",this.onLayerRemoved,this)},onLayerAdded:function(b){0>this.layers.indexOf(b.id)||b.addMeshInstances(this.meshInstances)},onLayerRemoved:function(b){0>this.layers.indexOf(b.id)||
- b.removeMeshInstances(this.meshInstances)},_setMaterialEvent:function(b,a,c,d){a=a+":"+c;this.system.app.assets.on(a,d,this);this._materialEvents||(this._materialEvents=[]);this._materialEvents[b]||(this._materialEvents[b]={});this._materialEvents[b][a]={id:c,handler:d}},_unsetMaterialEvents:function(){var b=this.system.app.assets,a=this._materialEvents;if(a){for(var c=0,d=a.length;c<d;c++)if(a[c]){var e=a[c],g;for(g in e)b.off(g,e[g].handler,this)}this._materialEvents=null}},_getAssetByIdOrPath:function(b){var a=
- null;isNaN(parseInt(b,10))?this.asset&&(b=this._getMaterialAssetUrl(b))&&(a=this.system.app.assets.getByUrl(b)):a=this.system.app.assets.get(b);return a},_getMaterialAssetUrl:function(b){if(!this.asset)return null;var a=this.system.app.assets.get(this.asset);if(!a)return null;a=a.getFileUrl();a=pc.path.getDirectory(a);return pc.path.join(a,b)},_loadAndSetMeshInstanceMaterial:function(b,a,c){var d=this.system.app.assets;b&&b&&(b.resource?(a.material=b.resource,this._setMaterialEvent(c,"remove",b.id,
- function(){a.material=this.system.defaultMaterial})):(this._setMaterialEvent(c,"load",b.id,function(d){a.material=d.resource;this._setMaterialEvent(c,"remove",b.id,function(){a.material=this.system.defaultMaterial})}),this.enabled&&this.entity.enabled&&d.load(b)))},onEnable:function(){var b=this.system.app,a=b.scene;a.on("set:layers",this.onLayersChanged,this);a.layers&&(a.layers.on("add",this.onLayerAdded,this),a.layers.on("remove",this.onLayerRemoved,this));var a="asset"===this._type,c;this._model?
- this.addModelToLayers():a&&this._asset&&(c=b.assets.get(this._asset))&&c.resource!==this._model&&this._bindModelAsset(c);this._materialAsset&&(c=b.assets.get(this._materialAsset))&&c.resource!==this._material&&this._bindMaterialAsset(c);if(a&&this._mapping)for(var d in this._mapping)this._mapping[d]&&(c=this._getAssetByIdOrPath(this._mapping[d]))&&!c.resource&&b.assets.load(c);0<=this.batchGroupId&&b.batcher.markGroupDirty(this.batchGroupId)},onDisable:function(){var b=this.system.app,a=b.scene;a.off("set:layers",
- this.onLayersChanged,this);a.layers&&(a.layers.off("add",this.onLayerAdded,this),a.layers.off("remove",this.onLayerRemoved,this));0<=this.batchGroupId&&b.batcher.markGroupDirty(this.batchGroupId);this._model&&this.removeModelFromLayers(this._model)},hide:function(){if(this._model){var b,a,c=this._model.meshInstances;b=0;for(a=c.length;b<a;b++)c[b].visible=!1}},show:function(){if(this._model){var b,a,c=this._model.meshInstances;b=0;for(a=c.length;b<a;b++)c[b].visible=!0}},_bindMaterialAsset:function(b){b.on("load",
- this._onMaterialAssetLoad,this);b.on("unload",this._onMaterialAssetUnload,this);b.on("remove",this._onMaterialAssetRemove,this);b.on("change",this._onMaterialAssetChange,this);b.resource?this._onMaterialAssetLoad(b):this.enabled&&this.entity.enabled&&this.system.app.assets.load(b)},_unbindMaterialAsset:function(b){b.off("load",this._onMaterialAssetLoad,this);b.off("unload",this._onMaterialAssetUnload,this);b.off("remove",this._onMaterialAssetRemove,this);b.off("change",this._onMaterialAssetChange,
- this)},_onMaterialAssetAdd:function(b){this.system.app.assets.off("add:"+b.id,this._onMaterialAssetAdd,this);this._materialAsset===b.id&&this._bindMaterialAsset(b)},_onMaterialAssetLoad:function(b){this.material=b.resource},_onMaterialAssetUnload:function(b){this.material=this.system.defaultMaterial},_onMaterialAssetRemove:function(b){this._onMaterialAssetUnload(b)},_onMaterialAssetChange:function(b){},_bindModelAsset:function(b){this._unbindModelAsset(b);b.on("load",this._onModelAssetLoad,this);
- b.on("unload",this._onModelAssetUnload,this);b.on("change",this._onModelAssetChange,this);b.on("remove",this._onModelAssetRemove,this);b.resource?this._onModelAssetLoad(b):this.enabled&&this.entity.enabled&&this.system.app.assets.load(b)},_unbindModelAsset:function(b){b.off("load",this._onModelAssetLoad,this);b.off("unload",this._onModelAssetUnload,this);b.off("change",this._onModelAssetChange,this);b.off("remove",this._onModelAssetRemove,this)},_onModelAssetAdded:function(b){this.system.app.assets.off("add:"+
- b.id,this._onModelAssetAdd,this);b.id===this._asset&&this._bindModelAsset(b)},_onModelAssetLoad:function(b){this.model=b.resource.clone();this._clonedModel=!0},_onModelAssetUnload:function(b){this.model=null},_onModelAssetChange:function(b,a,c,d){"data"===a&&(this.mapping=this._mapping)},_onModelAssetRemove:function(b){this.model=null}});Object.defineProperty(f.prototype,"meshInstances",{get:function(){return this._model?this._model.meshInstances:null},set:function(b){this._model&&(this._model.meshInstances=
- b)}});Object.defineProperty(f.prototype,"type",{get:function(){return this._type},set:function(b){if(this._type!==b)if(this._area=null,this._type=b,"asset"===b)null!==this._asset?this._bindModelAsset(this._asset):this.model=null;else{var a=this.system,c=a.app.graphicsDevice;switch(b){case "box":a.box||(a.box=pc.createBox(c,{halfExtents:new pc.Vec3(.5,.5,.5)}));b=a.box;this._area={x:2,y:2,z:2,uv:2/3};break;case "capsule":a.capsule||(a.capsule=pc.createCapsule(c,{radius:.5,height:2}));b=a.capsule;this._area=
- {x:2*Math.PI,y:Math.PI,z:2*Math.PI,uv:1/3+1/3/3*2};break;case "cone":a.cone||(a.cone=pc.createCone(c,{baseRadius:.5,peakRadius:0,height:1}));b=a.cone;this._area={x:2.54,y:2.54,z:2.54,uv:1/3+1/3/3};break;case "cylinder":a.cylinder||(a.cylinder=pc.createCylinder(c,{radius:.5,height:1}));b=a.cylinder;this._area={x:Math.PI,y:1.58,z:Math.PI,uv:1/3+1/3/3*2};break;case "plane":a.plane||(a.plane=pc.createPlane(c,{halfExtents:new pc.Vec2(.5,.5),widthSegments:1,lengthSegments:1}));b=a.plane;this._area={x:0,
- y:1,z:0,uv:1};break;case "sphere":a.sphere||(a.sphere=pc.createSphere(c,{radius:.5}));b=a.sphere;this._area={x:Math.PI,y:Math.PI,z:Math.PI,uv:1};break;default:throw Error("Invalid model type: "+b);}var c=new pc.GraphNode,d=new pc.Model;d.graph=c;d.meshInstances=[new pc.MeshInstance(c,b,this._material)];a._inTools&&d.generateWireframe();this.model=d;this._asset=null}}});Object.defineProperty(f.prototype,"asset",{get:function(){return this._asset},set:function(b){var a=this.system.app.assets,c=b;b instanceof
- pc.Asset&&(c=b.id);this._asset!==c&&(this._asset&&(a.off("add:"+this._asset,this._onModelAssetAdded,this),(b=a.get(this._asset))&&this._unbindModelAsset(b)),(this._asset=c)?(c=a.get(this._asset))?this._bindModelAsset(c):(this.model=null,a.on("add:"+this._asset,this._onModelAssetAdded,this)):this.model=null)}});Object.defineProperty(f.prototype,"model",{get:function(){return this._model},set:function(b){if(this._model!==b&&(this._model&&(this.removeModelFromLayers(this._model),this.entity.removeChild(this._model.getGraph()),
- delete this._model._entity,this._clonedModel&&(this._model.destroy(),this._clonedModel=!1)),this._model=b)){b=this._model.meshInstances;for(var a=0;a<b.length;a++)b[a].castShadow=this._castShadows,b[a].receiveShadow=this._receiveShadows,b[a].isStatic=this._isStatic;this.lightmapped=this._lightmapped;this.entity.addChild(this._model.graph);this.enabled&&this.entity.enabled&&this.addModelToLayers();this._model._entity=this.entity;this.entity.animation&&this.entity.animation.setModel(this._model);"asset"===
- this.type?this.mapping=this._mapping:this._unsetMaterialEvents()}}});Object.defineProperty(f.prototype,"lightmapped",{get:function(){return this._lightmapped},set:function(b){if(b!==this._lightmapped){var a,c;this._lightmapped=b;if(this._model){var d=this._model.meshInstances;if(b)for(b=0;b<d.length;b++)a=d[b],c=a.mask,a.mask=(c|pc.MASK_BAKED)&~(pc.MASK_DYNAMIC|pc.MASK_LIGHTMAP);else for(b=0;b<d.length;b++)a=d[b],a.deleteParameter("texture_lightMap"),a.deleteParameter("texture_dirLightMap"),a._shaderDefs&=
- ~pc.SHADERDEF_LM,c=a.mask,a.mask=(c|pc.MASK_DYNAMIC)&~(pc.MASK_BAKED|pc.MASK_LIGHTMAP)}}}});Object.defineProperty(f.prototype,"castShadows",{get:function(){return this._castShadows},set:function(b){if(this._castShadows!==b){var a,c,d=this._model;if(d){var e=this.layers,g=this.system.app.scene;if(this._castShadows&&!b)for(c=0;c<e.length;c++)(a=this.system.app.scene.layers.getLayerById(this.layers[c]))&&a.removeShadowCasters(d.meshInstances);a=d.meshInstances;for(c=0;c<a.length;c++)a[c].castShadow=
- b;if(!this._castShadows&&b)for(c=0;c<e.length;c++)(a=g.layers.getLayerById(e[c]))&&a.addShadowCasters(d.meshInstances)}this._castShadows=b}}});Object.defineProperty(f.prototype,"receiveShadows",{get:function(){return this._receiveShadows},set:function(b){if(this._receiveShadows!==b&&(this._receiveShadows=b,this._model))for(var a=this._model.meshInstances,c=0,d=a.length;c<d;c++)a[c].receiveShadow=b}});Object.defineProperty(f.prototype,"castShadowsLightmap",{get:function(){return this._castShadowsLightmap},
- set:function(b){this._castShadowsLightmap=b}});Object.defineProperty(f.prototype,"lightmapSizeMultiplier",{get:function(){return this._lightmapSizeMultiplier},set:function(b){this._lightmapSizeMultiplier=b}});Object.defineProperty(f.prototype,"isStatic",{get:function(){return this._isStatic},set:function(b){if(this._isStatic!==b){this._isStatic=b;var a,c;if(this._model){var d=this._model.meshInstances;for(a=0;a<d.length;a++)c=d[a],c.isStatic=b}}}});Object.defineProperty(f.prototype,"layers",{get:function(){return this._layers},
- set:function(b){var a,c,d=this.system.app.scene.layers;if(this.meshInstances)for(a=0;a<this._layers.length;a++)(c=d.getLayerById(this._layers[a]))&&c.removeMeshInstances(this.meshInstances);for(a=this._layers.length=0;a<b.length;a++)this._layers[a]=b[a];if(this.enabled&&this.entity.enabled&&this.meshInstances)for(a=0;a<this._layers.length;a++)(c=d.getLayerById(this._layers[a]))&&c.addMeshInstances(this.meshInstances)}});Object.defineProperty(f.prototype,"batchGroupId",{get:function(){return this._batchGroupId},
- set:function(b){if(this._batchGroupId!==b){var a=this.system.app.batcher;0<=this._batchGroupId&&a.markGroupDirty(this._batchGroupId);0<=b&&a.markGroupDirty(b);0>b&&0<=this._batchGroupId&&this.enabled&&this.entity.enabled&&this.addModelToLayers();this._batchGroupId=b}}});Object.defineProperty(f.prototype,"materialAsset",{get:function(){return this._materialAsset},set:function(b){var a=b;b instanceof pc.Asset&&(a=b.id);b=this.system.app.assets;if(a!==this._materialAsset){if(this._materialAsset){b.off("add:"+
- this._materialAsset,this._onMaterialAdded,this);var c=b.get(this._materialAsset);c&&this._unbindMaterialAsset(c)}(this._materialAsset=a)?(a=b.get(this._materialAsset))?this._bindMaterialAsset(a):(this.material=this.system.defaultMaterial,b.on("add:"+this._materialAsset,this._onMaterialAdded,this)):this.material=this.system.defaultMaterial}}});Object.defineProperty(f.prototype,"material",{get:function(){return this._material},set:function(b){if(this._material!==b){this._material=b;var a=this._model;
- if(a&&"asset"!==this._type)for(var a=a.meshInstances,c=0,d=a.length;c<d;c++)a[c].material=b}}});Object.defineProperty(f.prototype,"mapping",{get:function(){return this._mapping},set:function(b){if("asset"===this._type&&(this._unsetMaterialEvents(),b||(b={}),this._mapping=b,this._model))for(var a=this._model.meshInstances,c=this.asset?this.system.app.assets.get(this.asset):null,c=c?c.data.mapping:null,d=null,e=0,g=a.length;e<g;e++)if(void 0!==b[e])b[e]?(d=this.system.app.assets.get(b[e]),this._loadAndSetMeshInstanceMaterial(d,
- a[e],e)):a[e].material=this.system.defaultMaterial;else if(c)if(c[e]&&(c[e].material||c[e].path)){if(void 0!==c[e].material)d=this.system.app.assets.get(c[e].material);else if(void 0!==c[e].path){var f=this._getMaterialAssetUrl(c[e].path);f&&(d=this.system.app.assets.getByUrl(f))}this._loadAndSetMeshInstanceMaterial(d,a[e],e)}else a[e].material=this.system.defaultMaterial}});return{ModelComponent:f}}());Object.assign(pc,function(){var f=["enabled"],b=function(a){pc.ComponentSystem.call(this,a);this.id="model";this.description="Renders a 3D model at the location of the Entity.";this.ComponentType=pc.ModelComponent;this.DataType=pc.ModelComponentData;this.schema=f;this.sphere=this.plane=this.cylinder=this.cone=this.capsule=this.box=null;this.defaultMaterial=a.scene.defaultMaterial;this.on("beforeremove",this.onRemove,this)};b.prototype=Object.create(pc.ComponentSystem.prototype);b.prototype.constructor=
- b;pc.Component._buildAccessors(pc.ModelComponent.prototype,f);Object.assign(b.prototype,{initializeComponentData:function(a,b,d){d="material materialAsset asset castShadows receiveShadows castShadowsLightmap lightmapped lightmapSizeMultiplier type mapping layers isStatic batchGroupId".split(" ");if(null===b.batchGroupId||void 0===b.batchGroupId)b.batchGroupId=-1;b.layers&&b.layers.length&&(b.layers=b.layers.slice(0));for(var c=0;c<d.length;c++)b.hasOwnProperty(d[c])&&(a[d[c]]=b[d[c]]);pc.ComponentSystem.prototype.initializeComponentData.call(this,
- a,b,["enabled"])},cloneComponent:function(a,b){var c={type:a.model.type,asset:a.model.asset,castShadows:a.model.castShadows,receiveShadows:a.model.receiveShadows,castShadowsLightmap:a.model.castShadowsLightmap,lightmapped:a.model.lightmapped,lightmapSizeMultiplier:a.model.lightmapSizeMultiplier,isStatic:a.model.isStatic,enabled:a.model.enabled,layers:a.model.layers,batchGroupId:a.model.batchGroupId,mapping:pc.extend({},a.model.mapping)},e=a.model.materialAsset;e instanceof pc.Asset||null==e||(e=this.app.assets.get(e));
- var g=a.model.material;g&&g!==this.defaultMaterial&&e&&g!==e.resource||(c.materialAsset=e);e=this.addComponent(b,c);a.model.model&&"asset"===a.model.type&&!a.model.asset&&(e.model=a.model.model.clone(),e._clonedModel=!0);c.materialAsset||(e.material=g);if(a.model.model)for(c=a.model.model.meshInstances,g=e.model.meshInstances,e=0;e<c.length;e++)g[e].mask=c[e].mask,g[e].material=c[e].material,g[e].layer=c[e].layer,g[e].receiveShadow=c[e].receiveShadow},onRemove:function(a,b){b.onRemove()}});return{ModelComponentSystem:b}}());Object.assign(pc,function(){return{ModelComponentData:function(){this.enabled=!0}}}());Object.assign(pc,function(){var f=function(b,a){pc.Component.call(this,b,a);this.on("set_aspectRatioMode",this.onSetAspectRatioMode,this);this.on("set_aspectRatio",this.onSetAspectRatio,this);this.on("set_camera",this.onSetCamera,this);this.on("set_clearColor",this.onSetClearColor,this);this.on("set_fov",this.onSetFov,this);this.on("set_orthoHeight",this.onSetOrthoHeight,this);this.on("set_nearClip",this.onSetNearClip,this);this.on("set_farClip",this.onSetFarClip,this);this.on("set_projection",this.onSetProjection,
- this);this.on("set_priority",this.onSetPriority,this);this.on("set_clearColorBuffer",this.updateClearFlags,this);this.on("set_clearDepthBuffer",this.updateClearFlags,this);this.on("set_clearStencilBuffer",this.updateClearFlags,this);this.on("set_renderTarget",this.onSetRenderTarget,this);this.on("set_rect",this.onSetRect,this);this.on("set_scissorRect",this.onSetScissorRect,this);this.on("set_horizontalFov",this.onSetHorizontalFov,this);this.on("set_frustumCulling",this.onSetFrustumCulling,this);
- this.on("set_calculateTransform",this.onSetCalculateTransform,this);this.on("set_calculateProjection",this.onSetCalculateProjection,this);this.on("set_cullFaces",this.onSetCullFaces,this);this.on("set_flipFaces",this.onSetFlipFaces,this);this.on("set_layers",this.onSetLayers,this)};f.prototype=Object.create(pc.Component.prototype);f.prototype.constructor=f;Object.defineProperty(f.prototype,"projectionMatrix",{get:function(){return this.data.camera.getProjectionMatrix()}});Object.defineProperty(f.prototype,
- "viewMatrix",{get:function(){return this.data.camera._node.getWorldTransform().clone().invert()}});Object.defineProperty(f.prototype,"frustum",{get:function(){return this.data.camera.frustum}});Object.defineProperty(f.prototype,"vrDisplay",{get:function(){return this.data.camera.vrDisplay},set:function(b){if(this.data.camera.vrDisplay=b)b._camera=this.data.camera}});Object.defineProperty(f.prototype,"node",{get:function(){return this.data.camera._node}});Object.assign(f.prototype,{screenToWorld:function(b,
- a,c,d){var e=this.system.app.graphicsDevice;return this.data.camera.screenToWorld(b,a,c,e.clientRect.width,e.clientRect.height,d)},worldToScreen:function(b,a){var c=this.system.app.graphicsDevice;return this.data.camera.worldToScreen(b,c.clientRect.width,c.clientRect.height,a)},onSetAspectRatioMode:function(b,a,c){this.data.camera.aspectRatioMode=c},onSetAspectRatio:function(b,a,c){this.data.camera.aspectRatio=c},onSetCamera:function(b,a,c){a&&(a._node=null);c._node=this.entity},onSetClearColor:function(b,
- a,c){b=this.data.camera.clearColor;b[0]=c.r;b[1]=c.g;b[2]=c.b;b[3]=c.a},onSetFov:function(b,a,c){this.data.camera.fov=c},onSetOrthoHeight:function(b,a,c){this.data.camera.orthoHeight=c},onSetNearClip:function(b,a,c){this.data.camera.nearClip=c},onSetFarClip:function(b,a,c){this.data.camera.farClip=c},onSetHorizontalFov:function(b,a,c){this.data.camera.horizontalFov=c},onSetFrustumCulling:function(b,a,c){this.data.camera.frustumCulling=c},onSetCalculateTransform:function(b,a,c){this._calculateTransform=
- c;this.camera.overrideCalculateTransform=!!c},onSetCalculateProjection:function(b,a,c){this._calculateProjection=c;this.camera._projMatDirty=!0;this.camera.overrideCalculateProjection=!!c},onSetCullFaces:function(b,a,c){this.camera._cullFaces=c},onSetFlipFaces:function(b,a,c){this.camera._flipFaces=c},onSetProjection:function(b,a,c){this.data.camera.projection=c},onSetPriority:function(b,a,c){for(a=0;a<this.layers.length;a++)(b=this.system.app.scene.layers.getLayerById(this.layers[a]))&&b._sortCameras()},
- onSetLayers:function(b,a,c){var d;for(b=0;b<a.length;b++)(d=this.system.app.scene.layers.getLayerById(a[b]))&&d.removeCamera(this);if(this.enabled&&this.entity.enabled)for(b=0;b<c.length;b++)(d=this.system.app.scene.layers.getLayerById(c[b]))&&d.addCamera(this)},addCameraToLayers:function(){for(var b,a=0;a<this.layers.length;a++)(b=this.system.app.scene.layers.getLayerById(this.layers[a]))&&b.addCamera(this)},removeCameraFromLayers:function(){for(var b,a=0;a<this.layers.length;a++)(b=this.system.app.scene.layers.getLayerById(this.layers[a]))&&
- b.removeCamera(this)},onLayersChanged:function(b,a){this.addCameraToLayers();b.off("add",this.onLayerAdded,this);b.off("remove",this.onLayerRemoved,this);a.on("add",this.onLayerAdded,this);a.on("remove",this.onLayerRemoved,this)},onLayerAdded:function(b){0>this.layers.indexOf(b.id)||b.addCamera(this)},onLayerRemoved:function(b){0>this.layers.indexOf(b.id)||b.removeCamera(this)},updateClearFlags:function(){var b=0;this.clearColorBuffer&&(b|=pc.CLEARFLAG_COLOR);this.clearDepthBuffer&&(b|=pc.CLEARFLAG_DEPTH);
- this.clearStencilBuffer&&(b|=pc.CLEARFLAG_STENCIL);this.data.camera.clearFlags=b},onSetRenderTarget:function(b,a,c){this.data.camera.renderTarget=c},onSetRect:function(b,a,c){this.data.camera.setRect(c.x,c.y,c.z,c.w)},onSetScissorRect:function(b,a,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.off()},
- calculateAspectRatio:function(b){b=b?b:this.system.app.graphicsDevice;var a=this.rect;return b.width*a.z/(b.height*a.w)},frameBegin:function(b){this.aspectRatioMode===pc.ASPECT_AUTO&&(this.aspectRatio=this.calculateAspectRatio(b));this.data.isRendering=!0},frameEnd:function(){this.data.isRendering=!1},enterVr:function(b,a){b instanceof Function&&!a&&(a=b,b=null);if(this.system.app.vr)if(b||(b=this.system.app.vr.display),b){var c=this;b.capabilities.canPresent?b.requestPresent(function(d){d||(c.vrDisplay=
- b,c.vrDisplay.once("beforepresentchange",function(a){a.presenting||(c.vrDisplay=null)}));a(d)}):(c.vrDisplay=b,a())}else a("No pc.VrDisplay to present");else a("VrManager not created. Enable VR in project settings.")},exitVr:function(b){if(this.vrDisplay)if(this.vrDisplay.capabilities.canPresent){var a=this.vrDisplay;this.vrDisplay=null;a.exitPresent(b)}else this.vrDisplay=null,b();else b("Not presenting VR")}});return{CameraComponent:f}}());Object.assign(pc,function(){var f="enabled clearColorBuffer clearColor clearDepthBuffer clearStencilBuffer frustumCulling projection fov orthoHeight nearClip farClip priority rect scissorRect camera aspectRatio aspectRatioMode horizontalFov model renderTarget calculateTransform calculateProjection cullFaces flipFaces layers".split(" "),b=function(a){pc.ComponentSystem.call(this,a);this.id="camera";this.description="Renders the scene from the location of the Entity.";this.ComponentType=pc.CameraComponent;
- this.DataType=pc.CameraComponentData;this.schema=f;this.cameras=[];this.on("beforeremove",this.onBeforeRemove,this);this.on("remove",this.onRemove,this);pc.ComponentSystem.bind("update",this.onUpdate,this)};b.prototype=Object.create(pc.ComponentSystem.prototype);b.prototype.constructor=b;pc.Component._buildAccessors(pc.CameraComponent.prototype,f);Object.assign(b.prototype,{initializeComponentData:function(a,b,d){d="postEffects enabled model camera aspectRatio aspectRatioMode horizontalFov renderTarget clearColor fov orthoHeight nearClip farClip projection priority clearColorBuffer clearDepthBuffer clearStencilBuffer frustumCulling rect scissorRect calculateTransform calculateProjection cullFaces flipFaces layers".split(" ");
- for(var c={},g=0,f=d.length;g<f;g++){var k=d[g];c[k]=b[k]}c.layers&&"array"===pc.type(c.layers)&&(c.layers=c.layers.slice(0));c.clearColor&&"array"===pc.type(c.clearColor)&&(b=c.clearColor,c.clearColor=new pc.Color(b[0],b[1],b[2],b[3]));c.rect&&"array"===pc.type(c.rect)&&(b=c.rect,c.rect=new pc.Vec4(b[0],b[1],b[2],b[3]));c.scissorRect&&"array"===pc.type(c.scissorRect)&&(b=c.scissorRect,c.scissorRect=new pc.Vec4(b[0],b[1],b[2],b[3]));c.activate&&(console.warn("WARNING: activate: Property is deprecated. Set enabled property instead."),
- c.enabled=c.activate);c.camera=new pc.Camera;c._node=a.entity;c.camera._component=a;c.camera.calculateTransform=function(b,c){return a._calculateTransform?a._calculateTransform(b,c):null};c.camera.calculateProjection=function(b,c){return a._calculateProjection?a._calculateProjection(b,c):null};c.postEffects=new pc.PostEffectQueue(this.app,a);pc.ComponentSystem.prototype.initializeComponentData.call(this,a,c,d)},onBeforeRemove:function(a,b){this.removeCamera(b);b.onRemove()},onRemove:function(a,b){b.camera=
- null},onUpdate:function(a){a=this.store;var b,d,e,g;if(this.app.vr)for(var f in a)b=a[f],d=b.data,e=d.camera,g=e.vrDisplay,d.enabled&&b.entity.enabled&&g&&(g.setClipPlanes(e._nearClip,e._farClip),e._node&&(e._node.localTransform.copy(g.combinedViewInv),e._node._dirtyLocal=!1,e._node._dirtifyWorld()))},addCamera:function(a){this.cameras.push(a);this.sortCamerasByPriority()},removeCamera:function(a){a=this.cameras.indexOf(a);0<=a&&(this.cameras.splice(a,1),this.sortCamerasByPriority())},sortCamerasByPriority:function(){this.cameras.sort(function(a,
- b){return a.priority-b.priority})}});return{CameraComponentSystem:b}}());Object.assign(pc,function(){return{CameraComponentData:function(){this.clearColor=new pc.Color(.722,.722,.722,1);this.clearStencilBuffer=this.clearDepthBuffer=this.clearColorBuffer=!0;this.nearClip=.1;this.farClip=1E3;this.fov=45;this.orthoHeight=100;this.projection=pc.PROJECTION_PERSPECTIVE;this.priority=0;this.rect=new pc.Vec4(0,0,1,1);this.scissorRect=new pc.Vec4(0,0,1,1);this.enabled=!0;this.frustumCulling=!1;this.cullFaces=!0;this.flipFaces=!1;this.layers=[pc.LAYERID_WORLD,pc.LAYERID_DEPTH,pc.LAYERID_SKYBOX,
- pc.LAYERID_UI,pc.LAYERID_IMMEDIATE];this.camera=null;this.aspectRatio=16/9;this.aspectRatioMode=pc.ASPECT_AUTO;this.postEffects=this.renderTarget=null;this.isRendering=!1;this.calculateProjection=this.calculateTransform=null}}}());Object.assign(pc,function(){function f(b,a){var c=this;this.app=b;this.camera=a;this.effects=[];this.enabled=!1;this.depthTarget=null;this.renderTargetScale=1;this.resizeTimeout=null;this.resizeLast=0;this._resizeTimeoutCallback=function(){c.resizeRenderTargets()};a.on("set_rect",this.onCameraRectChanged,this);this._origStencilColorBuffer=this._origDepthColorBuffer=this._origClearColorBuffer=this._origOverrideClear=!1}Object.assign(f.prototype,{_createOffscreenTarget:function(b,a){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),e=this.app.graphicsDevice,g=a?e.getHdrFormat():pc.PIXELFORMAT_R8_G8_B8_A8,d=new pc.Texture(e,{format:g,width:d,height:c});d.name="posteffect";d.minFilter=pc.FILTER_NEAREST;d.magFilter=pc.FILTER_NEAREST;d.addressU=pc.ADDRESS_CLAMP_TO_EDGE;d.addressV=pc.ADDRESS_CLAMP_TO_EDGE;return new pc.RenderTarget(this.app.graphicsDevice,d,{depth:b})},_resizeOffscreenTarget:function(b){var a=
- this.camera.rect,c=Math.floor(a.z*this.app.graphicsDevice.width*this.renderTargetScale),a=Math.floor(a.w*this.app.graphicsDevice.height*this.renderTargetScale),d=this.app.graphicsDevice,e=b.colorBuffer.format;b._colorBuffer.destroy();c=new pc.Texture(d,{format:e,width:c,height:a});c.name="posteffect";c.minFilter=pc.FILTER_NEAREST;c.magFilter=pc.FILTER_NEAREST;c.addressU=pc.ADDRESS_CLAMP_TO_EDGE;c.addressV=pc.ADDRESS_CLAMP_TO_EDGE;b._colorBuffer=c;b.destroy()},setRenderTargetScale:function(b){this.renderTargetScale=
- b;this.resizeRenderTargets()},addEffect:function(b){var a=this.effects;b={effect:b,inputTarget:this._createOffscreenTarget(0===this.effects.length,b.hdr),outputTarget:null};if(!this.layer){this.layer=new pc.Layer({opaqueSortMode:pc.SORTMODE_NONE,transparentSortMode:pc.SORTMODE_NONE,passThrough:!0,name:"PostEffectQueue",renderTarget:this.camera.renderTarget,clear:!1,onPostRender:function(){for(var a=0;a<this._commandList.length;a++)this._commandList[a]()}});var c=this.app.scene.layers.layerList,d=
- 0,e,g=c.length-1;for(e=g;0<=e;e--)if(c[e].id===pc.LAYERID_UI){g=e-1;this._origOverrideClear=c[e].overrideClear;this._origClearColorBuffer=c[e].clearColorBuffer;this._origDepthColorBuffer=c[e].clearDepthBuffer;this._origStencilColorBuffer=c[e].clearStencilBuffer;c[e].overrideClear=!0;c[e].clearColorBuffer=!1;c[e].clearDepthBuffer=this.camera.clearDepthBuffer;c[e].clearStencilBuffer=this.camera.clearStencilBuffer;break}for(e=g;0<=e;e--)0<=c[e].cameras.indexOf(this.camera)&&(0===d&&(d=e+1),c[e].renderTarget=
- b.inputTarget);this.app.scene.layers.insertOpaque(this.layer,d);this.layer._commandList=[];this.layer.isPostEffect=!0}a.push(b);c=a.length;1<c&&(a[c-2].outputTarget=b.inputTarget);this.enable()},removeEffect:function(b){for(var a=-1,c=0,d=this.effects.length;c<d;c++)if(this.effects[c].effect===b){a=c;break}0<=a&&(0<a?this.effects[a-1].outputTarget=a+1<this.effects.length?this.effects[a+1].inputTarget:null:1<this.effects.length&&(this.effects[1].inputTarget._depth||(this.effects[1].inputTarget.destroy(),
- this.effects[1].inputTarget=this._createOffscreenTarget(!0,this.effects[1].hdr)),this.camera.renderTarget=this.effects[1].inputTarget),this.effects[a].inputTarget.destroy(),this.effects.splice(a,1));this.enabled&&b.needsDepthBuffer&&this.camera.releaseDepthMap();0===this.effects.length&&this.disable()},requestDepthMap:function(){for(var b=0,a=this.effects.length;b<a;b++)this.effects[b].effect.needsDepthBuffer&&this.camera.camera.requestDepthMap()},releaseDepthMap:function(){for(var b=0,a=this.effects.length;b<
- a;b++)this.effects[b].effect.needsDepthBuffer&&this.camera.releaseDepthMap()},destroy:function(){for(var b=0,a=this.effects.length;b<a;b++)this.effects[b].inputTarget.destroy();this.effects.length=0;this.disable()},enable:function(){if(!this.enabled&&this.effects.length){this.enabled=!0;var b=this;this.requestDepthMap();this.app.graphicsDevice.on("resizecanvas",this._onCanvasResized,this);this.command=function(){if(b.enabled){var a=null,c=b.effects.length;if(c){b.layer.renderTarget=b.effects[0].inputTarget;
- for(var d=0;d<c;d++){var e=b.effects[d];d===c-1&&(a=b.camera.rect);e.effect.render(e.inputTarget,e.outputTarget,a)}}}};this.layer._commandList.push(this.command)}},disable:function(){if(this.enabled){this.enabled=!1;this.app.graphicsDevice.off("resizecanvas",this._onCanvasResized,this);this.camera.renderTarget=null;this.releaseDepthMap();var b=this.layer._commandList.indexOf(this.command);0<=b&&this.layer._commandList.splice(b,1);for(var a=this.app.scene.layers.layerList,c=a.length-1,b=0;b<=a.length;b++)if(a[b].id===
- pc.LAYERID_UI){c=b-1;a[b].overrideClear=this._origOverrideClear;a[b].clearColorBuffer=this._origClearColorBuffer;a[b].clearDepthBuffer=this._origDepthColorBuffer;a[b].clearStencilBuffer=this._origStencilColorBuffer;break}for(b=c;0<=b;b--)0<=a[b].cameras.indexOf(this.camera)&&(a[b].renderTarget=void 0);this.app.scene.layers.removeOpaque(this.layer);this.layer=null}},_onCanvasResized:function(b,a){var c=this.camera.rect,d=this.app.graphicsDevice;this.camera.camera.aspectRatio=d.width*c.z/(d.height*
- c.w);this.resizeTimeout||(100<pc.now()-this.resizeLast?this.resizeRenderTargets():this.resizeTimeout=setTimeout(this._resizeTimeoutCallback,100))},resizeRenderTargets:function(){this.resizeTimeout&&(clearTimeout(this.resizeTimeout),this.resizeTimeout=null);this.resizeLast=pc.now();for(var b=this.camera.rect,a=Math.floor(b.z*this.app.graphicsDevice.width*this.renderTargetScale),b=Math.floor(b.w*this.app.graphicsDevice.height*this.renderTargetScale),c=this.effects,d=0,e=c.length;d<e;d++){var g=c[d];
- g.inputTarget.width===a&&g.inputTarget.height===b||this._resizeOffscreenTarget(g.inputTarget)}},onCameraRectChanged:function(b,a,c){this.enabled&&this.resizeRenderTargets()}});return{PostEffectQueue:f}}());Object.assign(pc,function(){function f(f,h){this.app=f;this.srcRenderTarget=h.srcRenderTarget;this.hdr=h.hdr;this.blending=h.blending;this.shader=h.shader;this.setup=h.setup;var n=this,q=f.graphicsDevice;this.layer=new pc.Layer({opaqueSortMode:pc.SORTMODE_NONE,transparentSortMode:pc.SORTMODE_NONE,passThrough:!0,name:h.name,onPostRender:function(){n.srcRenderTarget?(d.x=n.srcRenderTarget.width,d.y=n.srcRenderTarget.height,d.z=1/n.srcRenderTarget.width,d.w=1/n.srcRenderTarget.height):(d.x=q.width,d.y=
- q.height,d.z=1/q.width,d.w=1/q.height);e[0]=d.x;e[1]=d.y;e[2]=d.z;e[3]=d.w;c.setValue(e);if(this._postEffectCombined&&0>this._postEffectCombined)n.setup&&n.setup(q,n,d,null,this.renderTarget);else{var g;g=this._postEffectCombinedSrc?this._postEffectCombinedSrc:n.srcRenderTarget?n.srcRenderTarget:b[this._backbufferRtId];1<g._samples&&g.resolve(!0,!1);var k=g._colorBuffer;k.magFilter=(this._postEffectCombinedShader?this._postEffectCombinedBilinear:this.postEffectBilinear)?pc.FILTER_LINEAR:pc.FILTER_NEAREST;
- a.setValue(k);n.setup&&n.setup(q,n,d,g,this.renderTarget);(g=this._postEffectCombinedShader?this._postEffectCombinedShader:this.shader)&&pc.drawQuadWithShader(q,this.renderTarget,g,null,null,n.blending);if(!n.srcRenderTarget)for(g=f.scene.layers.layerList,k=0;k<g.length&&g[k]!==n.layer;k++)if(g[k].renderTarget===b[0]||g[k].renderTarget===b[1])g[k].renderTarget=null}}});this.layer._generateCameraHash();this.layer.isPostEffect=!0;this.layer.unmodifiedUvs=h.unmodifiedUvs;this.layer.postEffectBilinear=
- h.bilinear;this.layer.postEffect=this;this.layer.shader=h.shader;this.layer.renderTarget=h.destRenderTarget;if(!a){a=q.scope.resolve("uColorBuffer");c=q.scope.resolve("uScreenSize");for(var H=q.supportsMsaa?4:1,F=0;2>F;F++)b[F]=new pc.RenderTarget({depth:!0,stencil:q.supportsStencil,samples:H,autoResolve:!1}),b[F].name="backbuffer"+F;f.on("prerender",function(){var a=f.scene.layers.layerList,c,d,e=0,h=0;p=k=l=!1;var n=pc.PIXELFORMAT_R8_G8_B8_A8;if(f.scene.layers._dirty){var E=0,H,G;for(c=0;c<a.length;c++){d=
- !1;var F;if((F=a[c].isPostEffect)&&!(F=0===E)&&(F=a[c].unmodifiedUvs&&a[c].shader)){a:{var I,Q,aa,N;H=a;G=g;var ba=E,M=J(a[c].shader.definition.fshader);if(0!==M.length)for(N=0;N<ba;N++)for(aa=0;aa<M.length;aa++)for(F=M[aa],I=J(H[G[N]].shader.definition.fshader),Q=0;Q<I.length;Q++)if(I[Q]===F){F=!0;break a}F=!1}F=!F}F?(g[E]=c,E++,c===a.length-1&&(d=!0)):0<E&&(d=!0);if(d){if(1<E){F="post_";for(d=0;d<E;d++)I=a[g[d]],F+=I.name?I.name:I.id,d<E-1&&(F+="_");I=q.programLib._cache[F];if(!I){Q="vec4 shaderOutput;\n";
- aa="void main() {\n";N=[];for(d=0;d<E;d++){I=a[g[d]].shader.definition.fshader+"\n";I=I.replace(y,"//").replace(u,"//").replace(w,"//").replace(x,"shaderOutput");0<d&&(I=I.replace(D,"//").replace(z,"//").replace(C,"shaderOutput;//"));I=I.replace(A,"void main"+d);var ca,ea,fa,M=I;G=N;ea=M.length;var ga=0,Y=ca=0,ba="";for(H=0;H<ea;H++)fa=M.charAt(H),"{"===fa?(0===ca&&(ga=H),ca++):"}"===fa&&(1===ca&&(fa=H,ba+=M.substr(Y,ga-Y+1),Y=fa),ca--);ba+=M.substr(Y,M.length-Y+1);ga=null;Y=ba.match(m)||[];for(H=
- 0;H<Y.length;H++)for(M=Y[H].split(","),ea=0;ea<M.length;ea++)ca=M[ea].replace(r,"").trim(),0<=G.indexOf(ca)?(ga||(ga=[]),ga.push(ca)):G.push(ca);ba=ba.match(t)||[];for(H=0;H<ba.length;H++)for(M=ba[H].split(","),ea=0;ea<M.length;ea++)ca=M[ea].replace(v,"").trim(),ca=G.indexOf(ca),0<=ca&&G.splice(ca,1);if(H=ga)for(G=0;G<H.length;G++)I=I.replace(new RegExp("\\b"+H[G]+"\\b","g"),H[G]+"NNNN"+d);Q+=I;aa+="main"+d+"();\n"}aa+="gl_FragColor = shaderOutput;\n}\n";I=pc.shaderChunks.createShaderFromCode(q,pc.shaderChunks.fullscreenQuadVS,
- Q+aa,F)}for(d=0;d<E;d++)a[g[d]]._postEffectCombined=d===E-1?1:-1;a[g[E-1]]._postEffectCombinedShader=I;a[g[E-1]]._postEffectCombinedBilinear=a[g[0]].postEffectBilinear;a[g[E-1]]._postEffectCombinedSrc=a[g[0]].postEffect.srcRenderTarget}g[0]=c;E=1}}}for(c=0;c<a.length;c++){if(a[c].isPostEffect&&(!a[c].postEffect.srcRenderTarget&&!a[c]._postEffectCombined||!a[c].postEffect._postEffectCombinedSrc&&0<=a[c]._postEffectCombined)){for(d=c-1;d>=e;d--)a[d].renderTarget||(a[d].renderTarget=b[h]);a[c]._backbufferRtId=
- h;e=c;l=!0;1===h&&(k=!0);a[c].postEffect.hdr&&(n=q.webgl2&&q.textureFloatRenderable?pc.PIXELFORMAT_111110F:q.extTextureHalfFloatLinear&&q.textureHalfFloatRenderable?pc.PIXELFORMAT_RGBA16F:pc.PIXELFORMAT_R8_G8_B8_A8);a[c].postEffect.shader&&!a[c].renderTarget&&(h=1-h)}else a[c].isPostEffect||a[c].renderTarget||!l||(a[c].renderTarget=b[h]);a[c].isPostEffect&&!a[c].renderTarget&&(p=!0)}if(l)if(!b[0].colorBuffer)B(0,q,n);else if(b[0].width!==q.width||b[0].height!==q.height||b[0]._colorBuffer._format!==
- n)b[0].colorBuffer.destroy(),b[0].destroy(),B(0,q,n);if(k)if(!b[1].colorBuffer)B(1,q,n);else if(b[1].width!==q.width||b[1].height!==q.height||b[1]._colorBuffer._format!==n)b[1].colorBuffer.destroy(),b[1].destroy(),B(1,q,n)},this);f.on("postrender",function(){var a=f.graphicsDevice;if(l&&!p){for(var c=f.scene.layers.layerList,d,e=c.length-1;0<=e&&(d=c[e].renderTarget,d!==b[0]&&d!==b[1]);e--);d&&(1<d._samples&&d.resolve(!0,!1),a.copyRenderTarget(d,null,!0,!1))}},this)}}var b=[null,null],a=null,c,d=
- new pc.Vec4,e=new Float32Array(4),g=[],l=!1,k=!1,p=!1,h=/uniform[ \t\n\r]+\S+[ \t\n\r]+\S+[ \t\n\r]*\;/g,n=/\S+[ \t\n\r]*\;/,q=/[ \t\n\r]*\;/,m=/(float|int|bool|vec2|vec3|vec4|struct)([ \t\n\r]+[^\;]+[ \t\n\r]*\,*)+\;/g,r=/(float|int|bool|vec2|vec3|vec4|struct|\,|\;|\{|\})/g,t=/(uniform|varying|in|out)[ \t\n\r]+(float|int|bool|vec2|vec3|vec4|struct)([ \t\n\r]+[^\;]+[ \t\n\r]*\,*)+\;/g,v=/(float|int|bool|vec2|vec3|vec4|struct|uniform|varying|in|out|\,|\;|\{|\})/g,y=/#version/g,u=/out highp vec4 pc_fragColor;/g,
- w=/#define gl_FragColor/g,x=/gl_FragColor/g,D=/uniform[ \t\n\r]+sampler2D[ \t\n\r]+uColorBuffer;/g,z=/(varying|in)[ \t\n\r]+vec2[ \t\n\r]+vUv0;/g,C=/(texture2D|texture)[ \t\n\r]*\([ \t\n\r]*uColorBuffer/g,A=/void[ \t\n\r]+main/g,B=function(a,c,d){c=new pc.Texture(c,{format:d,width:c.width,height:c.height});c.name="posteffect-pass";c.minFilter=pc.FILTER_NEAREST;c.magFilter=pc.FILTER_NEAREST;c.addressU=pc.ADDRESS_CLAMP_TO_EDGE;c.addressV=pc.ADDRESS_CLAMP_TO_EDGE;b[a]._colorBuffer=c},J=function(a){a=
- a.match(h)||[];for(var b,c,d=[],e=0;e<a.length;e++)b=a[e].search(n),c=a[e].search(q),b=a[e].substr(b,c-b),"uColorBuffer"!==b&&d.push(b);return d};f.prototype.addToComposition=function(a){this.app.scene.layers.insertTransparent(this.layer,a)};return{PostEffectPass:f}}());Object.assign(pc,function(){var f=function(a,b){pc.Component.call(this,a,b);this._cookieAssetId=this._cookieAsset=null;this._cookieAssetAdd=!1;this._cookieMatrix=null};f.prototype=Object.create(pc.Component.prototype);f.prototype.constructor=f;var b=[],a=[],c=function(c,e,g,l){var d=f.prototype;b.push(c);a.push(e);Object.defineProperty(d,c,{get:function(){return this.data[c]},set:function(a){var b=this.data,d=b[c];if(l||d!==a)b[c]=a,g&&g.call(this,a,d)},configurable:!0})};(function(){c("enabled",
- !0,function(a,b){this.onSetEnabled(null,b,a)});c("light",null);c("type","directional",function(a,b){this.system.changeType(this,b,a);this.refreshProperties()});c("color",new pc.Color(1,1,1),function(a,b){this.light.setColor(a)},!0);c("intensity",1,function(a,b){this.light.intensity=a});c("castShadows",!1,function(a,b){this.light.castShadows=a});c("shadowDistance",40,function(a,b){this.light.shadowDistance=a});c("shadowResolution",1024,function(a,b){this.light.shadowResolution=a});c("shadowBias",.05,
- function(a,b){this.light.shadowBias=-.01*a});c("normalOffsetBias",0,function(a,b){this.light.normalOffsetBias=a});c("range",10,function(a,b){this.light.attenuationEnd=a});c("innerConeAngle",40,function(a,b){this.light.innerConeAngle=a});c("outerConeAngle",45,function(a,b){this.light.outerConeAngle=a});c("falloffMode",pc.LIGHTFALLOFF_LINEAR,function(a,b){this.light.falloffMode=a});c("shadowType",pc.SHADOW_PCF3,function(a,b){this.light.shadowType=a});c("vsmBlurSize",11,function(a,b){this.light.vsmBlurSize=
- a});c("vsmBlurMode",pc.BLUR_GAUSSIAN,function(a,b){this.light.vsmBlurMode=a});c("vsmBias",.0025,function(a,b){this.light.vsmBias=a});c("cookieAsset",null,function(a,b){if(!this._cookieAssetId||!(a instanceof pc.Asset&&a.id===this._cookieAssetId||a===this._cookieAssetId))if(this.onCookieAssetRemove(),this._cookieAssetId=null,a instanceof pc.Asset)this._cookieAssetId=this.data.cookieAsset=a.id,this.onCookieAssetAdd(a);else if("number"===typeof a){this._cookieAssetId=a;var c=this.system.app.assets.get(a);
- if(c)this.onCookieAssetAdd(c);else this._cookieAssetAdd=!0,this.system.app.assets.on("add:"+this._cookieAssetId,this.onCookieAssetAdd,this)}});c("cookie",null,function(a,b){this.light.cookie=a});c("cookieIntensity",1,function(a,b){this.light.cookieIntensity=a});c("cookieFalloff",!0,function(a,b){this.light.cookieFalloff=a});c("cookieChannel","rgb",function(a,b){this.light.cookieChannel=a});c("cookieAngle",0,function(a,b){if(0!==a||null!==this.cookieScale){this._cookieMatrix||(this._cookieMatrix=new pc.Vec4);
- var c=1,d=1;this.cookieScale&&(c=this.cookieScale.x,d=this.cookieScale.y);var e=Math.cos(a*pc.math.DEG_TO_RAD),f=Math.sin(a*pc.math.DEG_TO_RAD);this._cookieMatrix.set(e/c,-f/c,f/d,e/d);this.light.cookieTransform=this._cookieMatrix}else this.light.cookieTransform=null});c("cookieScale",null,function(a,b){if(null!==a||0!==this.cookieAngle){this._cookieMatrix||(this._cookieMatrix=new pc.Vec4);var c=a.x,d=a.y,e=Math.cos(this.cookieAngle*pc.math.DEG_TO_RAD),f=Math.sin(this.cookieAngle*pc.math.DEG_TO_RAD);
- this._cookieMatrix.set(e/c,-f/c,f/d,e/d);this.light.cookieTransform=this._cookieMatrix}else this.light.cookieTransform=null},!0);c("cookieOffset",null,function(a,b){this.light.cookieOffset=a},!0);c("shadowUpdateMode",pc.SHADOWUPDATE_REALTIME,function(a,b){this.light.shadowUpdateMode=a});c("mask",1,function(a,b){this.light.mask=a});c("affectDynamic",!0,function(a,b){this.light.mask=a?this.light.mask|pc.MASK_DYNAMIC:this.light.mask&~pc.MASK_DYNAMIC;this.light.mask=this.light._mask});c("affectLightmapped",
- !1,function(a,b){a?(this.light.mask|=pc.MASK_BAKED,this.bake&&(this.light.mask&=~pc.MASK_LIGHTMAP)):(this.light.mask&=~pc.MASK_BAKED,this.bake&&(this.light.mask|=pc.MASK_LIGHTMAP));this.light.mask=this.light._mask});c("bake",!1,function(a,b){a?(this.light.mask|=pc.MASK_LIGHTMAP,this.affectLightmapped&&(this.light.mask&=~pc.MASK_BAKED)):(this.light.mask&=~pc.MASK_LIGHTMAP,this.affectLightmapped&&(this.light.mask|=pc.MASK_BAKED));this.light.mask=this.light._mask});c("bakeDir",!0,function(a,b){this.light.bakeDir=
- a});c("isStatic",!1,function(a,b){this.light.isStatic=a});c("layers",[pc.LAYERID_WORLD],function(a,b){var c,d;for(c=0;c<b.length;c++)(d=this.system.app.scene.layers.getLayerById(b[c]))&&d.removeLight(this);for(c=0;c<a.length;c++)(d=this.system.app.scene.layers.getLayerById(a[c]))&&this.enabled&&this.entity.enabled&&d.addLight(this)})})();Object.defineProperty(f.prototype,"enable",{get:function(){console.warn("WARNING: enable: Property is deprecated. Query enabled property instead.");return this.enabled},
- set:function(a){console.warn("WARNING: enable: Property is deprecated. Set enabled property instead.");this.enabled=a}});Object.assign(f.prototype,{addLightToLayers:function(){for(var a,b=0;b<this.layers.length;b++)(a=this.system.app.scene.layers.getLayerById(this.layers[b]))&&a.addLight(this)},removeLightFromLayers:function(){for(var a,b=0;b<this.layers.length;b++)(a=this.system.app.scene.layers.getLayerById(this.layers[b]))&&a.removeLight(this)},onLayersChanged:function(a,b){this.enabled&&this.entity.enabled&&
- this.addLightToLayers();a.off("add",this.onLayerAdded,this);a.off("remove",this.onLayerRemoved,this);b.on("add",this.onLayerAdded,this);b.on("remove",this.onLayerRemoved,this)},onLayerAdded:function(a){0>this.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,c=0;c<b.length;c++)a=b[c],this[a]=this[a];if(this.enabled&&this.entity.enabled)this.onEnable()},updateShadow:function(){this.light.updateShadow()},
- onCookieAssetSet:function(){var a=!1;"cubemap"!==this._cookieAsset.type||this._cookieAsset.loadFaces||(a=this._cookieAsset.loadFaces=!0);this._cookieAsset.resource&&!a||this.system.app.assets.load(this._cookieAsset);if(this._cookieAsset.resource)this.onCookieAssetLoad()},onCookieAssetAdd:function(a){if(this._cookieAssetId===a.id){this._cookieAsset=a;if(this.light._enabled)this.onCookieAssetSet();this._cookieAsset.on("load",this.onCookieAssetLoad,this);this._cookieAsset.on("remove",this.onCookieAssetRemove,
- this)}},onCookieAssetLoad:function(){this._cookieAsset&&this._cookieAsset.resource&&(this.cookie=this._cookieAsset.resource)},onCookieAssetRemove:function(){this._cookieAssetId&&(this._cookieAssetAdd&&(this.system.app.assets.off("add:"+this._cookieAssetId,this.onCookieAssetAdd,this),this._cookieAssetAdd=!1),this._cookieAsset&&(this._cookieAsset.off("load",this.onCookieAssetLoad,this),this._cookieAsset.off("remove",this.onCookieAssetRemove,this),this._cookieAsset=null),this.cookie=null)},onEnable:function(){this.light.enabled=
- !0;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.addLightToLayers();if(this._cookieAsset&&!this.cookie)this.onCookieAssetSet()},onDisable:function(){this.light.enabled=!1;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.removeLightFromLayers()}});return{LightComponent:f,_lightProps:b,_lightPropsDefault:a}}());Object.assign(pc,function(){var f={directional:pc.LIGHTTYPE_DIRECTIONAL,point:pc.LIGHTTYPE_POINT,spot:pc.LIGHTTYPE_SPOT},b=function(a){pc.ComponentSystem.call(this,a);this.id="light";this.description="Enables the Entity to emit light.";this.ComponentType=pc.LightComponent;this.DataType=pc.LightComponentData};b.prototype=Object.create(pc.ComponentSystem.prototype);b.prototype.constructor=b;Object.assign(b.prototype,{initializeComponentData:function(a,b){for(var c=pc._lightProps,e={},g=0,l=c.length;g<
- l;g++){var k=c[g];e[k]=b[k]}e.type||(e.type=a.data.type);a.data.type=e.type;e.layers&&"array"===pc.type(e.layers)&&(e.layers=e.layers.slice(0));e.color&&"array"===pc.type(e.color)&&(e.color=new pc.Color(e.color[0],e.color[1],e.color[2]));e.cookieOffset&&e.cookieOffset instanceof Array&&(e.cookieOffset=new pc.Vec2(e.cookieOffset[0],e.cookieOffset[1]));e.cookieScale&&e.cookieScale instanceof Array&&(e.cookieScale=new pc.Vec2(e.cookieScale[0],e.cookieScale[1]));e.enable&&(console.warn("WARNING: enable: Property is deprecated. Set enabled property instead."),
- e.enabled=e.enable);g=new pc.Light;g.type=f[e.type];g._node=a.entity;g._scene=this.app.scene;a.data.light=g;pc.ComponentSystem.prototype.initializeComponentData.call(this,a,e,c)},removeComponent:function(a){a.light.data.light.destroy();pc.ComponentSystem.prototype.removeComponent.call(this,a)},cloneComponent:function(a,b){for(var c=a.light,e=[],g,f=pc._lightProps,k=0;k<f.length;k++)g=f[k],"light"!==g&&(e[g]=c[g]&&c[g].clone?c[g].clone():c[g]);this.addComponent(b,e)},changeType:function(a,b,d){b!==
- d&&(a.light.type=f[d])}});return{LightComponentSystem:b}}());Object.assign(pc,function(){return{LightComponentData:function(){for(var f=pc._lightProps,b=pc._lightPropsDefault,a,c=0;c<f.length;c++)a=b[c],this[f[c]]=a&&a.clone?a.clone():a}}}());Object.assign(pc,function(){var f=function(b,a){pc.Component.call(this,b,a);this._scripts=[];this._updateList=new pc.SortedLoopArray({sortBy:"__executionOrder"});this._postUpdateList=new pc.SortedLoopArray({sortBy:"__executionOrder"});this._scriptsIndex={};this._destroyedScripts=[];this._destroyed=!1;this._scriptsData=null;this._enabled=this._oldState=!0;this._isLoopingThroughScripts=this._beingEnabled=!1;this._executionOrder=-1;this.on("set_enabled",this._onSetEnabled,this)};f.prototype=Object.create(pc.Component.prototype);
- f.prototype.constructor=f;f.scriptMethods={initialize:"initialize",postInitialize:"postInitialize",update:"update",postUpdate:"postUpdate",swap:"swap"};Object.assign(f.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 b,a=this._beginLooping(),c=0,d=this.scripts.length;c<d;c++)b=this.scripts[c],b._initialized&&!b._postInitialized&&
- b.enabled&&(b._postInitialized=!0,b.postInitialize&&this._scriptMethod(b,f.scriptMethods.postInitialize));this._endLooping(a)},_beginLooping:function(){var b=this._isLoopingThroughScripts;this._isLoopingThroughScripts=!0;return b},_endLooping:function(b){(this._isLoopingThroughScripts=b)||this._removeDestroyedScripts()},_onSetEnabled:function(b,a,c){this._beingEnabled=!0;this._checkState();this._beingEnabled=!1},_checkState:function(){var b=this.enabled&&this.entity.enabled;if(b!==this._oldState){this._oldState=
- b;this.fire(b?"enable":"disable");this.fire("state",b);b?this.system._addComponentToEnabled(this):this.system._removeComponentFromEnabled(this);for(var b=this._beginLooping(),a,c=0,d=this.scripts.length;c<d;c++)a=this.scripts[c],a.enabled=a._enabled;this._endLooping(b)}},_onBeforeRemove:function(){this.fire("remove");for(var b=this._beginLooping(),a=0;a<this.scripts.length;a++){var c=this.scripts[a];c&&this.destroy(c.__scriptType.__name)}this._endLooping(b)},_removeDestroyedScripts:function(){var b=
- this._destroyedScripts.length;if(b){var a;for(a=0;a<b;a++)this._removeScriptInstance(this._destroyedScripts[a]);this._destroyedScripts.length=0;this._resetExecutionOrder(0,this._scripts.length)}},_onInitializeAttributes:function(){for(var b=0,a=this.scripts.length;b<a;b++)this.scripts[b].__initializeAttributes()},_scriptMethod:function(b,a,c){try{b[a](c)}catch(d){b.enabled=!1,b._callbacks&&b._callbacks.error||(console.warn('unhandled exception while calling "'+a+'" for "'+b.__scriptType.__name+'" script: ',
- d),console.error(d)),b.fire("error",d,a),this.fire("error",b,d,a)}},_onInitialize:function(){for(var b,a=this._scripts,c=this._beginLooping(),d=0,e=a.length;d<e;d++)b=a[d],!b._initialized&&b.enabled&&(b._initialized=!0,b.initialize&&this._scriptMethod(b,f.scriptMethods.initialize));this._endLooping(c)},_onPostInitialize:function(){this.onPostStateChange()},_onUpdate:function(b){var a=this._updateList;if(a.length){var c,d=this._beginLooping();for(a.loopIndex=0;a.loopIndex<a.length;a.loopIndex++)c=
- a.items[a.loopIndex],c.enabled&&this._scriptMethod(c,f.scriptMethods.update,b);this._endLooping(d)}},_onPostUpdate:function(b){var a=this._postUpdateList;if(a.length){var c=this._beginLooping(),d;for(a.loopIndex=0;a.loopIndex<a.length;a.loopIndex++)d=a.items[a.loopIndex],d.enabled&&this._scriptMethod(d,f.scriptMethods.postUpdate,b);this._endLooping(c)}},_insertScriptInstance:function(b,a,c){-1===a?(this._scripts.push(b),b.__executionOrder=c,b.update&&this._updateList.append(b),b.postUpdate&&this._postUpdateList.append(b)):
- (this._scripts.splice(a,0,b),b.__executionOrder=a,this._resetExecutionOrder(a+1,c+1),b.update&&this._updateList.insert(b),b.postUpdate&&this._postUpdateList.insert(b))},_removeScriptInstance:function(b){var a=this._scripts.indexOf(b);if(-1===a)return a;this._scripts.splice(a,1);b.update&&this._updateList.remove(b);b.postUpdate&&this._postUpdateList.remove(b);return a},_resetExecutionOrder:function(b,a){for(var c=b;c<a;c++)this._scripts[c].__executionOrder=c},has:function(b){"string"===typeof b&&(b=
- this.system.app.scripts.get(b));return!!this._scriptsIndex[b.__name]},create:function(b,a){var c=this;a=a||{};var d=b,e=b;"string"===typeof d?d=this.system.app.scripts.get(d):d&&(e=d.__name);if(d){if(!this._scriptsIndex[d.__name]||!this._scriptsIndex[d.__name].instance){var e=new d({app:this.system.app,entity:this.entity,enabled:a.hasOwnProperty("enabled")?a.enabled:!0,attributes:a.attributes||null}),g=this._scripts.length,l=-1;"number"===typeof a.ind&&-1!==a.ind&&g>a.ind&&(l=a.ind);this._insertScriptInstance(e,
- l,g);this._scriptsIndex[d.__name]={instance:e,onSwap:function(){c.swap(d.__name)}};this[d.__name]=e;a.preloading||e.__initializeAttributes();this.fire("create",d.__name,e);this.fire("create:"+d.__name,e);this.system.app.scripts.on("swap:"+d.__name,this._scriptsIndex[d.__name].onSwap);a.preloading||(e.enabled&&!e._initialized&&(e._initialized=!0,e.initialize&&this._scriptMethod(e,f.scriptMethods.initialize)),e.enabled&&!e._postInitialized&&(e._postInitialized=!0,e.postInitialize&&this._scriptMethod(e,
- f.scriptMethods.postInitialize)));return e}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(b){var a=b;"string"===typeof b&&(b=this.system.app.scripts.get(b))&&(a=b.__name);b=this._scriptsIndex[a];delete this._scriptsIndex[a];if(!b)return!1;if(b.instance&&!b.instance._destroyed)if(b.instance.enabled=
- !1,b.instance._destroyed=!0,this._isLoopingThroughScripts)this._destroyedScripts.push(b.instance);else{var c=this._removeScriptInstance(b.instance);0<=c&&this._resetExecutionOrder(c,this._scripts.length)}this.system.app.scripts.off("swap:"+a,b.onSwap);delete this[a];this.fire("destroy",a,b.instance||null);this.fire("destroy:"+a,b.instance||null);b.instance&&b.instance.fire("destroy");return!0},swap:function(b){"string"===typeof b&&(b=this.system.app.scripts.get(b));var a=this._scriptsIndex[b.__name];
- if(!a||!a.instance)return!1;var a=a.instance,c=this._scripts.indexOf(a),d=new b({app:this.system.app,entity:this.entity,enabled:a.enabled,attributes:a.__attributes});if(!d.swap)return!1;d.__initializeAttributes();this._scripts[c]=d;this._scriptsIndex[b.__name].instance=d;this[b.__name]=d;d.__executionOrder=c;a.update&&this._updateList.remove(a);a.postUpdate&&this._postUpdateList.remove(a);d.update&&this._updateList.insert(d);d.postUpdate&&this._postUpdateList.insert(d);this._scriptMethod(d,f.scriptMethods.swap,
- a);this.fire("swap",b.__name,d);this.fire("swap:"+b.__name,d);return!0},resolveDuplicatedEntityReferenceProperties:function(b,a){var c=this.entity.script,d;for(d in b._scriptsIndex){var e=this.system.app.scripts.get(d);if(e){var g=b._scriptsIndex[d];if(g&&g.instance){var f=c[d].__attributesRaw,k=c[d].__attributes;if(f||k){var g=g.instance.__attributes,p;for(p in g)if(g[p]){var h=e.attributes.get(p);if(h&&"entity"===h.type)if(h.array){var n=g[p];if(h=n.length){for(var n=n.slice(),q=0;q<h;q++){var m=
- n[q]instanceof pc.Entity?n[q].getGuid():n[q];a[m]&&(n[q]=f?a[m].getGuid():a[m])}f?f[p]=n:k[p]=n}}else{h=g[p];if(h instanceof pc.Entity)h=h.getGuid();else if("string"!==typeof h)continue;a[h]&&(f?f[p]=a[h].getGuid():k[p]=a[h])}}}}}}},move:function(b,a){var c=this._scripts.length;if(a>=c||0>a)return!1;var d=b;"string"!==typeof d&&(d=b.__name);var e=this._scriptsIndex[d];if(!e||!e.instance)return!1;var g=this._scripts.indexOf(e.instance);if(-1===g||g===a)return!1;this._scripts.splice(a,0,this._scripts.splice(g,
- 1)[0]);this._resetExecutionOrder(0,c);this._updateList.sort();this._postUpdateList.sort();this.fire("move",d,e.instance,a,g);this.fire("move:"+d,e.instance,a,g);return!0}});Object.defineProperty(f.prototype,"enabled",{get:function(){return this._enabled},set:function(b){var a=this._enabled;this._enabled=b;this.fire("set","enabled",a,b)}});Object.defineProperty(f.prototype,"scripts",{get:function(){return this._scripts},set:function(b){this._scriptsData=b;for(var a in b)if(b.hasOwnProperty(a)){var c=
- this._scriptsIndex[a];if(c){if("boolean"===typeof b[a].enabled&&(c.enabled=!!b[a].enabled),"object"===typeof b[a].attributes)for(var d in b[a].attributes)if(!pc.createScript.reservedAttributes[d]){if(!c.__attributes.hasOwnProperty(d)){var e=this.system.app.scripts.get(a);e&&e.attributes.add(d,{})}c[d]=b[a].attributes[d]}}else console.log(this.order)}}});return{ScriptComponent:f}}());Object.assign(pc,function(){var f=0,b=function(a){pc.ComponentSystem.call(this,a);this.id="script";this.app=a;this.ComponentType=pc.ScriptComponent;this.DataType=pc.ScriptComponentData;this._components=new pc.SortedLoopArray({sortBy:"_executionOrder"});this._enabledComponents=new pc.SortedLoopArray({sortBy:"_executionOrder"});this.preloading=!0;this.on("beforeremove",this._onBeforeRemove,this);pc.ComponentSystem.bind("initialize",this._onInitialize,this);pc.ComponentSystem.bind("postInitialize",this._onPostInitialize,
- this);pc.ComponentSystem.bind("update",this._onUpdate,this);pc.ComponentSystem.bind("postUpdate",this._onPostUpdate,this)};b.prototype=Object.create(pc.ComponentSystem.prototype);b.prototype.constructor=b;Object.assign(b.prototype,{initializeComponentData:function(a,b){a._executionOrder=f++;this._components.append(a);f>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;c<b.order.length;c++)a.create(b.order[c],{enabled:b.scripts[b.order[c]].enabled,attributes:b.scripts[b.order[c]].attributes,preloading:this.preloading})}},cloneComponent:function(a,b){var c,e,g=[],f={};for(c=0;c<a.script._scripts.length;c++){var k=a.script._scripts[c],p=k.__scriptType.__name;g.push(p);var h={};for(e in k.__attributes)h[e]=k.__attributes[e];f[p]={enabled:k._enabled,attributes:h}}for(e in a.script._scriptsIndex)e.awaiting&&
- g.splice(e.ind,0,e);return this.addComponent(b,{enabled:a.script.enabled,order:g,scripts:f})},_resetExecutionOrder:function(){for(var a=f=0,b=this._components.length;a<b;a++)this._components.items[a]._executionOrder=f++},_callComponentMethod:function(a,b,d){for(a.loopIndex=0;a.loopIndex<a.length;a.loopIndex++)a.items[a.loopIndex][b](d)},_onInitialize:function(){this.preloading=!1;this._callComponentMethod(this._components,"_onInitializeAttributes");this._callComponentMethod(this._enabledComponents,
- "_onInitialize")},_onPostInitialize:function(){this._callComponentMethod(this._enabledComponents,"_onPostInitialize")},_onUpdate:function(a){this._callComponentMethod(this._enabledComponents,"_onUpdate",a)},_onPostUpdate:function(a){this._callComponentMethod(this._enabledComponents,"_onPostUpdate",a)},_addComponentToEnabled:function(a){this._enabledComponents.insert(a)},_removeComponentFromEnabled:function(a){this._enabledComponents.remove(a)},_onBeforeRemove:function(a,b){0<=this._components.items.indexOf(b)&&
- b._onBeforeRemove();this._removeComponentFromEnabled(b);this._components.remove(b)}});return{ScriptComponentSystem:b}}());Object.assign(pc,function(){return{ScriptComponentData:function(){this.enabled=!0}}}());Object.assign(pc,function(){var f=function(b,a){pc.Component.call(this,b,a);this.on("set_scripts",this.onSetScripts,this)};f.prototype=Object.create(pc.Component.prototype);f.prototype.constructor=f;Object.assign(f.prototype,{send:function(b,a){console.warn("DEPRECATED: ScriptLegacyComponent.send() is deprecated and will be removed soon. Please use: http://developer.playcanvas.com/user-manual/scripting/communication/");var c=pc.makeArray(arguments).slice(2),d=this.entity.script.instances,e;if(d&&
- d[b]&&(e=d[b].instance[a]))return e.apply(d[b].instance,c)},onEnable:function(){this.data.areScriptsLoaded&&!this.system.preloading&&(this.data.initialized?this.system._enableScriptComponent(this):this.system._initializeScriptComponent(this),this.data.postInitialized||this.system._postInitializeScriptComponent(this))},onDisable:function(){this.system._disableScriptComponent(this)},onSetScripts:function(b,a,c){this.system._inTools&&!this.runInTools||this._updateScriptAttributes(a,c)||(this.enabled&&
- this.system._disableScriptComponent(this),this.system._destroyScriptComponent(this),this.data.areScriptsLoaded=!1,b=c.map(function(a){return a.url}),this._loadFromCache(b)||this._loadScripts(b))},_updateScriptAttributes:function(b,a){var c=!0;if(b.length!==a.length)c=!1;else{var d,e=a.length;for(d=0;d<e;d++)if(b[d].url!==a[d].url){c=!1;break}}if(c)for(var g in this.instances)this.instances.hasOwnProperty(g)&&this.system._updateAccessors(this.entity,this.instances[g]);return c},_loadFromCache:function(b){var a,
- c,d=[],e=this.system.app._scriptPrefix||"",g=/^http(s)?:\/\//i;a=0;for(c=b.length;a<c;a++){var f=b[a];g.test(f)||(f=pc.path.join(e,f));f=this.system.app.loader.getFromCache(f,"script");if(!f)return!1;d.push(f)}a=0;for(c=d.length;a<c;a++)e=d[a],!0!==e&&e&&this.entity.script&&!this.entity.script.instances[e._pcScriptName]&&(g=new e(this.entity),this.system._preRegisterInstance(this.entity,b[a],e._pcScriptName,g));this.data&&(this.data.areScriptsLoaded=!0);this.system.preloading||(this.system.onInitialize(this.entity),
- this.system.onPostInitialize(this.entity));return!0},_loadScripts:function(b){var a=b.length,c=this.system.app._scriptPrefix||"";b.forEach(function(b){var d=null,g=null;b.toLowerCase().startsWith("http://")||b.toLowerCase().startsWith("https://")?d=g=b:(g=b,d=pc.path.join(c,b));this.system.app.loader.load(d,"script",function(b,c){a--;if(b)console.error(b);else if(c&&this.entity.script&&!this.entity.script.instances[c._pcScriptName]){var d=new c(this.entity);this.system._preRegisterInstance(this.entity,
- g,c._pcScriptName,d)}0===a&&(this.data.areScriptsLoaded=!0,this.system.preloading||(this.system.onInitialize(this.entity),this.system.onPostInitialize(this.entity)))}.bind(this))}.bind(this))}});return{ScriptLegacyComponent:f}}());Object.assign(pc,function(){var f=["enabled","scripts","instances","runInTools"],b=function(a){pc.ComponentSystem.call(this,a);this.id="script";this.description="Allows the Entity to run JavaScript fragments to implement custom behavior.";this.ComponentType=pc.ScriptLegacyComponent;this.DataType=pc.ScriptLegacyComponentData;this.schema=f;this.preloading=!1;this.instancesWithUpdate=[];this.instancesWithFixedUpdate=[];this.instancesWithPostUpdate=[];this.instancesWithToolsUpdate=[];this.on("beforeremove",
- this.onBeforeRemove,this);pc.ComponentSystem.bind("initialize",this.onInitialize,this);pc.ComponentSystem.bind("postInitialize",this.onPostInitialize,this);pc.ComponentSystem.bind("update",this.onUpdate,this);pc.ComponentSystem.bind("fixedUpdate",this.onFixedUpdate,this);pc.ComponentSystem.bind("postUpdate",this.onPostUpdate,this);pc.ComponentSystem.bind("toolsUpdate",this.onToolsUpdate,this)};b.prototype=Object.create(pc.ComponentSystem.prototype);b.prototype.constructor=b;pc.Component._buildAccessors(pc.ScriptLegacyComponent.prototype,
- f);Object.assign(b.prototype,{initializeComponentData:function(a,b,d){d=["runInTools","enabled","scripts"];b.scripts&&b.scripts.length&&b.scripts.forEach(function(a){if(a.attributes&&"array"===pc.type(a.attributes)){for(var b={},c=0;c<a.attributes.length;c++)b[a.attributes[c].name]=a.attributes[c];a.attributes=b}});pc.ComponentSystem.prototype.initializeComponentData.call(this,a,b,d)},cloneComponent:function(a,b){for(var c=this.store[a.getGuid()],e={runInTools:c.data.runInTools,scripts:[],enabled:c.data.enabled},
- c=c.data.scripts,g=0,f=c.length;g<f;g++){var k=c[g].attributes;k&&delete c[g].attributes;e.scripts.push(pc.extend({},c[g]));k&&(e.scripts[g].attributes=this._cloneAttributes(k),c[g].attributes=k)}return this.addComponent(b,e)},onBeforeRemove:function(a,b){b.enabled&&this._disableScriptComponent(b);this._destroyScriptComponent(b)},onInitialize:function(a){this._registerInstances(a);if(a.enabled){a.script&&a.script.enabled&&this._initializeScriptComponent(a.script);a=a._children;var b,d=a.length;for(b=
- 0;b<d;b++)if(a[b]instanceof pc.Entity)this.onInitialize(a[b])}},onPostInitialize:function(a){if(a.enabled){a.script&&a.script.enabled&&this._postInitializeScriptComponent(a.script);a=a._children;var b,d=a.length;for(b=0;b<d;b++)if(a[b]instanceof pc.Entity)this.onPostInitialize(a[b])}},_callInstancesMethod:function(a,b){var c=a.data.instances,e;for(e in c)if(c.hasOwnProperty(e)){var g=c[e].instance;if(g[b])g[b]()}},_initializeScriptComponent:function(a){this._callInstancesMethod(a,"initialize");a.data.initialized=
- !0;a.enabled&&a.entity.enabled&&this._enableScriptComponent(a)},_enableScriptComponent:function(a){this._callInstancesMethod(a,"onEnable")},_disableScriptComponent:function(a){this._callInstancesMethod(a,"onDisable")},_destroyScriptComponent:function(a){var b,d=a.data.instances,e;for(e in d)if(d.hasOwnProperty(e)){var g=d[e].instance;g.destroy&&g.destroy();g.update&&(b=this.instancesWithUpdate.indexOf(g),0<=b&&this.instancesWithUpdate.splice(b,1));g.fixedUpdate&&(b=this.instancesWithFixedUpdate.indexOf(g),
- 0<=b&&this.instancesWithFixedUpdate.splice(b,1));g.postUpdate&&(b=this.instancesWithPostUpdate.indexOf(g),0<=b&&this.instancesWithPostUpdate.splice(b,1));g.toolsUpdate&&(b=this.instancesWithToolsUpdate.indexOf(g),0<=b&&this.instancesWithToolsUpdate.splice(b,1));a.instances[e].instance===a[e]&&delete a[e];delete a.instances[e]}},_postInitializeScriptComponent:function(a){this._callInstancesMethod(a,"postInitialize");a.data.postInitialized=!0},_updateInstances:function(a,b,d){for(var c,g=0,f=b.length;g<
- f;g++)if((c=b[g])&&c.entity&&c.entity.enabled&&c.entity.script.enabled)c[a](d)},onUpdate:function(a){this._updateInstances("update",this.instancesWithUpdate,a)},onFixedUpdate:function(a){this._updateInstances("fixedUpdate",this.instancesWithFixedUpdate,a)},onPostUpdate:function(a){this._updateInstances("postUpdate",this.instancesWithPostUpdate,a)},onToolsUpdate:function(a){this._updateInstances("toolsUpdate",this.instancesWithToolsUpdate,a)},broadcast:function(a,b){console.warn("DEPRECATED: ScriptLegacyComponentSystem.broadcast() is deprecated and will be removed soon. Please use: http://developer.playcanvas.com/user-manual/scripting/communication/");
- var c=pc.makeArray(arguments).slice(2),e,g,f,k=this.store;for(e in k)k.hasOwnProperty(e)&&(g=k[e].data,g.instances[a]&&(f=g.instances[a].instance[b])&&f.apply(g.instances[a].instance,c))},_preRegisterInstance:function(a,b,d,e){if(a.script){a.script.data._instances=a.script.data._instances||{};if(a.script.data._instances[d])throw Error(pc.string.format("Script name collision '{0}'. Scripts from '{1}' and '{2}' {{3}}",d,b,a.script.data._instances[d].url,a.getGuid()));a.script.data._instances[d]={url:b,
- name:d,instance:e}}},_registerInstances:function(a){var b,d,e;if(a.script&&a.script.data._instances){a.script.instances=a.script.data._instances;for(e in a.script.instances){b=a.script.instances[e];d=b.instance;pc.events.attach(d);d.update&&this.instancesWithUpdate.push(d);d.fixedUpdate&&this.instancesWithFixedUpdate.push(d);d.postUpdate&&this.instancesWithPostUpdate.push(d);d.toolsUpdate&&this.instancesWithToolsUpdate.push(d);a.script.scripts&&this._createAccessors(a,b);if(a.script[e])throw Error(pc.string.format("Script with name '{0}' is already attached to Script Component",
- e));a.script[e]=d}delete a.script.data._instances}a=a._children;d=a.length;for(b=0;b<d;b++)a[b]instanceof pc.Entity&&this._registerInstances(a[b])},_cloneAttributes:function(a){var b={},d;for(d in a)if(a.hasOwnProperty(d))if("entity"!==a[d].type)b[d]=pc.extend({},a[d]);else{var e=a[d].value;delete a[d].value;b[d]=pc.extend({},a[d]);b[d].value=e;a[d].value=e}return b},_createAccessors:function(a,b){var c,e=a.script.scripts.length,g=b.url;for(c=0;c<e;c++){var f=a.script.scripts[c];if(f.url===g){c=f.attributes;
- if(f.name&&c){for(var k in c)c.hasOwnProperty(k)&&this._createAccessor(c[k],b);a.script.data.attributes[f.name]=this._cloneAttributes(c)}break}}},_createAccessor:function(a,b){var c=this;a={name:a.name,value:a.value,type:a.type};c._convertAttributeValue(a);Object.defineProperty(b.instance,a.name,{get:function(){return a.value},set:function(d){var e=a.value;a.value=d;c._convertAttributeValue(a);b.instance.fire("set",a.name,e,a.value)},configurable:!0})},_updateAccessors:function(a,b){var c,e=a.script.scripts.length,
- g,f=b.url,k,p;for(c=0;c<e;c++)if(k=a.script,p=k.scripts[c],p.url===f){c=p.name;p=p.attributes;if(c){if(p)for(g in p)p.hasOwnProperty(g)&&this._createAccessor(p[g],b);if(e=k.data.attributes[c])for(g in e)if(f=e[g],!(g in p))delete b.instance[f.name];else if(p[g].value!==f.value&&b.instance.onAttributeChanged)b.instance.onAttributeChanged(f.name,f.value,p[g].value);p?k.data.attributes[c]=this._cloneAttributes(p):delete k.data.attributes[c]}break}},_convertAttributeValue:function(a){if("rgb"===a.type||
- "rgba"===a.type)"array"===pc.type(a.value)&&(a.value=3===a.value.length?new pc.Color(a.value[0],a.value[1],a.value[2]):new pc.Color(a.value[0],a.value[1],a.value[2],a.value[3]));else if("vec2"===a.type)"array"===pc.type(a.value)&&(a.value=new pc.Vec2(a.value[0],a.value[1]));else if("vec3"===a.type||"vector"===a.type)"array"===pc.type(a.value)&&(a.value=new pc.Vec3(a.value[0],a.value[1],a.value[2]));else if("vec4"===a.type)"array"===pc.type(a.value)&&(a.value=new pc.Vec4(a.value[0],a.value[1],a.value[2],
- a.value[3]));else if("entity"===a.type)null!==a.value&&"string"===typeof a.value&&(a.value=this.app.root.findByGuid(a.value));else if("curve"===a.type||"colorcurve"===a.type)a.value=new (a.value.keys[0]instanceof Array?pc.CurveSet:pc.Curve)(a.value.keys),a.value.type=a.value.type}});return{ScriptLegacyComponentSystem:b}}());Object.assign(pc,function(){return{ScriptLegacyComponentData:function(){this.scripts=[];this.enabled=!0;this.instances={};this._instances={};this.runInTools=!1;this.attributes={};this.areScriptsLoaded=this.postInitialized=this.initialized=!1}}}());Object.assign(pc,{DISTANCE_LINEAR:"linear",DISTANCE_INVERSE:"inverse",DISTANCE_EXPONENTIAL:"exponential"});Object.assign(pc,function(){var f={volume:0,pitch:0,loop:!1,startTime:0,duration:0,position:new pc.Vec3,maxDistance:0,refDistance:0,rollOffFactor:0,distanceModel:0,onPlay:null,onPause:null,onResume:null,onStop:null,onEnd:null},b=function(a,b,d){d=d||{};this._component=a;this._assets=a.system.app.assets;this._manager=a.system.manager;this._name=b||"Untitled";this._volume=void 0!==d.volume?pc.math.clamp(Number(d.volume)||0,0,1):1;this._pitch=void 0!==d.pitch?Math.max(.01,Number(d.pitch)||0):1;this._loop=
- !(void 0===d.loop||!d.loop);this._duration=0<d.duration?d.duration:null;this._startTime=Math.max(0,Number(d.startTime)||0);this._overlap=!!d.overlap;this._autoPlay=!!d.autoPlay;this._lastNode=this._firstNode=null;this._asset=d.asset;this._asset instanceof pc.Asset&&(this._asset=this._asset.id);this._onInstancePlayHandler=this._onInstancePlay.bind(this);this._onInstancePauseHandler=this._onInstancePause.bind(this);this._onInstanceResumeHandler=this._onInstanceResume.bind(this);this._onInstanceStopHandler=
- this._onInstanceStop.bind(this);this._onInstanceEndHandler=this._onInstanceEnd.bind(this);this.instances=[];pc.events.attach(this)};Object.assign(b.prototype,{play:function(){this.overlap||!this.isPlaying&&!this.isPaused||this.stop();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,d=0,e=b.length;d<
- e;d++)b[d].pause()&&(a=!0);return a},resume:function(){for(var a=!1,b=this.instances,d=0,e=b.length;d<e;d++)b[d].resume()&&(a=!0);return a},stop:function(){for(var a=!1,b=this.instances,d=0,e=b.length;d<e;d++)b[d].stop()&&(a=!0);b.length=0;return a},load:function(){if(this._hasAsset()){var a=this._assets.get(this._asset);a?(a.off("remove",this._onAssetRemoved,this),a.on("remove",this._onAssetRemoved,this),a.resource?this.fire("load",a.resource):(a.off("load",this._onAssetLoad,this),a.once("load",
- this._onAssetLoad,this),this._assets.load(a))):(this._assets.off("add:"+this._asset,this._onAssetAdd,this),this._assets.once("add:"+this._asset,this._onAssetAdd,this))}},setExternalNodes:function(a,b){if(a){if(b||(b=a),this._firstNode=a,this._lastNode=b,!this._overlap)for(var c=this.instances,e=0,g=c.length;e<g;e++)c[e].setExternalNodes(a,b)}else console.error("The firstNode must have a valid AudioNode")},clearExternalNodes:function(){this._lastNode=this._firstNode=null;if(!this._overlap)for(var a=
- this.instances,b=0,d=a.length;b<d;b++)a[b].clearExternalNodes()},getExternalNodes:function(){return[this._firstNode,this._lastNode]},_hasAsset:function(){return null!=this._asset},_createInstance:function(){var a;a=this._component;var b=null;if(this._hasAsset()){var d=this._assets.get(this._asset);d&&(b=d.resource)}f.volume=this._volume*a.volume;f.pitch=this._pitch*a.pitch;f.loop=this._loop;f.startTime=this._startTime;f.duration=this._duration;f.onPlay=this._onInstancePlayHandler;f.onPause=this._onInstancePauseHandler;
- f.onResume=this._onInstanceResumeHandler;f.onStop=this._onInstanceStopHandler;f.onEnd=this._onInstanceEndHandler;a.positional?(f.position.copy(a.entity.getPosition()),f.maxDistance=a.maxDistance,f.refDistance=a.refDistance,f.rollOffFactor=a.rollOffFactor,f.distanceModel=a.distanceModel,a=new pc.SoundInstance3d(this._manager,b,f)):a=new pc.SoundInstance(this._manager,b,f);this._firstNode&&a.setExternalNodes(this._firstNode,this._lastNode);return a},_onInstancePlay:function(a){this.fire("play",a);this._component.fire("play",
- this,a)},_onInstancePause:function(a){this.fire("pause",a);this._component.fire("pause",this,a)},_onInstanceResume:function(a){this.fire("resume",a);this._component.fire("resume",this,a)},_onInstanceStop:function(a){this.fire("stop",a);this._component.fire("stop",this,a)},_onInstanceEnd:function(a){var b=this.instances.indexOf(a);-1!==b&&this.instances.splice(b,1);this.fire("end",a);this._component.fire("end",this,a)},_onAssetAdd:function(a){this.load()},_onAssetLoad:function(a){this.load()},_onAssetRemoved:function(a){a.off("remove",
- this._onAssetRemoved,this);this._assets.off("add:"+a.id,this._onAssetAdd,this);this.stop()},updatePosition:function(a){for(var b=this.instances,d=0,e=b.length;d<e;d++)b[d].position=a}});Object.defineProperty(b.prototype,"name",{get:function(){return this._name},set:function(a){this._name=a}});Object.defineProperty(b.prototype,"volume",{get:function(){return this._volume},set:function(a){this._volume=pc.math.clamp(Number(a)||0,0,1);if(!this._overlap){a=this.instances;for(var b=0,d=a.length;b<d;b++)a[b].volume=
- this._volume*this._component.volume}}});Object.defineProperty(b.prototype,"pitch",{get:function(){return this._pitch},set:function(a){this._pitch=Math.max(Number(a)||0,.01);if(!this._overlap){a=this.instances;for(var b=0,d=a.length;b<d;b++)a[b].pitch=this.pitch*this._component.pitch}}});Object.defineProperty(b.prototype,"loop",{get:function(){return this._loop},set:function(a){this._loop=!!a;a=this.instances;for(var b=0,d=a.length;b<d;b++)a[b].loop=this._loop}});Object.defineProperty(b.prototype,
- "autoPlay",{get:function(){return this._autoPlay},set:function(a){this._autoPlay=!!a}});Object.defineProperty(b.prototype,"overlap",{get:function(){return this._overlap},set:function(a){this._overlap=!!a}});Object.defineProperty(b.prototype,"startTime",{get:function(){return this._startTime},set:function(a){this._startTime=Math.max(0,Number(a)||0);if(!this._overlap){a=this.instances;for(var b=0,d=a.length;b<d;b++)a[b].startTime=this._startTime}}});Object.defineProperty(b.prototype,"duration",{get:function(){var a=
- 0;this._hasAsset()&&(a=this._assets.get(this._asset),a=a.resource?a.resource.duration:0);return null!=this._duration?this._duration%(a||1):a},set:function(a){this._duration=Math.max(0,Number(a)||0)||null;if(!this._overlap){a=this.instances;for(var b=0,d=a.length;b<d;b++)a[b].duration=this._duration}}});Object.defineProperty(b.prototype,"asset",{get:function(){return this._asset},set:function(a){var b=this._asset;b&&(this._assets.off("add:"+b,this._onAssetAdd,this),(b=this._assets.get(b))&&b.off("remove",
- this._onAssetRemoved,this));this._asset=a;this._asset instanceof pc.Asset&&(this._asset=this._asset.id);this._hasAsset()&&this._component.enabled&&this._component.entity.enabled&&this.load()}});Object.defineProperty(b.prototype,"isLoaded",{get:function(){if(this._hasAsset()){var a=this._assets.get(this._asset);if(a)return!!a.resource}return!1}});Object.defineProperty(b.prototype,"isPlaying",{get:function(){for(var a=this.instances,b=0,d=a.length;b<d;b++)if(a[b].isPlaying)return!0;return!1}});Object.defineProperty(b.prototype,
- "isPaused",{get:function(){var a=this.instances,b=a.length;if(0===b)return!1;for(var d=0;d<b;d++)if(!a[d].isPaused)return!1;return!0}});Object.defineProperty(b.prototype,"isStopped",{get:function(){for(var a=this.instances,b=0,d=a.length;b<d;b++)if(!a[b].isStopped)return!1;return!0}});return{SoundSlot:b}}());Object.assign(pc,function(){var f=function(b,a){pc.Component.call(this,b,a);this.on("set_slots",this.onSetSlots,this);this.on("set_volume",this.onSetVolume,this);this.on("set_pitch",this.onSetPitch,this);this.on("set_refDistance",this.onSetRefDistance,this);this.on("set_maxDistance",this.onSetMaxDistance,this);this.on("set_rollOffFactor",this.onSetRollOffFactor,this);this.on("set_distanceModel",this.onSetDistanceModel,this);this.on("set_positional",this.onSetPositional,this)};f.prototype=Object.create(pc.Component.prototype);
- f.prototype.constructor=f;Object.assign(f.prototype,{onSetSlots:function(b,a,c){var d;if(a)for(d in a)a[d].stop();b={};for(d in c)c[d]instanceof pc.SoundSlot?b[c[d].name]=c[d]:c[d].name&&(b[c[d].name]=new pc.SoundSlot(this,c[d].name,c[d]));this.data.slots=b;if(this.enabled&&this.entity.enabled)this.onEnable()},onSetVolume:function(b,a,c){b=this.data.slots;for(var d in b)if(a=b[d],!a.overlap)for(var e=a.instances,g=0,f=e.length;g<f;g++)e[g].volume=a.volume*c},onSetPitch:function(b,a,c){b=this.data.slots;
- for(var d in b)if(a=b[d],!a.overlap)for(var e=a.instances,g=0,f=e.length;g<f;g++)e[g].pitch=a.pitch*c},onSetRefDistance:function(b,a,c){b=this.data.slots;for(var d in b)if(a=b[d],!a.overlap){a=a.instances;for(var e=0,g=a.length;e<g;e++)a[e].refDistance=c}},onSetMaxDistance:function(b,a,c){b=this.data.slots;for(var d in b)if(a=b[d],!a.overlap){a=a.instances;for(var e=0,g=a.length;e<g;e++)a[e].maxDistance=c}},onSetRollOffFactor:function(b,a,c){b=this.data.slots;for(var d in b)if(a=b[d],!a.overlap){a=
- a.instances;for(var e=0,g=a.length;e<g;e++)a[e].rollOffFactor=c}},onSetDistanceModel:function(b,a,c){b=this.data.slots;for(var d in b)if(a=b[d],!a.overlap){a=a.instances;for(var e=0,g=a.length;e<g;e++)a[e].distanceModel=c}},onSetPositional:function(b,a,c){b=this.data.slots;for(var d in b)if(a=b[d],!a.overlap){c=a.instances;for(var e=0,g=c.length;e<g;e++){var f=c[e].isPlaying||c[e].isSuspended,k=c[e].currentTime;f&&c[e].stop();c[e]=a._createInstance();f&&(c[e].play(),c[e].currentTime=k)}}},onEnable:function(){if(!this.system._inTools){var b=
- this.data.slots,a=this.data.playingBeforeDisable,c;for(c in b){var d=b[c];d.autoPlay&&d.isStopped?d.play():a[c]?d.resume():d.isLoaded||d.load()}}},onDisable:function(){var b=this.data.slots,a={},c;for(c in b)!b[c].overlap&&b[c].isPlaying&&(b[c].pause(),a[c]=!0);this.data.playingBeforeDisable=a},onRemove:function(){this.off()},addSlot:function(b,a){var c=this.data.slots;if(c[b])return logWARNING("A sound slot with name "+b+" already exists on Entity "+this.entity.getPath()),null;var d=new pc.SoundSlot(this,
- b,a);c[b]=d;d.autoPlay&&this.enabled&&this.entity.enabled&&d.play();return d},removeSlot:function(b){var a=this.data.slots;a[b]&&(a[b].stop(),delete a[b])},slot:function(b){return this.data.slots[b]},play:function(b){if(!this.enabled||!this.entity.enabled)return null;var a=this.slots[b];return a?a.play():(logWARNING("Trying to play sound slot with name "+b+" which does not exist"),null)},pause:function(b){var a;a=this.data.slots;if(b)(a=a[b])?a.pause():logWARNING("Trying to pause sound slot with name "+
- b+" which does not exist");else for(var c in a)a[c].pause()},resume:function(b){var a;a=this.data.slots;if(b)(a=a[b])?a.isPaused&&a.resume():logWARNING("Trying to resume sound slot with name "+b+" which does not exist");else for(var c in a)a[c].resume()},stop:function(b){var a;a=this.data.slots;if(b)(a=a[b])?a.stop():logWARNING("Trying to stop sound slot with name "+b+" which does not exist");else for(var c in a)a[c].stop()}});return{SoundComponent:f}}());Object.assign(pc,function(){var f="enabled volume pitch positional refDistance maxDistance rollOffFactor distanceModel slots".split(" "),b=function(a,b){pc.ComponentSystem.call(this,a);this.id="sound";this.description="Allows an Entity to play sounds";this.ComponentType=pc.SoundComponent;this.DataType=pc.SoundComponentData;this.schema=f;this.manager=b;pc.ComponentSystem.bind("update",this.onUpdate,this);this.on("beforeremove",this.onBeforeRemove,this)};b.prototype=Object.create(pc.ComponentSystem.prototype);
- b.prototype.constructor=b;pc.Component._buildAccessors(pc.SoundComponent.prototype,f);Object.assign(b.prototype,{initializeComponentData:function(a,b,d){d="volume pitch positional refDistance maxDistance rollOffFactor distanceModel slots enabled".split(" ");pc.ComponentSystem.prototype.initializeComponentData.call(this,a,b,d)},cloneComponent:function(a,b){var c,e=a.sound.data,g={};for(c in e)e.hasOwnProperty(c)&&(g[c]=e[c]);g.slots={};for(c in e.slots){var f=e.slots[c];g.slots[c]=f instanceof pc.SoundSlot?
- {name:f.name,volume:f.volume,pitch:f.pitch,loop:f.loop,duration:f.duration,startTime:f.startTime,overlap:f.overlap,autoPlay:f.autoPlay,asset:f.asset}:f}g.playingBeforeDisable={};return this.addComponent(b,g)},onUpdate:function(a){a=this.store;for(var b in a)if(a.hasOwnProperty(b)){var d=a[b],e=d.entity,d=d.data;if(d.enabled&&e.enabled&&d.positional){var e=e.getPosition(),d=d.slots,g;for(g in d)d[g].updatePosition(e)}}},onBeforeRemove:function(a,b){var c=b.slots,e;for(e in c)c[e].overlap||c[e].stop();
- b.onRemove()}});Object.defineProperty(b.prototype,"volume",{get:function(){return this.manager.volume},set:function(a){this.manager.volume=a}});Object.defineProperty(b.prototype,"context",{get:function(){return pc.SoundManager.hasAudioContext()?this.manager.context:(console.warn("WARNING: Audio context is not supported on this browser"),null)}});return{SoundComponentSystem:b}}());pc.SoundComponentData=function(){this.enabled=!0;this.pitch=this.volume=1;this.positional=!0;this.refDistance=1;this.maxDistance=1E4;this.rollOffFactor=1;this.distanceModel=pc.DISTANCE_LINEAR;this.slots={};this.playingBeforeDisable={}};Object.assign(pc,function(){var f=function(b,a){pc.Component.call(this,b,a);this.on("set_assets",this.onSetAssets,this);this.on("set_loop",this.onSetLoop,this);this.on("set_volume",this.onSetVolume,this);this.on("set_pitch",this.onSetPitch,this);this.on("set_minDistance",this.onSetMinDistance,this);this.on("set_maxDistance",this.onSetMaxDistance,this);this.on("set_rollOffFactor",this.onSetRollOffFactor,this);this.on("set_distanceModel",this.onSetDistanceModel,this);this.on("set_3d",this.onSet3d,this)};
- f.prototype=Object.create(pc.Component.prototype);f.prototype.constructor=f;Object.assign(f.prototype,{play:function(b){if(this.enabled&&this.entity.enabled){this.channel&&this.stop();var a,c=this.data;c.sources[b]&&(c["3d"]?(a=this.entity.getPosition(),a=this.system.manager.playSound3d(c.sources[b],a,c)):a=this.system.manager.playSound(c.sources[b],c),c.currentSource=b,c.channel=a)}},pause:function(){this.channel&&this.channel.pause()},unpause:function(){this.channel&&this.channel.paused&&this.channel.unpause()},
- stop:function(){this.channel&&(this.channel.stop(),this.channel=null)},onSetAssets:function(b,a,c){b=[];var d,e=c.length;if(a&&a.length)for(d=0;d<a.length;d++)if(a[d]){var g=this.system.app.assets.get(a[d]);g&&(g.off("change",this.onAssetChanged,this),g.off("remove",this.onAssetRemoved,this),this.currentSource===g.name&&this.stop())}if(e)for(d=0;d<e;d++)0>a.indexOf(c[d])&&(c[d]instanceof pc.Asset?b.push(c[d].id):b.push(c[d]));!this.system._inTools&&b.length&&this.loadAudioSourceAssets(b)},onAssetChanged:function(b,
- a,c,d){"resource"===a&&this.data.sources&&(this.data.sources[b.name]=c,this.data.currentSource===b.name&&this.channel&&(this.channel.paused?(this.play(b.name),this.pause()):this.play(b.name)))},onAssetRemoved:function(b){b.off("remove",this.onAssetRemoved,this);this.data.sources[b.name]&&(delete this.data.sources[b.name],this.data.currentSource===b.name&&(this.stop(),this.data.currentSource=null))},onSetLoop:function(b,a,c){a!=c&&this.channel&&this.channel.setLoop(c)},onSetVolume:function(b,a,c){a!=
- c&&this.channel&&this.channel.setVolume(c)},onSetPitch:function(b,a,c){a!=c&&this.channel&&this.channel.setPitch(c)},onSetMaxDistance:function(b,a,c){a!=c&&this.channel instanceof pc.Channel3d&&this.channel.setMaxDistance(c)},onSetMinDistance:function(b,a,c){a!=c&&this.channel instanceof pc.Channel3d&&this.channel.setMinDistance(c)},onSetRollOffFactor:function(b,a,c){a!=c&&this.channel instanceof pc.Channel3d&&this.channel.setRollOffFactor(c)},onSetDistanceModel:function(b,a,c){a!==c&&this.channel instanceof
- pc.Channel3d&&this.channel.setDistanceModel(c)},onSet3d:function(b,a,c){a!==c&&this.system.initialized&&this.currentSource&&(a=b=!1,this.channel&&(b=this.channel.paused,a=this.channel.suspended),this.play(this.currentSource),this.channel&&(this.channel.paused=b,this.channel.suspended=a))},onEnable:function(){var b=this.data.assets;if(b)for(var a=this.system.app.assets,c=0,d=b.length;c<d;c++){var e=b[c];e instanceof pc.Asset||(e=a.get(e));e&&!e.resource&&a.load(e)}this.system.initialized&&(this.data.activate&&
- !this.channel?this.play(this.currentSource):this.unpause())},onDisable:function(){this.pause()},loadAudioSourceAssets:function(b){var a=this,c=b.map(function(a){return this.system.app.assets.get(a)},this),d={},e=null,g=c.length,f=function(a){g--},k=function(){this.data.sources=d;this.data.currentSource=e;if(this.enabled&&this.activate&&e)this.onEnable()}.bind(this);c.forEach(function(c,l){c?(e=e||c.name,c.off("change",this.onAssetChanged,this),c.on("change",this.onAssetChanged,this),c.off("remove",
- this.onAssetRemoved,this),c.on("remove",this.onAssetRemoved,this),c.off("error",f,this),c.on("error",f,this),c.ready(function(a){d[a.name]=a.resource;g--;0===g&&k()}),!c.resource&&a.enabled&&a.entity.enabled&&this.system.app.assets.load(c)):(g--,0===g&&k(),this.system.app.assets.on("add:"+b[l],function(b){b.ready(function(b){a.data.sources[b.name]=b.resource});b.resource||a.system.app.assets.load(b)}))},this)}});return{AudioSourceComponent:f}}());Object.assign(pc,function(){var f="enabled assets volume pitch loop activate 3d minDistance maxDistance rollOffFactor distanceModel sources currentSource channel".split(" "),b=function(a,b){pc.ComponentSystem.call(this,a);this.id="audiosource";this.description="Specifies audio assets that can be played at the position of the Entity.";this.ComponentType=pc.AudioSourceComponent;this.DataType=pc.AudioSourceComponentData;this.schema=f;this.manager=b;this.initialized=!1;pc.ComponentSystem.bind("initialize",
- this.onInitialize,this);pc.ComponentSystem.bind("update",this.onUpdate,this);this.on("remove",this.onRemove,this)};b.prototype=Object.create(pc.ComponentSystem.prototype);b.prototype.constructor=b;pc.Component._buildAccessors(pc.AudioSourceComponent.prototype,f);Object.assign(b.prototype,{initializeComponentData:function(a,b,d){d="activate volume pitch loop 3d minDistance maxDistance rollOffFactor distanceModel enabled assets".split(" ");pc.ComponentSystem.prototype.initializeComponentData.call(this,
- a,b,d);a.paused=!(a.enabled&&a.activate)},onInitialize:function(a){a.audiosource&&a.enabled&&a.audiosource.enabled&&a.audiosource.activate&&a.audiosource.play(a.audiosource.currentSource);a=a._children;var b,d=a.length;for(b=0;b<d;b++)if(a[b]instanceof pc.Entity)this.onInitialize(a[b]);this.initialized=!0},onUpdate:function(a){a=this.store;for(var b in a)if(a.hasOwnProperty(b)){var d=a[b],e=d.entity,d=d.data;d.enabled&&e.enabled&&d.channel instanceof pc.Channel3d&&(e=e.getPosition(),d.channel.setPosition(e))}},
- onRemove:function(a,b){b.channel&&(b.channel.stop(),b.channel=null)},setVolume:function(a){this.manager.setVolume(a)}});return{AudioSourceComponentSystem:b}}());pc.AudioSourceComponentData=function(){this.enabled=!0;this.assets=[];this.activate=!0;this.pitch=this.volume=1;this.loop=!1;this["3d"]=!0;this.minDistance=1;this.maxDistance=1E4;this.rollOffFactor=1;this.distanceModel=pc.DISTANCE_INVERSE;this.paused=!0;this.sources={};this.channel=this.currentSource=null};Object.assign(pc,function(){var f=function(b,a){pc.Component.call(this,b,a)};f.prototype=Object.create(pc.Component.prototype);f.prototype.constructor=f;Object.assign(f.prototype,{setCurrentListener:function(){if(this.enabled&&this.entity.audiolistener&&this.entity.enabled){this.system.current=this.entity;var b=this.system.current.getPosition();this.system.manager.listener.setPosition(b)}},onEnable:function(){this.setCurrentListener()},onDisable:function(){this.system.current===this.entity&&(this.system.current=
- null)}});return{AudioListenerComponent:f}}());Object.assign(pc,function(){var f=["enabled"],b=function(a,b){pc.ComponentSystem.call(this,a);this.id="audiolistener";this.description="Specifies the location of the listener for 3D audio playback.";this.ComponentType=pc.AudioListenerComponent;this.DataType=pc.AudioListenerComponentData;this.schema=f;this.manager=b;this.current=null;pc.ComponentSystem.bind("update",this.onUpdate,this)};b.prototype=Object.create(pc.ComponentSystem.prototype);b.prototype.constructor=b;pc.Component._buildAccessors(pc.AudioListenerComponent.prototype,
- f);Object.assign(b.prototype,{initializeComponentData:function(a,b,d){d=["enabled"];pc.ComponentSystem.prototype.initializeComponentData.call(this,a,b,d)},onUpdate:function(a){this.current&&(a=this.current.getPosition(),this.manager.listener.setPosition(a),a=this.current.getWorldTransform(),this.manager.listener.setOrientation(a))}});return{AudioListenerComponentSystem:b}}());Object.assign(pc,function(){return{AudioListenerComponentData:function(){this.enabled=!0}}}());Object.assign(pc,{BODYTYPE_STATIC:"static",BODYTYPE_DYNAMIC:"dynamic",BODYTYPE_KINEMATIC:"kinematic",BODYFLAG_STATIC_OBJECT:1,BODYFLAG_KINEMATIC_OBJECT:2,BODYFLAG_NORESPONSE_OBJECT:4,BODYSTATE_ACTIVE_TAG:1,BODYSTATE_ISLAND_SLEEPING:2,BODYSTATE_WANTS_DEACTIVATION:3,BODYSTATE_DISABLE_DEACTIVATION:4,BODYSTATE_DISABLE_SIMULATION:5,BODYGROUP_NONE:0,BODYGROUP_DEFAULT:1,BODYGROUP_DYNAMIC:1,BODYGROUP_STATIC:2,BODYGROUP_KINEMATIC:4,BODYGROUP_ENGINE_1:8,BODYGROUP_TRIGGER:16,BODYGROUP_ENGINE_2:32,BODYGROUP_ENGINE_3:64,
- BODYGROUP_USER_1:128,BODYGROUP_USER_2:256,BODYGROUP_USER_3:512,BODYGROUP_USER_4:1024,BODYGROUP_USER_5:2048,BODYGROUP_USER_6:4096,BODYGROUP_USER_7:8192,BODYGROUP_USER_8:16384,BODYMASK_NONE:0,BODYMASK_ALL:65535,BODYMASK_STATIC:2,BODYMASK_NOT_STATIC:65533,BODYMASK_NOT_STATIC_KINEMATIC:65529});Object.assign(pc,function(){var f,b,a,c,d,e=function(e,l){pc.Component.call(this,e,l);"undefined"===typeof Ammo||f||(f=new Ammo.btTransform,b=new Ammo.btVector3,a=new Ammo.btVector3,c=new Ammo.btQuaternion,d=new Ammo.btVector3(0,0,0));this.on("set_mass",this.onSetMass,this);this.on("set_linearDamping",this.onSetLinearDamping,this);this.on("set_angularDamping",this.onSetAngularDamping,this);this.on("set_linearFactor",this.onSetLinearFactor,this);this.on("set_angularFactor",this.onSetAngularFactor,
- this);this.on("set_friction",this.onSetFriction,this);this.on("set_restitution",this.onSetRestitution,this);this.on("set_type",this.onSetType,this);this.on("set_group",this.onSetGroupOrMask,this);this.on("set_mask",this.onSetGroupOrMask,this);this.on("set_body",this.onSetBody,this);this._displacement=new pc.Vec3(0,0,0);this._linearVelocity=new pc.Vec3(0,0,0);this._angularVelocity=new pc.Vec3(0,0,0)};e.prototype=Object.create(pc.Component.prototype);e.prototype.constructor=e;Object.defineProperty(e.prototype,
- "bodyType",{get:function(){console.warn("WARNING: bodyType: Function is deprecated. Query type property instead.");return this.type},set:function(a){console.warn("WARNING: bodyType: Function is deprecated. Set type property instead.");this.type=a}});Object.defineProperty(e.prototype,"linearVelocity",{get:function(){if(!this.isKinematic()&&this.body){var a=this.body.getLinearVelocity();this._linearVelocity.set(a.x(),a.y(),a.z())}return this._linearVelocity},set:function(a){this.activate();!this.isKinematic()&&
- this.body&&(b.setValue(a.x,a.y,a.z),this.body.setLinearVelocity(b));this._linearVelocity.copy(a)}});Object.defineProperty(e.prototype,"angularVelocity",{get:function(){if(!this.isKinematic()&&this.body){var a=this.body.getAngularVelocity();this._angularVelocity.set(a.x(),a.y(),a.z())}return this._angularVelocity},set:function(a){this.activate();!this.isKinematic()&&this.body&&(b.setValue(a.x,a.y,a.z),this.body.setAngularVelocity(b));this._angularVelocity.copy(a)}});Object.assign(e.prototype,{createBody:function(){var a=
- this.entity,d;a.collision&&(d=a.collision.shape,a.trigger&&(a.trigger.destroy(),delete a.trigger));if(d){this.body&&(this.system.removeBody(this.body),Ammo.destroy(this.body));var e=this.isStaticOrKinematic(),f=e?0:this.mass,h=new Ammo.btVector3(0,0,0);e||d.calculateLocalInertia(f,h);var e=a.getPosition(),n=a.getRotation();c.setValue(n.x,n.y,n.z,n.w);n=new Ammo.btTransform;n.setIdentity();n.getOrigin().setValue(e.x,e.y,e.z);n.setRotation(c);e=new Ammo.btDefaultMotionState(n);d=new Ammo.btRigidBodyConstructionInfo(f,
- e,d,h);d=new Ammo.btRigidBody(d);d.setRestitution(this.restitution);d.setFriction(this.friction);d.setDamping(this.linearDamping,this.angularDamping);f=this.linearFactor;b.setValue(f.x,f.y,f.z);d.setLinearFactor(b);f=this.angularFactor;b.setValue(f.x,f.y,f.z);d.setAngularFactor(b);d.entity=a;this.isKinematic()&&(d.setCollisionFlags(d.getCollisionFlags()|pc.BODYFLAG_KINEMATIC_OBJECT),d.setActivationState(pc.BODYSTATE_DISABLE_DEACTIVATION));a.rigidbody.body=d;this.enabled&&this.entity.enabled&&this.enableSimulation()}},
- isActive:function(){return this.body?this.body.isActive():!1},activate:function(){this.body&&this.body.activate()},enableSimulation:function(){if(this.entity.collision&&this.entity.collision.enabled&&!this.data.simulationEnabled){var a=this.body;a&&(this.system.addBody(a,this.group,this.mask),this.isKinematic()?(a.forceActivationState(pc.BODYSTATE_DISABLE_DEACTIVATION),a.activate()):(a.forceActivationState(pc.BODYFLAG_ACTIVE_TAG),this.syncEntityToBody()),this.data.simulationEnabled=!0)}},disableSimulation:function(){var a=
- this.body;a&&this.data.simulationEnabled&&(this.system.removeBody(a),a.forceActivationState(pc.BODYSTATE_DISABLE_SIMULATION),this.data.simulationEnabled=!1)},applyForce:function(){var c,e,f,p,h,n;switch(arguments.length){case 1:c=arguments[0].x;e=arguments[0].y;f=arguments[0].z;break;case 2:c=arguments[0].x;e=arguments[0].y;f=arguments[0].z;p=arguments[1].x;h=arguments[1].y;n=arguments[1].z;break;case 3:c=arguments[0];e=arguments[1];f=arguments[2];break;case 6:c=arguments[0],e=arguments[1],f=arguments[2],
- p=arguments[3],h=arguments[4],n=arguments[5]}var q=this.body;q&&(q.activate(),b.setValue(c,e,f),void 0!==p?(a.setValue(p,h,n),q.applyForce(b,a)):q.applyForce(b,d))},applyTorque:function(){var a,c,d;switch(arguments.length){case 1:a=arguments[0].x;c=arguments[0].y;d=arguments[0].z;break;case 3:a=arguments[0];c=arguments[1];d=arguments[2];break;default:return}var e=this.body;e&&(e.activate(),b.setValue(a,c,d),e.applyTorque(b))},applyImpulse:function(){var c,e,f,p,h,n;switch(arguments.length){case 1:c=
- arguments[0].x;e=arguments[0].y;f=arguments[0].z;break;case 2:c=arguments[0].x;e=arguments[0].y;f=arguments[0].z;p=arguments[1].x;h=arguments[1].y;n=arguments[1].z;break;case 3:c=arguments[0];e=arguments[1];f=arguments[2];break;case 6:c=arguments[0];e=arguments[1];f=arguments[2];p=arguments[3];h=arguments[4];n=arguments[5];break;default:return}var q=this.body;q&&(q.activate(),b.setValue(c,e,f),void 0!==p?(a.setValue(p,h,n),q.applyImpulse(b,a)):q.applyImpulse(b,d))},applyTorqueImpulse:function(){var a,
- c,d;switch(arguments.length){case 1:a=arguments[0].x;c=arguments[0].y;d=arguments[0].z;break;case 3:a=arguments[0];c=arguments[1];d=arguments[2];break;default:return}var e=this.body;e&&(e.activate(),b.setValue(a,c,d),e.applyTorqueImpulse(b))},isStatic:function(){return this.type===pc.BODYTYPE_STATIC},isStaticOrKinematic:function(){return this.type===pc.BODYTYPE_STATIC||this.type===pc.BODYTYPE_KINEMATIC},isKinematic:function(){return this.type===pc.BODYTYPE_KINEMATIC},syncEntityToBody:function(){var a=
- this.body;if(a){var b=this.entity.getPosition(),d=this.entity.getRotation(),e=a.getWorldTransform();e.getOrigin().setValue(b.x,b.y,b.z);c.setValue(d.x,d.y,d.z,d.w);e.setRotation(c);this.isKinematic()&&(b=this.body.getMotionState())&&b.setWorldTransform(e);a.activate()}},syncBodyToEntity:function(){var a=this.body;if(a.isActive()&&(a=a.getMotionState())){a.getWorldTransform(f);var a=f.getOrigin(),b=f.getRotation();this.entity.setPosition(a.x(),a.y(),a.z());this.entity.setRotation(b.x(),b.y(),b.z(),
- b.w())}},teleport:function(){3>arguments.length?(arguments[0]&&this.entity.setPosition(arguments[0]),arguments[1]&&(arguments[1]instanceof pc.Quat?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()},_updateKinematic:function(a){this._displacement.copy(this._linearVelocity).scale(a);this.entity.translate(this._displacement);
- this._displacement.copy(this._angularVelocity).scale(a);this.entity.rotate(this._displacement.x,this._displacement.y,this._displacement.z);if(this.body.getMotionState()){a=this.entity.getPosition();var b=this.entity.getRotation();f.getOrigin().setValue(a.x,a.y,a.z);c.setValue(b.x,b.y,b.z,b.w);f.setRotation(c);this.body.getMotionState().setWorldTransform(f)}},onEnable:function(){this.body||this.createBody();this.enableSimulation()},onDisable:function(){this.disableSimulation()},onSetMass:function(a,
- b,c){if(a=this.data.body){(b=this.enabled&&this.entity.enabled)&&this.disableSimulation();var d=new Ammo.btVector3(0,0,0);a.getCollisionShape().calculateLocalInertia(c,d);a.setMassProps(c,d);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,c,d){if(a=this.data.body)b.setValue(d.x,
- d.y,d.z),a.setLinearFactor(b)},onSetAngularFactor:function(a,c,d){if(a=this.data.body)b.setValue(d.x,d.y,d.z),a.setAngularFactor(b)},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(),c===pc.BODYTYPE_DYNAMIC?(this.data.group=pc.BODYGROUP_DYNAMIC,this.data.mask=pc.BODYMASK_ALL):c===pc.BODYTYPE_KINEMATIC?(this.data.group=pc.BODYGROUP_KINEMATIC,this.data.mask=
- pc.BODYMASK_ALL):(this.data.group=pc.BODYGROUP_STATIC,this.data.mask=pc.BODYMASK_NOT_STATIC),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()}});return{RigidBodyComponent:e}}());Object.assign(pc,function(){var f,b,a={},c={},d=!1,e=function(a,b,c){this.entity=a;this.point=b;this.normal=c},g=function(a,b,c){0===arguments.length?(this.b=this.a=null,this.localPointA=new pc.Vec3,this.localPointB=new pc.Vec3,this.pointA=new pc.Vec3,this.pointB=new pc.Vec3,this.normal=new pc.Vec3):(this.a=a,this.b=b,this.localPointA=c.localPoint,this.localPointB=c.localPointOther,this.pointA=c.point,this.pointB=c.pointOther,this.normal=c.normal)},l=function(a,b,c,d,e){0===arguments.length?(this.localPoint=
- new pc.Vec3,this.localPointOther=new pc.Vec3,this.point=new pc.Vec3,this.pointOther=new pc.Vec3,this.normal=new pc.Vec3):(this.localPoint=a,this.localPointOther=b,this.point=c,this.pointOther=d,this.normal=e)},k=function(a,b){this.other=a;this.contacts=b},p="enabled type mass linearDamping angularDamping linearFactor angularFactor friction restitution group mask body".split(" "),h=function(a){pc.ComponentSystem.call(this,a);this.id="rigidbody";this.description="Adds the entity to the scene's physical simulation.";
- this._stats=a.stats.frame;this.ComponentType=pc.RigidBodyComponent;this.DataType=pc.RigidBodyComponentData;this.contactPointPool=new pc.AllocatePool(l,1);this.contactResultPool=new pc.AllocatePool(k,1);this.singleContactResultPool=new pc.AllocatePool(g,1);this.schema=p;this.maxSubSteps=10;this.fixedTimeStep=1/60;this.on("remove",this.onRemove,this)};h.prototype=Object.create(pc.ComponentSystem.prototype);h.prototype.constructor=h;pc.Component._buildAccessors(pc.RigidBodyComponent.prototype,p);Object.assign(h.prototype,
- {onLibraryLoaded:function(){if("undefined"!==typeof Ammo){var a=new Ammo.btDefaultCollisionConfiguration,c=new Ammo.btCollisionDispatcher(a),d=new Ammo.btDbvtBroadphase,e=new Ammo.btSequentialImpulseConstraintSolver;this.dynamicsWorld=new Ammo.btDiscreteDynamicsWorld(c,d,e,a);this._ammoGravity=new Ammo.btVector3(0,-9.82,0);this.dynamicsWorld.setGravity(this._ammoGravity);f=new Ammo.btVector3;b=new Ammo.btVector3;pc.ComponentSystem.bind("update",this.onUpdate,this)}else pc.ComponentSystem.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;e<g;e++){var f=c[e];d[f]=b[f]}b.bodyType&&(d.type=b.bodyType,console.warn("WARNING: rigidbody.bodyType: Property is deprecated. Use type instead."));d.linearFactor&&"array"===pc.type(d.linearFactor)&&(d.linearFactor=new pc.Vec3(d.linearFactor[0],d.linearFactor[1],d.linearFactor[2]));d.angularFactor&&
- "array"===pc.type(d.angularFactor)&&(d.angularFactor=new pc.Vec3(d.angularFactor[0],d.angularFactor[1],d.angularFactor[2]));pc.ComponentSystem.prototype.initializeComponentData.call(this,a,d,c)},cloneComponent:function(a,b){this.addComponent(b,{enabled:a.rigidbody.enabled,mass:a.rigidbody.mass,linearDamping:a.rigidbody.linearDamping,angularDamping:a.rigidbody.angularDamping,linearFactor:[a.rigidbody.linearFactor.x,a.rigidbody.linearFactor.y,a.rigidbody.linearFactor.z],angularFactor:[a.rigidbody.angularFactor.x,
- a.rigidbody.angularFactor.y,a.rigidbody.angularFactor.z],friction:a.rigidbody.friction,restitution:a.rigidbody.restitution,type:a.rigidbody.type,group:a.rigidbody.group,mask:a.rigidbody.mask})},onRemove:function(a,b){b.body&&(this.removeBody(b.body),Ammo.destroy(b.body));b.body=null},addBody:function(a,b,c){void 0!==b&&void 0!==c?this.dynamicsWorld.addRigidBody(a,b,c):this.dynamicsWorld.addRigidBody(a);return a},removeBody:function(a){this.dynamicsWorld.removeRigidBody(a)},addConstraint:function(a){this.dynamicsWorld.addConstraint(a);
- return a},removeConstraint:function(a){this.dynamicsWorld.removeConstraint(a)},setGravity:function(){var a,b,c;1===arguments.length?(a=arguments[0].x,b=arguments[0].y,c=arguments[0].z):(a=arguments[0],b=arguments[1],c=arguments[2]);this._ammoGravity.setValue(a,b,c);this.dynamicsWorld.setGravity(this._ammoGravity)},raycastFirst:function(a,c){var g=null;f.setValue(a.x,a.y,a.z);b.setValue(c.x,c.y,c.z);var k=new Ammo.ClosestRayResultCallback(f,b);this.dynamicsWorld.rayTest(f,b,k);if(k.hasHit()){var l=
- k.get_m_collisionObject();if(l=Ammo.castObject(l,Ammo.btRigidBody)){var g=k.get_m_hitPointWorld(),h=k.get_m_hitNormalWorld(),g=new e(l.entity,new pc.Vec3(g.x(),g.y(),g.z()),new pc.Vec3(h.x(),h.y(),h.z()));2<arguments.length&&((0,arguments[2])(g),d||(console.warn("[DEPRECATED]: pc.RigidBodyComponentSystem#rayCastFirst no longer requires a callback. The result of the raycast is returned by the function instead."),d=!0))}}Ammo.destroy(k);return g},_storeCollision:function(b,d){var e=!1,g=b.getGuid();
- a[g]=a[g]||{others:[],entity:b};0>a[g].others.indexOf(d)&&(a[g].others.push(d),e=!0);c[g]=c[g]||{others:[],entity:b};c[g].others.push(d);return e},_createContactPointFromAmmo:function(a){var b=this.contactPointPool.allocate();b.localPoint.set(a.get_m_localPointA().x(),a.get_m_localPointA().y(),a.get_m_localPointA().z());b.localPointOther.set(a.get_m_localPointB().x(),a.get_m_localPointB().y(),a.get_m_localPointB().z());b.point.set(a.getPositionWorldOnA().x(),a.getPositionWorldOnA().y(),a.getPositionWorldOnA().z());
- b.pointOther.set(a.getPositionWorldOnB().x(),a.getPositionWorldOnB().y(),a.getPositionWorldOnB().z());b.normal.set(a.get_m_normalWorldOnB().x(),a.get_m_normalWorldOnB().y(),a.get_m_normalWorldOnB().z());return b},_createReverseContactPointFromAmmo:function(a){var b=this.contactPointPool.allocate();b.localPointOther.set(a.get_m_localPointA().x(),a.get_m_localPointA().y(),a.get_m_localPointA().z());b.localPoint.set(a.get_m_localPointB().x(),a.get_m_localPointB().y(),a.get_m_localPointB().z());b.pointOther.set(a.getPositionWorldOnA().x(),
- a.getPositionWorldOnA().y(),a.getPositionWorldOnA().z());b.point.set(a.getPositionWorldOnB().x(),a.getPositionWorldOnB().y(),a.getPositionWorldOnB().z());b.normal.set(a.get_m_normalWorldOnB().x(),a.get_m_normalWorldOnB().y(),a.get_m_normalWorldOnB().z());return b},_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 b in a)if(a.hasOwnProperty(b)){for(var d=a[b].entity,e=d.collision,g=a[b].others,f=g.length;f--;){var k=g[f];if(!c[b]||0>c[b].others.indexOf(k))g.splice(f,1),e&&k.collision&&(d.rigidbody&&k.rigidbody?e.fire("collisionend",k):d.trigger&&e.fire("triggerleave",k))}0===g.length&&delete a[b]}},onUpdate:function(a){this.dynamicsWorld.stepSimulation(a,this.maxSubSteps,this.fixedTimeStep);var b=
- this.store,d;for(d in b)if(b.hasOwnProperty(d)){var e=b[d].entity,g=b[d].data;g.body&&g.body.isActive()&&g.enabled&&e.enabled&&(g.type===pc.BODYTYPE_DYNAMIC?e.rigidbody.syncBodyToEntity():g.type===pc.BODYTYPE_KINEMATIC&&e.rigidbody._updateKinematic(a))}a=this.dynamicsWorld.getDispatcher();var b=a.getNumManifolds(),f;c={};for(d=0;d<b;d++){var k=a.getManifoldByIndexInternal(d),l=k.getBody0(),h=k.getBody1(),e=Ammo.castObject(l,Ammo.btRigidBody),g=Ammo.castObject(h,Ammo.btRigidBody),e=e.entity,g=g.entity;
- if(e&&g){f=l.getCollisionFlags();var p=h.getCollisionFlags(),n=k.getNumContacts(),z=[],h=[],C;if(0<n)if(f&pc.BODYFLAG_NORESPONSE_OBJECT||p&pc.BODYFLAG_NORESPONSE_OBJECT)C=e.collision?e.collision.hasEvent("triggerenter")||e.collision.hasEvent("triggerleave"):!1,l=g.collision?g.collision.hasEvent("triggerenter")||g.collision.hasEvent("triggerleave"):!1,C&&(k=this._storeCollision(e,g))&&(!e.collision||p&pc.BODYFLAG_NORESPONSE_OBJECT||e.collision.fire("triggerenter",g)),l&&(k=this._storeCollision(g,e))&&
- (!g.collision||f&pc.BODYFLAG_NORESPONSE_OBJECT||g.collision.fire("triggerenter",e));else if(C=e.collision?e.collision.hasEvent("collisionstart")||e.collision.hasEvent("collisionend")||e.collision.hasEvent("contact"):!1,l=g.collision?g.collision.hasEvent("collisionstart")||g.collision.hasEvent("collisionend")||g.collision.hasEvent("contact"):!1,(p=this.hasEvent("contact"))||C||l){for(f=0;f<n;f++){var A=k.getContactPoint(f),B=this._createContactPointFromAmmo(A);if(C||l)A=this._createReverseContactPointFromAmmo(A),
- z.push(B),h.push(A);p&&(B=this._createSingleContactResult(e,g,B),this.fire("contact",B))}C&&(n=this._createContactResult(g,z),e.collision&&e.collision.fire("contact",n),(k=this._storeCollision(e,g))&&e.collision&&e.collision.fire("collisionstart",n));l&&(h=this._createContactResult(e,h),g.collision&&g.collision.fire("contact",h),(k=this._storeCollision(g,e))&&g.collision&&g.collision.fire("collisionstart",h))}}}this._cleanOldCollisions();this.contactPointPool.freeAll();this.contactResultPool.freeAll();
- this.singleContactResultPool.freeAll()}});return{RIGIDBODY_TYPE_STATIC:"static",RIGIDBODY_TYPE_DYNAMIC:"dynamic",RIGIDBODY_TYPE_KINEMATIC:"kinematic",RIGIDBODY_CF_STATIC_OBJECT:1,RIGIDBODY_CF_KINEMATIC_OBJECT:2,RIGIDBODY_CF_NORESPONSE_OBJECT:4,RIGIDBODY_ACTIVE_TAG:1,RIGIDBODY_ISLAND_SLEEPING:2,RIGIDBODY_WANTS_DEACTIVATION:3,RIGIDBODY_DISABLE_DEACTIVATION:4,RIGIDBODY_DISABLE_SIMULATION:5,RigidBodyComponentSystem:h}}());Object.assign(pc,function(){return{RigidBodyComponentData:function(){this.enabled=!0;this.mass=1;this.angularDamping=this.linearDamping=0;this.linearFactor=new pc.Vec3(1,1,1);this.angularFactor=new pc.Vec3(1,1,1);this.friction=.5;this.restitution=0;this.type=pc.BODYTYPE_STATIC;this.group=pc.BODYGROUP_STATIC;this.mask=pc.BODYMASK_NOT_STATIC;this.body=null;this.simulationEnabled=!1}}}());Object.assign(pc,function(){var f,b,a=function(a,d,e){this.entity=d.entity;this.component=d;this.app=a;"undefined"!==typeof Ammo&&(f=new Ammo.btVector3,b=new Ammo.btQuaternion);this.initialize(e)};Object.assign(a.prototype,{initialize:function(a){var c=this.entity;if((a=a.shape)&&"undefined"!==typeof Ammo){c.trigger&&c.trigger.destroy();var e=new Ammo.btVector3(0,0,0);a.calculateLocalInertia(1,e);var g=c.getPosition(),l=c.getRotation();b.setValue(l.x,l.y,l.z,l.w);l=new Ammo.btTransform;l.setIdentity();
- l.getOrigin().setValue(g.x,g.y,g.z);l.setRotation(b);g=new Ammo.btDefaultMotionState(l);a=new Ammo.btRigidBodyConstructionInfo(1,g,a,e);this.body=a=new Ammo.btRigidBody(a);a.setRestitution(0);a.setFriction(0);a.setDamping(0,0);f.setValue(0,0,0);a.setLinearFactor(f);a.setAngularFactor(f);a.setCollisionFlags(a.getCollisionFlags()|pc.BODYFLAG_NORESPONSE_OBJECT);a.entity=c;this.component.enabled&&c.enabled&&this.enable()}},destroy:function(){this.body&&this.app.systems.rigidbody.removeBody(this.body)},
- syncEntityToBody:function(){var a=this.body;if(a){var d=this.entity.getPosition(),e=this.entity.getRotation(),g=a.getWorldTransform();g.getOrigin().setValue(d.x,d.y,d.z);b.setValue(e.x,e.y,e.z,e.w);g.setRotation(b);a.activate()}},enable:function(){var a=this.body;a&&(this.app.systems.rigidbody.addBody(a,pc.BODYGROUP_TRIGGER,pc.BODYMASK_NOT_STATIC^pc.BODYGROUP_TRIGGER),a.forceActivationState(pc.BODYSTATE_ACTIVE_TAG),a.activate(),this.syncEntityToBody())},disable:function(){var a=this.body;a&&(this.app.systems.rigidbody.removeBody(a),
- a.forceActivationState(pc.BODYSTATE_DISABLE_SIMULATION))}});return{Trigger:a}}());Object.assign(pc,function(){var f=function(b,a){pc.Component.call(this,b,a);this.on("set_type",this.onSetType,this);this.on("set_halfExtents",this.onSetHalfExtents,this);this.on("set_radius",this.onSetRadius,this);this.on("set_height",this.onSetHeight,this);this.on("set_axis",this.onSetAxis,this);this.on("set_asset",this.onSetAsset,this);this.on("set_model",this.onSetModel,this)};f.prototype=Object.create(pc.Component.prototype);f.prototype.constructor=f;Object.assign(f.prototype,{onSetType:function(b,
- a,c){a!==c&&this.system.changeType(this,a,c)},onSetHalfExtents:function(b,a,c){this.data.initialized&&"box"===this.data.type&&this.system.recreatePhysicalShapes(this)},onSetRadius:function(b,a,c){!this.data.initialized||"sphere"!==this.data.type&&"capsule"!==this.data.type&&"cylinder"!==this.data.type||this.system.recreatePhysicalShapes(this)},onSetHeight:function(b,a,c){!this.data.initialized||"capsule"!==this.data.type&&"cylinder"!==this.data.type||this.system.recreatePhysicalShapes(this)},onSetAxis:function(b,
- a,c){!this.data.initialized||"capsule"!==this.data.type&&"cylinder"!==this.data.type||this.system.recreatePhysicalShapes(this)},onSetAsset:function(b,a,c){b=this.system.app.assets;a&&(a=b.get(a))&&a.off("remove",this.onAssetRemoved,this);c&&(c instanceof pc.Asset&&(this.data.asset=c.id),a=b.get(this.data.asset))&&(a.off("remove",this.onAssetRemoved,this),a.on("remove",this.onAssetRemoved,this));this.data.initialized&&"mesh"===this.data.type&&(c||(this.data.model=null),this.system.recreatePhysicalShapes(this))},
- onSetModel:function(b,a,c){this.data.initialized&&"mesh"===this.data.type&&this.system.implementations.mesh.doRecreatePhysicalShape(this)},onAssetRemoved:function(b){b.off("remove",this.onAssetRemoved,this);this.data.asset===b.id&&(this.asset=null)},onEnable:function(){if("mesh"===this.data.type&&this.data.asset&&this.data.initialized){var b=this.system.app.assets.get(this.data.asset);if(b&&(!b.resource||!this.data.shape)){this.system.recreatePhysicalShapes(this);return}}this.entity.trigger?this.entity.trigger.enable():
- this.entity.rigidbody&&this.entity.rigidbody.enabled&&this.entity.rigidbody.enableSimulation()},onDisable:function(){this.entity.trigger?this.entity.trigger.disable():this.entity.rigidbody&&this.entity.rigidbody.disableSimulation()}});return{CollisionComponent:f}}());Object.assign(pc,function(){var f="enabled type halfExtents radius axis height asset shape model".split(" "),b=function(a){this.system=a};Object.assign(b.prototype,{beforeInitialize:function(a,b){b.shape=this.createPhysicalShape(a.entity,b);b.model=new pc.Model;b.model.graph=new pc.GraphNode},afterInitialize:function(a,b){this.recreatePhysicalShapes(a);a.data.initialized=!0},reset:function(a,b){this.beforeInitialize(a,b);this.afterInitialize(a,b)},recreatePhysicalShapes:function(a){var b=a.entity,
- c=a.data;"undefined"!==typeof Ammo&&(c.shape=this.createPhysicalShape(a.entity,c),b.rigidbody?(b.rigidbody.disableSimulation(),b.rigidbody.createBody()):b.trigger?b.trigger.initialize(c):b.trigger=new pc.Trigger(this.system.app,a,c))},createPhysicalShape:function(a,b){},updateTransform:function(a,b,c,d){a.entity.trigger&&a.entity.trigger.syncEntityToBody()},remove:function(a,b){var c=this.system.app;a.rigidbody&&a.rigidbody.body&&(c.systems.rigidbody.removeBody(a.rigidbody.body),a.rigidbody.disableSimulation());
- a.trigger&&(a.trigger.destroy(),delete a.trigger);c.scene.containsModel(b.model)&&(c.root.removeChild(b.model.graph),c.scene.removeModel(b.model))},clone:function(a,b){var c=this.system.store[a.getGuid()];return this.system.addComponent(b,{enabled:c.data.enabled,type:c.data.type,halfExtents:[c.data.halfExtents.x,c.data.halfExtents.y,c.data.halfExtents.z],radius:c.data.radius,axis:c.data.axis,height:c.data.height,asset:c.data.asset,model:c.data.model})}});var a=function(a){this.system=a};a.prototype=
- Object.create(b.prototype);a.prototype.constructor=a;Object.assign(a.prototype,{createPhysicalShape:function(a,b){if("undefined"!==typeof Ammo){var c=b.halfExtents,c=new Ammo.btVector3(c?c.x:.5,c?c.y:.5,c?c.z:.5);return new Ammo.btBoxShape(c)}}});var c=function(a){this.system=a};c.prototype=Object.create(b.prototype);c.prototype.constructor=c;Object.assign(c.prototype,{createPhysicalShape:function(a,b){if("undefined"!==typeof Ammo)return new Ammo.btSphereShape(b.radius)}});var d=function(a){this.system=
- a};d.prototype=Object.create(b.prototype);d.prototype.constructor=d;Object.assign(d.prototype,{createPhysicalShape:function(a,b){var c=null,d=void 0!==b.axis?b.axis:1,e=b.radius||.5,g=Math.max((b.height||2)-2*e,0);if("undefined"!==typeof Ammo)switch(d){case 0:c=new Ammo.btCapsuleShapeX(e,g);break;case 1:c=new Ammo.btCapsuleShape(e,g);break;case 2:c=new Ammo.btCapsuleShapeZ(e,g)}return c}});var e=function(a){this.system=a};e.prototype=Object.create(b.prototype);e.prototype.constructor=e;Object.assign(e.prototype,
- {createPhysicalShape:function(a,b){var c;c=null;var d=void 0!==b.axis?b.axis:1,e=void 0!==b.radius?b.radius:.5,g=void 0!==b.height?b.height:1;if("undefined"!==typeof Ammo)switch(d){case 0:c=new Ammo.btVector3(.5*g,e,e);c=new Ammo.btCylinderShapeX(c);break;case 1:c=new Ammo.btVector3(e,.5*g,e);c=new Ammo.btCylinderShape(c);break;case 2:c=new Ammo.btVector3(e,e,.5*g),c=new Ammo.btCylinderShapeZ(c)}return c}});var g=function(a){this.system=a};g.prototype=Object.create(b.prototype);g.prototype.constructor=
- g;Object.assign(g.prototype,{beforeInitialize:function(a,b){},createPhysicalShape:function(a,b){if("undefined"!==typeof Ammo&&b.model){var c=b.model,d=new Ammo.btCompoundShape,e,g;for(e=0;e<c.meshInstances.length;e++){var f=c.meshInstances[e],k=f.mesh,l=k.indexBuffer[pc.RENDERSTYLE_SOLID],v=k.vertexBuffer,y=v.getFormat(),u=y.size/4,w;for(g=0;g<y.elements.length;g++){var x=y.elements[g];x.name===pc.SEMANTIC_POSITION&&(w=new Float32Array(v.lock(),x.offset))}var l=new Uint16Array(l.lock()),v=k.primitive[0].count/
- 3,y=new Ammo.btVector3,x=new Ammo.btVector3,D=new Ammo.btVector3,z,C,A=k.primitive[0].base,B=new Ammo.btTriangleMesh;for(g=0;g<v;g++)k=l[A+3*g]*u,z=l[A+3*g+1]*u,C=l[A+3*g+2]*u,y.setValue(w[k],w[k+1],w[k+2]),x.setValue(w[z],w[z+1],w[z+2]),D.setValue(w[C],w[C+1],w[C+2]),B.addTriangle(y,x,D,!0);g=new Ammo.btBvhTriangleMeshShape(B,!0);u=f.node.getWorldTransform().getScale();g.setLocalScaling(new Ammo.btVector3(u.x,u.y,u.z));u=f.node.getPosition();f=f.node.getRotation();l=new Ammo.btTransform;l.setIdentity();
- l.getOrigin().setValue(u.x,u.y,u.z);u=new Ammo.btQuaternion;u.setValue(f.x,f.y,f.z,f.w);l.setRotation(u);d.addChildShape(l,g)}c=a.getWorldTransform().getScale();e=new Ammo.btVector3;e.setValue(c.x,c.y,c.z);d.setLocalScaling(e);return d}},recreatePhysicalShapes:function(a){null!==a.data.asset&&a.enabled&&a.entity.enabled?this.loadModelAsset(a):this.doRecreatePhysicalShape(a)},loadModelAsset:function(a){var b=this,c=a.data.asset,d=a.data,e=this.system.app.assets,g=e.get(c);if(g)g.ready(function(c){d.model=
- c.resource;b.doRecreatePhysicalShape(a)}),e.load(g);else e.once("add:"+c,function(c){c.ready(function(c){d.model=c.resource;b.doRecreatePhysicalShape(a)});e.load(c)})},doRecreatePhysicalShape:function(a){var b=a.entity,c=a.data;c.model?(c.shape&&Ammo.destroy(c.shape),c.shape=this.createPhysicalShape(b,c),b.rigidbody?b.rigidbody.createBody():b.trigger?b.trigger.initialize(c):b.trigger=new pc.Trigger(this.system.app,a,c)):this.remove(b,c)},updateTransform:function(a,b,c,d){if(a.shape){var e=a.entity.getWorldTransform().getScale(),
- g=a.shape.getLocalScaling();e.x===g.x()&&e.y===g.y()&&e.z===g.z()||this.doRecreatePhysicalShape(a)}pc.CollisionSystemImpl.prototype.updateTransform.call(this,a,b,c,d)}});b=function(a){pc.ComponentSystem.call(this,a);this.id="collision";this.description="Specifies a collision volume.";this.ComponentType=pc.CollisionComponent;this.DataType=pc.CollisionComponentData;this.schema=f;this.implementations={};this.on("remove",this.onRemove,this);pc.ComponentSystem.bind("update",this.onUpdate,this)};b.prototype=
- Object.create(pc.ComponentSystem.prototype);b.prototype.constructor=b;pc.Component._buildAccessors(pc.CollisionComponent.prototype,f);Object.assign(b.prototype,{onLibraryLoaded:function(){"undefined"===typeof Ammo&&pc.ComponentSystem.unbind("update",this.onUpdate,this)},initializeComponentData:function(a,b,c){c="type halfExtents radius axis height shape model asset enabled".split(" ");for(var d={},e=0,g=c.length;e<g;e++){var f=c[e];d[f]=b[f]}b.hasOwnProperty("asset")?(b=c.indexOf("model"),-1!==b&&
- c.splice(b,1)):b.hasOwnProperty("model")&&(b=c.indexOf("asset"),-1!==b&&c.splice(b,1));d.type||(d.type=a.data.type);a.data.type=d.type;d.halfExtents&&"array"===pc.type(d.halfExtents)&&(d.halfExtents=new pc.Vec3(d.halfExtents[0],d.halfExtents[1],d.halfExtents[2]));b=this._createImplementation(d.type);b.beforeInitialize(a,d);pc.ComponentSystem.prototype.initializeComponentData.call(this.system,a,d,c);b.afterInitialize(a,d)},_createImplementation:function(b){if(void 0===this.implementations[b]){var f;
- switch(b){case "box":f=new a(this);break;case "sphere":f=new c(this);break;case "capsule":f=new d(this);break;case "cylinder":f=new e(this);break;case "mesh":f=new g(this)}this.implementations[b]=f}return this.implementations[b]},_getImplementation:function(a){return this.implementations[a.collision.data.type]},cloneComponent:function(a,b){return this._getImplementation(a).clone(a,b)},onRemove:function(a,b){this.implementations[b.type].remove(a,b)},onUpdate:function(a){var b,c,d=this.store;for(b in d)a=
- d[b].entity,c=d[b].data,c.enabled&&a.enabled&&!a.rigidbody&&a.trigger&&a.trigger.syncEntityToBody()},onTransformChanged:function(a,b,c,d){this.implementations[a.data.type].updateTransform(a,b,c,d)},changeType:function(a,b,c){this.implementations[b].remove(a.entity,a.data);this._createImplementation(c).reset(a,a.data)},recreatePhysicalShapes:function(a){this.implementations[a.data.type].recreatePhysicalShapes(a)}});return{CollisionComponentSystem:b}}());Object.assign(pc,function(){return{CollisionComponentData:function(){this.enabled=!0;this.type="box";this.halfExtents=new pc.Vec3(.5,.5,.5);this.radius=.5;this.axis=1;this.height=2;this.model=this.shape=this.asset=null;this.initialized=!1}}}());Object.assign(pc,function(){var f="emitterExtents emitterRadius loop initialVelocity animSpeed normalMap".split(" "),b="numParticles lifetime rate rate2 startAngle startAngle2 lighting halfLambert intensity wrap wrapBounds depthWrite noFog sort stretch alignToMotion preWarm emitterShape animTilesX animTilesY animFrames animLoop colorMap localSpace".split(" "),a="scaleGraph scaleGraph2 colorGraph colorGraph2 alphaGraph alphaGraph2 velocityGraph velocityGraph2 localVelocityGraph localVelocityGraph2 rotationSpeedGraph rotationSpeedGraph2".split(" "),
- c=["colorMapAsset","normalMapAsset","meshAsset"],d,e=function(c,d){pc.Component.call(this,c,d);this.on("set_colorMapAsset",this.onSetColorMapAsset,this);this.on("set_normalMapAsset",this.onSetNormalMapAsset,this);this.on("set_meshAsset",this.onSetMeshAsset,this);this.on("set_mesh",this.onSetMesh,this);this.on("set_loop",this.onSetLoop,this);this.on("set_blendType",this.onSetBlendType,this);this.on("set_depthSoftening",this.onSetDepthSoftening,this);this.on("set_layers",this.onSetLayers,this);f.forEach(function(a){this.on("set_"+
- a,this.onSetSimpleProperty,this)}.bind(this));b.forEach(function(a){this.on("set_"+a,this.onSetComplexProperty,this)}.bind(this));a.forEach(function(a){this.on("set_"+a,this.onSetGraphProperty,this)}.bind(this));this._requestedDepth=!1};e.prototype=Object.create(pc.Component.prototype);e.prototype.constructor=e;Object.assign(e.prototype,{addModelToLayers:function(){if(this.data.model)for(var a,b=0;b<this.layers.length;b++)if(a=this.system.app.scene.layers.getLayerById(this.layers[b]))a.addMeshInstances(this.data.model.meshInstances),
- this.emitter._layer=a},removeModelFromLayers:function(a){if(this.data.model)for(var b=0;b<this.layers.length;b++)(a=this.system.app.scene.layers.getLayerById(this.layers[b]))&&a.removeMeshInstances(this.data.model.meshInstances)},onSetLayers:function(a,b,c){if(this.data.model){var d;for(a=0;a<b.length;a++)(d=this.system.app.scene.layers.getLayerById(b[a]))&&d.removeMeshInstances(this.data.model.meshInstances);if(this.enabled&&this.entity.enabled)for(a=0;a<c.length;a++)(d=this.system.app.scene.layers.getLayerById(c[a]))&&
- d.addMeshInstances(this.data.model.meshInstances)}},onLayersChanged:function(a,b){this.addModelToLayers();a.off("add",this.onLayerAdded,this);a.off("remove",this.onLayerRemoved,this);b.on("add",this.onLayerAdded,this);b.on("remove",this.onLayerRemoved,this)},onLayerAdded:function(a){this.data.model&&(0>this.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.once("remove",this._onColorMapRemoved,this);a.resource?this.colorMap=a.resource:(a.once("load",this._onColorMapLoad,this),this.enabled&&this.entity.enabled&&this.system.app.assets.load(a))},_unbindColorMapAsset:function(a){a.off("remove",this._onColorMapRemoved,this);a.off("load",this._onColorMapLoad,this)},_onColorMapLoad:function(a){this.colorMap=a.resource},_onColorMapRemoved:function(a){this.colorMapAsset=null},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 pc.Asset&&(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.once("remove",this._onNormalMapRemoved,this);a.resource?this.normalMap=a.resource:(a.once("load",this._onNormalMapLoad,this),this.enabled&&this.entity.enabled&&this.system.app.assets.load(a))},_unbindNormalMapAsset:function(a){a.off("remove",
- this._onNormalMapRemoved,this);a.off("load",this._onNormalMapLoad,this)},_onNormalMapLoad:function(a){this.normalMap=a.resource},_onNormalMapRemoved:function(a){this.normalMapAsset=null},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 pc.Asset&&(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("remove",
- this._onMeshAssetRemoved,this);a.on("load",this._onMeshAssetLoad,this)},_unbindMeshAsset:function(a){a.off("remove",this._onMeshAssetRemoved,this);a.off("load",this._onMeshAssetLoad,this)},_onMeshAssetLoad:function(a){this._onMeshChanged(a.resource)},onSetMeshAsset:function(a,b,c){a=this.system.app.assets;b&&(b=a.get(b))&&this._unbindMeshAsset(b);if(c){if(c instanceof pc.Asset&&(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 pc.Asset||"number"===typeof c?this.meshAsset=c:this._onMeshChanged(c)},_onMeshChanged:function(a){!a||a instanceof pc.Mesh||(a=a.meshInstances[0]?a.meshInstances[0].mesh:null);this.data.mesh=a;this.emitter&&(this.emitter.mesh=a,this.emitter.resetMaterial(),this.rebuild())},onMeshAssetRemoved:function(a){a.off("remove",this.onMeshAssetRemoved,this);this.mesh=null},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||(d||(d=this.system.app.scene.layers.getLayerById(pc.LAYERID_DEPTH)),d&&(d.incrementCounter(),this._requestedDepth=!0))},_releaseDepth:function(){this._requestedDepth&&d&&(d.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.reset(),this.emitter.resetMaterial(),this.rebuild())},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,d=c.length;b<d;b++){var e=a[c[b]];if(e){if(!(e instanceof pc.Asset))if(0<=parseInt(e,10))e=this.system.app.assets.get(e);else continue;e&&!e.resource&&this.system.app.assets.load(e)}}this.emitter||(b=a.mesh,b instanceof pc.Mesh||(b=null),this.emitter=new pc.ParticleEmitter(this.system.app.graphicsDevice,{numParticles:a.numParticles,emitterExtents:a.emitterExtents,emitterRadius:a.emitterRadius,emitterShape:a.emitterShape,initialVelocity:a.initialVelocity,wrap:a.wrap,localSpace:a.localSpace,
- wrapBounds:a.wrapBounds,lifetime:a.lifetime,rate:a.rate,rate2:a.rate2,animTilesX:a.animTilesX,animTilesY:a.animTilesY,animNumFrames:a.animNumFrames,animSpeed:a.animSpeed,animLoop:a.animLoop,startAngle:a.startAngle,startAngle2:a.startAngle2,scaleGraph:a.scaleGraph,scaleGraph2:a.scaleGraph2,colorGraph:a.colorGraph,colorGraph2:a.colorGraph2,alphaGraph:a.alphaGraph,alphaGraph2:a.alphaGraph2,localVelocityGraph:a.localVelocityGraph,localVelocityGraph2:a.localVelocityGraph2,velocityGraph:a.velocityGraph,
- velocityGraph2:a.velocityGraph2,rotationSpeedGraph:a.rotationSpeedGraph,rotationSpeedGraph2:a.rotationSpeedGraph2,colorMap:a.colorMap,normalMap:a.normalMap,loop:a.loop,preWarm:a.preWarm,sort:a.sort,stretch:a.stretch,alignToMotion:a.alignToMotion,lighting:a.lighting,halfLambert:a.halfLambert,intensity:a.intensity,depthSoftening:a.depthSoftening,scene:this.system.app.scene,mesh:b,depthWrite:a.depthWrite,noFog:a.noFog,node:this.entity,blendType:a.blendType}),this.emitter.meshInstance.node=this.entity,
- this.psys=new pc.Model,this.psys.graph=this.entity,this.psys.emitter=this.emitter,this.psys.meshInstances=[this.emitter.meshInstance],a.model=this.psys,this.emitter.psys=this.psys,a.autoPlay||(this.pause(),this.emitter.meshInstance.visible=!1));a.model&&this.emitter.colorMap&&this.addModelToLayers();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&&a.depthSoftening&&this._requestDepth()},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));this.data.model&&(this.removeModelFromLayers(),this.data.depthSoftening&&this._releaseDepth());this.emitter&&(this.emitter.camera=null)},reset:function(){this.emitter&&this.emitter.reset()},
- stop:function(){this.emitter&&(this.emitter.loop=!1,this.emitter.resetTime(),this.emitter.addTime(0,!0))},pause:function(){this.data.paused=!0},unpause:function(){this.data.paused=!1},play:function(){this.data.paused=!1;this.emitter&&(this.emitter.meshInstance.visible=!0,this.emitter.loop=this.data.loop,this.emitter.resetTime())},isPlaying:function(){return this.data.paused?!1:this.emitter&&this.emitter.loop?!0:Date.now()<=this.emitter.endTime},rebuild:function(){var a=this.enabled;this.enabled=!1;
- this.emitter&&(this.emitter.rebuild(),this.emitter.meshInstance.node=this.entity,this.data.model.meshInstances=[this.emitter.meshInstance]);this.enabled=a},onRemove:function(){var a=this.data;a.model&&(this.entity.removeChild(a.model.getGraph()),a.model.destroy(),a.model=null);this.emitter&&(this.emitter.destroy(),this.emitter=null);for(var b=0;b<c.length;b++){var d=c[b];a[d]&&(this[d]=null)}this.off()}});return{ParticleSystemComponent:e}}());Object.assign(pc,function(){var f="enabled autoPlay numParticles lifetime rate rate2 startAngle startAngle2 loop preWarm lighting halfLambert intensity depthWrite noFog depthSoftening sort blendType stretch alignToMotion emitterShape emitterExtents emitterRadius initialVelocity wrap wrapBounds localSpace colorMapAsset normalMapAsset mesh meshAsset localVelocityGraph localVelocityGraph2 velocityGraph velocityGraph2 rotationSpeedGraph rotationSpeedGraph2 scaleGraph scaleGraph2 colorGraph colorGraph2 alphaGraph alphaGraph2 colorMap normalMap animTilesX animTilesY animNumFrames animSpeed animLoop layers".split(" "),
- b=function(a){pc.ComponentSystem.call(this,a);this.id="particlesystem";this.description="Updates and renders particle system in the scene.";this.ComponentType=pc.ParticleSystemComponent;this.DataType=pc.ParticleSystemComponentData;this.schema=f;this.propertyTypes={emitterExtents:"vec3",wrapBounds:"vec3",localVelocityGraph:"curveset",localVelocityGraph2:"curveset",velocityGraph:"curveset",velocityGraph2:"curveset",colorGraph:"curveset",colorGraph2:"curveset",alphaGraph:"curve",alphaGraph2:"curve",
- rotationSpeedGraph:"curve",rotationSpeedGraph2:"curve",scaleGraph:"curve",scaleGraph2:"curve"};this.on("beforeremove",this.onRemove,this);pc.ComponentSystem.bind("update",this.onUpdate,this)};b.prototype=Object.create(pc.ComponentSystem.prototype);b.prototype.constructor=b;pc.Component._buildAccessors(pc.ParticleSystemComponent.prototype,f);Object.assign(b.prototype,{initializeComponentData:function(a,b,d){var c={};d=[];var f=this.propertyTypes,l;if(b.mesh instanceof pc.Asset||"number"===typeof b.mesh)b.meshAsset=
- b.mesh,delete b.mesh;for(var k in b)b.hasOwnProperty(k)&&(d.push(k),c[k]=b[k]),"vec3"===f[k]?"array"===pc.type(c[k])&&(c[k]=new pc.Vec3(c[k][0],c[k][1],c[k][2])):"curve"===f[k]?c[k]instanceof pc.Curve||(l=c[k].type,c[k]=new pc.Curve(c[k].keys),c[k].type=l):"curveset"!==f[k]||c[k]instanceof pc.CurveSet||(l=c[k].type,c[k]=new pc.CurveSet(c[k].keys),c[k].type=l),c.layers&&"array"===pc.type(c.layers)&&(c.layers=c.layers.slice(0));pc.ComponentSystem.prototype.initializeComponentData.call(this,a,c,d)},
- cloneComponent:function(a,b){for(var c=a.particlesystem.data,e=this.schema,f={},l=0,k=e.length;l<k;l++){var p=e[l],h=c[p];h instanceof pc.Vec3||h instanceof pc.Curve||h instanceof pc.CurveSet?(h=h.clone(),f[p]=h):"layers"===p?f.layers=c.layers.slice(0):null!==h&&void 0!==h&&(f[p]=h)}return this.addComponent(b,f)},onUpdate:function(a){var b=this.store,d,e,f,l,k=this.app.stats.particles,p;for(p in b)if(b.hasOwnProperty(p)&&(l=b[p],e=l.entity,d=l.data,d.enabled&&e.enabled)){var h=d.model.emitter;if(h.meshInstance.visible){if(h.lighting){var n,
- q=d.layers;for(e=0;e<q.length;e++)if(l=this.app.scene.layers.getLayerById(q[e])){l._lightCube||(l._lightCube=new Float32Array(18));n=l._lightCube;for(e=0;6>e;e++)n[3*e]=this.app.scene.ambientLight.r,n[3*e+1]=this.app.scene.ambientLight.g,n[3*e+2]=this.app.scene.ambientLight.b;var m=l._sortedLights[pc.LIGHTTYPE_DIRECTIONAL];for(f=0;f<m.length;f++)for(l=0;6>l;l++){var r=Math.max(h.lightCubeDir[l].dot(m[f]._direction),0)*m[f]._intensity;n[3*l]+=m[f]._color.r*r;n[3*l+1]+=m[f]._color.g*r;n[3*l+2]+=m[f]._color.b*
- r}}h.constantLightCube.setValue(n)}if(!d.paused){h.simTime+=a;d=0;h.simTime>h.fixedTimeStep&&(d=Math.floor(h.simTime/h.fixedTimeStep),h.simTime-=d*h.fixedTimeStep);if(d){d=Math.min(d,h.maxSubSteps);for(e=0;e<d;e++)h.addTime(h.fixedTimeStep);k._updatesPerFrame+=d;k._frameTime+=h._addTimeTime;h._addTimeTime=0}h.finishFrame()}}}},onRemove:function(a,b){b.onRemove()}});return{ParticleSystemComponentSystem:b}}());Object.assign(pc,function(){return{ParticleSystemComponentData:function(){this.rate=this.numParticles=1;this.rate2=null;this.startAngle=0;this.startAngle2=null;this.lifetime=50;this.emitterExtents=new pc.Vec3;this.emitterRadius=0;this.emitterShape=pc.EMITTERSHAPE_BOX;this.initialVelocity=0;this.wrapBounds=new pc.Vec3;this.localSpace=!1;this.normalMapAsset=this.normalMap=this.colorMapAsset=this.colorMap=null;this.loop=!0;this.preWarm=!1;this.sort=0;this.mode=pc.PARTICLEMODE_GPU;this.scene=null;this.halfLambert=
- this.lighting=!1;this.intensity=1;this.stretch=0;this.alignToMotion=!1;this.depthSoftening=0;this.mesh=this.meshAsset=null;this.noFog=this.depthWrite=!1;this.animSpeed=this.animNumFrames=this.animTilesY=this.animTilesX=1;this.animLoop=!0;this.rotationSpeedGraph2=this.rotationSpeedGraph=this.velocityGraph2=this.velocityGraph=this.localVelocityGraph2=this.localVelocityGraph=this.alphaGraph2=this.alphaGraph=this.colorGraph2=this.colorGraph=this.scaleGraph2=this.scaleGraph=null;this.blendType=pc.BLEND_NORMAL;
- this.model=null;this.enabled=!0;this.paused=!1;this.autoPlay=!0;this.layers=[pc.LAYERID_WORLD]}}}());Object.assign(pc,function(){var f=function(b,a){this._component=b;this._frame=0;this._spriteAsset=this._sprite=null;this.spriteAsset=a.spriteAsset;this.name=a.name;this.fps=a.fps||0;this.loop=a.loop||!1;this._paused=this._playing=!1;this._time=0;pc.events.attach(this)};Object.assign(f.prototype,{_onSpriteAssetAdded:function(b){this._component.system.app.assets.off("add:"+b.id,this._onSpriteAssetAdded,this);this._spriteAsset===b.id&&this._bindSpriteAsset(b)},_bindSpriteAsset:function(b){b.on("load",
- this._onSpriteAssetLoad,this);b.on("remove",this._onSpriteAssetRemove,this);b.resource?this._onSpriteAssetLoad(b):this._component.system.app.assets.load(b)},_unbindSpriteAsset:function(b){b.off("load",this._onSpriteAssetLoad,this);b.off("remove",this._onSpriteAssetRemove,this);b.resource&&b.resource.atlas&&this._component.system.app.assets.off("load:"+b.data.textureAtlasAsset,this._onTextureAtlasLoad,this)},_onSpriteAssetLoad:function(b){if(b.resource)if(b.resource.atlas)this.sprite=b.resource;else{b=
- b.data.textureAtlasAsset;var a=this._component.system.app.assets;a.off("load:"+b,this._onTextureAtlasLoad,this);a.once("load:"+b,this._onTextureAtlasLoad,this)}else this.sprite=null},_onTextureAtlasLoad:function(b){b=this._spriteAsset;b instanceof pc.Asset?this._onSpriteAssetLoad(b):this._onSpriteAssetLoad(this._component.system.app.assets.get(b))},_onSpriteAssetRemove:function(b){this.sprite=null},_onSpriteMeshesChange:function(){this._component.currentClip===this&&this._component._showFrame(this.frame)},
- _onSpritePpuChanged:function(){this._component.currentClip===this&&this.sprite.renderMode!==pc.SPRITE_RENDERMODE_SIMPLE&&this._component._showFrame(this.frame)},_update:function(b){if(0!==this.fps&&this._playing&&!this._paused&&this._sprite){var a=this._time+b*this._component.speed*(0>this.fps?-1:1),c=this.duration;b=a>c||0>a;this._setTime(a);a=this._sprite?Math.floor(this._sprite.frameKeys.length*this._time/c):0;a!==this._frame&&this._setFrame(a);b&&(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(b){this._time=b;b=this.duration;0>this._time?this._time=this.loop?this._time%b+b:0:this._time>b&&(this._time=this.loop?this._time%b:b)},_setFrame:function(b){this._frame=this._sprite?pc.math.clamp(b,0,this._sprite.frameKeys.length-1):b;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(f.prototype,"spriteAsset",{get:function(){return this._spriteAsset},set:function(b){var a=this._component.system.app.assets,c=b;b instanceof pc.Asset&&(c=b.id);this._spriteAsset!==c&&(this._spriteAsset&&(b=a.get(this._spriteAsset))&&this._unbindSpriteAsset(b),(this._spriteAsset=c)?(c=a.get(this._spriteAsset))?this._bindSpriteAsset(c):(this.sprite=null,a.on("add:"+this._spriteAsset,this._onSpriteAssetAdded,this)):this.sprite=null)}});Object.defineProperty(f.prototype,"sprite",
- {get:function(){return this._sprite},set:function(b){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=b)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 a;if(b&&b.atlas){if(b.atlas.texture){if(a=this._component._meshInstance)a.setParameter("texture_emissiveMap",b.atlas.texture),a.setParameter("texture_opacityMap",b.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(a=this._component._meshInstance)a.deleteParameter("texture_emissiveMap"),a.deleteParameter("texture_opacityMap");this._component._hideModel()}}}});Object.defineProperty(f.prototype,"frame",{get:function(){return this._frame},set:function(b){this._setFrame(b);this._setTime(this._frame/(this.fps||Number.MIN_VALUE))}});Object.defineProperty(f.prototype,"isPlaying",{get:function(){return this._playing}});Object.defineProperty(f.prototype,"isPaused",{get:function(){return this._paused}});
- Object.defineProperty(f.prototype,"duration",{get:function(){return this._sprite?this._sprite.frameKeys.length/Math.abs(this.fps||Number.MIN_VALUE):0}});Object.defineProperty(f.prototype,"time",{get:function(){return this._time},set:function(b){this._setTime(b);this.frame=this._sprite?Math.min(this._sprite.frameKeys.length-1,Math.floor(this._time*Math.abs(this.fps))):0}});return{SpriteAnimationClip:f}}());Object.assign(pc,function(){pc.SPRITETYPE_SIMPLE="simple";pc.SPRITETYPE_ANIMATED="animated";var f=function(b,a){pc.Component.call(this,b,a);this._type=pc.SPRITETYPE_SIMPLE;this._material=b.defaultMaterial;this._color=new pc.Color(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=[pc.LAYERID_WORLD];this._outerScale=new pc.Vec2(1,1);this._outerScaleUniform=new Float32Array(2);this._innerOffset=new pc.Vec4;
- this._innerOffsetUniform=new Float32Array(4);this._atlasRect=new pc.Vec4;this._atlasRectUniform=new Float32Array(4);this._batchGroupId=-1;this._batchGroup=null;this._node=new pc.GraphNode;this._model=new pc.Model;this._model.graph=this._node;this._meshInstance=null;a.addChild(this._model.graph);this._model._entity=a;this._updateAabbFunc=this._updateAabb.bind(this);this._addedModel=!1;this._autoPlayClip=null;this._clips={};this._currentClip=this._defaultClip=new pc.SpriteAnimationClip(this,{name:this.entity.name,
- fps:0,loop:!1,spriteAsset:null})};f.prototype=Object.create(pc.Component.prototype);f.prototype.constructor=f;Object.assign(f.prototype,{onEnable:function(){var b=this.system.app.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()},onDisable:function(){var b=this.system.app,a=b.scene;a.off("set:layers",this._onLayersChanged,this);a.layers&&
- (a.layers.off("add",this._onLayerAdded,this),a.layers.off("remove",this._onLayerRemoved,this));this.stop();this._hideModel();0<=this._batchGroupId&&b.batcher.markGroupDirty(this.batchGroupId)},onDestroy:function(){this._currentClip=null;this._defaultClip&&(this._defaultClip._destroy(),this._defaultClip=null);for(var b in this._clips)this._clips[b]._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 b,a,c=[this._meshInstance];b=0;for(a=this._layers.length;b<a;b++){var d=this.system.app.scene.layers.getLayerById(this._layers[b]);d&&d.addMeshInstances(c)}this._addedModel=!0}},_hideModel:function(){if(this._addedModel&&this._meshInstance){var b,a,c=[this._meshInstance];b=0;for(a=this._layers.length;b<a;b++){var d=this.system.app.scene.layers.getLayerById(this._layers[b]);
- d&&d.removeMeshInstances(c)}this._addedModel=!1}},_showFrame:function(b){if(this.sprite){var a=this.sprite.meshes[b];if(a){var c=this.system.defaultMaterial;this.sprite.renderMode===pc.SPRITE_RENDERMODE_SLICED?c=this.system.default9SlicedMaterialSlicedMode:this.sprite.renderMode===pc.SPRITE_RENDERMODE_TILED&&(c=this.system.default9SlicedMaterialTiledMode);this._meshInstance||(this._meshInstance=new pc.MeshInstance(this._node,a,this._material),this._meshInstance.castShadow=!1,this._meshInstance.receiveShadow=
- !1,this._meshInstance.drawOrder=this._drawOrder,this._model.meshInstances.push(this._meshInstance),this._colorUniform[0]=this._color.r,this._colorUniform[1]=this._color.g,this._colorUniform[2]=this._color.b,this._meshInstance.setParameter("material_emissive",this._colorUniform),this._meshInstance.setParameter("material_opacity",this._color.a),this.enabled&&this.entity.enabled&&this._showModel());this._meshInstance.material!==c&&(this._meshInstance.material=c);this._meshInstance.mesh!==a&&(this._meshInstance.mesh=
- a,this._meshInstance.visible=!0,this._meshInstance._aabbVer=-1);this.sprite.atlas&&this.sprite.atlas.texture?(this._meshInstance.setParameter("texture_emissiveMap",this.sprite.atlas.texture),this._meshInstance.setParameter("texture_opacityMap",this.sprite.atlas.texture)):(this._meshInstance.deleteParameter("texture_emissiveMap"),this._meshInstance.deleteParameter("texture_opacityMap"));!this.sprite.atlas||this.sprite.renderMode!==pc.SPRITE_RENDERMODE_SLICED&&this.sprite.renderMode!==pc.SPRITE_RENDERMODE_TILED?
- this._meshInstance._updateAabbFunc=null:(this._meshInstance._updateAabbFunc=this._updateAabbFunc,(b=this.sprite.atlas.frames[this.sprite.frameKeys[b]])?(a=2/b.rect.z,c=2/b.rect.w,this._innerOffset.set(b.border.x*a,b.border.y*c,b.border.z*a,b.border.w*c),a=this.sprite.atlas.texture,this._atlasRect.set(b.rect.x/a.width,b.rect.y/a.height,b.rect.z/a.width,b.rect.w/a.height)):this._innerOffset.set(0,0,0,0),this._innerOffsetUniform[0]=this._innerOffset.x,this._innerOffsetUniform[1]=this._innerOffset.y,
- this._innerOffsetUniform[2]=this._innerOffset.z,this._innerOffsetUniform[3]=this._innerOffset.w,this._meshInstance.setParameter("innerOffset",this._innerOffsetUniform),this._atlasRectUniform[0]=this._atlasRect.x,this._atlasRectUniform[1]=this._atlasRect.y,this._atlasRectUniform[2]=this._atlasRect.z,this._atlasRectUniform[3]=this._atlasRect.w,this._meshInstance.setParameter("atlasRect",this._atlasRectUniform));this._updateTransform()}else this._meshInstance&&(this._meshInstance.mesh=null,this._meshInstance.visible=
- !1)}},_updateTransform:function(){var b=this.flipX?-1:1,a=this.flipY?-1:1,c=0,d=0;if(this.sprite&&(this.sprite.renderMode===pc.SPRITE_RENDERMODE_SLICED||this.sprite.renderMode===pc.SPRITE_RENDERMODE_TILED)){var e=1,f=1;if(this.sprite.atlas){var l=this.sprite.atlas.frames[this.sprite.frameKeys[this.frame]];l&&(e=l.rect.z,f=l.rect.w,c=(.5-l.pivot.x)*this._width,d=(.5-l.pivot.y)*this._height)}e/=this.sprite.pixelsPerUnit;f/=this.sprite.pixelsPerUnit;this._outerScale.set(Math.max(this._width,this._innerOffset.x*
- e),Math.max(this._height,this._innerOffset.y*f));a*=f;this._outerScale.x/=e;this._outerScale.y/=f;b=b*e*pc.math.clamp(this._width/(this._innerOffset.x*e),1E-4,1);a*=pc.math.clamp(this._height/(this._innerOffset.y*f),1E-4,1);this._meshInstance&&(this._outerScaleUniform[0]=this._outerScale.x,this._outerScaleUniform[1]=this._outerScale.y,this._meshInstance.setParameter("outerScale",this._outerScaleUniform,4294967295))}this._node.setLocalScale(b,a,1);this._node.setLocalPosition(c,d,0)},_updateAabb:function(b){b.center.set(0,
- 0,0);b.halfExtents.set(.5*this._outerScale.x,.5*this._outerScale.y,.001);b.setFromTransformedAabb(b,this._node.getWorldTransform());return b},_tryAutoPlay:function(){if(this._autoPlayClip&&this.type===pc.SPRITETYPE_ANIMATED){var b=this._clips[this._autoPlayClip];!b||b.isPlaying||this._currentClip&&this._currentClip.isPlaying||this.enabled&&this.entity.enabled&&this.play(b.name)}},_onLayersChanged:function(b,a){b.off("add",this.onLayerAdded,this);b.off("remove",this.onLayerRemoved,this);a.on("add",
- this.onLayerAdded,this);a.on("remove",this.onLayerRemoved,this);this.enabled&&this.entity.enabled&&this._showModel()},_onLayerAdded:function(b){0>this.layers.indexOf(b.id)||this._addedModel&&this.enabled&&this.entity.enabled&&this._meshInstance&&b.addMeshInstances([this._meshInstance])},_onLayerRemoved:function(b){this._meshInstance&&(0>this.layers.indexOf(b.id)||b.removeMeshInstances([this._meshInstance]))},addClip:function(b){var a=new pc.SpriteAnimationClip(this,{name:b.name,fps:b.fps,loop:b.loop,
- spriteAsset:b.spriteAsset});this._clips[b.name]=a;a.name&&a.name===this._autoPlayClip&&this._tryAutoPlay();return a},removeClip:function(b){delete this._clips[b]},clip:function(b){return this._clips[b]},play:function(b){var a=this._clips[b],c=this._currentClip;c&&c!==a&&(c._playing=!1);(this._currentClip=a)?(this._currentClip=a,this._currentClip.play()):logWARNING("Trying to play sprite animation "+b+" which does not exist.");return a},pause:function(){this._currentClip!==this._defaultClip&&this._currentClip.isPlaying&&
- this._currentClip.pause()},resume:function(){this._currentClip!==this._defaultClip&&this._currentClip.isPaused&&this._currentClip.resume()},stop:function(){this._currentClip!==this._defaultClip&&this._currentClip.stop()}});Object.defineProperty(f.prototype,"type",{get:function(){return this._type},set:function(b){this._type!==b&&(this._type=b,this._type===pc.SPRITETYPE_SIMPLE?(this.stop(),this._currentClip=this._defaultClip,this.enabled&&this.entity.enabled&&(this._currentClip.frame=this.frame,this._currentClip.sprite?
- this._showModel():this._hideModel())):this._type===pc.SPRITETYPE_ANIMATED&&(this.stop(),this._autoPlayClip&&this._tryAutoPlay(),this._currentClip&&this._currentClip.isPlaying&&this.enabled&&this.entity.enabled?this._showModel():this._hideModel()))}});Object.defineProperty(f.prototype,"frame",{get:function(){return this._currentClip.frame},set:function(b){this._currentClip.frame=b}});Object.defineProperty(f.prototype,"spriteAsset",{get:function(){return this._defaultClip._spriteAsset},set:function(b){this._defaultClip.spriteAsset=
- b}});Object.defineProperty(f.prototype,"sprite",{get:function(){return this._currentClip.sprite},set:function(b){this._currentClip.sprite=b}});Object.defineProperty(f.prototype,"material",{get:function(){return this._material},set:function(b){this._material=b;this._meshInstance&&(this._meshInstance.material=b)}});Object.defineProperty(f.prototype,"color",{get:function(){return this._color},set:function(b){this._color.r=b.r;this._color.g=b.g;this._color.b=b.b;this._meshInstance&&(this._colorUniform[0]=
- this._color.r,this._colorUniform[1]=this._color.g,this._colorUniform[2]=this._color.b,this._meshInstance.setParameter("material_emissive",this._colorUniform))}});Object.defineProperty(f.prototype,"opacity",{get:function(){return this._color.a},set:function(b){this._color.a=b;this._meshInstance&&this._meshInstance.setParameter("material_opacity",b)}});Object.defineProperty(f.prototype,"clips",{get:function(){return this._clips},set:function(b){var a,c;if(b){for(a in this._clips){var d=!1;for(c in b)if(b[c].name===
- a){d=!0;this._clips[a].fps=b[c].fps;this._clips[a].loop=b[c].loop;b[c].hasOwnProperty("sprite")?this._clips[a].sprite=b[c].sprite:b[c].hasOwnProperty("spriteAsset")&&(this._clips[a].spriteAsset=b[c].spriteAsset);break}d||this.removeClip(a)}for(c in b)this._clips[b[c].name]||this.addClip(b[c]);this._autoPlayClip&&this._tryAutoPlay();this._currentClip&&this._currentClip.sprite||this._hideModel()}else for(a in this._clips)this.removeClip(a)}});Object.defineProperty(f.prototype,"currentClip",{get:function(){return this._currentClip}});
- Object.defineProperty(f.prototype,"speed",{get:function(){return this._speed},set:function(b){this._speed=b}});Object.defineProperty(f.prototype,"flipX",{get:function(){return this._flipX},set:function(b){this._flipX!==b&&(this._flipX=b,this._updateTransform())}});Object.defineProperty(f.prototype,"flipY",{get:function(){return this._flipY},set:function(b){this._flipY!==b&&(this._flipY=b,this._updateTransform())}});Object.defineProperty(f.prototype,"width",{get:function(){return this._width},set:function(b){b!==
- this._width&&(this._width=b,this._outerScale.x=this._width,!this.sprite||this.sprite.renderMode!==pc.SPRITE_RENDERMODE_TILED&&this.sprite.renderMode!==pc.SPRITE_RENDERMODE_SLICED||this._updateTransform())}});Object.defineProperty(f.prototype,"height",{get:function(){return this._height},set:function(b){b!==this._height&&(this._height=b,this._outerScale.y=this.height,!this.sprite||this.sprite.renderMode!==pc.SPRITE_RENDERMODE_TILED&&this.sprite.renderMode!==pc.SPRITE_RENDERMODE_SLICED||this._updateTransform())}});
- Object.defineProperty(f.prototype,"batchGroupId",{get:function(){return this._batchGroupId},set:function(b){if(this._batchGroupId!==b){var a=this._batchGroupId;this._batchGroupId=b;0<=a&&this.system.app.batcher.markGroupDirty(a);0<=this._batchGroupId?this.system.app.batcher.markGroupDirty(this._batchGroupId):0<=a&&this._currentClip&&this._currentClip.sprite&&this.enabled&&this.entity.enabled&&this._showModel()}}});Object.defineProperty(f.prototype,"autoPlayClip",{get:function(){return this._autoPlayClip},
- set:function(b){this._autoPlayClip=b instanceof pc.SpriteAnimationClip?b.name:b;this._tryAutoPlay()}});Object.defineProperty(f.prototype,"drawOrder",{get:function(){return this._drawOrder},set:function(b){this._drawOrder=b;this._meshInstance&&(this._meshInstance.drawOrder=b)}});Object.defineProperty(f.prototype,"layers",{get:function(){return this._layers},set:function(b){this._addedModel&&this._hideModel();this._layers=b;this._meshInstance&&this.enabled&&this.entity.enabled&&this._showModel()}});
- Object.defineProperty(f.prototype,"aabb",{get:function(){return this._meshInstance?this._meshInstance.aabb:null}});return{SpriteComponent:f}}());Object.assign(pc,function(){var f=["enabled"],b=function(a){pc.ComponentSystem.call(this,a);this.id="sprite";this.app=a;this.ComponentType=pc.SpriteComponent;this.DataType=pc.SpriteComponentData;this.schema=f;this._defaultTexture=new pc.Texture(a.graphicsDevice,{width:1,height:1,format:pc.PIXELFORMAT_R8_G8_B8_A8});a=this._defaultTexture.lock();var b=new Uint8Array(4);b[0]=255;b[1]=255;b[2]=255;b[3]=255;a.set(b);this._defaultTexture.name="sprite";this._defaultTexture.unlock();this.defaultMaterial=
- new pc.StandardMaterial;this.defaultMaterial.diffuse=new pc.Color(0,0,0,1);this.defaultMaterial.emissive=new pc.Color(.5,.5,.5,1);this.defaultMaterial.emissiveMap=this._defaultTexture;this.defaultMaterial.emissiveMapTint=!0;this.defaultMaterial.opacityMap=this._defaultTexture;this.defaultMaterial.opacityMapChannel="a";this.defaultMaterial.opacityTint=!0;this.defaultMaterial.opacity=0;this.defaultMaterial.useLighting=!1;this.defaultMaterial.useGammaTonemap=!1;this.defaultMaterial.useFog=!1;this.defaultMaterial.useSkybox=
- !1;this.defaultMaterial.blendType=pc.BLEND_PREMULTIPLIED;this.defaultMaterial.depthWrite=!1;this.defaultMaterial.pixelSnap=!1;this.defaultMaterial.cull=pc.CULLFACE_NONE;this.defaultMaterial.update();this.default9SlicedMaterialSlicedMode=this.defaultMaterial.clone();this.default9SlicedMaterialSlicedMode.nineSlicedMode=pc.SPRITE_RENDERMODE_SLICED;this.default9SlicedMaterialSlicedMode.update();this.default9SlicedMaterialTiledMode=this.defaultMaterial.clone();this.default9SlicedMaterialTiledMode.nineSlicedMode=
- pc.SPRITE_RENDERMODE_TILED;this.default9SlicedMaterialTiledMode.update();pc.ComponentSystem.bind("update",this.onUpdate,this);this.on("beforeremove",this.onBeforeRemove,this)};b.prototype=Object.create(pc.ComponentSystem.prototype);b.prototype.constructor=b;pc.Component._buildAccessors(pc.SpriteComponent.prototype,f);Object.assign(b.prototype,{destroy:function(){this._defaultTexture.destroy();this._defaultTexture=null},initializeComponentData:function(a,b,d){void 0!==b.enabled&&(a.enabled=b.enabled);
- a.type=b.type;b.layers&&"array"===pc.type(b.layers)&&(a.layers=b.layers.slice(0));void 0!==b.drawOrder&&(a.drawOrder=b.drawOrder);void 0!==b.color&&(b.color instanceof pc.Color?a.color.set(b.color.r,b.color.g,b.color.b,void 0!==b.opacity?b.opacity:1):a.color.set(b.color[0],b.color[1],b.color[2],void 0!==b.opacity?b.opacity:1),a.color=a.color);void 0!==b.opacity&&(a.opacity=b.opacity);void 0!==b.flipX&&(a.flipX=b.flipX);void 0!==b.flipY&&(a.flipY=b.flipY);void 0!==b.width&&(a.width=b.width);void 0!==
- b.height&&(a.height=b.height);void 0!==b.spriteAsset&&(a.spriteAsset=b.spriteAsset);b.sprite&&(a.sprite=b.sprite);void 0!==b.frame&&(a.frame=b.frame);if(b.clips)for(var c in b.clips)a.addClip(b.clips[c]);void 0!==b.speed&&(a.speed=b.speed);b.autoPlayClip&&(a.autoPlayClip=b.autoPlayClip);a.batchGroupId=void 0===b.batchGroupId||null===b.batchGroupId?-1:b.batchGroupId;pc.ComponentSystem.prototype.initializeComponentData.call(this,a,b,d)},cloneComponent:function(a,b){var c=a.sprite;return this.addComponent(b,
- {enabled:c.enabled,type:c.type,spriteAsset:c.spriteAsset,sprite:c.sprite,frame:c.frame,color:c.color.clone(),opacity:c.opacity,flipX:c.flipX,flipY:c.flipY,speed:c.speed,clips:c.clips,autoPlayClip:c.autoPlayClip,batchGroupId:c.batchGroupId,drawOrder:c.drawOrder,layers:c.layers.slice(0)})},onUpdate:function(a){var b=this.store,d;for(d in b)if(b.hasOwnProperty(d)){var e=b[d];e.data.enabled&&e.entity.enabled&&(e=e.entity.sprite,e._currentClip&&e._currentClip._update(a))}},onBeforeRemove:function(a,b){b.onDestroy()}});
- return{SpriteComponentSystem:b}}());Object.assign(pc,function(){return{SpriteComponentData:function(){this.enabled=!0}}}());Object.assign(pc,function(){pc.SCALEMODE_NONE="none";pc.SCALEMODE_BLEND="blend";var f=function(a,b){pc.Component.call(this,a,b);this._resolution=new pc.Vec2(640,320);this._referenceResolution=new pc.Vec2(640,320);this._scaleMode=pc.SCALEMODE_NONE;this.scale=1;this._scaleBlend=.5;this._priority=0;this.cull=this._screenSpace=!1;this._screenMatrix=new pc.Mat4;a.app.graphicsDevice.on("resizecanvas",this._onResize,this)};f.prototype=Object.create(pc.Component.prototype);f.prototype.constructor=f;var b=
- new pc.Mat4;Object.assign(f.prototype,{syncDrawOrder:function(){this.system.queueDrawOrderSync(this.entity.getGuid(),this._processDrawOrderSync,this)},_recurseDrawOrderSync:function(a,b){if(!(a instanceof pc.Entity))return b;a.element&&(a.element.drawOrder=b++);for(var c=a.getChildren(),e=0;e<c.length;e++)b=this._recurseDrawOrderSync(c[e],b);return b},_processDrawOrderSync:function(){this._recurseDrawOrderSync(this.entity,1);this.fire("syncdraworder")},_calcProjectionMatrix:function(){var a=this._resolution.x/
- this.scale,c=this._resolution.y/this.scale;this._screenMatrix.setOrtho(0,a,-c,0,1,-1);this._screenSpace||(b.setScale(.5*a,.5*c,1),this._screenMatrix.mul2(b,this._screenMatrix))},_updateScale:function(){this.scale=this._calcScale(this._resolution,this.referenceResolution)},_calcScale:function(a,b){return Math.pow(2,Math.log2(a.x/b.x)*(1-this._scaleBlend)+Math.log2(a.y/b.y)*this._scaleBlend)},_onResize:function(a,b){this._screenSpace&&(this._resolution.set(a,b),this.resolution=this._resolution)},onRemove:function(){this.system.app.graphicsDevice.off("resizecanvas",
- this._onResize,this);this.fire("remove");this.off()}});Object.defineProperty(f.prototype,"resolution",{set:function(a){this._screenSpace?this._resolution.set(this.system.app.graphicsDevice.width,this.system.app.graphicsDevice.height):this._resolution.set(a.x,a.y);this._updateScale();this._calcProjectionMatrix();this.entity._dirtyLocal||this.entity._dirtifyLocal();this.fire("set:resolution",this._resolution)},get:function(){return this._resolution}});Object.defineProperty(f.prototype,"referenceResolution",
- {set:function(a){this._referenceResolution.set(a.x,a.y);this._updateScale();this._calcProjectionMatrix();this.entity._dirtyLocal||this.entity._dirtifyLocal();this.fire("set:referenceresolution",this._resolution)},get:function(){return this._scaleMode===pc.SCALEMODE_NONE?this._resolution:this._referenceResolution}});Object.defineProperty(f.prototype,"screenSpace",{set:function(a){(this._screenSpace=a)&&this._resolution.set(this.system.app.graphicsDevice.width,this.system.app.graphicsDevice.height);
- this.resolution=this._resolution;this.entity._dirtyLocal||this.entity._dirtifyLocal();this.fire("set:screenspace",this._screenSpace)},get:function(){return this._screenSpace}});Object.defineProperty(f.prototype,"scaleMode",{set:function(a){a!==pc.SCALEMODE_NONE&&a!==pc.SCALEMODE_BLEND&&(a=pc.SCALEMODE_NONE);this._screenSpace||a===pc.SCALEMODE_NONE||(a=pc.SCALEMODE_NONE);this._scaleMode=a;this.resolution=this._resolution;this.fire("set:scalemode",this._scaleMode)},get:function(){return this._scaleMode}});
- Object.defineProperty(f.prototype,"scaleBlend",{set:function(a){this._scaleBlend=a;this._updateScale();this._calcProjectionMatrix();this.entity._dirtyLocal||this.entity._dirtifyLocal();this.fire("set:scaleblend",this._scaleBlend)},get:function(){return this._scaleBlend}});Object.defineProperty(f.prototype,"priority",{get:function(){return this._priority},set:function(a){255<a&&(a=255);this._priority=a}});return{ScreenComponent:f}}());Object.assign(pc,function(){var f=["enabled"],b=function(a){pc.ComponentSystem.call(this,a);this.id="screen";this.app=a;this.ComponentType=pc.ScreenComponent;this.DataType=pc.ScreenComponentData;this.schema=f;this.windowResolution=new pc.Vec2;this._drawOrderSyncQueue=new pc.IndexedList;this.app.graphicsDevice.on("resizecanvas",this._onResize,this);pc.ComponentSystem.bind("update",this._onUpdate,this);this.on("beforeremove",this.onRemoveComponent,this)};b.prototype=Object.create(pc.ComponentSystem.prototype);
- b.prototype.constructor=b;pc.Component._buildAccessors(pc.ScreenComponent.prototype,f);Object.assign(b.prototype,{initializeComponentData:function(a,b,d){void 0!==b.priority&&(a.priority=b.priority);void 0!==b.screenSpace&&(a.screenSpace=b.screenSpace);a.cull=a.screenSpace;void 0!==b.scaleMode&&(a.scaleMode=b.scaleMode);void 0!==b.scaleBlend&&(a.scaleBlend=b.scaleBlend);void 0!==b.resolution&&(b.resolution instanceof pc.Vec2?a._resolution.copy(b.resolution):a._resolution.set(b.resolution[0],b.resolution[1]),
- a.resolution=a._resolution);void 0!==b.referenceResolution&&(b.referenceResolution instanceof pc.Vec2?a._referenceResolution.copy(b.referenceResolution):a._referenceResolution.set(b.referenceResolution[0],b.referenceResolution[1]),a.referenceResolution=a._referenceResolution);a.syncDrawOrder();pc.ComponentSystem.prototype.initializeComponentData.call(this,a,b,d)},destroy:function(){this.off();this.app.graphicsDevice.off("resizecanvas",this._onResize,this)},_onUpdate:function(a){var b=this.store,d;
- for(d in b)b[d].entity.screen.update&&b[d].entity.screen.update(a)},_onResize:function(a,b){this.windowResolution.x=a;this.windowResolution.y=b},cloneComponent:function(a,b){var c=a.screen;return this.addComponent(b,{enabled:c.enabled,screenSpace:c.screenSpace,scaleMode:c.scaleMode,resolution:c.resolution.clone(),referenceResolution:c.referenceResolution.clone()})},onRemoveComponent:function(a,b){b.onRemove()},processDrawOrderSyncQueue:function(){for(var a=this._drawOrderSyncQueue.list(),b=0;b<a.length;b++){var d=
- a[b];d.callback.call(d.scope)}this._drawOrderSyncQueue.clear()},queueDrawOrderSync:function(a,b,d){if(!this._drawOrderSyncQueue.list().length)this.app.once("prerender",this.processDrawOrderSyncQueue,this);this._drawOrderSyncQueue.has(a)||this._drawOrderSyncQueue.push(a,{callback:b,scope:d})}});return{ScreenComponentSystem:b}}());Object.assign(pc,function(){return{ScreenComponentData:function(){this.enabled=!0}}}());Object.assign(pc,function(){pc.ELEMENTTYPE_GROUP="group";pc.ELEMENTTYPE_IMAGE="image";pc.ELEMENTTYPE_TEXT="text";var f=new pc.Vec3,b=new pc.Vec3,a=new pc.Mat4,c=new pc.Mat4,d=new pc.Mat4,e=new pc.Mat4,g=function(a,b){pc.Component.call(this,a,b);this._beingInitialized=!1;this._anchor=new pc.Vec4;this._localAnchor=new pc.Vec4;this._pivot=new pc.Vec2;this._height=this._calculatedHeight=this._width=this._calculatedWidth=32;this._margin=new pc.Vec4(0,0,-32,-32);this._modelTransform=new pc.Mat4;this._screenToWorld=
- new pc.Mat4;this._anchorTransform=new pc.Mat4;this._anchorDirty=!0;this._parentWorldTransform=new pc.Mat4;this._screenTransform=new pc.Mat4;this._screenCorners=[new pc.Vec3,new pc.Vec3,new pc.Vec3,new pc.Vec3];this._canvasCorners=[new pc.Vec2,new pc.Vec2,new pc.Vec2,new pc.Vec2];this._worldCorners=[new pc.Vec3,new pc.Vec3,new pc.Vec3,new pc.Vec3];this._worldCornersDirty=this._canvasCornersDirty=this._cornersDirty=!0;this.entity.on("insert",this._onInsert,this);this._patch();this.screen=null;this._type=
- pc.ELEMENTTYPE_GROUP;this._group=this._text=this._image=null;this._drawOrder=0;this._useInput=!1;this._layers=[pc.LAYERID_UI];this._addedModels=[];this._batchGroupId=-1;this._offsetReadAt=0;this._maskOffset=.5;this._maskedBy=null};g.prototype=Object.create(pc.Component.prototype);g.prototype.constructor=g;Object.assign(g.prototype,{_patch:function(){this.entity._sync=this._sync;this.entity.setPosition=this._setPosition;this.entity.setLocalPosition=this._setLocalPosition},_unpatch:function(){this.entity._sync=
- pc.Entity.prototype._sync;this.entity.setPosition=pc.Entity.prototype.setPosition;this.entity.setLocalPosition=pc.Entity.prototype.setLocalPosition},_setPosition:function(){var a=new pc.Vec3,b=new pc.Mat4;return function(c,d,e){if(!this.element.screen)return pc.Entity.prototype.setPosition.call(this,c,d,e);c instanceof pc.Vec3?a.copy(c):a.set(c,d,e);this.getWorldTransform();b.copy(this.element._screenToWorld).invert();b.transformPoint(a,this.localPosition);this._dirtyLocal||this._dirtifyLocal()}}(),
- _setLocalPosition:function(a,b,c){a instanceof pc.Vec3?this.localPosition.copy(a):this.localPosition.set(a,b,c);a=this.element;b=this.localPosition;c=a._pivot;a._margin.x=b.x-a._calculatedWidth*c.x;a._margin.z=a._localAnchor.z-a._localAnchor.x-a._calculatedWidth-a._margin.x;a._margin.y=b.y-a._calculatedHeight*c.y;a._margin.w=a._localAnchor.w-a._localAnchor.y-a._calculatedHeight-a._margin.y;this._dirtyLocal||this._dirtifyLocal()},_sync:function(){var e=this.element,g=e.screen;if(g){if(e._anchorDirty){var l,
- n,q=0,m=1;this._parent&&this._parent.element?(l=this._parent.element.calculatedWidth,n=this._parent.element.calculatedHeight,q=this._parent.element.pivot.x,m=this._parent.element.pivot.y):(n=g.screen.resolution,l=n.x/g.screen.scale,n=n.y/g.screen.scale);e._anchorTransform.setTranslate(l*(e.anchor.x-q),-(n*(m-e.anchor.y)),0);e._anchorDirty=!1;e._calculateLocalAnchors()}e._sizeDirty&&e._calculateSize()}this._dirtyLocal&&(this.localTransform.setTRS(this.localPosition,this.localRotation,this.localScale),
- l=this.localPosition,q=e._pivot,e._margin.x=l.x-e._calculatedWidth*q.x,e._margin.z=e._localAnchor.z-e._localAnchor.x-e._calculatedWidth-e._margin.x,e._margin.y=l.y-e._calculatedHeight*q.y,e._margin.w=e._localAnchor.w-e._localAnchor.y-e._calculatedHeight-e._margin.y,this._dirtyLocal=!1);if(!g)return this._dirtyWorld&&(e._cornersDirty=!0,e._canvasCornersDirty=!0,e._worldCornersDirty=!0),pc.Entity.prototype._sync.call(this);this._dirtyWorld&&(null===this._parent?this.worldTransform.copy(this.localTransform):
- (this._parent.element?e._screenToWorld.mul2(this._parent.element._modelTransform,e._anchorTransform):e._screenToWorld.copy(e._anchorTransform),e._modelTransform.mul2(e._screenToWorld,this.localTransform),g?(e._screenToWorld.mul2(g.screen._screenMatrix,e._screenToWorld),g.screen.screenSpace||e._screenToWorld.mul2(g.worldTransform,e._screenToWorld),this.worldTransform.mul2(e._screenToWorld,this.localTransform),l=e._parentWorldTransform,l.setIdentity(),(q=this._parent)&&q.element&&q!==g&&(a.setTRS(pc.Vec3.ZERO,
- q.getLocalRotation(),q.getLocalScale()),l.mul2(q.element._parentWorldTransform,a)),f.set(0,0,this.localPosition.z),b.set(e._absLeft+e._pivot.x*e.calculatedWidth,e._absBottom+e._pivot.y*e.calculatedHeight,0),a.setTranslate(-b.x,-b.y,-b.z),c.setTRS(f,this.getLocalRotation(),this.getLocalScale()),d.setTranslate(b.x,b.y,b.z),e._screenTransform.mul2(e._parentWorldTransform,d).mul(c).mul(a),e._cornersDirty=!0,e._canvasCornersDirty=!0,e._worldCornersDirty=!0):this.worldTransform.copy(e._modelTransform)),
- this._dirtyWorld=!1)},_onInsert:function(a){a=this._parseUpToScreen();this.entity._dirtifyWorld();this._updateScreen(a.screen);this._dirtifyMask()},_dirtifyMask:function(){for(var a=this.entity;a;){var b=a.getParent();if((null===b||b.screen)&&a.element){this.system._prerender&&this.system._prerender.length||(this.system._prerender=[],this.system.app.once("prerender",this._onPrerender,this));var c=this.system._prerender.indexOf(this.entity);0<=c&&this.system._prerender.splice(c,1);0>this.system._prerender.indexOf(a)&&
- this.system._prerender.push(a)}a=b}},_onPrerender:function(){for(var a=0;a<this.system._prerender.length;a++){var b=this.system._prerender[a];b.element&&b.element.syncMask(1)}this.system._prerender.length=0},_bindScreen:function(a){a.on("set:resolution",this._onScreenResize,this);a.on("set:referenceresolution",this._onScreenResize,this);a.on("set:scaleblend",this._onScreenResize,this);a.on("set:screenspace",this._onScreenSpaceChange,this);a.on("remove",this._onScreenRemove,this)},_unbindScreen:function(a){a.off("set:resolution",
- this._onScreenResize,this);a.off("set:referenceresolution",this._onScreenResize,this);a.off("set:scaleblend",this._onScreenResize,this);a.off("set:screenspace",this._onScreenSpaceChange,this);a.off("remove",this._onScreenRemove,this)},_updateScreen:function(a){this.screen&&this.screen!==a&&this._unbindScreen(this.screen.screen);var b=this.screen;(this.screen=a)&&this._bindScreen(this.screen.screen);this._calculateSize(this._hasSplitAnchorsX,this._hasSplitAnchorsY);this.fire("set:screen",this.screen,
- b);this._anchorDirty=!0;for(var b=this.entity.getChildren(),c=0,d=b.length;c<d;c++)b[c].element&&b[c].element._updateScreen(a);this.screen&&this.screen.screen.syncDrawOrder()},syncMask:function(a){var b=this._parseUpToScreen();this._updateMask(b.mask,a)},_setMaskedBy:function(a){var b=this._image||this._text;if(a){var c=new pc.StencilParameters({ref:a.element._image._maskRef,func:pc.FUNC_EQUAL});b&&b._setStencil&&b._setStencil(c);this._maskedBy=a}else b&&b._setStencil&&b._setStencil(null),this._maskedBy=
- null},_updateMask:function(a,b){var c,d,e;a?(this._setMaskedBy(a),this.mask&&(c=new pc.StencilParameters({ref:a.element._image._maskRef,func:pc.FUNC_EQUAL,zpass:pc.STENCILOP_INCREMENT}),this._image._setStencil(c),this._image._maskRef=b,b++,a=this.entity)):(this._setMaskedBy(null),this.mask&&(c=new pc.StencilParameters({ref:b,func:pc.FUNC_ALWAYS,zpass:pc.STENCILOP_REPLACE}),this._image._setStencil(c),this._image._maskRef=b,b++,a=this.entity));e=this.entity.getChildren();c=0;for(d=e.length;c<d;c++)e[c].element&&
- e[c].element._updateMask(a,b)},_parseUpToScreen:function(){for(var a={screen:null,mask:null},b=this.entity._parent;b&&!b.screen;)b.element&&b.element.mask&&!a.mask&&(a.mask=b),b=b.parent;b&&b.screen&&(a.screen=b);return a},_onScreenResize:function(a){this._worldCornersDirty=this._cornersDirty=this._anchorDirty=!0;this._calculateSize(this._hasSplitAnchorsX,this._hasSplitAnchorsY);this.fire("screen:set:resolution",a)},_onScreenSpaceChange:function(){this.fire("screen:set:screenspace",this.screen.screen.screenSpace)},
- _onScreenRemove:function(){this.screen&&!this.screen._destroying&&this._updateScreen(null)},_calculateLocalAnchors:function(){var a=1E3,b=1E3,c=this.entity._parent;c&&c.element?(a=c.element.calculatedWidth,b=c.element.calculatedHeight):this.screen&&(b=this.screen.screen.resolution,c=this.screen.screen.scale,a=b.x/c,b=b.y/c);this._localAnchor.set(this._anchor.x*a,this._anchor.y*b,this._anchor.z*a,this._anchor.w*b)},getOffsetPosition:function(a,b){var c=this.entity.getLocalPosition().clone();c.x+=a;
- c.y+=b;this._screenToWorld.transformPoint(c,c);return c},onLayersChanged:function(a,b){this.addModelToLayers(this._image?this._image._model:this._text._model);a.off("add",this.onLayerAdded,this);a.off("remove",this.onLayerRemoved,this);b.on("add",this.onLayerAdded,this);b.on("remove",this.onLayerRemoved,this)},onLayerAdded:function(a){0>this.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));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.markGroupDirty(this.batchGroupId);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);c=this.entity.getLocalPosition();c.x=this._margin.x+this._calculatedWidth*this._pivot.x;c.y=this._margin.y+this._calculatedHeight*this._pivot.y;this.entity.setLocalPosition(c);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){var c=1E-4<Math.abs(a-this._calculatedWidth);this._calculatedWidth=a;if(b){var d=this.entity.getLocalPosition();this._margin.x=d.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);c&&this.fire("resize",this._calculatedWidth,this._calculatedHeight)},_setCalculatedHeight:function(a,b){var c=1E-4<Math.abs(a-this._calculatedHeight);this._calculatedHeight=a;if(b){var d=this.entity.getLocalPosition();this._margin.y=d.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);c&&this.fire("resize",this._calculatedWidth,
- this._calculatedHeight)},_flagChildrenAsDirty:function(){var a,b,c=this.entity._children;a=0;for(b=c.length;a<b;a++)c[a].element&&(c[a].element._anchorDirty=!0,c[a].element._sizeDirty=!0)},addModelToLayers:function(a){var b;this._addedModels.push(a);for(var c=0;c<this.layers.length;c++)(b=this.system.app.scene.layers.getLayerById(this.layers[c]))&&b.addMeshInstances(a.meshInstances)},removeModelFromLayers:function(a){var b;b=this._addedModels.indexOf(a);0<=b&&this._addedModels.splice(b,1);for(var c=
- 0;c<this.layers.length;c++)(b=this.system.app.scene.layers.getLayerById(this.layers[c]))&&b.removeMeshInstances(a.meshInstances)},getMaskOffset:function(){var a=this.system.app.frame;this._offsetReadAt!==a&&(this._maskOffset=.5,this._offsetReadAt=a);a=this._maskOffset;this._maskOffset-=.001;return a},isVisibleForCamera:function(a){var b,c,d;if(this.maskedBy)a=this.maskedBy.element.screenCorners,b=Math.min(Math.min(a[0].x,a[1].x),Math.min(a[2].x,a[3].x)),c=Math.max(Math.max(a[0].x,a[1].x),Math.max(a[2].x,
- a[3].x)),d=Math.min(Math.min(a[0].y,a[1].y),Math.min(a[2].y,a[3].y)),a=Math.max(Math.max(a[0].y,a[1].y),Math.max(a[2].y,a[3].y));else{b=this.system.app.graphicsDevice.width;var e=this.system.app.graphicsDevice.height;c=a._rect.width*b;d=a._rect.height*e;b*=a._rect.x;c=b+c;a=(1-a._rect.y)*e;d=a-d}var e=this.screenCorners,f=Math.min(Math.min(e[0].x,e[1].x),Math.min(e[2].x,e[3].x)),g=Math.min(Math.min(e[0].y,e[1].y),Math.min(e[2].y,e[3].y)),l=Math.max(Math.max(e[0].y,e[1].y),Math.max(e[2].y,e[3].y));
- return Math.max(Math.max(e[0].x,e[1].x),Math.max(e[2].x,e[3].x))<b||f>c||g>a||l<d?!1:!0},_isScreenSpace:function(){return this.screen&&this.screen.screen?this.screen.screen.screenSpace:!1},_isScreenCulled:function(){return this.screen&&this.screen.screen?this.screen.screen.cull:!1}});Object.defineProperty(g.prototype,"type",{get:function(){return this._type},set:function(a){a!==this._type&&(this._type=a,this._image&&(this._image.destroy(),this._image=null),this._text&&(this._text.destroy(),this._text=
- null),a===pc.ELEMENTTYPE_IMAGE?this._image=new pc.ImageElement(this):a===pc.ELEMENTTYPE_TEXT&&(this._text=new pc.TextElement(this)))}});Object.defineProperty(g.prototype,"layers",{get:function(){return this._layers},set:function(a){var b,c,d;if(this._addedModels.length)for(b=0;b<this._layers.length;b++)if(d=this.system.app.scene.layers.getLayerById(this._layers[b]))for(c=0;c<this._addedModels.length;c++)d.removeMeshInstances(this._addedModels[c].meshInstances);this._layers=a;if(this.enabled&&this.entity.enabled&&
- this._addedModels.length)for(b=0;b<this._layers.length;b++)if(d=this.system.app.scene.layers.getLayerById(this._layers[b]))for(c=0;c<this._addedModels.length;c++)d.addMeshInstances(this._addedModels[c].meshInstances)}});Object.defineProperty(g.prototype,"drawOrder",{get:function(){return this._drawOrder},set:function(a){var b=0;this.screen&&(b=this.screen.screen.priority);16777215<a&&(a=16777215);this._drawOrder=(b<<24)+a;this.fire("set:draworder",this._drawOrder)}});Object.defineProperty(g.prototype,
- "_absLeft",{get:function(){return this._localAnchor.x+this._margin.x}});Object.defineProperty(g.prototype,"_absRight",{get:function(){return this._localAnchor.z-this._margin.z}});Object.defineProperty(g.prototype,"_absTop",{get:function(){return this._localAnchor.w-this._margin.w}});Object.defineProperty(g.prototype,"_absBottom",{get:function(){return this._localAnchor.y+this._margin.y}});Object.defineProperty(g.prototype,"margin",{get:function(){return this._margin},set:function(a){this._margin.copy(a);
- this._calculateSize(!0,!0);this.fire("set:margin",this._margin)}});Object.defineProperty(g.prototype,"left",{get:function(){return this._margin.x},set:function(a){this._margin.x=a;var b=this.entity.getLocalPosition();this._setWidth(this._absRight-(this._localAnchor.x+a));b.x=a+this._calculatedWidth*this._pivot.x;this.entity.setLocalPosition(b)}});Object.defineProperty(g.prototype,"right",{get:function(){return this._margin.z},set:function(a){this._margin.z=a;var b=this.entity.getLocalPosition();this._setWidth(this._localAnchor.z-
- a-this._absLeft);b.x=this._localAnchor.z-this._localAnchor.x-a-this._calculatedWidth*(1-this._pivot.x);this.entity.setLocalPosition(b)}});Object.defineProperty(g.prototype,"top",{get:function(){return this._margin.w},set:function(a){this._margin.w=a;var b=this.entity.getLocalPosition();this._setHeight(this._localAnchor.w-a-this._absBottom);b.y=this._localAnchor.w-this._localAnchor.y-a-this._calculatedHeight*(1-this._pivot.y);this.entity.setLocalPosition(b)}});Object.defineProperty(g.prototype,"bottom",
- {get:function(){return this._margin.y},set:function(a){this._margin.y=a;var b=this.entity.getLocalPosition();this._setHeight(this._absTop-(this._localAnchor.y+a));b.y=a+this._calculatedHeight*this._pivot.y;this.entity.setLocalPosition(b)}});Object.defineProperty(g.prototype,"width",{get:function(){return this._width},set:function(a){this._width=a;this._hasSplitAnchorsX||this._setCalculatedWidth(a,!0);this.fire("set:width",this._width)}});Object.defineProperty(g.prototype,"height",{get:function(){return this._height},
- set:function(a){this._height=a;this._hasSplitAnchorsY||this._setCalculatedHeight(a,!0);this.fire("set:height",this._height)}});Object.defineProperty(g.prototype,"calculatedWidth",{get:function(){return this._calculatedWidth},set:function(a){this._setCalculatedWidth(a,!0)}});Object.defineProperty(g.prototype,"calculatedHeight",{get:function(){return this._calculatedHeight},set:function(a){this._setCalculatedHeight(a,!0)}});Object.defineProperty(g.prototype,"pivot",{get:function(){return this._pivot},
- set:function(a){var b=this._pivot.x,c=this._pivot.y;a instanceof pc.Vec2?this._pivot.set(a.x,a.y):this._pivot.set(a[0],a[1]);a=this._margin.x+this._margin.z;b=this._pivot.x-b;this._margin.x+=a*b;this._margin.z-=a*b;b=this._margin.y+this._margin.w;c=this._pivot.y-c;this._margin.y+=b*c;this._margin.w-=b*c;this._worldCornersDirty=this._cornersDirty=this._anchorDirty=!0;this._calculateSize();this.fire("set:pivot",this._pivot)}});Object.defineProperty(g.prototype,"anchor",{get:function(){return this._anchor},
- set:function(a){a instanceof pc.Vec4?this._anchor.set(a.x,a.y,a.z,a.w):this._anchor.set(a[0],a[1],a[2],a[3]);this.entity._parent||this.screen?this._calculateSize(this._hasSplitAnchorsX,this._hasSplitAnchorsY):this._calculateLocalAnchors();this._anchorDirty=!0;this.entity._dirtyLocal||this.entity._dirtifyLocal();this.fire("set:anchor",this._anchor)}});Object.defineProperty(g.prototype,"_hasSplitAnchorsX",{get:function(){return.001<Math.abs(this._anchor.x-this._anchor.z)}});Object.defineProperty(g.prototype,
- "_hasSplitAnchorsY",{get:function(){return.001<Math.abs(this._anchor.y-this._anchor.w)}});Object.defineProperty(g.prototype,"aabb",{get:function(){return this._image?this._image.aabb:this._text?this._text.aabb:null}});Object.defineProperty(g.prototype,"screenCorners",{get:function(){if(!this._cornersDirty||!this.screen)return this._screenCorners;var a=this.entity.parent&&this.entity.parent.element&&this.entity.parent.element.screenCorners[0];this._screenCorners[0].set(this._absLeft,this._absBottom,
- 0);this._screenCorners[1].set(this._absRight,this._absBottom,0);this._screenCorners[2].set(this._absRight,this._absTop,0);this._screenCorners[3].set(this._absLeft,this._absTop,0);for(var b=this.screen.screen.screenSpace,c=0;4>c;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(g.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(g.prototype,"worldCorners",{get:function(){if(!this._worldCornersDirty)return this._worldCorners;
- if(this.screen){var b=this.screenCorners;if(!this.screen.screen.screenSpace){a.copy(this.screen.screen._screenMatrix);a.data[13]=-a.data[13];a.mul2(this.screen.getWorldTransform(),a);for(var g=0;4>g;g++)a.transformPoint(b[g],this._worldCorners[g])}}else b=this.entity.getLocalPosition(),a.setTranslate(-b.x,-b.y,-b.z),c.setTRS(pc.Vec3.ZERO,this.entity.getLocalRotation(),this.entity.getLocalScale()),d.setTranslate(b.x,b.y,b.z),e.copy(this.entity.parent.getWorldTransform()),e.mul(d).mul(c).mul(a),f.set(b.x-
- this.pivot.x*this.calculatedWidth,b.y-this.pivot.y*this.calculatedHeight,b.z),e.transformPoint(f,this._worldCorners[0]),f.set(b.x+(1-this.pivot.x)*this.calculatedWidth,b.y-this.pivot.y*this.calculatedHeight,b.z),e.transformPoint(f,this._worldCorners[1]),f.set(b.x+(1-this.pivot.x)*this.calculatedWidth,b.y+(1-this.pivot.y)*this.calculatedHeight,b.z),e.transformPoint(f,this._worldCorners[2]),f.set(b.x-this.pivot.x*this.calculatedWidth,b.y+(1-this.pivot.y)*this.calculatedHeight,b.z),e.transformPoint(f,
- this._worldCorners[3]);this._worldCornersDirty=!1;return this._worldCorners}});Object.defineProperty(g.prototype,"textWidth",{get:function(){return this._text?this._text.width:0}});Object.defineProperty(g.prototype,"textHeight",{get:function(){return this._text?this._text.height:0}});Object.defineProperty(g.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(g.prototype,"batchGroupId",{get:function(){return this._batchGroupId},set:function(a){this._batchGroupId!==a&&(0<=this._batchGroupId&&this.system.app.batcher.markGroupDirty(this._batchGroupId),0<=a&&this.system.app.batcher.markGroupDirty(a),0>a&&0<=this._batchGroupId&&this.enabled&&this.entity.enabled&&(this._image._model?this.addModelToLayers(this._image._model):this._text._model&&this.addModelToLayers(this._text._model)),
- this._batchGroupId=a)}});Object.defineProperty(g.prototype,"maskedBy",{get:function(){return this._maskedBy}});var l=function(a){Object.defineProperty(g.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)}})};l("fontSize");l("color");l("font");l("fontAsset");l("spacing");l("lineHeight");l("wrapLines");l("lines");l("alignment");l("autoWidth");l("autoHeight");l("rtlReorder");l("unicodeConverter");
- l("text");l("key");l("texture");l("textureAsset");l("material");l("materialAsset");l("sprite");l("spriteAsset");l("spriteFrame");l("pixelsPerUnit");l("opacity");l("rect");l("mask");l("outlineColor");l("outlineThickness");l("shadowColor");l("shadowOffset");return{ElementComponent:g}}());Object.assign(pc,function(){var f=["enabled"],b=function(a){pc.ComponentSystem.call(this,a);this.id="element";this.app=a;this.ComponentType=pc.ElementComponent;this.DataType=pc.ElementComponentData;this.schema=f;this._rtlReorder=this._unicodeConverter=null;this._defaultTexture=new pc.Texture(a.graphicsDevice,{width:1,height:1,format:pc.PIXELFORMAT_R8_G8_B8_A8});this._defaultTexture.name="element-system";a=this._defaultTexture.lock();var b=new Uint8Array(4);b[0]=255;b[1]=255;b[2]=255;b[3]=255;a.set(b);
- this._defaultTexture.unlock();this.defaultScreenSpaceBitmapTextMaterial=this.defaultScreenSpaceTextMaterial=this.defaultBitmapTextMaterial=this.defaultTextMaterial=this.defaultScreenSpaceImageMaskMaterial=this.defaultScreenSpaceImageMask9TiledMaterial=this.defaultScreenSpaceImageMask9SlicedMaterial=this.defaultScreenSpaceImage9TiledMaterial=this.defaultScreenSpaceImage9SlicedMaterial=this.defaultScreenSpaceImageMaterial=this.defaultImage9TiledMaskMaterial=this.defaultImage9SlicedMaskMaterial=this.defaultImageMaskMaterial=
- this.defaultImage9TiledMaterial=this.defaultImage9SlicedMaterial=this.defaultImageMaterial=null;this.defaultImageMaterials=[];this.on("beforeremove",this.onRemoveComponent,this)};b.prototype=Object.create(pc.ComponentSystem.prototype);b.prototype.constructor=b;pc.Component._buildAccessors(pc.ElementComponent.prototype,f);Object.assign(b.prototype,{destroy:function(){this._defaultTexture.destroy()},initializeComponentData:function(a,b,d){a._beingInitialized=!0;void 0!==b.anchor&&(b.anchor instanceof
- pc.Vec4?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 pc.Vec2?a.pivot.copy(b.pivot):a.pivot.set(b.pivot[0],b.pivot[1]));var c=.001<Math.abs(a.anchor.x-a.anchor.z),f=.001<Math.abs(a.anchor.y-a.anchor.w),l=!1;void 0!==b.margin&&(b.margin instanceof pc.Vec4?a.margin.copy(b.margin):a._margin.set(b.margin[0],b.margin[1],b.margin[2],b.margin[3]),l=!0);void 0!==b.left&&(a._margin.x=b.left,l=!0);void 0!==b.bottom&&(a._margin.y=
- b.bottom,l=!0);void 0!==b.right&&(a._margin.z=b.right,l=!0);void 0!==b.top&&(a._margin.w=b.top,l=!0);l&&(a.margin=a._margin);l=!1;void 0===b.width||c?c&&(l=!0):a.width=b.width;void 0===b.height||f?f&&(l=!0):a.height=b.height;l&&(a.anchor=a.anchor);void 0!==b.enabled&&(a.enabled=b.enabled);void 0!==b.useInput&&(a.useInput=b.useInput);a.batchGroupId=void 0===b.batchGroupId||null===b.batchGroupId?-1:b.batchGroupId;b.layers&&"array"===pc.type(b.layers)&&(a.layers=b.layers.slice(0));a.type=b.type;a.type===
- pc.ELEMENTTYPE_IMAGE?(void 0!==b.rect&&(a.rect=b.rect),void 0!==b.color&&(c=b.color,c instanceof pc.Color||(c=new pc.Color(b.color[0],b.color[1],b.color[2])),a.color=c),void 0!==b.opacity&&(a.opacity=b.opacity),void 0!==b.textureAsset&&(a.textureAsset=b.textureAsset),b.texture&&(a.texture=b.texture),void 0!==b.spriteAsset&&(a.spriteAsset=b.spriteAsset),b.sprite&&(a.sprite=b.sprite),void 0!==b.spriteFrame&&(a.spriteFrame=b.spriteFrame),void 0!==b.pixelsPerUnit&&null!==b.pixelsPerUnit&&(a.pixelsPerUnit=
- b.pixelsPerUnit),void 0!==b.materialAsset&&(a.materialAsset=b.materialAsset),b.material&&(a.material=b.material),void 0!==b.mask&&(a.mask=b.mask)):a.type===pc.ELEMENTTYPE_TEXT&&(void 0!==b.autoWidth&&(a.autoWidth=b.autoWidth),void 0!==b.autoHeight&&(a.autoHeight=b.autoHeight),void 0!==b.rtlReorder&&(a.rtlReorder=b.rtlReorder),void 0!==b.unicodeConverter&&(a.unicodeConverter=b.unicodeConverter),null!==b.text&&void 0!==b.text?a.text=b.text:null!==b.key&&void 0!==b.key&&(a.key=b.key),void 0!==b.color&&
- (c=b.color,c instanceof pc.Color||(c=new pc.Color(c[0],c[1],c[2])),a.color=c),void 0!==b.opacity&&(a.opacity=b.opacity),void 0!==b.spacing&&(a.spacing=b.spacing),void 0!==b.fontSize&&(a.fontSize=b.fontSize,b.lineHeight||(a.lineHeight=b.fontSize)),void 0!==b.lineHeight&&(a.lineHeight=b.lineHeight),void 0!==b.wrapLines&&(a.wrapLines=b.wrapLines),void 0!==b.fontAsset&&(a.fontAsset=b.fontAsset),void 0!==b.font&&(a.font=b.font),void 0!==b.alignment&&(a.alignment=b.alignment),void 0!==b.outlineColor&&(a.outlineColor=
- b.outlineColor),void 0!==b.outlineThickness&&(a.outlineThickness=b.outlineThickness),void 0!==b.shadowColor&&(a.shadowColor=b.shadowColor),void 0!==b.shadowOffset&&(a.shadowOffset=b.shadowOffset));c=a._parseUpToScreen();c.screen&&a._updateScreen(c.screen);pc.ComponentSystem.prototype.initializeComponentData.call(this,a,b,d);a._beingInitialized=!1;a.type===pc.ELEMENTTYPE_IMAGE&&a._image._meshDirty&&a._image._updateMesh(a._image.mesh)},onRemoveComponent:function(a,b){b.onRemove()},cloneComponent:function(a,
- b){var c=a.element,e={enabled:c.enabled,width:c.width,height:c.height,anchor:c.anchor.clone(),pivot:c.pivot.clone(),margin:c.margin.clone(),alignment:c.alignment&&c.alignment.clone()||c.alignment,autoWidth:c.autoWidth,autoHeight:c.autoHeight,type:c.type,rect:c.rect&&c.rect.clone()||c.rect,rtlReorder:c.rtlReorder,unicodeConverter:c.unicodeConverter,materialAsset:c.materialAsset,material:c.material,color:c.color&&c.color.clone()||c.color,opacity:c.opacity,textureAsset:c.textureAsset,texture:c.texture,
- spriteAsset:c.spriteAsset,sprite:c.sprite,spriteFrame:c.spriteFrame,pixelsPerUnit:c.pixelsPerUnit,spacing:c.spacing,lineHeight:c.lineHeight,wrapLines:c.wrapLines,layers:c.layers,fontSize:c.fontSize,fontAsset:c.fontAsset,font:c.font,useInput:c.useInput,batchGroupId:c.batchGroupId,mask:c.mask,outlineColor:c.outlineColor&&c.outlineColor.clone()||c.outlineColor,outlineThickness:c.outlineThickness,shadowColor:c.shadowColor&&c.shadowColor.clone()||c.shadowColor,shadowOffset:c.shadowOffset&&c.shadowOffset.clone()||
- c.shadowOffset};void 0!==c.key&&null!==c.key?e.key=c.key:e.text=c.text;return this.addComponent(b,e)},getTextElementMaterial:function(a,b){if(a){if(b)return this.defaultScreenSpaceTextMaterial||(this.defaultScreenSpaceTextMaterial=new pc.StandardMaterial,this.defaultScreenSpaceTextMaterial.name="defaultScreenSpaceTextMaterial",this.defaultScreenSpaceTextMaterial.msdfMap=this._defaultTexture,this.defaultScreenSpaceTextMaterial.useLighting=!1,this.defaultScreenSpaceTextMaterial.useGammaTonemap=!1,this.defaultScreenSpaceTextMaterial.useFog=
- !1,this.defaultScreenSpaceTextMaterial.useSkybox=!1,this.defaultScreenSpaceTextMaterial.diffuse.set(0,0,0),this.defaultScreenSpaceTextMaterial.emissive.set(1,1,1),this.defaultScreenSpaceTextMaterial.opacity=.5,this.defaultScreenSpaceTextMaterial.blendType=pc.BLEND_PREMULTIPLIED,this.defaultScreenSpaceTextMaterial.depthWrite=!1,this.defaultScreenSpaceTextMaterial.depthTest=!1,this.defaultScreenSpaceTextMaterial.update()),this.defaultScreenSpaceTextMaterial;this.defaultScreenSpaceBitmapTextMaterial||
- (this.defaultScreenSpaceBitmapTextMaterial=new pc.StandardMaterial,this.defaultScreenSpaceBitmapTextMaterial.name="defaultScreenSpaceBitmapTextMaterial",this.defaultScreenSpaceBitmapTextMaterial.emissive.set(.5,.5,.5),this.defaultScreenSpaceBitmapTextMaterial.emissiveMap=this._defaultTexture,this.defaultScreenSpaceBitmapTextMaterial.emissiveTint=!0,this.defaultScreenSpaceBitmapTextMaterial.opacity=.5,this.defaultScreenSpaceBitmapTextMaterial.opacityMap=this._defaultTexture,this.defaultScreenSpaceBitmapTextMaterial.opacityMapChannel=
- "a",this.defaultScreenSpaceBitmapTextMaterial.useLighting=!1,this.defaultScreenSpaceBitmapTextMaterial.useGammaTonemap=!1,this.defaultScreenSpaceBitmapTextMaterial.useFog=!1,this.defaultScreenSpaceBitmapTextMaterial.useSkybox=!1,this.defaultScreenSpaceBitmapTextMaterial.diffuse.set(0,0,0),this.defaultScreenSpaceBitmapTextMaterial.blendType=pc.BLEND_PREMULTIPLIED,this.defaultScreenSpaceBitmapTextMaterial.depthWrite=!1,this.defaultScreenSpaceBitmapTextMaterial.depthTest=!1,this.defaultScreenSpaceBitmapTextMaterial.update());
- return this.defaultScreenSpaceBitmapTextMaterial}if(b)return this.defaultTextMaterial||(this.defaultTextMaterial=new pc.StandardMaterial,this.defaultTextMaterial.name="defaultTextMaterial",this.defaultTextMaterial.msdfMap=this._defaultTexture,this.defaultTextMaterial.useLighting=!1,this.defaultTextMaterial.useGammaTonemap=!1,this.defaultTextMaterial.useFog=!1,this.defaultTextMaterial.useSkybox=!1,this.defaultTextMaterial.diffuse.set(0,0,0),this.defaultTextMaterial.emissive.set(1,1,1),this.defaultTextMaterial.opacity=
- .5,this.defaultTextMaterial.blendType=pc.BLEND_PREMULTIPLIED,this.defaultTextMaterial.depthWrite=!1,this.defaultTextMaterial.update()),this.defaultTextMaterial;this.defaultBitmapTextMaterial||(this.defaultBitmapTextMaterial=new pc.StandardMaterial,this.defaultBitmapTextMaterial.name="defaultBitmapTextMaterial",this.defaultBitmapTextMaterial.emissive.set(.5,.5,.5),this.defaultBitmapTextMaterial.emissiveTint=!0,this.defaultBitmapTextMaterial.emissiveMap=this._defaultTexture,this.defaultBitmapTextMaterial.opacity=
- .5,this.defaultBitmapTextMaterial.opacityMap=this._defaultTexture,this.defaultBitmapTextMaterial.opacityMapChannel="a",this.defaultBitmapTextMaterial.useLighting=!1,this.defaultBitmapTextMaterial.useGammaTonemap=!1,this.defaultBitmapTextMaterial.useFog=!1,this.defaultBitmapTextMaterial.useSkybox=!1,this.defaultBitmapTextMaterial.diffuse.set(0,0,0),this.defaultBitmapTextMaterial.blendType=pc.BLEND_PREMULTIPLIED,this.defaultBitmapTextMaterial.depthWrite=!1,this.defaultBitmapTextMaterial.update());return this.defaultBitmapTextMaterial},
- _createBaseImageMaterial:function(){var a=new pc.StandardMaterial;a.diffuse.set(0,0,0);a.emissive.set(.5,.5,.5);a.emissiveMap=this._defaultTexture;a.emissiveTint=!0;a.opacityMap=this._defaultTexture;a.opacityMapChannel="a";a.opacityTint=!0;a.opacity=0;a.useLighting=!1;a.useGammaTonemap=!1;a.useFog=!1;a.useSkybox=!1;a.blendType=pc.BLEND_PREMULTIPLIED;a.depthWrite=!1;return a},getImageElementMaterial:function(a,b,d,e){if(a){if(b){if(d)return this.defaultScreenSpaceImageMask9SlicedMaterial||(this.defaultScreenSpaceImageMask9SlicedMaterial=
- this._createBaseImageMaterial(),this.defaultScreenSpaceImageMask9SlicedMaterial.name="defaultScreenSpaceImageMask9SlicedMaterial",this.defaultScreenSpaceImageMask9SlicedMaterial.nineSlicedMode=pc.SPRITE_RENDERMODE_SLICED,this.defaultScreenSpaceImageMask9SlicedMaterial.depthTest=!1,this.defaultScreenSpaceImageMask9SlicedMaterial.alphaTest=1,this.defaultScreenSpaceImageMask9SlicedMaterial.redWrite=!1,this.defaultScreenSpaceImageMask9SlicedMaterial.greenWrite=!1,this.defaultScreenSpaceImageMask9SlicedMaterial.blueWrite=
- !1,this.defaultScreenSpaceImageMask9SlicedMaterial.alphaWrite=!1,this.defaultScreenSpaceImageMask9SlicedMaterial.update(),this.defaultImageMaterials.push(this.defaultScreenSpaceImageMask9SlicedMaterial)),this.defaultScreenSpaceImageMask9SlicedMaterial;if(e)return this.defaultScreenSpaceImageMask9TiledMaterial||(this.defaultScreenSpaceImageMask9TiledMaterial=this.defaultScreenSpaceImage9TiledMaterial.clone(),this.defaultScreenSpaceImageMask9TiledMaterial.name="defaultScreenSpaceImageMask9TiledMaterial",
- this.defaultScreenSpaceImageMask9TiledMaterial.nineSlicedMode=pc.SPRITE_RENDERMODE_TILED,this.defaultScreenSpaceImageMask9TiledMaterial.depthTest=!1,this.defaultScreenSpaceImageMask9TiledMaterial.alphaTest=1,this.defaultScreenSpaceImageMask9TiledMaterial.redWrite=!1,this.defaultScreenSpaceImageMask9TiledMaterial.greenWrite=!1,this.defaultScreenSpaceImageMask9TiledMaterial.blueWrite=!1,this.defaultScreenSpaceImageMask9TiledMaterial.alphaWrite=!1,this.defaultScreenSpaceImageMask9TiledMaterial.update(),
- this.defaultImageMaterials.push(this.defaultScreenSpaceImageMask9TiledMaterial)),this.defaultScreenSpaceImageMask9TiledMaterial;this.defaultScreenSpaceImageMaskMaterial||(this.defaultScreenSpaceImageMaskMaterial=this._createBaseImageMaterial(),this.defaultScreenSpaceImageMaskMaterial.name="defaultScreenSpaceImageMaskMaterial",this.defaultScreenSpaceImageMaskMaterial.depthTest=!1,this.defaultScreenSpaceImageMaskMaterial.alphaTest=1,this.defaultScreenSpaceImageMaskMaterial.redWrite=!1,this.defaultScreenSpaceImageMaskMaterial.greenWrite=
- !1,this.defaultScreenSpaceImageMaskMaterial.blueWrite=!1,this.defaultScreenSpaceImageMaskMaterial.alphaWrite=!1,this.defaultScreenSpaceImageMaskMaterial.update(),this.defaultImageMaterials.push(this.defaultScreenSpaceImageMaskMaterial));return this.defaultScreenSpaceImageMaskMaterial}if(d)return this.defaultScreenSpaceImage9SlicedMaterial||(this.defaultScreenSpaceImage9SlicedMaterial=this._createBaseImageMaterial(),this.defaultScreenSpaceImage9SlicedMaterial.name="defaultScreenSpaceImage9SlicedMaterial",
- this.defaultScreenSpaceImage9SlicedMaterial.nineSlicedMode=pc.SPRITE_RENDERMODE_SLICED,this.defaultScreenSpaceImage9SlicedMaterial.depthTest=!1,this.defaultScreenSpaceImage9SlicedMaterial.update(),this.defaultImageMaterials.push(this.defaultScreenSpaceImage9SlicedMaterial)),this.defaultScreenSpaceImage9SlicedMaterial;if(e)return this.defaultScreenSpaceImage9TiledMaterial||(this.defaultScreenSpaceImage9TiledMaterial=this._createBaseImageMaterial(),this.defaultScreenSpaceImage9TiledMaterial.name="defaultScreenSpaceImage9TiledMaterial",
- this.defaultScreenSpaceImage9TiledMaterial.nineSlicedMode=pc.SPRITE_RENDERMODE_TILED,this.defaultScreenSpaceImage9TiledMaterial.depthTest=!1,this.defaultScreenSpaceImage9TiledMaterial.update(),this.defaultImageMaterials.push(this.defaultScreenSpaceImage9TiledMaterial)),this.defaultScreenSpaceImage9TiledMaterial;this.defaultScreenSpaceImageMaterial||(this.defaultScreenSpaceImageMaterial=this._createBaseImageMaterial(),this.defaultScreenSpaceImageMaterial.name="defaultScreenSpaceImageMaterial",this.defaultScreenSpaceImageMaterial.depthTest=
- !1,this.defaultScreenSpaceImageMaterial.update(),this.defaultImageMaterials.push(this.defaultScreenSpaceImageMaterial));return this.defaultScreenSpaceImageMaterial}if(b){if(d)return this.defaultImage9SlicedMaskMaterial||(this.defaultImage9SlicedMaskMaterial=this._createBaseImageMaterial(),this.defaultImage9SlicedMaskMaterial.name="defaultImage9SlicedMaskMaterial",this.defaultImage9SlicedMaskMaterial.nineSlicedMode=pc.SPRITE_RENDERMODE_SLICED,this.defaultImage9SlicedMaskMaterial.alphaTest=1,this.defaultImage9SlicedMaskMaterial.redWrite=
- !1,this.defaultImage9SlicedMaskMaterial.greenWrite=!1,this.defaultImage9SlicedMaskMaterial.blueWrite=!1,this.defaultImage9SlicedMaskMaterial.alphaWrite=!1,this.defaultImage9SlicedMaskMaterial.update(),this.defaultImageMaterials.push(this.defaultImage9SlicedMaskMaterial)),this.defaultImage9SlicedMaskMaterial;if(e)return this.defaultImage9TiledMaskMaterial||(this.defaultImage9TiledMaskMaterial=this._createBaseImageMaterial(),this.defaultImage9TiledMaskMaterial.name="defaultImage9TiledMaskMaterial",
- this.defaultImage9TiledMaskMaterial.nineSlicedMode=pc.SPRITE_RENDERMODE_TILED,this.defaultImage9TiledMaskMaterial.alphaTest=1,this.defaultImage9TiledMaskMaterial.redWrite=!1,this.defaultImage9TiledMaskMaterial.greenWrite=!1,this.defaultImage9TiledMaskMaterial.blueWrite=!1,this.defaultImage9TiledMaskMaterial.alphaWrite=!1,this.defaultImage9TiledMaskMaterial.update(),this.defaultImageMaterials.push(this.defaultImage9TiledMaskMaterial)),this.defaultImage9TiledMaskMaterial;this.defaultImageMaskMaterial||
- (this.defaultImageMaskMaterial=this._createBaseImageMaterial(),this.defaultImageMaskMaterial.name="defaultImageMaskMaterial",this.defaultImageMaskMaterial.alphaTest=1,this.defaultImageMaskMaterial.redWrite=!1,this.defaultImageMaskMaterial.greenWrite=!1,this.defaultImageMaskMaterial.blueWrite=!1,this.defaultImageMaskMaterial.alphaWrite=!1,this.defaultImageMaskMaterial.update(),this.defaultImageMaterials.push(this.defaultImageMaskMaterial));return this.defaultImageMaskMaterial}if(d)return this.defaultImage9SlicedMaterial||
- (this.defaultImage9SlicedMaterial=this._createBaseImageMaterial(),this.defaultImage9SlicedMaterial.name="defaultImage9SlicedMaterial",this.defaultImage9SlicedMaterial.nineSlicedMode=pc.SPRITE_RENDERMODE_SLICED,this.defaultImage9SlicedMaterial.update(),this.defaultImageMaterials.push(this.defaultImage9SlicedMaterial)),this.defaultImage9SlicedMaterial;if(e)return this.defaultImage9TiledMaterial||(this.defaultImage9TiledMaterial=this._createBaseImageMaterial(),this.defaultImage9TiledMaterial.name="defaultImage9TiledMaterial",
- this.defaultImage9TiledMaterial.nineSlicedMode=pc.SPRITE_RENDERMODE_TILED,this.defaultImage9TiledMaterial.update(),this.defaultImageMaterials.push(this.defaultImage9TiledMaterial)),this.defaultImage9TiledMaterial;this.defaultImageMaterial||(this.defaultImageMaterial=this._createBaseImageMaterial(),this.defaultImageMaterial.name="defaultImageMaterial",this.defaultImageMaterial.update(),this.defaultImageMaterials.push(this.defaultImageMaterial));return this.defaultImageMaterial},registerUnicodeConverter:function(a){this._unicodeConverter=
- a},registerRtlReorder:function(a){this._rtlReorder=a},getUnicodeConverter:function(){return this._unicodeConverter},getRtlReorder:function(){return this._rtlReorder}});return{ElementComponentSystem:b}}());Object.assign(pc,function(){return{ElementComponentData:function(){this.enabled=!0}}}());Object.assign(pc,function(){var f=function(a,b,d){this._entity=a;this._element=a.element;this.model=new pc.Model;this.node=new pc.GraphNode;this.model.graph=this.node;this.mesh=b;this.meshInstance=new pc.MeshInstance(this.node,this.mesh,d);this.meshInstance.name="ImageElement: "+a.name;this.meshInstance.castShadow=!1;this._meshDirty=this.meshInstance.receiveShadow=!1;this.model.meshInstances.push(this.meshInstance);this._entity.addChild(this.model.graph);this.model._entity=this._entity;this.unmaskMeshInstance=
- null};f.prototype.destroy=function(){this.setMaterial(null);this._element.removeModelFromLayers(this.model);this.model.destroy();this._element=this._entity=this.meshInstance=this.mesh=this.node=this.model=null};f.prototype.setMesh=function(a){this.meshInstance&&(this.mesh=a,this.meshInstance.mesh=a,this.meshInstance.visible=!!a,this.unmaskMeshInstance&&(this.unmaskMeshInstance.mesh=a),this.forceUpdateAabb())};f.prototype.setMask=function(a){if(this.meshInstance){if(a){this.unmaskMeshInstance=new pc.MeshInstance(this.node,
- this.mesh,this.meshInstance.material);this.unmaskMeshInstance.name="Unmask: "+this._entity.name;this.unmaskMeshInstance.castShadow=!1;this.unmaskMeshInstance.receiveShadow=!1;this.unmaskMeshInstance.pick=!1;this.model.meshInstances.push(this.unmaskMeshInstance);for(var b in this.meshInstance.parameters)this.unmaskMeshInstance.setParameter(b,this.meshInstance.parameters[b].data)}else a=this.model.meshInstances.indexOf(this.unmaskMeshInstance),0<=a&&this.model.meshInstances.splice(a,1),this.unmaskMeshInstance=
- null;this._entity.enabled&&this._element.enabled&&(this._element.removeModelFromLayers(this.model),this._element.addModelToLayers(this.model))}};f.prototype.setMaterial=function(a){this.meshInstance&&(this.meshInstance.material=a,this.unmaskMeshInstance&&(this.unmaskMeshInstance.material=a))};f.prototype.setParameter=function(a,b){this.meshInstance&&(this.meshInstance.setParameter(a,b),this.unmaskMeshInstance&&this.unmaskMeshInstance.setParameter(a,b))};f.prototype.deleteParameter=function(a){this.meshInstance&&
- (this.meshInstance.deleteParameter(a),this.unmaskMeshInstance&&this.unmaskMeshInstance.deleteParameter(a))};f.prototype.setUnmaskDrawOrder=function(){if(this.meshInstance){var a=function(b){var c;b=b.getChildren();var d=b.length;if(d){for(var f=0;f<d;f++)b[f].element&&(c=b[f]);return c?(b=a(c))?b:c:null}return null};if(this.unmaskMeshInstance){var b=a(this._entity);this.unmaskMeshInstance.drawOrder=b&&b.element?b.element.drawOrder+b.element.getMaskOffset():this.meshInstance.drawOrder+this._element.getMaskOffset()}}};
- f.prototype.setDrawOrder=function(a){this.meshInstance&&(this.meshInstance.drawOrder=a)};f.prototype.setCull=function(a){if(this.meshInstance){var b=this._element,d=null;a&&b._isScreenCulled()&&(d=function(a){return b.isVisibleForCamera(a)});this.meshInstance.cull=a;this.meshInstance.isVisibleFunc=d;this.unmaskMeshInstance&&(this.unmaskMeshInstance.cull=a,this.unmaskMeshInstance.isVisibleFunc=d)}};f.prototype.setScreenSpace=function(a){this.meshInstance&&(this.meshInstance.screenSpace=a,this.unmaskMeshInstance&&
- (this.unmaskMeshInstance.screenSpace=a))};f.prototype.setLayer=function(a){this.meshInstance&&(this.meshInstance.layer=a,this.unmaskMeshInstance&&(this.unmaskMeshInstance.layer=a))};f.prototype.forceUpdateAabb=function(a){this.meshInstance&&(this.meshInstance._aabbVer=-1,this.unmaskMeshInstance&&(this.unmaskMeshInstance._aabbVer=-1))};f.prototype.setAabbFunc=function(a){this.meshInstance&&(this.meshInstance._updateAabbFunc=a,this.unmaskMeshInstance&&(this.unmaskMeshInstance._updateAabbFunc=a))};var b=
- function(a){this._element=a;this._entity=a.entity;this._system=a.system;this._sprite=this._spriteAsset=this._material=this._materialAsset=this._texture=this._textureAsset=null;this._spriteFrame=0;this._pixelsPerUnit=null;this._rect=new pc.Vec4(0,0,1,1);this._mask=!1;this._maskRef=0;this._positions=[];this._normals=[];this._uvs=[];this._indices=[];this._outerScale=new pc.Vec2;this._outerScaleUniform=new Float32Array(2);this._innerOffset=new pc.Vec4;this._innerOffsetUniform=new Float32Array(4);this._atlasRect=
- new pc.Vec4;this._atlasRectUniform=new Float32Array(4);this._defaultMesh=this._createMesh();this._renderable=new f(this._entity,this._defaultMesh,this._material);this._color=new pc.Color(1,1,1,1);this._colorUniform=new Float32Array([1,1,1]);this._renderable.setParameter("material_emissive",this._colorUniform);this._renderable.setParameter("material_opacity",1);this._updateAabbFunc=this._updateAabb.bind(this);this._onScreenChange(this._element.screen);this._element.on("resize",this._onParentResizeOrPivotChange,
- this);this._element.on("set:pivot",this._onParentResizeOrPivotChange,this);this._element.on("screen:set:screenspace",this._onScreenSpaceChange,this);this._element.on("set:screen",this._onScreenChange,this);this._element.on("set:draworder",this._onDrawOrderChange,this);this._element.on("screen:set:resolution",this._onResolutionChange,this)};Object.assign(b.prototype,{destroy:function(){this.materialAsset=this.spriteAsset=this.textureAsset=null;this._renderable.setMesh(this._defaultMesh);this._renderable.destroy();
- this._defaultMesh=null;this._element.off("resize",this._onParentResizeOrPivotChange,this);this._element.off("set:pivot",this._onParentResizeOrPivotChange,this);this._element.off("screen:set:screenspace",this._onScreenSpaceChange,this);this._element.off("set:screen",this._onScreenChange,this);this._element.off("set:draworder",this._onDrawOrderChange,this);this._element.off("screen:set:resolution",this._onResolutionChange,this)},_onResolutionChange:function(a){},_onParentResizeOrPivotChange:function(){this._renderable.mesh&&
- this._updateMesh(this._renderable.mesh)},_onScreenSpaceChange:function(a){this._updateMaterial(a)},_onScreenChange:function(a,b){a?this._updateMaterial(a.screen.screenSpace):this._updateMaterial(!1)},_onDrawOrderChange:function(a){this._renderable.setDrawOrder(a);if(this.mask&&this._element.screen)this._element.screen.screen.once("syncdraworder",function(){this._renderable.setUnmaskDrawOrder()},this)},_hasUserMaterial:function(){return!!this._materialAsset||!!this._material&&-1===this._system.defaultImageMaterials.indexOf(this._material)},
- _use9Slicing:function(){return this.sprite&&(this.sprite.renderMode===pc.SPRITE_RENDERMODE_SLICED||this.sprite.renderMode===pc.SPRITE_RENDERMODE_TILED)},_updateMaterial:function(a){var b=!!this._mask,d=!(!this.sprite||this.sprite.renderMode!==pc.SPRITE_RENDERMODE_SLICED),e=!(!this.sprite||this.sprite.renderMode!==pc.SPRITE_RENDERMODE_TILED);this._hasUserMaterial()||(this._material=this._system.getImageElementMaterial(a,b,d,e));this._renderable&&(this._renderable.setCull(!0),this._renderable.setMaterial(this._material),
- this._renderable.setScreenSpace(a),this._renderable.setLayer(a?pc.LAYER_HUD:pc.LAYER_WORLD))},_createMesh:function(){var a=this._element.calculatedWidth,b=this._element.calculatedHeight;this._positions[0]=0;this._positions[1]=0;this._positions[2]=0;this._positions[3]=a;this._positions[4]=0;this._positions[5]=0;this._positions[6]=a;this._positions[7]=b;this._positions[8]=0;this._positions[9]=0;this._positions[10]=b;for(a=this._positions[11]=0;12>a;a+=3)this._normals[a]=0,this._normals[a+1]=0,this._normals[a+
- 2]=1;this._uvs[0]=this._rect.x;this._uvs[1]=this._rect.y;this._uvs[2]=this._rect.x+this._rect.z;this._uvs[3]=this._rect.y;this._uvs[4]=this._rect.x+this._rect.z;this._uvs[5]=this._rect.y+this._rect.w;this._uvs[6]=this._rect.x;this._uvs[7]=this._rect.y+this._rect.w;this._indices[0]=0;this._indices[1]=1;this._indices[2]=3;this._indices[3]=2;this._indices[4]=3;this._indices[5]=1;a=pc.createMesh(this._system.app.graphicsDevice,this._positions,{uvs:this._uvs,normals:this._normals,indices:this._indices});
- this._updateMesh(a);return a},_updateMesh:function(a){var b;b=this._element;var d=b.calculatedWidth,e=b.calculatedHeight,f=b._isScreenSpace();this._updateMaterial(f);this._renderable&&this._renderable.forceUpdateAabb();if(!this.sprite||this.sprite.renderMode!==pc.SPRITE_RENDERMODE_SLICED&&this.sprite.renderMode!==pc.SPRITE_RENDERMODE_TILED){this._positions[0]=0;this._positions[1]=0;this._positions[2]=0;this._positions[3]=d;this._positions[4]=0;this._positions[5]=0;this._positions[6]=d;this._positions[7]=
- e;this._positions[8]=0;this._positions[9]=0;this._positions[10]=e;this._positions[11]=0;var f=b.pivot.x,l=b.pivot.y;for(b=0;b<this._positions.length;b+=3)this._positions[b]-=f*d,this._positions[b+1]-=l*e;e=d=1;b=this._rect;this._sprite&&this._sprite.frameKeys[this._spriteFrame]&&this._sprite.atlas&&(f=this._sprite.atlas.frames[this._sprite.frameKeys[this._spriteFrame]])&&(b=f.rect,d=this._sprite.atlas.texture.width,e=this._sprite.atlas.texture.height);this._uvs[0]=b.x/d;this._uvs[1]=b.y/e;this._uvs[2]=
- (b.x+b.z)/d;this._uvs[3]=b.y/e;this._uvs[4]=(b.x+b.z)/d;this._uvs[5]=(b.y+b.w)/e;this._uvs[6]=b.x/d;this._uvs[7]=(b.y+b.w)/e;d=new pc.VertexIterator(a.vertexBuffer);for(b=0;4>b;b++)d.element[pc.SEMANTIC_POSITION].set(this._positions[3*b+0],this._positions[3*b+1],this._positions[3*b+2]),d.element[pc.SEMANTIC_NORMAL].set(this._normals[3*b+0],this._normals[3*b+1],this._normals[3*b+2]),d.element[pc.SEMANTIC_TEXCOORD0].set(this._uvs[2*b+0],this._uvs[2*b+1]),d.next();d.end();a.aabb.compute(this._positions);
- this._renderable&&(this._renderable.node.setLocalScale(1,1,1),this._renderable.node.setLocalPosition(0,0,0),this._renderable.setAabbFunc(null))}else a=this._sprite.atlas.frames[this._sprite.frameKeys[this._spriteFrame]],f=2/a.rect.z,l=2/a.rect.w,this._innerOffset.set(a.border.x*f,a.border.y*l,a.border.z*f,a.border.w*l),f=this.sprite.atlas.texture,this._atlasRect.set(a.rect.x/f.width,a.rect.y/f.height,a.rect.z/f.width,a.rect.w/f.height),l=null!==this._pixelsPerUnit?this._pixelsPerUnit:this.sprite.pixelsPerUnit,
- f=a.rect.z/l,a=a.rect.w/l,this._outerScale.set(Math.max(d,this._innerOffset.x*f),Math.max(e,this._innerOffset.y*a)),l=a,this._outerScale.x/=f,this._outerScale.y/=a,f*=pc.math.clamp(d/(this._innerOffset.x*f),1E-4,1),l*=pc.math.clamp(e/(this._innerOffset.y*a),1E-4,1),this._renderable&&(this._innerOffsetUniform[0]=this._innerOffset.x,this._innerOffsetUniform[1]=this._innerOffset.y,this._innerOffsetUniform[2]=this._innerOffset.z,this._innerOffsetUniform[3]=this._innerOffset.w,this._renderable.setParameter("innerOffset",
- this._innerOffsetUniform),this._atlasRectUniform[0]=this._atlasRect.x,this._atlasRectUniform[1]=this._atlasRect.y,this._atlasRectUniform[2]=this._atlasRect.z,this._atlasRectUniform[3]=this._atlasRect.w,this._renderable.setParameter("atlasRect",this._atlasRectUniform),this._outerScaleUniform[0]=this._outerScale.x,this._outerScaleUniform[1]=this._outerScale.y,this._renderable.setParameter("outerScale",this._outerScaleUniform),this._renderable.setAabbFunc(this._updateAabbFunc),this._renderable.node.setLocalScale(f,
- l,1),this._renderable.node.setLocalPosition((.5-b.pivot.x)*d,(.5-b.pivot.y)*e,0));this._meshDirty=!1},_updateSprite:function(){var a=!1,b=null;this._sprite&&this._sprite.atlas&&(b=this._sprite.meshes[this.spriteFrame],a=this._sprite.renderMode===pc.SPRITE_RENDERMODE_SLICED||this._sprite.renderMode===pc.SPRITE_RENDERMODE_TILED);if(this.mesh=a?b:this._defaultMesh)this._element._beingInitialized?this._meshDirty=!0:this._updateMesh(this.mesh)},_updateAabb:function(a){a.center.set(0,0,0);a.halfExtents.set(.5*
- this._outerScale.x,.5*this._outerScale.y,.001);a.setFromTransformedAabb(a,this._renderable.node.getWorldTransform());return a},_toggleMask:function(){this._element._dirtifyMask();var a=this._element._isScreenSpace();this._updateMaterial(a);this._renderable.setMask(!!this._mask)},_onMaterialLoad:function(a){this.material=a.resource},_onMaterialAdded:function(a){this._system.app.assets.off("add:"+a.id,this._onMaterialAdded,this);this._materialAsset===a.id&&this._bindMaterialAsset(a)},_bindMaterialAsset:function(a){this._entity.enabled&&
- (a.on("load",this._onMaterialLoad,this),a.on("change",this._onMaterialChange,this),a.on("remove",this._onMaterialRemove,this),a.resource?this._onMaterialLoad(a):this._system.app.assets.load(a))},_unbindMaterialAsset:function(a){a.off("load",this._onMaterialLoad,this);a.off("change",this._onMaterialChange,this);a.off("remove",this._onMaterialRemove,this)},_onMaterialChange:function(){},_onMaterialRemove:function(){},_onTextureAdded:function(a){this._system.app.assets.off("add:"+a.id,this._onTextureAdded,
- this);this._textureAsset===a.id&&this._bindTextureAsset(a)},_bindTextureAsset:function(a){this._entity.enabled&&(a.on("load",this._onTextureLoad,this),a.on("change",this._onTextureChange,this),a.on("remove",this._onTextureRemove,this),a.resource?this._onTextureLoad(a):this._system.app.assets.load(a))},_unbindTextureAsset:function(a){a.off("load",this._onTextureLoad,this);a.off("change",this._onTextureChange,this);a.off("remove",this._onTextureRemove,this)},_onTextureLoad:function(a){this.texture=
- a.resource},_onTextureChange:function(a){},_onTextureRemove:function(a){},_onSpriteAssetAdded:function(a){this._system.app.assets.off("add:"+a.id,this._onSpriteAssetAdded,this);this._spriteAsset===a.id&&this._bindSpriteAsset(a)},_bindSpriteAsset:function(a){this._entity.enabled&&(a.on("load",this._onSpriteAssetLoad,this),a.on("change",this._onSpriteAssetChange,this),a.on("remove",this._onSpriteAssetRemove,this),a.resource?this._onSpriteAssetLoad(a):this._system.app.assets.load(a))},_unbindSpriteAsset:function(a){a.off("load",
- this._onSpriteAssetLoad,this);a.off("change",this._onSpriteAssetChange,this);a.off("remove",this._onSpriteAssetRemove,this);a.data.textureAtlasAsset&&this._system.app.assets.off("load:"+a.data.textureAtlasAsset,this._onTextureAtlasLoad,this)},_onSpriteAssetLoad:function(a){if(a&&a.resource)if(a.resource.atlas)this.sprite=a.resource;else{if(a=a.data.textureAtlasAsset){var b=this._system.app.assets;b.off("load:"+a,this._onTextureAtlasLoad,this);b.once("load:"+a,this._onTextureAtlasLoad,this)}}else this.sprite=
- null},_onSpriteAssetChange:function(a){this._onSpriteAssetLoad(a)},_onSpriteAssetRemove:function(a){},_bindSprite:function(a){a.on("set:meshes",this._onSpriteMeshesChange,this);a.on("set:pixelsPerUnit",this._onSpritePpuChange,this);a.on("set:atlas",this._onAtlasTextureChange,this);if(a.atlas)a.atlas.on("set:texture",this._onAtlasTextureChange,this)},_unbindSprite:function(a){a.off("set:meshes",this._onSpriteMeshesChange,this);a.off("set:pixelsPerUnit",this._onSpritePpuChange,this);a.off("set:atlas",
- this._onAtlasTextureChange,this);a.atlas&&a.atlas.off("set:texture",this._onAtlasTextureChange,this)},_onSpriteMeshesChange:function(){this._sprite&&(this._spriteFrame=pc.math.clamp(this._spriteFrame,0,this._sprite.frameKeys.length-1));this._updateSprite()},_onSpritePpuChange:function(){this.sprite.renderMode!==pc.SPRITE_RENDERMODE_SIMPLE&&null===this._pixelsPerUnit&&this._updateSprite()},_onAtlasTextureChange:function(){this.sprite&&this.sprite.atlas&&this.sprite.atlas.texture?(this._renderable.setParameter("texture_emissiveMap",
- this._sprite.atlas.texture),this._renderable.setParameter("texture_opacityMap",this._sprite.atlas.texture)):(this._renderable.deleteParameter("texture_emissiveMap"),this._renderable.deleteParameter("texture_opacityMap"))},_onTextureAtlasLoad:function(a){a=this._spriteAsset;a instanceof pc.Asset?this._onSpriteAssetLoad(a):this._onSpriteAssetLoad(this._system.app.assets.get(a))},onEnable:function(){var a;this._materialAsset&&(a=this._system.app.assets.get(this._materialAsset))&&a.resource!==this._material&&
- this._bindMaterialAsset(a);this._textureAsset&&(a=this._system.app.assets.get(this._textureAsset))&&a.resource!==this._texture&&this._bindTextureAsset(a);this._spriteAsset&&(a=this._system.app.assets.get(this._spriteAsset))&&a.resource!==this._sprite&&this._bindSpriteAsset(a);this._element.addModelToLayers(this._renderable.model)},onDisable:function(){this._element.removeModelFromLayers(this._renderable.model)},_setStencil:function(a){this._renderable.meshInstance.stencilFront=a;this._renderable.meshInstance.stencilBack=
- a;a=0;this._element.maskedBy&&(a=this._element.maskedBy.element._image._maskRef);this._renderable.unmaskMeshInstance&&(a=new pc.StencilParameters({ref:a+1,func:pc.FUNC_EQUAL,zpass:pc.STENCILOP_DECREMENT}),this._renderable.unmaskMeshInstance.stencilFront=a,this._renderable.unmaskMeshInstance.stencilBack=a)}});Object.defineProperty(b.prototype,"color",{get:function(){return this._color},set:function(a){var b=a.r,d=a.g;a=a.b;if(this._color.r!==b||this._color.g!==d||this._color.b!==a)this._color.r=b,
- this._color.g=d,this._color.b=a,this._colorUniform[0]=b,this._colorUniform[1]=d,this._colorUniform[2]=a,this._renderable.setParameter("material_emissive",this._colorUniform),this._element&&this._element.fire("set:color",this._color)}});Object.defineProperty(b.prototype,"opacity",{get:function(){return this._color.a},set:function(a){a!==this._color.a&&(this._color.a=a,this._renderable.setParameter("material_opacity",a),this._element&&this._element.fire("set:opacity",a))}});Object.defineProperty(b.prototype,
- "rect",{get:function(){return this._rect},set:function(a){var b,d,e;a instanceof pc.Vec4?(b=a.x,d=a.y,e=a.z,a=a.w):(b=a[0],d=a[1],e=a[2],a=a[3]);if(b!==this._rect.x||d!==this._rect.y||e!==this._rect.z||a!==this._rect.w)this._rect.set(b,d,e,a),this._renderable.mesh&&(this._element._beingInitialized?this._meshDirty=!0:this._updateMesh(this._renderable.mesh))}});Object.defineProperty(b.prototype,"material",{get:function(){return this._material},set:function(a){this._material!==a&&(a||(a=this._element._isScreenSpace(),
- a=this.mask?a?this._system.defaultScreenSpaceImageMaskMaterial:this._system.defaultImageMaskMaterial:a?this._system.defaultScreenSpaceImageMaterial:this._system.defaultImageMaterial),this._material=a)&&(this._renderable.setMaterial(a),this._hasUserMaterial()?(this._renderable.deleteParameter("material_opacity"),this._renderable.deleteParameter("material_emissive")):(this._colorUniform[0]=this._color.r,this._colorUniform[1]=this._color.g,this._colorUniform[2]=this._color.b,this._renderable.setParameter("material_emissive",
- this._colorUniform),this._renderable.setParameter("material_opacity",this._color.a)))}});Object.defineProperty(b.prototype,"materialAsset",{get:function(){return this._materialAsset},set:function(a){var b=this._system.app.assets,d=a;a instanceof pc.Asset&&(d=a.id);this._materialAsset!==d&&(this._materialAsset&&(b.off("add:"+this._materialAsset,this._onMaterialAdded,this),a=b.get(this._materialAsset))&&(a.off("load",this._onMaterialLoad,this),a.off("change",this._onMaterialChange,this),a.off("remove",
- this._onMaterialRemove,this)),(this._materialAsset=d)?(d=b.get(this._materialAsset))?this._bindMaterialAsset(d):(this.material=null,b.on("add:"+this._materialAsset,this._onMaterialAdded,this)):this.material=null)}});Object.defineProperty(b.prototype,"texture",{get:function(){return this._texture},set:function(a){if(this._texture!==a){if(this._textureAsset){var b=this._system.app.assets.get(this._textureAsset);b&&b.resource!==a&&(this.textureAsset=null)}(this._texture=a)?(this._spriteAsset&&(this.spriteAsset=
- null),this._renderable.setParameter("texture_emissiveMap",this._texture),this._renderable.setParameter("texture_opacityMap",this._texture),this._colorUniform[0]=this._color.r,this._colorUniform[1]=this._color.g,this._colorUniform[2]=this._color.b,this._renderable.setParameter("material_emissive",this._colorUniform),this._renderable.setParameter("material_opacity",this._color.a)):(this._renderable.deleteParameter("texture_emissiveMap"),this._renderable.deleteParameter("texture_opacityMap"))}}});Object.defineProperty(b.prototype,
- "textureAsset",{get:function(){return this._textureAsset},set:function(a){var b=this._system.app.assets,d=a;a instanceof pc.Asset&&(d=a.id);this._textureAsset!==d&&(this._textureAsset&&(b.off("add:"+this._textureAsset,this._onTextureAdded,this),a=b.get(this._textureAsset))&&(a.off("load",this._onTextureLoad,this),a.off("change",this._onTextureChange,this),a.off("remove",this._onTextureRemove,this)),(this._textureAsset=d)?(d=b.get(this._textureAsset))?this._bindTextureAsset(d):(this.texture=null,b.on("add:"+
- this._textureAsset,this._onTextureAdded,this)):this.texture=null)}});Object.defineProperty(b.prototype,"spriteAsset",{get:function(){return this._spriteAsset},set:function(a){var b=this._system.app.assets,d=a;a instanceof pc.Asset&&(d=a.id);this._spriteAsset!==d&&(this._spriteAsset&&(b.off("add:"+this._spriteAsset,this._onSpriteAssetAdded,this),(a=b.get(this._spriteAsset))&&this._unbindSpriteAsset(a)),(this._spriteAsset=d)?(a=b.get(this._spriteAsset))?this._bindSpriteAsset(a):(this.sprite=null,b.on("add:"+
- this._spriteAsset,this._onSpriteAssetAdded,this)):this.sprite=null,this._element&&this._element.fire("set:spriteAsset",d))}});Object.defineProperty(b.prototype,"sprite",{get:function(){return this._sprite},set:function(a){if(this._sprite!==a){this._sprite&&this._unbindSprite(this._sprite);if(this._spriteAsset){var b=this._system.app.assets.get(this._spriteAsset);b&&b.resource!==a&&(this.spriteAsset=null)}if(this._sprite=a)this._bindSprite(this._sprite),this._textureAsset&&(this.textureAsset=null);
- this._sprite&&this._sprite.atlas&&this._sprite.atlas.texture?(this._renderable.setParameter("texture_emissiveMap",this._sprite.atlas.texture),this._renderable.setParameter("texture_opacityMap",this._sprite.atlas.texture)):(this._renderable.deleteParameter("texture_emissiveMap"),this._renderable.deleteParameter("texture_opacityMap"));this._sprite&&(this._spriteFrame=pc.math.clamp(this._spriteFrame,0,this._sprite.frameKeys.length-1));this._updateSprite()}}});Object.defineProperty(b.prototype,"spriteFrame",
- {get:function(){return this._spriteFrame},set:function(a){var b=this._spriteFrame;this._spriteFrame=this._sprite?pc.math.clamp(a,0,this._sprite.frameKeys.length-1):a;this._spriteFrame!==b&&(this._updateSprite(),this._element&&this._element.fire("set:spriteFrame",a))}});Object.defineProperty(b.prototype,"mesh",{get:function(){return this._renderable.mesh},set:function(a){this._renderable.setMesh(a);this._defaultMesh===a?this._renderable.setAabbFunc(null):this._renderable.setAabbFunc(this._updateAabbFunc)}});
- Object.defineProperty(b.prototype,"mask",{get:function(){return this._mask},set:function(a){this._mask!==a&&(this._mask=a,this._toggleMask())}});Object.defineProperty(b.prototype,"pixelsPerUnit",{get:function(){return this._pixelsPerUnit},set:function(a){this._pixelsPerUnit!==a&&(this._pixelsPerUnit=a,!this._sprite||this._sprite.renderMode!==pc.SPRITE_RENDERMODE_SLICED&&this._sprite.renderMode!==pc.SPRITE_RENDERMODE_TILED||this._updateSprite())}});Object.defineProperty(b.prototype,"aabb",{get:function(){return this._renderable.meshInstance?
- this._renderable.meshInstance.aabb:null}});return{ImageElement:b}}());Object.assign(pc,function(){var f=function(){this.quad=this.count=0;this.lines={};this.positions=[];this.normals=[];this.uvs=[];this.indices=[];this.meshInstance=null},b=function(a){this._element=a;this._system=a.system;this._entity=a.entity;this._text="";this._font=this._fontAsset=this._i18nKey=null;this._color=new pc.Color(1,1,1,1);this._colorUniform=new Float32Array(3);this._spacing=1;this._lineHeight=this._fontSize=32;this._wrapLines=!1;this._drawOrder=0;this._alignment=new pc.Vec2(.5,.5);this._autoHeight=
- this._autoWidth=!0;this.height=this.width=0;this._node=new pc.GraphNode;this._model=new pc.Model;this._model.graph=this._node;this._entity.addChild(this._node);this._meshInfo=[];this._material=null;this._aabbDirty=!0;this._aabb=new pc.BoundingBox;this._noResize=!1;this._maskedMaterialSrc=this._currentMaterialType=null;this._unicodeConverter=this._rtlReorder=!1;this._outlineColor=new pc.Color(0,0,0,1);this._outlineColorUniform=new Float32Array(4);this._outlineThicknessScale=.2;this._outlineThickness=
- 0;this._shadowColor=new pc.Color(0,0,0,1);this._shadowColorUniform=new Float32Array(4);this._shadowOffsetScale=.005;this._shadowOffset=new pc.Vec2(0,0);this._shadowOffsetUniform=new Float32Array(2);this._onScreenChange(this._element.screen);a.on("resize",this._onParentResize,this);this._element.on("set:screen",this._onScreenChange,this);a.on("screen:set:screenspace",this._onScreenSpaceChange,this);a.on("set:draworder",this._onDrawOrderChange,this);a.on("set:pivot",this._onPivotChange,this);this._system.app.i18n.on("set:locale",
- this._resetLocalizedText,this);this._system.app.i18n.on("data:add",this._onLocalizationData,this);this._system.app.i18n.on("data:remove",this._onLocalizationData,this)},a=/^[\r\n]$/,c=/^[ \t]$/,d=/^[ \t\-]$/;Object.assign(b.prototype,{destroy:function(){this._setMaterial(null);this._model&&(this._element.removeModelFromLayers(this._model),this._model.destroy(),this._model=null);this.font=this.fontAsset=null;this._element.off("resize",this._onParentResize,this);this._element.off("set:screen",this._onScreenChange,
- this);this._element.off("screen:set:screenspace",this._onScreenSpaceChange,this);this._element.off("set:draworder",this._onDrawOrderChange,this);this._element.off("set:pivot",this._onPivotChange,this)},_onParentResize:function(a,b){this._noResize||this._font&&this._updateText(this._text)},_onScreenChange:function(a){a?this._updateMaterial(a.screen.screenSpace):this._updateMaterial(!1)},_onScreenSpaceChange:function(a){this._updateMaterial(a)},_onDrawOrderChange:function(a){this._drawOrder=a;if(this._model){var b,
- c;b=0;for(c=this._model.meshInstances.length;b<c;b++)this._model.meshInstances[b].drawOrder=a}},_onPivotChange:function(a){this._font&&this._updateText()},_onLocalizationData:function(a,b){this._i18nKey&&b[this._i18nKey]&&this._resetLocalizedText()},_resetLocalizedText:function(){this._i18nKey&&this._setText(this._system.app.i18n.getText(this._i18nKey))},_setText:function(a){if(this.unicodeConverter){var b=this._system.getUnicodeConverter();b?a=b(a):console.warn("Element created with unicodeConverter option but no unicodeConverter function registered")}this._text!==
- a&&(this._font&&this._updateText(a),this._text=a)},_updateText:function(a){var b,c;void 0===a&&(a=this._text);a=pc.string.getSymbols(a);this.rtlReorder&&((b=this._system.app.systems.element.getRtlReorder())?a=b(a):console.warn("Element created with rtlReorder option but no rtlReorder function registered"));c=a.length;0===c&&(c=1,a=[" "]);var d={},e;for(b=0;b<c;b++)e=a[b],(e=this._font.data.chars[e])||(e=this._font.data.chars[" "]?this._font.data.chars[" "]:this._font.data.chars[Object.keys(this._font.data.chars)[0]]),
- e=e.map,d[e]||(d[e]=0),d[e]++;e=!1;var f=this._element,n=f._isScreenSpace(),q=f._isScreenCulled(),m=function(a){return f.isVisibleForCamera(a)};b=0;for(c=this._meshInfo.length;b<c;b++){var r=d[b]||0,t=this._meshInfo[b];if(t.count!==r)if(e||(f.removeModelFromLayers(this._model),e=!0),t.count=r,t.positions.length=t.normals.length=12*r,t.indices.length=6*r,t.uvs.length=8*r,t.meshInstance&&(this._removeMeshInstance(t.meshInstance),t.meshInstance.material=null),0===r)t.meshInstance=null;else{for(var v=
- 0;v<r;v++)t.indices[6*v+0]=4*v,t.indices[6*v+1]=4*v+1,t.indices[6*v+2]=4*v+3,t.indices[6*v+3]=4*v+2,t.indices[6*v+4]=4*v+3,t.indices[6*v+5]=4*v+1,t.normals[12*v+0]=0,t.normals[12*v+1]=0,t.normals[12*v+2]=-1,t.normals[12*v+3]=0,t.normals[12*v+4]=0,t.normals[12*v+5]=-1,t.normals[12*v+6]=0,t.normals[12*v+7]=0,t.normals[12*v+8]=-1,t.normals[12*v+9]=0,t.normals[12*v+10]=0,t.normals[12*v+11]=-1;r=pc.createMesh(this._system.app.graphicsDevice,t.positions,{uvs:t.uvs,normals:t.normals,indices:t.indices});
- r=new pc.MeshInstance(this._node,r,this._material);r.name="Text Element: "+this._entity.name;r.castShadow=!1;r.receiveShadow=!1;r.cull=!n;r.screenSpace=n;r.drawOrder=this._drawOrder;q&&(r.cull=!0,r.isVisibleFunc=m);this._setTextureParams(r,this._font.textures[b]);this._colorUniform[0]=this._color.r;this._colorUniform[1]=this._color.g;this._colorUniform[2]=this._color.b;r.setParameter("material_emissive",this._colorUniform);r.setParameter("material_opacity",this._color.a);r.setParameter("font_sdfIntensity",
- this._font.intensity);r.setParameter("font_pxrange",this._getPxRange(this._font));r.setParameter("font_textureWidth",this._font.data.info.maps[b].width);this._outlineColorUniform[0]=this._outlineColor.r;this._outlineColorUniform[1]=this._outlineColor.g;this._outlineColorUniform[2]=this._outlineColor.b;this._outlineColorUniform[3]=this._outlineColor.a;r.setParameter("outline_color",this._outlineColorUniform);r.setParameter("outline_thickness",this._outlineThicknessScale*this._outlineThickness);this._shadowColorUniform[0]=
- this._shadowColor.r;this._shadowColorUniform[1]=this._shadowColor.g;this._shadowColorUniform[2]=this._shadowColor.b;this._shadowColorUniform[3]=this._shadowColor.a;r.setParameter("shadow_color",this._shadowColorUniform);this._shadowOffsetUniform[0]=this._shadowOffsetScale*this._shadowOffset.x;this._shadowOffsetUniform[1]=this._shadowOffsetScale*this._shadowOffset.y;r.setParameter("shadow_offset",this._shadowOffsetUniform);t.meshInstance=r;this._model.meshInstances.push(r)}}this._element.maskedBy&&
- this._element._setMaskedBy(this._element.maskedBy);e&&this._element.enabled&&this._entity.enabled&&this._element.addModelToLayers(this._model);this._updateMeshes(a)},_removeMeshInstance:function(a){var b,c,d=a.mesh;if(d&&(d.vertexBuffer&&d.vertexBuffer.destroy(),d.indexBuffer))for(b=0,c=d.indexBuffer.length;b<c;b++)d.indexBuffer[b].destroy();a=this._model.meshInstances.indexOf(a);-1!==a&&this._model.meshInstances.splice(a,1)},_setMaterial:function(a){var b,c;this._material=a;if(this._model)for(b=
- 0,c=this._model.meshInstances.length;b<c;b++)this._model.meshInstances[b].material=a},_updateMaterial:function(a){var b=this._element,c=b._isScreenCulled(),d=function(a){return b.isVisibleForCamera(a)};this._material=this._system.getTextElementMaterial(a,this._font&&this._font.type===pc.FONT_MSDF);if(this._model)for(var e=0,f=this._model.meshInstances.length;e<f;e++){var n=this._model.meshInstances[e];n.cull=!a;n.material=this._material;n.screenSpace=a;c?(n.cull=!0,n.isVisibleFunc=d):n.isVisibleFunc=
- null}},_updateMeshes:function(b){function e(a,c){k._lineWidths.push(c);var d=b.slice(v,a).join("");k._lineContents.push(d);h=0;q-=k._lineHeight;m++;r=u=y=0;v=a}var f=this._font.data,k=this;this.height=this.width=0;this._lineWidths=[];this._lineContents=[];var p=b.length,h=0,n=0,q=0,m=1,r=0,t=0,v=0,y=0,u=0,w=1E-4<=Math.abs(this._element.anchor.x-this._element.anchor.z),x=this._element.calculatedWidth;if(this.autoWidth&&!w||!this._wrapLines)x=Number.POSITIVE_INFINITY;var D=0,w=0,z=1,C,A,B;for(A in f.chars)B=
- f.chars[A],z=B.height/32*this._fontSize/B.height,B.bounds&&(D=Math.min(D,B.bounds[1]*z),w=Math.max(w,B.bounds[3]*z));for(A=0;A<this._meshInfo.length;A++)this._meshInfo[A].quad=0,this._meshInfo[A].lines={};for(A=0;A<p;A++){C=b[A];var J=0,F=0,H=0,E=1,G=0,I=0;(B=f.chars[C])||(B=f.chars[" "]?f.chars[" "]:f.chars[Object.keys(f.chars)[0]]);B?(J=B.scale||1,F=(B.width+B.height)/2,z=F/32*this._fontSize/F,E=F/32*this._fontSize/J,H=B.xadvance*z,J=B.xoffset*z,F=B.yoffset*z,B.bounds?(I=(B.bounds[2]-B.bounds[0])*
- z,G=B.bounds[0]*z):(I=J,G=0)):console.error("Couldn't substitute missing character: '"+C+"'");var Q=a.test(C),V=d.test(C),W=c.test(C);if(Q)e(A,n),t=A+1,v=A+1;else{z=this._meshInfo[B&&B.map||0];if(h+I+G>=x&&0<u&&!W)if(0===y)t=A,e(A,n);else{B=Math.max(A-t,0);if(1>=this._meshInfo.length)z.lines[m-1]-=B,z.quad-=B;else for(C=t;C<A;C++)J=f.chars[b[C]],J=this._meshInfo[J&&J.map||0],--J.lines[m-1],--J.quad;A-=B+1;e(t,r);continue}B=z.quad;z.lines[m-1]=B;z.positions[12*B+0]=h-J;z.positions[12*B+1]=q-F;z.positions[12*
- B+2]=0;z.positions[12*B+3]=h-J+E;z.positions[12*B+4]=q-F;z.positions[12*B+5]=0;z.positions[12*B+6]=h-J+E;z.positions[12*B+7]=q-F+E;z.positions[12*B+8]=0;z.positions[12*B+9]=h-J;z.positions[12*B+10]=q-F+E;z.positions[12*B+11]=0;this.width=Math.max(this.width,h+I+G);this.height=Math.max(this.height,w-(q+D));h+=this._spacing*H;W||Q||(n=h);V&&(y++,r=n,t=A+1);u++;C=this._getUv(C);z.uvs[8*B+0]=C[0];z.uvs[8*B+1]=C[1];z.uvs[8*B+2]=C[2];z.uvs[8*B+3]=C[1];z.uvs[8*B+4]=C[2];z.uvs[8*B+5]=C[3];z.uvs[8*B+6]=C[0];
- z.uvs[8*B+7]=C[3];z.quad++}}v<p&&e(p,h);this._noResize=!0;this.autoWidth=this._autoWidth;this.autoHeight=this._autoHeight;this._noResize=!1;f=this._element.pivot.x;p=this._element.pivot.y;n=this._alignment.x;t=this._alignment.y;for(A=0;A<this._meshInfo.length;A++)if(0!==this._meshInfo[A].count){B=0;for(var U in this._meshInfo[A].lines){x=this._meshInfo[A].lines[U];D=-f*this._element.calculatedWidth+n*(this._element.calculatedWidth-this._lineWidths[parseInt(U,10)]);for(C=(1-p)*this._element.calculatedHeight-
- w-(1-t)*(this._element.calculatedHeight-this.height);B<=x;B++)this._meshInfo[A].positions[12*B]+=D,this._meshInfo[A].positions[12*B+3]+=D,this._meshInfo[A].positions[12*B+6]+=D,this._meshInfo[A].positions[12*B+9]+=D,this._meshInfo[A].positions[12*B+1]+=C,this._meshInfo[A].positions[12*B+4]+=C,this._meshInfo[A].positions[12*B+7]+=C,this._meshInfo[A].positions[12*B+10]+=C;B=x+1}x=4*this._meshInfo[A].count;D=4*this._meshInfo[A].quad;B=new pc.VertexIterator(this._meshInfo[A].meshInstance.mesh.vertexBuffer);
- for(C=0;C<x;C++)C>=D?(B.element[pc.SEMANTIC_POSITION].set(0,0,0),B.element[pc.SEMANTIC_TEXCOORD0].set(0,0)):(B.element[pc.SEMANTIC_POSITION].set(this._meshInfo[A].positions[3*C+0],this._meshInfo[A].positions[3*C+1],this._meshInfo[A].positions[3*C+2]),B.element[pc.SEMANTIC_TEXCOORD0].set(this._meshInfo[A].uvs[2*C+0],this._meshInfo[A].uvs[2*C+1])),B.next();B.end();this._meshInfo[A].meshInstance.mesh.aabb.compute(this._meshInfo[A].positions);this._meshInfo[A].meshInstance._aabbVer=-1}this._aabbDirty=
- !0},_onFontAdded:function(a){this._system.app.assets.off("add:"+a.id,this._onFontAdded,this);a.id===this._fontAsset&&this._bindFont(a)},_bindFont:function(a){this._entity.enabled&&(a.on("load",this._onFontLoad,this),a.on("change",this._onFontChange,this),a.on("remove",this._onFontRemove,this),a.resource?this._onFontLoad(a):this._system.app.assets.load(a))},_unbindFont:function(a){a.off("load",this._onFontLoad,this);a.off("change",this._onFontChange,this);a.off("remove",this._onFontRemove,this)},_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;b<a;b++)this._meshInfo[b]&&(c=this._meshInfo[b].meshInstance)&&(c.setParameter("font_sdfIntensity",this._font.intensity),c.setParameter("font_pxrange",this._getPxRange(this._font)),c.setParameter("font_textureWidth",this._font.data.info.maps[b].width))},_onFontRemove:function(a){},_setTextureParams:function(a,
- b){this._font&&(this._font.type===pc.FONT_MSDF?(a.deleteParameter("texture_emissiveMap"),a.deleteParameter("texture_opacityMap"),a.setParameter("texture_msdfMap",b)):this._font.type===pc.FONT_BITMAP&&(a.deleteParameter("texture_msdfMap"),a.setParameter("texture_emissiveMap",b),a.setParameter("texture_opacityMap",b)))},_getPxRange:function(a){a=Object.keys(this._font.data.chars);for(var b=0;b<a.length;b++){var c=this._font.data.chars[a[b]];if(c.scale&&c.range)return c.scale*c.range}return 2},_getUv:function(a){var b=
- this._font.data;if(!b.chars[a])return b.chars[" "]?this._getUv(" "):[0,0,0,0];var c=b.chars[a].map,d=b.info.maps[c].width,c=b.info.maps[c].height,e=b.chars[a].x,f=b.chars[a].y,n=1-b.chars[a].height/c;return[e/d,n-f/c,(e+b.chars[a].width)/d,n-(f-b.chars[a].height)/c]},onEnable:function(){if(this._fontAsset){var a=this._system.app.assets.get(this._fontAsset);a&&a.resource!==this._font&&(this._unbindFont(a),this._bindFont(a))}this._model&&this._element.addModelToLayers(this._model)},onDisable:function(){this._model&&
- this._element.removeModelFromLayers(this._model)},_setStencil:function(a){if(this._model)for(var b=this._model.meshInstances,c=0;c<b.length;c++)b[c].stencilFront=a,b[c].stencilBack=a}});Object.defineProperty(b.prototype,"text",{get:function(){return this._text},set:function(a){this._i18nKey=null;this._setText(a&&a.toString()||"")}});Object.defineProperty(b.prototype,"key",{get:function(){return this._i18nKey},set:function(a){a=null!==a?a.toString():null;this._i18nKey!==a&&(this._i18nKey=a,this._resetLocalizedText())}});
- Object.defineProperty(b.prototype,"color",{get:function(){return this._color},set:function(a){var b=a.r,c=a.g;a=a.b;if(this._color.r!==b||this._color.g!==c||this._color.b!==a)if(this._color.r=b,this._color.g=c,this._color.b=a,this._model)for(this._colorUniform[0]=this._color.r,this._colorUniform[1]=this._color.g,this._colorUniform[2]=this._color.b,b=0,c=this._model.meshInstances.length;b<c;b++)this._model.meshInstances[b].setParameter("material_emissive",this._colorUniform)}});Object.defineProperty(b.prototype,
- "opacity",{get:function(){return this._color.a},set:function(a){if(this._color.a!==a&&(this._color.a=a,this._model))for(var b=0,c=this._model.meshInstances.length;b<c;b++)this._model.meshInstances[b].setParameter("material_opacity",a)}});Object.defineProperty(b.prototype,"lineHeight",{get:function(){return this._lineHeight},set:function(a){var b=this._lineHeight;this._lineHeight=a;b!==a&&this._font&&this._updateText()}});Object.defineProperty(b.prototype,"wrapLines",{get:function(){return this._wrapLines},
- set:function(a){var b=this._wrapLines;this._wrapLines=a;b!==a&&this._font&&this._updateText()}});Object.defineProperty(b.prototype,"lines",{get:function(){return this._lineContents}});Object.defineProperty(b.prototype,"spacing",{get:function(){return this._spacing},set:function(a){var b=this._spacing;this._spacing=a;b!==a&&this._font&&this._updateText()}});Object.defineProperty(b.prototype,"fontSize",{get:function(){return this._fontSize},set:function(a){var b=this._fontSize;this._fontSize=a;b!==
- a&&this._font&&this._updateText()}});Object.defineProperty(b.prototype,"fontAsset",{get:function(){return this._fontAsset},set:function(a){var b=this._system.app.assets,c=a;a instanceof pc.Asset&&(c=a.id);if(this._fontAsset!==c&&(this._fontAsset&&(b.off("add:"+this._fontAsset,this._onFontAdded,this),(a=b.get(this._fontAsset))&&this._unbindFont(a)),this._fontAsset=c))if(c=b.get(this._fontAsset))this._bindFont(c);else b.on("add:"+this._fontAsset,this._onFontAdded,this)}});Object.defineProperty(b.prototype,
- "font",{get:function(){return this._font},set:function(a){var b;this._font&&(b=this._font.type,this._font.off&&this._font.off("render",this._onFontRender,this));if(this._font=a){if(this._font.on)this._font.on("render",this._onFontRender,this);if(this._fontAsset){var c=this._system.app.assets.get(this._fontAsset);c.resource!==this._font&&(this._unbindFont(c),this._fontAsset=null)}a.type!==b&&(a=this._element._isScreenSpace(),this._updateMaterial(a));a=0;for(b=this._font.textures.length;a<b;a++)if(this._meshInfo[a]){if(c=
- this._meshInfo[a].meshInstance)c.setParameter("font_sdfIntensity",this._font.intensity),c.setParameter("font_pxrange",this._getPxRange(this._font)),c.setParameter("font_textureWidth",this._font.data.info.maps[a].width),this._setTextureParams(c,this._font.textures[a])}else this._meshInfo[a]=new f;b=!1;for(a=this._font.textures.length;a<this._meshInfo.length;a++)this._meshInfo[a].meshInstance&&(b||(this._element.removeModelFromLayers(this._model),b=!0),this._removeMeshInstance(this._meshInfo[a].meshInstance));
- this._meshInfo.length>this._font.textures.length&&(this._meshInfo.length=this._font.textures.length);this._updateText()}}});Object.defineProperty(b.prototype,"alignment",{get:function(){return this._alignment},set:function(a){a instanceof pc.Vec2?this._alignment.set(a.x,a.y):this._alignment.set(a[0],a[1]);this._font&&this._updateText()}});Object.defineProperty(b.prototype,"autoWidth",{get:function(){return this._autoWidth},set:function(a){(this._autoWidth=a)&&1E-4>Math.abs(this._element.anchor.x-
- this._element.anchor.z)&&(this._element.width=this.width)}});Object.defineProperty(b.prototype,"autoHeight",{get:function(){return this._autoHeight},set:function(a){(this._autoHeight=a)&&1E-4>Math.abs(this._element.anchor.y-this._element.anchor.w)&&(this._element.height=this.height)}});Object.defineProperty(b.prototype,"rtlReorder",{get:function(){return this._rtlReorder},set:function(a){this._rtlReorder!==a&&(this._rtlReorder=a,this._font&&this._updateText())}});Object.defineProperty(b.prototype,
- "unicodeConverter",{get:function(){return this._unicodeConverter},set:function(a){this._unicodeConverter!==a&&(this._unicodeConverter=a,this.text=this._text)}});Object.defineProperty(b.prototype,"aabb",{get:function(){if(this._aabbDirty){for(var a=!1,b=0;b<this._meshInfo.length;b++)this._meshInfo[b].meshInstance&&(a?this._aabb.add(this._meshInfo[b].meshInstance.aabb):(this._aabb.copy(this._meshInfo[b].meshInstance.aabb),a=!0));this._aabbDirty=!1}return this._aabb}});Object.defineProperty(b.prototype,
- "outlineColor",{get:function(){return this._outlineColor},set:function(a){var b=a instanceof pc.Color?a.r:a[0],c=a instanceof pc.Color?a.g:a[1],d=a instanceof pc.Color?a.b:a[2];a=a instanceof pc.Color?a.a:a[3];if(this._outlineColor.r!==b||this._outlineColor.g!==c||this._outlineColor.b!==d||this._outlineColor.a!==a)if(this._outlineColor.r=b,this._outlineColor.g=c,this._outlineColor.b=d,this._outlineColor.a=a,this._model)for(this._outlineColorUniform[0]=this._outlineColor.r,this._outlineColorUniform[1]=
- this._outlineColor.g,this._outlineColorUniform[2]=this._outlineColor.b,this._outlineColorUniform[3]=this._outlineColor.a,b=0,c=this._model.meshInstances.length;b<c;b++)this._model.meshInstances[b].setParameter("outline_color",this._outlineColorUniform)}});Object.defineProperty(b.prototype,"outlineThickness",{get:function(){return this._outlineThickness},set:function(a){var b=this._outlineThickness;this._outlineThickness=a;if(b!==a&&this._font&&this._model)for(a=0,b=this._model.meshInstances.length;a<
- b;a++)this._model.meshInstances[a].setParameter("outline_thickness",this._outlineThicknessScale*this._outlineThickness)}});Object.defineProperty(b.prototype,"shadowColor",{get:function(){return this._shadowColor},set:function(a){var b=a instanceof pc.Color?a.r:a[0],c=a instanceof pc.Color?a.g:a[1],d=a instanceof pc.Color?a.b:a[2];a=a instanceof pc.Color?a.a:a[3];if(this._shadowColor.r!==b||this._shadowColor.g!==c||this._shadowColor.b!==d||this._shadowColor.a!==a)if(this._shadowColor.r=b,this._shadowColor.g=
- c,this._shadowColor.b=d,this._shadowColor.a=a,this._model)for(this._shadowColorUniform[0]=this._shadowColor.r,this._shadowColorUniform[1]=this._shadowColor.g,this._shadowColorUniform[2]=this._shadowColor.b,this._shadowColorUniform[3]=this._shadowColor.a,b=0,c=this._model.meshInstances.length;b<c;b++)this._model.meshInstances[b].setParameter("shadow_color",this._shadowColorUniform)}});Object.defineProperty(b.prototype,"shadowOffset",{get:function(){return this._shadowOffset},set:function(a){var b=
- a instanceof pc.Vec2?a.x:a[0];a=a instanceof pc.Vec2?a.y:a[1];if(this._shadowOffset.x!==b||this._shadowOffset.y!==a)if(this._shadowOffset.set(b,a),this._font&&this._model)for(this._shadowOffsetUniform[0]=this._shadowOffsetScale*this._shadowOffset.x,this._shadowOffsetUniform[1]=this._shadowOffsetScale*this._shadowOffset.y,b=0,a=this._model.meshInstances.length;b<a;b++)this._model.meshInstances[b].setParameter("shadow_offset",this._shadowOffsetUniform)}});return{TextElement:b}}());Object.assign(pc,function(){var f=new pc.Vec2,b=new pc.Vec3,a=new pc.Vec3,c=new pc.Vec3,d=new pc.Vec3,e=new pc.Vec3,g=new pc.Quat,l={x:"y",y:"x"},k=function(a,b){if(!(a&&a instanceof pc.ElementComponent))throw Error("Element was null or not an ElementComponent");if(b&&"x"!==b&&"y"!==b)throw Error("Unrecognized axis: "+b);this._element=a;this._app=a.system.app;this._axis=b||null;this._enabled=!0;this._dragScale=new pc.Vec3;this._dragStartMousePosition=new pc.Vec3;this._dragStartHandlePosition=new pc.Vec3;
- this._deltaMousePosition=new pc.Vec3;this._deltaHandlePosition=new pc.Vec3;this._isDragging=!1;pc.events.attach(this);this._toggleLifecycleListeners("on")};Object.assign(k.prototype,{_toggleLifecycleListeners:function(a){this._element[a]("mousedown",this._onMouseDownOrTouchStart,this);this._element[a]("touchstart",this._onMouseDownOrTouchStart,this)},_toggleDragListeners:function(a){var b="on"===a,c=b?"addEventListener":"removeEventListener";this._hasDragListeners&&b||(this._handleMouseUpOrTouchEnd||
- (this._handleMouseUpOrTouchEnd=this._onMouseUpOrTouchEnd.bind(this)),this._app.mouse[a]("mousemove",this._onMove,this),window[c]("mouseup",this._handleMouseUpOrTouchEnd,!1),pc.platform.touch&&(this._app.touch[a]("touchmove",this._onMove,this),window[c]("touchend",this._handleMouseUpOrTouchEnd,!1),window[c]("touchcancel",this._handleMouseUpOrTouchEnd,!1)),this._hasDragListeners=b)},_onMouseDownOrTouchStart:function(a){this._element&&!this._isDragging&&this.enabled&&(this._dragCamera=a.camera,this._calculateDragScale(),
- a=this._screenToLocal(a))&&(this._toggleDragListeners("on"),this._isDragging=!0,this._dragStartMousePosition.copy(a),this._dragStartHandlePosition.copy(this._element.entity.getLocalPosition()),this.fire("drag:start"))},_onMouseUpOrTouchEnd:function(){this._isDragging&&(this._isDragging=!1,this._toggleDragListeners("off"),this.fire("drag:end"))},_screenToLocal:function(b){this._determineInputPosition(b);this._chooseRayOriginAndDirection();d.copy(this._element.entity.getPosition());e.copy(this._element.entity.forward).scale(-1);
- b=e.dot(c);return 0<Math.abs(b)?(b=d.sub(a).dot(e)/b,b=a.add(c.scale(b)),g.copy(this._element.entity.getRotation()).invert().transformVector(b,b),b.mul(this._dragScale),b):null},_determineInputPosition:function(a){var b=this._app.graphicsDevice.maxPixelRatio;"undefined"!==typeof a.x&&"undefined"!==typeof a.y?(f.x=a.x*b,f.y=a.y*b):a.changedTouches?(f.x=a.changedTouches[0].x*b,f.y=a.changedTouches[0].y*b):console.warn("Could not determine position from input event")},_chooseRayOriginAndDirection:function(){this._element.screen&&
- this._element.screen.screen.screenSpace?(a.set(f.x,-f.y,0),c.set(0,0,-1)):(b.copy(this._dragCamera.screenToWorld(f.x,f.y,1)),a.copy(this._dragCamera.entity.getPosition()),c.copy(b).sub(a).normalize())},_calculateDragScale:function(){var a=this._element.entity.parent,b=this._element.screen&&this._element.screen.screen,c=b&&b.screenSpace,b=c?b.scale:1,d=this._dragScale;for(d.set(b,b,b);a&&(d.mul(a.getLocalScale()),a=a.parent,!c||!a.screen););d.x=1/d.x;d.y=1/d.y;d.z=1/d.z},_onMove:function(a){if(this._element&&
- this._isDragging&&this.enabled&&this._element.enabled&&this._element.entity.enabled&&(a=this._screenToLocal(a),this._dragStartMousePosition&&a)){this._deltaMousePosition.copy(a).sub(this._dragStartMousePosition);this._deltaHandlePosition.copy(this._dragStartHandlePosition).add(this._deltaMousePosition);if(this._axis){a=this._element.entity.getLocalPosition();var b=l[this._axis];this._deltaHandlePosition[b]=a[b]}this._element.entity.setLocalPosition(this._deltaHandlePosition);this.fire("drag:move",
- this._deltaHandlePosition)}},destroy:function(){this._toggleLifecycleListeners("off");this._toggleDragListeners("off")}});Object.defineProperty(k.prototype,"enabled",{get:function(){return this._enabled},set:function(a){this._enabled=a}});Object.defineProperty(k.prototype,"isDragging",{get:function(){return this._isDragging}});return{ElementDragHelper:k}}());Object.assign(pc,{BUTTON_TRANSITION_MODE_TINT:0,BUTTON_TRANSITION_MODE_SPRITE_CHANGE:1});Object.assign(pc,function(){var f={DEFAULT:"_defaultTint",HOVER:"hoverTint",PRESSED:"pressedTint",INACTIVE:"inactiveTint"},b={DEFAULT:"_defaultSpriteAsset",HOVER:"hoverSpriteAsset",PRESSED:"pressedSpriteAsset",INACTIVE:"inactiveSpriteAsset"},a={DEFAULT:"_defaultSpriteFrame",HOVER:"hoverSpriteFrame",PRESSED:"pressedSpriteFrame",INACTIVE:"inactiveSpriteFrame"},c=function(a,b){pc.Component.call(this,a,b);this._visualState="DEFAULT";this._isPressed=this._isHovering=!1;this._defaultTint=new pc.Color(1,
- 1,1,1);this._defaultSpriteAsset=null;this._defaultSpriteFrame=0;this._imageReference=new pc.EntityReference(this,"imageEntity",{"element#gain":this._onImageElementGain,"element#lose":this._onImageElementLose,"element#set:color":this._onSetColor,"element#set:opacity":this._onSetOpacity,"element#set:spriteAsset":this._onSetSpriteAsset,"element#set:spriteFrame":this._onSetSpriteFrame});this._toggleLifecycleListeners("on",a)};c.prototype=Object.create(pc.Component.prototype);c.prototype.constructor=c;
- Object.assign(c.prototype,{_toggleLifecycleListeners:function(a,b){this[a]("set_active",this._onSetActive,this);this[a]("set_transitionMode",this._onSetTransitionMode,this);this[a]("set_hoverTint",this._onSetTransitionValue,this);this[a]("set_pressedTint",this._onSetTransitionValue,this);this[a]("set_inactiveTint",this._onSetTransitionValue,this);this[a]("set_hoverSpriteAsset",this._onSetTransitionValue,this);this[a]("set_hoverSpriteFrame",this._onSetTransitionValue,this);this[a]("set_pressedSpriteAsset",
- this._onSetTransitionValue,this);this[a]("set_pressedSpriteFrame",this._onSetTransitionValue,this);this[a]("set_inactiveSpriteAsset",this._onSetTransitionValue,this);this[a]("set_inactiveSpriteFrame",this._onSetTransitionValue,this);b.app.systems.element[a]("add",this._onElementComponentAdd,this);b.app.systems.element[a]("beforeremove",this._onElementComponentRemove,this)},_onSetActive:function(a,b,c){b!==c&&this._updateVisualState()},_onSetTransitionMode:function(a,b,c){b!==c&&(this._cancelTween(),
- this._resetToDefaultVisualState(b),this._forceReapplyVisualState())},_onSetTransitionValue:function(a,b,c){b!==c&&this._forceReapplyVisualState()},_onElementComponentRemove:function(a){this.entity===a&&this._toggleHitElementListeners("off")},_onElementComponentAdd:function(a){this.entity===a&&this._toggleHitElementListeners("on")},_onImageElementLose:function(){this._cancelTween();this._resetToDefaultVisualState(this.transitionMode)},_onImageElementGain:function(){this._storeDefaultVisualState();
- this._forceReapplyVisualState()},_toggleHitElementListeners:function(a){if(this.entity.element){var b="on"===a;b&&this._hasHitElementListeners||(this.entity.element[a]("mouseenter",this._onMouseEnter,this),this.entity.element[a]("mouseleave",this._onMouseLeave,this),this.entity.element[a]("mousedown",this._onMouseDown,this),this.entity.element[a]("mouseup",this._onMouseUp,this),this.entity.element[a]("touchstart",this._onTouchStart,this),this.entity.element[a]("touchend",this._onTouchEnd,this),this.entity.element[a]("touchleave",
- this._onTouchLeave,this),this.entity.element[a]("touchcancel",this._onTouchCancel,this),this.entity.element[a]("click",this._onClick,this),this._hasHitElementListeners=b)}},_storeDefaultVisualState:function(){this._imageReference.hasComponent("element")&&(this._storeDefaultColor(this._imageReference.entity.element.color),this._storeDefaultOpacity(this._imageReference.entity.element.opacity),this._storeDefaultSpriteAsset(this._imageReference.entity.element.spriteAsset),this._storeDefaultSpriteFrame(this._imageReference.entity.element.spriteFrame))},
- _storeDefaultColor:function(a){this._defaultTint.r=a.r;this._defaultTint.g=a.g;this._defaultTint.b=a.b},_storeDefaultOpacity:function(a){this._defaultTint.a=a},_storeDefaultSpriteAsset:function(a){this._defaultSpriteAsset=a},_storeDefaultSpriteFrame:function(a){this._defaultSpriteFrame=a},_onSetColor:function(a){this._isApplyingTint||(this._storeDefaultColor(a),this._forceReapplyVisualState())},_onSetOpacity:function(a){this._isApplyingTint||(this._storeDefaultOpacity(a),this._forceReapplyVisualState())},
- _onSetSpriteAsset:function(a){this._isApplyingSprite||(this._storeDefaultSpriteAsset(a),this._forceReapplyVisualState())},_onSetSpriteFrame:function(a){this._isApplyingSprite||(this._storeDefaultSpriteFrame(a),this._forceReapplyVisualState())},_onMouseEnter:function(a){this._isHovering=!0;this._updateVisualState();this._fireIfActive("mouseenter",a)},_onMouseLeave:function(a){this._isPressed=this._isHovering=!1;this._updateVisualState();this._fireIfActive("mouseleave",a)},_onMouseDown:function(a){this._isPressed=
- !0;this._updateVisualState();this._fireIfActive("mousedown",a)},_onMouseUp:function(a){this._isPressed=!1;this._updateVisualState();this._fireIfActive("mouseup",a)},_onTouchStart:function(a){this._isPressed=!0;this._updateVisualState();this._fireIfActive("touchstart",a)},_onTouchEnd:function(a){a.event.preventDefault();this._isPressed=!1;this._updateVisualState();this._fireIfActive("touchend",a)},_onTouchLeave:function(a){this._isPressed=!1;this._updateVisualState();this._fireIfActive("touchleave",
- a)},_onTouchCancel:function(a){this._isPressed=!1;this._updateVisualState();this._fireIfActive("touchcancel",a)},_onClick:function(a){this._fireIfActive("click",a)},_fireIfActive:function(a,b){this.data.active&&this.fire(a,b)},_updateVisualState:function(c){var d=this._visualState,g=this._determineVisualState();if((d!==g||c)&&this.enabled)switch(this._visualState=g,"HOVER"===d&&this._fireIfActive("hoverend"),"PRESSED"===d&&this._fireIfActive("pressedend"),"HOVER"===g&&this._fireIfActive("hoverstart"),
- "PRESSED"===g&&this._fireIfActive("pressedstart"),this.transitionMode){case pc.BUTTON_TRANSITION_MODE_TINT:this._applyTint(this[f[this._visualState]]);break;case pc.BUTTON_TRANSITION_MODE_SPRITE_CHANGE:this._applySprite(this[b[this._visualState]],this[a[this._visualState]])}},_forceReapplyVisualState:function(){this._updateVisualState(!0)},_resetToDefaultVisualState:function(a){if(this._imageReference.hasComponent("element"))switch(a){case pc.BUTTON_TRANSITION_MODE_TINT:this._cancelTween();this._applyTintImmediately(this._defaultTint);
- break;case pc.BUTTON_TRANSITION_MODE_SPRITE_CHANGE:this._applySprite(this._defaultSpriteAsset,this._defaultSpriteFrame)}},_determineVisualState:function(){if(this.active){if(this._isPressed)return"PRESSED";if(this._isHovering)return"HOVER"}else return"INACTIVE";return"DEFAULT"},_applySprite:function(a,b){b=b||0;this._imageReference.hasComponent("element")&&(this._isApplyingSprite=!0,this._imageReference.entity.element.spriteAsset=a,this._imageReference.entity.element.spriteFrame=b,this._isApplyingSprite=
- !1)},_applyTint:function(a){this._cancelTween();0===this.fadeDuration?this._applyTintImmediately(a):this._applyTintWithTween(a)},_applyTintImmediately:function(a){this._imageReference.hasComponent("element")&&a&&(this._isApplyingTint=!0,this._imageReference.entity.element.color=new pc.Color(a.r,a.g,a.b),this._imageReference.entity.element.opacity=a.a,this._isApplyingTint=!1)},_applyTintWithTween:function(a){if(this._imageReference.hasComponent("element")&&a){var b=this._imageReference.entity.element.color,
- c=this._imageReference.entity.element.opacity;this._tweenInfo={startTime:pc.now(),from:new pc.Color(b.r,b.g,b.b,c),to:a.clone(),lerpColor:new pc.Color}}},_updateTintTween:function(){var a=pc.now()-this._tweenInfo.startTime,a=0===this.fadeDuration?1:a/this.fadeDuration,a=pc.math.clamp(a,0,1);if(1E-5<Math.abs(a-1)){var b=this._tweenInfo.lerpColor;b.lerp(this._tweenInfo.from,this._tweenInfo.to,a);this._applyTintImmediately(new pc.Color(b.r,b.g,b.b,b.a))}else this._applyTintImmediately(this._tweenInfo.to),
- this._cancelTween()},_cancelTween:function(){delete this._tweenInfo},onUpdate:function(){this._tweenInfo&&this._updateTintTween()},onEnable:function(){this._imageReference.onParentComponentEnable();this._toggleHitElementListeners("on");this._forceReapplyVisualState()},onDisable:function(){this._toggleHitElementListeners("off");this._resetToDefaultVisualState(this.transitionMode)},onRemove:function(){this._toggleLifecycleListeners("off",this.system);this.onDisable()}});return{ButtonComponent:c}}());Object.assign(pc,function(){var f=["enabled","active",{name:"imageEntity",type:"entity"},{name:"hitPadding",type:"vec4"},"transitionMode",{name:"hoverTint",type:"rgba"},{name:"pressedTint",type:"rgba"},{name:"inactiveTint",type:"rgba"},"fadeDuration","hoverSpriteAsset","hoverSpriteFrame","pressedSpriteAsset","pressedSpriteFrame","inactiveSpriteAsset","inactiveSpriteFrame"],b=function(a){pc.ComponentSystem.call(this,a);this.id="button";this.app=a;this.ComponentType=pc.ButtonComponent;this.DataType=
- pc.ButtonComponentData;this.schema=f;this.on("beforeremove",this._onRemoveComponent,this);pc.ComponentSystem.bind("update",this.onUpdate,this)};b.prototype=Object.create(pc.ComponentSystem.prototype);b.prototype.constructor=b;pc.Component._buildAccessors(pc.ButtonComponent.prototype,f);Object.assign(b.prototype,{initializeComponentData:function(a,b,d){pc.ComponentSystem.prototype.initializeComponentData.call(this,a,b,f)},onUpdate:function(a){a=this.store;for(var b in a){var d=a[b].entity,e=d.button;
- if(e.enabled&&d.enabled)e.onUpdate()}},_onRemoveComponent:function(a,b){b.onRemove()}});return{ButtonComponentSystem:b}}());Object.assign(pc,function(){return{ButtonComponentData:function(){this.active=this.enabled=!0;this.imageEntity=null;this.hitPadding=new pc.Vec4;this.transitionMode=pc.BUTTON_TRANSITION_MODE_TINT;this.hoverTint=new pc.Color(.75,.75,.75);this.pressedTint=new pc.Color(.5,.5,.5);this.inactiveTint=new pc.Color(.25,.25,.25);this.fadeDuration=0;this.hoverSpriteAsset=null;this.hoverSpriteFrame=0;this.pressedSpriteAsset=null;this.pressedSpriteFrame=0;this.inactiveSpriteAsset=null;this.inactiveSpriteFrame=
- 0}}}());Object.assign(pc,{SCROLL_MODE_CLAMP:0,SCROLL_MODE_BOUNCE:1,SCROLL_MODE_INFINITE:2,SCROLLBAR_VISIBILITY_SHOW_ALWAYS:0,SCROLLBAR_VISIBILITY_SHOW_WHEN_REQUIRED:1});Object.assign(pc,function(){var f=new pc.Vec2,b=function(a,b){pc.Component.call(this,a,b);this._viewportReference=new pc.EntityReference(this,"viewportEntity",{"element#gain":this._onViewportElementGain,"element#resize":this._onSetContentOrViewportSize});this._contentReference=new pc.EntityReference(this,"contentEntity",{"element#gain":this._onContentElementGain,"element#lose":this._onContentElementLose,"element#resize":this._onSetContentOrViewportSize});this._scrollbarUpdateFlags={};this._scrollbarReferences=
- {};this._scrollbarReferences[pc.ORIENTATION_HORIZONTAL]=new pc.EntityReference(this,"horizontalScrollbarEntity",{"scrollbar#set:value":this._onSetHorizontalScrollbarValue,"scrollbar#gain":this._onHorizontalScrollbarGain});this._scrollbarReferences[pc.ORIENTATION_VERTICAL]=new pc.EntityReference(this,"verticalScrollbarEntity",{"scrollbar#set:value":this._onSetVerticalScrollbarValue,"scrollbar#gain":this._onVerticalScrollbarGain});this._prevContentSizes={};this._prevContentSizes[pc.ORIENTATION_HORIZONTAL]=
- null;this._prevContentSizes[pc.ORIENTATION_VERTICAL]=null;this._scroll=new pc.Vec2;this._velocity=new pc.Vec3;this._dragStartPosition=new pc.Vec3;this._disabledContentInput=!1;this._disabledContentInputEntities=[];this._toggleLifecycleListeners("on",a);this._toggleElementListeners("on")};b.prototype=Object.create(pc.Component.prototype);b.prototype.constructor=b;Object.assign(b.prototype,{_toggleLifecycleListeners:function(a,b){this[a]("set_horizontal",this._onSetHorizontalScrollingEnabled,this);
- this[a]("set_vertical",this._onSetVerticalScrollingEnabled,this);b.app.systems.element[a]("add",this._onElementComponentAdd,this);b.app.systems.element[a]("beforeremove",this._onElementComponentRemove,this)},_toggleElementListeners:function(a){!this.entity.element||"on"===a&&this._hasElementListeners||(this.entity.element[a]("resize",this._onSetContentOrViewportSize,this),this._hasElementListeners="on"===a)},_onElementComponentAdd:function(a){this.entity===a&&this._toggleElementListeners("on")},_onElementComponentRemove:function(a){this.entity===
- a&&this._toggleElementListeners("off")},_onViewportElementGain:function(){this._syncAll()},_onContentElementGain:function(){this._destroyDragHelper();this._contentDragHelper=new pc.ElementDragHelper(this._contentReference.entity.element);this._contentDragHelper.on("drag:start",this._onContentDragStart,this);this._contentDragHelper.on("drag:end",this._onContentDragEnd,this);this._contentDragHelper.on("drag:move",this._onContentDragMove,this);this._prevContentSizes[pc.ORIENTATION_HORIZONTAL]=null;this._prevContentSizes[pc.ORIENTATION_VERTICAL]=
- null;this._syncAll()},_onContentElementLose:function(){this._destroyDragHelper()},_onContentDragStart:function(){this._contentReference.entity&&this.enabled&&this.entity.enabled&&this._dragStartPosition.copy(this._contentReference.entity.getLocalPosition())},_onContentDragEnd:function(){this._prevContentDragPosition=null;this._enableContentInput()},_onContentDragMove:function(a){if(this._contentReference.entity&&this.enabled&&this.entity.enabled&&(this._wasDragged=!0,this._setScrollFromContentPosition(a),
- this._setVelocityFromContentPositionDelta(a),!this._disabledContentInput)){var b=a.y-this._dragStartPosition.y;(Math.abs(a.x-this._dragStartPosition.x)>this.dragThreshold||Math.abs(b)>this.dragThreshold)&&this._disableContentInput()}},_onSetContentOrViewportSize:function(){this._syncAll()},_onSetHorizontalScrollbarValue:function(a){!this._scrollbarUpdateFlags[pc.ORIENTATION_HORIZONTAL]&&this.enabled&&this.entity.enabled&&this._onSetScroll(a,null)},_onSetVerticalScrollbarValue:function(a){!this._scrollbarUpdateFlags[pc.ORIENTATION_VERTICAL]&&
- this.enabled&&this.entity.enabled&&this._onSetScroll(null,a)},_onSetHorizontalScrollingEnabled:function(){this._syncScrollbarEnabledState(pc.ORIENTATION_HORIZONTAL)},_onSetVerticalScrollingEnabled:function(){this._syncScrollbarEnabledState(pc.ORIENTATION_VERTICAL)},_onHorizontalScrollbarGain:function(){this._syncScrollbarEnabledState(pc.ORIENTATION_HORIZONTAL);this._syncScrollbarPosition(pc.ORIENTATION_HORIZONTAL)},_onVerticalScrollbarGain:function(){this._syncScrollbarEnabledState(pc.ORIENTATION_VERTICAL);
- this._syncScrollbarPosition(pc.ORIENTATION_VERTICAL)},_onSetScroll:function(a,b,d){!1!==d&&this._velocity.set(0,0,0);a=0|this._updateAxis(a,"x",pc.ORIENTATION_HORIZONTAL);(a|=this._updateAxis(b,"y",pc.ORIENTATION_VERTICAL))&&this.fire("set:scroll",this._scroll)},_updateAxis:function(a,b,d){var c=null!==a&&1E-5<Math.abs(a-this._scroll[b]);if(c||this._isDragging()||0===a)this._scroll[b]=this._determineNewScrollValue(a,b,d),this._syncContentPosition(d),this._syncScrollbarPosition(d);return c},_determineNewScrollValue:function(a,
- b,d){if(!this._getScrollingEnabled(d))return this._scroll[b];switch(this.scrollMode){case pc.SCROLL_MODE_CLAMP:return pc.math.clamp(a,0,this._getMaxScrollValue(d));case pc.SCROLL_MODE_BOUNCE:return this._setVelocityFromOvershoot(a,b,d),a;case pc.SCROLL_MODE_INFINITE:return a;default:return console.warn("Unhandled scroll mode:"+this.scrollMode),a}},_syncAll:function(){this._syncContentPosition(pc.ORIENTATION_HORIZONTAL);this._syncContentPosition(pc.ORIENTATION_VERTICAL);this._syncScrollbarPosition(pc.ORIENTATION_HORIZONTAL);
- this._syncScrollbarPosition(pc.ORIENTATION_VERTICAL);this._syncScrollbarEnabledState(pc.ORIENTATION_HORIZONTAL);this._syncScrollbarEnabledState(pc.ORIENTATION_VERTICAL)},_syncContentPosition:function(a){var b=this._getAxis(a),d=this._getSign(a),e=this._contentReference.entity;if(e){var f=this._prevContentSizes[a],l=this._getContentSize(a);if(null!==f&&1E-4<Math.abs(f-l)){var f=this._getMaxOffset(a,f),k=this._getMaxOffset(a,l);this._scroll[b]=0===k?1:pc.math.clamp(this._scroll[b]*f/k,0,1)}f=this._scroll[b]*
- this._getMaxOffset(a);k=e.getLocalPosition();k[b]=f*d;e.setLocalPosition(k);this._prevContentSizes[a]=l}},_syncScrollbarPosition:function(a){var b=this._getAxis(a),d=this._scrollbarReferences[a].entity;d&&d.scrollbar&&(this._scrollbarUpdateFlags[a]=!0,d.scrollbar.value=this._scroll[b],d.scrollbar.handleSize=this._getScrollbarHandleSize(b,a),this._scrollbarUpdateFlags[a]=!1)},_syncScrollbarEnabledState:function(a){var b=this._scrollbarReferences[a].entity;if(b){var d=this._getScrollingEnabled(a),e=
- this._getScrollbarVisibility(a);switch(e){case pc.SCROLLBAR_VISIBILITY_SHOW_ALWAYS:b.enabled=d;break;case pc.SCROLLBAR_VISIBILITY_SHOW_WHEN_REQUIRED:b.enabled=d&&this._contentIsLargerThanViewport(a);break;default:console.warn("Unhandled scrollbar visibility:"+e),b.enabled=d}}},_contentIsLargerThanViewport:function(a){return this._getContentSize(a)>this._getViewportSize(a)},_contentPositionToScrollValue:function(a){var b=this._getMaxOffset(pc.ORIENTATION_HORIZONTAL),d=this._getMaxOffset(pc.ORIENTATION_VERTICAL);
- f.x=0===b?0:a.x/b;f.y=0===d?0:a.y/-d;return f},_getMaxOffset:function(a,b){b=void 0===b?this._getContentSize(a):b;var c=this._getViewportSize(a);return b<c?-this._getViewportSize(a):c-b},_getMaxScrollValue:function(a){return this._contentIsLargerThanViewport(a)?1:0},_getScrollbarHandleSize:function(a,b){var c=this._getViewportSize(b),e=this._getContentSize(b);if(.001>Math.abs(e))return 1;c=Math.min(c/e,1);e=this._toOvershoot(this._scroll[a],b);return 0===e?c:c/(1+Math.abs(e))},_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(a===pc.ORIENTATION_HORIZONTAL)return this.horizontal;if(a===pc.ORIENTATION_VERTICAL)return this.vertical;console.warn("Unrecognized orientation: "+a)},_getScrollbarVisibility:function(a){if(a===pc.ORIENTATION_HORIZONTAL)return this.horizontalScrollbarVisibility;
- if(a===pc.ORIENTATION_VERTICAL)return this.verticalScrollbarVisibility;console.warn("Unrecognized orientation: "+a)},_getSign:function(a){return a===pc.ORIENTATION_HORIZONTAL?1:-1},_getAxis:function(a){return a===pc.ORIENTATION_HORIZONTAL?"x":"y"},_getCalculatedDimension:function(a){return a===pc.ORIENTATION_HORIZONTAL?"calculatedWidth":"calculatedHeight"},_destroyDragHelper:function(){this._contentDragHelper&&this._contentDragHelper.destroy()},onUpdate:function(){this._contentReference.entity&&(this._updateVelocity(),
- this._syncScrollbarEnabledState(pc.ORIENTATION_HORIZONTAL),this._syncScrollbarEnabledState(pc.ORIENTATION_VERTICAL))},_updateVelocity:function(){if(!this._isDragging()&&(this.scrollMode===pc.SCROLL_MODE_BOUNCE&&(this._hasOvershoot("x",pc.ORIENTATION_HORIZONTAL)&&this._setVelocityFromOvershoot(this.scroll.x,"x",pc.ORIENTATION_HORIZONTAL),this._hasOvershoot("y",pc.ORIENTATION_VERTICAL)&&this._setVelocityFromOvershoot(this.scroll.y,"y",pc.ORIENTATION_VERTICAL)),this._velocity.x*=1-this.friction,this._velocity.y*=
- 1-this.friction,1E-4<Math.abs(this._velocity.x)||1E-4<Math.abs(this._velocity.y))){var a=this._contentReference.entity.getLocalPosition();a.x+=this._velocity.x;a.y+=this._velocity.y;this._contentReference.entity.setLocalPosition(a);this._setScrollFromContentPosition(a)}},_hasOvershoot:function(a,b){return.001<Math.abs(this._toOvershoot(this.scroll[a],b))},_toOvershoot:function(a,b){var c=this._getMaxScrollValue(b);return 0>a?a:a>c?a-c:0},_setVelocityFromOvershoot:function(a,b,d){a=this._toOvershoot(a,
- d)*this._getMaxOffset(d)*this._getSign(d);0<Math.abs(a)&&(this._velocity[b]=-a/(50*this.bounceAmount+1))},_setVelocityFromContentPositionDelta:function(a){this._prevContentDragPosition?(this._velocity.sub2(a,this._prevContentDragPosition),this._prevContentDragPosition.copy(a)):(this._velocity.set(0,0,0),this._prevContentDragPosition=a.clone())},_setScrollFromContentPosition:function(a){a=this._contentPositionToScrollValue(a);this._isDragging()&&(a=this._applyScrollValueTension(a));this._onSetScroll(a.x,
- a.y,!1)},_applyScrollValueTension:function(a){var b,d;b=this._getMaxScrollValue(pc.ORIENTATION_HORIZONTAL);d=this._toOvershoot(a.x,pc.ORIENTATION_HORIZONTAL);0<d?a.x=b+1*Math.log10(1+d):0>d&&(a.x=-1*Math.log10(1-d));b=this._getMaxScrollValue(pc.ORIENTATION_VERTICAL);d=this._toOvershoot(a.y,pc.ORIENTATION_VERTICAL);0<d?a.y=b+1*Math.log10(1+d):0>d&&(a.y=-1*Math.log10(1-d));return a},_isDragging:function(){return this._contentDragHelper&&this._contentDragHelper.isDragging},_setScrollbarComponentsEnabled:function(a){this._scrollbarReferences[pc.ORIENTATION_HORIZONTAL].hasComponent("scrollbar")&&
- (this._scrollbarReferences[pc.ORIENTATION_HORIZONTAL].entity.scrollbar.enabled=a);this._scrollbarReferences[pc.ORIENTATION_VERTICAL].hasComponent("scrollbar")&&(this._scrollbarReferences[pc.ORIENTATION_VERTICAL].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,e;d=0;for(e=c.length;d<e;d++)b(c[d])},d=this._contentReference.entity;if(d){var d=d.children,e,f=d.length;for(e=0;e<f;e++)b(d[e])}this._disabledContentInput=!0},onEnable:function(){this._viewportReference.onParentComponentEnable();this._contentReference.onParentComponentEnable();this._scrollbarReferences[pc.ORIENTATION_HORIZONTAL].onParentComponentEnable();
- this._scrollbarReferences[pc.ORIENTATION_VERTICAL].onParentComponentEnable();this._setScrollbarComponentsEnabled(!0);this._setContentDraggingEnabled(!0);this._syncAll()},onDisable:function(){this._setScrollbarComponentsEnabled(!1);this._setContentDraggingEnabled(!1)},onRemove:function(){this._toggleLifecycleListeners("off",this.system);this._toggleElementListeners("off");this._destroyDragHelper()}});Object.defineProperty(b.prototype,"scroll",{get:function(){return this._scroll},set:function(a){this._onSetScroll(a.x,
- a.y)}});return{ScrollViewComponent:b}}());Object.assign(pc,function(){var f=[{name:"enabled",type:"boolean"},{name:"horizontal",type:"boolean"},{name:"vertical",type:"boolean"},{name:"scrollMode",type:"number"},{name:"bounceAmount",type:"number"},{name:"friction",type:"number"},{name:"dragThreshold",type:"number"},{name:"horizontalScrollbarVisibility",type:"number"},{name:"verticalScrollbarVisibility",type:"number"},{name:"viewportEntity",type:"entity"},{name:"contentEntity",type:"entity"},{name:"horizontalScrollbarEntity",type:"entity"},
- {name:"verticalScrollbarEntity",type:"entity"}],b=function(a){pc.ComponentSystem.call(this,a);this.id="scrollview";this.app=a;this.ComponentType=pc.ScrollViewComponent;this.DataType=pc.ScrollViewComponentData;this.schema=f;this.on("beforeremove",this._onRemoveComponent,this);pc.ComponentSystem.bind("update",this.onUpdate,this)};b.prototype=Object.create(pc.ComponentSystem.prototype);b.prototype.constructor=b;pc.Component._buildAccessors(pc.ScrollViewComponent.prototype,f);Object.assign(b.prototype,
- {initializeComponentData:function(a,b,d){void 0===b.dragThreshold&&(b.dragThreshold=10);pc.ComponentSystem.prototype.initializeComponentData.call(this,a,b,f)},onUpdate:function(a){a=this.store;for(var b in a){var d=a[b].entity,e=d.scrollview;if(e.enabled&&d.enabled)e.onUpdate()}},_onRemoveComponent:function(a,b){b.onRemove()}});return{ScrollViewComponentSystem:b}}());Object.assign(pc,function(){return{ScrollViewComponentData:function(){this.enabled=!0}}}());Object.assign(pc,function(){var f=function(b,a){pc.Component.call(this,b,a);this._app=b.app;this._handleReference=new pc.EntityReference(this,"handleEntity",{"element#gain":this._onHandleElementGain,"element#lose":this._onHandleElementLose,"element#set:anchor":this._onSetHandleAlignment,"element#set:margin":this._onSetHandleAlignment,"element#set:pivot":this._onSetHandleAlignment});this._toggleLifecycleListeners("on")};f.prototype=Object.create(pc.Component.prototype);f.prototype.constructor=f;Object.assign(f.prototype,
- {_toggleLifecycleListeners:function(b){this[b]("set_value",this._onSetValue,this);this[b]("set_handleSize",this._onSetHandleSize,this);this[b]("set_orientation",this._onSetOrientation,this)},_onHandleElementGain:function(){this._destroyDragHelper();this._handleDragHelper=new pc.ElementDragHelper(this._handleReference.entity.element,this._getAxis());this._handleDragHelper.on("drag:move",this._onHandleDrag,this);this._updateHandlePositionAndSize()},_onHandleElementLose:function(){this._destroyDragHelper()},
- _onHandleDrag:function(b){this._handleReference.entity&&this.enabled&&this.entity.enabled&&(this.value=this._handlePositionToScrollValue(b[this._getAxis()]))},_onSetValue:function(b,a,c){1E-5<Math.abs(c-a)&&(this.data.value=pc.math.clamp(c,0,1),this._updateHandlePositionAndSize(),this.fire("set:value",this.data.value))},_onSetHandleSize:function(b,a,c){1E-5<Math.abs(c-a)&&(this.data.handleSize=pc.math.clamp(c,0,1),this._updateHandlePositionAndSize())},_onSetHandleAlignment:function(){this._updateHandlePositionAndSize()},
- _onSetOrientation:function(b,a,c){c!==a&&this._handleReference.hasComponent("element")&&(this._handleReference.entity.element[this._getOppositeDimension()]=0)},_updateHandlePositionAndSize:function(){var b=this._handleReference.entity,a=b&&b.element;b&&(b=b.getLocalPosition(),b[this._getAxis()]=this._getHandlePosition(),this._handleReference.entity.setLocalPosition(b));a&&(a[this._getDimension()]=this._getHandleLength())},_handlePositionToScrollValue:function(b){return b*this._getSign()/this._getUsableTrackLength()},
- _scrollValueToHandlePosition:function(b){return b*this._getSign()*this._getUsableTrackLength()},_getUsableTrackLength:function(){return Math.max(this._getTrackLength()-this._getHandleLength(),.001)},_getTrackLength:function(){return this.entity.element?this.orientation===pc.ORIENTATION_HORIZONTAL?this.entity.element.calculatedWidth:this.entity.element.calculatedHeight:0},_getHandleLength:function(){return this._getTrackLength()*this.handleSize},_getHandlePosition:function(){return this._scrollValueToHandlePosition(this.value)},
- _getSign:function(){return this.orientation===pc.ORIENTATION_HORIZONTAL?1:-1},_getAxis:function(){return this.orientation===pc.ORIENTATION_HORIZONTAL?"x":"y"},_getDimension:function(){return this.orientation===pc.ORIENTATION_HORIZONTAL?"width":"height"},_getOppositeDimension:function(){return this.orientation===pc.ORIENTATION_HORIZONTAL?"height":"width"},_destroyDragHelper:function(){this._handleDragHelper&&this._handleDragHelper.destroy()},_setHandleDraggingEnabled:function(b){this._handleDragHelper&&
- (this._handleDragHelper.enabled=b)},onEnable:function(){this._handleReference.onParentComponentEnable();this._setHandleDraggingEnabled(!0)},onDisable:function(){this._setHandleDraggingEnabled(!1)},onRemove:function(){this._destroyDragHelper();this._toggleLifecycleListeners("off")}});return{ScrollbarComponent:f}}());Object.assign(pc,function(){var f=[{name:"enabled",type:"boolean"},{name:"orientation",type:"number"},{name:"value",type:"number"},{name:"handleSize",type:"number"},{name:"handleEntity",type:"entity"}],b=function(a){pc.ComponentSystem.call(this,a);this.id="scrollbar";this.app=a;this.ComponentType=pc.ScrollbarComponent;this.DataType=pc.ScrollbarComponentData;this.schema=f;this.on("beforeremove",this._onRemoveComponent,this)};b.prototype=Object.create(pc.ComponentSystem.prototype);b.prototype.constructor=
- b;pc.Component._buildAccessors(pc.ScrollbarComponent.prototype,f);Object.assign(b.prototype,{initializeComponentData:function(a,b,d){pc.ComponentSystem.prototype.initializeComponentData.call(this,a,b,f)},_onRemoveComponent:function(a,b){b.onRemove()}});return{ScrollbarComponentSystem:b}}());Object.assign(pc,function(){return{ScrollbarComponentData:function(){this.enabled=!0}}}());Object.assign(pc,{FITTING_NONE:0,FITTING_STRETCH:1,FITTING_SHRINK:2,FITTING_BOTH:3});Object.assign(pc,function(){function f(a){return a.element}function b(a){return a.enabled&&a.element&&a.element.enabled}function a(a){var b="_"+a;Object.defineProperty(c.prototype,a,{get:function(){return this[b]},set:function(a){this[b]!==a&&(this[b]=a,this._scheduleReflow())}})}var c=function(a,b){pc.Component.call(this,a,b);this._orientation=pc.ORIENTATION_HORIZONTAL;this._reverseX=!1;this._reverseY=!0;this._alignment=new pc.Vec2(0,1);this._padding=new pc.Vec4;this._spacing=new pc.Vec2;this._heightFitting=
- this._widthFitting=pc.FITTING_NONE;this._wrap=!1;this._layoutCalculator=new pc.LayoutCalculator;this._listenForReflowEvents(this.entity,"on");this.entity.children.forEach(function(a){this._listenForReflowEvents(a,"on")}.bind(this));this.entity.on("childinsert",this._onChildInsert,this);this.entity.on("childremove",this._onChildRemove,this);a.app.systems.element.on("add",this._onElementOrLayoutComponentAdd,this);a.app.systems.element.on("beforeremove",this._onElementOrLayoutComponentRemove,this);a.app.systems.layoutchild.on("add",
- this._onElementOrLayoutComponentAdd,this);a.app.systems.layoutchild.on("beforeremove",this._onElementOrLayoutComponentRemove,this)};c.prototype=Object.create(pc.Component.prototype);c.prototype.constructor=c;Object.assign(c.prototype,{_isSelfOrChild:function(a){return a===this.entity||-1!==this.entity.children.indexOf(a)},_listenForReflowEvents:function(a,b){a.element&&(a.element[b]("enableelement",this._scheduleReflow,this),a.element[b]("disableelement",this._scheduleReflow,this),a.element[b]("resize",
- this._scheduleReflow,this),a.element[b]("set:pivot",this._scheduleReflow,this));a.layoutchild&&(a.layoutchild[b]("set_enabled",this._scheduleReflow,this),a.layoutchild[b]("resize",this._scheduleReflow,this))},_onElementOrLayoutComponentAdd:function(a){this._isSelfOrChild(a)&&(this._listenForReflowEvents(a,"on"),this._scheduleReflow())},_onElementOrLayoutComponentRemove:function(a){this._isSelfOrChild(a)&&(this._listenForReflowEvents(a,"off"),this._scheduleReflow())},_onChildInsert:function(a){this._listenForReflowEvents(a,
- "on");this._scheduleReflow()},_onChildRemove:function(a){this._listenForReflowEvents(a,"off");this._scheduleReflow()},_scheduleReflow:function(){this.enabled&&this.entity&&this.entity.enabled&&!this._isPerformingReflow&&this.system.scheduleReflow(this)},reflow:function(){var a=this.entity.element,c=this.entity.children.filter(b).map(f);a&&0!==c.length&&(a={orientation:this._orientation,reverseX:this._reverseX,reverseY:this._reverseY,alignment:this._alignment,padding:this._padding,spacing:this._spacing,
- widthFitting:this._widthFitting,heightFitting:this._heightFitting,wrap:this._wrap,containerSize:new pc.Vec2(Math.max(a.calculatedWidth,0),Math.max(a.calculatedHeight,0))},this._isPerformingReflow=!0,c=this._layoutCalculator.calculateLayout(c,a),this._isPerformingReflow=!1,this.fire("reflow",c))},onEnable:function(){this._scheduleReflow()},onRemove:function(){this.entity.off("childinsert",this._onChildInsert,this);this.entity.off("childremove",this._onChildRemove,this);this._listenForReflowEvents(this.entity,
- "off");this.entity.children.forEach(function(a){this._listenForReflowEvents(a,"off")}.bind(this));this.system.app.systems.element.off("add",this._onElementOrLayoutComponentAdd,this);this.system.app.systems.element.off("beforeremove",this._onElementOrLayoutComponentRemove,this);this.system.app.systems.layoutchild.off("add",this._onElementOrLayoutComponentAdd,this);this.system.app.systems.layoutchild.off("beforeremove",this._onElementOrLayoutComponentRemove,this)}});a("orientation");a("reverseX");a("reverseY");
- a("alignment");a("padding");a("spacing");a("widthFitting");a("heightFitting");a("wrap");return{LayoutGroupComponent:c}}());Object.assign(pc,function(){var f=["enabled"],b=function(a){pc.ComponentSystem.call(this,a);this.id="layoutgroup";this.app=a;this.ComponentType=pc.LayoutGroupComponent;this.DataType=pc.LayoutGroupComponentData;this.schema=f;this._reflowQueue=[];this.on("beforeremove",this._onRemoveComponent,this);pc.ComponentSystem.bind("postUpdate",this._onPostUpdate,this)};b.prototype=Object.create(pc.ComponentSystem.prototype);b.prototype.constructor=b;pc.Component._buildAccessors(pc.LayoutGroupComponent.prototype,
- f);Object.assign(b.prototype,{initializeComponentData:function(a,b,d){void 0!==b.enabled&&(a.enabled=b.enabled);void 0!==b.orientation&&(a.orientation=b.orientation);void 0!==b.reverseX&&(a.reverseX=b.reverseX);void 0!==b.reverseY&&(a.reverseY=b.reverseY);void 0!==b.alignment&&(b.alignment instanceof pc.Vec2?a.alignment.copy(b.alignment):a.alignment.set(b.alignment[0],b.alignment[1]),a.alignment=a.alignment);void 0!==b.padding&&(b.padding instanceof pc.Vec4?a.padding.copy(b.padding):a.padding.set(b.padding[0],
- b.padding[1],b.padding[2],b.padding[3]),a.padding=a.padding);void 0!==b.spacing&&(b.spacing instanceof pc.Vec2?a.spacing.copy(b.spacing):a.spacing.set(b.spacing[0],b.spacing[1]),a.spacing=a.spacing);void 0!==b.widthFitting&&(a.widthFitting=b.widthFitting);void 0!==b.heightFitting&&(a.heightFitting=b.heightFitting);void 0!==b.wrap&&(a.wrap=b.wrap);pc.ComponentSystem.prototype.initializeComponentData.call(this,a,b,d)},cloneComponent:function(a,b){var c=a.layoutgroup;return this.addComponent(b,{enabled:c.enabled,
- orientation:c.orientation,reverseX:c.reverseX,reverseY:c.reverseY,alignment:c.alignment,padding:c.padding,spacing:c.spacing,widthFitting:c.widthFitting,heightFitting:c.heightFitting,wrap:c.wrap})},scheduleReflow:function(a){-1===this._reflowQueue.indexOf(a)&&this._reflowQueue.push(a)},_onPostUpdate:function(){this._processReflowQueue()},_processReflowQueue:function(){if(0!==this._reflowQueue.length)for(var a=0;0<this._reflowQueue.length;){var b=this._reflowQueue.slice();this._reflowQueue.length=0;
- b.sort(function(a,b){return a.entity.graphDepth-b.entity.graphDepth});for(var d=0;d<b.length;++d)b[d].reflow();if(100<=++a){console.warn("Max reflow iterations limit reached, bailing.");break}}},_onRemoveComponent:function(a,b){b.onRemove()}});return{LayoutGroupComponentSystem:b}}());Object.assign(pc,function(){return{LayoutGroupComponentData:function(){this.enabled=!0}}}());Object.assign(pc,function(){function f(){}function b(b){function f(a){a=a.entity.layoutchild;return!a||!a.enabled||!a.excludeFromLayout}function l(a,b,c){switch(a){case pc.FITTING_NONE:return e.NONE;case pc.FITTING_STRETCH:return b<c?e.APPLY_STRETCHING:e.NONE;case pc.FITTING_SHRINK:return b>=c?e.APPLY_SHRINKING:e.NONE;case pc.FITTING_BOTH:return b<c?e.APPLY_STRETCHING:b>=c?e.APPLY_SHRINKING:e.NONE;default:throw Error("Unrecognized fitting mode: "+a);}}function k(a,b){return y(a,b.size)+(a.length-
- 1)*C.spacing[b.axis]}function q(a,b,c){var d=w(a,c.maxSize),e=u(a,c.fittingProportion),f=z(e,d);b=g[c.axis]-b;for(var l=0;l<a.length;++l){var h=d[l],k=r(h,b,e,f),m=a[h][c.size]+k,n=Math.min(m,a[h][c.maxSize]);a[h][c.size]=n;b-=k-Math.max(m-n,0)}}function m(a,b,c){var d=w(a,c.minSize,!0),e;e=u(a,c.fittingProportion);if(1===e.length)e=[1];else{for(var f=[],l=e.length,h=0;h<l;++h)f.push((1-e[h])/(l-1));e=f}f=z(e,d);b-=g[c.axis];for(l=0;l<a.length;++l){var h=d[l],k=r(h,b,e,f),m=a[h][c.size]-k,n=Math.max(m,
- a[h][c.minSize]);a[h][c.size]=n;b-=k-Math.max(n-m,0)}}function r(a,b,c,d){c=c[a];a=d[a];return 1E-5>Math.abs(c)&&1E-5>Math.abs(a)?b:b*c/a}function t(a){for(var b=[],c=0;c<a.length;++c){var d=a[c],e=Math.max(v(d,"minWidth"),0),f=Math.max(v(d,"minHeight"),0),g=Math.max(v(d,"maxWidth"),e),l=Math.max(v(d,"maxHeight"),f),h;h=v(d,"width");h=Math.min(Math.max(h,e),g);var k;k=v(d,"height");k=Math.min(Math.max(k,f),l);var m=v(d,"fitWidthProportion"),d=v(d,"fitHeightProportion");b.push({minWidth:e,minHeight:f,
- maxWidth:g,maxHeight:l,width:h,height:k,fitWidthProportion:m,fitHeightProportion:d})}return b}function v(a,b){var c=a.entity.layoutchild;return c&&c.enabled&&void 0!==c[b]&&null!==c[b]?c[b]:void 0!==a[b]?a[b]:d[b]}function y(a,b){return a.reduce(function(a,c){return a+c[b]},0)}function u(a,b){var c=y(a,b),d=[],e=a.length,f;if(0===c)for(f=0;f<e;++f)d.push(1/e);else for(f=0;f<e;++f)d.push(a[f][b]/c);return d}function w(a,b,c){a.forEach(x);return a.slice().sort(function(a,d){return c?d[b]-a[b]:a[b]-
- d[b]}).map(D)}function x(a,b){a.index=b}function D(a){return a.index}function z(a,b){var c=[];c[b[a.length-1]]=a[b[a.length-1]];for(var d=a.length-2;0<=d;--d)c[b[d]]=c[b[d+1]]+a[b[d]];return c}var C,A=a[b],B=a[c[b]];return function(a,b){a=a.filter(f);C=b;g.x=C.containerSize.x-C.padding.x-C.padding.z;g.y=C.containerSize.y-C.padding.y-C.padding.w;for(var c=a,d=0;d<c.length;++d){var h=c[d],n=h.anchor;if(0!==n.x||0!==n.y||0!==n.z||0!==n.w)h.anchor=pc.Vec4.ZERO}c=a;if(C.wrap){for(var d=[[]],h=t(c),n=0,
- p=C[A.fitting]===pc.FITTING_SHRINK,r=0;r<c.length;++r){0<d[d.length-1].length&&(n+=C.spacing[A.axis]);var v=h[r][A.size],n=n+v;!p&&n>g[A.axis]&&0!==d[d.length-1].length&&(n=v,d.push([]));d[d.length-1].push(c[r]);p&&n>g[A.axis]&&r!==c.length-1&&(n=0,d.push([]))}c=d}else c=[c];d=C.orientation===pc.ORIENTATION_HORIZONTAL&&C.reverseX||C.orientation===pc.ORIENTATION_VERTICAL&&C.reverseY;h=C.orientation===pc.ORIENTATION_HORIZONTAL&&C.reverseY||C.orientation===pc.ORIENTATION_VERTICAL&&C.reverseX;if(d)for(n=
- 0;n<c.length;++n)d&&c[n].reverse();h&&c.reverse();d=[];for(h=0;h<c.length;++h)n=t(c[h]),p=k(n,A),r=l(C[A.fitting],p,g[A.axis]),r===e.APPLY_STRETCHING?q(n,p,A):r===e.APPLY_SHRINKING&&m(n,p,A),d.push(n);v=[];r=[];for(n=0;n<c.length;++n){p=c[n];p.largestElement=null;p.largestSize={width:Number.NEGATIVE_INFINITY,height:Number.NEGATIVE_INFINITY};for(h=0;h<p.length;++h){var u=d[n][h];u[B.size]>p.largestSize[B.size]&&(p.largestElement=p[h],p.largestSize=u)}v.push(p.largestElement);r.push(p.largestSize)}h=
- k(r,B);n=l(C[B.fitting],h,g[B.axis]);n===e.APPLY_STRETCHING?q(r,h,B):n===e.APPLY_SHRINKING&&m(r,h,B);for(n=0;n<c.length;++n)for(p=c[n],h=0;h<p.length;++h)r=d[n][h],v=1===c.length?g[B.axis]:p.largestSize[B.size],u=l(C[B.fitting],r[B.size],v),u===e.APPLY_STRETCHING?r[B.size]=Math.min(v,r[B.maxSize]):u===e.APPLY_SHRINKING&&(r[B.size]=Math.max(v,r[B.minSize]));a:{h={};h[A.axis]=0;h[B.axis]=0;c[A.size]=Number.NEGATIVE_INFINITY;n=[];for(p=0;p<c.length;++p){r=c[p];if(0===r.length){h=void 0;break a}for(var v=
- [],u=d[p],w=0;w<r.length;++w){var x=r[w],y=u[w];h[B.axis]-=-y[B.size]*x.pivot[B.axis];h[A.axis]-=-y[A.size]*x.pivot[A.axis];v[w]={};v[w][A.axis]=h[A.axis];v[w][B.axis]=h[B.axis];h[B.axis]+=-y[B.size]*x.pivot[B.axis];h[A.axis]+=y[A.size]*(1-x.pivot[A.axis])+C.spacing[A.axis]}r[A.size]=h[A.axis]-C.spacing[A.axis];r[B.size]=r.largestSize[B.size];c[A.size]=Math.max(c[A.size],r[A.size]);h[A.axis]=0;h[B.axis]+=r[B.size]+C.spacing[B.axis];n.push(v)}c[B.size]=h[B.axis]-C.spacing[B.axis];h=n}n=h;p=C.alignment[A.axis];
- r=C.alignment[B.axis];v=C.padding[A.axis];u=C.padding[B.axis];for(w=0;w<c.length;++w)for(var x=c[w],y=d[w],z=n[w],D=(g[A.axis]-x[A.size])*p+v,F=(g[B.axis]-c[B.size])*r+u,J=0;J<x.length;++J){var O=(x[B.size]-y[J][B.size])*C.alignment[B.axis];z[J][A.axis]+=D;z[J][B.axis]+=F+O}for(n=0;n<c.length;++n)for(p=c[n],r=d[n],v=h[n],u=0;u<p.length;++u)w=p[u],w[A.calculatedSize]=r[u][A.size],w[B.calculatedSize]=r[u][B.size],C.orientation===pc.ORIENTATION_HORIZONTAL?w.entity.setLocalPosition(v[u][A.axis],v[u][B.axis],
- w.entity.getLocalPosition().z):w.entity.setLocalPosition(v[u][B.axis],v[u][A.axis],w.entity.getLocalPosition().z);d=c.width;c=c.height;return{bounds:new pc.Vec4((g.x-d)*C.alignment.x+C.padding.x,(g.y-c)*C.alignment.y+C.padding.y,d,c)}}}var a={};a[pc.ORIENTATION_HORIZONTAL]={axis:"x",size:"width",calculatedSize:"calculatedWidth",minSize:"minWidth",maxSize:"maxWidth",fitting:"widthFitting",fittingProportion:"fitWidthProportion"};a[pc.ORIENTATION_VERTICAL]={axis:"y",size:"height",calculatedSize:"calculatedHeight",
- minSize:"minHeight",maxSize:"maxHeight",fitting:"heightFitting",fittingProportion:"fitHeightProportion"};var c={};c[pc.ORIENTATION_HORIZONTAL]=pc.ORIENTATION_VERTICAL;c[pc.ORIENTATION_VERTICAL]=pc.ORIENTATION_HORIZONTAL;var d={minWidth:0,minHeight:0,maxWidth:Number.POSITIVE_INFINITY,maxHeight:Number.POSITIVE_INFINITY,width:null,height:null,fitWidthProportion:0,fitHeightProportion:0},e={NONE:"NONE",APPLY_STRETCHING:"APPLY_STRETCHING",APPLY_SHRINKING:"APPLY_SHRINKING"},g=new pc.Vec2,l={};l[pc.ORIENTATION_HORIZONTAL]=
- b(pc.ORIENTATION_HORIZONTAL);l[pc.ORIENTATION_VERTICAL]=b(pc.ORIENTATION_VERTICAL);Object.assign(f.prototype,{calculateLayout:function(a,b){var c=l[b.orientation];if(c)return c(a,b);throw Error("Unrecognized orientation value: "+b.orientation);}});return{LayoutCalculator:f}}());Object.assign(pc,function(){function f(a){var c="_"+a;Object.defineProperty(b.prototype,a,{get:function(){return this[c]},set:function(a){this[c]!==a&&(this[c]=a,this.fire("resize"))}})}var b=function(a,b){pc.Component.call(this,a,b);this._minHeight=this._minWidth=0;this._maxHeight=this._maxWidth=null;this._fitHeightProportion=this._fitWidthProportion=0;this._excludeFromLayout=!1};b.prototype=Object.create(pc.Component.prototype);b.prototype.constructor=b;f("minWidth");f("minHeight");f("maxWidth");
- f("maxHeight");f("fitWidthProportion");f("fitHeightProportion");f("excludeFromLayout");return{LayoutChildComponent:b}}());Object.assign(pc,function(){var f=["enabled"],b=function(a){pc.ComponentSystem.call(this,a);this.id="layoutchild";this.app=a;this.ComponentType=pc.LayoutChildComponent;this.DataType=pc.LayoutChildComponentData;this.schema=f};b.prototype=Object.create(pc.ComponentSystem.prototype);b.prototype.constructor=b;pc.Component._buildAccessors(pc.LayoutChildComponent.prototype,f);Object.assign(b.prototype,{initializeComponentData:function(a,b,d){void 0!==b.enabled&&(a.enabled=b.enabled);void 0!==b.minWidth&&
- (a.minWidth=b.minWidth);void 0!==b.minHeight&&(a.minHeight=b.minHeight);void 0!==b.maxWidth&&(a.maxWidth=b.maxWidth);void 0!==b.maxHeight&&(a.maxHeight=b.maxHeight);void 0!==b.fitWidthProportion&&(a.fitWidthProportion=b.fitWidthProportion);void 0!==b.fitHeightProportion&&(a.fitHeightProportion=b.fitHeightProportion);void 0!==b.excludeFromLayout&&(a.excludeFromLayout=b.excludeFromLayout);pc.ComponentSystem.prototype.initializeComponentData.call(this,a,b,d)},cloneComponent:function(a,b){var c=a.layoutchild;
- return this.addComponent(b,{enabled:c.enabled,minWidth:c.minWidth,minHeight:c.minHeight,maxWidth:c.maxWidth,maxHeight:c.maxHeight,fitWidthProportion:c.fitWidthProportion,fitHeightProportion:c.fitHeightProportion,excludeFromLayout:c.excludeFromLayout})}});return{LayoutChildComponentSystem:b}}());Object.assign(pc,function(){return{LayoutChildComponentData:function(){this.enabled=!0}}}());Object.assign(pc,function(){pc.FONT_MSDF="msdf";pc.FONT_BITMAP="bitmap";var f=function(b,a){this.type=a?a.type||pc.FONT_MSDF:pc.FONT_MSDF;this.em=1;this.textures=b;this.intensity=0;this._data=null;this.data=a};Object.defineProperty(f.prototype,"data",{get:function(){return this._data},set:function(b){if(this._data=b)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 a in this._data.chars)this._data.chars[a].map=0}});return{FONT_MSDF:pc.FONT_MSDF,Font:f}}());Object.assign(pc,function(){var f=function(b,a){this.type="bitmap";this.app=b;this.intensity=0;a=a||{};this.fontWeight=a.fontWeight||"normal";this.glyphSize=this.fontSize=parseInt(a.fontSize,10);this.fontName=a.fontName||"Arial";this.color=a.color||new pc.Color(1,1,1);var c=4096<a.width?4096:a.width||512,d=4096<a.height?4096:a.height||512,e=document.createElement("canvas");e.height=d;e.width=c;c=new pc.Texture(this.app.graphicsDevice,{format:pc.PIXELFORMAT_R8_G8_B8_A8,autoMipmap:!0});c.name="font";
- c.setSource(e);c.minFilter=pc.FILTER_LINEAR_MIPMAP_LINEAR;c.magFilter=pc.FILTER_LINEAR;c.addressU=pc.ADDRESS_CLAMP_TO_EDGE;c.addressV=pc.ADDRESS_CLAMP_TO_EDGE;this.textures=[c];this.chars="";this.data={};pc.events.attach(this)};f.prototype.createTextures=function(b){b=this._normalizeCharsSet(b);if(b.length!==this.chars.length)this._renderAtlas(b);else for(var a=0;a<b.length;a++)if(b[a]!==this.chars[a]){this._renderAtlas(b);break}};f.prototype.updateTextures=function(b){b=this._normalizeCharsSet(b);
- for(var a=[],c=0;c<b.length;c++){var d=b[c];this.data.chars[d]||a.push(d)}0<a.length&&this._renderAtlas(this.chars.concat(a))};f.prototype.destroy=function(){for(var b=0;b<this.textures.length;b++)this.textures[b].destroy();this.fontWeight=this.type=this.textures=this.intensity=this.glyphSize=this.fontSize=this.fontName=this.data=this.color=this.chars=null};f.prototype._getAndClearContext=function(b,a){var c=b.width,d=b.height,e=b.getContext("2d",{alpha:!0});e.clearRect(0,0,c,d);e.fillStyle=a;e.fillRect(0,
- 0,c,d);return e};f.prototype._colorToRgbString=function(b,a){var c=Math.round(255*b.r),d=Math.round(255*b.g),e=Math.round(255*b.b);return a?"rgba("+c+", "+d+", "+e+", "+b.a+")":"rgb("+c+", "+d+", "+e+")"};f.prototype.renderCharacter=function(b,a,c,d,e){b.fillStyle=e;b.fillText(a,c,d)};f.prototype._renderAtlas=function(b){this.chars=b;b=1;var a=this.textures[b-1].getSource(),c=a.width,d=a.height,e=this._colorToRgbString(this.color,!1),f=this.color.a;this.color.a=1/255;var l=this._colorToRgbString(this.color,
- !0);this.color.a=f;f=this._getAndClearContext(a,l);f.font=this.fontWeight+" "+this.fontSize.toString()+"px "+this.fontName;f.textAlign="center";f.textBaseline="bottom";this.data=this._createJson(this.chars,this.fontName,c,d);var k=pc.string.getSymbols(this.chars.join("")),p=this.textures.length,h=0,n=0,q={},m;for(m=0;m<k.length;m++)a=k[m],q[a]=this._getTextMetrics(a),h=Math.max(h,q[a].height),n=Math.max(n,q[a].descent);var r=h=this.glyphSize=Math.max(this.glyphSize,h),t=h/2,v=t,y=r;for(m=0;m<k.length;m++){var a=
- k[m],u=pc.string.getCodePoint(k[m]);f.font=this.fontWeight+" "+this.fontSize.toString()+"px "+this.fontName;f.textAlign="center";f.textBaseline="bottom";this.renderCharacter(f,a,v,y,e);var w=f.measureText(a).width;this._addChar(this.data,a,u,v-t,y-r,h,r,(h-w)/2,q[a].descent-n,w,b-1,c,d);v+=h;v+t>c&&(v=t,y+=r,y>d&&(this.textures[b-1].upload(),b++,y=r,b>p?(a=document.createElement("canvas"),a.height=d,a.width=c,f=this._getAndClearContext(a,l),u=new pc.Texture(this.app.graphicsDevice,{format:pc.PIXELFORMAT_R8_G8_B8_A8,
- autoMipmap:!0}),u.name="font-atlas",u.setSource(a),u.minFilter=pc.FILTER_LINEAR_MIPMAP_LINEAR,u.magFilter=pc.FILTER_LINEAR,u.addressU=pc.ADDRESS_CLAMP_TO_EDGE,u.addressV=pc.ADDRESS_CLAMP_TO_EDGE,this.textures.push(u)):(a=this.textures[b-1].getSource(),f=this._getAndClearContext(a,l))))}this.textures[b-1].upload();if(b<p){for(m=b;m<p;m++)this.textures[m].destroy();this.textures.splice(b)}this.fire("render")};f.prototype._createJson=function(b,a,c,d){return{version:3,intensity:this.intensity,info:{face:a,
- width:c,height:d,maps:[{width:c,height:d}]},chars:{}}};f.prototype._addChar=function(b,a,c,d,e,f,l,k,p,h,n,q,m){b.info.maps.length<n+1&&b.info.maps.push({width:q,height:m});q=this.fontSize/32;b.chars[a]={id:c,letter:a,x:d,y:e,width:f,height:l,xadvance:h/q,xoffset:k/q,yoffset:p/q,scale:q,range:1,map:n,bounds:[0,0,f/q,l/q]}};f.prototype._normalizeCharsSet=function(b){var a=this.app.systems.element.getUnicodeConverter();a&&(b=a(b));a={};b=pc.string.getSymbols(b);var c;for(c=0;c<b.length;c++){var d=b[c];
- a[d]||(a[d]=d)}return Object.keys(a).sort()};f.prototype._getTextMetrics=function(b){var a=document.createElement("span");a.id="content-span";a.innerHTML=b;b=document.createElement("div");b.id="content-block";b.style.display="inline-block";b.style.width="1px";b.style.height="0px";var c=document.createElement("div");c.appendChild(a);c.appendChild(b);c.style.font=this.fontName;c.style.fontSize=this.fontSize+"px";document.body.appendChild(c);var d=-1,e=-1,f=-1;try{b.style["vertical-align"]="baseline",
- d=b.offsetTop-a.offsetTop,b.style["vertical-align"]="bottom",f=b.offsetTop-a.offsetTop,e=f-d}finally{document.body.removeChild(c)}return{ascent:d,descent:e,height:f}};return{CanvasFont:f}}());Object.assign(pc,function(){var f=function(b,a){pc.Component.call(this,b,a);this._oldState=!0;this._size=new pc.Vec3;this.on("set_enabled",this._onSetEnabled,this)};f.prototype=Object.create(pc.Component.prototype);f.prototype.constructor=f;Object.assign(f.prototype,{onEnable:function(){this._checkState()},onDisable:function(){this._checkState()},_onSetEnabled:function(b,a,c){this._checkState()},_checkState:function(){var b=this.enabled&&this.entity.enabled;b!==this._oldState&&(this._oldState=b,this.fire("enable"),
- this.fire("state",this.enabled))},_onBeforeRemove:function(){this.fire("remove")}});Object.defineProperty(f.prototype,"size",{set:function(b){b instanceof pc.Vec3?this._size.copy(b):b instanceof Array&&3<=b.length&&this.size.set(b[0],b[1],b[2])},get:function(){return this._size}});return{ZoneComponent:f}}());Object.assign(pc,function(){var f=["enabled"],b=function(a){pc.ComponentSystem.call(this,a);this.id="zone";this.app=a;this.ComponentType=pc.ZoneComponent;this.DataType=pc.ZoneComponentData;this.schema=f;this.on("beforeremove",this._onBeforeRemove,this)};b.prototype=Object.create(pc.ComponentSystem.prototype);b.prototype.constructor=b;pc.Component._buildAccessors(pc.ZoneComponent.prototype,f);Object.assign(b.prototype,{initializeComponentData:function(a,b,d){a.enabled=b.hasOwnProperty("enabled")?!!b.enabled:
- !0;b.size&&(b.size instanceof pc.Vec3?a.size.copy(b.size):b.size instanceof Array&&3<=b.size.length&&a.size.set(b.size[0],b.size[1],b.size[2]))},cloneComponent:function(a,b){return this.addComponent(b,{size:a.zone.size})},_onBeforeRemove:function(a,b){b._onBeforeRemove()}});return{ZoneComponentSystem:b}}());Object.assign(pc,function(){return{ZoneComponentData:function(){this.enabled=!0}}}());Object.assign(pc,function(){function f(a,b,d,e){var c,l;if(b instanceof pc.Entity){var k=b.c,p;for(p in k){var h=k[p],n=h.system.getPropertiesOfType("entity");c=0;for(l=n.length;c<l;c++){var q=n[c].name,m=h[q];a.findByGuid(m)&&((m=e[m].getGuid())?d.c[p][q]=m:console.warn("Could not find corresponding entity id when resolving duplicated entity references"))}}k.script&&!d._app.useLegacyScriptAttributeCloning&&d.script.resolveDuplicatedEntityReferenceProperties(k.script,e);b=b.children.filter(function(a){return a instanceof
- pc.Entity});d=d.children.filter(function(a){return a instanceof pc.Entity});c=0;for(l=b.length;c<l;c++)f(a,b[c],d[c],e)}}var b=function(a,b){pc.GraphNode.call(this,a);a instanceof pc.Application&&(b=a);this._batchHandle=null;this.c={};this._app=b;if(!b&&(this._app=pc.Application.getApplication(),!this._app))throw Error("Couldn't find current application");this._guid=null;this._destroying=!1;pc.events.attach(this)};b.prototype=Object.create(pc.GraphNode.prototype);b.prototype.constructor=b;b.prototype.addComponent=
- function(a,b){var c=this._app.systems[a];return!c||this.c[a]?null:c.addComponent(this,b)};b.prototype.removeComponent=function(a){var b=this._app.systems[a];b&&this.c[a]&&b.removeComponent(this)};b.prototype.getGuid=function(){this._guid||this.setGuid(pc.guid.create());return this._guid};b.prototype.setGuid=function(a){var b=this._app._entityIndex;this._guid&&delete b[this._guid];this._guid=a;b[this._guid]=this};b.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 e,f,l=a._children;e=0;for(f=l.length;e<f;e++)l[e]._enabled&&this._notifyHierarchyStateChanged(l[e],b);a._beingEnabled=!1;if(c){e=0;for(f=this._app._enableList.length;e<f;e++)this._app._enableList[e]._onHierarchyStatePostChanged();this._app._enableList.length=0}};b.prototype._onHierarchyStateChanged=function(a){pc.GraphNode.prototype._onHierarchyStateChanged.call(this,a);var b,
- d=this.c,e;for(e in d)if(d.hasOwnProperty(e)&&(b=d[e],b.enabled))if(a)b.onEnable();else b.onDisable()};b.prototype._onHierarchyStatePostChanged=function(){var a=this.c,b;for(b in a)if(a.hasOwnProperty(b))a[b].onPostStateChange()};b.prototype.setRequest=function(a){this._request=a};b.prototype.getRequest=function(){return this._request};b.prototype.findByGuid=function(a){return this._guid===a?this:(a=this._app._entityIndex[a])&&(a===this||a.isDescendantOf(this))?a:null};b.prototype.destroy=function(){var a;
- this._destroying=!0;for(a in this.c)this.c[a].enabled=!1;for(a in this.c)this.c[a].system.removeComponent(this);this._parent&&this._parent.removeChild(this);a=this._children;for(var b=a.shift();b;)b instanceof pc.Entity&&b.destroy(),b._parent=null,b=a.shift();this.fire("destroy",this);this.off();this._guid&&delete this._app._entityIndex[this._guid];this._destroying=!1};b.prototype.clone=function(){var a={},b=this._cloneRecursively(a);a[this.getGuid()]=b;f(this,this,b,a);return b};b.prototype._cloneRecursively=
- function(a){var b=new pc.Entity(this._app);pc.GraphNode.prototype._cloneInternal.call(this,b);for(var d in this.c)this.c[d].system.cloneComponent(this,b);for(d=0;d<this._children.length;d++){var e=this._children[d];if(e instanceof pc.Entity){var f=e._cloneRecursively(a);b.addChild(f);a[e.getGuid()]=f}}return b};return{Entity:b}}());Object.assign(pc,function(){function f(b,a,c){if(b&&b instanceof pc.Component){if(!a||"string"!==typeof a)throw Error("The propertyName argument is required and must be a string");if(c&&"object"!==typeof c)throw Error("If provided, the eventConfig argument must be an object");}else throw Error("The parentComponent argument is required and must be a Component");this._parentComponent=b;this._entityPropertyName=a;this._entity=null;this._app=b.system.app;this._configureEventListeners(c||{},{"entity#destroy":this._onEntityDestroy});
- this._toggleLifecycleListeners("on")}Object.assign(f.prototype,{_configureEventListeners:function(b,a){var c=this._parseEventListenerConfig(b,"external",this._parentComponent),d=this._parseEventListenerConfig(a,"internal",this);this._eventListenerConfigs=c.concat(d);this._listenerStatusFlags={};this._gainListeners={};this._loseListeners={}},_parseEventListenerConfig:function(b,a,c){return Object.keys(b).map(function(d,e){var f=d.split("#"),l=f[0],k=f[1],p=b[d];if(2!==f.length||"string"!==typeof l||
- 0===l.length||"string"!==typeof k||0===k.length)throw Error("Invalid event listener description: `"+d+"`");if("function"!==typeof p)throw Error("Invalid or missing callback for event listener `"+d+"`");return{id:a+"_"+e+"_"+d,sourceName:l,eventName:k,callback:p,scope:c}},this)},_toggleLifecycleListeners:function(b){this._parentComponent[b]("set_"+this._entityPropertyName,this._onSetEntity,this);this._parentComponent.system[b]("beforeremove",this._onParentComponentRemove,this);pc.ComponentSystem[b]("postinitialize",
- this._onPostInitialize,this);this._app[b]("tools:sceneloaded",this._onSceneLoaded,this);for(var a=[],c=0;c<this._eventListenerConfigs.length;++c){var d=this._eventListenerConfigs[c],e=this._app.systems[d.sourceName];e&&(-1===a.indexOf(e)&&a.push(e),e&&"gain"===d.eventName&&(this._gainListeners[d.sourceName]=d),e&&"lose"===d.eventName&&(this._loseListeners[d.sourceName]=d))}for(c=0;c<a.length;++c)a[c][b]("add",this._onComponentAdd,this),a[c][b]("beforeremove",this._onComponentRemove,this)},_onSetEntity:function(b,
- a,c){c instanceof pc.Entity?this._updateEntityReference():null!==c&&void 0!==c&&"string"!==typeof c?console.warn("Entity field `"+this._entityPropertyName+"` was set to unexpected type '"+typeof c+"'"):a!==c&&this._updateEntityReference()},_onPostInitialize:function(){this._updateEntityReference()},onParentComponentEnable:function(){this._entity||this._updateEntityReference()},_onSceneLoaded:function(){this._updateEntityReference()},_updateEntityReference:function(){var b=this._parentComponent.data[this._entityPropertyName],
- a;b instanceof pc.Entity?(a=b,b=a.getGuid(),this._parentComponent.data[this._entityPropertyName]=b):(a=this._parentComponent.system.app.root,a=this._parentComponent.entity.isDescendantOf(a)&&b?a.findByGuid(b):null);this._entity!==a&&(this._entity&&this._onBeforeEntityChange(),(this._entity=a)&&this._onAfterEntityChange())},_onBeforeEntityChange:function(){this._toggleEntityListeners("off");this._callAllGainOrLoseListeners(this._loseListeners)},_onAfterEntityChange:function(){this._toggleEntityListeners("on");
- this._callAllGainOrLoseListeners(this._gainListeners)},_onComponentAdd:function(b,a){var c=a.system.id;b===this._entity&&(this._callGainOrLoseListener(c,this._gainListeners),this._toggleComponentListeners("on",c))},_onComponentRemove:function(b,a){var c=a.system.id;b===this._entity&&(this._callGainOrLoseListener(c,this._loseListeners),this._toggleComponentListeners("off",c,!0))},_callAllGainOrLoseListeners:function(b){for(var a in this._entity.c)this._callGainOrLoseListener(a,b)},_callGainOrLoseListener:function(b,
- a){if(this._entity.c.hasOwnProperty(b)&&a[b]){var c=a[b];c.callback.call(c.scope)}},_toggleEntityListeners:function(b,a){if(this._entity)for(var c=0;c<this._eventListenerConfigs.length;++c)this._safeToggleListener(b,this._eventListenerConfigs[c],a)},_toggleComponentListeners:function(b,a,c){for(var d=0;d<this._eventListenerConfigs.length;++d){var e=this._eventListenerConfigs[d];e.sourceName===a&&this._safeToggleListener(b,e,c)}},_safeToggleListener:function(b,a,c){var d="on"===b;if(!d||!this._listenerStatusFlags[a.id])if(c=
- this._getEventSource(a.sourceName,c))c[b](a.eventName,a.callback,a.scope),this._listenerStatusFlags[a.id]=d},_getEventSource:function(b,a){if("entity"===b)return this._entity;var c=this._entity[b];if(c)return c;a||console.warn("Entity has no component with name "+b);return null},_onEntityDestroy:function(b){this._entity===b&&(this._toggleEntityListeners("off",!0),this._entity=null)},_onParentComponentRemove:function(b,a){a===this._parentComponent&&(this._toggleLifecycleListeners("off"),this._toggleEntityListeners("off",
- !0))},hasComponent:function(b){return this._entity&&this._entity.c?!!this._entity.c[b]:!1}});Object.defineProperty(f.prototype,"entity",{get:function(){return this._entity}});return{EntityReference:f}}());Object.assign(pc,function(){var f=function(b){this._sortBy=b.sortBy;this.items=[];this.length=0;this.loopIndex=-1;this._sortHandler=this._doSort.bind(this)};f.prototype._binarySearch=function(b){var a=0,c=this.items.length-1;b=b[this._sortBy];for(var d,e;a<=c;)d=Math.floor((a+c)/2),e=this.items[d][this._sortBy],e<=b?a=d+1:e>b&&(c=d-1);return a};f.prototype._doSort=function(b,a){var c=this._sortBy;return b[c]-a[c]};f.prototype.insert=function(b){var a=this._binarySearch(b);this.items.splice(a,0,b);
- this.length++;this.loopIndex>=a&&this.loopIndex++};f.prototype.append=function(b){this.items.push(b);this.length++};f.prototype.remove=function(b){b=this.items.indexOf(b);0>b||(this.items.splice(b,1),this.length--,this.loopIndex>=b&&this.loopIndex--)};f.prototype.sort=function(){var b=0<=this.loopIndex?this.items[this.loopIndex]:null;this.items.sort(this._sortHandler);null!==b&&(this.loopIndex=this.items.indexOf(b))};return{SortedLoopArray:f}}());Object.assign(pc,function(){var f=function(b){this._handlers={};this._requests={};this._cache={};this._app=b};Object.assign(f.prototype,{addHandler:function(b,a){this._handlers[b]=a;a._loader=this},removeHandler:function(b){delete this._handlers[b]},getHandler:function(b){return this._handlers[b]},load:function(b,a,c,d){var e=this._handlers[a];if(e){var f=b+a;if(void 0!==this._cache[f])c(null,this._cache[f]);else if(this._requests[f])this._requests[f].push(c);else{this._requests[f]=[c];var l=function(a,
- b){if(a){console.error(a);if(this._requests[f])for(var c=0,g=this._requests[f].length;c<g;c++)this._requests[f][c](a);delete this._requests[f]}else e.load(b,function(a,c,g){if(this._requests[f]){var l=this._requests[f].length,h;if(!a)try{h=e.open(b.original,c,d)}catch(y){a=y}if(a)for(console.error(a),c=0;c<l;c++)this._requests[f][c](a);else for(this._cache[f]=h,c=0;c<l;c++)this._requests[f][c](null,h,g);delete this._requests[f]}}.bind(this),d)}.bind(this);a=b.split("?")[0];this._app.enableBundles&&
- this._app.bundles.hasUrl(a)?this._app.bundles.canLoadUrl(a)?this._app.bundles.loadUrl(a,function(a,c){l(a,{load:c,original:b})}):l("Bundle for "+b+" not loaded yet"):l(null,{load:b,original:b})}}else c("No handler for asset type: "+a)},open:function(b,a){var c=this._handlers[b];return c?c.open(null,a):(console.warn("No resource handler found for: "+b),a)},patch:function(b,a){var c=this._handlers[b.type];c?c.patch&&c.patch(b,a):console.warn("No resource handler found for: "+b.type)},clearCache:function(b,
- a){delete this._cache[b+a]},getFromCache:function(b,a){if(this._cache[b+a])return this._cache[b+a]},destroy:function(){this._handlers={};this._requests={};this._cache={}}});return{ResourceLoader:f}}());Object.assign(pc,function(){var f=function(b){this._assets=b;this._worker=null};Object.assign(f.prototype,{load:function(b,a){"string"===typeof b&&(b={load:b,original:b});var c=this;pc.http.get(b.load,{responseType:pc.Http.ResponseType.ARRAY_BUFFER},function(d,e){if(d)a("Error loading bundle resource "+b.original+": "+d);else try{c._untar(e,a)}catch(g){a("Error loading bundle resource "+b.original+": "+g)}})},_untar:function(b,a){var c=this;if(pc.platform.workers)c._worker||(c._worker=new pc.UntarWorker(c._assets.prefix)),
- c._worker.untar(b,function(b,d){a(b,d);c._worker.hasPendingRequests()||(c._worker.destroy(),c._worker=null)});else{var d=(new pc.Untar(b)).untar(c._assets.prefix);a(null,d)}},open:function(b,a){return new pc.Bundle(a)},patch:function(b,a){}});return{BundleHandler:f}}());Object.assign(pc,function(){function f(a){function c(a){this._fields=a}var d,f;"undefined"!==typeof TextDecoder?(d=new TextDecoder("utf-8"),f=new TextDecoder("windows-1252")):console.warn("TextDecoder not supported - pc.Untar module will not work");c.parse=function(a,b,e){for(var f=new Uint8Array(a,b,e),g=0,l=[];g<e;){var h;for(h=g;h<e&&32!=f[h];h++);if(h>=e)throw Error("Invalid PAX header data format.");var k=parseInt(d.decode(new Uint8Array(a,b+g,h-g)),10);h=d.decode(new Uint8Array(a,b+h+1,k-(h-
- g)-2)).split("=");if(2!==h.length)throw Error("Invalid PAX header data format.");0===h[1].length&&(h[1]=null);l.push({name:h[0],value:h[1]});g+=k}return new c(l)};c.prototype.applyHeader=function(a){for(var b=0;b<this._fields.length;b++){var c=this._fields[b].name,d=this._fields[b].value;"path"===c&&(c="name");null===d?delete a[c]:a[c]=d}};var k=function(a){this._arrayBuffer=a||new ArrayBuffer(0);this._bufferView=new DataView(this._arrayBuffer);this._globalPaxHeader=null;this._bytesRead=0};a||(b=
- k);k.prototype._hasNext=function(){return this._bytesRead+4<this._arrayBuffer.byteLength&&0!==this._bufferView.getUint32(this._bytesRead)};k.prototype._readNextFile=function(){var b=new DataView(this._arrayBuffer,this._bytesRead,512),d=f.decode(b);this._bytesRead+=512;var b=d.substr(0,100).replace(/\0/g,""),e=d.substr(257,6),g=parseInt(d.substr(124,12),8),l=d.substr(156,1),k=this._bytesRead,t=null,v,y=!1;switch(l){case "0":case "":y=!0;a||(t=new Blob([this._arrayBuffer.slice(this._bytesRead,this._bytesRead+
- g)]),t=URL.createObjectURL(t));break;case "g":this._globalPaxHeader=c.parse(this._arrayBuffer,this._bytesRead,g);break;case "x":v=c.parse(this._arrayBuffer,this._bytesRead,g)}this._bytesRead+=g;l=g%512;0!==l&&(this._bytesRead+=512-l);if(!y)return null;-1!==e.indexOf("ustar")&&(d=d.substr(345,155).replace(/\0/g,""),0<d.length&&(b=d.trim()+b.trim()));b={name:b,start:k,size:g,url:t};this._globalPaxHeader&&this._globalPaxHeader.applyHeader(b);v&&v.applyHeader(b);return b};k.prototype.untar=function(a){if(!d)return console.error("Cannot untar because TextDecoder interface is not available for this platform."),
- [];for(var b=[];this._hasNext();){var c=this._readNextFile();c&&(a&&c.name&&(c.name=a+c.name),b.push(c))}return b};a&&(self.onmessage=function(a){var b=a.data.id;try{var c=(new k(a.data.arrayBuffer)).untar(a.data.prefix);postMessage({id:b,files:c,arrayBuffer:a.data.arrayBuffer},[a.data.arrayBuffer])}catch(q){postMessage({id:b,error:q.toString()})}})}var b,a=function(){var a=new Blob(["("+f.toString()+")(true)\n\n"],{type:"application/javascript"});return URL.createObjectURL(a)}(),c=function(b){this._requestId=
- 0;this._pendingRequests={};this._filenamePrefix=b;this._worker=new Worker(a);this._worker.addEventListener("message",this._onMessage.bind(this))};c.prototype._onMessage=function(a){var b=a.data.id;if(this._pendingRequests[b]){var c=this._pendingRequests[b];delete this._pendingRequests[b];if(a.data.error)c(a.data.error);else{for(var b=a.data.arrayBuffer,d=0,f=a.data.files.length;d<f;d++){var p=a.data.files[d],h=new Blob([b.slice(p.start,p.start+p.size)]);p.url=URL.createObjectURL(h)}c(null,a.data.files)}}};
- c.prototype.untar=function(a,b){var c=this._requestId++;this._pendingRequests[c]=b;this._worker.postMessage({id:c,prefix:this._filenamePrefix,arrayBuffer:a},[a])};c.prototype.hasPendingRequests=function(){for(var a in this._pendingRequests)return!0;return!1};c.prototype.destroy=function(){this._worker&&(this._worker.terminate(),this._pendingRequests=this._worker=null)};f();return{Untar:b,UntarWorker:c}}());Object.assign(pc,function(){var f=function(){};Object.assign(f.prototype,{load:function(b,a){"string"===typeof b&&(b={load:b,original:b});var c={};b.load.startsWith("blob:")&&(c.responseType=pc.Http.ResponseType.JSON);pc.http.get(b.load,c,function(c,e){c?a(pc.string.format("Error loading animation resource: {0} [{1}]",b.original,c)):a(null,e)})},open:function(b,a){return this["_parseAnimationV"+a.animation.version](a)},_parseAnimationV3:function(b){b=b.animation;var a=new pc.Animation;a.setName(b.name);
- a.duration=b.duration;for(var c=0;c<b.nodes.length;c++){var d=new pc.Node,e=b.nodes[c];d._name=e.name;for(var f=0;f<e.keys.length;f++){var l=e.keys[f],k=l.time,p=l.pos,h=l.rot,l=l.scale,p=new pc.Vec3(p[0],p[1],p[2]),h=(new pc.Quat).setFromEulerAngles(h[0],h[1],h[2]),l=new pc.Vec3(l[0],l[1],l[2]),k=new pc.Key(k,p,h,l);d._keys.push(k)}a.addNode(d)}return a},_parseAnimationV4:function(b){b=b.animation;var a=new pc.Animation;a.setName(b.name);a.duration=b.duration;for(var c=0;c<b.nodes.length;c++){var d=
- new pc.Node,e=b.nodes[c];d._name=e.name;for(var f=e.defaults.p,l=e.defaults.r,k=e.defaults.s,p=0;p<e.keys.length;p++){var h=e.keys[p],n=h.t,q=f?f:h.p,m=l?l:h.r,h=k?k:h.s,q=new pc.Vec3(q[0],q[1],q[2]),m=(new pc.Quat).setFromEulerAngles(m[0],m[1],m[2]),h=new pc.Vec3(h[0],h[1],h[2]),n=new pc.Key(n,q,m,h);d._keys.push(n)}a.addNode(d)}return a}});return{AnimationHandler:f}}());Object.assign(pc,function(){var f=function(){var a=window.navigator.userAgent,b=a.indexOf("MSIE ");return 0<b?parseInt(a.substring(b+5,a.indexOf(".",b)),10):0<a.indexOf("Trident/")?(b=a.indexOf("rv:"),parseInt(a.substring(b+3,a.indexOf(".",b)),10)):!1}(),b=function(a){this.manager=a};Object.assign(b.prototype,{_isSupported:function(a){return{".ogg":"audio/ogg",".mp3":"audio/mpeg",".wav":"audio/x-wav",".mp4a":"audio/mp4",".m4a":"audio/mp4",".mp4":"audio/mp4",".aac":"audio/aac"}[pc.path.getExtension(a)]?
- !0:!1},load:function(a,b){"string"===typeof a&&(a={load:a,original:a});var c=function(a){b(null,new pc.Sound(a))},e=function(c){c=c||"Error loading audio url: "+a.original;console.warn(c);b(c)};this._createSound?this._isSupported(a.original)?this._createSound(a.load,c,e):e(pc.string.format("Audio format for {0} not supported",a.original)):e(null)},open:function(a,b){return b}});pc.SoundManager.hasAudioContext()?b.prototype._createSound=function(a,b,d){var c=this.manager;if(c.context){var f={};a.startsWith("blob:")&&
- (f.responseType=pc.Http.ResponseType.ARRAY_BUFFER);pc.http.get(a,f,function(a,e){a?d(a):c.context.decodeAudioData(e,b,d)})}else d("Audio manager has no audio context")}:pc.SoundManager.hasAudio()&&(b.prototype._createSound=function(a,b,d){var c=null;try{c=new Audio}catch(l){d("No support for Audio element");return}f&&document.body.appendChild(c);var g=function(){c.removeEventListener("canplaythrough",g);f&&document.body.removeChild(c);b(c)};c.onerror=function(){c.onerror=null;f&&document.body.removeChild(c);
- d()};c.addEventListener("canplaythrough",g);c.src=a});return{AudioHandler:b}}());Object.assign(pc,function(){var f=function(b,a,c){this._device=b;this._assets=a;this._loader=c};Object.assign(f.prototype,{load:function(b,a){},open:function(b,a){},patch:function(b,a){var c=this,d=!1;b.resources[0]||(b.resources[0]=new pc.Texture(this._device,{format:pc.PIXELFORMAT_R8_G8_B8_A8,cubemap:!0,mipmaps:!0,fixCubemapSeams:!!b._dds}),b.resources[0].name="cubemap",d=!0);if(!b.file)delete b._dds;else if(b.file&&!b._dds){var e=b.getFileUrl();a._loader.load(e+"?t="+b.file.hash,"texture",function(d,
- e){d?(a.fire("error",d,b),a.fire("error:"+b.id,d,b),b.fire("error",d,b)):(a._loader.patch({resource:e,type:"texture",data:b.data},a),b._dds=e,c.patch(b,a))})}if((!b.file||!b._dds)&&b.resources[1])b.resources=[b.resources[0]],d=!0;else if(b._dds&&!b.resources[1]){b.resources=[b.resources[0]];b._dds.fixCubemapSeams=!0;b._dds.addressU=pc.ADDRESS_CLAMP_TO_EDGE;b._dds.addressV=pc.ADDRESS_CLAMP_TO_EDGE;d=0;this._device.useTexCubeLod&&(b.resources.push(b._dds),d=1);for(;6>d;d++)e=new pc.Texture(this._device,
- {cubemap:!0,fixCubemapSeams:!0,mipmaps:!0,format:b._dds.format,rgbm:b._dds.rgbm,width:Math.pow(2,7-d),height:Math.pow(2,7-d)}),e.name="cubemap-mip",e._levels[0]=b._dds._levels[d],e.upload(),b.resources.push(e);d=!0}e=b.resource;e.name!==b.name&&(e.name=b.name);var f=!!b.data.rgbm;b.data.hasOwnProperty("rgbm")&&e.rgbm!==f&&(e.rgbm=f);e.fixCubemapSeams=!!b._dds;b.data.hasOwnProperty("minFilter")&&e.minFilter!==b.data.minFilter&&(e.minFilter=b.data.minFilter);b.data.hasOwnProperty("magFilter")&&e.magFilter!==
- b.data.magFilter&&(e.magFilter=b.data.magFilter);b.data.hasOwnProperty("anisotropy")&&e.anisotropy!==b.data.anisotropy&&(e.anisotropy=b.data.anisotropy);e.addressU!==pc.ADDRESS_CLAMP_TO_EDGE&&(e.addressU=pc.ADDRESS_CLAMP_TO_EDGE);e.addressV!==pc.ADDRESS_CLAMP_TO_EDGE&&(e.addressV=pc.ADDRESS_CLAMP_TO_EDGE);this._patchTextureFaces(b,a);d&&(a.fire("load",b),a.fire("load:"+b.id,b),b.fire("load",b))},_patchTexture:function(){this.registry._loader._handlers.cubemap._patchTextureFaces(this,this.registry)},
- _patchTextureFaces:function(b,a){if(b.loadFaces||!b.file){var c=b.resource,d=[],e=0,f=!1,l=this;b._levelsEvents||(b._levelsEvents=[null,null,null,null,null,null]);b.data.textures.forEach(function(g,p){var h=function(g){e++;d[p]=g&&g.resource.getSource()||null;var h=b._levelsEvents[p];if(h!==g){h&&h.off("load",l._patchTexture,b);if(g)g.on("load",l._patchTexture,b);b._levelsEvents[p]=g||null}d[p]!==c._levels[0][p]&&(f=!0);6===e&&f&&(c.setSource(d),a.fire("load",b),a.fire("load:"+b.id,b),b.fire("load",
- b))},k=function(b){b.ready(h);a.load(b)},q=a.get(g);q?(q.ready(h),a.load(q)):g?(a.once("load:"+g,h),a.once("add:"+g,k)):h(null)})}}});return{CubemapHandler:f}}());Object.assign(pc,function(){var f=function(){};Object.assign(f.prototype,{load:function(b,a){"string"===typeof b&&(b={load:b,original:b});var c={};b.load.startsWith("blob:")&&(c.responseType=pc.Http.ResponseType.JSON);pc.http.get(b.load,c,function(c,e){c?a(pc.string.format("Error loading JSON resource: {0} [{1}]",b.original,c)):a(null,e)})},open:function(b,a){return a},patch:function(b,a){}});return{JsonHandler:f}}());Object.assign(pc,function(){var f={aoMap:"white",diffuseMap:"gray",specularMap:"gray",metalnessMap:"black",glossMap:"gray",emissiveMap:"gray",normalMap:"normal",heightMap:"gray",opacityMap:"gray",sphereMap:"gray",lightMap:"white"},b=function(a){this._assets=a.assets;this._device=a.graphicsDevice;this._placeholderTextures=null;this._parser=new pc.JsonStandardMaterialParser};Object.assign(b.prototype,{load:function(a,b){"string"===typeof a&&(a={load:a,original:a});pc.http.get(a.load,function(c,e){c?
- b&&b(pc.string.format("Error loading material: {0} [{1}]",a.original,c)):b&&(e._engine=!0,b(null,e))})},open:function(a,b){var c=this._parser.parse(b);b._engine&&(c._data=b,delete b._engine);return c},_createPlaceholders:function(){this._placeholderTextures={};var a={white:[255,255,255,255],gray:[128,128,128,255],black:[0,0,0,255],normal:[128,128,255,255]},b;for(b in a)if(a.hasOwnProperty(b)){this._placeholderTextures[b]=new pc.Texture(this._device,{width:2,height:2,format:pc.PIXELFORMAT_R8_G8_B8_A8});
- this._placeholderTextures[b].name="placeholder";for(var d=this._placeholderTextures[b].lock(),e=0;4>e;e++)for(var f=0;4>f;f++)d[4*e+f]=a[b][f];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,d){b.data[a]=d;b.resource[a]=d},_assignPlaceholderTexture:function(a,b){this._placeholderTextures||this._createPlaceholders();b.resource[a]=this._placeholderTextures[f[a]]},_onTextureLoad:function(a,b,d){this._assignTexture(a,b,d.resource);b.resource.update()},_onTextureAdd:function(a,b,d){this._assets.load(d)},_onTextureRemove:function(a,b,d){var c=b.resource;c[a]===d.resource&&(this._assignTexture(a,b,null),c.update())},_assignCubemap:function(a,b,d){b.data[a]=d[0];7===
- d.length&&(b.data.prefilteredCubeMap128=d[1],b.data.prefilteredCubeMap64=d[2],b.data.prefilteredCubeMap32=d[3],b.data.prefilteredCubeMap16=d[4],b.data.prefilteredCubeMap8=d[5],b.data.prefilteredCubeMap4=d[6])},_onCubemapLoad:function(a,b,d){this._assignCubemap(a,b,d.resources);this._parser.initialize(b.resource,b.data)},_onCubemapAdd:function(a,b,d){b.data.shadingModel===pc.SPECULAR_PHONG&&(b.loadFaces=!0);this._assets.load(d)},_onCubemapRemove:function(a,b,d){var c=b.resource;c[a]===d.resource&&
- (this._assignCubemap(a,b,[null,null,null,null,null,null,null]),c.update())},_bindAndAssignAssets:function(a,b){var c=this._parser.migrate(a.data),e=a.resource,f="path"===c.mappingFormat,l=pc.StandardMaterial.TEXTURE_PARAMETERS,k;f&&(k=pc.path.getDirectory(a.getFileUrl()));var p,h,n;for(p=0;p<l.length;p++)(h=l[p],n=e._assetReferences[h],!c[h]||c[h]instanceof pc.Texture)?n&&(f?n.url=null:n.id=null):(n||(n=new pc.AssetReference(h,a,b,{load:this._onTextureLoad,add:this._onTextureAdd,remove:this._onTextureRemove},
- this),e._assetReferences[h]=n),f?n.url=pc.path.join(k,c[h]):n.id=c[h],n.asset&&(n.asset.resource?this._assignTexture(h,a,n.asset.resource):this._assignPlaceholderTexture(h,a),b.load(n.asset)));l=pc.StandardMaterial.CUBEMAP_PARAMETERS;for(p=0;p<l.length;p++)h=l[p],n=e._assetReferences[h],!c[h]||c[h]instanceof pc.Texture||(n||(n=new pc.AssetReference(h,a,b,{load:this._onCubemapLoad,add:this._onCubemapAdd,remove:this._onCubemapRemove},this),e._assetReferences[h]=n),f?n.url=c[h]:n.id=c[h],n.asset&&(n.asset.resource&&
- this._assignCubemap(h,a,n.asset.resources),b.load(n.asset)));this._parser.initialize(e,c)}});return{MaterialHandler:b}}());Object.assign(pc,function(){var f=function(b,a){this._device=b;this._parsers=[];this._defaultMaterial=a;this.addParser(new pc.JsonModelParser(this._device),function(a,b){return".json"===pc.path.getExtension(a)})};Object.assign(f.prototype,{load:function(b,a){"string"===typeof b&&(b={load:b,original:b});var c={};b.load.startsWith("blob:")&&(c.responseType=pc.Http.ResponseType.JSON);pc.http.get(b.load,c,function(c,e){a&&(c?a(pc.string.format("Error loading model: {0} [{1}]",b.original,c)):a(null,e))})},
- open:function(b,a){for(var c=0;c<this._parsers.length;c++){var d=this._parsers[c];if(d.decider(b,a))return d.parser.parse(a)}logWARNING(pc.string.format("No model parser found for: {0}",b));return null},patch:function(b,a){if(b.resource){var c=b.data,d=this;b.resource.meshInstances.forEach(function(e,f){if(c.mapping){var g=function(b){b.resource?e.material=b.resource:(b.once("load",g),a.load(b));b.once("remove",function(a){e.material===a.resource&&(e.material=d._defaultMaterial)})};if(c.mapping[f]){var k=
- c.mapping[f].material,p=c.mapping[f].path;if(void 0!==k)if(k)if(p=a.get(k))g(p);else a.once("add:"+k,g);else e.material=d._defaultMaterial;else if(p)if(k=b.getFileUrl(),k=pc.path.getDirectory(k),k=pc.path.join(k,c.mapping[f].path),p=a.getByUrl(k))g(p);else a.once("add:url:"+k,g)}else e.material=d._defaultMaterial}})}},addParser:function(b,a){this._parsers.push({parser:b,decider:a})}});return{ModelHandler:f}}());Object.assign(pc,function(){var f=function(b){this._app=b;this._scripts={};this._cache={}};f._types=[];f._push=function(b){pc.script.legacy&&0<f._types.length?console.assert("Script Ordering Error. Contact support@playcanvas.com"):f._types.push(b)};Object.assign(f.prototype,{load:function(b,a){"string"===typeof b&&(b={load:b,original:b});var c=this;pc.script.app=this._app;this._loadScript(b.original,function(b,e,g){if(b)a(b);else if(pc.script.legacy)b=null,f._types.length&&(b=f._types.pop()),b?this._scripts[e]=
- b:b=null,a(null,b,g);else{b={};for(var d=0;d<f._types.length;d++)b[f._types[d].name]=f._types[d];f._types.length=0;a(null,b,g);delete c._loader._cache[e+"script"]}}.bind(this))},open:function(b,a){return a},patch:function(b,a){},_loadScript:function(b,a){var c=document.head,d=document.createElement("script");this._cache[b]=d;d.async=!1;d.addEventListener("error",function(b){a(pc.string.format("Script: {0} failed to load",b.target.src))},!1);var e=!1;d.onload=d.onreadystatechange=function(){e||this.readyState&&
- "loaded"!=this.readyState&&"complete"!=this.readyState||(e=!0,a(null,b,d))};d.src=b;c.appendChild(d)}});return{ScriptHandler:f}}());Object.assign(pc,function(){var f=function(){};Object.assign(f.prototype,{load:function(b,a){"string"===typeof b&&(b={load:b,original:b});pc.http.get(b.load,function(c,d){c?a(pc.string.format("Error loading text resource: {0} [{1}]",b.original,c)):a(null,d)})},open:function(b,a){return a},patch:function(b,a){}});return{TextHandler:f}}());Object.assign(pc,function(){var f=function(){};Object.assign(f.prototype,{load:function(b,a){"string"===typeof b&&(b={load:b,original:b});pc.http.get(b.load,{responseType:pc.Http.ResponseType.ARRAY_BUFFER},function(c,d){c?a(pc.string.format("Error loading binary resource: {0} [{1}]",b.original,c)):a(null,d)})},open:function(b,a){return a},patch:function(b,a){}});return{BinaryHandler:f}}());Object.assign(pc,function(){var f=function(a){return a.charCodeAt(0)+(a.charCodeAt(1)<<8)+(a.charCodeAt(2)<<16)+(a.charCodeAt(3)<<24)},b=f("DDS "),a=f("DXT1"),c=f("DXT5"),d=f("DX10"),e=f("ETC1"),g=f("P231"),l=f("P241"),k=f("P431"),p=f("P441"),h={};h[116]=pc.PIXELFORMAT_RGBA32F;h[a]=pc.PIXELFORMAT_DXT1;h[c]=pc.PIXELFORMAT_DXT5;h[e]=pc.PIXELFORMAT_ETC1;h[g]=pc.PIXELFORMAT_PVRTC_2BPP_RGB_1;h[l]=pc.PIXELFORMAT_PVRTC_2BPP_RGBA_1;h[k]=pc.PIXELFORMAT_PVRTC_4BPP_RGB_1;h[p]=pc.PIXELFORMAT_PVRTC_4BPP_RGBA_1;
- return{DdsParser:function(f){var n=new Uint32Array(f,0,32);if(n[0]!==b)return null;var m=n[1],r=n[2],t=n[3],v=n[4],y=Math.max(n[7],1),u=n[22],w=n[28];if(124!==m)return null;var m=4+m,x=n[21];n[20]&4&&x===d&&(new Uint32Array(f,128,5),m+=20);w=(n=65024===w)?6:1;r=r&131072?y:1;y=[];if(n)for(var D=0;D<r;D++)y.push([]);for(D=0;D<w;D++)for(var z=v,C=t,A=0;A<r;A++){var B;if(x===a||x===c||x===e)B=Math.floor((z+3)/4)*Math.floor((C+3)/4)*(x===c?16:8);else if(x===g||x===l)B=Math.max(z,16)*Math.max(C,8)/4;else if(x===
- k||x===p)B=Math.max(z,8)*Math.max(C,8)/2;else if(32===u)B=z*C*4;else return null;var J=116===x?new Float32Array(f,m,B):new Uint8Array(f,m,B);n?y[A][D]=J:y.push(J);m+=116===x?4*B:B;z=Math.max(.5*z,1);C=Math.max(.5*C,1)}this.format=h[x]||pc.PIXELFORMAT_R8_G8_B8_A8;this.width=v;this.height=t;this.levels=y;this.cubemap=n}}}());Object.assign(pc,function(){var f=[1481919403,3140563232,169478669],b={33776:pc.PIXELFORMAT_DXT1,33778:pc.PIXELFORMAT_DXT3,33779:pc.PIXELFORMAT_DXT5,36196:pc.PIXELFORMAT_ETC1,37492:pc.PIXELFORMAT_ETC2_RGB,37496:pc.PIXELFORMAT_ETC2_RGBA,35840:pc.PIXELFORMAT_PVRTC_4BPP_RGB_1,35841:pc.PIXELFORMAT_PVRTC_2BPP_RGB_1,35842:pc.PIXELFORMAT_PVRTC_4BPP_RGBA_1,35843:pc.PIXELFORMAT_PVRTC_2BPP_RGBA_1};return{KtxParser:function(a){var c=new Uint32Array(a,0,16);if(f[0]!==c[0]||f[1]!==c[1]||f[2]!==c[2])return null;
- var d=c[6],e=c[7],g=c[9],l=c[10],k=c[12],p=c[13],h=c[14];if(1<c[11]||1<k||0!==d||!b[e])return null;for(var c=64+c[15],d=[],k=!1,n=0;n<(h||1);n++){var q=(new Uint32Array(a.slice(c,c+4)))[0],c=c+4,q=q/(p||1);1<p&&(k=!0,d.push([]));for(var m=0;m<p;m++){var r=new Uint8Array(a,c,q);1<p?d[n].push(r):d.push(r);c+=q}c+=3-(c+3)%4}this.format=b[e];this.width=g;this.height=l;this.levels=d;this.cubemap=k}}}());Object.assign(pc,function(){var f={repeat:pc.ADDRESS_REPEAT,clamp:pc.ADDRESS_CLAMP_TO_EDGE,mirror:pc.ADDRESS_MIRRORED_REPEAT},b={nearest:pc.FILTER_NEAREST,linear:pc.FILTER_LINEAR,nearest_mip_nearest:pc.FILTER_NEAREST_MIPMAP_NEAREST,linear_mip_nearest:pc.FILTER_LINEAR_MIPMAP_NEAREST,nearest_mip_linear:pc.FILTER_NEAREST_MIPMAP_LINEAR,linear_mip_linear:pc.FILTER_LINEAR_MIPMAP_LINEAR},a=function(a,b,e){this._device=a;this._assets=b;this._loader=e;this.crossOrigin=void 0;b.prefix&&(this.crossOrigin="anonymous")};
- Object.assign(a.prototype,{load:function(a,b){"string"===typeof a&&(a={load:a,original:a});var c,d=0<=a.original.indexOf("?")?a.original.split("?")[0]:a.original,f=pc.path.getExtension(d).toLowerCase();if(".dds"===f||".ktx"===f)pc.http.get(a.load,{cache:!0,responseType:"arraybuffer"},function(a,c){a?b(a):b(null,c)});else if(".jpg"===f||".jpeg"===f||".gif"===f||".png"===f)c=new Image,void 0!==this.crossOrigin&&pc.ABSOLUTE_URL.test(a.original)&&(c.crossOrigin=this.crossOrigin),c.onload=function(){b(null,
- c)},c.onerror=function(c){b(pc.string.format("Error loading Texture from: '{0}'",a.original))},c.src=a.load;else{var k=d.indexOf("blob:");0<=k?(a=d=d.substr(k),c=new Image,c.onload=function(){b(null,c)},c.onerror=function(c){b(pc.string.format("Error loading Texture from: '{0}'",a))},c.src=a):setTimeout(function(){b(pc.string.format("Error loading Texture: format not supported: '{0}'",f))},0)}},open:function(a,b){if(a){var c,d=pc.path.getExtension(a).toLowerCase();if(b instanceof Image||b instanceof
- HTMLImageElement)c=".jpg"===d||".jpeg"===d?pc.PIXELFORMAT_R8_G8_B8:pc.PIXELFORMAT_R8_G8_B8_A8,c=new pc.Texture(this._device,{width:b.width,height:b.height,format:c}),c.name=a,c.setSource(b);else if(b instanceof ArrayBuffer)if(".dds"===d){c=b;var f=this._device;if(".crn"===pc.path.getExtension(a).toLowerCase()){var d=c.byteLength,k=new Uint8Array(c);c=Module._malloc(d);var p=Module.HEAPU8,h,n=c/4,q=d%4,m=new Uint32Array(k.buffer,0,(d-q)/4),r=new Uint32Array(p.buffer);for(h=0;h<m.length;h++)r[n+h]=
- m[h];for(h=d-q;h<d;h++)p[c+h]=k[h];k=Module._crn_decompress_get_data(c,d);c=Module._crn_decompress_get_size(c,d);c=Module.HEAPU8.buffer.slice(k,k+c)}var t=new Uint32Array(c,0,32),d=t[4],k=t[3],p=Math.max(t[7],1),v=t[21],y=t[22];h=65024===t[28];var u=r=m=q=n=!1,w=null;if(4===t[20])if(827611204===v)w=pc.PIXELFORMAT_DXT1,n=!0;else if(894720068===v)w=pc.PIXELFORMAT_DXT5,n=!0;else if(116===v)w=pc.PIXELFORMAT_RGBA32F,q=!0;else if(826496069===v)w=pc.PIXELFORMAT_ETC1,m=n=!0;else if(825438800===v||825504336===
- v)w=825438800===v?pc.PIXELFORMAT_PVRTC_2BPP_RGB_1:pc.PIXELFORMAT_PVRTC_2BPP_RGBA_1,r=n=!0;else{if(825439312===v||825504848===v)w=825439312===v?pc.PIXELFORMAT_PVRTC_4BPP_RGB_1:pc.PIXELFORMAT_PVRTC_4BPP_RGBA_1,u=n=!0}else 32===y&&(w=pc.PIXELFORMAT_R8_G8_B8_A8);if(w){f=new pc.Texture(f,{width:d,height:k,format:w,cubemap:h});h&&(f.addressU=pc.ADDRESS_CLAMP_TO_EDGE,f.addressV=pc.ADDRESS_CLAMP_TO_EDGE);for(var t=128,y=h?6:1,x,v=827611204===v?8:16,D,w=0;w<y;w++)for(var z=d,C=k,A=0;A<p;A++)n?m?x=Math.floor((z+
- 3)/4)*Math.floor((C+3)/4)*8:r?x=Math.max(z,16)*Math.max(C,8)/4:u?x=Math.max(z,8)*Math.max(C,8)/2:(x=Math.floor((z+4-1)/4),D=Math.floor((C+4-1)/4),x*=D,x*=v):x=z*C*4,D=q?new Float32Array(c,t,x):new Uint8Array(c,t,x),h?(f._levels[A]||(f._levels[A]=[]),f._levels[A][w]=D):f._levels[A]=D,t+=q?4*x:x,z=Math.max(.5*z,1),C=Math.max(.5*C,1);f.name=a;f.upload()}else f=new pc.Texture(f,{width:4,height:4,format:pc.PIXELFORMAT_R8_G8_B8}),f.name="dds-legacy-empty";c=f}else{switch(d){case ".dds":k=new pc.DdsParser(b);
- break;case ".ktx":k=new pc.KtxParser(b);break;case ".pvr":console.warn("PVR container not supported.")}if(!k)return c=new pc.Texture(this._device,{width:4,height:4,format:pc.PIXELFORMAT_R8_G8_B8}),c.name="unsupported-empty",c;c=new pc.Texture(this._device,{addressU:k.cubemap?pc.ADDRESS_CLAMP_TO_EDGE:pc.ADDRESS_REPEAT,addressV:k.cubemap?pc.ADDRESS_CLAMP_TO_EDGE:pc.ADDRESS_REPEAT,width:k.width,height:k.height,format:k.format,cubemap:k.cubemap,levels:k.levels});c.name=a;c.upload()}return c}},patch:function(a,
- d){var c=a.resource;if(c){c.name!==a.name&&(c.name=a.name);a.data.hasOwnProperty("minfilter")&&c.minFilter!==b[a.data.minfilter]&&(c.minFilter=b[a.data.minfilter]);a.data.hasOwnProperty("magfilter")&&c.magFilter!==b[a.data.magfilter]&&(c.magFilter=b[a.data.magfilter]);a.data.hasOwnProperty("addressu")&&c.addressU!==f[a.data.addressu]&&(c.addressU=f[a.data.addressu]);a.data.hasOwnProperty("addressv")&&c.addressV!==f[a.data.addressv]&&(c.addressV=f[a.data.addressv]);a.data.hasOwnProperty("mipmaps")&&
- c.mipmaps!==a.data.mipmaps&&(c.mipmaps=a.data.mipmaps);a.data.hasOwnProperty("anisotropy")&&c.anisotropy!==a.data.anisotropy&&(c.anisotropy=a.data.anisotropy);var g=!!a.data.rgbm;a.data.hasOwnProperty("rgbm")&&c.rgbm!==g&&(c.rgbm=g)}}});return{TextureHandler:a}}());Object.assign(pc,function(){var f=function(){};Object.assign(f.prototype,{load:function(b,a){"string"===typeof b&&(b={load:b,original:b});pc.http.get(b.load,function(c,d){c?a(pc.string.format("Error loading html resource: {0} [{1}]",b.original,c)):a(null,d)})},open:function(b,a){return a},patch:function(b,a){}});return{HtmlHandler:f}}());Object.assign(pc,function(){var f=function(){};Object.assign(f.prototype,{load:function(b,a){"string"===typeof b&&(b={load:b,original:b});pc.http.get(b.load,function(c,d){c?a(pc.string.format("Error loading css resource: {0} [{1}]",b.original,c)):a(null,d)})},open:function(b,a){return a},patch:function(b,a){}});return{CssHandler:f,createStyle:function(b){var a=document.createElement("style");a.type="text/css";a.styleSheet?a.styleSheet.cssText=b:a.appendChild(document.createTextNode(b));return a}}}());Object.assign(pc,function(){var f=function(){};Object.assign(f.prototype,{load:function(b,a){"string"===typeof b&&(b={load:b,original:b});pc.http.get(b.load,function(c,d){c?a(pc.string.format("Error loading shader resource: {0} [{1}]",b.original,c)):a(null,d)})},open:function(b,a){return a},patch:function(b,a){}});return{ShaderHandler:f}}());Object.assign(pc,function(){var f=function(b){this._app=b};Object.assign(f.prototype,{load:function(b,a){"string"===typeof b&&(b={load:b,original:b});pc.http.get(b.load,function(c,d){c?a("Error requesting scene: "+b.original):a(null,d)})},open:function(b,a){this._app.systems.script.preloading=!0;var c=(new pc.SceneParser(this._app)).parse(a),d=this._app.scene;d.root=c;this._app.applySceneSettings(a.settings);this._app.systems.script.preloading=!1;return d},patch:function(b,a){}});return{SceneHandler:f}}());Object.assign(pc,function(){var f=function(b){this._app=b};Object.assign(f.prototype,{load:function(b,a){"string"===typeof b&&(b={load:b,original:b});pc.http.get(b.load,function(c,d){c?a("Error requesting scene: "+b.original):a(null,d)})},open:function(b,a){this._app.systems.script.preloading=!0;var c=(new pc.SceneParser(this._app)).parse(a);this._app.systems.script.preloading=!1;return c}});return{HierarchyHandler:f}}());Object.assign(pc,function(){var f=function(b){this._app=b};Object.assign(f.prototype,{load:function(b,a){"string"===typeof b&&(b={load:b,original:b});pc.http.get(b.load,function(c,d){c?a("Error requesting scene: "+b.original):a(null,d)})},open:function(b,a){return a.settings}});return{SceneSettingsHandler:f}}());Object.assign(pc,function(){var f=function(){};Object.assign(f.prototype,{load:function(b,a){a(null,null)},open:function(b,a){return a}});return{FolderHandler:f}}());Object.assign(pc,function(){function f(a){3>a.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,d){var c=a.chars[d],f=void 0!==c.letter?c.letter:pc.string.fromCodePoint(d);2>a.version&&(c.map=c.map||0);b[f]=c;return b},{}),a.version=3);return a}var b=function(a){this._loader=a};Object.assign(b.prototype,{load:function(a,b,d){"string"===typeof a&&(a={load:a,original:a});var c=this;".json"===pc.path.getExtension(a.original)?
- pc.http.get(a.load,function(d,e){var g=f(e);d?b(pc.string.format("Error loading font resource: {0} [{1}]",a.original,d)):c._loadTextures(a.original.replace(".json",".png"),g,function(a,c){if(a)return b(a);b(null,{data:g,textures:c})})}):(d&&d.data&&(d.data=f(d.data)),this._loadTextures(a.original,d&&d.data,b))},_loadTextures:function(a,b,d){var c=b.info.maps.length,f=0,l=null,k=Array(c),p=this._loader;b=function(b){var e=function(a,e){if(!l){if(a)return l=a,d(a);e.upload();k[b]=e;f++;f===c&&d(null,
- k)}};0===b?p.load(a,"texture",e):p.load(a.replace(".png",b+".png"),"texture",e)};for(var h=0;h<c;h++)b(h)},open:function(a,b,d){return b.textures?new pc.Font(b.textures,b.data):new pc.Font(b,null)},patch:function(a,b){var c=a.resource;!c.data&&a.data?c.data=a.data:!a.data&&c.data&&(a.data=c.data)}});return{FontHandler:b}}());Object.assign(pc,function(){var f={repeat:pc.ADDRESS_REPEAT,clamp:pc.ADDRESS_CLAMP_TO_EDGE,mirror:pc.ADDRESS_MIRRORED_REPEAT},b={nearest:pc.FILTER_NEAREST,linear:pc.FILTER_LINEAR,nearest_mip_nearest:pc.FILTER_NEAREST_MIPMAP_NEAREST,linear_mip_nearest:pc.FILTER_LINEAR_MIPMAP_NEAREST,nearest_mip_linear:pc.FILTER_NEAREST_MIPMAP_LINEAR,linear_mip_linear:pc.FILTER_LINEAR_MIPMAP_LINEAR},a=/^data\.frames\.(\d+)$/,c=function(a){this._loader=a};Object.assign(c.prototype,{load:function(a,b){"string"===typeof a&&
- (a={load:a,original:a});var c=this,d=this._loader.getHandler("texture");if(".json"===pc.path.getExtension(a.original))pc.http.get(a.load,function(d,e){if(d)b(d);else{var f=a.original.replace(".json",".png");c._loader.load(f,"texture",function(a,c){a?b(a):b(null,{data:e,texture:c})})}});else return d.load(a,b)},open:function(a,b){var c=new pc.TextureAtlas;if(b.texture&&b.data)c.texture=b.texture,c.__data=b.data;else{var d=this._loader.getHandler("texture").open(a,b);if(!d)return null;c.texture=d}return c},
- patch:function(a,c){a.resource.__data&&(void 0!==a.resource.__data.minfilter&&(a.data.minfilter=a.resource.__data.minfilter),void 0!==a.resource.__data.magfilter&&(a.data.magfilter=a.resource.__data.magfilter),void 0!==a.resource.__data.addressu&&(a.data.addressu=a.resource.__data.addressu),void 0!==a.resource.__data.addressv&&(a.data.addressv=a.resource.__data.addressv),void 0!==a.resource.__data.mipmaps&&(a.data.mipmaps=a.resource.__data.mipmaps),void 0!==a.resource.__data.anisotropy&&(a.data.anisotropy=
- a.resource.__data.anisotropy),void 0!==a.resource.__data.rgbm&&(a.data.rgbm=!!a.resource.__data.rgbm),a.data.frames=a.resource.__data.frames,delete a.resource.__data);var d=a.resource.texture;if(d){d.name=a.name;a.data.hasOwnProperty("minfilter")&&d.minFilter!==b[a.data.minfilter]&&(d.minFilter=b[a.data.minfilter]);a.data.hasOwnProperty("magfilter")&&d.magFilter!==b[a.data.magfilter]&&(d.magFilter=b[a.data.magfilter]);a.data.hasOwnProperty("addressu")&&d.addressU!==f[a.data.addressu]&&(d.addressU=
- f[a.data.addressu]);a.data.hasOwnProperty("addressv")&&d.addressV!==f[a.data.addressv]&&(d.addressV=f[a.data.addressv]);a.data.hasOwnProperty("mipmaps")&&d.mipmaps!==a.data.mipmaps&&(d.mipmaps=a.data.mipmaps);a.data.hasOwnProperty("anisotropy")&&d.anisotropy!==a.data.anisotropy&&(d.anisotropy=a.data.anisotropy);var e=!!a.data.rgbm;a.data.hasOwnProperty("rgbm")&&d.rgbm!==e&&(d.rgbm=e)}a.resource.texture=d;var d={},k;for(k in a.data.frames)e=a.data.frames[k],d[k]={rect:new pc.Vec4(e.rect),pivot:new pc.Vec2(e.pivot),
- border:new pc.Vec4(e.border)};a.resource.frames=d;a.off("change",this._onAssetChange,this);a.on("change",this._onAssetChange,this)},_onAssetChange:function(b,c,f){if("data"===c||"data.frames"===c){var d={},e;for(e in f.frames)c=f.frames[e],d[e]={rect:new pc.Vec4(c.rect),pivot:new pc.Vec2(c.pivot),border:new pc.Vec4(c.border)};b.resource.frames=d}else if(c=c.match(a))e=c[1],f?(b.resource.frames[e]?(c=b.resource.frames[e],c.rect.set(f.rect[0],f.rect[1],f.rect[2],f.rect[3]),c.pivot.set(f.pivot[0],f.pivot[1]),
- c.border.set(f.border[0],f.border[1],f.border[2],f.border[3])):b.resource.frames[e]={rect:new pc.Vec4(f.rect),pivot:new pc.Vec2(f.pivot),border:new pc.Vec4(f.border)},b.resource.fire("set:frame",e,b.resource.frames[e])):b.resource.frames[e]&&(delete b.resource.frames[e],b.resource.fire("remove:frame",e))}});return{TextureAtlasHandler:c}}());Object.assign(pc,function(){var f=function(a,b){this._assets=a;this._device=b},b=function(a){this.resource&&(this.resource.atlas=a.resource)},a=function(a){this.registry.load(a)};Object.assign(f.prototype,{load:function(a,b){"string"===typeof a&&(a={load:a,original:a});".json"===pc.path.getExtension(a.original)&&pc.http.get(a.load,function(a,c){a?b(a):b(null,c)})},open:function(a,b){var c=new pc.Sprite(this._device);a&&(c.__data=b);return c},patch:function(a,b){var c=a.resource;if(c.__data&&(a.data.pixelsPerUnit=
- c.__data.pixelsPerUnit,a.data.renderMode=c.__data.renderMode,a.data.frameKeys=c.__data.frameKeys,c.__data.textureAtlasAsset)){var d=b.getByUrl(c.__data.textureAtlasAsset);d?a.data.textureAtlasAsset=d.id:console.warn("Could not find textureatlas with url: "+c.__data.textureAtlasAsset)}c.startUpdate();c.renderMode=a.data.renderMode;c.pixelsPerUnit=a.data.pixelsPerUnit;c.frameKeys=a.data.frameKeys;this._updateAtlas(a);c.endUpdate();a.off("change",this._onAssetChange,this);a.on("change",this._onAssetChange,
- this)},_updateAtlas:function(c){var d=c.resource;if(c.data.textureAtlasAsset){this._assets.off("load:"+c.data.textureAtlasAsset,b,c);this._assets.on("load:"+c.data.textureAtlasAsset,b,c);var e=this._assets.get(c.data.textureAtlasAsset);e&&e.resource?d.atlas=e.resource:e?this._assets.load(e):(this._assets.off("add:"+c.data.textureAtlasAsset,a,c),this._assets.on("add:"+c.data.textureAtlasAsset,a,c))}else d.atlas=null},_onAssetChange:function(c,d,e,f){"data"===d&&e&&e.textureAtlasAsset&&f&&e.textureAtlasAsset!==
- f.textureAtlasAsset&&(this._assets.off("load:"+f.textureAtlasAsset,b,c),this._assets.off("add:"+f.textureAtlasAsset,a,c))}});return{SpriteHandler:f}}());Object.assign(pc,function(){var f={points:pc.PRIMITIVE_POINTS,lines:pc.PRIMITIVE_LINES,lineloop:pc.PRIMITIVE_LINELOOP,linestrip:pc.PRIMITIVE_LINESTRIP,triangles:pc.PRIMITIVE_TRIANGLES,trianglestrip:pc.PRIMITIVE_TRISTRIP,trianglefan:pc.PRIMITIVE_TRIFAN},b={int8:pc.TYPE_INT8,uint8:pc.TYPE_UINT8,int16:pc.TYPE_INT16,uint16:pc.TYPE_UINT16,int32:pc.TYPE_INT32,uint32:pc.TYPE_UINT32,float32:pc.TYPE_FLOAT32},a=function(a){this._device=a;this._defaultMaterial=pc.getDefaultMaterial()};Object.assign(a.prototype,
- {parse:function(a){var b=a.model;if(!b||1>=b.version)return null;var b=this._parseNodes(a),c=this._parseSkins(a,b),f=this._parseMorphs(a,b),l=this._parseVertexBuffers(a),k=this._parseIndexBuffers(a,l),k=this._parseMeshes(a,c.skins,f.morphs,l,k.buffer,k.data);this._initMorphs(a,f.morphs,l,k);a=this._parseMeshInstances(a,b,k,c.skins,c.instances,f.morphs,f.instances);l=new pc.Model;l.graph=b[0];l.meshInstances=a;l.skinInstances=c.instances;l.morphInstances=f.instances;l.getGraph().syncHierarchy();return l},
- _parseNodes:function(a){a=a.model;var b=[],c;for(c=0;c<a.nodes.length;c++){var f=a.nodes[c],l=new pc.GraphNode;l.setName(f.name);l.setLocalPosition(f.position[0],f.position[1],f.position[2]);l.setLocalEulerAngles(f.rotation[0],f.rotation[1],f.rotation[2]);l.setLocalScale(f.scale[0],f.scale[1],f.scale[2]);l.scaleCompensation=!!f.scaleCompensation;b.push(l)}for(c=1;c<a.parents.length;c++)b[a.parents[c]].addChild(b[c]);return b},_parseSkins:function(a,b){var c=a.model,d=[],f=[],k,p;!this._device.supportsBoneTextures&&
- 0<c.skins.length&&(k=this._device.getBoneLimit(),pc.partitionSkin(c,null,k));for(k=0;k<c.skins.length;k++){var h=c.skins[k],n=[];for(p=0;p<h.inverseBindMatrices.length;p++){var q=h.inverseBindMatrices[p];n[p]=(new pc.Mat4).set(q)}h=new pc.Skin(this._device,n,h.boneNames);d.push(h);n=new pc.SkinInstance(h);q=[];for(p=0;p<h.boneNames.length;p++){var m=b[0].findByName(h.boneNames[p]);q.push(m)}n.bones=q;f.push(n)}return{skins:d,instances:f}},_parseMorphs:function(a,b){var c=a.model,d=[],f=[],k,p,h,n,
- q;if(c.morphs)for(k=0;k<c.morphs.length;k++){h=c.morphs[k].targets;q=[];for(p=0;p<h.length;p++){var m=h[p].aabb;n=m.min;m=m.max;n=new pc.BoundingBox(new pc.Vec3(.5*(m[0]+n[0]),.5*(m[1]+n[1]),.5*(m[2]+n[2])),new pc.Vec3(.5*(m[0]-n[0]),.5*(m[1]-n[1]),.5*(m[2]-n[2])));n=new pc.MorphTarget({indices:h[p].indices,deltaPositions:h[p].deltaPositions,deltaNormals:h[p].deltaNormals,name:h[p].name,aabb:n});q.push(n)}p=new pc.Morph(q);d.push(p);p=new pc.MorphInstance(p);f.push(p)}return{morphs:d,instances:f}},
- _calculateTangentsMorphTarget:function(a,b,e,f,l,k,p,h){var c,d,g,r,t,v,y,u,w,x,D,z,C,A,B,J,F,H,E,G;J=f.length/3;for(G=0;G<J;G++)F=f[3*G],H=f[3*G+1],E=f[3*G+2],y=a[3*F],t=a[3*F+1],v=a[3*F+2],r=a[3*H],u=a[3*H+1],w=a[3*H+2],x=a[3*E],D=a[3*E+1],z=a[3*E+2],C=e[2*F],c=e[2*F+1],A=e[2*H],g=e[2*H+1],B=e[2*E],d=e[2*E+1],r-=y,y=x-y,u-=t,t=D-t,w-=v,v=z-v,A-=C,C=B-C,g-=c,z=d-c,c=A*z-C*g,0==c?(c=0,d=1,g=0,r=1,v=t=0):(B=1/c,c=(z*r-g*y)*B,d=(z*u-g*t)*B,g=(z*w-g*v)*B,r=(A*y-C*r)*B,t=(A*t-C*u)*B,v=(A*v-C*w)*B),l[3*
- F+0]+=c,l[3*F+1]+=d,l[3*F+2]+=g,l[3*H+0]+=c,l[3*H+1]+=d,l[3*H+2]+=g,l[3*E+0]+=c,l[3*E+1]+=d,l[3*E+2]+=g,k[3*F+0]+=r,k[3*F+1]+=t,k[3*F+2]+=v,k[3*H+0]+=r,k[3*H+1]+=t,k[3*H+2]+=v,k[3*E+0]+=r,k[3*E+1]+=t,k[3*E+2]+=v;c=p.length;for(E=0;E<c;E++)G=p[E],w=b[3*G],d=b[3*G+1],u=b[3*G+2],a=l[3*G],e=l[3*G+1],f=l[3*G+2],J=k[3*G],F=k[3*G+1],H=k[3*G+2],v=w*a+d*e+u*f,y=w*v,t=d*v,v*=u,r=d*f-e*u,u=u*a-f*w,w=w*e-a*d,a-=y,e-=t,f-=v,v=1/Math.sqrt(a*a+e*e+f*f),a*=v,e*=v,f*=v,h[4*G]=a,h[4*G+1]=e,h[4*G+2]=f,h[4*G+3]=0>r*
- J+u*F+w*H?-1:1;return h},_initMorphs:function(a,b,e,f){a=a.model;var c,d,g,h,n,q,m,r,t,v,y,u,w,x,D,z=[],C=[];for(e=0;e<f.length;e++)if(t=a.meshes[e].vertices,!C[t]&&(d=a.vertices[t],d.tangent)){var A=new Float32Array(d.tangent.data);C[t]=!0;if(d.position&&d.normal&&d.texCoord0){var B=[];for(c=0;c<a.meshes.length;c++)a.meshes[c].vertices===t&&(B=B.concat(a.meshes[c].indices));t=d.position.data;v=d.normal.data;y=d.texCoord0.data;u=t.length/3;w=B.length;var J=new Float32Array(4*u),F=new Float32Array(3*
- u),H=new Float32Array(3*u);x=new Float32Array(3*u);x.set(t);D=new Float32Array(3*u);D.set(v);for(c=0;c<b.length;c++)if(a.meshes[e].morph===c)for(g=0;g<b[c]._targets.length;g++){d=b[c]._targets[g];var E=d.indices,G=E.length;if(0!==G){d.deltaTangents=new Float32Array(4*G);if(!r||r.length<u)r=new Uint8Array(u);else for(h=0;h<u;h++)r[h]=0;for(h=0;h<G;h++)n=E[h],r[n]=1;var I=0;for(h=0;h<w;h+=3)if(n=B[h],q=B[h+1],m=B[h+2],r[n]||r[q]||r[m])z[I]=n,z[I+1]=q,z[I+2]=m,I+=3;z.length=I;q=d.deltaPositions;m=d.deltaNormals;
- for(h=0;h<G;h++)n=E[h],x[3*n]+=q[3*h],x[3*n+1]+=q[3*h+1],x[3*n+2]+=q[3*h+2],D[3*n]+=m[3*h],D[3*n+1]+=m[3*h+1],D[3*n+2]+=m[3*h+2];this._calculateTangentsMorphTarget(x,D,y,z,F,H,E,J);q=d.deltaTangents;for(h=0;h<G;h++)n=E[h],q[4*h]=J[4*h]-A[4*n],q[4*h+1]=J[4*h+1]-A[4*n+1],q[4*h+2]=J[4*h+2]-A[4*n+2],q[4*h+3]=J[4*h+3]-A[4*n+3];if(g!==b[c]._targets.length-1){for(h=0;h<w;h+=3)n=B[h],q=B[h+1],m=B[h+2],F[3*n+0]=0,F[3*n+1]=0,F[3*n+2]=0,F[3*q+0]=0,F[3*q+1]=0,F[3*q+2]=0,F[3*m+0]=0,F[3*m+1]=0,F[3*m+2]=0,H[3*n+
- 0]=0,H[3*n+1]=0,H[3*n+2]=0,H[3*q+0]=0,H[3*q+1]=0,H[3*q+2]=0,H[3*m+0]=0,H[3*m+1]=0,H[3*m+2]=0;for(h=0;h<G;h++)n=d.indices[h],x[3*n]=t[3*n],x[3*n+1]=t[3*n+1],x[3*n+2]=t[3*n+2],D[3*n]=v[3*n],D[3*n+1]=v[3*n+1],D[3*n+2]=v[3*n+2]}}}}}},_parseVertexBuffers:function(a){a=a.model;var c=[],e,f,l={position:pc.SEMANTIC_POSITION,normal:pc.SEMANTIC_NORMAL,tangent:pc.SEMANTIC_TANGENT,blendWeight:pc.SEMANTIC_BLENDWEIGHT,blendIndices:pc.SEMANTIC_BLENDINDICES,color:pc.SEMANTIC_COLOR,texCoord0:pc.SEMANTIC_TEXCOORD0,
- texCoord1:pc.SEMANTIC_TEXCOORD1,texCoord2:pc.SEMANTIC_TEXCOORD2,texCoord3:pc.SEMANTIC_TEXCOORD3,texCoord4:pc.SEMANTIC_TEXCOORD4,texCoord5:pc.SEMANTIC_TEXCOORD5,texCoord6:pc.SEMANTIC_TEXCOORD6,texCoord7:pc.SEMANTIC_TEXCOORD7},k,p;for(k=0;k<a.vertices.length;k++){var h=a.vertices[k],n=[];for(f in h)e=h[f],n.push({semantic:l[f],components:e.components,type:b[e.type],normalize:l[f]===pc.SEMANTIC_COLOR});e=new pc.VertexFormat(this._device,n);var n=h.position.data.length/h.position.components,q=new pc.VertexBuffer(this._device,
- e,n),m=new pc.VertexIterator(q);for(p=0;p<n;p++){for(f in h)switch(e=h[f],e.components){case 1:m.element[l[f]].set(e.data[p]);break;case 2:m.element[l[f]].set(e.data[2*p],e.data[2*p+1]);break;case 3:m.element[l[f]].set(e.data[3*p],e.data[3*p+1],e.data[3*p+2]);break;case 4:m.element[l[f]].set(e.data[4*p],e.data[4*p+1],e.data[4*p+2],e.data[4*p+3])}m.next()}m.end();c.push(q)}return c},_parseIndexBuffers:function(a,b){var c=a.model,d=null,f=null,k,p=0;for(k=0;k<c.meshes.length;k++){var h=c.meshes[k];
- void 0!==h.indices&&(p+=h.indices.length)}for(k=c=0;k<b.length;k++)c=Math.max(c,b[k].numVertices);0<p&&(65535<c&&this._device.extUintElement?(d=new pc.IndexBuffer(this._device,pc.INDEXFORMAT_UINT32,p),f=new Uint32Array(d.lock())):(d=new pc.IndexBuffer(this._device,pc.INDEXFORMAT_UINT16,p),f=new Uint16Array(d.lock())));return{buffer:d,data:f}},_parseMeshes:function(a,b,e,g,l,k){a=a.model;var c=[],d=0,n;for(n=0;n<a.meshes.length;n++){var q=a.meshes[n],m=q.aabb,r=m.min,m=m.max,r=new pc.BoundingBox(new pc.Vec3(.5*
- (m[0]+r[0]),.5*(m[1]+r[1]),.5*(m[2]+r[2])),new pc.Vec3(.5*(m[0]-r[0]),.5*(m[1]-r[1]),.5*(m[2]-r[2]))),m=void 0!==q.indices,t=new pc.Mesh;t.vertexBuffer=g[q.vertices];t.indexBuffer[0]=m?l:null;t.primitive[0].type=f[q.type];t.primitive[0].base=m?q.base+d:q.base;t.primitive[0].count=q.count;t.primitive[0].indexed=m;t.skin=void 0!==q.skin?b[q.skin]:null;t.morph=void 0!==q.morph?e[q.morph]:null;t.aabb=r;m&&(k.set(q.indices,d),d+=q.indices.length);c.push(t)}null!==l&&l.unlock();return c},_parseMeshInstances:function(a,
- b,e,f,l,k,p){a=a.model;var c=[],d;for(d=0;d<a.meshInstances.length;d++){var g=a.meshInstances[d],m=e[g.mesh],g=new pc.MeshInstance(b[g.node],m,this._defaultMaterial);if(m.skin){var r=f.indexOf(m.skin);g.skinInstance=l[r]}m.morph&&(m=k.indexOf(m.morph),g.morphInstance=p[m]);c.push(g)}return c}});return{JsonModelParser:a}}());Object.assign(pc,function(){var f=function(b){this._app=b};Object.assign(f.prototype,{parse:function(b){var a={},c,d,e=null;for(c in b.entities)a[c]=this._createEntity(b.entities[c]),null===b.entities[c].parent&&(e=a[c]);for(c in b.entities){var f=b.entities[c].children.length;for(d=0;d<f;d++){var l=b.entities[c].children[d];a[l]&&a[c].addChild(a[l])}}this._openComponentData(e,b.entities);return e},_createEntity:function(b){var a=new pc.Entity,c=b.position,d=b.rotation,e=b.scale;a.name=b.name;a.setGuid(b.resource_id);
- a.setLocalPosition(c[0],c[1],c[2]);a.setLocalEulerAngles(d[0],d[1],d[2]);a.setLocalScale(e[0],e[1],e[2]);a._enabled=void 0!==b.enabled?b.enabled:!0;a._enabledInHierarchy=a._enabled;a.template=b.template;if(b.tags)for(c=0;c<b.tags.length;c++)a.tags.add(b.tags[c]);b.labels&&b.labels.forEach(function(b){a.addLabel(b)});return a},_openComponentData:function(b,a){var c=this._app.systems.list,d,e=c.length,f=a[b.getGuid()];for(d=0;d<e;d++){var l=c[d],k=f.components[l.id];k&&l.addComponent(b,k)}e=f.children.length;
- c=b._children;for(d=0;d<e;d++)c[d]=this._openComponentData(c[d],a);return b}});return{SceneParser:f}}());Object.assign(pc,function(){var f=function(){this._validator=null};f.prototype.parse=function(b){b=this.migrate(b);b=this._validate(b);var a=new pc.StandardMaterial;this.initialize(a,b);return a};f.prototype.initialize=function(b,a){a.validated||(this._validator||(this._validator=new pc.StandardMaterialValidator),this._validator.validate(a));a.chunks&&b.chunks.copy(a.chunks);for(var c in a){var d=pc.StandardMaterial.PARAMETER_TYPES[c],e=a[c];"vec2"===d?b[c]=new pc.Vec2(e[0],e[1]):"rgb"===d?b[c]=new pc.Color(e[0],
- e[1],e[2]):"texture"===d?e instanceof pc.Texture?b[c]=e:b[c]instanceof pc.Texture&&"number"===typeof e&&0<e||(b[c]=null):"cubemap"===d?e instanceof pc.Texture?b[c]=e:b[c]instanceof pc.Texture&&"number"===typeof e&&0<e||(b[c]=null):"boundingbox"===d?(d=new pc.Vec3(e.center[0],e.center[1],e.center[2]),e=new pc.Vec3(e.halfExtents[0],e.halfExtents[1],e.halfExtents[2]),b[c]=new pc.BoundingBox(d,e)):b[c]=a[c]}b.update()};f.prototype.migrate=function(b){void 0===b.shadingModel&&(b.shadingModel="blinn"===
- b.shader?pc.SPECULAR_BLINN:pc.SPECULAR_PHONG);b.shader&&delete b.shader;b.mapping_format&&(b.mappingFormat=b.mapping_format,delete b.mapping_format);var a,c=[["bumpMapFactor","bumpiness"],["aoUvSet","aoMapUv"],["aoMapVertexColor","aoVertexColor"],["diffuseMapVertexColor","diffuseVertexColor"],["emissiveMapVertexColor","emissiveVertexColor"],["specularMapVertexColor","specularVertexColor"],["metalnessMapVertexColor","metalnessVertexColor"],["opacityMapVertexColor","opacityVertexColor"],["glossMapVertexColor",
- "glossVertexColor"],["lightMapVertexColor","lightVertexColor"],["diffuseMapTint","diffuseTint"],["specularMapTint","specularTint"],["emissiveMapTint","emissiveTint"],["metalnessMapTint","metalnessTint"]];for(a=0;a<c.length;a++){var d=c[a][0],e=c[a][1];void 0!==b[d]&&void 0===b[e]&&(b[e]=b[d],delete b[d])}c=["fresnelFactor","shadowSampleType"];for(a=0;a<c.length;a++)d=c[a],b.hasOwnProperty(d)&&delete b[d];return b};f.prototype._validate=function(b){this._validator||(this._validator=new pc.StandardMaterialValidator);
- this._validator.validate(b);return b};return{JsonStandardMaterialParser:f}}());Object.assign(pc,function(){var f=0,b=/^\s*(?:[a-z]+[a-z0-9\-\+\.]*:)?\/\//i,a={pvr:"extCompressedTexturePVRTC",dxt:"extCompressedTextureS3TC",etc2:"extCompressedTextureETC",etc1:"extCompressedTextureETC1"},c=["pvr","dxt","etc2","etc1"],d=function(a,b,c,d){this._id=++f;this.name=a||"";this.type=b;this.tags=new pc.Tags(this);this._preload=!1;this.variants=new pc.AssetVariants(this);this._file=null;this._data=d||{};this._resources=[];this.loading=this.loaded=!1;this.registry=null;pc.events.attach(this);
- c&&(this.file=c)};Object.assign(d.prototype,{getFileUrl:function(){var a=this.getPreferredFile();if(!a||!a.url)return null;var c=a.url;this.registry&&this.registry.prefix&&!b.test(c)&&(c=this.registry.prefix+c);if("script"!==this.type&&a.hash)var d=-1!==c.indexOf("?")?"&":"?",c=c+(d+"t="+a.hash);return c},getPreferredFile:function(){if(!this.file)return null;if("texture"===this.type||"textureatlas"===this.type||"bundle"===this.type)for(var b=this.registry._loader._app,d=b.graphicsDevice,f=0,k=c.length;f<
- k;f++){var p=c[f];if(d[a[p]]){if(this.file.variants[p])return this.file.variants[p];if(b.enableBundles){var h=b.bundles.listBundlesForAsset(this);if(h)for(var n=0,q=h.length;n<q;n++)if(h[n].file&&h[n].file.variants&&h[n].file.variants[p])return this.file}}}return this.file},ready:function(a,b){b=b||this;if(this.resource)a.call(b,this);else this.once("load",function(c){a.call(b,c)})},reload:function(){this.loaded&&("cubemap"===this.type?this.registry._loader.patch(this,this.registry):(this.loaded=
- !1,this.registry.load(this)))},unload:function(){if(this.loaded||this.resource)this.fire("unload",this),this.registry.fire("unload:"+this.id,this),this.resource&&this.resource.destroy&&this.resource.destroy(),this.resource=null,this.loaded=!1,this.file&&this.registry._loader.clearCache(this.getFileUrl(),this.type)}});Object.defineProperty(d.prototype,"id",{get:function(){return this._id},set:function(a){this._id=a;a>f&&(f=a)}});Object.defineProperty(d.prototype,"file",{get:function(){return this._file},
- set:function(a){var b;if(!!a!==!!this._file||a&&this._file&&a.hash!==this._file)if(a){this._file||(this._file={});this._file.url=a.url;this._file.filename=a.filename;this._file.hash=a.hash;this._file.size=a.size;this._file.variants=this.variants;if(a.hasOwnProperty("variants")&&(this.variants.clear(),a.variants))for(b in a.variants)a.variants[b]&&(this.variants[b]=a.variants[b]);this.fire("change",this,"file",this._file,this._file);this.reload()}else this._file=null,this.variants.clear();else if(a&&
- this._file&&a.hasOwnProperty("variants")&&(this.variants.clear(),a.variants))for(b in a.variants)a.variants[b]&&(this.variants[b]=a.variants[b])}});Object.defineProperty(d.prototype,"data",{get:function(){return this._data},set:function(a){var b=this._data;this._data=a;a!==b&&(this.fire("change",this,"data",a,b),this.loaded&&this.registry._loader.patch(this,this.registry))}});Object.defineProperty(d.prototype,"resource",{get:function(){return this._resources[0]},set:function(a){var b=this._resources[0];
- this._resources[0]=a;this.fire("change",this,"resource",a,b)}});Object.defineProperty(d.prototype,"resources",{get:function(){return this._resources},set:function(a){var b=this._resources;this._resources=a;this.fire("change",this,"resources",a,b)}});Object.defineProperty(d.prototype,"preload",{get:function(){return this._preload},set:function(a){a=!!a;this._preload!==a&&(this._preload=a)&&!this.loaded&&!this.loading&&this.registry&&this.registry.load(this)}});return{Asset:d,ASSET_ANIMATION:"animation",
- ASSET_AUDIO:"audio",ASSET_IMAGE:"image",ASSET_JSON:"json",ASSET_MODEL:"model",ASSET_MATERIAL:"material",ASSET_TEXT:"text",ASSET_TEXTURE:"texture",ASSET_CUBEMAP:"cubemap",ASSET_SHADER:"shader",ASSET_CSS:"css",ASSET_HTML:"html",ASSET_SCRIPT:"script",ABSOLUTE_URL:b}}());Object.assign(pc,function(){var f=[],b=function(a){this.asset=a},a=function(a){var c="_"+a;f.push(c);Object.defineProperty(b.prototype,a,{get:function(){return this[c]||null},set:function(a){if(!!this[c]!==!!a||this[c]&&a&&this[c].hash!==a.hash)this[c]=a?{url:a.url,filename:a.filename,size:a.size,hash:a.hash,opt:a.opt||0}:null,this.asset.file&&(this.asset.fire("change",this.asset,"file",this.asset._file,this.asset._file),this.asset.reload())}})};a("dxt");a("pvr");a("etc1");a("etc2");b.prototype.clear=
- function(){for(var a=0;a<f.length;a++)this[f[a]]=null};return{AssetVariants:b}}());Object.assign(pc,function(){var f=function(b){this._loader=b;this._assets=[];this._cache={};this._names={};this._tags=new pc.TagsCache("_id");this._urls={};this.prefix=null;Object.assign(this,pc.events)};Object.assign(f.prototype,{list:function(b){b=b||{};return this._assets.filter(function(a){var c=!0;void 0!==b.preload&&(c=a.preload===b.preload);return c})},add:function(b){var a=this._assets.push(b)-1,c;this._cache[b.id]=a;this._names[b.name]||(this._names[b.name]=[]);this._names[b.name].push(a);
- b.file&&(c=b.file.url,this._urls[c]=a);b.registry=this;this._tags.addItem(b);b.tags.on("add",this._onTagAdd,this);b.tags.on("remove",this._onTagRemove,this);this.fire("add",b);this.fire("add:"+b.id,b);c&&this.fire("add:url:"+c,b);b.preload&&this.load(b)},remove:function(b){var a=this._cache[b.id],c=b.file?b.file.url:null;if(void 0!==a){this._assets.splice(a,1);delete this._cache[b.id];this._names={};this._urls=[];for(var a=0,d=this._assets.length;a<d;a++){var e=this._assets[a];this._cache[e.id]=a;
- this._names[e.name]||(this._names[e.name]=[]);this._names[e.name].push(a);e.file&&(this._urls[e.file.url]=a)}this._tags.removeItem(b);b.tags.off("add",this._onTagAdd,this);b.tags.off("remove",this._onTagRemove,this);b.fire("remove",b);this.fire("remove",b);this.fire("remove:"+b.id,b);c&&this.fire("remove:url:"+c,b);return!0}return!1},get:function(b){return this._assets[this._cache[b]]},getByUrl:function(b){return this._assets[this._urls[b]]},load:function(b){if(!b.loading){var a=this;if(b.loaded)"cubemap"===
- b.type&&a._loader.patch(b,this);else{var c=!!b.file,d=b.getPreferredFile(),e=function(){var c=b.getFileUrl();b.loading=!0;a._loader.load(c,b.type,function(c,e,f){b.loaded=!0;b.loading=!1;c?(a.fire("error",c,b),a.fire("error:"+b.id,c,b),b.fire("error",c,b)):(e instanceof Array?b.resources=e:b.resource=e,pc.script.legacy||"script"!==b.type||(c=a._loader.getHandler("script"),c._cache[b.id]&&c._cache[b.id].parentNode===document.head&&document.head.removeChild(c._cache[b.id]),c._cache[b.id]=f),a._loader.patch(b,
- a),a.fire("load",b),a.fire("load:"+b.id,b),d&&d.url&&a.fire("load:url:"+d.url,b),b.fire("load",b))},b)},f=function(){var c=a._loader.open(b.type,b.data);c instanceof Array?b.resources=c:b.resource=c;b.loaded=!0;a._loader.patch(b,a);a.fire("load",b);a.fire("load:"+b.id,b);d&&d.url&&a.fire("load:url:"+d.url,b);b.fire("load",b)};if(d&&"cubemap"===b.type){var c=!1,l=b.getFileUrl();this._loader.load(l,"texture",function(c,d){c?(a.fire("error",c,b),a.fire("error:"+b.id,c,b),b.fire("error",c,b)):(a._loader.patch({resource:d,
- type:"texture",data:b.data},a),b._dds=d,f())})}d?c&&(this.fire("load:start",b),this.fire("load:"+b.id+":start",b),e()):f()}}},loadFromUrl:function(b,a,c){var d=pc.path.getBasename(b),e={url:b},f={};b=this.getByUrl(b);b||(b=new pc.Asset(d,a,e,f),this.add(b));"model"===a?this._loadModel(b,c):(b.once("load",function(a){c(null,a)}),b.once("error",function(a){c(a)}),this.load(b))},_loadModel:function(b,a){var c=this,d=b.getFileUrl(),e=pc.path.getDirectory(d),f=pc.path.getBasename(d),l=function(d){b.once("load",
- function(b){a(null,b)});b.once("error",function(b){a(b)});c.load(d)};".json"===pc.path.getExtension(d)?(d=pc.path.join(e,f.replace(".json",".mapping.json")),this._loader.load(d,"json",function(a,d){a?(b.data={mapping:[]},l(b)):c._loadMaterials(e,d,function(a,c){b.data=d;l(b)})})):l(b)},_loadMaterials:function(b,a,c){var d=this,e,f=a.mapping.length,l=[],k=function(a,b){d._loadTextures(b,function(a,d){c(null,b)})};0===f&&c(null,l);var p=function(a,b){l.push(b);f--;0===f&&k(null,l)};for(e=0;e<a.mapping.length;e++){var h=
- a.mapping[e].path;h?(h=pc.path.join(b,h),d.loadFromUrl(h,"material",p)):f--}},_loadTextures:function(b,a){var c,d={},e=[],f=[],l=0;for(c=0;c<b.length;c++){var k=b[c].data;if("path"!==k.mappingFormat)console.warn("Skipping: "+b[c].name+', material files must be mappingFormat: "path" to be loaded from URL');else for(var p=b[c].getFileUrl(),p=pc.path.getDirectory(p),h,n=0;n<pc.StandardMaterial.TEXTURE_PARAMETERS.length;n++)h=pc.StandardMaterial.TEXTURE_PARAMETERS[n],k[h]&&(h=pc.path.join(p,k[h]),d[h]||
- (d[h]=!0,e.push(h),l++))}if(l)for(d=function(b,c){f.push(c);l--;b&&console.error(b);0===l&&a(null,f)},c=0;c<e.length;c++)this.loadFromUrl(e[c],"texture",d);else a(null,f)},findAll:function(b,a){var c=this,d=this._names[b];return d?(d=d.map(function(a){return c._assets[a]}),a?d.filter(function(b){return b.type===a}):d):[]},_onTagAdd:function(b,a){this._tags.add(b,a)},_onTagRemove:function(b,a){this._tags.remove(b,a)},findByTag:function(){return this._tags.find(arguments)},filter:function(b){for(var a=
- [],c=0,d=this._assets.length;c<d;c++)b(this._assets[c])&&a.push(this._assets[c]);return a},find:function(b,a){var c=this.findAll(b,a);return c?c[0]:null},getAssetById:function(b){console.warn("DEPRECATED: getAssetById() use get() instead");return this.get(b)}});return{AssetRegistry:f}}());Object.assign(pc,function(){var f=function(b,a,c,d,e){this.propertyName=b;this.parent=a;this._scope=e;this._registry=c;this.asset=this.url=this.id=null;this._onAssetLoad=d.load;this._onAssetAdd=d.add;this._onAssetRemove=d.remove};f.prototype._bind=function(){if(this.id){if(this._onAssetLoad)this._registry.on("load:"+this.id,this._onLoad,this);if(this._onAssetAdd)this._registry.once("add:"+this.id,this._onAdd,this);if(this._onAssetRemove)this._registry.on("remove:"+this.id,this._onRemove,this)}if(this.url){if(this._onAssetLoad)this._registry.on("load:url:"+
- this.url,this._onLoad,this);if(this._onAssetAdd)this._registry.once("add:url:"+this.url,this._onAdd,this);if(this._onAssetRemove)this._registry.on("remove:url:"+this.url,this._onRemove,this)}};f.prototype._unbind=function(){this.id&&(this._onAssetLoad&&this._registry.off("load:"+this.id,this._onLoad,this),this._onAssetAdd&&this._registry.off("add:"+this.id,this._onAdd,this),this._onAssetRemove&&this._registry.off("remove:"+this.id,this._onRemove,this));this.url&&(this._onAssetLoad&&this._registry.off("load:"+
- this.url,this._onLoad,this),this._onAssetAdd&&this._registry.off("add:"+this.url,this._onAdd,this),this._onAssetRemove&&this._registry.off("remove:"+this.url,this._onRemove,this))};f.prototype._onLoad=function(b){this._onAssetLoad.call(this._scope,this.propertyName,this.parent,b)};f.prototype._onAdd=function(b){this._onAssetAdd.call(this._scope,this.propertyName,this.parent,b)};f.prototype._onRemove=function(b){this._onAssetRemove.call(this._scope,this.propertyName,this.parent,b)};Object.defineProperty(f.prototype,
- "id",{get:function(){return this._id},set:function(b){if(this.url)throw Error("Can't set id and url");this._unbind();this._id=b;this.asset=this._registry.get(this._id);this._bind()}});Object.defineProperty(f.prototype,"url",{get:function(){return this._url},set:function(b){if(this.id)throw Error("Can't set id and url");this._unbind();this._url=b;this.asset=this._registry.getByUrl(this._url);this._bind()}});return{AssetReference:f}}());Object.assign(pc,function(){return{inherits:function(f,b){var a=function(){},c=function(a,c,g,l,k,p,h,n){b.call(this,a,c,g,l,k,p,h,n);f.call(this,a,c,g,l,k,p,h,n)};c._super=b.prototype;a.prototype=b.prototype;c.prototype=new a;return c}}}());pc.anim={Animation:pc.Animation,Key:pc.Key,Node:pc.Node,Skeleton:pc.Skeleton};
- pc.asset={ASSET_ANIMATION:"animation",ASSET_AUDIO:"audio",ASSET_IMAGE:"image",ASSET_JSON:"json",ASSET_MODEL:"model",ASSET_MATERIAL:"material",ASSET_TEXT:"text",ASSET_TEXTURE:"texture",ASSET_CUBEMAP:"cubemap",ASSET_SCRIPT:"script"};pc.audio={AudioManager:pc.SoundManager,Channel:pc.Channel,Channel3d:pc.Channel3d,Listener:pc.Listener,Sound:pc.Sound};
- pc.fw={Application:pc.Application,Component:pc.Component,ComponentData:pc.ComponentData,ComponentSystem:pc.ComponentSystem,Entity:pc.Entity,FillMode:{NONE:pc.FILLMODE_NONE,FILL_WINDOW:pc.FILLMODE_FILL_WINDOW,KEEP_ASPECT:pc.FILLMODE_KEEP_ASPECT},ResolutionMode:{AUTO:pc.RESOLUTION_AUTO,FIXED:pc.RESOLUTION_FIXED}};
- Object.assign(pc.gfx,{drawQuadWithShader:pc.drawQuadWithShader,programlib:pc.programlib,shaderChunks:pc.shaderChunks,ContextCreationError:pc.ContextCreationError,Device:pc.GraphicsDevice,IndexBuffer:pc.IndexBuffer,ProgramLibrary:pc.ProgramLibrary,RenderTarget:pc.RenderTarget,ScopeId:pc.ScopeId,Shader:pc.Shader,ShaderInput:pc.ShaderInput,Texture:pc.Texture,UnsupportedBrowserError:pc.UnsupportedBrowserError,VertexBuffer:pc.VertexBuffer,VertexFormat:pc.VertexFormat,VertexIterator:pc.VertexIterator});
- (function(){function f(a){this.name="UnsupportedBrowserError";this.message=a||""}function b(a){this.name="ContextCreationError";this.message=a||""}f.prototype=Error.prototype;b.prototype=Error.prototype;pc.ContextCreationError=b;pc.UnsupportedBrowserError=f})();
- Object.assign(pc.input,{getTouchTargetCoords:pc.getTouchTargetCoords,Controller:pc.Controller,GamePads:pc.GamePads,Keyboard:pc.Keyboard,KeyboardEvent:pc.KeyboardEvent,Mouse:pc.Mouse,MouseEvent:pc.MouseEvent,Touch:pc.Touch,TouchDevice:pc.TouchDevice,TouchEvent:pc.TouchEvent});pc.math.INV_LOG2=Math.LOG2E;pc.math.intToBytes=pc.math.intToBytes32;pc.math.bytesToInt=pc.math.bytesToInt32;
- pc.posteffect={createFullscreenQuad:pc.createFullscreenQuad,drawFullscreenQuad:pc.drawFullscreenQuad,PostEffect:pc.PostEffect,PostEffectQueue:pc.PostEffectQueue};
- Object.assign(pc.scene,{partitionSkin:pc.partitionSkin,procedural:{calculateTangents:pc.calculateTangents,createMesh:pc.createMesh,createTorus:pc.createTorus,createCylinder:pc.createCylinder,createCapsule:pc.createCapsule,createCone:pc.createCone,createSphere:pc.createSphere,createPlane:pc.createPlane,createBox:pc.createBox},BasicMaterial:pc.BasicMaterial,DepthMaterial:pc.DepthMaterial,ForwardRenderer:pc.ForwardRenderer,GraphNode:pc.GraphNode,Material:pc.Material,Command:pc.Command,Mesh:pc.Mesh,MeshInstance:pc.MeshInstance,
- Model:pc.Model,ParticleEmitter:pc.ParticleEmitter,PhongMaterial:pc.StandardMaterial,Picker:pc.Picker,PickMaterial:pc.PickMaterial,Projection:{ORTHOGRAPHIC:pc.PROJECTION_ORTHOGRAPHIC,PERSPECTIVE:pc.PROJECTION_PERSPECTIVE},Scene:pc.Scene,Skin:pc.Skin,SkinInstance:pc.SkinInstance});pc.shape={Aabb:pc.BoundingBox,Sphere:pc.BoundingSphere,Plane:pc.Plane};pc.time={now:pc.now,Timer:pc.Timer};pc.PhongMaterial=pc.StandardMaterial;pc.BoundingSphere.prototype.intersectRay=pc.BoundingSphere.prototype.intersectsRay;
- pc.ELEMENTTYPE_INT8=pc.TYPE_INT8;pc.ELEMENTTYPE_UINT8=pc.TYPE_UINT8;pc.ELEMENTTYPE_INT16=pc.TYPE_INT16;pc.ELEMENTTYPE_UINT16=pc.TYPE_UINT16;pc.ELEMENTTYPE_INT32=pc.TYPE_INT32;pc.ELEMENTTYPE_UINT32=pc.TYPE_UINT32;pc.ELEMENTTYPE_FLOAT32=pc.TYPE_FLOAT32;Object.defineProperty(pc.shaderChunks,"transformSkinnedVS",{get:function(){return"#define SKIN\n"+pc.shaderChunks.transformVS}});
- Object.defineProperty(pc.Vec2.prototype,"data",{get:function(){this._data||(this._data=new Float32Array(2));this._data[0]=this.x;this._data[1]=this.y;return this._data}});Object.defineProperty(pc.Vec3.prototype,"data",{get:function(){this._data||(this._data=new Float32Array(3));this._data[0]=this.x;this._data[1]=this.y;this._data[2]=this.z;return this._data}});
- Object.defineProperty(pc.Vec4.prototype,"data",{get:function(){this._data||(this._data=new Float32Array(4));this._data[0]=this.x;this._data[1]=this.y;this._data[2]=this.z;this._data[3]=this.w;return this._data}});Object.defineProperty(pc.Color.prototype,"data",{get:function(){this._data||(this._data=new Float32Array(4));this._data[0]=this.r;this._data[1]=this.g;this._data[2]=this.b;this._data[3]=this.a;return this._data}});
- Object.defineProperty(pc.Color.prototype,"data3",{get:function(){this._data3||(this._data3=new Float32Array(3));this._data3[0]=this.r;this._data3[1]=this.g;this._data3[2]=this.b;return this._data3}});pc.Material.prototype.getName=function(){return this.name};pc.Material.prototype.setName=function(f){this.name=f};pc.Material.prototype.getShader=function(){return this.shader};pc.Material.prototype.setShader=function(f){this.shader=f};
- pc.GraphNode.prototype._dirtify=function(f){f?this._dirtifyLocal():this._dirtifyWorld()};Object.assign(pc.Application.prototype,function(){var f=new pc.GraphNode,b=new pc.GraphNode,a=[],c=!1,d=function(a){this.lineVertexFormat=new pc.VertexFormat(a,[{semantic:pc.SEMANTIC_POSITION,components:3,type:pc.TYPE_FLOAT32},{semantic:pc.SEMANTIC_COLOR,components:4,type:pc.TYPE_UINT8,normalize:!0}]);this.lineBatches=[];this.layers=[];this.layerToBatch={};this.cubeWorldPos=this.cubeLocalPos=this.quadMesh=null;this.identityGraphNode=new pc.GraphNode};d.prototype.addLayer=function(a){0>this.layers.indexOf(a)&&
- this.layers.push(a)};d.prototype.getLayerIdx=function(a){return this.layerToBatch[a.id]};d.prototype.addLayerIdx=function(a,b){this.layerToBatch[b.id]=a};var e=function(){this.numLinesAllocated=128;this.mesh=this.vbRam=this.vb=null;this.linesUsed=0;this.layer=this.meshInstance=this.material=null};Object.assign(e.prototype,{init:function(a,c,d,e){this.mesh||(this.mesh=new pc.Mesh,this.mesh.primitive[0].type=pc.PRIMITIVE_LINES,this.mesh.primitive[0].base=0,this.mesh.primitive[0].indexed=!1,this.material=
- new pc.BasicMaterial,this.material.vertexColors=!0,this.material.blend=!0,this.material.blendType=pc.BLEND_NORMAL,this.material.update());for(this.layer=d;this.linesUsed+e>this.numLinesAllocated;)this.vb&&(this.vb.destroy(),this.vb=null),this.numLinesAllocated*=2;this.vertexFormat=c;this.vb||(this.vb=new pc.VertexBuffer(a,c,2*this.numLinesAllocated,pc.BUFFER_DYNAMIC),this.mesh.vertexBuffer=this.vb,this.vbRam=new DataView(this.vb.lock()),this.meshInstance||(b.worldTransform=pc.Mat4.IDENTITY,b._dirtyWorld=
- b._dirtyNormal=!1,this.meshInstance=new pc.MeshInstance(b,this.mesh,this.material),this.meshInstance.cull=!1))},addLines:function(a,b){for(var c=!!b.length,d=2*this.linesUsed*this.vertexFormat.size,e,f=0;f<a.length;f++)this.vbRam.setFloat32(d,a[f].x,!0),d+=4,this.vbRam.setFloat32(d,a[f].y,!0),d+=4,this.vbRam.setFloat32(d,a[f].z,!0),d+=4,e=c?b[f]:b,this.vbRam.setUint8(d,255*e.r),d+=1,this.vbRam.setUint8(d,255*e.g),d+=1,this.vbRam.setUint8(d,255*e.b),d+=1,this.vbRam.setUint8(d,255*e.a),d+=1;this.linesUsed+=
- a.length/2},finalize:function(){0<this.linesUsed&&(this.vb.setData(this.vbRam.buffer),this.mesh.primitive[0].count=2*this.linesUsed,a[0]=this.meshInstance,this.layer.addMeshInstances(a,!0),this.linesUsed=0)}});return{renderMeshInstance:function(b,c){c||(c={layer:this.scene.layers.getLayerById(pc.LAYERID_IMMEDIATE)});this._initImmediate();this._immediateData.addLayer(c.layer);a[0]=b;c.layer.addMeshInstances(a,!0)},renderMesh:function(b,c,d,e){e||(e={layer:this.scene.layers.getLayerById(pc.LAYERID_IMMEDIATE)});
- this._initImmediate();f.worldTransform=d;f._dirtyWorld=f._dirtyNormal=!1;b=new pc.MeshInstance(f,b,c);b.cull=!1;e.mask&&(b.mask=e.mask);this._immediateData.addLayer(e.layer);a[0]=b;e.layer.addMeshInstances(a,!0)},renderLine:function(a,b,d,e,f){var g=d;e instanceof pc.Color?(g=e,"number"===typeof f?(c||(console.warn("lineBatch argument is deprecated for renderLine. Use options.layer instead"),c=!0),e=f===pc.LINEBATCH_OVERLAY?{layer:this.scene.layers.getLayerById(pc.LAYERID_IMMEDIATE),depthTest:!1}:
- {layer:this.scene.layers.getLayerById(pc.LAYERID_IMMEDIATE),depthTest:!0}):e=f):"number"===typeof e?(c||(console.warn("lineBatch argument is deprecated for renderLine. Use options.layer instead"),c=!0),g=d,e=e===pc.LINEBATCH_OVERLAY?{layer:this.scene.layers.getLayerById(pc.LAYERID_IMMEDIATE),depthTest:!1}:{layer:this.scene.layers.getLayerById(pc.LAYERID_IMMEDIATE),depthTest:!0}):e=e?e:{layer:this.scene.layers.getLayerById(pc.LAYERID_IMMEDIATE),depthTest:!0};this._addLines([a,b],[d,g],e)},renderLines:function(a,
- b,d){d?"number"===typeof d&&(c||(console.warn("lineBatch argument is deprecated for renderLine. Use options.layer instead"),c=!0),d=d===pc.LINEBATCH_OVERLAY?{layer:this.scene.layers.getLayerById(pc.LAYERID_IMMEDIATE),depthTest:!1}:{layer:this.scene.layers.getLayerById(pc.LAYERID_IMMEDIATE),depthTest:!0}):d={layer:this.scene.layers.getLayerById(pc.LAYERID_IMMEDIATE),depthTest:!0};b.length&&a.length!==b.length?pc.log.error("renderLines: position/color arrays have different lengths"):0!==a.length%2?
- pc.log.error("renderLines: array length is not divisible by 2"):this._addLines(a,b,d)},renderQuad:function(b,c,d){d||(d={layer:this.scene.layers.getLayerById(pc.LAYERID_IMMEDIATE)});this._initImmediate();if(!this._immediateData.quadMesh){var e=new pc.VertexFormat(this.graphicsDevice,[{semantic:pc.SEMANTIC_POSITION,components:3,type:pc.TYPE_FLOAT32}]),e=new pc.VertexBuffer(this.graphicsDevice,e,4),g=new pc.VertexIterator(e);g.element[pc.SEMANTIC_POSITION].set(-.5,-.5,0);g.next();g.element[pc.SEMANTIC_POSITION].set(.5,
- -.5,0);g.next();g.element[pc.SEMANTIC_POSITION].set(-.5,.5,0);g.next();g.element[pc.SEMANTIC_POSITION].set(.5,.5,0);g.end();this._immediateData.quadMesh=new pc.Mesh;this._immediateData.quadMesh.vertexBuffer=e;this._immediateData.quadMesh.primitive[0].type=pc.PRIMITIVE_TRISTRIP;this._immediateData.quadMesh.primitive[0].base=0;this._immediateData.quadMesh.primitive[0].count=4;this._immediateData.quadMesh.primitive[0].indexed=!1}f.worldTransform=b;f._dirtyWorld=f._dirtyNormal=!1;b=new pc.MeshInstance(f,
- this._immediateData.quadMesh,c);b.cull=!1;a[0]=b;this._immediateData.addLayer(d.layer);d.layer.addMeshInstances(a,!0)},renderWireCube:function(a,b,c){var d;this._initImmediate();this._immediateData.cubeLocalPos||(this._immediateData.cubeLocalPos=[new pc.Vec3(-.5,-.5,-.5),new pc.Vec3(-.5,.5,-.5),new pc.Vec3(.5,.5,-.5),new pc.Vec3(.5,-.5,-.5),new pc.Vec3(-.5,-.5,.5),new pc.Vec3(-.5,.5,.5),new pc.Vec3(.5,.5,.5),new pc.Vec3(.5,-.5,.5)],this._immediateData.cubeWorldPos=[new pc.Vec3,new pc.Vec3,new pc.Vec3,
- new pc.Vec3,new pc.Vec3,new pc.Vec3,new pc.Vec3,new pc.Vec3]);var e=this._immediateData.cubeLocalPos,f=this._immediateData.cubeWorldPos;for(d=0;8>d;d++)a.transformPoint(e[d],f[d]);this.renderLines([f[0],f[1],f[1],f[2],f[2],f[3],f[3],f[0],f[4],f[5],f[5],f[6],f[6],f[7],f[7],f[4],f[0],f[4],f[1],f[5],f[2],f[6],f[3],f[7]],b,c)},_addLines:function(a,b,c){void 0===c.layer&&(c.layer=this.scene.layers.getLayerById(pc.LAYERID_IMMEDIATE));void 0===c.depthTest&&(c.depthTest=!0);this._initImmediate();var d=c.layer;
- this._immediateData.addLayer(d);var f=this._immediateData.getLayerIdx(d);void 0===f?(f=new e,f.init(this.graphicsDevice,this._immediateData.lineVertexFormat,d,a.length/2),f.material.depthTest=c.depthTest,c.mask&&(f.meshInstance.mask=c.mask),f=this._immediateData.lineBatches.push(f)-1,this._immediateData.addLayerIdx(f,d)):(this._immediateData.lineBatches[f].init(this.graphicsDevice,this._immediateData.lineVertexFormat,d,a.length/2),this._immediateData.lineBatches[f].material.depthTest=c.depthTest,
- c.mask&&(this._immediateData.lineBatches[f].meshInstance.mask=c.mask));this._immediateData.lineBatches[f].addLines(a,b)},_initImmediate:function(){this._immediateData||(this._immediateData=new d(this.graphicsDevice),this.on("prerender",this._preRenderImmediate,this),this.on("postrender",this._postRenderImmediate,this))},_preRenderImmediate:function(){for(var a=0;a<this._immediateData.lineBatches.length;a++)this._immediateData.lineBatches[a]&&this._immediateData.lineBatches[a].finalize()},_postRenderImmediate:function(){for(var a=
- 0;a<this._immediateData.layers.length;a++)this._immediateData.layers[a].clearMeshInstances(!0);this._immediateData.layers.length=0}}}());Object.assign(pc,function(){function f(a,b,c,d){if(a.enabled){var e;if(a.model&&a.model.model&&a.model.enabled&&(d&&d.push(a),a.model.lightmapped&&b)){var g=!0,h=a.model.model.meshInstances;for(e=0;e<h.length;e++)if(!h[e].mesh.vertexBuffer.format.hasUv1){g=!1;break}if(g){var l,k=[];for(e=0;e<h.length;e++){l=!1;for(g=0;g<h.length;g++)e!==g&&h[e].mesh===h[g].mesh&&(l=!0);l?(b.push(a),c.push([h[e]])):k.push(h[e])}0<k.length&&(b.push(a),c.push(k))}}for(e=0;e<a._children.length;e++)f(a._children[e],b,
- c,d)}}var b=[],a=[],c,d=new pc.Vec3,e=new pc.BoundingBox,g=new pc.BoundingBox,l={},k=["texture_lightMap","texture_dirLightMap"],p=[],h=function(a,b,c,d,e){this.device=a;this.root=b;this.scene=c;this.renderer=d;this.assets=e};Object.assign(h.prototype,{destroy:function(){this.assets=this.renderer=this.scene=this.root=this.device=null},calculateLightmapSize:function(a){var b,c=this.scene.lightmapSizeMultiplier||16,e=1,f=1,g=1,h=1;a.model.asset?(b=this.assets.get(a.model.asset).data,b.area&&(e=b.area.x,
- f=b.area.y,g=b.area.z,h=b.area.uv)):a.model._area&&(b=a.model,b._area&&(e=b._area.x,f=b._area.y,g=b._area.z,h=b._area.uv));b=a.model.lightmapSizeMultiplier||1;e*=b;f*=b;g*=b;d.copy(a.localScale);for(a=a._parent;a;)d.mul(a.localScale),a=a._parent;d.x=Math.abs(d.x);d.y=Math.abs(d.y);d.z=Math.abs(d.z);e=e*d.y*d.z+f*d.x*d.z+g*d.x*d.y;e=Math.sqrt(e/h);return Math.min(pc.math.nextPowerOfTwo(e*c),this.scene.lightmapMaxResolution||2048)},bake:function(h,q){var m,n,t=this.device,v=this.scene,y=1;void 0===
- q&&(q=pc.BAKE_COLORDIR);q===pc.BAKE_COLORDIR&&(y=2);var u,w=[],x=[];if(h){var D;for(m=a.length-1;0<=m;m--)for(n=0;n<h.length;n++)if(a[m]===h[n]){for(D=0;D<b[m].length;D++)b[m][D].destroy();b.splice(m,1);a.splice(m,1)}D=[];for(m=0;m<h.length;m++)f(h[m],D,x);h=D;f(this.root,null,null,w)}else{for(m=0;m<b.length;m++)for(n=0;n<b[m].length;n++)b[m][n].destroy();b=[];a=[];h=[];f(this.root,h,x,w)}if(0===h.length)t.fire("lightmapper:end",{timestamp:pc.now(),target:this});else{D=!1;v._needsStaticPrepare&&(v._needsStaticPrepare=
- !1,D=!0);var z=[],C=[[],[]],A={},B,J;n=new pc.Texture(this.device,{width:4,height:4,format:pc.PIXELFORMAT_R8_G8_B8_A8,rgbm:!0});n.name="lightmap";for(m=0;m<h.length;m++){B=this.calculateLightmapSize(h[m]);z.push(B);for(u=0;u<y;u++)J=new pc.Texture(t,{width:B,height:B,format:pc.PIXELFORMAT_R8_G8_B8_A8,mipmaps:!1,rgbm:0===u,minFilter:pc.FILTER_NEAREST,magFilter:pc.FILTER_NEAREST}),J.name="lightmap",C[u].push(J);if(!A[B]){var F=new pc.Texture(t,{width:B,height:B,format:pc.PIXELFORMAT_R8_G8_B8_A8,mipmaps:!1,
- rgbm:!0,minFilter:pc.FILTER_NEAREST,magFilter:pc.FILTER_NEAREST});F.name="lightmap";F=new pc.RenderTarget(t,F,{depth:!1});A[B]=F}}var H=v.layers;H._update();z=[];B=[];var F=[],E=[],G=H._lights;for(m=0;m<G.length;m++)G[m]._enabled&&(J=G[m]._mask,0!==(J&4)&&(B.push(J),F.push(G[m].shadowUpdateMode),G[m]._mask=4294967295,G[m].shadowUpdateMode=G[m]._type===pc.LIGHTTYPE_DIRECTIONAL?pc.SHADOWUPDATE_REALTIME:pc.SHADOWUPDATE_THISFRAME,z.push(G[m]),G[m].isStatic=!1)),E.push(G[m]._enabled),G[m].enabled=!1;var I=
- pc.shaderChunks,Q="#define UV1LAYOUT\n"+I.transformVS,V=I.bakeLmEndPS;J=I.createShaderFromCode(t,I.fullscreenQuadVS,I.dilatePS,"lmDilate");var W=t.scope.resolve("source"),U=t.scope.resolve("pixelOffset"),Z=t.scope.resolve("bakeDir"),T=new Float32Array(2),H=H._meshInstances;for(m=0;m<H.length;m++)H[m].node&&H[m].node.getWorldTransform();var H=v.fog,L=v.ambientLight.r,R=v.ambientLight.g,P=v.ambientLight.b;v.fog=pc.FOG_NONE;v.ambientLight.set(0,0,0);c||(c=new pc.Camera,c._node=new pc.GraphNode,c.clearColor[0]=
- 0,c.clearColor[1]=0,c.clearColor[2]=0,c.clearColor[3]=0,c.clearDepth=1,c.clearFlags=pc.CLEARFLAG_COLOR,c.clearStencil=null,c.frustumCulling=!1);var K,da,O,S,aa=[];aa.length=a.length;var N;for(K=0;K<w.length;K++){O=w[K].model.model.meshInstances;N=[];for(m=0;m<O.length;m++)N.push(O[m]._shaderDefs),O[m]._shaderDefs&=~(pc.SHADERDEF_LM|pc.SHADERDEF_DIRLM);for(m=0;m<a.length;m++)if(a[m]===w[K]){aa[m]=N;break}}N=[];var ba=[],M;for(K=0;K<w.length;K++)if(N[K]=w[K].model.castShadows,w[K].model.castShadows=
- w[K].model.castShadowsLightmap,w[K].model.castShadowsLightmap)for(M=w[K].model.meshInstances,m=0;m<M.length;m++)M[m].visibleThisFrame=!0,ba.push(M[m]);this.renderer.updateCpuSkinMatrices(ba);this.renderer.gpuUpdate(ba);var ca=[],ea=[];M=[[],[]];var fa,ga,Y,ia=[];ia.length=h.length;for(u=0;u<y;u++)p[u]||(m=new pc.StandardMaterial,m.chunks.transformVS=Q,0===u?(m.chunks.endPS=V,m.ambient=new pc.Color(0,0,0),m.ambientTint=!0,m.lightMap=n):(m.chunks.basePS=I.basePS+"\nuniform sampler2D texture_dirLightMap;\nuniform float bakeDir;\n",
- m.chunks.endPS=I.bakeDirLmEndPS),m.chunks.outputAlphaPS="\n",m.chunks.outputAlphaOpaquePS="\n",m.chunks.outputAlphaPremulPS="\n",m.cull=pc.CULLFACE_NONE,m.forceUv1=!0,m.update(),m.updateShader(t,v),m.name="lmMaterial"+u,p[u]=m);for(K=0;K<h.length;K++){O=x[K];ia[K]=0;if(0<O.length)for(e.copy(O[0].aabb),m=0;m<O.length;m++)O[m].node.getWorldTransform(),e.add(O[m].aabb);m=new pc.BoundingBox;m.copy(e);ea.push(m);for(m=0;m<O.length;m++)S=O[m],S._shaderDefs&=~(pc.SHADERDEF_LM|pc.SHADERDEF_DIRLM),S.mask=
- 4,S.deleteParameter("texture_lightMap"),S.deleteParameter("texture_dirLightMap"),S.setParameter("texture_lightMap",S.material.lightMap?S.material.lightMap:n),S.setParameter("texture_dirLightMap",n);for(u=0;u<y;u++)da=C[u][K],fa=new pc.RenderTarget(t,da,{depth:!1}),M[u].push(fa)}for(n=0;n<z.length;n++)z[n].enabled=!1;I=[[],[],[]];Q=!1;for(m=0;m<z.length;m++){z[m].enabled=!0;V=!1;z[m]._cacheShadowMap=!0;z[m]._type!==pc.LIGHTTYPE_DIRECTIONAL&&(z[m]._node.getWorldTransform(),z[m].getBoundingSphere(l),
- g.center=l.center,g.halfExtents.x=l.radius,g.halfExtents.y=l.radius,g.halfExtents.z=l.radius);z[m]._type===pc.LIGHTTYPE_SPOT&&(n=z[m],Y=this.renderer.getShadowCamera(t,n),Y._node.setPosition(n._node.getPosition()),Y._node.setRotation(n._node.getRotation()),Y._node.rotateLocal(-90,0,0),Y.projection=pc.PROJECTION_PERSPECTIVE,Y.nearClip=n.attenuationEnd/1E3,Y.farClip=n.attenuationEnd,Y.aspectRatio=1,Y.fov=2*n._outerConeAngle,this.renderer.updateCameraFrustum(Y));0<x.length&&this.renderer.updateShaders(x[0]);
- for(K=0;K<h.length;K++){O=x[K];e=ea[K];if(z[m]._type===pc.LIGHTTYPE_DIRECTIONAL)d.copy(e.center),d.y+=e.halfExtents.y,c._node.setPosition(d),c._node.setEulerAngles(-90,0,0),n=Math.max(e.halfExtents.x,e.halfExtents.z),c.projection=pc.PROJECTION_ORTHOGRAPHIC,c.nearClip=0,c.farClip=2*e.halfExtents.y,c.aspectRatio=1,c.orthoHeight=n;else if(!g.intersects(e))continue;if(z[m]._type===pc.LIGHTTYPE_SPOT){u=!1;for(n=0;n<O.length;n++)if(this.renderer._isVisible(Y,O[n])){u=!0;break}if(!u)continue}z[m]._type===
- pc.LIGHTTYPE_DIRECTIONAL?(I[pc.LIGHTTYPE_DIRECTIONAL][0]=z[m],I[pc.LIGHTTYPE_POINT].length=0,I[pc.LIGHTTYPE_SPOT].length=0,!V&&z[m].castShadows&&(this.renderer.cullDirectionalShadowmap(z[m],ba,c,0),this.renderer.renderShadows(I[pc.LIGHTTYPE_DIRECTIONAL],0),V=!0)):(I[pc.LIGHTTYPE_DIRECTIONAL].length=0,z[m]._type===pc.LIGHTTYPE_POINT?(I[pc.LIGHTTYPE_POINT][0]=z[m],I[pc.LIGHTTYPE_SPOT].length=0,!V&&z[m].castShadows&&(this.renderer.cullLocalShadowmap(z[m],ba),this.renderer.renderShadows(I[pc.LIGHTTYPE_POINT]),
- V=!0)):(I[pc.LIGHTTYPE_POINT].length=0,I[pc.LIGHTTYPE_SPOT][0]=z[m],!V&&z[m].castShadows&&(this.renderer.cullLocalShadowmap(z[m],ba),this.renderer.renderShadows(I[pc.LIGHTTYPE_SPOT]),V=!0)));for(n=0;n<O.length;n++)ca[n]=O[n].material;for(u=0;u<y;u++){da=C[u][K];fa=M[u][K];S=A[da.width];ga=S.colorBuffer;0===u?Q=v.updateShaders:Q&&(v.updateShaders=!0);for(n=0;n<O.length;n++)O[n].material=p[u];1<y&&this.renderer.updateShaders(O);this.renderer.setCamera(c,S,!0);1===u&&Z.setValue(z[m].bakeDir?1:0);this.renderer._forwardTime=
- 0;this.renderer._shadowMapTime=0;this.renderer.renderForward(c,O,O.length,I,pc.SHADER_FORWARDHDR);C[u][K]=ga;M[u][K]=S;A[da.width]=fa;for(n=0;n<O.length;n++)S=O[n],S.setParameter(k[u],ga),S._shaderDefs|=pc.SHADERDEF_LM}ia[K]++;for(n=0;n<O.length;n++)O[n].material=ca[n]}z[m].enabled=!1;z[m]._cacheShadowMap=!1;z[m]._isCachedShadowMap&&z[m]._destroyShadowMap()}for(K=0;K<h.length;K++){O=x[K];Y=[];for(u=0;u<y;u++){da=C[u][K];fa=M[u][K];S=A[da.width];ga=S.colorBuffer;T[0]=1/da.width;T[1]=1/da.height;U.setValue(T);
- for(m=0;4>m;m++)W.setValue(da),pc.drawQuadWithShader(t,S,J),W.setValue(ga),pc.drawQuadWithShader(t,fa,J);for(m=0;m<O.length;m++)S=O[m],S.mask=2,O[m].setParameter(k[u],da),1===u&&(O[m]._shaderDefs|=pc.SHADERDEF_DIRLM);Y[u]=da;u===y-1&&fa.destroy()}b.push(Y);a.push(h[K])}for(var ja in A)A.hasOwnProperty(ja)&&(A[ja].colorBuffer.destroy(),A[ja].destroy());for(m=0;m<b.length;m++)for(n=0;n<b[m].length;n++)J=b[m][n],J.minFilter=pc.FILTER_LINEAR,J.magFilter=pc.FILTER_LINEAR;for(K=0;K<w.length;K++)w[K].model.castShadows=
- N[K];for(m=0;m<aa.length;m++)if(aa[m])for(O=a[m].model.model.meshInstances,n=0;n<O.length;n++)O[n]._shaderDefs|=aa[m][n]&(pc.SHADERDEF_LM|pc.SHADERDEF_DIRLM);for(m=0;m<z.length;m++)z[m]._mask=B[m],z[m].shadowUpdateMode=F[m];for(m=0;m<G.length;m++)G[m].enabled=E[m];v.fog=H;v.ambientLight.set(L,R,P);D&&(v._needsStaticPrepare=!0)}}});return{Lightmapper:h}}());Object.assign(pc,function(){function f(a,b){if(a&&!b||!a&&b)return!1;a=a.data;b=b.data;if(a===b)return!0;if(a instanceof Float32Array&&b instanceof Float32Array){if(a.length!==b.length)return!1;for(var c=0;c<a.length;c++)if(a[c]!==b[c])return!1;return!0}return!1}var b=function(a,b,e){this.device=a;this.rootNode=e;this._dirty=!0;this.bones=b;b=b.length;a.supportsBoneTextures?(b=256<b?64:64<b?32:16<b?16:8,this.boneTexture=new pc.Texture(a,{width:b,height:b,format:pc.PIXELFORMAT_RGBA32F,mipmaps:!1,minFilter:pc.FILTER_NEAREST,
- magFilter:pc.FILTER_NEAREST}),this.boneTexture.name="batching",this.matrixPalette=this.boneTexture.lock()):this.matrixPalette=new Float32Array(16*b)};Object.assign(b.prototype,{updateMatrices:function(){},updateMatrixPalette:function(){for(var a,b=this.matrixPalette,e,f=this.bones.length-1;0<=f;f--)a=this.bones[f].getWorldTransform().data,e=16*f,b[e]=a[0],b[e+1]=a[1],b[e+2]=a[2],b[e+3]=a[3],b[e+4]=a[4],b[e+5]=a[5],b[e+6]=a[6],b[e+7]=a[7],b[e+8]=a[8],b[e+9]=a[9],b[e+10]=a[10],b[e+11]=a[11],b[e+12]=
- a[12],b[e+13]=a[13],b[e+14]=a[14],b[e+15]=a[15];this.device.supportsBoneTextures&&(this.boneTexture.lock(),this.boneTexture.unlock())}});var a=function(a,b,e){this.device=a;this.rootNode=b;this.scene=e;this._init=!1;this._batchGroups={};this._batchGroupCounter=0;this._batchList=[];this._dirtyGroups=[]};a.prototype.destroyManager=function(){this.scene=this.rootNode=this.device=null;this._batchGroups={};this._batchList=[];this._dirtyGroups=[]};a.prototype.addGroup=function(a,b,e,f,l){void 0===f&&(f=
- this._batchGroupCounter,this._batchGroupCounter++);if(!this._batchGroups[f])return this._batchGroups[f]=a=new pc.BatchGroup(f,a,b,e,l)};a.prototype.removeGroup=function(a){if(this._batchGroups[a]){for(var b=[],c=0;c<this._batchList.length;c++)this._batchList[c].batchGroupId!==a?b.push(this._batchList[c]):this.destroy(this._batchList[c]);this._batchList=b;this._removeModelsFromBatchGroup(this.rootNode,a);delete this._batchGroups[a]}};a.prototype.markGroupDirty=function(a){0>this._dirtyGroups.indexOf(a)&&
- this._dirtyGroups.push(a)};a.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};a.prototype.getBatches=function(a){for(var b=[],c=this._batchList.length,f=0;f<c;f++){var l=this._batchList[f];l.batchGroupId===a&&b.push(l)}return b};a.prototype._removeModelsFromBatchGroup=function(a,b){if(a.enabled){a.model&&a.model.batchGroupId===b&&(a.model.batchGroupId=-1);a.element&&a.element.batchGroupId===b&&(a.element.batchGroupId=
- -1);a.sprite&&a.sprite.batchGroupId===b&&(a.sprite.batchGroupId=-1);for(var c=0;c<a._children.length;c++)this._removeModelsFromBatchGroup(a._children[c],b)}};a.prototype._collectAndRemoveModels=function(a,b,e){if(a.enabled){var c;if(a.model&&0<=a.model.batchGroupId&&a.model.model&&a.model.enabled&&(!e||e&&0<=e.indexOf(a.model.batchGroupId))){(c=b[a.model.batchGroupId])||(c=b[a.model.batchGroupId]=[]);if(a.model.isStatic){var d=this.scene.drawCalls,f=a.model.meshInstances;for(c=0;c<d.length;c++)d[c]._staticSource&&
- (0>f.indexOf(d[c]._staticSource)||b[a.model.batchGroupId].push(d[c]));for(c=0;c<f.length;c++)0<=d.indexOf(f[c])&&b[a.model.batchGroupId].push(f[c])}else b[a.model.batchGroupId]=c.concat(a.model.meshInstances);a.model.removeModelFromLayers(a.model.model)}a.element&&0<=a.element.batchGroupId&&a.element.enabled&&(!e||e&&0<=e.indexOf(a.element.batchGroupId))&&((c=b[a.element.batchGroupId])||(b[a.element.batchGroupId]=[]),a.element._text?(b[a.element.batchGroupId].push(a.element._text._model.meshInstances[0]),
- a.element.removeModelFromLayers(a.element._text._model)):a.element._image&&(b[a.element.batchGroupId].push(a.element._image._model.meshInstances[0]),a.element.removeModelFromLayers(a.element._image._model)));a.sprite&&0<=a.sprite.batchGroupId&&a.sprite.enabled&&(!e||e&&0<=e.indexOf(a.sprite.batchGroupId))&&((c=b[a.sprite.batchGroupId])||(b[a.sprite.batchGroupId]=[]),a.sprite._meshInstance&&(b[a.sprite.batchGroupId].push(a.sprite._meshInstance),this.scene.removeModel(a.sprite._model),a.sprite._batchGroup=
- this._batchGroups[a.sprite.batchGroupId]));for(c=0;c<a._children.length;c++)this._collectAndRemoveModels(a._children[c],b,e)}};a.prototype._registerEntities=function(a,b){for(var c,d=[],f=0;f<b.length;f++){for(c=b[f].node;!c._app&&c._parent;)c=c._parent;c._app&&d.push(c)}this.register(a,d)};a.prototype.generate=function(a){var b,c,f={};if(a){c=[];for(b=0;b<this._batchList.length;b++)0>a.indexOf(this._batchList[b].batchGroupId)?c.push(this._batchList[b]):this.destroy(this._batchList[b]);this._batchList=
- c;this._collectAndRemoveModels(this.rootNode,f,a);if(a===this._dirtyGroups)this._dirtyGroups.length=0;else{c=[];for(b=0;b<this._dirtyGroups.length;b++)0>a.indexOf(this._dirtyGroups[b])&&c.push(this._dirtyGroups[b]);this._dirtyGroups=c}}else{for(b=0;b<this._batchList.length;b++)this.destroy(this._batchList[b]);this._batchList.length=0;this._collectAndRemoveModels(this.rootNode,f);this._dirtyGroups.length=0}var l,k,p;for(p in f)if(f.hasOwnProperty(p)&&(b=f[p],a=this._batchGroups[p]))for(l=this.prepare(b,
- a.dynamic,a.maxAabbSize),b=0;b<l.length;b++){k=this.create(l[b],a.dynamic,parseInt(p,10));for(c=0;c<a.layers.length;c++)this.scene.layers.getLayerById(a.layers[c]).addMeshInstances(k.model.meshInstances);this._registerEntities(k,l[b])}};a.prototype.prepare=function(a,b,e){if(0===a.length)return[];void 0===e&&(e=Number.POSITIVE_INFINITY);e*=.5;for(var c=this.device.supportsBoneTextures?1024:this.device.boneLimit,d,k,p,h,n,q,m,r,t,v=new pc.BoundingBox,y=new pc.BoundingBox,u=[],w=0,x=a,D,z;0<x.length;){u[w]=
- [];D=[];d=x[0].material;k=x[0].layer;t=x[0]._shaderDefs;h=x[0].parameters;r=x[0]._staticLightList;p=x[0].mesh.vertexBuffer.getNumVertices();v.copy(x[0].aabb);for(a=0;a<x.length;a++){if(0<a){if(d!==x[a].material){D.push(x[a]);continue}if(k!==x[a].layer){D.push(x[a]);continue}if(t!==x[a]._shaderDefs){D.push(x[a]);continue}if(65535<p+x[a].mesh.vertexBuffer.getNumVertices()){D.push(x[a]);continue}y.copy(v);y.add(x[a].aabb);if(y.halfExtents.x>e||y.halfExtents.y>e||y.halfExtents.z>e){D.push(x[a]);continue}n=
- x[a].parameters;m=!1;for(q in h)if(h.hasOwnProperty(q)&&!f(h[q],n[q])){m=!0;break}if(!m)for(q in n)if(n.hasOwnProperty(q)&&!f(n[q],h[q])){m=!0;break}if(m){D.push(x[a]);continue}n=x[a]._staticLightList;if(r&&!n||!r&&n){D.push(x[a]);continue}if(r&&n){m=!1;for(z=0;z<r.length;z++)if(0>n.indexOf(r[z])){m=!0;break}for(z=0;z<n.length;z++)if(0>r.indexOf(n[z])){m=!0;break}if(m){D.push(x[a]);continue}}}v.add(x[a].aabb);p+=x[a].mesh.vertexBuffer.getNumVertices();u[w].push(x[a]);if(b&&u[w].length===c){D=a===
- x.length?[]:x.slice(a+1);break}}w++;x=D}return u};a.prototype.create=function(a,d,f){this._init||(this.transformVS="#define BONE_LIMIT "+this.device.getBoneLimit()+"\n#define DYNAMICBATCH\n"+pc.shaderChunks.transformVS,this.skinTexVS=pc.shaderChunks.skinBatchTexVS,this.skinConstVS=pc.shaderChunks.skinBatchConstVS,this.vertexFormats={},this._init=!0);var c,e;f=new pc.Batch(a,d,f);this._batchList.push(f);var k=null,p,h,n,q,m,r,t,v,y,u=0,w=0;for(c=0;c<a.length;c++){if(!k)k=a[c].material;else if(k!==
- a[c].material)return;p=a[c].mesh;h=p.vertexBuffer.format.elements;n=p.vertexBuffer.numVertices;u+=n;for(e=0;e<h.length;e++)h[e].name===pc.SEMANTIC_POSITION?q=!0:h[e].name===pc.SEMANTIC_NORMAL?m=!0:h[e].name===pc.SEMANTIC_TEXCOORD0?r=!0:h[e].name===pc.SEMANTIC_TEXCOORD1?t=!0:h[e].name===pc.SEMANTIC_TANGENT?v=!0:h[e].name===pc.SEMANTIC_COLOR&&(y=!0);w+=p.primitive[0].count}if(q){var x=3+(m?3:0)+(r?2:0)+(t?2:0)+(v?4:0)+(y?1:0)+(d?1:0),D=m?6:3,z=(m?6:3)+(r?2:0),C=(m?6:3)+(r?2:0)+(t?2:0),A=(m?6:3)+(r?
- 2:0)+(t?2:0)+(v?4:0),B=(m?6:3)+(r?2:0)+(t?2:0)+(v?4:0)+(y?1:0),J=new ArrayBuffer(u*x*4);q=new Float32Array(J);var F=new Uint8Array(J),J=new pc.IndexBuffer(this.device,pc.INDEXFORMAT_UINT16,w,pc.BUFFER_STATIC),H=new Uint16Array(J.lock()),E,G,I,Q=0,V=0;I=0;var W,U,Z,T,L,R,P,K;d||(K=new pc.Vec3);for(c=0;c<a.length;c++){p=a[c].mesh;h=p.vertexBuffer.format.elements;n=p.vertexBuffer.numVertices;e=p.vertexBuffer.format.size;E=e/4;for(e=0;e<h.length;e++)h[e].name===pc.SEMANTIC_POSITION?W=h[e].offset/4:h[e].name===
- pc.SEMANTIC_NORMAL?U=h[e].offset/4:h[e].name===pc.SEMANTIC_TEXCOORD0?Z=h[e].offset/4:h[e].name===pc.SEMANTIC_TEXCOORD1?T=h[e].offset/4:h[e].name===pc.SEMANTIC_TANGENT?L=h[e].offset/4:h[e].name===pc.SEMANTIC_COLOR&&(R=h[e].offset/4);h=new Float32Array(p.vertexBuffer.storage);G=new Uint8Array(p.vertexBuffer.storage);if(d)for(e=0;e<n;e++)q[e*x+I]=h[e*E+W],q[e*x+I+1]=h[e*E+W+1],q[e*x+I+2]=h[e*E+W+2],m&&(q[e*x+I+3]=h[e*E+U],q[e*x+I+3+1]=h[e*E+U+1],q[e*x+I+3+2]=h[e*E+U+2]),r&&(q[e*x+I+D]=h[e*E+Z],q[e*x+
- I+D+1]=h[e*E+Z+1]),t&&(q[e*x+I+z]=h[e*E+T],q[e*x+I+z+1]=h[e*E+T+1]),v&&(q[e*x+I+C]=h[e*E+L],q[e*x+I+C+1]=h[e*E+L+1],q[e*x+I+C+2]=h[e*E+L+2],q[e*x+I+C+3]=h[e*E+L+3]),y&&(F[e*x*4+4*I+4*A]=G[e*E*4+4*R],F[e*x*4+4*I+4*A+1]=G[e*E*4+4*R+1],F[e*x*4+4*I+4*A+2]=G[e*E*4+4*R+2],F[e*x*4+4*I+4*A+3]=G[e*E*4+4*R+3]),q[e*x+B+I]=c;else for(P=a[c].node.getWorldTransform(),e=0;e<n;e++)K.set(h[e*E+W],h[e*E+W+1],h[e*E+W+2]),P.transformPoint(K,K),q[e*x+I]=K.x,q[e*x+I+1]=K.y,q[e*x+I+2]=K.z,m&&(K.set(h[e*E+U],h[e*E+U+1],
- h[e*E+U+2]),P.transformVector(K,K),q[e*x+I+3]=K.x,q[e*x+I+3+1]=K.y,q[e*x+I+3+2]=K.z),r&&(q[e*x+I+D]=h[e*E+Z],q[e*x+I+D+1]=h[e*E+Z+1]),t&&(q[e*x+I+z]=h[e*E+T],q[e*x+I+z+1]=h[e*E+T+1]),v&&(K.set(h[e*E+L],h[e*E+L+1],h[e*E+L+2]),P.transformVector(K,K),q[e*x+I+C]=K.x,q[e*x+I+C+1]=K.y,q[e*x+I+C+2]=K.z,q[e*x+I+C+3]=h[e*E+L+3]),y&&(F[e*x*4+4*I+4*A]=G[e*E*4+4*R],F[e*x*4+4*I+4*A+1]=G[e*E*4+4*R+1],F[e*x*4+4*I+4*A+2]=G[e*E*4+4*R+2],F[e*x*4+4*I+4*A+3]=G[e*E*4+4*R+3]);I=p.primitive[0].base;E=p.primitive[0].count;
- p=new Uint16Array(p.indexBuffer[0].storage);for(e=0;e<E;e++)H[e+V]=p[I+e]+Q;V+=E;Q+=n;I=Q*x}a=0;m&&(a|=2);r&&(a|=4);t&&(a|=8);v&&(a|=16);y&&(a|=32);d&&(a|=64);c=this.vertexFormats[a];c||(c=[],c.push({semantic:pc.SEMANTIC_POSITION,components:3,type:pc.ELEMENTTYPE_FLOAT32,normalize:!1}),m&&c.push({semantic:pc.SEMANTIC_NORMAL,components:3,type:pc.ELEMENTTYPE_FLOAT32,normalize:!1}),r&&c.push({semantic:pc.SEMANTIC_TEXCOORD0,components:2,type:pc.ELEMENTTYPE_FLOAT32,normalize:!1}),t&&c.push({semantic:pc.SEMANTIC_TEXCOORD1,
- components:2,type:pc.ELEMENTTYPE_FLOAT32,normalize:!1}),v&&c.push({semantic:pc.SEMANTIC_TANGENT,components:4,type:pc.ELEMENTTYPE_FLOAT32,normalize:!1}),y&&c.push({semantic:pc.SEMANTIC_COLOR,components:4,type:pc.ELEMENTTYPE_UINT8,normalize:!0}),d&&c.push({semantic:pc.SEMANTIC_BLENDINDICES,components:1,type:pc.ELEMENTTYPE_FLOAT32,normalize:!1}),c=this.vertexFormats[a]=new pc.VertexFormat(this.device,c));m=new pc.VertexBuffer(this.device,c,u,pc.BUFFER_STATIC,q.buffer);J.unlock();p=new pc.Mesh;p.vertexBuffer=
- m;p.indexBuffer[0]=J;p.primitive[0].type=f.origMeshInstances[0].mesh.primitive[0].type;p.primitive[0].base=0;p.primitive[0].count=w;p.primitive[0].indexed=!0;p.cull=!1;d&&(k=k.clone(),k.chunks.transformVS=this.transformVS,k.chunks.skinTexVS=this.skinTexVS,k.chunks.skinConstVS=this.skinConstVS,k.update());k=new pc.MeshInstance(this.rootNode,p,k);k.castShadow=f.origMeshInstances[0].castShadow;k.parameters=f.origMeshInstances[0].parameters;k.isStatic=f.origMeshInstances[0].isStatic;k.cull=f.origMeshInstances[0].cull;
- k.layer=f.origMeshInstances[0].layer;k._staticLightList=f.origMeshInstances[0]._staticLightList;k._shaderDefs=f.origMeshInstances[0]._shaderDefs;if(d){d=[];for(c=0;c<f.origMeshInstances.length;c++)d.push(f.origMeshInstances[c].node);k.skinInstance=new b(this.device,d,this.rootNode)}k._updateAabb=!1;f.meshInstance=k;this.update(f);d=new pc.Model;d.meshInstances=[f.meshInstance];d.castShadows=f.origMeshInstances[0].castShadows;f.model=d;return f}};a.prototype.update=function(a){a._aabb.copy(a.origMeshInstances[0].aabb);
- for(var b=0;b<a.origMeshInstances.length;b++)0<b&&a._aabb.add(a.origMeshInstances[b].aabb);a.meshInstance.aabb=a._aabb;a._aabb._radiusVer=-1;a.meshInstance._aabbVer=0};a.prototype.updateAll=function(){0<this._dirtyGroups.length&&this.generate(this._dirtyGroups);for(var a=0;a<this._batchList.length;a++)this._batchList[a].dynamic&&this.update(this._batchList[a])};a.prototype.clone=function(a,d){var c=new pc.Batch(d,a.dynamic,a.batchGroupId);this._batchList.push(c);for(var f=[],l=0;l<d.length;l++)f.push(d[l].node);
- c.meshInstance=new pc.MeshInstance(a.meshInstance.node,a.meshInstance.mesh,a.meshInstance.material);c.meshInstance._updateAabb=!1;c.meshInstance.parameters=d[0].parameters;c.meshInstance.isStatic=d[0].isStatic;c.meshInstance.cull=d[0].cull;c.meshInstance.layer=d[0].layer;c.meshInstance._staticLightList=d[0]._staticLightList;a.dynamic&&(c.meshInstance.skinInstance=new b(this.device,f,this.rootNode));c.meshInstance.castShadow=a.meshInstance.castShadow;c.meshInstance._shader=a.meshInstance._shader;f=
- new pc.Model;f.meshInstances=[c.meshInstance];f.castShadows=a.origMeshInstances[0].castShadows;c.model=f;return c};a.prototype.destroy=function(a){a.refCounter=0;for(var b=this._batchGroups[a.batchGroupId].layers,c=0;c<b.length;c++)this.scene.layers.getLayerById(b[c]).removeMeshInstances(a.model.meshInstances);a.model.destroy()};a.prototype.decrement=function(a){a.refCounter--;0===a.refCounter&&this.destroy(a)};a.prototype.register=function(a,b){a.refCounter=b.length;for(var c=this,d=function(){c.decrement(a)},
- f=0;f<b.length;f++)b[f].once("destroy",d)};return{Batch:function(a,b,e){this.origMeshInstances=a;this._aabb=new pc.BoundingBox;this.model=this.meshInstance=null;this.dynamic=b;this.batchGroupId=e;this.refCounter=0},BatchGroup:function(a,b,e,f,l){this.dynamic=e;this.maxAabbSize=f;this.id=a;this.name=b;this.layers=void 0===l?[pc.LAYERID_WORLD]:l},BatchManager:a}}());
- return pc;
- }));
|