UNPKG

@xeokit/xeokit-bim-viewer

Version:
1 lines 3.39 MB
let A=class{constructor(A,e){this.items=A||[],this._lastUniqueId=(e||0)+1}addItem(){let A;if(2===arguments.length){const e=arguments[0];if(A=arguments[1],this.items[e])throw"ID clash: '"+e+"'";return this.items[e]=A,e}for(A=arguments[0]||{};;){const e=this._lastUniqueId++;if(!this.items[e])return this.items[e]=A,e}}removeItem(A){const e=this.items[A];return delete this.items[A],e}};const e=new A;class t{constructor(A){this.id=A,this.parentItem=null,this.groups=[],this.menuElement=null,this.shown=!1,this.mouseOver=0}}class i{constructor(){this.items=[]}}class s{constructor(A,e,t,i,s){this.id=A,this.getTitle=e,this.doAction=t,this.getEnabled=i,this.getShown=s,this.itemElement=null,this.subMenu=null,this.enabled=!0}}class n{constructor(A={}){this._id=e.addItem(),this._context=null,this._enabled=!1,this._itemsCfg=[],this._rootMenu=null,this._menuList=[],this._menuMap={},this._itemList=[],this._itemMap={},this._shown=!1,this._nextId=0,this._parentNode=A.parentNode||document.body,this._offsetParent=this._parentNode instanceof ShadowRoot?this._parentNode.host:this._parentNode,this._eventSubs={},!1!==A.hideOnMouseDown&&(this._parentNode.addEventListener("mousedown",(A=>{A.target.classList.contains("xeokit-context-menu-item")||this.hide()})),this._parentNode.addEventListener("touchstart",this._canvasTouchStartHandler=A=>{A.target.classList.contains("xeokit-context-menu-item")||this.hide()})),A.items&&(this.items=A.items),this._hideOnAction=!1!==A.hideOnAction,this.context=A.context,this.enabled=!1!==A.enabled,this.hide()}on(A,e){let t=this._eventSubs[A];t||(t=[],this._eventSubs[A]=t),t.push(e)}fire(A,e){const t=this._eventSubs[A];if(t)for(let A=0,i=t.length;A<i;A++)t[A](e)}set items(A){this._clear(),this._itemsCfg=A||[],this._parseItems(A),this._createUI()}get items(){return this._itemsCfg}set enabled(A){(A=!!A)!==this._enabled&&(this._enabled=A,this._enabled||this.hide())}get enabled(){return this._enabled}set context(A){this._context=A}get context(){return this._context}show(A,e){this._context?this._enabled&&(this._shown||(this._hideAllMenus(),this._updateItemsTitles(),this._updateItemsEnabledStatus(),this._showMenu(this._rootMenu.id,A,e),this._updateSubMenuInfo(),this._shown=!0,this.fire("shown",{}))):console.error("ContextMenu cannot be shown without a context - set context first")}get shown(){return this._shown}hide(){this._enabled&&this._shown&&(this._hideAllMenus(),this._shown=!1,this.fire("hidden",{}))}destroy(){this._context=null,this._clear(),null!==this._id&&(e.removeItem(this._id),this._id=null)}_clear(){for(let A=0,e=this._menuList.length;A<e;A++){this._menuList[A].menuElement.remove()}this._itemsCfg=[],this._rootMenu=null,this._menuList=[],this._menuMap={},this._itemList=[],this._itemMap={}}_parseItems(A){const e=A=>{const n=this._getNextId(),o=new t(n);for(let t=0,n=A.length;t<n;t++){const n=A[t],r=new i;o.groups.push(r);for(let A=0,t=n.length;A<t;A++){const t=n[A],i=t.items,c=i&&i.length>0,a=this._getNextId(),h=t.getTitle||(()=>t.title||""),B=t.doAction||t.callback||(()=>{}),g=t.getEnabled||(()=>!0),l=t.getShown||(()=>!0),E=new s(a,h,B,g,l);if(E.parentMenu=o,r.items.push(E),c){const A=e(i);E.subMenu=A,A.parentItem=E}this._itemList.push(E),this._itemMap[E.id]=E}}return this._menuList.push(o),this._menuMap[o.id]=o,o};this._rootMenu=e(A)}_getNextId(){return"ContextMenu_"+this._id+"_"+this._nextId++}_createUI(){const A=e=>{this._createMenuUI(e);const t=e.groups;for(let e=0,i=t.length;e<i;e++){const i=t[e].items;for(let e=0,t=i.length;e<t;e++){const t=i[e].subMenu;t&&A(t)}}};A(this._rootMenu)}_createMenuUI(A){const e=A.groups,t=[],i=document.createElement("div");if(i.classList.add("xeokit-context-menu",A.id),i.style.zIndex=3e5,i.style.position="absolute",t.push("<ul>"),e)for(let A=0,i=e.length;A<i;A++){const s=A,n=i,o=e[A].items;if(o)for(let A=0,e=o.length;A<e;A++){const i=o[A],r=i.subMenu,c=i.title||"";r?(t.push('<li id="'+i.id+'" class="xeokit-context-menu-item xeokit-context-menu-submenu">'+c+"</li>"),s===n-1||A<e-1||t.push('<li id="'+i.id+'" class="xeokit-context-menu-item-separator"></li>')):(t.push('<li id="'+i.id+'" class="xeokit-context-menu-item">'+c+"</li>"),s===n-1||A<e-1||t.push('<li id="'+i.id+'" class="xeokit-context-menu-item-separator"></li>'))}}t.push("</ul>");const s=t.join("");i.innerHTML=s,this._parentNode.appendChild(i),A.menuElement=i,i.style["border-radius"]="4px",i.style.display="none",i.style["z-index"]=3e5,i.style.background="white",i.style.border="1px solid black",i.style["box-shadow"]="0 4px 5px 0 gray",i.oncontextmenu=A=>{A.preventDefault()};const n=this;let o=null;if(e)for(let A=0,t=e.length;A<t;A++){const t=e[A].items;if(t)for(let A=0,e=t.length;A<e;A++){const e=t[A],i=e.subMenu;e.itemElement=this._parentNode.querySelector(`#${e.id}`),e.itemElement?(e.itemElement.addEventListener("mouseenter",(A=>{A.preventDefault();const t=e.subMenu;if(!t)return void(o&&(n._hideMenu(o.id),o=null));if(o&&o.id!==t.id&&(n._hideMenu(o.id),o=null),!1===e.enabled)return;const i=e.itemElement,s=t.menuElement,r=i.getBoundingClientRect();s.getBoundingClientRect();const c=n._offsetParent.getBoundingClientRect(),a=200,h=r.right+a<c.right,B=r.left-a>c.left;if(h)n._showMenu(t.id,r.right+window.scrollX-5,r.top+window.scrollY-1);else if(B)n._showMenu(t.id,r.left-a+window.scrollX,r.top+window.scrollY-1);else{const A=r.left-c.left,e=c.right-r.right;e>A?n._showMenu(t.id,r.right-5-(a-e),r.top+window.scrollY-1):n._showMenu(t.id,r.left-A,r.top+window.scrollY-1)}o=t})),i||(e.itemElement.addEventListener("click",(A=>{A.preventDefault(),n._context&&!1!==e.enabled&&(e.doAction&&e.doAction(n._context),this._hideOnAction?n.hide():(n._updateItemsTitles(),n._updateItemsEnabledStatus()))})),e.itemElement.addEventListener("mouseup",(A=>{3===A.which&&(A.preventDefault(),n._context&&!1!==e.enabled&&(e.doAction&&e.doAction(n._context),this._hideOnAction?n.hide():(n._updateItemsTitles(),n._updateItemsEnabledStatus())))})),e.itemElement.addEventListener("mouseenter",(A=>{A.preventDefault(),!1!==e.enabled&&e.doHover&&e.doHover(n._context)})))):console.error("ContextMenu item element not found: "+e.id)}}}_updateItemsTitles(){if(this._context)for(let A=0,e=this._itemList.length;A<e;A++){const e=this._itemList[A],t=e.itemElement;if(!t)continue;const i=e.getShown;if(!i||!i(this._context))continue;const s=e.getTitle(this._context);e.subMenu,t.innerText=s}}_updateItemsEnabledStatus(){if(this._context)for(let A=0,e=this._itemList.length;A<e;A++){const e=this._itemList[A],t=e.itemElement;if(!t)continue;const i=e.getEnabled;if(!i)continue;const s=e.getShown;if(!s)continue;const n=s(this._context);if(e.shown=n,!n){t.style.display="none";continue}t.style.display="";const o=i(this._context);e.enabled=o,o?t.classList.remove("disabled"):t.classList.add("disabled")}}_updateSubMenuInfo(){if(!this._context)return;let A,e,t,i,s,n;this._itemList.forEach((o=>{o.subMenu&&(A=o.itemElement,e=A.getBoundingClientRect(),t=o.subMenu.menuElement,i={visibility:t.style.visibility,display:t.style.display},t.style.display="block",t.style.visibility="hidden",n=o.subMenu.menuElement.getBoundingClientRect().width,t.style.visibility=i.visibility,t.style.display=i.display,s=e.right+n>window.innerWidth,A.setAttribute("data-submenuposition",s?"left":"right"))}))}_showMenu(A,e,t){const i=this._menuMap[A];if(!i)return void console.error("Menu not found: "+A);if(i.shown)return;const s=i.menuElement;s&&(this._showMenuElement(s,e,t),i.shown=!0)}_hideMenu(A){const e=this._menuMap[A];if(!e)return void console.error("Menu not found: "+A);if(!e.shown)return;const t=e.menuElement;t&&(this._hideMenuElement(t),e.shown=!1)}_hideAllMenus(){for(let A=0,e=this._menuList.length;A<e;A++){const e=this._menuList[A];this._hideMenu(e.id)}}_showMenuElement(A,e,t){A.style.display="block";const i=A.offsetHeight,s=A.offsetWidth,n=this._offsetParent.getBoundingClientRect(),o=n.bottom+window.scrollY,r=n.right+window.scrollX;t+i>o&&(t=o-i),e+s>r&&(e=r-s),A.style.left=e-n.left-window.scrollX+"px",A.style.top=t-n.top-window.scrollY+"px"}_hideMenuElement(A){A.style.display="none"}}let o=!0,r=o?Float64Array:Float32Array;const c=new r(3),a=new r(16),h=new r(16),B=new r(4),g={setDoublePrecisionEnabled(A){o=A,r=o?Float64Array:Float32Array},getDoublePrecisionEnabled:()=>o,MIN_DOUBLE:-Number.MAX_SAFE_INTEGER,MAX_DOUBLE:Number.MAX_SAFE_INTEGER,MAX_INT:1e7,DEGTORAD:.0174532925,RADTODEG:57.295779513,unglobalizeObjectId(A,e){const t=e.indexOf("#");return t===A.length&&e.startsWith(A)?e.substring(t+1):e},globalizeObjectId:(A,e)=>A+"#"+e,safeInv(A){const e=1/A;return isNaN(e)||!isFinite(e)?1:e},vec2:A=>new r(A||2),vec3:A=>new r(A||3),vec4:A=>new r(A||4),mat3:A=>new r(A||9),mat3ToMat4:(A,e=new r(16))=>(e[0]=A[0],e[1]=A[1],e[2]=A[2],e[3]=0,e[4]=A[3],e[5]=A[4],e[6]=A[5],e[7]=0,e[8]=A[6],e[9]=A[7],e[10]=A[8],e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e),mat4:A=>new r(A||16),mat4ToMat3:(A,e=new r(9))=>(e[0]=A[0],e[1]=A[1],e[2]=A[2],e[3]=A[4],e[4]=A[5],e[5]=A[6],e[6]=A[8],e[7]=A[9],e[8]=A[10],e),doublesToFloats(A,e,t){const i=new r(2);for(let s=0,n=A.length;s<n;s++)g.splitDouble(A[s],i),e[s]=i[0],t[s]=i[1]},splitDouble(A,e){const t=r.from([A])[0],i=A-t;e[0]=t,e[1]=i},createUUID:(()=>{const A=[];for(let e=0;e<256;e++)A[e]=(e<16?"0":"")+e.toString(16);return()=>{const e=4294967295*Math.random()|0,t=4294967295*Math.random()|0,i=4294967295*Math.random()|0,s=4294967295*Math.random()|0;return`${A[255&e]+A[e>>8&255]+A[e>>16&255]+A[e>>24&255]}-${A[255&t]}${A[t>>8&255]}-${A[t>>16&15|64]}${A[t>>24&255]}-${A[63&i|128]}${A[i>>8&255]}-${A[i>>16&255]}${A[i>>24&255]}${A[255&s]}${A[s>>8&255]}${A[s>>16&255]}${A[s>>24&255]}`}})(),clamp:(A,e,t)=>Math.max(e,Math.min(t,A)),fmod(A,e){if(A<e)return console.error("math.fmod : Attempting to find modulus within negative range - would be infinite loop - ignoring"),A;for(;e<=A;)A-=e;return A},compareVec3:(A,e)=>A[0]===e[0]&&A[1]===e[1]&&A[2]===e[2],compareVec4:(A,e)=>A[0]===e[0]&&A[1]===e[1]&&A[2]===e[2]&&A[3]===e[3],negateVec3:(A,e)=>(e||(e=A),e[0]=-A[0],e[1]=-A[1],e[2]=-A[2],e),negateVec4:(A,e)=>(e||(e=A),e[0]=-A[0],e[1]=-A[1],e[2]=-A[2],e[3]=-A[3],e),addVec4:(A,e,t)=>(t||(t=A),t[0]=A[0]+e[0],t[1]=A[1]+e[1],t[2]=A[2]+e[2],t[3]=A[3]+e[3],t),addVec4Scalar:(A,e,t)=>(t||(t=A),t[0]=A[0]+e,t[1]=A[1]+e,t[2]=A[2]+e,t[3]=A[3]+e,t),addVec3:(A,e,t)=>(t||(t=A),t[0]=A[0]+e[0],t[1]=A[1]+e[1],t[2]=A[2]+e[2],t),addVec3Scalar:(A,e,t)=>(t||(t=A),t[0]=A[0]+e,t[1]=A[1]+e,t[2]=A[2]+e,t),subVec4:(A,e,t)=>(t||(t=A),t[0]=A[0]-e[0],t[1]=A[1]-e[1],t[2]=A[2]-e[2],t[3]=A[3]-e[3],t),subVec3:(A,e,t)=>(t||(t=A),t[0]=A[0]-e[0],t[1]=A[1]-e[1],t[2]=A[2]-e[2],t),subVec2:(A,e,t)=>(t||(t=A),t[0]=A[0]-e[0],t[1]=A[1]-e[1],t),geometricMeanVec2(...A){const e=new r(A[0]);for(let t=1;t<A.length;t++)e[0]+=A[t][0],e[1]+=A[t][1];return e[0]/=A.length,e[1]/=A.length,e},subVec4Scalar:(A,e,t)=>(t||(t=A),t[0]=A[0]-e,t[1]=A[1]-e,t[2]=A[2]-e,t[3]=A[3]-e,t),subScalarVec4:(A,e,t)=>(t||(t=A),t[0]=e-A[0],t[1]=e-A[1],t[2]=e-A[2],t[3]=e-A[3],t),mulVec4:(A,e,t)=>(t||(t=A),t[0]=A[0]*e[0],t[1]=A[1]*e[1],t[2]=A[2]*e[2],t[3]=A[3]*e[3],t),mulVec4Scalar:(A,e,t)=>(t||(t=A),t[0]=A[0]*e,t[1]=A[1]*e,t[2]=A[2]*e,t[3]=A[3]*e,t),mulVec3Scalar:(A,e,t)=>(t||(t=A),t[0]=A[0]*e,t[1]=A[1]*e,t[2]=A[2]*e,t),mulVec2Scalar:(A,e,t)=>(t||(t=A),t[0]=A[0]*e,t[1]=A[1]*e,t),divVec3:(A,e,t)=>(t||(t=A),t[0]=A[0]/e[0],t[1]=A[1]/e[1],t[2]=A[2]/e[2],t),divVec4:(A,e,t)=>(t||(t=A),t[0]=A[0]/e[0],t[1]=A[1]/e[1],t[2]=A[2]/e[2],t[3]=A[3]/e[3],t),divScalarVec3:(A,e,t)=>(t||(t=e),t[0]=A/e[0],t[1]=A/e[1],t[2]=A/e[2],t),divVec3Scalar:(A,e,t)=>(t||(t=A),t[0]=A[0]/e,t[1]=A[1]/e,t[2]=A[2]/e,t),divVec4Scalar:(A,e,t)=>(t||(t=A),t[0]=A[0]/e,t[1]=A[1]/e,t[2]=A[2]/e,t[3]=A[3]/e,t),divScalarVec4:(A,e,t)=>(t||(t=e),t[0]=A/e[0],t[1]=A/e[1],t[2]=A/e[2],t[3]=A/e[3],t),dotVec4:(A,e)=>A[0]*e[0]+A[1]*e[1]+A[2]*e[2]+A[3]*e[3],cross3Vec4(A,e){const t=A[0],i=A[1],s=A[2],n=e[0],o=e[1],r=e[2];return[i*r-s*o,s*n-t*r,t*o-i*n,0]},cross3Vec3(A,e,t){t||(t=A);const i=A[0],s=A[1],n=A[2],o=e[0],r=e[1],c=e[2];return t[0]=s*c-n*r,t[1]=n*o-i*c,t[2]=i*r-s*o,t},sqLenVec4:A=>g.dotVec4(A,A),lenVec4:A=>Math.sqrt(g.sqLenVec4(A)),dotVec3:(A,e)=>A[0]*e[0]+A[1]*e[1]+A[2]*e[2],dotVec2:(A,e)=>A[0]*e[0]+A[1]*e[1],sqLenVec3:A=>g.dotVec3(A,A),sqLenVec2:A=>g.dotVec2(A,A),lenVec3:A=>Math.sqrt(g.sqLenVec3(A)),distVec3:(()=>{const A=new r(3);return(e,t)=>g.lenVec3(g.subVec3(e,t,A))})(),lenVec2:A=>Math.sqrt(g.sqLenVec2(A)),distVec2:(()=>{const A=new r(2);return(e,t)=>g.lenVec2(g.subVec2(e,t,A))})(),rcpVec3:(A,e)=>g.divScalarVec3(1,A,e),normalizeVec4(A,e){const t=1/g.lenVec4(A);return g.mulVec4Scalar(A,t,e)},normalizeVec3(A,e){const t=1/g.lenVec3(A);return g.mulVec3Scalar(A,t,e)},normalizeVec2(A,e){const t=1/g.lenVec2(A);return g.mulVec2Scalar(A,t,e)},angleVec3(A,e){let t=g.dotVec3(A,e)/Math.sqrt(g.sqLenVec3(A)*g.sqLenVec3(e));return t=t<-1?-1:t>1?1:t,Math.acos(t)},vec3FromMat4Scale:(()=>{const A=new r(3);return(e,t)=>(A[0]=e[0],A[1]=e[1],A[2]=e[2],t[0]=g.lenVec3(A),A[0]=e[4],A[1]=e[5],A[2]=e[6],t[1]=g.lenVec3(A),A[0]=e[8],A[1]=e[9],A[2]=e[10],t[2]=g.lenVec3(A),t)})(),vecToArray:(()=>{function A(A){return Math.round(1e5*A)/1e5}return e=>{for(let t=0,i=(e=Array.prototype.slice.call(e)).length;t<i;t++)e[t]=A(e[t]);return e}})(),xyzArrayToObject:A=>({x:A[0],y:A[1],z:A[2]}),xyzObjectToArray:(A,e)=>((e=e||g.vec3())[0]=A.x,e[1]=A.y,e[2]=A.z,e),dupMat4:A=>A.slice(0,16),mat4To3:A=>[A[0],A[1],A[2],A[4],A[5],A[6],A[8],A[9],A[10]],m4s:A=>[A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A],setMat4ToZeroes:()=>g.m4s(0),setMat4ToOnes:()=>g.m4s(1),diagonalMat4v:A=>new r([A[0],0,0,0,0,A[1],0,0,0,0,A[2],0,0,0,0,A[3]]),diagonalMat4c:(A,e,t,i)=>g.diagonalMat4v([A,e,t,i]),diagonalMat4s:A=>g.diagonalMat4c(A,A,A,A),identityMat4:(A=new r(16))=>(A[0]=1,A[1]=0,A[2]=0,A[3]=0,A[4]=0,A[5]=1,A[6]=0,A[7]=0,A[8]=0,A[9]=0,A[10]=1,A[11]=0,A[12]=0,A[13]=0,A[14]=0,A[15]=1,A),identityMat3:(A=new r(9))=>(A[0]=1,A[1]=0,A[2]=0,A[3]=0,A[4]=1,A[5]=0,A[6]=0,A[7]=0,A[8]=1,A),isIdentityMat4:A=>1===A[0]&&0===A[1]&&0===A[2]&&0===A[3]&&0===A[4]&&1===A[5]&&0===A[6]&&0===A[7]&&0===A[8]&&0===A[9]&&1===A[10]&&0===A[11]&&0===A[12]&&0===A[13]&&0===A[14]&&1===A[15],negateMat4:(A,e)=>(e||(e=A),e[0]=-A[0],e[1]=-A[1],e[2]=-A[2],e[3]=-A[3],e[4]=-A[4],e[5]=-A[5],e[6]=-A[6],e[7]=-A[7],e[8]=-A[8],e[9]=-A[9],e[10]=-A[10],e[11]=-A[11],e[12]=-A[12],e[13]=-A[13],e[14]=-A[14],e[15]=-A[15],e),addMat4:(A,e,t)=>(t||(t=A),t[0]=A[0]+e[0],t[1]=A[1]+e[1],t[2]=A[2]+e[2],t[3]=A[3]+e[3],t[4]=A[4]+e[4],t[5]=A[5]+e[5],t[6]=A[6]+e[6],t[7]=A[7]+e[7],t[8]=A[8]+e[8],t[9]=A[9]+e[9],t[10]=A[10]+e[10],t[11]=A[11]+e[11],t[12]=A[12]+e[12],t[13]=A[13]+e[13],t[14]=A[14]+e[14],t[15]=A[15]+e[15],t),addMat4Scalar:(A,e,t)=>(t||(t=A),t[0]=A[0]+e,t[1]=A[1]+e,t[2]=A[2]+e,t[3]=A[3]+e,t[4]=A[4]+e,t[5]=A[5]+e,t[6]=A[6]+e,t[7]=A[7]+e,t[8]=A[8]+e,t[9]=A[9]+e,t[10]=A[10]+e,t[11]=A[11]+e,t[12]=A[12]+e,t[13]=A[13]+e,t[14]=A[14]+e,t[15]=A[15]+e,t),addScalarMat4:(A,e,t)=>g.addMat4Scalar(e,A,t),subMat4:(A,e,t)=>(t||(t=A),t[0]=A[0]-e[0],t[1]=A[1]-e[1],t[2]=A[2]-e[2],t[3]=A[3]-e[3],t[4]=A[4]-e[4],t[5]=A[5]-e[5],t[6]=A[6]-e[6],t[7]=A[7]-e[7],t[8]=A[8]-e[8],t[9]=A[9]-e[9],t[10]=A[10]-e[10],t[11]=A[11]-e[11],t[12]=A[12]-e[12],t[13]=A[13]-e[13],t[14]=A[14]-e[14],t[15]=A[15]-e[15],t),subMat4Scalar:(A,e,t)=>(t||(t=A),t[0]=A[0]-e,t[1]=A[1]-e,t[2]=A[2]-e,t[3]=A[3]-e,t[4]=A[4]-e,t[5]=A[5]-e,t[6]=A[6]-e,t[7]=A[7]-e,t[8]=A[8]-e,t[9]=A[9]-e,t[10]=A[10]-e,t[11]=A[11]-e,t[12]=A[12]-e,t[13]=A[13]-e,t[14]=A[14]-e,t[15]=A[15]-e,t),subScalarMat4:(A,e,t)=>(t||(t=e),t[0]=A-e[0],t[1]=A-e[1],t[2]=A-e[2],t[3]=A-e[3],t[4]=A-e[4],t[5]=A-e[5],t[6]=A-e[6],t[7]=A-e[7],t[8]=A-e[8],t[9]=A-e[9],t[10]=A-e[10],t[11]=A-e[11],t[12]=A-e[12],t[13]=A-e[13],t[14]=A-e[14],t[15]=A-e[15],t),mulMat4(A,e,t){t||(t=A);const i=A[0],s=A[1],n=A[2],o=A[3],r=A[4],c=A[5],a=A[6],h=A[7],B=A[8],g=A[9],l=A[10],E=A[11],Q=A[12],M=A[13],u=A[14],w=A[15],d=e[0],C=e[1],x=e[2],F=e[3],p=e[4],I=e[5],f=e[6],Y=e[7],D=e[8],m=e[9],J=e[10],N=e[11],y=e[12],z=e[13],T=e[14],U=e[15];return t[0]=d*i+C*r+x*B+F*Q,t[1]=d*s+C*c+x*g+F*M,t[2]=d*n+C*a+x*l+F*u,t[3]=d*o+C*h+x*E+F*w,t[4]=p*i+I*r+f*B+Y*Q,t[5]=p*s+I*c+f*g+Y*M,t[6]=p*n+I*a+f*l+Y*u,t[7]=p*o+I*h+f*E+Y*w,t[8]=D*i+m*r+J*B+N*Q,t[9]=D*s+m*c+J*g+N*M,t[10]=D*n+m*a+J*l+N*u,t[11]=D*o+m*h+J*E+N*w,t[12]=y*i+z*r+T*B+U*Q,t[13]=y*s+z*c+T*g+U*M,t[14]=y*n+z*a+T*l+U*u,t[15]=y*o+z*h+T*E+U*w,t},mulMat3(A,e,t){t||(t=new r(9));const i=A[0],s=A[3],n=A[6],o=A[1],c=A[4],a=A[7],h=A[2],B=A[5],g=A[8],l=e[0],E=e[3],Q=e[6],M=e[1],u=e[4],w=e[7],d=e[2],C=e[5],x=e[8];return t[0]=i*l+s*M+n*d,t[3]=i*E+s*u+n*C,t[6]=i*Q+s*w+n*x,t[1]=o*l+c*M+a*d,t[4]=o*E+c*u+a*C,t[7]=o*Q+c*w+a*x,t[2]=h*l+B*M+g*d,t[5]=h*E+B*u+g*C,t[8]=h*Q+B*w+g*x,t},mulMat4Scalar:(A,e,t)=>(t||(t=A),t[0]=A[0]*e,t[1]=A[1]*e,t[2]=A[2]*e,t[3]=A[3]*e,t[4]=A[4]*e,t[5]=A[5]*e,t[6]=A[6]*e,t[7]=A[7]*e,t[8]=A[8]*e,t[9]=A[9]*e,t[10]=A[10]*e,t[11]=A[11]*e,t[12]=A[12]*e,t[13]=A[13]*e,t[14]=A[14]*e,t[15]=A[15]*e,t),mulMat4v4(A,e,t=g.vec4()){const i=e[0],s=e[1],n=e[2],o=e[3];return t[0]=A[0]*i+A[4]*s+A[8]*n+A[12]*o,t[1]=A[1]*i+A[5]*s+A[9]*n+A[13]*o,t[2]=A[2]*i+A[6]*s+A[10]*n+A[14]*o,t[3]=A[3]*i+A[7]*s+A[11]*n+A[15]*o,t},transposeMat4(A,e){const t=A[4],i=A[14],s=A[8],n=A[13],o=A[12],r=A[9];if(!e||A===e){const e=A[1],c=A[2],a=A[3],h=A[6],B=A[7],g=A[11];return A[1]=t,A[2]=s,A[3]=o,A[4]=e,A[6]=r,A[7]=n,A[8]=c,A[9]=h,A[11]=i,A[12]=a,A[13]=B,A[14]=g,A}return e[0]=A[0],e[1]=t,e[2]=s,e[3]=o,e[4]=A[1],e[5]=A[5],e[6]=r,e[7]=n,e[8]=A[2],e[9]=A[6],e[10]=A[10],e[11]=i,e[12]=A[3],e[13]=A[7],e[14]=A[11],e[15]=A[15],e},transposeMat3(A,e){if(e===A){const t=A[1],i=A[2],s=A[5];e[1]=A[3],e[2]=A[6],e[3]=t,e[5]=A[7],e[6]=i,e[7]=s}else e[0]=A[0],e[1]=A[3],e[2]=A[6],e[3]=A[1],e[4]=A[4],e[5]=A[7],e[6]=A[2],e[7]=A[5],e[8]=A[8];return e},determinantMat4(A){const e=A[0],t=A[1],i=A[2],s=A[3],n=A[4],o=A[5],r=A[6],c=A[7],a=A[8],h=A[9],B=A[10],g=A[11],l=A[12],E=A[13],Q=A[14],M=A[15];return l*h*r*s-a*E*r*s-l*o*B*s+n*E*B*s+a*o*Q*s-n*h*Q*s-l*h*i*c+a*E*i*c+l*t*B*c-e*E*B*c-a*t*Q*c+e*h*Q*c+l*o*i*g-n*E*i*g-l*t*r*g+e*E*r*g+n*t*Q*g-e*o*Q*g-a*o*i*M+n*h*i*M+a*t*r*M-e*h*r*M-n*t*B*M+e*o*B*M},inverseMat4(A,e){e||(e=A);const t=A[0],i=A[1],s=A[2],n=A[3],o=A[4],r=A[5],c=A[6],a=A[7],h=A[8],B=A[9],g=A[10],l=A[11],E=A[12],Q=A[13],M=A[14],u=A[15],w=t*r-i*o,d=t*c-s*o,C=t*a-n*o,x=i*c-s*r,F=i*a-n*r,p=s*a-n*c,I=h*Q-B*E,f=h*M-g*E,Y=h*u-l*E,D=B*M-g*Q,m=B*u-l*Q,J=g*u-l*M,N=1/(w*J-d*m+C*D+x*Y-F*f+p*I);return e[0]=(r*J-c*m+a*D)*N,e[1]=(-i*J+s*m-n*D)*N,e[2]=(Q*p-M*F+u*x)*N,e[3]=(-B*p+g*F-l*x)*N,e[4]=(-o*J+c*Y-a*f)*N,e[5]=(t*J-s*Y+n*f)*N,e[6]=(-E*p+M*C-u*d)*N,e[7]=(h*p-g*C+l*d)*N,e[8]=(o*m-r*Y+a*I)*N,e[9]=(-t*m+i*Y-n*I)*N,e[10]=(E*F-Q*C+u*w)*N,e[11]=(-h*F+B*C-l*w)*N,e[12]=(-o*D+r*f-c*I)*N,e[13]=(t*D-i*f+s*I)*N,e[14]=(-E*x+Q*d-M*w)*N,e[15]=(h*x-B*d+g*w)*N,e},traceMat4:A=>A[0]+A[5]+A[10]+A[15],translationMat4v(A,e){const t=e||g.identityMat4();return t[12]=A[0],t[13]=A[1],t[14]=A[2],t},translationMat3v(A,e){const t=e||g.identityMat3();return t[6]=A[0],t[7]=A[1],t},translationMat4c:(()=>{const A=new r(3);return(e,t,i,s)=>(A[0]=e,A[1]=t,A[2]=i,g.translationMat4v(A,s))})(),translationMat4s:(A,e)=>g.translationMat4c(A,A,A,e),translateMat4v:(A,e)=>g.translateMat4c(A[0],A[1],A[2],e),translateMat4c(A,e,t,i){const s=i[3];i[0]+=s*A,i[1]+=s*e,i[2]+=s*t;const n=i[7];i[4]+=n*A,i[5]+=n*e,i[6]+=n*t;const o=i[11];i[8]+=o*A,i[9]+=o*e,i[10]+=o*t;const r=i[15];return i[12]+=r*A,i[13]+=r*e,i[14]+=r*t,i},setMat4Translation:(A,e,t)=>(t[0]=A[0],t[1]=A[1],t[2]=A[2],t[3]=A[3],t[4]=A[4],t[5]=A[5],t[6]=A[6],t[7]=A[7],t[8]=A[8],t[9]=A[9],t[10]=A[10],t[11]=A[11],t[12]=e[0],t[13]=e[1],t[14]=e[2],t[15]=A[15],t),rotationMat4v(A,e,t){const i=g.normalizeVec4([e[0],e[1],e[2],0],[]),s=Math.sin(A),n=Math.cos(A),o=1-n,r=i[0],c=i[1],a=i[2];let h,B,l,E,Q,M;return h=r*c,B=c*a,l=a*r,E=r*s,Q=c*s,M=a*s,(t=t||g.mat4())[0]=o*r*r+n,t[1]=o*h+M,t[2]=o*l-Q,t[3]=0,t[4]=o*h-M,t[5]=o*c*c+n,t[6]=o*B+E,t[7]=0,t[8]=o*l+Q,t[9]=o*B-E,t[10]=o*a*a+n,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t},rotationMat4c:(A,e,t,i,s)=>g.rotationMat4v(A,[e,t,i],s),scalingMat4v:(A,e=g.identityMat4())=>(e[0]=A[0],e[5]=A[1],e[10]=A[2],e),scalingMat3v:(A,e=g.identityMat3())=>(e[0]=A[0],e[4]=A[1],e),scalingMat4c:(()=>{const A=new r(3);return(e,t,i,s)=>(A[0]=e,A[1]=t,A[2]=i,g.scalingMat4v(A,s))})(),scaleMat4c:(A,e,t,i)=>(i[0]*=A,i[4]*=e,i[8]*=t,i[1]*=A,i[5]*=e,i[9]*=t,i[2]*=A,i[6]*=e,i[10]*=t,i[3]*=A,i[7]*=e,i[11]*=t,i),scaleMat4v(A,e){const t=A[0],i=A[1],s=A[2];return e[0]*=t,e[4]*=i,e[8]*=s,e[1]*=t,e[5]*=i,e[9]*=s,e[2]*=t,e[6]*=i,e[10]*=s,e[3]*=t,e[7]*=i,e[11]*=s,e},scalingMat4s:A=>g.scalingMat4c(A,A,A),rotationTranslationMat4(A,e,t=g.mat4()){const i=A[0],s=A[1],n=A[2],o=A[3],r=i+i,c=s+s,a=n+n,h=i*r,B=i*c,l=i*a,E=s*c,Q=s*a,M=n*a,u=o*r,w=o*c,d=o*a;return t[0]=1-(E+M),t[1]=B+d,t[2]=l-w,t[3]=0,t[4]=B-d,t[5]=1-(h+M),t[6]=Q+u,t[7]=0,t[8]=l+w,t[9]=Q-u,t[10]=1-(h+E),t[11]=0,t[12]=e[0],t[13]=e[1],t[14]=e[2],t[15]=1,t},mat4ToEuler(A,e,t=g.vec4()){const i=g.clamp,s=A[0],n=A[4],o=A[8],r=A[1],c=A[5],a=A[9],h=A[2],B=A[6],l=A[10];return"XYZ"===e?(t[1]=Math.asin(i(o,-1,1)),Math.abs(o)<.99999?(t[0]=Math.atan2(-a,l),t[2]=Math.atan2(-n,s)):(t[0]=Math.atan2(B,c),t[2]=0)):"YXZ"===e?(t[0]=Math.asin(-i(a,-1,1)),Math.abs(a)<.99999?(t[1]=Math.atan2(o,l),t[2]=Math.atan2(r,c)):(t[1]=Math.atan2(-h,s),t[2]=0)):"ZXY"===e?(t[0]=Math.asin(i(B,-1,1)),Math.abs(B)<.99999?(t[1]=Math.atan2(-h,l),t[2]=Math.atan2(-n,c)):(t[1]=0,t[2]=Math.atan2(r,s))):"ZYX"===e?(t[1]=Math.asin(-i(h,-1,1)),Math.abs(h)<.99999?(t[0]=Math.atan2(B,l),t[2]=Math.atan2(r,s)):(t[0]=0,t[2]=Math.atan2(-n,c))):"YZX"===e?(t[2]=Math.asin(i(r,-1,1)),Math.abs(r)<.99999?(t[0]=Math.atan2(-a,c),t[1]=Math.atan2(-h,s)):(t[0]=0,t[1]=Math.atan2(o,l))):"XZY"===e&&(t[2]=Math.asin(-i(n,-1,1)),Math.abs(n)<.99999?(t[0]=Math.atan2(B,c),t[1]=Math.atan2(o,s)):(t[0]=Math.atan2(-a,l),t[1]=0)),t[0]*=g.RADTODEG,t[1]*=g.RADTODEG,t[2]*=g.RADTODEG,t},composeMat4:(A,e,t,i=g.mat4())=>(g.quaternionToRotationMat4(e,i),g.scaleMat4v(t,i),g.translateMat4v(A,i),i),decomposeMat4:(()=>{const A=new r(3),e=new r(16);return function(t,i,s,n){A[0]=t[0],A[1]=t[1],A[2]=t[2];let o=g.lenVec3(A);A[0]=t[4],A[1]=t[5],A[2]=t[6];const r=g.lenVec3(A);A[8]=t[8],A[9]=t[9],A[10]=t[10];const c=g.lenVec3(A);g.determinantMat4(t)<0&&(o=-o),i[0]=t[12],i[1]=t[13],i[2]=t[14],e.set(t);const a=1/o,h=1/r,B=1/c;return e[0]*=a,e[1]*=a,e[2]*=a,e[4]*=h,e[5]*=h,e[6]*=h,e[8]*=B,e[9]*=B,e[10]*=B,g.mat4ToQuaternion(e,s),n[0]=o,n[1]=r,n[2]=c,this}})(),getColMat4(A,e){const t=4*e;return[A[t],A[t+1],A[t+2],A[t+3]]},setRowMat4(A,e,t){A[e]=t[0],A[e+4]=t[1],A[e+8]=t[2],A[e+12]=t[3]},lookAtMat4v(A,e,t,i){i||(i=g.mat4());const s=A[0],n=A[1],o=A[2],r=t[0],c=t[1],a=t[2],h=e[0],B=e[1],l=e[2];if(s===h&&n===B&&o===l)return g.identityMat4();let E,Q,M,u,w,d,C,x,F,p;return E=s-h,Q=n-B,M=o-l,p=1/Math.sqrt(E*E+Q*Q+M*M),E*=p,Q*=p,M*=p,u=c*M-a*Q,w=a*E-r*M,d=r*Q-c*E,p=Math.sqrt(u*u+w*w+d*d),p?(p=1/p,u*=p,w*=p,d*=p):(u=0,w=0,d=0),C=Q*d-M*w,x=M*u-E*d,F=E*w-Q*u,p=Math.sqrt(C*C+x*x+F*F),p?(p=1/p,C*=p,x*=p,F*=p):(C=0,x=0,F=0),i[0]=u,i[1]=C,i[2]=E,i[3]=0,i[4]=w,i[5]=x,i[6]=Q,i[7]=0,i[8]=d,i[9]=F,i[10]=M,i[11]=0,i[12]=-(u*s+w*n+d*o),i[13]=-(C*s+x*n+F*o),i[14]=-(E*s+Q*n+M*o),i[15]=1,i},lookAtMat4c:(A,e,t,i,s,n,o,r,c)=>g.lookAtMat4v([A,e,t],[i,s,n],[o,r,c],[]),orthoMat4c(A,e,t,i,s,n,o){o||(o=g.mat4());const r=e-A,c=i-t,a=n-s;return o[0]=2/r,o[1]=0,o[2]=0,o[3]=0,o[4]=0,o[5]=2/c,o[6]=0,o[7]=0,o[8]=0,o[9]=0,o[10]=-2/a,o[11]=0,o[12]=-(A+e)/r,o[13]=-(i+t)/c,o[14]=-(n+s)/a,o[15]=1,o},frustumMat4v(A,e,t){t||(t=g.mat4());const i=[A[0],A[1],A[2],0],s=[e[0],e[1],e[2],0];g.addVec4(s,i,a),g.subVec4(s,i,h);const n=2*i[2],o=h[0],r=h[1],c=h[2];return t[0]=n/o,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=n/r,t[6]=0,t[7]=0,t[8]=a[0]/o,t[9]=a[1]/r,t[10]=-a[2]/c,t[11]=-1,t[12]=0,t[13]=0,t[14]=-n*s[2]/c,t[15]=0,t},frustumMat4(A,e,t,i,s,n,o){o||(o=g.mat4());const r=e-A,c=i-t,a=n-s;return o[0]=2*s/r,o[1]=0,o[2]=0,o[3]=0,o[4]=0,o[5]=2*s/c,o[6]=0,o[7]=0,o[8]=(e+A)/r,o[9]=(i+t)/c,o[10]=-(n+s)/a,o[11]=-1,o[12]=0,o[13]=0,o[14]=-n*s*2/a,o[15]=0,o},perspectiveMat4(A,e,t,i,s){const n=[],o=[];return n[2]=t,o[2]=i,o[1]=n[2]*Math.tan(A/2),n[1]=-o[1],o[0]=o[1]*e,n[0]=-o[0],g.frustumMat4v(n,o,s)},compareMat4:(A,e)=>A[0]===e[0]&&A[1]===e[1]&&A[2]===e[2]&&A[3]===e[3]&&A[4]===e[4]&&A[5]===e[5]&&A[6]===e[6]&&A[7]===e[7]&&A[8]===e[8]&&A[9]===e[9]&&A[10]===e[10]&&A[11]===e[11]&&A[12]===e[12]&&A[13]===e[13]&&A[14]===e[14]&&A[15]===e[15],transformPoint3(A,e,t=g.vec3()){const i=e[0],s=e[1],n=e[2];return t[0]=A[0]*i+A[4]*s+A[8]*n+A[12],t[1]=A[1]*i+A[5]*s+A[9]*n+A[13],t[2]=A[2]*i+A[6]*s+A[10]*n+A[14],t},transformPoint4:(A,e,t=g.vec4())=>(t[0]=A[0]*e[0]+A[4]*e[1]+A[8]*e[2]+A[12]*e[3],t[1]=A[1]*e[0]+A[5]*e[1]+A[9]*e[2]+A[13]*e[3],t[2]=A[2]*e[0]+A[6]*e[1]+A[10]*e[2]+A[14]*e[3],t[3]=A[3]*e[0]+A[7]*e[1]+A[11]*e[2]+A[15]*e[3],t),transformPoints3(A,e,t){const i=t||[],s=e.length;let n,o,r,c;const a=A[0],h=A[1],B=A[2],g=A[3],l=A[4],E=A[5],Q=A[6],M=A[7],u=A[8],w=A[9],d=A[10],C=A[11],x=A[12],F=A[13],p=A[14],I=A[15];let f;for(let A=0;A<s;++A)c=e[A],n=c[0],o=c[1],r=c[2],f=i[A]||(i[A]=[0,0,0]),f[0]=a*n+l*o+u*r+x,f[1]=h*n+E*o+w*r+F,f[2]=B*n+Q*o+d*r+p,f[3]=g*n+M*o+C*r+I;return i.length=s,i},transformPositions3(A,e,t=e){let i;const s=e.length;let n,o,r;const c=A[0],a=A[1],h=A[2];A[3];const B=A[4],g=A[5],l=A[6];A[7];const E=A[8],Q=A[9],M=A[10];A[11];const u=A[12],w=A[13],d=A[14];for(A[15],i=0;i<s;i+=3)n=e[i+0],o=e[i+1],r=e[i+2],t[i+0]=c*n+B*o+E*r+u,t[i+1]=a*n+g*o+Q*r+w,t[i+2]=h*n+l*o+M*r+d;return t},transformPositions4(A,e,t=e){let i;const s=e.length;let n,o,r;const c=A[0],a=A[1],h=A[2],B=A[3],g=A[4],l=A[5],E=A[6],Q=A[7],M=A[8],u=A[9],w=A[10],d=A[11],C=A[12],x=A[13],F=A[14],p=A[15];for(i=0;i<s;i+=4)n=e[i+0],o=e[i+1],r=e[i+2],t[i+0]=c*n+g*o+M*r+C,t[i+1]=a*n+l*o+u*r+x,t[i+2]=h*n+E*o+w*r+F,t[i+3]=B*n+Q*o+d*r+p;return t},transformVec3(A,e,t){const i=e[0],s=e[1],n=e[2];return(t=t||this.vec3())[0]=A[0]*i+A[4]*s+A[8]*n,t[1]=A[1]*i+A[5]*s+A[9]*n,t[2]=A[2]*i+A[6]*s+A[10]*n,t},transformVec4(A,e,t){const i=e[0],s=e[1],n=e[2],o=e[3];return(t=t||g.vec4())[0]=A[0]*i+A[4]*s+A[8]*n+A[12]*o,t[1]=A[1]*i+A[5]*s+A[9]*n+A[13]*o,t[2]=A[2]*i+A[6]*s+A[10]*n+A[14]*o,t[3]=A[3]*i+A[7]*s+A[11]*n+A[15]*o,t},rotateVec2(A,e,t,i=A){const s=Math.cos(t),n=Math.sin(t),o=A[0]-e[0],r=A[1]-e[1];return i[0]=o*s-r*n+e[0],i[1]=o*n+r*s+e[1],A},rotateVec3X(A,e,t,i){const s=[],n=[];return s[0]=A[0]-e[0],s[1]=A[1]-e[1],s[2]=A[2]-e[2],n[0]=s[0],n[1]=s[1]*Math.cos(t)-s[2]*Math.sin(t),n[2]=s[1]*Math.sin(t)+s[2]*Math.cos(t),i[0]=n[0]+e[0],i[1]=n[1]+e[1],i[2]=n[2]+e[2],i},rotateVec3Y(A,e,t,i){const s=[],n=[];return s[0]=A[0]-e[0],s[1]=A[1]-e[1],s[2]=A[2]-e[2],n[0]=s[2]*Math.sin(t)+s[0]*Math.cos(t),n[1]=s[1],n[2]=s[2]*Math.cos(t)-s[0]*Math.sin(t),i[0]=n[0]+e[0],i[1]=n[1]+e[1],i[2]=n[2]+e[2],i},rotateVec3Z(A,e,t,i){const s=[],n=[];return s[0]=A[0]-e[0],s[1]=A[1]-e[1],s[2]=A[2]-e[2],n[0]=s[0]*Math.cos(t)-s[1]*Math.sin(t),n[1]=s[0]*Math.sin(t)+s[1]*Math.cos(t),n[2]=s[2],i[0]=n[0]+e[0],i[1]=n[1]+e[1],i[2]=n[2]+e[2],i},projectVec4(A,e){const t=1/A[3];return(e=e||g.vec2())[0]=A[0]*t,e[1]=A[1]*t,e},unprojectVec3:(()=>{const A=new r(16),e=new r(16),t=new r(16);return function(i,s,n,o){return this.transformVec3(this.mulMat4(this.inverseMat4(s,A),this.inverseMat4(n,e),t),i,o)}})(),lerpVec3(A,e,t,i,s,n){const o=n||g.vec3(),r=(A-e)/(t-e);return o[0]=i[0]+r*(s[0]-i[0]),o[1]=i[1]+r*(s[1]-i[1]),o[2]=i[2]+r*(s[2]-i[2]),o},lerpMat4(A,e,t,i,s,n){const o=n||g.mat4(),r=(A-e)/(t-e);return o[0]=i[0]+r*(s[0]-i[0]),o[1]=i[1]+r*(s[1]-i[1]),o[2]=i[2]+r*(s[2]-i[2]),o[3]=i[3]+r*(s[3]-i[3]),o[4]=i[4]+r*(s[4]-i[4]),o[5]=i[5]+r*(s[5]-i[5]),o[6]=i[6]+r*(s[6]-i[6]),o[7]=i[7]+r*(s[7]-i[7]),o[8]=i[8]+r*(s[8]-i[8]),o[9]=i[9]+r*(s[9]-i[9]),o[10]=i[10]+r*(s[10]-i[10]),o[11]=i[11]+r*(s[11]-i[11]),o[12]=i[12]+r*(s[12]-i[12]),o[13]=i[13]+r*(s[13]-i[13]),o[14]=i[14]+r*(s[14]-i[14]),o[15]=i[15]+r*(s[15]-i[15]),o},flatten(A){const e=[];let t,i,s,n,o;for(t=0,i=A.length;t<i;t++)for(o=A[t],s=0,n=o.length;s<n;s++)e.push(o[s]);return e},identityQuaternion:(A=g.vec4())=>(A[0]=0,A[1]=0,A[2]=0,A[3]=1,A),eulerToQuaternion(A,e,t=g.vec4()){const i=A[0]*g.DEGTORAD/2,s=A[1]*g.DEGTORAD/2,n=A[2]*g.DEGTORAD/2,o=Math.cos(i),r=Math.cos(s),c=Math.cos(n),a=Math.sin(i),h=Math.sin(s),B=Math.sin(n);return"XYZ"===e?(t[0]=a*r*c+o*h*B,t[1]=o*h*c-a*r*B,t[2]=o*r*B+a*h*c,t[3]=o*r*c-a*h*B):"YXZ"===e?(t[0]=a*r*c+o*h*B,t[1]=o*h*c-a*r*B,t[2]=o*r*B-a*h*c,t[3]=o*r*c+a*h*B):"ZXY"===e?(t[0]=a*r*c-o*h*B,t[1]=o*h*c+a*r*B,t[2]=o*r*B+a*h*c,t[3]=o*r*c-a*h*B):"ZYX"===e?(t[0]=a*r*c-o*h*B,t[1]=o*h*c+a*r*B,t[2]=o*r*B-a*h*c,t[3]=o*r*c+a*h*B):"YZX"===e?(t[0]=a*r*c+o*h*B,t[1]=o*h*c+a*r*B,t[2]=o*r*B-a*h*c,t[3]=o*r*c-a*h*B):"XZY"===e&&(t[0]=a*r*c-o*h*B,t[1]=o*h*c-a*r*B,t[2]=o*r*B+a*h*c,t[3]=o*r*c+a*h*B),t},mat4ToQuaternion(A,e=g.vec4()){const t=A[0],i=A[4],s=A[8],n=A[1],o=A[5],r=A[9],c=A[2],a=A[6],h=A[10];let B;const l=t+o+h;return l>0?(B=.5/Math.sqrt(l+1),e[3]=.25/B,e[0]=(a-r)*B,e[1]=(s-c)*B,e[2]=(n-i)*B):t>o&&t>h?(B=2*Math.sqrt(1+t-o-h),e[3]=(a-r)/B,e[0]=.25*B,e[1]=(i+n)/B,e[2]=(s+c)/B):o>h?(B=2*Math.sqrt(1+o-t-h),e[3]=(s-c)/B,e[0]=(i+n)/B,e[1]=.25*B,e[2]=(r+a)/B):(B=2*Math.sqrt(1+h-t-o),e[3]=(n-i)/B,e[0]=(s+c)/B,e[1]=(r+a)/B,e[2]=.25*B),e},vec3PairToQuaternion(A,e,t=g.vec4()){const i=Math.sqrt(g.dotVec3(A,A)*g.dotVec3(e,e));let s=i+g.dotVec3(A,e);return s<1e-8*i?(s=0,Math.abs(A[0])>Math.abs(A[2])?(t[0]=-A[1],t[1]=A[0],t[2]=0):(t[0]=0,t[1]=-A[2],t[2]=A[1])):g.cross3Vec3(A,e,t),t[3]=s,g.normalizeQuaternion(t)},angleAxisToQuaternion(A,e=g.vec4()){const t=A[3]/2,i=Math.sin(t);return e[0]=i*A[0],e[1]=i*A[1],e[2]=i*A[2],e[3]=Math.cos(t),e},quaternionToEuler:(()=>{const A=new r(16);return(e,t,i)=>(i=i||g.vec3(),g.quaternionToRotationMat4(e,A),g.mat4ToEuler(A,t,i),i)})(),mulQuaternions(A,e,t=g.vec4()){const i=A[0],s=A[1],n=A[2],o=A[3],r=e[0],c=e[1],a=e[2],h=e[3];return t[0]=o*r+i*h+s*a-n*c,t[1]=o*c+s*h+n*r-i*a,t[2]=o*a+n*h+i*c-s*r,t[3]=o*h-i*r-s*c-n*a,t},vec3ApplyQuaternion(A,e,t=g.vec3()){const i=e[0],s=e[1],n=e[2],o=A[0],r=A[1],c=A[2],a=A[3],h=a*i+r*n-c*s,B=a*s+c*i-o*n,l=a*n+o*s-r*i,E=-o*i-r*s-c*n;return t[0]=h*a+E*-o+B*-c-l*-r,t[1]=B*a+E*-r+l*-o-h*-c,t[2]=l*a+E*-c+h*-r-B*-o,t},quaternionToMat4(A,e){e=g.identityMat4(e);const t=A[0],i=A[1],s=A[2],n=A[3],o=2*t,r=2*i,c=2*s,a=o*n,h=r*n,B=c*n,l=o*t,E=r*t,Q=c*t,M=r*i,u=c*i,w=c*s;return e[0]=1-(M+w),e[1]=E+B,e[2]=Q-h,e[4]=E-B,e[5]=1-(l+w),e[6]=u+a,e[8]=Q+h,e[9]=u-a,e[10]=1-(l+M),e},quaternionToRotationMat4(A,e){const t=A[0],i=A[1],s=A[2],n=A[3],o=t+t,r=i+i,c=s+s,a=t*o,h=t*r,B=t*c,g=i*r,l=i*c,E=s*c,Q=n*o,M=n*r,u=n*c;return e[0]=1-(g+E),e[4]=h-u,e[8]=B+M,e[1]=h+u,e[5]=1-(a+E),e[9]=l-Q,e[2]=B-M,e[6]=l+Q,e[10]=1-(a+g),e[3]=0,e[7]=0,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e},normalizeQuaternion(A,e=A){const t=g.lenVec4([A[0],A[1],A[2],A[3]]);return e[0]=A[0]/t,e[1]=A[1]/t,e[2]=A[2]/t,e[3]=A[3]/t,e},conjugateQuaternion:(A,e=A)=>(e[0]=-A[0],e[1]=-A[1],e[2]=-A[2],e[3]=A[3],e),inverseQuaternion:(A,e)=>g.normalizeQuaternion(g.conjugateQuaternion(A,e)),quaternionToAngleAxis(A,e=g.vec4()){const t=(A=g.normalizeQuaternion(A,B))[3],i=2*Math.acos(t),s=Math.sqrt(1-t*t);return s<.001?(e[0]=A[0],e[1]=A[1],e[2]=A[2]):(e[0]=A[0]/s,e[1]=A[1]/s,e[2]=A[2]/s),e[3]=i,e},AABB3:A=>new r(A||6),AABB2:A=>new r(A||4),OBB3:A=>new r(A||32),OBB2:A=>new r(A||16),Sphere3:(A,e,t,i)=>new r([A,e,t,i]),transformOBB3(A,e,t=e){let i;const s=e.length;let n,o,r;const c=A[0],a=A[1],h=A[2],B=A[3],g=A[4],l=A[5],E=A[6],Q=A[7],M=A[8],u=A[9],w=A[10],d=A[11],C=A[12],x=A[13],F=A[14],p=A[15];for(i=0;i<s;i+=4)n=e[i+0],o=e[i+1],r=e[i+2],t[i+0]=c*n+g*o+M*r+C,t[i+1]=a*n+l*o+u*r+x,t[i+2]=h*n+E*o+w*r+F,t[i+3]=B*n+Q*o+d*r+p;return t},containsAABB3:function(A,e){return A[0]<=e[0]&&e[3]<=A[3]&&A[1]<=e[1]&&e[4]<=A[4]&&A[2]<=e[2]&&e[5]<=A[5]},getAABB3Diag:(()=>{const A=new r(3),e=new r(3),t=new r(3);return i=>(A[0]=i[0],A[1]=i[1],A[2]=i[2],e[0]=i[3],e[1]=i[4],e[2]=i[5],g.subVec3(e,A,t),Math.abs(g.lenVec3(t)))})(),getAABB3DiagPoint:(()=>{const A=new r(3),e=new r(3),t=new r(3);return(i,s)=>{A[0]=i[0],A[1]=i[1],A[2]=i[2],e[0]=i[3],e[1]=i[4],e[2]=i[5];const n=g.subVec3(e,A,t),o=s[0]-i[0],r=i[3]-s[0],c=s[1]-i[1],a=i[4]-s[1],h=s[2]-i[2],B=i[5]-s[2];return n[0]+=o>r?o:r,n[1]+=c>a?c:a,n[2]+=h>B?h:B,Math.abs(g.lenVec3(n))}})(),getAABB3Area:A=>(A[3]-A[0])*(A[4]-A[1])*(A[5]-A[2]),getAABB3Center(A,e){const t=e||g.vec3();return t[0]=(A[0]+A[3])/2,t[1]=(A[1]+A[4])/2,t[2]=(A[2]+A[5])/2,t},getAABB2Center(A,e){const t=e||g.vec2();return t[0]=(A[2]+A[0])/2,t[1]=(A[3]+A[1])/2,t},collapseAABB3:(A=g.AABB3())=>(A[0]=g.MAX_DOUBLE,A[1]=g.MAX_DOUBLE,A[2]=g.MAX_DOUBLE,A[3]=g.MIN_DOUBLE,A[4]=g.MIN_DOUBLE,A[5]=g.MIN_DOUBLE,A),AABB3ToOBB3:(A,e=g.OBB3())=>(e[0]=A[0],e[1]=A[1],e[2]=A[2],e[3]=1,e[4]=A[3],e[5]=A[1],e[6]=A[2],e[7]=1,e[8]=A[3],e[9]=A[4],e[10]=A[2],e[11]=1,e[12]=A[0],e[13]=A[4],e[14]=A[2],e[15]=1,e[16]=A[0],e[17]=A[1],e[18]=A[5],e[19]=1,e[20]=A[3],e[21]=A[1],e[22]=A[5],e[23]=1,e[24]=A[3],e[25]=A[4],e[26]=A[5],e[27]=1,e[28]=A[0],e[29]=A[4],e[30]=A[5],e[31]=1,e),positions3ToAABB3:(()=>{const A=new r(3);return(e,t,i)=>{t=t||g.AABB3();let s,n,o,r=g.MAX_DOUBLE,c=g.MAX_DOUBLE,a=g.MAX_DOUBLE,h=g.MIN_DOUBLE,B=g.MIN_DOUBLE,l=g.MIN_DOUBLE;for(let t=0,E=e.length;t<E;t+=3)i?(A[0]=e[t+0],A[1]=e[t+1],A[2]=e[t+2],g.decompressPosition(A,i,A),s=A[0],n=A[1],o=A[2]):(s=e[t+0],n=e[t+1],o=e[t+2]),s<r&&(r=s),n<c&&(c=n),o<a&&(a=o),s>h&&(h=s),n>B&&(B=n),o>l&&(l=o);return t[0]=r,t[1]=c,t[2]=a,t[3]=h,t[4]=B,t[5]=l,t}})(),OBB3ToAABB3(A,e=g.AABB3()){let t,i,s,n=g.MAX_DOUBLE,o=g.MAX_DOUBLE,r=g.MAX_DOUBLE,c=g.MIN_DOUBLE,a=g.MIN_DOUBLE,h=g.MIN_DOUBLE;for(let e=0,B=A.length;e<B;e+=4)t=A[e+0],i=A[e+1],s=A[e+2],t<n&&(n=t),i<o&&(o=i),s<r&&(r=s),t>c&&(c=t),i>a&&(a=i),s>h&&(h=s);return e[0]=n,e[1]=o,e[2]=r,e[3]=c,e[4]=a,e[5]=h,e},points3ToAABB3(A,e=g.AABB3()){let t,i,s,n=g.MAX_DOUBLE,o=g.MAX_DOUBLE,r=g.MAX_DOUBLE,c=g.MIN_DOUBLE,a=g.MIN_DOUBLE,h=g.MIN_DOUBLE;for(let e=0,B=A.length;e<B;e++)t=A[e][0],i=A[e][1],s=A[e][2],t<n&&(n=t),i<o&&(o=i),s<r&&(r=s),t>c&&(c=t),i>a&&(a=i),s>h&&(h=s);return e[0]=n,e[1]=o,e[2]=r,e[3]=c,e[4]=a,e[5]=h,e},points3ToSphere3:(()=>{const A=new r(3);return(e,t)=>{t=t||g.vec4();let i,s=0,n=0,o=0;const r=e.length;for(i=0;i<r;i++)s+=e[i][0],n+=e[i][1],o+=e[i][2];t[0]=s/r,t[1]=n/r,t[2]=o/r;let c,a=0;for(i=0;i<r;i++)c=Math.abs(g.lenVec3(g.subVec3(e[i],t,A))),c>a&&(a=c);return t[3]=a,t}})(),positions3ToSphere3:(()=>{const A=new r(3),e=new r(3);return(t,i)=>{i=i||g.vec4();let s,n=0,o=0,r=0;const c=t.length;let a=0;for(s=0;s<c;s+=3)n+=t[s],o+=t[s+1],r+=t[s+2];const h=c/3;let B;for(i[0]=n/h,i[1]=o/h,i[2]=r/h,s=0;s<c;s+=3)A[0]=t[s],A[1]=t[s+1],A[2]=t[s+2],B=Math.abs(g.lenVec3(g.subVec3(A,i,e))),B>a&&(a=B);return i[3]=a,i}})(),OBB3ToSphere3:(()=>{const A=new r(3),e=new r(3);return(t,i)=>{i=i||g.vec4();let s,n=0,o=0,r=0;const c=t.length,a=c/4;for(s=0;s<c;s+=4)n+=t[s+0],o+=t[s+1],r+=t[s+2];i[0]=n/a,i[1]=o/a,i[2]=r/a;let h,B=0;for(s=0;s<c;s+=4)A[0]=t[s+0],A[1]=t[s+1],A[2]=t[s+2],h=Math.abs(g.lenVec3(g.subVec3(A,i,e))),h>B&&(B=h);return i[3]=B,i}})(),getSphere3Center:(A,e=g.vec3())=>(e[0]=A[0],e[1]=A[1],e[2]=A[2],e),getPositionsCenter(A,e=g.vec3()){let t=0,i=0,s=0;for(var n=0,o=A.length;n<o;n+=3)t+=A[n+0],i+=A[n+1],s+=A[n+2];const r=A.length/3;return e[0]=t/r,e[1]=i/r,e[2]=s/r,e},expandAABB3:(A,e)=>(A[0]>e[0]&&(A[0]=e[0]),A[1]>e[1]&&(A[1]=e[1]),A[2]>e[2]&&(A[2]=e[2]),A[3]<e[3]&&(A[3]=e[3]),A[4]<e[4]&&(A[4]=e[4]),A[5]<e[5]&&(A[5]=e[5]),A),expandAABB3Point3:(A,e)=>(A[0]>e[0]&&(A[0]=e[0]),A[1]>e[1]&&(A[1]=e[1]),A[2]>e[2]&&(A[2]=e[2]),A[3]<e[0]&&(A[3]=e[0]),A[4]<e[1]&&(A[4]=e[1]),A[5]<e[2]&&(A[5]=e[2]),A),expandAABB3Points3(A,e){for(var t,i,s,n=0,o=e.length;n<o;n+=3)t=e[n],i=e[n+1],s=e[n+2],A[0]>t&&(A[0]=t),A[1]>i&&(A[1]=i),A[2]>s&&(A[2]=s),A[3]<t&&(A[3]=t),A[4]<i&&(A[4]=i),A[5]<s&&(A[5]=s);return A},collapseAABB2:(A=g.AABB2())=>(A[0]=g.MAX_DOUBLE,A[1]=g.MAX_DOUBLE,A[2]=g.MIN_DOUBLE,A[3]=g.MIN_DOUBLE,A),point3AABB3Intersect:(A,e)=>A[0]>e[0]||A[3]<e[0]||A[1]>e[1]||A[4]<e[1]||A[2]>e[2]||A[5]<e[2],point3AABB3AbsoluteIntersect:(A,e)=>A[0]<=e[0]&&A[3]>=e[0]&&A[1]<=e[1]&&A[4]>=e[1]&&A[2]<=e[2]&&A[5]>=e[2],planeAABB3Intersect(A,e,t){let i,s;A[0]>0?(i=A[0]*t[0],s=A[0]*t[3]):(i=A[0]*t[3],s=A[0]*t[0]),A[1]>0?(i+=A[1]*t[1],s+=A[1]*t[4]):(i+=A[1]*t[4],s+=A[1]*t[1]),A[2]>0?(i+=A[2]*t[2],s+=A[2]*t[5]):(i+=A[2]*t[5],s+=A[2]*t[2]);if(i<=-e&&s<=-e)return-1;return i>=-e&&s>=-e?1:0},OBB3ToAABB2(A,e=g.AABB2()){let t,i,s,n,o=g.MAX_DOUBLE,r=g.MAX_DOUBLE,c=g.MIN_DOUBLE,a=g.MIN_DOUBLE;for(let e=0,h=A.length;e<h;e+=4)t=A[e+0],i=A[e+1],s=A[e+3]||1,n=1/s,t*=n,i*=n,t<o&&(o=t),i<r&&(r=i),t>c&&(c=t),i>a&&(a=i);return e[0]=o,e[1]=r,e[2]=c,e[3]=a,e},expandAABB2:(A,e)=>(A[0]>e[0]&&(A[0]=e[0]),A[1]>e[1]&&(A[1]=e[1]),A[2]<e[2]&&(A[2]=e[2]),A[3]<e[3]&&(A[3]=e[3]),A),expandAABB2Point2:(A,e)=>(A[0]>e[0]&&(A[0]=e[0]),A[1]>e[1]&&(A[1]=e[1]),A[2]<e[0]&&(A[2]=e[0]),A[3]<e[1]&&(A[3]=e[1]),A),AABB2ToCanvas(A,e,t,i=A){const s=.5*(A[0]+1),n=.5*(A[1]+1),o=.5*(A[2]+1),r=.5*(A[3]+1);return i[0]=Math.floor(s*e),i[1]=t-Math.floor(r*t),i[2]=Math.floor(o*e),i[3]=t-Math.floor(n*t),i},tangentQuadraticBezier:(A,e,t,i)=>2*(1-A)*(t-e)+2*A*(i-t),tangentQuadraticBezier3:(A,e,t,i,s)=>-3*e*(1-A)*(1-A)+3*t*(1-A)*(1-A)-6*A*t*(1-A)+6*A*i*(1-A)-3*A*A*i+3*A*A*s,tangentSpline:A=>6*A*A-6*A+(3*A*A-4*A+1)+(-6*A*A+6*A)+(3*A*A-2*A),catmullRomInterpolate(A,e,t,i,s){const n=.5*(t-A),o=.5*(i-e),r=s*s;return(2*e-2*t+n+o)*(s*r)+(-3*e+3*t-2*n-o)*r+n*s+e},b2p0(A,e){const t=1-A;return t*t*e},b2p1:(A,e)=>2*(1-A)*A*e,b2p2:(A,e)=>A*A*e,b2(A,e,t,i){return this.b2p0(A,e)+this.b2p1(A,t)+this.b2p2(A,i)},b3p0(A,e){const t=1-A;return t*t*t*e},b3p1(A,e){const t=1-A;return 3*t*t*A*e},b3p2:(A,e)=>3*(1-A)*A*A*e,b3p3:(A,e)=>A*A*A*e,b3(A,e,t,i,s){return this.b3p0(A,e)+this.b3p1(A,t)+this.b3p2(A,i)+this.b3p3(A,s)},triangleNormal(A,e,t,i=g.vec3()){const s=e[0]-A[0],n=e[1]-A[1],o=e[2]-A[2],r=t[0]-A[0],c=t[1]-A[1],a=t[2]-A[2],h=n*a-o*c,B=o*r-s*a,l=s*c-n*r,E=Math.sqrt(h*h+B*B+l*l);return 0===E?(i[0]=0,i[1]=0,i[2]=0):(i[0]=h/E,i[1]=B/E,i[2]=l/E),i},rayTriangleIntersect:(()=>{const A=new r(3),e=new r(3),t=new r(3),i=new r(3),s=new r(3);return(n,o,r,c,a,h)=>{h=h||g.vec3();const B=g.subVec3(c,r,A),l=g.subVec3(a,r,e),E=g.cross3Vec3(o,l,t),Q=g.dotVec3(B,E);if(Q<1e-6)return null;const M=g.subVec3(n,r,i),u=g.dotVec3(M,E);if(u<0||u>Q)return null;const w=g.cross3Vec3(M,B,s),d=g.dotVec3(o,w);if(d<0||u+d>Q)return null;const C=g.dotVec3(l,w)/Q;return h[0]=n[0]+C*o[0],h[1]=n[1]+C*o[1],h[2]=n[2]+C*o[2],h}})(),rayPlaneIntersect:(()=>{const A=new r(3),e=new r(3),t=new r(3),i=new r(3);return(s,n,o,r,c,a)=>{a=a||g.vec3(),n=g.normalizeVec3(n,A);const h=g.subVec3(r,o,e),B=g.subVec3(c,o,t),l=g.cross3Vec3(h,B,i);g.normalizeVec3(l,l);const E=-g.dotVec3(o,l),Q=-(g.dotVec3(s,l)+E)/g.dotVec3(n,l);return a[0]=s[0]+Q*n[0],a[1]=s[1]+Q*n[1],a[2]=s[2]+Q*n[2],a}})(),cartesianToBarycentric:(()=>{const A=new r(3),e=new r(3),t=new r(3);return(i,s,n,o,r)=>{const c=g.subVec3(o,s,A),a=g.subVec3(n,s,e),h=g.subVec3(i,s,t),B=g.dotVec3(c,c),l=g.dotVec3(c,a),E=g.dotVec3(c,h),Q=g.dotVec3(a,a),M=g.dotVec3(a,h),u=B*Q-l*l;if(0===u)return null;const w=1/u,d=(Q*E-l*M)*w,C=(B*M-l*E)*w;return r[0]=1-d-C,r[1]=C,r[2]=d,r}})(),barycentricInsideTriangle(A){const e=A[1],t=A[2];return t>=0&&e>=0&&t+e<1},barycentricToCartesian(A,e,t,i,s=g.vec3()){const n=A[0],o=A[1],r=A[2];return s[0]=e[0]*n+t[0]*o+i[0]*r,s[1]=e[1]*n+t[1]*o+i[1]*r,s[2]=e[2]*n+t[2]*o+i[2]*r,s},mergeVertices(A,e,t,i){const s={},n=[],o=[],r=e?[]:null,c=t?[]:null,a=[];let h,B,g,l;const E=1e4;let Q,M,u=0;for(Q=0,M=A.length;Q<M;Q+=3)h=A[Q],B=A[Q+1],g=A[Q+2],l=`${Math.round(h*E)}_${Math.round(B*E)}_${Math.round(g*E)}`,void 0===s[l]&&(s[l]=o.length/3,o.push(h),o.push(B),o.push(g),e&&(r.push(e[Q]),r.push(e[Q+1]),r.push(e[Q+2])),t&&(c.push(t[u]),c.push(t[u+1]))),n[Q/3]=s[l],u+=2;for(Q=0,M=i.length;Q<M;Q++)a[Q]=n[i[Q]];const w={positions:o,indices:a};return r&&(w.normals=r),c&&(w.uv=c),w},buildNormals:(()=>{const A=new r(3),e=new r(3),t=new r(3),i=new r(3),s=new r(3),n=new r(3);return(o,r,c)=>{let a,h;const B=new Array(o.length/3);let l,E,Q,M,u,w,d;for(a=0,h=r.length;a<h;a+=3){l=r[a],E=r[a+1],Q=r[a+2],A[0]=o[3*l],A[1]=o[3*l+1],A[2]=o[3*l+2],e[0]=o[3*E],e[1]=o[3*E+1],e[2]=o[3*E+2],t[0]=o[3*Q],t[1]=o[3*Q+1],t[2]=o[3*Q+2],g.subVec3(e,A,i),g.subVec3(t,A,s);const c=g.vec3();g.normalizeVec3(g.cross3Vec3(i,s,n),c),B[l]||(B[l]=[]),B[E]||(B[E]=[]),B[Q]||(B[Q]=[]),B[l].push(c),B[E].push(c),B[Q].push(c)}for(c=c&&c.length===o.length?c:new Float32Array(o.length),a=0,h=B.length;a<h;a++){M=B[a].length,u=0,w=0,d=0;for(let A=0;A<M;A++)u+=B[a][A][0],w+=B[a][A][1],d+=B[a][A][2];c[3*a]=u/M,c[3*a+1]=w/M,c[3*a+2]=d/M}return c}})(),buildTangents:(()=>{const A=new r(3),e=new r(3),t=new r(3),i=new r(3),s=new r(3),n=new r(3),o=new r(3);return(r,c,a)=>{const h=new Float32Array(r.length);for(let B=0;B<c.length;B+=3){let l=c[B];const E=r.subarray(3*l,3*l+3),Q=a.subarray(2*l,2*l+2);l=c[B+1];const M=r.subarray(3*l,3*l+3),u=a.subarray(2*l,2*l+2);l=c[B+2];const w=r.subarray(3*l,3*l+3),d=a.subarray(2*l,2*l+2),C=g.subVec3(M,E,A),x=g.subVec3(w,E,e),F=g.subVec2(u,Q,t),p=g.subVec2(d,Q,i),I=1/(F[0]*p[1]-F[1]*p[0]),f=g.mulVec3Scalar(g.subVec3(g.mulVec3Scalar(C,p[1],s),g.mulVec3Scalar(x,F[1],n),o),I,n);let Y;for(let A=0;A<3;A++)Y=3*c[B+A],h[Y]+=f[0],h[Y+1]+=f[1],h[Y+2]+=f[2]}return h}})(),buildPickTriangles(A,e,t){const i=e.length,s=t?new Uint16Array(9*i):new Float32Array(9*i),n=new Uint8Array(12*i);let o,r,c,a,h,B,g=0,l=0,E=0;for(let t=0;t<i;t+=3)B=g>>24&255,h=g>>16&255,a=g>>8&255,c=255&g,r=e[t],o=3*r,s[l++]=A[o],s[l++]=A[o+1],s[l++]=A[o+2],n[E++]=c,n[E++]=a,n[E++]=h,n[E++]=B,r=e[t+1],o=3*r,s[l++]=A[o],s[l++]=A[o+1],s[l++]=A[o+2],n[E++]=c,n[E++]=a,n[E++]=h,n[E++]=B,r=e[t+2],o=3*r,s[l++]=A[o],s[l++]=A[o+1],s[l++]=A[o+2],n[E++]=c,n[E++]=a,n[E++]=h,n[E++]=B,g++;return{positions:s,colors:n}},faceToVertexNormals(A,e,t={}){const i=t.smoothNormalsAngleThreshold||20,s={},n=[],o={};let r,c,a,h,B;const l=1e4;let E,Q,M,u,w,d;for(Q=0,u=A.length;Q<u;Q+=3){E=Q/3,c=A[Q],a=A[Q+1],h=A[Q+2],B=`${Math.round(c*l)}_${Math.round(a*l)}_${Math.round(h*l)}`,void 0===s[B]?s[B]=[E]:s[B].push(E);const t=g.normalizeVec3([e[Q],e[Q+1],e[Q+2]]);n[E]=t,r=g.vec4([t[0],t[1],t[2],1]),o[E]=r}for(B in s)if(s.hasOwnProperty(B)){const A=s[B],e=A.length;for(Q=0;Q<e;Q++){const t=A[Q];for(r=o[t],M=0;M<e;M++){if(Q===M)continue;const e=A[M];w=n[t],d=n[e];Math.abs(g.angleVec3(w,d)/g.DEGTORAD)<i&&(r[0]+=d[0],r[1]+=d[1],r[2]+=d[2],r[3]+=1)}}}for(Q=0,u=e.length;Q<u;Q+=3)r=o[Q/3],e[Q+0]=r[0]/r[3],e[Q+1]=r[1]/r[3],e[Q+2]=r[2]/r[3]},transformRay:(()=>{const A=new r(4),e=new r(4);return(t,i,s,n,o)=>{A[0]=i[0],A[1]=i[1],A[2]=i[2],A[3]=1,g.transformVec4(t,A,e),n[0]=e[0],n[1]=e[1],n[2]=e[2],A[0]=s[0],A[1]=s[1],A[2]=s[2],g.transformVec3(t,A,e),g.normalizeVec3(e),o[0]=e[0],o[1]=e[1],o[2]=e[2]}})(),canvasPosToWorldRay:(()=>{const A=new r(16),e=new r(4),t=new r(4),i=(e,t,i,s,n)=>{n[0]=e,n[1]=t,n[2]=i,n[3]=1,g.transformVec4(A,n,n),s||g.mulVec4Scalar(n,1/n[3])};return(s,n,o,r,c,a,h)=>{const B="ortho"===r;g.mulMat4(o,n,A),g.inverseMat4(A,A);const l=2*c[0]/s.clientWidth-1,E=1-2*c[1]/s.clientHeight;i(l,E,-1,B,e),i(l,E,1,B,t),a[0]=e[0],a[1]=e[1],a[2]=e[2],g.subVec3(t,e,h),g.normalizeVec3(h)}})(),canvasPosToLocalRay:(()=>{const A=new r(3),e=new r(3);return(t,i,s,n,o,r,c,a)=>{g.canvasPosToWorldRay(t,i,s,n,r,A,e),g.worldRayToLocalRay(o,A,e,c,a)}})(),worldRayToLocalRay:(()=>{const A=new r(16),e=new r(4),t=new r(4);return(i,s,n,o,r)=>{const c=g.inverseMat4(i,A);e[0]=s[0],e[1]=s[1],e[2]=s[2],e[3]=1,g.transformVec4(c,e,t),o[0]=t[0],o[1]=t[1],o[2]=t[2],g.transformVec3(c,n,r)}})(),buildKDTree:(()=>{const A=new Float32Array;function e(t,i,s,n){const o=new r(6),c={triangles:null,left:null,right:null,leaf:!1,splitDim:0,aabb:o};let a,h;for(o[0]=o[1]=o[2]=Number.POSITIVE_INFINITY,o[3]=o[4]=o[5]=Number.NEGATIVE_INFINITY,a=0,h=t.length;a<h;++a){var B=3*t[a];for(let A=0;A<3;++A){const e=3*i[B+A];s[e]<o[0]&&(o[0]=s[e]),s[e]>o[3]&&(o[3]=s[e]),s[e+1]<o[1]&&(o[1]=s[e+1]),s[e+1]>o[4]&&(o[4]=s[e+1]),s[e+2]<o[2]&&(o[2]=s[e+2]),s[e+2]>o[5]&&(o[5]=s[e+2])}}if(t.length<20||n>10)return c.triangles=t,c.leaf=!0,c;A[0]=o[3]-o[0],A[1]=o[4]-o[1],A[2]=o[5]-o[2];let g=0;A[1]>A[g]&&(g=1),A[2]>A[g]&&(g=2),c.splitDim=g;const l=(o[g]+o[g+3])/2,E=new Array(t.length);let Q=0;const M=new Array(t.length);let u=0;for(a=0,h=t.length;a<h;++a){const A=i[B=3*t[a]],e=3*i[B+1],n=3*i[B+2];s[3*A+g]<=l||s[e+g]<=l||s[n+g]<=l?E[Q++]=t[a]:M[u++]=t[a]}return E.length=Q,M.length=u,c.left=e(E,i,s,n+1),c.right=e(M,i,s,n+1),c}return(A,t)=>{const i=A.length/3,s=new Array(i);for(let A=0;A<i;++A)s[A]=A;return e(s,A,t,0)}})(),decompressPosition(A,e,t){(t=t||A)[0]=A[0]*e[0]+e[12],t[1]=A[1]*e[5]+e[13],t[2]=A[2]*e[10]+e[14]},decompressPositions(A,e,t=new Float32Array(A.length)){for(let i=0,s=A.length;i<s;i+=3)t[i+0]=A[i+0]*e[0]+e[12],t[i+1]=A[i+1]*e[5]+e[13],t[i+2]=A[i+2]*e[10]+e[14];return t},decompressUV(A,e,t){t[0]=A[0]*e[0]+e[6],t[1]=A[1]*e[4]+e[7]},decompressUVs(A,e,t=new Float32Array(A.length)){for(let i=0,s=A.length;i<s;i+=3)t[i+0]=A[i+0]*e[0]+e[6],t[i+1]=A[i+1]*e[4]+e[7];return t},octDecodeVec2(A,e){let t=A[0],i=A[1];t=(2*t+1)/255,i=(2*i+1)/255;const s=1-Math.abs(t)-Math.abs(i);s<0&&(t=(1-Math.abs(i))*(t>=0?1:-1),i=(1-Math.abs(t))*(i>=0?1:-1));const n=Math.sqrt(t*t+i*i+s*s);return e[0]=t/n,e[1]=i/n,e[2]=s/n,e},octDecodeVec2s(A,e){for(let t=0,i=0,s=A.length;t<s;t+=2){let s=A[t+0],n=A[t+1];s=(2*s+1)/255,n=(2*n+1)/255;const o=1-Math.abs(s)-Math.abs(n);o<0&&(s=(1-Math.abs(n))*(s>=0?1:-1),n=(1-Math.abs(s))*(n>=0?1:-1));const r=Math.sqrt(s*s+n*n+o*o);e[i+0]=s/r,e[i+1]=n/r,e[i+2]=o/r,i+=3}return e}};g.buildEdgeIndices=function(){const A=[],e=[],t=[],i=[],s=[];let n=0;const o=new Uint16Array(3),r=new Uint16Array(3),c=new Uint16Array(3),a=g.vec3(),h=g.vec3(),B=g.vec3(),l=g.vec3(),E=g.vec3(),Q=g.vec3(),M=g.vec3();return function(u,w,d,C){!function(s,n){const o={};let r,c,a,h;const B=Math.pow(10,4);let g,l,E=0;for(g=0,l=s.length;g<l;g+=3)r=s[g],c=s[g+1],a=s[g+2],h=Math.round(r*B)+"_"+Math.round(c*B)+"_"+Math.round(a*B),void 0===o[h]&&(o[h]=E/3,A[E++]=r,A[E++]=c,A[E++]=a),e[g/3]=o[h];for(g=0,l=n.length;g<l;g++)i[g]=e[n[g]],t[i[g]]=n[g]}(u,w),function(e,t){n=0;for(let u=0,w=e;u<w;u+=3){const e=3*i[u],w=3*i[u+1],d=3*i[u+2];t?(o[0]=A[e],o[1]=A[e+1],o[2]=A[e+2],r[0]=A[w],r[1]=A[w+1],r[2]=A[w+2],c[0]=A[d],c[1]=A[d+1],c[2]=A[d+2],g.decompressPosition(o,t,a),g.decompressPosition(r,t,h),g.decompressPosition(c,t,B)):(a[0]=A[e],a[1]=A[e+1],a[2]=A[e+2],h[0]=A[w],h[1]=A[w+1],h[2]=A[w+2],B[0]=A[d],B[1]=A[d+1],B[2]=A[d+2]),g.subVec3(B,h,l),g.subVec3(a,h,E),g.cross3Vec3(l,E,Q),g.normalizeVec3(Q,M);const C=s[n]||(s[n]={normal:g.vec3()});C.normal[0]=M[0],C.normal[1]=M[1],C.normal[2]=M[2],n++}}(w.length,d);const x=[],F=Math.cos(g.DEGTORAD*C),p={};let I,f,Y,D,m,J,N,y,z,T,U,R=!1;for(let A=0,e=w.length;A<e;A+=3){const e=A/3;for(let t=0;t<3;t++)I=i[A+t],f=i[A+(t+1)%3],Y=Math.min(I,f),D=Math.max(I,f),m=Y+","+D,void 0===p[m]?p[m]={index1:Y,index2:D,face1:e,face2:void 0}:p[m].face2=e}for(m in p)J=p[m],void 0!==J.face2&&(N=s[J.face1].normal,y=s[J.face2].normal,z=g.dotVec3(N,y),z>F)||(T=t[J.index1],U=t[J.index2],(!R&&T>65535||U>65535)&&(R=!0),x.push(T),x.push(U));return R?new Uint32Array(x):new Uint16Array(x)}}(),g.planeClipsPositions3=function(A,e,t,i=3){for(let s=0,n=t.length;s<n;s+=i){if(c[0]=t[s+0]-A[0],c[1]=t[s+1]-A[1],c[2]=t[s+2]-A[2],c[0]*e[0]+c[1]*e[1]+c[2]*e[2]<0)return!0}return!1};const l={components:{scenes:0},memory:{meshes:0,positions:0,colors:0,normals:0,uvs:0,indices:0,textures:0,materials:0,programs:0},frame:{frameCount:0,fps:0,useProgram:0,bindTexture:0,bindArray:0,drawElements:0,drawArrays:0,tasksRun:0,tasksScheduled:0}};var E=[["0",10],["A",26],["a",26],["_",1],["$",1]].map((function(A){for(var e=[],t=A[0].charCodeAt(0),i=t+A[1],s=t;s<i;++s)e.push(s);return String.fromCharCode.apply(null,e)})).join("");function Q(A,e){return(e&&4!==e?[0,6]:[0,6,12,18]).map((function(e){return E.substr(parseInt(A/(1<<e))%64,1)})).reverse().join("")}const M=function(){for(var A={},e=window.location.search.substring(1).split("&"),t=0;t<e.length;t++){var i=e[t].split("=");if(void 0===A[i[0]])A[i[0]]=decodeURIComponent(i[1]);else if("string"==typeof A[i[0]]){var s=[A[i[0]],decodeURIComponent(i[1])];A[i[0]]=s}else A[i[0]].push(decodeURIComponent(i[1]))}return A}();const u={xmlToJson:function A(e,t){if(e.nodeType===e.TEXT_NODE){var i=e.nodeValue;if(null===i.match(/^\s+$/))return i}else if(e.nodeType===e.ELEMENT_NODE||e.nodeType===e.DOCUMENT_NODE){var s={type:e.nodeName,children:[]};if(e.nodeType===e.ELEMENT_NODE)for(var n=0;n<e.attributes.length;n++){var o=e.attributes[n];s[t[o.nodeName]||o.nodeName]=o.nodeValue}for(var r=0;r<e.childNodes.length;r++){(n=A(e.childNodes[r],t))&&s.children.push(n)}return s}},clone:function(A){return JSON.parse(JSON.stringify(A))},compressGuid:function(A){var e=[0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30].map((function(e){return parseInt(A.substr(e,2),16)}));return Q(e[0],2)+[1,4,7,10,13].map((function(A){return Q((e[A]<<16)+(e[A+1]<<8)+e[A+2])})).join("")},findNodeOfType:function(A,e){var t=[],i=function(A){A.type===e&&t.push(A),(A.children||[]).forEach((function(A){i(A)}))};return i(A),t},timeout:function(A){return new Promise((function(e,t){setTimeout(e,A)}))},httpRequest:function(A){return new Promise((function(e,t){var i=new XMLHttpRequest;i.open(A.method||"GET",A.url,!0),i.onload=function(A){4===i.readyState&&(200===i.status?e(i.responseXML):t(i.statusText))},i.send(null)}))},loadJSON:function(A,e,t){var i=A=>{};e=e||i,t=t||i;var s=new XMLHttpRequest;s.overrideMimeType("application/json"),s.open("GET",A,!0),s.addEventListener("load",(function(A){var i=A.target.response;if(200===this.status){var s;try{s=JSON.parse(i)}catch(A){t(`utils.loadJSON(): Failed to parse JSON response - ${A}`)}e(s)}else if(0===this.status){console.warn("loadFile: HTTP Status 0 received.");try{e(JSON.parse(i))}catch(A){t(`utils.loadJSON(): Failed to parse JSON response - ${A}`)}}else t(A)}),!1),s.addEventListener("error",(function(A){t(A)}),!1),s.send(null)},loadArraybuffer:function(A,e,t){var i=A=>{};e=e||i,t=t||i;const s=A.match(/^data:(.*?)(;base64)?,(.*)$/);if(s){const A=!!s[2];var n=s[3];n=window.decodeURIComponent(n),A&&(n=window.atob(n));try{const A=new ArrayBuffer(n.length),t=new Uint8Array(A);for(var o=0;o<n.length;o++)t[o]=n.charCodeAt(o);Y.scheduleTask((()=>{e(A)}))}catch(A){Y.scheduleTask((()=>{t(A)}))}}else{const i=new XMLHttpRequest;i.open("GET",A,!0),i.responseType="arraybuffer