UNPKG

@xeokit/xeokit-sdk

Version:

3D BIM IFC Viewer SDK for AEC engineering applications. Open Source JavaScript Toolkit based on pure WebGL for top performance, real-world coordinates and full double precision

7 lines (6 loc) 2.35 MB
/** * xeokit-sdk v2.6.87 * Commit: 8fcdaeda55a3bd75b49a6cc6fe5d950fa3251f38 * Built: 2025-07-31T17:46:22.388Z */ class e{constructor(e,t){this.items=e||[],this._lastUniqueId=(t||0)+1}addItem(){let e;if(2===arguments.length){const t=arguments[0];if(e=arguments[1],this.items[t])throw"ID clash: '"+t+"'";return this.items[t]=e,t}for(e=arguments[0]||{};;){const t=this._lastUniqueId++;if(!this.items[t])return this.items[t]=e,t}}removeItem(e){const t=this.items[e];return delete this.items[e],t}}const t=new e;class i{constructor(e){this.id=e,this.parentItem=null,this.groups=[],this.menuElement=null,this.shown=!1,this.mouseOver=0}}class s{constructor(){this.items=[]}}class r{constructor(e,t,i,s,r){this.id=e,this.getTitle=t,this.doAction=i,this.getEnabled=s,this.getShown=r,this.itemElement=null,this.subMenu=null,this.enabled=!0}}class o{constructor(e={}){this._id=t.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=e.parentNode||document.body,this._offsetParent=this._parentNode instanceof ShadowRoot?this._parentNode.host:this._parentNode,this._eventSubs={},!1!==e.hideOnMouseDown&&(this._parentNode.addEventListener("mousedown",(e=>{e.target.classList.contains("xeokit-context-menu-item")||this.hide()})),this._parentNode.addEventListener("touchstart",this._canvasTouchStartHandler=e=>{e.target.classList.contains("xeokit-context-menu-item")||this.hide()})),e.items&&(this.items=e.items),this._hideOnAction=!1!==e.hideOnAction,this.context=e.context,this.enabled=!1!==e.enabled,this.hide()}on(e,t){let i=this._eventSubs[e];i||(i=[],this._eventSubs[e]=i),i.push(t)}fire(e,t){const i=this._eventSubs[e];if(i)for(let e=0,s=i.length;e<s;e++)i[e](t)}set items(e){this._clear(),this._itemsCfg=e||[],this._parseItems(e),this._createUI()}get items(){return this._itemsCfg}set enabled(e){(e=!!e)!==this._enabled&&(this._enabled=e,this._enabled||this.hide())}get enabled(){return this._enabled}set context(e){this._context=e}get context(){return this._context}show(e,t){this._context?this._enabled&&(this._shown||(this._hideAllMenus(),this._updateItemsTitles(),this._updateItemsEnabledStatus(),this._showMenu(this._rootMenu.id,e,t),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&&(t.removeItem(this._id),this._id=null)}_clear(){for(let e=0,t=this._menuList.length;e<t;e++){this._menuList[e].menuElement.remove()}this._itemsCfg=[],this._rootMenu=null,this._menuList=[],this._menuMap={},this._itemList=[],this._itemMap={}}_parseItems(e){const t=e=>{const o=this._getNextId(),n=new i(o);for(let i=0,o=e.length;i<o;i++){const o=e[i],a=new s;n.groups.push(a);for(let e=0,i=o.length;e<i;e++){const i=o[e],s=i.items,l=s&&s.length>0,A=this._getNextId(),c=i.getTitle||(()=>i.title||""),h=i.doAction||i.callback||(()=>{}),u=i.getEnabled||(()=>!0),d=i.getShown||(()=>!0),p=new r(A,c,h,u,d);if(p.parentMenu=n,a.items.push(p),l){const e=t(s);p.subMenu=e,e.parentItem=p}this._itemList.push(p),this._itemMap[p.id]=p}}return this._menuList.push(n),this._menuMap[n.id]=n,n};this._rootMenu=t(e)}_getNextId(){return"ContextMenu_"+this._id+"_"+this._nextId++}_createUI(){const e=t=>{this._createMenuUI(t);const i=t.groups;for(let t=0,s=i.length;t<s;t++){const s=i[t].items;for(let t=0,i=s.length;t<i;t++){const i=s[t].subMenu;i&&e(i)}}};e(this._rootMenu)}_createMenuUI(e){const t=e.groups,i=[],s=document.createElement("div");if(s.classList.add("xeokit-context-menu",e.id),s.style.zIndex=3e5,s.style.position="absolute",i.push("<ul>"),t)for(let e=0,s=t.length;e<s;e++){const r=e,o=s,n=t[e].items;if(n)for(let e=0,t=n.length;e<t;e++){const s=n[e],a=s.subMenu,l=s.title||"";a?(i.push('<li id="'+s.id+'" class="xeokit-context-menu-item xeokit-context-menu-submenu">'+l+"</li>"),r===o-1||e<t-1||i.push('<li id="'+s.id+'" class="xeokit-context-menu-item-separator"></li>')):(i.push('<li id="'+s.id+'" class="xeokit-context-menu-item">'+l+"</li>"),r===o-1||e<t-1||i.push('<li id="'+s.id+'" class="xeokit-context-menu-item-separator"></li>'))}}i.push("</ul>");const r=i.join("");s.innerHTML=r,this._parentNode.appendChild(s),e.menuElement=s,s.style["border-radius"]="4px",s.style.display="none",s.style["z-index"]=3e5,s.style.background="white",s.style.border="1px solid black",s.style["box-shadow"]="0 4px 5px 0 gray",s.oncontextmenu=e=>{e.preventDefault()};const o=this;let n=null;if(t)for(let e=0,i=t.length;e<i;e++){const i=t[e].items;if(i)for(let e=0,t=i.length;e<t;e++){const t=i[e],s=t.subMenu;t.itemElement=this._parentNode.querySelector(`#${t.id}`),t.itemElement?(t.itemElement.addEventListener("mouseenter",(e=>{e.preventDefault();const i=t.subMenu;if(!i)return void(n&&(o._hideMenu(n.id),n=null));if(n&&n.id!==i.id&&(o._hideMenu(n.id),n=null),!1===t.enabled)return;const s=t.itemElement,r=i.menuElement,a=s.getBoundingClientRect();r.getBoundingClientRect();const l=o._offsetParent.getBoundingClientRect(),A=200,c=a.right+A<l.right,h=a.left-A>l.left;if(c)o._showMenu(i.id,a.right+window.scrollX-5,a.top+window.scrollY-1);else if(h)o._showMenu(i.id,a.left-A+window.scrollX,a.top+window.scrollY-1);else{const e=a.left-l.left,t=l.right-a.right;t>e?o._showMenu(i.id,a.right-5-(A-t),a.top+window.scrollY-1):o._showMenu(i.id,a.left-e,a.top+window.scrollY-1)}n=i})),s||(t.itemElement.addEventListener("click",(e=>{e.preventDefault(),o._context&&!1!==t.enabled&&(t.doAction&&t.doAction(o._context),this._hideOnAction?o.hide():(o._updateItemsTitles(),o._updateItemsEnabledStatus()))})),t.itemElement.addEventListener("mouseup",(e=>{3===e.which&&(e.preventDefault(),o._context&&!1!==t.enabled&&(t.doAction&&t.doAction(o._context),this._hideOnAction?o.hide():(o._updateItemsTitles(),o._updateItemsEnabledStatus())))})),t.itemElement.addEventListener("mouseenter",(e=>{e.preventDefault(),!1!==t.enabled&&t.doHover&&t.doHover(o._context)})))):console.error("ContextMenu item element not found: "+t.id)}}}_updateItemsTitles(){if(this._context)for(let e=0,t=this._itemList.length;e<t;e++){const t=this._itemList[e],i=t.itemElement;if(!i)continue;const s=t.getShown;if(!s||!s(this._context))continue;const r=t.getTitle(this._context);t.subMenu,i.innerText=r}}_updateItemsEnabledStatus(){if(this._context)for(let e=0,t=this._itemList.length;e<t;e++){const t=this._itemList[e],i=t.itemElement;if(!i)continue;const s=t.getEnabled;if(!s)continue;const r=t.getShown;if(!r)continue;const o=r(this._context);if(t.shown=o,!o){i.style.display="none";continue}i.style.display="";const n=s(this._context);t.enabled=n,n?i.classList.remove("disabled"):i.classList.add("disabled")}}_updateSubMenuInfo(){if(!this._context)return;let e,t,i,s,r,o;this._itemList.forEach((n=>{n.subMenu&&(e=n.itemElement,t=e.getBoundingClientRect(),i=n.subMenu.menuElement,s={visibility:i.style.visibility,display:i.style.display},i.style.display="block",i.style.visibility="hidden",o=n.subMenu.menuElement.getBoundingClientRect().width,i.style.visibility=s.visibility,i.style.display=s.display,r=t.right+o>window.innerWidth,e.setAttribute("data-submenuposition",r?"left":"right"))}))}_showMenu(e,t,i){const s=this._menuMap[e];if(!s)return void console.error("Menu not found: "+e);if(s.shown)return;const r=s.menuElement;r&&(this._showMenuElement(r,t,i),s.shown=!0)}_hideMenu(e){const t=this._menuMap[e];if(!t)return void console.error("Menu not found: "+e);if(!t.shown)return;const i=t.menuElement;i&&(this._hideMenuElement(i),t.shown=!1)}_hideAllMenus(){for(let e=0,t=this._menuList.length;e<t;e++){const t=this._menuList[e];this._hideMenu(t.id)}}_showMenuElement(e,t,i){e.style.display="block";const s=e.offsetHeight,r=e.offsetWidth,o=this._offsetParent.getBoundingClientRect(),n=this._offsetParent===window.document.body&&0===o.bottom?window.innerHeight:o.bottom+window.scrollY,a=o.right+window.scrollX;i+s>n&&(i=n-s),t+r>a&&(t=a-r),e.style.left=t-o.left-window.scrollX+"px",e.style.top=i-o.top-window.scrollY+"px"}_hideMenuElement(e){e.style.display="none"}}class n{constructor(e,t={}){this.viewer=e,this.scene=this.viewer.scene,this._lensCursorDiv=document.createElement("div"),this._lensParams={canvasSize:300,cursorBorder:2,cursorSize:10},this._lensCursorDiv.style.borderRadius="50%",this._lensCursorDiv.style.width=this._lensParams.cursorSize+"px",this._lensCursorDiv.style.height=this._lensParams.cursorSize+"px",this._lensCursorDiv.style.zIndex="100000",this._lensCursorDiv.style.position="absolute",this._lensCursorDiv.style.pointerEvents="none",this._lensContainer=document.createElement("div"),this._lensContainerId=t.containerId||"xeokit-lens",this._lensContainer.setAttribute("id",this._lensContainerId),this._lensContainer.style.border="1px solid black",this._lensContainer.style.background="white",this._lensContainer.style.borderRadius="50%",this._lensContainer.style.width=this._lensParams.canvasSize+"px",this._lensContainer.style.height=this._lensParams.canvasSize+"px",this._lensContainer.style.zIndex="15000",this._lensContainer.style.position="absolute",this._lensContainer.style.pointerEvents="none",this._lensContainer.style.visibility="hidden",this._lensCanvas=document.createElement("canvas"),this._lensCanvas.id=`${this._lensContainerId}-canvas`,this._lensCanvas.style.borderRadius="50%",this._lensCanvas.style.width=this._lensParams.canvasSize+"px",this._lensCanvas.style.height=this._lensParams.canvasSize+"px",this._lensCanvas.style.zIndex="15000",this._lensCanvas.style.pointerEvents="none",document.body.appendChild(this._lensContainer),this._lensContainer.appendChild(this._lensCanvas),this._lensContainer.appendChild(this._lensCursorDiv),this._lensCanvasContext=this._lensCanvas.getContext("2d"),this._canvasElement=this.viewer.scene.canvas.canvas,this._canvasPos=null,this._snappedCanvasPos=null,this._lensPosToggle=t.lensPosToggle||!0,this._lensPosToggleAmount=t.lensPosToggleAmount||85,this._lensPosMarginLeft=t.lensPosMarginLeft||85,this._lensPosMarginTop=t.lensPosMarginTop||25,this._lensContainer.style.marginTop=`${this._lensPosMarginTop}px`,this._lensContainer.style.marginLeft=`${this._lensPosMarginLeft}px`,this._zoomLevel=t.zoomLevel||2,this._active=!1!==t.active,this._visible=!1,this.snapped=!1,this._onViewerRendering=this.viewer.scene.on("rendering",(()=>{this._active&&this._visible&&this.update()}))}update(){if(!this._active||!this._visible)return;if(!this._canvasPos)return;const e=this._lensContainer.getBoundingClientRect(),t=this._canvasElement.getBoundingClientRect(),i=this._canvasPos[0]<e.right&&this._canvasPos[0]>e.left&&this._canvasPos[1]<e.bottom&&this._canvasPos[1]>e.top;this._lensContainer.style.marginLeft=`${this._lensPosMarginLeft}px`,i&&(this._lensPosToggle?this._lensContainer.style.marginTop=t.bottom-t.top-this._lensCanvas.height-this._lensPosToggleAmount+"px":this._lensContainer.style.marginTop=`${this._lensPosMarginTop}px`,this._lensPosToggle=!this._lensPosToggle),this._lensCanvasContext.clearRect(0,0,this._lensCanvas.width,this._lensCanvas.height);const s=Math.max(this._lensCanvas.width,this._lensCanvas.height)/this._zoomLevel;this._lensCanvasContext.drawImage(this._canvasElement,this._canvasPos[0]-s/2,this._canvasPos[1]-s/2,s,s,0,0,this._lensCanvas.width,this._lensCanvas.height);const r=this._lensParams.canvasSize/2-this._lensParams.cursorSize/2-this._lensParams.cursorBorder,o=this._snappedCanvasPos?this._snappedCanvasPos[0]-this._canvasPos[0]:0,n=this._snappedCanvasPos?this._snappedCanvasPos[1]-this._canvasPos[1]:0;this._lensCursorDiv.style.left=`${r+o*this._zoomLevel}px`,this._lensCursorDiv.style.top=`${r+n*this._zoomLevel}px`}set zoomFactor(e){this._zoomFactor=e,this.update()}get zoomFactor(){return this._zoomFactor}set canvasPos(e){this._canvasPos=e,this.update()}get canvasPos(){return this._canvasPos}set snappedCanvasPos(e){this._snappedCanvasPos=e,this.update()}get snappedCanvasPos(){return this._snappedCanvasPos}set snapped(e){this._snapped=e;const[t,i]=e?["greenyellow","green"]:["pink","red"];this._lensCursorDiv.style.background=t,this._lensCursorDiv.style.border=this._lensParams.cursorBorder+"px solid "+i}get snapped(){return this._snapped}_updateActiveVisible(){this._lensContainer.style.visibility=this._active&&this._visible?"visible":"hidden",this.update()}set active(e){this._active=e,this._updateActiveVisible()}get active(){return this._active}set visible(e){this._visible=e,this._updateActiveVisible()}get visible(){return this._visible}destroy(){this._destroyed||(this.viewer.scene.off(this._onViewerRendering),this._lensContainer.removeChild(this._lensCanvas),document.body.removeChild(this._lensContainer),this._destroyed=!0)}}let a=!0,l=a?Float64Array:Float32Array;const A=new l(3),c=new l(16),h=new l(16),u=new l(4),d={setDoublePrecisionEnabled(e){a=e,l=a?Float64Array:Float32Array},getDoublePrecisionEnabled:()=>a,MIN_DOUBLE:-Number.MAX_SAFE_INTEGER,MAX_DOUBLE:Number.MAX_SAFE_INTEGER,MAX_INT:1e7,DEGTORAD:.0174532925,RADTODEG:57.295779513,unglobalizeObjectId(e,t){const i=t.indexOf("#");return i===e.length&&t.startsWith(e)?t.substring(i+1):t},globalizeObjectId:(e,t)=>e+"#"+t,safeInv(e){const t=1/e;return isNaN(t)||!isFinite(t)?1:t},vec2:e=>new l(e||2),vec3:e=>new l(e||3),vec4:e=>new l(e||4),mat3:e=>new l(e||9),mat3ToMat4:(e,t=new l(16))=>(t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=0,t[4]=e[3],t[5]=e[4],t[6]=e[5],t[7]=0,t[8]=e[6],t[9]=e[7],t[10]=e[8],t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t),mat4:e=>new l(e||16),mat4ToMat3:(e,t=new l(9))=>(t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[4],t[4]=e[5],t[5]=e[6],t[6]=e[8],t[7]=e[9],t[8]=e[10],t),doublesToFloats(e,t,i){const s=new l(2);for(let r=0,o=e.length;r<o;r++)d.splitDouble(e[r],s),t[r]=s[0],i[r]=s[1]},splitDouble(e,t){const i=l.from([e])[0],s=e-i;t[0]=i,t[1]=s},createUUID:(()=>{const e=[];for(let t=0;t<256;t++)e[t]=(t<16?"0":"")+t.toString(16);return()=>{const t=4294967295*Math.random()|0,i=4294967295*Math.random()|0,s=4294967295*Math.random()|0,r=4294967295*Math.random()|0;return`${e[255&t]+e[t>>8&255]+e[t>>16&255]+e[t>>24&255]}-${e[255&i]}${e[i>>8&255]}-${e[i>>16&15|64]}${e[i>>24&255]}-${e[63&s|128]}${e[s>>8&255]}-${e[s>>16&255]}${e[s>>24&255]}${e[255&r]}${e[r>>8&255]}${e[r>>16&255]}${e[r>>24&255]}`}})(),clamp:(e,t,i)=>Math.max(t,Math.min(i,e)),fmod(e,t){if(e<t)return console.error("math.fmod : Attempting to find modulus within negative range - would be infinite loop - ignoring"),e;for(;t<=e;)e-=t;return e},compareVec3:(e,t)=>e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2],compareVec4:(e,t)=>e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]&&e[3]===t[3],negateVec3:(e,t)=>(t||(t=e),t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t),negateVec4:(e,t)=>(t||(t=e),t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=-e[3],t),addVec4:(e,t,i)=>(i||(i=e),i[0]=e[0]+t[0],i[1]=e[1]+t[1],i[2]=e[2]+t[2],i[3]=e[3]+t[3],i),addVec4Scalar:(e,t,i)=>(i||(i=e),i[0]=e[0]+t,i[1]=e[1]+t,i[2]=e[2]+t,i[3]=e[3]+t,i),addVec3:(e,t,i)=>(i||(i=e),i[0]=e[0]+t[0],i[1]=e[1]+t[1],i[2]=e[2]+t[2],i),addVec3Scalar:(e,t,i)=>(i||(i=e),i[0]=e[0]+t,i[1]=e[1]+t,i[2]=e[2]+t,i),subVec4:(e,t,i)=>(i||(i=e),i[0]=e[0]-t[0],i[1]=e[1]-t[1],i[2]=e[2]-t[2],i[3]=e[3]-t[3],i),subVec3:(e,t,i)=>(i||(i=e),i[0]=e[0]-t[0],i[1]=e[1]-t[1],i[2]=e[2]-t[2],i),subVec2:(e,t,i)=>(i||(i=e),i[0]=e[0]-t[0],i[1]=e[1]-t[1],i),geometricMeanVec2(...e){const t=new l(e[0]);for(let i=1;i<e.length;i++)t[0]+=e[i][0],t[1]+=e[i][1];return t[0]/=e.length,t[1]/=e.length,t},subVec4Scalar:(e,t,i)=>(i||(i=e),i[0]=e[0]-t,i[1]=e[1]-t,i[2]=e[2]-t,i[3]=e[3]-t,i),subScalarVec4:(e,t,i)=>(i||(i=e),i[0]=t-e[0],i[1]=t-e[1],i[2]=t-e[2],i[3]=t-e[3],i),mulVec4:(e,t,i)=>(i||(i=e),i[0]=e[0]*t[0],i[1]=e[1]*t[1],i[2]=e[2]*t[2],i[3]=e[3]*t[3],i),mulVec4Scalar:(e,t,i)=>(i||(i=e),i[0]=e[0]*t,i[1]=e[1]*t,i[2]=e[2]*t,i[3]=e[3]*t,i),mulVec3Scalar:(e,t,i)=>(i||(i=e),i[0]=e[0]*t,i[1]=e[1]*t,i[2]=e[2]*t,i),mulVec2Scalar:(e,t,i)=>(i||(i=e),i[0]=e[0]*t,i[1]=e[1]*t,i),divVec3:(e,t,i)=>(i||(i=e),i[0]=e[0]/t[0],i[1]=e[1]/t[1],i[2]=e[2]/t[2],i),divVec4:(e,t,i)=>(i||(i=e),i[0]=e[0]/t[0],i[1]=e[1]/t[1],i[2]=e[2]/t[2],i[3]=e[3]/t[3],i),divScalarVec3:(e,t,i)=>(i||(i=t),i[0]=e/t[0],i[1]=e/t[1],i[2]=e/t[2],i),divVec3Scalar:(e,t,i)=>(i||(i=e),i[0]=e[0]/t,i[1]=e[1]/t,i[2]=e[2]/t,i),divVec4Scalar:(e,t,i)=>(i||(i=e),i[0]=e[0]/t,i[1]=e[1]/t,i[2]=e[2]/t,i[3]=e[3]/t,i),divScalarVec4:(e,t,i)=>(i||(i=t),i[0]=e/t[0],i[1]=e/t[1],i[2]=e/t[2],i[3]=e/t[3],i),dotVec4:(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2]+e[3]*t[3],cross3Vec4(e,t){const i=e[0],s=e[1],r=e[2],o=t[0],n=t[1],a=t[2];return[s*a-r*n,r*o-i*a,i*n-s*o,0]},cross3Vec3(e,t,i){i||(i=e);const s=e[0],r=e[1],o=e[2],n=t[0],a=t[1],l=t[2];return i[0]=r*l-o*a,i[1]=o*n-s*l,i[2]=s*a-r*n,i},sqLenVec4:e=>d.dotVec4(e,e),lenVec4:e=>Math.sqrt(d.sqLenVec4(e)),dotVec3:(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],dotVec2:(e,t)=>e[0]*t[0]+e[1]*t[1],sqLenVec3:e=>d.dotVec3(e,e),sqLenVec2:e=>d.dotVec2(e,e),lenVec3:e=>Math.sqrt(d.sqLenVec3(e)),distVec3:(()=>{const e=new l(3);return(t,i)=>d.lenVec3(d.subVec3(t,i,e))})(),lenVec2:e=>Math.sqrt(d.sqLenVec2(e)),distVec2:(()=>{const e=new l(2);return(t,i)=>d.lenVec2(d.subVec2(t,i,e))})(),rcpVec3:(e,t)=>d.divScalarVec3(1,e,t),normalizeVec4(e,t){const i=1/d.lenVec4(e);return d.mulVec4Scalar(e,i,t)},normalizeVec3(e,t){const i=1/d.lenVec3(e);return d.mulVec3Scalar(e,i,t)},normalizeVec2(e,t){const i=1/d.lenVec2(e);return d.mulVec2Scalar(e,i,t)},angleVec3(e,t){let i=d.dotVec3(e,t)/Math.sqrt(d.sqLenVec3(e)*d.sqLenVec3(t));return i=i<-1?-1:i>1?1:i,Math.acos(i)},vec3FromMat4Scale:(()=>{const e=new l(3);return(t,i)=>(e[0]=t[0],e[1]=t[1],e[2]=t[2],i[0]=d.lenVec3(e),e[0]=t[4],e[1]=t[5],e[2]=t[6],i[1]=d.lenVec3(e),e[0]=t[8],e[1]=t[9],e[2]=t[10],i[2]=d.lenVec3(e),i)})(),vecToArray:(()=>{function e(e){return Math.round(1e5*e)/1e5}return t=>{for(let i=0,s=(t=Array.prototype.slice.call(t)).length;i<s;i++)t[i]=e(t[i]);return t}})(),xyzArrayToObject:e=>({x:e[0],y:e[1],z:e[2]}),xyzObjectToArray:(e,t)=>((t=t||d.vec3())[0]=e.x,t[1]=e.y,t[2]=e.z,t),dupMat4:e=>e.slice(0,16),mat4To3:e=>[e[0],e[1],e[2],e[4],e[5],e[6],e[8],e[9],e[10]],m4s:e=>[e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e],setMat4ToZeroes:()=>d.m4s(0),setMat4ToOnes:()=>d.m4s(1),diagonalMat4v:e=>new l([e[0],0,0,0,0,e[1],0,0,0,0,e[2],0,0,0,0,e[3]]),diagonalMat4c:(e,t,i,s)=>d.diagonalMat4v([e,t,i,s]),diagonalMat4s:e=>d.diagonalMat4c(e,e,e,e),identityMat4:(e=new l(16))=>(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,e),identityMat3:(e=new l(9))=>(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,e),isIdentityMat4:e=>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],negateMat4:(e,t)=>(t||(t=e),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],t),addMat4:(e,t,i)=>(i||(i=e),i[0]=e[0]+t[0],i[1]=e[1]+t[1],i[2]=e[2]+t[2],i[3]=e[3]+t[3],i[4]=e[4]+t[4],i[5]=e[5]+t[5],i[6]=e[6]+t[6],i[7]=e[7]+t[7],i[8]=e[8]+t[8],i[9]=e[9]+t[9],i[10]=e[10]+t[10],i[11]=e[11]+t[11],i[12]=e[12]+t[12],i[13]=e[13]+t[13],i[14]=e[14]+t[14],i[15]=e[15]+t[15],i),addMat4Scalar:(e,t,i)=>(i||(i=e),i[0]=e[0]+t,i[1]=e[1]+t,i[2]=e[2]+t,i[3]=e[3]+t,i[4]=e[4]+t,i[5]=e[5]+t,i[6]=e[6]+t,i[7]=e[7]+t,i[8]=e[8]+t,i[9]=e[9]+t,i[10]=e[10]+t,i[11]=e[11]+t,i[12]=e[12]+t,i[13]=e[13]+t,i[14]=e[14]+t,i[15]=e[15]+t,i),addScalarMat4:(e,t,i)=>d.addMat4Scalar(t,e,i),subMat4:(e,t,i)=>(i||(i=e),i[0]=e[0]-t[0],i[1]=e[1]-t[1],i[2]=e[2]-t[2],i[3]=e[3]-t[3],i[4]=e[4]-t[4],i[5]=e[5]-t[5],i[6]=e[6]-t[6],i[7]=e[7]-t[7],i[8]=e[8]-t[8],i[9]=e[9]-t[9],i[10]=e[10]-t[10],i[11]=e[11]-t[11],i[12]=e[12]-t[12],i[13]=e[13]-t[13],i[14]=e[14]-t[14],i[15]=e[15]-t[15],i),subMat4Scalar:(e,t,i)=>(i||(i=e),i[0]=e[0]-t,i[1]=e[1]-t,i[2]=e[2]-t,i[3]=e[3]-t,i[4]=e[4]-t,i[5]=e[5]-t,i[6]=e[6]-t,i[7]=e[7]-t,i[8]=e[8]-t,i[9]=e[9]-t,i[10]=e[10]-t,i[11]=e[11]-t,i[12]=e[12]-t,i[13]=e[13]-t,i[14]=e[14]-t,i[15]=e[15]-t,i),subScalarMat4:(e,t,i)=>(i||(i=t),i[0]=e-t[0],i[1]=e-t[1],i[2]=e-t[2],i[3]=e-t[3],i[4]=e-t[4],i[5]=e-t[5],i[6]=e-t[6],i[7]=e-t[7],i[8]=e-t[8],i[9]=e-t[9],i[10]=e-t[10],i[11]=e-t[11],i[12]=e-t[12],i[13]=e-t[13],i[14]=e-t[14],i[15]=e-t[15],i),mulMat4(e,t,i){i||(i=e);const s=e[0],r=e[1],o=e[2],n=e[3],a=e[4],l=e[5],A=e[6],c=e[7],h=e[8],u=e[9],d=e[10],p=e[11],f=e[12],m=e[13],g=e[14],_=e[15],v=t[0],b=t[1],y=t[2],w=t[3],B=t[4],P=t[5],x=t[6],C=t[7],M=t[8],E=t[9],F=t[10],I=t[11],T=t[12],D=t[13],S=t[14],R=t[15];return i[0]=v*s+b*a+y*h+w*f,i[1]=v*r+b*l+y*u+w*m,i[2]=v*o+b*A+y*d+w*g,i[3]=v*n+b*c+y*p+w*_,i[4]=B*s+P*a+x*h+C*f,i[5]=B*r+P*l+x*u+C*m,i[6]=B*o+P*A+x*d+C*g,i[7]=B*n+P*c+x*p+C*_,i[8]=M*s+E*a+F*h+I*f,i[9]=M*r+E*l+F*u+I*m,i[10]=M*o+E*A+F*d+I*g,i[11]=M*n+E*c+F*p+I*_,i[12]=T*s+D*a+S*h+R*f,i[13]=T*r+D*l+S*u+R*m,i[14]=T*o+D*A+S*d+R*g,i[15]=T*n+D*c+S*p+R*_,i},mulMat3(e,t,i){i||(i=new l(9));const s=e[0],r=e[3],o=e[6],n=e[1],a=e[4],A=e[7],c=e[2],h=e[5],u=e[8],d=t[0],p=t[3],f=t[6],m=t[1],g=t[4],_=t[7],v=t[2],b=t[5],y=t[8];return i[0]=s*d+r*m+o*v,i[3]=s*p+r*g+o*b,i[6]=s*f+r*_+o*y,i[1]=n*d+a*m+A*v,i[4]=n*p+a*g+A*b,i[7]=n*f+a*_+A*y,i[2]=c*d+h*m+u*v,i[5]=c*p+h*g+u*b,i[8]=c*f+h*_+u*y,i},mulMat4Scalar:(e,t,i)=>(i||(i=e),i[0]=e[0]*t,i[1]=e[1]*t,i[2]=e[2]*t,i[3]=e[3]*t,i[4]=e[4]*t,i[5]=e[5]*t,i[6]=e[6]*t,i[7]=e[7]*t,i[8]=e[8]*t,i[9]=e[9]*t,i[10]=e[10]*t,i[11]=e[11]*t,i[12]=e[12]*t,i[13]=e[13]*t,i[14]=e[14]*t,i[15]=e[15]*t,i),mulMat4v4(e,t,i=d.vec4()){const s=t[0],r=t[1],o=t[2],n=t[3];return i[0]=e[0]*s+e[4]*r+e[8]*o+e[12]*n,i[1]=e[1]*s+e[5]*r+e[9]*o+e[13]*n,i[2]=e[2]*s+e[6]*r+e[10]*o+e[14]*n,i[3]=e[3]*s+e[7]*r+e[11]*o+e[15]*n,i},transposeMat4(e,t){const i=e[4],s=e[14],r=e[8],o=e[13],n=e[12],a=e[9];if(!t||e===t){const t=e[1],l=e[2],A=e[3],c=e[6],h=e[7],u=e[11];return e[1]=i,e[2]=r,e[3]=n,e[4]=t,e[6]=a,e[7]=o,e[8]=l,e[9]=c,e[11]=s,e[12]=A,e[13]=h,e[14]=u,e}return t[0]=e[0],t[1]=i,t[2]=r,t[3]=n,t[4]=e[1],t[5]=e[5],t[6]=a,t[7]=o,t[8]=e[2],t[9]=e[6],t[10]=e[10],t[11]=s,t[12]=e[3],t[13]=e[7],t[14]=e[11],t[15]=e[15],t},transposeMat3(e,t){if(t===e){const i=e[1],s=e[2],r=e[5];t[1]=e[3],t[2]=e[6],t[3]=i,t[5]=e[7],t[6]=s,t[7]=r}else t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8];return t},determinantMat4(e){const t=e[0],i=e[1],s=e[2],r=e[3],o=e[4],n=e[5],a=e[6],l=e[7],A=e[8],c=e[9],h=e[10],u=e[11],d=e[12],p=e[13],f=e[14],m=e[15];return d*c*a*r-A*p*a*r-d*n*h*r+o*p*h*r+A*n*f*r-o*c*f*r-d*c*s*l+A*p*s*l+d*i*h*l-t*p*h*l-A*i*f*l+t*c*f*l+d*n*s*u-o*p*s*u-d*i*a*u+t*p*a*u+o*i*f*u-t*n*f*u-A*n*s*m+o*c*s*m+A*i*a*m-t*c*a*m-o*i*h*m+t*n*h*m},inverseMat4(e,t){t||(t=e);const i=e[0],s=e[1],r=e[2],o=e[3],n=e[4],a=e[5],l=e[6],A=e[7],c=e[8],h=e[9],u=e[10],d=e[11],p=e[12],f=e[13],m=e[14],g=e[15],_=i*a-s*n,v=i*l-r*n,b=i*A-o*n,y=s*l-r*a,w=s*A-o*a,B=r*A-o*l,P=c*f-h*p,x=c*m-u*p,C=c*g-d*p,M=h*m-u*f,E=h*g-d*f,F=u*g-d*m,I=1/(_*F-v*E+b*M+y*C-w*x+B*P);return t[0]=(a*F-l*E+A*M)*I,t[1]=(-s*F+r*E-o*M)*I,t[2]=(f*B-m*w+g*y)*I,t[3]=(-h*B+u*w-d*y)*I,t[4]=(-n*F+l*C-A*x)*I,t[5]=(i*F-r*C+o*x)*I,t[6]=(-p*B+m*b-g*v)*I,t[7]=(c*B-u*b+d*v)*I,t[8]=(n*E-a*C+A*P)*I,t[9]=(-i*E+s*C-o*P)*I,t[10]=(p*w-f*b+g*_)*I,t[11]=(-c*w+h*b-d*_)*I,t[12]=(-n*M+a*x-l*P)*I,t[13]=(i*M-s*x+r*P)*I,t[14]=(-p*y+f*v-m*_)*I,t[15]=(c*y-h*v+u*_)*I,t},traceMat4:e=>e[0]+e[5]+e[10]+e[15],translationMat4v(e,t){const i=t||d.identityMat4();return i[12]=e[0],i[13]=e[1],i[14]=e[2],i},translationMat3v(e,t){const i=t||d.identityMat3();return i[6]=e[0],i[7]=e[1],i},translationMat4c:(()=>{const e=new l(3);return(t,i,s,r)=>(e[0]=t,e[1]=i,e[2]=s,d.translationMat4v(e,r))})(),translationMat4s:(e,t)=>d.translationMat4c(e,e,e,t),translateMat4v:(e,t)=>d.translateMat4c(e[0],e[1],e[2],t),translateMat4c(e,t,i,s){const r=s[3];s[0]+=r*e,s[1]+=r*t,s[2]+=r*i;const o=s[7];s[4]+=o*e,s[5]+=o*t,s[6]+=o*i;const n=s[11];s[8]+=n*e,s[9]+=n*t,s[10]+=n*i;const a=s[15];return s[12]+=a*e,s[13]+=a*t,s[14]+=a*i,s},setMat4Translation:(e,t,i)=>(i[0]=e[0],i[1]=e[1],i[2]=e[2],i[3]=e[3],i[4]=e[4],i[5]=e[5],i[6]=e[6],i[7]=e[7],i[8]=e[8],i[9]=e[9],i[10]=e[10],i[11]=e[11],i[12]=t[0],i[13]=t[1],i[14]=t[2],i[15]=e[15],i),rotationMat4v(e,t,i){const s=d.normalizeVec4([t[0],t[1],t[2],0],[]),r=Math.sin(e),o=Math.cos(e),n=1-o,a=s[0],l=s[1],A=s[2];let c,h,u,p,f,m;return c=a*l,h=l*A,u=A*a,p=a*r,f=l*r,m=A*r,(i=i||d.mat4())[0]=n*a*a+o,i[1]=n*c+m,i[2]=n*u-f,i[3]=0,i[4]=n*c-m,i[5]=n*l*l+o,i[6]=n*h+p,i[7]=0,i[8]=n*u+f,i[9]=n*h-p,i[10]=n*A*A+o,i[11]=0,i[12]=0,i[13]=0,i[14]=0,i[15]=1,i},rotationMat4c:(e,t,i,s,r)=>d.rotationMat4v(e,[t,i,s],r),scalingMat4v:(e,t=d.identityMat4())=>(t[0]=e[0],t[5]=e[1],t[10]=e[2],t),scalingMat3v:(e,t=d.identityMat3())=>(t[0]=e[0],t[4]=e[1],t),scalingMat4c:(()=>{const e=new l(3);return(t,i,s,r)=>(e[0]=t,e[1]=i,e[2]=s,d.scalingMat4v(e,r))})(),scaleMat4c:(e,t,i,s)=>(s[0]*=e,s[4]*=t,s[8]*=i,s[1]*=e,s[5]*=t,s[9]*=i,s[2]*=e,s[6]*=t,s[10]*=i,s[3]*=e,s[7]*=t,s[11]*=i,s),scaleMat4v(e,t){const i=e[0],s=e[1],r=e[2];return t[0]*=i,t[4]*=s,t[8]*=r,t[1]*=i,t[5]*=s,t[9]*=r,t[2]*=i,t[6]*=s,t[10]*=r,t[3]*=i,t[7]*=s,t[11]*=r,t},scalingMat4s:e=>d.scalingMat4c(e,e,e),rotationTranslationMat4(e,t,i=d.mat4()){const s=e[0],r=e[1],o=e[2],n=e[3],a=s+s,l=r+r,A=o+o,c=s*a,h=s*l,u=s*A,p=r*l,f=r*A,m=o*A,g=n*a,_=n*l,v=n*A;return i[0]=1-(p+m),i[1]=h+v,i[2]=u-_,i[3]=0,i[4]=h-v,i[5]=1-(c+m),i[6]=f+g,i[7]=0,i[8]=u+_,i[9]=f-g,i[10]=1-(c+p),i[11]=0,i[12]=t[0],i[13]=t[1],i[14]=t[2],i[15]=1,i},mat4ToEuler(e,t,i=d.vec4()){const s=d.clamp,r=e[0],o=e[4],n=e[8],a=e[1],l=e[5],A=e[9],c=e[2],h=e[6],u=e[10];return"XYZ"===t?(i[1]=Math.asin(s(n,-1,1)),Math.abs(n)<.99999?(i[0]=Math.atan2(-A,u),i[2]=Math.atan2(-o,r)):(i[0]=Math.atan2(h,l),i[2]=0)):"YXZ"===t?(i[0]=Math.asin(-s(A,-1,1)),Math.abs(A)<.99999?(i[1]=Math.atan2(n,u),i[2]=Math.atan2(a,l)):(i[1]=Math.atan2(-c,r),i[2]=0)):"ZXY"===t?(i[0]=Math.asin(s(h,-1,1)),Math.abs(h)<.99999?(i[1]=Math.atan2(-c,u),i[2]=Math.atan2(-o,l)):(i[1]=0,i[2]=Math.atan2(a,r))):"ZYX"===t?(i[1]=Math.asin(-s(c,-1,1)),Math.abs(c)<.99999?(i[0]=Math.atan2(h,u),i[2]=Math.atan2(a,r)):(i[0]=0,i[2]=Math.atan2(-o,l))):"YZX"===t?(i[2]=Math.asin(s(a,-1,1)),Math.abs(a)<.99999?(i[0]=Math.atan2(-A,l),i[1]=Math.atan2(-c,r)):(i[0]=0,i[1]=Math.atan2(n,u))):"XZY"===t&&(i[2]=Math.asin(-s(o,-1,1)),Math.abs(o)<.99999?(i[0]=Math.atan2(h,l),i[1]=Math.atan2(n,r)):(i[0]=Math.atan2(-A,u),i[1]=0)),i[0]*=d.RADTODEG,i[1]*=d.RADTODEG,i[2]*=d.RADTODEG,i},composeMat4:(e,t,i,s=d.mat4())=>(d.quaternionToRotationMat4(t,s),d.scaleMat4v(i,s),d.translateMat4v(e,s),s),decomposeMat4:(()=>{const e=new l(3),t=new l(16);return function(i,s,r,o){e[0]=i[0],e[1]=i[1],e[2]=i[2];let n=d.lenVec3(e);e[0]=i[4],e[1]=i[5],e[2]=i[6];const a=d.lenVec3(e);e[8]=i[8],e[9]=i[9],e[10]=i[10];const l=d.lenVec3(e);d.determinantMat4(i)<0&&(n=-n),s[0]=i[12],s[1]=i[13],s[2]=i[14],t.set(i);const A=1/n,c=1/a,h=1/l;return t[0]*=A,t[1]*=A,t[2]*=A,t[4]*=c,t[5]*=c,t[6]*=c,t[8]*=h,t[9]*=h,t[10]*=h,d.mat4ToQuaternion(t,r),o[0]=n,o[1]=a,o[2]=l,this}})(),getColMat4(e,t){const i=4*t;return[e[i],e[i+1],e[i+2],e[i+3]]},setRowMat4(e,t,i){e[t]=i[0],e[t+4]=i[1],e[t+8]=i[2],e[t+12]=i[3]},lookAtMat4v(e,t,i,s){s||(s=d.mat4());const r=e[0],o=e[1],n=e[2],a=i[0],l=i[1],A=i[2],c=t[0],h=t[1],u=t[2];if(r===c&&o===h&&n===u)return d.identityMat4();let p,f,m,g,_,v,b,y,w,B;return p=r-c,f=o-h,m=n-u,B=1/Math.sqrt(p*p+f*f+m*m),p*=B,f*=B,m*=B,g=l*m-A*f,_=A*p-a*m,v=a*f-l*p,B=Math.sqrt(g*g+_*_+v*v),B?(B=1/B,g*=B,_*=B,v*=B):(g=0,_=0,v=0),b=f*v-m*_,y=m*g-p*v,w=p*_-f*g,B=Math.sqrt(b*b+y*y+w*w),B?(B=1/B,b*=B,y*=B,w*=B):(b=0,y=0,w=0),s[0]=g,s[1]=b,s[2]=p,s[3]=0,s[4]=_,s[5]=y,s[6]=f,s[7]=0,s[8]=v,s[9]=w,s[10]=m,s[11]=0,s[12]=-(g*r+_*o+v*n),s[13]=-(b*r+y*o+w*n),s[14]=-(p*r+f*o+m*n),s[15]=1,s},lookAtMat4c:(e,t,i,s,r,o,n,a,l)=>d.lookAtMat4v([e,t,i],[s,r,o],[n,a,l],[]),orthoMat4c(e,t,i,s,r,o,n){n||(n=d.mat4());const a=t-e,l=s-i,A=o-r;return n[0]=2/a,n[1]=0,n[2]=0,n[3]=0,n[4]=0,n[5]=2/l,n[6]=0,n[7]=0,n[8]=0,n[9]=0,n[10]=-2/A,n[11]=0,n[12]=-(e+t)/a,n[13]=-(s+i)/l,n[14]=-(o+r)/A,n[15]=1,n},frustumMat4v(e,t,i){i||(i=d.mat4());const s=[e[0],e[1],e[2],0],r=[t[0],t[1],t[2],0];d.addVec4(r,s,c),d.subVec4(r,s,h);const o=2*s[2],n=h[0],a=h[1],l=h[2];return i[0]=o/n,i[1]=0,i[2]=0,i[3]=0,i[4]=0,i[5]=o/a,i[6]=0,i[7]=0,i[8]=c[0]/n,i[9]=c[1]/a,i[10]=-c[2]/l,i[11]=-1,i[12]=0,i[13]=0,i[14]=-o*r[2]/l,i[15]=0,i},frustumMat4(e,t,i,s,r,o,n){n||(n=d.mat4());const a=t-e,l=s-i,A=o-r;return n[0]=2*r/a,n[1]=0,n[2]=0,n[3]=0,n[4]=0,n[5]=2*r/l,n[6]=0,n[7]=0,n[8]=(t+e)/a,n[9]=(s+i)/l,n[10]=-(o+r)/A,n[11]=-1,n[12]=0,n[13]=0,n[14]=-o*r*2/A,n[15]=0,n},perspectiveMat4(e,t,i,s,r){const o=[],n=[];return o[2]=i,n[2]=s,n[1]=o[2]*Math.tan(e/2),o[1]=-n[1],n[0]=n[1]*t,o[0]=-n[0],d.frustumMat4v(o,n,r)},compareMat4:(e,t)=>e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]&&e[3]===t[3]&&e[4]===t[4]&&e[5]===t[5]&&e[6]===t[6]&&e[7]===t[7]&&e[8]===t[8]&&e[9]===t[9]&&e[10]===t[10]&&e[11]===t[11]&&e[12]===t[12]&&e[13]===t[13]&&e[14]===t[14]&&e[15]===t[15],transformPoint3(e,t,i=d.vec3()){const s=t[0],r=t[1],o=t[2];return i[0]=e[0]*s+e[4]*r+e[8]*o+e[12],i[1]=e[1]*s+e[5]*r+e[9]*o+e[13],i[2]=e[2]*s+e[6]*r+e[10]*o+e[14],i},transformPoint4:(e,t,i=d.vec4())=>(i[0]=e[0]*t[0]+e[4]*t[1]+e[8]*t[2]+e[12]*t[3],i[1]=e[1]*t[0]+e[5]*t[1]+e[9]*t[2]+e[13]*t[3],i[2]=e[2]*t[0]+e[6]*t[1]+e[10]*t[2]+e[14]*t[3],i[3]=e[3]*t[0]+e[7]*t[1]+e[11]*t[2]+e[15]*t[3],i),transformPoints3(e,t,i){const s=i||[],r=t.length;let o,n,a,l;const A=e[0],c=e[1],h=e[2],u=e[3],d=e[4],p=e[5],f=e[6],m=e[7],g=e[8],_=e[9],v=e[10],b=e[11],y=e[12],w=e[13],B=e[14],P=e[15];let x;for(let e=0;e<r;++e)l=t[e],o=l[0],n=l[1],a=l[2],x=s[e]||(s[e]=[0,0,0]),x[0]=A*o+d*n+g*a+y,x[1]=c*o+p*n+_*a+w,x[2]=h*o+f*n+v*a+B,x[3]=u*o+m*n+b*a+P;return s.length=r,s},transformPositions3(e,t,i=t){let s;const r=t.length;let o,n,a;const l=e[0],A=e[1],c=e[2];e[3];const h=e[4],u=e[5],d=e[6];e[7];const p=e[8],f=e[9],m=e[10];e[11];const g=e[12],_=e[13],v=e[14];for(e[15],s=0;s<r;s+=3)o=t[s+0],n=t[s+1],a=t[s+2],i[s+0]=l*o+h*n+p*a+g,i[s+1]=A*o+u*n+f*a+_,i[s+2]=c*o+d*n+m*a+v;return i},transformPositions4(e,t,i=t){let s;const r=t.length;let o,n,a;const l=e[0],A=e[1],c=e[2],h=e[3],u=e[4],d=e[5],p=e[6],f=e[7],m=e[8],g=e[9],_=e[10],v=e[11],b=e[12],y=e[13],w=e[14],B=e[15];for(s=0;s<r;s+=4)o=t[s+0],n=t[s+1],a=t[s+2],i[s+0]=l*o+u*n+m*a+b,i[s+1]=A*o+d*n+g*a+y,i[s+2]=c*o+p*n+_*a+w,i[s+3]=h*o+f*n+v*a+B;return i},transformVec3(e,t,i){const s=t[0],r=t[1],o=t[2];return(i=i||this.vec3())[0]=e[0]*s+e[4]*r+e[8]*o,i[1]=e[1]*s+e[5]*r+e[9]*o,i[2]=e[2]*s+e[6]*r+e[10]*o,i},transformVec4(e,t,i){const s=t[0],r=t[1],o=t[2],n=t[3];return(i=i||d.vec4())[0]=e[0]*s+e[4]*r+e[8]*o+e[12]*n,i[1]=e[1]*s+e[5]*r+e[9]*o+e[13]*n,i[2]=e[2]*s+e[6]*r+e[10]*o+e[14]*n,i[3]=e[3]*s+e[7]*r+e[11]*o+e[15]*n,i},rotateVec2(e,t,i,s=e){const r=Math.cos(i),o=Math.sin(i),n=e[0]-t[0],a=e[1]-t[1];return s[0]=n*r-a*o+t[0],s[1]=n*o+a*r+t[1],e},rotateVec3X(e,t,i,s){const r=[],o=[];return r[0]=e[0]-t[0],r[1]=e[1]-t[1],r[2]=e[2]-t[2],o[0]=r[0],o[1]=r[1]*Math.cos(i)-r[2]*Math.sin(i),o[2]=r[1]*Math.sin(i)+r[2]*Math.cos(i),s[0]=o[0]+t[0],s[1]=o[1]+t[1],s[2]=o[2]+t[2],s},rotateVec3Y(e,t,i,s){const r=[],o=[];return r[0]=e[0]-t[0],r[1]=e[1]-t[1],r[2]=e[2]-t[2],o[0]=r[2]*Math.sin(i)+r[0]*Math.cos(i),o[1]=r[1],o[2]=r[2]*Math.cos(i)-r[0]*Math.sin(i),s[0]=o[0]+t[0],s[1]=o[1]+t[1],s[2]=o[2]+t[2],s},rotateVec3Z(e,t,i,s){const r=[],o=[];return r[0]=e[0]-t[0],r[1]=e[1]-t[1],r[2]=e[2]-t[2],o[0]=r[0]*Math.cos(i)-r[1]*Math.sin(i),o[1]=r[0]*Math.sin(i)+r[1]*Math.cos(i),o[2]=r[2],s[0]=o[0]+t[0],s[1]=o[1]+t[1],s[2]=o[2]+t[2],s},projectVec4(e,t){const i=1/e[3];return(t=t||d.vec2())[0]=e[0]*i,t[1]=e[1]*i,t},unprojectVec3:(()=>{const e=new l(16),t=new l(16),i=new l(16);return function(s,r,o,n){return this.transformVec3(this.mulMat4(this.inverseMat4(r,e),this.inverseMat4(o,t),i),s,n)}})(),lerpVec3(e,t,i,s,r,o){const n=o||d.vec3(),a=(e-t)/(i-t);return n[0]=s[0]+a*(r[0]-s[0]),n[1]=s[1]+a*(r[1]-s[1]),n[2]=s[2]+a*(r[2]-s[2]),n},lerpMat4(e,t,i,s,r,o){const n=o||d.mat4(),a=(e-t)/(i-t);return n[0]=s[0]+a*(r[0]-s[0]),n[1]=s[1]+a*(r[1]-s[1]),n[2]=s[2]+a*(r[2]-s[2]),n[3]=s[3]+a*(r[3]-s[3]),n[4]=s[4]+a*(r[4]-s[4]),n[5]=s[5]+a*(r[5]-s[5]),n[6]=s[6]+a*(r[6]-s[6]),n[7]=s[7]+a*(r[7]-s[7]),n[8]=s[8]+a*(r[8]-s[8]),n[9]=s[9]+a*(r[9]-s[9]),n[10]=s[10]+a*(r[10]-s[10]),n[11]=s[11]+a*(r[11]-s[11]),n[12]=s[12]+a*(r[12]-s[12]),n[13]=s[13]+a*(r[13]-s[13]),n[14]=s[14]+a*(r[14]-s[14]),n[15]=s[15]+a*(r[15]-s[15]),n},flatten(e){const t=[];let i,s,r,o,n;for(i=0,s=e.length;i<s;i++)for(n=e[i],r=0,o=n.length;r<o;r++)t.push(n[r]);return t},identityQuaternion:(e=d.vec4())=>(e[0]=0,e[1]=0,e[2]=0,e[3]=1,e),eulerToQuaternion(e,t,i=d.vec4()){const s=e[0]*d.DEGTORAD/2,r=e[1]*d.DEGTORAD/2,o=e[2]*d.DEGTORAD/2,n=Math.cos(s),a=Math.cos(r),l=Math.cos(o),A=Math.sin(s),c=Math.sin(r),h=Math.sin(o);return"XYZ"===t?(i[0]=A*a*l+n*c*h,i[1]=n*c*l-A*a*h,i[2]=n*a*h+A*c*l,i[3]=n*a*l-A*c*h):"YXZ"===t?(i[0]=A*a*l+n*c*h,i[1]=n*c*l-A*a*h,i[2]=n*a*h-A*c*l,i[3]=n*a*l+A*c*h):"ZXY"===t?(i[0]=A*a*l-n*c*h,i[1]=n*c*l+A*a*h,i[2]=n*a*h+A*c*l,i[3]=n*a*l-A*c*h):"ZYX"===t?(i[0]=A*a*l-n*c*h,i[1]=n*c*l+A*a*h,i[2]=n*a*h-A*c*l,i[3]=n*a*l+A*c*h):"YZX"===t?(i[0]=A*a*l+n*c*h,i[1]=n*c*l+A*a*h,i[2]=n*a*h-A*c*l,i[3]=n*a*l-A*c*h):"XZY"===t&&(i[0]=A*a*l-n*c*h,i[1]=n*c*l-A*a*h,i[2]=n*a*h+A*c*l,i[3]=n*a*l+A*c*h),i},mat4ToQuaternion(e,t=d.vec4()){const i=e[0],s=e[4],r=e[8],o=e[1],n=e[5],a=e[9],l=e[2],A=e[6],c=e[10];let h;const u=i+n+c;return u>0?(h=.5/Math.sqrt(u+1),t[3]=.25/h,t[0]=(A-a)*h,t[1]=(r-l)*h,t[2]=(o-s)*h):i>n&&i>c?(h=2*Math.sqrt(1+i-n-c),t[3]=(A-a)/h,t[0]=.25*h,t[1]=(s+o)/h,t[2]=(r+l)/h):n>c?(h=2*Math.sqrt(1+n-i-c),t[3]=(r-l)/h,t[0]=(s+o)/h,t[1]=.25*h,t[2]=(a+A)/h):(h=2*Math.sqrt(1+c-i-n),t[3]=(o-s)/h,t[0]=(r+l)/h,t[1]=(a+A)/h,t[2]=.25*h),t},vec3PairToQuaternion(e,t,i=d.vec4()){const s=Math.sqrt(d.dotVec3(e,e)*d.dotVec3(t,t));let r=s+d.dotVec3(e,t);return r<1e-8*s?(r=0,Math.abs(e[0])>Math.abs(e[2])?(i[0]=-e[1],i[1]=e[0],i[2]=0):(i[0]=0,i[1]=-e[2],i[2]=e[1])):d.cross3Vec3(e,t,i),i[3]=r,d.normalizeQuaternion(i)},angleAxisToQuaternion(e,t=d.vec4()){const i=e[3]/2,s=Math.sin(i);return t[0]=s*e[0],t[1]=s*e[1],t[2]=s*e[2],t[3]=Math.cos(i),t},quaternionToEuler:(()=>{const e=new l(16);return(t,i,s)=>(s=s||d.vec3(),d.quaternionToRotationMat4(t,e),d.mat4ToEuler(e,i,s),s)})(),mulQuaternions(e,t,i=d.vec4()){const s=e[0],r=e[1],o=e[2],n=e[3],a=t[0],l=t[1],A=t[2],c=t[3];return i[0]=n*a+s*c+r*A-o*l,i[1]=n*l+r*c+o*a-s*A,i[2]=n*A+o*c+s*l-r*a,i[3]=n*c-s*a-r*l-o*A,i},vec3ApplyQuaternion(e,t,i=d.vec3()){const s=t[0],r=t[1],o=t[2],n=e[0],a=e[1],l=e[2],A=e[3],c=A*s+a*o-l*r,h=A*r+l*s-n*o,u=A*o+n*r-a*s,p=-n*s-a*r-l*o;return i[0]=c*A+p*-n+h*-l-u*-a,i[1]=h*A+p*-a+u*-n-c*-l,i[2]=u*A+p*-l+c*-a-h*-n,i},quaternionToMat4(e,t){t=d.identityMat4(t);const i=e[0],s=e[1],r=e[2],o=e[3],n=2*i,a=2*s,l=2*r,A=n*o,c=a*o,h=l*o,u=n*i,p=a*i,f=l*i,m=a*s,g=l*s,_=l*r;return t[0]=1-(m+_),t[1]=p+h,t[2]=f-c,t[4]=p-h,t[5]=1-(u+_),t[6]=g+A,t[8]=f+c,t[9]=g-A,t[10]=1-(u+m),t},quaternionToRotationMat4(e,t){const i=e[0],s=e[1],r=e[2],o=e[3],n=i+i,a=s+s,l=r+r,A=i*n,c=i*a,h=i*l,u=s*a,d=s*l,p=r*l,f=o*n,m=o*a,g=o*l;return t[0]=1-(u+p),t[4]=c-g,t[8]=h+m,t[1]=c+g,t[5]=1-(A+p),t[9]=d-f,t[2]=h-m,t[6]=d+f,t[10]=1-(A+u),t[3]=0,t[7]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t},normalizeQuaternion(e,t=e){const i=d.lenVec4([e[0],e[1],e[2],e[3]]);return t[0]=e[0]/i,t[1]=e[1]/i,t[2]=e[2]/i,t[3]=e[3]/i,t},conjugateQuaternion:(e,t=e)=>(t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=e[3],t),inverseQuaternion:(e,t)=>d.normalizeQuaternion(d.conjugateQuaternion(e,t)),quaternionToAngleAxis(e,t=d.vec4()){const i=(e=d.normalizeQuaternion(e,u))[3],s=2*Math.acos(i),r=Math.sqrt(1-i*i);return r<.001?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=e[0]/r,t[1]=e[1]/r,t[2]=e[2]/r),t[3]=s,t},AABB3:e=>new l(e||6),AABB2:e=>new l(e||4),OBB3:e=>new l(e||32),OBB2:e=>new l(e||16),Sphere3:(e,t,i,s)=>new l([e,t,i,s]),transformOBB3(e,t,i=t){let s;const r=t.length;let o,n,a;const l=e[0],A=e[1],c=e[2],h=e[3],u=e[4],d=e[5],p=e[6],f=e[7],m=e[8],g=e[9],_=e[10],v=e[11],b=e[12],y=e[13],w=e[14],B=e[15];for(s=0;s<r;s+=4)o=t[s+0],n=t[s+1],a=t[s+2],i[s+0]=l*o+u*n+m*a+b,i[s+1]=A*o+d*n+g*a+y,i[s+2]=c*o+p*n+_*a+w,i[s+3]=h*o+f*n+v*a+B;return i},containsAABB3:function(e,t){return e[0]<=t[0]&&t[3]<=e[3]&&e[1]<=t[1]&&t[4]<=e[4]&&e[2]<=t[2]&&t[5]<=e[5]},getAABB3Diag:(()=>{const e=new l(3),t=new l(3),i=new l(3);return s=>(e[0]=s[0],e[1]=s[1],e[2]=s[2],t[0]=s[3],t[1]=s[4],t[2]=s[5],d.subVec3(t,e,i),Math.abs(d.lenVec3(i)))})(),getAABB3DiagPoint:(()=>{const e=new l(3),t=new l(3),i=new l(3);return(s,r)=>{e[0]=s[0],e[1]=s[1],e[2]=s[2],t[0]=s[3],t[1]=s[4],t[2]=s[5];const o=d.subVec3(t,e,i),n=r[0]-s[0],a=s[3]-r[0],l=r[1]-s[1],A=s[4]-r[1],c=r[2]-s[2],h=s[5]-r[2];return o[0]+=n>a?n:a,o[1]+=l>A?l:A,o[2]+=c>h?c:h,Math.abs(d.lenVec3(o))}})(),getAABB3Area:e=>(e[3]-e[0])*(e[4]-e[1])*(e[5]-e[2]),getAABB3Center(e,t){const i=t||d.vec3();return i[0]=(e[0]+e[3])/2,i[1]=(e[1]+e[4])/2,i[2]=(e[2]+e[5])/2,i},getAABB2Center(e,t){const i=t||d.vec2();return i[0]=(e[2]+e[0])/2,i[1]=(e[3]+e[1])/2,i},collapseAABB3:(e=d.AABB3())=>(e[0]=d.MAX_DOUBLE,e[1]=d.MAX_DOUBLE,e[2]=d.MAX_DOUBLE,e[3]=d.MIN_DOUBLE,e[4]=d.MIN_DOUBLE,e[5]=d.MIN_DOUBLE,e),AABB3ToOBB3:(e,t=d.OBB3())=>(t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=1,t[4]=e[3],t[5]=e[1],t[6]=e[2],t[7]=1,t[8]=e[3],t[9]=e[4],t[10]=e[2],t[11]=1,t[12]=e[0],t[13]=e[4],t[14]=e[2],t[15]=1,t[16]=e[0],t[17]=e[1],t[18]=e[5],t[19]=1,t[20]=e[3],t[21]=e[1],t[22]=e[5],t[23]=1,t[24]=e[3],t[25]=e[4],t[26]=e[5],t[27]=1,t[28]=e[0],t[29]=e[4],t[30]=e[5],t[31]=1,t),positions3ToAABB3:(()=>{const e=new l(3);return(t,i,s)=>{i=i||d.AABB3();let r,o,n,a=d.MAX_DOUBLE,l=d.MAX_DOUBLE,A=d.MAX_DOUBLE,c=d.MIN_DOUBLE,h=d.MIN_DOUBLE,u=d.MIN_DOUBLE;for(let i=0,p=t.length;i<p;i+=3)s?(e[0]=t[i+0],e[1]=t[i+1],e[2]=t[i+2],d.decompressPosition(e,s,e),r=e[0],o=e[1],n=e[2]):(r=t[i+0],o=t[i+1],n=t[i+2]),r<a&&(a=r),o<l&&(l=o),n<A&&(A=n),r>c&&(c=r),o>h&&(h=o),n>u&&(u=n);return i[0]=a,i[1]=l,i[2]=A,i[3]=c,i[4]=h,i[5]=u,i}})(),OBB3ToAABB3(e,t=d.AABB3()){let i,s,r,o=d.MAX_DOUBLE,n=d.MAX_DOUBLE,a=d.MAX_DOUBLE,l=d.MIN_DOUBLE,A=d.MIN_DOUBLE,c=d.MIN_DOUBLE;for(let t=0,h=e.length;t<h;t+=4)i=e[t+0],s=e[t+1],r=e[t+2],i<o&&(o=i),s<n&&(n=s),r<a&&(a=r),i>l&&(l=i),s>A&&(A=s),r>c&&(c=r);return t[0]=o,t[1]=n,t[2]=a,t[3]=l,t[4]=A,t[5]=c,t},points3ToAABB3(e,t=d.AABB3()){let i,s,r,o=d.MAX_DOUBLE,n=d.MAX_DOUBLE,a=d.MAX_DOUBLE,l=d.MIN_DOUBLE,A=d.MIN_DOUBLE,c=d.MIN_DOUBLE;for(let t=0,h=e.length;t<h;t++)i=e[t][0],s=e[t][1],r=e[t][2],i<o&&(o=i),s<n&&(n=s),r<a&&(a=r),i>l&&(l=i),s>A&&(A=s),r>c&&(c=r);return t[0]=o,t[1]=n,t[2]=a,t[3]=l,t[4]=A,t[5]=c,t},points3ToSphere3:(()=>{const e=new l(3);return(t,i)=>{i=i||d.vec4();let s,r=0,o=0,n=0;const a=t.length;for(s=0;s<a;s++)r+=t[s][0],o+=t[s][1],n+=t[s][2];i[0]=r/a,i[1]=o/a,i[2]=n/a;let l,A=0;for(s=0;s<a;s++)l=Math.abs(d.lenVec3(d.subVec3(t[s],i,e))),l>A&&(A=l);return i[3]=A,i}})(),positions3ToSphere3:(()=>{const e=new l(3),t=new l(3);return(i,s)=>{s=s||d.vec4();let r,o=0,n=0,a=0;const l=i.length;let A=0;for(r=0;r<l;r+=3)o+=i[r],n+=i[r+1],a+=i[r+2];const c=l/3;let h;for(s[0]=o/c,s[1]=n/c,s[2]=a/c,r=0;r<l;r+=3)e[0]=i[r],e[1]=i[r+1],e[2]=i[r+2],h=Math.abs(d.lenVec3(d.subVec3(e,s,t))),h>A&&(A=h);return s[3]=A,s}})(),OBB3ToSphere3:(()=>{const e=new l(3),t=new l(3);return(i,s)=>{s=s||d.vec4();let r,o=0,n=0,a=0;const l=i.length,A=l/4;for(r=0;r<l;r+=4)o+=i[r+0],n+=i[r+1],a+=i[r+2];s[0]=o/A,s[1]=n/A,s[2]=a/A;let c,h=0;for(r=0;r<l;r+=4)e[0]=i[r+0],e[1]=i[r+1],e[2]=i[r+2],c=Math.abs(d.lenVec3(d.subVec3(e,s,t))),c>h&&(h=c);return s[3]=h,s}})(),getSphere3Center:(e,t=d.vec3())=>(t[0]=e[0],t[1]=e[1],t[2]=e[2],t),getPositionsCenter(e,t=d.vec3()){let i=0,s=0,r=0;for(var o=0,n=e.length;o<n;o+=3)i+=e[o+0],s+=e[o+1],r+=e[o+2];const a=e.length/3;return t[0]=i/a,t[1]=s/a,t[2]=r/a,t},expandAABB3:(e,t)=>(e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]>t[2]&&(e[2]=t[2]),e[3]<t[3]&&(e[3]=t[3]),e[4]<t[4]&&(e[4]=t[4]),e[5]<t[5]&&(e[5]=t[5]),e),expandAABB3Point3:(e,t)=>(e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]>t[2]&&(e[2]=t[2]),e[3]<t[0]&&(e[3]=t[0]),e[4]<t[1]&&(e[4]=t[1]),e[5]<t[2]&&(e[5]=t[2]),e),expandAABB3Points3(e,t){for(var i,s,r,o=0,n=t.length;o<n;o+=3)i=t[o],s=t[o+1],r=t[o+2],e[0]>i&&(e[0]=i),e[1]>s&&(e[1]=s),e[2]>r&&(e[2]=r),e[3]<i&&(e[3]=i),e[4]<s&&(e[4]=s),e[5]<r&&(e[5]=r);return e},collapseAABB2:(e=d.AABB2())=>(e[0]=d.MAX_DOUBLE,e[1]=d.MAX_DOUBLE,e[2]=d.MIN_DOUBLE,e[3]=d.MIN_DOUBLE,e),point3AABB3Intersect:(e,t)=>e[0]>t[0]||e[3]<t[0]||e[1]>t[1]||e[4]<t[1]||e[2]>t[2]||e[5]<t[2],point3AABB3AbsoluteIntersect:(e,t)=>e[0]<=t[0]&&e[3]>=t[0]&&e[1]<=t[1]&&e[4]>=t[1]&&e[2]<=t[2]&&e[5]>=t[2],planeAABB3Intersect(e,t,i){let s,r;e[0]>0?(s=e[0]*i[0],r=e[0]*i[3]):(s=e[0]*i[3],r=e[0]*i[0]),e[1]>0?(s+=e[1]*i[1],r+=e[1]*i[4]):(s+=e[1]*i[4],r+=e[1]*i[1]),e[2]>0?(s+=e[2]*i[2],r+=e[2]*i[5]):(s+=e[2]*i[5],r+=e[2]*i[2]);if(s<=-t&&r<=-t)return-1;return s>=-t&&r>=-t?1:0},OBB3ToAABB2(e,t=d.AABB2()){let i,s,r,o,n=d.MAX_DOUBLE,a=d.MAX_DOUBLE,l=d.MIN_DOUBLE,A=d.MIN_DOUBLE;for(let t=0,c=e.length;t<c;t+=4)i=e[t+0],s=e[t+1],r=e[t+3]||1,o=1/r,i*=o,s*=o,i<n&&(n=i),s<a&&(a=s),i>l&&(l=i),s>A&&(A=s);return t[0]=n,t[1]=a,t[2]=l,t[3]=A,t},expandAABB2:(e,t)=>(e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]<t[2]&&(e[2]=t[2]),e[3]<t[3]&&(e[3]=t[3]),e),expandAABB2Point2:(e,t)=>(e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]<t[0]&&(e[2]=t[0]),e[3]<t[1]&&(e[3]=t[1]),e),AABB2ToCanvas(e,t,i,s=e){const r=.5*(e[0]+1),o=.5*(e[1]+1),n=.5*(e[2]+1),a=.5*(e[3]+1);return s[0]=Math.floor(r*t),s[1]=i-Math.floor(a*i),s[2]=Math.floor(n*t),s[3]=i-Math.floor(o*i),s},tangentQuadraticBezier:(e,t,i,s)=>2*(1-e)*(i-t)+2*e*(s-i),tangentQuadraticBezier3:(e,t,i,s,r)=>-3*t*(1-e)*(1-e)+3*i*(1-e)*(1-e)-6*e*i*(1-e)+6*e*s*(1-e)-3*e*e*s+3*e*e*r,tangentSpline:e=>6*e*e-6*e+(3*e*e-4*e+1)+(-6*e*e+6*e)+(3*e*e-2*e),catmullRomInterpolate(e,t,i,s,r){const o=.5*(i-e),n=.5*(s-t),a=r*r;return(2*t-2*i+o+n)*(r*a)+(-3*t+3*i-2*o-n)*a+o*r+t},b2p0(e,t){const i=1-e;return i*i*t},b2p1:(e,t)=>2*(1-e)*e*t,b2p2:(e,t)=>e*e*t,b2(e,t,i,s){return this.b2p0(e,t)+this.b2p1(e,i)+this.b2p2(e,s)},b3p0(e,t){const i=1-e;return i*i*i*t},b3p1(e,t){const i=1-e;return 3*i*i*e*t},b3p2:(e,t)=>3*(1-e)*e*e*t,b3p3:(e,t)=>e*e*e*t,b3(e,t,i,s,r){return this.b3p0(e,t)+this.b3p1(e,i)+this.b3p2(e,s)+this.b3p3(e,r)},triangleNormal(e,t,i,s=d.vec3()){const r=t[0]-e[0],o=t[1]-e[1],n=t[2]-e[2],a=i[0]-e[0],l=i[1]-e[1],A=i[2]-e[2],c=o*A-n*l,h=n*a-r*A,u=r*l-o*a,p=Math.sqrt(c*c+h*h+u*u);return 0===p?(s[0]=0,s[1]=0,s[2]=0):(s[0]=c/p,s[1]=h/p,s[2]=u/p),s},rayTriangleIntersect:(()=>{const e=new l(3),t=new l(3),i=new l(3),s=new l(3),r=new l(3);return(o,n,a,l,A,c)=>{c=c||d.vec3();const h=d.subVec3(l,a,e),u=d.subVec3(A,a,t),p=d.cross3Vec3(n,u,i),f=d.dotVec3(h,p);if(f<1e-6)return null;const m=d.subVec3(o,a,s),g=d.dotVec3(m,p);if(g<0||g>f)return null;const _=d.cross3Vec3(m,h,r),v=d.dotVec3(n,_);if(v<0||g+v>f)return null;const b=d.dotVec3(u,_)/f;return c[0]=o[0]+b*n[0],c[1]=o[1]+b*n[1],c[2]=o[2]+b*n[2],c}})(),rayPlaneIntersect:(()=>{const e=new l(3),t=new l(3),i=new l(3),s=new l(3);return(r,o,n,a,l,A)=>{A=A||d.vec3(),o=d.normalizeVec3(o,e);const c=d.subVec3(a,n,t),h=d.subVec3(l,n,i),u=d.cross3Vec3(c,h,s);d.normalizeVec3(u,u);const p=-d.dotVec3(n,u),f=-(d.dotVec3(r,u)+p)/d.dotVec3(o,u);return A[0]=r[0]+f*o[0],A[1]=r[1]+f*o[1],A[2]=r[2]+f*o[2],A}})(),cartesianToBarycentric:(()=>{const e=new l(3),t=new l(3),i=new l(3);return(s,r,o,n,a)=>{const l=d.subVec3(n,r,e),A=d.subVec3(o,r,t),c=d.subVec3(s,r,i),h=d.dotVec3(l,l),u=d.dotVec3(l,A),p=d.dotVec3(l,c),f=d.dotVec3(A,A),m=d.dotVec3(A,c),g=h*f-u*u;if(0===g)return null;const _=1/g,v=(f*p-u*m)*_,b=(h*m-u*p)*_;return a[0]=1-v-b,a[1]=b,a[2]=v,a}})(),barycentricInsideTriangle(e){const t=e[1],i=e[2];return i>=0&&t>=0&&i+t<1},barycentricToCartesian(e,t,i,s,r=d.vec3()){const o=e[0],n=e[1],a=e[2];return r[0]=t[0]*o+i[0]*n+s[0]*a,r[1]=t[1]*o+i[1]*n+s[1]*a,r[2]=t[2]*o+i[2]*n+s[2]*a,r},mergeVertices(e,t,i,s){const r={},o=[],n=[],a=t?[]:null,l=i?[]:null,A=[];let c,h,u,d;const p=1e4;let f,m,g=0;for(f=0,m=e.length;f<m;f+=3)c=e[f],h=e[f+1],u=e[f+2],d=`${Math.round(c*p)}_${Math.round(h*p)}_${Math.round(u*p)}`,void 0===r[d]&&(r[d]=n.length/3,n.push(c),n.push(h),n.push(u),t&&(a.push(t[f]),a.push(t[f+1]),a.push(t[f+2])),i&&(l.push(i[g]),l.push(i[g+1]))),o[f/3]=r[d],g+=2;for(f=0,m=s.length;f<m;f++)A[f]=o[s[f]];const _={positions:n,indices:A};return a&&(_.normals=a),l&&(_.uv=l),_},buildNormals:(()=>{const e=new l(3),t=new l(3),i=new l(3),s=new l(3),r=new l(3),o=new l(3);return(n,a,l)=>{let A,c;const h=new Array(n.length/3);let u,p,f,m,g,_,v;for(A=0,c=a.length;A<c;A+=3){u=a[A],p=a[A+1],f=a[A+2],e[0]=n[3*u],e[1]=n[3*u+1],e[2]=n[3*u+2],t[0]=n[3*p],t[1]=n[3*p+1],t[2]=n[3*p+2],i[0]=n[3*f],i[1]=n[3*f+1],i[2]=n[3*f+2],d.subVec3(t,e,s),d.subVec3(i,e,r);const l=d.vec3();d.normalizeVec3(d.cross3Vec3(s,r,o),l),h[u]||(h[u]=[]),h[p]||(h[p]=[]),h[f]||(h[f]=[]),h[u].push(l),h[p].push(l),h[f].push(l)}for(l=l&&l.length===n.length?l:new Float32Array(n.length),A=0,c=h.length;A<c;A++){m=h[A].length,g=0,_=0,v=0;for(let e=0;e<m;e++)g+=h[A][e][0],_+=h[A][e][1],v+=h[A][e][2];l[3*A]=g/m,l[3*A+1]=_/m,l[3*A+2]=v/m}return l}})(),buildTangents:(()=>{const e=new l(3),t=new l(3),i=new l(3),s=new l(3),r=new l(3),o=new l(3),n=new l(3);return(a,l,A)=>{const c=new Float32Array(a.length);for(let h=0;h<l.length;h+=3){let u=l[h];const p=a.subarray(3*u,3*u+3),f=A.subarray(2*u,2*u+2);u=l[h+1];const m=a.subarray(3*u,3*u+3),g=A.subarray(2*u,2*u+2);u=l[h+2];const _=a.subarray(3*u,3*u+3),v=A.subarray(2*u,2*u+2),b=d.subVec3(m,p,e),y=d.subVec3(_,p,t),w=d.subVec2(g,f,i),B=d.subVec2(v,f,s),P=1/(w[0]*B[1]-w[1]*B[0]),x=d.mulVec3Scalar(d.subVec3(d.mulVec3Scalar(b,B[1],r),d.mulVec3Scalar(y,w[1],o),n),P,o);let C;for(let e=0;e<3;e++)C=3*l[h+e],c[C]+=x[0],c[C+1]+=x[1],c[C+2]+=x[2]}return c}})(),buildPickTriangles(e,t,i){const s=t.length,r=i?new Uint16Array(9*s):new Float32Array(9*s),o=new Uint8Array(12*s);let n,a,l,A,c,h,u=0,d=0,p=0;for(let i=0;i<s;i+=3)h=u>>24&255,c=u>>16&255,A=u>>8&255,l=255&u,a=t[i],n=3*a,r[d++]=e[n],r[d++]=e[n+1],r[d++]=e[n+2],o[p++]=l,o[p++]=A,o[p++]=c,o[p++]=h,a=t[i+1],n=3*a,r[d++]=e[n],r[d++]=e[n+1],r[d++]=e[n+2],o[p++]=l,o[p++]=A,o[p++]=c,o[p++]=h,a=t[i+2],n=3*a,r[d++]=e[n],r[d++]=e[n+1],r[d++]=e[n+2],o[p++]=l,o[p++]=A,o[p++]=c,o[p++]=h,u++;return{positions:r,colors:o}},faceToVertexNormals(e,t,i={}){const s=i.smoothNormalsAngleThreshold||20,r={},o=[],n={};let a,l,A,c,h;const u=1e4;let p,f,m,g,_,v;for(f=0,g=e.length;f<g;f+=3){p=f/3,l=e[f],A=e[f+1],c=e[f+2],h=`${Math.round(l*u)}_${Math.round(A*u)}_${Math.round(c*u)}`,void 0===r[h]?r[h]=[p]:r[h].push(p);const i=d.normalizeVec3([t[f],t[f+1],t[f+2]]);o[p]=i,a=d.vec4([i[0],i[1],i[2],1]),n[p]=a}for(h in r)if(r.hasOwnProperty(h)){const e=r[h],t=e.length;for(f=0;f<t;f++){const i=e[f];for(a=n[i],m=0;m<t;m++){if(f===m)continue;const t=e[m];_=o[i],v=o[t];Math.abs(d.angleVec3(_,v)/d.DEGTORAD)<s&&(a[0]+=v[0],a[1]+=v[1],a[2]+=v[2],a[3]+=1)}}}for(f=0,g=t.length;f<g;f+=3)a=n[f/3],t[f+0]=a[0]/a[3],t[f+1]=a[1]/a[3],t[f+2]=a[2]/a[3]},transformRay:(()=>{const e=new l(4),t=new l(4);return(i,s,r,o,n)=>{e[0]=s[0],e[1]=s[1],e[2]=s[2],e[3]=1,d.transformVec4(i,e,t),o[0]=t[0],o[1]=t[1],o[2]=t[2],e[0]=r[0],e[1]=r[1],e[2]=r[2],d.transformVec3(i,e,t),d.normalizeVec3(t),n[0]=t[0],n[1]=t[1],n[2]=t[2]}})(),canvasPosToWorldRay:(()=>{const e=new l(16),t=new l(4),i=new l(4),s=(t,i,s,r,o)=>{o[0]=t,o[1]=i,o[2]=s,o[3]=1,d.transformVec4(e,o,o),r||d.mulVec4Scalar(o,1/o[3])};return(r,o,n,a,l,A,c)=>{const h="ortho"===a;d.mulMat4(n,o,e),d.inverseMat4(e,e);const u=2*l[0]/r.clientWidth-1,p=1-2*l[1]/r.clientHeight;s(u,p,-1,h,t),s(u,p,1,h,i),A[0]=t[0],A[1]=t[1],A[2]=t[2],d.subVec3(i,t,c),d.normalizeVec3(c)}})(),canvasPosToLocalRay:(()=>{const e=new l(3),t=new l(3);return(i,s,r,o,n,a,l,A)=>{d.canvasPosToWorldRay(i,s,r,o,a,e,t),d.worldRayToLocalRay(n,e,t,l,A)}})(),worldRayToLocalRay:(()=>{const e=new l(16),t=new l(4),i=new l(4);return(s,r,o,n,a)=>{const l=d.inverseMat4(s,e);t[0]=r[0],t[1]=r[1],t[2]=r[2],t[3]=1,d.transformVec4(l,t,i),n[0]=i[0],n[1]=i[1],n[2]=i[2],d.transformVec3(l,o,a)}})(),buildKDTree:(()=>{const e=new Float32Array;function t(i,s,r,o){const n=new l(6),a={triangles:null,left:null,right:null,leaf:!1,splitDim:0,aabb:n};let A,c;for(n[0]=n[1]=n[2]=Number.POSITIVE_INFINITY,n[3]=n[4]=n[5]=Number.NEGATIVE_INFINITY,A=0,c=i.length;A<c;++A){var h=3*i[A];for(let e=0;e<3;++e){const t=3*s[h+e];r[t]<n[0]&&(n[0]=r[t]),r[t]>n[3]&&(n[3]=r[t]),r[t+1]<n[1]&&(n[1]=r[t+1]),r[t+1]>n[4]&&(n[4]=r[t+1]),r[t+2]<n[2]&&(n[2]=r[t+2]),r[t+2]>n[5]&&(n[5]=r[t+2])}}if(i.length<20||o>10)return a.triangles=i,a.leaf=!0,a;e[0]=n[3]-n[0],e[1]=n[4]-n[1],e[2]=n[5]-n[2];let u=0;e[1]>e[u]&&(u=1),e[2]>e[u]&&(u=2),a.splitDim=u;const d=(n[u]+n[u+3])/2,p=new Array(i.length);let f=0;const m=new Array(i.length);let g=0;for(A=0,c=i.length;A<c;++A){const e=s[h=3*i[A]],t=3*s[h+1],o=3*s[h+2];r[3*e+u]<=d||r[t+u]<=d||r[o+u]<=d?p[f++]=i[A]:m[g++]=i[A]}return p.length=f,m.length=g,a.left=t(p,s,r,o+1),a.right=t(m,s,r,o+1),a}return(e,i)=>{const s=e.length/3,r=new Array(s);for(let e=0;e<s;++e)r[e]=e;return t(r,e,i,0)}})(),decompressPosition(e,t,i){(i=i||e)[0]=e[0]*t[0]+t[12],i[1]=e[1]*t[5]+t[13],i[2]=e[2]*t[10]+t[14]},decompressPositions(e,t,i=new Float32Array(e.length)){for(let s=0,r=e.length;s<r;s+=3)i[s+0]=e[s+0]*t[0]+t[12],i[s+1]=e[s+1]*t[5]+t[13],i[s+2]=e[s+2]*t[10]+t[14];return i},decompressUV(e,t,i){i[0]=e[0]*t[0]+t[6],i[1]=e[1]*t[4]+t[7]},decompressUVs(e,t,i=new Float32Array(e.length)){for(let s=0,r=e.length;s<r;s+=3)i[s+0]=e[s+0]*t[0]+t[6],i[s+1]=e[s+1]*t[4]+t[7];return i},octDecodeVec2(e,t){let i=e[0],s=e[1];i=(2*i+1)/255,s=(2*s+1)/255;const r=1-Math.abs(i)-Math.abs(s);r<0&&(i=(1-Math.abs(s))*(i>=0?1:-1),s=(1-Math.abs(i))*(s>=0?1:-1));const o=Math.sqrt(i*i+s*s+r*r);return t[0]=i/o,t[1]=s/o,t[2]=r/o,t},octDecodeVec2s(e,t){for(let i=0,s=0,r=e.length;i<r;i+=2){let r=e[i+0],o=e[i+1];r=(2*r+1)/255,o=(2*o+1)/255;const n=1-Math.abs(r)-Math.abs(o);n<0&&(r=(1-Math.abs(o))*(r>=0?1:-1),o=(1-Math.abs(r))*(o>=0?1:-1));const a=Math.sqrt(r*r+o*o+n*n);t[s+0]=r/a,t[s+1]=o/a,t[s+2]=n/a,s+=3}return t}};d.buildEdgeIndices=function(){const e=[],t=[],i=[],s=[],r=[];let o=0;const n=ne