playcanvas 2.16.0-preview.0 → 2.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +1,11 @@
1
1
  let e,t,i,s,r,a,n,o,l,h,c,d,u,f,p,m,_,g,v,S,y;/**
2
2
  * @license
3
- * PlayCanvas Engine v2.16.0-preview.0 revision aa34e6d (RELEASE)
3
+ * PlayCanvas Engine v2.16.0 revision 7aba7cb (RELEASE)
4
4
  * Copyright 2011-2026 PlayCanvas Ltd. All rights reserved.
5
5
  *
6
6
  * This source code is licensed under the MIT license found in the
7
7
  * LICENSE file in the root directory of this source tree.
8
- */let x="RenderFrame",T="RenderFrameTime",E="RenderPass",w="RenderPassDetail",b="RenderAction",A="RenderTargetAlloc",C="TextureAlloc",P="ShaderAlloc",I="ShaderCompile",D="VRAM.Texture",R="VRAM.Vb",L="VRAM.Ib",M="VRAM.Sb",O="BindGroupAlloc",F="BindGroupFormatAlloc",N="RenderPipelineAlloc",B="ComputePipelineAlloc",k="PipelineLayoutAlloc",U="Element",z="Textures",V="Assets",G="RenderQueue",H="OctreeResources",W="GpuTimings",X="2.16.0-preview.0",Y="aa34e6d";function q(e,t){for(let i in t){let s=t[i];Array.isArray(s)?e[i]=q([],s):s&&"object"==typeof s?e[i]=q({},s):e[i]=s;}return e}let $={create:()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{let t=16*Math.random()|0;return ("x"===e?t:3&t|8).toString(16)})},j={delimiter:"/",join(...e){let t=e[0];for(let i=0;i<e.length-1;i++){let s=e[i],r=e[i+1];if(r[0]===j.delimiter){t=r;continue}s&&r&&s[s.length-1]!==j.delimiter&&r[0]!==j.delimiter?t+=j.delimiter+r:t+=r;}return t},normalize(e){let t=e.startsWith(j.delimiter),i=e.endsWith(j.delimiter),s=e.split("/"),r="",a=[];for(let e=0;e<s.length;e++)if(""!==s[e]&&"."!==s[e]){if(".."===s[e]&&a.length>0){a=a.slice(0,a.length-2);continue}e>0&&a.push(j.delimiter),a.push(s[e]);}return r=a.join(""),t||r[0]!==j.delimiter||(r=r.slice(1)),i&&r[r.length-1]!==j.delimiter&&(r+=j.delimiter),r},split(e){let t=e.lastIndexOf(j.delimiter);return -1!==t?[e.substring(0,t),e.substring(t+1)]:["",e]},getBasename:e=>j.split(e)[1],getDirectory:e=>j.split(e)[0],getExtension(e){let t=e.split("?")[0].split(".").pop();return t!==e?`.${t}`:""},isRelativePath:e=>"/"!==e.charAt(0)&&null===e.match(/:\/\//),extractPath(e){let t="",i=e.split("/"),s=0;if(i.length>1)if(j.isRelativePath(e))if("."===i[0])for(s=0;s<i.length-1;++s)t+=0===s?i[s]:`/${i[s]}`;else if(".."===i[0])for(s=0;s<i.length-1;++s)t+=0===s?i[s]:`/${i[s]}`;else for(s=0,t=".";s<i.length-1;++s)t+=`/${i[s]}`;else for(s=0;s<i.length-1;++s)t+=0===s?i[s]:`/${i[s]}`;return t}},K="undefined"!=typeof navigator?navigator.userAgent:"",Z="undefined"!=typeof window?"browser":"undefined"!=typeof global?"node":"worker",Q=/android/i.test(K)?"android":/ip(?:[ao]d|hone)/i.test(K)?"ios":/windows/i.test(K)?"windows":/mac os/i.test(K)?"osx":/linux/i.test(K)?"linux":/cros/i.test(K)?"cros":null,J="browser"!==Z?null:/Chrome\/|Chromium\/|Edg.*\//.test(K)?"chrome":/Safari\//.test(K)?"safari":/Firefox\//.test(K)?"firefox":"other",ee=/xbox/i.test(K),et="browser"===Z&&("ontouchstart"in window||"maxTouchPoints"in navigator&&navigator.maxTouchPoints>0),ei="browser"===Z&&(!!navigator.getGamepads||!!navigator.webkitGetGamepads),es="undefined"!=typeof Worker,er=(()=>{let e=false;try{let t=Object.defineProperty({},"passive",{get:function(){return e=!0,!1}});window.addEventListener("testpassive",null,t),window.removeEventListener("testpassive",null,t);}catch(e){}return e})(),ea={name:Q,environment:Z,global:("undefined"!=typeof globalThis&&globalThis)??("browser"===Z&&window)??("node"===Z&&global)??("worker"===Z&&self),browser:"browser"===Z,worker:"worker"===Z,desktop:["windows","osx","linux","cros"].includes(Q),mobile:["android","ios"].includes(Q),ios:"ios"===Q,android:"android"===Q,xbox:ee,gamepads:ei,touch:et,workers:es,passiveEvents:er,browserName:J},en="abcdefghijklmnopqrstuvwxyz",eo="ABCDEFGHIJKLMNOPQRSTUVWXYZ";function el(e,t=0){let i=e.length;if(t<0||t>=i)return null;let s=e.charCodeAt(t);if(i>1&&s>=55296&&s<=56319){let i=e.charCodeAt(t+1);if(i>=56320&&i<=57343)return {code:(s-55296)*1024+i-56320+65536,long:true}}return {code:s,long:false}}function eh(e,t,i){if(!e)return false;let s=el(e);if(s){let e=s.code;return e>=t&&e<=i}return false}let ec={ASCII_LOWERCASE:en,ASCII_UPPERCASE:eo,ASCII_LETTERS:en+eo,format(e,...t){for(let i=0;i<t.length;i++)e=e.replace(`{${i}}`,t[i]);return e},getCodePoint(e,t){let i=el(e,t);return i&&i.code},getCodePoints(e){let t;if("string"!=typeof e)throw TypeError("Not a string");let i=0,s=[];for(;t=el(e,i);)s.push(t.code),i+=t.long?2:1;return s},getSymbols(e){let t;if("string"!=typeof e)throw TypeError("Not a string");let i=0,s=e.length,r=[],a=0;for(;i<s;){if(a+=function(e,t){if(t===e.length-1)return 1;if(eh(e[t],55296,56319)){let i=e.substring(t,t+2),s=e.substring(t+2,t+4);return eh(s,127995,127999)||eh(i,127462,127487)&&eh(s,127462,127487)?4:eh(s,65024,65039)?3:2}return eh(e[t+1],65024,65039)?2:1}(e,i+a),eh(t=e[i+a],8400,8447)&&(t=e[i+a++]),eh(t,65024,65039)&&(t=e[i+a++]),t&&8205===t.charCodeAt(0)){t=e[i+a++];continue}let s=e.substring(i,i+a);r.push(s),i+=a,a=0;}return r},fromCodePoint:(...e)=>e.map(e=>e>65535?String.fromCharCode(((e-=65536)>>10)+55296,e%1024+56320):String.fromCharCode(e)).join("")};class ed{off(){this._removed||this.handler.offByHandle(this);}on(e,t,i=this){return this.handler._addCallback(e,t,i,false)}once(e,t,i=this){return this.handler._addCallback(e,t,i,true)}set removed(e){e&&(this._removed=true);}get removed(){return this._removed}toJSON(e){}constructor(e,t,i,s,r=false){this._removed=false,this.handler=e,this.name=t,this.callback=i,this.scope=s,this._once=r;}}class eu{initEventHandler(){this._callbacks=new Map,this._callbackActive=new Map;}_addCallback(e,t,i,s){if(this._callbacks.has(e)||this._callbacks.set(e,[]),this._callbackActive.has(e)){let t=this._callbackActive.get(e);t&&t===this._callbacks.get(e)&&this._callbackActive.set(e,t.slice());}let r=new ed(this,e,t,i,s);return this._callbacks.get(e).push(r),r}on(e,t,i=this){return this._addCallback(e,t,i,false)}once(e,t,i=this){return this._addCallback(e,t,i,true)}off(e,t,i){if(e)this._callbackActive.has(e)&&this._callbackActive.get(e)===this._callbacks.get(e)&&this._callbackActive.set(e,this._callbackActive.get(e).slice());else for(let[e,t]of this._callbackActive)this._callbacks.has(e)&&this._callbacks.get(e)===t&&this._callbackActive.set(e,t.slice());if(e)if(t){let s=this._callbacks.get(e);if(!s)return this;for(let e=0;e<s.length;e++)s[e].callback===t&&(!i||s[e].scope===i)&&(s[e].removed=true,s.splice(e,1),e--);0===s.length&&this._callbacks.delete(e);}else {let t=this._callbacks.get(e);if(t){for(let e=0;e<t.length;e++)t[e].removed=true;this._callbacks.delete(e);}}else {for(let e of this._callbacks.values())for(let t=0;t<e.length;t++)e[t].removed=true;this._callbacks.clear();}return this}offByHandle(e){let t=e.name;e.removed=true,this._callbackActive.has(t)&&this._callbackActive.get(t)===this._callbacks.get(t)&&this._callbackActive.set(t,this._callbackActive.get(t).slice());let i=this._callbacks.get(t);if(!i)return this;let s=i.indexOf(e);return -1!==s&&(i.splice(s,1),0===i.length&&this._callbacks.delete(t)),this}fire(e,t,i,s,r,a,n,o,l){let h;if(!e)return this;let c=this._callbacks.get(e);if(!c)return this;this._callbackActive.has(e)?this._callbackActive.get(e)!==c&&(h=c.slice()):this._callbackActive.set(e,c);for(let c=0;(h||this._callbackActive.get(e))&&c<(h||this._callbackActive.get(e)).length;c++){let d=(h||this._callbackActive.get(e))[c];if(d.callback&&(d.callback.call(d.scope,t,i,s,r,a,n,o,l),d._once)){let t=this._callbacks.get(e),i=t?t.indexOf(d):-1;if(-1!==i){this._callbackActive.get(e)===t&&this._callbackActive.set(e,this._callbackActive.get(e).slice());let s=this._callbacks.get(e);if(!s)continue;s[i].removed=true,s.splice(i,1),0===s.length&&this._callbacks.delete(e);}}}return h||this._callbackActive.delete(e),this}hasEvent(e){return !!this._callbacks.get(e)?.length}constructor(){this._callbacks=new Map,this._callbackActive=new Map;}}class ef{push(e,t){if(this._index[e])throw Error(`Key already in index ${e}`);let i=this._list.push(t)-1;this._index[e]=i;}has(e){return void 0!==this._index[e]}get(e){let t=this._index[e];return void 0!==t?this._list[t]:null}remove(e){let t=this._index[e];if(void 0!==t){for(e in this._list.splice(t,1),delete this._index[e],this._index){let i=this._index[e];i>t&&(this._index[e]=i-1);}return true}return false}list(){return this._list}clear(){for(let e in this._list.length=0,this._index)delete this._index[e];}constructor(){this._list=[],this._index={};}}class ep{static loadScript(e,t){let i=document.createElement("script");i.setAttribute("src",e),i.onload=()=>{t(null);},i.onerror=()=>{t(`Failed to load script='${e}'`);},document.body.appendChild(i);}static loadWasm(e,t,i){let s=ep.wasmSupported()&&t.glueUrl&&t.wasmUrl?t.glueUrl:t.fallbackUrl;s?ep.loadScript(s,s=>{if(s)i(s,null);else {let s=window[e];window[e]=void 0,s({locateFile:()=>t.wasmUrl,onAbort:()=>{i("wasm module aborted.");}}).then(e=>{i(null,e);});}}):i("No supported wasm modules found.",null);}static getModule(e){return ep.modules.hasOwnProperty(e)||(ep.modules[e]={config:null,initializing:false,instance:null,callbacks:[]}),ep.modules[e]}static initialize(e,t){if(t.initializing)return;let i=t.config;(i.glueUrl||i.wasmUrl||i.fallbackUrl)&&(t.initializing=true,ep.loadWasm(e,i,(e,s)=>{e?i.errorHandler&&i.errorHandler(e):(t.instance=s,t.callbacks.forEach(e=>{e(s);}));}));}}ep.modules={},S=v={},ep.wasmSupported=()=>(S===v&&(S=(()=>{try{if("object"==typeof WebAssembly&&"function"==typeof WebAssembly.instantiate){let e=new WebAssembly.Module(Uint8Array.of(0,97,115,109,1,0,0,0));if(e instanceof WebAssembly.Module)return new WebAssembly.Instance(e)instanceof WebAssembly.Instance}}catch(e){}return false})()),S);class em{static setConfig(e,t){let i=ep.getModule(e);i.config=t,i.callbacks.length>0&&ep.initialize(e,i);}static getConfig(e){return ep.modules?.[e]?.config}static getInstance(e,t){let i=ep.getModule(e);i.instance?t(i.instance):(i.callbacks.push(t),i.config&&ep.initialize(e,i));}}class e_{get remainingBytes(){return this.dataView.byteLength-this.offset}reset(e=0){this.offset=e;}skip(e){this.offset+=e;}align(e){this.offset=this.offset+e-1&~(e-1);}_inc(e){return this.offset+=e,this.offset-e}readChar(){return String.fromCharCode(this.dataView.getUint8(this.offset++))}readChars(e){let t="";for(let i=0;i<e;++i)t+=this.readChar();return t}readU8(){return this.dataView.getUint8(this.offset++)}readU16(){return this.dataView.getUint16(this._inc(2),true)}readU32(){return this.dataView.getUint32(this._inc(4),true)}readU64(){return this.readU32()+0x100000000*this.readU32()}readU32be(){return this.dataView.getUint32(this._inc(4),false)}readArray(e){for(let t=0;t<e.length;++t)e[t]=this.readU8();}readLine(){let e=this.dataView,t="";for(;!(this.offset>=e.byteLength);){let e=String.fromCharCode(this.readU8());if("\n"===e)break;t+=e;}return t}constructor(e){this.offset=0,this.arraybuffer=e,this.dataView=new DataView(e);}}class eg{_binarySearch(e){let t,i,s=0,r=this.items.length-1,a=e[this._sortBy];for(;s<=r;)t=Math.floor((s+r)/2),(i=this.items[t][this._sortBy])<=a?s=t+1:i>a&&(r=t-1);return s}_doSort(e,t){let i=this._sortBy;return e[i]-t[i]}insert(e){let t=this._binarySearch(e);this.items.splice(t,0,e),this.length++,this.loopIndex>=t&&this.loopIndex++;}append(e){this.items.push(e),this.length++;}remove(e){let t=this.items.indexOf(e);!(t<0)&&(this.items.splice(t,1),this.length--,this.loopIndex>=t&&this.loopIndex--);}sort(){let e=this.loopIndex>=0?this.items[this.loopIndex]:null;this.items.sort(this._sortHandler),null!==e&&(this.loopIndex=this.items.indexOf(e));}constructor(e){this.items=[],this.length=0,this.loopIndex=-1,this._sortBy=e.sortBy,this._sortHandler=this._doSort.bind(this);}}class ev extends eu{add(...e){let t=false,i=this._processArguments(e,true);if(!i.length)return t;for(let e=0;e<i.length;e++)this._index[i[e]]||(t=true,this._index[i[e]]=true,this._list.push(i[e]),this.fire("add",i[e],this._parent));return t&&this.fire("change",this._parent),t}remove(...e){let t=false;if(!this._list.length)return t;let i=this._processArguments(e,true);if(!i.length)return t;for(let e=0;e<i.length;e++)this._index[i[e]]&&(t=true,delete this._index[i[e]],this._list.splice(this._list.indexOf(i[e]),1),this.fire("remove",i[e],this._parent));return t&&this.fire("change",this._parent),t}clear(){if(!this._list.length)return;let e=this._list.slice(0);this._list=[],this._index={};for(let t=0;t<e.length;t++)this.fire("remove",e[t],this._parent);this.fire("change",this._parent);}has(...e){return !!this._list.length&&this._has(this._processArguments(e))}_has(e){if(!this._list.length||!e.length)return false;for(let t=0;t<e.length;t++)if(1===e[t].length){if(this._index[e[t][0]])return true}else {let i=true;for(let s=0;s<e[t].length;s++)if(!this._index[e[t][s]]){i=false;break}if(i)return true}return false}list(){return this._list.slice(0)}_processArguments(e,t){let i=[],s=[];if(!e||!e.length)return i;for(let r=0;r<e.length;r++)if(e[r]instanceof Array){t||(s=[]);for(let a=0;a<e[r].length;a++)"string"==typeof e[r][a]&&(t?i.push(e[r][a]):s.push(e[r][a]));!t&&s.length&&i.push(s);}else "string"==typeof e[r]&&(t?i.push(e[r]):i.push([e[r]]));return i}get size(){return this._list.length}constructor(e){super(),this._index={},this._list=[],this._parent=e;}}ev.EVENT_ADD="add",ev.EVENT_REMOVE="remove",ev.EVENT_CHANGE="change";let eS="undefined"!=typeof window&&window.performance&&window.performance.now?performance.now.bind(performance):Date.now;function ey(e){let t="";if((e.authority||e.scheme)&&(e.host||e.hostpath))throw Error("Can't have 'scheme' or 'authority' and 'host' or 'hostpath' option");if(e.host&&e.hostpath)throw Error("Can't have 'host' and 'hostpath' option");if(e.path&&e.hostpath)throw Error("Can't have 'path' and 'hostpath' option");return e.scheme&&(t+=`${e.scheme}:`),e.authority&&(t+=`//${e.authority}`),e.host&&(t+=e.host),e.path&&(t+=e.path),e.hostpath&&(t+=e.hostpath),e.query&&(t+=`?${e.query}`),e.fragment&&(t+=`#${e.fragment}`),t}let ex=/^(([^:/?#]+):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/;class eT{toString(){let e="";return this.scheme&&(e+=`${this.scheme}:`),this.authority&&(e+=`//${this.authority}`),e+=this.path,this.query&&(e+=`?${this.query}`),this.fragment&&(e+=`#${this.fragment}`),e}getQuery(){let e={};if(this.query)for(let t of decodeURIComponent(this.query).split("&")){let i=t.split("=");e[i[0]]=i[1];}return e}setQuery(e){let t="";for(let i in e)e.hasOwnProperty(i)&&(""!==t&&(t+="&"),t+=`${encodeURIComponent(i)}=${encodeURIComponent(e[i])}`);this.query=t;}constructor(e){let t=e.match(ex);this.scheme=t[2],this.authority=t[4],this.path=t[5],this.query=t[7],this.fragment=t[9];}}class eE{static set(e,t=true){}static get(e){return eE._traceChannels.has(e)}}eE._traceChannels=new Set,eE.stack=false;let ew=0,eb=1,eA=4,eC=5,eP={DEG_TO_RAD:Math.PI/180,RAD_TO_DEG:180/Math.PI,clamp:(e,t,i)=>e>=i?i:e<=t?t:e,intToBytes24:e=>[e>>16&255,e>>8&255,255&e],intToBytes32:e=>[e>>24&255,e>>16&255,e>>8&255,255&e],bytesToInt24:(e,t,i)=>(e.length&&(i=e[2],t=e[1],e=e[0]),e<<16|t<<8|i),bytesToInt32:(e,t,i,s)=>(e.length&&(s=e[3],i=e[2],t=e[1],e=e[0]),(e<<24|t<<16|i<<8|s)>>>0),lerp:(e,t,i)=>e+(t-e)*eP.clamp(i,0,1),lerpAngle:(e,t,i)=>(t-e>180&&(t-=360),t-e<-180&&(t+=360),eP.lerp(e,t,eP.clamp(i,0,1))),powerOfTwo:e=>0!==e&&!(e&e-1),nextPowerOfTwo:e=>(e--,e|=e>>1,e|=e>>2,e|=e>>4,e|=e>>8,e|=e>>16,++e),nearestPowerOfTwo:e=>Math.pow(2,Math.round(Math.log2(e))),random:(e,t)=>Math.random()*(t-e)+e,smoothstep:(e,t,i)=>i<=e?0:i>=t?1:(i=(i-e)/(t-e))*i*(3-2*i),smootherstep:(e,t,i)=>i<=e?0:i>=t?1:(i=(i-e)/(t-e))*i*i*(i*(6*i-15)+10),roundUp:(e,t)=>0===t?e:Math.ceil(e/t)*t,between(e,t,i,s){let r=Math.min(t,i),a=Math.max(t,i);return s?e>=r&&e<=a:e>r&&e<a}};class eI{clone(){return new this.constructor(this.r,this.g,this.b,this.a)}copy(e){return this.r=e.r,this.g=e.g,this.b=e.b,this.a=e.a,this}equals(e){return this.r===e.r&&this.g===e.g&&this.b===e.b&&this.a===e.a}set(e,t,i,s=1){return this.r=e,this.g=t,this.b=i,this.a=s,this}lerp(e,t,i){return this.r=e.r+i*(t.r-e.r),this.g=e.g+i*(t.g-e.g),this.b=e.b+i*(t.b-e.b),this.a=e.a+i*(t.a-e.a),this}linear(e=this){return this.r=Math.pow(e.r,2.2),this.g=Math.pow(e.g,2.2),this.b=Math.pow(e.b,2.2),this.a=e.a,this}gamma(e=this){return this.r=Math.pow(e.r,1/2.2),this.g=Math.pow(e.g,1/2.2),this.b=Math.pow(e.b,1/2.2),this.a=e.a,this}mulScalar(e){return this.r*=e,this.g*=e,this.b*=e,this}fromString(e){let t,i=parseInt(e.replace("#","0x"),16);return e.length>7?t=eP.intToBytes32(i):(t=eP.intToBytes24(i))[3]=255,this.set(t[0]/255,t[1]/255,t[2]/255,t[3]/255),this}fromArray(e,t=0){return this.r=e[t]??this.r,this.g=e[t+1]??this.g,this.b=e[t+2]??this.b,this.a=e[t+3]??this.a,this}toString(e,t){let{r:i,g:s,b:r,a}=this;if(t||i>1||s>1||r>1)return `${i.toFixed(3)}, ${s.toFixed(3)}, ${r.toFixed(3)}, ${a.toFixed(3)}`;let n=`#${(0x1000000+(Math.round(255*i)<<16)+(Math.round(255*s)<<8)+Math.round(255*r)).toString(16).slice(1)}`;if(true===e){let e=Math.round(255*a).toString(16);this.a<16/255?n+=`0${e}`:n+=e;}return n}toArray(e=[],t=0,i=true){return e[t]=this.r,e[t+1]=this.g,e[t+2]=this.b,i&&(e[t+3]=this.a),e}constructor(e=0,t=0,i=0,s=1){let r=e.length;3===r||4===r?(this.r=e[0],this.g=e[1],this.b=e[2],this.a=e[3]??1):(this.r=e,this.g=t,this.b=i,this.a=s);}}eI.BLACK=Object.freeze(new eI(0,0,0,1)),eI.BLUE=Object.freeze(new eI(0,0,1,1)),eI.CYAN=Object.freeze(new eI(0,1,1,1)),eI.GRAY=Object.freeze(new eI(.5,.5,.5,1)),eI.GREEN=Object.freeze(new eI(0,1,0,1)),eI.MAGENTA=Object.freeze(new eI(1,0,1,1)),eI.RED=Object.freeze(new eI(1,0,0,1)),eI.WHITE=Object.freeze(new eI(1,1,1,1)),eI.YELLOW=Object.freeze(new eI(1,1,0,1));class eD{evaluate(e,t=false){let i;(t||e<this._left||e>=this._right)&&this._reset(e);let s=this._curve.type;if(s===eC)i=this._p0;else {let t=0===this._recip?0:(e-this._left)*this._recip;i=s===ew?eP.lerp(this._p0,this._p1,t):s===eb?eP.lerp(this._p0,this._p1,t*t*(3-2*t)):this._evaluateHermite(this._p0,this._p1,this._m0,this._m1,t);}return i}_reset(e){let t=this._curve.keys,i=t.length;if(i)if(e<t[0][0])this._left=-1/0,this._right=t[0][0],this._recip=0,this._p0=this._p1=t[0][1],this._m0=this._m1=0;else if(e>=t[i-1][0])this._left=t[i-1][0],this._right=1/0,this._recip=0,this._p0=this._p1=t[i-1][1],this._m0=this._m1=0;else {let i=0;for(;e>=t[i+1][0];)i++;this._left=t[i][0],this._right=t[i+1][0];let s=1/(this._right-this._left);this._recip=isFinite(s)?s:0,this._p0=t[i][1],this._p1=t[i+1][1],this._curve.type===eA&&this._calcTangents(t,i);}else this._left=-1/0,this._right=1/0,this._recip=0,this._p0=this._p1=this._m0=this._m1=0;}_calcTangents(e,t){let i,s,r=e[t],a=e[t+1];if(i=0===t?[e[0][0]+(e[0][0]-e[1][0]),e[0][1]+(e[0][1]-e[1][1])]:e[t-1],s=t===e.length-2?[e[t+1][0]+(e[t+1][0]-e[t][0]),e[t+1][1]+(e[t+1][1]-e[t][1])]:e[t+2],this._curve.type===eA){let e=2*(a[0]-r[0])/(a[0]-i[0]),t=2*(a[0]-r[0])/(s[0]-r[0]);this._m0=this._curve.tension*(isFinite(e)?e:0)*(a[1]-i[1]),this._m1=this._curve.tension*(isFinite(t)?t:0)*(s[1]-r[1]);}else {let e=(a[0]-r[0])/(r[0]-i[0]),t=(a[0]-r[0])/(s[0]-a[0]),n=r[1]+(i[1]-r[1])*(isFinite(e)?e:0),o=a[1]+(s[1]-a[1])*(isFinite(t)?t:0),l=this._curve.tension;this._m0=l*(a[1]-n),this._m1=l*(o-r[1]);}}_evaluateHermite(e,t,i,s,r){let a=r*r,n=r+r,o=1-r,l=o*o;return (1+n)*l*e+r*l*i+a*(3-n)*t+a*(r-1)*s}constructor(e,t=0){this._left=-1/0,this._right=1/0,this._recip=0,this._p0=0,this._p1=0,this._m0=0,this._m1=0,this._curve=e,this._reset(t);}}class eR{get length(){return this.keys.length}add(e,t){let i=this.keys,s=i.length,r=0;for(;r<s&&!(i[r][0]>e);r++);let a=[e,t];return this.keys.splice(r,0,a),a}get(e){return this.keys[e]}sort(){this.keys.sort((e,t)=>e[0]-t[0]);}value(e){return this._eval.evaluate(e,true)}closest(e){let t=this.keys,i=t.length,s=2,r=null;for(let a=0;a<i;a++){let i=Math.abs(e-t[a][0]);if(s>=i)s=i,r=t[a];else break}return r}clone(){let e=new this.constructor;return e.keys=this.keys.map(e=>[...e]),e.type=this.type,e.tension=this.tension,e}quantize(e){let t=new Float32Array(e=Math.max(e,2)),i=1/(e-1);t[0]=this._eval.evaluate(0,true);for(let s=1;s<e;s++)t[s]=this._eval.evaluate(i*s);return t}quantizeClamped(e,t,i){let s=this.quantize(e);for(let e=0;e<s.length;++e)s[e]=Math.min(i,Math.max(t,s[e]));return s}constructor(e){if(this.keys=[],this.type=eb,this.tension=.5,this._eval=new eD(this),e)for(let t=0;t<e.length-1;t+=2)this.keys.push([e[t],e[t+1]]);this.sort();}}class eL{get length(){return this.curves.length}set type(e){this._type=e;for(let t=0;t<this.curves.length;t++)this.curves[t].type=e;}get type(){return this._type}get(e){return this.curves[e]}value(e,t=[]){let i=this.curves.length;t.length=i;for(let s=0;s<i;s++)t[s]=this.curves[s].value(e);return t}clone(){let e=new this.constructor;e.curves=[];for(let t=0;t<this.curves.length;t++)e.curves.push(this.curves[t].clone());return e._type=this._type,e}quantize(e){e=Math.max(e,2);let t=this.curves.length,i=new Float32Array(e*t),s=1/(e-1);for(let r=0;r<t;r++){let a=new eD(this.curves[r]);for(let n=0;n<e;n++)i[n*t+r]=a.evaluate(s*n);}return i}quantizeClamped(e,t,i){let s=this.quantize(e);for(let e=0;e<s.length;++e)s[e]=Math.min(i,Math.max(t,s[e]));return s}constructor(...e){if(this.curves=[],this._type=eb,e.length>1)for(let t=0;t<e.length;t++)this.curves.push(new eR(e[t]));else if(0===e.length)this.curves.push(new eR);else {let t=e[0];if("number"==typeof t)for(let e=0;e<t;e++)this.curves.push(new eR);else for(let e=0;e<t.length;e++)this.curves.push(new eR(t[e]));}}}let eM=new Float32Array(1),eO=new Int32Array(eM.buffer);class eF{static float2Half(e){eM[0]=e;let t=eO[0],i=t>>16&32768,s=t>>12&2047,r=t>>23&255;return r<103?i:r>142?(i|=31744,i|=+(255!==r)&&8388607&t):r<113?(s|=2048,i|=(s>>114-r)+(s>>113-r&1)):(i|=r-112<<10|s>>1,i+=1&s)}static float2RGBA8(e,t){eM[0]=e;let i=eO[0];t.r=(i>>24&255)/255,t.g=(i>>16&255)/255,t.b=(i>>8&255)/255,t.a=(255&i)/255;}}class eN{static concentric(e,t){let i=[];i.push(0,0);let s=2*Math.PI/e/t;for(let t=1;t<=e;t++){let r=t/e,a=Math.max(1,Math.floor(2*Math.PI*r/s)),n=2*Math.PI/a;for(let e=0;e<a;e++){let t=e*n,s=r*Math.cos(t),a=r*Math.sin(t);i.push(s,a);}}return i}}class eB{add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}add2(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this}addScalar(e){return this.x+=e,this.y+=e,this.z+=e,this}addScaled(e,t){return this.x+=e.x*t,this.y+=e.y*t,this.z+=e.z*t,this}clone(){return new this.constructor(this.x,this.y,this.z)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this}cross(e,t){let i=e.x,s=e.y,r=e.z,a=t.x,n=t.y,o=t.z;return this.x=s*o-n*r,this.y=r*a-o*i,this.z=i*n-a*s,this}distance(e){let t=this.x-e.x,i=this.y-e.y,s=this.z-e.z;return Math.sqrt(t*t+i*i+s*s)}div(e){return this.x/=e.x,this.y/=e.y,this.z/=e.z,this}div2(e,t){return this.x=e.x/t.x,this.y=e.y/t.y,this.z=e.z/t.z,this}divScalar(e){return this.x/=e,this.y/=e,this.z/=e,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z}equals(e){return this.x===e.x&&this.y===e.y&&this.z===e.z}equalsApprox(e,t=1e-6){return Math.abs(this.x-e.x)<t&&Math.abs(this.y-e.y)<t&&Math.abs(this.z-e.z)<t}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}lerp(e,t,i){return this.x=e.x+i*(t.x-e.x),this.y=e.y+i*(t.y-e.y),this.z=e.z+i*(t.z-e.z),this}mul(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this}mul2(e,t){return this.x=e.x*t.x,this.y=e.y*t.y,this.z=e.z*t.z,this}mulScalar(e){return this.x*=e,this.y*=e,this.z*=e,this}normalize(e=this){let t=e.x*e.x+e.y*e.y+e.z*e.z;if(t>0){let i=1/Math.sqrt(t);this.x=e.x*i,this.y=e.y*i,this.z=e.z*i;}return this}floor(e=this){return this.x=Math.floor(e.x),this.y=Math.floor(e.y),this.z=Math.floor(e.z),this}ceil(e=this){return this.x=Math.ceil(e.x),this.y=Math.ceil(e.y),this.z=Math.ceil(e.z),this}round(e=this){return this.x=Math.round(e.x),this.y=Math.round(e.y),this.z=Math.round(e.z),this}min(e){return e.x<this.x&&(this.x=e.x),e.y<this.y&&(this.y=e.y),e.z<this.z&&(this.z=e.z),this}max(e){return e.x>this.x&&(this.x=e.x),e.y>this.y&&(this.y=e.y),e.z>this.z&&(this.z=e.z),this}project(e){let t=(this.x*e.x+this.y*e.y+this.z*e.z)/(e.x*e.x+e.y*e.y+e.z*e.z);return this.x=e.x*t,this.y=e.y*t,this.z=e.z*t,this}set(e,t,i){return this.x=e,this.y=t,this.z=i,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}sub2(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z,this}subScalar(e){return this.x-=e,this.y-=e,this.z-=e,this}fromArray(e,t=0){return this.x=e[t]??this.x,this.y=e[t+1]??this.y,this.z=e[t+2]??this.z,this}toString(){return `[${this.x}, ${this.y}, ${this.z}]`}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,e}constructor(e=0,t=0,i=0){3===e.length?(this.x=e[0],this.y=e[1],this.z=e[2]):(this.x=e,this.y=t,this.z=i);}}eB.ZERO=Object.freeze(new eB(0,0,0)),eB.HALF=Object.freeze(new eB(.5,.5,.5)),eB.ONE=Object.freeze(new eB(1,1,1)),eB.UP=Object.freeze(new eB(0,1,0)),eB.DOWN=Object.freeze(new eB(0,-1,0)),eB.RIGHT=Object.freeze(new eB(1,0,0)),eB.LEFT=Object.freeze(new eB(-1,0,0)),eB.FORWARD=Object.freeze(new eB(0,0,-1)),eB.BACK=Object.freeze(new eB(0,0,1));class ek{clone(){return new this.constructor().copy(this)}copy(e){let t=e.data,i=this.data;return i[0]=t[0],i[1]=t[1],i[2]=t[2],i[3]=t[3],i[4]=t[4],i[5]=t[5],i[6]=t[6],i[7]=t[7],i[8]=t[8],this}set(e){let t=this.data;return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],this}getX(e=new eB){return e.set(this.data[0],this.data[1],this.data[2])}getY(e=new eB){return e.set(this.data[3],this.data[4],this.data[5])}getZ(e=new eB){return e.set(this.data[6],this.data[7],this.data[8])}equals(e){let t=this.data,i=e.data;return t[0]===i[0]&&t[1]===i[1]&&t[2]===i[2]&&t[3]===i[3]&&t[4]===i[4]&&t[5]===i[5]&&t[6]===i[6]&&t[7]===i[7]&&t[8]===i[8]}isIdentity(){let e=this.data;return 1===e[0]&&0===e[1]&&0===e[2]&&0===e[3]&&1===e[4]&&0===e[5]&&0===e[6]&&0===e[7]&&1===e[8]}setIdentity(){let e=this.data;return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=1,e[5]=0,e[6]=0,e[7]=0,e[8]=1,this}toString(){return `[${this.data.join(", ")}]`}transpose(e=this){let t=e.data,i=this.data;if(t===i){let e;e=t[1],i[1]=t[3],i[3]=e,e=t[2],i[2]=t[6],i[6]=e,e=t[5],i[5]=t[7],i[7]=e;}else i[0]=t[0],i[1]=t[3],i[2]=t[6],i[3]=t[1],i[4]=t[4],i[5]=t[7],i[6]=t[2],i[7]=t[5],i[8]=t[8];return this}setFromMat4(e){let t=e.data,i=this.data;return i[0]=t[0],i[1]=t[1],i[2]=t[2],i[3]=t[4],i[4]=t[5],i[5]=t[6],i[6]=t[8],i[7]=t[9],i[8]=t[10],this}setFromQuat(e){let t=e.x,i=e.y,s=e.z,r=e.w,a=t+t,n=i+i,o=s+s,l=t*a,h=t*n,c=t*o,d=i*n,u=i*o,f=s*o,p=r*a,m=r*n,_=r*o,g=this.data;return g[0]=1-(d+f),g[1]=h+_,g[2]=c-m,g[3]=h-_,g[4]=1-(l+f),g[5]=u+p,g[6]=c+m,g[7]=u-p,g[8]=1-(l+d),this}invertMat4(e){let t=e.data,i=t[0],s=t[1],r=t[2],a=t[4],n=t[5],o=t[6],l=t[8],h=t[9],c=t[10],d=c*n-o*h,u=-c*a+o*l,f=h*a-n*l,p=i*d+s*u+r*f;if(0===p)this.setIdentity();else {let e=1/p,t=this.data;t[0]=d*e,t[1]=(-c*s+r*h)*e,t[2]=(o*s-r*n)*e,t[3]=u*e,t[4]=(c*i-r*l)*e,t[5]=(-o*i+r*a)*e,t[6]=f*e,t[7]=(-h*i+s*l)*e,t[8]=(n*i-s*a)*e;}return this}transformVector(e,t=new eB){let i=this.data,{x:s,y:r,z:a}=e;return t.x=s*i[0]+r*i[3]+a*i[6],t.y=s*i[1]+r*i[4]+a*i[7],t.z=s*i[2]+r*i[5]+a*i[8],t}constructor(){this.data=new Float32Array(9),this.data[0]=this.data[4]=this.data[8]=1;}}ek.IDENTITY=Object.freeze(new ek),ek.ZERO=Object.freeze(new ek().set([0,0,0,0,0,0,0,0,0]));class eU{add(e){return this.x+=e.x,this.y+=e.y,this}add2(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this}addScalar(e){return this.x+=e,this.y+=e,this}addScaled(e,t){return this.x+=e.x*t,this.y+=e.y*t,this}clone(){return new this.constructor(this.x,this.y)}copy(e){return this.x=e.x,this.y=e.y,this}cross(e){return this.x*e.y-this.y*e.x}distance(e){let t=this.x-e.x,i=this.y-e.y;return Math.sqrt(t*t+i*i)}div(e){return this.x/=e.x,this.y/=e.y,this}div2(e,t){return this.x=e.x/t.x,this.y=e.y/t.y,this}divScalar(e){return this.x/=e,this.y/=e,this}dot(e){return this.x*e.x+this.y*e.y}equals(e){return this.x===e.x&&this.y===e.y}equalsApprox(e,t=1e-6){return Math.abs(this.x-e.x)<t&&Math.abs(this.y-e.y)<t}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}lengthSq(){return this.x*this.x+this.y*this.y}lerp(e,t,i){return this.x=e.x+i*(t.x-e.x),this.y=e.y+i*(t.y-e.y),this}mul(e){return this.x*=e.x,this.y*=e.y,this}mul2(e,t){return this.x=e.x*t.x,this.y=e.y*t.y,this}mulScalar(e){return this.x*=e,this.y*=e,this}normalize(e=this){let t=e.x*e.x+e.y*e.y;if(t>0){let i=1/Math.sqrt(t);this.x=e.x*i,this.y=e.y*i;}return this}rotate(e){let t=Math.atan2(this.x,this.y)+e*eP.DEG_TO_RAD,i=Math.sqrt(this.x*this.x+this.y*this.y);return this.x=Math.sin(t)*i,this.y=Math.cos(t)*i,this}angle(){return Math.atan2(this.x,this.y)*eP.RAD_TO_DEG}angleTo(e){return Math.atan2(this.x*e.y+this.y*e.x,this.x*e.x+this.y*e.y)*eP.RAD_TO_DEG}floor(e=this){return this.x=Math.floor(e.x),this.y=Math.floor(e.y),this}ceil(e=this){return this.x=Math.ceil(e.x),this.y=Math.ceil(e.y),this}round(e=this){return this.x=Math.round(e.x),this.y=Math.round(e.y),this}min(e){return e.x<this.x&&(this.x=e.x),e.y<this.y&&(this.y=e.y),this}max(e){return e.x>this.x&&(this.x=e.x),e.y>this.y&&(this.y=e.y),this}set(e,t){return this.x=e,this.y=t,this}sub(e){return this.x-=e.x,this.y-=e.y,this}sub2(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this}subScalar(e){return this.x-=e,this.y-=e,this}fromArray(e,t=0){return this.x=e[t]??this.x,this.y=e[t+1]??this.y,this}toString(){return `[${this.x}, ${this.y}]`}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e}static angleRad(e,t){return Math.atan2(e.x*t.y-e.y*t.x,e.x*t.x+e.y*t.y)}constructor(e=0,t=0){2===e.length?(this.x=e[0],this.y=e[1]):(this.x=e,this.y=t);}}eU.ZERO=Object.freeze(new eU(0,0)),eU.HALF=Object.freeze(new eU(.5,.5)),eU.ONE=Object.freeze(new eU(1,1)),eU.UP=Object.freeze(new eU(0,1)),eU.DOWN=Object.freeze(new eU(0,-1)),eU.RIGHT=Object.freeze(new eU(1,0)),eU.LEFT=Object.freeze(new eU(-1,0));class ez{add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this.w+=e.w,this}add2(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this.w=e.w+t.w,this}addScalar(e){return this.x+=e,this.y+=e,this.z+=e,this.w+=e,this}addScaled(e,t){return this.x+=e.x*t,this.y+=e.y*t,this.z+=e.z*t,this.w+=e.w*t,this}clone(){return new this.constructor(this.x,this.y,this.z,this.w)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w,this}div(e){return this.x/=e.x,this.y/=e.y,this.z/=e.z,this.w/=e.w,this}div2(e,t){return this.x=e.x/t.x,this.y=e.y/t.y,this.z=e.z/t.z,this.w=e.w/t.w,this}divScalar(e){return this.x/=e,this.y/=e,this.z/=e,this.w/=e,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z+this.w*e.w}equals(e){return this.x===e.x&&this.y===e.y&&this.z===e.z&&this.w===e.w}equalsApprox(e,t=1e-6){return Math.abs(this.x-e.x)<t&&Math.abs(this.y-e.y)<t&&Math.abs(this.z-e.z)<t&&Math.abs(this.w-e.w)<t}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}lerp(e,t,i){return this.x=e.x+i*(t.x-e.x),this.y=e.y+i*(t.y-e.y),this.z=e.z+i*(t.z-e.z),this.w=e.w+i*(t.w-e.w),this}mul(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this.w*=e.w,this}mul2(e,t){return this.x=e.x*t.x,this.y=e.y*t.y,this.z=e.z*t.z,this.w=e.w*t.w,this}mulScalar(e){return this.x*=e,this.y*=e,this.z*=e,this.w*=e,this}normalize(e=this){let t=e.x*e.x+e.y*e.y+e.z*e.z+e.w*e.w;if(t>0){let i=1/Math.sqrt(t);this.x=e.x*i,this.y=e.y*i,this.z=e.z*i,this.w=e.w*i;}return this}floor(e=this){return this.x=Math.floor(e.x),this.y=Math.floor(e.y),this.z=Math.floor(e.z),this.w=Math.floor(e.w),this}ceil(e=this){return this.x=Math.ceil(e.x),this.y=Math.ceil(e.y),this.z=Math.ceil(e.z),this.w=Math.ceil(e.w),this}round(e=this){return this.x=Math.round(e.x),this.y=Math.round(e.y),this.z=Math.round(e.z),this.w=Math.round(e.w),this}min(e){return e.x<this.x&&(this.x=e.x),e.y<this.y&&(this.y=e.y),e.z<this.z&&(this.z=e.z),e.w<this.w&&(this.w=e.w),this}max(e){return e.x>this.x&&(this.x=e.x),e.y>this.y&&(this.y=e.y),e.z>this.z&&(this.z=e.z),e.w>this.w&&(this.w=e.w),this}set(e,t,i,s){return this.x=e,this.y=t,this.z=i,this.w=s,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this.w-=e.w,this}sub2(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z,this.w=e.w-t.w,this}subScalar(e){return this.x-=e,this.y-=e,this.z-=e,this.w-=e,this}fromArray(e,t=0){return this.x=e[t]??this.x,this.y=e[t+1]??this.y,this.z=e[t+2]??this.z,this.w=e[t+3]??this.w,this}toString(){return `[${this.x}, ${this.y}, ${this.z}, ${this.w}]`}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,e[t+3]=this.w,e}constructor(e=0,t=0,i=0,s=0){4===e.length?(this.x=e[0],this.y=e[1],this.z=e[2],this.w=e[3]):(this.x=e,this.y=t,this.z=i,this.w=s);}}ez.ZERO=Object.freeze(new ez(0,0,0,0)),ez.HALF=Object.freeze(new ez(.5,.5,.5,.5)),ez.ONE=Object.freeze(new ez(1,1,1,1));let eV=new eU,eG=new eB,eH=new eB,eW=new eB,eX=new eB;class eY{static _getPerspectiveHalfSize(e,t,i,s,r){r?(e.x=s*Math.tan(t*Math.PI/360),e.y=e.x/i):(e.y=s*Math.tan(t*Math.PI/360),e.x=e.y*i);}add2(e,t){let i=e.data,s=t.data,r=this.data;return r[0]=i[0]+s[0],r[1]=i[1]+s[1],r[2]=i[2]+s[2],r[3]=i[3]+s[3],r[4]=i[4]+s[4],r[5]=i[5]+s[5],r[6]=i[6]+s[6],r[7]=i[7]+s[7],r[8]=i[8]+s[8],r[9]=i[9]+s[9],r[10]=i[10]+s[10],r[11]=i[11]+s[11],r[12]=i[12]+s[12],r[13]=i[13]+s[13],r[14]=i[14]+s[14],r[15]=i[15]+s[15],this}add(e){return this.add2(this,e)}clone(){return new this.constructor().copy(this)}copy(e){let t=e.data,i=this.data;return i[0]=t[0],i[1]=t[1],i[2]=t[2],i[3]=t[3],i[4]=t[4],i[5]=t[5],i[6]=t[6],i[7]=t[7],i[8]=t[8],i[9]=t[9],i[10]=t[10],i[11]=t[11],i[12]=t[12],i[13]=t[13],i[14]=t[14],i[15]=t[15],this}equals(e){let t=this.data,i=e.data;return t[0]===i[0]&&t[1]===i[1]&&t[2]===i[2]&&t[3]===i[3]&&t[4]===i[4]&&t[5]===i[5]&&t[6]===i[6]&&t[7]===i[7]&&t[8]===i[8]&&t[9]===i[9]&&t[10]===i[10]&&t[11]===i[11]&&t[12]===i[12]&&t[13]===i[13]&&t[14]===i[14]&&t[15]===i[15]}isIdentity(){let e=this.data;return 1===e[0]&&0===e[1]&&0===e[2]&&0===e[3]&&0===e[4]&&1===e[5]&&0===e[6]&&0===e[7]&&0===e[8]&&0===e[9]&&1===e[10]&&0===e[11]&&0===e[12]&&0===e[13]&&0===e[14]&&1===e[15]}mul2(e,t){let i,s,r,a,n=e.data,o=t.data,l=this.data,h=n[0],c=n[1],d=n[2],u=n[3],f=n[4],p=n[5],m=n[6],_=n[7],g=n[8],v=n[9],S=n[10],y=n[11],x=n[12],T=n[13],E=n[14],w=n[15];return i=o[0],s=o[1],r=o[2],a=o[3],l[0]=h*i+f*s+g*r+x*a,l[1]=c*i+p*s+v*r+T*a,l[2]=d*i+m*s+S*r+E*a,l[3]=u*i+_*s+y*r+w*a,i=o[4],s=o[5],r=o[6],a=o[7],l[4]=h*i+f*s+g*r+x*a,l[5]=c*i+p*s+v*r+T*a,l[6]=d*i+m*s+S*r+E*a,l[7]=u*i+_*s+y*r+w*a,i=o[8],s=o[9],r=o[10],a=o[11],l[8]=h*i+f*s+g*r+x*a,l[9]=c*i+p*s+v*r+T*a,l[10]=d*i+m*s+S*r+E*a,l[11]=u*i+_*s+y*r+w*a,i=o[12],s=o[13],r=o[14],a=o[15],l[12]=h*i+f*s+g*r+x*a,l[13]=c*i+p*s+v*r+T*a,l[14]=d*i+m*s+S*r+E*a,l[15]=u*i+_*s+y*r+w*a,this}mulAffine2(e,t){let i,s,r,a=e.data,n=t.data,o=this.data,l=a[0],h=a[1],c=a[2],d=a[4],u=a[5],f=a[6],p=a[8],m=a[9],_=a[10],g=a[12],v=a[13],S=a[14];return i=n[0],s=n[1],r=n[2],o[0]=l*i+d*s+p*r,o[1]=h*i+u*s+m*r,o[2]=c*i+f*s+_*r,o[3]=0,i=n[4],s=n[5],r=n[6],o[4]=l*i+d*s+p*r,o[5]=h*i+u*s+m*r,o[6]=c*i+f*s+_*r,o[7]=0,i=n[8],s=n[9],r=n[10],o[8]=l*i+d*s+p*r,o[9]=h*i+u*s+m*r,o[10]=c*i+f*s+_*r,o[11]=0,i=n[12],s=n[13],r=n[14],o[12]=l*i+d*s+p*r+g,o[13]=h*i+u*s+m*r+v,o[14]=c*i+f*s+_*r+S,o[15]=1,this}mul(e){return this.mul2(this,e)}transformPoint(e,t=new eB){let i=this.data,{x:s,y:r,z:a}=e;return t.x=s*i[0]+r*i[4]+a*i[8]+i[12],t.y=s*i[1]+r*i[5]+a*i[9]+i[13],t.z=s*i[2]+r*i[6]+a*i[10]+i[14],t}transformVector(e,t=new eB){let i=this.data,{x:s,y:r,z:a}=e;return t.x=s*i[0]+r*i[4]+a*i[8],t.y=s*i[1]+r*i[5]+a*i[9],t.z=s*i[2]+r*i[6]+a*i[10],t}transformVec4(e,t=new ez){let i=this.data,{x:s,y:r,z:a,w:n}=e;return t.x=s*i[0]+r*i[4]+a*i[8]+n*i[12],t.y=s*i[1]+r*i[5]+a*i[9]+n*i[13],t.z=s*i[2]+r*i[6]+a*i[10]+n*i[14],t.w=s*i[3]+r*i[7]+a*i[11]+n*i[15],t}setLookAt(e,t,i){eW.sub2(e,t).normalize(),eH.copy(i).normalize(),eG.cross(eH,eW).normalize(),eH.cross(eW,eG);let s=this.data;return s[0]=eG.x,s[1]=eG.y,s[2]=eG.z,s[3]=0,s[4]=eH.x,s[5]=eH.y,s[6]=eH.z,s[7]=0,s[8]=eW.x,s[9]=eW.y,s[10]=eW.z,s[11]=0,s[12]=e.x,s[13]=e.y,s[14]=e.z,s[15]=1,this}setFrustum(e,t,i,s,r,a){let n=2*r,o=t-e,l=s-i,h=a-r,c=this.data;return c[0]=n/o,c[1]=0,c[2]=0,c[3]=0,c[4]=0,c[5]=n/l,c[6]=0,c[7]=0,c[8]=(t+e)/o,c[9]=(s+i)/l,c[10]=(-a-r)/h,c[11]=-1,c[12]=0,c[13]=0,c[14]=-n*a/h,c[15]=0,this}setPerspective(e,t,i,s,r){return eY._getPerspectiveHalfSize(eV,e,t,i,r),this.setFrustum(-eV.x,eV.x,-eV.y,eV.y,i,s)}setOrtho(e,t,i,s,r,a){let n=this.data;return n[0]=2/(t-e),n[1]=0,n[2]=0,n[3]=0,n[4]=0,n[5]=2/(s-i),n[6]=0,n[7]=0,n[8]=0,n[9]=0,n[10]=-2/(a-r),n[11]=0,n[12]=-(t+e)/(t-e),n[13]=-(s+i)/(s-i),n[14]=-(a+r)/(a-r),n[15]=1,this}setFromAxisAngle(e,t){t*=eP.DEG_TO_RAD;let{x:i,y:s,z:r}=e,a=Math.cos(t),n=Math.sin(t),o=1-a,l=o*i,h=o*s,c=this.data;return c[0]=l*i+a,c[1]=l*s+n*r,c[2]=l*r-n*s,c[3]=0,c[4]=l*s-n*r,c[5]=h*s+a,c[6]=h*r+n*i,c[7]=0,c[8]=l*r+n*s,c[9]=h*r-i*n,c[10]=o*r*r+a,c[11]=0,c[12]=0,c[13]=0,c[14]=0,c[15]=1,this}setTranslate(e,t,i){let s=this.data;return s[0]=1,s[1]=0,s[2]=0,s[3]=0,s[4]=0,s[5]=1,s[6]=0,s[7]=0,s[8]=0,s[9]=0,s[10]=1,s[11]=0,s[12]=e,s[13]=t,s[14]=i,s[15]=1,this}setScale(e,t,i){let s=this.data;return s[0]=e,s[1]=0,s[2]=0,s[3]=0,s[4]=0,s[5]=t,s[6]=0,s[7]=0,s[8]=0,s[9]=0,s[10]=i,s[11]=0,s[12]=0,s[13]=0,s[14]=0,s[15]=1,this}setViewport(e,t,i,s){let r=this.data;return r[0]=.5*i,r[1]=0,r[2]=0,r[3]=0,r[4]=0,r[5]=.5*s,r[6]=0,r[7]=0,r[8]=0,r[9]=0,r[10]=.5,r[11]=0,r[12]=e+.5*i,r[13]=t+.5*s,r[14]=.5,r[15]=1,this}setReflection(e,t){let i=e.x,s=e.y,r=e.z,a=this.data;return a[0]=1-2*i*i,a[1]=-2*i*s,a[2]=-2*i*r,a[3]=0,a[4]=-2*i*s,a[5]=1-2*s*s,a[6]=-2*s*r,a[7]=0,a[8]=-2*i*r,a[9]=-2*s*r,a[10]=1-2*r*r,a[11]=0,a[12]=-2*i*t,a[13]=-2*s*t,a[14]=-2*r*t,a[15]=1,this}invert(e=this){let t=e.data,i=t[0],s=t[1],r=t[2],a=t[3],n=t[4],o=t[5],l=t[6],h=t[7],c=t[8],d=t[9],u=t[10],f=t[11],p=t[12],m=t[13],_=t[14],g=t[15],v=i*o-s*n,S=i*l-r*n,y=i*h-a*n,x=s*l-r*o,T=s*h-a*o,E=r*h-a*l,w=c*m-d*p,b=c*_-u*p,A=c*g-f*p,C=d*_-u*m,P=d*g-f*m,I=u*g-f*_,D=v*I-S*P+y*C+x*A-T*b+E*w;if(0===D)this.setIdentity();else {let e=1/D,t=this.data;t[0]=(o*I-l*P+h*C)*e,t[1]=(-s*I+r*P-a*C)*e,t[2]=(m*E-_*T+g*x)*e,t[3]=(-d*E+u*T-f*x)*e,t[4]=(-n*I+l*A-h*b)*e,t[5]=(i*I-r*A+a*b)*e,t[6]=(-p*E+_*y-g*S)*e,t[7]=(c*E-u*y+f*S)*e,t[8]=(n*P-o*A+h*w)*e,t[9]=(-i*P+s*A-a*w)*e,t[10]=(p*T-m*y+g*v)*e,t[11]=(-c*T+d*y-f*v)*e,t[12]=(-n*C+o*b-l*w)*e,t[13]=(i*C-s*b+r*w)*e,t[14]=(-p*x+m*S-_*v)*e,t[15]=(c*x-d*S+u*v)*e;}return this}set(e){let t=this.data;return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],this}setIdentity(){let e=this.data;return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}setTRS(e,t,i){let s=t.x,r=t.y,a=t.z,n=t.w,o=i.x,l=i.y,h=i.z,c=s+s,d=r+r,u=a+a,f=s*c,p=s*d,m=s*u,_=r*d,g=r*u,v=a*u,S=n*c,y=n*d,x=n*u,T=this.data;return T[0]=(1-(_+v))*o,T[1]=(p+x)*o,T[2]=(m-y)*o,T[3]=0,T[4]=(p-x)*l,T[5]=(1-(f+v))*l,T[6]=(g+S)*l,T[7]=0,T[8]=(m+y)*h,T[9]=(g-S)*h,T[10]=(1-(f+_))*h,T[11]=0,T[12]=e.x,T[13]=e.y,T[14]=e.z,T[15]=1,this}transpose(e=this){let t=e.data,i=this.data;if(t===i){let e;e=t[1],i[1]=t[4],i[4]=e,e=t[2],i[2]=t[8],i[8]=e,e=t[3],i[3]=t[12],i[12]=e,e=t[6],i[6]=t[9],i[9]=e,e=t[7],i[7]=t[13],i[13]=e,e=t[11],i[11]=t[14],i[14]=e;}else i[0]=t[0],i[1]=t[4],i[2]=t[8],i[3]=t[12],i[4]=t[1],i[5]=t[5],i[6]=t[9],i[7]=t[13],i[8]=t[2],i[9]=t[6],i[10]=t[10],i[11]=t[14],i[12]=t[3],i[13]=t[7],i[14]=t[11],i[15]=t[15];return this}getTranslation(e=new eB){return e.set(this.data[12],this.data[13],this.data[14])}getX(e=new eB){return e.set(this.data[0],this.data[1],this.data[2])}getY(e=new eB){return e.set(this.data[4],this.data[5],this.data[6])}getZ(e=new eB){return e.set(this.data[8],this.data[9],this.data[10])}getScale(e=new eB){return this.getX(eG),this.getY(eH),this.getZ(eW),e.set(eG.length(),eH.length(),eW.length()),e}get scaleSign(){return this.getX(eG),this.getY(eH),this.getZ(eW),eG.cross(eG,eH),0>eG.dot(eW)?-1:1}setFromEulerAngles(e,t,i){e*=eP.DEG_TO_RAD,t*=eP.DEG_TO_RAD,i*=eP.DEG_TO_RAD;let s=Math.sin(-e),r=Math.cos(-e),a=Math.sin(-t),n=Math.cos(-t),o=Math.sin(-i),l=Math.cos(-i),h=this.data;return h[0]=n*l,h[1]=-n*o,h[2]=a,h[3]=0,h[4]=r*o+l*s*a,h[5]=r*l-s*a*o,h[6]=-n*s,h[7]=0,h[8]=s*o-r*l*a,h[9]=l*s+r*a*o,h[10]=r*n,h[11]=0,h[12]=0,h[13]=0,h[14]=0,h[15]=1,this}getEulerAngles(e=new eB){let t,i;this.getScale(eX);let s=eX.x,r=eX.y,a=eX.z;if(0===s||0===r||0===a)return e.set(0,0,0);let n=this.data,o=Math.asin(-n[2]/s),l=.5*Math.PI;return o<l?o>-l?(t=Math.atan2(n[6]/r,n[10]/a),i=Math.atan2(n[1]/s,n[0]/s)):(i=0,t=-Math.atan2(n[4]/r,n[5]/r)):(i=0,t=Math.atan2(n[4]/r,n[5]/r)),e.set(t,o,i).mulScalar(eP.RAD_TO_DEG)}toString(){return `[${this.data.join(", ")}]`}constructor(){this.data=new Float32Array(16),this.data[0]=this.data[5]=this.data[10]=this.data[15]=1;}}eY.IDENTITY=Object.freeze(new eY),eY.ZERO=Object.freeze(new eY().set([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]));class eq{clone(){return new this.constructor(this.x,this.y,this.z,this.w)}conjugate(e=this){return this.x=-1*e.x,this.y=-1*e.y,this.z=-1*e.z,this.w=e.w,this}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z+this.w*e.w}equals(e){return this.x===e.x&&this.y===e.y&&this.z===e.z&&this.w===e.w}equalsApprox(e,t=1e-6){return Math.abs(this.x-e.x)<t&&Math.abs(this.y-e.y)<t&&Math.abs(this.z-e.z)<t&&Math.abs(this.w-e.w)<t}getAxisAngle(e){let t=2*Math.acos(this.w),i=Math.sin(t/2);return 0!==i?(e.x=this.x/i,e.y=this.y/i,e.z=this.z/i,(e.x<0||e.y<0||e.z<0)&&(e.x*=-1,e.y*=-1,e.z*=-1,t*=-1)):(e.x=1,e.y=0,e.z=0),t*eP.RAD_TO_DEG}getEulerAngles(e=new eB){let t,i,s,r=this.x,a=this.y,n=this.z,o=this.w,l=2*(o*a-r*n);return l<=-0.99999?(t=2*Math.atan2(r,o),i=-Math.PI/2,s=0):l>=.99999?(t=2*Math.atan2(r,o),i=Math.PI/2,s=0):(t=Math.atan2(2*(o*r+a*n),1-2*(r*r+a*a)),i=Math.asin(l),s=Math.atan2(2*(o*n+r*a),1-2*(a*a+n*n))),e.set(t,i,s).mulScalar(eP.RAD_TO_DEG)}invert(e=this){return this.conjugate(e).normalize()}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}lerp(e,t,i){let s=(1-i)*(0>e.dot(t)?-1:1);return this.x=e.x*s+t.x*i,this.y=e.y*s+t.y*i,this.z=e.z*s+t.z*i,this.w=e.w*s+t.w*i,this.normalize()}mul(e){let t=this.x,i=this.y,s=this.z,r=this.w,a=e.x,n=e.y,o=e.z,l=e.w;return this.x=r*a+t*l+i*o-s*n,this.y=r*n+i*l+s*a-t*o,this.z=r*o+s*l+t*n-i*a,this.w=r*l-t*a-i*n-s*o,this}mulScalar(e,t=this){return this.x=t.x*e,this.y=t.y*e,this.z=t.z*e,this.w=t.w*e,this}mul2(e,t){let i=e.x,s=e.y,r=e.z,a=e.w,n=t.x,o=t.y,l=t.z,h=t.w;return this.x=a*n+i*h+s*l-r*o,this.y=a*o+s*h+r*n-i*l,this.z=a*l+r*h+i*o-s*n,this.w=a*h-i*n-s*o-r*l,this}normalize(e=this){let t=e.length();return 0===t?(this.x=this.y=this.z=0,this.w=1):(t=1/t,this.x=e.x*t,this.y=e.y*t,this.z=e.z*t,this.w=e.w*t),this}set(e,t,i,s){return this.x=e,this.y=t,this.z=i,this.w=s,this}setFromAxisAngle(e,t){let i=Math.sin(t*=.5*eP.DEG_TO_RAD),s=Math.cos(t);return this.x=i*e.x,this.y=i*e.y,this.z=i*e.z,this.w=s,this}setFromEulerAngles(e,t,i){if(e instanceof eB){let s=e;e=s.x,t=s.y,i=s.z;}let s=.5*eP.DEG_TO_RAD;e*=s,t*=s,i*=s;let r=Math.sin(e),a=Math.cos(e),n=Math.sin(t),o=Math.cos(t),l=Math.sin(i),h=Math.cos(i);return this.x=r*o*h-a*n*l,this.y=a*n*h+r*o*l,this.z=a*o*l-r*n*h,this.w=a*o*h+r*n*l,this}setFromMat4(e){let t,i=e.data,s=i[0],r=i[1],a=i[2],n=i[4],o=i[5],l=i[6],h=i[8],c=i[9],d=i[10];return (s*(o*d-l*c)-r*(n*d-l*h)+a*(n*c-o*h)<0&&(s=-s,r=-r,a=-a),0==(t=s*s+r*r+a*a)||(s*=t=1/Math.sqrt(t),r*=t,a*=t,0==(t=n*n+o*o+l*l)||(n*=t=1/Math.sqrt(t),o*=t,l*=t,0==(t=h*h+c*c+d*d))))?this.set(0,0,0,1):(h*=t=1/Math.sqrt(t),c*=t,(d*=t)<0?s>o?this.set(1+s-o-d,r+n,h+a,l-c):this.set(r+n,1-s+o-d,l+c,h-a):s<-o?this.set(h+a,l+c,1-s-o+d,r-n):this.set(l-c,h-a,r-n,1+s+o+d),this.mulScalar(1/this.length()))}setFromDirections(e,t){let i=1+e.dot(t);return i<Number.EPSILON?(Math.abs(e.x)>Math.abs(e.y)?(this.x=-e.z,this.y=0,this.z=e.x):(this.x=0,this.y=-e.z,this.z=e.y),this.w=0):(this.x=e.y*t.z-e.z*t.y,this.y=e.z*t.x-e.x*t.z,this.z=e.x*t.y-e.y*t.x,this.w=i),this.normalize()}slerp(e,t,i){let s=e.x,r=e.y,a=e.z,n=e.w,o=t.x,l=t.y,h=t.z,c=t.w,d=n*c+s*o+r*l+a*h;if(d<0&&(c=-c,o=-o,l=-l,h=-h,d=-d),Math.abs(d)>=1)return this.w=n,this.x=s,this.y=r,this.z=a,this;let u=Math.acos(d),f=Math.sqrt(1-d*d);if(.001>Math.abs(f))return this.w=.5*n+.5*c,this.x=.5*s+.5*o,this.y=.5*r+.5*l,this.z=.5*a+.5*h,this;let p=Math.sin((1-i)*u)/f,m=Math.sin(i*u)/f;return this.w=n*p+c*m,this.x=s*p+o*m,this.y=r*p+l*m,this.z=a*p+h*m,this}transformVector(e,t=new eB){let i=e.x,s=e.y,r=e.z,a=this.x,n=this.y,o=this.z,l=this.w,h=l*i+n*r-o*s,c=l*s+o*i-a*r,d=l*r+a*s-n*i,u=-a*i-n*s-o*r;return t.x=h*l+-(u*a)+-(c*o)- -(d*n),t.y=c*l+-(u*n)+-(d*a)- -(h*o),t.z=d*l+-(u*o)+-(h*n)- -(c*a),t}fromArray(e,t=0){return this.x=e[t]??this.x,this.y=e[t+1]??this.y,this.z=e[t+2]??this.z,this.w=e[t+3]??this.w,this}toString(){return `[${this.x}, ${this.y}, ${this.z}, ${this.w}]`}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,e[t+3]=this.w,e}constructor(e=0,t=0,i=0,s=1){4===e.length?(this.x=e[0],this.y=e[1],this.z=e[2],this.w=e[3]):(this.x=e,this.y=t,this.z=i,this.w=s);}}eq.IDENTITY=Object.freeze(new eq(0,0,0,1)),eq.ZERO=Object.freeze(new eq(0,0,0,0));let e$=new eB,ej=new eB,eK=new eB,eZ=new eB,eQ=new eB;class eJ{add(e){let t=this.center,i=t.x,s=t.y,r=t.z,a=this.halfExtents,n=a.x,o=a.y,l=a.z,h=i-n,c=i+n,d=s-o,u=s+o,f=r-l,p=r+l,m=e.center,_=m.x,g=m.y,v=m.z,S=e.halfExtents,y=S.x,x=S.y,T=S.z,E=_-y,w=_+y,b=g-x,A=g+x,C=v-T,P=v+T;E<h&&(h=E),w>c&&(c=w),b<d&&(d=b),A>u&&(u=A),C<f&&(f=C),P>p&&(p=P),t.x=(h+c)*.5,t.y=(d+u)*.5,t.z=(f+p)*.5,a.x=(c-h)*.5,a.y=(u-d)*.5,a.z=(p-f)*.5;}copy(e){this.center.copy(e.center),this.halfExtents.copy(e.halfExtents);}clone(){return new eJ(this.center,this.halfExtents)}intersects(e){let t=this.getMax(),i=this.getMin(),s=e.getMax(),r=e.getMin();return i.x<=s.x&&t.x>=r.x&&i.y<=s.y&&t.y>=r.y&&i.z<=s.z&&t.z>=r.z}_intersectsRay(e,t){let i=e$.copy(this.getMin()).sub(e.origin),s=ej.copy(this.getMax()).sub(e.origin),r=e.direction;0===r.x?(i.x=i.x<0?-Number.MAX_VALUE:Number.MAX_VALUE,s.x=s.x<0?-Number.MAX_VALUE:Number.MAX_VALUE):(i.x/=r.x,s.x/=r.x),0===r.y?(i.y=i.y<0?-Number.MAX_VALUE:Number.MAX_VALUE,s.y=s.y<0?-Number.MAX_VALUE:Number.MAX_VALUE):(i.y/=r.y,s.y/=r.y),0===r.z?(i.z=i.z<0?-Number.MAX_VALUE:Number.MAX_VALUE,s.z=s.z<0?-Number.MAX_VALUE:Number.MAX_VALUE):(i.z/=r.z,s.z/=r.z);let a=eK.set(Math.min(i.x,s.x),Math.min(i.y,s.y),Math.min(i.z,s.z)),n=eZ.set(Math.max(i.x,s.x),Math.max(i.y,s.y),Math.max(i.z,s.z)),o=Math.min(Math.min(n.x,n.y),n.z),l=Math.max(Math.max(a.x,a.y),a.z),h=o>=l&&l>=0;return h&&t.copy(e.direction).mulScalar(l).add(e.origin),h}_fastIntersectsRay(e){let t=e.direction;return e$.sub2(e.origin,this.center),eZ.set(Math.abs(e$.x),Math.abs(e$.y),Math.abs(e$.z)),eK.mul2(e$,t),(!(eZ.x>this.halfExtents.x)||!(eK.x>=0))&&(!(eZ.y>this.halfExtents.y)||!(eK.y>=0))&&(!(eZ.z>this.halfExtents.z)||!(eK.z>=0))&&(eQ.set(Math.abs(t.x),Math.abs(t.y),Math.abs(t.z)),ej.cross(t,e$),ej.set(Math.abs(ej.x),Math.abs(ej.y),Math.abs(ej.z)),!(ej.x>this.halfExtents.y*eQ.z+this.halfExtents.z*eQ.y)&&!(ej.y>this.halfExtents.x*eQ.z+this.halfExtents.z*eQ.x)&&!(ej.z>this.halfExtents.x*eQ.y+this.halfExtents.y*eQ.x))}intersectsRay(e,t){return t?this._intersectsRay(e,t):this._fastIntersectsRay(e)}setMinMax(e,t){this.center.add2(t,e).mulScalar(.5),this.halfExtents.sub2(t,e).mulScalar(.5);}getMin(){return this._min.copy(this.center).sub(this.halfExtents)}getMax(){return this._max.copy(this.center).add(this.halfExtents)}containsPoint(e){let t=this.center,i=this.halfExtents;return !(e.x<t.x-i.x)&&!(e.x>t.x+i.x)&&!(e.y<t.y-i.y)&&!(e.y>t.y+i.y)&&!(e.z<t.z-i.z)&&!(e.z>t.z+i.z)}closestPoint(e,t=new eB){let i=this.center,s=this.halfExtents;return t.set(Math.max(i.x-s.x,Math.min(e.x,i.x+s.x)),Math.max(i.y-s.y,Math.min(e.y,i.y+s.y)),Math.max(i.z-s.z,Math.min(e.z,i.z+s.z)))}setFromTransformedAabb(e,t,i=false){let s=e.center,r=e.halfExtents,a=t.data,n=a[0],o=a[4],l=a[8],h=a[1],c=a[5],d=a[9],u=a[2],f=a[6],p=a[10];if(i){let e=n*n+o*o+l*l;if(e>0){let t=1/Math.sqrt(e);n*=t,o*=t,l*=t;}if((e=h*h+c*c+d*d)>0){let t=1/Math.sqrt(e);h*=t,c*=t,d*=t;}if((e=u*u+f*f+p*p)>0){let t=1/Math.sqrt(e);u*=t,f*=t,p*=t;}}this.center.set(a[12]+n*s.x+o*s.y+l*s.z,a[13]+h*s.x+c*s.y+d*s.z,a[14]+u*s.x+f*s.y+p*s.z),this.halfExtents.set(Math.abs(n)*r.x+Math.abs(o)*r.y+Math.abs(l)*r.z,Math.abs(h)*r.x+Math.abs(c)*r.y+Math.abs(d)*r.z,Math.abs(u)*r.x+Math.abs(f)*r.y+Math.abs(p)*r.z);}static computeMinMax(e,t,i,s=e.length/3){if(s>0){let r=e[0],a=e[1],n=e[2],o=r,l=a,h=n,c=3*s;for(let t=3;t<c;t+=3){let i=e[t],s=e[t+1],c=e[t+2];i<r&&(r=i),s<a&&(a=s),c<n&&(n=c),i>o&&(o=i),s>l&&(l=s),c>h&&(h=c);}t.set(r,a,n),i.set(o,l,h);}}compute(e,t){eJ.computeMinMax(e,e$,ej,t),this.setMinMax(e$,ej);}intersectsBoundingSphere(e){return this._distanceToBoundingSphereSq(e)<=e.radius*e.radius}_distanceToBoundingSphereSq(e){let t=this.getMin(),i=this.getMax(),s=0,r=["x","y","z"];for(let a=0;a<3;++a){let n=0,o=e.center[r[a]],l=t[r[a]],h=i[r[a]],c=0;o<l&&(n+=(c=l-o)*c),o>h&&(n+=(c=o-h)*c),s+=n;}return s}_expand(e,t){e$.add2(this.getMin(),e),ej.add2(this.getMax(),t),this.setMinMax(e$,ej);}constructor(e,t){this.center=new eB,this.halfExtents=new eB(.5,.5,.5),this._min=new eB,this._max=new eB,e&&this.center.copy(e),t&&this.halfExtents.copy(t);}}let e0=new eB,e1=new eB;class e2{containsPoint(e){let t=e0.sub2(e,this.center).lengthSq(),i=this.radius;return t<i*i}intersectsRay(e,t){let i=e0.copy(e.origin).sub(this.center),s=i.dot(e1.copy(e.direction).normalize()),r=i.dot(i)-this.radius*this.radius;if(r>0&&s>0)return false;let a=s*s-r;if(a<0)return false;let n=Math.abs(-s-Math.sqrt(a));return t&&t.copy(e.direction).mulScalar(n).add(e.origin),true}intersectsBoundingSphere(e){e0.sub2(e.center,this.center);let t=e.radius+this.radius;return e0.lengthSq()<=t*t}constructor(e=new eB,t=.5){this.center=e,this.radius=t;}}class e3{clone(){return new this.constructor().copy(this)}copy(e){return this.normal.copy(e.normal),this.distance=e.distance,this}intersectsLine(e,t,i){let s=this.distance,r=this.normal.dot(e)+s,a=r/(r-(this.normal.dot(t)+s)),n=a>=0&&a<=1;return n&&i&&i.lerp(e,t,a),n}intersectsRay(e,t){let i=this.normal.dot(e.direction);if(0===i)return false;let s=-(this.normal.dot(e.origin)+this.distance)/i;return s>=0&&t&&t.copy(e.direction).mulScalar(s).add(e.origin),s>=0}normalize(){let e=1/this.normal.length();return this.normal.mulScalar(e),this.distance*=e,this}set(e,t,i,s){return this.normal.set(e,t,i),this.distance=s,this}setFromPointNormal(e,t){return this.normal.copy(t),this.distance=-this.normal.dot(e),this}constructor(e=eB.UP,t=0){this.normal=new eB,this.normal.copy(e),this.distance=t;}}class e4{clone(){return new this.constructor().copy(this)}copy(e){for(let t=0;t<6;t++)this.planes[t].copy(e.planes[t]);return this}setFromMat4(e){let[t,i,s,r,a,n,o,l,h,c,d,u,f,p,m,_]=e.data,g=this.planes;g[0].set(r-t,l-a,u-h,_-f).normalize(),g[1].set(r+t,l+a,u+h,_+f).normalize(),g[2].set(r+i,l+n,u+c,_+p).normalize(),g[3].set(r-i,l-n,u-c,_-p).normalize(),g[4].set(r-s,l-o,u-d,_-m).normalize(),g[5].set(r+s,l+o,u+d,_+m).normalize();}containsPoint(e){for(let t=0;t<6;t++){let{normal:i,distance:s}=this.planes[t];if(i.dot(e)+s<=0)return false}return true}add(e){let t=this.planes,i=e.planes;for(let e=0;e<6;e++)i[e].distance>t[e].distance&&t[e].copy(i[e]);return this}containsSphere(e){let{center:t,radius:i}=e,s=0;for(let e=0;e<6;e++){let{normal:r,distance:a}=this.planes[e],n=r.dot(t)+a;if(n<=-i)return 0;n>i&&s++;}return 6===s?2:1}constructor(){this.planes=[];for(let e=0;e<6;e++)this.planes[e]=new e3;}}class e5{set(e,t){return this.origin.copy(e),this.direction.copy(t),this}copy(e){return this.set(e.origin,e.direction)}clone(){return new this.constructor(this.origin,this.direction)}constructor(e,t){this.origin=new eB,this.direction=eB.FORWARD.clone(),e&&this.origin.copy(e),t&&this.direction.copy(t);}}let e8=new e5,e6=new eB,e9=new e2,e7=new eY;class te{set worldTransform(e){this._worldTransform.copy(e),this._modelTransform.copy(e).invert();}get worldTransform(){return this._worldTransform}intersectsRay(e,t){if(this._modelTransform.transformPoint(e.origin,e8.origin),this._modelTransform.transformVector(e.direction,e8.direction),t){let e=this._aabb._intersectsRay(e8,t);return e7.copy(this._modelTransform).invert().transformPoint(t,t),e}return this._aabb._fastIntersectsRay(e8)}containsPoint(e){return this._modelTransform.transformPoint(e,e6),this._aabb.containsPoint(e6)}intersectsBoundingSphere(e){return this._modelTransform.transformPoint(e.center,e9.center),e9.radius=e.radius,!!this._aabb.intersectsBoundingSphere(e9)}constructor(e=new eY,t){this.halfExtents=new eB(.5,.5,.5),t&&this.halfExtents.copy(t),this._modelTransform=e.clone().invert(),this._worldTransform=e.clone(),this._aabb=new eJ(new eB,this.halfExtents);}}let tt=new eB,ti=new eB,ts=new eB,tr=new eB,ta=new eB;class tn{set(e,t,i){return this.v0.copy(e),this.v1.copy(t),this.v2.copy(i),this}intersectsRay(e,t){tt.sub2(this.v1,this.v0),ti.sub2(this.v2,this.v0),ts.cross(e.direction,ti);let i=tt.dot(ts);if(i>-1e-6&&i<1e-6)return false;let s=1/i;tr.sub2(e.origin,this.v0);let r=s*tr.dot(ts);if(r<0||r>1)return false;ta.cross(tr,tt);let a=s*e.direction.dot(ta);if(a<0||r+a>1)return false;let n=s*ti.dot(ta);return n>1e-6&&(t instanceof eB&&t.copy(e.direction).mulScalar(n).add(e.origin),true)}toString(){return `[${this.v0.toString()}, ${this.v1.toString()}, ${this.v2.toString()}]`}constructor(e=eB.ZERO,t=eB.ZERO,i=eB.ZERO){this.v0=new eB,this.v1=new eB,this.v2=new eB,this.set(e,t,i);}}let to=0,tl=1,th=2,tc=0,td=1,tu=2,tf=3,tp=4,tm=5,t_=6,tg=7,tv=8,tS=9,ty=10,tx=11,tT=12,tE=0,tw=1,tb=2,tA=3,tC=4,tP=1,tI=2,tD=4,tR=8,tL=16,tM=32,tO=64,tF=128,tN=256,tB=0,tk=1,tU=2,tz=3,tV=1,tG=2,tH=4,tW=0,tX=1,tY=2,tq=3,t$=4,tj=5,tK=0,tZ=1,tQ=2,tJ=3,t0=0,t1=1,t2=2,t3=3,t4=4,t5=5,t8=0,t6=1,t9=2,t7=3,ie=4,it=5,ii=6,is=7,ir=0,ia=1,io=2,il=[1,2,4],ih=0,ic=1,id=2,iu=3,ip=4,im=5,i_=6,ig=7,iv=8,iS=9,iy=10,ix=11,iT=12,iE=13,iw=14,ib=15,iA=16,iC=17,iP=18,iI=19,iD=20,iR=21,iL=22,iM=23,iO=24,iF=25,iN=26,iB=27,ik=28,iU=29,iz=30,iV=31,iG=32,iH=33,iW=34,iX=35,iY=36,iq=37,i$=38,ij=39,iK=40,iZ=41,iQ=42,iJ=43,i0=44,i1=45,i2=46,i3=47,i4=48,i5=49,i8=50,i6=51,i9=52,i7=53,se=54,st=55,si=56,ss=61,sr=62,sa=63,sn=64,so=65,sl=66,sh=67,sc=68,sd=69,su=70,sf=71,sp=72,sm=73,s_=74,sg=75,sv=new Map([[ih,{name:"A8",size:1,ldr:true}],[i9,{name:"R8",size:1,ldr:true}],[ic,{name:"L8",size:1,ldr:true}],[id,{name:"LA8",size:2,ldr:true}],[i7,{name:"RG8",size:2,ldr:true}],[iu,{name:"RGB565",size:2,ldr:true}],[ip,{name:"RGBA5551",size:2,ldr:true}],[im,{name:"RGBA4",size:2,ldr:true}],[i_,{name:"RGB8",size:4,ldr:true}],[ig,{name:"RGBA8",size:4,ldr:true,srgbFormat:iD}],[i8,{name:"R16F",size:2}],[i6,{name:"RG16F",size:4}],[ix,{name:"RGB16F",size:8}],[iT,{name:"RGBA16F",size:8}],[iE,{name:"RGB32F",size:16}],[iw,{name:"RGBA32F",size:16}],[ib,{name:"R32F",size:4}],[su,{name:"RG32F",size:8}],[sf,{name:"RGB9E5",size:4}],[sp,{name:"RG8S",size:2}],[sm,{name:"RGBA8S",size:4}],[s_,{name:"RGB10A2",size:4}],[sg,{name:"RGB10A2U",size:4,isUint:true}],[iA,{name:"DEPTH",size:4}],[sd,{name:"DEPTH16",size:2}],[iC,{name:"DEPTHSTENCIL",size:4}],[iP,{name:"111110F",size:4}],[iI,{name:"SRGB8",size:4,ldr:true,srgb:true}],[iD,{name:"SRGBA8",size:4,ldr:true,srgb:true}],[iV,{name:"BGRA8",size:4,ldr:true}],[sn,{name:"SBGRA8",size:4,ldr:true,srgb:true}],[iv,{name:"DXT1",blockSize:8,ldr:true,srgbFormat:se}],[iS,{name:"DXT3",blockSize:16,ldr:true,srgbFormat:st}],[iy,{name:"DXT5",blockSize:16,ldr:true,srgbFormat:si}],[iR,{name:"ETC1",blockSize:8,ldr:true}],[iL,{name:"ETC2_RGB",blockSize:8,ldr:true,srgbFormat:ss}],[iM,{name:"ETC2_RGBA",blockSize:16,ldr:true,srgbFormat:sr}],[iO,{name:"PVRTC_2BPP_RGB_1",ldr:true,blockSize:8}],[iF,{name:"PVRTC_2BPP_RGBA_1",ldr:true,blockSize:8}],[iN,{name:"PVRTC_4BPP_RGB_1",ldr:true,blockSize:8}],[iB,{name:"PVRTC_4BPP_RGBA_1",ldr:true,blockSize:8}],[ik,{name:"ASTC_4x4",blockSize:16,ldr:true,srgbFormat:sa}],[iU,{name:"ATC_RGB",blockSize:8,ldr:true}],[iz,{name:"ATC_RGBA",blockSize:16,ldr:true}],[so,{name:"BC6H_RGBF",blockSize:16}],[sl,{name:"BC6H_RGBUF",blockSize:16}],[sh,{name:"BC7_RGBA",blockSize:16,ldr:true,srgbFormat:sc}],[se,{name:"DXT1_SRGB",blockSize:8,ldr:true,srgb:true}],[st,{name:"DXT3_SRGBA",blockSize:16,ldr:true,srgb:true}],[si,{name:"DXT5_SRGBA",blockSize:16,ldr:true,srgb:true}],[ss,{name:"ETC2_SRGB",blockSize:8,ldr:true,srgb:true}],[sr,{name:"ETC2_SRGBA",blockSize:16,ldr:true,srgb:true}],[sa,{name:"ASTC_4x4_SRGB",blockSize:16,ldr:true,srgb:true}],[sc,{name:"BC7_SRGBA",blockSize:16,ldr:true,srgb:true}],[iG,{name:"R8I",size:1,isInt:true}],[iW,{name:"R16I",size:2,isInt:true}],[iY,{name:"R32I",size:4,isInt:true}],[i$,{name:"RG8I",size:2,isInt:true}],[iK,{name:"RG16I",size:4,isInt:true}],[iQ,{name:"RG32I",size:8,isInt:true}],[i0,{name:"RGBA8I",size:4,isInt:true}],[i2,{name:"RGBA16I",size:8,isInt:true}],[i4,{name:"RGBA32I",size:16,isInt:true}],[iH,{name:"R8U",size:1,isUint:true}],[iX,{name:"R16U",size:2,isUint:true}],[iq,{name:"R32U",size:4,isUint:true}],[ij,{name:"RG8U",size:2,isUint:true}],[iZ,{name:"RG16U",size:4,isUint:true}],[iJ,{name:"RG32U",size:8,isUint:true}],[i1,{name:"RGBA8U",size:4,isUint:true}],[i3,{name:"RGBA16U",size:8,isUint:true}],[i5,{name:"RGBA32U",size:16,isUint:true}]]),sS=e=>sv.get(e)?.blockSize!==void 0,sy=e=>sv.get(e)?.srgb===true,sx=e=>{let t=sv.get(e);return t?.isInt===true||t?.isUint===true},sT={sampler:"sampler2D",returnType:"vec4"},sE={sampler:"usampler2D",returnType:"uvec4"},sw={sampler:"isampler2D",returnType:"ivec4"},sb={textureType:"texture_2d<f32>",returnType:"vec4f"},sA={textureType:"texture_2d<u32>",returnType:"vec4u"},sC={textureType:"texture_2d<i32>",returnType:"vec4i"},sP=e=>{let t=sv.get(e);return t?.isUint?sE:t?.isInt?sw:sT},sI=e=>{let t=sv.get(e);return t?.isUint?sA:t?.isInt?sC:sb},sD=e=>sv.get(e)?.srgbFormat||e,sR=e=>{for(let[t,i]of sv)if(i.srgbFormat===e)return t;return e},sL=e=>{let t=sv.get(e);return !!(t?.ldr&&!t?.srgb)},sM=e=>{switch(e){case ib:case su:case iE:case iw:return Float32Array;case iY:case iQ:case i4:return Int32Array;case iq:case iJ:case i5:case sf:case s_:case sg:return Uint32Array;case iW:case iK:case i2:return Int16Array;case iX:case iZ:case i3:case iu:case ip:case im:case i8:case i6:case ix:case iT:return Uint16Array;case iG:case i$:case i0:case sp:case sm:return Int8Array;default:return Uint8Array}},sO=0,sF=1,sN=2,sB=3,sk=4,sU=5,sz=6,sV="POSITION",sG="NORMAL",sH="TANGENT",sW="BLENDWEIGHT",sX="BLENDINDICES",sY="COLOR",sq="TEXCOORD",s$="TEXCOORD0",sj="TEXCOORD1",sK="TEXCOORD2",sZ="TEXCOORD3",sQ="TEXCOORD4",sJ="TEXCOORD5",s0="TEXCOORD6",s1="TEXCOORD7",s2="ATTR0",s3="ATTR1",s4="ATTR2",s5="ATTR3",s8="ATTR4",s6="ATTR5",s9="ATTR6",s7="ATTR7",re="ATTR8",rt="ATTR9",ri="ATTR10",rs="ATTR11",rr="ATTR12",ra="ATTR13",rn="ATTR14",ro="ATTR15",rl=1,rh=0,rc=1,rd=2,ru=3,rf=4,rp=5,rm=6,r_=7,rg=0,rv=1,rS=2,ry="default",rx="rgbm",rT="rgbe",rE="rgbp",rw="swizzleGGGR",rb=0,rA=1,rC=2,rP=3,rI="1d",rD="2d",rR="2d-array",rL="cube",rM="cube-array",rO="3d",rF=0,rN=1,rB=2,rk=3,rU=4,rz="none",rV="cube",rG="equirect",rH="octahedral",rW="glsl",rX="wgsl",rY=0,rq=1,r$=2,rj=3,rK=4,rZ=5,rQ=6,rJ=7,r0=0,r1=1,r2=2,r3=3,r4=4,r5=5,r8=6,r6=7,r9=8,r7=9,ae=10,at=11,ai=12,as=13,ar=14,aa=15,an=16,ao=17,al=18,ah=19,ac=20,ad=21,au=22,af=23,ap=24,am=25,a_=26,ag=27,av=28,aS=29,ay=30,ax=31,aT=32,aE=33,aw=34,ab=35,aA=36,aC=37,aP=38,aI=39,aD=40,aR=41,aL=42,aM=43,aO=44,aF=45,aN=46,aB=47,ak=48,aU=49,az=["bool","int","float","vec2","vec3","vec4","ivec2","ivec3","ivec4","bvec2","bvec3","bvec4","mat2","mat3","mat4","sampler2D","samplerCube","","sampler2DShadow","samplerCubeShadow","sampler3D","","","","","sampler2DArray","uint","uvec2","uvec3","uvec4","","","","","","","","","","","","","isampler2D","usampler2D","isamplerCube","usamplerCube","isampler3D","usampler3D","isampler2DArray","usampler2DArray"],aV=[["bool"],["i32"],["f32"],["vec2f","vec2<f32>"],["vec3f","vec3<f32>"],["vec4f","vec4<f32>"],["vec2i","vec2<i32>"],["vec3i","vec3<i32>"],["vec4i","vec4<i32>"],["vec2<bool>"],["vec3<bool>"],["vec4<bool>"],["mat2x2f","mat2x2<f32>"],["mat3x3f","mat3x3<f32>"],["mat4x4f","mat4x4<f32>"],["texture_2d<f32>"],["texture_cube<f32>"],["array<f32>"],["texture_depth_2d"],["texture_depth_cube"],["texture_3d<f32>"],["array<vec2<f32>>"],["array<vec3<f32>>"],["array<vec4<f32>>"],["array<mat4x4<f32>>"],["texture_2d_array<f32>"],["u32"],["vec2u","vec2<u32>"],["vec3u","vec3<u32>"],["vec4u","vec4<u32>"],["array<i32>"],["array<u32>"],["array<bool>"],["array<vec2i>","array<vec2<i32>>"],["array<vec2u>","array<vec2<u32>>"],["array<vec2b>","array<vec2<bool>>"],["array<vec3i>","array<vec3<i32>>"],["array<vec3u>","array<vec3<u32>>"],["array<vec3b>","array<vec3<bool>>"],["array<vec4i>","array<vec4<i32>>"],["array<vec4u>","array<vec4<u32>>"],["array<vec4b>","array<vec4<bool>>"],["texture_2d<i32>"],["texture_2d<u32>"],["texture_cube<i32>"],["texture_cube<u32>"],["texture_3d<i32>"],["texture_3d<u32>"],["texture_2d_array<i32>"],["texture_2d_array<u32>"]],aG=new Map;aV.forEach((e,t)=>{e.forEach(e=>aG.set(e,t));});let aH=new Uint8Array([rK,rK,rQ,rQ,rQ,rQ,rK,rK,rK,rK,rK,rK,rQ,rQ,rQ,rK,rK,rQ,rK,rK,rK,rQ,rQ,rQ,rQ,rK,rZ,rZ,rZ,rZ,rK,rZ,rK,rK,rZ,rK,rK,rZ,rK,rK,rZ,rK,rK,rZ,rK,rZ,rK,rZ,rK,rZ]),aW="webgl2",aX="webgpu",aY="null",aq=1,a$=2,aj=4,aK="ldr",aZ="ldr_srgb",aQ="hdr",aJ=1,a0=2,a1=4,a2=8,a3=16,a4=32,a5=64,a8=128,a6=255,a9=0,a7=1,ne=2,nt=["view","mesh","mesh_ub"],ni="default",ns="_unused_float_uniform",nr=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Uint16Array],na=[1,1,2,2,4,4,4,2],nn=["INT8","UINT8","INT16","UINT16","INT32","UINT32","FLOAT32","FLOAT16"],no={Int8Array:rY,Uint8Array:rq,Int16Array:r$,Uint16Array:rj,Int32Array:rK,Uint32Array:rZ,Float32Array:rQ},nl=[Uint8Array,Uint16Array,Uint32Array],nh=[1,2,4],nc=new Map([["float","f32"],["vec2","vec2f"],["vec3","vec3f"],["vec4","vec4f"],["int","i32"],["ivec2","vec2i"],["ivec3","vec3i"],["ivec4","vec4i"],["uint","u32"],["uvec2","vec2u"],["uvec3","vec3u"],["uvec4","vec4u"]]),nd={};nd[sV]=0,nd[sG]=1,nd[sW]=2,nd[sX]=3,nd[sY]=4,nd[s$]=5,nd[sj]=6,nd[sK]=7,nd[sZ]=8,nd[sQ]=9,nd[sJ]=10,nd[s0]=11,nd[s1]=12,nd[sH]=13,nd[s2]=0,nd[s3]=1,nd[s4]=2,nd[s5]=3,nd[s8]=4,nd[s6]=5,nd[s9]=6,nd[s7]=7,nd[re]=8,nd[rt]=9,nd[ri]=10,nd[rs]=11,nd[rr]=12,nd[ra]=13,nd[rn]=14,nd[ro]=15;let nu=0;class nf{constructor(e,t){this.slot=-1,this.scopeId=null,this.name=e,this.visibility=t;}}class np extends nf{}class nm extends nf{constructor(e,t,i=false){super(e,t),this.format="",this.readOnly=i;}}class n_ extends nf{constructor(e,t,i=rD,s=rF,r=true,a=null){super(e,t),this.textureDimension=i,this.sampleType=s,this.hasSampler=r,this.samplerName=a??`${e}_sampler`;}}class ng extends nf{constructor(e,t=ig,i=rD,s=true,r=false){super(e,aj),this.format=t,this.textureDimension=i,this.write=s,this.read=r;}}class nv{destroy(){this.impl.destroy();}getTexture(e){let t=this.textureFormatsMap.get(e);return void 0!==t?this.textureFormats[t]:null}getStorageTexture(e){let t=this.storageTextureFormatsMap.get(e);return void 0!==t?this.storageTextureFormats[t]:null}loseContext(){}constructor(e,t){this.uniformBufferFormats=[],this.textureFormats=[],this.storageTextureFormats=[],this.storageBufferFormats=[],this.id=nu++;let i=0;t.forEach(e=>{e.slot=i++,e instanceof n_&&e.hasSampler&&i++,e instanceof np?this.uniformBufferFormats.push(e):e instanceof n_?this.textureFormats.push(e):e instanceof ng?this.storageTextureFormats.push(e):e instanceof nm&&this.storageBufferFormats.push(e);}),this.device=e;let s=e.scope;this.bufferFormatsMap=new Map,this.uniformBufferFormats.forEach((e,t)=>this.bufferFormatsMap.set(e.name,t)),this.textureFormatsMap=new Map,this.textureFormats.forEach((e,t)=>{this.textureFormatsMap.set(e.name,t),e.scopeId=s.resolve(e.name);}),this.storageTextureFormatsMap=new Map,this.storageTextureFormats.forEach((e,t)=>{this.storageTextureFormatsMap.set(e.name,t),e.scopeId=s.resolve(e.name);}),this.storageBufferFormatsMap=new Map,this.storageBufferFormats.forEach((e,t)=>{this.storageBufferFormatsMap.set(e.name,t),e.scopeId=s.resolve(e.name);}),this.impl=e.createBindGroupFormatImpl(this);}}class nS{get(e,t){return this._cache.has(e)||(this._cache.set(e,t()),e.on("destroy",()=>{this.remove(e);}),e.on("devicelost",()=>{this._cache.get(e)?.loseContext?.(e);})),this._cache.get(e)}remove(e){this._cache.get(e)?.destroy?.(e),this._cache.delete(e);}constructor(){this._cache=new Map;}}class ny{static calcLevelDimension(e,t){return Math.max(e>>t,1)}static calcMipLevelsCount(e,t,i=1){return 1+Math.floor(Math.log2(Math.max(e,t,i)))}static calcLevelGpuSize(e,t,i,s){let r=sv.get(s),a=sv.get(s)?.size??0;if(a>0)return e*t*i*a;let n=r.blockSize??0,o=Math.floor((e+3)/4),l=Math.floor((t+3)/4),h=Math.floor((i+3)/4);return (s===iO||s===iF)&&(o=Math.max(Math.floor(o/2),1)),o*l*h*n}static calcGpuSize(e,t,i,s,r,a){let n=0;for(;n+=ny.calcLevelGpuSize(e,t,i,s),r&&(1!==e||1!==t||1!==i);)e=Math.max(e>>1,1),t=Math.max(t>>1,1),i=Math.max(i>>1,1);return n*(a?6:1)}}class nx{get(e){let t=this.map.get(e);return void 0===t&&(t=this.id++,this.map.set(e,t)),t}constructor(){this.map=new Map,this.id=0;}}let nT=new nx;class nE{constructor(e,t=0,i=1,s=0,r=1){this.texture=e,this.baseMipLevel=t,this.mipLevelCount=i,this.baseArrayLayer=s,this.arrayLayerCount=r,this.key=nT.get(`${t}:${i}:${s}:${r}`);}}let nw=0;class nb{destroy(){let e=this.device;e&&(e.onTextureDestroyed(this),this.impl.destroy(e),this.adjustVramSizeTracking(e._vram,-this._gpuSize),this._levels=null,this.device=null);}recreateImpl(e=true){let{device:t}=this;this.impl?.destroy(t),this.impl=null,this.impl=t.createTextureImpl(this),this.dirtyAll(),e&&this.upload();}_clearLevels(){this._levels=this._cubemap?[[null,null,null,null,null,null]]:[null];}resize(e,t,i=1){if(this.width!==e||this.height!==t||this.depth!==i){let s=this.device;this.adjustVramSizeTracking(s._vram,-this._gpuSize),this._gpuSize=0,this.impl.destroy(s),this._clearLevels(),this._width=Math.floor(e),this._height=Math.floor(t),this._depth=Math.floor(i),this._updateNumLevel(),this.impl=s.createTextureImpl(this),this.dirtyAll();}}loseContext(){this.impl.loseContext(),this.dirtyAll();}adjustVramSizeTracking(e,t){e.tex+=t;}propertyChanged(e){this.impl.propertyChanged(e),this.renderVersionDirty=this.device.renderVersion;}_updateNumLevel(){let e=this.mipmaps?ny.calcMipLevelsCount(this.width,this.height):1,t=this._numLevelsRequested;this._numLevels=Math.min(t??e,e),this._mipmaps=this._numLevels>1;}get lockedMode(){return this._lockedMode}set minFilter(e){this._minFilter!==e&&(sx(this._format)||(this._minFilter=e,this.propertyChanged(aJ)));}get minFilter(){return this._minFilter}set magFilter(e){this._magFilter!==e&&(sx(this._format)||(this._magFilter=e,this.propertyChanged(a0)));}get magFilter(){return this._magFilter}set addressU(e){this._addressU!==e&&(this._addressU=e,this.propertyChanged(a1));}get addressU(){return this._addressU}set addressV(e){this._addressV!==e&&(this._addressV=e,this.propertyChanged(a2));}get addressV(){return this._addressV}set addressW(e){this._volume&&e!==this._addressW&&(this._addressW=e,this.propertyChanged(a3));}get addressW(){return this._addressW}set compareOnRead(e){this._compareOnRead!==e&&(this._compareOnRead=e,this.propertyChanged(a4));}get compareOnRead(){return this._compareOnRead}set compareFunc(e){this._compareFunc!==e&&(this._compareFunc=e,this.propertyChanged(a5));}get compareFunc(){return this._compareFunc}set anisotropy(e){this._anisotropy!==e&&(this._anisotropy=e,this.propertyChanged(a8));}get anisotropy(){return this._anisotropy}set mipmaps(e){this._mipmaps!==e&&(this.device.isWebGPU||sx(this._format)||(this._mipmaps=e),e&&(this._needsMipmapsUpload=true,this.device?.texturesToUpload?.add(this)));}get mipmaps(){return this._mipmaps}get numLevels(){return this._numLevels}get storage(){return this._storage}get width(){return this._width}get height(){return this._height}get depth(){return this._depth}get format(){return this._format}get cubemap(){return this._cubemap}get gpuSize(){let e=this.pot&&this._mipmaps&&!(this._compressed&&1===this._levels.length);return ny.calcGpuSize(this._width,this._height,this._depth,this._format,e,this._cubemap)}get array(){return this._arrayLength>0}get arrayLength(){return this._arrayLength}get volume(){return this._volume}set type(e){this._type!==e&&(this._type=e,this.device._shadersDirty=true);}get type(){return this._type}set srgb(e){if(e!==sy(this.format))if(e){let e=sD(this.format);this._format!==e&&(this._format=e,this.recreateImpl(),this.device._shadersDirty=true);}else {let e=sR(this.format);this._format!==e&&(this._format=e,this.recreateImpl(),this.device._shadersDirty=true);}}get srgb(){return sy(this.format)}set flipY(e){this._flipY!==e&&(this._flipY=e,this.markForUpload());}get flipY(){return this._flipY}set premultiplyAlpha(e){this._premultiplyAlpha!==e&&(this._premultiplyAlpha=e,this.markForUpload());}get premultiplyAlpha(){return this._premultiplyAlpha}get pot(){return eP.powerOfTwo(this._width)&&eP.powerOfTwo(this._height)}get encoding(){switch(this.type){case rx:return "rgbm";case rT:return "rgbe";case rE:return "rgbp"}return sL(this.format)?"srgb":"linear"}dirtyAll(){this._levelsUpdated=this._cubemap?[[true,true,true,true,true,true]]:[true],this.markForUpload(),this._needsMipmapsUpload=this._mipmaps,this._mipmapsUploaded=false,this.propertyChanged(a6);}lock(e={}){e.level??(e.level=0),e.face??(e.face=0),e.mode??(e.mode=rS),this._lockedMode=e.mode,this._lockedLevel=e.level;let t=this.cubemap?this._levels[e.face]:this._levels;if(null===t[e.level]){let i=Math.max(1,this._width>>e.level),s=Math.max(1,this._height>>e.level),r=Math.max(1,this._depth>>e.level),a=new ArrayBuffer(ny.calcLevelGpuSize(i,s,r,this._format));t[e.level]=new(sM(this._format))(a);}return t[e.level]}setSource(e,t=0){let i,s,r=false;if(this._cubemap){if(e[0]){i=e[0].width||0,s=e[0].height||0;for(let t=0;t<6;t++){let a=e[t];if(!a||a.width!==i||a.height!==s||!this.device._isBrowserInterface(a)){r=true;break}}}else r=true;if(!r)for(let i=0;i<6;i++)this._levels[t][i]!==e[i]&&(this._levelsUpdated[t][i]=true);}else this.device._isBrowserInterface(e)||(r=true),r||(e!==this._levels[t]&&(this._levelsUpdated[t]=true),e instanceof HTMLVideoElement?(i=e.videoWidth,s=e.videoHeight):(i=e.width,s=e.height));if(r)if(this._width=4,this._height=4,this._cubemap)for(let e=0;e<6;e++)this._levels[t][e]=null,this._levelsUpdated[t][e]=true;else this._levels[t]=null,this._levelsUpdated[t]=true;else 0===t&&(this._width=i,this._height=s),this._levels[t]=e;this._invalid===r&&r||(this._invalid=r,this.upload());}getSource(e=0){return this._levels[e]}unlock(){this._lockedMode,this._lockedMode===rS&&this.upload(),this._lockedLevel=-1,this._lockedMode=rg;}markForUpload(){this._needsUpload=true,this.device?.texturesToUpload?.add(this);}upload(){this.markForUpload(),this._needsMipmapsUpload=this._mipmaps,this.impl.uploadImmediate?.(this.device,this);}read(e,t,i,s,r={}){return this.impl.read?.(e,t,i,s,r)}write(e,t,i,s,r){return this.impl.write?.(e,t,i,s,r)}getView(e=0,t=1,i=0,s=1){return new nE(this,e,t,i,s)}constructor(e,t={}){this._gpuSize=0,this.id=nw++,this._invalid=false,this._lockedLevel=-1,this._lockedMode=rg,this.renderVersionDirty=0,this._storage=false,this._numLevels=0,this.device=e,this.name=t.name??"",this._width=Math.floor(t.width??4),this._height=Math.floor(t.height??4),this._format=t.format??ig,this._compressed=sS(this._format),this._integerFormat=sx(this._format),this._integerFormat&&(t.minFilter=t0,t.magFilter=t0),this._volume=t.volume??false,this._depth=Math.floor(t.depth??1),this._arrayLength=Math.floor(t.arrayLength??0),this._storage=t.storage??false,this._cubemap=t.cubemap??false,this._flipY=t.flipY??false,this._premultiplyAlpha=t.premultiplyAlpha??false,this._mipmaps=t.mipmaps??true,this._numLevelsRequested=t.numLevels,void 0!==t.numLevels&&(this._numLevels=t.numLevels),this._updateNumLevel(),this._minFilter=t.minFilter??t5,this._magFilter=t.magFilter??t1,this._anisotropy=t.anisotropy??1,this._addressU=t.addressU??to,this._addressV=t.addressV??to,this._addressW=t.addressW??to,this._compareOnRead=t.compareOnRead??false,this._compareFunc=t.compareFunc??t6,this._type=t.type??ry,this.projection=rz,this._cubemap?this.projection=rV:t.projection&&t.projection!==rV&&(this.projection=t.projection),this._levels=t.levels;let i=!!t.levels;this._levels||this._clearLevels(),this.recreateImpl(i);}}let nA={white:[255,255,255,255],gray:[128,128,128,255],black:[0,0,0,255],normal:[128,128,255,255],pink:[255,128,255,255]};class nC{destroy(){this.map.forEach(e=>{e.destroy();});}constructor(){this.map=new Map;}}let nP=new nS,nI=(e,t)=>{let i=nP.get(e,()=>new nC);if(!i.map.has(t)){let s=new nb(e,{name:`built-in-texture-${t}`,width:1,height:1,format:ig}),r=s.lock(),a=nA[t];r.set(a),s.unlock(),i.map.set(t,s);}return i.map.get(t)},nD=0;class nR{constructor(){this.offsets=[];}}class nL{destroy(){this.impl.destroy(),this.impl=null,this.format=null,this.defaultUniformBuffer=null;}setUniformBuffer(e,t){let i=this.format.bufferFormatsMap.get(e);this.uniformBuffers[i]!==t&&(this.uniformBuffers[i]=t,this.dirty=true);}setStorageBuffer(e,t){let i=this.format.storageBufferFormatsMap.get(e);this.storageBuffers[i]!==t&&(this.storageBuffers[i]=t,this.dirty=true);}setTexture(e,t){let i=this.format.textureFormatsMap.get(e),s=t instanceof nE?t.texture:t;this.textures[i]!==t?(this.textures[i]=t,this.dirty=true):this.renderVersionUpdated<s.renderVersionDirty&&(this.dirty=true);}setStorageTexture(e,t){let i=this.format.storageTextureFormatsMap.get(e),s=t instanceof nE?t.texture:t;this.storageTextures[i]!==t?(this.storageTextures[i]=t,this.dirty=true):this.renderVersionUpdated<s.renderVersionDirty&&(this.dirty=true);}updateUniformBuffers(){for(let e=0;e<this.uniformBuffers.length;e++)this.uniformBuffers[e].update();}update(){let{textureFormats:e,storageTextureFormats:t,storageBufferFormats:i}=this.format;for(let t=0;t<e.length;t++){let i=e[t],s=i.scopeId.value;!s&&("uSceneDepthMap"===i.name&&(s=nI(this.device,"white")),"uSceneColorMap"===i.name&&(s=nI(this.device,"pink")),s||(s=nI(this.device,"pink"))),this.setTexture(i.name,s);}for(let e=0;e<t.length;e++){let i=t[e],s=i.scopeId.value;this.setStorageTexture(i.name,s);}for(let e=0;e<i.length;e++){let t=i[e],s=t.scopeId.value;this.setStorageBuffer(t.name,s);}this.uniformBufferOffsets.length=this.uniformBuffers.length;for(let e=0;e<this.uniformBuffers.length;e++){let t=this.uniformBuffers[e];this.uniformBufferOffsets[e]=t.offset,this.renderVersionUpdated<t.renderVersionDirty&&(this.dirty=true);}this.dirty&&(this.dirty=false,this.renderVersionUpdated=this.device.renderVersion,this.impl.update(this));}constructor(e,t,i){this.renderVersionUpdated=-1,this.uniformBufferOffsets=[],this.id=nD++,this.device=e,this.format=t,this.dirty=true,this.impl=e.createBindGroupImpl(this),this.textures=[],this.storageTextures=[],this.storageBuffers=[],this.uniformBuffers=[],this.defaultUniformBuffer=i,i&&this.setUniformBuffer(ni,i);}}let nM={set:(e,t,i,s=1)=>e&~(s<<i)|t<<i,get:(e,t,i=1)=>e>>t&i,all(e,t,i=1){let s=i<<t;return (e&s)===s},any:(e,t,i=1)=>(e&i<<t)!=0};class nO{set blend(e){this.target0=nM.set(this.target0,+!!e,26);}get blend(){return nM.all(this.target0,26)}setColorBlend(e,t,i){this.target0=nM.set(this.target0,e,0,7),this.target0=nM.set(this.target0,t,3,15),this.target0=nM.set(this.target0,i,7,15);}setAlphaBlend(e,t,i){this.target0=nM.set(this.target0,e,11,7),this.target0=nM.set(this.target0,t,14,15),this.target0=nM.set(this.target0,i,18,15);}setColorWrite(e,t,i,s){this.redWrite=e,this.greenWrite=t,this.blueWrite=i,this.alphaWrite=s;}get colorOp(){return nM.get(this.target0,0,7)}get colorSrcFactor(){return nM.get(this.target0,3,15)}get colorDstFactor(){return nM.get(this.target0,7,15)}get alphaOp(){return nM.get(this.target0,11,7)}get alphaSrcFactor(){return nM.get(this.target0,14,15)}get alphaDstFactor(){return nM.get(this.target0,18,15)}set redWrite(e){this.target0=nM.set(this.target0,+!!e,22);}get redWrite(){return nM.all(this.target0,22)}set greenWrite(e){this.target0=nM.set(this.target0,+!!e,23);}get greenWrite(){return nM.all(this.target0,23)}set blueWrite(e){this.target0=nM.set(this.target0,+!!e,24);}get blueWrite(){return nM.all(this.target0,24)}set alphaWrite(e){this.target0=nM.set(this.target0,+!!e,25);}get alphaWrite(){return nM.all(this.target0,25)}get allWrite(){return nM.get(this.target0,22,15)}copy(e){return this.target0=e.target0,this}clone(){return new this.constructor().copy(this)}get key(){return this.target0}equals(e){return this.target0===e.target0}constructor(e=false,t=tE,i=td,s=tc,r,a,n,o=true,l=true,h=true,c=true){this.target0=0,this.setColorBlend(t,i,s),this.setAlphaBlend(r??t,a??i,n??s),this.setColorWrite(o,l,h,c),this.blend=e;}}nO.NOBLEND=Object.freeze(new nO),nO.NOWRITE=Object.freeze(new nO(void 0,void 0,void 0,void 0,void 0,void 0,void 0,false,false,false,false)),nO.ALPHABLEND=Object.freeze(new nO(true,tE,t_,tv)),nO.ADDBLEND=Object.freeze(new nO(true,tE,td,td));let nF=new nx;class nN{set test(e){this.func=e?t7:is,this.updateKey();}get test(){return this.func!==is}set write(e){this.data=nM.set(this.data,+!!e,3),this.updateKey();}get write(){return nM.all(this.data,3)}set func(e){this.data=nM.set(this.data,e,0,7),this.updateKey();}get func(){return nM.get(this.data,0,7)}set depthBias(e){this._depthBias=e,this.updateKey();}get depthBias(){return this._depthBias}set depthBiasSlope(e){this._depthBiasSlope=e,this.updateKey();}get depthBiasSlope(){return this._depthBiasSlope}copy(e){return this.data=e.data,this._depthBias=e._depthBias,this._depthBiasSlope=e._depthBiasSlope,this.key=e.key,this}clone(){return new this.constructor().copy(this)}updateKey(){let{data:e,_depthBias:t,_depthBiasSlope:i}=this,s=`${e}-${t}-${i}`;this.key=nF.get(s);}equals(e){return this.key===e.key}constructor(e=t7,t=true){this.data=0,this._depthBias=0,this._depthBiasSlope=0,this.key=0,this.func=e,this.write=t;}}nN.DEFAULT=Object.freeze(new nN),nN.NODEPTH=Object.freeze(new nN(is,false)),nN.WRITEDEPTH=Object.freeze(new nN(is,true));class nB{equals(e){return this.globalId===e.globalId&&this.revision===e.revision}copy(e){this.globalId=e.globalId,this.revision=e.revision;}reset(){this.globalId=0,this.revision=0;}constructor(){this.globalId=0,this.revision=0;}}let nk=0;class nU{increment(){this.version.revision++;}constructor(){nk++,this.version=new nB,this.version.globalId=nk;}}class nz{toJSON(e){}setValue(e){this.value=e,this.versionObject.increment();}getValue(){return this.value}constructor(e){this.name=e,this.value=null,this.versionObject=new nU;}}class nV{resolve(e){return this.variables.has(e)||this.variables.set(e,new nz(e)),this.variables.get(e)}removeValue(e){for(let t of this.variables.values())t.value===e&&(t.value=null);}constructor(e){this.name=e,this.variables=new Map;}}let nG=0;class nH{destroy(){let e=this.device;e.buffers.delete(this),this.impl.initialized&&(this.impl.destroy(e),this.adjustVramSizeTracking(e._vram,-this.storage.byteLength));}adjustVramSizeTracking(e,t){e.vb+=t;}loseContext(){this.impl.loseContext();}getFormat(){return this.format}getUsage(){return this.usage}getNumVertices(){return this.numVertices}lock(){return this.storage}unlock(){this.impl.unlock(this);}setData(e){return e.byteLength===this.numBytes&&(this.storage=e,this.unlock(),true)}constructor(e,t,i,s){this.usage=tB,this.usage=s?.usage??tB,this.device=e,this.format=t,this.numVertices=i,this.id=nG++,this.impl=e.createVertexBufferImpl(this,t,s),this.numBytes=t.verticesByteSize?t.verticesByteSize:t.size*i,this.adjustVramSizeTracking(e._vram,this.numBytes);let r=s?.data;r?this.setData(r):this.storage=new ArrayBuffer(this.numBytes),this.device.buffers.add(this);}}function nW(e){if(null==e)return 0;let t=0;for(let i=0,s=e.length;i<s;i++)t=(t<<5)-t+e.charCodeAt(i)|0;return t}function nX(e){let t=0x811c9dc5;for(let i=0;i<e.length;i++)t^=e[i],t*=0x1000193;return t>>>0}let nY=new nx,nq=[2,4,8,12,16],n$=new nS;class nj{get elements(){return this._elements}static getDefaultInstancingFormat(e){return n$.get(e,()=>new nj(e,[{semantic:rs,components:4,type:rQ},{semantic:rr,components:4,type:rQ},{semantic:rn,components:4,type:rQ},{semantic:ro,components:4,type:rQ}]))}static isElementValid(e,t){let i=t.components*na[t.type];return !e.isWebGPU||!!nq.includes(i)}update(){this._evaluateHash();}_evaluateHash(){let e=[],t=[],i=this._elements.length;for(let s=0;s<i;s++){let{name:i,dataType:r,numComponents:a,normalize:n,offset:o,stride:l,size:h,asInt:c}=this._elements[s],d=i+r+a+n+c;e.push(d);let u=d+o+l+h;t.push(u);}e.sort();let s=e.join();this.batchingHash=nW(s),this.shaderProcessingHashString=s,this.renderingHashString=t.join("_"),this.renderingHash=nY.get(this.renderingHashString);}constructor(e,t,i){this.device=e,this._elements=[],this.hasUv0=false,this.hasUv1=false,this.hasColor=false,this.hasTangents=false,this.verticesByteSize=0,this.vertexCount=i,this.interleaved=void 0===i,this.instancing=false,this.size=t.reduce((e,t)=>e+4*Math.ceil(t.components*na[t.type]/4),0);let s=0,r;for(let e=0,a=t.length;e<a;e++){let a=t[e];r=a.components*na[a.type],i&&(s=eP.roundUp(s,r));let n=a.asInt??false,o=!n&&(a.normalize??false),l={name:a.semantic,offset:i?s:a.hasOwnProperty("offset")?a.offset:s,stride:i?r:a.hasOwnProperty("stride")?a.stride:this.size,dataType:a.type,numComponents:a.components,normalize:o,size:r,asInt:n};this._elements.push(l),i?s+=r*i:s+=4*Math.ceil(r/4),a.semantic===s$?this.hasUv0=true:a.semantic===sj?this.hasUv1=true:a.semantic===sY?this.hasColor=true:a.semantic===sH&&(this.hasTangents=true);}i&&(this.verticesByteSize=s),this._evaluateHash();}}let nK=new nx;class nZ{set func(e){this._func=e,this._dirty=true;}get func(){return this._func}set ref(e){this._ref=e,this._dirty=true;}get ref(){return this._ref}set fail(e){this._fail=e,this._dirty=true;}get fail(){return this._fail}set zfail(e){this._zfail=e,this._dirty=true;}get zfail(){return this._zfail}set zpass(e){this._zpass=e,this._dirty=true;}get zpass(){return this._zpass}set readMask(e){this._readMask=e,this._dirty=true;}get readMask(){return this._readMask}set writeMask(e){this._writeMask=e,this._dirty=true;}get writeMask(){return this._writeMask}_evalKey(){let{_func:e,_ref:t,_fail:i,_zfail:s,_zpass:r,_readMask:a,_writeMask:n}=this,o=`${e},${t},${i},${s},${r},${a},${n}`;this._key=nK.get(o),this._dirty=false;}get key(){return this._dirty&&this._evalKey(),this._key}copy(e){return this._func=e._func,this._ref=e._ref,this._readMask=e._readMask,this._writeMask=e._writeMask,this._fail=e._fail,this._zfail=e._zfail,this._zpass=e._zpass,this._dirty=e._dirty,this._key=e._key,this}clone(){return new this.constructor().copy(this)}constructor(e={}){this._dirty=true,this._func=e.func??is,this._ref=e.ref??0,this._readMask=e.readMask??255,this._writeMask=e.writeMask??255,this._fail=e.fail??rh,this._zfail=e.zfail??rh,this._zpass=e.zpass??rh,this._evalKey();}}nZ.DEFAULT=Object.freeze(new nZ);class nQ extends eu{postInit(){let e=new nj(this,[{semantic:sV,components:2,type:rQ}]),t=new Float32Array([-1,-1,1,-1,-1,1,1,1]);this.quadVertexBuffer=new nH(this,e,4,{data:t});}initCapsDefines(){let{capsDefines:e}=this;e.clear(),this.textureFloatFilterable&&e.set("CAPS_TEXTURE_FLOAT_FILTERABLE",""),this.textureFloatRenderable&&e.set("CAPS_TEXTURE_FLOAT_RENDERABLE",""),this.supportsMultiDraw&&e.set("CAPS_MULTI_DRAW",""),this.supportsPrimitiveIndex&&e.set("CAPS_PRIMITIVE_INDEX",""),ea.desktop&&e.set("PLATFORM_DESKTOP",""),ea.mobile&&e.set("PLATFORM_MOBILE",""),ea.android&&e.set("PLATFORM_ANDROID",""),ea.ios&&e.set("PLATFORM_IOS","");}destroy(){this.fire("destroy"),this.quadVertexBuffer?.destroy(),this.quadVertexBuffer=null,this.dynamicBuffers?.destroy(),this.dynamicBuffers=null,this.gpuProfiler?.destroy(),this.gpuProfiler=null,this._destroyed=true;}onDestroyShader(e){this.fire("destroy:shader",e);let t=this.shaders.indexOf(e);-1!==t&&this.shaders.splice(t,1);}onTextureDestroyed(e){this.textures.delete(e),this.texturesToUpload.delete(e),this.scope.removeValue(e);}postDestroy(){this.scope=null,this.canvas=null;}loseContext(){for(let e of(this.contextLost=true,this.backBufferSize.set(-1,-1),this.textures))e.loseContext();for(let e of this.buffers)e.loseContext();for(let e of this.targets)e.loseContext();this.gpuProfiler?.loseContext();}restoreContext(){for(let e of(this.contextLost=false,this.initializeRenderState(),this.initializeContextCaches(),this.buffers))e.unlock();this.gpuProfiler?.restoreContext?.();}toJSON(e){}initializeContextCaches(){this.vertexBuffers=[],this.shader=null,this.shaderValid=void 0,this.shaderAsyncCompile=false,this.renderTarget=null;}initializeRenderState(){this.blendState=new nO,this.depthState=new nN,this.cullMode=tZ,this.vx=this.vy=this.vw=this.vh=0,this.sx=this.sy=this.sw=this.sh=0,this.blendColor=new eI(0,0,0,0);}setStencilState(e,t){}setBlendState(e){}setBlendColor(e,t,i,s){}setDepthState(e){}setCullMode(e){}setRenderTarget(e){this.renderTarget=e;}setVertexBuffer(e){e&&this.vertexBuffers.push(e);}clearVertexBuffer(){this.vertexBuffers.length=0;}getIndirectDrawSlot(e=1){return 0}get indirectDrawBuffer(){return null}getIndirectDispatchSlot(e=1){return 0}get indirectDispatchBuffer(){return null}getRenderTarget(){return this.renderTarget}initRenderTarget(e){e.initialized||(e.init(),this.targets.add(e));}draw(e,t,i,s,r=true,a=true){}_isBrowserInterface(e){return this._isImageBrowserInterface(e)||this._isImageCanvasInterface(e)||this._isImageVideoInterface(e)}_isImageBrowserInterface(e){return "undefined"!=typeof ImageBitmap&&e instanceof ImageBitmap||"undefined"!=typeof HTMLImageElement&&e instanceof HTMLImageElement}_isImageCanvasInterface(e){return "undefined"!=typeof HTMLCanvasElement&&e instanceof HTMLCanvasElement}_isImageVideoInterface(e){return "undefined"!=typeof HTMLVideoElement&&e instanceof HTMLVideoElement}resizeCanvas(e,t){let i=Math.min(this._maxPixelRatio,ea.browser?window.devicePixelRatio:1),s=Math.floor(e*i),r=Math.floor(t*i);(s!==this.canvas.width||r!==this.canvas.height)&&this.setResolution(s,r);}setResolution(e,t){this.canvas.width=e,this.canvas.height=t,this.fire(nQ.EVENT_RESIZE,e,t);}update(){this.updateClientRect();}updateClientRect(){if(ea.worker)this.clientRect.width=this.canvas.width,this.clientRect.height=this.canvas.height;else {let e=this.canvas.getBoundingClientRect();this.clientRect.width=e.width,this.clientRect.height=e.height;}}get width(){return this.canvas.width}get height(){return this.canvas.height}set fullscreen(e){}get fullscreen(){return false}set maxPixelRatio(e){this._maxPixelRatio=e;}get maxPixelRatio(){return this._maxPixelRatio}get deviceType(){return this._deviceType}startRenderPass(e){}endRenderPass(e){}startComputePass(e){}endComputePass(){}frameStart(){this.renderPassIndex=0,this.renderVersion++;}frameEnd(){this.mapsToClear.forEach(e=>e.clear()),this.mapsToClear.clear();}computeDispatch(e,t="Unnamed"){}getRenderableHdrFormat(e=[iP,iT,iw],t=true,i=1){for(let s=0;s<e.length;s++){let r=e[s];switch(r){case iP:if(this.textureRG11B10Renderable)return r;break;case iT:if(this.textureHalfFloatRenderable)return r;break;case iw:if(this.isWebGPU&&i>1)continue;if(this.textureFloatRenderable&&(!t||this.textureFloatFilterable))return r}}}validateAttributes(e,t,i){}constructor(e,t){var i,s,r,a,n,o;super(),this.backBuffer=null,this.backBufferSize=new eU,this.backBufferAntialias=false,this.isWebGPU=false,this.isWebGL2=false,this.isNull=false,this.isHdr=false,this.maxIndirectDrawCount=1024,this.maxIndirectDispatchCount=256,this.maxColorAttachments=1,this.maxSamples=1,this.supportsMultiDraw=true,this.supportsCompute=false,this.supportsStorageTextureRead=false,this.supportsSubgroupUniformity=false,this.supportsSubgroupId=false,this.renderTarget=null,this.shaders=[],this.textures=new Set,this.texturesToUpload=new Set,this.targets=new Set,this.renderVersion=0,this.insideRenderPass=false,this.supportsUniformBuffers=false,this.supportsClipDistances=false,this.supportsPrimitiveIndex=false,this.textureRG11B10Renderable=false,this.textureFloatFilterable=false,this.blendState=new nO,this.depthState=new nN,this.stencilEnabled=false,this.stencilFront=new nZ,this.stencilBack=new nZ,this._destroyed=false,this.defaultClearOptions={color:[0,0,0,1],depth:1,stencil:0,flags:tV|tG},this.clientRect={width:0,height:0},this._shadersDirty=false,this.capsDefines=new Map,this.mapsToClear=new Set,this.canvas=e,"setAttribute"in e&&e.setAttribute("data-engine",`PlayCanvas ${X}`),this.initOptions={...t},(i=this.initOptions).alpha??(i.alpha=true),(s=this.initOptions).depth??(s.depth=true),(r=this.initOptions).stencil??(r.stencil=true),(a=this.initOptions).antialias??(a.antialias=true),(n=this.initOptions).powerPreference??(n.powerPreference="high-performance"),(o=this.initOptions).displayFormat??(o.displayFormat=aK),this._maxPixelRatio=ea.browser?Math.min(1,window.devicePixelRatio):1,this.buffers=new Set,this._vram={tex:0,vb:0,ib:0,ub:0,sb:0},this._shaderStats={vsCompiled:0,fsCompiled:0,linked:0,materialShaders:0,compileTime:0},this.initializeContextCaches(),this._drawCallsPerFrame=0,this._shaderSwitchesPerFrame=0,this._primsPerFrame=[];for(let e=sO;e<=sz;e++)this._primsPerFrame[e]=0;this._renderTargetCreationTime=0,this.scope=new nV("Device"),this.textureBias=this.scope.resolve("textureBias"),this.textureBias.setValue(0);}}nQ.EVENT_RESIZE="resizecanvas";let nJ=0;class n0{destroy(){let e=this._device;e&&(e.targets.delete(this),e.renderTarget===this&&e.setRenderTarget(null),this.destroyFrameBuffers());}destroyFrameBuffers(){let e=this._device;e&&this.impl.destroy(e);}destroyTextureBuffers(){this._depthBuffer?.destroy(),this._depthBuffer=null,this._colorBuffers?.forEach(e=>{e.destroy();}),this._colorBuffers=null,this._colorBuffer=null;}resize(e,t){if(!(this.mipLevel>0)&&(this._depthBuffer?.resize(e,t),this._colorBuffers?.forEach(i=>{i.resize(e,t);}),this._width!==e||this._height!==t)){this.destroyFrameBuffers();let e=this._device;e.renderTarget===this&&e.setRenderTarget(null),this.evaluateDimensions(),this.validateMrt(),this.impl=e.createRenderTargetImpl(this);}}validateMrt(){}evaluateDimensions(){let e=this._colorBuffer??this._depthBuffer;e&&(this._width=e.width,this._height=e.height,this._mipLevel>0&&(this._width=ny.calcLevelDimension(this._width,this._mipLevel),this._height=ny.calcLevelDimension(this._height,this._mipLevel)));}init(){this.impl.init(this._device,this);}get initialized(){return this.impl.initialized}get device(){return this._device}loseContext(){this.impl.loseContext();}resolve(e=true,t=!!this._depthBuffer){this._device&&this._samples>1&&this.impl.resolve(this._device,this,e,t);}copy(e,t,i){if(!this._device)if(!e._device)return false;else this._device=e._device;return this._device.copyRenderTarget(e,this,t,i)}get samples(){return this._samples}get depth(){return this._depth}get stencil(){return this._stencil}get colorBuffer(){return this._colorBuffer}getColorBuffer(e){return this._colorBuffers?.[e]}get depthBuffer(){return this._depthBuffer}get face(){return this._face}get mipLevel(){return this._mipLevel}get mipmaps(){return this._mipmaps}get width(){return this._width??this._device.width}get height(){return this._height??this._device.height}isColorBufferSrgb(e=0){if(this.device.backBuffer===this)return sy(this.device.backBufferFormat);let t=this.getColorBuffer(e);return !!t&&sy(t.format)}constructor(e={}){this.id=nJ++;let t=e.colorBuffer?.device??e.colorBuffers?.[0].device??e.depthBuffer?.device??e.graphicsDevice;this._device=t;let{maxSamples:i}=this._device;if(this._samples=Math.min(e.samples??1,i),t.isWebGPU&&(this._samples=this._samples>1?i:1),this._colorBuffer=e.colorBuffer,e.colorBuffer&&(this._colorBuffers=[e.colorBuffer]),this._depthBuffer=e.depthBuffer,this._face=e.face??0,this._depthBuffer){let e=this._depthBuffer._format;e===iA||e===sd?(this._depth=true,this._stencil=false):e===iC?(this._depth=true,this._stencil=true):(e===ib&&this._depthBuffer.device.isWebGPU&&this._samples>1?this._depth=true:this._depth=false,this._stencil=false);}else this._depth=e.depth??true,this._stencil=e.stencil??false;e.colorBuffers&&!this._colorBuffers&&(this._colorBuffers=[...e.colorBuffers],this._colorBuffer=e.colorBuffers[0]),this.autoResolve=e.autoResolve??true,this.name=e.name,this.name||(this.name=this._colorBuffer?.name),this.name||(this.name=this._depthBuffer?.name),this.name||(this.name="Untitled"),this.flipY=e.flipY??false,this._mipLevel=e.mipLevel??0,this._mipLevel>0&&this._depth&&(this._mipLevel=0),this._mipmaps=void 0===e.mipLevel,this.evaluateDimensions(),this.validateMrt(),this.impl=t.createRenderTargetImpl(this);}}class n1{update(e){this.destroy();let t=e.device,i=this.createDescriptor(t,e);this.bindGroup=t.wgpu.createBindGroup(i);}destroy(){this.bindGroup=null;}createDescriptor(e,t){let i=[],s=t.format,r=t.format.uniformBufferFormats;t.uniformBuffers.forEach((e,t)=>{let s=r[t].slot,a=e.persistent?e.impl.buffer:e.allocation.gpuBuffer.buffer;i.push({binding:s,resource:{buffer:a,offset:0,size:e.format.byteSize}});});let a=t.format.textureFormats;t.textures.forEach((t,r)=>{let n=t instanceof nE,o=(n?t.texture:t).impl,l=s.textureFormats[r],h=a[r].slot,c=o.getView(e,n?t:void 0);if(i.push({binding:h,resource:c}),l.hasSampler){let t=o.getSampler(e,l.sampleType);i.push({binding:h+1,resource:t});}});let n=t.format.storageTextureFormats;t.storageTextures.forEach((t,s)=>{let r=t instanceof nE,a=(r?t.texture:t).impl,o=n[s].slot,l=a.getView(e,r?t:void 0);i.push({binding:o,resource:l});});let o=t.format.storageBufferFormats;return t.storageBuffers.forEach((e,t)=>{let s=e.impl.buffer,r=o[t].slot;i.push({binding:r,resource:{buffer:s}});}),{layout:t.format.impl.bindGroupLayout,entries:i}}}class n2{static shaderStage(e){let t=0;return e&aq&&(t|=GPUShaderStage.VERTEX),e&a$&&(t|=GPUShaderStage.FRAGMENT),e&aj&&(t|=GPUShaderStage.COMPUTE),t}}let n3=[];n3[ih]="",n3[ic]="",n3[id]="",n3[i9]="r8unorm",n3[i7]="rg8unorm",n3[iu]="",n3[ip]="",n3[im]="",n3[i_]="rgba8unorm",n3[ig]="rgba8unorm",n3[iv]="bc1-rgba-unorm",n3[iS]="bc2-rgba-unorm",n3[iy]="bc3-rgba-unorm",n3[ix]="",n3[iT]="rgba16float",n3[i8]="r16float",n3[i6]="rg16float",n3[iE]="",n3[iw]="rgba32float",n3[ib]="r32float",n3[su]="rg32float",n3[iA]="depth32float",n3[sd]="depth16unorm",n3[iC]="depth24plus-stencil8",n3[iP]="rg11b10ufloat",n3[iI]="",n3[iD]="rgba8unorm-srgb",n3[iR]="",n3[iL]="etc2-rgb8unorm",n3[iM]="etc2-rgba8unorm",n3[iO]="",n3[iF]="",n3[iN]="",n3[iB]="",n3[ik]="astc-4x4-unorm",n3[iU]="",n3[iz]="",n3[iV]="bgra8unorm",n3[sn]="bgra8unorm-srgb",n3[iG]="r8sint",n3[iH]="r8uint",n3[iW]="r16sint",n3[iX]="r16uint",n3[iY]="r32sint",n3[iq]="r32uint",n3[i$]="rg8sint",n3[ij]="rg8uint",n3[iK]="rg16sint",n3[iZ]="rg16uint",n3[iQ]="rg32sint",n3[iJ]="rg32uint",n3[i0]="rgba8sint",n3[i1]="rgba8uint",n3[i2]="rgba16sint",n3[i3]="rgba16uint",n3[i4]="rgba32sint",n3[i5]="rgba32uint",n3[so]="bc6h-rgb-float",n3[sl]="bc6h-rgb-ufloat",n3[sh]="bc7-rgba-unorm",n3[sf]="rgb9e5ufloat",n3[sp]="rg8snorm",n3[sm]="rgba8snorm",n3[s_]="rgb10a2unorm",n3[sg]="rgb10a2uint",n3[se]="bc1-rgba-unorm-srgb",n3[st]="bc2-rgba-unorm-srgb",n3[si]="bc3-rgba-unorm-srgb",n3[ss]="etc2-rgb8unorm-srgb",n3[sr]="etc2-rgba8unorm-srgb",n3[sc]="bc7-rgba-unorm-srgb",n3[sa]="astc-4x4-unorm-srgb";let n4=[];n4[rF]="filtering",n4[rN]="non-filtering",n4[rB]="comparison",n4[rk]="comparison",n4[rU]="comparison";let n5=[];n5[rF]="float",n5[rN]="unfilterable-float",n5[rB]="depth",n5[rk]="sint",n5[rU]="uint";let n8=new nx;class n6{destroy(){this.bindGroupLayout=null;}loseContext(){}createDescriptor(e){let t=[],i="";return e.uniformBufferFormats.forEach(e=>{let s=n2.shaderStage(e.visibility);i+=`#${e.slot}U:${s}`,t.push({binding:e.slot,visibility:s,buffer:{type:"uniform",hasDynamicOffset:true}});}),e.textureFormats.forEach(e=>{let s=n2.shaderStage(e.visibility),r=e.sampleType,a=e.textureDimension,n=n5[r];if(i+=`#${e.slot}T:${s}-${n}-${a}-false`,t.push({binding:e.slot,visibility:s,texture:{sampleType:n,viewDimension:a,multisampled:false}}),e.hasSampler){let a=n4[r];i+=`#${e.slot+1}S:${s}-${a}`,t.push({binding:e.slot+1,visibility:s,sampler:{type:a}});}}),e.storageTextureFormats.forEach(e=>{let{format:s,textureDimension:r}=e,{read:a,write:n}=e;i+=`#${e.slot}ST:${s}-${r}-${a?"r1":"r0"}-${n?"w1":"w0"}`,t.push({binding:e.slot,visibility:GPUShaderStage.COMPUTE,storageTexture:{access:a?n?"read-write":"read-only":"write-only",format:n3[s],viewDimension:r}});}),e.storageBufferFormats.forEach(e=>{let s=e.readOnly,r=n2.shaderStage(e.visibility);i+=`#${e.slot}SB:${r}-${s?"ro":"rw"}`,t.push({binding:e.slot,visibility:r,buffer:{type:s?"read-only-storage":"storage"}});}),{key:i,desc:{entries:t}}}constructor(e){let t=e.device,{key:i,desc:s}=this.createDescriptor(e);this.key=n8.get(i),this.bindGroupLayout=t.wgpu.createBindGroupLayout(s);}}class n9{destroy(e){this.buffer&&(this.buffer.destroy(),this.buffer=null);}get initialized(){return !!this.buffer}loseContext(){}allocate(e,t){this.buffer=e.wgpu.createBuffer({size:t,usage:this.usageFlags});}unlock(e,t){let i=e.wgpu;if(!this.buffer){let i=t.byteLength+3&-4;this.usageFlags|=GPUBufferUsage.COPY_DST,this.allocate(e,i);}let s=t.byteOffset??0,r=new Uint8Array(t.buffer??t,s,t.byteLength),a=new Uint8Array(this.buffer.size);a.set(r),i.queue.writeBuffer(this.buffer,0,a,0,a.length);}read(e,t,i,s,r){return e.readStorageBuffer(this,t,i,s,r)}write(e,t,i,s,r){e.writeStorageBuffer(this,t,i,s,r);}clear(e,t,i){e.clearStorageBuffer(this,t,i);}constructor(e=0){this.buffer=null,this.usageFlags=0,this.usageFlags=e;}}class n7 extends n9{unlock(e){let t=e.device;super.unlock(t,e.storage);}constructor(e,t){super(tL|(t?.storage?tF:0)),this.format=null,this.format=e.format===ia?"uint16":"uint32";}}let oe={equals(e,t){if(e.length!==t.length)return false;for(let i=0;i<e.length;i++)if(e[i]!==t[i])return false;return true}},ot=[];ot[rY]="sint8",ot[rq]="uint8",ot[r$]="sint16",ot[rj]="uint16",ot[rK]="sint32",ot[rZ]="uint32",ot[rQ]="float32",ot[rJ]="float16";let oi=[];oi[rY]="snorm8",oi[rq]="unorm8",oi[r$]="snorm16",oi[rj]="unorm16",oi[rK]="sint32",oi[rZ]="uint32",oi[rQ]="float32",oi[rJ]="float16";class os{get(e,t=null){let i=this.getKey(e,t),s=this.cache.get(i);return s||(s=this.create(e,t),this.cache.set(i,s)),s}getKey(e,t=null){return `${e?.renderingHashString}-${t?.renderingHashString}`}create(e,t){let i=[],s=e=>{let t=e.interleaved,s=e.instancing?"instance":"vertex",r=[],a=e.elements.length;for(let n=0;n<a;n++){let o=e.elements[n],l=nd[o.name],h=o.normalize?oi:ot;r.push({shaderLocation:l,offset:t?o.offset:0,format:`${h[o.dataType]}${o.numComponents>1?`x${o.numComponents}`:""}`}),t&&n!==a-1||(i.push({attributes:r,arrayStride:o.stride,stepMode:s}),r=[]);}};return e&&s(e),t&&s(t),i}constructor(){this.cache=new Map;}}class or{getPipelineLayout(e){let t=[];return e.forEach(e=>{t.push(e.bindGroupLayout);}),this.device.wgpu.createPipelineLayout({bindGroupLayouts:t})}constructor(e){this.device=e;}}let oa=["point-list","line-list",void 0,"line-strip","triangle-list","triangle-strip",void 0],on=["add","subtract","reverse-subtract","min","max"],oo=["zero","one","src","one-minus-src","dst","one-minus-dst","src-alpha","src-alpha-saturated","one-minus-src-alpha","dst-alpha","one-minus-dst-alpha","constant","one-minus-constant"],ol=["never","less","equal","less-equal","greater","not-equal","greater-equal","always"],oh=["none","back","front"],oc=["keep","zero","replace","increment-clamp","increment-wrap","decrement-clamp","decrement-wrap","invert"],od=["","uint16","uint32"],ou=class{};class of extends or{get(e,t,i,s,r,a,n,o,l,h,c,d,u){let f=e.type;s&&f!==sB&&f!==sU&&(s=void 0);let p=this.lookupHashes;p[0]=f,p[1]=r.id,p[2]=h,p[3]=l.key,p[4]=o.key,p[5]=t?.renderingHash??0,p[6]=i?.renderingHash??0,p[7]=a.impl.key,p[8]=n[0]?.key??0,p[9]=n[1]?.key??0,p[10]=n[2]?.key??0,p[11]=c?d.key:0,p[12]=c?u.key:0,p[13]=s??0;let m=nX(p),_=this.cache.get(m);if(_)for(let e=0;e<_.length;e++){let t=_[e];if(oe.equals(t.hashes,p))return t.pipeline}let g=oa[f],v=this.getPipelineLayout(n),S=this.vertexBufferLayout.get(t,i),y=new ou;return y.hashes=new Uint32Array(p),y.pipeline=this.create(g,s,r,a,v,o,l,S,h,c,d,u),_?_.push(y):_=[y],this.cache.set(m,_),y.pipeline}getBlend(e){let t;return e.blend&&(t={color:{operation:on[e.colorOp],srcFactor:oo[e.colorSrcFactor],dstFactor:oo[e.colorDstFactor]},alpha:{operation:on[e.alphaOp],srcFactor:oo[e.alphaSrcFactor],dstFactor:oo[e.alphaDstFactor]}}),t}getDepthStencil(e,t,i,s,r,a){let n,{depth:o,stencil:l}=t;if(o||l){if(n={format:t.impl.depthAttachment.format},o){n.depthWriteEnabled=e.write,n.depthCompare=ol[e.func];let t="triangle-list"===a||"triangle-strip"===a;n.depthBias=t?e.depthBias:0,n.depthBiasSlopeScale=t?e.depthBiasSlope:0;}else n.depthWriteEnabled=false,n.depthCompare="always";l&&i&&(n.stencilReadMas=s.readMask,n.stencilWriteMask=s.writeMask,n.stencilFront={compare:ol[s.func],failOp:oc[s.fail],passOp:oc[s.zpass],depthFailOp:oc[s.zfail]},n.stencilBack={compare:ol[r.func],failOp:oc[r.fail],passOp:oc[r.zpass],depthFailOp:oc[r.zfail]});}return n}create(e,t,i,s,r,a,n,o,l,h,c,d){let u=this.device.wgpu,f=i.impl,p={vertex:{module:f.getVertexShaderModule(),entryPoint:f.vertexEntryPoint,buffers:o},primitive:{topology:e,frontFace:"ccw",cullMode:oh[l]},depthStencil:this.getDepthStencil(n,s,h,c,d,e),multisample:{count:s.samples},layout:r};t&&(p.primitive.stripIndexFormat=od[t]),p.fragment={module:f.getFragmentShaderModule(),entryPoint:f.fragmentEntryPoint,targets:[]};let m=s.impl.colorAttachments;if(m.length>0){let e=0;a.redWrite&&(e|=GPUColorWrite.RED),a.greenWrite&&(e|=GPUColorWrite.GREEN),a.blueWrite&&(e|=GPUColorWrite.BLUE),a.alphaWrite&&(e|=GPUColorWrite.ALPHA);let t=this.getBlend(a);m.forEach(i=>{p.fragment.targets.push({format:i.format,writeMask:e,blend:t});});}return u.createRenderPipeline(p)}constructor(e){super(e),this.lookupHashes=new Uint32Array(14),this.vertexBufferLayout=new os,this.cache=new Map;}}class op{constructor(){this.pipeline=null,this.hashes=null;}}class om extends or{get(e,t){let i=this.lookupHashes;i[0]=e.impl.computeKey,i[1]=t.impl.key;let s=nX(i),r=this.cache.get(s);if(r)for(let e=0;e<r.length;e++){let t=r[e];if(oe.equals(t.hashes,i))return t.pipeline}let a=this.getPipelineLayout([t.impl]),n=new op;return n.hashes=new Uint32Array(i),n.pipeline=this.create(e,a),r?r.push(n):r=[n],this.cache.set(s,r),n.pipeline}create(e,t){let i=this.device.wgpu,s=e.impl,r={compute:{module:s.getComputeShaderModule(),entryPoint:s.computeEntryPoint},layout:t};return i.createComputePipeline(r)}constructor(...e){super(...e),this.lookupHashes=new Uint32Array(2),this.cache=new Map;}}class o_{incRefCount(){this._refCount++;}decRefCount(){this._refCount--;}get refCount(){return this._refCount}constructor(){this._refCount=0;}}class og extends o_{constructor(e){super(),this.object=e,this.incRefCount();}}class ov{destroy(){this.cache.forEach(e=>{e.object?.destroy();}),this.cache.clear();}clear(){this.cache.clear();}get(e){let t=this.cache.get(e);return t?(t.incRefCount(),t.object):null}set(e,t){this.cache.set(e,new og(t));}release(e){let t=this.cache.get(e);t&&(t.decRefCount(),0===t.refCount&&(this.cache.delete(e),t.object?.destroy()));}constructor(){this.cache=new Map;}}class oS extends ov{loseContext(e){this.clear();}}let oy=new nS,ox=e=>oy.get(e,()=>new oS),oT=new nx;class oE{destroy(){this.multisampledBuffer?.destroy(),this.multisampledBuffer=null;}}class ow{destroy(e){this.depthTextureInternal&&(this.depthTexture?.destroy(),this.depthTexture=null),this.multisampledDepthBuffer&&(this.multisampledDepthBuffer=null,ox(e).release(this.multisampledDepthBufferKey));}constructor(e){this.depthTexture=null,this.depthTextureInternal=false,this.multisampledDepthBuffer=null,this.format=e,this.hasStencil="depth24plus-stencil8"===e;}}class ob{destroy(e){this.initialized=false,this.assignedColorTexture=null,this.colorAttachments.forEach(e=>{e.destroy();}),this.colorAttachments.length=0,this.depthAttachment?.destroy(e),this.depthAttachment=null;}updateKey(){let e=this.renderTarget,t=`${e.samples}:${this.depthAttachment?this.depthAttachment.format:"nodepth"}`;this.colorAttachments.forEach(e=>{t+=`:${e.format}`;}),this.key=oT.get(t);}assignColorTexture(e,t){this.assignedColorTexture=t;let i=t.createView({format:e.backBufferViewFormat}),s=this.renderPassDescriptor.colorAttachments[0];this.renderTarget.samples>1?s.resolveTarget=i:s.view=i,this.setColorAttachment(0,void 0,e.backBufferViewFormat),this.updateKey();}setColorAttachment(e,t,i){this.colorAttachments[e]||(this.colorAttachments[e]=new oE),t&&(this.colorAttachments[e].multisampledBuffer=t),i&&(this.colorAttachments[e].format=i);}init(e,t){let i=e.wgpu;this.initDepthStencil(e,i,t),t._colorBuffers&&t._colorBuffers.forEach((e,t)=>{this.setColorAttachment(t,void 0,e.impl.format);}),this.renderPassDescriptor.colorAttachments=[];let s=this.isBackbuffer?1:t._colorBuffers?.length??0;for(let r=0;r<s;++r){let s=this.initColor(e,i,t,r),a=0===r&&this.colorAttachments[0]?.format;(s.view||a)&&this.renderPassDescriptor.colorAttachments.push(s);}this.updateKey(),this.initialized=true;}initDepthStencil(e,t,i){let{samples:s,width:r,height:a,depth:n,depthBuffer:o}=i;if(n||o){let i;if(o)if(this.depthAttachment=new ow(o.impl.format),s>1){let n="depth24plus-stencil8";this.depthAttachment.format=n,this.depthAttachment.hasStencil=true;let l=`${o.id}:${r}:${a}:${s}:${n}`,h=ox(e),c=h.get(l);if(!c){let e={size:[r,a,1],dimension:"2d",sampleCount:s,format:n,usage:GPUTextureUsage.RENDER_ATTACHMENT|(n!==o.impl.format?GPUTextureUsage.TEXTURE_BINDING:0)};c=t.createTexture(e),h.set(l,c);}this.depthAttachment.multisampledDepthBuffer=c,this.depthAttachment.multisampledDepthBufferKey=l,i=c.createView();}else {let e=o.impl.gpuTexture;this.depthAttachment.depthTexture=e,i=e.createView();}else {this.depthAttachment=new ow("depth24plus-stencil8");let e={size:[r,a,1],dimension:"2d",sampleCount:s,format:this.depthAttachment.format,usage:GPUTextureUsage.RENDER_ATTACHMENT};s>1?e.usage|=GPUTextureUsage.TEXTURE_BINDING:e.usage|=GPUTextureUsage.COPY_SRC;let n=t.createTexture(e);this.depthAttachment.depthTexture=n,this.depthAttachment.depthTextureInternal=true,i=n.createView();}this.renderPassDescriptor.depthStencilAttachment={view:i};}}initColor(e,t,i,s){let r={},{samples:a,width:n,height:o,mipLevel:l}=i,h=i.getColorBuffer(s),c=null;if(h&&(c=h.cubemap?h.impl.createView({dimension:"2d",baseArrayLayer:i.face,arrayLayerCount:1,mipLevelCount:1,baseMipLevel:l}):h.impl.createView({mipLevelCount:1,baseMipLevel:l})),a>1){let i={size:[n,o,1],dimension:"2d",sampleCount:a,format:this.isBackbuffer?e.backBufferViewFormat:h.impl.format,usage:GPUTextureUsage.RENDER_ATTACHMENT},l=t.createTexture(i);this.setColorAttachment(s,l,i.format),r.view=l.createView(),r.resolveTarget=c;}else r.view=c;return r}setupForRenderPass(e,t){let i=this.renderPassDescriptor.colorAttachments?.length??0;for(let s=0;s<i;++s){let i=this.renderPassDescriptor.colorAttachments[s],r=e.colorArrayOps[s];i.clearValue=t.isColorBufferSrgb(s)?r.clearValueLinear:r.clearValue,i.loadOp=r.clear?"clear":"load",i.storeOp=r.store?"store":"discard";}let s=this.renderPassDescriptor.depthStencilAttachment;s&&(s.depthClearValue=e.depthStencilOps.clearDepthValue,s.depthLoadOp=e.depthStencilOps.clearDepth?"clear":"load",s.depthStoreOp=e.depthStencilOps.storeDepth?"store":"discard",s.depthReadOnly=false,this.depthAttachment.hasStencil&&(s.stencilClearValue=e.depthStencilOps.clearStencilValue,s.stencilLoadOp=e.depthStencilOps.clearStencil?"clear":"load",s.stencilStoreOp=e.depthStencilOps.storeStencil?"store":"discard",s.stencilReadOnly=false));}loseContext(){this.initialized=false;}resolve(e,t,i,s){}constructor(e){this.initialized=false,this.colorAttachments=[],this.depthAttachment=null,this.assignedColorTexture=null,this.renderPassDescriptor={},this.isBackbuffer=false,this.renderTarget=e;}}let oA=[];oA[r2]=1,oA[r3]=2,oA[r4]=3,oA[r5]=4,oA[r1]=1,oA[r8]=2,oA[r6]=3,oA[r9]=4,oA[r0]=1,oA[r7]=2,oA[ae]=3,oA[at]=4,oA[ai]=8,oA[as]=12,oA[ar]=16,oA[a_]=1,oA[ag]=2,oA[av]=3,oA[aS]=4;class oC{get isArrayType(){return this.count>0}calculateOffset(e){let t=this.byteSize<=8?this.byteSize:16;this.count&&(t=16),e=eP.roundUp(e,t),this.offset=e/4;}constructor(e,t,i=0){if(this.shortName=e,this.name=i?`${e}[0]`:e,this.type=t,this.numComponents=oA[t],this.updateType=t,i>0)switch(t){case r2:this.updateType=ao;break;case r1:this.updateType=ay;break;case a_:this.updateType=ax;break;case r0:this.updateType=aT;break;case r3:this.updateType=ad;break;case r8:this.updateType=aE;break;case ag:this.updateType=aw;break;case r7:this.updateType=ab;break;case r4:this.updateType=au;break;case r6:this.updateType=aA;break;case av:this.updateType=aC;break;case ae:this.updateType=aP;break;case r5:this.updateType=af;break;case r9:this.updateType=aI;break;case aS:this.updateType=aD;break;case at:this.updateType=aR;break;case ar:this.updateType=ap;}this.count=i;let s=this.numComponents;i&&(s=eP.roundUp(s,4)),this.byteSize=4*s,i&&(this.byteSize*=i);}}class oP{get(e){return this.map.get(e)}constructor(e,t){this.byteSize=0,this.map=new Map,this.scope=e.scope,this.uniforms=t;let i=0;for(let e=0;e<t.length;e++){let s=t[e];s.calculateOffset(i),i=4*s.offset+s.byteSize,s.scopeId=this.scope.resolve(s.name),this.map.set(s.name,s);}this.byteSize=eP.roundUp(i,16);}}let oI=/[ \t]*(\battribute\b|\bvarying\b|\buniform\b)/g,oD=/(\battribute\b|\bvarying\b|\bout\b|\buniform\b)[ \t]*([^;]+)(;+)/g,oR=/([\w-]+)\[(.*?)\]/,oL=new Set(["highp","mediump","lowp"]),oM=new Set(["sampler2DShadow","samplerCubeShadow","sampler2DArrayShadow"]),oO={sampler2D:rD,sampler3D:rO,samplerCube:rL,samplerCubeShadow:rL,sampler2DShadow:rD,sampler2DArray:rR,sampler2DArrayShadow:rR,isampler2D:rD,usampler2D:rD,isampler3D:rO,usampler3D:rO,isamplerCube:rL,usamplerCube:rL,isampler2DArray:rR,usampler2DArray:rR},oF={[rD]:"texture2D",[rL]:"textureCube",[rO]:"texture3D",[rR]:"texture2DArray"},oN=class{constructor(e,t){this.line=e;let i=e.trim().split(/\s+/);if(oL.has(i[0])&&(this.precision=i.shift()),this.type=i.shift(),e.includes(","),e.includes("[")){let e=i.join(" "),s=oR.exec(e);this.name=s[1],this.arraySize=Number(s[2]),isNaN(this.arraySize)&&(t.failed=true);}else this.name=i.shift(),this.arraySize=0;this.isSampler=-1!==this.type.indexOf("sampler"),this.isSignedInt=-1!==this.type.indexOf("isampler"),this.isUnsignedInt=-1!==this.type.indexOf("usampler");}};class oB{static run(e,t,i){let s=new Map,r=oB.extract(t.vshader),a=oB.extract(t.fshader),n=new Map,o=oB.processAttributes(r.attributes,t.attributes,n,t.processingOptions),l=oB.processVaryings(r.varyings,s,true),h=oB.processVaryings(a.varyings,s,false),c=oB.processOuts(a.outs),d=Array.from(new Set(r.uniforms.concat(a.uniforms))).map(e=>new oN(e,i)),u=oB.processUniforms(e,d,t.processingOptions,i),f=`${o}
8
+ */let x="RenderFrame",T="RenderFrameTime",E="RenderPass",w="RenderPassDetail",b="RenderAction",A="RenderTargetAlloc",C="TextureAlloc",P="ShaderAlloc",I="ShaderCompile",D="VRAM.Texture",R="VRAM.Vb",L="VRAM.Ib",M="VRAM.Sb",O="BindGroupAlloc",F="BindGroupFormatAlloc",N="RenderPipelineAlloc",B="ComputePipelineAlloc",k="PipelineLayoutAlloc",U="Element",z="Textures",V="Assets",G="RenderQueue",H="OctreeResources",W="GpuTimings",X="2.16.0",Y="7aba7cb";function q(e,t){for(let i in t){let s=t[i];Array.isArray(s)?e[i]=q([],s):s&&"object"==typeof s?e[i]=q({},s):e[i]=s;}return e}let $={create:()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{let t=16*Math.random()|0;return ("x"===e?t:3&t|8).toString(16)})},j={delimiter:"/",join(...e){let t=e[0];for(let i=0;i<e.length-1;i++){let s=e[i],r=e[i+1];if(r[0]===j.delimiter){t=r;continue}s&&r&&s[s.length-1]!==j.delimiter&&r[0]!==j.delimiter?t+=j.delimiter+r:t+=r;}return t},normalize(e){let t=e.startsWith(j.delimiter),i=e.endsWith(j.delimiter),s=e.split("/"),r="",a=[];for(let e=0;e<s.length;e++)if(""!==s[e]&&"."!==s[e]){if(".."===s[e]&&a.length>0){a=a.slice(0,a.length-2);continue}e>0&&a.push(j.delimiter),a.push(s[e]);}return r=a.join(""),t||r[0]!==j.delimiter||(r=r.slice(1)),i&&r[r.length-1]!==j.delimiter&&(r+=j.delimiter),r},split(e){let t=e.lastIndexOf(j.delimiter);return -1!==t?[e.substring(0,t),e.substring(t+1)]:["",e]},getBasename:e=>j.split(e)[1],getDirectory:e=>j.split(e)[0],getExtension(e){let t=e.split("?")[0].split(".").pop();return t!==e?`.${t}`:""},isRelativePath:e=>"/"!==e.charAt(0)&&null===e.match(/:\/\//),extractPath(e){let t="",i=e.split("/"),s=0;if(i.length>1)if(j.isRelativePath(e))if("."===i[0])for(s=0;s<i.length-1;++s)t+=0===s?i[s]:`/${i[s]}`;else if(".."===i[0])for(s=0;s<i.length-1;++s)t+=0===s?i[s]:`/${i[s]}`;else for(s=0,t=".";s<i.length-1;++s)t+=`/${i[s]}`;else for(s=0;s<i.length-1;++s)t+=0===s?i[s]:`/${i[s]}`;return t}},K="undefined"!=typeof navigator?navigator.userAgent:"",Z="undefined"!=typeof window?"browser":"undefined"!=typeof global?"node":"worker",Q=/android/i.test(K)?"android":/ip(?:[ao]d|hone)/i.test(K)?"ios":/windows/i.test(K)?"windows":/mac os/i.test(K)?"osx":/linux/i.test(K)?"linux":/cros/i.test(K)?"cros":null,J="browser"!==Z?null:/Chrome\/|Chromium\/|Edg.*\//.test(K)?"chrome":/Safari\//.test(K)?"safari":/Firefox\//.test(K)?"firefox":"other",ee=/xbox/i.test(K),et="browser"===Z&&("ontouchstart"in window||"maxTouchPoints"in navigator&&navigator.maxTouchPoints>0),ei="browser"===Z&&(!!navigator.getGamepads||!!navigator.webkitGetGamepads),es="undefined"!=typeof Worker,er=(()=>{let e=false;try{let t=Object.defineProperty({},"passive",{get:function(){return e=!0,!1}});window.addEventListener("testpassive",null,t),window.removeEventListener("testpassive",null,t);}catch(e){}return e})(),ea={name:Q,environment:Z,global:("undefined"!=typeof globalThis&&globalThis)??("browser"===Z&&window)??("node"===Z&&global)??("worker"===Z&&self),browser:"browser"===Z,worker:"worker"===Z,desktop:["windows","osx","linux","cros"].includes(Q),mobile:["android","ios"].includes(Q),ios:"ios"===Q,android:"android"===Q,xbox:ee,gamepads:ei,touch:et,workers:es,passiveEvents:er,browserName:J},en="abcdefghijklmnopqrstuvwxyz",eo="ABCDEFGHIJKLMNOPQRSTUVWXYZ";function el(e,t=0){let i=e.length;if(t<0||t>=i)return null;let s=e.charCodeAt(t);if(i>1&&s>=55296&&s<=56319){let i=e.charCodeAt(t+1);if(i>=56320&&i<=57343)return {code:(s-55296)*1024+i-56320+65536,long:true}}return {code:s,long:false}}function eh(e,t,i){if(!e)return false;let s=el(e);if(s){let e=s.code;return e>=t&&e<=i}return false}let ec={ASCII_LOWERCASE:en,ASCII_UPPERCASE:eo,ASCII_LETTERS:en+eo,format(e,...t){for(let i=0;i<t.length;i++)e=e.replace(`{${i}}`,t[i]);return e},getCodePoint(e,t){let i=el(e,t);return i&&i.code},getCodePoints(e){let t;if("string"!=typeof e)throw TypeError("Not a string");let i=0,s=[];for(;t=el(e,i);)s.push(t.code),i+=t.long?2:1;return s},getSymbols(e){let t;if("string"!=typeof e)throw TypeError("Not a string");let i=0,s=e.length,r=[],a=0;for(;i<s;){if(a+=function(e,t){if(t===e.length-1)return 1;if(eh(e[t],55296,56319)){let i=e.substring(t,t+2),s=e.substring(t+2,t+4);return eh(s,127995,127999)||eh(i,127462,127487)&&eh(s,127462,127487)?4:eh(s,65024,65039)?3:2}return eh(e[t+1],65024,65039)?2:1}(e,i+a),eh(t=e[i+a],8400,8447)&&(t=e[i+a++]),eh(t,65024,65039)&&(t=e[i+a++]),t&&8205===t.charCodeAt(0)){t=e[i+a++];continue}let s=e.substring(i,i+a);r.push(s),i+=a,a=0;}return r},fromCodePoint:(...e)=>e.map(e=>e>65535?String.fromCharCode(((e-=65536)>>10)+55296,e%1024+56320):String.fromCharCode(e)).join("")};class ed{off(){this._removed||this.handler.offByHandle(this);}on(e,t,i=this){return this.handler._addCallback(e,t,i,false)}once(e,t,i=this){return this.handler._addCallback(e,t,i,true)}set removed(e){e&&(this._removed=true);}get removed(){return this._removed}toJSON(e){}constructor(e,t,i,s,r=false){this._removed=false,this.handler=e,this.name=t,this.callback=i,this.scope=s,this._once=r;}}class eu{initEventHandler(){this._callbacks=new Map,this._callbackActive=new Map;}_addCallback(e,t,i,s){if(this._callbacks.has(e)||this._callbacks.set(e,[]),this._callbackActive.has(e)){let t=this._callbackActive.get(e);t&&t===this._callbacks.get(e)&&this._callbackActive.set(e,t.slice());}let r=new ed(this,e,t,i,s);return this._callbacks.get(e).push(r),r}on(e,t,i=this){return this._addCallback(e,t,i,false)}once(e,t,i=this){return this._addCallback(e,t,i,true)}off(e,t,i){if(e)this._callbackActive.has(e)&&this._callbackActive.get(e)===this._callbacks.get(e)&&this._callbackActive.set(e,this._callbackActive.get(e).slice());else for(let[e,t]of this._callbackActive)this._callbacks.has(e)&&this._callbacks.get(e)===t&&this._callbackActive.set(e,t.slice());if(e)if(t){let s=this._callbacks.get(e);if(!s)return this;for(let e=0;e<s.length;e++)s[e].callback===t&&(!i||s[e].scope===i)&&(s[e].removed=true,s.splice(e,1),e--);0===s.length&&this._callbacks.delete(e);}else {let t=this._callbacks.get(e);if(t){for(let e=0;e<t.length;e++)t[e].removed=true;this._callbacks.delete(e);}}else {for(let e of this._callbacks.values())for(let t=0;t<e.length;t++)e[t].removed=true;this._callbacks.clear();}return this}offByHandle(e){let t=e.name;e.removed=true,this._callbackActive.has(t)&&this._callbackActive.get(t)===this._callbacks.get(t)&&this._callbackActive.set(t,this._callbackActive.get(t).slice());let i=this._callbacks.get(t);if(!i)return this;let s=i.indexOf(e);return -1!==s&&(i.splice(s,1),0===i.length&&this._callbacks.delete(t)),this}fire(e,t,i,s,r,a,n,o,l){let h;if(!e)return this;let c=this._callbacks.get(e);if(!c)return this;this._callbackActive.has(e)?this._callbackActive.get(e)!==c&&(h=c.slice()):this._callbackActive.set(e,c);for(let c=0;(h||this._callbackActive.get(e))&&c<(h||this._callbackActive.get(e)).length;c++){let d=(h||this._callbackActive.get(e))[c];if(d.callback&&(d.callback.call(d.scope,t,i,s,r,a,n,o,l),d._once)){let t=this._callbacks.get(e),i=t?t.indexOf(d):-1;if(-1!==i){this._callbackActive.get(e)===t&&this._callbackActive.set(e,this._callbackActive.get(e).slice());let s=this._callbacks.get(e);if(!s)continue;s[i].removed=true,s.splice(i,1),0===s.length&&this._callbacks.delete(e);}}}return h||this._callbackActive.delete(e),this}hasEvent(e){return !!this._callbacks.get(e)?.length}constructor(){this._callbacks=new Map,this._callbackActive=new Map;}}class ef{push(e,t){if(this._index[e])throw Error(`Key already in index ${e}`);let i=this._list.push(t)-1;this._index[e]=i;}has(e){return void 0!==this._index[e]}get(e){let t=this._index[e];return void 0!==t?this._list[t]:null}remove(e){let t=this._index[e];if(void 0!==t){for(e in this._list.splice(t,1),delete this._index[e],this._index){let i=this._index[e];i>t&&(this._index[e]=i-1);}return true}return false}list(){return this._list}clear(){for(let e in this._list.length=0,this._index)delete this._index[e];}constructor(){this._list=[],this._index={};}}class ep{static loadScript(e,t){let i=document.createElement("script");i.setAttribute("src",e),i.onload=()=>{t(null);},i.onerror=()=>{t(`Failed to load script='${e}'`);},document.body.appendChild(i);}static loadWasm(e,t,i){let s=ep.wasmSupported()&&t.glueUrl&&t.wasmUrl?t.glueUrl:t.fallbackUrl;s?ep.loadScript(s,s=>{if(s)i(s,null);else {let s=window[e];window[e]=void 0,s({locateFile:()=>t.wasmUrl,onAbort:()=>{i("wasm module aborted.");}}).then(e=>{i(null,e);});}}):i("No supported wasm modules found.",null);}static getModule(e){return ep.modules.hasOwnProperty(e)||(ep.modules[e]={config:null,initializing:false,instance:null,callbacks:[]}),ep.modules[e]}static initialize(e,t){if(t.initializing)return;let i=t.config;(i.glueUrl||i.wasmUrl||i.fallbackUrl)&&(t.initializing=true,ep.loadWasm(e,i,(e,s)=>{e?i.errorHandler&&i.errorHandler(e):(t.instance=s,t.callbacks.forEach(e=>{e(s);}));}));}}ep.modules={},S=v={},ep.wasmSupported=()=>(S===v&&(S=(()=>{try{if("object"==typeof WebAssembly&&"function"==typeof WebAssembly.instantiate){let e=new WebAssembly.Module(Uint8Array.of(0,97,115,109,1,0,0,0));if(e instanceof WebAssembly.Module)return new WebAssembly.Instance(e)instanceof WebAssembly.Instance}}catch(e){}return false})()),S);class em{static setConfig(e,t){let i=ep.getModule(e);i.config=t,i.callbacks.length>0&&ep.initialize(e,i);}static getConfig(e){return ep.modules?.[e]?.config}static getInstance(e,t){let i=ep.getModule(e);i.instance?t(i.instance):(i.callbacks.push(t),i.config&&ep.initialize(e,i));}}class e_{get remainingBytes(){return this.dataView.byteLength-this.offset}reset(e=0){this.offset=e;}skip(e){this.offset+=e;}align(e){this.offset=this.offset+e-1&~(e-1);}_inc(e){return this.offset+=e,this.offset-e}readChar(){return String.fromCharCode(this.dataView.getUint8(this.offset++))}readChars(e){let t="";for(let i=0;i<e;++i)t+=this.readChar();return t}readU8(){return this.dataView.getUint8(this.offset++)}readU16(){return this.dataView.getUint16(this._inc(2),true)}readU32(){return this.dataView.getUint32(this._inc(4),true)}readU64(){return this.readU32()+0x100000000*this.readU32()}readU32be(){return this.dataView.getUint32(this._inc(4),false)}readArray(e){for(let t=0;t<e.length;++t)e[t]=this.readU8();}readLine(){let e=this.dataView,t="";for(;!(this.offset>=e.byteLength);){let e=String.fromCharCode(this.readU8());if("\n"===e)break;t+=e;}return t}constructor(e){this.offset=0,this.arraybuffer=e,this.dataView=new DataView(e);}}class eg{_binarySearch(e){let t,i,s=0,r=this.items.length-1,a=e[this._sortBy];for(;s<=r;)t=Math.floor((s+r)/2),(i=this.items[t][this._sortBy])<=a?s=t+1:i>a&&(r=t-1);return s}_doSort(e,t){let i=this._sortBy;return e[i]-t[i]}insert(e){let t=this._binarySearch(e);this.items.splice(t,0,e),this.length++,this.loopIndex>=t&&this.loopIndex++;}append(e){this.items.push(e),this.length++;}remove(e){let t=this.items.indexOf(e);!(t<0)&&(this.items.splice(t,1),this.length--,this.loopIndex>=t&&this.loopIndex--);}sort(){let e=this.loopIndex>=0?this.items[this.loopIndex]:null;this.items.sort(this._sortHandler),null!==e&&(this.loopIndex=this.items.indexOf(e));}constructor(e){this.items=[],this.length=0,this.loopIndex=-1,this._sortBy=e.sortBy,this._sortHandler=this._doSort.bind(this);}}class ev extends eu{add(...e){let t=false,i=this._processArguments(e,true);if(!i.length)return t;for(let e=0;e<i.length;e++)this._index[i[e]]||(t=true,this._index[i[e]]=true,this._list.push(i[e]),this.fire("add",i[e],this._parent));return t&&this.fire("change",this._parent),t}remove(...e){let t=false;if(!this._list.length)return t;let i=this._processArguments(e,true);if(!i.length)return t;for(let e=0;e<i.length;e++)this._index[i[e]]&&(t=true,delete this._index[i[e]],this._list.splice(this._list.indexOf(i[e]),1),this.fire("remove",i[e],this._parent));return t&&this.fire("change",this._parent),t}clear(){if(!this._list.length)return;let e=this._list.slice(0);this._list=[],this._index={};for(let t=0;t<e.length;t++)this.fire("remove",e[t],this._parent);this.fire("change",this._parent);}has(...e){return !!this._list.length&&this._has(this._processArguments(e))}_has(e){if(!this._list.length||!e.length)return false;for(let t=0;t<e.length;t++)if(1===e[t].length){if(this._index[e[t][0]])return true}else {let i=true;for(let s=0;s<e[t].length;s++)if(!this._index[e[t][s]]){i=false;break}if(i)return true}return false}list(){return this._list.slice(0)}_processArguments(e,t){let i=[],s=[];if(!e||!e.length)return i;for(let r=0;r<e.length;r++)if(e[r]instanceof Array){t||(s=[]);for(let a=0;a<e[r].length;a++)"string"==typeof e[r][a]&&(t?i.push(e[r][a]):s.push(e[r][a]));!t&&s.length&&i.push(s);}else "string"==typeof e[r]&&(t?i.push(e[r]):i.push([e[r]]));return i}get size(){return this._list.length}constructor(e){super(),this._index={},this._list=[],this._parent=e;}}ev.EVENT_ADD="add",ev.EVENT_REMOVE="remove",ev.EVENT_CHANGE="change";let eS="undefined"!=typeof window&&window.performance&&window.performance.now?performance.now.bind(performance):Date.now;function ey(e){let t="";if((e.authority||e.scheme)&&(e.host||e.hostpath))throw Error("Can't have 'scheme' or 'authority' and 'host' or 'hostpath' option");if(e.host&&e.hostpath)throw Error("Can't have 'host' and 'hostpath' option");if(e.path&&e.hostpath)throw Error("Can't have 'path' and 'hostpath' option");return e.scheme&&(t+=`${e.scheme}:`),e.authority&&(t+=`//${e.authority}`),e.host&&(t+=e.host),e.path&&(t+=e.path),e.hostpath&&(t+=e.hostpath),e.query&&(t+=`?${e.query}`),e.fragment&&(t+=`#${e.fragment}`),t}let ex=/^(([^:/?#]+):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/;class eT{toString(){let e="";return this.scheme&&(e+=`${this.scheme}:`),this.authority&&(e+=`//${this.authority}`),e+=this.path,this.query&&(e+=`?${this.query}`),this.fragment&&(e+=`#${this.fragment}`),e}getQuery(){let e={};if(this.query)for(let t of decodeURIComponent(this.query).split("&")){let i=t.split("=");e[i[0]]=i[1];}return e}setQuery(e){let t="";for(let i in e)e.hasOwnProperty(i)&&(""!==t&&(t+="&"),t+=`${encodeURIComponent(i)}=${encodeURIComponent(e[i])}`);this.query=t;}constructor(e){let t=e.match(ex);this.scheme=t[2],this.authority=t[4],this.path=t[5],this.query=t[7],this.fragment=t[9];}}class eE{static set(e,t=true){}static get(e){return eE._traceChannels.has(e)}}eE._traceChannels=new Set,eE.stack=false;let ew=0,eb=1,eA=4,eC=5,eP={DEG_TO_RAD:Math.PI/180,RAD_TO_DEG:180/Math.PI,clamp:(e,t,i)=>e>=i?i:e<=t?t:e,intToBytes24:e=>[e>>16&255,e>>8&255,255&e],intToBytes32:e=>[e>>24&255,e>>16&255,e>>8&255,255&e],bytesToInt24:(e,t,i)=>(e.length&&(i=e[2],t=e[1],e=e[0]),e<<16|t<<8|i),bytesToInt32:(e,t,i,s)=>(e.length&&(s=e[3],i=e[2],t=e[1],e=e[0]),(e<<24|t<<16|i<<8|s)>>>0),lerp:(e,t,i)=>e+(t-e)*eP.clamp(i,0,1),lerpAngle:(e,t,i)=>(t-e>180&&(t-=360),t-e<-180&&(t+=360),eP.lerp(e,t,eP.clamp(i,0,1))),powerOfTwo:e=>0!==e&&!(e&e-1),nextPowerOfTwo:e=>(e--,e|=e>>1,e|=e>>2,e|=e>>4,e|=e>>8,e|=e>>16,++e),nearestPowerOfTwo:e=>Math.pow(2,Math.round(Math.log2(e))),random:(e,t)=>Math.random()*(t-e)+e,smoothstep:(e,t,i)=>i<=e?0:i>=t?1:(i=(i-e)/(t-e))*i*(3-2*i),smootherstep:(e,t,i)=>i<=e?0:i>=t?1:(i=(i-e)/(t-e))*i*i*(i*(6*i-15)+10),roundUp:(e,t)=>0===t?e:Math.ceil(e/t)*t,between(e,t,i,s){let r=Math.min(t,i),a=Math.max(t,i);return s?e>=r&&e<=a:e>r&&e<a}};class eI{clone(){return new this.constructor(this.r,this.g,this.b,this.a)}copy(e){return this.r=e.r,this.g=e.g,this.b=e.b,this.a=e.a,this}equals(e){return this.r===e.r&&this.g===e.g&&this.b===e.b&&this.a===e.a}set(e,t,i,s=1){return this.r=e,this.g=t,this.b=i,this.a=s,this}lerp(e,t,i){return this.r=e.r+i*(t.r-e.r),this.g=e.g+i*(t.g-e.g),this.b=e.b+i*(t.b-e.b),this.a=e.a+i*(t.a-e.a),this}linear(e=this){return this.r=Math.pow(e.r,2.2),this.g=Math.pow(e.g,2.2),this.b=Math.pow(e.b,2.2),this.a=e.a,this}gamma(e=this){return this.r=Math.pow(e.r,1/2.2),this.g=Math.pow(e.g,1/2.2),this.b=Math.pow(e.b,1/2.2),this.a=e.a,this}mulScalar(e){return this.r*=e,this.g*=e,this.b*=e,this}fromString(e){let t,i=parseInt(e.replace("#","0x"),16);return e.length>7?t=eP.intToBytes32(i):(t=eP.intToBytes24(i))[3]=255,this.set(t[0]/255,t[1]/255,t[2]/255,t[3]/255),this}fromArray(e,t=0){return this.r=e[t]??this.r,this.g=e[t+1]??this.g,this.b=e[t+2]??this.b,this.a=e[t+3]??this.a,this}toString(e,t){let{r:i,g:s,b:r,a}=this;if(t||i>1||s>1||r>1)return `${i.toFixed(3)}, ${s.toFixed(3)}, ${r.toFixed(3)}, ${a.toFixed(3)}`;let n=`#${(0x1000000+(Math.round(255*i)<<16)+(Math.round(255*s)<<8)+Math.round(255*r)).toString(16).slice(1)}`;if(true===e){let e=Math.round(255*a).toString(16);this.a<16/255?n+=`0${e}`:n+=e;}return n}toArray(e=[],t=0,i=true){return e[t]=this.r,e[t+1]=this.g,e[t+2]=this.b,i&&(e[t+3]=this.a),e}constructor(e=0,t=0,i=0,s=1){let r=e.length;3===r||4===r?(this.r=e[0],this.g=e[1],this.b=e[2],this.a=e[3]??1):(this.r=e,this.g=t,this.b=i,this.a=s);}}eI.BLACK=Object.freeze(new eI(0,0,0,1)),eI.BLUE=Object.freeze(new eI(0,0,1,1)),eI.CYAN=Object.freeze(new eI(0,1,1,1)),eI.GRAY=Object.freeze(new eI(.5,.5,.5,1)),eI.GREEN=Object.freeze(new eI(0,1,0,1)),eI.MAGENTA=Object.freeze(new eI(1,0,1,1)),eI.RED=Object.freeze(new eI(1,0,0,1)),eI.WHITE=Object.freeze(new eI(1,1,1,1)),eI.YELLOW=Object.freeze(new eI(1,1,0,1));class eD{evaluate(e,t=false){let i;(t||e<this._left||e>=this._right)&&this._reset(e);let s=this._curve.type;if(s===eC)i=this._p0;else {let t=0===this._recip?0:(e-this._left)*this._recip;i=s===ew?eP.lerp(this._p0,this._p1,t):s===eb?eP.lerp(this._p0,this._p1,t*t*(3-2*t)):this._evaluateHermite(this._p0,this._p1,this._m0,this._m1,t);}return i}_reset(e){let t=this._curve.keys,i=t.length;if(i)if(e<t[0][0])this._left=-1/0,this._right=t[0][0],this._recip=0,this._p0=this._p1=t[0][1],this._m0=this._m1=0;else if(e>=t[i-1][0])this._left=t[i-1][0],this._right=1/0,this._recip=0,this._p0=this._p1=t[i-1][1],this._m0=this._m1=0;else {let i=0;for(;e>=t[i+1][0];)i++;this._left=t[i][0],this._right=t[i+1][0];let s=1/(this._right-this._left);this._recip=isFinite(s)?s:0,this._p0=t[i][1],this._p1=t[i+1][1],this._curve.type===eA&&this._calcTangents(t,i);}else this._left=-1/0,this._right=1/0,this._recip=0,this._p0=this._p1=this._m0=this._m1=0;}_calcTangents(e,t){let i,s,r=e[t],a=e[t+1];if(i=0===t?[e[0][0]+(e[0][0]-e[1][0]),e[0][1]+(e[0][1]-e[1][1])]:e[t-1],s=t===e.length-2?[e[t+1][0]+(e[t+1][0]-e[t][0]),e[t+1][1]+(e[t+1][1]-e[t][1])]:e[t+2],this._curve.type===eA){let e=2*(a[0]-r[0])/(a[0]-i[0]),t=2*(a[0]-r[0])/(s[0]-r[0]);this._m0=this._curve.tension*(isFinite(e)?e:0)*(a[1]-i[1]),this._m1=this._curve.tension*(isFinite(t)?t:0)*(s[1]-r[1]);}else {let e=(a[0]-r[0])/(r[0]-i[0]),t=(a[0]-r[0])/(s[0]-a[0]),n=r[1]+(i[1]-r[1])*(isFinite(e)?e:0),o=a[1]+(s[1]-a[1])*(isFinite(t)?t:0),l=this._curve.tension;this._m0=l*(a[1]-n),this._m1=l*(o-r[1]);}}_evaluateHermite(e,t,i,s,r){let a=r*r,n=r+r,o=1-r,l=o*o;return (1+n)*l*e+r*l*i+a*(3-n)*t+a*(r-1)*s}constructor(e,t=0){this._left=-1/0,this._right=1/0,this._recip=0,this._p0=0,this._p1=0,this._m0=0,this._m1=0,this._curve=e,this._reset(t);}}class eR{get length(){return this.keys.length}add(e,t){let i=this.keys,s=i.length,r=0;for(;r<s&&!(i[r][0]>e);r++);let a=[e,t];return this.keys.splice(r,0,a),a}get(e){return this.keys[e]}sort(){this.keys.sort((e,t)=>e[0]-t[0]);}value(e){return this._eval.evaluate(e,true)}closest(e){let t=this.keys,i=t.length,s=2,r=null;for(let a=0;a<i;a++){let i=Math.abs(e-t[a][0]);if(s>=i)s=i,r=t[a];else break}return r}clone(){let e=new this.constructor;return e.keys=this.keys.map(e=>[...e]),e.type=this.type,e.tension=this.tension,e}quantize(e){let t=new Float32Array(e=Math.max(e,2)),i=1/(e-1);t[0]=this._eval.evaluate(0,true);for(let s=1;s<e;s++)t[s]=this._eval.evaluate(i*s);return t}quantizeClamped(e,t,i){let s=this.quantize(e);for(let e=0;e<s.length;++e)s[e]=Math.min(i,Math.max(t,s[e]));return s}constructor(e){if(this.keys=[],this.type=eb,this.tension=.5,this._eval=new eD(this),e)for(let t=0;t<e.length-1;t+=2)this.keys.push([e[t],e[t+1]]);this.sort();}}class eL{get length(){return this.curves.length}set type(e){this._type=e;for(let t=0;t<this.curves.length;t++)this.curves[t].type=e;}get type(){return this._type}get(e){return this.curves[e]}value(e,t=[]){let i=this.curves.length;t.length=i;for(let s=0;s<i;s++)t[s]=this.curves[s].value(e);return t}clone(){let e=new this.constructor;e.curves=[];for(let t=0;t<this.curves.length;t++)e.curves.push(this.curves[t].clone());return e._type=this._type,e}quantize(e){e=Math.max(e,2);let t=this.curves.length,i=new Float32Array(e*t),s=1/(e-1);for(let r=0;r<t;r++){let a=new eD(this.curves[r]);for(let n=0;n<e;n++)i[n*t+r]=a.evaluate(s*n);}return i}quantizeClamped(e,t,i){let s=this.quantize(e);for(let e=0;e<s.length;++e)s[e]=Math.min(i,Math.max(t,s[e]));return s}constructor(...e){if(this.curves=[],this._type=eb,e.length>1)for(let t=0;t<e.length;t++)this.curves.push(new eR(e[t]));else if(0===e.length)this.curves.push(new eR);else {let t=e[0];if("number"==typeof t)for(let e=0;e<t;e++)this.curves.push(new eR);else for(let e=0;e<t.length;e++)this.curves.push(new eR(t[e]));}}}let eM=new Float32Array(1),eO=new Int32Array(eM.buffer);class eF{static float2Half(e){eM[0]=e;let t=eO[0],i=t>>16&32768,s=t>>12&2047,r=t>>23&255;return r<103?i:r>142?(i|=31744,i|=+(255!==r)&&8388607&t):r<113?(s|=2048,i|=(s>>114-r)+(s>>113-r&1)):(i|=r-112<<10|s>>1,i+=1&s)}static float2RGBA8(e,t){eM[0]=e;let i=eO[0];t.r=(i>>24&255)/255,t.g=(i>>16&255)/255,t.b=(i>>8&255)/255,t.a=(255&i)/255;}}class eN{static concentric(e,t){let i=[];i.push(0,0);let s=2*Math.PI/e/t;for(let t=1;t<=e;t++){let r=t/e,a=Math.max(1,Math.floor(2*Math.PI*r/s)),n=2*Math.PI/a;for(let e=0;e<a;e++){let t=e*n,s=r*Math.cos(t),a=r*Math.sin(t);i.push(s,a);}}return i}}class eB{add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}add2(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this}addScalar(e){return this.x+=e,this.y+=e,this.z+=e,this}addScaled(e,t){return this.x+=e.x*t,this.y+=e.y*t,this.z+=e.z*t,this}clone(){return new this.constructor(this.x,this.y,this.z)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this}cross(e,t){let i=e.x,s=e.y,r=e.z,a=t.x,n=t.y,o=t.z;return this.x=s*o-n*r,this.y=r*a-o*i,this.z=i*n-a*s,this}distance(e){let t=this.x-e.x,i=this.y-e.y,s=this.z-e.z;return Math.sqrt(t*t+i*i+s*s)}div(e){return this.x/=e.x,this.y/=e.y,this.z/=e.z,this}div2(e,t){return this.x=e.x/t.x,this.y=e.y/t.y,this.z=e.z/t.z,this}divScalar(e){return this.x/=e,this.y/=e,this.z/=e,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z}equals(e){return this.x===e.x&&this.y===e.y&&this.z===e.z}equalsApprox(e,t=1e-6){return Math.abs(this.x-e.x)<t&&Math.abs(this.y-e.y)<t&&Math.abs(this.z-e.z)<t}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}lerp(e,t,i){return this.x=e.x+i*(t.x-e.x),this.y=e.y+i*(t.y-e.y),this.z=e.z+i*(t.z-e.z),this}mul(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this}mul2(e,t){return this.x=e.x*t.x,this.y=e.y*t.y,this.z=e.z*t.z,this}mulScalar(e){return this.x*=e,this.y*=e,this.z*=e,this}normalize(e=this){let t=e.x*e.x+e.y*e.y+e.z*e.z;if(t>0){let i=1/Math.sqrt(t);this.x=e.x*i,this.y=e.y*i,this.z=e.z*i;}return this}floor(e=this){return this.x=Math.floor(e.x),this.y=Math.floor(e.y),this.z=Math.floor(e.z),this}ceil(e=this){return this.x=Math.ceil(e.x),this.y=Math.ceil(e.y),this.z=Math.ceil(e.z),this}round(e=this){return this.x=Math.round(e.x),this.y=Math.round(e.y),this.z=Math.round(e.z),this}min(e){return e.x<this.x&&(this.x=e.x),e.y<this.y&&(this.y=e.y),e.z<this.z&&(this.z=e.z),this}max(e){return e.x>this.x&&(this.x=e.x),e.y>this.y&&(this.y=e.y),e.z>this.z&&(this.z=e.z),this}project(e){let t=(this.x*e.x+this.y*e.y+this.z*e.z)/(e.x*e.x+e.y*e.y+e.z*e.z);return this.x=e.x*t,this.y=e.y*t,this.z=e.z*t,this}set(e,t,i){return this.x=e,this.y=t,this.z=i,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}sub2(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z,this}subScalar(e){return this.x-=e,this.y-=e,this.z-=e,this}fromArray(e,t=0){return this.x=e[t]??this.x,this.y=e[t+1]??this.y,this.z=e[t+2]??this.z,this}toString(){return `[${this.x}, ${this.y}, ${this.z}]`}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,e}constructor(e=0,t=0,i=0){3===e.length?(this.x=e[0],this.y=e[1],this.z=e[2]):(this.x=e,this.y=t,this.z=i);}}eB.ZERO=Object.freeze(new eB(0,0,0)),eB.HALF=Object.freeze(new eB(.5,.5,.5)),eB.ONE=Object.freeze(new eB(1,1,1)),eB.UP=Object.freeze(new eB(0,1,0)),eB.DOWN=Object.freeze(new eB(0,-1,0)),eB.RIGHT=Object.freeze(new eB(1,0,0)),eB.LEFT=Object.freeze(new eB(-1,0,0)),eB.FORWARD=Object.freeze(new eB(0,0,-1)),eB.BACK=Object.freeze(new eB(0,0,1));class ek{clone(){return new this.constructor().copy(this)}copy(e){let t=e.data,i=this.data;return i[0]=t[0],i[1]=t[1],i[2]=t[2],i[3]=t[3],i[4]=t[4],i[5]=t[5],i[6]=t[6],i[7]=t[7],i[8]=t[8],this}set(e){let t=this.data;return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],this}getX(e=new eB){return e.set(this.data[0],this.data[1],this.data[2])}getY(e=new eB){return e.set(this.data[3],this.data[4],this.data[5])}getZ(e=new eB){return e.set(this.data[6],this.data[7],this.data[8])}equals(e){let t=this.data,i=e.data;return t[0]===i[0]&&t[1]===i[1]&&t[2]===i[2]&&t[3]===i[3]&&t[4]===i[4]&&t[5]===i[5]&&t[6]===i[6]&&t[7]===i[7]&&t[8]===i[8]}isIdentity(){let e=this.data;return 1===e[0]&&0===e[1]&&0===e[2]&&0===e[3]&&1===e[4]&&0===e[5]&&0===e[6]&&0===e[7]&&1===e[8]}setIdentity(){let e=this.data;return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=1,e[5]=0,e[6]=0,e[7]=0,e[8]=1,this}toString(){return `[${this.data.join(", ")}]`}transpose(e=this){let t=e.data,i=this.data;if(t===i){let e;e=t[1],i[1]=t[3],i[3]=e,e=t[2],i[2]=t[6],i[6]=e,e=t[5],i[5]=t[7],i[7]=e;}else i[0]=t[0],i[1]=t[3],i[2]=t[6],i[3]=t[1],i[4]=t[4],i[5]=t[7],i[6]=t[2],i[7]=t[5],i[8]=t[8];return this}setFromMat4(e){let t=e.data,i=this.data;return i[0]=t[0],i[1]=t[1],i[2]=t[2],i[3]=t[4],i[4]=t[5],i[5]=t[6],i[6]=t[8],i[7]=t[9],i[8]=t[10],this}setFromQuat(e){let t=e.x,i=e.y,s=e.z,r=e.w,a=t+t,n=i+i,o=s+s,l=t*a,h=t*n,c=t*o,d=i*n,u=i*o,f=s*o,p=r*a,m=r*n,_=r*o,g=this.data;return g[0]=1-(d+f),g[1]=h+_,g[2]=c-m,g[3]=h-_,g[4]=1-(l+f),g[5]=u+p,g[6]=c+m,g[7]=u-p,g[8]=1-(l+d),this}invertMat4(e){let t=e.data,i=t[0],s=t[1],r=t[2],a=t[4],n=t[5],o=t[6],l=t[8],h=t[9],c=t[10],d=c*n-o*h,u=-c*a+o*l,f=h*a-n*l,p=i*d+s*u+r*f;if(0===p)this.setIdentity();else {let e=1/p,t=this.data;t[0]=d*e,t[1]=(-c*s+r*h)*e,t[2]=(o*s-r*n)*e,t[3]=u*e,t[4]=(c*i-r*l)*e,t[5]=(-o*i+r*a)*e,t[6]=f*e,t[7]=(-h*i+s*l)*e,t[8]=(n*i-s*a)*e;}return this}transformVector(e,t=new eB){let i=this.data,{x:s,y:r,z:a}=e;return t.x=s*i[0]+r*i[3]+a*i[6],t.y=s*i[1]+r*i[4]+a*i[7],t.z=s*i[2]+r*i[5]+a*i[8],t}constructor(){this.data=new Float32Array(9),this.data[0]=this.data[4]=this.data[8]=1;}}ek.IDENTITY=Object.freeze(new ek),ek.ZERO=Object.freeze(new ek().set([0,0,0,0,0,0,0,0,0]));class eU{add(e){return this.x+=e.x,this.y+=e.y,this}add2(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this}addScalar(e){return this.x+=e,this.y+=e,this}addScaled(e,t){return this.x+=e.x*t,this.y+=e.y*t,this}clone(){return new this.constructor(this.x,this.y)}copy(e){return this.x=e.x,this.y=e.y,this}cross(e){return this.x*e.y-this.y*e.x}distance(e){let t=this.x-e.x,i=this.y-e.y;return Math.sqrt(t*t+i*i)}div(e){return this.x/=e.x,this.y/=e.y,this}div2(e,t){return this.x=e.x/t.x,this.y=e.y/t.y,this}divScalar(e){return this.x/=e,this.y/=e,this}dot(e){return this.x*e.x+this.y*e.y}equals(e){return this.x===e.x&&this.y===e.y}equalsApprox(e,t=1e-6){return Math.abs(this.x-e.x)<t&&Math.abs(this.y-e.y)<t}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}lengthSq(){return this.x*this.x+this.y*this.y}lerp(e,t,i){return this.x=e.x+i*(t.x-e.x),this.y=e.y+i*(t.y-e.y),this}mul(e){return this.x*=e.x,this.y*=e.y,this}mul2(e,t){return this.x=e.x*t.x,this.y=e.y*t.y,this}mulScalar(e){return this.x*=e,this.y*=e,this}normalize(e=this){let t=e.x*e.x+e.y*e.y;if(t>0){let i=1/Math.sqrt(t);this.x=e.x*i,this.y=e.y*i;}return this}rotate(e){let t=Math.atan2(this.x,this.y)+e*eP.DEG_TO_RAD,i=Math.sqrt(this.x*this.x+this.y*this.y);return this.x=Math.sin(t)*i,this.y=Math.cos(t)*i,this}angle(){return Math.atan2(this.x,this.y)*eP.RAD_TO_DEG}angleTo(e){return Math.atan2(this.x*e.y+this.y*e.x,this.x*e.x+this.y*e.y)*eP.RAD_TO_DEG}floor(e=this){return this.x=Math.floor(e.x),this.y=Math.floor(e.y),this}ceil(e=this){return this.x=Math.ceil(e.x),this.y=Math.ceil(e.y),this}round(e=this){return this.x=Math.round(e.x),this.y=Math.round(e.y),this}min(e){return e.x<this.x&&(this.x=e.x),e.y<this.y&&(this.y=e.y),this}max(e){return e.x>this.x&&(this.x=e.x),e.y>this.y&&(this.y=e.y),this}set(e,t){return this.x=e,this.y=t,this}sub(e){return this.x-=e.x,this.y-=e.y,this}sub2(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this}subScalar(e){return this.x-=e,this.y-=e,this}fromArray(e,t=0){return this.x=e[t]??this.x,this.y=e[t+1]??this.y,this}toString(){return `[${this.x}, ${this.y}]`}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e}static angleRad(e,t){return Math.atan2(e.x*t.y-e.y*t.x,e.x*t.x+e.y*t.y)}constructor(e=0,t=0){2===e.length?(this.x=e[0],this.y=e[1]):(this.x=e,this.y=t);}}eU.ZERO=Object.freeze(new eU(0,0)),eU.HALF=Object.freeze(new eU(.5,.5)),eU.ONE=Object.freeze(new eU(1,1)),eU.UP=Object.freeze(new eU(0,1)),eU.DOWN=Object.freeze(new eU(0,-1)),eU.RIGHT=Object.freeze(new eU(1,0)),eU.LEFT=Object.freeze(new eU(-1,0));class ez{add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this.w+=e.w,this}add2(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this.w=e.w+t.w,this}addScalar(e){return this.x+=e,this.y+=e,this.z+=e,this.w+=e,this}addScaled(e,t){return this.x+=e.x*t,this.y+=e.y*t,this.z+=e.z*t,this.w+=e.w*t,this}clone(){return new this.constructor(this.x,this.y,this.z,this.w)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w,this}div(e){return this.x/=e.x,this.y/=e.y,this.z/=e.z,this.w/=e.w,this}div2(e,t){return this.x=e.x/t.x,this.y=e.y/t.y,this.z=e.z/t.z,this.w=e.w/t.w,this}divScalar(e){return this.x/=e,this.y/=e,this.z/=e,this.w/=e,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z+this.w*e.w}equals(e){return this.x===e.x&&this.y===e.y&&this.z===e.z&&this.w===e.w}equalsApprox(e,t=1e-6){return Math.abs(this.x-e.x)<t&&Math.abs(this.y-e.y)<t&&Math.abs(this.z-e.z)<t&&Math.abs(this.w-e.w)<t}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}lerp(e,t,i){return this.x=e.x+i*(t.x-e.x),this.y=e.y+i*(t.y-e.y),this.z=e.z+i*(t.z-e.z),this.w=e.w+i*(t.w-e.w),this}mul(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this.w*=e.w,this}mul2(e,t){return this.x=e.x*t.x,this.y=e.y*t.y,this.z=e.z*t.z,this.w=e.w*t.w,this}mulScalar(e){return this.x*=e,this.y*=e,this.z*=e,this.w*=e,this}normalize(e=this){let t=e.x*e.x+e.y*e.y+e.z*e.z+e.w*e.w;if(t>0){let i=1/Math.sqrt(t);this.x=e.x*i,this.y=e.y*i,this.z=e.z*i,this.w=e.w*i;}return this}floor(e=this){return this.x=Math.floor(e.x),this.y=Math.floor(e.y),this.z=Math.floor(e.z),this.w=Math.floor(e.w),this}ceil(e=this){return this.x=Math.ceil(e.x),this.y=Math.ceil(e.y),this.z=Math.ceil(e.z),this.w=Math.ceil(e.w),this}round(e=this){return this.x=Math.round(e.x),this.y=Math.round(e.y),this.z=Math.round(e.z),this.w=Math.round(e.w),this}min(e){return e.x<this.x&&(this.x=e.x),e.y<this.y&&(this.y=e.y),e.z<this.z&&(this.z=e.z),e.w<this.w&&(this.w=e.w),this}max(e){return e.x>this.x&&(this.x=e.x),e.y>this.y&&(this.y=e.y),e.z>this.z&&(this.z=e.z),e.w>this.w&&(this.w=e.w),this}set(e,t,i,s){return this.x=e,this.y=t,this.z=i,this.w=s,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this.w-=e.w,this}sub2(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z,this.w=e.w-t.w,this}subScalar(e){return this.x-=e,this.y-=e,this.z-=e,this.w-=e,this}fromArray(e,t=0){return this.x=e[t]??this.x,this.y=e[t+1]??this.y,this.z=e[t+2]??this.z,this.w=e[t+3]??this.w,this}toString(){return `[${this.x}, ${this.y}, ${this.z}, ${this.w}]`}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,e[t+3]=this.w,e}constructor(e=0,t=0,i=0,s=0){4===e.length?(this.x=e[0],this.y=e[1],this.z=e[2],this.w=e[3]):(this.x=e,this.y=t,this.z=i,this.w=s);}}ez.ZERO=Object.freeze(new ez(0,0,0,0)),ez.HALF=Object.freeze(new ez(.5,.5,.5,.5)),ez.ONE=Object.freeze(new ez(1,1,1,1));let eV=new eU,eG=new eB,eH=new eB,eW=new eB,eX=new eB;class eY{static _getPerspectiveHalfSize(e,t,i,s,r){r?(e.x=s*Math.tan(t*Math.PI/360),e.y=e.x/i):(e.y=s*Math.tan(t*Math.PI/360),e.x=e.y*i);}add2(e,t){let i=e.data,s=t.data,r=this.data;return r[0]=i[0]+s[0],r[1]=i[1]+s[1],r[2]=i[2]+s[2],r[3]=i[3]+s[3],r[4]=i[4]+s[4],r[5]=i[5]+s[5],r[6]=i[6]+s[6],r[7]=i[7]+s[7],r[8]=i[8]+s[8],r[9]=i[9]+s[9],r[10]=i[10]+s[10],r[11]=i[11]+s[11],r[12]=i[12]+s[12],r[13]=i[13]+s[13],r[14]=i[14]+s[14],r[15]=i[15]+s[15],this}add(e){return this.add2(this,e)}clone(){return new this.constructor().copy(this)}copy(e){let t=e.data,i=this.data;return i[0]=t[0],i[1]=t[1],i[2]=t[2],i[3]=t[3],i[4]=t[4],i[5]=t[5],i[6]=t[6],i[7]=t[7],i[8]=t[8],i[9]=t[9],i[10]=t[10],i[11]=t[11],i[12]=t[12],i[13]=t[13],i[14]=t[14],i[15]=t[15],this}equals(e){let t=this.data,i=e.data;return t[0]===i[0]&&t[1]===i[1]&&t[2]===i[2]&&t[3]===i[3]&&t[4]===i[4]&&t[5]===i[5]&&t[6]===i[6]&&t[7]===i[7]&&t[8]===i[8]&&t[9]===i[9]&&t[10]===i[10]&&t[11]===i[11]&&t[12]===i[12]&&t[13]===i[13]&&t[14]===i[14]&&t[15]===i[15]}isIdentity(){let e=this.data;return 1===e[0]&&0===e[1]&&0===e[2]&&0===e[3]&&0===e[4]&&1===e[5]&&0===e[6]&&0===e[7]&&0===e[8]&&0===e[9]&&1===e[10]&&0===e[11]&&0===e[12]&&0===e[13]&&0===e[14]&&1===e[15]}mul2(e,t){let i,s,r,a,n=e.data,o=t.data,l=this.data,h=n[0],c=n[1],d=n[2],u=n[3],f=n[4],p=n[5],m=n[6],_=n[7],g=n[8],v=n[9],S=n[10],y=n[11],x=n[12],T=n[13],E=n[14],w=n[15];return i=o[0],s=o[1],r=o[2],a=o[3],l[0]=h*i+f*s+g*r+x*a,l[1]=c*i+p*s+v*r+T*a,l[2]=d*i+m*s+S*r+E*a,l[3]=u*i+_*s+y*r+w*a,i=o[4],s=o[5],r=o[6],a=o[7],l[4]=h*i+f*s+g*r+x*a,l[5]=c*i+p*s+v*r+T*a,l[6]=d*i+m*s+S*r+E*a,l[7]=u*i+_*s+y*r+w*a,i=o[8],s=o[9],r=o[10],a=o[11],l[8]=h*i+f*s+g*r+x*a,l[9]=c*i+p*s+v*r+T*a,l[10]=d*i+m*s+S*r+E*a,l[11]=u*i+_*s+y*r+w*a,i=o[12],s=o[13],r=o[14],a=o[15],l[12]=h*i+f*s+g*r+x*a,l[13]=c*i+p*s+v*r+T*a,l[14]=d*i+m*s+S*r+E*a,l[15]=u*i+_*s+y*r+w*a,this}mulAffine2(e,t){let i,s,r,a=e.data,n=t.data,o=this.data,l=a[0],h=a[1],c=a[2],d=a[4],u=a[5],f=a[6],p=a[8],m=a[9],_=a[10],g=a[12],v=a[13],S=a[14];return i=n[0],s=n[1],r=n[2],o[0]=l*i+d*s+p*r,o[1]=h*i+u*s+m*r,o[2]=c*i+f*s+_*r,o[3]=0,i=n[4],s=n[5],r=n[6],o[4]=l*i+d*s+p*r,o[5]=h*i+u*s+m*r,o[6]=c*i+f*s+_*r,o[7]=0,i=n[8],s=n[9],r=n[10],o[8]=l*i+d*s+p*r,o[9]=h*i+u*s+m*r,o[10]=c*i+f*s+_*r,o[11]=0,i=n[12],s=n[13],r=n[14],o[12]=l*i+d*s+p*r+g,o[13]=h*i+u*s+m*r+v,o[14]=c*i+f*s+_*r+S,o[15]=1,this}mul(e){return this.mul2(this,e)}transformPoint(e,t=new eB){let i=this.data,{x:s,y:r,z:a}=e;return t.x=s*i[0]+r*i[4]+a*i[8]+i[12],t.y=s*i[1]+r*i[5]+a*i[9]+i[13],t.z=s*i[2]+r*i[6]+a*i[10]+i[14],t}transformVector(e,t=new eB){let i=this.data,{x:s,y:r,z:a}=e;return t.x=s*i[0]+r*i[4]+a*i[8],t.y=s*i[1]+r*i[5]+a*i[9],t.z=s*i[2]+r*i[6]+a*i[10],t}transformVec4(e,t=new ez){let i=this.data,{x:s,y:r,z:a,w:n}=e;return t.x=s*i[0]+r*i[4]+a*i[8]+n*i[12],t.y=s*i[1]+r*i[5]+a*i[9]+n*i[13],t.z=s*i[2]+r*i[6]+a*i[10]+n*i[14],t.w=s*i[3]+r*i[7]+a*i[11]+n*i[15],t}setLookAt(e,t,i){eW.sub2(e,t).normalize(),eH.copy(i).normalize(),eG.cross(eH,eW).normalize(),eH.cross(eW,eG);let s=this.data;return s[0]=eG.x,s[1]=eG.y,s[2]=eG.z,s[3]=0,s[4]=eH.x,s[5]=eH.y,s[6]=eH.z,s[7]=0,s[8]=eW.x,s[9]=eW.y,s[10]=eW.z,s[11]=0,s[12]=e.x,s[13]=e.y,s[14]=e.z,s[15]=1,this}setFrustum(e,t,i,s,r,a){let n=2*r,o=t-e,l=s-i,h=a-r,c=this.data;return c[0]=n/o,c[1]=0,c[2]=0,c[3]=0,c[4]=0,c[5]=n/l,c[6]=0,c[7]=0,c[8]=(t+e)/o,c[9]=(s+i)/l,c[10]=(-a-r)/h,c[11]=-1,c[12]=0,c[13]=0,c[14]=-n*a/h,c[15]=0,this}setPerspective(e,t,i,s,r){return eY._getPerspectiveHalfSize(eV,e,t,i,r),this.setFrustum(-eV.x,eV.x,-eV.y,eV.y,i,s)}setOrtho(e,t,i,s,r,a){let n=this.data;return n[0]=2/(t-e),n[1]=0,n[2]=0,n[3]=0,n[4]=0,n[5]=2/(s-i),n[6]=0,n[7]=0,n[8]=0,n[9]=0,n[10]=-2/(a-r),n[11]=0,n[12]=-(t+e)/(t-e),n[13]=-(s+i)/(s-i),n[14]=-(a+r)/(a-r),n[15]=1,this}setFromAxisAngle(e,t){t*=eP.DEG_TO_RAD;let{x:i,y:s,z:r}=e,a=Math.cos(t),n=Math.sin(t),o=1-a,l=o*i,h=o*s,c=this.data;return c[0]=l*i+a,c[1]=l*s+n*r,c[2]=l*r-n*s,c[3]=0,c[4]=l*s-n*r,c[5]=h*s+a,c[6]=h*r+n*i,c[7]=0,c[8]=l*r+n*s,c[9]=h*r-i*n,c[10]=o*r*r+a,c[11]=0,c[12]=0,c[13]=0,c[14]=0,c[15]=1,this}setTranslate(e,t,i){let s=this.data;return s[0]=1,s[1]=0,s[2]=0,s[3]=0,s[4]=0,s[5]=1,s[6]=0,s[7]=0,s[8]=0,s[9]=0,s[10]=1,s[11]=0,s[12]=e,s[13]=t,s[14]=i,s[15]=1,this}setScale(e,t,i){let s=this.data;return s[0]=e,s[1]=0,s[2]=0,s[3]=0,s[4]=0,s[5]=t,s[6]=0,s[7]=0,s[8]=0,s[9]=0,s[10]=i,s[11]=0,s[12]=0,s[13]=0,s[14]=0,s[15]=1,this}setViewport(e,t,i,s){let r=this.data;return r[0]=.5*i,r[1]=0,r[2]=0,r[3]=0,r[4]=0,r[5]=.5*s,r[6]=0,r[7]=0,r[8]=0,r[9]=0,r[10]=.5,r[11]=0,r[12]=e+.5*i,r[13]=t+.5*s,r[14]=.5,r[15]=1,this}setReflection(e,t){let i=e.x,s=e.y,r=e.z,a=this.data;return a[0]=1-2*i*i,a[1]=-2*i*s,a[2]=-2*i*r,a[3]=0,a[4]=-2*i*s,a[5]=1-2*s*s,a[6]=-2*s*r,a[7]=0,a[8]=-2*i*r,a[9]=-2*s*r,a[10]=1-2*r*r,a[11]=0,a[12]=-2*i*t,a[13]=-2*s*t,a[14]=-2*r*t,a[15]=1,this}invert(e=this){let t=e.data,i=t[0],s=t[1],r=t[2],a=t[3],n=t[4],o=t[5],l=t[6],h=t[7],c=t[8],d=t[9],u=t[10],f=t[11],p=t[12],m=t[13],_=t[14],g=t[15],v=i*o-s*n,S=i*l-r*n,y=i*h-a*n,x=s*l-r*o,T=s*h-a*o,E=r*h-a*l,w=c*m-d*p,b=c*_-u*p,A=c*g-f*p,C=d*_-u*m,P=d*g-f*m,I=u*g-f*_,D=v*I-S*P+y*C+x*A-T*b+E*w;if(0===D)this.setIdentity();else {let e=1/D,t=this.data;t[0]=(o*I-l*P+h*C)*e,t[1]=(-s*I+r*P-a*C)*e,t[2]=(m*E-_*T+g*x)*e,t[3]=(-d*E+u*T-f*x)*e,t[4]=(-n*I+l*A-h*b)*e,t[5]=(i*I-r*A+a*b)*e,t[6]=(-p*E+_*y-g*S)*e,t[7]=(c*E-u*y+f*S)*e,t[8]=(n*P-o*A+h*w)*e,t[9]=(-i*P+s*A-a*w)*e,t[10]=(p*T-m*y+g*v)*e,t[11]=(-c*T+d*y-f*v)*e,t[12]=(-n*C+o*b-l*w)*e,t[13]=(i*C-s*b+r*w)*e,t[14]=(-p*x+m*S-_*v)*e,t[15]=(c*x-d*S+u*v)*e;}return this}set(e){let t=this.data;return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],this}setIdentity(){let e=this.data;return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}setTRS(e,t,i){let s=t.x,r=t.y,a=t.z,n=t.w,o=i.x,l=i.y,h=i.z,c=s+s,d=r+r,u=a+a,f=s*c,p=s*d,m=s*u,_=r*d,g=r*u,v=a*u,S=n*c,y=n*d,x=n*u,T=this.data;return T[0]=(1-(_+v))*o,T[1]=(p+x)*o,T[2]=(m-y)*o,T[3]=0,T[4]=(p-x)*l,T[5]=(1-(f+v))*l,T[6]=(g+S)*l,T[7]=0,T[8]=(m+y)*h,T[9]=(g-S)*h,T[10]=(1-(f+_))*h,T[11]=0,T[12]=e.x,T[13]=e.y,T[14]=e.z,T[15]=1,this}transpose(e=this){let t=e.data,i=this.data;if(t===i){let e;e=t[1],i[1]=t[4],i[4]=e,e=t[2],i[2]=t[8],i[8]=e,e=t[3],i[3]=t[12],i[12]=e,e=t[6],i[6]=t[9],i[9]=e,e=t[7],i[7]=t[13],i[13]=e,e=t[11],i[11]=t[14],i[14]=e;}else i[0]=t[0],i[1]=t[4],i[2]=t[8],i[3]=t[12],i[4]=t[1],i[5]=t[5],i[6]=t[9],i[7]=t[13],i[8]=t[2],i[9]=t[6],i[10]=t[10],i[11]=t[14],i[12]=t[3],i[13]=t[7],i[14]=t[11],i[15]=t[15];return this}getTranslation(e=new eB){return e.set(this.data[12],this.data[13],this.data[14])}getX(e=new eB){return e.set(this.data[0],this.data[1],this.data[2])}getY(e=new eB){return e.set(this.data[4],this.data[5],this.data[6])}getZ(e=new eB){return e.set(this.data[8],this.data[9],this.data[10])}getScale(e=new eB){return this.getX(eG),this.getY(eH),this.getZ(eW),e.set(eG.length(),eH.length(),eW.length()),e}get scaleSign(){return this.getX(eG),this.getY(eH),this.getZ(eW),eG.cross(eG,eH),0>eG.dot(eW)?-1:1}setFromEulerAngles(e,t,i){e*=eP.DEG_TO_RAD,t*=eP.DEG_TO_RAD,i*=eP.DEG_TO_RAD;let s=Math.sin(-e),r=Math.cos(-e),a=Math.sin(-t),n=Math.cos(-t),o=Math.sin(-i),l=Math.cos(-i),h=this.data;return h[0]=n*l,h[1]=-n*o,h[2]=a,h[3]=0,h[4]=r*o+l*s*a,h[5]=r*l-s*a*o,h[6]=-n*s,h[7]=0,h[8]=s*o-r*l*a,h[9]=l*s+r*a*o,h[10]=r*n,h[11]=0,h[12]=0,h[13]=0,h[14]=0,h[15]=1,this}getEulerAngles(e=new eB){let t,i;this.getScale(eX);let s=eX.x,r=eX.y,a=eX.z;if(0===s||0===r||0===a)return e.set(0,0,0);let n=this.data,o=Math.asin(-n[2]/s),l=.5*Math.PI;return o<l?o>-l?(t=Math.atan2(n[6]/r,n[10]/a),i=Math.atan2(n[1]/s,n[0]/s)):(i=0,t=-Math.atan2(n[4]/r,n[5]/r)):(i=0,t=Math.atan2(n[4]/r,n[5]/r)),e.set(t,o,i).mulScalar(eP.RAD_TO_DEG)}toString(){return `[${this.data.join(", ")}]`}constructor(){this.data=new Float32Array(16),this.data[0]=this.data[5]=this.data[10]=this.data[15]=1;}}eY.IDENTITY=Object.freeze(new eY),eY.ZERO=Object.freeze(new eY().set([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]));class eq{clone(){return new this.constructor(this.x,this.y,this.z,this.w)}conjugate(e=this){return this.x=-1*e.x,this.y=-1*e.y,this.z=-1*e.z,this.w=e.w,this}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z+this.w*e.w}equals(e){return this.x===e.x&&this.y===e.y&&this.z===e.z&&this.w===e.w}equalsApprox(e,t=1e-6){return Math.abs(this.x-e.x)<t&&Math.abs(this.y-e.y)<t&&Math.abs(this.z-e.z)<t&&Math.abs(this.w-e.w)<t}getAxisAngle(e){let t=2*Math.acos(this.w),i=Math.sin(t/2);return 0!==i?(e.x=this.x/i,e.y=this.y/i,e.z=this.z/i,(e.x<0||e.y<0||e.z<0)&&(e.x*=-1,e.y*=-1,e.z*=-1,t*=-1)):(e.x=1,e.y=0,e.z=0),t*eP.RAD_TO_DEG}getEulerAngles(e=new eB){let t,i,s,r=this.x,a=this.y,n=this.z,o=this.w,l=2*(o*a-r*n);return l<=-0.99999?(t=2*Math.atan2(r,o),i=-Math.PI/2,s=0):l>=.99999?(t=2*Math.atan2(r,o),i=Math.PI/2,s=0):(t=Math.atan2(2*(o*r+a*n),1-2*(r*r+a*a)),i=Math.asin(l),s=Math.atan2(2*(o*n+r*a),1-2*(a*a+n*n))),e.set(t,i,s).mulScalar(eP.RAD_TO_DEG)}invert(e=this){return this.conjugate(e).normalize()}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}lerp(e,t,i){let s=(1-i)*(0>e.dot(t)?-1:1);return this.x=e.x*s+t.x*i,this.y=e.y*s+t.y*i,this.z=e.z*s+t.z*i,this.w=e.w*s+t.w*i,this.normalize()}mul(e){let t=this.x,i=this.y,s=this.z,r=this.w,a=e.x,n=e.y,o=e.z,l=e.w;return this.x=r*a+t*l+i*o-s*n,this.y=r*n+i*l+s*a-t*o,this.z=r*o+s*l+t*n-i*a,this.w=r*l-t*a-i*n-s*o,this}mulScalar(e,t=this){return this.x=t.x*e,this.y=t.y*e,this.z=t.z*e,this.w=t.w*e,this}mul2(e,t){let i=e.x,s=e.y,r=e.z,a=e.w,n=t.x,o=t.y,l=t.z,h=t.w;return this.x=a*n+i*h+s*l-r*o,this.y=a*o+s*h+r*n-i*l,this.z=a*l+r*h+i*o-s*n,this.w=a*h-i*n-s*o-r*l,this}normalize(e=this){let t=e.length();return 0===t?(this.x=this.y=this.z=0,this.w=1):(t=1/t,this.x=e.x*t,this.y=e.y*t,this.z=e.z*t,this.w=e.w*t),this}set(e,t,i,s){return this.x=e,this.y=t,this.z=i,this.w=s,this}setFromAxisAngle(e,t){let i=Math.sin(t*=.5*eP.DEG_TO_RAD),s=Math.cos(t);return this.x=i*e.x,this.y=i*e.y,this.z=i*e.z,this.w=s,this}setFromEulerAngles(e,t,i){if(e instanceof eB){let s=e;e=s.x,t=s.y,i=s.z;}let s=.5*eP.DEG_TO_RAD;e*=s,t*=s,i*=s;let r=Math.sin(e),a=Math.cos(e),n=Math.sin(t),o=Math.cos(t),l=Math.sin(i),h=Math.cos(i);return this.x=r*o*h-a*n*l,this.y=a*n*h+r*o*l,this.z=a*o*l-r*n*h,this.w=a*o*h+r*n*l,this}setFromMat4(e){let t,i=e.data,s=i[0],r=i[1],a=i[2],n=i[4],o=i[5],l=i[6],h=i[8],c=i[9],d=i[10];return (s*(o*d-l*c)-r*(n*d-l*h)+a*(n*c-o*h)<0&&(s=-s,r=-r,a=-a),0==(t=s*s+r*r+a*a)||(s*=t=1/Math.sqrt(t),r*=t,a*=t,0==(t=n*n+o*o+l*l)||(n*=t=1/Math.sqrt(t),o*=t,l*=t,0==(t=h*h+c*c+d*d))))?this.set(0,0,0,1):(h*=t=1/Math.sqrt(t),c*=t,(d*=t)<0?s>o?this.set(1+s-o-d,r+n,h+a,l-c):this.set(r+n,1-s+o-d,l+c,h-a):s<-o?this.set(h+a,l+c,1-s-o+d,r-n):this.set(l-c,h-a,r-n,1+s+o+d),this.mulScalar(1/this.length()))}setFromDirections(e,t){let i=1+e.dot(t);return i<Number.EPSILON?(Math.abs(e.x)>Math.abs(e.y)?(this.x=-e.z,this.y=0,this.z=e.x):(this.x=0,this.y=-e.z,this.z=e.y),this.w=0):(this.x=e.y*t.z-e.z*t.y,this.y=e.z*t.x-e.x*t.z,this.z=e.x*t.y-e.y*t.x,this.w=i),this.normalize()}slerp(e,t,i){let s=e.x,r=e.y,a=e.z,n=e.w,o=t.x,l=t.y,h=t.z,c=t.w,d=n*c+s*o+r*l+a*h;if(d<0&&(c=-c,o=-o,l=-l,h=-h,d=-d),Math.abs(d)>=1)return this.w=n,this.x=s,this.y=r,this.z=a,this;let u=Math.acos(d),f=Math.sqrt(1-d*d);if(.001>Math.abs(f))return this.w=.5*n+.5*c,this.x=.5*s+.5*o,this.y=.5*r+.5*l,this.z=.5*a+.5*h,this;let p=Math.sin((1-i)*u)/f,m=Math.sin(i*u)/f;return this.w=n*p+c*m,this.x=s*p+o*m,this.y=r*p+l*m,this.z=a*p+h*m,this}transformVector(e,t=new eB){let i=e.x,s=e.y,r=e.z,a=this.x,n=this.y,o=this.z,l=this.w,h=l*i+n*r-o*s,c=l*s+o*i-a*r,d=l*r+a*s-n*i,u=-a*i-n*s-o*r;return t.x=h*l+-(u*a)+-(c*o)- -(d*n),t.y=c*l+-(u*n)+-(d*a)- -(h*o),t.z=d*l+-(u*o)+-(h*n)- -(c*a),t}fromArray(e,t=0){return this.x=e[t]??this.x,this.y=e[t+1]??this.y,this.z=e[t+2]??this.z,this.w=e[t+3]??this.w,this}toString(){return `[${this.x}, ${this.y}, ${this.z}, ${this.w}]`}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,e[t+3]=this.w,e}constructor(e=0,t=0,i=0,s=1){4===e.length?(this.x=e[0],this.y=e[1],this.z=e[2],this.w=e[3]):(this.x=e,this.y=t,this.z=i,this.w=s);}}eq.IDENTITY=Object.freeze(new eq(0,0,0,1)),eq.ZERO=Object.freeze(new eq(0,0,0,0));let e$=new eB,ej=new eB,eK=new eB,eZ=new eB,eQ=new eB;class eJ{add(e){let t=this.center,i=t.x,s=t.y,r=t.z,a=this.halfExtents,n=a.x,o=a.y,l=a.z,h=i-n,c=i+n,d=s-o,u=s+o,f=r-l,p=r+l,m=e.center,_=m.x,g=m.y,v=m.z,S=e.halfExtents,y=S.x,x=S.y,T=S.z,E=_-y,w=_+y,b=g-x,A=g+x,C=v-T,P=v+T;E<h&&(h=E),w>c&&(c=w),b<d&&(d=b),A>u&&(u=A),C<f&&(f=C),P>p&&(p=P),t.x=(h+c)*.5,t.y=(d+u)*.5,t.z=(f+p)*.5,a.x=(c-h)*.5,a.y=(u-d)*.5,a.z=(p-f)*.5;}copy(e){this.center.copy(e.center),this.halfExtents.copy(e.halfExtents);}clone(){return new eJ(this.center,this.halfExtents)}intersects(e){let t=this.getMax(),i=this.getMin(),s=e.getMax(),r=e.getMin();return i.x<=s.x&&t.x>=r.x&&i.y<=s.y&&t.y>=r.y&&i.z<=s.z&&t.z>=r.z}_intersectsRay(e,t){let i=e$.copy(this.getMin()).sub(e.origin),s=ej.copy(this.getMax()).sub(e.origin),r=e.direction;0===r.x?(i.x=i.x<0?-Number.MAX_VALUE:Number.MAX_VALUE,s.x=s.x<0?-Number.MAX_VALUE:Number.MAX_VALUE):(i.x/=r.x,s.x/=r.x),0===r.y?(i.y=i.y<0?-Number.MAX_VALUE:Number.MAX_VALUE,s.y=s.y<0?-Number.MAX_VALUE:Number.MAX_VALUE):(i.y/=r.y,s.y/=r.y),0===r.z?(i.z=i.z<0?-Number.MAX_VALUE:Number.MAX_VALUE,s.z=s.z<0?-Number.MAX_VALUE:Number.MAX_VALUE):(i.z/=r.z,s.z/=r.z);let a=eK.set(Math.min(i.x,s.x),Math.min(i.y,s.y),Math.min(i.z,s.z)),n=eZ.set(Math.max(i.x,s.x),Math.max(i.y,s.y),Math.max(i.z,s.z)),o=Math.min(Math.min(n.x,n.y),n.z),l=Math.max(Math.max(a.x,a.y),a.z),h=o>=l&&l>=0;return h&&t.copy(e.direction).mulScalar(l).add(e.origin),h}_fastIntersectsRay(e){let t=e.direction;return e$.sub2(e.origin,this.center),eZ.set(Math.abs(e$.x),Math.abs(e$.y),Math.abs(e$.z)),eK.mul2(e$,t),(!(eZ.x>this.halfExtents.x)||!(eK.x>=0))&&(!(eZ.y>this.halfExtents.y)||!(eK.y>=0))&&(!(eZ.z>this.halfExtents.z)||!(eK.z>=0))&&(eQ.set(Math.abs(t.x),Math.abs(t.y),Math.abs(t.z)),ej.cross(t,e$),ej.set(Math.abs(ej.x),Math.abs(ej.y),Math.abs(ej.z)),!(ej.x>this.halfExtents.y*eQ.z+this.halfExtents.z*eQ.y)&&!(ej.y>this.halfExtents.x*eQ.z+this.halfExtents.z*eQ.x)&&!(ej.z>this.halfExtents.x*eQ.y+this.halfExtents.y*eQ.x))}intersectsRay(e,t){return t?this._intersectsRay(e,t):this._fastIntersectsRay(e)}setMinMax(e,t){this.center.add2(t,e).mulScalar(.5),this.halfExtents.sub2(t,e).mulScalar(.5);}getMin(){return this._min.copy(this.center).sub(this.halfExtents)}getMax(){return this._max.copy(this.center).add(this.halfExtents)}containsPoint(e){let t=this.center,i=this.halfExtents;return !(e.x<t.x-i.x)&&!(e.x>t.x+i.x)&&!(e.y<t.y-i.y)&&!(e.y>t.y+i.y)&&!(e.z<t.z-i.z)&&!(e.z>t.z+i.z)}closestPoint(e,t=new eB){let i=this.center,s=this.halfExtents;return t.set(Math.max(i.x-s.x,Math.min(e.x,i.x+s.x)),Math.max(i.y-s.y,Math.min(e.y,i.y+s.y)),Math.max(i.z-s.z,Math.min(e.z,i.z+s.z)))}setFromTransformedAabb(e,t,i=false){let s=e.center,r=e.halfExtents,a=t.data,n=a[0],o=a[4],l=a[8],h=a[1],c=a[5],d=a[9],u=a[2],f=a[6],p=a[10];if(i){let e=n*n+o*o+l*l;if(e>0){let t=1/Math.sqrt(e);n*=t,o*=t,l*=t;}if((e=h*h+c*c+d*d)>0){let t=1/Math.sqrt(e);h*=t,c*=t,d*=t;}if((e=u*u+f*f+p*p)>0){let t=1/Math.sqrt(e);u*=t,f*=t,p*=t;}}this.center.set(a[12]+n*s.x+o*s.y+l*s.z,a[13]+h*s.x+c*s.y+d*s.z,a[14]+u*s.x+f*s.y+p*s.z),this.halfExtents.set(Math.abs(n)*r.x+Math.abs(o)*r.y+Math.abs(l)*r.z,Math.abs(h)*r.x+Math.abs(c)*r.y+Math.abs(d)*r.z,Math.abs(u)*r.x+Math.abs(f)*r.y+Math.abs(p)*r.z);}static computeMinMax(e,t,i,s=e.length/3){if(s>0){let r=e[0],a=e[1],n=e[2],o=r,l=a,h=n,c=3*s;for(let t=3;t<c;t+=3){let i=e[t],s=e[t+1],c=e[t+2];i<r&&(r=i),s<a&&(a=s),c<n&&(n=c),i>o&&(o=i),s>l&&(l=s),c>h&&(h=c);}t.set(r,a,n),i.set(o,l,h);}}compute(e,t){eJ.computeMinMax(e,e$,ej,t),this.setMinMax(e$,ej);}intersectsBoundingSphere(e){return this._distanceToBoundingSphereSq(e)<=e.radius*e.radius}_distanceToBoundingSphereSq(e){let t=this.getMin(),i=this.getMax(),s=0,r=["x","y","z"];for(let a=0;a<3;++a){let n=0,o=e.center[r[a]],l=t[r[a]],h=i[r[a]],c=0;o<l&&(n+=(c=l-o)*c),o>h&&(n+=(c=o-h)*c),s+=n;}return s}_expand(e,t){e$.add2(this.getMin(),e),ej.add2(this.getMax(),t),this.setMinMax(e$,ej);}constructor(e,t){this.center=new eB,this.halfExtents=new eB(.5,.5,.5),this._min=new eB,this._max=new eB,e&&this.center.copy(e),t&&this.halfExtents.copy(t);}}let e0=new eB,e1=new eB;class e2{containsPoint(e){let t=e0.sub2(e,this.center).lengthSq(),i=this.radius;return t<i*i}intersectsRay(e,t){let i=e0.copy(e.origin).sub(this.center),s=i.dot(e1.copy(e.direction).normalize()),r=i.dot(i)-this.radius*this.radius;if(r>0&&s>0)return false;let a=s*s-r;if(a<0)return false;let n=Math.abs(-s-Math.sqrt(a));return t&&t.copy(e.direction).mulScalar(n).add(e.origin),true}intersectsBoundingSphere(e){e0.sub2(e.center,this.center);let t=e.radius+this.radius;return e0.lengthSq()<=t*t}constructor(e=new eB,t=.5){this.center=e,this.radius=t;}}class e3{clone(){return new this.constructor().copy(this)}copy(e){return this.normal.copy(e.normal),this.distance=e.distance,this}intersectsLine(e,t,i){let s=this.distance,r=this.normal.dot(e)+s,a=r/(r-(this.normal.dot(t)+s)),n=a>=0&&a<=1;return n&&i&&i.lerp(e,t,a),n}intersectsRay(e,t){let i=this.normal.dot(e.direction);if(0===i)return false;let s=-(this.normal.dot(e.origin)+this.distance)/i;return s>=0&&t&&t.copy(e.direction).mulScalar(s).add(e.origin),s>=0}normalize(){let e=1/this.normal.length();return this.normal.mulScalar(e),this.distance*=e,this}set(e,t,i,s){return this.normal.set(e,t,i),this.distance=s,this}setFromPointNormal(e,t){return this.normal.copy(t),this.distance=-this.normal.dot(e),this}constructor(e=eB.UP,t=0){this.normal=new eB,this.normal.copy(e),this.distance=t;}}class e4{clone(){return new this.constructor().copy(this)}copy(e){for(let t=0;t<6;t++)this.planes[t].copy(e.planes[t]);return this}setFromMat4(e){let[t,i,s,r,a,n,o,l,h,c,d,u,f,p,m,_]=e.data,g=this.planes;g[0].set(r-t,l-a,u-h,_-f).normalize(),g[1].set(r+t,l+a,u+h,_+f).normalize(),g[2].set(r+i,l+n,u+c,_+p).normalize(),g[3].set(r-i,l-n,u-c,_-p).normalize(),g[4].set(r-s,l-o,u-d,_-m).normalize(),g[5].set(r+s,l+o,u+d,_+m).normalize();}containsPoint(e){for(let t=0;t<6;t++){let{normal:i,distance:s}=this.planes[t];if(i.dot(e)+s<=0)return false}return true}add(e){let t=this.planes,i=e.planes;for(let e=0;e<6;e++)i[e].distance>t[e].distance&&t[e].copy(i[e]);return this}containsSphere(e){let{center:t,radius:i}=e,s=0;for(let e=0;e<6;e++){let{normal:r,distance:a}=this.planes[e],n=r.dot(t)+a;if(n<=-i)return 0;n>i&&s++;}return 6===s?2:1}constructor(){this.planes=[];for(let e=0;e<6;e++)this.planes[e]=new e3;}}class e5{set(e,t){return this.origin.copy(e),this.direction.copy(t),this}copy(e){return this.set(e.origin,e.direction)}clone(){return new this.constructor(this.origin,this.direction)}constructor(e,t){this.origin=new eB,this.direction=eB.FORWARD.clone(),e&&this.origin.copy(e),t&&this.direction.copy(t);}}let e8=new e5,e6=new eB,e9=new e2,e7=new eY;class te{set worldTransform(e){this._worldTransform.copy(e),this._modelTransform.copy(e).invert();}get worldTransform(){return this._worldTransform}intersectsRay(e,t){if(this._modelTransform.transformPoint(e.origin,e8.origin),this._modelTransform.transformVector(e.direction,e8.direction),t){let e=this._aabb._intersectsRay(e8,t);return e7.copy(this._modelTransform).invert().transformPoint(t,t),e}return this._aabb._fastIntersectsRay(e8)}containsPoint(e){return this._modelTransform.transformPoint(e,e6),this._aabb.containsPoint(e6)}intersectsBoundingSphere(e){return this._modelTransform.transformPoint(e.center,e9.center),e9.radius=e.radius,!!this._aabb.intersectsBoundingSphere(e9)}constructor(e=new eY,t){this.halfExtents=new eB(.5,.5,.5),t&&this.halfExtents.copy(t),this._modelTransform=e.clone().invert(),this._worldTransform=e.clone(),this._aabb=new eJ(new eB,this.halfExtents);}}let tt=new eB,ti=new eB,ts=new eB,tr=new eB,ta=new eB;class tn{set(e,t,i){return this.v0.copy(e),this.v1.copy(t),this.v2.copy(i),this}intersectsRay(e,t){tt.sub2(this.v1,this.v0),ti.sub2(this.v2,this.v0),ts.cross(e.direction,ti);let i=tt.dot(ts);if(i>-1e-6&&i<1e-6)return false;let s=1/i;tr.sub2(e.origin,this.v0);let r=s*tr.dot(ts);if(r<0||r>1)return false;ta.cross(tr,tt);let a=s*e.direction.dot(ta);if(a<0||r+a>1)return false;let n=s*ti.dot(ta);return n>1e-6&&(t instanceof eB&&t.copy(e.direction).mulScalar(n).add(e.origin),true)}toString(){return `[${this.v0.toString()}, ${this.v1.toString()}, ${this.v2.toString()}]`}constructor(e=eB.ZERO,t=eB.ZERO,i=eB.ZERO){this.v0=new eB,this.v1=new eB,this.v2=new eB,this.set(e,t,i);}}let to=0,tl=1,th=2,tc=0,td=1,tu=2,tf=3,tp=4,tm=5,t_=6,tg=7,tv=8,tS=9,ty=10,tx=11,tT=12,tE=0,tw=1,tb=2,tA=3,tC=4,tP=1,tI=2,tD=4,tR=8,tL=16,tM=32,tO=64,tF=128,tN=256,tB=0,tk=1,tU=2,tz=3,tV=1,tG=2,tH=4,tW=0,tX=1,tY=2,tq=3,t$=4,tj=5,tK=0,tZ=1,tQ=2,tJ=3,t0=0,t1=1,t2=2,t3=3,t4=4,t5=5,t8=0,t6=1,t9=2,t7=3,ie=4,it=5,ii=6,is=7,ir=0,ia=1,io=2,il=[1,2,4],ih=0,ic=1,id=2,iu=3,ip=4,im=5,i_=6,ig=7,iv=8,iS=9,iy=10,ix=11,iT=12,iE=13,iw=14,ib=15,iA=16,iC=17,iP=18,iI=19,iD=20,iR=21,iL=22,iM=23,iO=24,iF=25,iN=26,iB=27,ik=28,iU=29,iz=30,iV=31,iG=32,iH=33,iW=34,iX=35,iY=36,iq=37,i$=38,ij=39,iK=40,iZ=41,iQ=42,iJ=43,i0=44,i1=45,i2=46,i3=47,i4=48,i5=49,i8=50,i6=51,i9=52,i7=53,se=54,st=55,si=56,ss=61,sr=62,sa=63,sn=64,so=65,sl=66,sh=67,sc=68,sd=69,su=70,sf=71,sp=72,sm=73,s_=74,sg=75,sv=new Map([[ih,{name:"A8",size:1,ldr:true}],[i9,{name:"R8",size:1,ldr:true}],[ic,{name:"L8",size:1,ldr:true}],[id,{name:"LA8",size:2,ldr:true}],[i7,{name:"RG8",size:2,ldr:true}],[iu,{name:"RGB565",size:2,ldr:true}],[ip,{name:"RGBA5551",size:2,ldr:true}],[im,{name:"RGBA4",size:2,ldr:true}],[i_,{name:"RGB8",size:4,ldr:true}],[ig,{name:"RGBA8",size:4,ldr:true,srgbFormat:iD}],[i8,{name:"R16F",size:2}],[i6,{name:"RG16F",size:4}],[ix,{name:"RGB16F",size:8}],[iT,{name:"RGBA16F",size:8}],[iE,{name:"RGB32F",size:16}],[iw,{name:"RGBA32F",size:16}],[ib,{name:"R32F",size:4}],[su,{name:"RG32F",size:8}],[sf,{name:"RGB9E5",size:4}],[sp,{name:"RG8S",size:2}],[sm,{name:"RGBA8S",size:4}],[s_,{name:"RGB10A2",size:4}],[sg,{name:"RGB10A2U",size:4,isUint:true}],[iA,{name:"DEPTH",size:4}],[sd,{name:"DEPTH16",size:2}],[iC,{name:"DEPTHSTENCIL",size:4}],[iP,{name:"111110F",size:4}],[iI,{name:"SRGB8",size:4,ldr:true,srgb:true}],[iD,{name:"SRGBA8",size:4,ldr:true,srgb:true}],[iV,{name:"BGRA8",size:4,ldr:true}],[sn,{name:"SBGRA8",size:4,ldr:true,srgb:true}],[iv,{name:"DXT1",blockSize:8,ldr:true,srgbFormat:se}],[iS,{name:"DXT3",blockSize:16,ldr:true,srgbFormat:st}],[iy,{name:"DXT5",blockSize:16,ldr:true,srgbFormat:si}],[iR,{name:"ETC1",blockSize:8,ldr:true}],[iL,{name:"ETC2_RGB",blockSize:8,ldr:true,srgbFormat:ss}],[iM,{name:"ETC2_RGBA",blockSize:16,ldr:true,srgbFormat:sr}],[iO,{name:"PVRTC_2BPP_RGB_1",ldr:true,blockSize:8}],[iF,{name:"PVRTC_2BPP_RGBA_1",ldr:true,blockSize:8}],[iN,{name:"PVRTC_4BPP_RGB_1",ldr:true,blockSize:8}],[iB,{name:"PVRTC_4BPP_RGBA_1",ldr:true,blockSize:8}],[ik,{name:"ASTC_4x4",blockSize:16,ldr:true,srgbFormat:sa}],[iU,{name:"ATC_RGB",blockSize:8,ldr:true}],[iz,{name:"ATC_RGBA",blockSize:16,ldr:true}],[so,{name:"BC6H_RGBF",blockSize:16}],[sl,{name:"BC6H_RGBUF",blockSize:16}],[sh,{name:"BC7_RGBA",blockSize:16,ldr:true,srgbFormat:sc}],[se,{name:"DXT1_SRGB",blockSize:8,ldr:true,srgb:true}],[st,{name:"DXT3_SRGBA",blockSize:16,ldr:true,srgb:true}],[si,{name:"DXT5_SRGBA",blockSize:16,ldr:true,srgb:true}],[ss,{name:"ETC2_SRGB",blockSize:8,ldr:true,srgb:true}],[sr,{name:"ETC2_SRGBA",blockSize:16,ldr:true,srgb:true}],[sa,{name:"ASTC_4x4_SRGB",blockSize:16,ldr:true,srgb:true}],[sc,{name:"BC7_SRGBA",blockSize:16,ldr:true,srgb:true}],[iG,{name:"R8I",size:1,isInt:true}],[iW,{name:"R16I",size:2,isInt:true}],[iY,{name:"R32I",size:4,isInt:true}],[i$,{name:"RG8I",size:2,isInt:true}],[iK,{name:"RG16I",size:4,isInt:true}],[iQ,{name:"RG32I",size:8,isInt:true}],[i0,{name:"RGBA8I",size:4,isInt:true}],[i2,{name:"RGBA16I",size:8,isInt:true}],[i4,{name:"RGBA32I",size:16,isInt:true}],[iH,{name:"R8U",size:1,isUint:true}],[iX,{name:"R16U",size:2,isUint:true}],[iq,{name:"R32U",size:4,isUint:true}],[ij,{name:"RG8U",size:2,isUint:true}],[iZ,{name:"RG16U",size:4,isUint:true}],[iJ,{name:"RG32U",size:8,isUint:true}],[i1,{name:"RGBA8U",size:4,isUint:true}],[i3,{name:"RGBA16U",size:8,isUint:true}],[i5,{name:"RGBA32U",size:16,isUint:true}]]),sS=e=>sv.get(e)?.blockSize!==void 0,sy=e=>sv.get(e)?.srgb===true,sx=e=>{let t=sv.get(e);return t?.isInt===true||t?.isUint===true},sT={sampler:"sampler2D",returnType:"vec4"},sE={sampler:"usampler2D",returnType:"uvec4"},sw={sampler:"isampler2D",returnType:"ivec4"},sb={textureType:"texture_2d<f32>",returnType:"vec4f"},sA={textureType:"texture_2d<u32>",returnType:"vec4u"},sC={textureType:"texture_2d<i32>",returnType:"vec4i"},sP=e=>{let t=sv.get(e);return t?.isUint?sE:t?.isInt?sw:sT},sI=e=>{let t=sv.get(e);return t?.isUint?sA:t?.isInt?sC:sb},sD=e=>sv.get(e)?.srgbFormat||e,sR=e=>{for(let[t,i]of sv)if(i.srgbFormat===e)return t;return e},sL=e=>{let t=sv.get(e);return !!(t?.ldr&&!t?.srgb)},sM=e=>{switch(e){case ib:case su:case iE:case iw:return Float32Array;case iY:case iQ:case i4:return Int32Array;case iq:case iJ:case i5:case sf:case s_:case sg:return Uint32Array;case iW:case iK:case i2:return Int16Array;case iX:case iZ:case i3:case iu:case ip:case im:case i8:case i6:case ix:case iT:return Uint16Array;case iG:case i$:case i0:case sp:case sm:return Int8Array;default:return Uint8Array}},sO=0,sF=1,sN=2,sB=3,sk=4,sU=5,sz=6,sV="POSITION",sG="NORMAL",sH="TANGENT",sW="BLENDWEIGHT",sX="BLENDINDICES",sY="COLOR",sq="TEXCOORD",s$="TEXCOORD0",sj="TEXCOORD1",sK="TEXCOORD2",sZ="TEXCOORD3",sQ="TEXCOORD4",sJ="TEXCOORD5",s0="TEXCOORD6",s1="TEXCOORD7",s2="ATTR0",s3="ATTR1",s4="ATTR2",s5="ATTR3",s8="ATTR4",s6="ATTR5",s9="ATTR6",s7="ATTR7",re="ATTR8",rt="ATTR9",ri="ATTR10",rs="ATTR11",rr="ATTR12",ra="ATTR13",rn="ATTR14",ro="ATTR15",rl=1,rh=0,rc=1,rd=2,ru=3,rf=4,rp=5,rm=6,r_=7,rg=0,rv=1,rS=2,ry="default",rx="rgbm",rT="rgbe",rE="rgbp",rw="swizzleGGGR",rb=0,rA=1,rC=2,rP=3,rI="1d",rD="2d",rR="2d-array",rL="cube",rM="cube-array",rO="3d",rF=0,rN=1,rB=2,rk=3,rU=4,rz="none",rV="cube",rG="equirect",rH="octahedral",rW="glsl",rX="wgsl",rY=0,rq=1,r$=2,rj=3,rK=4,rZ=5,rQ=6,rJ=7,r0=0,r1=1,r2=2,r3=3,r4=4,r5=5,r8=6,r6=7,r9=8,r7=9,ae=10,at=11,ai=12,as=13,ar=14,aa=15,an=16,ao=17,al=18,ah=19,ac=20,ad=21,au=22,af=23,ap=24,am=25,a_=26,ag=27,av=28,aS=29,ay=30,ax=31,aT=32,aE=33,aw=34,ab=35,aA=36,aC=37,aP=38,aI=39,aD=40,aR=41,aL=42,aM=43,aO=44,aF=45,aN=46,aB=47,ak=48,aU=49,az=["bool","int","float","vec2","vec3","vec4","ivec2","ivec3","ivec4","bvec2","bvec3","bvec4","mat2","mat3","mat4","sampler2D","samplerCube","","sampler2DShadow","samplerCubeShadow","sampler3D","","","","","sampler2DArray","uint","uvec2","uvec3","uvec4","","","","","","","","","","","","","isampler2D","usampler2D","isamplerCube","usamplerCube","isampler3D","usampler3D","isampler2DArray","usampler2DArray"],aV=[["bool"],["i32"],["f32"],["vec2f","vec2<f32>"],["vec3f","vec3<f32>"],["vec4f","vec4<f32>"],["vec2i","vec2<i32>"],["vec3i","vec3<i32>"],["vec4i","vec4<i32>"],["vec2<bool>"],["vec3<bool>"],["vec4<bool>"],["mat2x2f","mat2x2<f32>"],["mat3x3f","mat3x3<f32>"],["mat4x4f","mat4x4<f32>"],["texture_2d<f32>"],["texture_cube<f32>"],["array<f32>"],["texture_depth_2d"],["texture_depth_cube"],["texture_3d<f32>"],["array<vec2<f32>>"],["array<vec3<f32>>"],["array<vec4<f32>>"],["array<mat4x4<f32>>"],["texture_2d_array<f32>"],["u32"],["vec2u","vec2<u32>"],["vec3u","vec3<u32>"],["vec4u","vec4<u32>"],["array<i32>"],["array<u32>"],["array<bool>"],["array<vec2i>","array<vec2<i32>>"],["array<vec2u>","array<vec2<u32>>"],["array<vec2b>","array<vec2<bool>>"],["array<vec3i>","array<vec3<i32>>"],["array<vec3u>","array<vec3<u32>>"],["array<vec3b>","array<vec3<bool>>"],["array<vec4i>","array<vec4<i32>>"],["array<vec4u>","array<vec4<u32>>"],["array<vec4b>","array<vec4<bool>>"],["texture_2d<i32>"],["texture_2d<u32>"],["texture_cube<i32>"],["texture_cube<u32>"],["texture_3d<i32>"],["texture_3d<u32>"],["texture_2d_array<i32>"],["texture_2d_array<u32>"]],aG=new Map;aV.forEach((e,t)=>{e.forEach(e=>aG.set(e,t));});let aH=new Uint8Array([rK,rK,rQ,rQ,rQ,rQ,rK,rK,rK,rK,rK,rK,rQ,rQ,rQ,rK,rK,rQ,rK,rK,rK,rQ,rQ,rQ,rQ,rK,rZ,rZ,rZ,rZ,rK,rZ,rK,rK,rZ,rK,rK,rZ,rK,rK,rZ,rK,rK,rZ,rK,rZ,rK,rZ,rK,rZ]),aW="webgl2",aX="webgpu",aY="null",aq=1,a$=2,aj=4,aK="ldr",aZ="ldr_srgb",aQ="hdr",aJ=1,a0=2,a1=4,a2=8,a3=16,a4=32,a5=64,a8=128,a6=255,a9=0,a7=1,ne=2,nt=["view","mesh","mesh_ub"],ni="default",ns="_unused_float_uniform",nr=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Uint16Array],na=[1,1,2,2,4,4,4,2],nn=["INT8","UINT8","INT16","UINT16","INT32","UINT32","FLOAT32","FLOAT16"],no={Int8Array:rY,Uint8Array:rq,Int16Array:r$,Uint16Array:rj,Int32Array:rK,Uint32Array:rZ,Float32Array:rQ},nl=[Uint8Array,Uint16Array,Uint32Array],nh=[1,2,4],nc=new Map([["float","f32"],["vec2","vec2f"],["vec3","vec3f"],["vec4","vec4f"],["int","i32"],["ivec2","vec2i"],["ivec3","vec3i"],["ivec4","vec4i"],["uint","u32"],["uvec2","vec2u"],["uvec3","vec3u"],["uvec4","vec4u"]]),nd={};nd[sV]=0,nd[sG]=1,nd[sW]=2,nd[sX]=3,nd[sY]=4,nd[s$]=5,nd[sj]=6,nd[sK]=7,nd[sZ]=8,nd[sQ]=9,nd[sJ]=10,nd[s0]=11,nd[s1]=12,nd[sH]=13,nd[s2]=0,nd[s3]=1,nd[s4]=2,nd[s5]=3,nd[s8]=4,nd[s6]=5,nd[s9]=6,nd[s7]=7,nd[re]=8,nd[rt]=9,nd[ri]=10,nd[rs]=11,nd[rr]=12,nd[ra]=13,nd[rn]=14,nd[ro]=15;let nu=0;class nf{constructor(e,t){this.slot=-1,this.scopeId=null,this.name=e,this.visibility=t;}}class np extends nf{}class nm extends nf{constructor(e,t,i=false){super(e,t),this.format="",this.readOnly=i;}}class n_ extends nf{constructor(e,t,i=rD,s=rF,r=true,a=null){super(e,t),this.textureDimension=i,this.sampleType=s,this.hasSampler=r,this.samplerName=a??`${e}_sampler`;}}class ng extends nf{constructor(e,t=ig,i=rD,s=true,r=false){super(e,aj),this.format=t,this.textureDimension=i,this.write=s,this.read=r;}}class nv{destroy(){this.impl.destroy();}getTexture(e){let t=this.textureFormatsMap.get(e);return void 0!==t?this.textureFormats[t]:null}getStorageTexture(e){let t=this.storageTextureFormatsMap.get(e);return void 0!==t?this.storageTextureFormats[t]:null}loseContext(){}constructor(e,t){this.uniformBufferFormats=[],this.textureFormats=[],this.storageTextureFormats=[],this.storageBufferFormats=[],this.id=nu++;let i=0;t.forEach(e=>{e.slot=i++,e instanceof n_&&e.hasSampler&&i++,e instanceof np?this.uniformBufferFormats.push(e):e instanceof n_?this.textureFormats.push(e):e instanceof ng?this.storageTextureFormats.push(e):e instanceof nm&&this.storageBufferFormats.push(e);}),this.device=e;let s=e.scope;this.bufferFormatsMap=new Map,this.uniformBufferFormats.forEach((e,t)=>this.bufferFormatsMap.set(e.name,t)),this.textureFormatsMap=new Map,this.textureFormats.forEach((e,t)=>{this.textureFormatsMap.set(e.name,t),e.scopeId=s.resolve(e.name);}),this.storageTextureFormatsMap=new Map,this.storageTextureFormats.forEach((e,t)=>{this.storageTextureFormatsMap.set(e.name,t),e.scopeId=s.resolve(e.name);}),this.storageBufferFormatsMap=new Map,this.storageBufferFormats.forEach((e,t)=>{this.storageBufferFormatsMap.set(e.name,t),e.scopeId=s.resolve(e.name);}),this.impl=e.createBindGroupFormatImpl(this);}}class nS{get(e,t){return this._cache.has(e)||(this._cache.set(e,t()),e.on("destroy",()=>{this.remove(e);}),e.on("devicelost",()=>{this._cache.get(e)?.loseContext?.(e);})),this._cache.get(e)}remove(e){this._cache.get(e)?.destroy?.(e),this._cache.delete(e);}constructor(){this._cache=new Map;}}class ny{static calcLevelDimension(e,t){return Math.max(e>>t,1)}static calcMipLevelsCount(e,t,i=1){return 1+Math.floor(Math.log2(Math.max(e,t,i)))}static calcLevelGpuSize(e,t,i,s){let r=sv.get(s),a=sv.get(s)?.size??0;if(a>0)return e*t*i*a;let n=r.blockSize??0,o=Math.floor((e+3)/4),l=Math.floor((t+3)/4),h=Math.floor((i+3)/4);return (s===iO||s===iF)&&(o=Math.max(Math.floor(o/2),1)),o*l*h*n}static calcGpuSize(e,t,i,s,r,a){let n=0;for(;n+=ny.calcLevelGpuSize(e,t,i,s),r&&(1!==e||1!==t||1!==i);)e=Math.max(e>>1,1),t=Math.max(t>>1,1),i=Math.max(i>>1,1);return n*(a?6:1)}}class nx{get(e){let t=this.map.get(e);return void 0===t&&(t=this.id++,this.map.set(e,t)),t}constructor(){this.map=new Map,this.id=0;}}let nT=new nx;class nE{constructor(e,t=0,i=1,s=0,r=1){this.texture=e,this.baseMipLevel=t,this.mipLevelCount=i,this.baseArrayLayer=s,this.arrayLayerCount=r,this.key=nT.get(`${t}:${i}:${s}:${r}`);}}let nw=0;class nb{destroy(){let e=this.device;e&&(e.onTextureDestroyed(this),this.impl.destroy(e),this.adjustVramSizeTracking(e._vram,-this._gpuSize),this._levels=null,this.device=null);}recreateImpl(e=true){let{device:t}=this;this.impl?.destroy(t),this.impl=null,this.impl=t.createTextureImpl(this),this.dirtyAll(),e&&this.upload();}_clearLevels(){this._levels=this._cubemap?[[null,null,null,null,null,null]]:[null];}resize(e,t,i=1){if(this.width!==e||this.height!==t||this.depth!==i){let s=this.device;this.adjustVramSizeTracking(s._vram,-this._gpuSize),this._gpuSize=0,this.impl.destroy(s),this._clearLevels(),this._width=Math.floor(e),this._height=Math.floor(t),this._depth=Math.floor(i),this._updateNumLevel(),this.impl=s.createTextureImpl(this),this.dirtyAll();}}loseContext(){this.impl.loseContext(),this.dirtyAll();}adjustVramSizeTracking(e,t){e.tex+=t;}propertyChanged(e){this.impl.propertyChanged(e),this.renderVersionDirty=this.device.renderVersion;}_updateNumLevel(){let e=this.mipmaps?ny.calcMipLevelsCount(this.width,this.height):1,t=this._numLevelsRequested;this._numLevels=Math.min(t??e,e),this._mipmaps=this._numLevels>1;}get lockedMode(){return this._lockedMode}set minFilter(e){this._minFilter!==e&&(sx(this._format)||(this._minFilter=e,this.propertyChanged(aJ)));}get minFilter(){return this._minFilter}set magFilter(e){this._magFilter!==e&&(sx(this._format)||(this._magFilter=e,this.propertyChanged(a0)));}get magFilter(){return this._magFilter}set addressU(e){this._addressU!==e&&(this._addressU=e,this.propertyChanged(a1));}get addressU(){return this._addressU}set addressV(e){this._addressV!==e&&(this._addressV=e,this.propertyChanged(a2));}get addressV(){return this._addressV}set addressW(e){this._volume&&e!==this._addressW&&(this._addressW=e,this.propertyChanged(a3));}get addressW(){return this._addressW}set compareOnRead(e){this._compareOnRead!==e&&(this._compareOnRead=e,this.propertyChanged(a4));}get compareOnRead(){return this._compareOnRead}set compareFunc(e){this._compareFunc!==e&&(this._compareFunc=e,this.propertyChanged(a5));}get compareFunc(){return this._compareFunc}set anisotropy(e){this._anisotropy!==e&&(this._anisotropy=e,this.propertyChanged(a8));}get anisotropy(){return this._anisotropy}set mipmaps(e){this._mipmaps!==e&&(this.device.isWebGPU||sx(this._format)||(this._mipmaps=e),e&&(this._needsMipmapsUpload=true,this.device?.texturesToUpload?.add(this)));}get mipmaps(){return this._mipmaps}get numLevels(){return this._numLevels}get storage(){return this._storage}get width(){return this._width}get height(){return this._height}get depth(){return this._depth}get format(){return this._format}get cubemap(){return this._cubemap}get gpuSize(){let e=this.pot&&this._mipmaps&&!(this._compressed&&1===this._levels.length);return ny.calcGpuSize(this._width,this._height,this._depth,this._format,e,this._cubemap)}get array(){return this._arrayLength>0}get arrayLength(){return this._arrayLength}get volume(){return this._volume}set type(e){this._type!==e&&(this._type=e,this.device._shadersDirty=true);}get type(){return this._type}set srgb(e){if(e!==sy(this.format))if(e){let e=sD(this.format);this._format!==e&&(this._format=e,this.recreateImpl(),this.device._shadersDirty=true);}else {let e=sR(this.format);this._format!==e&&(this._format=e,this.recreateImpl(),this.device._shadersDirty=true);}}get srgb(){return sy(this.format)}set flipY(e){this._flipY!==e&&(this._flipY=e,this.markForUpload());}get flipY(){return this._flipY}set premultiplyAlpha(e){this._premultiplyAlpha!==e&&(this._premultiplyAlpha=e,this.markForUpload());}get premultiplyAlpha(){return this._premultiplyAlpha}get pot(){return eP.powerOfTwo(this._width)&&eP.powerOfTwo(this._height)}get encoding(){switch(this.type){case rx:return "rgbm";case rT:return "rgbe";case rE:return "rgbp"}return sL(this.format)?"srgb":"linear"}dirtyAll(){this._levelsUpdated=this._cubemap?[[true,true,true,true,true,true]]:[true],this.markForUpload(),this._needsMipmapsUpload=this._mipmaps,this._mipmapsUploaded=false,this.propertyChanged(a6);}lock(e={}){e.level??(e.level=0),e.face??(e.face=0),e.mode??(e.mode=rS),this._lockedMode=e.mode,this._lockedLevel=e.level;let t=this.cubemap?this._levels[e.face]:this._levels;if(null===t[e.level]){let i=Math.max(1,this._width>>e.level),s=Math.max(1,this._height>>e.level),r=Math.max(1,this._depth>>e.level),a=new ArrayBuffer(ny.calcLevelGpuSize(i,s,r,this._format));t[e.level]=new(sM(this._format))(a);}return t[e.level]}setSource(e,t=0){let i,s,r=false;if(this._cubemap){if(e[0]){i=e[0].width||0,s=e[0].height||0;for(let t=0;t<6;t++){let a=e[t];if(!a||a.width!==i||a.height!==s||!this.device._isBrowserInterface(a)){r=true;break}}}else r=true;if(!r)for(let i=0;i<6;i++)this._levels[t][i]!==e[i]&&(this._levelsUpdated[t][i]=true);}else this.device._isBrowserInterface(e)||(r=true),r||(e!==this._levels[t]&&(this._levelsUpdated[t]=true),e instanceof HTMLVideoElement?(i=e.videoWidth,s=e.videoHeight):(i=e.width,s=e.height));if(r)if(this._width=4,this._height=4,this._cubemap)for(let e=0;e<6;e++)this._levels[t][e]=null,this._levelsUpdated[t][e]=true;else this._levels[t]=null,this._levelsUpdated[t]=true;else 0===t&&(this._width=i,this._height=s),this._levels[t]=e;this._invalid===r&&r||(this._invalid=r,this.upload());}getSource(e=0){return this._levels[e]}unlock(){this._lockedMode,this._lockedMode===rS&&this.upload(),this._lockedLevel=-1,this._lockedMode=rg;}markForUpload(){this._needsUpload=true,this.device?.texturesToUpload?.add(this);}upload(){this.markForUpload(),this._needsMipmapsUpload=this._mipmaps,this.impl.uploadImmediate?.(this.device,this);}read(e,t,i,s,r={}){return this.impl.read?.(e,t,i,s,r)}write(e,t,i,s,r){return this.impl.write?.(e,t,i,s,r)}getView(e=0,t=1,i=0,s=1){return new nE(this,e,t,i,s)}constructor(e,t={}){this._gpuSize=0,this.id=nw++,this._invalid=false,this._lockedLevel=-1,this._lockedMode=rg,this.renderVersionDirty=0,this._storage=false,this._numLevels=0,this.device=e,this.name=t.name??"",this._width=Math.floor(t.width??4),this._height=Math.floor(t.height??4),this._format=t.format??ig,this._compressed=sS(this._format),this._integerFormat=sx(this._format),this._integerFormat&&(t.minFilter=t0,t.magFilter=t0),this._volume=t.volume??false,this._depth=Math.floor(t.depth??1),this._arrayLength=Math.floor(t.arrayLength??0),this._storage=t.storage??false,this._cubemap=t.cubemap??false,this._flipY=t.flipY??false,this._premultiplyAlpha=t.premultiplyAlpha??false,this._mipmaps=t.mipmaps??true,this._numLevelsRequested=t.numLevels,void 0!==t.numLevels&&(this._numLevels=t.numLevels),this._updateNumLevel(),this._minFilter=t.minFilter??t5,this._magFilter=t.magFilter??t1,this._anisotropy=t.anisotropy??1,this._addressU=t.addressU??to,this._addressV=t.addressV??to,this._addressW=t.addressW??to,this._compareOnRead=t.compareOnRead??false,this._compareFunc=t.compareFunc??t6,this._type=t.type??ry,this.projection=rz,this._cubemap?this.projection=rV:t.projection&&t.projection!==rV&&(this.projection=t.projection),this._levels=t.levels;let i=!!t.levels;this._levels||this._clearLevels(),this.recreateImpl(i);}}let nA={white:[255,255,255,255],gray:[128,128,128,255],black:[0,0,0,255],normal:[128,128,255,255],pink:[255,128,255,255]};class nC{destroy(){this.map.forEach(e=>{e.destroy();});}constructor(){this.map=new Map;}}let nP=new nS,nI=(e,t)=>{let i=nP.get(e,()=>new nC);if(!i.map.has(t)){let s=new nb(e,{name:`built-in-texture-${t}`,width:1,height:1,format:ig}),r=s.lock(),a=nA[t];r.set(a),s.unlock(),i.map.set(t,s);}return i.map.get(t)},nD=0;class nR{constructor(){this.offsets=[];}}class nL{destroy(){this.impl.destroy(),this.impl=null,this.format=null,this.defaultUniformBuffer=null;}setUniformBuffer(e,t){let i=this.format.bufferFormatsMap.get(e);this.uniformBuffers[i]!==t&&(this.uniformBuffers[i]=t,this.dirty=true);}setStorageBuffer(e,t){let i=this.format.storageBufferFormatsMap.get(e);this.storageBuffers[i]!==t&&(this.storageBuffers[i]=t,this.dirty=true);}setTexture(e,t){let i=this.format.textureFormatsMap.get(e),s=t instanceof nE?t.texture:t;this.textures[i]!==t?(this.textures[i]=t,this.dirty=true):this.renderVersionUpdated<s.renderVersionDirty&&(this.dirty=true);}setStorageTexture(e,t){let i=this.format.storageTextureFormatsMap.get(e),s=t instanceof nE?t.texture:t;this.storageTextures[i]!==t?(this.storageTextures[i]=t,this.dirty=true):this.renderVersionUpdated<s.renderVersionDirty&&(this.dirty=true);}updateUniformBuffers(){for(let e=0;e<this.uniformBuffers.length;e++)this.uniformBuffers[e].update();}update(){let{textureFormats:e,storageTextureFormats:t,storageBufferFormats:i}=this.format;for(let t=0;t<e.length;t++){let i=e[t],s=i.scopeId.value;!s&&("uSceneDepthMap"===i.name&&(s=nI(this.device,"white")),"uSceneColorMap"===i.name&&(s=nI(this.device,"pink")),s||(s=nI(this.device,"pink"))),this.setTexture(i.name,s);}for(let e=0;e<t.length;e++){let i=t[e],s=i.scopeId.value;this.setStorageTexture(i.name,s);}for(let e=0;e<i.length;e++){let t=i[e],s=t.scopeId.value;this.setStorageBuffer(t.name,s);}this.uniformBufferOffsets.length=this.uniformBuffers.length;for(let e=0;e<this.uniformBuffers.length;e++){let t=this.uniformBuffers[e];this.uniformBufferOffsets[e]=t.offset,this.renderVersionUpdated<t.renderVersionDirty&&(this.dirty=true);}this.dirty&&(this.dirty=false,this.renderVersionUpdated=this.device.renderVersion,this.impl.update(this));}constructor(e,t,i){this.renderVersionUpdated=-1,this.uniformBufferOffsets=[],this.id=nD++,this.device=e,this.format=t,this.dirty=true,this.impl=e.createBindGroupImpl(this),this.textures=[],this.storageTextures=[],this.storageBuffers=[],this.uniformBuffers=[],this.defaultUniformBuffer=i,i&&this.setUniformBuffer(ni,i);}}let nM={set:(e,t,i,s=1)=>e&~(s<<i)|t<<i,get:(e,t,i=1)=>e>>t&i,all(e,t,i=1){let s=i<<t;return (e&s)===s},any:(e,t,i=1)=>(e&i<<t)!=0};class nO{set blend(e){this.target0=nM.set(this.target0,+!!e,26);}get blend(){return nM.all(this.target0,26)}setColorBlend(e,t,i){this.target0=nM.set(this.target0,e,0,7),this.target0=nM.set(this.target0,t,3,15),this.target0=nM.set(this.target0,i,7,15);}setAlphaBlend(e,t,i){this.target0=nM.set(this.target0,e,11,7),this.target0=nM.set(this.target0,t,14,15),this.target0=nM.set(this.target0,i,18,15);}setColorWrite(e,t,i,s){this.redWrite=e,this.greenWrite=t,this.blueWrite=i,this.alphaWrite=s;}get colorOp(){return nM.get(this.target0,0,7)}get colorSrcFactor(){return nM.get(this.target0,3,15)}get colorDstFactor(){return nM.get(this.target0,7,15)}get alphaOp(){return nM.get(this.target0,11,7)}get alphaSrcFactor(){return nM.get(this.target0,14,15)}get alphaDstFactor(){return nM.get(this.target0,18,15)}set redWrite(e){this.target0=nM.set(this.target0,+!!e,22);}get redWrite(){return nM.all(this.target0,22)}set greenWrite(e){this.target0=nM.set(this.target0,+!!e,23);}get greenWrite(){return nM.all(this.target0,23)}set blueWrite(e){this.target0=nM.set(this.target0,+!!e,24);}get blueWrite(){return nM.all(this.target0,24)}set alphaWrite(e){this.target0=nM.set(this.target0,+!!e,25);}get alphaWrite(){return nM.all(this.target0,25)}get allWrite(){return nM.get(this.target0,22,15)}copy(e){return this.target0=e.target0,this}clone(){return new this.constructor().copy(this)}get key(){return this.target0}equals(e){return this.target0===e.target0}constructor(e=false,t=tE,i=td,s=tc,r,a,n,o=true,l=true,h=true,c=true){this.target0=0,this.setColorBlend(t,i,s),this.setAlphaBlend(r??t,a??i,n??s),this.setColorWrite(o,l,h,c),this.blend=e;}}nO.NOBLEND=Object.freeze(new nO),nO.NOWRITE=Object.freeze(new nO(void 0,void 0,void 0,void 0,void 0,void 0,void 0,false,false,false,false)),nO.ALPHABLEND=Object.freeze(new nO(true,tE,t_,tv)),nO.ADDBLEND=Object.freeze(new nO(true,tE,td,td));let nF=new nx;class nN{set test(e){this.func=e?t7:is,this.updateKey();}get test(){return this.func!==is}set write(e){this.data=nM.set(this.data,+!!e,3),this.updateKey();}get write(){return nM.all(this.data,3)}set func(e){this.data=nM.set(this.data,e,0,7),this.updateKey();}get func(){return nM.get(this.data,0,7)}set depthBias(e){this._depthBias=e,this.updateKey();}get depthBias(){return this._depthBias}set depthBiasSlope(e){this._depthBiasSlope=e,this.updateKey();}get depthBiasSlope(){return this._depthBiasSlope}copy(e){return this.data=e.data,this._depthBias=e._depthBias,this._depthBiasSlope=e._depthBiasSlope,this.key=e.key,this}clone(){return new this.constructor().copy(this)}updateKey(){let{data:e,_depthBias:t,_depthBiasSlope:i}=this,s=`${e}-${t}-${i}`;this.key=nF.get(s);}equals(e){return this.key===e.key}constructor(e=t7,t=true){this.data=0,this._depthBias=0,this._depthBiasSlope=0,this.key=0,this.func=e,this.write=t;}}nN.DEFAULT=Object.freeze(new nN),nN.NODEPTH=Object.freeze(new nN(is,false)),nN.WRITEDEPTH=Object.freeze(new nN(is,true));class nB{equals(e){return this.globalId===e.globalId&&this.revision===e.revision}copy(e){this.globalId=e.globalId,this.revision=e.revision;}reset(){this.globalId=0,this.revision=0;}constructor(){this.globalId=0,this.revision=0;}}let nk=0;class nU{increment(){this.version.revision++;}constructor(){nk++,this.version=new nB,this.version.globalId=nk;}}class nz{toJSON(e){}setValue(e){this.value=e,this.versionObject.increment();}getValue(){return this.value}constructor(e){this.name=e,this.value=null,this.versionObject=new nU;}}class nV{resolve(e){return this.variables.has(e)||this.variables.set(e,new nz(e)),this.variables.get(e)}removeValue(e){for(let t of this.variables.values())t.value===e&&(t.value=null);}constructor(e){this.name=e,this.variables=new Map;}}let nG=0;class nH{destroy(){let e=this.device;e.buffers.delete(this),this.impl.initialized&&(this.impl.destroy(e),this.adjustVramSizeTracking(e._vram,-this.storage.byteLength));}adjustVramSizeTracking(e,t){e.vb+=t;}loseContext(){this.impl.loseContext();}getFormat(){return this.format}getUsage(){return this.usage}getNumVertices(){return this.numVertices}lock(){return this.storage}unlock(){this.impl.unlock(this);}setData(e){return e.byteLength===this.numBytes&&(this.storage=e,this.unlock(),true)}constructor(e,t,i,s){this.usage=tB,this.usage=s?.usage??tB,this.device=e,this.format=t,this.numVertices=i,this.id=nG++,this.impl=e.createVertexBufferImpl(this,t,s),this.numBytes=t.verticesByteSize?t.verticesByteSize:t.size*i,this.adjustVramSizeTracking(e._vram,this.numBytes);let r=s?.data;r?this.setData(r):this.storage=new ArrayBuffer(this.numBytes),this.device.buffers.add(this);}}function nW(e){if(null==e)return 0;let t=0;for(let i=0,s=e.length;i<s;i++)t=(t<<5)-t+e.charCodeAt(i)|0;return t}function nX(e){let t=0x811c9dc5;for(let i=0;i<e.length;i++)t^=e[i],t*=0x1000193;return t>>>0}let nY=new nx,nq=[2,4,8,12,16],n$=new nS;class nj{get elements(){return this._elements}static getDefaultInstancingFormat(e){return n$.get(e,()=>new nj(e,[{semantic:rs,components:4,type:rQ},{semantic:rr,components:4,type:rQ},{semantic:rn,components:4,type:rQ},{semantic:ro,components:4,type:rQ}]))}static isElementValid(e,t){let i=t.components*na[t.type];return !e.isWebGPU||!!nq.includes(i)}update(){this._evaluateHash();}_evaluateHash(){let e=[],t=[],i=this._elements.length;for(let s=0;s<i;s++){let{name:i,dataType:r,numComponents:a,normalize:n,offset:o,stride:l,size:h,asInt:c}=this._elements[s],d=i+r+a+n+c;e.push(d);let u=d+o+l+h;t.push(u);}e.sort();let s=e.join();this.batchingHash=nW(s),this.shaderProcessingHashString=s,this.renderingHashString=t.join("_"),this.renderingHash=nY.get(this.renderingHashString);}constructor(e,t,i){this.device=e,this._elements=[],this.hasUv0=false,this.hasUv1=false,this.hasColor=false,this.hasTangents=false,this.verticesByteSize=0,this.vertexCount=i,this.interleaved=void 0===i,this.instancing=false,this.size=t.reduce((e,t)=>e+4*Math.ceil(t.components*na[t.type]/4),0);let s=0,r;for(let e=0,a=t.length;e<a;e++){let a=t[e];r=a.components*na[a.type],i&&(s=eP.roundUp(s,r));let n=a.asInt??false,o=!n&&(a.normalize??false),l={name:a.semantic,offset:i?s:a.hasOwnProperty("offset")?a.offset:s,stride:i?r:a.hasOwnProperty("stride")?a.stride:this.size,dataType:a.type,numComponents:a.components,normalize:o,size:r,asInt:n};this._elements.push(l),i?s+=r*i:s+=4*Math.ceil(r/4),a.semantic===s$?this.hasUv0=true:a.semantic===sj?this.hasUv1=true:a.semantic===sY?this.hasColor=true:a.semantic===sH&&(this.hasTangents=true);}i&&(this.verticesByteSize=s),this._evaluateHash();}}let nK=new nx;class nZ{set func(e){this._func=e,this._dirty=true;}get func(){return this._func}set ref(e){this._ref=e,this._dirty=true;}get ref(){return this._ref}set fail(e){this._fail=e,this._dirty=true;}get fail(){return this._fail}set zfail(e){this._zfail=e,this._dirty=true;}get zfail(){return this._zfail}set zpass(e){this._zpass=e,this._dirty=true;}get zpass(){return this._zpass}set readMask(e){this._readMask=e,this._dirty=true;}get readMask(){return this._readMask}set writeMask(e){this._writeMask=e,this._dirty=true;}get writeMask(){return this._writeMask}_evalKey(){let{_func:e,_ref:t,_fail:i,_zfail:s,_zpass:r,_readMask:a,_writeMask:n}=this,o=`${e},${t},${i},${s},${r},${a},${n}`;this._key=nK.get(o),this._dirty=false;}get key(){return this._dirty&&this._evalKey(),this._key}copy(e){return this._func=e._func,this._ref=e._ref,this._readMask=e._readMask,this._writeMask=e._writeMask,this._fail=e._fail,this._zfail=e._zfail,this._zpass=e._zpass,this._dirty=e._dirty,this._key=e._key,this}clone(){return new this.constructor().copy(this)}constructor(e={}){this._dirty=true,this._func=e.func??is,this._ref=e.ref??0,this._readMask=e.readMask??255,this._writeMask=e.writeMask??255,this._fail=e.fail??rh,this._zfail=e.zfail??rh,this._zpass=e.zpass??rh,this._evalKey();}}nZ.DEFAULT=Object.freeze(new nZ);class nQ extends eu{postInit(){let e=new nj(this,[{semantic:sV,components:2,type:rQ}]),t=new Float32Array([-1,-1,1,-1,-1,1,1,1]);this.quadVertexBuffer=new nH(this,e,4,{data:t});}initCapsDefines(){let{capsDefines:e}=this;e.clear(),this.textureFloatFilterable&&e.set("CAPS_TEXTURE_FLOAT_FILTERABLE",""),this.textureFloatRenderable&&e.set("CAPS_TEXTURE_FLOAT_RENDERABLE",""),this.supportsMultiDraw&&e.set("CAPS_MULTI_DRAW",""),this.supportsPrimitiveIndex&&e.set("CAPS_PRIMITIVE_INDEX",""),ea.desktop&&e.set("PLATFORM_DESKTOP",""),ea.mobile&&e.set("PLATFORM_MOBILE",""),ea.android&&e.set("PLATFORM_ANDROID",""),ea.ios&&e.set("PLATFORM_IOS","");}destroy(){this.fire("destroy"),this.quadVertexBuffer?.destroy(),this.quadVertexBuffer=null,this.dynamicBuffers?.destroy(),this.dynamicBuffers=null,this.gpuProfiler?.destroy(),this.gpuProfiler=null,this._destroyed=true;}onDestroyShader(e){this.fire("destroy:shader",e);let t=this.shaders.indexOf(e);-1!==t&&this.shaders.splice(t,1);}onTextureDestroyed(e){this.textures.delete(e),this.texturesToUpload.delete(e),this.scope.removeValue(e);}postDestroy(){this.scope=null,this.canvas=null;}loseContext(){for(let e of(this.contextLost=true,this.backBufferSize.set(-1,-1),this.textures))e.loseContext();for(let e of this.buffers)e.loseContext();for(let e of this.targets)e.loseContext();this.gpuProfiler?.loseContext();}restoreContext(){for(let e of(this.contextLost=false,this.initializeRenderState(),this.initializeContextCaches(),this.buffers))e.unlock();this.gpuProfiler?.restoreContext?.();}toJSON(e){}initializeContextCaches(){this.vertexBuffers=[],this.shader=null,this.shaderValid=void 0,this.shaderAsyncCompile=false,this.renderTarget=null;}initializeRenderState(){this.blendState=new nO,this.depthState=new nN,this.cullMode=tZ,this.vx=this.vy=this.vw=this.vh=0,this.sx=this.sy=this.sw=this.sh=0,this.blendColor=new eI(0,0,0,0);}setStencilState(e,t){}setBlendState(e){}setBlendColor(e,t,i,s){}setDepthState(e){}setCullMode(e){}setRenderTarget(e){this.renderTarget=e;}setVertexBuffer(e){e&&this.vertexBuffers.push(e);}clearVertexBuffer(){this.vertexBuffers.length=0;}getIndirectDrawSlot(e=1){return 0}get indirectDrawBuffer(){return null}getIndirectDispatchSlot(e=1){return 0}get indirectDispatchBuffer(){return null}getRenderTarget(){return this.renderTarget}initRenderTarget(e){e.initialized||(e.init(),this.targets.add(e));}draw(e,t,i,s,r=true,a=true){}_isBrowserInterface(e){return this._isImageBrowserInterface(e)||this._isImageCanvasInterface(e)||this._isImageVideoInterface(e)}_isImageBrowserInterface(e){return "undefined"!=typeof ImageBitmap&&e instanceof ImageBitmap||"undefined"!=typeof HTMLImageElement&&e instanceof HTMLImageElement}_isImageCanvasInterface(e){return "undefined"!=typeof HTMLCanvasElement&&e instanceof HTMLCanvasElement}_isImageVideoInterface(e){return "undefined"!=typeof HTMLVideoElement&&e instanceof HTMLVideoElement}resizeCanvas(e,t){let i=Math.min(this._maxPixelRatio,ea.browser?window.devicePixelRatio:1),s=Math.floor(e*i),r=Math.floor(t*i);(s!==this.canvas.width||r!==this.canvas.height)&&this.setResolution(s,r);}setResolution(e,t){this.canvas.width=e,this.canvas.height=t,this.fire(nQ.EVENT_RESIZE,e,t);}update(){this.updateClientRect();}updateClientRect(){if(ea.worker)this.clientRect.width=this.canvas.width,this.clientRect.height=this.canvas.height;else {let e=this.canvas.getBoundingClientRect();this.clientRect.width=e.width,this.clientRect.height=e.height;}}get width(){return this.canvas.width}get height(){return this.canvas.height}set fullscreen(e){}get fullscreen(){return false}set maxPixelRatio(e){this._maxPixelRatio=e;}get maxPixelRatio(){return this._maxPixelRatio}get deviceType(){return this._deviceType}startRenderPass(e){}endRenderPass(e){}startComputePass(e){}endComputePass(){}frameStart(){this.renderPassIndex=0,this.renderVersion++;}frameEnd(){this.mapsToClear.forEach(e=>e.clear()),this.mapsToClear.clear();}computeDispatch(e,t="Unnamed"){}getRenderableHdrFormat(e=[iP,iT,iw],t=true,i=1){for(let s=0;s<e.length;s++){let r=e[s];switch(r){case iP:if(this.textureRG11B10Renderable)return r;break;case iT:if(this.textureHalfFloatRenderable)return r;break;case iw:if(this.isWebGPU&&i>1)continue;if(this.textureFloatRenderable&&(!t||this.textureFloatFilterable))return r}}}validateAttributes(e,t,i){}constructor(e,t){var i,s,r,a,n,o;super(),this.backBuffer=null,this.backBufferSize=new eU,this.backBufferAntialias=false,this.isWebGPU=false,this.isWebGL2=false,this.isNull=false,this.isHdr=false,this.maxIndirectDrawCount=1024,this.maxIndirectDispatchCount=256,this.maxColorAttachments=1,this.maxSamples=1,this.supportsMultiDraw=true,this.supportsCompute=false,this.supportsStorageTextureRead=false,this.supportsSubgroupUniformity=false,this.supportsSubgroupId=false,this.renderTarget=null,this.shaders=[],this.textures=new Set,this.texturesToUpload=new Set,this.targets=new Set,this.renderVersion=0,this.insideRenderPass=false,this.supportsUniformBuffers=false,this.supportsClipDistances=false,this.supportsPrimitiveIndex=false,this.textureRG11B10Renderable=false,this.textureFloatFilterable=false,this.blendState=new nO,this.depthState=new nN,this.stencilEnabled=false,this.stencilFront=new nZ,this.stencilBack=new nZ,this._destroyed=false,this.defaultClearOptions={color:[0,0,0,1],depth:1,stencil:0,flags:tV|tG},this.clientRect={width:0,height:0},this._shadersDirty=false,this.capsDefines=new Map,this.mapsToClear=new Set,this.canvas=e,"setAttribute"in e&&e.setAttribute("data-engine",`PlayCanvas ${X}`),this.initOptions={...t},(i=this.initOptions).alpha??(i.alpha=true),(s=this.initOptions).depth??(s.depth=true),(r=this.initOptions).stencil??(r.stencil=true),(a=this.initOptions).antialias??(a.antialias=true),(n=this.initOptions).powerPreference??(n.powerPreference="high-performance"),(o=this.initOptions).displayFormat??(o.displayFormat=aK),this._maxPixelRatio=ea.browser?Math.min(1,window.devicePixelRatio):1,this.buffers=new Set,this._vram={tex:0,vb:0,ib:0,ub:0,sb:0},this._shaderStats={vsCompiled:0,fsCompiled:0,linked:0,materialShaders:0,compileTime:0},this.initializeContextCaches(),this._drawCallsPerFrame=0,this._shaderSwitchesPerFrame=0,this._primsPerFrame=[];for(let e=sO;e<=sz;e++)this._primsPerFrame[e]=0;this._renderTargetCreationTime=0,this.scope=new nV("Device"),this.textureBias=this.scope.resolve("textureBias"),this.textureBias.setValue(0);}}nQ.EVENT_RESIZE="resizecanvas";let nJ=0;class n0{destroy(){let e=this._device;e&&(e.targets.delete(this),e.renderTarget===this&&e.setRenderTarget(null),this.destroyFrameBuffers());}destroyFrameBuffers(){let e=this._device;e&&this.impl.destroy(e);}destroyTextureBuffers(){this._depthBuffer?.destroy(),this._depthBuffer=null,this._colorBuffers?.forEach(e=>{e.destroy();}),this._colorBuffers=null,this._colorBuffer=null;}resize(e,t){if(!(this.mipLevel>0)&&(this._depthBuffer?.resize(e,t),this._colorBuffers?.forEach(i=>{i.resize(e,t);}),this._width!==e||this._height!==t)){this.destroyFrameBuffers();let e=this._device;e.renderTarget===this&&e.setRenderTarget(null),this.evaluateDimensions(),this.validateMrt(),this.impl=e.createRenderTargetImpl(this);}}validateMrt(){}evaluateDimensions(){let e=this._colorBuffer??this._depthBuffer;e&&(this._width=e.width,this._height=e.height,this._mipLevel>0&&(this._width=ny.calcLevelDimension(this._width,this._mipLevel),this._height=ny.calcLevelDimension(this._height,this._mipLevel)));}init(){this.impl.init(this._device,this);}get initialized(){return this.impl.initialized}get device(){return this._device}loseContext(){this.impl.loseContext();}resolve(e=true,t=!!this._depthBuffer){this._device&&this._samples>1&&this.impl.resolve(this._device,this,e,t);}copy(e,t,i){if(!this._device)if(!e._device)return false;else this._device=e._device;return this._device.copyRenderTarget(e,this,t,i)}get samples(){return this._samples}get depth(){return this._depth}get stencil(){return this._stencil}get colorBuffer(){return this._colorBuffer}getColorBuffer(e){return this._colorBuffers?.[e]}get depthBuffer(){return this._depthBuffer}get face(){return this._face}get mipLevel(){return this._mipLevel}get mipmaps(){return this._mipmaps}get width(){return this._width??this._device.width}get height(){return this._height??this._device.height}isColorBufferSrgb(e=0){if(this.device.backBuffer===this)return sy(this.device.backBufferFormat);let t=this.getColorBuffer(e);return !!t&&sy(t.format)}constructor(e={}){this.id=nJ++;let t=e.colorBuffer?.device??e.colorBuffers?.[0].device??e.depthBuffer?.device??e.graphicsDevice;this._device=t;let{maxSamples:i}=this._device;if(this._samples=Math.min(e.samples??1,i),t.isWebGPU&&(this._samples=this._samples>1?i:1),this._colorBuffer=e.colorBuffer,e.colorBuffer&&(this._colorBuffers=[e.colorBuffer]),this._depthBuffer=e.depthBuffer,this._face=e.face??0,this._depthBuffer){let e=this._depthBuffer._format;e===iA||e===sd?(this._depth=true,this._stencil=false):e===iC?(this._depth=true,this._stencil=true):(e===ib&&this._depthBuffer.device.isWebGPU&&this._samples>1?this._depth=true:this._depth=false,this._stencil=false);}else this._depth=e.depth??true,this._stencil=e.stencil??false;e.colorBuffers&&!this._colorBuffers&&(this._colorBuffers=[...e.colorBuffers],this._colorBuffer=e.colorBuffers[0]),this.autoResolve=e.autoResolve??true,this.name=e.name,this.name||(this.name=this._colorBuffer?.name),this.name||(this.name=this._depthBuffer?.name),this.name||(this.name="Untitled"),this.flipY=e.flipY??false,this._mipLevel=e.mipLevel??0,this._mipLevel>0&&this._depth&&(this._mipLevel=0),this._mipmaps=void 0===e.mipLevel,this.evaluateDimensions(),this.validateMrt(),this.impl=t.createRenderTargetImpl(this);}}class n1{update(e){this.destroy();let t=e.device,i=this.createDescriptor(t,e);this.bindGroup=t.wgpu.createBindGroup(i);}destroy(){this.bindGroup=null;}createDescriptor(e,t){let i=[],s=t.format,r=t.format.uniformBufferFormats;t.uniformBuffers.forEach((e,t)=>{let s=r[t].slot,a=e.persistent?e.impl.buffer:e.allocation.gpuBuffer.buffer;i.push({binding:s,resource:{buffer:a,offset:0,size:e.format.byteSize}});});let a=t.format.textureFormats;t.textures.forEach((t,r)=>{let n=t instanceof nE,o=(n?t.texture:t).impl,l=s.textureFormats[r],h=a[r].slot,c=o.getView(e,n?t:void 0);if(i.push({binding:h,resource:c}),l.hasSampler){let t=o.getSampler(e,l.sampleType);i.push({binding:h+1,resource:t});}});let n=t.format.storageTextureFormats;t.storageTextures.forEach((t,s)=>{let r=t instanceof nE,a=(r?t.texture:t).impl,o=n[s].slot,l=a.getView(e,r?t:void 0);i.push({binding:o,resource:l});});let o=t.format.storageBufferFormats;return t.storageBuffers.forEach((e,t)=>{let s=e.impl.buffer,r=o[t].slot;i.push({binding:r,resource:{buffer:s}});}),{layout:t.format.impl.bindGroupLayout,entries:i}}}class n2{static shaderStage(e){let t=0;return e&aq&&(t|=GPUShaderStage.VERTEX),e&a$&&(t|=GPUShaderStage.FRAGMENT),e&aj&&(t|=GPUShaderStage.COMPUTE),t}}let n3=[];n3[ih]="",n3[ic]="",n3[id]="",n3[i9]="r8unorm",n3[i7]="rg8unorm",n3[iu]="",n3[ip]="",n3[im]="",n3[i_]="rgba8unorm",n3[ig]="rgba8unorm",n3[iv]="bc1-rgba-unorm",n3[iS]="bc2-rgba-unorm",n3[iy]="bc3-rgba-unorm",n3[ix]="",n3[iT]="rgba16float",n3[i8]="r16float",n3[i6]="rg16float",n3[iE]="",n3[iw]="rgba32float",n3[ib]="r32float",n3[su]="rg32float",n3[iA]="depth32float",n3[sd]="depth16unorm",n3[iC]="depth24plus-stencil8",n3[iP]="rg11b10ufloat",n3[iI]="",n3[iD]="rgba8unorm-srgb",n3[iR]="",n3[iL]="etc2-rgb8unorm",n3[iM]="etc2-rgba8unorm",n3[iO]="",n3[iF]="",n3[iN]="",n3[iB]="",n3[ik]="astc-4x4-unorm",n3[iU]="",n3[iz]="",n3[iV]="bgra8unorm",n3[sn]="bgra8unorm-srgb",n3[iG]="r8sint",n3[iH]="r8uint",n3[iW]="r16sint",n3[iX]="r16uint",n3[iY]="r32sint",n3[iq]="r32uint",n3[i$]="rg8sint",n3[ij]="rg8uint",n3[iK]="rg16sint",n3[iZ]="rg16uint",n3[iQ]="rg32sint",n3[iJ]="rg32uint",n3[i0]="rgba8sint",n3[i1]="rgba8uint",n3[i2]="rgba16sint",n3[i3]="rgba16uint",n3[i4]="rgba32sint",n3[i5]="rgba32uint",n3[so]="bc6h-rgb-float",n3[sl]="bc6h-rgb-ufloat",n3[sh]="bc7-rgba-unorm",n3[sf]="rgb9e5ufloat",n3[sp]="rg8snorm",n3[sm]="rgba8snorm",n3[s_]="rgb10a2unorm",n3[sg]="rgb10a2uint",n3[se]="bc1-rgba-unorm-srgb",n3[st]="bc2-rgba-unorm-srgb",n3[si]="bc3-rgba-unorm-srgb",n3[ss]="etc2-rgb8unorm-srgb",n3[sr]="etc2-rgba8unorm-srgb",n3[sc]="bc7-rgba-unorm-srgb",n3[sa]="astc-4x4-unorm-srgb";let n4=[];n4[rF]="filtering",n4[rN]="non-filtering",n4[rB]="comparison",n4[rk]="comparison",n4[rU]="comparison";let n5=[];n5[rF]="float",n5[rN]="unfilterable-float",n5[rB]="depth",n5[rk]="sint",n5[rU]="uint";let n8=new nx;class n6{destroy(){this.bindGroupLayout=null;}loseContext(){}createDescriptor(e){let t=[],i="";return e.uniformBufferFormats.forEach(e=>{let s=n2.shaderStage(e.visibility);i+=`#${e.slot}U:${s}`,t.push({binding:e.slot,visibility:s,buffer:{type:"uniform",hasDynamicOffset:true}});}),e.textureFormats.forEach(e=>{let s=n2.shaderStage(e.visibility),r=e.sampleType,a=e.textureDimension,n=n5[r];if(i+=`#${e.slot}T:${s}-${n}-${a}-false`,t.push({binding:e.slot,visibility:s,texture:{sampleType:n,viewDimension:a,multisampled:false}}),e.hasSampler){let a=n4[r];i+=`#${e.slot+1}S:${s}-${a}`,t.push({binding:e.slot+1,visibility:s,sampler:{type:a}});}}),e.storageTextureFormats.forEach(e=>{let{format:s,textureDimension:r}=e,{read:a,write:n}=e;i+=`#${e.slot}ST:${s}-${r}-${a?"r1":"r0"}-${n?"w1":"w0"}`,t.push({binding:e.slot,visibility:GPUShaderStage.COMPUTE,storageTexture:{access:a?n?"read-write":"read-only":"write-only",format:n3[s],viewDimension:r}});}),e.storageBufferFormats.forEach(e=>{let s=e.readOnly,r=n2.shaderStage(e.visibility);i+=`#${e.slot}SB:${r}-${s?"ro":"rw"}`,t.push({binding:e.slot,visibility:r,buffer:{type:s?"read-only-storage":"storage"}});}),{key:i,desc:{entries:t}}}constructor(e){let t=e.device,{key:i,desc:s}=this.createDescriptor(e);this.key=n8.get(i),this.bindGroupLayout=t.wgpu.createBindGroupLayout(s);}}class n9{destroy(e){this.buffer&&(this.buffer.destroy(),this.buffer=null);}get initialized(){return !!this.buffer}loseContext(){}allocate(e,t){this.buffer=e.wgpu.createBuffer({size:t,usage:this.usageFlags});}unlock(e,t){let i=e.wgpu;if(!this.buffer){let i=t.byteLength+3&-4;this.usageFlags|=GPUBufferUsage.COPY_DST,this.allocate(e,i);}let s=t.byteOffset??0,r=new Uint8Array(t.buffer??t,s,t.byteLength),a=new Uint8Array(this.buffer.size);a.set(r),i.queue.writeBuffer(this.buffer,0,a,0,a.length);}read(e,t,i,s,r){return e.readStorageBuffer(this,t,i,s,r)}write(e,t,i,s,r){e.writeStorageBuffer(this,t,i,s,r);}clear(e,t,i){e.clearStorageBuffer(this,t,i);}constructor(e=0){this.buffer=null,this.usageFlags=0,this.usageFlags=e;}}class n7 extends n9{unlock(e){let t=e.device;super.unlock(t,e.storage);}constructor(e,t){super(tL|(t?.storage?tF:0)),this.format=null,this.format=e.format===ia?"uint16":"uint32";}}let oe={equals(e,t){if(e.length!==t.length)return false;for(let i=0;i<e.length;i++)if(e[i]!==t[i])return false;return true}},ot=[];ot[rY]="sint8",ot[rq]="uint8",ot[r$]="sint16",ot[rj]="uint16",ot[rK]="sint32",ot[rZ]="uint32",ot[rQ]="float32",ot[rJ]="float16";let oi=[];oi[rY]="snorm8",oi[rq]="unorm8",oi[r$]="snorm16",oi[rj]="unorm16",oi[rK]="sint32",oi[rZ]="uint32",oi[rQ]="float32",oi[rJ]="float16";class os{get(e,t=null){let i=this.getKey(e,t),s=this.cache.get(i);return s||(s=this.create(e,t),this.cache.set(i,s)),s}getKey(e,t=null){return `${e?.renderingHashString}-${t?.renderingHashString}`}create(e,t){let i=[],s=e=>{let t=e.interleaved,s=e.instancing?"instance":"vertex",r=[],a=e.elements.length;for(let n=0;n<a;n++){let o=e.elements[n],l=nd[o.name],h=o.normalize?oi:ot;r.push({shaderLocation:l,offset:t?o.offset:0,format:`${h[o.dataType]}${o.numComponents>1?`x${o.numComponents}`:""}`}),t&&n!==a-1||(i.push({attributes:r,arrayStride:o.stride,stepMode:s}),r=[]);}};return e&&s(e),t&&s(t),i}constructor(){this.cache=new Map;}}class or{getPipelineLayout(e){let t=[];return e.forEach(e=>{t.push(e.bindGroupLayout);}),this.device.wgpu.createPipelineLayout({bindGroupLayouts:t})}constructor(e){this.device=e;}}let oa=["point-list","line-list",void 0,"line-strip","triangle-list","triangle-strip",void 0],on=["add","subtract","reverse-subtract","min","max"],oo=["zero","one","src","one-minus-src","dst","one-minus-dst","src-alpha","src-alpha-saturated","one-minus-src-alpha","dst-alpha","one-minus-dst-alpha","constant","one-minus-constant"],ol=["never","less","equal","less-equal","greater","not-equal","greater-equal","always"],oh=["none","back","front"],oc=["keep","zero","replace","increment-clamp","increment-wrap","decrement-clamp","decrement-wrap","invert"],od=["","uint16","uint32"],ou=class{};class of extends or{get(e,t,i,s,r,a,n,o,l,h,c,d,u){let f=e.type;s&&f!==sB&&f!==sU&&(s=void 0);let p=this.lookupHashes;p[0]=f,p[1]=r.id,p[2]=h,p[3]=l.key,p[4]=o.key,p[5]=t?.renderingHash??0,p[6]=i?.renderingHash??0,p[7]=a.impl.key,p[8]=n[0]?.key??0,p[9]=n[1]?.key??0,p[10]=n[2]?.key??0,p[11]=c?d.key:0,p[12]=c?u.key:0,p[13]=s??0;let m=nX(p),_=this.cache.get(m);if(_)for(let e=0;e<_.length;e++){let t=_[e];if(oe.equals(t.hashes,p))return t.pipeline}let g=oa[f],v=this.getPipelineLayout(n),S=this.vertexBufferLayout.get(t,i),y=new ou;return y.hashes=new Uint32Array(p),y.pipeline=this.create(g,s,r,a,v,o,l,S,h,c,d,u),_?_.push(y):_=[y],this.cache.set(m,_),y.pipeline}getBlend(e){let t;return e.blend&&(t={color:{operation:on[e.colorOp],srcFactor:oo[e.colorSrcFactor],dstFactor:oo[e.colorDstFactor]},alpha:{operation:on[e.alphaOp],srcFactor:oo[e.alphaSrcFactor],dstFactor:oo[e.alphaDstFactor]}}),t}getDepthStencil(e,t,i,s,r,a){let n,{depth:o,stencil:l}=t;if(o||l){if(n={format:t.impl.depthAttachment.format},o){n.depthWriteEnabled=e.write,n.depthCompare=ol[e.func];let t="triangle-list"===a||"triangle-strip"===a;n.depthBias=t?e.depthBias:0,n.depthBiasSlopeScale=t?e.depthBiasSlope:0;}else n.depthWriteEnabled=false,n.depthCompare="always";l&&i&&(n.stencilReadMas=s.readMask,n.stencilWriteMask=s.writeMask,n.stencilFront={compare:ol[s.func],failOp:oc[s.fail],passOp:oc[s.zpass],depthFailOp:oc[s.zfail]},n.stencilBack={compare:ol[r.func],failOp:oc[r.fail],passOp:oc[r.zpass],depthFailOp:oc[r.zfail]});}return n}create(e,t,i,s,r,a,n,o,l,h,c,d){let u=this.device.wgpu,f=i.impl,p={vertex:{module:f.getVertexShaderModule(),entryPoint:f.vertexEntryPoint,buffers:o},primitive:{topology:e,frontFace:"ccw",cullMode:oh[l]},depthStencil:this.getDepthStencil(n,s,h,c,d,e),multisample:{count:s.samples},layout:r};t&&(p.primitive.stripIndexFormat=od[t]),p.fragment={module:f.getFragmentShaderModule(),entryPoint:f.fragmentEntryPoint,targets:[]};let m=s.impl.colorAttachments;if(m.length>0){let e=0;a.redWrite&&(e|=GPUColorWrite.RED),a.greenWrite&&(e|=GPUColorWrite.GREEN),a.blueWrite&&(e|=GPUColorWrite.BLUE),a.alphaWrite&&(e|=GPUColorWrite.ALPHA);let t=this.getBlend(a);m.forEach(i=>{p.fragment.targets.push({format:i.format,writeMask:e,blend:t});});}return u.createRenderPipeline(p)}constructor(e){super(e),this.lookupHashes=new Uint32Array(14),this.vertexBufferLayout=new os,this.cache=new Map;}}class op{constructor(){this.pipeline=null,this.hashes=null;}}class om extends or{get(e,t){let i=this.lookupHashes;i[0]=e.impl.computeKey,i[1]=t.impl.key;let s=nX(i),r=this.cache.get(s);if(r)for(let e=0;e<r.length;e++){let t=r[e];if(oe.equals(t.hashes,i))return t.pipeline}let a=this.getPipelineLayout([t.impl]),n=new op;return n.hashes=new Uint32Array(i),n.pipeline=this.create(e,a),r?r.push(n):r=[n],this.cache.set(s,r),n.pipeline}create(e,t){let i=this.device.wgpu,s=e.impl,r={compute:{module:s.getComputeShaderModule(),entryPoint:s.computeEntryPoint},layout:t};return i.createComputePipeline(r)}constructor(...e){super(...e),this.lookupHashes=new Uint32Array(2),this.cache=new Map;}}class o_{incRefCount(){this._refCount++;}decRefCount(){this._refCount--;}get refCount(){return this._refCount}constructor(){this._refCount=0;}}class og extends o_{constructor(e){super(),this.object=e,this.incRefCount();}}class ov{destroy(){this.cache.forEach(e=>{e.object?.destroy();}),this.cache.clear();}clear(){this.cache.clear();}get(e){let t=this.cache.get(e);return t?(t.incRefCount(),t.object):null}set(e,t){this.cache.set(e,new og(t));}release(e){let t=this.cache.get(e);t&&(t.decRefCount(),0===t.refCount&&(this.cache.delete(e),t.object?.destroy()));}constructor(){this.cache=new Map;}}class oS extends ov{loseContext(e){this.clear();}}let oy=new nS,ox=e=>oy.get(e,()=>new oS),oT=new nx;class oE{destroy(){this.multisampledBuffer?.destroy(),this.multisampledBuffer=null;}}class ow{destroy(e){this.depthTextureInternal&&(this.depthTexture?.destroy(),this.depthTexture=null),this.multisampledDepthBuffer&&(this.multisampledDepthBuffer=null,ox(e).release(this.multisampledDepthBufferKey));}constructor(e){this.depthTexture=null,this.depthTextureInternal=false,this.multisampledDepthBuffer=null,this.format=e,this.hasStencil="depth24plus-stencil8"===e;}}class ob{destroy(e){this.initialized=false,this.assignedColorTexture=null,this.colorAttachments.forEach(e=>{e.destroy();}),this.colorAttachments.length=0,this.depthAttachment?.destroy(e),this.depthAttachment=null;}updateKey(){let e=this.renderTarget,t=`${e.samples}:${this.depthAttachment?this.depthAttachment.format:"nodepth"}`;this.colorAttachments.forEach(e=>{t+=`:${e.format}`;}),this.key=oT.get(t);}assignColorTexture(e,t){this.assignedColorTexture=t;let i=t.createView({format:e.backBufferViewFormat}),s=this.renderPassDescriptor.colorAttachments[0];this.renderTarget.samples>1?s.resolveTarget=i:s.view=i,this.setColorAttachment(0,void 0,e.backBufferViewFormat),this.updateKey();}setColorAttachment(e,t,i){this.colorAttachments[e]||(this.colorAttachments[e]=new oE),t&&(this.colorAttachments[e].multisampledBuffer=t),i&&(this.colorAttachments[e].format=i);}init(e,t){let i=e.wgpu;this.initDepthStencil(e,i,t),t._colorBuffers&&t._colorBuffers.forEach((e,t)=>{this.setColorAttachment(t,void 0,e.impl.format);}),this.renderPassDescriptor.colorAttachments=[];let s=this.isBackbuffer?1:t._colorBuffers?.length??0;for(let r=0;r<s;++r){let s=this.initColor(e,i,t,r),a=0===r&&this.colorAttachments[0]?.format;(s.view||a)&&this.renderPassDescriptor.colorAttachments.push(s);}this.updateKey(),this.initialized=true;}initDepthStencil(e,t,i){let{samples:s,width:r,height:a,depth:n,depthBuffer:o}=i;if(n||o){let i;if(o)if(this.depthAttachment=new ow(o.impl.format),s>1){let n="depth24plus-stencil8";this.depthAttachment.format=n,this.depthAttachment.hasStencil=true;let l=`${o.id}:${r}:${a}:${s}:${n}`,h=ox(e),c=h.get(l);if(!c){let e={size:[r,a,1],dimension:"2d",sampleCount:s,format:n,usage:GPUTextureUsage.RENDER_ATTACHMENT|(n!==o.impl.format?GPUTextureUsage.TEXTURE_BINDING:0)};c=t.createTexture(e),h.set(l,c);}this.depthAttachment.multisampledDepthBuffer=c,this.depthAttachment.multisampledDepthBufferKey=l,i=c.createView();}else {let e=o.impl.gpuTexture;this.depthAttachment.depthTexture=e,i=e.createView();}else {this.depthAttachment=new ow("depth24plus-stencil8");let e={size:[r,a,1],dimension:"2d",sampleCount:s,format:this.depthAttachment.format,usage:GPUTextureUsage.RENDER_ATTACHMENT};s>1?e.usage|=GPUTextureUsage.TEXTURE_BINDING:e.usage|=GPUTextureUsage.COPY_SRC;let n=t.createTexture(e);this.depthAttachment.depthTexture=n,this.depthAttachment.depthTextureInternal=true,i=n.createView();}this.renderPassDescriptor.depthStencilAttachment={view:i};}}initColor(e,t,i,s){let r={},{samples:a,width:n,height:o,mipLevel:l}=i,h=i.getColorBuffer(s),c=null;if(h&&(c=h.cubemap?h.impl.createView({dimension:"2d",baseArrayLayer:i.face,arrayLayerCount:1,mipLevelCount:1,baseMipLevel:l}):h.impl.createView({mipLevelCount:1,baseMipLevel:l})),a>1){let i={size:[n,o,1],dimension:"2d",sampleCount:a,format:this.isBackbuffer?e.backBufferViewFormat:h.impl.format,usage:GPUTextureUsage.RENDER_ATTACHMENT},l=t.createTexture(i);this.setColorAttachment(s,l,i.format),r.view=l.createView(),r.resolveTarget=c;}else r.view=c;return r}setupForRenderPass(e,t){let i=this.renderPassDescriptor.colorAttachments?.length??0;for(let s=0;s<i;++s){let i=this.renderPassDescriptor.colorAttachments[s],r=e.colorArrayOps[s];i.clearValue=t.isColorBufferSrgb(s)?r.clearValueLinear:r.clearValue,i.loadOp=r.clear?"clear":"load",i.storeOp=r.store?"store":"discard";}let s=this.renderPassDescriptor.depthStencilAttachment;s&&(s.depthClearValue=e.depthStencilOps.clearDepthValue,s.depthLoadOp=e.depthStencilOps.clearDepth?"clear":"load",s.depthStoreOp=e.depthStencilOps.storeDepth?"store":"discard",s.depthReadOnly=false,this.depthAttachment.hasStencil&&(s.stencilClearValue=e.depthStencilOps.clearStencilValue,s.stencilLoadOp=e.depthStencilOps.clearStencil?"clear":"load",s.stencilStoreOp=e.depthStencilOps.storeStencil?"store":"discard",s.stencilReadOnly=false));}loseContext(){this.initialized=false;}resolve(e,t,i,s){}constructor(e){this.initialized=false,this.colorAttachments=[],this.depthAttachment=null,this.assignedColorTexture=null,this.renderPassDescriptor={},this.isBackbuffer=false,this.renderTarget=e;}}let oA=[];oA[r2]=1,oA[r3]=2,oA[r4]=3,oA[r5]=4,oA[r1]=1,oA[r8]=2,oA[r6]=3,oA[r9]=4,oA[r0]=1,oA[r7]=2,oA[ae]=3,oA[at]=4,oA[ai]=8,oA[as]=12,oA[ar]=16,oA[a_]=1,oA[ag]=2,oA[av]=3,oA[aS]=4;class oC{get isArrayType(){return this.count>0}calculateOffset(e){let t=this.byteSize<=8?this.byteSize:16;this.count&&(t=16),e=eP.roundUp(e,t),this.offset=e/4;}constructor(e,t,i=0){if(this.shortName=e,this.name=i?`${e}[0]`:e,this.type=t,this.numComponents=oA[t],this.updateType=t,i>0)switch(t){case r2:this.updateType=ao;break;case r1:this.updateType=ay;break;case a_:this.updateType=ax;break;case r0:this.updateType=aT;break;case r3:this.updateType=ad;break;case r8:this.updateType=aE;break;case ag:this.updateType=aw;break;case r7:this.updateType=ab;break;case r4:this.updateType=au;break;case r6:this.updateType=aA;break;case av:this.updateType=aC;break;case ae:this.updateType=aP;break;case r5:this.updateType=af;break;case r9:this.updateType=aI;break;case aS:this.updateType=aD;break;case at:this.updateType=aR;break;case ar:this.updateType=ap;}this.count=i;let s=this.numComponents;i&&(s=eP.roundUp(s,4)),this.byteSize=4*s,i&&(this.byteSize*=i);}}class oP{get(e){return this.map.get(e)}constructor(e,t){this.byteSize=0,this.map=new Map,this.scope=e.scope,this.uniforms=t;let i=0;for(let e=0;e<t.length;e++){let s=t[e];s.calculateOffset(i),i=4*s.offset+s.byteSize,s.scopeId=this.scope.resolve(s.name),this.map.set(s.name,s);}this.byteSize=eP.roundUp(i,16);}}let oI=/[ \t]*(\battribute\b|\bvarying\b|\buniform\b)/g,oD=/(\battribute\b|\bvarying\b|\bout\b|\buniform\b)[ \t]*([^;]+)(;+)/g,oR=/([\w-]+)\[(.*?)\]/,oL=new Set(["highp","mediump","lowp"]),oM=new Set(["sampler2DShadow","samplerCubeShadow","sampler2DArrayShadow"]),oO={sampler2D:rD,sampler3D:rO,samplerCube:rL,samplerCubeShadow:rL,sampler2DShadow:rD,sampler2DArray:rR,sampler2DArrayShadow:rR,isampler2D:rD,usampler2D:rD,isampler3D:rO,usampler3D:rO,isamplerCube:rL,usamplerCube:rL,isampler2DArray:rR,usampler2DArray:rR},oF={[rD]:"texture2D",[rL]:"textureCube",[rO]:"texture3D",[rR]:"texture2DArray"},oN=class{constructor(e,t){this.line=e;let i=e.trim().split(/\s+/);if(oL.has(i[0])&&(this.precision=i.shift()),this.type=i.shift(),e.includes(","),e.includes("[")){let e=i.join(" "),s=oR.exec(e);this.name=s[1],this.arraySize=Number(s[2]),isNaN(this.arraySize)&&(t.failed=true);}else this.name=i.shift(),this.arraySize=0;this.isSampler=-1!==this.type.indexOf("sampler"),this.isSignedInt=-1!==this.type.indexOf("isampler"),this.isUnsignedInt=-1!==this.type.indexOf("usampler");}};class oB{static run(e,t,i){let s=new Map,r=oB.extract(t.vshader),a=oB.extract(t.fshader),n=new Map,o=oB.processAttributes(r.attributes,t.attributes,n,t.processingOptions),l=oB.processVaryings(r.varyings,s,true),h=oB.processVaryings(a.varyings,s,false),c=oB.processOuts(a.outs),d=Array.from(new Set(r.uniforms.concat(a.uniforms))).map(e=>new oN(e,i)),u=oB.processUniforms(e,d,t.processingOptions,i),f=`${o}
9
9
  ${l}
10
10
  ${u.code}`,p=r.src.replace("@@@",f),m=`${h}
11
11
  ${c}
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * PlayCanvas Engine v2.16.0-preview.0 revision aa34e6d (RELEASE)
3
+ * PlayCanvas Engine v2.16.0 revision 7aba7cb (RELEASE)
4
4
  * Copyright 2011-2026 PlayCanvas Ltd. All rights reserved.
5
5
  *
6
6
  * This source code is licensed under the MIT license found in the
@@ -31,8 +31,8 @@ const TRACEID_RENDER_QUEUE = 'RenderQueue';
31
31
  const TRACEID_OCTREE_RESOURCES = 'OctreeResources';
32
32
  const TRACEID_GPU_TIMINGS = 'GpuTimings';
33
33
 
34
- const version = '2.16.0-preview.0';
35
- const revision = 'aa34e6d';
34
+ const version = '2.16.0';
35
+ const revision = '7aba7cb';
36
36
  function extend(target, ex) {
37
37
  for(const prop in ex){
38
38
  const copy = ex[prop];