@xeokit/xeokit-sdk 2.6.97 → 2.6.98

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,10 @@
1
1
  /**
2
- * xeokit-sdk v2.6.97
3
- * Commit: fd8731b8272e4958c8231a6794a98a1874564a08
4
- * Built: 2025-12-03T17:04:45.022Z
2
+ * xeokit-sdk v2.6.98
3
+ * Commit: 30ac0fa9a4eaf6759fe306bb2e332cce49884787
4
+ * Built: 2025-12-08T14:34:05.193Z
5
5
  */
6
6
 
7
- "undefined"!=typeof window&&(window.__XEOKIT__={version:"2.6.97",commit:"fd8731b8272e4958c8231a6794a98a1874564a08",built:"2025-12-03T17:04:45.022Z"});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 n{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 n=this._getNextId(),A=new i(n);for(let i=0,n=e.length;i<n;i++){const n=e[i],o=new s;A.groups.push(o);for(let e=0,i=n.length;e<i;e++){const i=n[e],s=i.items,a=s&&s.length>0,l=this._getNextId(),c=i.getTitle||(()=>i.title||""),h=i.doAction||i.callback||(()=>{}),u=i.getEnabled||(()=>!0),d=i.getShown||(()=>!0),f=new r(l,c,h,u,d);if(f.parentMenu=A,o.items.push(f),a){const e=t(s);f.subMenu=e,e.parentItem=f}this._itemList.push(f),this._itemMap[f.id]=f}}return this._menuList.push(A),this._menuMap[A.id]=A,A};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,n=s,A=t[e].items;if(A)for(let e=0,t=A.length;e<t;e++){const s=A[e],o=s.subMenu,a=s.title||"";o?(i.push('<li id="'+s.id+'" class="xeokit-context-menu-item xeokit-context-menu-submenu">'+a+"</li>"),r===n-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">'+a+"</li>"),r===n-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 n=this;let A=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(A&&(n._hideMenu(A.id),A=null));if(A&&A.id!==i.id&&(n._hideMenu(A.id),A=null),!1===t.enabled)return;const s=t.itemElement,r=i.menuElement,o=s.getBoundingClientRect();r.getBoundingClientRect();const a=n._offsetParent.getBoundingClientRect(),l=200,c=o.right+l<a.right,h=o.left-l>a.left;if(c)n._showMenu(i.id,o.right+window.scrollX-5,o.top+window.scrollY-1);else if(h)n._showMenu(i.id,o.left-l+window.scrollX,o.top+window.scrollY-1);else{const e=o.left-a.left,t=a.right-o.right;t>e?n._showMenu(i.id,o.right-5-(l-t),o.top+window.scrollY-1):n._showMenu(i.id,o.left-e,o.top+window.scrollY-1)}A=i})),s||(t.itemElement.addEventListener("click",(e=>{e.preventDefault(),n._context&&!1!==t.enabled&&(t.doAction&&t.doAction(n._context),this._hideOnAction?n.hide():(n._updateItemsTitles(),n._updateItemsEnabledStatus()))})),t.itemElement.addEventListener("mouseup",(e=>{3===e.which&&(e.preventDefault(),n._context&&!1!==t.enabled&&(t.doAction&&t.doAction(n._context),this._hideOnAction?n.hide():(n._updateItemsTitles(),n._updateItemsEnabledStatus())))})),t.itemElement.addEventListener("mouseenter",(e=>{e.preventDefault(),!1!==t.enabled&&t.doHover&&t.doHover(n._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 n=r(this._context);if(t.shown=n,!n){i.style.display="none";continue}i.style.display="";const A=s(this._context);t.enabled=A,A?i.classList.remove("disabled"):i.classList.add("disabled")}}_updateSubMenuInfo(){if(!this._context)return;let e,t,i,s,r,n;this._itemList.forEach((A=>{A.subMenu&&(e=A.itemElement,t=e.getBoundingClientRect(),i=A.subMenu.menuElement,s={visibility:i.style.visibility,display:i.style.display},i.style.display="block",i.style.visibility="hidden",n=A.subMenu.menuElement.getBoundingClientRect().width,i.style.visibility=s.visibility,i.style.display=s.display,r=t.right+n>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,n=this._offsetParent.getBoundingClientRect(),A=this._offsetParent===window.document.body&&0===n.bottom?window.innerHeight:n.bottom+window.scrollY,o=n.right+window.scrollX;i+s>A&&(i=A-s),t+r>o&&(t=o-r),e.style.left=t-n.left-window.scrollX+"px",e.style.top=i-n.top-window.scrollY+"px"}_hideMenuElement(e){e.style.display="none"}}class A{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,n=this._snappedCanvasPos?this._snappedCanvasPos[0]-this._canvasPos[0]:0,A=this._snappedCanvasPos?this._snappedCanvasPos[1]-this._canvasPos[1]:0;this._lensCursorDiv.style.left=`${r+n*this._zoomLevel}px`,this._lensCursorDiv.style.top=`${r+A*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)}}function o(e,t,i=2){const s=t&&t.length,r=s?t[0]*i:e.length;let n=a(e,0,r,i,!0);const A=[];if(!n||n.next===n.prev)return A;let o,l,h;if(s&&(n=function(e,t,i,s){const r=[];for(let i=0,n=t.length;i<n;i++){const A=a(e,t[i]*s,i<n-1?t[i+1]*s:e.length,s,!1);A===A.next&&(A.steiner=!0),r.push(b(A))}r.sort(p);for(let e=0;e<r.length;e++)i=g(r[e],i);return i}(e,t,n,i)),e.length>80*i){o=1/0,l=1/0;let t=-1/0,s=-1/0;for(let n=i;n<r;n+=i){const i=e[n],r=e[n+1];i<o&&(o=i),r<l&&(l=r),i>t&&(t=i),r>s&&(s=r)}h=Math.max(t-o,s-l),h=0!==h?32767/h:0}return c(n,A,i,o,l,h,0),A}function a(e,t,i,s,r){let n;if(r===function(e,t,i,s){let r=0;for(let n=t,A=i-s;n<i;n+=s)r+=(e[A]-e[n])*(e[n+1]+e[A+1]),A=n;return r}(e,t,i,s)>0)for(let r=t;r<i;r+=s)n=I(r/s|0,e[r],e[r+1],n);else for(let r=i-s;r>=t;r-=s)n=I(r/s|0,e[r],e[r+1],n);return n&&C(n,n.next)&&(T(n),n=n.next),n}function l(e,t){if(!e)return e;t||(t=e);let i,s=e;do{if(i=!1,s.steiner||!C(s,s.next)&&0!==v(s.prev,s,s.next))s=s.next;else{if(T(s),s=t=s.prev,s===s.next)break;i=!0}}while(i||s!==t);return t}function c(e,t,i,s,r,n,A){if(!e)return;!A&&n&&function(e,t,i,s){let r=e;do{0===r.z&&(r.z=_(r.x,r.y,t,i,s)),r.prevZ=r.prev,r.nextZ=r.next,r=r.next}while(r!==e);r.prevZ.nextZ=null,r.prevZ=null,function(e){let t,i=1;do{let s,r=e;e=null;let n=null;for(t=0;r;){t++;let A=r,o=0;for(let e=0;e<i&&(o++,A=A.nextZ,A);e++);let a=i;for(;o>0||a>0&&A;)0!==o&&(0===a||!A||r.z<=A.z)?(s=r,r=r.nextZ,o--):(s=A,A=A.nextZ,a--),n?n.nextZ=s:e=s,s.prevZ=n,n=s;r=A}n.nextZ=null,i*=2}while(t>1)}(r)}(e,s,r,n);let o=e;for(;e.prev!==e.next;){const a=e.prev,p=e.next;if(n?u(e,s,r,n):h(e))t.push(a.i,e.i,p.i),T(e),e=p.next,o=p.next;else if((e=p)===o){A?1===A?c(e=d(l(e),t),t,i,s,r,n,2):2===A&&f(e,t,i,s,r,n):c(l(e),t,i,s,r,n,1);break}}}function h(e){const t=e.prev,i=e,s=e.next;if(v(t,i,s)>=0)return!1;const r=t.x,n=i.x,A=s.x,o=t.y,a=i.y,l=s.y,c=Math.min(r,n,A),h=Math.min(o,a,l),u=Math.max(r,n,A),d=Math.max(o,a,l);let f=s.next;for(;f!==t;){if(f.x>=c&&f.x<=u&&f.y>=h&&f.y<=d&&y(r,o,n,a,A,l,f.x,f.y)&&v(f.prev,f,f.next)>=0)return!1;f=f.next}return!0}function u(e,t,i,s){const r=e.prev,n=e,A=e.next;if(v(r,n,A)>=0)return!1;const o=r.x,a=n.x,l=A.x,c=r.y,h=n.y,u=A.y,d=Math.min(o,a,l),f=Math.min(c,h,u),p=Math.max(o,a,l),g=Math.max(c,h,u),m=_(d,f,t,i,s),b=_(p,g,t,i,s);let B=e.prevZ,w=e.nextZ;for(;B&&B.z>=m&&w&&w.z<=b;){if(B.x>=d&&B.x<=p&&B.y>=f&&B.y<=g&&B!==r&&B!==A&&y(o,c,a,h,l,u,B.x,B.y)&&v(B.prev,B,B.next)>=0)return!1;if(B=B.prevZ,w.x>=d&&w.x<=p&&w.y>=f&&w.y<=g&&w!==r&&w!==A&&y(o,c,a,h,l,u,w.x,w.y)&&v(w.prev,w,w.next)>=0)return!1;w=w.nextZ}for(;B&&B.z>=m;){if(B.x>=d&&B.x<=p&&B.y>=f&&B.y<=g&&B!==r&&B!==A&&y(o,c,a,h,l,u,B.x,B.y)&&v(B.prev,B,B.next)>=0)return!1;B=B.prevZ}for(;w&&w.z<=b;){if(w.x>=d&&w.x<=p&&w.y>=f&&w.y<=g&&w!==r&&w!==A&&y(o,c,a,h,l,u,w.x,w.y)&&v(w.prev,w,w.next)>=0)return!1;w=w.nextZ}return!0}function d(e,t){let i=e;do{const s=i.prev,r=i.next.next;!C(s,r)&&M(s,i,i.next,r)&&U(s,r)&&U(r,s)&&(t.push(s.i,i.i,r.i),T(i),T(i.next),i=e=r),i=i.next}while(i!==e);return l(i)}function f(e,t,i,s,r,n){let A=e;do{let e=A.next.next;for(;e!==A.prev;){if(A.i!==e.i&&w(A,e)){let o=x(A,e);return A=l(A,A.next),o=l(o,o.next),c(A,t,i,s,r,n,0),void c(o,t,i,s,r,n,0)}e=e.next}A=A.next}while(A!==e)}function p(e,t){let i=e.x-t.x;if(0===i&&(i=e.y-t.y,0===i)){i=(e.next.y-e.y)/(e.next.x-e.x)-(t.next.y-t.y)/(t.next.x-t.x)}return i}function g(e,t){const i=function(e,t){let i=t;const s=e.x,r=e.y;let n,A=-1/0;if(C(e,i))return i;do{if(C(e,i.next))return i.next;if(r<=i.y&&r>=i.next.y&&i.next.y!==i.y){const e=i.x+(r-i.y)*(i.next.x-i.x)/(i.next.y-i.y);if(e<=s&&e>A&&(A=e,n=i.x<i.next.x?i:i.next,e===s))return n}i=i.next}while(i!==t);if(!n)return null;const o=n,a=n.x,l=n.y;let c=1/0;i=n;do{if(s>=i.x&&i.x>=a&&s!==i.x&&B(r<l?s:A,r,a,l,r<l?A:s,r,i.x,i.y)){const t=Math.abs(r-i.y)/(s-i.x);U(i,e)&&(t<c||t===c&&(i.x>n.x||i.x===n.x&&m(n,i)))&&(n=i,c=t)}i=i.next}while(i!==o);return n}(e,t);if(!i)return t;const s=x(i,e);return l(s,s.next),l(i,i.next)}function m(e,t){return v(e.prev,e,t.prev)<0&&v(t.next,e,e.next)<0}function _(e,t,i,s,r){return(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=(e-i)*r|0)|e<<8))|e<<4))|e<<2))|e<<1))|(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=(t-s)*r|0)|t<<8))|t<<4))|t<<2))|t<<1))<<1}function b(e){let t=e,i=e;do{(t.x<i.x||t.x===i.x&&t.y<i.y)&&(i=t),t=t.next}while(t!==e);return i}function B(e,t,i,s,r,n,A,o){return(r-A)*(t-o)>=(e-A)*(n-o)&&(e-A)*(s-o)>=(i-A)*(t-o)&&(i-A)*(n-o)>=(r-A)*(s-o)}function y(e,t,i,s,r,n,A,o){return!(e===A&&t===o)&&B(e,t,i,s,r,n,A,o)}function w(e,t){return e.next.i!==t.i&&e.prev.i!==t.i&&!function(e,t){let i=e;do{if(i.i!==e.i&&i.next.i!==e.i&&i.i!==t.i&&i.next.i!==t.i&&M(i,i.next,e,t))return!0;i=i.next}while(i!==e);return!1}(e,t)&&(U(e,t)&&U(t,e)&&function(e,t){let i=e,s=!1;const r=(e.x+t.x)/2,n=(e.y+t.y)/2;do{i.y>n!=i.next.y>n&&i.next.y!==i.y&&r<(i.next.x-i.x)*(n-i.y)/(i.next.y-i.y)+i.x&&(s=!s),i=i.next}while(i!==e);return s}(e,t)&&(v(e.prev,e,t.prev)||v(e,t.prev,t))||C(e,t)&&v(e.prev,e,e.next)>0&&v(t.prev,t,t.next)>0)}function v(e,t,i){return(t.y-e.y)*(i.x-t.x)-(t.x-e.x)*(i.y-t.y)}function C(e,t){return e.x===t.x&&e.y===t.y}function M(e,t,i,s){const r=F(v(e,t,i)),n=F(v(e,t,s)),A=F(v(i,s,e)),o=F(v(i,s,t));return r!==n&&A!==o||(!(0!==r||!E(e,i,t))||(!(0!==n||!E(e,s,t))||(!(0!==A||!E(i,e,s))||!(0!==o||!E(i,t,s)))))}function E(e,t,i){return t.x<=Math.max(e.x,i.x)&&t.x>=Math.min(e.x,i.x)&&t.y<=Math.max(e.y,i.y)&&t.y>=Math.min(e.y,i.y)}function F(e){return e>0?1:e<0?-1:0}function U(e,t){return v(e.prev,e,e.next)<0?v(e,t,e.next)>=0&&v(e,e.prev,t)>=0:v(e,t,e.prev)<0||v(e,e.next,t)<0}function x(e,t){const i=P(e.i,e.x,e.y),s=P(t.i,t.x,t.y),r=e.next,n=t.prev;return e.next=t,t.prev=e,i.next=r,r.prev=i,s.next=i,i.prev=s,n.next=s,s.prev=n,s}function I(e,t,i,s){const r=P(e,t,i);return s?(r.next=s.next,r.prev=s,s.next.prev=r,s.next=r):(r.prev=r,r.next=r),r}function T(e){e.next.prev=e.prev,e.prev.next=e.next,e.prevZ&&(e.prevZ.nextZ=e.nextZ),e.nextZ&&(e.nextZ.prevZ=e.prevZ)}function P(e,t,i){return{i:e,x:t,y:i,prev:null,next:null,z:0,prevZ:null,nextZ:null,steiner:!1}}let S=!0,D=S?Float64Array:Float32Array;const k=new D(3),Q=new D(16),R=new D(16),O=new D(4),V={setDoublePrecisionEnabled(e){S=e,D=S?Float64Array:Float32Array},getDoublePrecisionEnabled:()=>S,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 D(e||2),vec3:e=>new D(e||3),vec4:e=>new D(e||4),mat3:e=>new D(e||9),mat3ToMat4:(e,t=new D(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 D(e||16),mat4ToMat3:(e,t=new D(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 D(2);for(let r=0,n=e.length;r<n;r++)V.splitDouble(e[r],s),t[r]=s[0],i[r]=s[1]},splitDouble(e,t){const i=D.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 D(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],n=t[0],A=t[1],o=t[2];return[s*o-r*A,r*n-i*o,i*A-s*n,0]},cross3Vec3(e,t,i){i||(i=e);const s=e[0],r=e[1],n=e[2],A=t[0],o=t[1],a=t[2];return i[0]=r*a-n*o,i[1]=n*A-s*a,i[2]=s*o-r*A,i},sqLenVec4:e=>V.dotVec4(e,e),lenVec4:e=>Math.sqrt(V.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=>V.dotVec3(e,e),sqLenVec2:e=>V.dotVec2(e,e),lenVec3:e=>Math.sqrt(V.sqLenVec3(e)),distVec3:(()=>{const e=new D(3);return(t,i)=>V.lenVec3(V.subVec3(t,i,e))})(),lenVec2:e=>Math.sqrt(V.sqLenVec2(e)),distVec2:(()=>{const e=new D(2);return(t,i)=>V.lenVec2(V.subVec2(t,i,e))})(),rcpVec3:(e,t)=>V.divScalarVec3(1,e,t),normalizeVec4(e,t){const i=1/V.lenVec4(e);return V.mulVec4Scalar(e,i,t)},normalizeVec3(e,t){const i=1/V.lenVec3(e);return V.mulVec3Scalar(e,i,t)},normalizeVec2(e,t){const i=1/V.lenVec2(e);return V.mulVec2Scalar(e,i,t)},angleVec3(e,t){let i=V.dotVec3(e,t)/Math.sqrt(V.sqLenVec3(e)*V.sqLenVec3(t));return i=i<-1?-1:i>1?1:i,Math.acos(i)},vec3FromMat4Scale:(()=>{const e=new D(3);return(t,i)=>(e[0]=t[0],e[1]=t[1],e[2]=t[2],i[0]=V.lenVec3(e),e[0]=t[4],e[1]=t[5],e[2]=t[6],i[1]=V.lenVec3(e),e[0]=t[8],e[1]=t[9],e[2]=t[10],i[2]=V.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||V.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:()=>V.m4s(0),setMat4ToOnes:()=>V.m4s(1),diagonalMat4v:e=>new D([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)=>V.diagonalMat4v([e,t,i,s]),diagonalMat4s:e=>V.diagonalMat4c(e,e,e,e),identityMat4:(e=new D(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 D(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)=>V.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],n=e[2],A=e[3],o=e[4],a=e[5],l=e[6],c=e[7],h=e[8],u=e[9],d=e[10],f=e[11],p=e[12],g=e[13],m=e[14],_=e[15],b=t[0],B=t[1],y=t[2],w=t[3],v=t[4],C=t[5],M=t[6],E=t[7],F=t[8],U=t[9],x=t[10],I=t[11],T=t[12],P=t[13],S=t[14],D=t[15];return i[0]=b*s+B*o+y*h+w*p,i[1]=b*r+B*a+y*u+w*g,i[2]=b*n+B*l+y*d+w*m,i[3]=b*A+B*c+y*f+w*_,i[4]=v*s+C*o+M*h+E*p,i[5]=v*r+C*a+M*u+E*g,i[6]=v*n+C*l+M*d+E*m,i[7]=v*A+C*c+M*f+E*_,i[8]=F*s+U*o+x*h+I*p,i[9]=F*r+U*a+x*u+I*g,i[10]=F*n+U*l+x*d+I*m,i[11]=F*A+U*c+x*f+I*_,i[12]=T*s+P*o+S*h+D*p,i[13]=T*r+P*a+S*u+D*g,i[14]=T*n+P*l+S*d+D*m,i[15]=T*A+P*c+S*f+D*_,i},mulMat3(e,t,i){i||(i=new D(9));const s=e[0],r=e[3],n=e[6],A=e[1],o=e[4],a=e[7],l=e[2],c=e[5],h=e[8],u=t[0],d=t[3],f=t[6],p=t[1],g=t[4],m=t[7],_=t[2],b=t[5],B=t[8];return i[0]=s*u+r*p+n*_,i[3]=s*d+r*g+n*b,i[6]=s*f+r*m+n*B,i[1]=A*u+o*p+a*_,i[4]=A*d+o*g+a*b,i[7]=A*f+o*m+a*B,i[2]=l*u+c*p+h*_,i[5]=l*d+c*g+h*b,i[8]=l*f+c*m+h*B,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=V.vec4()){const s=t[0],r=t[1],n=t[2],A=t[3];return i[0]=e[0]*s+e[4]*r+e[8]*n+e[12]*A,i[1]=e[1]*s+e[5]*r+e[9]*n+e[13]*A,i[2]=e[2]*s+e[6]*r+e[10]*n+e[14]*A,i[3]=e[3]*s+e[7]*r+e[11]*n+e[15]*A,i},transposeMat4(e,t){const i=e[4],s=e[14],r=e[8],n=e[13],A=e[12],o=e[9];if(!t||e===t){const t=e[1],a=e[2],l=e[3],c=e[6],h=e[7],u=e[11];return e[1]=i,e[2]=r,e[3]=A,e[4]=t,e[6]=o,e[7]=n,e[8]=a,e[9]=c,e[11]=s,e[12]=l,e[13]=h,e[14]=u,e}return t[0]=e[0],t[1]=i,t[2]=r,t[3]=A,t[4]=e[1],t[5]=e[5],t[6]=o,t[7]=n,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],n=e[4],A=e[5],o=e[6],a=e[7],l=e[8],c=e[9],h=e[10],u=e[11],d=e[12],f=e[13],p=e[14],g=e[15];return d*c*o*r-l*f*o*r-d*A*h*r+n*f*h*r+l*A*p*r-n*c*p*r-d*c*s*a+l*f*s*a+d*i*h*a-t*f*h*a-l*i*p*a+t*c*p*a+d*A*s*u-n*f*s*u-d*i*o*u+t*f*o*u+n*i*p*u-t*A*p*u-l*A*s*g+n*c*s*g+l*i*o*g-t*c*o*g-n*i*h*g+t*A*h*g},inverseMat4(e,t){t||(t=e);const i=e[0],s=e[1],r=e[2],n=e[3],A=e[4],o=e[5],a=e[6],l=e[7],c=e[8],h=e[9],u=e[10],d=e[11],f=e[12],p=e[13],g=e[14],m=e[15],_=i*o-s*A,b=i*a-r*A,B=i*l-n*A,y=s*a-r*o,w=s*l-n*o,v=r*l-n*a,C=c*p-h*f,M=c*g-u*f,E=c*m-d*f,F=h*g-u*p,U=h*m-d*p,x=u*m-d*g,I=1/(_*x-b*U+B*F+y*E-w*M+v*C);return t[0]=(o*x-a*U+l*F)*I,t[1]=(-s*x+r*U-n*F)*I,t[2]=(p*v-g*w+m*y)*I,t[3]=(-h*v+u*w-d*y)*I,t[4]=(-A*x+a*E-l*M)*I,t[5]=(i*x-r*E+n*M)*I,t[6]=(-f*v+g*B-m*b)*I,t[7]=(c*v-u*B+d*b)*I,t[8]=(A*U-o*E+l*C)*I,t[9]=(-i*U+s*E-n*C)*I,t[10]=(f*w-p*B+m*_)*I,t[11]=(-c*w+h*B-d*_)*I,t[12]=(-A*F+o*M-a*C)*I,t[13]=(i*F-s*M+r*C)*I,t[14]=(-f*y+p*b-g*_)*I,t[15]=(c*y-h*b+u*_)*I,t},traceMat4:e=>e[0]+e[5]+e[10]+e[15],translationMat4v(e,t){const i=t||V.identityMat4();return i[12]=e[0],i[13]=e[1],i[14]=e[2],i},translationMat3v(e,t){const i=t||V.identityMat3();return i[6]=e[0],i[7]=e[1],i},translationMat4c:(()=>{const e=new D(3);return(t,i,s,r)=>(e[0]=t,e[1]=i,e[2]=s,V.translationMat4v(e,r))})(),translationMat4s:(e,t)=>V.translationMat4c(e,e,e,t),translateMat4v:(e,t)=>V.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 n=s[7];s[4]+=n*e,s[5]+=n*t,s[6]+=n*i;const A=s[11];s[8]+=A*e,s[9]+=A*t,s[10]+=A*i;const o=s[15];return s[12]+=o*e,s[13]+=o*t,s[14]+=o*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=V.normalizeVec4([t[0],t[1],t[2],0],[]),r=Math.sin(e),n=Math.cos(e),A=1-n,o=s[0],a=s[1],l=s[2];let c,h,u,d,f,p;return c=o*a,h=a*l,u=l*o,d=o*r,f=a*r,p=l*r,(i=i||V.mat4())[0]=A*o*o+n,i[1]=A*c+p,i[2]=A*u-f,i[3]=0,i[4]=A*c-p,i[5]=A*a*a+n,i[6]=A*h+d,i[7]=0,i[8]=A*u+f,i[9]=A*h-d,i[10]=A*l*l+n,i[11]=0,i[12]=0,i[13]=0,i[14]=0,i[15]=1,i},rotationMat4c:(e,t,i,s,r)=>V.rotationMat4v(e,[t,i,s],r),scalingMat4v:(e,t=V.identityMat4())=>(t[0]=e[0],t[5]=e[1],t[10]=e[2],t),scalingMat3v:(e,t=V.identityMat3())=>(t[0]=e[0],t[4]=e[1],t),scalingMat4c:(()=>{const e=new D(3);return(t,i,s,r)=>(e[0]=t,e[1]=i,e[2]=s,V.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=>V.scalingMat4c(e,e,e),rotationTranslationMat4(e,t,i=V.mat4()){const s=e[0],r=e[1],n=e[2],A=e[3],o=s+s,a=r+r,l=n+n,c=s*o,h=s*a,u=s*l,d=r*a,f=r*l,p=n*l,g=A*o,m=A*a,_=A*l;return i[0]=1-(d+p),i[1]=h+_,i[2]=u-m,i[3]=0,i[4]=h-_,i[5]=1-(c+p),i[6]=f+g,i[7]=0,i[8]=u+m,i[9]=f-g,i[10]=1-(c+d),i[11]=0,i[12]=t[0],i[13]=t[1],i[14]=t[2],i[15]=1,i},mat4ToEuler(e,t,i=V.vec4()){const s=V.clamp,r=e[0],n=e[4],A=e[8],o=e[1],a=e[5],l=e[9],c=e[2],h=e[6],u=e[10];return"XYZ"===t?(i[1]=Math.asin(s(A,-1,1)),Math.abs(A)<.99999?(i[0]=Math.atan2(-l,u),i[2]=Math.atan2(-n,r)):(i[0]=Math.atan2(h,a),i[2]=0)):"YXZ"===t?(i[0]=Math.asin(-s(l,-1,1)),Math.abs(l)<.99999?(i[1]=Math.atan2(A,u),i[2]=Math.atan2(o,a)):(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(-n,a)):(i[1]=0,i[2]=Math.atan2(o,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(o,r)):(i[0]=0,i[2]=Math.atan2(-n,a))):"YZX"===t?(i[2]=Math.asin(s(o,-1,1)),Math.abs(o)<.99999?(i[0]=Math.atan2(-l,a),i[1]=Math.atan2(-c,r)):(i[0]=0,i[1]=Math.atan2(A,u))):"XZY"===t&&(i[2]=Math.asin(-s(n,-1,1)),Math.abs(n)<.99999?(i[0]=Math.atan2(h,a),i[1]=Math.atan2(A,r)):(i[0]=Math.atan2(-l,u),i[1]=0)),i[0]*=V.RADTODEG,i[1]*=V.RADTODEG,i[2]*=V.RADTODEG,i},composeMat4:(e,t,i,s=V.mat4())=>(V.quaternionToRotationMat4(t,s),V.scaleMat4v(i,s),V.translateMat4v(e,s),s),decomposeMat4:(()=>{const e=new D(3),t=new D(16);return function(i,s,r,n){e[0]=i[0],e[1]=i[1],e[2]=i[2];let A=V.lenVec3(e);e[0]=i[4],e[1]=i[5],e[2]=i[6];const o=V.lenVec3(e);e[8]=i[8],e[9]=i[9],e[10]=i[10];const a=V.lenVec3(e);V.determinantMat4(i)<0&&(A=-A),s[0]=i[12],s[1]=i[13],s[2]=i[14],t.set(i);const l=1/A,c=1/o,h=1/a;return t[0]*=l,t[1]*=l,t[2]*=l,t[4]*=c,t[5]*=c,t[6]*=c,t[8]*=h,t[9]*=h,t[10]*=h,V.mat4ToQuaternion(t,r),n[0]=A,n[1]=o,n[2]=a,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=V.mat4());const r=e[0],n=e[1],A=e[2],o=i[0],a=i[1],l=i[2],c=t[0],h=t[1],u=t[2];if(r===c&&n===h&&A===u)return V.identityMat4();let d,f,p,g,m,_,b,B,y,w;return d=r-c,f=n-h,p=A-u,w=1/Math.sqrt(d*d+f*f+p*p),d*=w,f*=w,p*=w,g=a*p-l*f,m=l*d-o*p,_=o*f-a*d,w=Math.sqrt(g*g+m*m+_*_),w?(w=1/w,g*=w,m*=w,_*=w):(g=0,m=0,_=0),b=f*_-p*m,B=p*g-d*_,y=d*m-f*g,w=Math.sqrt(b*b+B*B+y*y),w?(w=1/w,b*=w,B*=w,y*=w):(b=0,B=0,y=0),s[0]=g,s[1]=b,s[2]=d,s[3]=0,s[4]=m,s[5]=B,s[6]=f,s[7]=0,s[8]=_,s[9]=y,s[10]=p,s[11]=0,s[12]=-(g*r+m*n+_*A),s[13]=-(b*r+B*n+y*A),s[14]=-(d*r+f*n+p*A),s[15]=1,s},lookAtMat4c:(e,t,i,s,r,n,A,o,a)=>V.lookAtMat4v([e,t,i],[s,r,n],[A,o,a],[]),orthoMat4c(e,t,i,s,r,n,A){A||(A=V.mat4());const o=t-e,a=s-i,l=n-r;return A[0]=2/o,A[1]=0,A[2]=0,A[3]=0,A[4]=0,A[5]=2/a,A[6]=0,A[7]=0,A[8]=0,A[9]=0,A[10]=-2/l,A[11]=0,A[12]=-(e+t)/o,A[13]=-(s+i)/a,A[14]=-(n+r)/l,A[15]=1,A},frustumMat4v(e,t,i){i||(i=V.mat4());const s=[e[0],e[1],e[2],0],r=[t[0],t[1],t[2],0];V.addVec4(r,s,Q),V.subVec4(r,s,R);const n=2*s[2],A=R[0],o=R[1],a=R[2];return i[0]=n/A,i[1]=0,i[2]=0,i[3]=0,i[4]=0,i[5]=n/o,i[6]=0,i[7]=0,i[8]=Q[0]/A,i[9]=Q[1]/o,i[10]=-Q[2]/a,i[11]=-1,i[12]=0,i[13]=0,i[14]=-n*r[2]/a,i[15]=0,i},frustumMat4(e,t,i,s,r,n,A){A||(A=V.mat4());const o=t-e,a=s-i,l=n-r;return A[0]=2*r/o,A[1]=0,A[2]=0,A[3]=0,A[4]=0,A[5]=2*r/a,A[6]=0,A[7]=0,A[8]=(t+e)/o,A[9]=(s+i)/a,A[10]=-(n+r)/l,A[11]=-1,A[12]=0,A[13]=0,A[14]=-n*r*2/l,A[15]=0,A},perspectiveMat4(e,t,i,s,r){const n=[],A=[];return n[2]=i,A[2]=s,A[1]=n[2]*Math.tan(e/2),n[1]=-A[1],A[0]=A[1]*t,n[0]=-A[0],V.frustumMat4v(n,A,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=V.vec3()){const s=t[0],r=t[1],n=t[2];return i[0]=e[0]*s+e[4]*r+e[8]*n+e[12],i[1]=e[1]*s+e[5]*r+e[9]*n+e[13],i[2]=e[2]*s+e[6]*r+e[10]*n+e[14],i},transformPoint4:(e,t,i=V.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 n,A,o,a;const l=e[0],c=e[1],h=e[2],u=e[3],d=e[4],f=e[5],p=e[6],g=e[7],m=e[8],_=e[9],b=e[10],B=e[11],y=e[12],w=e[13],v=e[14],C=e[15];let M;for(let e=0;e<r;++e)a=t[e],n=a[0],A=a[1],o=a[2],M=s[e]||(s[e]=[0,0,0]),M[0]=l*n+d*A+m*o+y,M[1]=c*n+f*A+_*o+w,M[2]=h*n+p*A+b*o+v,M[3]=u*n+g*A+B*o+C;return s.length=r,s},transformPositions3(e,t,i=t){let s;const r=t.length;let n,A,o;const a=e[0],l=e[1],c=e[2];e[3];const h=e[4],u=e[5],d=e[6];e[7];const f=e[8],p=e[9],g=e[10];e[11];const m=e[12],_=e[13],b=e[14];for(e[15],s=0;s<r;s+=3)n=t[s+0],A=t[s+1],o=t[s+2],i[s+0]=a*n+h*A+f*o+m,i[s+1]=l*n+u*A+p*o+_,i[s+2]=c*n+d*A+g*o+b;return i},transformPositions4(e,t,i=t){let s;const r=t.length;let n,A,o;const a=e[0],l=e[1],c=e[2],h=e[3],u=e[4],d=e[5],f=e[6],p=e[7],g=e[8],m=e[9],_=e[10],b=e[11],B=e[12],y=e[13],w=e[14],v=e[15];for(s=0;s<r;s+=4)n=t[s+0],A=t[s+1],o=t[s+2],i[s+0]=a*n+u*A+g*o+B,i[s+1]=l*n+d*A+m*o+y,i[s+2]=c*n+f*A+_*o+w,i[s+3]=h*n+p*A+b*o+v;return i},transformVec3(e,t,i){const s=t[0],r=t[1],n=t[2];return(i=i||this.vec3())[0]=e[0]*s+e[4]*r+e[8]*n,i[1]=e[1]*s+e[5]*r+e[9]*n,i[2]=e[2]*s+e[6]*r+e[10]*n,i},transformVec4(e,t,i){const s=t[0],r=t[1],n=t[2],A=t[3];return(i=i||V.vec4())[0]=e[0]*s+e[4]*r+e[8]*n+e[12]*A,i[1]=e[1]*s+e[5]*r+e[9]*n+e[13]*A,i[2]=e[2]*s+e[6]*r+e[10]*n+e[14]*A,i[3]=e[3]*s+e[7]*r+e[11]*n+e[15]*A,i},rotateVec2(e,t,i,s=e){const r=Math.cos(i),n=Math.sin(i),A=e[0]-t[0],o=e[1]-t[1];return s[0]=A*r-o*n+t[0],s[1]=A*n+o*r+t[1],e},rotateVec3X(e,t,i,s){const r=[],n=[];return r[0]=e[0]-t[0],r[1]=e[1]-t[1],r[2]=e[2]-t[2],n[0]=r[0],n[1]=r[1]*Math.cos(i)-r[2]*Math.sin(i),n[2]=r[1]*Math.sin(i)+r[2]*Math.cos(i),s[0]=n[0]+t[0],s[1]=n[1]+t[1],s[2]=n[2]+t[2],s},rotateVec3Y(e,t,i,s){const r=[],n=[];return r[0]=e[0]-t[0],r[1]=e[1]-t[1],r[2]=e[2]-t[2],n[0]=r[2]*Math.sin(i)+r[0]*Math.cos(i),n[1]=r[1],n[2]=r[2]*Math.cos(i)-r[0]*Math.sin(i),s[0]=n[0]+t[0],s[1]=n[1]+t[1],s[2]=n[2]+t[2],s},rotateVec3Z(e,t,i,s){const r=[],n=[];return r[0]=e[0]-t[0],r[1]=e[1]-t[1],r[2]=e[2]-t[2],n[0]=r[0]*Math.cos(i)-r[1]*Math.sin(i),n[1]=r[0]*Math.sin(i)+r[1]*Math.cos(i),n[2]=r[2],s[0]=n[0]+t[0],s[1]=n[1]+t[1],s[2]=n[2]+t[2],s},projectVec4(e,t){const i=1/e[3];return(t=t||V.vec2())[0]=e[0]*i,t[1]=e[1]*i,t},unprojectVec3:(()=>{const e=new D(16),t=new D(16),i=new D(16);return function(s,r,n,A){return this.transformVec3(this.mulMat4(this.inverseMat4(r,e),this.inverseMat4(n,t),i),s,A)}})(),lerpVec3(e,t,i,s,r,n){const A=n||V.vec3(),o=(e-t)/(i-t);return A[0]=s[0]+o*(r[0]-s[0]),A[1]=s[1]+o*(r[1]-s[1]),A[2]=s[2]+o*(r[2]-s[2]),A},lerpMat4(e,t,i,s,r,n){const A=n||V.mat4(),o=(e-t)/(i-t);return A[0]=s[0]+o*(r[0]-s[0]),A[1]=s[1]+o*(r[1]-s[1]),A[2]=s[2]+o*(r[2]-s[2]),A[3]=s[3]+o*(r[3]-s[3]),A[4]=s[4]+o*(r[4]-s[4]),A[5]=s[5]+o*(r[5]-s[5]),A[6]=s[6]+o*(r[6]-s[6]),A[7]=s[7]+o*(r[7]-s[7]),A[8]=s[8]+o*(r[8]-s[8]),A[9]=s[9]+o*(r[9]-s[9]),A[10]=s[10]+o*(r[10]-s[10]),A[11]=s[11]+o*(r[11]-s[11]),A[12]=s[12]+o*(r[12]-s[12]),A[13]=s[13]+o*(r[13]-s[13]),A[14]=s[14]+o*(r[14]-s[14]),A[15]=s[15]+o*(r[15]-s[15]),A},flatten(e){const t=[];let i,s,r,n,A;for(i=0,s=e.length;i<s;i++)for(A=e[i],r=0,n=A.length;r<n;r++)t.push(A[r]);return t},identityQuaternion:(e=V.vec4())=>(e[0]=0,e[1]=0,e[2]=0,e[3]=1,e),eulerToQuaternion(e,t,i=V.vec4()){const s=e[0]*V.DEGTORAD/2,r=e[1]*V.DEGTORAD/2,n=e[2]*V.DEGTORAD/2,A=Math.cos(s),o=Math.cos(r),a=Math.cos(n),l=Math.sin(s),c=Math.sin(r),h=Math.sin(n);return"XYZ"===t?(i[0]=l*o*a+A*c*h,i[1]=A*c*a-l*o*h,i[2]=A*o*h+l*c*a,i[3]=A*o*a-l*c*h):"YXZ"===t?(i[0]=l*o*a+A*c*h,i[1]=A*c*a-l*o*h,i[2]=A*o*h-l*c*a,i[3]=A*o*a+l*c*h):"ZXY"===t?(i[0]=l*o*a-A*c*h,i[1]=A*c*a+l*o*h,i[2]=A*o*h+l*c*a,i[3]=A*o*a-l*c*h):"ZYX"===t?(i[0]=l*o*a-A*c*h,i[1]=A*c*a+l*o*h,i[2]=A*o*h-l*c*a,i[3]=A*o*a+l*c*h):"YZX"===t?(i[0]=l*o*a+A*c*h,i[1]=A*c*a+l*o*h,i[2]=A*o*h-l*c*a,i[3]=A*o*a-l*c*h):"XZY"===t&&(i[0]=l*o*a-A*c*h,i[1]=A*c*a-l*o*h,i[2]=A*o*h+l*c*a,i[3]=A*o*a+l*c*h),i},mat4ToQuaternion(e,t=V.vec4()){const i=e[0],s=e[4],r=e[8],n=e[1],A=e[5],o=e[9],a=e[2],l=e[6],c=e[10];let h;const u=i+A+c;return u>0?(h=.5/Math.sqrt(u+1),t[3]=.25/h,t[0]=(l-o)*h,t[1]=(r-a)*h,t[2]=(n-s)*h):i>A&&i>c?(h=2*Math.sqrt(1+i-A-c),t[3]=(l-o)/h,t[0]=.25*h,t[1]=(s+n)/h,t[2]=(r+a)/h):A>c?(h=2*Math.sqrt(1+A-i-c),t[3]=(r-a)/h,t[0]=(s+n)/h,t[1]=.25*h,t[2]=(o+l)/h):(h=2*Math.sqrt(1+c-i-A),t[3]=(n-s)/h,t[0]=(r+a)/h,t[1]=(o+l)/h,t[2]=.25*h),t},vec3PairToQuaternion(e,t,i=V.vec4()){const s=Math.sqrt(V.dotVec3(e,e)*V.dotVec3(t,t));let r=s+V.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])):V.cross3Vec3(e,t,i),i[3]=r,V.normalizeQuaternion(i)},angleAxisToQuaternion(e,t=V.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 D(16);return(t,i,s)=>(s=s||V.vec3(),V.quaternionToRotationMat4(t,e),V.mat4ToEuler(e,i,s),s)})(),mulQuaternions(e,t,i=V.vec4()){const s=e[0],r=e[1],n=e[2],A=e[3],o=t[0],a=t[1],l=t[2],c=t[3];return i[0]=A*o+s*c+r*l-n*a,i[1]=A*a+r*c+n*o-s*l,i[2]=A*l+n*c+s*a-r*o,i[3]=A*c-s*o-r*a-n*l,i},vec3ApplyQuaternion(e,t,i=V.vec3()){const s=t[0],r=t[1],n=t[2],A=e[0],o=e[1],a=e[2],l=e[3],c=l*s+o*n-a*r,h=l*r+a*s-A*n,u=l*n+A*r-o*s,d=-A*s-o*r-a*n;return i[0]=c*l+d*-A+h*-a-u*-o,i[1]=h*l+d*-o+u*-A-c*-a,i[2]=u*l+d*-a+c*-o-h*-A,i},quaternionToMat4(e,t){t=V.identityMat4(t);const i=e[0],s=e[1],r=e[2],n=e[3],A=2*i,o=2*s,a=2*r,l=A*n,c=o*n,h=a*n,u=A*i,d=o*i,f=a*i,p=o*s,g=a*s,m=a*r;return t[0]=1-(p+m),t[1]=d+h,t[2]=f-c,t[4]=d-h,t[5]=1-(u+m),t[6]=g+l,t[8]=f+c,t[9]=g-l,t[10]=1-(u+p),t},quaternionToRotationMat4(e,t){const i=e[0],s=e[1],r=e[2],n=e[3],A=i+i,o=s+s,a=r+r,l=i*A,c=i*o,h=i*a,u=s*o,d=s*a,f=r*a,p=n*A,g=n*o,m=n*a;return t[0]=1-(u+f),t[4]=c-m,t[8]=h+g,t[1]=c+m,t[5]=1-(l+f),t[9]=d-p,t[2]=h-g,t[6]=d+p,t[10]=1-(l+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=V.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)=>V.normalizeQuaternion(V.conjugateQuaternion(e,t)),quaternionToAngleAxis(e,t=V.vec4()){const i=(e=V.normalizeQuaternion(e,O))[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 D(e||6),AABB2:e=>new D(e||4),OBB3:e=>new D(e||32),OBB2:e=>new D(e||16),Sphere3:(e,t,i,s)=>new D([e,t,i,s]),transformOBB3(e,t,i=t){let s;const r=t.length;let n,A,o;const a=e[0],l=e[1],c=e[2],h=e[3],u=e[4],d=e[5],f=e[6],p=e[7],g=e[8],m=e[9],_=e[10],b=e[11],B=e[12],y=e[13],w=e[14],v=e[15];for(s=0;s<r;s+=4)n=t[s+0],A=t[s+1],o=t[s+2],i[s+0]=a*n+u*A+g*o+B,i[s+1]=l*n+d*A+m*o+y,i[s+2]=c*n+f*A+_*o+w,i[s+3]=h*n+p*A+b*o+v;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 D(3),t=new D(3),i=new D(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],V.subVec3(t,e,i),Math.abs(V.lenVec3(i)))})(),getAABB3DiagPoint:(()=>{const e=new D(3),t=new D(3),i=new D(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 n=V.subVec3(t,e,i),A=r[0]-s[0],o=s[3]-r[0],a=r[1]-s[1],l=s[4]-r[1],c=r[2]-s[2],h=s[5]-r[2];return n[0]+=A>o?A:o,n[1]+=a>l?a:l,n[2]+=c>h?c:h,Math.abs(V.lenVec3(n))}})(),getAABB3Area:e=>(e[3]-e[0])*(e[4]-e[1])*(e[5]-e[2]),getAABB3Center(e,t){const i=t||V.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||V.vec2();return i[0]=(e[2]+e[0])/2,i[1]=(e[3]+e[1])/2,i},collapseAABB3:(e=V.AABB3())=>(e[0]=V.MAX_DOUBLE,e[1]=V.MAX_DOUBLE,e[2]=V.MAX_DOUBLE,e[3]=V.MIN_DOUBLE,e[4]=V.MIN_DOUBLE,e[5]=V.MIN_DOUBLE,e),AABB3ToOBB3:(e,t=V.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 D(3);return(t,i,s)=>{i=i||V.AABB3();let r,n,A,o=V.MAX_DOUBLE,a=V.MAX_DOUBLE,l=V.MAX_DOUBLE,c=V.MIN_DOUBLE,h=V.MIN_DOUBLE,u=V.MIN_DOUBLE;for(let i=0,d=t.length;i<d;i+=3)s?(e[0]=t[i+0],e[1]=t[i+1],e[2]=t[i+2],V.decompressPosition(e,s,e),r=e[0],n=e[1],A=e[2]):(r=t[i+0],n=t[i+1],A=t[i+2]),r<o&&(o=r),n<a&&(a=n),A<l&&(l=A),r>c&&(c=r),n>h&&(h=n),A>u&&(u=A);return i[0]=o,i[1]=a,i[2]=l,i[3]=c,i[4]=h,i[5]=u,i}})(),OBB3ToAABB3(e,t=V.AABB3()){let i,s,r,n=V.MAX_DOUBLE,A=V.MAX_DOUBLE,o=V.MAX_DOUBLE,a=V.MIN_DOUBLE,l=V.MIN_DOUBLE,c=V.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<n&&(n=i),s<A&&(A=s),r<o&&(o=r),i>a&&(a=i),s>l&&(l=s),r>c&&(c=r);return t[0]=n,t[1]=A,t[2]=o,t[3]=a,t[4]=l,t[5]=c,t},points3ToAABB3(e,t=V.AABB3()){let i,s,r,n=V.MAX_DOUBLE,A=V.MAX_DOUBLE,o=V.MAX_DOUBLE,a=V.MIN_DOUBLE,l=V.MIN_DOUBLE,c=V.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<n&&(n=i),s<A&&(A=s),r<o&&(o=r),i>a&&(a=i),s>l&&(l=s),r>c&&(c=r);return t[0]=n,t[1]=A,t[2]=o,t[3]=a,t[4]=l,t[5]=c,t},points3ToSphere3:(()=>{const e=new D(3);return(t,i)=>{i=i||V.vec4();let s,r=0,n=0,A=0;const o=t.length;for(s=0;s<o;s++)r+=t[s][0],n+=t[s][1],A+=t[s][2];i[0]=r/o,i[1]=n/o,i[2]=A/o;let a,l=0;for(s=0;s<o;s++)a=Math.abs(V.lenVec3(V.subVec3(t[s],i,e))),a>l&&(l=a);return i[3]=l,i}})(),positions3ToSphere3:(()=>{const e=new D(3),t=new D(3);return(i,s)=>{s=s||V.vec4();let r,n=0,A=0,o=0;const a=i.length;let l=0;for(r=0;r<a;r+=3)n+=i[r],A+=i[r+1],o+=i[r+2];const c=a/3;let h;for(s[0]=n/c,s[1]=A/c,s[2]=o/c,r=0;r<a;r+=3)e[0]=i[r],e[1]=i[r+1],e[2]=i[r+2],h=Math.abs(V.lenVec3(V.subVec3(e,s,t))),h>l&&(l=h);return s[3]=l,s}})(),OBB3ToSphere3:(()=>{const e=new D(3),t=new D(3);return(i,s)=>{s=s||V.vec4();let r,n=0,A=0,o=0;const a=i.length,l=a/4;for(r=0;r<a;r+=4)n+=i[r+0],A+=i[r+1],o+=i[r+2];s[0]=n/l,s[1]=A/l,s[2]=o/l;let c,h=0;for(r=0;r<a;r+=4)e[0]=i[r+0],e[1]=i[r+1],e[2]=i[r+2],c=Math.abs(V.lenVec3(V.subVec3(e,s,t))),c>h&&(h=c);return s[3]=h,s}})(),getSphere3Center:(e,t=V.vec3())=>(t[0]=e[0],t[1]=e[1],t[2]=e[2],t),getPositionsCenter(e,t=V.vec3()){let i=0,s=0,r=0;for(var n=0,A=e.length;n<A;n+=3)i+=e[n+0],s+=e[n+1],r+=e[n+2];const o=e.length/3;return t[0]=i/o,t[1]=s/o,t[2]=r/o,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,n=0,A=t.length;n<A;n+=3)i=t[n],s=t[n+1],r=t[n+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=V.AABB2())=>(e[0]=V.MAX_DOUBLE,e[1]=V.MAX_DOUBLE,e[2]=V.MIN_DOUBLE,e[3]=V.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=V.AABB2()){let i,s,r,n,A=V.MAX_DOUBLE,o=V.MAX_DOUBLE,a=V.MIN_DOUBLE,l=V.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,n=1/r,i*=n,s*=n,i<A&&(A=i),s<o&&(o=s),i>a&&(a=i),s>l&&(l=s);return t[0]=A,t[1]=o,t[2]=a,t[3]=l,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),n=.5*(e[1]+1),A=.5*(e[2]+1),o=.5*(e[3]+1);return s[0]=Math.floor(r*t),s[1]=i-Math.floor(o*i),s[2]=Math.floor(A*t),s[3]=i-Math.floor(n*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 n=.5*(i-e),A=.5*(s-t),o=r*r;return(2*t-2*i+n+A)*(r*o)+(-3*t+3*i-2*n-A)*o+n*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=V.vec3()){const r=t[0]-e[0],n=t[1]-e[1],A=t[2]-e[2],o=i[0]-e[0],a=i[1]-e[1],l=i[2]-e[2],c=n*l-A*a,h=A*o-r*l,u=r*a-n*o,d=Math.sqrt(c*c+h*h+u*u);return 0===d?(s[0]=0,s[1]=0,s[2]=0):(s[0]=c/d,s[1]=h/d,s[2]=u/d),s},rayTriangleIntersect:(()=>{const e=new D(3),t=new D(3),i=new D(3),s=new D(3),r=new D(3);return(n,A,o,a,l,c)=>{c=c||V.vec3();const h=V.subVec3(a,o,e),u=V.subVec3(l,o,t),d=V.cross3Vec3(A,u,i),f=V.dotVec3(h,d);if(f<1e-6)return null;const p=V.subVec3(n,o,s),g=V.dotVec3(p,d);if(g<0||g>f)return null;const m=V.cross3Vec3(p,h,r),_=V.dotVec3(A,m);if(_<0||g+_>f)return null;const b=V.dotVec3(u,m)/f;return c[0]=n[0]+b*A[0],c[1]=n[1]+b*A[1],c[2]=n[2]+b*A[2],c}})(),rayPlaneIntersect:(()=>{const e=new D(3),t=new D(3),i=new D(3),s=new D(3);return(r,n,A,o,a,l)=>{l=l||V.vec3(),n=V.normalizeVec3(n,e);const c=V.subVec3(o,A,t),h=V.subVec3(a,A,i),u=V.cross3Vec3(c,h,s);V.normalizeVec3(u,u);const d=-V.dotVec3(A,u),f=-(V.dotVec3(r,u)+d)/V.dotVec3(n,u);return l[0]=r[0]+f*n[0],l[1]=r[1]+f*n[1],l[2]=r[2]+f*n[2],l}})(),cartesianToBarycentric:(()=>{const e=new D(3),t=new D(3),i=new D(3);return(s,r,n,A,o)=>{const a=V.subVec3(A,r,e),l=V.subVec3(n,r,t),c=V.subVec3(s,r,i),h=V.dotVec3(a,a),u=V.dotVec3(a,l),d=V.dotVec3(a,c),f=V.dotVec3(l,l),p=V.dotVec3(l,c),g=h*f-u*u;if(0===g)return null;const m=1/g,_=(f*d-u*p)*m,b=(h*p-u*d)*m;return o[0]=1-_-b,o[1]=b,o[2]=_,o}})(),barycentricInsideTriangle(e){const t=e[1],i=e[2];return i>=0&&t>=0&&i+t<1},barycentricToCartesian(e,t,i,s,r=V.vec3()){const n=e[0],A=e[1],o=e[2];return r[0]=t[0]*n+i[0]*A+s[0]*o,r[1]=t[1]*n+i[1]*A+s[1]*o,r[2]=t[2]*n+i[2]*A+s[2]*o,r},mergeVertices(e,t,i,s){const r={},n=[],A=[],o=t?[]:null,a=i?[]:null,l=[];let c,h,u,d;const f=1e4;let p,g,m=0;for(p=0,g=e.length;p<g;p+=3)c=e[p],h=e[p+1],u=e[p+2],d=`${Math.round(c*f)}_${Math.round(h*f)}_${Math.round(u*f)}`,void 0===r[d]&&(r[d]=A.length/3,A.push(c),A.push(h),A.push(u),t&&(o.push(t[p]),o.push(t[p+1]),o.push(t[p+2])),i&&(a.push(i[m]),a.push(i[m+1]))),n[p/3]=r[d],m+=2;for(p=0,g=s.length;p<g;p++)l[p]=n[s[p]];const _={positions:A,indices:l};return o&&(_.normals=o),a&&(_.uv=a),_},buildNormals:(()=>{const e=new D(3),t=new D(3),i=new D(3),s=new D(3),r=new D(3),n=new D(3);return(A,o,a)=>{let l,c;const h=new Array(A.length/3);let u,d,f,p,g,m,_;for(l=0,c=o.length;l<c;l+=3){u=o[l],d=o[l+1],f=o[l+2],e[0]=A[3*u],e[1]=A[3*u+1],e[2]=A[3*u+2],t[0]=A[3*d],t[1]=A[3*d+1],t[2]=A[3*d+2],i[0]=A[3*f],i[1]=A[3*f+1],i[2]=A[3*f+2],V.subVec3(t,e,s),V.subVec3(i,e,r);const a=V.vec3();V.normalizeVec3(V.cross3Vec3(s,r,n),a),h[u]||(h[u]=[]),h[d]||(h[d]=[]),h[f]||(h[f]=[]),h[u].push(a),h[d].push(a),h[f].push(a)}for(a=a&&a.length===A.length?a:new Float32Array(A.length),l=0,c=h.length;l<c;l++){p=h[l].length,g=0,m=0,_=0;for(let e=0;e<p;e++)g+=h[l][e][0],m+=h[l][e][1],_+=h[l][e][2];a[3*l]=g/p,a[3*l+1]=m/p,a[3*l+2]=_/p}return a}})(),buildTangents:(()=>{const e=new D(3),t=new D(3),i=new D(3),s=new D(3),r=new D(3),n=new D(3),A=new D(3);return(o,a,l)=>{const c=new Float32Array(o.length);for(let h=0;h<a.length;h+=3){let u=a[h];const d=o.subarray(3*u,3*u+3),f=l.subarray(2*u,2*u+2);u=a[h+1];const p=o.subarray(3*u,3*u+3),g=l.subarray(2*u,2*u+2);u=a[h+2];const m=o.subarray(3*u,3*u+3),_=l.subarray(2*u,2*u+2),b=V.subVec3(p,d,e),B=V.subVec3(m,d,t),y=V.subVec2(g,f,i),w=V.subVec2(_,f,s),v=1/(y[0]*w[1]-y[1]*w[0]),C=V.mulVec3Scalar(V.subVec3(V.mulVec3Scalar(b,w[1],r),V.mulVec3Scalar(B,y[1],n),A),v,n);let M;for(let e=0;e<3;e++)M=3*a[h+e],c[M]+=C[0],c[M+1]+=C[1],c[M+2]+=C[2]}return c}})(),buildPickTriangles(e,t,i){const s=t.length,r=i?new Uint16Array(9*s):new Float32Array(9*s),n=new Uint8Array(12*s);let A,o,a,l,c,h,u=0,d=0,f=0;for(let i=0;i<s;i+=3)h=u>>24&255,c=u>>16&255,l=u>>8&255,a=255&u,o=t[i],A=3*o,r[d++]=e[A],r[d++]=e[A+1],r[d++]=e[A+2],n[f++]=a,n[f++]=l,n[f++]=c,n[f++]=h,o=t[i+1],A=3*o,r[d++]=e[A],r[d++]=e[A+1],r[d++]=e[A+2],n[f++]=a,n[f++]=l,n[f++]=c,n[f++]=h,o=t[i+2],A=3*o,r[d++]=e[A],r[d++]=e[A+1],r[d++]=e[A+2],n[f++]=a,n[f++]=l,n[f++]=c,n[f++]=h,u++;return{positions:r,colors:n}},faceToVertexNormals(e,t,i={}){const s=i.smoothNormalsAngleThreshold||20,r={},n=[],A={};let o,a,l,c,h;const u=1e4;let d,f,p,g,m,_;for(f=0,g=e.length;f<g;f+=3){d=f/3,a=e[f],l=e[f+1],c=e[f+2],h=`${Math.round(a*u)}_${Math.round(l*u)}_${Math.round(c*u)}`,void 0===r[h]?r[h]=[d]:r[h].push(d);const i=V.normalizeVec3([t[f],t[f+1],t[f+2]]);n[d]=i,o=V.vec4([i[0],i[1],i[2],1]),A[d]=o}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(o=A[i],p=0;p<t;p++){if(f===p)continue;const t=e[p];m=n[i],_=n[t];Math.abs(V.angleVec3(m,_)/V.DEGTORAD)<s&&(o[0]+=_[0],o[1]+=_[1],o[2]+=_[2],o[3]+=1)}}}for(f=0,g=t.length;f<g;f+=3)o=A[f/3],t[f+0]=o[0]/o[3],t[f+1]=o[1]/o[3],t[f+2]=o[2]/o[3]},transformRay:(()=>{const e=new D(4),t=new D(4);return(i,s,r,n,A)=>{e[0]=s[0],e[1]=s[1],e[2]=s[2],e[3]=1,V.transformVec4(i,e,t),n[0]=t[0],n[1]=t[1],n[2]=t[2],e[0]=r[0],e[1]=r[1],e[2]=r[2],V.transformVec3(i,e,t),V.normalizeVec3(t),A[0]=t[0],A[1]=t[1],A[2]=t[2]}})(),canvasPosToWorldRay:(()=>{const e=new D(16),t=new D(4),i=new D(4),s=(t,i,s,r,n)=>{n[0]=t,n[1]=i,n[2]=s,n[3]=1,V.transformVec4(e,n,n),r||V.mulVec4Scalar(n,1/n[3])};return(r,n,A,o,a,l,c)=>{const h="ortho"===o;V.mulMat4(A,n,e),V.inverseMat4(e,e);const u=2*a[0]/r.clientWidth-1,d=1-2*a[1]/r.clientHeight;s(u,d,-1,h,t),s(u,d,1,h,i),l[0]=t[0],l[1]=t[1],l[2]=t[2],V.subVec3(i,t,c),V.normalizeVec3(c)}})(),canvasPosToLocalRay:(()=>{const e=new D(3),t=new D(3);return(i,s,r,n,A,o,a,l)=>{V.canvasPosToWorldRay(i,s,r,n,o,e,t),V.worldRayToLocalRay(A,e,t,a,l)}})(),worldRayToLocalRay:(()=>{const e=new D(16),t=new D(4),i=new D(4);return(s,r,n,A,o)=>{const a=V.inverseMat4(s,e);t[0]=r[0],t[1]=r[1],t[2]=r[2],t[3]=1,V.transformVec4(a,t,i),A[0]=i[0],A[1]=i[1],A[2]=i[2],V.transformVec3(a,n,o)}})(),buildKDTree:(()=>{const e=new Float32Array;function t(i,s,r,n){const A=new D(6),o={triangles:null,left:null,right:null,leaf:!1,splitDim:0,aabb:A};let a,l;for(A[0]=A[1]=A[2]=Number.POSITIVE_INFINITY,A[3]=A[4]=A[5]=Number.NEGATIVE_INFINITY,a=0,l=i.length;a<l;++a){var c=3*i[a];for(let e=0;e<3;++e){const t=3*s[c+e];r[t]<A[0]&&(A[0]=r[t]),r[t]>A[3]&&(A[3]=r[t]),r[t+1]<A[1]&&(A[1]=r[t+1]),r[t+1]>A[4]&&(A[4]=r[t+1]),r[t+2]<A[2]&&(A[2]=r[t+2]),r[t+2]>A[5]&&(A[5]=r[t+2])}}if(i.length<20||n>10)return o.triangles=i,o.leaf=!0,o;e[0]=A[3]-A[0],e[1]=A[4]-A[1],e[2]=A[5]-A[2];let h=0;e[1]>e[h]&&(h=1),e[2]>e[h]&&(h=2),o.splitDim=h;const u=(A[h]+A[h+3])/2,d=new Array(i.length);let f=0;const p=new Array(i.length);let g=0;for(a=0,l=i.length;a<l;++a){const e=s[c=3*i[a]],t=3*s[c+1],n=3*s[c+2];r[3*e+h]<=u||r[t+h]<=u||r[n+h]<=u?d[f++]=i[a]:p[g++]=i[a]}return d.length=f,p.length=g,o.left=t(d,s,r,n+1),o.right=t(p,s,r,n+1),o}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 n=Math.sqrt(i*i+s*s+r*r);return t[0]=i/n,t[1]=s/n,t[2]=r/n,t},octDecodeVec2s(e,t){for(let i=0,s=0,r=e.length;i<r;i+=2){let r=e[i+0],n=e[i+1];r=(2*r+1)/255,n=(2*n+1)/255;const A=1-Math.abs(r)-Math.abs(n);A<0&&(r=(1-Math.abs(n))*(r>=0?1:-1),n=(1-Math.abs(r))*(n>=0?1:-1));const o=Math.sqrt(r*r+n*n+A*A);t[s+0]=r/o,t[s+1]=n/o,t[s+2]=A/o,s+=3}return t}};V.buildEdgeIndices=function(){const e=[],t=[],i=[],s=[],r=[];let n=0;const A=new Uint16Array(3),o=new Uint16Array(3),a=new Uint16Array(3),l=V.vec3(),c=V.vec3(),h=V.vec3(),u=V.vec3(),d=V.vec3(),f=V.vec3(),p=V.vec3();return function(g,m,_,b){!function(r,n){const A={};let o,a,l,c;const h=Math.pow(10,4);let u,d,f=0;for(u=0,d=r.length;u<d;u+=3)o=r[u],a=r[u+1],l=r[u+2],c=Math.round(o*h)+"_"+Math.round(a*h)+"_"+Math.round(l*h),void 0===A[c]&&(A[c]=f/3,e[f++]=o,e[f++]=a,e[f++]=l),t[u/3]=A[c];for(u=0,d=n.length;u<d;u++)s[u]=t[n[u]],i[s[u]]=n[u]}(g,m),function(t,i){n=0;for(let g=0,m=t;g<m;g+=3){const t=3*s[g],m=3*s[g+1],_=3*s[g+2];i?(A[0]=e[t],A[1]=e[t+1],A[2]=e[t+2],o[0]=e[m],o[1]=e[m+1],o[2]=e[m+2],a[0]=e[_],a[1]=e[_+1],a[2]=e[_+2],V.decompressPosition(A,i,l),V.decompressPosition(o,i,c),V.decompressPosition(a,i,h)):(l[0]=e[t],l[1]=e[t+1],l[2]=e[t+2],c[0]=e[m],c[1]=e[m+1],c[2]=e[m+2],h[0]=e[_],h[1]=e[_+1],h[2]=e[_+2]),V.subVec3(h,c,u),V.subVec3(l,c,d),V.cross3Vec3(u,d,f),V.normalizeVec3(f,p);const b=r[n]||(r[n]={normal:V.vec3()});b.normal[0]=p[0],b.normal[1]=p[1],b.normal[2]=p[2],n++}}(m.length,_);const B=[],y=Math.cos(V.DEGTORAD*b),w={};let v,C,M,E,F,U,x,I,T,P,S,D=!1;for(let e=0,t=m.length;e<t;e+=3){const t=e/3;for(let i=0;i<3;i++)v=s[e+i],C=s[e+(i+1)%3],M=Math.min(v,C),E=Math.max(v,C),F=M+","+E,void 0===w[F]?w[F]={index1:M,index2:E,face1:t,face2:void 0}:w[F].face2=t}for(F in w)U=w[F],void 0!==U.face2&&(x=r[U.face1].normal,I=r[U.face2].normal,T=V.dotVec3(x,I),T>y)||(P=i[U.index1],S=i[U.index2],(!D&&P>65535||S>65535)&&(D=!0),B.push(P),B.push(S));return D?new Uint32Array(B):new Uint16Array(B)}}(),V.planeClipsPositions3=function(e,t,i,s=3){for(let r=0,n=i.length;r<n;r+=s){if(k[0]=i[r+0]-e[0],k[1]=i[r+1]-e[1],k[2]=i[r+2]-e[2],k[0]*t[0]+k[1]*t[1]+k[2]*t[2]<0)return!0}return!1},V.planeIntersectsAABB3=(e,t)=>{const i=[t[0],t[1],t[2]],s=[t[3],t[4],t[5]],r=[[i[0],i[1],i[2]],[s[0],i[1],i[2]],[i[0],s[1],i[2]],[s[0],s[1],i[2]],[i[0],i[1],s[2]],[s[0],i[1],s[2]],[i[0],s[1],s[2]],[s[0],s[1],s[2]]];let n=!1,A=!1;for(const t of r){const i=e.dist+V.dotVec3(e.dir,t);if(i>0&&(n=!0),i<0&&(A=!0),n&&A)return!0}return!1},V.makeSectionPlaneSlicer=function(){const e=V.vec2(),t=V.vec2(),i=V.vec2(),s=V.vec2(),r=V.vec3(),n=V.vec3(),A=V.vec3();V.vec3();const a=[V.vec3(),V.vec3(),V.vec3()],l=[null,null,null],c=[null,null,null],h=[null,null,null],u=[1,0,0],d=[0,1,0],f=[0,0,1],p=function(){const e=V.vec3();return(t,i)=>V.sqLenVec3(V.subVec3(t,i,e))}(),g=e=>{const t=[];for(let i=0;i<e;++i)t.push(i);return t},m=(e,t,i)=>(i[1]-e[1])*(t[0]-e[0])>(t[1]-e[1])*(i[0]-e[0]);return function(_){const b=V.vec3ApplyQuaternion(_.quaternion,u,V.vec3()),B=V.vec3ApplyQuaternion(_.quaternion,d,V.vec3()),y=V.vec3ApplyQuaternion(_.quaternion,f,V.vec3());return function(u,d={}){const f=V.subVec3(u.origin,_.pos,V.vec3()),w=V.dotVec3(y,f),v=[],C=[null],M=(e,t)=>{const i=C.length,s=new Float64Array(5);return s.set(e),t&&(V.addVec3(f,e,r),s[3]=-V.dotVec3(b,r),s[4]=V.dotVec3(B,r)),C.push(s),i},E=(e,t)=>{const i=C[e];return t[0]=i[3],t[1]=i[4],t},F=(r,n)=>{const A=r.boundingBox,o=n.boundingBox;if(A[0]<o[0]||A[1]<o[1]||A[2]>o[2]||A[3]>o[3])return!1;const a=r.endPoints,l=n.endPoints;for(let r=0,n=a.length-1;r<a.length;n=r++){const A=E(a[r],e),[o,c]=A,h=E(a[n],t);let u=!1;for(let e=0,t=l.length-1;e<l.length;t=e++){const r=E(l[e],i),n=E(l[t],s);if(m(A,r,n)!==m(h,r,n)&&m(A,h,r)!==m(A,h,n))return!1;const[a,d]=r,[f,p]=n,g=o-a,_=c-d,b=f-a,B=p-d,y=(0!==b||0!==B)&&Math.abs(b*_-B*g)<1e-10?g*b+_*B:-1;if(y>=0&&y<=Math.pow(b,2)+Math.pow(B,2))return!1;d>c!=p>c&&g<_*b/B&&(u=!u)}if(!u)return!1}return!0},U={indices:[],normals:[]},x=!d.onlyPosSliceWithUV&&{indices:[],normals:[]},I=(e,t,i)=>{if(e){const s=C[t[0]];i||=V.normalizeVec3(V.cross3Vec3(V.subVec3(C[t[1]],s,r),V.subVec3(C[t[2]],s,n),r),r);for(let s=0;s<3;++s)e.indices.push(t[s]),e.normals.push(i[0],i[1],i[2])}},T=(e,t)=>{const i=3*u.indices[e];return t[0]=u.positions[i+0],t[1]=u.positions[i+1],t[2]=u.positions[i+2],t};for(let e=0;e<u.indices.length;e+=3){const t=T(e+0,a[0]),i=T(e+1,a[1]),s=T(e+2,a[2]);if(V.compareVec3(t,i)||V.compareVec3(i,s)||V.compareVec3(s,t))continue;const n=w+V.dotVec3(y,t),A=w+V.dotVec3(y,i),o=w+V.dotVec3(y,s);if(0!==n||0!==A||0!==o){const e=n*A<=0&&M(V.lerpVec3(n/(n-A),0,1,t,i,r),!0),a=A*o<=0&&M(V.lerpVec3(A/(A-o),0,1,i,s,r),!0),u=o*n<=0&&M(V.lerpVec3(o/(o-n),0,1,s,t,r),!0),f=!d.onlyPosSliceWithUV&&c;if(f&&(f[0]=M(t),f[1]=M(i),f[2]=M(s)),e?a||u:a&&u){if(v.push(e?[e,a||u]:[a,u]),f)if(0===n&&0===A)I(o>0?U:x,f);else if(0===n&&0===o)I(A>0?U:x,f);else if(0===A&&0===o)I(n>0?U:x,f);else{const t=(e?n:A)>0,i=t?U:x,s=t?x:U,r=l;r[0]=e,r[1]=a,r[2]=u;const o=h;e?(o[0]=0,o[1]=1,o[2]=2):(o[0]=1,o[1]=2,o[2]=0),r[o[1]]?(I(i,[f[o[0]],r[o[0]],f[o[2]]]),I(i,[r[o[0]],r[o[1]],f[o[2]]]),I(s,[r[o[0]],f[o[1]],r[o[1]]])):(I(i,[f[o[0]],r[o[0]],r[o[2]]]),I(s,[r[o[0]],f[o[1]],f[o[2]]]),I(s,[r[o[0]],f[o[2]],r[o[2]]]))}}else f&&(n>=0&&A>=0&&o>=0?I(U,f):n<=0&&A<=0&&o<=0&&I(x,f))}}const P=[];for(;v.length>0;){P.push([v[0][0],v[0][1]]);const e=P[P.length-1];for(v.splice(0,1);v.length>0;){const t=C[e[e.length-1]],i={distSq:p(C[e[0]],t),idx:-1,side:-1};if(v.forEach(((e,s)=>{const r=p(C[e[0]],t),n=p(C[e[1]],t),A=Math.min(r,n);i.distSq>A&&(i.distSq=A,i.idx=s,i.side=n<r?1:0)})),!(i.distSq<1e-20)){P.pop();break}{const s=i.idx>=0&&v[i.idx];if(C[s?s[i.side]:e[0]]=t,!s)break;{v.splice(i.idx,1);const t=s[1-i.side];if(!(p(C[t],C[e[0]])>1e-20))break;e.push(t)}}}}const S=P.filter((e=>e.length>2)).map(((i,s)=>{let r=0;const n=V.collapseAABB2(V.AABB2());for(let s=0;s<i.length;s++)E(i[s],e),V.expandAABB2Point2(n,e),E(i[(s+1)%i.length],t),r+=e[0]*t[1]-t[0]*e[1];return{boundingBox:n,doubleArea:Math.abs(r),endPoints:i}})).sort(((e,t)=>t.doubleArea-e.doubleArea));for(;S.length>0;){const t=[],i=[],s=s=>s.endPoints.forEach((s=>{E(s,e),t.push(e[0],e[1]),i.push(s)})),r=S.shift();s(r);const a=[];let c=0;for(;c<S.length;){const e=S[c];F(e,r)&&a.every((t=>!F(e,t)))?(e.index=t.length/2,s(e),a.push(e),S.splice(c,1)):++c}const h=o(t,a.map((e=>e.index)));for(let e=0;e<h.length;e+=3){const t=l;t[0]=i[h[e+0]],t[1]=i[h[e+1]],t[2]=i[h[e+2]];const s=C[t[0]];V.subVec3(C[t[1]],s,n),V.subVec3(C[t[2]],s,A),V.normalizeVec3(V.cross3Vec3(n,A,A),A);const r=V.dotVec3(A,y)<=0;I(r?U:x,t,A);const o=t[0];t[0]=t[2],t[2]=o,I(r?x:U,t,V.negateVec3(A,A))}}const D=e=>e&&e.indices.length>0&&function(){const t=[],i=d.onlyPosSliceWithUV&&[];return e.indices.forEach((e=>{const s=C[e];t.push(s[0],s[1],s[2]),i&&i.push(s[3],s[4])})),{indices:g(e.indices.length),positions:t,normals:e.normals,uv:i}}();return{pos:D(U),neg:D(x)}}}}();const L=new Float32Array(3);class H{constructor(e){if(!e)throw"Parameter expected: cfg";if(!e.viewer)throw"Parameter expected: cfg.viewer";this.viewer=e.viewer,this._maxTreeDepth=e.maxTreeDepth||15,this._root=null,this._needsRebuild=!0,this._onModelLoaded=this.viewer.scene.on("modelLoaded",(e=>{this._needsRebuild=!0})),this._onModelUnloaded=this.viewer.scene.on("modelUnloaded",(e=>{this._needsRebuild=!0}))}get root(){return this._needsRebuild&&this._rebuild(),this._root}_rebuild(){const e=this.viewer.scene;this._root={aabb:e.getAABB()};for(let t in e.objects){const i=e.objects[t];this._insertEntity(this._root,i,1)}this._needsRebuild=!1}_insertEntity(e,t,i){const s=t.aabb;if(i>=this._maxTreeDepth)return e.entities=e.entities||[],void e.entities.push(t);if(e.left&&V.containsAABB3(e.left.aabb,s))return void this._insertEntity(e.left,t,i+1);if(e.right&&V.containsAABB3(e.right.aabb,s))return void this._insertEntity(e.right,t,i+1);const r=e.aabb;L[0]=r[3]-r[0],L[1]=r[4]-r[1],L[2]=r[5]-r[2];let n=0;if(L[1]>L[n]&&(n=1),L[2]>L[n]&&(n=2),!e.left){const A=r.slice();if(A[n+3]=(r[n]+r[n+3])/2,e.left={aabb:A},V.containsAABB3(A,s))return void this._insertEntity(e.left,t,i+1)}if(!e.right){const A=r.slice();if(A[n]=(r[n]+r[n+3])/2,e.right={aabb:A},V.containsAABB3(A,s))return void this._insertEntity(e.right,t,i+1)}e.entities=e.entities||[],e.entities.push(t)}destroy(){const e=this.viewer.scene;e.off(this._onModelLoaded),e.off(this._onModelUnloaded),this._root=null,this._needsRebuild=!0}}class N{constructor(){this._head=[],this._headLength=0,this._tail=[],this._index=0,this._length=0}get length(){return this._length}shift(){if(this._index>=this._headLength){const e=this._head;if(e.length=0,this._head=this._tail,this._tail=e,this._index=0,this._headLength=this._head.length,!this._headLength)return}const e=this._head[this._index];return this._index<0?delete this._head[this._index++]:this._head[this._index++]=void 0,this._length--,e}push(e){return this._length++,this._tail.push(e),this}unshift(e){return this._head[--this._index]=e,this._length++,this}}const G={build:{version:"0.8"},client:{browser:navigator&&navigator.userAgent?navigator.userAgent:"n/a"},components:{scenes:0,models:0,meshes:0,objects:0},memory:{meshes:0,positions:0,colors:0,normals:0,uvs:0,indices:0,textures:0,transforms: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 j=[["0",10],["A",26],["a",26],["_",1],["$",1]].map((function(e){for(var t=[],i=e[0].charCodeAt(0),s=i+e[1],r=i;r<s;++r)t.push(r);return String.fromCharCode.apply(null,t)})).join("");function W(e,t){return(t&&4!==t?[0,6]:[0,6,12,18]).map((function(t){return j.substr(parseInt(e/(1<<t))%64,1)})).reverse().join("")}const z=function(){for(var e={},t=window.location.search.substring(1).split("&"),i=0;i<t.length;i++){var s=t[i].split("=");if(void 0===e[s[0]])e[s[0]]=decodeURIComponent(s[1]);else if("string"==typeof e[s[0]]){var r=[e[s[0]],decodeURIComponent(s[1])];e[s[0]]=r}else e[s[0]].push(decodeURIComponent(s[1]))}return e}();const X={xmlToJson:function e(t,i){if(t.nodeType===t.TEXT_NODE){var s=t.nodeValue;if(null===s.match(/^\s+$/))return s}else if(t.nodeType===t.ELEMENT_NODE||t.nodeType===t.DOCUMENT_NODE){var r={type:t.nodeName,children:[]};if(t.nodeType===t.ELEMENT_NODE)for(var n=0;n<t.attributes.length;n++){var A=t.attributes[n];r[i[A.nodeName]||A.nodeName]=A.nodeValue}for(var o=0;o<t.childNodes.length;o++){(n=e(t.childNodes[o],i))&&r.children.push(n)}return r}},clone:function(e){return JSON.parse(JSON.stringify(e))},compressGuid:function(e){var t=[0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30].map((function(t){return parseInt(e.substr(t,2),16)}));return W(t[0],2)+[1,4,7,10,13].map((function(e){return W((t[e]<<16)+(t[e+1]<<8)+t[e+2])})).join("")},findNodeOfType:function(e,t){var i=[],s=function(e){e.type===t&&i.push(e),(e.children||[]).forEach((function(e){s(e)}))};return s(e),i},timeout:function(e){return new Promise((function(t,i){setTimeout(t,e)}))},httpRequest:function(e){return new Promise((function(t,i){var s=new XMLHttpRequest;s.open(e.method||"GET",e.url,!0),s.onload=function(e){4===s.readyState&&(200===s.status?t(s.responseXML):i(s.statusText))},s.send(null)}))},loadJSON:function(e,t,i){var s=e=>{};t=t||s,i=i||s;var r=new XMLHttpRequest;r.overrideMimeType("application/json"),r.open("GET",e,!0),r.addEventListener("load",(function(e){var s=e.target.response;if(200===this.status){var r;try{r=JSON.parse(s)}catch(e){i(`utils.loadJSON(): Failed to parse JSON response - ${e}`)}t(r)}else if(0===this.status){console.warn("loadFile: HTTP Status 0 received.");try{t(JSON.parse(s))}catch(e){i(`utils.loadJSON(): Failed to parse JSON response - ${e}`)}}else i(e)}),!1),r.addEventListener("error",(function(e){i(e)}),!1),r.send(null)},loadArraybuffer:function(e,t,i){var s=e=>{};t=t||s,i=i||s;const r=e.match(/^data:(.*?)(;base64)?,(.*)$/);if(r){const e=!!r[2];var n=r[3];n=window.decodeURIComponent(n),e&&(n=window.atob(n));try{const e=new ArrayBuffer(n.length),i=new Uint8Array(e);for(var A=0;A<n.length;A++)i[A]=n.charCodeAt(A);ie.scheduleTask((()=>{t(e)}))}catch(e){ie.scheduleTask((()=>{i(e)}))}}else{const s=new XMLHttpRequest;s.open("GET",e,!0),s.responseType="arraybuffer",s.onreadystatechange=function(){4===s.readyState&&(200===s.status?t(s.response):i("loadArrayBuffer error : "+s.response))},s.send(null)}},queryString:z,isArray:function(e){return e&&!e.propertyIsEnumerable("length")&&"object"==typeof e&&"number"==typeof e.length},isString:function(e){return"string"==typeof e||e instanceof String},isNumeric:function(e){return!isNaN(parseFloat(e))&&isFinite(e)},isID:function(e){return X.isString(e)||X.isNumeric(e)},isSameComponent:function(e,t){return!(!e||!t)&&(X.isNumeric(e)||X.isString(e)?`${e}`:e.id)===(X.isNumeric(t)||X.isString(t)?`${t}`:t.id)},isFunction:function(e){return"function"==typeof e},isObject:function(e){const t={}.constructor;return!!e&&e.constructor===t},copy:function(e){return X.apply(e,{})},apply:function(e,t){for(const i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t},apply2:function(e,t){for(const i in e)e.hasOwnProperty(i)&&void 0!==e[i]&&null!==e[i]&&(t[i]=e[i]);return t},applyIf:function(e,t){for(const i in e)e.hasOwnProperty(i)&&(void 0!==t[i]&&null!==t[i]||(t[i]=e[i]));return t},isEmptyObject:function(e){for(const t in e)if(e.hasOwnProperty(t))return!1;return!0},inQuotes:function(e){return X.isNumeric(e)?`${e}`:`'${e}'`},concat:function(e,t){const i=new e.constructor(e.length+t.length);return i.set(e),i.set(t,e.length),i},flattenParentChildHierarchy:function(e){var t=[];return function e(i){i.id=i.uuid,delete i.oid,t.push(i);var s=i.children;if(s)for(var r=0,n=s.length;r<n;r++){s[r].parent=i.id,e(s[r])}i.children=[]}(e),t}},K={},Z=new e,J=new N,Y={sceneId:null,time:null,startTime:null,prevTime:null,deltaTime:null},$=[];let q,ee=0,te=0;const ie=new function(){this.version="1.0.0",this.scenes={},this._superTypes={},this._addScene=function(e){if(e.id){if(ie.scenes[e.id])return void console.error(`[ERROR] Scene ${X.inQuotes(e.id)} already exists`)}else e.id=Z.addItem({});ie.scenes[e.id]=e;const t=e.ticksPerOcclusionTest,i=e.ticksPerRender;K[e.id]={ticksPerOcclusionTest:t,ticksPerRender:i,renderCountdown:i},G.components.scenes++,e.once("destroyed",(()=>{Z.removeItem(e.id),delete ie.scenes[e.id],delete K[e.id],G.components.scenes--}))},this.clear=function(){let e;for(const t in ie.scenes)ie.scenes.hasOwnProperty(t)&&(e=ie.scenes[t],"default.scene"===t?e.clear():(e.destroy(),delete ie.scenes[e.id]))},this.scheduleTask=function(e,t=null){J.push(e),J.push(t)},this.runTasks=function(e=-1){let t,i,s=(new Date).getTime(),r=0;for(;J.length>0&&(e<0||s<e);)t=J.shift(),i=J.shift(),i?t.call(i):t(),s=(new Date).getTime(),r++;return r},this.getNumTasks=function(){return J.length}},se=function(){let e=Date.now();if(q=e-ee,ee>0&&q>0){var t=1e3/q;te+=t,$.push(t),$.length>=30&&(te-=$.shift()),G.frame.fps=Math.round(te/$.length)}for(let e in ie.scenes)ie.scenes[e].compile();ne(e),ee=e};!function(e,t){let i=Date.now()+t;(function s(){const r=Date.now()-i;e(),i+=t,setTimeout(s,Math.max(0,t-r))})()}((()=>{se()}),100);const re=function(){let e=Date.now();if(q=e-ee,ee>0&&q>0){var t=1e3/q;te+=t,$.push(t),$.length>=30&&(te-=$.shift()),G.frame.fps=Math.round(te/$.length)}ne(e),function(e){for(var t in Y.time=e,ie.scenes)if(ie.scenes.hasOwnProperty(t)){var i=ie.scenes[t];Y.sceneId=t,Y.startTime=i.startTime,Y.deltaTime=null!=Y.prevTime?Y.time-Y.prevTime:0,i.fire("tick",Y,!0)}Y.prevTime=e}(e),function(){const e=ie.scenes,t=!1;let i,s,r,n,A;for(A in e)e.hasOwnProperty(A)&&(i=e[A],s=K[A],s||(s=K[A]={}),r=i.ticksPerOcclusionTest,s.ticksPerOcclusionTest!==r&&(s.ticksPerOcclusionTest=r,s.renderCountdown=r),--i.occlusionTestCountdown<=0&&(i.doOcclusionTest(),i.occlusionTestCountdown=r),n=i.ticksPerRender,s.ticksPerRender!==n&&(s.ticksPerRender=n,s.renderCountdown=n),0==--s.renderCountdown&&(i.render(t),s.renderCountdown=n))}(),void 0!==window.requestPostAnimationFrame?window.requestPostAnimationFrame(se):requestAnimationFrame(re)};function ne(e){const t=ie.runTasks(e+10),i=ie.getNumTasks();G.frame.tasksRun=t,G.frame.tasksScheduled=i,G.frame.tasksBudget=10}re();class Ae{get type(){return"Component"}get isComponent(){return!0}constructor(e=null,t={}){if(this.scene=null,"Scene"===this.type)this.scene=this,this.viewer=t.viewer;else{if("Scene"===e.type)this.scene=e;else{if(!(e instanceof Ae))throw"Invalid param: owner must be a Component";this.scene=e.scene}this._owner=e}this._dontClear=!!t.dontClear,this._renderer=this.scene._renderer,this.meta=t.meta||{},this.id=t.id,this.destroyed=!1,this._attached={},this._attachments=null,this._subIdMap=null,this._subIdEvents=null,this._eventSubs=null,this._eventSubsNum=null,this._events=null,this._eventCallDepth=0,this._ownedComponents=null,this!==this.scene&&this.scene._addComponent(this),this._updateScheduled=!1,e&&e._own(this)}glRedraw(){this._renderer&&(this._renderer.imageDirty(),this.castsShadow&&this._renderer.shadowsDirty())}glResort(){this._renderer&&this._renderer.needStateSort()}get owner(){return this._owner}isType(e){return this.type===e}fire(e,t,i){this._events||(this._events={}),this._eventSubs||(this._eventSubs={},this._eventSubsNum={}),!0!==i&&(this._events[e]=t||!0);const s=this._eventSubs[e];let r;if(s)for(const i in s)s.hasOwnProperty(i)&&(r=s[i],this._eventCallDepth++,this._eventCallDepth<300?r.callback.call(r.scope,t):this.error("fire: potential stack overflow from recursive event '"+e+"' - dropping this event"),this._eventCallDepth--)}on(t,i,s){this._events||(this._events={}),this._subIdMap||(this._subIdMap=new e),this._subIdEvents||(this._subIdEvents={}),this._eventSubs||(this._eventSubs={}),this._eventSubsNum||(this._eventSubsNum={});let r=this._eventSubs[t];r?this._eventSubsNum[t]++:(r={},this._eventSubs[t]=r,this._eventSubsNum[t]=1);const n=this._subIdMap.addItem();r[n]={callback:i,scope:s||this},this._subIdEvents[n]=t;const A=this._events[t];return void 0!==A&&i.call(s||this,A),n}off(e){if(null==e)return;if(!this._subIdEvents)return;const t=this._subIdEvents[e];if(t){delete this._subIdEvents[e];const i=this._eventSubs[t];i&&(delete i[e],this._eventSubsNum[t]--),this._subIdMap.removeItem(e)}}once(e,t,i){const s=this,r=this.on(e,(function(e){s.off(r),t.call(i||this,e)}),i)}hasSubs(e){return this._eventSubsNum&&this._eventSubsNum[e]>0}log(e){e="[LOG]"+this._message(e),window.console.log(e),this.scene.fire("log",e)}_message(e){return" ["+this.type+" "+X.inQuotes(this.id)+"]: "+e}warn(e){e="[WARN]"+this._message(e),window.console.warn(e),this.scene.fire("warn",e)}error(e){e="[ERROR]"+this._message(e),window.console.error(e),this.scene.fire("error",e)}_attach(e){const t=e.name;if(!t)return void this.error("Component 'name' expected");let i=e.component;const s=e.sceneDefault,r=e.sceneSingleton,n=e.type,A=e.on,o=!1!==e.recompiles;if(i&&(X.isNumeric(i)||X.isString(i))){const e=i;if(i=this.scene.components[e],!i)return void this.error("Component not found: "+X.inQuotes(e))}if(!i)if(!0===r){const e=this.scene.types[n];for(const t in e)if(e.hasOwnProperty){i=e[t];break}if(!i)return this.error("Scene has no default component for '"+t+"'"),null}else if(!0===s&&(i=this.scene[t],!i))return this.error("Scene has no default component for '"+t+"'"),null;if(i){if(i.scene.id!==this.scene.id)return void this.error("Not in same scene: "+i.type+" "+X.inQuotes(i.id));if(n&&!i.isType(n))return void this.error("Expected a "+n+" type or subtype: "+i.type+" "+X.inQuotes(i.id))}this._attachments||(this._attachments={});const a=this._attached[t];let l,c,h;if(a){if(i&&a.id===i.id)return;const e=this._attachments[a.id];for(l=e.subs,c=0,h=l.length;c<h;c++)a.off(l[c]);delete this._attached[t],delete this._attachments[a.id];const s=e.params.onDetached;s&&(X.isFunction(s)?s(a):s.scope?s.callback.call(s.scope,a):s.callback(a)),e.managingLifecycle&&a.destroy()}if(i){const s={params:e,component:i,subs:[],managingLifecycle:false};s.subs.push(i.once("destroyed",(function(){s.params.component=null,this._attach(s.params)}),this)),o&&s.subs.push(i.on("dirty",(function(){this.fire("dirty",this)}),this)),this._attached[t]=i,this._attachments[i.id]=s;const r=e.onAttached;if(r&&(X.isFunction(r)?r(i):r.scope?r.callback.call(r.scope,i):r.callback(i)),A){let e,t,r,n;for(e in A)if(A.hasOwnProperty(e)){if(t=A[e],X.isFunction(t)?(r=t,n=null):(r=t.callback,n=t.scope),!r)continue;s.subs.push(i.on(e,r,n))}}}return o&&this.fire("dirty",this),this.fire(t,i),i}_checkComponent(e,t){if(!t.isComponent){if(!X.isID(t))return void this.error("Expected a Component or ID");{const e=t;if(!(t=this.scene.components[e]))return void this.error("Component not found: "+e)}}if(e===t.type){if(t.scene.id===this.scene.id)return t;this.error("Not in same scene: "+t.type)}else this.error("Expected a "+e+" Component")}_checkComponent2(e,t){if(!t.isComponent){if(!X.isID(t))return void this.error("Expected a Component or ID");{const e=t;if(!(t=this.scene.components[e]))return void this.error("Component not found: "+e)}}if(t.scene.id===this.scene.id){for(var i=0,s=e.length;i<s;i++)if(e[i]===t.type)return t;return this.error("Expected component types: "+e),null}this.error("Not in same scene: "+t.type)}_own(e){this._ownedComponents||(this._ownedComponents={}),this._ownedComponents[e.id]||(this._ownedComponents[e.id]=e),e.once("destroyed",(()=>{delete this._ownedComponents[e.id]}),this)}_needUpdate(e){this._updateScheduled||(this._updateScheduled=!0,0===e?this._doUpdate():ie.scheduleTask(this._doUpdate,this))}_doUpdate(){this._updateScheduled&&(this._updateScheduled=!1,this._update&&this._update())}scheduleTask(e){ie.scheduleTask(e,null)}_update(){}clear(){if(this._ownedComponents)for(var e in this._ownedComponents)if(this._ownedComponents.hasOwnProperty(e)){this._ownedComponents[e].destroy(),delete this._ownedComponents[e]}}destroy(){if(this.destroyed)return;let e,t,i,s,r,n;if(this.fire("destroyed",this.destroyed=!0),this._attachments)for(e in this._attachments)if(this._attachments.hasOwnProperty(e)){for(t=this._attachments[e],i=t.component,s=t.subs,r=0,n=s.length;r<n;r++)i.off(s[r]);t.managingLifecycle&&i.destroy()}if(this._ownedComponents)for(e in this._ownedComponents)this._ownedComponents.hasOwnProperty(e)&&(i=this._ownedComponents[e],i.destroy(),delete this._ownedComponents[e]);this.scene._removeComponent(this),this._attached={},this._attachments=null,this._subIdMap=null,this._subIdEvents=null,this._eventSubs=null,this._events=null,this._eventCallDepth=0,this._ownedComponents=null,this._updateScheduled=!1}}const oe=V.vec3(),ae=V.vec3(),le=V.mat4();class ce{constructor(){this.normal=V.vec3(),this.offset=0,this.testVertex=V.vec3()}set(e,t,i,s){const r=1/Math.sqrt(e*e+t*t+i*i);this.normal[0]=e*r,this.normal[1]=t*r,this.normal[2]=i*r,this.offset=s*r,this.testVertex[0]=this.normal[0]>=0?1:0,this.testVertex[1]=this.normal[1]>=0?1:0,this.testVertex[2]=this.normal[2]>=0?1:0}}class he{constructor(){this.planes=[new ce,new ce,new ce,new ce,new ce,new ce]}}function ue(e,t,i){const s=V.mulMat4(i,t,le),r=s[0],n=s[1],A=s[2],o=s[3],a=s[4],l=s[5],c=s[6],h=s[7],u=s[8],d=s[9],f=s[10],p=s[11],g=s[12],m=s[13],_=s[14],b=s[15];e.planes[0].set(o-r,h-a,p-u,b-g),e.planes[1].set(o+r,h+a,p+u,b+g),e.planes[2].set(o-n,h-l,p-d,b-m),e.planes[3].set(o+n,h+l,p+d,b+m),e.planes[4].set(o-A,h-c,p-f,b-_),e.planes[5].set(o+A,h+c,p+f,b+_)}function de(e,t){let i=he.INSIDE;const s=oe,r=ae;s[0]=t[0],s[1]=t[1],s[2]=t[2],r[0]=t[3],r[1]=t[4],r[2]=t[5];const n=[s,r];for(let t=0;t<6;++t){const s=e.planes[t];if(s.normal[0]*n[s.testVertex[0]][0]+s.normal[1]*n[s.testVertex[1]][1]+s.normal[2]*n[s.testVertex[2]][2]+s.offset<0)return he.OUTSIDE;s.normal[0]*n[1-s.testVertex[0]][0]+s.normal[1]*n[1-s.testVertex[1]][1]+s.normal[2]*n[1-s.testVertex[2]][2]+s.offset<0&&(i=he.INTERSECT)}return i}he.INSIDE=0,he.INTERSECT=1,he.OUTSIDE=2;class fe extends Ae{constructor(e={}){if(!e.viewer)throw"[MarqueePicker] Missing config: viewer";if(!e.objectsKdTree3)throw"[MarqueePicker] Missing config: objectsKdTree3";super(e.viewer.scene,e),this.viewer=e.viewer,this._objectsKdTree3=e.objectsKdTree3,this._canvasMarqueeCorner1=V.vec2(),this._canvasMarqueeCorner2=V.vec2(),this._canvasMarquee=V.AABB2(),this._marqueeFrustum=new he,this._marqueeFrustumProjMat=V.mat4(),this._pickMode=!1,this._marqueeElement=document.createElement("div"),document.body.appendChild(this._marqueeElement),this._marqueeElement.style.position="absolute",this._marqueeElement.style["z-index"]="40000005",this._marqueeElement.style.width="8px",this._marqueeElement.style.height="8px",this._marqueeElement.style.visibility="hidden",this._marqueeElement.style.top="0px",this._marqueeElement.style.left="0px",this._marqueeElement.style["box-shadow"]="0 2px 5px 0 #182A3D;",this._marqueeElement.style.opacity=1,this._marqueeElement.style["pointer-events"]="none"}setMarqueeCorner1(e){this._canvasMarqueeCorner1.set(e),this._canvasMarqueeCorner2.set(e),this._updateMarquee()}setMarqueeCorner2(e){this._canvasMarqueeCorner2.set(e),this._updateMarquee()}setMarquee(e,t){this._canvasMarqueeCorner1.set(e),this._canvasMarqueeCorner2.set(t),this._updateMarquee()}setMarqueeVisible(e){this._marqueVisible=e,this._marqueeElement.style.visibility=e?"visible":"hidden"}getMarqueeVisible(){return this._marqueVisible}setPickMode(e){if(e!==fe.PICK_MODE_INSIDE&&e!==fe.PICK_MODE_INTERSECTS)throw"Illegal MarqueePicker pickMode: must be MarqueePicker.PICK_MODE_INSIDE or MarqueePicker.PICK_MODE_INTERSECTS";e!==this._pickMode&&(this._marqueeElement.style["background-image"]=e===fe.PICK_MODE_INSIDE?"url(\"data:image/svg+xml,%3csvg width='100%25' height='100%25' xmlns='http://www.w3.org/2000/svg'%3e%3crect width='100%25' height='100%25' fill='none' rx='6' ry='6' stroke='%23333' stroke-width='4'/%3e%3c/svg%3e\")":"url(\"data:image/svg+xml,%3csvg width='100%25' height='100%25' xmlns='http://www.w3.org/2000/svg'%3e%3crect width='100%25' height='100%25' fill='none' rx='6' ry='6' stroke='%23333' stroke-width='4' stroke-dasharray='6%2c 14' stroke-dashoffset='0' stroke-linecap='square'/%3e%3c/svg%3e\")",this._pickMode=e)}getPickMode(){return this._pickMode}clear(){this.fire("clear",{})}pick(){this._updateMarquee(),this._buildMarqueeFrustum();const e=[],t=(i,s=he.INTERSECT)=>{if(s===he.INTERSECT&&(s=de(this._marqueeFrustum,i.aabb)),s!==he.OUTSIDE){if(i.entities){const t=i.entities;for(let i=0,s=t.length;i<s;i++){const s=t[i];if(!s.visible)continue;const r=s.aabb;if(this._pickMode===fe.PICK_MODE_INSIDE){de(this._marqueeFrustum,r)===he.INSIDE&&e.push(s.id)}else{de(this._marqueeFrustum,r)!==he.OUTSIDE&&e.push(s.id)}}}i.left&&t(i.left,s),i.right&&t(i.right,s)}};return(this._canvasMarquee[2]-this._canvasMarquee[0]>3||this._canvasMarquee[3]-this._canvasMarquee[1]>3)&&t(this._objectsKdTree3.root),this.fire("picked",e),e}_updateMarquee(){this._canvasMarquee[0]=Math.min(this._canvasMarqueeCorner1[0],this._canvasMarqueeCorner2[0]),this._canvasMarquee[1]=Math.min(this._canvasMarqueeCorner1[1],this._canvasMarqueeCorner2[1]),this._canvasMarquee[2]=Math.max(this._canvasMarqueeCorner1[0],this._canvasMarqueeCorner2[0]),this._canvasMarquee[3]=Math.max(this._canvasMarqueeCorner1[1],this._canvasMarqueeCorner2[1]),this._marqueeElement.style.width=this._canvasMarquee[2]-this._canvasMarquee[0]+"px",this._marqueeElement.style.height=this._canvasMarquee[3]-this._canvasMarquee[1]+"px",this._marqueeElement.style.left=`${this._canvasMarquee[0]}px`,this._marqueeElement.style.top=`${this._canvasMarquee[1]}px`}_buildMarqueeFrustum(){const e=this.viewer.scene.canvas.canvas,t=e.clientWidth,i=e.clientHeight,s=e.clientLeft,r=e.clientTop,n=2/t,A=2/i,o=e.clientHeight/e.clientWidth,a=(this._canvasMarquee[0]-s)*n-1,l=(this._canvasMarquee[2]-s)*n-1,c=-(this._canvasMarquee[3]-r)*A+1,h=-(this._canvasMarquee[1]-r)*A+1,u=this.viewer.scene.camera.frustum.near*(17*o);V.frustumMat4(a,l,c*o,h*o,u,1e4,this._marqueeFrustumProjMat),ue(this._marqueeFrustum,this.viewer.scene.camera.viewMatrix,this._marqueeFrustumProjMat)}destroy(){super.destroy(),this._marqueeElement.parentElement&&(this._marqueeElement.parentElement.removeChild(this._marqueeElement),this._marqueeElement=null,this._objectsKdTree3=null)}}fe.PICK_MODE_INTERSECTS=0,fe.PICK_MODE_INSIDE=1;class pe extends Ae{constructor(e){super(e.marqueePicker,e);const t=e.marqueePicker,i=t.viewer.scene.canvas.canvas;let s,r,n,A,o,a,l,c=!1,h=!1,u=!1;i.addEventListener("mousedown",(e=>{this.getActive()&&0===e.button&&(l=setTimeout((function(){const n=t.viewer.scene.input;n.keyDown[n.KEY_CTRL]||t.clear(),s=e.pageX,r=e.pageY,o=e.offsetX,t.setMarqueeCorner1([s,r]),c=!0,t.viewer.cameraControl.pointerEnabled=!1,t.setMarqueeVisible(!0),i.style.cursor="crosshair"}),400),h=!0)})),i.addEventListener("mouseup",(e=>{if(!this.getActive())return;if(!c&&!u)return;if(0!==e.button)return;clearTimeout(l),n=e.pageX,A=e.pageY;const i=Math.abs(n-s),o=Math.abs(A-r);c=!1,t.viewer.cameraControl.pointerEnabled=!0,u&&(u=!1),(i>3||o>3)&&t.pick()})),document.addEventListener("mouseup",(e=>{this.getActive()&&0===e.button&&(clearTimeout(l),c&&(t.setMarqueeVisible(!1),c=!1,h=!1,u=!0,t.viewer.cameraControl.pointerEnabled=!0))}),!0),i.addEventListener("mousemove",(e=>{this.getActive()&&0===e.button&&h&&(clearTimeout(l),c&&(n=e.pageX,A=e.pageY,a=e.offsetX,t.setMarqueeVisible(!0),t.setMarqueeCorner2([n,A]),t.setPickMode(o<a?fe.PICK_MODE_INSIDE:fe.PICK_MODE_INTERSECTS)))}))}setActive(e){this._active!==e&&(this._active=e,this.fire("active",this._active))}getActive(){return this._active}destroy(){}}class ge{constructor(e,t={}){this.viewer=e,this.scene=this.viewer.scene,this._circleDiv=document.createElement("div"),this.viewer.scene.canvas.canvas.parentNode.insertBefore(this._circleDiv,this.viewer.scene.canvas.canvas),this._circleDiv.style.backgroundColor="transparent",this._circleDiv.style.border="2px solid green",this._circleDiv.style.borderRadius="50px",this._circleDiv.style.width="50px",this._circleDiv.style.height="50px",this._circleDiv.style.margin="-200px -200px",this._circleDiv.style.zIndex="100000",this._circleDiv.style.position="absolute",this._circleDiv.style.pointerEvents="none",this._circlePos=null,this._circleMaxRadius=200,this._circleMinRadius=2,this._active=!1!==t.active,this._visible=!1,this._running=!1,this._destroyed=!1}start(e){if(this._destroyed)return;this._circlePos=e,this._running=!1,this._circleRadius=this._circleMaxRadius,this._circleDiv.style.borderRadius=`${this._circleRadius}px`,this._circleDiv.style.marginLeft=this._circlePos[0]-this._circleRadius+"px",this._circleDiv.style.marginTop=this._circlePos[1]-this._circleRadius+"px";const t=this._circleMaxRadius;let i;const s=e=>{if(!this._running)return;i||(i=e);const r=e-i,n=Math.min(r/300,1),A=t+(2-t)*n;this._circleRadius=A,this._circleDiv.style.width=`${this._circleRadius}px`,this._circleDiv.style.height=`${this._circleRadius}px`,this._circleDiv.style.marginLeft=this._circlePos[0]-this._circleRadius/2+"px",this._circleDiv.style.marginTop=this._circlePos[1]-this._circleRadius/2+"px",n<1&&requestAnimationFrame(s)};this._running=!0,requestAnimationFrame(s),this._circleDiv.style.visibility="visible"}stop(){this._destroyed||(this._running=!1,this._circleRadius=this._circleMaxRadius,this._circleDiv.style.borderRadius=`${this._circleRadius}px`,this._circleDiv.style.visibility="hidden")}set durationMs(e){this.stop(),this._durationMs=e}get durationMs(){return this._durationMs}destroy(){this._destroyed||(this.stop(),this._circleDiv.parentElement.removeChild(this._circleDiv),this._destroyed=!0)}}class me{constructor(e={}){this._eventSubIDMap=null,this._eventSubEvents=null,this._eventSubs=null,this._events=null,this._locale="en",this._messages={},this._locales=[],this._locale="en",this.messages=e.messages,this.locale=e.locale}set messages(e){this._messages=e||{},this._locales=Object.keys(this._messages),this.fire("updated",this)}loadMessages(e={}){for(let t in e)this._messages[t]=e[t];this.messages=this._messages}clearMessages(){this.messages={}}get locales(){return this._locales}set locale(e){e=e||"de",this._locale!==e&&(this._locale=e,this.fire("updated",e))}get locale(){return this._locale}translate(e,t){const i=this._messages[this._locale];if(!i)return null;const s=_e(e,i);return s?t?be(s,t):s:null}translatePlurals(e,t,i){const s=this._messages[this._locale];if(!s)return null;let r=_e(e,s);return r=0===(t=parseInt(""+t,10))?r.zero:t>1?r.other:r.one,r?(r=be(r,[t]),i&&(r=be(r,i)),r):null}fire(e,t,i){this._events||(this._events={}),this._eventSubs||(this._eventSubs={}),!0!==i&&(this._events[e]=t||!0);const s=this._eventSubs[e];if(s)for(const e in s)if(s.hasOwnProperty(e)){s[e].callback(t)}}on(t,i){this._events||(this._events={}),this._eventSubIDMap||(this._eventSubIDMap=new e),this._eventSubEvents||(this._eventSubEvents={}),this._eventSubs||(this._eventSubs={});let s=this._eventSubs[t];s||(s={},this._eventSubs[t]=s);const r=this._eventSubIDMap.addItem();s[r]={callback:i},this._eventSubEvents[r]=t;const n=this._events[t];return void 0!==n&&i(n),r}off(e){if(null==e)return;if(!this._eventSubEvents)return;const t=this._eventSubEvents[e];if(t){delete this._eventSubEvents[e];const i=this._eventSubs[t];i&&delete i[e],this._eventSubIDMap.removeItem(e)}}}function _e(e,t){if(t[e])return t[e];const i=e.split(".");let s=t;for(let e=0,t=i.length;s&&e<t;e++){s=s[i[e]]}return s}function be(e,t=[]){return e.replace(/\{\{|\}\}|\{(\d+)\}/g,(function(e,i){return"{{"===e?"{":"}}"===e?"}":t[i]}))}class Be extends Ae{constructor(e,t={}){super(e,t),this.t=t.t}set t(e){e=e||0,this._t=e<0?0:e>1?1:e}get t(){return this._t}get tangent(){return this.getTangent(this._t)}get length(){var e=this._getLengths();return e[e.length-1]}getTangent(e){var t=1e-4;void 0===e&&(e=this._t);var i=e-t,s=e+t;i<0&&(i=0),s>1&&(s=1);var r=this.getPoint(i),n=this.getPoint(s),A=V.subVec3(n,r,[]);return V.normalizeVec3(A,[])}getPointAt(e){var t=this.getUToTMapping(e);return this.getPoint(t)}getPoints(e){e||(e=5);var t,i=[];for(t=0;t<=e;t++)i.push(this.getPoint(t/e));return i}_getLengths(e){if(e||(e=this.__arcLengthDivisions?this.__arcLengthDivisions:200),this.cacheArcLengths&&this.cacheArcLengths.length===e+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=!1;var t,i,s=[],r=this.getPoint(0),n=0;for(s.push(0),i=1;i<=e;i++)t=this.getPoint(i/e),n+=V.lenVec3(V.subVec3(t,r,[])),s.push(n),r=t;return this.cacheArcLengths=s,s}_updateArcLengths(){this.needsUpdate=!0,this._getLengths()}getUToTMapping(e,t){var i,s=this._getLengths(),r=0,n=s.length;i=t||e*s[n-1];for(var A,o=0,a=n-1;o<=a;)if((A=s[r=Math.floor(o+(a-o)/2)]-i)<0)o=r+1;else{if(!(A>0)){a=r;break}a=r-1}if(s[r=a]===i)return r/(n-1);var l=s[r];return(r+(i-l)/(s[r+1]-l))/(n-1)}}class ye extends Be{constructor(e,t={}){super(e,t),this.points=t.points,this.t=t.t}set points(e){this._points=e||[]}get points(){return this._points}set t(e){e=e||0,this._t=e<0?0:e>1?1:e}get t(){return this._t}get point(){return this.getPoint(this._t)}getPoint(e){var t=this.points;if(!(t.length<3)){var i=(t.length-1)*e,s=Math.floor(i),r=i-s,n=t[0===s?s:s-1],A=t[s],o=t[s>t.length-2?t.length-1:s+1],a=t[s>t.length-3?t.length-1:s+2],l=V.vec3();return l[0]=V.catmullRomInterpolate(n[0],A[0],o[0],a[0],r),l[1]=V.catmullRomInterpolate(n[1],A[1],o[1],a[1],r),l[2]=V.catmullRomInterpolate(n[2],A[2],o[2],a[2],r),l}this.error("Can't sample point from SplineCurve - not enough points on curve - returning [0,0,0].")}getJSON(){return{points:points,t:this._t}}}const we=V.vec3();class ve extends Ae{get type(){return"CameraPath"}constructor(e,t={}){super(e,t),this._frames=[],this._eyeCurve=new ye(this),this._lookCurve=new ye(this),this._upCurve=new ye(this),t.frames&&(this.addFrames(t.frames),this.smoothFrameTimes(1))}get frames(){return this._frames}get eyeCurve(){return this._eyeCurve}get lookCurve(){return this._lookCurve}get upCurve(){return this._upCurve}saveFrame(e){const t=this.scene.camera;this.addFrame(e,t.eye,t.look,t.up)}addFrame(e,t,i,s){const r={t:e,eye:t.slice(0),look:i.slice(0),up:s.slice(0)};this._frames.push(r),this._eyeCurve.points.push(r.eye),this._lookCurve.points.push(r.look),this._upCurve.points.push(r.up)}addFrames(e){let t;for(let i=0,s=e.length;i<s;i++)t=e[i],this.addFrame(t.t||0,t.eye,t.look,t.up)}loadFrame(e){const t=this.scene.camera;e=(e/=this._frames[this._frames.length-1].t-this._frames[0].t)<0?0:e>1?1:e,t.eye=this._eyeCurve.getPoint(e,we),t.look=this._lookCurve.getPoint(e,we),t.up=this._upCurve.getPoint(e,we)}sampleFrame(e,t,i,s){e=e<0?0:e>1?1:e,this._eyeCurve.getPoint(e,t),this._lookCurve.getPoint(e,i),this._upCurve.getPoint(e,s)}smoothFrameTimes(e){if(0===this._frames.length)return;const t=V.vec3();var i=0;this._frames[0].t=0;const s=[];for(let e=1,n=this._frames.length;e<n;e++){var r=V.lenVec3(V.subVec3(this._frames[e].eye,this._frames[e-1].eye,t));s[e]=r,i+=r}for(let t=1,r=this._frames.length;t<r;t++){const r=s[t]/i*e;this._frames[t].t=this._frames[t-1].t+r}}clearFrames(){this._frames=[],this._eyeCurve.points=[],this._lookCurve.points=[],this._upCurve.points=[]}}const Ce=V.vec3(),Me=V.vec3(),Ee=V.vec3(),Fe=V.vec3(),Ue=V.vec3();class xe extends Ae{get type(){return"CameraFlightAnimation"}constructor(e,t={}){super(e,t),this._look1=V.vec3(),this._eye1=V.vec3(),this._up1=V.vec3(),this._look2=V.vec3(),this._eye2=V.vec3(),this._up2=V.vec3(),this._orthoScale1=1,this._orthoScale2=1,this._flying=!1,this._flyEyeLookUp=!1,this._flyingEye=!1,this._flyingLook=!1,this._callback=null,this._callbackScope=null,this._time1=null,this._time2=null,this.easing=!1!==t.easing,this.duration=t.duration,this.fit=t.fit,this.fitFOV=t.fitFOV,this.trail=t.trail}flyTo(e,t,i){e=e||this.scene,this._flying&&this.stop(),this._flying=!1,this._flyingEye=!1,this._flyingLook=!1,this._flyingEyeLookUp=!1,this._callback=t,this._callbackScope=i;const s=this.scene.camera,r=!!e.projection&&e.projection!==s.projection;let n,A,o,a,l;if(this._eye1[0]=s.eye[0],this._eye1[1]=s.eye[1],this._eye1[2]=s.eye[2],this._look1[0]=s.look[0],this._look1[1]=s.look[1],this._look1[2]=s.look[2],this._up1[0]=s.up[0],this._up1[1]=s.up[1],this._up1[2]=s.up[2],this._orthoScale1=s.ortho.scale,this._orthoScale2=e.orthoScale||this._orthoScale1,e.aabb)n=e.aabb;else if(6===e.length)n=e;else if(e.eye&&e.look||e.up)A=e.eye,o=e.look,a=e.up;else if(e.eye)A=e.eye;else if(e.look)o=e.look;else{let s=e;if((X.isNumeric(s)||X.isString(s))&&(l=s,s=this.scene.components[l],!s))return this.error("Component not found: "+X.inQuotes(l)),void(t&&(i?t.call(i):t()));r||(n=s.aabb||this.scene.aabb)}const c=e.poi;if(n){if(n[3]<n[0]||n[4]<n[1]||n[5]<n[2])return;if(n[3]===n[0]&&n[4]===n[1]&&n[5]===n[2])return;n=n.slice();const t=V.getAABB3Center(n);this._look2=c||t;const i=V.subVec3(this._eye1,this._look1,Ce),s=V.normalizeVec3(i),r=c?V.getAABB3DiagPoint(n,c):V.getAABB3Diag(n),A=e.fitFOV||this._fitFOV,o=Math.abs(r/Math.tan(A*V.DEGTORAD));this._orthoScale2=1.1*r,this._eye2[0]=this._look2[0]+s[0]*o,this._eye2[1]=this._look2[1]+s[1]*o,this._eye2[2]=this._look2[2]+s[2]*o,this._up2[0]=this._up1[0],this._up2[1]=this._up1[1],this._up2[2]=this._up1[2],this._flyingEyeLookUp=!0}else(A||o||a)&&(this._flyingEyeLookUp=!!A&&!!o&&!!a,this._flyingEye=!!A&&!o,this._flyingLook=!!o&&!A,A&&(this._eye2[0]=A[0],this._eye2[1]=A[1],this._eye2[2]=A[2]),o&&(this._look2[0]=o[0],this._look2[1]=o[1],this._look2[2]=o[2]),a&&(this._up2[0]=a[0],this._up2[1]=a[1],this._up2[2]=a[2]));r?("ortho"===e.projection&&"ortho"!==s.projection&&(this._projection2="ortho",this._projMatrix1=s.projMatrix.slice(),this._projMatrix2=s.ortho.matrix.slice(),s.projection="customProjection"),"perspective"===e.projection&&"perspective"!==s.projection&&(this._projection2="perspective",this._projMatrix1=s.projMatrix.slice(),this._projMatrix2=s.perspective.matrix.slice(),s.projection="customProjection")):this._projection2=null,this.fire("started",e,!0),this._time1=Date.now(),this._time2=this._time1+(Number.isFinite(e.duration)?1e3*e.duration:this._duration),this._flying=!0,ie.scheduleTask(this._update,this)}jumpTo(e){this._jumpTo(e)}_jumpTo(e){this._flying&&this.stop();const t=this.scene.camera;var i,s,r,n,A;if(e.aabb)i=e.aabb;else if(6===e.length)i=e;else if(e.eye||e.look||e.up)r=e.eye,n=e.look,A=e.up;else{let t=e;if((X.isNumeric(t)||X.isString(t))&&(s=t,t=this.scene.components[s],!t))return void this.error("Component not found: "+X.inQuotes(s));i=t.aabb||this.scene.aabb}const o=e.poi;if(i){if(i[3]<=i[0]||i[4]<=i[1]||i[5]<=i[2])return;var a=o?V.getAABB3DiagPoint(i,o):V.getAABB3Diag(i);let s;n=o||V.getAABB3Center(i,n),this._trail?V.subVec3(t.look,n,Ue):V.subVec3(t.eye,t.look,Ue),V.normalizeVec3(Ue);s=(void 0!==e.fit?e.fit:this._fit)?Math.abs(a/Math.tan((e.fitFOV||this._fitFOV)*V.DEGTORAD)):V.lenVec3(V.subVec3(t.eye,t.look,Ce)),V.mulVec3Scalar(Ue,s),t.eye=V.addVec3(n,Ue,Ce),t.look=n,this.scene.camera.ortho.scale=1.1*a}else(r||n||A)&&(r&&(t.eye=r),n&&(t.look=n),A&&(t.up=A));e.projection&&(t.projection=e.projection)}_update(){if(!this._flying)return;let e=(Date.now()-this._time1)/(this._time2-this._time1);const t=e>=1;e>1&&(e=1);const i=this.easing?xe._ease(e,0,1,1):e,s=this.scene.camera;if(this._flyingEye||this._flyingLook?this._flyingEye?(V.subVec3(s.eye,s.look,Ue),s.eye=V.lerpVec3(i,0,1,this._eye1,this._eye2,Ee),s.look=V.subVec3(Ee,Ue,Me)):this._flyingLook&&(s.look=V.lerpVec3(i,0,1,this._look1,this._look2,Me),s.up=V.lerpVec3(i,0,1,this._up1,this._up2,Fe)):this._flyingEyeLookUp&&(s.eye=V.lerpVec3(i,0,1,this._eye1,this._eye2,Ee),s.look=V.lerpVec3(i,0,1,this._look1,this._look2,Me),s.up=V.lerpVec3(i,0,1,this._up1,this._up2,Fe)),this._projection2){const t="ortho"===this._projection2?xe._easeOutExpo(e,0,1,1):xe._easeInCubic(e,0,1,1);s.customProjection.matrix=V.lerpMat4(t,0,1,this._projMatrix1,this._projMatrix2)}else s.ortho.scale=this._orthoScale1+e*(this._orthoScale2-this._orthoScale1);if(t)return s.ortho.scale=this._orthoScale2,void this.stop();ie.scheduleTask(this._update,this)}static _ease(e,t,i,s){return-i*(e/=s)*(e-2)+t}static _easeInCubic(e,t,i,s){return i*(e/=s)*e*e+t}static _easeOutExpo(e,t,i,s){return i*(1-Math.pow(2,-10*e/s))+t}stop(){if(!this._flying)return;this._flying=!1,this._time1=null,this._time2=null,this._projection2&&(this.scene.camera.projection=this._projection2);const e=this._callback;e&&(this._callback=null,this._callbackScope?e.call(this._callbackScope):e()),this.fire("stopped",!0,!0)}cancel(){this._flying&&(this._flying=!1,this._time1=null,this._time2=null,this._callback&&(this._callback=null),this.fire("canceled",!0,!0))}set duration(e){this._duration=Number.isFinite(e)?1e3*e:500,this.stop()}get duration(){return this._duration/1e3}set fit(e){this._fit=!1!==e}get fit(){return this._fit}set fitFOV(e){this._fitFOV=e||45}get fitFOV(){return this._fitFOV}set trail(e){this._trail=!!e}get trail(){return this._trail}destroy(){this.stop(),super.destroy()}}class Ie extends Ae{get type(){return"CameraPathAnimation"}constructor(e,t={}){super(e,t),this._cameraFlightAnimation=new xe(this),this._t=0,this.state=Ie.SCRUBBING,this._playingFromT=0,this._playingToT=0,this._playingRate=t.playingRate||1,this._playingDir=1,this._lastTime=null,this.cameraPath=t.cameraPath,this._tick=this.scene.on("tick",this._updateT,this)}_updateT(){const e=this._cameraPath;if(!e)return;let t,i;const s=performance.now(),r=this._lastTime?.001*(s-this._lastTime):0;if(this._lastTime=s,0!==r)switch(this.state){case Ie.SCRUBBING:return;case Ie.PLAYING:if(this._t+=this._playingRate*r,t=this._cameraPath.frames.length,0===t||this._playingDir<0&&this._t<=0||this._playingDir>0&&this._t>=this._cameraPath.frames[t-1].t)return this.state=Ie.SCRUBBING,this._t=this._cameraPath.frames[t-1].t,void this.fire("stopped");e.loadFrame(this._t);break;case Ie.PLAYING_TO:i=this._t+this._playingRate*r*this._playingDir,(this._playingDir<0&&i<=this._playingToT||this._playingDir>0&&i>=this._playingToT)&&(i=this._playingToT,this.state=Ie.SCRUBBING,this.fire("stopped")),this._t=i,e.loadFrame(this._t)}}_ease(e,t,i,s){return-i*(e/=s)*(e-2)+t}set cameraPath(e){this._cameraPath=e}get cameraPath(){return this._cameraPath}set rate(e){this._playingRate=e}get rate(){return this._playingRate}play(){this._cameraPath&&(this._lastTime=null,this.state=Ie.PLAYING)}playToT(e){this._cameraPath&&(this._playingFromT=this._t,this._playingToT=e,this._playingDir=this._playingToT-this._playingFromT<0?-1:1,this._lastTime=null,this.state=Ie.PLAYING_TO)}playToFrame(e){const t=this._cameraPath;if(!t)return;const i=t.frames[e];i?this.playToT(i.t):this.error("playToFrame - frame index out of range: "+e)}flyToFrame(e,t){const i=this._cameraPath;if(!i)return;const s=i.frames[e];s?(this.state=Ie.SCRUBBING,this._cameraFlightAnimation.flyTo(s,t)):this.error("flyToFrame - frame index out of range: "+e)}scrubToT(e){const t=this._cameraPath;if(!t)return;this.scene.camera&&(this._t=e,t.loadFrame(this._t),this.state=Ie.SCRUBBING)}scrubToFrame(e){const t=this._cameraPath;if(!t)return;if(!this.scene.camera)return;t.frames[e]?(t.loadFrame(this._t),this.state=Ie.SCRUBBING):this.error("playToFrame - frame index out of range: "+e)}stop(){this.state=Ie.SCRUBBING,this.fire("stopped")}destroy(){super.destroy(),this.scene.off(this._tick)}}Ie.STOPPED=0,Ie.SCRUBBING=1,Ie.PLAYING=2,Ie.PLAYING_TO=3;class Te extends Ae{get type(){return"Geometry"}get isGeometry(){return!0}constructor(e,t={}){super(e,t),G.memory.meshes++}destroy(){super.destroy(),G.memory.meshes--}}const Pe=new e({});class Se{constructor(e){this.id=Pe.addItem({});for(const t in e)e.hasOwnProperty(t)&&(this[t]=e[t])}destroy(){Pe.removeItem(this.id)}}class De{constructor(e,t,i,s,r,n,A,o,a){switch(this._gl=e,this.type=t,this.allocated=!1,i.constructor){case Uint8Array:this.itemType=e.UNSIGNED_BYTE,this.itemByteSize=1;break;case Int8Array:this.itemType=e.BYTE,this.itemByteSize=1;break;case Uint16Array:this.itemType=e.UNSIGNED_SHORT,this.itemByteSize=2;break;case Int16Array:this.itemType=e.SHORT,this.itemByteSize=2;break;case Uint32Array:this.itemType=e.UNSIGNED_INT,this.itemByteSize=4;break;case Int32Array:this.itemType=e.INT,this.itemByteSize=4;break;default:this.itemType=e.FLOAT,this.itemByteSize=4}this.usage=n,this.length=0,this.dataLength=s,this.numItems=0,this.itemSize=r,this.normalized=!!A,this.stride=o||0,this.offset=a||0,this._allocate(i)}_allocate(e){if(this.allocated=!1,this._handle=this._gl.createBuffer(),!this._handle)throw"Failed to allocate WebGL ArrayBuffer";this._handle&&(this._gl.bindBuffer(this.type,this._handle),this._gl.bufferData(this.type,e.length>this.dataLength?e.slice(0,this.dataLength):e,this.usage),this._gl.bindBuffer(this.type,null),this.length=e.length,this.numItems=this.length/this.itemSize,this.allocated=!0)}setData(e,t){this.allocated&&(e.length+(t||0)>this.length?(this.destroy(),this._allocate(e)):(this._gl.bindBuffer(this.type,this._handle),t||0===t?this._gl.bufferSubData(this.type,t*this.itemByteSize,e):this._gl.bufferData(this.type,e,this.usage),this._gl.bindBuffer(this.type,null)))}bind(){this.allocated&&this._gl.bindBuffer(this.type,this._handle)}unbind(){this.allocated&&this._gl.bindBuffer(this.type,null)}bindAtLocation(e){this.bind(),this._gl.vertexAttribPointer(e,this.itemSize,this.itemType,this.normalized,0,0)}destroy(){this.allocated&&(this._gl.deleteBuffer(this._handle),this._handle=null,this.allocated=!1)}}var ke=function(){const e=[],t=[],i=[],s=[],r=[];let n=0;const A=new Uint16Array(3),o=new Uint16Array(3),a=new Uint16Array(3),l=V.vec3(),c=V.vec3(),h=V.vec3(),u=V.vec3(),d=V.vec3(),f=V.vec3(),p=V.vec3();return function(g,m,_,b){!function(r,n){const A={};let o,a,l,c;const h=Math.pow(10,4);let u,d,f=0;for(u=0,d=r.length;u<d;u+=3)o=r[u],a=r[u+1],l=r[u+2],c=Math.round(o*h)+"_"+Math.round(a*h)+"_"+Math.round(l*h),void 0===A[c]&&(A[c]=f/3,e[f++]=o,e[f++]=a,e[f++]=l),t[u/3]=A[c];for(u=0,d=n.length;u<d;u++)s[u]=t[n[u]],i[s[u]]=n[u]}(g,m),function(t,i){n=0;for(let g=0,m=t;g<m;g+=3){const t=3*s[g],m=3*s[g+1],_=3*s[g+2];i?(A[0]=e[t],A[1]=e[t+1],A[2]=e[t+2],o[0]=e[m],o[1]=e[m+1],o[2]=e[m+2],a[0]=e[_],a[1]=e[_+1],a[2]=e[_+2],V.decompressPosition(A,i,l),V.decompressPosition(o,i,c),V.decompressPosition(a,i,h)):(l[0]=e[t],l[1]=e[t+1],l[2]=e[t+2],c[0]=e[m],c[1]=e[m+1],c[2]=e[m+2],h[0]=e[_],h[1]=e[_+1],h[2]=e[_+2]),V.subVec3(h,c,u),V.subVec3(l,c,d),V.cross3Vec3(u,d,f),V.normalizeVec3(f,p);const b=r[n]||(r[n]={normal:V.vec3()});b.normal[0]=p[0],b.normal[1]=p[1],b.normal[2]=p[2],n++}}(m.length,_);const B=[],y=Math.cos(V.DEGTORAD*b),w={};let v,C,M,E,F,U,x,I,T,P,S,D=!1;for(let e=0,t=m.length;e<t;e+=3){const t=e/3;for(let i=0;i<3;i++)v=s[e+i],C=s[e+(i+1)%3],M=Math.min(v,C),E=Math.max(v,C),F=M+","+E,void 0===w[F]?w[F]={index1:M,index2:E,face1:t,face2:void 0}:w[F].face2=t}for(F in w)U=w[F],void 0!==U.face2&&(x=r[U.face1].normal,I=r[U.face2].normal,T=V.dotVec3(x,I),T>y)||(P=i[U.index1],S=i[U.index2],(!D&&P>65535||S>65535)&&(D=!0),B.push(P),B.push(S));return D?new Uint32Array(B):new Uint16Array(B)}}();const Qe=function(){const e=V.mat4(),t=V.mat4();return function(i,s){s=s||V.mat4();const r=i[0],n=i[1],A=i[2],o=i[3]-r,a=i[4]-n,l=i[5]-A,c=65535;return V.identityMat4(e),V.translationMat4v(i,e),V.identityMat4(t),V.scalingMat4v([o/c,a/c,l/c],t),V.mulMat4(e,t,s),s}}();var Re=function(){const e=V.mat4(),t=V.mat4();return function(i,s,r){const n=new Uint16Array(i.length),A=new Float32Array([r[0]!==s[0]?65535/(r[0]-s[0]):0,r[1]!==s[1]?65535/(r[1]-s[1]):0,r[2]!==s[2]?65535/(r[2]-s[2]):0]);let o;for(o=0;o<i.length;o+=3)n[o+0]=Math.max(0,Math.min(65535,Math.floor((i[o+0]-s[0])*A[0]))),n[o+1]=Math.max(0,Math.min(65535,Math.floor((i[o+1]-s[1])*A[1]))),n[o+2]=Math.max(0,Math.min(65535,Math.floor((i[o+2]-s[2])*A[2])));V.identityMat4(e),V.translationMat4v(s,e),V.identityMat4(t),V.scalingMat4v([(r[0]-s[0])/65535,(r[1]-s[1])/65535,(r[2]-s[2])/65535],t);return{quantized:n,decodeMatrix:V.mulMat4(e,t,V.identityMat4())}}}();var Oe=function(){const e=V.mat3(),t=V.mat3();return function(i,s,r){const n=new Uint16Array(i.length),A=new Float32Array([65535/(r[0]-s[0]),65535/(r[1]-s[1])]);let o;for(o=0;o<i.length;o+=2)n[o+0]=Math.max(0,Math.min(65535,Math.floor((i[o+0]-s[0])*A[0]))),n[o+1]=Math.max(0,Math.min(65535,Math.floor((i[o+1]-s[1])*A[1])));V.identityMat3(e),V.translationMat3v(s,e),V.identityMat3(t),V.scalingMat3v([(r[0]-s[0])/65535,(r[1]-s[1])/65535],t);return{quantized:n,decodeMatrix:V.mulMat3(e,t,V.identityMat3())}}}();function Ve(e,t,i,s){let r=e[t]/(Math.abs(e[t])+Math.abs(e[t+1])+Math.abs(e[t+2])),n=e[t+1]/(Math.abs(e[t])+Math.abs(e[t+1])+Math.abs(e[t+2]));if(e[t+2]<0){let e=(1-Math.abs(n))*(r>=0?1:-1),t=(1-Math.abs(r))*(n>=0?1:-1);r=e,n=t}return new Int8Array([Math[i](127.5*r+(r<0?-1:0)),Math[s](127.5*n+(n<0?-1:0))])}function Le(e){let t=e[0],i=e[1];t/=t<0?127:128,i/=i<0?127:128;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 r=Math.sqrt(t*t+i*i+s*s);return[t/r,i/r,s/r]}function He(e,t,i){return e[t]*i[0]+e[t+1]*i[1]+e[t+2]*i[2]}const Ne={getPositionsBounds:function(e){const t=new Float32Array(3),i=new Float32Array(3);let s,r;for(s=0;s<3;s++)t[s]=Number.MAX_VALUE,i[s]=-Number.MAX_VALUE;for(s=0;s<e.length;s+=3)for(r=0;r<3;r++)t[r]=Math.min(t[r],e[s+r]),i[r]=Math.max(i[r],e[s+r]);return{min:t,max:i}},createPositionsDecodeMatrix:Qe,compressPositions:Re,compressPosition:function(e,t,i){const s=new Float32Array([t[3]!==t[0]?65535/(t[3]-t[0]):0,t[4]!==t[1]?65535/(t[4]-t[1]):0,t[5]!==t[2]?65535/(t[5]-t[2]):0]);i[0]=Math.max(0,Math.min(65535,Math.floor((e[0]-t[0])*s[0]))),i[1]=Math.max(0,Math.min(65535,Math.floor((e[1]-t[1])*s[1]))),i[2]=Math.max(0,Math.min(65535,Math.floor((e[2]-t[2])*s[2])))},decompressPositions:function(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},decompressPosition:function(e,t,i){return i[0]=e[0]*t[0]+t[12],i[1]=e[1]*t[5]+t[13],i[2]=e[2]*t[10]+t[14],i},decompressAABB:function(e,t,i=e){return i[0]=e[0]*t[0]+t[12],i[1]=e[1]*t[5]+t[13],i[2]=e[2]*t[10]+t[14],i[3]=e[3]*t[0]+t[12],i[4]=e[4]*t[5]+t[13],i[5]=e[5]*t[10]+t[14],i},getUVBounds:function(e){const t=new Float32Array(2),i=new Float32Array(2);let s,r;for(s=0;s<2;s++)t[s]=Number.MAX_VALUE,i[s]=-Number.MAX_VALUE;for(s=0;s<e.length;s+=2)for(r=0;r<2;r++)t[r]=Math.min(t[r],e[s+r]),i[r]=Math.max(i[r],e[s+r]);return{min:t,max:i}},compressUVs:Oe,decompressUVs:function(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},decompressUV:function(e,t,i){i[0]=e[0]*t[0]+t[6],i[1]=e[1]*t[4]+t[7]},compressNormals:function(e){const t=new Int8Array(e.length);let i,s,r,n,A;for(let o=0;o<e.length;o+=3)r=i=Ve(e,o,"floor","floor"),s=Le(i),n=A=He(e,o,s),i=Ve(e,o,"ceil","floor"),s=Le(i),n=He(e,o,s),n>A&&(r=i,A=n),i=Ve(e,o,"floor","ceil"),s=Le(i),n=He(e,o,s),n>A&&(r=i,A=n),i=Ve(e,o,"ceil","ceil"),s=Le(i),n=He(e,o,s),n>A&&(r=i,A=n),t[o]=r[0],t[o+1]=r[1];return t},decompressNormals:function(e,t){for(let i=0,s=0,r=e.length;i<r;i+=2){let r=e[i+0],n=e[i+1];r=(2*r+1)/255,n=(2*n+1)/255;const A=1-Math.abs(r)-Math.abs(n);A<0&&(r=(1-Math.abs(n))*(r>=0?1:-1),n=(1-Math.abs(r))*(n>=0?1:-1));const o=Math.sqrt(r*r+n*n+A*A);t[s+0]=r/o,t[s+1]=n/o,t[s+2]=A/o,s+=3}return t},decompressNormal:function(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 n=Math.sqrt(i*i+s*s+r*r);return t[0]=i/n,t[1]=s/n,t[2]=r/n,t}},Ge=G.memory,je=V.AABB3();class We extends Te{get type(){return"ReadableGeometry"}get isReadableGeometry(){return!0}constructor(e,t={}){super(e,t),this._state=new Se({compressGeometry:!!t.compressGeometry,primitive:null,primitiveName:null,positions:null,normals:null,colors:null,uv:null,indices:null,positionsDecodeMatrix:null,uvDecodeMatrix:null,positionsBuf:null,normalsBuf:null,colorsbuf:null,uvBuf:null,indicesBuf:null,hash:""}),this._numTriangles=0,this._edgeThreshold=t.edgeThreshold||10,this._edgeIndicesBuf=null,this._pickTrianglePositionsBuf=null,this._pickTriangleColorsBuf=null,this._aabbDirty=!0,this._boundingSphere=!0,this._aabb=null,this._aabbDirty=!0,this._obb=null,this._obbDirty=!0;const i=this._state,s=this.scene.canvas.gl;switch(t.primitive=t.primitive||"triangles",t.primitive){case"points":i.primitive=s.POINTS,i.primitiveName=t.primitive;break;case"lines":i.primitive=s.LINES,i.primitiveName=t.primitive;break;case"line-loop":i.primitive=s.LINE_LOOP,i.primitiveName=t.primitive;break;case"line-strip":i.primitive=s.LINE_STRIP,i.primitiveName=t.primitive;break;case"triangles":i.primitive=s.TRIANGLES,i.primitiveName=t.primitive;break;case"triangle-strip":i.primitive=s.TRIANGLE_STRIP,i.primitiveName=t.primitive;break;case"triangle-fan":i.primitive=s.TRIANGLE_FAN,i.primitiveName=t.primitive;break;default:this.error("Unsupported value for 'primitive': '"+t.primitive+"' - supported values are 'points', 'lines', 'line-loop', 'line-strip', 'triangles', 'triangle-strip' and 'triangle-fan'. Defaulting to 'triangles'."),i.primitive=s.TRIANGLES,i.primitiveName=t.primitive}if(t.positions)if(this._state.compressGeometry){const e=Ne.getPositionsBounds(t.positions),s=Ne.compressPositions(t.positions,e.min,e.max);i.positions=s.quantized,i.positionsDecodeMatrix=s.decodeMatrix}else i.positions=t.positions.constructor===Float32Array?t.positions:new Float32Array(t.positions);if(t.colors&&(i.colors=t.colors.constructor===Float32Array?t.colors:new Float32Array(t.colors)),t.uv)if(this._state.compressGeometry){const e=Ne.getUVBounds(t.uv),s=Ne.compressUVs(t.uv,e.min,e.max);i.uv=s.quantized,i.uvDecodeMatrix=s.decodeMatrix}else i.uv=t.uv.constructor===Float32Array?t.uv:new Float32Array(t.uv);if(t.normals&&(this._state.compressGeometry?i.normals=Ne.compressNormals(t.normals):i.normals=t.normals.constructor===Float32Array?t.normals:new Float32Array(t.normals)),t.indices&&(i.indices=t.indices.constructor===Uint32Array||t.indices.constructor===Uint16Array?t.indices:new Uint32Array(t.indices),"triangles"===this._state.primitiveName&&(this._numTriangles=t.indices.length/3)),this._buildHash(),Ge.meshes++,i.indices&&(i.indicesBuf=new De(s,s.ELEMENT_ARRAY_BUFFER,i.indices,i.indices.length,1,s.STATIC_DRAW),Ge.indices+=i.indicesBuf.numItems),i.positions&&(i.positionsBuf=new De(s,s.ARRAY_BUFFER,i.positions,i.positions.length,3,s.STATIC_DRAW),Ge.positions+=i.positionsBuf.numItems),i.normals){let e=i.compressGeometry;i.normalsBuf=new De(s,s.ARRAY_BUFFER,i.normals,i.normals.length,3,s.STATIC_DRAW,e),Ge.normals+=i.normalsBuf.numItems}i.colors&&(i.colorsBuf=new De(s,s.ARRAY_BUFFER,i.colors,i.colors.length,4,s.STATIC_DRAW),Ge.colors+=i.colorsBuf.numItems),i.uv&&(i.uvBuf=new De(s,s.ARRAY_BUFFER,i.uv,i.uv.length,2,s.STATIC_DRAW),Ge.uvs+=i.uvBuf.numItems)}_buildHash(){const e=this._state,t=["/g"];t.push("/"+e.primitive+";"),e.positions&&t.push("p"),e.colors&&t.push("c"),(e.normals||e.autoVertexNormals)&&t.push("n"),e.uv&&t.push("u"),e.compressGeometry&&t.push("cp"),t.push(";"),e.hash=t.join("")}_getEdgeIndices(){return this._edgeIndicesBuf||this._buildEdgeIndices(),this._edgeIndicesBuf}_getPickTrianglePositions(){return this._pickTrianglePositionsBuf||this._buildPickTriangleVBOs(),this._pickTrianglePositionsBuf}_getPickTriangleColors(){return this._pickTriangleColorsBuf||this._buildPickTriangleVBOs(),this._pickTriangleColorsBuf}_buildEdgeIndices(){const e=this._state;if(!e.positions||!e.indices)return;const t=this.scene.canvas.gl,i=ke(e.positions,e.indices,e.positionsDecodeMatrix,this._edgeThreshold);this._edgeIndicesBuf=new De(t,t.ELEMENT_ARRAY_BUFFER,i,i.length,1,t.STATIC_DRAW),Ge.indices+=this._edgeIndicesBuf.numItems}_buildPickTriangleVBOs(){const e=this._state;if(!e.positions||!e.indices)return;const t=this.scene.canvas.gl,i=V.buildPickTriangles(e.positions,e.indices,e.compressGeometry),s=i.positions,r=i.colors;this._pickTrianglePositionsBuf=new De(t,t.ARRAY_BUFFER,s,s.length,3,t.STATIC_DRAW),this._pickTriangleColorsBuf=new De(t,t.ARRAY_BUFFER,r,r.length,4,t.STATIC_DRAW,!0),Ge.positions+=this._pickTrianglePositionsBuf.numItems,Ge.colors+=this._pickTriangleColorsBuf.numItems}_buildPickVertexVBOs(){}get primitive(){return this._state.primitiveName}get compressGeometry(){return this._state.compressGeometry}get positions(){return this._state.positions?this._state.compressGeometry?(this._decompressedPositions||(this._decompressedPositions=new Float32Array(this._state.positions.length),Ne.decompressPositions(this._state.positions,this._state.positionsDecodeMatrix,this._decompressedPositions)),this._decompressedPositions):this._state.positions:null}set positions(e){const t=this._state,i=t.positions;if(i)if(i.length===e.length){if(this._state.compressGeometry){const i=Ne.getPositionsBounds(e),s=Ne.compressPositions(e,i.min,i.max);e=s.quantized,t.positionsDecodeMatrix=s.decodeMatrix}i.set(e),t.positionsBuf&&t.positionsBuf.setData(i),this._setAABBDirty(),this.glRedraw()}else this.error("can't update geometry positions - new positions are wrong length");else this.error("can't update geometry positions - geometry has no positions")}get normals(){if(this._state.normals){if(!this._state.compressGeometry)return this._state.normals;if(!this._decompressedNormals){const e=this._state.normals.length,t=e+e/2;this._decompressedNormals=new Float32Array(t),Ne.decompressNormals(this._state.normals,this._decompressedNormals)}return this._decompressedNormals}}set normals(e){if(this._state.compressGeometry)return void this.error("can't update geometry normals - quantized geometry is immutable");const t=this._state,i=t.normals;i?i.length===e.length?(i.set(e),t.normalsBuf&&t.normalsBuf.setData(i),this.glRedraw()):this.error("can't update geometry normals - new normals are wrong length"):this.error("can't update geometry normals - geometry has no normals")}get uv(){return this._state.uv?this._state.compressGeometry?(this._decompressedUV||(this._decompressedUV=new Float32Array(this._state.uv.length),Ne.decompressUVs(this._state.uv,this._state.uvDecodeMatrix,this._decompressedUV)),this._decompressedUV):this._state.uv:null}set uv(e){if(this._state.compressGeometry)return void this.error("can't update geometry UVs - quantized geometry is immutable");const t=this._state,i=t.uv;i?i.length===e.length?(i.set(e),t.uvBuf&&t.uvBuf.setData(i),this.glRedraw()):this.error("can't update geometry UVs - new UVs are wrong length"):this.error("can't update geometry UVs - geometry has no UVs")}get colors(){return this._state.colors}set colors(e){if(this._state.compressGeometry)return void this.error("can't update geometry colors - quantized geometry is immutable");const t=this._state,i=t.colors;i?i.length===e.length?(i.set(e),t.colorsBuf&&t.colorsBuf.setData(i),this.glRedraw()):this.error("can't update geometry colors - new colors are wrong length"):this.error("can't update geometry colors - geometry has no colors")}get indices(){return this._state.indices}get aabb(){return this._aabbDirty&&(this._aabb||(this._aabb=V.AABB3()),V.positions3ToAABB3(this._state.positions,this._aabb,this._state.positionsDecodeMatrix),this._aabbDirty=!1),this._aabb}get obb(){return this._obbDirty&&(this._obb||(this._obb=V.OBB3()),V.positions3ToAABB3(this._state.positions,je,this._state.positionsDecodeMatrix),V.AABB3ToOBB3(je,this._obb),this._obbDirty=!1),this._obb}_getMetrics(){if(!("_metrics"in this))switch(this._state.primitiveName){case"solid":case"surface":case"triangles":{const e=this._state.indices,t=this._state.positions,i=(i,s)=>{const r=3*e[i];for(let e=0;e<3;++e)s[e]=t[r+e];return s},s=[V.vec3(),V.vec3(),V.vec3(),V.vec3()];let r=0;const n=V.vec3([0,0,0]);for(let t=0;t<e.length;t+=3){const e=i(t,s[0]),A=i(t+1,s[1]),o=i(t+2,s[2]);V.addVec3(e,A,s[3]),V.addVec3(o,s[3],s[3]);const a=V.lenVec3(V.cross3Vec3(V.subVec3(A,e,s[1]),V.subVec3(o,e,s[2]),s[0]))/2;r+=a,V.mulVec3Scalar(s[3],a,s[3]),V.addVec3(n,s[3],n)}this._metrics={surfaceArea:r,centroid:V.mulVec3Scalar(n,1/r/3,n)};break}default:this._metrics={surfaceArea:0}}return this._metrics}get surfaceArea(){return this._getMetrics().surfaceArea}get centroid(){return this._getMetrics().centroid}get numTriangles(){return this._numTriangles}_setAABBDirty(){this._aabbDirty||(this._aabbDirty=!0,this._aabbDirty=!0,this._obbDirty=!0)}_getState(){return this._state}destroy(){super.destroy();const e=this._state;e.indicesBuf&&e.indicesBuf.destroy(),e.positionsBuf&&e.positionsBuf.destroy(),e.normalsBuf&&e.normalsBuf.destroy(),e.uvBuf&&e.uvBuf.destroy(),e.colorsBuf&&e.colorsBuf.destroy(),this._edgeIndicesBuf&&this._edgeIndicesBuf.destroy(),this._pickTrianglePositionsBuf&&this._pickTrianglePositionsBuf.destroy(),this._pickTriangleColorsBuf&&this._pickTriangleColorsBuf.destroy(),this._pickVertexPositionsBuf&&this._pickVertexPositionsBuf.destroy(),this._pickVertexColorsBuf&&this._pickVertexColorsBuf.destroy(),e.destroy(),Ge.meshes--}}const ze=G.memory,Xe=V.AABB3();class Ke extends Te{get type(){return"VBOGeometry"}get isVBOGeometry(){return!0}constructor(e,t={}){super(e,t),this._state=new Se({compressGeometry:!0,primitive:null,primitiveName:null,positionsDecodeMatrix:null,uvDecodeMatrix:null,positionsBuf:null,normalsBuf:null,colorsbuf:null,uvBuf:null,indicesBuf:null,hash:""}),this._numTriangles=0,this._edgeThreshold=t.edgeThreshold||10,this._aabb=null,this._obb=V.OBB3();const i=this._state,s=this.scene.canvas.gl;switch(t.primitive=t.primitive||"triangles",t.primitive){case"points":i.primitive=s.POINTS,i.primitiveName=t.primitive;break;case"lines":i.primitive=s.LINES,i.primitiveName=t.primitive;break;case"line-loop":i.primitive=s.LINE_LOOP,i.primitiveName=t.primitive;break;case"line-strip":i.primitive=s.LINE_STRIP,i.primitiveName=t.primitive;break;case"triangles":i.primitive=s.TRIANGLES,i.primitiveName=t.primitive;break;case"triangle-strip":i.primitive=s.TRIANGLE_STRIP,i.primitiveName=t.primitive;break;case"triangle-fan":i.primitive=s.TRIANGLE_FAN,i.primitiveName=t.primitive;break;default:this.error("Unsupported value for 'primitive': '"+t.primitive+"' - supported values are 'points', 'lines', 'line-loop', 'line-strip', 'triangles', 'triangle-strip' and 'triangle-fan'. Defaulting to 'triangles'."),i.primitive=s.TRIANGLES,i.primitiveName=t.primitive}if(t.positions)if(t.indices){var r;if(t.positionsDecodeMatrix);else{const e=Ne.getPositionsBounds(t.positions),n=Ne.compressPositions(t.positions,e.min,e.max);r=n.quantized,i.positionsDecodeMatrix=n.decodeMatrix,i.positionsBuf=new De(s,s.ARRAY_BUFFER,r,r.length,3,s.STATIC_DRAW),ze.positions+=i.positionsBuf.numItems,V.positions3ToAABB3(t.positions,this._aabb),V.positions3ToAABB3(r,Xe,i.positionsDecodeMatrix),V.AABB3ToOBB3(Xe,this._obb)}if(t.colors){const e=t.colors.constructor===Float32Array?t.colors:new Float32Array(t.colors);i.colorsBuf=new De(s,s.ARRAY_BUFFER,e,e.length,4,s.STATIC_DRAW),ze.colors+=i.colorsBuf.numItems}if(t.uv){const e=Ne.getUVBounds(t.uv),r=Ne.compressUVs(t.uv,e.min,e.max),n=r.quantized;i.uvDecodeMatrix=r.decodeMatrix,i.uvBuf=new De(s,s.ARRAY_BUFFER,n,n.length,2,s.STATIC_DRAW),ze.uvs+=i.uvBuf.numItems}if(t.normals){const e=Ne.compressNormals(t.normals);let r=i.compressGeometry;i.normalsBuf=new De(s,s.ARRAY_BUFFER,e,e.length,3,s.STATIC_DRAW,r),ze.normals+=i.normalsBuf.numItems}{const e=t.indices.constructor===Uint32Array||t.indices.constructor===Uint16Array?t.indices:new Uint32Array(t.indices);i.indicesBuf=new De(s,s.ELEMENT_ARRAY_BUFFER,e,e.length,1,s.STATIC_DRAW),ze.indices+=i.indicesBuf.numItems;const n=ke(r,e,i.positionsDecodeMatrix,this._edgeThreshold);this._edgeIndicesBuf=new De(s,s.ELEMENT_ARRAY_BUFFER,n,n.length,1,s.STATIC_DRAW),"triangles"===this._state.primitiveName&&(this._numTriangles=t.indices.length/3)}this._buildHash(),ze.meshes++}else this.error("Config expected: indices");else this.error("Config expected: positions")}_buildHash(){const e=this._state,t=["/g"];t.push("/"+e.primitive+";"),e.positionsBuf&&t.push("p"),e.colorsBuf&&t.push("c"),(e.normalsBuf||e.autoVertexNormals)&&t.push("n"),e.uvBuf&&t.push("u"),t.push("cp"),t.push(";"),e.hash=t.join("")}_getEdgeIndices(){return this._edgeIndicesBuf}get primitive(){return this._state.primitiveName}get aabb(){return this._aabb}get obb(){return this._obb}get numTriangles(){return this._numTriangles}_getState(){return this._state}destroy(){super.destroy();const e=this._state;e.indicesBuf&&e.indicesBuf.destroy(),e.positionsBuf&&e.positionsBuf.destroy(),e.normalsBuf&&e.normalsBuf.destroy(),e.uvBuf&&e.uvBuf.destroy(),e.colorsBuf&&e.colorsBuf.destroy(),this._edgeIndicesBuf&&this._edgeIndicesBuf.destroy(),e.destroy(),ze.meshes--}}var Ze={};function Je(e,t={}){return new Promise((function(i,s){t.src||(console.error("load3DSGeometry: Parameter expected: src"),s());var r=e.canvas.spinner;r.processes++,X.loadArraybuffer(t.src,(function(e){e.byteLength||(console.error("load3DSGeometry: no data loaded"),r.processes--,s());var n=Ze.parse.from3DS(e).edit.objects[0].mesh,A=n.vertices,o=n.uvt,a=n.indices;r.processes--,i(X.apply(t,{primitive:"triangles",positions:A,normals:null,uv:o,indices:a}))}),(function(e){console.error("load3DSGeometry: "+e),r.processes--,s()}))}))}function Ye(e,t={}){return new Promise((function(i,s){t.src||(console.error("loadOBJGeometry: Parameter expected: src"),s());var r=e.canvas.spinner;r.processes++,X.loadArraybuffer(t.src,(function(e){e.byteLength||(console.error("loadOBJGeometry: no data loaded"),r.processes--,s());for(var n=Ze.parse.fromOBJ(e),A=Ze.edit.unwrap(n.i_verts,n.c_verts,3),o=Ze.edit.unwrap(n.i_norms,n.c_norms,3),a=Ze.edit.unwrap(n.i_uvt,n.c_uvt,2),l=new Int32Array(n.i_verts.length),c=0;c<n.i_verts.length;c++)l[c]=c;r.processes--,i(X.apply(t,{primitive:"triangles",positions:A,normals:o.length>0?o:null,autoNormals:0===o.length,uv:a,indices:l}))}),(function(e){console.error("loadOBJGeometry: "+e),r.processes--,s()}))}))}function $e(e={}){let t=e.xSize||1;t<0&&(console.error("negative xSize not allowed - will invert"),t*=-1);let i=e.ySize||1;i<0&&(console.error("negative ySize not allowed - will invert"),i*=-1);let s=e.zSize||1;s<0&&(console.error("negative zSize not allowed - will invert"),s*=-1);const r=e.center,n=r?r[0]:0,A=r?r[1]:0,o=r?r[2]:0,a=-t+n,l=-i+A,c=-s+o,h=t+n,u=i+A,d=s+o;return X.apply(e,{positions:[h,u,d,a,u,d,a,l,d,h,l,d,h,u,d,h,l,d,h,l,c,h,u,c,h,u,d,h,u,c,a,u,c,a,u,d,a,u,d,a,u,c,a,l,c,a,l,d,a,l,c,h,l,c,h,l,d,a,l,d,h,l,c,a,l,c,a,u,c,h,u,c],normals:[0,0,1,0,0,1,0,0,1,0,0,1,1,0,0,1,0,0,1,0,0,1,0,0,0,1,0,0,1,0,0,1,0,0,1,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,0,-1,0,0,-1,0,0,-1,0,0,-1],uv:[1,0,0,0,0,1,1,1,0,0,0,1,1,1,1,0,1,1,1,0,0,0,0,1,1,0,0,0,0,1,1,1,0,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0],indices:[0,1,2,0,2,3,4,5,6,4,6,7,8,9,10,8,10,11,12,13,14,12,14,15,16,17,18,16,18,19,20,21,22,20,22,23]})}function qe(e={}){let t=e.xSize||1;t<0&&(console.error("negative xSize not allowed - will invert"),t*=-1);let i=e.ySize||1;i<0&&(console.error("negative ySize not allowed - will invert"),i*=-1);let s=e.zSize||1;s<0&&(console.error("negative zSize not allowed - will invert"),s*=-1);const r=e.center,n=r?r[0]:0,A=r?r[1]:0,o=r?r[2]:0,a=-t+n,l=-i+A,c=-s+o,h=t+n,u=i+A,d=s+o;return X.apply(e,{primitive:"lines",positions:[a,l,c,a,l,d,a,u,c,a,u,d,h,l,c,h,l,d,h,u,c,h,u,d],indices:[0,1,1,3,3,2,2,0,4,5,5,7,7,6,6,4,0,4,1,5,2,6,3,7]})}function et(e={}){return qe({id:e.id,center:[(e.aabb[0]+e.aabb[3])/2,(e.aabb[1]+e.aabb[4])/2,(e.aabb[2]+e.aabb[5])/2],xSize:Math.abs(e.aabb[3]-e.aabb[0])/2,ySize:Math.abs(e.aabb[4]-e.aabb[1])/2,zSize:Math.abs(e.aabb[5]-e.aabb[2])/2})}function tt(e={}){let t=e.radiusTop||1;t<0&&(console.error("negative radiusTop not allowed - will invert"),t*=-1);let i=e.radiusBottom||1;i<0&&(console.error("negative radiusBottom not allowed - will invert"),i*=-1);let s=e.height||1;s<0&&(console.error("negative height not allowed - will invert"),s*=-1);let r=e.radialSegments||32;r<0&&(console.error("negative radialSegments not allowed - will invert"),r*=-1),r<3&&(r=3);let n=e.heightSegments||1;n<0&&(console.error("negative heightSegments not allowed - will invert"),n*=-1),n<1&&(n=1);const A=!!e.openEnded;let o=e.center;const a=o?o[0]:0,l=o?o[1]:0,c=o?o[2]:0,h=s/2,u=s/n,d=2*Math.PI/r,f=1/r,p=(t-i)/n,g=[],m=[],_=[],b=[];let B,y,w,v,C,M,E,F,U,x,I;const T=(90-180*Math.atan(s/(i-t))/Math.PI)/90;for(B=0;B<=n;B++)for(C=t-B*p,M=h-B*u,y=0;y<=r;y++)w=Math.sin(y*d),v=Math.cos(y*d),m.push(C*w),m.push(T),m.push(C*v),_.push(y*f),_.push(1*B/n),g.push(C*w+a),g.push(M+l),g.push(C*v+c);for(B=0;B<n;B++)for(y=0;y<=r;y++)E=B*(r+1)+y,F=E+r,b.push(E),b.push(F),b.push(F+1),b.push(E),b.push(F+1),b.push(E+1);if(!A&&t>0){for(U=g.length/3,m.push(0),m.push(1),m.push(0),_.push(.5),_.push(.5),g.push(0+a),g.push(h+l),g.push(0+c),y=0;y<=r;y++)w=Math.sin(y*d),v=Math.cos(y*d),x=.5*Math.sin(y*d)+.5,I=.5*Math.cos(y*d)+.5,m.push(t*w),m.push(1),m.push(t*v),_.push(x),_.push(I),g.push(t*w+a),g.push(h+l),g.push(t*v+c);for(y=0;y<r;y++)o=U,E=U+1+y,b.push(E),b.push(E+1),b.push(o)}if(!A&&i>0){for(U=g.length/3,m.push(0),m.push(-1),m.push(0),_.push(.5),_.push(.5),g.push(0+a),g.push(0-h+l),g.push(0+c),y=0;y<=r;y++)w=Math.sin(y*d),v=Math.cos(y*d),x=.5*Math.sin(y*d)+.5,I=.5*Math.cos(y*d)+.5,m.push(i*w),m.push(-1),m.push(i*v),_.push(x),_.push(I),g.push(i*w+a),g.push(0-h+l),g.push(i*v+c);for(y=0;y<r;y++)o=U,E=U+1+y,b.push(o),b.push(E+1),b.push(E)}return X.apply(e,{positions:g,normals:m,uv:_,indices:b})}function it(e={}){let t=e.size||1;t<0&&(console.error("negative size not allowed - will invert"),t*=-1);let i=e.divisions||1;i<0&&(console.error("negative divisions not allowed - will invert"),i*=-1),i<1&&(i=1),t=t||10,i=i||10;const s=t/i,r=t/2,n=[],A=[];let o=0;for(let e=0,t=-r;e<=i;e++,t+=s)n.push(-r),n.push(0),n.push(t),n.push(r),n.push(0),n.push(t),n.push(t),n.push(0),n.push(-r),n.push(t),n.push(0),n.push(r),A.push(o++),A.push(o++),A.push(o++),A.push(o++);return X.apply(e,{primitive:"lines",positions:n,indices:A})}function st(e={}){let t=e.xSize||1;t<0&&(console.error("negative xSize not allowed - will invert"),t*=-1);let i=e.zSize||1;i<0&&(console.error("negative zSize not allowed - will invert"),i*=-1);let s=e.xSegments||1;s<0&&(console.error("negative xSegments not allowed - will invert"),s*=-1),s<1&&(s=1);let r=e.xSegments||1;r<0&&(console.error("negative zSegments not allowed - will invert"),r*=-1),r<1&&(r=1);const n=e.center,A=n?n[0]:0,o=n?n[1]:0,a=n?n[2]:0,l=t/2,c=i/2,h=Math.floor(s)||1,u=Math.floor(r)||1,d=h+1,f=u+1,p=t/h,g=i/u,m=new Float32Array(d*f*3),_=new Float32Array(d*f*3),b=new Float32Array(d*f*2);let B,y,w,v,C,M,E,F=0,U=0;for(B=0;B<f;B++){const e=B*g-c;for(y=0;y<d;y++)w=y*p-l,m[F]=w+A,m[F+1]=o,m[F+2]=-e+a,_[F+1]=1,b[U]=y/h,b[U+1]=(u-B)/u,F+=3,U+=2}F=0;const x=new(m.length/3>65535?Uint32Array:Uint16Array)(h*u*6);for(B=0;B<u;B++)for(y=0;y<h;y++)v=y+d*B,C=y+d*(B+1),M=y+1+d*(B+1),E=y+1+d*B,x[F]=E,x[F+1]=C,x[F+2]=v,x[F+3]=E,x[F+4]=M,x[F+5]=C,F+=6;return X.apply(e,{positions:m,normals:_,uv:b,indices:x})}function rt(e={}){const t=e.lod||1,i=e.center?e.center[0]:0,s=e.center?e.center[1]:0,r=e.center?e.center[2]:0;let n=e.radius||1;n<0&&(console.error("negative radius not allowed - will invert"),n*=-1);let A=e.heightSegments||18;A<0&&(console.error("negative heightSegments not allowed - will invert"),A*=-1),A=Math.floor(t*A),A<18&&(A=18);let o=e.widthSegments||18;o<0&&(console.error("negative widthSegments not allowed - will invert"),o*=-1),o=Math.floor(t*o),o<18&&(o=18);const a=[],l=[],c=[],h=[];let u,d,f,p,g,m,_,b,B,y,w,v,C,M,E;for(u=0;u<=A;u++)for(f=u*Math.PI/A,p=Math.sin(f),g=Math.cos(f),d=0;d<=o;d++)m=2*d*Math.PI/o,_=Math.sin(m),b=Math.cos(m),B=b*p,y=g,w=_*p,v=1-d/o,C=u/A,l.push(B),l.push(y),l.push(w),c.push(v),c.push(C),a.push(i+n*B),a.push(s+n*y),a.push(r+n*w);for(u=0;u<A;u++)for(d=0;d<o;d++)M=u*(o+1)+d,E=M+o+1,h.push(M+1),h.push(E+1),h.push(E),h.push(M+1),h.push(E),h.push(M);return X.apply(e,{positions:a,normals:l,uv:c,indices:h})}function nt(e={}){let t=e.radius||1;t<0&&(console.error("negative radius not allowed - will invert"),t*=-1),t*=.5;let i=e.tube||.3;i<0&&(console.error("negative tube not allowed - will invert"),i*=-1);let s=e.radialSegments||32;s<0&&(console.error("negative radialSegments not allowed - will invert"),s*=-1),s<4&&(s=4);let r=e.tubeSegments||24;r<0&&(console.error("negative tubeSegments not allowed - will invert"),r*=-1),r<4&&(r=4);let n=e.arc||2*Math.PI;n<0&&(console.warn("negative arc not allowed - will invert"),n*=-1),n>360&&(n=360);const A=e.center;let o=A?A[0]:0,a=A?A[1]:0;const l=A?A[2]:0,c=[],h=[],u=[],d=[];let f,p,g,m,_,b,B,y,w,v,C,M;for(y=0;y<=r;y++)for(B=0;B<=s;B++)f=B/s*n,p=.785398+y/r*Math.PI*2,o=t*Math.cos(f),a=t*Math.sin(f),g=(t+i*Math.cos(p))*Math.cos(f),m=(t+i*Math.cos(p))*Math.sin(f),_=i*Math.sin(p),c.push(g+o),c.push(m+a),c.push(_+l),u.push(1-B/s),u.push(y/r),b=V.normalizeVec3(V.subVec3([g,m,_],[o,a,l],[]),[]),h.push(b[0]),h.push(b[1]),h.push(b[2]);for(y=1;y<=r;y++)for(B=1;B<=s;B++)w=(s+1)*y+B-1,v=(s+1)*(y-1)+B-1,C=(s+1)*(y-1)+B,M=(s+1)*y+B,d.push(w),d.push(v),d.push(C),d.push(C),d.push(M),d.push(w);return X.apply(e,{positions:c,normals:h,uv:u,indices:d})}Ze.load=function(e,t){var i=new XMLHttpRequest;i.open("GET",e,!0),i.responseType="arraybuffer",i.onload=function(e){t(e.target.response)},i.send()},Ze.save=function(e,t){var i="data:application/octet-stream;base64,"+btoa(Ze.parse._buffToStr(e));window.location.href=i},Ze.clone=function(e){return JSON.parse(JSON.stringify(e))},Ze.bin={},Ze.bin.f=new Float32Array(1),Ze.bin.fb=new Uint8Array(Ze.bin.f.buffer),Ze.bin.rf=function(e,t){for(var i=Ze.bin.f,s=Ze.bin.fb,r=0;r<4;r++)s[r]=e[t+r];return i[0]},Ze.bin.rsl=function(e,t){return e[t]|e[t+1]<<8},Ze.bin.ril=function(e,t){return e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24},Ze.bin.rASCII0=function(e,t){for(var i="";0!=e[t];)i+=String.fromCharCode(e[t++]);return i},Ze.bin.wf=function(e,t,i){new Float32Array(e.buffer,t,1)[0]=i},Ze.bin.wsl=function(e,t,i){e[t]=i,e[t+1]=i>>8},Ze.bin.wil=function(e,t,i){e[t]=i,e[t+1]=i>>8,e[t+2]=i>>16,e[t+3]},Ze.parse={},Ze.parse._buffToStr=function(e){for(var t=new Uint8Array(e),i="",s=0;s<t.length;s++)i=i.concat(String.fromCharCode(t[s]));return i},Ze.parse._strToBuff=function(e){for(var t=new ArrayBuffer(e.length),i=new Uint8Array(t),s=0;s<e.length;s++)i[s]=e.charCodeAt(s);return t},Ze.parse._readLine=function(e,t){for(var i="";10!=e[t];)i+=String.fromCharCode(e[t++]);return i},Ze.parse.fromJSON=function(e){return JSON.parse(Ze.parse._buffToStr(e))},Ze.parse.toJSON=function(e){var t=JSON.stringify(e);return Ze.parse._strToBuff(t)},Ze.parse.fromOBJ=function(e){for(var t={groups:{},c_verts:[],c_uvt:[],c_norms:[],i_verts:[],i_uvt:[],i_norms:[]},i={from:0,to:0},s=0,r=new Uint8Array(e);s<r.length;){var n=Ze.parse._readLine(r,s);s+=n.length+1;var A=(n=(n=n.replace(/ +(?= )/g,"")).replace(/(^\s+|\s+$)/g,"")).split(" ");if("g"==A[0]&&(i.to=t.i_verts.length,null==t.groups[A[1]]&&(t.groups[A[1]]={from:t.i_verts.length,to:0}),i=t.groups[A[1]]),"v"==A[0]){var o=parseFloat(A[1]),a=parseFloat(A[2]),l=parseFloat(A[3]);t.c_verts.push(o,a,l)}if("vt"==A[0]){o=parseFloat(A[1]),a=1-parseFloat(A[2]);t.c_uvt.push(o,a)}if("vn"==A[0]){o=parseFloat(A[1]),a=parseFloat(A[2]),l=parseFloat(A[3]);t.c_norms.push(o,a,l)}if("f"==A[0]){var c=A[1].split("/"),h=A[2].split("/"),u=A[3].split("/"),d=parseInt(c[0])-1,f=parseInt(h[0])-1,p=parseInt(u[0])-1,g=parseInt(c[1])-1,m=parseInt(h[1])-1,_=parseInt(u[1])-1,b=parseInt(c[2])-1,B=parseInt(h[2])-1,y=parseInt(u[2])-1,w=t.c_verts.length/3,v=t.c_uvt.length/2,C=t.c_norms.length/3;if(d<0&&(d=w+d+1),f<0&&(f=w+f+1),p<0&&(p=w+p+1),g<0&&(g=v+g+1),m<0&&(m=v+m+1),_<0&&(_=v+_+1),b<0&&(b=C+b+1),B<0&&(B=C+B+1),y<0&&(y=C+y+1),t.i_verts.push(d,f,p),t.i_uvt.push(g,m,_),t.i_norms.push(b,B,y),5==A.length){var M=A[4].split("/"),E=parseInt(M[0])-1,F=parseInt(M[1])-1,U=parseInt(M[2])-1;E<0&&(E=w+E+1),F<0&&(F=v+F+1),U<0&&(U=C+U+1),t.i_verts.push(d,p,E),t.i_uvt.push(g,_,F),t.i_norms.push(b,y,U)}}}return i.to=t.i_verts.length,t},Ze.parse.fromMD2=function(e){e=new Uint8Array(e);var t={},i={};i.ident=Ze.bin.ril(e,0),i.version=Ze.bin.ril(e,4),i.skinwidth=Ze.bin.ril(e,8),i.skinheight=Ze.bin.ril(e,12),i.framesize=Ze.bin.ril(e,16),i.num_skins=Ze.bin.ril(e,20),i.num_vertices=Ze.bin.ril(e,24),i.num_st=Ze.bin.ril(e,28),i.num_tris=Ze.bin.ril(e,32),i.num_glcmds=Ze.bin.ril(e,36),i.num_frames=Ze.bin.ril(e,40),i.offset_skins=Ze.bin.ril(e,44),i.offset_st=Ze.bin.ril(e,48),i.offset_tris=Ze.bin.ril(e,52),i.offset_frames=Ze.bin.ril(e,56),i.offset_glcmds=Ze.bin.ril(e,60),i.offset_end=Ze.bin.ril(e,64);var s=i.offset_st;t.c_uvt=[];for(var r=0;r<i.num_st;r++){var n=Ze.bin.rsl(e,s)/i.skinwidth,A=Ze.bin.rsl(e,s+2)/i.skinheight;t.c_uvt.push(n,A),s+=4}s=i.offset_tris;var o=[],a=[];t.i_verts=o,t.i_uvt=a;for(r=0;r<i.num_tris;r++)o.push(Ze.bin.rsl(e,s),Ze.bin.rsl(e,s+2),Ze.bin.rsl(e,s+4)),a.push(Ze.bin.rsl(e,s+6),Ze.bin.rsl(e,s+8),Ze.bin.rsl(e,s+10)),s+=12;s=i.offset_skins;t.skins=[];for(r=0;r<i.num_skins;r++)t.skins.push(Ze.bin.rASCII0(e,s)),s+=64;s=i.offset_frames;t.frames=[];var l=Ze.parse.fromMD2._normals;for(r=0;r<i.num_frames;r++){var c={},h=Ze.bin.rf(e,s),u=Ze.bin.rf(e,s+4),d=Ze.bin.rf(e,s+8);s+=12;var f=Ze.bin.rf(e,s),p=Ze.bin.rf(e,s+4),g=Ze.bin.rf(e,s+8);s+=12,c.name=Ze.bin.rASCII0(e,s),s+=16,c.verts=[],c.norms=[];for(var m=0;m<i.num_vertices;m++)c.verts.push(e[s]*h+f,e[s+1]*u+p,e[s+2]*d+g),c.norms.push(l[3*e[s+3]],l[3*e[s+3]+1],l[3*e[s+3]+2]),s+=4;t.frames.push(c)}return t},Ze.parse.fromMD2._normals=[-.525731,0,.850651,-.442863,.238856,.864188,-.295242,0,.955423,-.309017,.5,.809017,-.16246,.262866,.951056,0,0,1,0,.850651,.525731,-.147621,.716567,.681718,.147621,.716567,.681718,0,.525731,.850651,.309017,.5,.809017,.525731,0,.850651,.295242,0,.955423,.442863,.238856,.864188,.16246,.262866,.951056,-.681718,.147621,.716567,-.809017,.309017,.5,-.587785,.425325,.688191,-.850651,.525731,0,-.864188,.442863,.238856,-.716567,.681718,.147621,-.688191,.587785,.425325,-.5,.809017,.309017,-.238856,.864188,.442863,-.425325,.688191,.587785,-.716567,.681718,-.147621,-.5,.809017,-.309017,-.525731,.850651,0,0,.850651,-.525731,-.238856,.864188,-.442863,0,.955423,-.295242,-.262866,.951056,-.16246,0,1,0,0,.955423,.295242,-.262866,.951056,.16246,.238856,.864188,.442863,.262866,.951056,.16246,.5,.809017,.309017,.238856,.864188,-.442863,.262866,.951056,-.16246,.5,.809017,-.309017,.850651,.525731,0,.716567,.681718,.147621,.716567,.681718,-.147621,.525731,.850651,0,.425325,.688191,.587785,.864188,.442863,.238856,.688191,.587785,.425325,.809017,.309017,.5,.681718,.147621,.716567,.587785,.425325,.688191,.955423,.295242,0,1,0,0,.951056,.16246,.262866,.850651,-.525731,0,.955423,-.295242,0,.864188,-.442863,.238856,.951056,-.16246,.262866,.809017,-.309017,.5,.681718,-.147621,.716567,.850651,0,.525731,.864188,.442863,-.238856,.809017,.309017,-.5,.951056,.16246,-.262866,.525731,0,-.850651,.681718,.147621,-.716567,.681718,-.147621,-.716567,.850651,0,-.525731,.809017,-.309017,-.5,.864188,-.442863,-.238856,.951056,-.16246,-.262866,.147621,.716567,-.681718,.309017,.5,-.809017,.425325,.688191,-.587785,.442863,.238856,-.864188,.587785,.425325,-.688191,.688191,.587785,-.425325,-.147621,.716567,-.681718,-.309017,.5,-.809017,0,.525731,-.850651,-.525731,0,-.850651,-.442863,.238856,-.864188,-.295242,0,-.955423,-.16246,.262866,-.951056,0,0,-1,.295242,0,-.955423,.16246,.262866,-.951056,-.442863,-.238856,-.864188,-.309017,-.5,-.809017,-.16246,-.262866,-.951056,0,-.850651,-.525731,-.147621,-.716567,-.681718,.147621,-.716567,-.681718,0,-.525731,-.850651,.309017,-.5,-.809017,.442863,-.238856,-.864188,.16246,-.262866,-.951056,.238856,-.864188,-.442863,.5,-.809017,-.309017,.425325,-.688191,-.587785,.716567,-.681718,-.147621,.688191,-.587785,-.425325,.587785,-.425325,-.688191,0,-.955423,-.295242,0,-1,0,.262866,-.951056,-.16246,0,-.850651,.525731,0,-.955423,.295242,.238856,-.864188,.442863,.262866,-.951056,.16246,.5,-.809017,.309017,.716567,-.681718,.147621,.525731,-.850651,0,-.238856,-.864188,-.442863,-.5,-.809017,-.309017,-.262866,-.951056,-.16246,-.850651,-.525731,0,-.716567,-.681718,-.147621,-.716567,-.681718,.147621,-.525731,-.850651,0,-.5,-.809017,.309017,-.238856,-.864188,.442863,-.262866,-.951056,.16246,-.864188,-.442863,.238856,-.809017,-.309017,.5,-.688191,-.587785,.425325,-.681718,-.147621,.716567,-.442863,-.238856,.864188,-.587785,-.425325,.688191,-.309017,-.5,.809017,-.147621,-.716567,.681718,-.425325,-.688191,.587785,-.16246,-.262866,.951056,.442863,-.238856,.864188,.16246,-.262866,.951056,.309017,-.5,.809017,.147621,-.716567,.681718,0,-.525731,.850651,.425325,-.688191,.587785,.587785,-.425325,.688191,.688191,-.587785,.425325,-.955423,.295242,0,-.951056,.16246,.262866,-1,0,0,-.850651,0,.525731,-.955423,-.295242,0,-.951056,-.16246,.262866,-.864188,.442863,-.238856,-.951056,.16246,-.262866,-.809017,.309017,-.5,-.864188,-.442863,-.238856,-.951056,-.16246,-.262866,-.809017,-.309017,-.5,-.681718,.147621,-.716567,-.681718,-.147621,-.716567,-.850651,0,-.525731,-.688191,.587785,-.425325,-.587785,.425325,-.688191,-.425325,.688191,-.587785,-.425325,-.688191,-.587785,-.587785,-.425325,-.688191,-.688191,-.587785,-.425325],Ze.parse.fromCollada=function(e){var t=Ze.parse._buffToStr(e),i=(new DOMParser).parseFromString(t,"text/xml"),s={},r=(i=i.childNodes[0]).getElementsByTagName("asset")[0],n=i.getElementsByTagName("library_geometries")[0],A=i.getElementsByTagName("library_images")[0],o=i.getElementsByTagName("library_materials")[0],a=i.getElementsByTagName("library_effects")[0];return r&&(s.asset=Ze.parse.fromCollada._asset(r)),n&&(s.geometries=Ze.parse.fromCollada._libGeometries(n)),A&&(s.images=Ze.parse.fromCollada._libImages(A)),o&&(s.materials=Ze.parse.fromCollada._libMaterials(o)),a&&(s.effects=Ze.parse.fromCollada._libEffects(a)),s},Ze.parse.fromCollada._asset=function(e){return{created:e.getElementsByTagName("created")[0].textContent,modified:e.getElementsByTagName("modified")[0].textContent,up_axis:e.getElementsByTagName("up_axis")[0].textContent}},Ze.parse.fromCollada._libGeometries=function(e){e=e.getElementsByTagName("geometry");for(var t=[],i=0;i<e.length;i++){var s=e[i],r=Ze.parse.fromCollada._getMesh(s.getElementsByTagName("mesh")[0]);t.push(r)}return t},Ze.parse.fromCollada._getMesh=function(e){for(var t={},i=e.getElementsByTagName("source"),s=t.sources={},r=0;r<i.length;r++){for(var n=i[r].getElementsByTagName("float_array")[0].textContent.split(" "),A=n.length-(""==n[n.length-1]?1:0),o=new Array(A),a=0;a<A;a++)o[a]=parseFloat(n[a]);s[i[r].getAttribute("id")]=o}t.triangles=[];var l=e.getElementsByTagName("triangles");if(null==l)return t;for(r=0;r<l.length;r++){var c={},h=l[r];c.material=h.getAttribute("material");var u=h.getElementsByTagName("input"),d=[];for(a=0;a<u.length;a++){var f=u[a];o=[];d[parseInt(f.getAttribute("offset"))]=o;var p=f.getAttribute("semantic");c["s_"+p]="VERTEX"==p?e.getElementsByTagName("vertices")[0].getElementsByTagName("input")[0].getAttribute("source").substring(1):f.getAttribute("source").substring(1),c["i_"+p]=o,s[c["s_"+p]]}var g=h.getElementsByTagName("p")[0].textContent.split(" "),m=3*Math.floor(g.length/3);for(a=0;a<m;a++)d[a%u.length].push(parseInt(g[a]));t.triangles.push(c)}return t},Ze.parse.fromCollada._libImages=function(e){e=e.getElementsByTagName("image");for(var t={},i=0;i<e.length;i++)t[e[i].getAttribute("id")]=e[i].getElementsByTagName("init_from")[0].textContent;return t},Ze.parse.fromCollada._libMaterials=function(e){e=e.getElementsByTagName("material");for(var t={},i=0;i<e.length;i++)t[e[i].getAttribute("name")]=e[i].getElementsByTagName("instance_effect")[0].getAttribute("url").substring(1);return t},Ze.parse.fromCollada._libEffects=function(e){e=e.getElementsByTagName("effect");for(var t={},i=0;i<e.length;i++){for(var s={},r=e[i].getElementsByTagName("newparam"),n=0;n<r.length;n++){var A=r[n].getElementsByTagName("surface")[0];A&&(s.surface=A.getElementsByTagName("init_from")[0].textContent)}t[e[i].getAttribute("id")]=s}return t},Ze.parse.from3DS=function(e){e=new Uint8Array(e);var t={};if(19789!=Ze.bin.rsl(e,0))return null;for(var i=Ze.bin.ril(e,2),s=6;s<i;){var r=Ze.bin.rsl(e,s),n=Ze.bin.ril(e,s+2);15677==r&&(t.edit=Ze.parse.from3DS._edit3ds(e,s,n)),45056==r&&(t.keyf=Ze.parse.from3DS._keyf3ds(e,s,n)),s+=n}return t},Ze.parse.from3DS._edit3ds=function(e,t,i){for(var s={},r=t+6;r<t+i;){var n=Ze.bin.rsl(e,r),A=Ze.bin.ril(e,r+2);16384==n&&(null==s.objects&&(s.objects=[]),s.objects.push(Ze.parse.from3DS._edit_object(e,r,A))),r+=A}return s},Ze.parse.from3DS._keyf3ds=function(e,t,i){for(var s={},r=t+6;r<t+i;){var n=Ze.bin.rsl(e,r),A=Ze.bin.ril(e,r+2);45058==n&&(null==s.desc&&(s.desc=[]),s.desc.push(Ze.parse.from3DS._keyf_objdes(e,r,A))),r+=A}return s},Ze.parse.from3DS._keyf_objdes=function(e,t,i){for(var s={},r=t+6;r<t+i;){var n=Ze.bin.rsl(e,r),A=Ze.bin.ril(e,r+2);45072==n&&(s.hierarchy=Ze.parse.from3DS._keyf_objhierarch(e,r,A)),45073==n&&(s.dummy_name=Ze.bin.rASCII0(e,r+6)),r+=A}return s},Ze.parse.from3DS._keyf_objhierarch=function(e,t,i){var s={},r=t+6;return s.name=Ze.bin.rASCII0(e,r),r+=s.name.length+1,s.hierarchy=Ze.bin.rsl(e,r+4),s},Ze.parse.from3DS._edit_object=function(e,t,i){var s={},r=t+6;for(s.name=Ze.bin.rASCII0(e,r),r+=s.name.length+1;r<t+i;){var n=Ze.bin.rsl(e,r),A=Ze.bin.ril(e,r+2);16640==n&&(s.mesh=Ze.parse.from3DS._obj_trimesh(e,r,A)),r+=A}return s},Ze.parse.from3DS._obj_trimesh=function(e,t,i){for(var s={},r=t+6;r<t+i;){var n=Ze.bin.rsl(e,r),A=Ze.bin.ril(e,r+2);16656==n&&(s.vertices=Ze.parse.from3DS._tri_vertexl(e,r,A)),16672==n&&(s.indices=Ze.parse.from3DS._tri_facel1(e,r,A)),16704==n&&(s.uvt=Ze.parse.from3DS._tri_mappingcoors(e,r,A)),16736==n&&(s.local=Ze.parse.from3DS._tri_local(e,r,A)),r+=A}return s},Ze.parse.from3DS._tri_vertexl=function(e,t,i){var s=[],r=t+6,n=Ze.bin.rsl(e,r);r+=2;for(var A=0;A<n;A++)s.push(Ze.bin.rf(e,r)),s.push(Ze.bin.rf(e,r+4)),s.push(Ze.bin.rf(e,r+8)),r+=12;return s},Ze.parse.from3DS._tri_facel1=function(e,t,i){var s=[],r=t+6,n=Ze.bin.rsl(e,r);r+=2;for(var A=0;A<n;A++)s.push(Ze.bin.rsl(e,r)),s.push(Ze.bin.rsl(e,r+2)),s.push(Ze.bin.rsl(e,r+4)),r+=8;return s},Ze.parse.from3DS._tri_mappingcoors=function(e,t,i){var s=[],r=t+6,n=Ze.bin.rsl(e,r);r+=2;for(var A=0;A<n;A++)s.push(Ze.bin.rf(e,r)),s.push(1-Ze.bin.rf(e,r+4)),r+=8;return s},Ze.parse.from3DS._tri_local=function(e,t,i){var s={},r=t+6;return s.X=[Ze.bin.rf(e,r),Ze.bin.rf(e,r+4),Ze.bin.rf(e,r+8)],r+=12,s.Y=[Ze.bin.rf(e,r),Ze.bin.rf(e,r+4),Ze.bin.rf(e,r+8)],r+=12,s.Z=[Ze.bin.rf(e,r),Ze.bin.rf(e,r+4),Ze.bin.rf(e,r+8)],r+=12,s.C=[Ze.bin.rf(e,r),Ze.bin.rf(e,r+4),Ze.bin.rf(e,r+8)],r+=12,s},Ze.parse.fromBIV=function(e){e=new Uint8Array(e);var t={},i={};return i.id=Ze.bin.ril(e,0),i.verS=Ze.bin.ril(e,4),i.texS=Ze.bin.ril(e,8),i.indS=Ze.bin.ril(e,12),i.verO=Ze.bin.ril(e,16),i.verL=Ze.bin.ril(e,20),i.texO=Ze.bin.ril(e,24),i.texL=Ze.bin.ril(e,28),i.indO=Ze.bin.ril(e,32),i.indL=Ze.bin.ril(e,36),0!=i.verO&&(t.vertices=Ze.parse.fromBIV._readFloats(e,i.verO,i.verL)),0!=i.texO&&(t.uvt=Ze.parse.fromBIV._readFloats(e,i.texO,i.texL)),0!=i.indO&&(t.indices=Ze.parse.fromBIV._readInts(e,i.indO,i.indL,i.indS)),t},Ze.parse.toBIV=function(e){for(var t=0,i=0;i<e.indices.length;i++)t=Math.max(t,e.indices[i]);var s=32;t<=65535&&(s=16);var r=40;e.vertices&&(r+=4*e.vertices.length),e.uvt&&(r+=4*e.uvt.length),e.indices&&(r+=e.indices.length*s/8);var n=new Uint8Array(r);Ze.bin.wil(n,0,1769365870),Ze.bin.wil(n,4,32),Ze.bin.wil(n,8,32),Ze.bin.wil(n,12,s);var A=40;return e.vertices&&(Ze.bin.wil(n,16,A),Ze.bin.wil(n,20,4*e.vertices.length),Ze.parse.fromBIV._writeFloats(n,A,e.vertices),A+=4*e.vertices.length),e.uvt&&(Ze.bin.wil(n,24,A),Ze.bin.wil(n,28,4*e.uvt.length),Ze.parse.fromBIV._writeFloats(n,A,e.uvt),A+=4*e.uvt.length),e.indices&&(Ze.bin.wil(n,32,A),Ze.bin.wil(n,36,4*e.indices.length),Ze.parse.fromBIV._writeInts(n,A,e.indices,s)),n.buffer},Ze.parse.fromBIV._readFloats=function(e,t,i){for(var s=[],r=0;r<i/4;r++)s.push(Ze.bin.rf(e,t+4*r));return s},Ze.parse.fromBIV._writeFloats=function(e,t,i){for(var s=0;s<i.length;s++)Ze.bin.wf(e,t+4*s,i[s])},Ze.parse.fromBIV._readInts=function(e,t,i,s){for(var r=[],n=0;n<i/4;n++)16==s&&r.push(Ze.bin.rsl(e,t+2*n)),32==s&&r.push(Ze.bin.ril(e,t+4*n));return r},Ze.parse.fromBIV._writeInts=function(e,t,i,s){for(var r=0;r<i.length;r++)16==s&&Ze.bin.wsl(e,t+2*r,i[r]),32==s&&Ze.bin.wil(e,t+4*r,i[r])},Ze.gen={},Ze.gen.Plane=function(e,t,i,s){i||(i=1),s||(s=1);for(var r={verts:[],inds:[],uvt:[]},n=e+1,A=t+1,o=0;o<A;o++)for(var a=0;a<n;a++){var l=a*(2/e)-1,c=o*(2/t)-1;r.verts.push(l,c,0),r.uvt.push(i*a/e,s*o/t),o<t&&a<e&&r.inds.push(o*n+a,o*n+a+1,(o+1)*n+a,o*n+a+1,(o+1)*n+a,(o+1)*n+a+1)}return r},Ze.gen.Cube=function(){return{verts:[-1,1,-1,1,1,-1,-1,-1,-1,1,-1,-1,-1,1,1,1,1,1,-1,-1,1,1,-1,1,-1,1,1,-1,1,-1,-1,-1,1,-1,-1,-1,1,1,1,1,1,-1,1,-1,1,1,-1,-1,-1,1,-1,1,1,-1,-1,1,1,1,1,1,-1,-1,-1,1,-1,-1,-1,-1,1,1,-1,1],inds:[0,1,2,1,2,3,4,5,6,5,6,7,8,9,10,9,10,11,12,13,14,13,14,15,16,17,18,17,18,19,20,21,22,21,22,23],uvt:[1/4,1/4,.5,1/4,1/4,.5,.5,.5,1,1/4,3/4,1/4,1,.5,3/4,.5,0,1/4,1/4,1/4,0,.5,1/4,.5,3/4,1/4,.5,1/4,3/4,.5,.5,.5,1/4,1/4,.5,1/4,1/4,0,.5,0,1/4,.5,.5,.5,1/4,3/4,.5,3/4]}},Ze.gen.Sphere=function(e,t){for(var i={verts:[],inds:[],uvt:[]},s=e+1,r=t+1,n=0;n<r;n++)for(var A=0;A<s;A++){var o=-Math.PI/2+n*Math.PI/t,a=2*A*Math.PI/e,l=Math.cos(o)*Math.cos(a),c=Math.sin(o),h=Math.cos(o)*Math.sin(a);i.verts.push(l,c,h),i.uvt.push(A/e,n/t),n<t&&A<e&&i.inds.push(s*n+A,s*n+A+1,s*(n+1)+A,s*n+A+1,s*(n+1)+A,s*(n+1)+A+1)}return i},Ze.mat={},Ze.mat.scale=function(e,t,i){return[e,0,0,0,0,t,0,0,0,0,i,0,0,0,0,1]},Ze.mat.translate=function(e,t,i){return[1,0,0,0,0,1,0,0,0,0,1,0,e,t,i,1]},Ze.mat.rotateDeg=function(e,t,i){var s=Math.PI/180;return Ze.mat.rotate(e*s,t*s,i*s)},Ze.mat.rotate=function(e,t,i){var s=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],r=e,n=t,A=i,o=Math.cos(r),a=Math.cos(n),l=Math.cos(A),c=Math.sin(r),h=Math.sin(n),u=Math.sin(A);return s[0]=a*l,s[1]=-a*u,s[2]=h,s[4]=o*u+c*h*l,s[5]=o*l-c*h*u,s[6]=-c*a,s[8]=c*u-o*h*l,s[9]=c*l+o*h*u,s[10]=o*a,s},Ze.edit={},Ze.edit.interpolate=function(e,t,i,s){for(var r=0;r<e.length;r++)i[r]=e[r]+s*(t[r]-e[r])},Ze.edit.transform=function(e,t){for(var i=0;i<e.length;i+=3){var s=e[i],r=e[i+1],n=e[i+2];e[i+0]=t[0]*s+t[4]*r+t[8]*n+t[12],e[i+1]=t[1]*s+t[5]*r+t[9]*n+t[13],e[i+2]=t[2]*s+t[6]*r+t[10]*n+t[14]}},Ze.edit.unwrap=function(e,t,i){for(var s=new Array(Math.floor(e.length/3)*i),r=0;r<e.length;r++)for(var n=0;n<i;n++)s[r*i+n]=t[e[r]*i+n];return s},Ze.edit.remap=function(e,t,i,s){for(var r=new Array(i.length),n=0;n<e.length;n++)for(var A=0;A<s;A++)r[t[n]*s+A]=i[e[n]*s+A];return r},Ze.utils={},Ze.utils.getAABB=function(e){var t,i,s,r,n,A;r=n=A=-(t=i=s=999999999);for(var o=0;o<e.length;o+=3){var a=e[o+0],l=e[o+1],c=e[o+2];a<t&&(t=a),a>r&&(r=a),l<i&&(i=l),l>n&&(n=l),c<s&&(s=c),l>A&&(A=c)}return{min:{x:t,y:i,z:s},max:{x:r,y:n,z:A}}};const At={" ":{width:16,points:[]},"!":{width:10,points:[[5,21],[5,7],[-1,-1],[5,2],[4,1],[5,0],[6,1],[5,2]]},'"':{width:16,points:[[4,21],[4,14],[-1,-1],[12,21],[12,14]]},"#":{width:21,points:[[11,25],[4,-7],[-1,-1],[17,25],[10,-7],[-1,-1],[4,12],[18,12],[-1,-1],[3,6],[17,6]]},$:{width:20,points:[[8,25],[8,-4],[-1,-1],[12,25],[12,-4],[-1,-1],[17,18],[15,20],[12,21],[8,21],[5,20],[3,18],[3,16],[4,14],[5,13],[7,12],[13,10],[15,9],[16,8],[17,6],[17,3],[15,1],[12,0],[8,0],[5,1],[3,3]]},"%":{width:24,points:[[21,21],[3,0],[-1,-1],[8,21],[10,19],[10,17],[9,15],[7,14],[5,14],[3,16],[3,18],[4,20],[6,21],[8,21],[10,20],[13,19],[16,19],[19,20],[21,21],[-1,-1],[17,7],[15,6],[14,4],[14,2],[16,0],[18,0],[20,1],[21,3],[21,5],[19,7],[17,7]]},"&":{width:26,points:[[23,12],[23,13],[22,14],[21,14],[20,13],[19,11],[17,6],[15,3],[13,1],[11,0],[7,0],[5,1],[4,2],[3,4],[3,6],[4,8],[5,9],[12,13],[13,14],[14,16],[14,18],[13,20],[11,21],[9,20],[8,18],[8,16],[9,13],[11,10],[16,3],[18,1],[20,0],[22,0],[23,1],[23,2]]},"'":{width:10,points:[[5,19],[4,20],[5,21],[6,20],[6,18],[5,16],[4,15]]},"(":{width:14,points:[[11,25],[9,23],[7,20],[5,16],[4,11],[4,7],[5,2],[7,-2],[9,-5],[11,-7]]},")":{width:14,points:[[3,25],[5,23],[7,20],[9,16],[10,11],[10,7],[9,2],[7,-2],[5,-5],[3,-7]]},"*":{width:16,points:[[8,21],[8,9],[-1,-1],[3,18],[13,12],[-1,-1],[13,18],[3,12]]},"+":{width:26,points:[[13,18],[13,0],[-1,-1],[4,9],[22,9]]},",":{width:10,points:[[6,1],[5,0],[4,1],[5,2],[6,1],[6,-1],[5,-3],[4,-4]]},"-":{width:26,points:[[4,9],[22,9]]},".":{width:10,points:[[5,2],[4,1],[5,0],[6,1],[5,2]]},"/":{width:22,points:[[20,25],[2,-7]]},0:{width:20,points:[[9,21],[6,20],[4,17],[3,12],[3,9],[4,4],[6,1],[9,0],[11,0],[14,1],[16,4],[17,9],[17,12],[16,17],[14,20],[11,21],[9,21]]},1:{width:20,points:[[6,17],[8,18],[11,21],[11,0]]},2:{width:20,points:[[4,16],[4,17],[5,19],[6,20],[8,21],[12,21],[14,20],[15,19],[16,17],[16,15],[15,13],[13,10],[3,0],[17,0]]},3:{width:20,points:[[5,21],[16,21],[10,13],[13,13],[15,12],[16,11],[17,8],[17,6],[16,3],[14,1],[11,0],[8,0],[5,1],[4,2],[3,4]]},4:{width:20,points:[[13,21],[3,7],[18,7],[-1,-1],[13,21],[13,0]]},5:{width:20,points:[[15,21],[5,21],[4,12],[5,13],[8,14],[11,14],[14,13],[16,11],[17,8],[17,6],[16,3],[14,1],[11,0],[8,0],[5,1],[4,2],[3,4]]},6:{width:20,points:[[16,18],[15,20],[12,21],[10,21],[7,20],[5,17],[4,12],[4,7],[5,3],[7,1],[10,0],[11,0],[14,1],[16,3],[17,6],[17,7],[16,10],[14,12],[11,13],[10,13],[7,12],[5,10],[4,7]]},7:{width:20,points:[[17,21],[7,0],[-1,-1],[3,21],[17,21]]},8:{width:20,points:[[8,21],[5,20],[4,18],[4,16],[5,14],[7,13],[11,12],[14,11],[16,9],[17,7],[17,4],[16,2],[15,1],[12,0],[8,0],[5,1],[4,2],[3,4],[3,7],[4,9],[6,11],[9,12],[13,13],[15,14],[16,16],[16,18],[15,20],[12,21],[8,21]]},9:{width:20,points:[[16,14],[15,11],[13,9],[10,8],[9,8],[6,9],[4,11],[3,14],[3,15],[4,18],[6,20],[9,21],[10,21],[13,20],[15,18],[16,14],[16,9],[15,4],[13,1],[10,0],[8,0],[5,1],[4,3]]},":":{width:10,points:[[5,14],[4,13],[5,12],[6,13],[5,14],[-1,-1],[5,2],[4,1],[5,0],[6,1],[5,2]]},";":{width:10,points:[[5,14],[4,13],[5,12],[6,13],[5,14],[-1,-1],[6,1],[5,0],[4,1],[5,2],[6,1],[6,-1],[5,-3],[4,-4]]},"<":{width:24,points:[[20,18],[4,9],[20,0]]},"=":{width:26,points:[[4,12],[22,12],[-1,-1],[4,6],[22,6]]},">":{width:24,points:[[4,18],[20,9],[4,0]]},"?":{width:18,points:[[3,16],[3,17],[4,19],[5,20],[7,21],[11,21],[13,20],[14,19],[15,17],[15,15],[14,13],[13,12],[9,10],[9,7],[-1,-1],[9,2],[8,1],[9,0],[10,1],[9,2]]},"@":{width:27,points:[[18,13],[17,15],[15,16],[12,16],[10,15],[9,14],[8,11],[8,8],[9,6],[11,5],[14,5],[16,6],[17,8],[-1,-1],[12,16],[10,14],[9,11],[9,8],[10,6],[11,5],[-1,-1],[18,16],[17,8],[17,6],[19,5],[21,5],[23,7],[24,10],[24,12],[23,15],[22,17],[20,19],[18,20],[15,21],[12,21],[9,20],[7,19],[5,17],[4,15],[3,12],[3,9],[4,6],[5,4],[7,2],[9,1],[12,0],[15,0],[18,1],[20,2],[21,3],[-1,-1],[19,16],[18,8],[18,6],[19,5]]},A:{width:18,points:[[9,21],[1,0],[-1,-1],[9,21],[17,0],[-1,-1],[4,7],[14,7]]},B:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[13,21],[16,20],[17,19],[18,17],[18,15],[17,13],[16,12],[13,11],[-1,-1],[4,11],[13,11],[16,10],[17,9],[18,7],[18,4],[17,2],[16,1],[13,0],[4,0]]},C:{width:21,points:[[18,16],[17,18],[15,20],[13,21],[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5]]},D:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[11,21],[14,20],[16,18],[17,16],[18,13],[18,8],[17,5],[16,3],[14,1],[11,0],[4,0]]},E:{width:19,points:[[4,21],[4,0],[-1,-1],[4,21],[17,21],[-1,-1],[4,11],[12,11],[-1,-1],[4,0],[17,0]]},F:{width:18,points:[[4,21],[4,0],[-1,-1],[4,21],[17,21],[-1,-1],[4,11],[12,11]]},G:{width:21,points:[[18,16],[17,18],[15,20],[13,21],[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5],[18,8],[-1,-1],[13,8],[18,8]]},H:{width:22,points:[[4,21],[4,0],[-1,-1],[18,21],[18,0],[-1,-1],[4,11],[18,11]]},I:{width:8,points:[[4,21],[4,0]]},J:{width:16,points:[[12,21],[12,5],[11,2],[10,1],[8,0],[6,0],[4,1],[3,2],[2,5],[2,7]]},K:{width:21,points:[[4,21],[4,0],[-1,-1],[18,21],[4,7],[-1,-1],[9,12],[18,0]]},L:{width:17,points:[[4,21],[4,0],[-1,-1],[4,0],[16,0]]},M:{width:24,points:[[4,21],[4,0],[-1,-1],[4,21],[12,0],[-1,-1],[20,21],[12,0],[-1,-1],[20,21],[20,0]]},N:{width:22,points:[[4,21],[4,0],[-1,-1],[4,21],[18,0],[-1,-1],[18,21],[18,0]]},O:{width:22,points:[[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5],[19,8],[19,13],[18,16],[17,18],[15,20],[13,21],[9,21]]},P:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[13,21],[16,20],[17,19],[18,17],[18,14],[17,12],[16,11],[13,10],[4,10]]},Q:{width:22,points:[[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5],[19,8],[19,13],[18,16],[17,18],[15,20],[13,21],[9,21],[-1,-1],[12,4],[18,-2]]},R:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[13,21],[16,20],[17,19],[18,17],[18,15],[17,13],[16,12],[13,11],[4,11],[-1,-1],[11,11],[18,0]]},S:{width:20,points:[[17,18],[15,20],[12,21],[8,21],[5,20],[3,18],[3,16],[4,14],[5,13],[7,12],[13,10],[15,9],[16,8],[17,6],[17,3],[15,1],[12,0],[8,0],[5,1],[3,3]]},T:{width:16,points:[[8,21],[8,0],[-1,-1],[1,21],[15,21]]},U:{width:22,points:[[4,21],[4,6],[5,3],[7,1],[10,0],[12,0],[15,1],[17,3],[18,6],[18,21]]},V:{width:18,points:[[1,21],[9,0],[-1,-1],[17,21],[9,0]]},W:{width:24,points:[[2,21],[7,0],[-1,-1],[12,21],[7,0],[-1,-1],[12,21],[17,0],[-1,-1],[22,21],[17,0]]},X:{width:20,points:[[3,21],[17,0],[-1,-1],[17,21],[3,0]]},Y:{width:18,points:[[1,21],[9,11],[9,0],[-1,-1],[17,21],[9,11]]},Z:{width:20,points:[[17,21],[3,0],[-1,-1],[3,21],[17,21],[-1,-1],[3,0],[17,0]]},"[":{width:14,points:[[4,25],[4,-7],[-1,-1],[5,25],[5,-7],[-1,-1],[4,25],[11,25],[-1,-1],[4,-7],[11,-7]]},"\\":{width:14,points:[[0,21],[14,-3]]},"]":{width:14,points:[[9,25],[9,-7],[-1,-1],[10,25],[10,-7],[-1,-1],[3,25],[10,25],[-1,-1],[3,-7],[10,-7]]},"^":{width:16,points:[[6,15],[8,18],[10,15],[-1,-1],[3,12],[8,17],[13,12],[-1,-1],[8,17],[8,0]]},_:{width:16,points:[[0,-2],[16,-2]]},"`":{width:10,points:[[6,21],[5,20],[4,18],[4,16],[5,15],[6,16],[5,17]]},a:{width:19,points:[[15,14],[15,0],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},b:{width:19,points:[[4,21],[4,0],[-1,-1],[4,11],[6,13],[8,14],[11,14],[13,13],[15,11],[16,8],[16,6],[15,3],[13,1],[11,0],[8,0],[6,1],[4,3]]},c:{width:18,points:[[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},d:{width:19,points:[[15,21],[15,0],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},e:{width:18,points:[[3,8],[15,8],[15,10],[14,12],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},f:{width:12,points:[[10,21],[8,21],[6,20],[5,17],[5,0],[-1,-1],[2,14],[9,14]]},g:{width:19,points:[[15,14],[15,-2],[14,-5],[13,-6],[11,-7],[8,-7],[6,-6],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},h:{width:19,points:[[4,21],[4,0],[-1,-1],[4,10],[7,13],[9,14],[12,14],[14,13],[15,10],[15,0]]},i:{width:8,points:[[3,21],[4,20],[5,21],[4,22],[3,21],[-1,-1],[4,14],[4,0]]},j:{width:10,points:[[5,21],[6,20],[7,21],[6,22],[5,21],[-1,-1],[6,14],[6,-3],[5,-6],[3,-7],[1,-7]]},k:{width:17,points:[[4,21],[4,0],[-1,-1],[14,14],[4,4],[-1,-1],[8,8],[15,0]]},l:{width:8,points:[[4,21],[4,0]]},m:{width:30,points:[[4,14],[4,0],[-1,-1],[4,10],[7,13],[9,14],[12,14],[14,13],[15,10],[15,0],[-1,-1],[15,10],[18,13],[20,14],[23,14],[25,13],[26,10],[26,0]]},n:{width:19,points:[[4,14],[4,0],[-1,-1],[4,10],[7,13],[9,14],[12,14],[14,13],[15,10],[15,0]]},o:{width:19,points:[[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3],[16,6],[16,8],[15,11],[13,13],[11,14],[8,14]]},p:{width:19,points:[[4,14],[4,-7],[-1,-1],[4,11],[6,13],[8,14],[11,14],[13,13],[15,11],[16,8],[16,6],[15,3],[13,1],[11,0],[8,0],[6,1],[4,3]]},q:{width:19,points:[[15,14],[15,-7],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},r:{width:13,points:[[4,14],[4,0],[-1,-1],[4,8],[5,11],[7,13],[9,14],[12,14]]},s:{width:17,points:[[14,11],[13,13],[10,14],[7,14],[4,13],[3,11],[4,9],[6,8],[11,7],[13,6],[14,4],[14,3],[13,1],[10,0],[7,0],[4,1],[3,3]]},t:{width:12,points:[[5,21],[5,4],[6,1],[8,0],[10,0],[-1,-1],[2,14],[9,14]]},u:{width:19,points:[[4,14],[4,4],[5,1],[7,0],[10,0],[12,1],[15,4],[-1,-1],[15,14],[15,0]]},v:{width:16,points:[[2,14],[8,0],[-1,-1],[14,14],[8,0]]},w:{width:22,points:[[3,14],[7,0],[-1,-1],[11,14],[7,0],[-1,-1],[11,14],[15,0],[-1,-1],[19,14],[15,0]]},x:{width:17,points:[[3,14],[14,0],[-1,-1],[14,14],[3,0]]},y:{width:16,points:[[2,14],[8,0],[-1,-1],[14,14],[8,0],[6,-4],[4,-6],[2,-7],[1,-7]]},z:{width:17,points:[[14,14],[3,0],[-1,-1],[3,14],[14,14],[-1,-1],[3,0],[14,0]]},"{":{width:14,points:[[9,25],[7,24],[6,23],[5,21],[5,19],[6,17],[7,16],[8,14],[8,12],[6,10],[-1,-1],[7,24],[6,22],[6,20],[7,18],[8,17],[9,15],[9,13],[8,11],[4,9],[8,7],[9,5],[9,3],[8,1],[7,0],[6,-2],[6,-4],[7,-6],[-1,-1],[6,8],[8,6],[8,4],[7,2],[6,1],[5,-1],[5,-3],[6,-5],[7,-6],[9,-7]]},"|":{width:8,points:[[4,25],[4,-7]]},"}":{width:14,points:[[5,25],[7,24],[8,23],[9,21],[9,19],[8,17],[7,16],[6,14],[6,12],[8,10],[-1,-1],[7,24],[8,22],[8,20],[7,18],[6,17],[5,15],[5,13],[6,11],[10,9],[6,7],[5,5],[5,3],[6,1],[7,0],[8,-2],[8,-4],[7,-6],[-1,-1],[8,8],[6,6],[6,4],[7,2],[8,1],[9,-1],[9,-3],[8,-5],[7,-6],[5,-7]]},"~":{width:24,points:[[3,6],[3,8],[4,11],[6,12],[8,12],[10,11],[14,8],[16,7],[18,7],[20,8],[21,10],[-1,-1],[3,8],[4,10],[6,11],[8,11],[10,10],[14,7],[16,6],[18,6],[20,7],[21,10],[21,12]]}};function ot(e={}){var t=e.origin||[0,0,0],i=t[0],s=t[1],r=t[2],n=e.size||1,A=[],o=[],a=e.text;X.isNumeric(a)&&(a=""+a);for(var l,c,h,u,d,f,p,g,m,_=(a||"").split("\n"),b=0,B=0,y=.04,w=0;w<_.length;w++){l=0,h=(c=_[w]).length;for(var v=0;v<h;v++)if(u=At[c.charAt(v)]){d=1,f=-1,p=-1,g=u.points.length;for(var C=0;C<g;C++)-1!==(m=u.points[C])[0]||-1!==m[1]?(A.push(l+m[0]*n*y+i),A.push(B+m[1]*n*y+s),A.push(0+r),-1===f?f=b:(-1===p||(f=p),p=b),b++,d?d=!1:(o.push(f),o.push(p))):d=1;l+=u.width*y*n}B-=35*y*n}return X.apply(e,{primitive:"lines",positions:A,indices:o})}function at(e={}){if(e.points.length%3!=0)throw"Size of points array for given polyline should be divisible by 3";let t=e.points.length/3;if(t<2)throw"There should be at least 2 points to create a polyline";let i=[];for(let e=0;e<t-1;e++)i.push(e),i.push(e+1);return X.apply(e,{primitive:"lines",positions:e.points,indices:i})}function lt(e={}){let t=e.curve.getPoints(e.divisions).map((e=>[...e])).flat();return at({id:e.id,points:t})}function ct(e={}){if(3!==e.startPoint.length)throw"Start point should contain 3 elements in array: x, y and z";if(3!==e.endPoint.length)throw"End point should contain 3 elements in array: x, y and z";let t=[],i=[],s=e.startPoint[0],r=e.startPoint[1],n=e.startPoint[2],A=e.endPoint[0],o=e.endPoint[1],a=e.endPoint[2],l=Math.sqrt((A-s)**2+(o-r)**2+(a-n)**2),c=[(A-s)/l,(o-r)/l,(a-n)/l];if(e.pattern){let h=e.pattern.length,u=!1,d=0,f=0,p=0,g=[s,r,n],m=e.pattern[f];for(i.push(g[0],g[1],g[2]);m<=l-d;){let s=[c[0]*m,c[1]*m,c[2]*m],r=[g[0]+s[0],g[1]+s[1],g[2]+s[2]];i.push(r[0],r[1],r[2]),u||(t.push(p),t.push(p+1)),u=!u,p+=1,g=r,f+=1,f>=h&&(f=0),d+=m,m=e.pattern[f]}e.extendToEnd&&(i.push(A,o,a),t.push(t.length-2),t.push(t.length-1))}else t.push(0),t.push(1),i.push(s,r,n,A,o,a);return X.apply(e,{primitive:"lines",positions:i,indices:t})}const ht=V.vec4(4),ut=V.vec4(),dt=V.vec4(),ft=V.vec3([1,0,0]),pt=V.vec3([0,1,0]),gt=V.vec3([0,0,1]),mt=V.vec3(3),_t=V.vec3(3),bt=V.identityMat4();class Bt extends Ae{constructor(e,t={}){if(super(e,t),this._parentNode=null,this._children=[],this._aabb=null,this._aabbDirty=!0,this.scene._aabbDirty=!0,this._numTriangles=0,this._scale=V.vec3(),this._quaternion=V.identityQuaternion(),this._rotation=V.vec3(),this._position=V.vec3(),this._offset=V.vec3(),this._localMatrix=V.identityMat4(),this._worldMatrix=V.identityMat4(),this._localMatrixDirty=!0,this._worldMatrixDirty=!0,t.matrix?this.matrix=t.matrix:(this.scale=t.scale,this.position=t.position,t.quaternion||(this.rotation=t.rotation)),this._isModel=t.isModel,this._isModel&&this.scene._registerModel(this),this._isObject=t.isObject,this._isObject&&this.scene._registerObject(this),this.origin=t.origin,this.visible=t.visible,this.culled=t.culled,this.pickable=t.pickable,this.clippable=t.clippable,this.collidable=t.collidable,this.castsShadow=t.castsShadow,this.receivesShadow=t.receivesShadow,this.xrayed=t.xrayed,this.highlighted=t.highlighted,this.selected=t.selected,this.edges=t.edges,this.colorize=t.colorize,this.opacity=t.opacity,this.offset=t.offset,t.children){const e=t.children;for(let i=0,s=e.length;i<s;i++)this.addChild(e[i],t.inheritStates)}if(t.parentId){const e=this.scene.components[t.parentId];e?e.isNode?e.addChild(this):this.error("Parent is not a Node: '"+t.parentId+"'"):this.error("Parent not found: '"+t.parentId+"'")}else t.parent&&(t.parent.isNode||this.error("Parent is not a Node"),t.parent.addChild(this))}get isEntity(){return!0}get isModel(){return this._isModel}get isObject(){return this._isObject}get aabb(){return this._aabbDirty&&this._updateAABB(),this._aabb}set origin(e){e?(this._origin||(this._origin=V.vec3()),this._origin.set(e)):this._origin&&(this._origin=null);for(let t=0,i=this._children.length;t<i;t++)this._children[t].origin=e;this.glRedraw()}get origin(){return this._origin}set rtcCenter(e){this.origin=e}get rtcCenter(){return this.origin}get numTriangles(){return this._numTriangles}set visible(e){e=!1!==e,this._visible=e;for(let t=0,i=this._children.length;t<i;t++)this._children[t].visible=e;this._isObject&&this.scene._objectVisibilityUpdated(this,e)}get visible(){return this._visible}set xrayed(e){e=!!e,this._xrayed=e;for(let t=0,i=this._children.length;t<i;t++)this._children[t].xrayed=e;this._isObject&&this.scene._objectXRayedUpdated(this,e)}get xrayed(){return this._xrayed}set highlighted(e){e=!!e,this._highlighted=e;for(let t=0,i=this._children.length;t<i;t++)this._children[t].highlighted=e;this._isObject&&this.scene._objectHighlightedUpdated(this,e)}get highlighted(){return this._highlighted}set selected(e){e=!!e,this._selected=e;for(let t=0,i=this._children.length;t<i;t++)this._children[t].selected=e;this._isObject&&this.scene._objectSelectedUpdated(this,e)}get selected(){return this._selected}set edges(e){e=!!e,this._edges=e;for(let t=0,i=this._children.length;t<i;t++)this._children[t].edges=e}get edges(){return this._edges}set culled(e){e=!!e,this._culled=e;for(let t=0,i=this._children.length;t<i;t++)this._children[t].culled=e}get culled(){return this._culled}set clippable(e){e=!1!==e,this._clippable=e;for(let t=0,i=this._children.length;t<i;t++)this._children[t].clippable=e}get clippable(){return this._clippable}set collidable(e){e=!1!==e,this._collidable=e;for(let t=0,i=this._children.length;t<i;t++)this._children[t].collidable=e}get collidable(){return this._collidable}set pickable(e){e=!1!==e,this._pickable=e;for(let t=0,i=this._children.length;t<i;t++)this._children[t].pickable=e}get pickable(){return this._pickable}set colorize(e){let t=this._colorize;t||(t=this._colorize=new Float32Array(4),t[3]=1),e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1);for(let e=0,i=this._children.length;e<i;e++)this._children[e].colorize=t;if(this._isObject){const t=!!e;this.scene._objectColorizeUpdated(this,t)}}get colorize(){return this._colorize.slice(0,3)}set opacity(e){let t=this._colorize;t||(t=this._colorize=new Float32Array(4),t[0]=1,t[1]=1,t[2]=1),t[3]=null!=e?e:1;for(let t=0,i=this._children.length;t<i;t++)this._children[t].opacity=e;if(this._isObject){const t=null!=e;this.scene._objectOpacityUpdated(this,t)}}get opacity(){return this._colorize[3]}set castsShadow(e){e=!!e,this._castsShadow=e;for(let t=0,i=this._children.length;t<i;t++)this._children[t].castsShadow=e}get castsShadow(){return this._castsShadow}set receivesShadow(e){e=!!e,this._receivesShadow=e;for(let t=0,i=this._children.length;t<i;t++)this._children[t].receivesShadow=e}get receivesShadow(){return this._receivesShadow}get saoEnabled(){return!1}set offset(e){e?(this._offset[0]=e[0],this._offset[1]=e[1],this._offset[2]=e[2]):(this._offset[0]=0,this._offset[1]=0,this._offset[2]=0);for(let e=0,t=this._children.length;e<t;e++)this._children[e].offset=this._offset;this._isObject&&this.scene._objectOffsetUpdated(this,e)}get offset(){return this._offset}get isNode(){return!0}_setLocalMatrixDirty(){this._localMatrixDirty=!0,this._setWorldMatrixDirty()}_setWorldMatrixDirty(){this._worldMatrixDirty=!0;for(let e=0,t=this._children.length;e<t;e++)this._children[e]._setWorldMatrixDirty()}_buildWorldMatrix(){const e=this.matrix;if(this._parentNode)V.mulMat4(this._parentNode.worldMatrix,e,this._worldMatrix);else for(let t=0,i=e.length;t<i;t++)this._worldMatrix[t]=e[t];this._worldMatrixDirty=!1}_setSubtreeAABBsDirty(e){if(e._aabbDirty=!0,e._children)for(let t=0,i=e._children.length;t<i;t++)this._setSubtreeAABBsDirty(e._children[t])}_setAABBDirty(){if(this._setSubtreeAABBsDirty(this),this.collidable)for(let e=this;e;e=e._parentNode)e._aabbDirty=!0}_updateAABB(){if(this.scene._aabbDirty=!0,this._aabb||(this._aabb=V.AABB3()),this._buildAABB)this._buildAABB(this.worldMatrix,this._aabb);else{let e;V.collapseAABB3(this._aabb);for(let t=0,i=this._children.length;t<i;t++)e=this._children[t],e.collidable&&V.expandAABB3(this._aabb,e.aabb)}this._aabbDirty=!1}addChild(e,t){if(X.isNumeric(e)||X.isString(e)){const t=e;if(!(e=this.scene.component[t]))return void this.warn("Component not found: "+X.inQuotes(t));if(!e.isNode&&!e.isMesh)return void this.error("Not a Node or Mesh: "+t)}else{if(!e.isNode&&!e.isMesh)return void this.error("Not a Node or Mesh: "+e.id);if(e._parentNode){if(e._parentNode.id===this.id)return void this.warn("Already a child: "+e.id);e._parentNode.removeChild(e)}}if(e.id,e.scene.id===this.scene.id)return this._children.push(e),e._parentNode=this,t&&(e.visible=this.visible,e.culled=this.culled,e.xrayed=this.xrayed,e.highlited=this.highlighted,e.selected=this.selected,e.edges=this.edges,e.clippable=this.clippable,e.pickable=this.pickable,e.collidable=this.collidable,e.castsShadow=this.castsShadow,e.receivesShadow=this.receivesShadow,e.colorize=this.colorize,e.opacity=this.opacity,e.offset=this.offset),e._setWorldMatrixDirty(),e._setAABBDirty(),this._numTriangles+=e.numTriangles,e;this.error("Child not in same Scene: "+e.id)}removeChild(e){for(let t=0,i=this._children.length;t<i;t++)if(this._children[t].id===e.id)return e._parentNode=null,this._children=this._children.splice(t,1),e._setWorldMatrixDirty(),e._setAABBDirty(),this._setAABBDirty(),void(this._numTriangles-=e.numTriangles)}removeChildren(){let e;for(let t=0,i=this._children.length;t<i;t++)e=this._children[t],e._parentNode=null,e._setWorldMatrixDirty(),e._setAABBDirty(),this._numTriangles-=e.numTriangles;this._children=[],this._setAABBDirty()}get numChildren(){return this._children.length}get children(){return this._children}set parent(e){if(X.isNumeric(e)||X.isString(e)){const t=e;if(!(e=this.scene.components[t]))return void this.warn("Node not found: "+X.inQuotes(t));if(!e.isNode)return void this.error("Not a Node: "+e.id)}e.scene.id===this.scene.id?this._parentNode&&this._parentNode.id===e.id?this.warn("Already a child of Node: "+e.id):e.addChild(this):this.error("Node not in same Scene: "+e.id)}get parent(){return this._parentNode}set position(e){this._position.set(e||[0,0,0]),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw()}get position(){return this._position}set rotation(e){this._rotation.set(e||[0,0,0]),V.eulerToQuaternion(this._rotation,"XYZ",this._quaternion),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw()}get rotation(){return this._rotation}set quaternion(e){this._quaternion.set(e||[0,0,0,1]),V.quaternionToEuler(this._quaternion,"XYZ",this._rotation),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw()}get quaternion(){return this._quaternion}set scale(e){this._scale.set(e||[1,1,1]),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw()}get scale(){return this._scale}set matrix(e){this._localMatrix||(this._localMatrix=V.identityMat4()),this._localMatrix.set(e||bt),V.decomposeMat4(this._localMatrix,this._position,this._quaternion,this._scale),this._localMatrixDirty=!1,this._setWorldMatrixDirty(),this._setAABBDirty(),this.glRedraw()}get matrix(){return this._localMatrixDirty&&(this._localMatrix||(this._localMatrix=V.identityMat4()),V.composeMat4(this._position,this._quaternion,this._scale,this._localMatrix),this._localMatrixDirty=!1),this._localMatrix}get worldMatrix(){return this._worldMatrixDirty&&this._buildWorldMatrix(),this._worldMatrix}rotate(e,t){return ht[0]=e[0],ht[1]=e[1],ht[2]=e[2],ht[3]=t*V.DEGTORAD,V.angleAxisToQuaternion(ht,ut),V.mulQuaternions(this.quaternion,ut,dt),this.quaternion=dt,this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw(),this}rotateOnWorldAxis(e,t){return ht[0]=e[0],ht[1]=e[1],ht[2]=e[2],ht[3]=t*V.DEGTORAD,V.angleAxisToQuaternion(ht,ut),V.mulQuaternions(ut,this.quaternion,ut),this}rotateX(e){return this.rotate(ft,e)}rotateY(e){return this.rotate(pt,e)}rotateZ(e){return this.rotate(gt,e)}translate(e,t){return V.vec3ApplyQuaternion(this.quaternion,e,mt),V.mulVec3Scalar(mt,t,_t),V.addVec3(this.position,_t,this.position),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw(),this}translateX(e){return this.translate(ft,e)}translateY(e){return this.translate(pt,e)}translateZ(e){return this.translate(gt,e)}get type(){return"Node"}destroy(){if(super.destroy(),this._parentNode&&this._parentNode.removeChild(this),this._isObject&&(this.scene._deregisterObject(this),this._visible&&this.scene._objectVisibilityUpdated(this,!1,!1),this._xrayed&&this.scene._objectXRayedUpdated(this,!1,!1),this._selected&&this.scene._objectSelectedUpdated(this,!1,!1),this._highlighted&&this.scene._objectHighlightedUpdated(this,!1,!1),this.scene._objectColorizeUpdated(this,!1),this.scene._objectOpacityUpdated(this,!1),this.offset.some((e=>0!==e))&&this.scene._objectOffsetUpdated(this,!1)),this._isModel&&this.scene._deregisterModel(this),this._children.length){const e=this._children.splice(0);let t;for(let i=0,s=e.length;i<s;i++)t=e[i],t.destroy()}this._children=[],this._setAABBDirty(),this.scene._aabbDirty=!0}}const yt=V.vec3(),wt=function(){const e=new Float64Array(16),t=new Float64Array(4),i=new Float64Array(4);return function(s,r,n){return n=n||e,t[0]=r[0],t[1]=r[1],t[2]=r[2],t[3]=1,V.transformVec4(s,t,i),V.setMat4Translation(s,i,n),n.slice()}}();function vt(e,t,i){const s=Float32Array.from([e[0]])[0],r=e[0]-s,n=Float32Array.from([e[1]])[0],A=e[1]-n,o=Float32Array.from([e[2]])[0],a=e[2]-o;t[0]=s,t[1]=n,t[2]=o,i[0]=r,i[1]=A,i[2]=a}function Ct(e,t,i,s=1e3){const r=V.getPositionsCenter(e,yt),n=Math.round(r[0]/s)*s,A=Math.round(r[1]/s)*s,o=Math.round(r[2]/s)*s;i[0]=n,i[1]=A,i[2]=o;const a=0!==i[0]||0!==i[1]||0!==i[2];if(a)for(let i=0,s=e.length;i<s;i+=3)t[i+0]=e[i+0]-n,t[i+1]=e[i+1]-A,t[i+2]=e[i+2]-o;return a}const Mt=1e3,Et=1001,Ft=1002,Ut=1003,xt=1004,It=1004,Tt=1005,Pt=1005,St=1006,Dt=1007,kt=1007,Qt=1008,Rt=1008,Ot=1009,Vt=1010,Lt=1011,Ht=1012,Nt=1013,Gt=1014,jt=1015,Wt=1016,zt=1017,Xt=1018,Kt=1020,Zt=1021,Jt=1022,Yt=1023,$t=1024,qt=1025,ei=1026,ti=1027,ii=1028,si=1029,ri=1030,ni=1031,Ai=1033,oi=33776,ai=33777,li=33778,ci=33779,hi=35840,ui=35841,di=35842,fi=35843,pi=36196,gi=37492,mi=37496,_i=37808,bi=37809,Bi=37810,yi=37811,wi=37812,vi=37813,Ci=37814,Mi=37815,Ei=37816,Fi=37817,Ui=37818,xi=37819,Ii=37820,Ti=37821,Pi=36492,Si=3e3,Di=3001,ki=1e4,Qi=10001,Ri=10002,Oi=10003,Vi=new e({}),Li=V.vec3(),Hi=V.vec4(),Ni={3001:"sRGBToLinear"},Gi=function(){const e=[],t=[],i=[],s=[],r=[],n=[],A=[],o=(t,i)=>{let s=!1;return e.push((e=>s&&i(t,e))),{toString:()=>(s=!0,t)}},a={createAttribute:function(t,i){let s=!1;e.push((e=>s&&e.push(`in ${t} ${i};`)));const A={toString:()=>(s=!0,i)};return r.push((e=>{const t=s&&e(i);return t&&n.push(t.attributeHash),A.setInputValue=t,null})),A},createFragmentDefinition:(e,t)=>{let i=!1;return s.push((s=>i&&t(e,s))),{toString:()=>(i=!0,e)}},createOutput:(e,t,s)=>{let r=!1;return i.push((i=>r&&i.push(`layout(location = ${s||0}) out ${e} ${t};`))),{toString:()=>(r=!0,t)}},createUniform:(t,s,r)=>{let n=!1;const o=e=>n&&e.push(`uniform ${t} ${s};`);e.push(o),i.push(o);const a={toString:()=>(n=!0,s)};return A.push((e=>{const t=n&&e(s);return r?t&&(e=>r(t,e)):(a.setInputValue=t,null)})),a},createUniformArray:(t,s,r)=>{let n=!1;const o=e=>n&&e.push(`uniform ${t} ${s}[${r}];`);e.push(o),i.push(o);const a={toString:()=>(n=!0,s)};return A.push((e=>(a.setInputValue=n&&e(s),null))),a},createUniformBlock:(t,s,r)=>{let n=!1;const o=Object.keys(s),a=e=>{n&&(e.push(`uniform ${t} {`),o.forEach((t=>e.push(` ${s[t]} ${t};`))),e.push("};"))};e.push(a),i.push(a);const l={};return o.forEach((e=>l[e]={toString:()=>(n=!0,e)})),A.push((e=>{const i=n&&e(t);return r?i&&(e=>r(i,e)):(l.setInputValue=i,null)})),l},createVarying:(s,r,n,A)=>{let o=!1;const a=A?A+" ":"";return e.push((e=>o&&e.push(`${a}out ${s} ${r};`))),t.push((e=>o&&e.push(`${r} = ${n()};`))),i.push((e=>o&&e.push(`${a}in ${s} ${r};`))),{toString:()=>(o=!0,r)}},createVertexDefinition:o,commonLibrary:{octDecode:o("octDecode",((e,t)=>{t.push(`vec3 ${e}(vec2 oct) {`),t.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),t.push(" if (v.z < 0.0) {"),t.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),t.push(" }"),t.push(" return normalize(v);"),t.push("}")}))}};return{programVariables:a,buildProgram:(o,l,c)=>{const h=c.getLogDepth,u=c.clipPos,d=c.usePickClipPos&&function(){const e=a.createUniform("vec2","pickClipPos"),t=a.createUniform("vec2","pickClipPosInv");return{setClipPosInputValue:i=>{e.setInputValue(i.pickClipPos),t.setInputValue(i.pickClipPosInv)},transformedClipPos:()=>`vec4((${u}.xy / ${u}.w - ${e}) * ${t} * ${u}.w, ${u}.zw)`}}(),f=d?d.transformedClipPos():u,p=[],g=a.createVarying("float","isPerspective",(()=>`(${c.projMatrix}[2][3] == -1.0) ? 1.0 : 0.0`)),m=a.createUniform("float","logDepthBufFC",((e,t)=>e(2/(Math.log(t.view.far+1)/Math.LN2)))),_=a.createVarying("float","vFragDepth",(()=>"1.0 + clipPos.w"));h?p.push(`gl_FragDepth = ${c.testPerspectiveForGl_FragDepth?`${g} == 0.0 ? gl_FragCoord.z : `:""}log2(${h(_)}) * ${m} * 0.5;`):c.cleanerEdges&&p.push("gl_FragDepth = gl_FragCoord.z + length(vec2(dFdx(gl_FragCoord.z), dFdy(gl_FragCoord.z)));");const b=a.createFragmentDefinition("linearToGamma",((e,t)=>{t.push(`vec4 ${e}(in vec4 value, in float gammaFactor) {`),t.push(" return vec4(pow(value.xyz, vec3(1.0 / gammaFactor)), value.w);"),t.push("}")})),B=c.sectionPlanesState,y=B&&function(){const e=function(e){const t=[];for(let i=0;i<e;++i)t.push(i);return t}(B.getNumAllocatedSectionPlanes()).map((e=>{const t=(t,i,s)=>a.createUniform(t,`sectionPlane${i}${e}`,((t,i)=>{const r=B.sectionPlanes,n=r.length,A=(i.mesh.layerIndex||0)*n,o=e<n&&i.mesh.renderFlags.sectionPlanesActivePerLayer[A+e];return s(t,o,r[e],i.mesh.origin)}));return{act:t("bool","Active",((e,t)=>e(t?1:0))),dir:t("vec3","Dir",((e,t,i)=>t&&e(i.dir))),pos:t("vec3","Pos",((e,t,i,s)=>t&&e(s?V.mulVec3Scalar(V.normalizeVec3(i.dir,Li),-(V.dotVec3(i.dir,s)+i.dist),Li):i.pos)))}}));return e.length>0&&(t=>e.map((e=>`(${e.act} ? clamp(dot(-${e.dir}, ${t} - ${e.pos}), 0.0, 1000.0) : 0.0)`)).join(" + "))}(),w=c.crossSections,v=y?function(){const e=a.createUniform("vec4","sliceColor",(e=>e(w.sliceColor))),t=i=>(t.needed=!0,`(sliced ? ${e} : ${i})`);return t}():e=>e,C=c.getGammaFactor,M=a.createUniform("float","gammaFactor",(e=>e(C())));c.appendFragmentOutputs(p,C&&(e=>`${b}(${e}, ${M})`),"gl_FragCoord",v);const E=function(){const e=[],t=a.createUniform("float","sliceThickness",(e=>e(w.sliceThickness)));if(y){v.needed&&e.push(" bool sliced = false;"),e.push(` if (${c.clippableTest()}) {`);const i=a.createVarying("highp vec3","vHighpWorldPosition",(()=>`${c.worldPositionAttribute}.xyz`));if(e.push(` float dist = ${y(i)};`),c.clippingCaps){const t=a.createVarying("float","vClipPositionW",(()=>"gl_Position.w"));e.push(` if (dist > (0.002 * ${t})) { discard; }`),e.push(" if (dist > 0.0) { "),e.push(` ${c.clippingCaps} = vec4(1.0, 0.0, 0.0, 1.0);`),h&&e.push(` gl_FragDepth = log2(${h(_)}) * ${m} * 0.5;`),e.push(" return;"),e.push(" }")}else e.push(` if (dist > ${v.needed?t:"0.0"}) { discard; }`);v.needed&&e.push(" sliced = dist > 0.0;"),e.push(" }")}return e}(),F=function(){const e=[];return s.forEach((t=>t(e))),e}(),U=[...function(){const e=[];return i.forEach((t=>t(e))),e}(),...F,"void main(void) {",...c.discardPoints?[" vec2 cxy = 2.0 * gl_PointCoord - 1.0;"," if (dot(cxy, cxy) > 1.0) { discard; }"]:[],...E,...p,"}"],x=[`gl_Position = ${f};`,...c.getPointSize?[`gl_PointSize = ${c.getPointSize()};`]:[],...function(){const e=[];return t.forEach((t=>t(e))),e}()],I=c.getVertexData?c.getVertexData():[],T=[...function(){const t=[];return e.forEach((e=>e(t))),t}(),"void main(void) {",...I,...x,"}"],P=e=>["#version 300 es","// "+l+" "+e+" shader","#ifdef GL_FRAGMENT_PRECISION_HIGH","precision highp float;","precision highp int;","precision highp usampler2D;","precision highp isampler2D;","precision highp sampler2D;","#else","precision mediump float;","precision mediump int;","precision mediump usampler2D;","precision mediump isampler2D;","precision mediump sampler2D;","#endif"],S=P("vertex").concat(T),D=P("fragment").concat(["vec4 sRGBToLinear(in vec4 value) {"," return vec4(mix(pow(value.rgb * 0.9478672986 + 0.0521327014, vec3(2.4)), value.rgb * 0.0773993808, vec3(lessThanEqual(value.rgb, vec3(0.04045)))), value.w);","}"]).concat(U),k=(e,t)=>{const i=t.join("\n"),s=o.createShader(e);return o.shaderSource(s,i),o.compileShader(s),o.getShaderParameter(s,o.COMPILE_STATUS)?[s]:[null,["Failed to compile",o.getShaderInfoLog(s),i.split("\n").map(((e,t)=>t+1+": "+e+"\n")).join("")]]},[Q,R]=k(o.VERTEX_SHADER,S),[O,L]=k(o.FRAGMENT_SHADER,D),H=e=>(console.error(e.join("\n")),[null,e]);if(R)return H(["Vertex shader error"].concat(R));if(L)return H(["Fragment shader error"].concat(L));{const e=o.createProgram();if(e){if(o.attachShader(e,Q),o.attachShader(e,O),o.linkProgram(e),o.getProgramParameter(e,o.LINK_STATUS)){const t=zi(o,e);r.forEach((e=>e(t)));const i=A.map((e=>e(t))).filter((e=>e)),s=Vi.addItem({});return[{id:s,bind:()=>o.useProgram(e),inputSetters:{attributesHash:n.sort().join(", "),setUniforms:(e,t)=>{d&&d.setClipPosInputValue(e),i.forEach((e=>e(t)))}},destroy:()=>{Vi.removeItem(s),o.deleteProgram(e),o.deleteShader(Q),o.deleteShader(O)}}]}return H(["",o.getProgramInfoLog(this.program),"","Vertex shader:","",...S,"","Fragment shader:","",...D])}return H(["Failed to allocate program"])}}}},ji=function(e,t){const i=e.createUniform("vec4","lightAmbient",(e=>e(t.getAmbientColorAndIntensity()))),s=t.lights,r=s.map(((t,i)=>{const r={color:e.createUniform("vec4",`lightColor${i}`,(e=>{const t=s[i];Hi[0]=t.color[0],Hi[1]=t.color[1],Hi[2]=t.color[2],Hi[3]=t.intensity,e(Hi)})),position:e.createUniform("vec3",`lightPos${i}`,(e=>e(s[i].pos))),direction:e.createUniform("vec3",`lightDir${i}`,(e=>e(s[i].dir))),shadowProjMatrix:e.createUniform("mat4",`shadowProjMatrix${i}`,(e=>e(s[i].getShadowViewMatrix()))),shadowViewMatrix:e.createUniform("mat4",`shadowViewMatrix${i}`,(e=>e(s[i].getShadowViewMatrix()))),shadowMap:e.createUniform("sampler2D",`shadowMap${i}`,(e=>e(s[i].getShadowRenderBuf().colorTextures[0])))},n=e=>({glslLight:{isViewSpace:"view"===t.space,getColor:()=>`${r.color}.rgb * ${r.color}.a`,getDirection:(t,i)=>`normalize(${e(t,i)})`,shadowParameters:t.castsShadow&&{getShadowProjMatrix:()=>r.shadowProjMatrix,getShadowViewMatrix:()=>r.shadowViewMatrix,getShadowMap:()=>r.shadowMap}},setupLightsInputs:()=>{const e=Object.values(r).map((e=>e.setupLightsInputs())).filter((e=>e));return()=>e.forEach((e=>e()))}});return"dir"===t.type?"view"===t.space?n(((e,t)=>`-${r.direction}`)):n(((e,t)=>`-(${e} * vec4(${r.direction}, 0.0)).xyz`)):"point"===t.type?"view"===t.space?n(((e,t)=>`${r.position} - ${t}`)):n(((e,t)=>`(${e} * vec4(${r.position}, 1.0)).xyz - ${t}`)):null})).filter((e=>e)),n=(t,i)=>{const s=()=>{const e=i();return e.length>0&&e[0]},r=s();return r&&Wi(e,"samplerCube",t,r.encoding,(e=>{const t=s();t&&e(t.texture)}))},A=n("light",(()=>t.lightMaps)),o=n("reflection",(()=>t.reflectionMaps));return{getHash:()=>t.getHash(),getAmbientColor:()=>`${i}.rgb * ${i}.a`,directionalLights:r.map((e=>e.glslLight)),getIrradiance:A&&(e=>`${A(e)}.rgb`),getReflection:o&&((e,t)=>`${o(e,t)}.rgb`)}},Wi=(e,t,i,s,r)=>{const n=e.createUniform(t,i+"Map",r);return(e,t)=>{const i=t?`texture(${n}, ${e}, ${t})`:`texture(${n}, ${e})`;return 3e3!==s?`${Ni[s]}(${i})`:i}},zi=function(e,t){const i={},s=e.getProgramParameter(t,e.ACTIVE_ATTRIBUTES);for(let r=0;r<s;++r){const n=e.getActiveAttrib(t,r),A=e.getAttribLocation(t,n.name);i[n.name]=function(t){t.bindAtLocation(A),e.enableVertexAttribArray(A);const i=t.attributeDivisor;i&&e.vertexAttribDivisor(A,i)},i[n.name].attributeHash=`${A.toString().padStart(1+Math.floor(Math.log10(s)),"0")}:${n.name}`}const r=e.getProgramParameter(t,e.ACTIVE_UNIFORM_BLOCKS);for(let s=0;s<r;++s){const r=e.getActiveUniformBlockName(t,s),n=e.getUniformBlockIndex(t,r),A=s;e.uniformBlockBinding(t,n,A);const o=e.createBuffer();i[r]=function(t){e.bindBuffer(e.UNIFORM_BUFFER,o),e.bufferData(e.UNIFORM_BUFFER,t,e.DYNAMIC_DRAW),e.bindBufferBase(e.UNIFORM_BUFFER,A,o)}}const n=e.getProgramParameter(t,e.ACTIVE_UNIFORMS);let A=0;for(let s=0;s<n;++s){const r=e.getActiveUniform(t,s);let n=r.name;n.endsWith("[0]")&&(n=n.substr(0,n.length-3)),"\0"===n[n.length-1]&&(n=n.substr(0,n.length-1));const o=e.getUniformLocation(t,n);if(function(){for(let t in e)if(r.type===e[t])return t}(),r.type===e.SAMPLER_2D||r.type===e.SAMPLER_CUBE||r.type===e.SAMPLER_2D_SHADOW||e instanceof window.WebGL2RenderingContext&&(r.type===e.UNSIGNED_INT_SAMPLER_2D||r.type===e.INT_SAMPLER_2D)){const t=A++;i[n]=function(i){const s=i.bind(t);return s&&e.uniform1i(o,t),s}}else i[n]=function(){if(1===r.size)switch(r.type){case e.BOOL:case e.INT:return t=>e.uniform1i(o,t);case e.FLOAT:return t=>e.uniform1f(o,t);case e.FLOAT_VEC2:return t=>e.uniform2fv(o,t);case e.FLOAT_VEC3:return t=>e.uniform3fv(o,t);case e.FLOAT_VEC4:return t=>e.uniform4fv(o,t);case e.FLOAT_MAT3:return t=>e.uniformMatrix3fv(o,!1,t);case e.FLOAT_MAT4:return t=>e.uniformMatrix4fv(o,!1,t)}else if(r.size>1)switch(r.type){case e.FLOAT:return t=>e.uniform1fv(o,t);case e.FLOAT_VEC2:return t=>e.uniform2fv(o,t);case e.FLOAT_VEC3:return t=>e.uniform3fv(o,t);case e.FLOAT_VEC4:return t=>e.uniform4fv(o,t)}throw`Unhandled uniform ${n}`}()}return function(e){const t=i[e];if(!t)throw`Missing input "${e}"`;return t}},Xi=V.vec4(),Ki=V.vec4();class Zi{constructor(){this.visibleLayers=[],this.sectionPlanesActivePerLayer=[],this.reset()}reset(){this.culled=!1,this.sectioned=!1,this.numLayers=0,this.numVisibleLayers=0,this.colorOpaque=!1,this.colorTransparent=!1,this.edgesOpaque=!1,this.edgesTransparent=!1,this.xrayedSilhouetteOpaque=!1,this.xrayedEdgesOpaque=!1,this.xrayedSilhouetteTransparent=!1,this.xrayedEdgesTransparent=!1,this.highlightedSilhouetteOpaque=!1,this.highlightedEdgesOpaque=!1,this.highlightedSilhouetteTransparent=!1,this.highlightedEdgesTransparent=!1,this.selectedSilhouetteOpaque=!1,this.selectedEdgesOpaque=!1,this.selectedSilhouetteTransparent=!1,this.selectedEdgesTransparent=!1}}const Ji=V.OBB3(),Yi=V.vec4(),$i=V.vec4(),qi=V.vec4(),es=V.vec3([1,0,0]),ts=V.vec3([0,1,0]),is=V.vec3([0,0,1]),ss=V.vec3(3),rs=V.vec3(3),ns=V.identityMat4(),As=new e({}),os={};class as extends Ae{constructor(e,t={}){super(e,t),this.renderOrder=t.renderOrder||0,this.originalSystemId=t.originalSystemId||this.id,this.renderFlags=new Zi,this._state=new Se({visible:!0,culled:!1,pickable:null,clippable:null,collidable:null,occluder:!1!==t.occluder,castsShadow:null,receivesShadow:null,xrayed:!1,highlighted:!1,selected:!1,edges:!1,stationary:!!t.stationary,background:!!t.background,billboard:this._checkBillboard(t.billboard),layer:null,colorize:null,pickID:this.scene._renderer.getPickID(this),drawHash:"",pickOcclusionHash:"",offset:V.vec3(),origin:null,originHash:null,isUI:t.isUI});const i=t.material?this._checkComponent2(["PhongMaterial","MetallicMaterial","SpecularMaterial","LambertMaterial"],t.material):this.scene.material,s=this,r=e=>{let t=null;const i=()=>{if(!t){const i=Gi(),r=i.programVariables.createAttribute,n=s._geometry._state,A={position:r("vec3","position"),color:n.colorsBuf&&r("vec4","color"),pickColor:r("vec4","pickColor"),uv:n.uvBuf&&r("vec2","uv"),normal:(n.autoVertexNormals||n.normalsBuf)&&["triangles","triangle-strip","triangle-fan"].includes(n.primitiveName)&&r("vec3","normal")},o=function(e){const t={toString:()=>(t.needed=!0,e)};return t},a=A.normal&&o("worldNormal"),l=a&&o("viewNormal"),c=A.uv&&o("decodedUv"),h=e(i.programVariables,{attributes:{position:{world:"worldPosition",view:"viewPosition"},color:A.color,pickColor:A.pickColor,uv:c,normal:A.normal&&{world:a,view:l}},viewMatrix:"viewMatrix2"}),u=[h.programName,s.scene.canvas.canvas.id,s.scene._sectionPlanesState.getHash(),s._geometry._state.hash].concat(h.getHash()).join(";");if(!(u in os)){const e=cs(s,A,{decodedUv:c,worldNormal:a,viewNormal:l},h,i);if(e.errors)return void console.log(e.errors.join("\n"));const t=As.addItem({});os[u]={drawMesh:e.drawMesh,id:t,useCount:0,delete:()=>{As.removeItem(t),e.destroy(),delete os[u],G.memory.programs--}},G.memory.programs++}t=os[u],t.useCount++}};return{get:i,getId:()=>t.id,put:()=>{t&&(0==--t.useCount&&t.delete(),t=null)},drawMesh:(e,s,r)=>{i(),t&&t.drawMesh(e,s,r)}}},n=s.scene,A=e=>(t,i)=>function(e,t,i,s,r){const n=r&&ji(t,s._lightsState),A=t.createUniform("vec3","uColor",((e,t)=>e(r?t.material.fillColor:t.material.edgeColor))),o=t.createUniform("float","uAlpha",((e,t)=>e(r?t.material.fillAlpha:t.material.edgeAlpha))),a=t.createVarying("vec4","vColor",(()=>{const e=i.attributes,t=r&&[n.getAmbientColor()].concat(e.normal?n.directionalLights.map((t=>`(max(dot(${e.normal.view}, ${t.getDirection(i.viewMatrix,e.position.view)}), 0.0) * ${t.getColor()})`)):[]);return`vec4(${A}${t?` * (${t.join(" + ")})`:""}, ${o})`})),l=t.createOutput("vec4","outColor");return{getHash:()=>[e,s.gammaOutput?"go":"",n&&n.getHash()],programName:r?"EmphasisFill":"EmphasisEdges",dontSetFrontFace:!0,discardPoints:r,drawEdges:!r,appendFragmentOutputs:(e,t)=>e.push(`${l} = ${t?t(a):a};`)}}(s._state.hash,t,i,n,e);this._renderers={_drawRenderer:r(((e,t)=>"LambertMaterial"===i.type?function(e,t,i,s,r){const n=ji(t,r._lightsState),A=t.createUniform("vec4","colorize",((e,t)=>e(t.meshColorize))),o=t.createUniform("float","materialAlpha",((e,t)=>e(t.material.alpha))),a=t.createUniform("vec3","materialColor",((e,t)=>e(t.material.color))),l=t.createUniform("vec3","materialEmissive",((e,t)=>e(t.material.emissive))),c=t.createVarying("vec4","vColor",(()=>{const e=i.attributes,t=[n.getAmbientColor()].concat(e.normal?n.directionalLights.map((t=>`(max(dot(${e.normal.view}, ${t.getDirection(i.viewMatrix,e.position.view)}), 0.0) * ${t.getColor()})`)):[]);return`${A} * vec4((${t.join(" + ")}) * ${a} + ${l}, ${o});`})),h=t.createOutput("vec4","outColor");return{getHash:()=>[e,r.gammaOutput?"go":"",n.getHash(),s._state.hash],programName:"Lambert",canActAsBackground:!0,discardPoints:!0,setupPointSize:!0,setsLineWidth:!0,appendFragmentOutputs:(e,t)=>e.push(`${h} = ${t?t(c):c};`)}}(s._state.drawHash,e,t,i,n):function(e,t,i,s,r){const n=s._state,A="PhongMaterial"===n.type,o="MetallicMaterial"===n.type,a="SpecularMaterial"===n.type,l=i.attributes,c=ji(t,r._lightsState),h=t.createUniform("vec4","colorize",((e,t)=>e(t.meshColorize))),u=t.createFragmentDefinition("fresnel",((e,t)=>{t.push(`float ${e}(vec3 eyeDir, vec3 normal, float edgeBias, float centerBias, float power) {`),t.push(" float fr = abs(dot(eyeDir, normal));"),t.push(" float finalFr = clamp((fr - edgeBias) / (centerBias - edgeBias), 0.0, 1.0);"),t.push(" return pow(finalFr, power);"),t.push("}")})),d=(e,i,r)=>{const n=(i,s,n)=>t.createUniform(i,e+"Fresnel"+s,((e,t)=>e(n(r(t.material))))),A=n("float","EdgeBias",(e=>e.edgeBias)),o=n("float","CenterBias",(e=>e.centerBias)),a=n("float","Power",(e=>e.power)),l=n("vec3","EdgeColor",(e=>e.edgeColor)),c=n("vec3","CenterColor",(e=>e.centerColor));return r(s)&&((e,t)=>`mix(${l+i}, ${c+i}, ${u}(${e}, ${t}, ${A}, ${o}, ${a}))`)},f=d("diffuse","",(e=>e._diffuseFresnel)),p=d("specular","",(e=>e._specularFresnel)),g=d("emissive","",(e=>e._emissiveFresnel)),m=d("alpha",".r",(e=>e._alphaFresnel)),_=(e,i)=>{const r=l.uv&&i(s),n=r&&Wi(t,"sampler2D",e,r.encoding,((e,t)=>e(i(t.material)._state.texture)));return n&&function(){const s=r._state.matrix&&t.createUniform("mat4",e+"MapMatrix",((e,t)=>e(i(t.material)._state.matrix))),A=s?e=>`(${s} * ${e}).st`:e=>`${e}.st`,o=(e,t)=>n(A(e));return o.getTexCoordExpression=A,o}()},b=_("ambient",(e=>e._ambientMap)),B=_("baseColor",(e=>e._baseColorMap)),y=_("diffuse",(e=>e._diffuseMap)),w=_("emissive",(e=>e._emissiveMap)),v=_("occlusion",(e=>e._occlusionMap)),C=_("alpha",(e=>e._alphaMap)),M=_("metallic",(e=>e._metallicMap)),E=_("roughness",(e=>e._roughnessMap)),F=_("metallicRoughness",(e=>e._metallicRoughnessMap)),U=_("specular",(e=>e._specularMap)),x=_("glossiness",(e=>e._glossinessMap)),I=_("specularGlossiness",(e=>e._specularGlossinessMap)),T=_("normal",(e=>e._normalMap)),P=(e,i,r)=>{const n=r(s);return("float"===i?null!=n:n)&&t.createUniform(i,e,((e,t)=>e(r(t.material))))},S=P("materialAmbient","vec3",(e=>e.ambient)),D=P("materialDiffuse","vec3",(e=>e.diffuse)),k=P("materialBaseColor","vec3",(e=>e.baseColor)),Q=P("materialEmissive","vec3",(e=>e.emissive)),R=P("materialSpecular","vec3",(e=>e.specular)),O=P("materialGlossiness","float",(e=>e.glossiness)),V=P("materialMetallic","float",(e=>e.metallic)),L=P("materialRoughness","float",(e=>e.roughness)),H=P("materialShininess","float",(e=>e.shininess)),N=P("materialSpecularF0","float",(e=>e.specularF0)),G=P("materialAlphaModeCutoff","vec4",(e=>{const t=e.alpha;return null!=t?(Xi[0]=t,Xi[1]=1===e.alphaMode?1:0,Xi[2]=e.alphaCutoff,Xi):null})),j=t.createVarying("vec3","vViewPosition",(()=>`${l.position.view}.xyz`)),W=t.createVarying("vec4","texturePos",(()=>`vec4(${l.uv}, 1.0, 1.0)`)),z=l.color&&t.createVarying("vec4","vColor",(()=>l.color)),X=t.createVarying("vec3","vViewNormal",(()=>l.normal.view)),K=c.directionalLights.map(((e,s)=>({vViewLightReverseDir:t.createVarying("vec3",`vViewLightReverseDir${s}`,(()=>e.getDirection(i.viewMatrix,null))),vShadowPosFromLight:t.createVarying("vec3",`vShadowPosFromLight${s}`,(()=>`(mat4(0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.5, 0.5, 0.5, 1.0) * ${e.shadowParameters.getShadowProjMatrix()} * (${e.shadowParameters.getShadowViewMatrix()} * ${l.position.world})).xyz`))}))),Z=t.createVarying("vec3","vWorldNormal",(()=>l.normal.world)),J=t.createOutput("vec4","outColor"),Y=t.createFragmentDefinition("saturate",((e,t)=>t.push(`float ${e}(const in float a) { return clamp(a, 0.0, 1.0); }`))),$=t.createFragmentDefinition("BRDF_Specular_GGX",((e,t)=>{t.push("vec3 F_Schlick(const in vec3 specularColor, const in float dotLH) {"),t.push(" float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );"),t.push(" return ( 1.0 - specularColor ) * fresnel + specularColor;"),t.push("}"),t.push("float G_GGX_Smith(const in float alpha, const in float dotNL, const in float dotNV) {"),t.push(" float a2 = ( alpha * alpha );"),t.push(" float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),t.push(" float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),t.push(" return 1.0 / ( gl * gv );"),t.push("}"),t.push("float G_GGX_SmithCorrelated(const in float alpha, const in float dotNL, const in float dotNV) {"),t.push(" float a2 = ( alpha * alpha );"),t.push(" float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),t.push(" float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),t.push(" return 0.5 / max( gv + gl, 1e-6 );"),t.push("}"),t.push("float D_GGX(const in float alpha, const in float dotNH) {"),t.push(" float a2 = ( alpha * alpha );"),t.push(" float denom = ( dotNH * dotNH) * ( a2 - 1.0 ) + 1.0;"),t.push(" return 0.31830988618 * a2 / ( denom * denom);"),t.push("}"),t.push(`vec3 ${e}(const in vec3 incidentLightDirection, const in vec3 viewNormal, const in vec3 viewEyeDir, const in vec3 specularColor, const in float roughness) {`),t.push(" float alpha = ( roughness * roughness );"),t.push(" vec3 halfDir = normalize( incidentLightDirection + viewEyeDir );"),t.push(` float dotNL = ${Y}( dot( viewNormal, incidentLightDirection ) );`),t.push(` float dotNV = ${Y}( dot( viewNormal, viewEyeDir ) );`),t.push(` float dotNH = ${Y}( dot( viewNormal, halfDir ) );`),t.push(` float dotLH = ${Y}( dot( incidentLightDirection, halfDir ) );`),t.push(" vec3 F = F_Schlick( specularColor, dotLH );"),t.push(" float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );"),t.push(" float D = D_GGX( alpha, dotNH );"),t.push(" return F * (G * D);"),t.push("}")})),q=t.createFragmentDefinition("BRDF_Specular_GGX_Environment",((e,t)=>{t.push(`vec3 ${e}(const in vec3 viewNormal, const in vec3 viewEyeDir, const in vec3 specularColor, const in float roughness) {`),t.push(` float dotNV = ${Y}(dot(viewNormal, viewEyeDir));`),t.push(" const vec4 c0 = vec4( -1, -0.0275, -0.572, 0.022);"),t.push(" const vec4 c1 = vec4( 1, 0.0425, 1.04, -0.04);"),t.push(" vec4 r = roughness * c0 + c1;"),t.push(" float a004 = min(r.x * r.x, exp2(-9.28 * dotNV)) * r.x + r.y;"),t.push(" vec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;"),t.push(" return specularColor * AB.x + AB.y;"),t.push("}")})),ee=t.createFragmentDefinition("perturbNormal2Arb",((e,t)=>{t.push(`vec3 ${e}( vec3 eye_pos, vec3 surf_norm, vec2 uv, vec4 texel ) {`),t.push(" vec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );"),t.push(" vec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );"),t.push(" vec2 st0 = dFdx( uv.st );"),t.push(" vec2 st1 = dFdy( uv.st );"),t.push(" vec3 S = normalize( q0 * st1.t - q1 * st0.t );"),t.push(" vec3 T = normalize( -q0 * st1.s + q1 * st0.s );"),t.push(" vec3 N = normalize( surf_norm );"),t.push(" vec3 mapN = texel.xyz * 2.0 - 1.0;"),t.push(" mat3 tsn = mat3( S, T, N );"),t.push(" return normalize( tsn * mapN );"),t.push("}")}));return{getHash:()=>[e,r.gammaOutput?"go":"",c.getHash(),s._state.hash],programName:"Draw",canActAsBackground:!0,discardPoints:!0,setupPointSize:!0,setsLineWidth:!0,appendFragmentOutputs:(e,t,s)=>{const r=l.normal&&(c.directionalLights.length>0||c.getIrradiance||c.getReflection);if(e.push(`vec3 diffuseColor = ${r&&(A||a)&&D||o&&k||"vec3(1.0)"};`),e.push(`vec4 alphaModeCutoff = ${(A||o||a)&&G||"vec4(1.0, 0.0, 0.0, 0.0)"};`),e.push("float alpha = alphaModeCutoff[0];"),(A||o||a)&&C&&e.push(`alpha *= ${C(W)}.r;`),z&&(e.push(`diffuseColor *= ${z}.rgb;`),e.push(`alpha *= ${z}.a;`)),o&&B&&(e.push("vec4 baseColorTexel = "+B(W)+";"),e.push("diffuseColor *= baseColorTexel.rgb;"),e.push("alpha *= baseColorTexel.a;")),(A||a)&&y&&(e.push("vec4 diffuseTexel = "+y(W)+";"),e.push("diffuseColor *= diffuseTexel.rgb;"),e.push("alpha *= diffuseTexel.a;")),e.push(`vec3 emissiveColor = ${(A||o||a)&&Q||"vec3(0.0)"};`),(A||o||a)&&w&&e.push(`emissiveColor = ${w(W)}.rgb;`),r){e.push(`vec3 specular = ${(A||a)&&R||"vec3(1.0)"};`),e.push(`float glossiness = ${a&&O||"1.0"};`),e.push(`float metallic = ${o&&V||"1.0"};`),e.push(`float roughness = ${(o||a)&&L||"1.0"};`),e.push(`float shininess = ${A&&H||"1.0"};`),e.push(`float specularF0 = ${o&&N||"1.0"};`),e.push(`float occlusion = ${(A||o||a)&&v?`${v(W)}.r`:"1.0"};`),o&&M&&e.push(`metallic *= ${M(W)}.r;`),o&&E&&e.push(`roughness *= ${E(W)}.r;`),o&&F&&(e.push("vec4 metalRoughTexel = "+F(W)+";"),e.push("metallic *= metalRoughTexel.b;"),e.push("roughness *= metalRoughTexel.g;")),(A||a)&&U&&e.push(`specular *= ${U(W)}.rgb;`),a&&x&&e.push(`glossiness *= ${x(W)}.r;`),a&&I&&(e.push("vec4 specGlossTexel = "+I(W)+";"),e.push("specular *= specGlossTexel.rgb;"),e.push("glossiness *= specGlossTexel.a;"));const t=`normalize(${X})`,s=(A||o||a)&&T?`${ee}(${j}, ${t}, ${T.getTexCoordExpression(W)}, ${T(W)})`:t;if(e.push(`vec3 viewNormal = ${s};`),e.push(`vec3 viewEyeDir = normalize(-${j});`),f&&e.push(`diffuseColor *= ${f("viewEyeDir","viewNormal")};`),p&&e.push(`specular *= ${p("viewEyeDir","viewNormal")};`),g&&e.push(`emissiveColor *= ${g("viewEyeDir","viewNormal")};`),m&&e.push(`alpha *= ${m("viewEyeDir","viewNormal")};`),e.push("if (alphaModeCutoff[1] == 1.0 && alpha < alphaModeCutoff[2]) {"),e.push(" discard;"),e.push("}"),e.push("vec3 material_diffuseColor;"),A&&(e.push("material_diffuseColor = diffuseColor;"),e.push("roughness = 0.0;")),a&&(e.push("float oneMinusSpecularStrength = 1.0 - max(max(specular.r, specular.g ),specular.b);"),e.push("material_diffuseColor = diffuseColor * oneMinusSpecularStrength;"),e.push("roughness = clamp(1.0 - glossiness, 0.04, 1.0);")),o&&(e.push("float dielectricSpecular = 0.16 * specularF0 * specularF0;"),e.push("material_diffuseColor = diffuseColor * (1.0 - dielectricSpecular) * (1.0 - metallic);"),e.push("roughness = clamp(roughness, 0.04, 1.0);"),e.push("specular = mix(vec3(dielectricSpecular), diffuseColor, metallic);")),A||o||a){if(e.push("const float PI = 3.14159265359;"),e.push("vec3 reflDiff = vec3(0.0);"),e.push("vec3 reflSpec = vec3(0.0);"),c.getIrradiance&&e.push(`reflDiff += ${c.getIrradiance(`normalize(${Z})`)};`),c.getReflection){const t="reflect(-viewEyeDir, viewNormal)",s=A?`0.2 * PI * ${c.getReflection(t)}`:function(){const e=`${q}(viewNormal, viewEyeDir, specular, roughness)`,s=`normalize((vec4(${t}, 0.0) * ${i.viewMatrix}).xyz)`;return`${e} * ${c.getReflection(s,"clamp(4.0 - 0.39624 - 0.25 * log2(pow(2.0 / pow(roughness + 0.0001, 2.0) - 2.0, 2.0) + 1.0), 0.0, 4.0)")}`}();e.push(`reflSpec += ${s};`)}c.directionalLights.some((e=>e.shadowParameters))&&(e.push("const vec4 bitShift = vec4(1.0, 1.0/256.0, 1.0/(256.0 * 256.0), 1.0/(256.0*256.0*256.0));"),e.push("const float texelSize = 1.0 / 1024.0;"),e.push("float shadow;"),e.push("float fragmentDepth;")),c.directionalLights.forEach(((t,i)=>{if(t.shadowParameters){const s="0.007";e.push(`fragmentDepth = ${K[i].vShadowPosFromLight}.z - ${s};`),e.push("shadow = 0.0;"),e.push("for (int x = -3; x <= 3; x++) {"),e.push(" for (int y = -3; y <= 3; y++) {"),e.push(` float texelDepth = dot(texture(${t.getShadowMap()}, ${K[i].vShadowPosFromLight}.xy + vec2(x, y) * texelSize), bitShift);`),e.push(" if (fragmentDepth < texelDepth) {"),e.push(" shadow += 1.0;"),e.push(" }"),e.push(" }"),e.push("}"),e.push("shadow /= 9.0;")}e.push(`vec3 lightColor${i} = ${t.getColor()}${t.shadowParameters?" * shadow":""};`),e.push(`vec3 lightDirection${i} = ${t.isViewSpace?t.getDirection(null,j):K[i].vViewLightReverseDir};`);const s=`${Y}(dot(viewNormal, lightDirection${i}))`;e.push(`vec3 irradiance${i} = ${s} * lightColor${i};`),e.push(`reflDiff += irradiance${i};`);const r=A?`lightColor${i} * specular * pow(max(dot(reflect(-lightDirection${i}, -viewNormal), viewEyeDir), 0.0), shininess)`:`irradiance${i} * PI * ${$}(lightDirection${i}, viewNormal, viewEyeDir, specular, roughness)`;e.push(`reflSpec += ${r};`)}))}const r=A&&`${c.getAmbientColor()} * diffuseColor`;e.push("vec3 outgoingLight = emissiveColor + occlusion * (reflDiff * material_diffuseColor + reflSpec)"+(r?" + "+r:"")+";")}else e.push(`vec3 ambientColor = ${A&&S||"vec3(1.0)"};`),A&&b&&e.push(`ambientColor *= ${b(W)}.rgb;`),e.push(`ambientColor *= ${c.getAmbientColor()};`),e.push("vec3 outgoingLight = emissiveColor + ambientColor;");e.push(`vec4 fragColor = ${h} * vec4(outgoingLight, alpha);`),e.push(`${J} = ${t?t("fragColor"):"fragColor"};`)}}}(s._state.drawHash,e,t,i,n))),_shadowRenderer:r((e=>function(e,t){const i=t.createFragmentDefinition("encodeFloat",((e,t)=>{t.push(`vec4 ${e}( const in float depth ) {`),t.push(" const vec4 bitShift = vec4(256 * 256 * 256, 256 * 256, 256, 1.0);"),t.push(" const vec4 bitMask = vec4(0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0);"),t.push(" vec4 comp = fract(depth * bitShift);"),t.push(" comp -= comp.xxyz * bitMask;"),t.push(" return comp;"),t.push("}")})),s=t.createOutput("vec4","outColor");return{getHash:()=>[e],programName:"Shadow",setsLineWidth:!0,useShadowView:!0,dontBillboardAnything:!0,dontGetLogDepth:!0,appendFragmentOutputs:(e,t,r)=>e.push(`${s} = ${i}(${r}.z);`)}}(s._state.hash,e))),_emphasisEdgesRenderer:r(A(!1)),_emphasisFillRenderer:r(A(!0)),_pickMeshRenderer:r((e=>function(e,t){const i=t.createUniform("vec4","pickColor",((e,t)=>{var i=t.meshPickID;Ki[0]=255&i,Ki[1]=i>>8&255,Ki[2]=i>>16&255,Ki[3]=i>>24&255,V.mulVec4Scalar(Ki,1/255,Ki),e(Ki)})),s=t.createOutput("vec4","outColor");return{getHash:()=>[e],programName:"PickMesh",isPick:!0,dontBillboardAnything:!0,appendFragmentOutputs:e=>e.push(`${s} = ${i};`)}}(s._state.hash,e))),_pickTriangleRenderer:r(((e,t)=>function(e,t,i){const s=t.createVarying("vec4","vColor",(()=>i.attributes.pickColor)),r=t.createOutput("vec4","outColor");return{getHash:()=>[e],programName:"PickTriangle",isPick:!0,trianglePick:!0,dontBillboardAnything:!0,appendFragmentOutputs:e=>e.push(`${r} = ${s};`)}}(s._state.hash,e,t))),_occlusionRenderer:r((e=>function(e,t){const i=t.createOutput("vec4","outColor");return{getHash:()=>[e],programName:"Occlusion",skipIfTransparent:!0,appendFragmentOutputs:e=>e.push(`${i} = vec4(0.0, 0.0, 1.0, 1.0);`)}}(s._state.pickOcclusionHash,e)))},this._geometry=t.geometry?this._checkComponent2(["ReadableGeometry","VBOGeometry"],t.geometry):this.scene.geometry,this._material=i,this._xrayMaterial=t.xrayMaterial?this._checkComponent("EmphasisMaterial",t.xrayMaterial):this.scene.xrayMaterial,this._highlightMaterial=t.highlightMaterial?this._checkComponent("EmphasisMaterial",t.highlightMaterial):this.scene.highlightMaterial,this._selectedMaterial=t.selectedMaterial?this._checkComponent("EmphasisMaterial",t.selectedMaterial):this.scene.selectedMaterial,this._edgeMaterial=t.edgeMaterial?this._checkComponent("EdgeMaterial",t.edgeMaterial):this.scene.edgeMaterial,this._parentNode=null,this._aabb=null,this._aabbDirty=!0,this._numTriangles=this._geometry?this._geometry.numTriangles:0,this.scene._aabbDirty=!0,this._scale=V.vec3(),this._quaternion=V.identityQuaternion(),this._rotation=V.vec3(),this._position=V.vec3(),this._worldMatrix=V.identityMat4(),this._worldNormalMatrix=V.identityMat4(),this._localMatrixDirty=!0,this._worldMatrixDirty=!0,this._worldNormalMatrixDirty=!0;const o=t.origin||t.rtcCenter;if(o&&(this._state.origin=V.vec3(o),this._state.originHash=o.join()),t.matrix?this.matrix=t.matrix:(this.scale=t.scale,this.position=t.position,t.quaternion||(this.rotation=t.rotation)),this._isObject=t.isObject,this._isObject&&this.scene._registerObject(this),this._isModel=t.isModel,this._isModel&&this.scene._registerModel(this),this.visible=t.visible,this.culled=t.culled,this.pickable=t.pickable,this.clippable=t.clippable,this.collidable=t.collidable,this.castsShadow=t.castsShadow,this.receivesShadow=t.receivesShadow,this.xrayed=t.xrayed,this.highlighted=t.highlighted,this.selected=t.selected,this.edges=t.edges,this.layer=t.layer,this.colorize=t.colorize,this.opacity=t.opacity,this.offset=t.offset,t.parentId){const e=this.scene.components[t.parentId];e?e.isNode?e.addChild(this):this.error("Parent is not a Node: '"+t.parentId+"'"):this.error("Parent not found: '"+t.parentId+"'"),this._parentNode=e}else t.parent&&(t.parent.isNode||this.error("Parent is not a Node"),t.parent.addChild(this),this._parentNode=t.parent);this.compile()}get type(){return"Mesh"}get isMesh(){return!0}get parent(){return this._parentNode}get geometry(){return this._geometry}get material(){return this._material}get position(){return this._position}set position(e){this._position.set(e||[0,0,0]),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw()}get rotation(){return this._rotation}set rotation(e){this._rotation.set(e||[0,0,0]),V.eulerToQuaternion(this._rotation,"XYZ",this._quaternion),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw()}get quaternion(){return this._quaternion}set quaternion(e){this._quaternion.set(e||[0,0,0,1]),V.quaternionToEuler(this._quaternion,"XYZ",this._rotation),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw()}get scale(){return this._scale}set scale(e){this._scale.set(e||[1,1,1]),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw()}get matrix(){return this._localMatrixDirty&&(this.__localMatrix||(this.__localMatrix=V.identityMat4()),V.composeMat4(this._position,this._quaternion,this._scale,this.__localMatrix),this._localMatrixDirty=!1),this.__localMatrix}set matrix(e){this.__localMatrix||(this.__localMatrix=V.identityMat4()),this.__localMatrix.set(e||ns),V.decomposeMat4(this.__localMatrix,this._position,this._quaternion,this._scale),this._localMatrixDirty=!1,this._setWorldMatrixDirty(),this._setAABBDirty(),this.glRedraw()}get worldMatrix(){return this._worldMatrixDirty&&this._buildWorldMatrix(),this._worldMatrix}get worldNormalMatrix(){return this._worldNormalMatrixDirty&&this._buildWorldNormalMatrix(),this._worldNormalMatrix}get isEntity(){return!0}get isModel(){return this._isModel}get isObject(){return this._isObject}get isUI(){return this._state.isUI}get aabb(){return this._aabbDirty&&this._updateAABB(),this._aabb}get origin(){return this._state.origin}set origin(e){e?(this._state.origin||(this._state.origin=V.vec3()),this._state.origin.set(e),this._state.originHash=e.join(),this._setAABBDirty(),this.scene._aabbDirty=!0):this._state.origin&&(this._state.origin=null,this._state.originHash=null,this._setAABBDirty(),this.scene._aabbDirty=!0)}get rtcCenter(){return this.origin}set rtcCenter(e){this.origin=e}get numTriangles(){return this._numTriangles}get visible(){return this._state.visible}set visible(e){e=!1!==e,this._state.visible=e,this._isObject&&this.scene._objectVisibilityUpdated(this,e),this.glRedraw()}get xrayed(){return this._state.xrayed}set xrayed(e){e=!!e,this._state.xrayed!==e&&(this._state.xrayed=e,this._isObject&&this.scene._objectXRayedUpdated(this,e),this.glRedraw())}get highlighted(){return this._state.highlighted}set highlighted(e){(e=!!e)!==this._state.highlighted&&(this._state.highlighted=e,this._isObject&&this.scene._objectHighlightedUpdated(this,e),this.glRedraw())}get selected(){return this._state.selected}set selected(e){(e=!!e)!==this._state.selected&&(this._state.selected=e,this._isObject&&this.scene._objectSelectedUpdated(this,e),this.glRedraw())}get edges(){return this._state.edges}set edges(e){(e=!!e)!==this._state.edges&&(this._state.edges=e,this.glRedraw())}get culled(){return this._state.culled}set culled(e){this._state.culled=!!e,this.glRedraw()}get clippable(){return this._state.clippable}set clippable(e){e=!1!==e,this._state.clippable!==e&&(this._state.clippable=e,this.glRedraw())}get collidable(){return this._state.collidable}set collidable(e){(e=!1!==e)!==this._state.collidable&&(this._state.collidable=e,this._setAABBDirty(),this.scene._aabbDirty=!0)}get pickable(){return this._state.pickable}set pickable(e){e=!1!==e,this._state.pickable!==e&&(this._state.pickable=e)}get castsShadow(){return this._state.castsShadow}set castsShadow(e){(e=!1!==e)!==this._state.castsShadow&&(this._state.castsShadow=e,this.glRedraw())}get receivesShadow(){return this._state.receivesShadow}set receivesShadow(e){(e=!1!==e)!==this._state.receivesShadow&&(this._state.receivesShadow=e,this._state.hash=e?"/mod/rs;":"/mod;",this.fire("dirty",this))}get saoEnabled(){return!1}get colorize(){return this._state.colorize}set colorize(e){let t=this._state.colorize;t||(t=this._state.colorize=new Float32Array(4),t[3]=1),e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1);const i=!!e;this.scene._objectColorizeUpdated(this,i),this.glRedraw()}get opacity(){return this._state.colorize[3]}set opacity(e){let t=this._state.colorize;t||(t=this._state.colorize=new Float32Array(4),t[0]=1,t[1]=1,t[2]=1);const i=null!=e;t[3]=i?e:1,this.scene._objectOpacityUpdated(this,i),this.glRedraw()}get transparent(){return 2===this._material.alphaMode||this._state.colorize[3]<1}get layer(){return this._state.layer}set layer(e){e=e||0,(e=Math.round(e))!==this._state.layer&&(this._state.layer=e,this._renderer.needStateSort())}get stationary(){return this._state.stationary}get billboard(){return this._state.billboard}get offset(){return this._state.offset}set offset(e){this._state.offset.set(e||[0,0,0]),this._setAABBDirty(),this.glRedraw()}get isDrawable(){return!0}get isStateSortable(){return!0}get xrayMaterial(){return this._xrayMaterial}get highlightMaterial(){return this._highlightMaterial}get selectedMaterial(){return this._selectedMaterial}get edgeMaterial(){return this._edgeMaterial}_checkBillboard(e){return"spherical"!==(e=e||"none")&&"cylindrical"!==e&&"none"!==e&&(this.error("Unsupported value for 'billboard': "+e+" - accepted values are 'spherical', 'cylindrical' and 'none' - defaulting to 'none'."),e="none"),e}compile(){const e=this.scene,t=this._state,i=[e.canvas.canvas.id,e._sectionPlanesState.getHash()];t.stationary&&i.push("/s"),"none"===t.billboard?i.push("/n"):"spherical"===t.billboard?i.push("/s"):"cylindrical"===t.billboard&&i.push("/c"),i.push(";");const s=i.concat([e.gammaOutput?"go":"",e._lightsState.getHash(),t.receivesShadow?"/rs":""]).join("");this._state.drawHash!==s&&(this._state.drawHash=s,this._renderers._drawRenderer.put(),this._renderers._shadowRenderer.put(),this._renderers._emphasisFillRenderer.put(),this._renderers._emphasisEdgesRenderer.put(),this._renderers._drawRenderer.get(),this._renderers._emphasisFillRenderer.get(),this._renderers._emphasisEdgesRenderer.get());const r=i.join("");this._state.pickOcclusionHash!==r&&(this._state.pickOcclusionHash=r,this._renderers._pickMeshRenderer.put(),this._renderers._pickTriangleRenderer.put(),this._renderers._pickMeshRenderer.get(),this._state.occluder&&(this._renderers._occlusionRenderer.put(),this._renderers._occlusionRenderer.get()))}_setLocalMatrixDirty(){this._localMatrixDirty=!0,this._setWorldMatrixDirty()}_setWorldMatrixDirty(){this._worldMatrixDirty=!0,this._worldNormalMatrixDirty=!0}_buildWorldMatrix(){const e=this.matrix;if(this._parentNode)V.mulMat4(this._parentNode.worldMatrix,e,this._worldMatrix);else for(let t=0,i=e.length;t<i;t++)this._worldMatrix[t]=e[t];this._worldMatrixDirty=!1}_buildWorldNormalMatrix(){this._worldMatrixDirty&&this._buildWorldMatrix(),this._worldNormalMatrix||(this._worldNormalMatrix=V.mat4()),V.transposeMat4(this._worldMatrix,this._worldNormalMatrix),V.inverseMat4(this._worldNormalMatrix),this._worldNormalMatrixDirty=!1}_setAABBDirty(){if(this.collidable)for(let e=this;e;e=e._parentNode)e._aabbDirty=!0}_updateAABB(){this.scene._aabbDirty=!0,this._aabb||(this._aabb=V.AABB3()),this._buildAABB(this.worldMatrix,this._aabb),this._aabbDirty=!1}_buildAABB(e,t){V.transformOBB3(e,this._geometry.obb,Ji),V.OBB3ToAABB3(Ji,t);const i=this._state.offset;if(t[0]+=i[0],t[1]+=i[1],t[2]+=i[2],t[3]+=i[0],t[4]+=i[1],t[5]+=i[2],this._state.origin){const e=this._state.origin;t[0]+=e[0],t[1]+=e[1],t[2]+=e[2],t[3]+=e[0],t[4]+=e[1],t[5]+=e[2]}}rotate(e,t){return Yi[0]=e[0],Yi[1]=e[1],Yi[2]=e[2],Yi[3]=t*V.DEGTORAD,V.angleAxisToQuaternion(Yi,$i),V.mulQuaternions(this.quaternion,$i,qi),this.quaternion=qi,this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw(),this}rotateOnWorldAxis(e,t){return Yi[0]=e[0],Yi[1]=e[1],Yi[2]=e[2],Yi[3]=t*V.DEGTORAD,V.angleAxisToQuaternion(Yi,$i),V.mulQuaternions($i,this.quaternion,$i),this}rotateX(e){return this.rotate(es,e)}rotateY(e){return this.rotate(ts,e)}rotateZ(e){return this.rotate(is,e)}translate(e,t){return V.vec3ApplyQuaternion(this.quaternion,e,ss),V.mulVec3Scalar(ss,t,rs),V.addVec3(this.position,rs,this.position),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw(),this}translateX(e){return this.translate(es,e)}translateY(e){return this.translate(ts,e)}translateZ(e){return this.translate(is,e)}stateSortCompare(e,t){return e._state.layer-t._state.layer||e._renderers._drawRenderer.getId()-t._renderers._drawRenderer.getId()||e._material._state.id-t._material._state.id||e._geometry._state.id-t._geometry._state.id}rebuildRenderFlags(){this.renderFlags.reset(),this._getActiveSectionPlanes()?(this.renderFlags.numLayers=1,this.renderFlags.numVisibleLayers=1,this.renderFlags.visibleLayers[0]=0,this._updateRenderFlags()):this.renderFlags.culled=!0}_updateRenderFlags(){const e=this.renderFlags,t=this._state;if(t.xrayed){const t=this._xrayMaterial._state;t.fill&&(t.fillAlpha<1?e.xrayedSilhouetteTransparent=!0:e.xrayedSilhouetteOpaque=!0),t.edges&&(t.edgeAlpha<1?e.xrayedEdgesTransparent=!0:e.xrayedEdgesOpaque=!0)}else{if(this._material._state.alpha<1||t.colorize[3]<1?e.colorTransparent=!0:e.colorOpaque=!0,t.edges){this._edgeMaterial._state.alpha<1?e.edgesTransparent=!0:e.edgesOpaque=!0}if(t.selected){const t=this._selectedMaterial._state;t.fill&&(t.fillAlpha<1?e.selectedSilhouetteTransparent=!0:e.selectedSilhouetteOpaque=!0),t.edges&&(t.edgeAlpha<1?e.selectedEdgesTransparent=!0:e.selectedEdgesOpaque=!0)}else if(t.highlighted){const t=this._highlightMaterial._state;t.fill&&(t.fillAlpha<1?e.highlightedSilhouetteTransparent=!0:e.highlightedSilhouetteOpaque=!0),t.edges&&(t.edgeAlpha<1?e.highlightedEdgesTransparent=!0:e.highlightedEdgesOpaque=!0)}}}_getActiveSectionPlanes(){if(this._state.clippable){const e=this.scene._sectionPlanesState.sectionPlanes,t=e.length;if(t>0)for(let i=0;i<t;i++){const t=e[i],s=this.renderFlags;if(t.active)if(this._state.origin){const e=V.planeAABB3Intersect(t.dir,t.dist,this.aabb);if(-1===e)return!1;const r=0===e;s.sectionPlanesActivePerLayer[i]=r}else s.sectionPlanesActivePerLayer[i]=!0;else s.sectionPlanesActivePerLayer[i]=!1}}return!0}drawColorOpaque(e){this._renderers._drawRenderer.drawMesh(e,this,this._material)}drawColorTransparent(e){this._renderers._drawRenderer.drawMesh(e,this,this._material)}drawSilhouetteXRayed(e){this._renderers._emphasisFillRenderer.drawMesh(e,this,this._xrayMaterial)}drawSilhouetteHighlighted(e){this._renderers._emphasisFillRenderer.drawMesh(e,this,this._highlightMaterial)}drawSilhouetteSelected(e){this._renderers._emphasisFillRenderer.drawMesh(e,this,this._selectedMaterial)}drawEdgesColorOpaque(e){this._renderers._emphasisEdgesRenderer.drawMesh(e,this,this._edgeMaterial)}drawEdgesColorTransparent(e){this._renderers._emphasisEdgesRenderer.drawMesh(e,this,this._edgeMaterial)}drawEdgesXRayed(e){this._renderers._emphasisEdgesRenderer.drawMesh(e,this,this._xrayMaterial)}drawEdgesHighlighted(e){this._renderers._emphasisEdgesRenderer.drawMesh(e,this,this._highlightMaterial)}drawEdgesSelected(e){this._renderers._emphasisEdgesRenderer.drawMesh(e,this,this._selectedMaterial)}drawOcclusion(e){this._renderers._occlusionRenderer.drawMesh(e,this,this._material)}drawShadow(e){this._renderers._shadowRenderer.drawMesh(e,this,this._material)}drawPickMesh(e){this._renderers._pickMeshRenderer.drawMesh(e,this,this._material)}canPickTriangle(){return this._geometry.isReadableGeometry}drawPickTriangles(e){this._renderers._pickTriangleRenderer.drawMesh(e,this,this._material)}pickTriangleSurface(e,t,i,s){ls(this,e,t,i,s)}drawPickVertices(e){}delegatePickedEntity(){return this}destroy(){super.destroy(),Object.values(this._renderers).forEach((e=>e.put())),this.scene._renderer.putPickID(this._state.pickID),this._isObject&&(this.scene._deregisterObject(this),this._visible&&this.scene._objectVisibilityUpdated(this,!1,!1),this._xrayed&&this.scene._objectXRayedUpdated(this,!1,!1),this._selected&&this.scene._objectSelectedUpdated(this,!1,!1),this._highlighted&&this.scene._objectHighlightedUpdated(this,!1,!1),this.scene._objectColorizeUpdated(this,!1),this.scene._objectOpacityUpdated(this,!1),this.offset.some((e=>0!==e))&&this.scene._objectOffsetUpdated(this,!1)),this._isModel&&this.scene._deregisterModel(this),this.glRedraw()}}const ls=function(){const e=V.vec3(),t=V.vec3(),i=V.vec3(),s=V.vec3(),r=V.vec3(),n=V.vec3(),A=V.vec4(),o=V.vec3(),a=V.vec3(),l=V.vec3(),c=V.vec3(),h=V.vec3(),u=V.vec3(),d=V.vec3(),f=V.vec3(),p=V.vec3(),g=V.vec4(),m=V.vec4(),_=V.vec4(),b=V.vec3(),B=V.vec3(),y=V.vec3(),w=V.vec3(),v=V.vec3(),C=V.vec3(),M=V.vec3(),E=V.vec3(),F=V.vec3(),U=V.vec3(),x=V.vec3();return function(I,T,P,S,D){var k=D.primIndex;if(null!=k&&k>-1){const L=I.geometry._state,H=I.scene,N=H.camera,G=H.canvas;if("triangles"===L.primitiveName){D.primitive="triangle";const H=k,j=L.indices,W=L.positions;let z,X,K;if(j){var Q=j[H+0],R=j[H+1],O=j[H+2];n[0]=Q,n[1]=R,n[2]=O,D.indices=n,z=3*Q,X=3*R,K=3*O}else z=3*H,X=z+3,K=X+3;if(i[0]=W[z+0],i[1]=W[z+1],i[2]=W[z+2],s[0]=W[X+0],s[1]=W[X+1],s[2]=W[X+2],r[0]=W[K+0],r[1]=W[K+1],r[2]=W[K+2],L.compressGeometry){const e=L.positionsDecodeMatrix;e&&(Ne.decompressPosition(i,e,i),Ne.decompressPosition(s,e,s),Ne.decompressPosition(r,e,r))}D.canvasPos?V.canvasPosToLocalRay(G.canvas,I.origin?wt(T,I.origin):T,P,S,I.worldMatrix,D.canvasPos,e,t):D.origin&&D.direction&&V.worldRayToLocalRay(I.worldMatrix,D.origin,D.direction,e,t),V.normalizeVec3(t),V.rayPlaneIntersect(e,t,i,s,r,A),D.localPos=A,D.position=A,g[0]=A[0],g[1]=A[1],g[2]=A[2],g[3]=1,V.transformVec4(I.worldMatrix,g,m),o[0]=m[0],o[1]=m[1],o[2]=m[2],D.canvasPos&&I.origin&&(o[0]+=I.origin[0],o[1]+=I.origin[1],o[2]+=I.origin[2]),D.worldPos=o,V.transformVec4(N.matrix,m,_),a[0]=_[0],a[1]=_[1],a[2]=_[2],D.viewPos=a,V.cartesianToBarycentric(A,i,s,r,l),D.bary=l;const Z=L.normals;if(Z){if(L.compressGeometry){const e=3*Q,t=3*R,i=3*O;Ne.decompressNormal(Z.subarray(e,e+2),c),Ne.decompressNormal(Z.subarray(t,t+2),h),Ne.decompressNormal(Z.subarray(i,i+2),u)}else c[0]=Z[z],c[1]=Z[z+1],c[2]=Z[z+2],h[0]=Z[X],h[1]=Z[X+1],h[2]=Z[X+2],u[0]=Z[K],u[1]=Z[K+1],u[2]=Z[K+2];const e=V.addVec3(V.addVec3(V.mulVec3Scalar(c,l[0],b),V.mulVec3Scalar(h,l[1],B),y),V.mulVec3Scalar(u,l[2],w),v);D.worldNormal=V.normalizeVec3(V.transformVec3(I.worldNormalMatrix,e,C))}const J=L.uv;if(J){if(d[0]=J[2*Q],d[1]=J[2*Q+1],f[0]=J[2*R],f[1]=J[2*R+1],p[0]=J[2*O],p[1]=J[2*O+1],L.compressGeometry){const e=L.uvDecodeMatrix;e&&(Ne.decompressUV(d,e,d),Ne.decompressUV(f,e,f),Ne.decompressUV(p,e,p))}D.uv=V.addVec3(V.addVec3(V.mulVec2Scalar(d,l[0],M),V.mulVec2Scalar(f,l[1],E),F),V.mulVec2Scalar(p,l[2],U),x)}}}}}(),cs=(e,t,i,s,r)=>{const n=r.programVariables,A=i.decodedUv,o=i.worldNormal,a=i.viewNormal,l=e.scene,c=l.canvas.gl,h=e._state.background,u=e._geometry._state,d=u.compressGeometry,f="points"===u.primitiveName,p=n.createUniform("float","pointSize"),g=n.createUniform("mat4","modelMatrix"),m=n.createUniform("mat4","modelNormalMatrix"),_=n.createUniform("vec3","offset"),b=n.createUniform("vec3","scale"),B=n.createUniform("mat4","positionsDecodeMatrix"),y=n.createUniform("mat3","uvDecodeMatrix"),w=n.createUniform("mat4","viewMatrix"),v=n.createUniform("mat4","viewNormalMatrix"),C=n.createUniform("mat4","projMatrix"),M=e.billboard,E=!s.dontBillboardAnything&&("spherical"===M||"cylindrical"===M),F=e.stationary,U=E&&((e,t)=>[`mat4 ${e}(in mat4 matIn) {`," mat4 mat = matIn;",` mat[0].xyz = vec3(${b}[0], 0.0, 0.0);`,..."spherical"===M?[` mat[1].xyz = vec3(0.0, ${b}[1], 0.0);`]:[]," mat[2].xyz = vec3(0.0, 0.0, 1.0);"," return mat;","}"].forEach((e=>t.push(e)))),x=function(){const e=U&&n.createVertexDefinition("billboard",U);return t=>e?`${e}(${t})`:t}(),I=function(){const e=U&&n.createFragmentDefinition("billboard",U);return t=>e?`${e}(${t})`:t}(),T=[];s.dontBillboardAnything?T.push(`mat4 viewMatrix2 = ${w};`):(T.push(`mat4 viewMatrix1 = ${w};`),F?T.push("viewMatrix1[3].xyz = vec3(0.0, 0.0, 0.0);"):h&&T.push("viewMatrix1[3] = vec4(0.0, 0.0, 0.0, 1.0);"),T.push(`mat4 viewMatrix2 = ${I("viewMatrix1")};`));const P="clipPos",S=n.createUniform("bool","clippable"),[D,k]=r.buildProgram(c,s.programName,{appendFragmentOutputs:(e,t,i,r)=>{T.forEach((t=>e.push(t))),s.appendFragmentOutputs(e,t,i,r)},clippableTest:()=>S,clippingCaps:s.clippingCaps,clipPos:h?"clipPos.xyww":P,crossSections:l.crossSections,discardPoints:f&&s.discardPoints,getGammaFactor:l.gammaOutput&&(()=>l.gammaFactor),getLogDepth:!s.dontGetLogDepth&&l.logarithmicDepthBufferEnabled&&(e=>e),getPointSize:s.setupPointSize&&f&&(()=>p),getVertexData:function(){const e=a&&a.needed&&`vec3 ${a} = normalize((${x(v)} * vec4(${o}, 0.0)).xyz);`,i=[];if(i.push(`vec4 localPosition = vec4(${t.position}, 1.0);`),d&&i.push(`localPosition = ${B} * localPosition;`),i.push(`vec4 worldPosition = ${x(g)} * localPosition;`),i.push(`worldPosition.xyz = worldPosition.xyz + ${_};`),s.dontBillboardAnything?i.push(`vec4 viewPosition = ${w} * worldPosition;`):(i.push(`mat4 viewMatrix1 = ${w};`),F?i.push("viewMatrix1[3].xyz = vec3(0.0, 0.0, 0.0);"):h&&i.push("viewMatrix1[3] = vec4(0.0, 0.0, 0.0, 1.0);"),i.push(`mat4 viewMatrix2 = ${x("viewMatrix1")};`),i.push(`vec4 viewPosition = ${E?`${x(`viewMatrix1 * ${g}`)} * localPosition`:"viewMatrix2 * worldPosition"};`)),A&&A.needed&&i.push(`vec2 ${A} = ${d?`(${y} * vec3(${t.uv}, 1.0)).xy`:t.uv};`),o&&o.needed){const e=d?`${n.commonLibrary.octDecode}(${t.normal}.xy)`:t.normal;i.push(`vec3 ${o} = (${x(m)} * vec4(${e}, 0.0)).xyz;`)}return e&&i.push(e),i.push(`vec4 clipPos = ${C} * viewPosition;`),i},projMatrix:C,sectionPlanesState:l._sectionPlanesState,testPerspectiveForGl_FragDepth:!0,usePickClipPos:s.isPick,worldPositionAttribute:"worldPosition"});if(k)return{errors:k};{const e=D.inputSetters;let i=null,r=null;return{destroy:()=>D.destroy(),drawMesh:(n,A,o)=>{if(s.skipIfTransparent&&o.alpha<1)return;const a=o._state,l=A._state,u=A._geometry,d=u._state,f=n.viewParams,M=s.canActAsBackground&&h;n.lastProgramId!==D.id&&(n.lastProgramId=D.id,D.bind(),n.useProgram++,i=null,r=null,M&&c.depthFunc(c.LEQUAL)),a.id!==i&&(n.backfaces!==a.backfaces&&(a.backfaces?c.disable(c.CULL_FACE):c.enable(c.CULL_FACE),n.backfaces=a.backfaces),s.dontSetFrontFace||n.frontface===a.frontface||(c.frontFace(a.frontface?c.CCW:c.CW),n.frontface=a.frontface),s.drawEdges&&n.lineWidth!==a.edgeWidth&&(c.lineWidth(a.edgeWidth),n.lineWidth=a.edgeWidth),s.setsLineWidth&&n.lineWidth!==a.lineWidth&&(c.lineWidth(a.lineWidth),n.lineWidth=a.lineWidth),i=a.id);const E=!s.useShadowView&&A.origin;((t,i)=>{const s=(e,t)=>e.setInputValue&&e.setInputValue(t);s(p,o.pointSize),s(g,A.worldMatrix),s(m,A.worldNormalMatrix),s(_,A.offset),s(b,A.scale),s(B,d.positionsDecodeMatrix),s(y,d.uvDecodeMatrix),s(w,i),s(v,f.viewNormalMatrix),s(C,t),s(S,A.clippable),e.setUniforms(n,{material:o,meshColorize:A.colorize,meshPickID:A._state.pickID,mesh:{origin:A.origin,renderFlags:{sectionPlanesActivePerLayer:A.renderFlags.sectionPlanesActivePerLayer}},view:{far:f.far}})})(f.projMatrix,E?n.getRTCViewMatrix(l.originHash,E):f.viewMatrix);const F=e=>{const i=(e,t)=>{e&&e.setInputValue&&t&&(e.setInputValue(t),n.bindArray++)};i(t.position,(e||d).positionsBuf),i(t.color,d.colorsBuf),i(t.pickColor,e&&e.pickColorsBuf),i(t.uv,d.uvBuf),i(t.normal,d.normalsBuf)};if(s.trianglePick){const e=u._getPickTrianglePositions();d.id!==r&&(F({positionsBuf:e,pickColorsBuf:u._getPickTriangleColors()}),r=d.id),c.drawArrays(d.primitive,0,e.numItems/3)}else if(s.drawEdges){const e=d.primitive===c.TRIANGLES?u._getEdgeIndices():d.primitive===c.LINES&&d.indicesBuf;e&&(d.id!==r&&(F(),e.bind(),n.bindArray++,r=d.id),c.drawElements(c.LINES,e.numItems,e.itemType,0),n.drawElements++)}else d.id!==r&&(F(),d.indicesBuf&&(d.indicesBuf.bind(),n.bindArray++),r=d.id),d.indicesBuf?(c.drawElements(d.primitive,d.indicesBuf.numItems,d.indicesBuf.itemType,0),n.drawElements++):d.positionsBuf&&(c.drawArrays(c.TRIANGLES,0,d.positionsBuf.numItems),n.drawArrays++);M&&c.depthFunc(c.LESS)}}}};class hs extends Ae{get type(){return"Material"}constructor(e,t={}){super(e,t),G.memory.materials++}destroy(){super.destroy(),G.memory.materials--}}const us={opaque:0,mask:1,blend:2},ds=["opaque","mask","blend"];class fs extends hs{get type(){return"PhongMaterial"}constructor(e,t={}){super(e,t),this._state=new Se({type:"PhongMaterial",ambient:V.vec3([1,1,1]),diffuse:V.vec3([1,1,1]),specular:V.vec3([1,1,1]),emissive:V.vec3([0,0,0]),alpha:null,shininess:null,reflectivity:null,alphaMode:null,alphaCutoff:null,lineWidth:null,pointSize:null,backfaces:null,frontface:null,hash:null}),this.ambient=t.ambient,this.diffuse=t.diffuse,this.specular=t.specular,this.emissive=t.emissive,this.alpha=t.alpha,this.shininess=t.shininess,this.reflectivity=t.reflectivity,this.lineWidth=t.lineWidth,this.pointSize=t.pointSize,t.ambientMap&&(this._ambientMap=this._checkComponent("Texture",t.ambientMap)),t.diffuseMap&&(this._diffuseMap=this._checkComponent("Texture",t.diffuseMap)),t.specularMap&&(this._specularMap=this._checkComponent("Texture",t.specularMap)),t.emissiveMap&&(this._emissiveMap=this._checkComponent("Texture",t.emissiveMap)),t.alphaMap&&(this._alphaMap=this._checkComponent("Texture",t.alphaMap)),t.reflectivityMap&&(this._reflectivityMap=this._checkComponent("Texture",t.reflectivityMap)),t.normalMap&&(this._normalMap=this._checkComponent("Texture",t.normalMap)),t.occlusionMap&&(this._occlusionMap=this._checkComponent("Texture",t.occlusionMap)),t.diffuseFresnel&&(this._diffuseFresnel=this._checkComponent("Fresnel",t.diffuseFresnel)),t.specularFresnel&&(this._specularFresnel=this._checkComponent("Fresnel",t.specularFresnel)),t.emissiveFresnel&&(this._emissiveFresnel=this._checkComponent("Fresnel",t.emissiveFresnel)),t.alphaFresnel&&(this._alphaFresnel=this._checkComponent("Fresnel",t.alphaFresnel)),t.reflectivityFresnel&&(this._reflectivityFresnel=this._checkComponent("Fresnel",t.reflectivityFresnel)),this.alphaMode=t.alphaMode,this.alphaCutoff=t.alphaCutoff,this.backfaces=t.backfaces,this.frontface=t.frontface,this._makeHash()}_makeHash(){const e=this._state,t=["/p"];this._normalMap&&(t.push("/nm"),this._normalMap.hasMatrix&&t.push("/mat")),this._ambientMap&&(t.push("/am"),this._ambientMap.hasMatrix&&t.push("/mat"),t.push("/"+this._ambientMap.encoding)),this._diffuseMap&&(t.push("/dm"),this._diffuseMap.hasMatrix&&t.push("/mat"),t.push("/"+this._diffuseMap.encoding)),this._specularMap&&(t.push("/sm"),this._specularMap.hasMatrix&&t.push("/mat")),this._emissiveMap&&(t.push("/em"),this._emissiveMap.hasMatrix&&t.push("/mat"),t.push("/"+this._emissiveMap.encoding)),this._alphaMap&&(t.push("/opm"),this._alphaMap.hasMatrix&&t.push("/mat")),this._reflectivityMap&&(t.push("/rm"),this._reflectivityMap.hasMatrix&&t.push("/mat")),this._occlusionMap&&(t.push("/ocm"),this._occlusionMap.hasMatrix&&t.push("/mat")),this._diffuseFresnel&&t.push("/df"),this._specularFresnel&&t.push("/sf"),this._emissiveFresnel&&t.push("/ef"),this._alphaFresnel&&t.push("/of"),this._reflectivityFresnel&&t.push("/rf"),t.push(";"),e.hash=t.join("")}set ambient(e){let t=this._state.ambient;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.ambient=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}get ambient(){return this._state.ambient}set diffuse(e){let t=this._state.diffuse;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.diffuse=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}get diffuse(){return this._state.diffuse}set specular(e){let t=this._state.specular;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.specular=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}get specular(){return this._state.specular}set emissive(e){let t=this._state.emissive;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.emissive=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=0,t[1]=0,t[2]=0),this.glRedraw()}get emissive(){return this._state.emissive}set alpha(e){e=null!=e?e:1,this._state.alpha!==e&&(this._state.alpha=e,this.glRedraw())}get alpha(){return this._state.alpha}set shininess(e){this._state.shininess=void 0!==e?e:80,this.glRedraw()}get shininess(){return this._state.shininess}set lineWidth(e){this._state.lineWidth=e||1,this.glRedraw()}get lineWidth(){return this._state.lineWidth}set pointSize(e){this._state.pointSize=e||1,this.glRedraw()}get pointSize(){return this._state.pointSize}set reflectivity(e){this._state.reflectivity=void 0!==e?e:1,this.glRedraw()}get reflectivity(){return this._state.reflectivity}get normalMap(){return this._normalMap}get ambientMap(){return this._ambientMap}get diffuseMap(){return this._diffuseMap}get specularMap(){return this._specularMap}get emissiveMap(){return this._emissiveMap}get alphaMap(){return this._alphaMap}get reflectivityMap(){return this._reflectivityMap}get occlusionMap(){return this._occlusionMap}get diffuseFresnel(){return this._diffuseFresnel}get specularFresnel(){return this._specularFresnel}get emissiveFresnel(){return this._emissiveFresnel}get alphaFresnel(){return this._alphaFresnel}get reflectivityFresnel(){return this._reflectivityFresnel}set alphaMode(e){let t=us[e=e||"opaque"];void 0===t&&(this.error("Unsupported value for 'alphaMode': "+e+" - defaulting to 'opaque'"),t="opaque"),this._state.alphaMode!==t&&(this._state.alphaMode=t,this.glRedraw())}get alphaMode(){return ds[this._state.alphaMode]}set alphaCutoff(e){null==e&&(e=.5),this._state.alphaCutoff!==e&&(this._state.alphaCutoff=e)}get alphaCutoff(){return this._state.alphaCutoff}set backfaces(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}get backfaces(){return this._state.backfaces}set frontface(e){e="cw"!==e,this._state.frontface!==e&&(this._state.frontface=e,this.glRedraw())}get frontface(){return this._state.frontface?"ccw":"cw"}destroy(){super.destroy(),this._state.destroy()}}function ps(e,t){if(void 0===e._cachedExtensions&&(e._cachedExtensions={}),void 0!==e._cachedExtensions[t])return e._cachedExtensions[t];let i;switch(t){case"WEBGL_depth_texture":i=e.getExtension("WEBGL_depth_texture")||e.getExtension("MOZ_WEBGL_depth_texture")||e.getExtension("WEBKIT_WEBGL_depth_texture");break;case"EXT_texture_filter_anisotropic":i=e.getExtension("EXT_texture_filter_anisotropic")||e.getExtension("MOZ_EXT_texture_filter_anisotropic")||e.getExtension("WEBKIT_EXT_texture_filter_anisotropic");break;case"WEBGL_compressed_texture_s3tc":i=e.getExtension("WEBGL_compressed_texture_s3tc")||e.getExtension("MOZ_WEBGL_compressed_texture_s3tc")||e.getExtension("WEBKIT_WEBGL_compressed_texture_s3tc");break;case"WEBGL_compressed_texture_pvrtc":i=e.getExtension("WEBGL_compressed_texture_pvrtc")||e.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc");break;default:i=e.getExtension(t)}return e._cachedExtensions[t]=i,i}function gs(e,t,i=null){let s;const r=t;if(1009===r)return e.UNSIGNED_BYTE;if(1017===r)return e.UNSIGNED_SHORT_4_4_4_4;if(1018===r)return e.UNSIGNED_SHORT_5_5_5_1;if(1010===r)return e.BYTE;if(1011===r)return e.SHORT;if(1012===r)return e.UNSIGNED_SHORT;if(1013===r)return e.INT;if(1014===r)return e.UNSIGNED_INT;if(1015===r)return e.FLOAT;if(1016===r)return e.HALF_FLOAT;if(1021===r)return e.ALPHA;if(1023===r)return e.RGBA;if(1024===r)return e.LUMINANCE;if(1025===r)return e.LUMINANCE_ALPHA;if(1026===r)return e.DEPTH_COMPONENT;if(1027===r)return e.DEPTH_STENCIL;if(1028===r)return e.RED;if(1022===r)return e.RGBA;if(1029===r)return e.RED_INTEGER;if(1030===r)return e.RG;if(1031===r)return e.RG_INTEGER;if(1033===r)return e.RGBA_INTEGER;if(33776===r||33777===r||33778===r||33779===r)if(3001===i){const t=ps(e,"WEBGL_compressed_texture_s3tc_srgb");if(null===t)return null;if(33776===r)return t.COMPRESSED_SRGB_S3TC_DXT1_EXT;if(33777===r)return t.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;if(33778===r)return t.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;if(33779===r)return t.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}else{if(s=ps(e,"WEBGL_compressed_texture_s3tc"),null===s)return null;if(33776===r)return s.COMPRESSED_RGB_S3TC_DXT1_EXT;if(33777===r)return s.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(33778===r)return s.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(33779===r)return s.COMPRESSED_RGBA_S3TC_DXT5_EXT}if(35840===r||35841===r||35842===r||35843===r){const t=ps(e,"WEBGL_compressed_texture_pvrtc");if(null===t)return null;if(35840===r)return t.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(35841===r)return t.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(35842===r)return t.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(35843===r)return t.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}if(36196===r){const t=ps(e,"WEBGL_compressed_texture_etc1");return null!==t?t.COMPRESSED_RGB_ETC1_WEBGL:null}if(37492===r||37496===r){const t=ps(e,"WEBGL_compressed_texture_etc");if(null===t)return null;if(37492===r)return 3001===i?t.COMPRESSED_SRGB8_ETC2:t.COMPRESSED_RGB8_ETC2;if(37496===r)return 3001===i?t.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:t.COMPRESSED_RGBA8_ETC2_EAC}if(37808===r||37809===r||37810===r||37811===r||37812===r||37813===r||37814===r||37815===r||37816===r||37817===r||37818===r||37819===r||37820===r||37821===r){const t=ps(e,"WEBGL_compressed_texture_astc");if(null===t)return null;if(37808===r)return 3001===i?t.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:t.COMPRESSED_RGBA_ASTC_4x4_KHR;if(37809===r)return 3001===i?t.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:t.COMPRESSED_RGBA_ASTC_5x4_KHR;if(37810===r)return 3001===i?t.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:t.COMPRESSED_RGBA_ASTC_5x5_KHR;if(37811===r)return 3001===i?t.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:t.COMPRESSED_RGBA_ASTC_6x5_KHR;if(37812===r)return 3001===i?t.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:t.COMPRESSED_RGBA_ASTC_6x6_KHR;if(37813===r)return 3001===i?t.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:t.COMPRESSED_RGBA_ASTC_8x5_KHR;if(37814===r)return 3001===i?t.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:t.COMPRESSED_RGBA_ASTC_8x6_KHR;if(37815===r)return 3001===i?t.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:t.COMPRESSED_RGBA_ASTC_8x8_KHR;if(37816===r)return 3001===i?t.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:t.COMPRESSED_RGBA_ASTC_10x5_KHR;if(37817===r)return 3001===i?t.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:t.COMPRESSED_RGBA_ASTC_10x6_KHR;if(37818===r)return 3001===i?t.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:t.COMPRESSED_RGBA_ASTC_10x8_KHR;if(37819===r)return 3001===i?t.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:t.COMPRESSED_RGBA_ASTC_10x10_KHR;if(37820===r)return 3001===i?t.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:t.COMPRESSED_RGBA_ASTC_12x10_KHR;if(37821===r)return 3001===i?t.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:t.COMPRESSED_RGBA_ASTC_12x12_KHR}if(36492===r){const t=ps(e,"EXT_texture_compression_bptc");if(null===t)return null;if(36492===r)return 3001===i?t.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:t.COMPRESSED_RGBA_BPTC_UNORM_EXT}return 1020===r?e.UNSIGNED_INT_24_8:1e3===r?e.REPEAT:1001===r?e.CLAMP_TO_EDGE:1004===r||1005===r?e.NEAREST_MIPMAP_LINEAR:1007===r?e.LINEAR_MIPMAP_NEAREST:1008===r?e.LINEAR_MIPMAP_LINEAR:1003===r?e.NEAREST:1006===r?e.LINEAR:null}const ms=new Uint8Array([0,0,0,1]);class _s{constructor({gl:e,target:t,format:i,type:s,wrapS:r,wrapT:n,wrapR:A,encoding:o,preloadColor:a,premultiplyAlpha:l,flipY:c}){this.gl=e,this.target=t||e.TEXTURE_2D,this.format=i||1023,this.type=s||1009,this.internalFormat=null,this.premultiplyAlpha=!!l,this.flipY=!!c,this.unpackAlignment=4,this.wrapS=r||1e3,this.wrapT=n||1e3,this.wrapR=A||1e3,this.encoding=o||3001,this.texture=e.createTexture(),a&&this.setPreloadColor(a),this.allocated=!0}setPreloadColor(e){e?(ms[0]=Math.floor(255*e[0]),ms[1]=Math.floor(255*e[1]),ms[2]=Math.floor(255*e[2]),ms[3]=Math.floor(255*(void 0!==e[3]?e[3]:1))):(ms[0]=0,ms[1]=0,ms[2]=0,ms[3]=255);const t=this.gl;if(t.bindTexture(this.target,this.texture),this.target===t.TEXTURE_CUBE_MAP){const e=[t.TEXTURE_CUBE_MAP_POSITIVE_X,t.TEXTURE_CUBE_MAP_NEGATIVE_X,t.TEXTURE_CUBE_MAP_POSITIVE_Y,t.TEXTURE_CUBE_MAP_NEGATIVE_Y,t.TEXTURE_CUBE_MAP_POSITIVE_Z,t.TEXTURE_CUBE_MAP_NEGATIVE_Z];for(let i=0,s=e.length;i<s;i++)t.texImage2D(e[i],0,t.RGBA,1,1,0,t.RGBA,t.UNSIGNED_BYTE,ms)}else t.texImage2D(this.target,0,t.RGBA,1,1,0,t.RGBA,t.UNSIGNED_BYTE,ms);t.bindTexture(this.target,null)}setTarget(e){this.target=e||this.gl.TEXTURE_2D}setImage(e,t={}){const i=this.gl;void 0!==t.format&&(this.format=t.format),void 0!==t.internalFormat&&(this.internalFormat=t.internalFormat),void 0!==t.encoding&&(this.encoding=t.encoding),void 0!==t.type&&(this.type=t.type),void 0!==t.flipY&&(this.flipY=t.flipY),void 0!==t.premultiplyAlpha&&(this.premultiplyAlpha=t.premultiplyAlpha),void 0!==t.unpackAlignment&&(this.unpackAlignment=t.unpackAlignment),void 0!==t.minFilter&&(this.minFilter=t.minFilter),void 0!==t.magFilter&&(this.magFilter=t.magFilter),void 0!==t.wrapS&&(this.wrapS=t.wrapS),void 0!==t.wrapT&&(this.wrapT=t.wrapT),void 0!==t.wrapR&&(this.wrapR=t.wrapR);let s=!1;i.bindTexture(this.target,this.texture);const r=i.getParameter(i.UNPACK_FLIP_Y_WEBGL);i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL,this.flipY);const n=i.getParameter(i.UNPACK_PREMULTIPLY_ALPHA_WEBGL);i.pixelStorei(i.UNPACK_PREMULTIPLY_ALPHA_WEBGL,this.premultiplyAlpha);const A=i.getParameter(i.UNPACK_ALIGNMENT);i.pixelStorei(i.UNPACK_ALIGNMENT,this.unpackAlignment);const o=i.getParameter(i.UNPACK_COLORSPACE_CONVERSION_WEBGL);i.pixelStorei(i.UNPACK_COLORSPACE_CONVERSION_WEBGL,i.NONE);const a=gs(i,this.minFilter);i.texParameteri(this.target,i.TEXTURE_MIN_FILTER,a),a!==i.NEAREST_MIPMAP_NEAREST&&a!==i.LINEAR_MIPMAP_NEAREST&&a!==i.NEAREST_MIPMAP_LINEAR&&a!==i.LINEAR_MIPMAP_LINEAR||(s=!0);const l=gs(i,this.magFilter);l&&i.texParameteri(this.target,i.TEXTURE_MAG_FILTER,l);const c=gs(i,this.wrapS);c&&i.texParameteri(this.target,i.TEXTURE_WRAP_S,c);const h=gs(i,this.wrapT);h&&i.texParameteri(this.target,i.TEXTURE_WRAP_T,h);const u=gs(i,this.format,this.encoding),d=gs(i,this.type),f=bs(i,this.internalFormat,u,d,this.encoding,!1);if(this.target===i.TEXTURE_CUBE_MAP){if(X.isArray(e)){const t=e,s=[i.TEXTURE_CUBE_MAP_POSITIVE_X,i.TEXTURE_CUBE_MAP_NEGATIVE_X,i.TEXTURE_CUBE_MAP_POSITIVE_Y,i.TEXTURE_CUBE_MAP_NEGATIVE_Y,i.TEXTURE_CUBE_MAP_POSITIVE_Z,i.TEXTURE_CUBE_MAP_NEGATIVE_Z];for(let e=0,r=s.length;e<r;e++)i.texImage2D(s[e],0,f,u,d,t[e])}}else i.texImage2D(i.TEXTURE_2D,0,f,u,d,e);s&&i.generateMipmap(this.target),i.bindTexture(this.target,null),i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL,r),i.pixelStorei(i.UNPACK_PREMULTIPLY_ALPHA_WEBGL,n),i.pixelStorei(i.UNPACK_ALIGNMENT,A),i.pixelStorei(i.UNPACK_COLORSPACE_CONVERSION_WEBGL,o)}setCompressedData({mipmaps:e,props:t={}}){const i=this.gl,s=e.length;void 0!==t.format&&(this.format=t.format),void 0!==t.internalFormat&&(this.internalFormat=t.internalFormat),void 0!==t.encoding&&(this.encoding=t.encoding),void 0!==t.type&&(this.type=t.type),void 0!==t.flipY&&(this.flipY=t.flipY),void 0!==t.premultiplyAlpha&&(this.premultiplyAlpha=t.premultiplyAlpha),void 0!==t.unpackAlignment&&(this.unpackAlignment=t.unpackAlignment),void 0!==t.minFilter&&(this.minFilter=t.minFilter),void 0!==t.magFilter&&(this.magFilter=t.magFilter),void 0!==t.wrapS&&(this.wrapS=t.wrapS),void 0!==t.wrapT&&(this.wrapT=t.wrapT),void 0!==t.wrapR&&(this.wrapR=t.wrapR),i.activeTexture(i.TEXTURE0+0),i.bindTexture(this.target,this.texture);let r=e.length>1;i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL,this.flipY),i.pixelStorei(i.UNPACK_PREMULTIPLY_ALPHA_WEBGL,this.premultiplyAlpha),i.pixelStorei(i.UNPACK_ALIGNMENT,this.unpackAlignment),i.pixelStorei(i.UNPACK_COLORSPACE_CONVERSION_WEBGL,i.NONE);const n=gs(i,this.wrapS);n&&i.texParameteri(this.target,i.TEXTURE_WRAP_S,n);const A=gs(i,this.wrapT);if(A&&i.texParameteri(this.target,i.TEXTURE_WRAP_T,A),this.type===i.TEXTURE_3D||this.type===i.TEXTURE_2D_ARRAY){const e=gs(i,this.wrapR);e&&i.texParameteri(this.target,i.TEXTURE_WRAP_R,e),i.texParameteri(this.type,i.TEXTURE_WRAP_R,e)}r?(i.texParameteri(this.target,i.TEXTURE_MIN_FILTER,Bs(i,this.minFilter)),i.texParameteri(this.target,i.TEXTURE_MAG_FILTER,Bs(i,this.magFilter))):(i.texParameteri(this.target,i.TEXTURE_MIN_FILTER,gs(i,this.minFilter)),i.texParameteri(this.target,i.TEXTURE_MAG_FILTER,gs(i,this.magFilter)));const o=gs(i,this.format,this.encoding),a=gs(i,this.type),l=bs(i,this.internalFormat,o,a,this.encoding,!1);i.texStorage2D(i.TEXTURE_2D,s,l,e[0].width,e[0].height);for(let t=0,s=e.length;t<s;t++){const s=e[t];1023!==this.format?null!==o?i.compressedTexSubImage2D(i.TEXTURE_2D,t,0,0,s.width,s.height,o,s.data):console.warn("Attempt to load unsupported compressed texture format in .setCompressedData()"):i.texSubImage2D(i.TEXTURE_2D,t,0,0,s.width,s.height,o,a,s.data)}i.bindTexture(this.target,null)}setProps(e){const t=this.gl;t.bindTexture(this.target,this.texture),this._uploadProps(e),t.bindTexture(this.target,null)}_uploadProps(e){const t=this.gl;if(void 0!==e.format&&(this.format=e.format),void 0!==e.internalFormat&&(this.internalFormat=e.internalFormat),void 0!==e.encoding&&(this.encoding=e.encoding),void 0!==e.type&&(this.type=e.type),void 0!==e.minFilter){const i=gs(t,e.minFilter);i&&(this.minFilter=e.minFilter,t.texParameteri(this.target,t.TEXTURE_MIN_FILTER,i),i!==t.NEAREST_MIPMAP_NEAREST&&i!==t.LINEAR_MIPMAP_NEAREST&&i!==t.NEAREST_MIPMAP_LINEAR&&i!==t.LINEAR_MIPMAP_LINEAR||t.generateMipmap(this.target))}if(void 0!==e.magFilter){const i=gs(t,e.magFilter);i&&(this.magFilter=e.magFilter,t.texParameteri(this.target,t.TEXTURE_MAG_FILTER,i))}if(void 0!==e.wrapS){const i=gs(t,e.wrapS);i&&(this.wrapS=e.wrapS,t.texParameteri(this.target,t.TEXTURE_WRAP_S,i))}if(void 0!==e.wrapT){const i=gs(t,e.wrapT);i&&(this.wrapT=e.wrapT,t.texParameteri(this.target,t.TEXTURE_WRAP_T,i))}}bind(e){if(this.allocated){if(this.texture){const t=this.gl;return t.activeTexture(t["TEXTURE"+e]),t.bindTexture(this.target,this.texture),!0}return!1}}unbind(e){if(this.allocated&&this.texture){const t=this.gl;t.activeTexture(t["TEXTURE"+e]),t.bindTexture(this.target,null)}}destroy(){this.allocated&&this.texture&&(this.gl.deleteTexture(this.texture),this.texture=null)}}function bs(e,t,i,s,r,n=!1){if(null!==t){if(void 0!==e[t])return e[t];console.warn("Attempt to use non-existing WebGL internal format '"+t+"'")}let A=i;return i===e.RED&&(s===e.FLOAT&&(A=e.R32F),s===e.HALF_FLOAT&&(A=e.R16F),s===e.UNSIGNED_BYTE&&(A=e.R8)),i===e.RG&&(s===e.FLOAT&&(A=e.RG32F),s===e.HALF_FLOAT&&(A=e.RG16F),s===e.UNSIGNED_BYTE&&(A=e.RG8)),i===e.RGBA&&(s===e.FLOAT&&(A=e.RGBA32F),s===e.HALF_FLOAT&&(A=e.RGBA16F),s===e.UNSIGNED_BYTE&&(A=3001===r&&!1===n?e.SRGB8_ALPHA8:e.RGBA8),s===e.UNSIGNED_SHORT_4_4_4_4&&(A=e.RGBA4),s===e.UNSIGNED_SHORT_5_5_5_1&&(A=e.RGB5_A1)),A!==e.R16F&&A!==e.R32F&&A!==e.RG16F&&A!==e.RG32F&&A!==e.RGBA16F&&A!==e.RGBA32F||ps(e,"EXT_color_buffer_float"),A}function Bs(e,t){return 1003===t||1004===t||1005===t?e.NEAREST:e.LINEAR}function ys(e){if(!ws(e.width)||!ws(e.height)){const t=document.createElement("canvas");t.width=vs(e.width),t.height=vs(e.height);t.getContext("2d").drawImage(e,0,0,e.width,e.height,0,0,t.width,t.height),e=t}return e}function ws(e){return 0==(e&e-1)}function vs(e){--e;for(let t=1;t<32;t<<=1)e|=e>>t;return e+1}class Cs extends Ae{get type(){return"Texture"}constructor(e,t={}){super(e,t),this._state=new Se({texture:new _s({gl:this.scene.canvas.gl}),matrix:V.identityMat4(),hasMatrix:t.translate&&(0!==t.translate[0]||0!==t.translate[1])||!!t.rotate||t.scale&&(0!==t.scale[0]||0!==t.scale[1]),minFilter:this._checkMinFilter(t.minFilter),magFilter:this._checkMagFilter(t.magFilter),wrapS:this._checkWrapS(t.wrapS),wrapT:this._checkWrapT(t.wrapT),flipY:this._checkFlipY(t.flipY),encoding:this._checkEncoding(t.encoding)}),this._src=null,this._image=null,this._translate=V.vec2([0,0]),this._scale=V.vec2([1,1]),this._rotate=V.vec2([0,0]),this._matrixDirty=!1,this.translate=t.translate,this.scale=t.scale,this.rotate=t.rotate,t.src?this.src=t.src:t.image&&(this.image=t.image),G.memory.textures++}_checkMinFilter(e){return 1006!==(e=e||1008)&&1007!==e&&1008!==e&&1005!==e&&1004!==e&&(this.error("Unsupported value for 'minFilter' - supported values are LinearFilter, LinearMipMapNearestFilter, NearestMipMapNearestFilter, NearestMipMapLinearFilter and LinearMipMapLinearFilter. Defaulting to LinearMipMapLinearFilter."),e=1008),e}_checkMagFilter(e){return 1006!==(e=e||1006)&&1003!==e&&(this.error("Unsupported value for 'magFilter' - supported values are LinearFilter and NearestFilter. Defaulting to LinearFilter."),e=1006),e}_checkWrapS(e){return 1001!==(e=e||1e3)&&1002!==e&&1e3!==e&&(this.error("Unsupported value for 'wrapS' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),e=1e3),e}_checkWrapT(e){return 1001!==(e=e||1e3)&&1002!==e&&1e3!==e&&(this.error("Unsupported value for 'wrapT' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),e=1e3),e}_checkFlipY(e){return!!e}_checkEncoding(e){return 3e3!==(e=e||3e3)&&3001!==e&&(this.error("Unsupported value for 'encoding' - supported values are LinearEncoding and sRGBEncoding. Defaulting to LinearEncoding."),e=3e3),e}_update(){const e=this._state;if(this._matrixDirty){let t,i;0===this._translate[0]&&0===this._translate[1]||(t=V.translationMat4v([this._translate[0],this._translate[1],0],this._state.matrix)),1===this._scale[0]&&1===this._scale[1]||(i=V.scalingMat4v([this._scale[0],this._scale[1],1]),t=t?V.mulMat4(t,i):i),0!==this._rotate&&(i=V.rotationMat4v(.0174532925*this._rotate,[0,0,1]),t=t?V.mulMat4(t,i):i),t&&(e.matrix=t),this._matrixDirty=!1}this.glRedraw()}set image(e){this._image=ys(e),this._image.crossOrigin="Anonymous",this._state.texture.setImage(this._image,this._state),this._src=null,this.glRedraw()}get image(){return this._image}set src(e){this.scene.loading++,this.scene.canvas.spinner.processes++;const t=this;let i=new Image;i.onload=function(){i=ys(i),t._state.texture.setImage(i,t._state),t.scene.loading--,t.glRedraw(),t.scene.canvas.spinner.processes--},i.src=e,this._src=e,this._image=null}get src(){return this._src}set translate(e){this._translate.set(e||[0,0]),this._matrixDirty=!0,this._needUpdate()}get translate(){return this._translate}set scale(e){this._scale.set(e||[1,1]),this._matrixDirty=!0,this._needUpdate()}get scale(){return this._scale}set rotate(e){e=e||0,this._rotate!==e&&(this._rotate=e,this._matrixDirty=!0,this._needUpdate())}get rotate(){return this._rotate}get minFilter(){return this._state.minFilter}get magFilter(){return this._state.magFilter}get wrapS(){return this._state.wrapS}get wrapT(){return this._state.wrapT}get flipY(){return this._state.flipY}get encoding(){return this._state.encoding}destroy(){super.destroy(),this._state.texture&&this._state.texture.destroy(),this._state.destroy(),G.memory.textures--}}const Ms=V.vec3(),Es=V.vec3();V.vec3();const Fs=V.vec3([0,-1,0]),Us=V.vec4([0,0,0,1]);class xs extends Ae{constructor(e,t={}){super(e,t),this._src=null,this._image=null,this._pos=V.vec3(),this._origin=V.vec3(),this._rtcPos=V.vec3(),this._dir=V.vec3(),this._size=1,this._imageSize=V.vec2(),this._texture=new Cs(this),this._plane=new as(this,{geometry:new We(this,st({center:[0,0,0],xSize:1,zSize:1,xSegments:10,zSegments:10})),material:new fs(this,{diffuse:[0,0,0],ambient:[0,0,0],specular:[0,0,0],diffuseMap:this._texture,emissiveMap:this._texture,backfaces:!0}),clippable:t.clippable}),this._grid=new as(this,{geometry:new We(this,it({size:1,divisions:10})),material:new fs(this,{diffuse:[0,0,0],ambient:[0,0,0],emissive:[.2,.8,.2]}),position:[0,.001,0],clippable:t.clippable}),this._node=new Bt(this,{rotation:[0,0,0],position:[0,0,0],scale:[1,1,1],clippable:!1,children:[this._plane,this._grid]}),this._gridVisible=!1,this.visible=!0,this.gridVisible=t.gridVisible,this.position=t.position,this.rotation=t.rotation,this.dir=t.dir,this.size=t.size,this.collidable=t.collidable,this.clippable=t.clippable,this.pickable=t.pickable,this.opacity=t.opacity,t.image?this.image=t.image:this.src=t.src}set visible(e){this._plane.visible=e,this._grid.visible=this._gridVisible&&e}get visible(){return this._plane.visible}set gridVisible(e){e=!1!==e,this._gridVisible=e,this._grid.visible=this._gridVisible&&this.visible}get gridVisible(){return this._gridVisible}set image(e){this._image=e,this._image&&(this._imageSize[0]=e.width,this._imageSize[1]=e.height,this._updatePlaneSizeFromImage(),this._src=null,this._texture.image=this._image)}get image(){return this._image}set src(e){if(this._src=e,this._src){this._image=null;const e=new Image;e.onload=()=>{this._texture.image=e,this._imageSize[0]=e.width,this._imageSize[1]=e.height,this._updatePlaneSizeFromImage()},e.src=this._src}}get src(){return this._src}set position(e){this._pos.set(e||[0,0,0]),vt(this._pos,this._origin,this._rtcPos),this._node.origin=this._origin,this._node.position=this._rtcPos}get position(){return this._pos}set rotation(e){this._node.rotation=e}get rotation(){return this._node.rotation}set size(e){this._size=null==e?1:e,this._image&&this._updatePlaneSizeFromImage()}get size(){return this._size}set dir(e){if(this._dir.set(e||[0,0,-1]),e){const t=this.scene.center,i=[-this._dir[0],-this._dir[1],-this._dir[2]];V.subVec3(t,this.position,Ms);const s=-V.dotVec3(i,Ms);V.normalizeVec3(i),V.mulVec3Scalar(i,s,Es),V.vec3PairToQuaternion(Fs,e,Us),this._node.quaternion=Us}}get dir(){return this._dir}set collidable(e){this._node.collidable=!1!==e}get collidable(){return this._node.collidable}set clippable(e){this._node.clippable=!1!==e}get clippable(){return this._node.clippable}set pickable(e){this._node.pickable=!1!==e}get pickable(){return this._node.pickable}set opacity(e){this._node.opacity=e}get opacity(){return this._node.opacity}destroy(){super.destroy()}_updatePlaneSizeFromImage(){const e=this._size,t=this._imageSize[0],i=this._imageSize[1];if(t>i){const s=i/t;this._node.scale=[e,1,e*s]}else{const s=t/i;this._node.scale=[e*s,1,e]}}}class Is extends hs{get type(){return"LambertMaterial"}constructor(e,t={}){super(e,t),this._state=new Se({type:"LambertMaterial",ambient:V.vec3([1,1,1]),color:V.vec3([1,1,1]),emissive:V.vec3([0,0,0]),alpha:null,alphaMode:0,lineWidth:null,pointSize:null,backfaces:null,frontface:null,hash:"/lam;"}),this.ambient=t.ambient,this.color=t.color,this.emissive=t.emissive,this.alpha=t.alpha,this.lineWidth=t.lineWidth,this.pointSize=t.pointSize,this.backfaces=t.backfaces,this.frontface=t.frontface}set ambient(e){let t=this._state.ambient;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.ambient=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}get ambient(){return this._state.ambient}set color(e){let t=this._state.color;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.color=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}get color(){return this._state.color}set emissive(e){let t=this._state.emissive;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.emissive=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=0,t[1]=0,t[2]=0),this.glRedraw()}get emissive(){return this._state.emissive}set alpha(e){e=null!=e?e:1,this._state.alpha!==e&&(this._state.alpha=e,this._state.alphaMode=e<1?2:0,this.glRedraw())}get alpha(){return this._state.alpha}set lineWidth(e){this._state.lineWidth=e||1,this.glRedraw()}get lineWidth(){return this._state.lineWidth}set pointSize(e){this._state.pointSize=e||1,this.glRedraw()}get pointSize(){return this._state.pointSize}set backfaces(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}get backfaces(){return this._state.backfaces}set frontface(e){e="cw"!==e,this._state.frontface!==e&&(this._state.frontface=e,this.glRedraw())}get frontface(){return this._state.frontface?"ccw":"cw"}_getState(){return this._state}destroy(){super.destroy(),this._state.destroy()}}const Ts={opaque:0,mask:1,blend:2},Ps=["opaque","mask","blend"];class Ss extends hs{get type(){return"MetallicMaterial"}constructor(e,t={}){super(e,t),this._state=new Se({type:"MetallicMaterial",baseColor:V.vec4([1,1,1]),emissive:V.vec4([0,0,0]),metallic:null,roughness:null,specularF0:null,alpha:null,alphaMode:null,alphaCutoff:null,lineWidth:null,pointSize:null,backfaces:null,frontface:null,hash:null}),this.baseColor=t.baseColor,this.metallic=t.metallic,this.roughness=t.roughness,this.specularF0=t.specularF0,this.emissive=t.emissive,this.alpha=t.alpha,t.baseColorMap&&(this._baseColorMap=this._checkComponent("Texture",t.baseColorMap)),t.metallicMap&&(this._metallicMap=this._checkComponent("Texture",t.metallicMap)),t.roughnessMap&&(this._roughnessMap=this._checkComponent("Texture",t.roughnessMap)),t.metallicRoughnessMap&&(this._metallicRoughnessMap=this._checkComponent("Texture",t.metallicRoughnessMap)),t.emissiveMap&&(this._emissiveMap=this._checkComponent("Texture",t.emissiveMap)),t.occlusionMap&&(this._occlusionMap=this._checkComponent("Texture",t.occlusionMap)),t.alphaMap&&(this._alphaMap=this._checkComponent("Texture",t.alphaMap)),t.normalMap&&(this._normalMap=this._checkComponent("Texture",t.normalMap)),this.alphaMode=t.alphaMode,this.alphaCutoff=t.alphaCutoff,this.backfaces=t.backfaces,this.frontface=t.frontface,this.lineWidth=t.lineWidth,this.pointSize=t.pointSize,this._makeHash()}_makeHash(){const e=this._state,t=["/met"];this._baseColorMap&&(t.push("/bm"),this._baseColorMap._state.hasMatrix&&t.push("/mat"),t.push("/"+this._baseColorMap._state.encoding)),this._metallicMap&&(t.push("/mm"),this._metallicMap._state.hasMatrix&&t.push("/mat")),this._roughnessMap&&(t.push("/rm"),this._roughnessMap._state.hasMatrix&&t.push("/mat")),this._metallicRoughnessMap&&(t.push("/mrm"),this._metallicRoughnessMap._state.hasMatrix&&t.push("/mat")),this._emissiveMap&&(t.push("/em"),this._emissiveMap._state.hasMatrix&&t.push("/mat")),this._occlusionMap&&(t.push("/ocm"),this._occlusionMap._state.hasMatrix&&t.push("/mat")),this._alphaMap&&(t.push("/am"),this._alphaMap._state.hasMatrix&&t.push("/mat")),this._normalMap&&(t.push("/nm"),this._normalMap._state.hasMatrix&&t.push("/mat")),t.push(";"),e.hash=t.join("")}set baseColor(e){let t=this._state.baseColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.baseColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}get baseColor(){return this._state.baseColor}get baseColorMap(){return this._baseColorMap}set metallic(e){e=null!=e?e:1,this._state.metallic!==e&&(this._state.metallic=e,this.glRedraw())}get metallic(){return this._state.metallic}get metallicMap(){return this._attached.metallicMap}set roughness(e){e=null!=e?e:1,this._state.roughness!==e&&(this._state.roughness=e,this.glRedraw())}get roughness(){return this._state.roughness}get roughnessMap(){return this._attached.roughnessMap}get metallicRoughnessMap(){return this._attached.metallicRoughnessMap}set specularF0(e){e=null!=e?e:0,this._state.specularF0!==e&&(this._state.specularF0=e,this.glRedraw())}get specularF0(){return this._state.specularF0}set emissive(e){let t=this._state.emissive;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.emissive=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=0,t[1]=0,t[2]=0),this.glRedraw()}get emissive(){return this._state.emissive}get emissiveMap(){return this._attached.emissiveMap}get occlusionMap(){return this._attached.occlusionMap}set alpha(e){e=null!=e?e:1,this._state.alpha!==e&&(this._state.alpha=e,this.glRedraw())}get alpha(){return this._state.alpha}get alphaMap(){return this._attached.alphaMap}get normalMap(){return this._attached.normalMap}set alphaMode(e){let t=Ts[e=e||"opaque"];void 0===t&&(this.error("Unsupported value for 'alphaMode': "+e+" defaulting to 'opaque'"),t="opaque"),this._state.alphaMode!==t&&(this._state.alphaMode=t,this.glRedraw())}get alphaMode(){return Ps[this._state.alphaMode]}set alphaCutoff(e){null==e&&(e=.5),this._state.alphaCutoff!==e&&(this._state.alphaCutoff=e)}get alphaCutoff(){return this._state.alphaCutoff}set backfaces(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}get backfaces(){return this._state.backfaces}set frontface(e){e="cw"!==e,this._state.frontface!==e&&(this._state.frontface=e,this.glRedraw())}get frontface(){return this._state.frontface?"ccw":"cw"}set lineWidth(e){this._state.lineWidth=e||1,this.glRedraw()}get lineWidth(){return this._state.lineWidth}set pointSize(e){this._state.pointSize=e||1,this.glRedraw()}get pointSize(){return this._state.pointSize}destroy(){super.destroy(),this._state.destroy()}}const Ds={opaque:0,mask:1,blend:2},ks=["opaque","mask","blend"];class Qs extends hs{get type(){return"SpecularMaterial"}constructor(e,t={}){super(e,t),this._state=new Se({type:"SpecularMaterial",diffuse:V.vec3([1,1,1]),emissive:V.vec3([0,0,0]),specular:V.vec3([1,1,1]),glossiness:null,specularF0:null,alpha:null,alphaMode:null,alphaCutoff:null,lineWidth:null,pointSize:null,backfaces:null,frontface:null,hash:null}),this.diffuse=t.diffuse,this.specular=t.specular,this.glossiness=t.glossiness,this.specularF0=t.specularF0,this.emissive=t.emissive,this.alpha=t.alpha,t.diffuseMap&&(this._diffuseMap=this._checkComponent("Texture",t.diffuseMap)),t.emissiveMap&&(this._emissiveMap=this._checkComponent("Texture",t.emissiveMap)),t.specularMap&&(this._specularMap=this._checkComponent("Texture",t.specularMap)),t.glossinessMap&&(this._glossinessMap=this._checkComponent("Texture",t.glossinessMap)),t.specularGlossinessMap&&(this._specularGlossinessMap=this._checkComponent("Texture",t.specularGlossinessMap)),t.occlusionMap&&(this._occlusionMap=this._checkComponent("Texture",t.occlusionMap)),t.alphaMap&&(this._alphaMap=this._checkComponent("Texture",t.alphaMap)),t.normalMap&&(this._normalMap=this._checkComponent("Texture",t.normalMap)),this.alphaMode=t.alphaMode,this.alphaCutoff=t.alphaCutoff,this.backfaces=t.backfaces,this.frontface=t.frontface,this.lineWidth=t.lineWidth,this.pointSize=t.pointSize,this._makeHash()}_makeHash(){const e=this._state,t=["/spe"];this._diffuseMap&&(t.push("/dm"),this._diffuseMap.hasMatrix&&t.push("/mat"),t.push("/"+this._diffuseMap.encoding)),this._emissiveMap&&(t.push("/em"),this._emissiveMap.hasMatrix&&t.push("/mat")),this._glossinessMap&&(t.push("/gm"),this._glossinessMap.hasMatrix&&t.push("/mat")),this._specularMap&&(t.push("/sm"),this._specularMap.hasMatrix&&t.push("/mat")),this._specularGlossinessMap&&(t.push("/sgm"),this._specularGlossinessMap.hasMatrix&&t.push("/mat")),this._occlusionMap&&(t.push("/ocm"),this._occlusionMap.hasMatrix&&t.push("/mat")),this._normalMap&&(t.push("/nm"),this._normalMap.hasMatrix&&t.push("/mat")),this._alphaMap&&(t.push("/opm"),this._alphaMap.hasMatrix&&t.push("/mat")),t.push(";"),e.hash=t.join("")}set diffuse(e){let t=this._state.diffuse;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.diffuse=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}get diffuse(){return this._state.diffuse}get diffuseMap(){return this._diffuseMap}set specular(e){let t=this._state.specular;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.specular=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}get specular(){return this._state.specular}get specularMap(){return this._specularMap}get specularGlossinessMap(){return this._specularGlossinessMap}set glossiness(e){e=null!=e?e:1,this._state.glossiness!==e&&(this._state.glossiness=e,this.glRedraw())}get glossiness(){return this._state.glossiness}get glossinessMap(){return this._glossinessMap}set specularF0(e){e=null!=e?e:0,this._state.specularF0!==e&&(this._state.specularF0=e,this.glRedraw())}get specularF0(){return this._state.specularF0}set emissive(e){let t=this._state.emissive;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.emissive=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=0,t[1]=0,t[2]=0),this.glRedraw()}get emissive(){return this._state.emissive}get emissiveMap(){return this._emissiveMap}set alpha(e){e=null!=e?e:1,this._state.alpha!==e&&(this._state.alpha=e,this.glRedraw())}get alpha(){return this._state.alpha}get alphaMap(){return this._alphaMap}get normalMap(){return this._normalMap}get occlusionMap(){return this._occlusionMap}set alphaMode(e){let t=Ds[e=e||"opaque"];void 0===t&&(this.error("Unsupported value for 'alphaMode': "+e+" defaulting to 'opaque'"),t="opaque"),this._state.alphaMode!==t&&(this._state.alphaMode=t,this.glRedraw())}get alphaMode(){return ks[this._state.alphaMode]}set alphaCutoff(e){null==e&&(e=.5),this._state.alphaCutoff!==e&&(this._state.alphaCutoff=e)}get alphaCutoff(){return this._state.alphaCutoff}set backfaces(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}get backfaces(){return this._state.backfaces}set frontface(e){e="cw"!==e,this._state.frontface!==e&&(this._state.frontface=e,this.glRedraw())}get frontface(){return this._state.frontface?"ccw":"cw"}set lineWidth(e){this._state.lineWidth=e||1,this.glRedraw()}get lineWidth(){return this._state.lineWidth}set pointSize(e){this._state.pointSize=e||1,this.glRedraw()}get pointSize(){return this._state.pointSize}destroy(){super.destroy(),this._state.destroy()}}const Rs={default:{fill:!0,fillColor:[.4,.4,.4],fillAlpha:.2,edges:!0,edgeColor:[.2,.2,.2],edgeAlpha:.5,edgeWidth:1},defaultWhiteBG:{fill:!0,fillColor:[1,1,1],fillAlpha:.6,edgeColor:[.2,.2,.2],edgeAlpha:1,edgeWidth:1},defaultLightBG:{fill:!0,fillColor:[.4,.4,.4],fillAlpha:.2,edges:!0,edgeColor:[.2,.2,.2],edgeAlpha:.5,edgeWidth:1},defaultDarkBG:{fill:!0,fillColor:[.4,.4,.4],fillAlpha:.2,edges:!0,edgeColor:[.5,.5,.5],edgeAlpha:.5,edgeWidth:1},phosphorous:{fill:!0,fillColor:[0,0,0],fillAlpha:.4,edges:!0,edgeColor:[.9,.9,.9],edgeAlpha:.5,edgeWidth:2},sunset:{fill:!0,fillColor:[.9,.9,.6],fillAlpha:.2,edges:!0,edgeColor:[.9,.9,.9],edgeAlpha:.5,edgeWidth:1},vectorscope:{fill:!0,fillColor:[0,0,0],fillAlpha:.7,edges:!0,edgeColor:[.2,1,.2],edgeAlpha:1,edgeWidth:2},battlezone:{fill:!0,fillColor:[0,0,0],fillAlpha:1,edges:!0,edgeColor:[.2,1,.2],edgeAlpha:1,edgeWidth:3},sepia:{fill:!0,fillColor:[.970588207244873,.7965892553329468,.6660899519920349],fillAlpha:.4,edges:!0,edgeColor:[.529411792755127,.4577854573726654,.4100345969200134],edgeAlpha:1,edgeWidth:1},yellowHighlight:{fill:!0,fillColor:[1,1,0],fillAlpha:.5,edges:!0,edgeColor:[1,1,1],edgeAlpha:1,edgeWidth:1},greenSelected:{fill:!0,fillColor:[0,1,0],fillAlpha:.5,edges:!0,edgeColor:[1,1,1],edgeAlpha:1,edgeWidth:1},gamegrid:{fill:!0,fillColor:[.2,.2,.7],fillAlpha:.9,edges:!0,edgeColor:[.4,.4,1.6],edgeAlpha:.8,edgeWidth:3}};class Os extends hs{get type(){return"EmphasisMaterial"}get presets(){return Rs}constructor(e,t={}){super(e,t),this._state=new Se({type:"EmphasisMaterial",fill:null,fillColor:null,fillAlpha:null,edges:null,edgeColor:null,edgeAlpha:null,edgeWidth:null,backfaces:!0,glowThrough:!0}),this._preset="default",t.preset?(this.preset=t.preset,void 0!==t.fill&&(this.fill=t.fill),t.fillColor&&(this.fillColor=t.fillColor),void 0!==t.fillAlpha&&(this.fillAlpha=t.fillAlpha),void 0!==t.edges&&(this.edges=t.edges),t.edgeColor&&(this.edgeColor=t.edgeColor),void 0!==t.edgeAlpha&&(this.edgeAlpha=t.edgeAlpha),void 0!==t.edgeWidth&&(this.edgeWidth=t.edgeWidth),void 0!==t.backfaces&&(this.backfaces=t.backfaces),void 0!==t.glowThrough&&(this.glowThrough=t.glowThrough)):(this.fill=t.fill,this.fillColor=t.fillColor,this.fillAlpha=t.fillAlpha,this.edges=t.edges,this.edgeColor=t.edgeColor,this.edgeAlpha=t.edgeAlpha,this.edgeWidth=t.edgeWidth,this.backfaces=t.backfaces,this.glowThrough=t.glowThrough)}set fill(e){e=!1!==e,this._state.fill!==e&&(this._state.fill=e,this.glRedraw())}get fill(){return this._state.fill}set fillColor(e){let t=this._state.fillColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.fillColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.4,t[1]=.4,t[2]=.4),this.glRedraw()}get fillColor(){return this._state.fillColor}set fillAlpha(e){e=null!=e?e:.2,this._state.fillAlpha!==e&&(this._state.fillAlpha=e,this.glRedraw())}get fillAlpha(){return this._state.fillAlpha}set edges(e){e=!1!==e,this._state.edges!==e&&(this._state.edges=e,this.glRedraw())}get edges(){return this._state.edges}set edgeColor(e){let t=this._state.edgeColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.edgeColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}get edgeColor(){return this._state.edgeColor}set edgeAlpha(e){e=null!=e?e:.5,this._state.edgeAlpha!==e&&(this._state.edgeAlpha=e,this.glRedraw())}get edgeAlpha(){return this._state.edgeAlpha}set edgeWidth(e){this._state.edgeWidth=e||1,this.glRedraw()}get edgeWidth(){return this._state.edgeWidth}set backfaces(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}get backfaces(){return this._state.backfaces}set glowThrough(e){e=!1!==e,this._state.glowThrough!==e&&(this._state.glowThrough=e,this.glRedraw())}get glowThrough(){return this._state.glowThrough}set preset(e){if(console.warn("EmphasisMaterial.preset is deprecated and will be removed in future versions."),e=e||"default",this._preset===e)return;const t=Rs[e];t?(this.fill=t.fill,this.fillColor=t.fillColor,this.fillAlpha=t.fillAlpha,this.edges=t.edges,this.edgeColor=t.edgeColor,this.edgeAlpha=t.edgeAlpha,this.edgeWidth=t.edgeWidth,this.glowThrough=t.glowThrough,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(Rs).join(", "))}get preset(){return console.warn("EmphasisMaterial.preset is deprecated and will be removed in future versions."),this._preset}destroy(){super.destroy(),this._state.destroy()}}const Vs={default:{edgeColor:[0,0,0],edgeAlpha:1,edgeWidth:1},defaultWhiteBG:{edgeColor:[.2,.2,.2],edgeAlpha:1,edgeWidth:1},defaultLightBG:{edgeColor:[.2,.2,.2],edgeAlpha:1,edgeWidth:1},defaultDarkBG:{edgeColor:[.5,.5,.5],edgeAlpha:1,edgeWidth:1}};class Ls extends hs{get type(){return"EdgeMaterial"}get presets(){return Vs}constructor(e,t={}){super(e,t),this._state=new Se({type:"EdgeMaterial",edges:null,edgeColor:null,edgeAlpha:null,edgeWidth:null}),this._preset="default",t.preset?(this.preset=t.preset,t.edgeColor&&(this.edgeColor=t.edgeColor),void 0!==t.edgeAlpha&&(this.edgeAlpha=t.edgeAlpha),void 0!==t.edgeWidth&&(this.edgeWidth=t.edgeWidth)):(this.edgeColor=t.edgeColor,this.edgeAlpha=t.edgeAlpha,this.edgeWidth=t.edgeWidth),this.edges=!1!==t.edges}set edges(e){e=!1!==e,this._state.edges!==e&&(this._state.edges=e,this.glRedraw())}get edges(){return this._state.edges}set edgeColor(e){let t=this._state.edgeColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.edgeColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}get edgeColor(){return this._state.edgeColor}set edgeAlpha(e){e=null!=e?e:1,this._state.edgeAlpha!==e&&(this._state.edgeAlpha=e,this.glRedraw())}get edgeAlpha(){return this._state.edgeAlpha}set edgeWidth(e){this._state.edgeWidth=e||1,this.glRedraw()}get edgeWidth(){return this._state.edgeWidth}set preset(e){if(e=e||"default",this._preset===e)return;const t=Vs[e];t?(this.edgeColor=t.edgeColor,this.edgeAlpha=t.edgeAlpha,this.edgeWidth=t.edgeWidth,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(Vs).join(", "))}get preset(){return this._preset}destroy(){super.destroy(),this._state.destroy()}}class Hs extends Ae{get type(){return"Fresnel"}constructor(e,t={}){super(e,t),this._state=new Se({edgeColor:V.vec3([0,0,0]),centerColor:V.vec3([1,1,1]),edgeBias:0,centerBias:1,power:1}),this.edgeColor=t.edgeColor,this.centerColor=t.centerColor,this.edgeBias=t.edgeBias,this.centerBias=t.centerBias,this.power=t.power}set edgeColor(e){this._state.edgeColor.set(e||[0,0,0]),this.glRedraw()}get edgeColor(){return this._state.edgeColor}set centerColor(e){this._state.centerColor.set(e||[1,1,1]),this.glRedraw()}get centerColor(){return this._state.centerColor}set edgeBias(e){this._state.edgeBias=e||0,this.glRedraw()}get edgeBias(){return this._state.edgeBias}set centerBias(e){this._state.centerBias=null!=e?e:1,this.glRedraw()}get centerBias(){return this._state.centerBias}set power(e){this._state.power=null!=e?e:1,this.glRedraw()}get power(){return this._state.power}destroy(){super.destroy(),this._state.destroy()}}class Ns extends Ae{constructor(e,t={}){super(e,t),this._type=t.type||(t.src?t.src.split(".").pop():null)||"jpg",this._pos=V.vec3(t.pos||[0,0,0]),this._up=V.vec3(t.up||[0,1,0]),this._normal=V.vec3(t.normal||[0,0,1]),this._height=t.height||1,this._origin=V.vec3(),this._rtcPos=V.vec3(),this._imageSize=V.vec2(),this._texture=new Cs(this,{flipY:!0}),this._image=new Image,"jpg"!==this._type&&"png"!==this._type&&(this.error('Unsupported type - defaulting to "jpg"'),this._type="jpg"),this._node=new Bt(this,{matrix:V.inverseMat4(V.lookAtMat4v(this._pos,V.subVec3(this._pos,this._normal,V.mat4()),this._up,V.mat4())),children:[this._bitmapMesh=new as(this,{scale:[1,1,1],rotation:[-90,0,0],collidable:t.collidable,pickable:t.pickable,opacity:t.opacity,clippable:t.clippable,geometry:new We(this,st({center:[0,0,0],xSize:1,zSize:1,xSegments:2,zSegments:2})),material:new fs(this,{diffuse:[0,0,0],ambient:[0,0,0],specular:[0,0,0],diffuseMap:this._texture,emissiveMap:this._texture,backfaces:!0})})]}),t.image?this.image=t.image:t.src?this.src=t.src:t.imageData&&(this.imageData=t.imageData),this.scene._bitmapCreated(this)}set visible(e){this._bitmapMesh.visible=e}get visible(){return this._bitmapMesh.visible}set image(e){this._image=e,this._image&&(this._texture.image=this._image,this._imageSize[0]=this._image.width,this._imageSize[1]=this._image.height,this._updateBitmapMeshScale())}get image(){return this._image}set src(e){if(e){this._image.onload=()=>{this._texture.image=this._image,this._imageSize[0]=this._image.width,this._imageSize[1]=this._image.height,this._updateBitmapMeshScale()},this._image.src=e;switch(e.split(".").pop()){case"jpeg":case"jpg":this._type="jpg";break;case"png":this._type="png"}}}get src(){return this._image.src}set imageData(e){this._image.onload=()=>{this._texture.image=image,this._imageSize[0]=image.width,this._imageSize[1]=image.height,this._updateBitmapMeshScale()},this._image.src=e}get imageData(){const e=document.createElement("canvas"),t=e.getContext("2d");return e.width=this._image.width,e.height=this._image.height,t.drawImage(this._image,0,0),e.toDataURL("jpg"===this._type?"image/jpeg":"image/png")}set type(e){"png"===(e=e||"jpg")&&"jpg"===e||(this.error("Unsupported value for `type` - supported types are `jpg` and `png` - defaulting to `jpg`"),e="jpg"),this._type=e}get type(){return this._type}get pos(){return this._pos}get normal(){return this._normal}get up(){return this._up}set height(e){this._height=null==e?1:e,this._image&&this._updateBitmapMeshScale()}get height(){return this._height}set collidable(e){this._bitmapMesh.collidable=!1!==e}get collidable(){return this._bitmapMesh.collidable}set clippable(e){this._bitmapMesh.clippable=!1!==e}get clippable(){return this._bitmapMesh.clippable}set pickable(e){this._bitmapMesh.pickable=!1!==e}get pickable(){return this._bitmapMesh.pickable}set opacity(e){this._bitmapMesh.opacity=e}get opacity(){return this._bitmapMesh.opacity}destroy(){super.destroy(),this.scene._bitmapDestroyed(this)}_updateBitmapMeshScale(){const e=this._imageSize[1]/this._imageSize[0];this._bitmapMesh.scale=[this._height/e,1,this._height]}}const Gs=(e,t)=>{const i=[];let s=[];function r(e,i){let s,r;for(let n=0;n<3;n++)if(s=t[3*e+n],r=t[3*i+n],s!==r)return r-s;return 0}let n=e.slice().sort(r),A=null;for(let e=0,t=n.length;e<t;e++)0!==e&&0===r(n[e],n[e-1])||(A=n[e]),i[n[e]]=A;for(let t=0,r=e.length;t<r;t+=3){const r=i[e[t]],n=i[e[t+1]],A=i[e[t+2]];let o=r,a=n,l=A;if(r>n&&r>A?n>A?(o=r,a=n,l=A):(o=r,a=A,l=n):n>r&&n>A?r>A?(o=n,a=r,l=A):(o=n,a=A,l=r):A>r&&A>n&&(r>n?(o=A,a=r,l=n):(o=A,a=n,l=r)),s[t+0]=[o,a],s[t+1]=[a,l],o>l){const e=l;l=o,o=e}s[t+2]=[l,o]}function o(e,t){let i,s;for(let r=0;r<2;r++)if(i=e[r],s=t[r],s!==i)return s-i;return 0}s=s.slice(0,e.length),s.sort(o);let a=0;for(let e=0;e<s.length;e++)if(0===e||0!==o(s[e],s[e-1])){if(0!==e&&2!==a)return!1;a=1}else a++;return!(s.length>0&&2!==a)},js=V.vec3(),Ws=V.vec3(),zs=V.vec3();class Xs{constructor(){this.vertices=[],this.indices=[],this.reset()}reset(){this.lenVertices=0,this.lenIndices=0,this.primitive=null}setPrimitive(e){this.primitive=e}addVertex(e){this.vertices[this.lenVertices++]=e[0],this.vertices[this.lenVertices++]=e[1],this.vertices[this.lenVertices++]=e[2]}addIndex(e){this.indices[this.lenIndices++]=e}get volume(){const e=this.vertices,t=this.indices;if("solid"!==this.primitive&&"surface"!==this.primitive&&"triangles"!==this.primitive)return-1;if("solid"!==this.primitive&&!Gs(t,e))return-1;let i=0;for(let s=0;s<this.lenIndices;s+=3){const r=3*t[s],n=3*t[s+1],A=3*t[s+2];js[0]=e[r],js[1]=e[r+1],js[2]=e[r+2],Ws[0]=e[n],Ws[1]=e[n+1],Ws[2]=e[n+2],zs[0]=e[A],zs[1]=e[A+1],zs[2]=e[A+2],V.cross3Vec3(js,Ws,js),i+=V.dotVec3(js,zs)}return i/6}}const Ks=new Xs,Zs=V.vec3(),Js=V.vec3(),Ys=V.vec3(),$s=V.vec3(),qs=V.vec3(),er=V.vec3();class tr{constructor(){this.vertices=[],this.indices=[],this.reset()}reset(){this.lenVertices=0,this.lenIndices=0}addVertex(e){this.vertices[this.lenVertices++]=e[0],this.vertices[this.lenVertices++]=e[1],this.vertices[this.lenVertices++]=e[2]}addIndex(e){this.indices[this.lenIndices++]=e}get surfaceArea(){const e=this.vertices,t=this.indices;let i=0;for(let s=0;s<this.lenIndices;s+=3){const r=3*t[s],n=3*t[s+1],A=3*t[s+2];Zs[0]=e[r],Zs[1]=e[r+1],Zs[2]=e[r+2],Js[0]=e[n],Js[1]=e[n+1],Js[2]=e[n+2],Ys[0]=e[A],Ys[1]=e[A+1],Ys[2]=e[A+2],V.subVec3(Zs,Js,$s),V.subVec3(Ys,Js,qs),i+=.5*V.lenVec3(V.cross3Vec3($s,qs,er))}return i}}const ir=new tr,sr=V.OBB3(),rr=V.OBB3(),nr=V.OBB3();class Ar{constructor(e,t,i,s,r,n,A=null,o=0){this.model=e,this.object=null,this.parent=null,this.transform=r,this.textureSet=n,this._matrixDirty=!1,this._matrixUpdateScheduled=!1,this.id=t,this.obb=null,this._aabbLocal=null,this._aabbWorld=V.AABB3(),this._aabbWorldDirty=!1,this.layer=A,this.portionId=o,this._color=new Uint8Array([i[0],i[1],i[2],s]),this._colorize=new Uint8Array([i[0],i[1],i[2],s]),this._colorizing=!1,this._transparent=s<255,this.numTriangles=0,this.origin=null,this.entity=null,r&&r._addMesh(this),this._volume=null,this._surfaceArea=null}_sceneModelDirty(){this._aabbWorldDirty=!0,this.layer.aabbChanged()}_transformDirty(){this._matrixDirty||this._matrixUpdateScheduled||(this.model._meshMatrixDirty(this),this._matrixDirty=!0,this._matrixUpdateScheduled=!0),this._aabbWorldDirty=!0,this.layer.aabbChanged(),this.entity&&this.entity._transformDirty()}_updateMatrix(){this.transform&&this._matrixDirty&&this.layer.setMatrix(this.portionId,this.transform.worldMatrix),this._matrixDirty=!1,this._matrixUpdateScheduled=!1}_finalize(e){this.layer.initFlags(this.portionId,e,this._transparent)}_finalize2(){this.layer.flushInitFlags&&this.layer.flushInitFlags()}_setVisible(e){this.layer.setVisible(this.portionId,e,this._transparent)}_setColor(e){this._color[0]=e[0],this._color[1]=e[1],this._color[2]=e[2],this._colorizing||this.layer.setColor(this.portionId,this._color,!1)}_setColorize(e){e?(this._colorize[0]=e[0],this._colorize[1]=e[1],this._colorize[2]=e[2],this.layer.setColor(this.portionId,this._colorize,false),this._colorizing=!0):(this.layer.setColor(this.portionId,this._color,false),this._colorizing=!1)}_setOpacity(e,t){const i=e<255,s=this._transparent!==i;this._color[3]=e,this._colorize[3]=e,this._transparent=i,this._colorizing?this.layer.setColor(this.portionId,this._colorize):this.layer.setColor(this.portionId,this._color),s&&this.layer.setTransparent(this.portionId,t,i)}_setOffset(e){this.layer.setOffset(this.portionId,e)}_setHighlighted(e){this.layer.setHighlighted(this.portionId,e,this._transparent)}_setXRayed(e){this.layer.setXRayed(this.portionId,e,this._transparent)}_setSelected(e){this.layer.setSelected(this.portionId,e,this._transparent)}_setEdges(e){this.layer.setEdges(this.portionId,e,this._transparent)}_setClippable(e){this.layer.setClippable(this.portionId,e,this._transparent)}_setCollidable(e){this.layer.setCollidable(this.portionId,e)}_setPickable(e){this.layer.setPickable(this.portionId,e,this._transparent)}_setCulled(e){this.layer.setCulled(this.portionId,e,this._transparent)}canPickTriangle(){return!1}drawPickTriangles(e,t){}pickTriangleSurface(e){}precisionRayPickSurface(e,t,i,s){return this.layer.precisionRayPickSurface(this.portionId,e,t,i,s)}canPickWorldPos(){return!0}drawPickDepths(e){this.model.drawPickDepths(e)}drawPickNormals(e){this.model.drawPickNormals(e)}delegatePickedEntity(){return this.parent}getEachVertex(e){this.layer.getEachVertex&&this.layer.getEachVertex(this.portionId,e)}getEachIndex(e){this.layer.getEachIndex&&this.layer.getEachIndex(this.portionId,e)}isSolid(){return this.layer.solid}get volume(){if(null!==this._volume)return this._volume;switch(this.layer.primitive){case"solid":case"surface":case"triangles":Ks.reset(),Ks.setPrimitive(this.layer.primitive),this.getEachVertex((e=>{Ks.addVertex(e)})),this.getEachIndex((e=>{Ks.addIndex(e)})),this._volume=Ks.volume;break;default:this._volume=0}return this._volume}get surfaceArea(){if(null!==this._surfaceArea)return this._surfaceArea;switch(this.layer.primitive){case"solid":case"surface":case"triangles":ir.reset(),this.getEachVertex((e=>{ir.addVertex(e)})),this.getEachIndex((e=>{ir.addIndex(e)})),this._surfaceArea=ir.surfaceArea;break;default:this._surfaceArea=0}return this._surfaceArea}set aabb(e){if(this._aabbLocal=e,this.origin){this._aabbLocal=e.slice(0);const t=this.origin;this._aabbLocal[0]+=t[0],this._aabbLocal[1]+=t[1],this._aabbLocal[2]+=t[2],this._aabbLocal[3]+=t[0],this._aabbLocal[4]+=t[1],this._aabbLocal[5]+=t[2]}}get aabb(){return this._aabbWorldDirty&&(V.AABB3ToOBB3(this._aabbLocal,sr),this.transform?(V.transformOBB3(this.transform.worldMatrix,sr,rr),V.transformOBB3(this.model.worldMatrix,rr,nr),V.OBB3ToAABB3(nr,this._aabbWorld)):(V.transformOBB3(this.model.worldMatrix,sr,rr),V.OBB3ToAABB3(rr,this._aabbWorld)),this._aabbWorldDirty=!1),this._aabbWorld}_destroy(){this.model.scene._renderer.putPickID(this.pickId),this.layer=null}}const or=1,ar=4,lr=8,cr=16,hr=32,ur=256,dr=512,fr=1024,pr=2048,gr=function(e,t,i,s){const r=s&&e.createUniform("vec4","edgeColor",((e,t)=>e(t.legacyFrameCtx.programColor))),n=t.attributes.color,A=!s&&e.createVarying("vec4","vColor",(()=>`vec4(${n}.rgb * 0.5, ${n}.a)`)),o=e.createOutput("vec4","outColor");return{programName:s?"Edges":"EdgesColor",getLogDepth:i&&(e=>e),renderPassFlag:2,appendFragmentOutputs:e=>e.push(`${o} = ${r||A};`)}},mr=function(e,t){const i=e.createOutput("vec4","outColor");return{programName:"Occlusion",getLogDepth:!1,renderPassFlag:0,appendFragmentOutputs:e=>e.push(`${i} = vec4(0.0, 0.0, 1.0, 1.0);`)}},_r=function(e,t,i,s){const r=e.createUniform("vec4","silhouetteColor",((e,t)=>e(t.legacyFrameCtx.programColor))),n=e.createVarying("float","vAlpha",(()=>`${t.attributes.color}.a`)),A=e.createOutput("vec4","outColor");return{programName:"Silhouette",getLogDepth:i&&(e=>e),renderPassFlag:1,appendFragmentOutputs:(e,t,i,o)=>{e.push(`${A} = ${s?r:o(`vec4(${r}.rgb, min(${r}.a, ${n}))`)};`)}}},br=V.vec2(),Br=V.vec3(),yr=V.vec4(),wr=V.mat4(),vr=V.vec3([0,0,0]),Cr=0,Mr=1,Er=2,Fr=3,Ur=4,xr=5,Ir=6,Tr=7,Pr=8,Sr=9,Dr=10,kr=11,Qr=e=>[V.safeInv(e[0]),V.safeInv(e[1]),V.safeInv(e[2])],Rr=(e,t,i,s,r)=>{const n=!!(e&or),A=!!(e&ur),o=!!(e&dr),a=!!(e&fr),l=!!(e&pr),c=!!(e&lr),h=!!(e&ar);let u,d;u=!n||h||A||o&&!s.highlightMaterial.glowThrough||a&&!s.selectedMaterial.glowThrough?Cr:t?Er:Mr,d=!n||h?Cr:a?Ur:o?Fr:A?xr:Cr;let f=0;f=i&&n&&!h?a?Sr:o?Pr:A?Dr:l?t?Tr:Ir:Cr:Cr;const p=n&&!h&&c?kr:Cr;r[0]=u,r[1]=d,r[2]=f,r[3]=p},Or=function(){const e={};return function(t,i,s,r,n,A,o,a){const l=[i,"points"===s||"lines"===s?s:"triangles",!!r,!!n,!!A,!!o].join(":");l in e||(e[l]={});const c=e[l],h=t.id;if(!(h in c)){const e=t.canvas.gl,l=function(r,n,A){const o=function(){const A=Gi(),o=A.programVariables,l=a(o,n);return r(o,l.geometryParameters,(function(r,a){const c=t.pointsMaterial,h="points"===s&&!n,u=()=>[t._sectionPlanesState.getHash()].concat(h?[c.hash]:[]).concat(r.getHash?r.getHash():[]).join(";"),d=u(),f=()=>d===u(),p=l.geometryParameters,g=r.incrementDrawState,m=r.isShadowProgram,_=p.attributes,b=_.position.world,B="clipPos",[y,w]=A.buildProgram(e,i+" "+s+" "+r.programName,{appendFragmentOutputs:r.appendFragmentOutputs,cleanerEdges:r.cleanerEdges,clipPos:B,clippableTest:l.clippableTest,clippingCaps:r.clippingCaps,crossSections:t.crossSections,discardPoints:h&&c.roundPoints,getGammaFactor:t.gammaOutput&&(()=>t.gammaFactor),getLogDepth:r.getLogDepth,getPointSize:function(){const e=[];if(h){const t=o.createUniform("float","pointSize",(e=>e(c.pointSize)));if(c.perspectivePoints){const i=o.createUniform("float","nearPlaneHeight",((e,t)=>e(t.legacyFrameCtx.nearPlaneHeight))),s=`${Math.floor(c.minPerspectivePointSize)}.0`,r=`${Math.floor(c.maxPerspectivePointSize)}.0`;e.push(`clamp((${i} * ${t}) / gl_Position.w, ${s}, ${r})`)}else e.push(t)}else n&&n.vertices&&e.push("1.0");return r.incPointSizeBy10&&"points"===s&&e.push("10.0"),e.length>0&&(()=>e.join(" + "))}(),getVertexData:()=>{const e=_.color,t=_.flags[r.renderPassFlag],i=o.createUniform("int","renderPass",((e,t)=>e(t.renderPass))),n=[`if (${m?`(${t} <= 0) || (${e}.a < 1.0)`:`${t} != ${i}`}) {`,` gl_Position = vec4(${r.vertexCullX||0}, 0.0, 0.0, 0.0);`," return;","}"].concat(l.dontCullOnAlphaZero||r.dontCullOnAlphaZero?[]:[`if (${e}.a == 0.0) {`," gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"," return;","}"]).concat(r.filterIntensityRange&&"points"===s&&c.filterIntensity?function(){const t=o.createUniform("vec2","intensityRange",(e=>{br[0]=c.minIntensity,br[1]=c.maxIntensity,e(br)}));return[`if ((${e}.a < ${t}[0]) || (${e}.a > ${t}[1])) {`," gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"," return;","}"]}():[]),A=[];l.ensureColorAndFlagAvailable&&l.ensureColorAndFlagAvailable(A),n.forEach((e=>A.push(e))),l.appendVertexData(A);const a=p.attributes.position.view;return A.push(`vec4 ${a} = ${p.viewMatrix} * ${b};`),A.push(`vec4 clipPos = ${p.projMatrix} * ${a};`),A},projMatrix:p.projMatrix,sectionPlanesState:t._sectionPlanesState,testPerspectiveForGl_FragDepth:"points"!==s&&"lines"!==s||n,usePickClipPos:a,worldPositionAttribute:b});return w?(console.error(w),{getValid:f,destroy:()=>{},drawLayer:(e,t,i)=>{}}):{getValid:f,destroy:()=>y.destroy(),drawLayer:(e,t,i)=>{e.lastProgramId!==y.id&&(e.lastProgramId=y.id,y.bind());const s=t.origin,r=t.model,A=e.viewParams,o=Br;V.transformPoint3(r.matrix,s,o);const a=A.viewMatrix,c=A.projMatrix;e.snapPickOrigin&&(e.snapPickOrigin[0]=o[0],e.snapPickOrigin[1]=o[1],e.snapPickOrigin[2]=o[2]);const h={legacyFrameCtx:e,layerTextureSet:t.layerTextureSet,mesh:{layerIndex:t.layerIndex,origin:o,renderFlags:{sectionPlanesActivePerLayer:r.renderFlags.sectionPlanesActivePerLayer}},renderPass:i,view:{eye:A.eye,far:A.far,projMatrix:c,viewMatrix:V.compareVec3(o,vr)?a:wt(a,o,wr),viewNormalMatrix:A.viewNormalMatrix}};y.inputSetters.setUniforms(e,h),t.drawCalls[n?n.vertices?"drawVertices":"drawEdges":"drawSurface"](y.inputSetters.attributesHash,l.layerTypeInputs,{projMatrix:c,viewMatrix:V.compareVec3(o,vr)?a:wt(a,o,wr),viewNormalMatrix:A.viewNormalMatrix,eye:A.eye}),g&&e.drawElements++}}}))};let l=A&&o();return{drawLayer:(e,t,i)=>{l||(l=o()),l.drawLayer(e,t,i)},revalidate:e=>{!l||!e&&l.getValid()||(l.destroy(),l=A&&o())}}},u=(e,t)=>l(e,t,!0),d=(e,t)=>l(e,t,!1),f=(e,i,r,n)=>function(e,t,i,s,r,n){const A=e.createVarying("vec4","vColor",(()=>{const e=t.attributes,i="points"===n?`vec4(${e.color}.rgb, 1.0)`:`${e.color}`;return s?`vec4(${[s.getAmbientColor()].concat(s.directionalLights.map((i=>`max(dot(${e.normal.view}, ${i.getDirection(t.viewMatrix,e.position.view)}), 0.0) * ${i.getColor()}`))).join(" + ")}, 1) * ${i}`:i})),o=e.createOutput("vec4","outColor");return{programName:"Color",getHash:()=>[s?s.getHash():"-",r?"sao":"nosao"],cleanerEdges:!0,getLogDepth:i&&(e=>"points"!==n&&"lines"!==n?`${e} + length(vec2(dFdx(${e}), dFdy(${e})))`:e),renderPassFlag:0,appendFragmentOutputs:(e,t,i,s)=>{"points"===n||"lines"===n?e.push(`${o} = ${A};`):(e.push(`vec4 fragColor = ${s(A)};`),e.push(`${o} = ${r?`vec4(fragColor.rgb * ${r.getAmbient(i)}, fragColor.a)`:"fragColor"};`))},filterIntensityRange:!0,incrementDrawState:!0}}(e,i,t.logarithmicDepthBufferEnabled,r,n,s),p=(e,i,s)=>s(function(e,t,i){const s=e.createUniform("float","far",((e,t)=>e(t.legacyFrameCtx.viewParams.far))),r=e.createUniform("float","near",((e,t)=>e(t.legacyFrameCtx.viewParams.near))),n=e.createVarying("vec3","vViewPosition",(()=>`${t.attributes.position.view}.xyz`)),A=e.createOutput("vec4","outPackedDepth"),o=e.createFragmentDefinition("packDepth",((e,t)=>{t.push(`vec4 ${e}(const in float depth) {`),t.push(" const vec4 bitShift = vec4(256.0*256.0*256.0, 256.0*256.0, 256.0, 1.0);"),t.push(" const vec4 bitMask = vec4(0.0, 1.0/256.0, 1.0/256.0, 1.0/256.0);"),t.push(" vec4 res = fract(depth * bitShift);"),t.push(" res -= res.xxyz * bitMask;"),t.push(" return res;"),t.push("}")}));return{programName:"PickDepth",getLogDepth:i&&(e=>e),renderPassFlag:3,incPointSizeBy10:!0,appendFragmentOutputs:e=>{e.push(`float zNormalizedDepth = abs((${r} + ${n}.z) / (${s} - ${r}));`),e.push(`${A} = ${o}(zNormalizedDepth);`)}}}(e,i,t.logarithmicDepthBufferEnabled),!0),g=(e,i,s)=>s(function(e,t,i){const s=e.createVarying("vec4","vPickColor",(()=>`${t.attributes.pickColor} / 255.0`)),r=e.createOutput("vec4","outPickColor");return{programName:"PickMesh",getLogDepth:i&&(e=>e),renderPassFlag:3,incPointSizeBy10:!0,dontCullOnAlphaZero:!0,appendFragmentOutputs:e=>e.push(`${r} = ${s};`)}}(e,i,t.logarithmicDepthBufferEnabled),!0),m=(e,i,s,r)=>s(function(e,t,i,s){const r=e.createVarying("vec3","vWorldPosition",(()=>`${t.attributes.position.world}.xyz`)),n=e.createVarying("vec3","vWorldNormal",(()=>t.attributes.normal.world)),A=e.createOutput("highp ivec4","outNormal");return{programName:s?"PickNormalsFlat":"PickNormals",getLogDepth:i&&(e=>e),renderPassFlag:3,appendFragmentOutputs:e=>{const t=s?`normalize(cross(dFdx(${r}), dFdy(${r})))`:n;e.push(`${A} = ivec4(${t} * float(${V.MAX_INT}), 1.0);`)}}}(e,i,t.logarithmicDepthBufferEnabled,r),!0),_=(e,t,i,s,r)=>i(function(e,t,i,s){const r=e.createUniform("int","layerNumber",((e,t)=>e(t.legacyFrameCtx.snapPickLayerParams.length))),n=e.createUniform("vec3","coordinateScaler",((e,t)=>e(t.legacyFrameCtx.snapPickCoordinateScale))),A=e.createVarying("vec3","vWorldPosition",(()=>`${t.attributes.position.world}.xyz`)),o=e.createVarying("vec4","vPickColor",(()=>t.attributes.pickColor),"flat"),a=e.createOutput("highp ivec4","outCoords",0),l=e.createOutput("highp ivec4","outNormal",1),c=e.createOutput("lowp uvec4","outPickColor",2);return{programName:i?"SnapInit":"Snap",getLogDepth:e=>i?`${e} + length(vec2(dFdx(${e}), dFdy(${e})))`:e,renderPassFlag:3,vertexCullX:!i&&"2.0",dontCullOnAlphaZero:!i,appendFragmentOutputs:e=>{e.push(`${a} = ivec4(${A} * ${n}.xyz, ${i?"-":""}${r});`),i&&(e.push(`${l} = ${s?"ivec4(1.0)":`ivec4(normalize(cross(dFdx(${A}), dFdy(${A}))) * float(${V.MAX_INT}), 1.0)`};`),e.push(`${c} = uvec4(${o});`))}}}(e,t,s,r),!0);c[h]="points"===s?{colorRenderers:{"sao-":{vertex:d(((e,t,i)=>i(f(e,t,null,null))))}},occlusionRenderer:d(((e,i,s)=>s(mr(e,t.logarithmicDepthBufferEnabled)))),pickDepthRenderer:d(p),pickMeshRenderer:d(g),silhouetteRenderer:d(((e,i,s)=>s(_r(e,i,t.logarithmicDepthBufferEnabled,!0)))),snapInitRenderer:d(((e,t,i)=>_(e,t,i,!0,!0))),snapVertexRenderer:d(((e,t,i)=>_(e,t,i,!1,!0)),{vertices:!0})}:"lines"===s?{colorRenderers:{"sao-":{vertex:d(((e,t,i)=>i(f(e,t,null,null))))}},silhouetteRenderer:d(((e,i,s)=>s(_r(e,i,t.logarithmicDepthBufferEnabled,!0)))),snapInitRenderer:d(((e,t,i)=>_(e,t,i,!0,!1))),snapEdgeRenderer:d(((e,t,i)=>_(e,t,i,!1,!1)),{vertices:!1}),snapVertexRenderer:d(((e,t,i)=>_(e,t,i,!1,!1)),{vertices:!0})}:{colorRenderers:function(){const e=e=>ji(e,t._lightsState),i=e=>{const t=e.createUniform("vec4","uSAOParams",((e,t)=>e(t.legacyFrameCtx.saoParams))),i=Wi(e,"sampler2D","uOcclusionTexture",3e3,((e,t)=>e(t.legacyFrameCtx.occlusionTexture)));return{getAmbient:e=>{const s=`${t}.w`;return`(smoothstep(${`${t}.z`}, 1.0, dot(${i(`${e}.xy / ${t}.xy`)}, (255. / 256.) / vec4(256. * 256. * 256., 256. * 256., 256., 1.))) * ${s})`}}},s=function(s){const r=(r,n,A)=>function(e,t,i,s,r,n,A){const o=Wi(e,"sampler2D","uColorMap",3001,((e,t)=>{const i=t.layerTextureSet.colorTexture;i&&e(i.texture)})),a=n&&e.createUniform("float","materialAlphaCutoff",((e,t)=>e(t.layerTextureSet.alphaCutoff))),l=t.attributes,c=e.createVarying("vec3","vViewPosition",(()=>`${l.position.view}.xyz`)),h=e.createVarying("vec2","vUV",(()=>l.uv)),u=e.createVarying("vec4","vColor",(()=>l.color)),d=e.createOutput("vec4","outColor");return{programName:"ColorTexture",getHash:()=>[s.getHash(),r?"sao":"nosao",!!A,n?"alphaCutoffYes":"alphaCutoffNo"],getLogDepth:i.logarithmicDepthBufferEnabled&&(e=>e),renderPassFlag:0,appendFragmentOutputs:(e,i,n,A)=>{e.push(`vec3 viewNormal = normalize(cross(dFdx(${c}), dFdy(${c})));`),e.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),s.directionalLights.forEach((i=>{e.push(`reflectedColor += max(dot(viewNormal, ${i.getDirection(t.viewMatrix,c)}), 0.0) * ${i.getColor()};`)})),e.push(`vec4 color = vec4(${s.getAmbientColor()} + reflectedColor, 1) * ${A(u)};`),e.push(`vec4 sampleColor = ${o(h)};`),a&&e.push(`if (sampleColor.a < ${a}) { discard; }`),e.push("vec4 colorTexel = color * sampleColor;"),e.push(`${d} = vec4(colorTexel.rgb${r?" * "+r.getAmbient(n):""}, color.a);`),i&&e.push(`${d} = ${i(d)};`)},incrementDrawState:!0}}(r,n,t,e(r),s&&i(r),A,t.gammaOutput);return{PBR:n&&d(((r,n,A)=>A(function(e,t,i,s,r){const n=(t,i,s)=>Wi(e,"sampler2D",t,i?3001:3e3,((e,t)=>{const i=s(t.layerTextureSet);i&&e(i.texture)})),A=t.attributes,o=s.getIrradiance,a=n("uColorMap",!0,(e=>e.colorTexture)),l=n("uMetallicRoughMap",!1,(e=>e.metallicRoughnessTexture)),c=n("uEmissiveMap",!0,(e=>e.emissiveTexture)),h=n("uNormalMap",!1,(e=>e.normalsTexture)),u=n("uAOMap",!1,(e=>e.occlusionTexture)),d=e.createVarying("vec3","vViewPosition",(()=>`${A.position.view}.xyz`)),f=e.createVarying("vec3","vViewNormal",(()=>A.normal.view)),p=e.createVarying("vec4","vColor",(()=>A.color)),g=e.createVarying("vec2","vUV",(()=>A.uv)),m=e.createVarying("vec2","vMetallicRoughness",(()=>A.metallicRoughness)),_=e.createVarying("vec3","vWorldNormal",(()=>`${A.normal.world}.xyz`)),b=e.createOutput("vec4","outColor"),B=e.createFragmentDefinition("saturate",((e,t)=>t.push(`float ${e}(const in float a) { return clamp(a, 0.0, 1.0); }`))),y=e.createFragmentDefinition("BRDF_Specular_GGX",((e,t)=>{t.push("vec3 F_Schlick(const in vec3 specularColor, const in float dotLH) {"),t.push(" float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );"),t.push(" return ( 1.0 - specularColor ) * fresnel + specularColor;"),t.push("}"),t.push("float G_GGX_Smith(const in float alpha, const in float dotNL, const in float dotNV) {"),t.push(" float a2 = ( alpha * alpha );"),t.push(" float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),t.push(" float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),t.push(" return 1.0 / ( gl * gv );"),t.push("}"),t.push("float G_GGX_SmithCorrelated(const in float alpha, const in float dotNL, const in float dotNV) {"),t.push(" float a2 = ( alpha * alpha );"),t.push(" float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),t.push(" float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),t.push(" return 0.5 / max( gv + gl, 1e-6 );"),t.push("}"),t.push("float D_GGX(const in float alpha, const in float dotNH) {"),t.push(" float a2 = ( alpha * alpha );"),t.push(" float denom = ( dotNH * dotNH) * ( a2 - 1.0 ) + 1.0;"),t.push(" return 0.31830988618 * a2 / ( denom * denom);"),t.push("}"),t.push(`vec3 ${e}(const in vec3 incidentLightDirection, const in vec3 viewNormal, const in vec3 viewEyeDir, const in vec3 specularColor, const in float roughness) {`),t.push(" float alpha = ( roughness * roughness );"),t.push(" vec3 halfDir = normalize( incidentLightDirection + viewEyeDir );"),t.push(` float dotNL = ${B}( dot( viewNormal, incidentLightDirection ) );`),t.push(` float dotNV = ${B}( dot( viewNormal, viewEyeDir ) );`),t.push(` float dotNH = ${B}( dot( viewNormal, halfDir ) );`),t.push(` float dotLH = ${B}( dot( incidentLightDirection, halfDir ) );`),t.push(" vec3 F = F_Schlick( specularColor, dotLH );"),t.push(" float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );"),t.push(" float D = D_GGX( alpha, dotNH );"),t.push(" return F * (G * D);"),t.push("}")})),w=e.createFragmentDefinition("BRDF_Specular_GGX_Environment",((e,t)=>{t.push(`vec3 ${e}(const in vec3 viewNormal, const in vec3 viewEyeDir, const in vec3 specularColor, const in float roughness) {`),t.push(` float dotNV = ${B}(dot(viewNormal, viewEyeDir));`),t.push(" const vec4 c0 = vec4( -1, -0.0275, -0.572, 0.022);"),t.push(" const vec4 c1 = vec4( 1, 0.0425, 1.04, -0.04);"),t.push(" vec4 r = roughness * c0 + c1;"),t.push(" float a004 = min(r.x * r.x, exp2(-9.28 * dotNV)) * r.x + r.y;"),t.push(" vec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;"),t.push(" return specularColor * AB.x + AB.y;"),t.push("}")})),v=e.createFragmentDefinition("perturbNormal2Arb",((e,t)=>{t.push(`vec3 ${e}( vec3 eye_pos, vec3 surf_norm, vec2 uv, vec4 texel ) {`),t.push(" if (texel.r == 0.0 && texel.g == 0.0 && texel.b == 0.0) {"),t.push(" return surf_norm;"),t.push(" }"),t.push(" vec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );"),t.push(" vec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );"),t.push(" vec2 st0 = dFdx( uv.st );"),t.push(" vec2 st1 = dFdy( uv.st );"),t.push(" vec3 S = normalize( q0 * st1.t - q1 * st0.t );"),t.push(" vec3 T = normalize( -q0 * st1.s + q1 * st0.s );"),t.push(" vec3 N = normalize( surf_norm );"),t.push(" vec3 mapN = texel.xyz * 2.0 - 1.0;"),t.push(" mat3 tsn = mat3( S, T, N );"),t.push(" return normalize( tsn * mapN );"),t.push("}")}));return{programName:"PBR",getHash:()=>[s.getHash(),r?"sao":"nosao",!!i.gammaOutput],getLogDepth:i.logarithmicDepthBufferEnabled&&(e=>e),renderPassFlag:0,clippingCaps:i._sectionPlanesState.clippingCaps&&b,incrementDrawState:!0,appendFragmentOutputs:(e,i,n)=>{if(e.push("const float PI = 3.14159265359;"),e.push("vec3 reflDiff = vec3(0.0);"),e.push("vec3 reflSpec = vec3(0.0);"),e.push(`vec3 rgb = ${p}.rgb;`),e.push(`float opacity = ${p}.a;`),e.push("vec3 baseColor = rgb;"),e.push("float specularF0 = 1.0;"),e.push(`float metallic = float(${m}.r) / 255.0;`),e.push(`float roughness = float(${m}.g) / 255.0;`),e.push("float dielectricSpecular = 0.16 * specularF0 * specularF0;"),e.push(`vec4 colorTexel = ${a(g)};`),e.push("baseColor *= colorTexel.rgb;"),e.push(`vec3 metalRoughTexel = ${l(g)}.rgb;`),e.push("metallic *= metalRoughTexel.b;"),e.push("roughness *= metalRoughTexel.g;"),e.push("vec3 diffuseColor = baseColor * (1.0 - dielectricSpecular) * (1.0 - metallic);"),e.push("float specularRoughness = clamp(roughness, 0.04, 1.0);"),e.push("vec3 specularColor = mix(vec3(dielectricSpecular), baseColor, metallic);"),e.push(`vec3 viewNormal = -${v}(${d}, normalize(${f}), ${g}, ${h(g)});`),e.push(`vec3 viewEyeDir = normalize(${d});`),o&&e.push(`reflDiff += ${o(`normalize(${_})`)};`),s.getReflection){const i=`normalize((vec4(reflect(viewEyeDir, viewNormal), 0.0) * ${t.viewMatrix}).xyz)`,r="8.0",n=`0.5 * clamp(${r} - 0.79248 - 0.5 * log2(pow((2.0 / pow(specularRoughness + 0.0001, 2.0) - 2.0), 2.0) + 1.0), 0.0, ${r})`,A=s.getReflection(i,n),o=`${w}(viewNormal, viewEyeDir, specularColor, specularRoughness)`;e.push(`reflSpec += ${A} * ${o};`)}s.directionalLights.forEach(((i,s)=>{e.push(`vec3 lightDirection${s} = -${i.getDirection(t.viewMatrix,d)};`);const r=`${B}(dot(viewNormal, lightDirection${s}))`;e.push(`vec3 irradiance${s} = ${r} * ${i.getColor()};`),e.push(`reflDiff += irradiance${s};`),e.push(`reflSpec += irradiance${s} * PI * ${y}(lightDirection${s}, viewNormal, viewEyeDir, specularColor, specularRoughness);`)})),e.push(`vec3 emissiveColor = ${c(g)}.rgb;`),e.push(`float aoFactor = ${u(g)}.r;`);const A=`${s.getAmbientColor()} * baseColor * opacity * rgb`;e.push(`vec3 outgoingLight = emissiveColor + reflDiff * diffuseColor + reflSpec + ${A};`),e.push(`${b} = vec4(outgoingLight * aoFactor${r?` * ${r.getAmbient(n)}`:""}, opacity);`),i&&e.push(`${b} = ${i(b)};`)}}}(r,n,t,e(r),s&&i(r))))),texture:A&&{"alphaCutoff-":d(((e,t,i)=>i(r(e,t,!1)))),"alphaCutoff+":d(((e,t,i)=>i(r(e,t,!0))))},vertex:d(o?(t,r,n)=>n(f(t,r,e(t),s&&i(t))):(r,n,A)=>A(function(e,t,i,s,r){const n=t.attributes,A=e.createVarying("vec3","vViewPosition",(()=>`${n.position.view}.xyz`)),o=e.createVarying("vec4","vColor",(()=>n.color)),a=e.createOutput("vec4","outColor");return{programName:"FlatColor",getHash:()=>[s.getHash(),r?"sao":"nosao"],cleanerEdges:!0,getLogDepth:i&&(e=>e),renderPassFlag:0,appendFragmentOutputs:(e,i,n,l)=>{e.push(`vec3 viewNormal = normalize(cross(dFdx(${A}), dFdy(${A})));`);const c=[s.getAmbientColor()].concat(s.directionalLights.map((e=>`max(dot(viewNormal, ${e.getDirection(t.viewMatrix,A)}), 0.0) * ${e.getColor()}`)));e.push(`vec4 fragColor = vec4(${c.join(" + ")}, 1) * ${l(o)};`),e.push(`${a} = ${r?`vec4(fragColor.rgb * ${r.getAmbient(n)}, fragColor.a)`:"fragColor"};`)}}}(r,n,t.logarithmicDepthBufferEnabled,e(r),s&&i(r))))}};return{"sao-":s(!1),"sao+":r&&s(!0)}}(),depthRenderer:d(((e,i,s)=>s(function(e,t,i){const s=e.createVarying("highp vec2","vHighPrecisionZW",(()=>`${t.attributes.position.clip}.zw`)),r=e.createOutput("vec4","outColor");return{programName:"Depth",getLogDepth:i&&(e=>e),renderPassFlag:0,appendFragmentOutputs:e=>e.push(`${r} = vec4(vec3((1.0 - ${s}[0] / ${s}[1]) / 2.0), 1.0);`)}}(e,i,t.logarithmicDepthBufferEnabled)))),edgesRenderers:{uniform:d(((e,i,s)=>s(gr(e,i,t.logarithmicDepthBufferEnabled,!0))),{vertices:!1}),vertex:d(((e,i,s)=>s(gr(e,i,t.logarithmicDepthBufferEnabled,!1))),{vertices:!1})},occlusionRenderer:d(((e,i,s)=>s(mr(e,t.logarithmicDepthBufferEnabled)))),pickDepthRenderer:u(p),pickMeshRenderer:u(g),pickNormalsFlatRenderer:u(((e,t,i)=>m(e,t,i,!0))),pickNormalsRenderer:u(((e,t,i)=>m(e,t,i,!1))),shadowRenderer:d(((e,i,s)=>s(function(e,t){const i=e.createOutput("vec4","outColor"),s=e.createFragmentDefinition("encodeFloat",((e,t)=>{t.push(`vec4 ${e}(const in float v) {`),t.push(" const vec4 bitShift = vec4(256 * 256 * 256, 256 * 256, 256, 1.0);"),t.push(" const vec4 bitMask = vec4(0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0);"),t.push(" vec4 comp = fract(v * bitShift);"),t.push(" comp -= comp.xxyz * bitMask;"),t.push(" return comp;"),t.push("}")}));return{programName:"Shadow",getLogDepth:t&&(e=>e),renderPassFlag:0,isShadowProgram:!0,appendFragmentOutputs:(e,t,r)=>e.push(`${i} = ${s}(${r}.z);`)}}(e,t)))),silhouetteRenderer:u(((e,i,s)=>s(_r(e,i,t.logarithmicDepthBufferEnabled,!1)))),snapInitRenderer:u(((e,t,i)=>_(e,t,i,!0,!1))),snapEdgeRenderer:u(((e,t,i)=>_(e,t,i,!1,!1)),{vertices:!1}),snapVertexRenderer:u(((e,t,i)=>_(e,t,i,!1,!1)),{vertices:!0})};const b=e=>{!function t(i){i.revalidate?i.revalidate(e):Object.values(i).forEach((e=>e&&t(e)))}(c[h])},B=()=>b(!1);B(),t.on("compile",B),t.on("destroyed",(()=>{delete c[h]}))}return c[h]}}();class Vr{constructor(e,t,i){this.model=e,this.primitive=t,this.origin=i,this._meshes=[],this._aabb=V.collapseAABB3(),this._aabbDirty=!0}finalize(){if(!this._compiledPortions){this._compiledPortions=this.compilePortions(),this.solid=this._compiledPortions.solid,this.sortId=this._compiledPortions.sortId,this.layerTextureSet=this._compiledPortions.layerTextureSet,this.drawCalls=this._compiledPortions.drawCalls,this._renderers=this._compiledPortions.renderers,this._setFlags=this._compiledPortions.setFlags,this.setColor=this._compiledPortions.setColor,this.setMatrix=this._compiledPortions.setMatrix,this.setOffset=this._compiledPortions.setOffset,this.getEachIndex=this._compiledPortions.getEachIndex,this.getEachVertex=this._compiledPortions.getEachVertex,this.readGeometryData=this._compiledPortions.readGeometryData,this.precisionRayPickSurface=this._compiledPortions.precisionRayPickSurface,this._countsByFlag={};const e=(e,t)=>{const i={count:0,fromFlags:(s,r)=>{s&e?(i.count++,this.model[t]++):r||(i.count--,this.model[t]--)}};this._countsByFlag[e]=i};e(or,"numVisibleLayerPortions"),e(ar,"numCulledLayerPortions"),e(lr,"numPickableLayerPortions"),e(cr,"numClippableLayerPortions"),e(ur,"numXRayedLayerPortions"),e(dr,"numHighlightedLayerPortions"),e(fr,"numSelectedLayerPortions"),this._renderers.edgesRenderers&&e(pr,"numEdgesLayerPortions"),this._countsByFlagArr=Object.values(this._countsByFlag),this._numTransparentLayerPortions=0}}aabbChanged(){this._aabbDirty=!0}getAABB(){return this._aabbDirty&&(V.collapseAABB3(this._aabb),this._meshes.forEach((e=>V.expandAABB3(this._aabb,e.aabb))),this._aabbDirty=!1),this._aabb}__drawLayer(e,t,i,s){if(this._countsByFlag[ar].count<this._portions.length&&this._countsByFlag[or].count>0){const e="points"!==this.primitive&&"lines"!==this.primitive&&[Mr,Er,kr,Fr,Ur,xr];if(e&&e.includes(s)){const e=!0;if(t.backfaces!==e){const i=this.model.scene.canvas.gl;i.disable(i.CULL_FACE),t.backfaces=e}}t.textureUnit=0,i.drawLayer(t,this,s)}}__setVec4FromMaterialColorAlpha(e,t,i){return i[0]=e[0],i[1]=e[1],i[2]=e[2],i[3]=t,i}__drawColor(e,t,i){if((i?this._numTransparentLayerPortions<this._portions.length:this._numTransparentLayerPortions>0)&&this._countsByFlag[ur].count<this._portions.length){const s=i&&t.withSAO&&this._renderers.colorRenderers["sao+"]||this._renderers.colorRenderers["sao-"],r=t.pbrEnabled&&s.PBR?s.PBR:t.colorTextureEnabled&&s.texture?s.texture[this.layerTextureSet&&"number"==typeof this.layerTextureSet.alphaCutoff?"alphaCutoff+":"alphaCutoff-"]:s.vertex,n=i?Mr:Er;this.__drawLayer(e,t,r,n)}}drawColorOpaque(e,t){this.__drawColor(e,t,!0)}drawColorTransparent(e,t){this.__drawColor(e,t,!1)}drawDepth(e,t){const i=this._renderers.depthRenderer;i&&this._numTransparentLayerPortions<this._portions.length&&this._countsByFlag[ur].count<this._portions.length&&this.__drawLayer(e,t,i,Mr)}__drawSilhouette(e,t,i,s){t.programColor=this.__setVec4FromMaterialColorAlpha(i.fillColor,i.fillAlpha,yr),this.__drawLayer(e,t,this._renderers.silhouetteRenderer,s)}drawSilhouetteXRayed(e,t){this._countsByFlag[ur].count>0&&this.__drawSilhouette(e,t,this.model.scene.xrayMaterial,xr)}drawSilhouetteHighlighted(e,t){this._countsByFlag[dr].count>0&&this.__drawSilhouette(e,t,this.model.scene.highlightMaterial,Fr)}drawSilhouetteSelected(e,t){this._countsByFlag[fr].count>0&&this.__drawSilhouette(e,t,this.model.scene.selectedMaterial,Ur)}__drawVertexEdges(e,t,i){const s=this._renderers.edgesRenderers&&this._renderers.edgesRenderers.vertex;s&&this._countsByFlag[pr].count>0&&this.__drawLayer(e,t,s,i)}drawEdgesColorOpaque(e,t){this._compiledPortions.edgesColorOpaqueAllowed()&&this.__drawVertexEdges(e,t,Ir)}drawEdgesColorTransparent(e,t){this._numTransparentLayerPortions>0&&this.__drawVertexEdges(e,t,Tr)}__drawUniformEdges(e,t,i,s){const r=this._renderers.edgesRenderers&&this._renderers.edgesRenderers.uniform;r&&(t.programColor=this.__setVec4FromMaterialColorAlpha(i.edgeColor,i.edgeAlpha,yr),this.__drawLayer(e,t,r,s))}drawEdgesHighlighted(e,t){this._countsByFlag[dr].count>0&&this.__drawUniformEdges(e,t,this.model.scene.highlightMaterial,Pr)}drawEdgesSelected(e,t){this._countsByFlag[fr].count>0&&this.__drawUniformEdges(e,t,this.model.scene.selectedMaterial,Sr)}drawEdgesXRayed(e,t){this._countsByFlag[ur].count>0&&this.__drawUniformEdges(e,t,this.model.scene.xrayMaterial,Dr)}__drawPick(e,t,i){i&&this.__drawLayer(e,t,i,kr)}drawPickMesh(e,t){this.__drawPick(e,t,this._renderers.pickMeshRenderer)}drawPickDepths(e,t){this.__drawPick(e,t,this._renderers.pickDepthRenderer)}drawPickNormals(e,t){const i=this._renderers.pickNormalsFlatRenderer;this.__drawPick(e,t,i)}drawSnap(e,t,i){t.snapPickOrigin=[0,0,0];const s=this.getAABB();t.snapPickCoordinateScale=V.mulVec3Scalar(Qr([s[3]-s[0],s[4]-s[1],s[5]-s[2]]),V.MAX_INT);const r=i?this._renderers.snapInitRenderer:"edge"===t.snapMode?this._renderers.snapEdgeRenderer:this._renderers.snapVertexRenderer;this.__drawPick(e,t,r),t.snapPickLayerParams.push({origin:t.snapPickOrigin.slice(),coordinateScale:Qr(t.snapPickCoordinateScale)})}drawOcclusion(e,t){const i=this._renderers.occlusionRenderer;i&&this.__drawLayer(e,t,i,Mr)}drawShadow(e,t){const i=this._renderers.shadowRenderer;i&&this.__drawLayer(e,t,i,Mr)}initFlags(e,t,i){this._countsByFlagArr.forEach((e=>e.fromFlags(t,!0))),i&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++);const s="points"!==this.primitive;this._setFlags(e,t,i,s),this._compiledPortions.setFlags2(e,t,s)}flushInitFlags(){this._compiledPortions.setDeferredFlags()}setVisible(e,t,i){this._countsByFlag[or].fromFlags(t),this._setFlags(e,t,i)}setCulled(e,t,i){this._countsByFlag[ar].fromFlags(t),this._setFlags(e,t,i)}setPickable(e,t,i){this._countsByFlag[lr].fromFlags(t),this._setFlags(e,t,i)}setClippable(e,t){this._countsByFlag[cr].fromFlags(t),this._compiledPortions.setClippableFlags(e,t)}setCollidable(e,t){}setXRayed(e,t,i){this._countsByFlag[ur].fromFlags(t),this._setFlags(e,t,i)}setHighlighted(e,t,i){this._countsByFlag[dr].fromFlags(t),this._setFlags(e,t,i)}setSelected(e,t,i){this._countsByFlag[fr].fromFlags(t),this._setFlags(e,t,i)}setEdges(e,t,i){this._countsByFlag[pr]&&(this._countsByFlag[pr].fromFlags(t),this._setFlags(e,t,i))}setTransparent(e,t,i){i?(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++):(this._numTransparentLayerPortions--,this.model.numTransparentLayerPortions--),this._setFlags(e,t,i)}destroy(){this._compiledPortions&&this._compiledPortions.destroy()}}let Lr=65536,Hr=5e6;class Nr{constructor(){}set doublePrecisionEnabled(e){V.setDoublePrecisionEnabled(e)}get doublePrecisionEnabled(){return V.getDoublePrecisionEnabled()}set maxDataTextureHeight(e){(e=1024*Math.ceil(e/1024))>4096?e=4096:e<1024&&(e=1024),Lr=e}get maxDataTextureHeight(){return Lr}set maxGeometryBatchSize(e){e<1e5?e=1e5:e>5e6&&(e=5e6),Hr=e}get maxGeometryBatchSize(){return Hr}}const Gr=e=>{const t=[];for(let i=0;i<e;++i)t.push(i);return t},jr={sizeDataColorsAndFlags:0,sizeDataInstancesMatrices:0,sizeDataPositionDecodeMatrices:0,sizeDataTextureOffsets:0,sizeDataTexturePositions:0,sizeDataTextureIndices:0,sizeDataTextureEdgeIndices:0,sizeDataTexturePortionIds:0,numberOfGeometries:0,numberOfPortions:0,numberOfLayers:0,numberOfTextures:0,totalPolygons:0,totalPolygons8Bits:0,totalPolygons16Bits:0,totalPolygons32Bits:0,totalEdges:0,totalEdges8Bits:0,totalEdges16Bits:0,totalEdges32Bits:0,cannotCreatePortion:{because10BitsObjectId:0,becauseTextureSize:0},overheadSizeAlignementIndices:0,overheadSizeAlignementEdgeIndices:0};window.printDataTextureRamStats=function(){console.log(JSON.stringify(jr,null,4));let e=0;Object.keys(jr).forEach((t=>{t.startsWith("size")&&(e+=jr[t])})),console.log(`Total size ${e} bytes (${(e/1e3/1e3).toFixed(2)} MB)`),console.log(`Avg bytes / triangle: ${(e/jr.totalPolygons).toFixed(2)}`);let t={};Object.keys(jr).forEach((i=>{i.startsWith("size")&&(t[i]=`${(jr[i]/e*100).toFixed(2)} % of total`)})),console.log(JSON.stringify({percentualRamUsage:t},null,4))};const Wr=new Nr,zr=Wr.maxDataTextureHeight,Xr=V.vec3(),Kr=V.vec3(),Zr=V.vec4();V.vec4();const Jr=new Float32Array(16),Yr=new Uint8Array(4),$r=V.identityMat4();class qr extends Vr{constructor(e,t,i){super(e,t,i),jr.numberOfLayers++,this._sortId=`TriDTX-${jr.numberOfLayers}`;const s=e.scene.canvas.gl,r=(e,t)=>{const i=[];let r=0;const A=[];let o=0;const a=[];let l=0;const c=[];let h=0;return{len:()=>o,accumulateIndices:(s,u)=>{const d=s&&s.length>0&&function(){const t=r/3;r+=s.length,i.push(s);const a=s.length/3;return i=>{const s=o;o+=3*a,n.perObjectIndexBaseOffsets.push(s/3-t);for(let e=0;e<a;e+=8)A.push(i);jr[e]+=a,jr.totalPolygons+=a}}(),f=u&&function(){const e=l/2;l+=u.length,a.push(u);const i=u.length/2;return s=>{const r=h;h+=2*i,n.perObjectEdgeIndexBaseOffsets.push(r/2-e);for(let e=0;e<i;e+=8)c.push(s);jr[t]+=i,jr.totalEdges+=i}}();return jr.numberOfGeometries++,{numTriangles:s?s.length/3:0,accumulateSubPortionId:e=>{d&&d(e),f&&f(e)}}},createDrawers:(e,t)=>{const n=function(t,i){return t.length>0?e([t],t.length,1,s.UNSIGNED_SHORT,"sizeDataTexturePortionIds"):i},u=n(A,{texture:null}),d=r>0&&e(i,r,3,t,"sizeDataTextureIndices"),f=n(c),p=l>0&&e(a,l,2,t,"sizeDataTextureEdgeIndices");return{indices:function(e,t){o>0&&(e.perPrimIndices.setInputValue(d),e.perPrimIdPorIds.setInputValue(u),s.drawArrays(t,0,o))},edges:function(e,t){h>0&&(e.perPrimIndices.setInputValue(p),e.perPrimIdPorIds.setInputValue(f),s.drawArrays(t,0,h))}}}}},n=this._buffer={positionsCompressed:[],lenPositionsCompressed:0,geometry8Bits:r("totalPolygons8Bits","totalEdges8Bits"),geometry16Bits:r("totalPolygons16Bits","totalEdges16Bits"),geometry32Bits:r("totalPolygons32Bits","totalEdges32Bits"),perObjectColors:[],perObjectPickColors:[],perObjectSolid:[],perObjectPositionsDecodeMatrices:[],perObjectInstancePositioningMatrices:[],perObjectVertexBases:[],perObjectIndexBaseOffsets:[],perObjectEdgeIndexBaseOffsets:[]};this._numVertices=0,this._portions=[],this._subPortionReadableGeometries=this.model.scene.readableGeometryEnabled&&{},this._portionToSubPortionsMap=[],this._bucketGeometries={},this._primitive=t}canCreatePortion(e){const t=e.buckets.length;this._portions.length+t>65536&&jr.cannotCreatePortion.because10BitsObjectId++;let i=this._portions.length+t<=65536;const s=void 0!==e.geometryId&&null!==e.geometryId?`${e.geometryId}#0`:`${e.id}#0`;if(!this._bucketGeometries[s]){const t=this._buffer,s=Math.max(t.geometry8Bits.len(),t.geometry16Bits.len(),t.geometry32Bits.len());let r=0,n=0;e.buckets.forEach((e=>{r+=e.positionsCompressed.length/3,n+=e.indices.length/3})),(this._numVertices+r>4096*zr||s+n>4096*zr)&&jr.cannotCreatePortion.becauseTextureSize++,i&&=this._numVertices+r<=4096*zr&&s+n<=4096*zr}return i}createPortion(e,t){const i=this._buffer,s=t.buckets.map(((e,s)=>{const r=(t.geometryId??t.id)+"#"+s;if(!(r in this._bucketGeometries)){const t=(e,t,i)=>{if(e){const s=8*Math.ceil(e.length/t/8)*t,r=new Uint32Array(s);return r.set(e),jr[i]+=2*(r.length-e.length),r}return e};e.indices=t(e.indices,3,"overheadSizeAlignementIndices"),e.edgeIndices=t(e.edgeIndices,2,"overheadSizeAlignementEdgeIndices");const s=e.positionsCompressed;i.positionsCompressed.push(s);const n=s.length/3;this._numVertices+=n;const A=i.lenPositionsCompressed/3;i.lenPositionsCompressed+=s.length,this._bucketGeometries[r]={vertexBase:A,geometryData:function(){const t=e.indices,s=e.edgeIndices;return n<=256?i.geometry8Bits.accumulateIndices(t,s):n<=65536?i.geometry16Bits.accumulateIndices(t,s):i.geometry32Bits.accumulateIndices(t,s)}()}}const n=this._bucketGeometries[r];i.perObjectPositionsDecodeMatrices.push(t.positionsDecodeMatrix),i.perObjectInstancePositioningMatrices.push(t.meshMatrix||$r),i.perObjectSolid.push(!!t.solid),i.perObjectPickColors.push(t.pickColor),i.perObjectVertexBases.push(n.vertexBase);const A=t.colors,o=t.color;i.perObjectColors.push(A?[255*A[0],255*A[1],255*A[2],255]:[o[0],o[1],o[2],t.opacity]);const a=this._portions.length;return this._portions.push({}),n.geometryData.accumulateSubPortionId(a),this._subPortionReadableGeometries&&(this._subPortionReadableGeometries[a]={indices:e.indices,positionsCompressed:e.positionsCompressed,positionsDecodeMatrix:t.positionsDecodeMatrix}),jr.numberOfPortions++,a})),r=this._portionToSubPortionsMap.length;return this._portionToSubPortionsMap.push(s),this.model.numPortions++,this._meshes.push(e),r}compilePortions(){const e=this._buffer,t=this.model,i=this._portions.length,s=this.origin,r=this._portionToSubPortionsMap,n=this._primitive,A=this._sortId,o=this._subPortionReadableGeometries,a=t.scene,l=a.canvas.gl,c=en(l,i,32,l.UNSIGNED_BYTE,512,(t=>{const s=e=>[e>>24&255,e>>16&255,e>>8&255,255&e];for(let r=0;r<i;r++)t.set(e.perObjectColors[r],32*r+0),t.set(e.perObjectPickColors[r],32*r+4),t.set([0,0,0,0],32*r+8),t.set([0,0,0,0],32*r+12),t.set(s(e.perObjectVertexBases[r]),32*r+16),t.set(s(e.perObjectIndexBaseOffsets[r]),32*r+20),t.set(s(e.perObjectEdgeIndexBaseOffsets[r]),32*r+24),t.set([e.perObjectSolid[r]?1:0,0,0,0],32*r+28)}),"sizeDataColorsAndFlags",!0),h=c.textureData,u=function(e,t,i,s,r,n,A){return en(l,t,i,s,r,(t=>{for(let i=0,s=0,r=e.length;i<r;i++){const r=e[i];t.set(r,s),s+=r.length}}),n,A)},d=function(e,t,i){const s=e.length;if(0===s)throw"num "+t+" matrices===0";return u(e,s,16,l.FLOAT,512,t,i)},f=d(e.perObjectInstancePositioningMatrices,"sizeDataInstancesMatrices",!0),p=f.textureData,g=d(e.perObjectPositionsDecodeMatrices,"sizeDataPositionDecodeMatrices",!1),m=function(e,t,i,s,r){return u(e,t/i,i,s,4096,r,!1)},_=m(e.positionsCompressed,e.lenPositionsCompressed,3,l.UNSIGNED_SHORT,"sizeDataTexturePositions"),b=e.geometry8Bits.createDrawers(m,l.UNSIGNED_BYTE),B=e.geometry16Bits.createDrawers(m,l.UNSIGNED_SHORT),y=e.geometry32Bits.createDrawers(m,l.UNSIGNED_INT);this._buffer=null;let w=!1,v=!1,C=!1,M=0;const E=()=>{w=!0},F=a.on("rendering",(()=>{v&&(w=!1,v=!1,h.reloadData()),M=0})),U=(e,i)=>{const s=r[e];if(s)for(let e=0,t=s.length;e<t;e++)i(s[e]);else t.error("portion not found: "+e)},x=(e,t,i,s)=>{const r=w||s;r?v=!0:++M>=10&&E(),h.setData(i,e,t,!r)},I=(e,t,i=!1)=>{Yr.set([t&cr?255:0,0,1,2]),U(e,(e=>x(e,3,Yr,i)))};return{edgesColorOpaqueAllowed:()=>!a.logarithmicDepthBufferEnabled||(a._loggedWarning||(console.log("Edge enhancement for SceneModel data texture layers currently disabled with logarithmic depth buffer"),a._loggedWarning=!0),!1),sortId:A,setClippableFlags:I,setFlags:(e,t,i,s=!1)=>{Rr(t,i,!0,a,Yr),U(e,(e=>x(e,2,Yr,s)))},setFlags2:I,setDeferredFlags:()=>{},setColor:(e,t)=>{Yr.set(t),U(e,(e=>x(e,0,Yr,!1)))},setMatrix:(e,t)=>{U(e,(e=>{const i=w;i?v=!0:++M>=10&&E(),Jr.set(t),p.setData(Jr,e,0,!i)}))},setOffset:(e,t)=>{},getEachIndex:(e,t)=>{o&&U(e,(e=>o[e].indices.forEach((e=>t(e)))))},getEachVertex:(e,i)=>{o&&U(e,(e=>{const r=o[e],n=r.positionsCompressed,A=r.positionsDecodeMatrix,a=Zr;for(let e=0,r=n.length;e<r;e+=3)a[0]=n[e],a[1]=n[e+1],a[2]=n[e+2],a[3]=1,V.decompressPosition(a,A),V.mulMat4v4(t.worldMatrix,a,a),V.addVec3(s,a,a),i(a)}))},precisionRayPickSurface:(e,t,i,s,r)=>!1,renderers:Or(a,"dtx",n,t.saoEnabled,!1,!1,!0,((e,t)=>tn(e,!t))),drawCalls:function(){const e=function(e){const i=(e,t)=>e.setInputValue&&e.setInputValue(t);return(r,n,A)=>{i(n.worldMatrix,t.rotationMatrix),i(n.viewMatrix,A.viewMatrix),i(n.projMatrix,A.projMatrix);const o=V.transformPoint3(t.matrix,s,Xr);i(n.uCameraEyeRtc,V.subVec3(A.eye,o,Kr)),i(n.perObjPosDecode,g),i(n.perVertIdCoords,_),i(n.perObjColsFlags,c),i(n.perObjectMatrix,f),e(n)}},i=function(t){return e((e=>{b.edges(e,t),B.edges(e,t),y.edges(e,t)}))};return{drawVertices:i(l.POINTS),drawEdges:i(l.LINES),drawSurface:e((e=>{const t=l.TRIANGLES;b.indices(e,t),B.indices(e,t),y.indices(e,t)}))}}(),destroy:()=>{C||(a.off(F),C=!0)}}}}const en=function(e,t,i,s,r,n,A,o){if(i>4&&i%4>0)throw"Unhandled data size "+i;const a=Math.ceil(i/4),l=i/a,[c,h,u]=function(){switch(s){case e.UNSIGNED_BYTE:return[Uint8Array,...1===l?[e.R8UI,e.RED_INTEGER]:2===l?[e.RG8UI,e.RG_INTEGER]:3===l?[e.RGB8UI,e.RGB_INTEGER]:[e.RGBA8UI,e.RGBA_INTEGER]];case e.UNSIGNED_SHORT:return[Uint16Array,...1===l?[e.R16UI,e.RED_INTEGER]:2===l?[e.RG16UI,e.RG_INTEGER]:3===l?[e.RGB16UI,e.RGB_INTEGER]:[e.RGBA16UI,e.RGBA_INTEGER]];case e.UNSIGNED_INT:return[Uint32Array,...1===l?[e.R32UI,e.RED_INTEGER]:2===l?[e.RG32UI,e.RG_INTEGER]:3===l?[e.RGB32UI,e.RGB_INTEGER]:[e.RGBA32UI,e.RGBA_INTEGER]];case e.FLOAT:return[Float32Array,...1===l?[e.R32F,e.RED]:2===l?[e.RG32F,e.RG]:3===l?[e.RGB32F,e.RGB]:[e.RGBA32F,e.RGBA]];default:throw"Unhandled data type "+s}}(),d=r*a,f=Math.ceil(t/r);if(0===f)throw"texture height===0";const p=new c(d*f*l);jr[A]+=p.byteLength,jr.numberOfTextures++,n(p);const g=e.createTexture();return e.bindTexture(e.TEXTURE_2D,g),e.texStorage2D(e.TEXTURE_2D,1,h,d,f),e.texSubImage2D(e.TEXTURE_2D,0,0,0,d,f,u,s,p),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.bindTexture(e.TEXTURE_2D,null),{bind:t=>(e.activeTexture(e["TEXTURE"+t]),e.bindTexture(e.TEXTURE_2D,g),!0),unbind(e){},textureData:o&&{setData(t,n,A=0,o=!1){if(p.set(t,n*i+A*l),o){e.bindTexture(e.TEXTURE_2D,g);const i=n%r*a+A,o=Math.floor(n/r),c=t.length/l;e.texSubImage2D(e.TEXTURE_2D,0,i,o,c,1,u,s,t)}},reloadData(){e.bindTexture(e.TEXTURE_2D,g),e.texSubImage2D(e.TEXTURE_2D,0,0,0,d,f,u,s,p)}}}},tn=function(e,t){const i=(t,i)=>{const s=e.createUniform(t,i),r=e=>`texelFetch(${s}, ${e}, 0)`;return r.map=s,r},s=i("highp usampler2D","perPrimIndices"),r=i("mediump usampler2D","perPrimIdPorIds"),n=i("highp sampler2D","perObjPosDecode"),A=i("mediump usampler2D","perVertIdCoords"),o=i("lowp usampler2D","perObjColsFlags"),a=i("highp sampler2D","perObjectMatrix"),l=e.createUniform("mat4","worldMatrix"),c=e.createUniform("mat4","viewMatrix"),h=e.createUniform("mat4","projMatrix"),u=e.createUniform("vec3","uCameraEyeRtc"),d=function(e){const t={toString:()=>(t.needed=!0,e)};return t},f=d("colorA"),p=d("pickColor"),g=d("worldNormal"),m=d("viewNormal"),_=e=>o(`ivec2(objectIndexCoords.x*8+${e}, objectIndexCoords.y)`);return{clippableTest:function(){const t=e.createVarying("uint","vClippable",(()=>"flags2.r"),"flat");return()=>`${t} > 0u`}(),geometryParameters:{attributes:{color:f,flags:Gr(4).map((e=>`int(flags[${e}])`)),metallicRoughness:null,normal:{view:m,world:g},pickColor:p,position:{clip:"gl_Position",view:"viewPosition",world:"worldPosition"},uv:null},projMatrix:h,viewMatrix:c},ensureColorAndFlagAvailable:e=>{e.push("int primitiveIndex = gl_VertexID / "+(t?3:2)+";"),e.push("int h_packed_object_id_index = (primitiveIndex >> 3) & 4095;"),e.push("int v_packed_object_id_index = (primitiveIndex >> 3) >> 12;"),e.push(`int objectIndex = int(${r("ivec2(h_packed_object_id_index, v_packed_object_id_index)")}.r);`),e.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),e.push(`uvec4 flags = ${_(2)};`),e.push(`uvec4 flags2 = ${_(3)};`),f.needed&&e.push(`vec4 ${f} = vec4(${_(0)}) / 255.0;`)},appendVertexData:e=>{const i=e=>a(`ivec2(objectIndexCoords.x*4+${e}, objectIndexCoords.y)`);e.push(`mat4 objectInstanceMatrix = mat4(${i(0)}, ${i(1)}, ${i(2)}, ${i(3)});`);const r=e=>n(`ivec2(objectIndexCoords.x*4+${e}, objectIndexCoords.y)`);if(e.push(`mat4 objectDecodeAndInstanceMatrix = objectInstanceMatrix * mat4(${r(0)}, ${r(1)}, ${r(2)}, ${r(3)});`),e.push(`ivec4 packedVertexBase = ivec4(${_(4)});`),e.push(`ivec4 packedIndexBaseOffset = ivec4(${_(t?5:6)});`),e.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),e.push("int h_index = (primitiveIndex - indexBaseOffset) & 4095;"),e.push("int v_index = (primitiveIndex - indexBaseOffset) >> 12;"),e.push(`ivec3 vertexIndices = ivec3(${s("ivec2(h_index, v_index)")});`),e.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),t){e.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),e.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),e.push(`uint solid = ${_(7)}.r;`);const t=e=>`vec3(${A(`ivec2(indexPositionH[${e}], indexPositionV[${e}])`)})`;e.push(`vec3 positions[] = vec3[](${t(0)}, ${t(1)}, ${t(2)});`),e.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),e.push("vec3 position = positions[gl_VertexID % 3];"),g.needed&&e.push(`vec3 worldNormal = -normalize((transpose(inverse(${l} * objectDecodeAndInstanceMatrix)) * vec4(normal,1)).xyz);`),m.needed&&e.push(`vec3 viewNormal = -normalize((transpose(inverse(${c} * objectDecodeAndInstanceMatrix)) * vec4(normal,1)).xyz);`),e.push("if (solid != 1u) {"),e.push(` if (${o=h,`(${o}[2][3] == - 1.0)`}) {`),e.push(` vec3 uCameraEyeRtcInQuantizedSpace = (inverse(${l} * objectDecodeAndInstanceMatrix) * vec4(${u}, 1)).xyz;`),e.push(" if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),e.push(" position = positions[2 - (gl_VertexID % 3)];"),g.needed&&e.push(" worldNormal = -worldNormal;"),m.needed&&e.push(" viewNormal = -viewNormal;"),e.push(" }"),e.push(" } else {"),m.needed||e.push(` vec3 viewNormal = -normalize((transpose(inverse(${c} * objectDecodeAndInstanceMatrix)) * vec4(normal,1)).xyz);`),e.push(" if (viewNormal.z < 0.0) {"),e.push(" position = positions[2 - (gl_VertexID % 3)];"),g.needed&&e.push(" worldNormal = -worldNormal;"),m.needed&&e.push(" viewNormal = -viewNormal;"),e.push(" }"),e.push(" }"),e.push("}")}else e.push("int indexPositionH = uniqueVertexIndexes[gl_VertexID % 2] & 4095;"),e.push("int indexPositionV = uniqueVertexIndexes[gl_VertexID % 2] >> 12;"),e.push(`vec3 position = vec3(${A("ivec2(indexPositionH, indexPositionV)")});`);var o;p.needed&&e.push(`vec4 pickColor = vec4(${_(1)});`),e.push(`vec4 worldPosition = ${l} * (objectDecodeAndInstanceMatrix * vec4(position, 1.0));`)},layerTypeInputs:{perPrimIndices:s.map,perPrimIdPorIds:r.map,perObjPosDecode:n.map,perVertIdCoords:A.map,perObjColsFlags:o.map,perObjectMatrix:a.map,worldMatrix:l,viewMatrix:c,projMatrix:h,uCameraEyeRtc:u}}},sn=V.mat4(),rn=V.mat4();function nn(e,t,i){const s=e.length,r=new Uint16Array(s),n=t[0],A=t[1],o=t[2],a=t[3]-n||1,l=t[4]-A||1,c=t[5]-o||1,h=65525,u=h/a,d=h/l,f=h/c,p=e=>e>=0?e:0;for(let t=0;t<s;t+=3)r[t+0]=Math.floor(p(e[t+0]-n)*u),r[t+1]=Math.floor(p(e[t+1]-A)*d),r[t+2]=Math.floor(p(e[t+2]-o)*f);return V.identityMat4(sn),V.translationMat4v(t,sn),V.identityMat4(rn),V.scalingMat4v([a/h,l/h,c/h],rn),V.mulMat4(sn,rn,i),r}function An(e,t){const i=e[0],s=e[1],r=e[2],n=e[3]-i||1,A=e[4]-s||1,o=e[5]-r||1,a=65525;return V.identityMat4(sn),V.translationMat4v(e,sn),V.identityMat4(rn),V.scalingMat4v([n/a,A/a,o/a],rn),V.mulMat4(sn,rn,t),t}function on(e,t,i){let s=e[0]/(Math.abs(e[0])+Math.abs(e[1])+Math.abs(e[2])),r=e[1]/(Math.abs(e[0])+Math.abs(e[1])+Math.abs(e[2]));if(e[2]<0){let e=s,t=r;e=(1-Math.abs(r))*(s>=0?1:-1),t=(1-Math.abs(s))*(r>=0?1:-1),s=e,r=t}return new Int8Array([Math[t](127.5*s+(s<0?-1:0)),Math[i](127.5*r+(r<0?-1:0))])}function an(e){let t=e[0],i=e[1];t/=t<0?127:128,i/=i<0?127:128;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 r=Math.sqrt(t*t+i*i+s*s);return[t/r,i/r,s/r]}const ln=new Float32Array(1),cn=new Float32Array(4),hn=new Float32Array(3),un=V.mat4(),dn=V.vec4([0,0,0,1]),fn=V.vec4(),pn=V.vec3(),gn=V.vec3(),mn=V.vec3(),_n=V.vec3(),bn=V.vec3(),Bn=V.vec3(),yn=V.vec3(),wn=new Uint8Array(4),vn=new Float32Array(96),Cn=function(e){const t=[];for(let i=0;i<e;++i)t.push(i);return t},Mn=function(e,t){e.set(t);let i=t.length;const s=e.length;for(;i<s;){const t=Math.min(i,s-i);e.set(e.subarray(0,t),i),i+=t}},En=function(){let e=0;const t=new Map;return{acquire:()=>e++,release:()=>{e--,0===e&&t.clear()},getTypeArray:function(e,i){t.has(e)||t.set(e,{});const s=t.get(e);return i in s||(s[i]=new e(i)),s[i]}}}();class Fn extends Vr{constructor(e,t,i,s){super(e,t,i);const r=!!s.geometry;this._maxVerts=s.maxGeometryBatchSize;const n=r?s.geometry.positionsDecodeMatrix:s.positionsDecodeMatrix;this._positionsDecodeMatrix=n&&V.mat4(n),this._cfgUvDecodeMatrix=s.uvDecodeMatrix&&V.mat3(s.uvDecodeMatrix),this._instancedGeometry=s.geometry,this._textureSet=s.textureSet,this._modelAABB=!r&&V.collapseAABB3(),this._portions=[];const A=function(){let e=0;const t=[];return{length:()=>e,append:function(i,s=1,r=1,n=0){e+=s*i.length,t.push({data:i,times:s,denormalizeScale:r,increment:n})},compileBuffer:function(e){let i=0;t.forEach((e=>{i+=e.times*e.data.length}));const s=new e(i);let r=0;return t.forEach((e=>{const t=e.data,i=e.denormalizeScale,n=e.increment,A=s.subarray(r);if(1===i&&0===n)A.set(t);else for(let e=0;e<t.length;++e)A[e]=n+t[e]*i;let o=t.length;const a=e.times*t.length;for(;o<a;){const e=Math.min(o,a-o);A.set(A.subarray(0,e),o),o+=e}r+=o})),s}}};this._buffer={colors:A(),metallicRoughness:A(),pickColors:A(),...r?{modelMatrixCol:[A(),A(),A()],modelNormalMatrixCol:[A(),A(),A()]}:{positions:A(),indices:A(),uv:A(),normals:A(),edgeIndices:A()}}}canCreatePortion(e,t){return this._instancedGeometry||this._buffer.positions.length()+e<=3*this._maxVerts&&this._buffer.indices.length()+t<=3*this._maxVerts}createPortion(e,t){const i=this._buffer,s=this._instancedGeometry,r=this.model,n=this._portions.length,A=this.primitive,o=!!this._positionsDecodeMatrix,a=r.scene,l=t.meshMatrix,c=(s,o,l,c,h)=>{const u=this._portions.length>0&&this._portions[this._portions.length-1],d={indicesBaseIndex:u?u.indicesBaseIndex+u.numIndices:0,numIndices:l?l.length:0,portionBase:s,portionSize:o,retainedGeometry:a.readableGeometryEnabled&&"points"!==A&&"lines"!==A&&{indices:l,quantizedPositions:c,offset:a.entityOffsetsEnabled&&V.vec3(),matrix:h&&h.slice(),inverseMatrix:null,normalMatrix:null}};return"points"!==A&&"lines"!==A&&i.metallicRoughness.append([t.metallic??0,t.roughness??255],o),"lines"!==A&&i.pickColors.append(t.pickColor.slice(0,4),o),this._portions.push(d),r.numPortions++,this._meshes.push(e),n};if(s){if(i.modelMatrixCol.forEach(((e,t)=>e.append([l[t+0],l[t+4],l[t+8],l[t+12]]))),"points"!==A){const e=t.color;i.colors.append([e[0],e[1],e[2],t.opacity??255])}if("points"!==A&&"lines"!==A&&s.normals){const e=V.inverseMat4(V.transposeMat4(l,V.mat4()));i.modelNormalMatrixCol.forEach(((t,i)=>t.append([e[i+0],e[i+4],e[i+8],e[i+12]])))}return c(n,1,s.indices,s.positionsCompressed,l)}{const e=i.positions.length()/3,s=o?t.positionsCompressed:t.positions;if(!s)throw(o?"positionsCompressed":"positions")+" expected";i.positions.append(s);const r=s.length/3,n=t.indices;n&&i.indices.append(n,1,1,e);const a=t.normalsCompressed,h=t.normals;if(a&&a.length>0)i.normals.append(a);else if(h&&h.length>0){const e=un;l?(V.transposeMat4(l,e),V.inverseMat4(e,e)):V.identityMat4(e);const t=[];!function(e,t,i,s,r){function n(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}let A,o,a,l,c,h,u=new Float32Array([0,0,0,0]),d=new Float32Array([0,0,0,0]);for(h=0;h<i;h+=3)u[0]=t[h],u[1]=t[h+1],u[2]=t[h+2],V.transformVec3(e,u,d),V.normalizeVec3(d,d),a=A=on(d,"floor","floor"),o=an(A),l=c=n(d,o),A=on(d,"ceil","floor"),o=an(A),l=n(d,o),l>c&&(a=A,c=l),A=on(d,"floor","ceil"),o=an(A),l=n(d,o),l>c&&(a=A,c=l),A=on(d,"ceil","ceil"),o=an(A),l=n(d,o),l>c&&(a=A,c=l),s[r+h+0]=a[0],s[r+h+1]=a[1],s[r+h+2]=0}(e,h,h.length,t,0),i.normals.append(t)}const u=t.colors,d=t.colorsCompressed,f=t.color;if(u)if("points"===A)i.colors.append(u,1,255);else{const e=[];for(let t=0,i=u.length;t<i;t+=3)e.push(255*u[t]),e.push(255*u[t+1]),e.push(255*u[t+2]),e.push(255);i.colors.append(e)}else if(d)if("points"===A)i.colors.append(d);else{const e=[];for(let t=0,i=d.length;t<i;t+=3)e.push(d[t]),e.push(d[t+1]),e.push(d[t+2]),e.push(255);i.colors.append(e)}else f&&i.colors.append([f[0],f[1],f[2],"points"===A?1:t.opacity],r);const p=e=>e&&e.length>0&&e,g=p(t.uv)||p(t.uvCompressed);g&&i.uv.append(g);const m=t.edgeIndices;return m&&i.edgeIndices.append(m,1,1,e),V.expandAABB3(this._modelAABB,t.aabb),c(e,r,n)}}compilePortions(){const e=this._buffer,t=this._instancedGeometry,i=this.model,s=this._modelAABB,r=this.origin,n=this._portions,A=this.primitive,o=this._textureSet;let a=this._positionsDecodeMatrix;const l=this._cfgUvDecodeMatrix,c=i.scene,h=c.canvas.gl,u=!!t,d=[],f=(e,t,i,s)=>{if(t.length>0){const r=t.constructor,[n,A]={[Uint8Array]:[1,h.UNSIGNED_BYTE],[Int8Array]:[1,h.BYTE],[Uint16Array]:[2,h.UNSIGNED_SHORT],[Int16Array]:[2,h.SHORT],[Uint32Array]:[4,h.UNSIGNED_INT],[Int32Array]:[4,h.INT],[Float32Array]:[4,h.FLOAT]}[r],o=h.createBuffer();d.push((()=>h.deleteBuffer(o)));const a=()=>h.bindBuffer(e,o),l=t=>{a(),h.bufferData(e,t,s)};l(t);const c=t.BYTES_PER_ELEMENT,u=t.length/i;return{bindBuffer:a,getData:(t=0,s=u-t)=>{a();const A=new r(s*i);return h.getBufferSubData(e,t*n*i,A,0,s*i),A},numItems:u,setData:l,setSubData:(t,i)=>{a(),h.bufferSubData(e,i*c,t)},type:A}}return null},p=(e,t,i,s=!1,r=!1)=>{const n=f(h.ARRAY_BUFFER,e,t,i);return n&&{getData:n.getData,numItems:n.numItems,setData:n.setData,setSubData:n.setSubData,attributeDivisor:s&&1,bindAtLocation:e=>{n.bindBuffer(),h.vertexAttribPointer(e,t,n.type,!!r,0,0)}}},g=e=>{const t=f(h.ELEMENT_ARRAY_BUFFER,e,1,h.STATIC_DRAW);return t&&{getData:t.getData,bindIndicesBuffer:t.bindBuffer,indicesCount:e.length,indicesType:t.type}},m=n.reduce(((e,t)=>e+t.portionSize),0),_=p(new Float32Array(m),1,h.DYNAMIC_DRAW,u),b=(e,t)=>p(e,4,t,u&&"points"!==A,!0),B=u&&t.colorsCompressed?b(new Uint8Array(t.colorsCompressed),h.STATIC_DRAW):b(e.colors.compileBuffer(Uint8Array),h.DYNAMIC_DRAW),y=c.entityOffsetsEnabled&&p(new Float32Array(3*m),3,h.DYNAMIC_DRAW,u),w=p(e.metallicRoughness.compileBuffer(Uint8Array),2,h.STATIC_DRAW,u),v=p(e.pickColors.compileBuffer(Uint8Array),4,h.STATIC_DRAW,u),C=g(u?new Uint32Array(t.edgeIndices):e.edgeIndices.compileBuffer(Uint32Array)),M=u?"points"!==A&&t.indices&&new Uint32Array(t.indices):e.indices.compileBuffer(Uint32Array),E=M&&g(M),F=u?t.positionsCompressed:a?e.positions.compileBuffer(Uint16Array):nn(e.positions.compileBuffer(Float64Array),s,a=V.mat4()),U=F&&p(F,3,h.STATIC_DRAW);u||n.forEach((e=>{if(e.retainedGeometry){const t=3*e.portionBase;e.retainedGeometry.quantizedPositions=F.subarray(t,t+3*e.portionSize)}}));const x=u&&e.modelMatrixCol.map((e=>p(e.compileBuffer(Float32Array),4,h.STATIC_DRAW,!0))),I=!u&&e.normals.compileBuffer(Int8Array),T=I&&p(I,3,h.STATIC_DRAW,!1,!0),P=x&&T&&e.modelNormalMatrixCol.map((e=>p(e.compileBuffer(Float32Array),4,h.STATIC_DRAW,!0))),S=u?"points"!==A&&"lines"!==A&&t.uvCompressed&&{buf:p(t.uvCompressed,2,h.STATIC_DRAW),mat:t.uvDecodeMatrix}:function(){const t=e.uv.compileBuffer(Float32Array);if(0===t.length)return null;if(l)return{buf:p(t,2,h.STATIC_DRAW),mat:l};{const e=Ne.getUVBounds(t),i=Ne.compressUVs(t,e.min,e.max);return{buf:p(i.quantized,2,h.STATIC_DRAW),mat:V.mat3(i.decodeMatrix)}}}();this._buffer=null,En.acquire(),d.push((()=>En.release()));let D=null;const k=(e,i,s,r=!1)=>{Rr(i,s,"points"!==A&&"lines"!==A,c,wn);const o=i&cr?1:0;let a=0;a|=wn[0],a|=wn[1]<<4,a|=wn[2]<<8,a|=wn[3]<<12,a|=o<<16,ln[0]=a;const l=n[e],h=l.portionBase,u=l.portionSize;if(r&&!t)D||(D=new Float32Array(m)),Mn(D.subarray(h,h+u),ln);else if(_){const e=En.getTypeArray(Float32Array,u);Mn(e,ln),_.setSubData(e,h)}},Q="solid"===A;return{edgesColorOpaqueAllowed:()=>!0,solid:Q,sortId:("points"===A?"Points":"lines"===A?"Lines":"Triangles")+(u?"Instancing":"Batching")+"Layer"+("points"!==A&&"lines"!==A?(Q?"-solid":"-surface")+"-autoNormals"+(u?"":(o&&o.colorTexture?"-colorTexture":"")+(o&&o.metallicRoughnessTexture?"-metallicRoughnessTexture":"")):""),setClippableFlags:k,setFlags:k,setFlags2:(e,t,i)=>{},setDeferredFlags:()=>{D&&(_.setData(D),D=null)},setColor:(e,t)=>{if(B){const i=n[e],s=En.getTypeArray(Uint8Array,4*i.portionSize);Mn(s,t.slice(0,4)),B.setSubData(s,4*i.portionBase)}},setMatrix:(e,t)=>{x&&x.forEach(((i,s)=>{cn[0]=t[s+0],cn[1]=t[s+4],cn[2]=t[s+8],cn[3]=t[s+12],i.setSubData(cn,4*e)}))},setOffset:(e,t)=>{if(c.entityOffsetsEnabled){const i=n[e];if(y){hn.set(t);const e=En.getTypeArray(Float32Array,3*i.portionSize);Mn(e,hn),y.setSubData(e,3*i.portionBase)}i.retainedGeometry&&i.retainedGeometry.offset.set(t)}else i.error("Entity#offset not enabled for this Viewer")},getEachIndex:(e,t)=>{const i=n[e].retainedGeometry;i&&i.indices.forEach((e=>t(e)))},getEachVertex:(e,t)=>{const s=n[e].retainedGeometry;if(s){const e=fn;r?e.set(r,0):e[0]=e[1]=e[2]=0,e[3]=1;const n=i.matrix;V.mulMat4v4(n,e,e);const A=s.quantizedPositions,o=dn;for(let i=0,r=A.length;i<r;i+=3)o[0]=A[i],o[1]=A[i+1],o[2]=A[i+2],V.decompressPosition(o,a),s.matrix&&V.transformPoint3(s.matrix,o,o),o[3]=1,V.mulMat4v4(n,o,o),V.addVec3(e,o,o),t(o)}},readGeometryData:"points"!==A&&"lines"!==A&&(e=>{const t=!u&&n[e],s=t?E.getData(t.indicesBaseIndex,t.numIndices).map((e=>e-t.portionBase)):E.getData(),A=i.matrix,o=V.vec4();o.set(r,0),o[3]=1,V.mulMat4v4(A,o,o);const l=x&&V.mat4();if(l){const t=x[0].getData(e,1),i=x[1].getData(e,1),s=x[2].getData(e,1);l.set([t[0],i[0],s[0],0,t[1],i[1],s[1],0,t[2],i[2],s[2],0,t[3],i[3],s[3],1])}const c=V.mat4();V.mulMat4(A,l?V.mulMat4(l,a,c):a,c),c[12]+=o[0],c[13]+=o[1],c[14]+=o[2];const h=t?U.getData(t.portionBase,t.portionSize):U.getData();return{indices:s,positions:V.transformPositions3(c,h,new Float64Array(h.length))}}),precisionRayPickSurface:(e,t,s,A,o)=>{const l=n[e].retainedGeometry;if(l){l.matrix&&!l.inverseMatrix&&(l.inverseMatrix=V.inverseMat4(l.matrix,V.mat4())),o&&l.inverseMatrix&&!l.normalMatrix&&(l.normalMatrix=V.transposeMat4(l.inverseMatrix,V.mat4()));const e=l.quantizedPositions,n=l.indices,c=l.offset,h=pn,u=gn;h.set(r?V.subVec3(t,r,mn):t),u.set(s),c&&V.subVec3(h,c),V.transformRay(i.worldNormalMatrix,h,u,h,u),l.inverseMatrix&&V.transformRay(l.inverseMatrix,h,u,h,u);const d=_n,f=bn,p=Bn;let g=!1,m=0;const _=yn;for(let s=0,b=n.length;s<b;s+=3){const b=3*n[s],B=3*n[s+1],y=3*n[s+2];if(d[0]=e[b],d[1]=e[b+1],d[2]=e[b+2],f[0]=e[B],f[1]=e[B+1],f[2]=e[B+2],p[0]=e[y],p[1]=e[y+1],p[2]=e[y+2],V.decompressPosition(d,a),V.decompressPosition(f,a),V.decompressPosition(p,a),V.rayTriangleIntersect(h,u,d,f,p,_)){l.matrix&&V.transformPoint3(l.matrix,_,_),V.transformPoint3(i.worldMatrix,_,_),c&&V.addVec3(_,c),r&&V.addVec3(_,r);const e=Math.abs(V.lenVec3(V.subVec3(_,t,[])));(!g||e>m)&&(m=e,A.set(_),o&&V.triangleNormal(d,f,p,o),g=!0)}}return g&&o&&(l.normalMatrix&&V.transformVec3(l.normalMatrix,o,o),V.transformVec3(i.worldNormalMatrix,o,o),V.normalizeVec3(o)),g}return!1},layerTextureSet:o,renderers:Or(c,u?"instancing":"batching",A,i.saoEnabled,i.pbrEnabled&&S&&o&&o.colorTexture&&T&&w&&o.metallicRoughnessTexture,i.colorTextureEnabled&&S&&o&&o.colorTexture,!!T,(e=>xn(e,u&&{hasModelNormalMat:!!P},c.entityOffsetsEnabled))),drawCalls:function(){const e={},t=t=>(s,r,o)=>{let l=0;vn.set(i.rotationMatrix,0),vn.set(o.viewMatrix,l+=16),vn.set(o.projMatrix,l+=16),vn.set(a,l+=16),r.needNormal()&&(vn.set(i.worldNormalMatrix,l+=16),vn.set(o.viewNormalMatrix,l+=16)),r.matrices.setInputValue(vn),r.uvDecodeMatrix.setInputValue&&r.uvDecodeMatrix.setInputValue(S.mat),s in e||(e[s]=[null,null,null]);const c=e[s],f=t?t.vertices?0:1:2;if(!c[f]){const e=h.createVertexArray();h.bindVertexArray(e);const i=(e,t)=>{e&&e.setInputValue&&t&&e.setInputValue(t)},s=r.attributes;i(s.position,U),i(s.normal,T),i(s.color,B),i(s.pickColor,v),i(s.uV,S&&S.buf),i(s.metallicRoughness,w),i(s.flags,_),i(s.offset,y),s.modelMatrixCol&&s.modelMatrixCol.forEach(((e,t)=>i(e,x[t]))),s.modelNormalMatrixCol&&s.modelNormalMatrixCol.forEach(((e,t)=>i(e,P[t])));const o=function(){const e=()=>{u?h.drawArraysInstanced(h.POINTS,0,U.numItems,n.length):h.drawArrays(h.POINTS,0,U.numItems)},i=(e,t)=>{t.bindIndicesBuffer();const i=t.indicesCount,s=t.indicesType;return()=>{u?h.drawElementsInstanced(e,i,s,0,n.length):h.drawElements(e,i,s,0)}};return"points"===A?e:"lines"===A?t&&t.vertices?e:i(h.LINES,E):t&&t.vertices?e:t?C?i(h.LINES,C):()=>{}:i(h.TRIANGLES,E)}();h.bindVertexArray(null),d.push((()=>h.deleteVertexArray(e))),c[f]=()=>{h.bindVertexArray(e),o(),h.bindVertexArray(null)}}c[f]()};return{drawVertices:t({vertices:!0}),drawEdges:t({}),drawSurface:t(null)}}(),destroy:()=>{d.forEach((e=>e())),d.length=0}}}}const Un=function(e){const t={toString:()=>(t.needed=!0,e)};return t},xn=function(e,t,i){const s=e.createAttribute,r={position:s("vec3","positionA"),normal:s("vec3","normalA"),color:s("vec4","colorA"),pickColor:s("vec4","pickColor"),uV:s("vec2","uvApremul"),metallicRoughness:s("vec2","metallicRoughness"),flags:s("float","flagsA"),offset:i&&s("vec3","offset"),modelMatrixCol:t&&Cn(3).map((e=>s("vec4","modelMatrixCol"+e))),modelNormalMatrixCol:t&&t.hasModelNormalMat&&Cn(3).map((e=>s("vec4","modelNormalMatrixCol"+e)))},n=Un("aUv"),A=Un("viewNormal"),o=Un("worldNormal"),a=e.createUniform("mat3","uvDecodeMatrix"),l=()=>A.needed||o.needed,c=e.createUniformBlock("Matrices",{worldMatrix:"mat4",viewMatrix:"mat4",projMatrix:"mat4",positionsDecodeMatrix:"mat4",worldNormalMatrix:"mat4",viewNormalMatrix:"mat4"});return{dontCullOnAlphaZero:!0,clippableTest:function(){const t=e.createVarying("float","vClippable",(()=>`((int(${r.flags}) >> 16 & 0xF) == 1) ? 1.0 : 0.0`));return()=>`${t} != 0.0`}(),geometryParameters:{attributes:{color:r.color,flags:Cn(4).map((e=>({toString:()=>`(int(${r.flags}) >> ${4*e} & 0xF)`}))),metallicRoughness:r.metallicRoughness,normal:{view:A,world:o},pickColor:r.pickColor,position:{clip:"gl_Position",view:"viewPosition",world:"worldPosition"},uv:n},projMatrix:c.projMatrix,viewMatrix:c.viewMatrix},appendVertexData:t=>{n.needed&&t.push(`vec2 ${n} = (${a} * vec3(${r.uV}, 1.0)).xy;`);const i=r.modelMatrixCol&&`mat4(${r.modelMatrixCol[0]}, ${r.modelMatrixCol[1]}, ${r.modelMatrixCol[2]}, vec4(0.0,0.0,0.0,1.0))`;if(t.push(`vec4 worldPosition = ${c.worldMatrix} * (${c.positionsDecodeMatrix} * vec4(${r.position}, 1.0)${i?" * "+i:""});`),r.offset&&t.push(`worldPosition.xyz = worldPosition.xyz + ${r.offset};`),l()){const i=r.modelNormalMatrixCol&&`* mat4(${r.modelNormalMatrixCol[0]}, ${r.modelNormalMatrixCol[1]}, ${r.modelNormalMatrixCol[2]}, vec4(0.0,0.0,0.0,1.0))`;t.push(`vec4 modelNormal = vec4(${e.commonLibrary.octDecode}(${r.normal}.xy), 0.0)${i||""};`),t.push(`vec3 ${o} = (${c.worldNormalMatrix} * modelNormal).xyz;`),A.needed&&t.push(`vec3 ${A} = normalize((${c.viewNormalMatrix} * vec4(${o}, 0.0)).xyz);`)}},layerTypeInputs:{attributes:r,matrices:c,uvDecodeMatrix:a,needNormal:l}}};class In{constructor(e){this.id=e.id,this.colorTexture=e.colorTexture,this.alphaCutoff=e.alphaCutoff,this.metallicRoughnessTexture=e.metallicRoughnessTexture,this.normalsTexture=e.normalsTexture,this.emissiveTexture=e.emissiveTexture,this.occlusionTexture=e.occlusionTexture}destroy(){}}class Tn{constructor(e){this.id=e.id,this.texture=e.texture}destroy(){this.texture&&(this.texture.destroy(),this.texture=null)}}const Pn={enabled:!1,files:{},add:function(e,t){!1!==this.enabled&&(this.files[e]=t)},get:function(e){if(!1!==this.enabled)return this.files[e]},remove:function(e){delete this.files[e]},clear:function(){this.files={}}};class Sn{constructor(e,t,i){this.isLoading=!1,this.itemsLoaded=0,this.itemsTotal=0,this.urlModifier=void 0,this.handlers=[],this.onStart=void 0,this.onLoad=e,this.onProgress=t,this.onError=i}itemStart(e){this.itemsTotal++,!1===this.isLoading&&void 0!==this.onStart&&this.onStart(e,this.itemsLoaded,this.itemsTotal),this.isLoading=!0}itemEnd(e){this.itemsLoaded++,void 0!==this.onProgress&&this.onProgress(e,this.itemsLoaded,this.itemsTotal),this.itemsLoaded===this.itemsTotal&&(this.isLoading=!1,void 0!==this.onLoad&&this.onLoad())}itemError(e){void 0!==this.onError&&this.onError(e)}resolveURL(e){return this.urlModifier?this.urlModifier(e):e}setURLModifier(e){return this.urlModifier=e,this}addHandler(e,t){return this.handlers.push(e,t),this}removeHandler(e){const t=this.handlers.indexOf(e);return-1!==t&&this.handlers.splice(t,2),this}getHandler(e){for(let t=0,i=this.handlers.length;t<i;t+=2){const i=this.handlers[t],s=this.handlers[t+1];if(i.global&&(i.lastIndex=0),i.test(e))return s}return null}}const Dn=new Sn;class kn{constructor(e){this.manager=void 0!==e?e:Dn,this.crossOrigin="anonymous",this.withCredentials=!1,this.path="",this.resourcePath="",this.requestHeader={}}load(){}loadAsync(e,t){const i=this;return new Promise((function(s,r){i.load(e,s,t,r)}))}parse(){}setCrossOrigin(e){return this.crossOrigin=e,this}setWithCredentials(e){return this.withCredentials=e,this}setPath(e){return this.path=e,this}setResourcePath(e){return this.resourcePath=e,this}setRequestHeader(e){return this.requestHeader=e,this}}const Qn={};class Rn extends kn{constructor(e){super(e)}load(e,t,i,s){void 0===e&&(e=""),void 0!==this.path&&(e=this.path+e),e=this.manager.resolveURL(e);const r=Pn.get(e);if(void 0!==r)return this.manager.itemStart(e),ie.scheduleTask((()=>{t&&t(r),this.manager.itemEnd(e)}),0),r;if(void 0!==Qn[e])return void Qn[e].push({onLoad:t,onProgress:i,onError:s});Qn[e]=[],Qn[e].push({onLoad:t,onProgress:i,onError:s});const n=new Request(e,{headers:new Headers(this.requestHeader),credentials:this.withCredentials?"include":"same-origin"}),A=this.mimeType,o=this.responseType;fetch(n).then((t=>{if(200===t.status||0===t.status){if(0===t.status&&console.warn("FileLoader: HTTP Status 0 received."),"undefined"==typeof ReadableStream||void 0===t.body.getReader)return t;const i=Qn[e],s=t.body.getReader(),r=t.headers.get("Content-Length"),n=r?parseInt(r):0,A=0!==n;let o=0;const a=new ReadableStream({start(e){!function t(){s.read().then((({done:s,value:r})=>{if(s)e.close();else{o+=r.byteLength;const s=new ProgressEvent("progress",{lengthComputable:A,loaded:o,total:n});for(let e=0,t=i.length;e<t;e++){const t=i[e];t.onProgress&&t.onProgress(s)}e.enqueue(r),t()}}))}()}});return new Response(a)}throw Error(`fetch for "${t.url}" responded with ${t.status}: ${t.statusText}`)})).then((e=>{switch(o){case"arraybuffer":return e.arrayBuffer();case"blob":return e.blob();case"document":return e.text().then((e=>(new DOMParser).parseFromString(e,A)));case"json":return e.json();default:if(void 0===A)return e.text();{const t=/charset="?([^;"\s]*)"?/i.exec(A),i=t&&t[1]?t[1].toLowerCase():void 0,s=new TextDecoder(i);return e.arrayBuffer().then((e=>s.decode(e)))}}})).then((t=>{Pn.add(e,t);const i=Qn[e];delete Qn[e];for(let e=0,s=i.length;e<s;e++){const s=i[e];s.onLoad&&s.onLoad(t)}})).catch((t=>{const i=Qn[e];if(void 0===i)throw this.manager.itemError(e),t;delete Qn[e];for(let e=0,s=i.length;e<s;e++){const s=i[e];s.onError&&s.onError(t)}this.manager.itemError(e)})).finally((()=>{this.manager.itemEnd(e)})),this.manager.itemStart(e)}setResponseType(e){return this.responseType=e,this}setMimeType(e){return this.mimeType=e,this}}class On{constructor(e=4){this.pool=e,this.queue=[],this.workers=[],this.workersResolve=[],this.workerStatus=0}_initWorker(e){if(!this.workers[e]){const t=this.workerCreator();t.addEventListener("message",this._onMessage.bind(this,e)),this.workers[e]=t}}_getIdleWorker(){for(let e=0;e<this.pool;e++)if(!(this.workerStatus&1<<e))return e;return-1}_onMessage(e,t){const i=this.workersResolve[e];if(i&&i(t),this.queue.length){const{resolve:t,msg:i,transfer:s}=this.queue.shift();this.workersResolve[e]=t,this.workers[e].postMessage(i,s)}else this.workerStatus^=1<<e}setWorkerCreator(e){this.workerCreator=e}setWorkerLimit(e){this.pool=e}postMessage(e,t){return new Promise((i=>{const s=this._getIdleWorker();-1!==s?(this._initWorker(s),this.workerStatus|=1<<s,this.workersResolve[s]=i,this.workers[s].postMessage(e,t)):this.queue.push({resolve:i,msg:e,transfer:t})}))}destroy(){this.workers.forEach((e=>e.terminate())),this.workersResolve.length=0,this.workers.length=0,this.queue.length=0,this.workerStatus=0}}let Vn=0;class Ln{constructor({viewer:e,transcoderPath:t,workerLimit:i}){this._transcoderPath=t||"https://cdn.jsdelivr.net/npm/@xeokit/xeokit-sdk/dist/basis/",this._transcoderBinary=null,this._transcoderPending=null,this._workerPool=new On,this._workerSourceURL="",i&&this._workerPool.setWorkerLimit(i);const s=e.capabilities;this._workerConfig={astcSupported:s.astcSupported,etc1Supported:s.etc1Supported,etc2Supported:s.etc2Supported,dxtSupported:s.dxtSupported,bptcSupported:s.bptcSupported,pvrtcSupported:s.pvrtcSupported},this._supportedFileTypes=["xkt2"]}_init(){if(!this._transcoderPending){const e=new Rn;e.setPath(this._transcoderPath),e.setWithCredentials(this.withCredentials);const t=e.loadAsync("basis_transcoder.js"),i=new Rn;i.setPath(this._transcoderPath),i.setResponseType("arraybuffer"),i.setWithCredentials(this.withCredentials);const s=i.loadAsync("basis_transcoder.wasm");this._transcoderPending=Promise.all([t,s]).then((([e,t])=>{const i=Ln.BasisWorker.toString(),s=["/* constants */","let _EngineFormat = "+JSON.stringify(Ln.EngineFormat),"let _TranscoderFormat = "+JSON.stringify(Ln.TranscoderFormat),"let _BasisFormat = "+JSON.stringify(Ln.BasisFormat),"/* basis_transcoder.js */",e,"/* worker */",i.substring(i.indexOf("{")+1,i.lastIndexOf("}"))].join("\n");this._workerSourceURL=URL.createObjectURL(new Blob([s])),this._transcoderBinary=t,this._workerPool.setWorkerCreator((()=>{const e=new Worker(this._workerSourceURL),t=this._transcoderBinary.slice(0);return e.postMessage({type:"init",config:this._workerConfig,transcoderBinary:t},[t]),e}))})),Vn>0&&console.warn("KTX2TextureTranscoder: Multiple active KTX2TextureTranscoder may cause performance issues. Use a single KTX2TextureTranscoder instance, or call .dispose() on old instances."),Vn++}return this._transcoderPending}transcode(e,t,i={}){return new Promise(((s,r)=>{const n=i;this._init().then((()=>this._workerPool.postMessage({type:"transcode",buffers:e,taskConfig:n},e))).then((e=>{const i=e.data,{mipmaps:n,width:A,height:o,format:a,type:l,error:c,dfdTransferFn:h,dfdFlags:u}=i;if("error"===l)return r(c);t.setCompressedData({mipmaps:n,props:{format:a,minFilter:1===n.length?1006:1008,magFilter:1===n.length?1006:1008,encoding:2===h?3001:3e3,premultiplyAlpha:!!(1&u)}}),s()}))}))}destroy(){URL.revokeObjectURL(this._workerSourceURL),this._workerPool.destroy(),Vn--}}Ln.BasisFormat={ETC1S:0,UASTC_4x4:1},Ln.TranscoderFormat={ETC1:0,ETC2:1,BC1:2,BC3:3,BC4:4,BC5:5,BC7_M6_OPAQUE_ONLY:6,BC7_M5:7,PVRTC1_4_RGB:8,PVRTC1_4_RGBA:9,ASTC_4x4:10,ATC_RGB:11,ATC_RGBA_INTERPOLATED_ALPHA:12,RGBA32:13,RGB565:14,BGR565:15,RGBA4444:16},Ln.EngineFormat={RGBAFormat:1023,RGBA_ASTC_4x4_Format:37808,RGBA_BPTC_Format:36492,RGBA_ETC2_EAC_Format:37496,RGBA_PVRTC_4BPPV1_Format:35842,RGBA_S3TC_DXT5_Format:33779,RGB_ETC1_Format:36196,RGB_ETC2_Format:37492,RGB_PVRTC_4BPPV1_Format:35840,RGB_S3TC_DXT1_Format:33776},Ln.BasisWorker=function(){let e,t,i;const s=_EngineFormat,r=_TranscoderFormat,n=_BasisFormat;self.addEventListener("message",(function(A){const c=A.data;switch(c.type){case"init":e=c.config,h=c.transcoderBinary,t=new Promise((e=>{i={wasmBinary:h,onRuntimeInitialized:e},BASIS(i)})).then((()=>{i.initializeBasis(),void 0===i.KTX2File&&console.warn("KTX2TextureTranscoder: Please update Basis Universal transcoder.")}));break;case"transcode":t.then((()=>{try{const{width:t,height:A,hasAlpha:h,mipmaps:u,format:d,dfdTransferFn:f,dfdFlags:p}=function(t){const A=new i.KTX2File(new Uint8Array(t));function c(){A.close(),A.delete()}if(!A.isValid())throw c(),new Error("KTX2TextureTranscoder: Invalid or unsupported .ktx2 file");const h=A.isUASTC()?n.UASTC_4x4:n.ETC1S,u=A.getWidth(),d=A.getHeight(),f=A.getLevels(),p=A.getHasAlpha(),g=A.getDFDTransferFunc(),m=A.getDFDFlags(),{transcoderFormat:_,engineFormat:b}=function(t,i,A,c){let h,u;const d=t===n.ETC1S?o:a;for(let s=0;s<d.length;s++){const r=d[s];if(e[r.if]&&(r.basisFormat.includes(t)&&!(c&&r.transcoderFormat.length<2)&&(!r.needsPowerOfTwo||l(i)&&l(A))))return h=r.transcoderFormat[c?1:0],u=r.engineFormat[c?1:0],{transcoderFormat:h,engineFormat:u}}return console.warn("KTX2TextureTranscoder: No suitable compressed texture format found. Decoding to RGBA32."),h=r.RGBA32,u=s.RGBAFormat,{transcoderFormat:h,engineFormat:u}}(h,u,d,p);if(!u||!d||!f)throw c(),new Error("KTX2TextureTranscoder: Invalid texture");if(!A.startTranscoding())throw c(),new Error("KTX2TextureTranscoder: .startTranscoding failed");const B=[];for(let e=0;e<f;e++){const t=A.getImageLevelInfo(e,0,0),i=t.origWidth,s=t.origHeight,r=new Uint8Array(A.getImageTranscodedSizeInBytes(e,0,0,_));if(!A.transcodeImage(r,e,0,0,_,0,-1,-1))throw c(),new Error("KTX2TextureTranscoder: .transcodeImage failed.");B.push({data:r,width:i,height:s})}return c(),{width:u,height:d,hasAlpha:p,mipmaps:B,format:b,dfdTransferFn:g,dfdFlags:m}}(c.buffers[0]),g=[];for(let e=0;e<u.length;++e)g.push(u[e].data.buffer);self.postMessage({type:"transcode",id:c.id,width:t,height:A,hasAlpha:h,mipmaps:u,format:d,dfdTransferFn:f,dfdFlags:p},g)}catch(e){console.error(`[KTX2TextureTranscoder.BasisWorker]: ${e}`),self.postMessage({type:"error",id:c.id,error:e.message})}}))}var h}));const A=[{if:"astcSupported",basisFormat:[n.UASTC_4x4],transcoderFormat:[r.ASTC_4x4,r.ASTC_4x4],engineFormat:[s.RGBA_ASTC_4x4_Format,s.RGBA_ASTC_4x4_Format],priorityETC1S:1/0,priorityUASTC:1,needsPowerOfTwo:!1},{if:"bptcSupported",basisFormat:[n.ETC1S,n.UASTC_4x4],transcoderFormat:[r.BC7_M5,r.BC7_M5],engineFormat:[s.RGBA_BPTC_Format,s.RGBA_BPTC_Format],priorityETC1S:3,priorityUASTC:2,needsPowerOfTwo:!1},{if:"dxtSupported",basisFormat:[n.ETC1S,n.UASTC_4x4],transcoderFormat:[r.BC1,r.BC3],engineFormat:[s.RGB_S3TC_DXT1_Format,s.RGBA_S3TC_DXT5_Format],priorityETC1S:4,priorityUASTC:5,needsPowerOfTwo:!1},{if:"etc2Supported",basisFormat:[n.ETC1S,n.UASTC_4x4],transcoderFormat:[r.ETC1,r.ETC2],engineFormat:[s.RGB_ETC2_Format,s.RGBA_ETC2_EAC_Format],priorityETC1S:1,priorityUASTC:3,needsPowerOfTwo:!1},{if:"etc1Supported",basisFormat:[n.ETC1S,n.UASTC_4x4],transcoderFormat:[r.ETC1],engineFormat:[s.RGB_ETC1_Format],priorityETC1S:2,priorityUASTC:4,needsPowerOfTwo:!1},{if:"pvrtcSupported",basisFormat:[n.ETC1S,n.UASTC_4x4],transcoderFormat:[r.PVRTC1_4_RGB,r.PVRTC1_4_RGBA],engineFormat:[s.RGB_PVRTC_4BPPV1_Format,s.RGBA_PVRTC_4BPPV1_Format],priorityETC1S:5,priorityUASTC:6,needsPowerOfTwo:!0}],o=A.sort((function(e,t){return e.priorityETC1S-t.priorityETC1S})),a=A.sort((function(e,t){return e.priorityUASTC-t.priorityUASTC}));function l(e){return e<=2||0==(e&e-1)&&0!==e}};const Hn={};function Nn(e){const t=e.scene.id;let i=Hn[t];return i||(i=new Ln({viewer:e}),Hn[t]=i,e.scene.on("destroyed",(()=>{delete Hn[t],i.destroy()}))),i}
7
+ "undefined"!=typeof window&&(window.__XEOKIT__={version:"2.6.98",commit:"30ac0fa9a4eaf6759fe306bb2e332cce49884787",built:"2025-12-08T14:34:05.193Z"});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 n{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 n=this._getNextId(),A=new i(n);for(let i=0,n=e.length;i<n;i++){const n=e[i],o=new s;A.groups.push(o);for(let e=0,i=n.length;e<i;e++){const i=n[e],s=i.items,a=s&&s.length>0,l=this._getNextId(),c=i.getTitle||(()=>i.title||""),h=i.doAction||i.callback||(()=>{}),u=i.getEnabled||(()=>!0),d=i.getShown||(()=>!0),f=new r(l,c,h,u,d);if(f.parentMenu=A,o.items.push(f),a){const e=t(s);f.subMenu=e,e.parentItem=f}this._itemList.push(f),this._itemMap[f.id]=f}}return this._menuList.push(A),this._menuMap[A.id]=A,A};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,n=s,A=t[e].items;if(A)for(let e=0,t=A.length;e<t;e++){const s=A[e],o=s.subMenu,a=s.title||"";o?(i.push('<li id="'+s.id+'" class="xeokit-context-menu-item xeokit-context-menu-submenu">'+a+"</li>"),r===n-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">'+a+"</li>"),r===n-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 n=this;let A=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(A&&(n._hideMenu(A.id),A=null));if(A&&A.id!==i.id&&(n._hideMenu(A.id),A=null),!1===t.enabled)return;const s=t.itemElement,r=i.menuElement,o=s.getBoundingClientRect();r.getBoundingClientRect();const a=n._offsetParent.getBoundingClientRect(),l=200,c=o.right+l<a.right,h=o.left-l>a.left;if(c)n._showMenu(i.id,o.right+window.scrollX-5,o.top+window.scrollY-1);else if(h)n._showMenu(i.id,o.left-l+window.scrollX,o.top+window.scrollY-1);else{const e=o.left-a.left,t=a.right-o.right;t>e?n._showMenu(i.id,o.right-5-(l-t),o.top+window.scrollY-1):n._showMenu(i.id,o.left-e,o.top+window.scrollY-1)}A=i})),s||(t.itemElement.addEventListener("click",(e=>{e.preventDefault(),n._context&&!1!==t.enabled&&(t.doAction&&t.doAction(n._context),this._hideOnAction?n.hide():(n._updateItemsTitles(),n._updateItemsEnabledStatus()))})),t.itemElement.addEventListener("mouseup",(e=>{3===e.which&&(e.preventDefault(),n._context&&!1!==t.enabled&&(t.doAction&&t.doAction(n._context),this._hideOnAction?n.hide():(n._updateItemsTitles(),n._updateItemsEnabledStatus())))})),t.itemElement.addEventListener("mouseenter",(e=>{e.preventDefault(),!1!==t.enabled&&t.doHover&&t.doHover(n._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 n=r(this._context);if(t.shown=n,!n){i.style.display="none";continue}i.style.display="";const A=s(this._context);t.enabled=A,A?i.classList.remove("disabled"):i.classList.add("disabled")}}_updateSubMenuInfo(){if(!this._context)return;let e,t,i,s,r,n;this._itemList.forEach((A=>{A.subMenu&&(e=A.itemElement,t=e.getBoundingClientRect(),i=A.subMenu.menuElement,s={visibility:i.style.visibility,display:i.style.display},i.style.display="block",i.style.visibility="hidden",n=A.subMenu.menuElement.getBoundingClientRect().width,i.style.visibility=s.visibility,i.style.display=s.display,r=t.right+n>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,n=this._offsetParent.getBoundingClientRect(),A=this._offsetParent===window.document.body&&0===n.bottom?window.innerHeight:n.bottom+window.scrollY,o=n.right+window.scrollX;i+s>A&&(i=A-s),t+r>o&&(t=o-r),e.style.left=t-n.left-window.scrollX+"px",e.style.top=i-n.top-window.scrollY+"px"}_hideMenuElement(e){e.style.display="none"}}class A{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,n=this._snappedCanvasPos?this._snappedCanvasPos[0]-this._canvasPos[0]:0,A=this._snappedCanvasPos?this._snappedCanvasPos[1]-this._canvasPos[1]:0;this._lensCursorDiv.style.left=`${r+n*this._zoomLevel}px`,this._lensCursorDiv.style.top=`${r+A*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)}}function o(e,t,i=2){const s=t&&t.length,r=s?t[0]*i:e.length;let n=a(e,0,r,i,!0);const A=[];if(!n||n.next===n.prev)return A;let o,l,h;if(s&&(n=function(e,t,i,s){const r=[];for(let i=0,n=t.length;i<n;i++){const A=a(e,t[i]*s,i<n-1?t[i+1]*s:e.length,s,!1);A===A.next&&(A.steiner=!0),r.push(b(A))}r.sort(p);for(let e=0;e<r.length;e++)i=g(r[e],i);return i}(e,t,n,i)),e.length>80*i){o=1/0,l=1/0;let t=-1/0,s=-1/0;for(let n=i;n<r;n+=i){const i=e[n],r=e[n+1];i<o&&(o=i),r<l&&(l=r),i>t&&(t=i),r>s&&(s=r)}h=Math.max(t-o,s-l),h=0!==h?32767/h:0}return c(n,A,i,o,l,h,0),A}function a(e,t,i,s,r){let n;if(r===function(e,t,i,s){let r=0;for(let n=t,A=i-s;n<i;n+=s)r+=(e[A]-e[n])*(e[n+1]+e[A+1]),A=n;return r}(e,t,i,s)>0)for(let r=t;r<i;r+=s)n=I(r/s|0,e[r],e[r+1],n);else for(let r=i-s;r>=t;r-=s)n=I(r/s|0,e[r],e[r+1],n);return n&&C(n,n.next)&&(T(n),n=n.next),n}function l(e,t){if(!e)return e;t||(t=e);let i,s=e;do{if(i=!1,s.steiner||!C(s,s.next)&&0!==v(s.prev,s,s.next))s=s.next;else{if(T(s),s=t=s.prev,s===s.next)break;i=!0}}while(i||s!==t);return t}function c(e,t,i,s,r,n,A){if(!e)return;!A&&n&&function(e,t,i,s){let r=e;do{0===r.z&&(r.z=_(r.x,r.y,t,i,s)),r.prevZ=r.prev,r.nextZ=r.next,r=r.next}while(r!==e);r.prevZ.nextZ=null,r.prevZ=null,function(e){let t,i=1;do{let s,r=e;e=null;let n=null;for(t=0;r;){t++;let A=r,o=0;for(let e=0;e<i&&(o++,A=A.nextZ,A);e++);let a=i;for(;o>0||a>0&&A;)0!==o&&(0===a||!A||r.z<=A.z)?(s=r,r=r.nextZ,o--):(s=A,A=A.nextZ,a--),n?n.nextZ=s:e=s,s.prevZ=n,n=s;r=A}n.nextZ=null,i*=2}while(t>1)}(r)}(e,s,r,n);let o=e;for(;e.prev!==e.next;){const a=e.prev,p=e.next;if(n?u(e,s,r,n):h(e))t.push(a.i,e.i,p.i),T(e),e=p.next,o=p.next;else if((e=p)===o){A?1===A?c(e=d(l(e),t),t,i,s,r,n,2):2===A&&f(e,t,i,s,r,n):c(l(e),t,i,s,r,n,1);break}}}function h(e){const t=e.prev,i=e,s=e.next;if(v(t,i,s)>=0)return!1;const r=t.x,n=i.x,A=s.x,o=t.y,a=i.y,l=s.y,c=Math.min(r,n,A),h=Math.min(o,a,l),u=Math.max(r,n,A),d=Math.max(o,a,l);let f=s.next;for(;f!==t;){if(f.x>=c&&f.x<=u&&f.y>=h&&f.y<=d&&y(r,o,n,a,A,l,f.x,f.y)&&v(f.prev,f,f.next)>=0)return!1;f=f.next}return!0}function u(e,t,i,s){const r=e.prev,n=e,A=e.next;if(v(r,n,A)>=0)return!1;const o=r.x,a=n.x,l=A.x,c=r.y,h=n.y,u=A.y,d=Math.min(o,a,l),f=Math.min(c,h,u),p=Math.max(o,a,l),g=Math.max(c,h,u),m=_(d,f,t,i,s),b=_(p,g,t,i,s);let B=e.prevZ,w=e.nextZ;for(;B&&B.z>=m&&w&&w.z<=b;){if(B.x>=d&&B.x<=p&&B.y>=f&&B.y<=g&&B!==r&&B!==A&&y(o,c,a,h,l,u,B.x,B.y)&&v(B.prev,B,B.next)>=0)return!1;if(B=B.prevZ,w.x>=d&&w.x<=p&&w.y>=f&&w.y<=g&&w!==r&&w!==A&&y(o,c,a,h,l,u,w.x,w.y)&&v(w.prev,w,w.next)>=0)return!1;w=w.nextZ}for(;B&&B.z>=m;){if(B.x>=d&&B.x<=p&&B.y>=f&&B.y<=g&&B!==r&&B!==A&&y(o,c,a,h,l,u,B.x,B.y)&&v(B.prev,B,B.next)>=0)return!1;B=B.prevZ}for(;w&&w.z<=b;){if(w.x>=d&&w.x<=p&&w.y>=f&&w.y<=g&&w!==r&&w!==A&&y(o,c,a,h,l,u,w.x,w.y)&&v(w.prev,w,w.next)>=0)return!1;w=w.nextZ}return!0}function d(e,t){let i=e;do{const s=i.prev,r=i.next.next;!C(s,r)&&M(s,i,i.next,r)&&U(s,r)&&U(r,s)&&(t.push(s.i,i.i,r.i),T(i),T(i.next),i=e=r),i=i.next}while(i!==e);return l(i)}function f(e,t,i,s,r,n){let A=e;do{let e=A.next.next;for(;e!==A.prev;){if(A.i!==e.i&&w(A,e)){let o=x(A,e);return A=l(A,A.next),o=l(o,o.next),c(A,t,i,s,r,n,0),void c(o,t,i,s,r,n,0)}e=e.next}A=A.next}while(A!==e)}function p(e,t){let i=e.x-t.x;if(0===i&&(i=e.y-t.y,0===i)){i=(e.next.y-e.y)/(e.next.x-e.x)-(t.next.y-t.y)/(t.next.x-t.x)}return i}function g(e,t){const i=function(e,t){let i=t;const s=e.x,r=e.y;let n,A=-1/0;if(C(e,i))return i;do{if(C(e,i.next))return i.next;if(r<=i.y&&r>=i.next.y&&i.next.y!==i.y){const e=i.x+(r-i.y)*(i.next.x-i.x)/(i.next.y-i.y);if(e<=s&&e>A&&(A=e,n=i.x<i.next.x?i:i.next,e===s))return n}i=i.next}while(i!==t);if(!n)return null;const o=n,a=n.x,l=n.y;let c=1/0;i=n;do{if(s>=i.x&&i.x>=a&&s!==i.x&&B(r<l?s:A,r,a,l,r<l?A:s,r,i.x,i.y)){const t=Math.abs(r-i.y)/(s-i.x);U(i,e)&&(t<c||t===c&&(i.x>n.x||i.x===n.x&&m(n,i)))&&(n=i,c=t)}i=i.next}while(i!==o);return n}(e,t);if(!i)return t;const s=x(i,e);return l(s,s.next),l(i,i.next)}function m(e,t){return v(e.prev,e,t.prev)<0&&v(t.next,e,e.next)<0}function _(e,t,i,s,r){return(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=(e-i)*r|0)|e<<8))|e<<4))|e<<2))|e<<1))|(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=(t-s)*r|0)|t<<8))|t<<4))|t<<2))|t<<1))<<1}function b(e){let t=e,i=e;do{(t.x<i.x||t.x===i.x&&t.y<i.y)&&(i=t),t=t.next}while(t!==e);return i}function B(e,t,i,s,r,n,A,o){return(r-A)*(t-o)>=(e-A)*(n-o)&&(e-A)*(s-o)>=(i-A)*(t-o)&&(i-A)*(n-o)>=(r-A)*(s-o)}function y(e,t,i,s,r,n,A,o){return!(e===A&&t===o)&&B(e,t,i,s,r,n,A,o)}function w(e,t){return e.next.i!==t.i&&e.prev.i!==t.i&&!function(e,t){let i=e;do{if(i.i!==e.i&&i.next.i!==e.i&&i.i!==t.i&&i.next.i!==t.i&&M(i,i.next,e,t))return!0;i=i.next}while(i!==e);return!1}(e,t)&&(U(e,t)&&U(t,e)&&function(e,t){let i=e,s=!1;const r=(e.x+t.x)/2,n=(e.y+t.y)/2;do{i.y>n!=i.next.y>n&&i.next.y!==i.y&&r<(i.next.x-i.x)*(n-i.y)/(i.next.y-i.y)+i.x&&(s=!s),i=i.next}while(i!==e);return s}(e,t)&&(v(e.prev,e,t.prev)||v(e,t.prev,t))||C(e,t)&&v(e.prev,e,e.next)>0&&v(t.prev,t,t.next)>0)}function v(e,t,i){return(t.y-e.y)*(i.x-t.x)-(t.x-e.x)*(i.y-t.y)}function C(e,t){return e.x===t.x&&e.y===t.y}function M(e,t,i,s){const r=F(v(e,t,i)),n=F(v(e,t,s)),A=F(v(i,s,e)),o=F(v(i,s,t));return r!==n&&A!==o||(!(0!==r||!E(e,i,t))||(!(0!==n||!E(e,s,t))||(!(0!==A||!E(i,e,s))||!(0!==o||!E(i,t,s)))))}function E(e,t,i){return t.x<=Math.max(e.x,i.x)&&t.x>=Math.min(e.x,i.x)&&t.y<=Math.max(e.y,i.y)&&t.y>=Math.min(e.y,i.y)}function F(e){return e>0?1:e<0?-1:0}function U(e,t){return v(e.prev,e,e.next)<0?v(e,t,e.next)>=0&&v(e,e.prev,t)>=0:v(e,t,e.prev)<0||v(e,e.next,t)<0}function x(e,t){const i=P(e.i,e.x,e.y),s=P(t.i,t.x,t.y),r=e.next,n=t.prev;return e.next=t,t.prev=e,i.next=r,r.prev=i,s.next=i,i.prev=s,n.next=s,s.prev=n,s}function I(e,t,i,s){const r=P(e,t,i);return s?(r.next=s.next,r.prev=s,s.next.prev=r,s.next=r):(r.prev=r,r.next=r),r}function T(e){e.next.prev=e.prev,e.prev.next=e.next,e.prevZ&&(e.prevZ.nextZ=e.nextZ),e.nextZ&&(e.nextZ.prevZ=e.prevZ)}function P(e,t,i){return{i:e,x:t,y:i,prev:null,next:null,z:0,prevZ:null,nextZ:null,steiner:!1}}let S=!0,D=S?Float64Array:Float32Array;const k=new D(3),Q=new D(16),R=new D(16),O=new D(4),V={setDoublePrecisionEnabled(e){S=e,D=S?Float64Array:Float32Array},getDoublePrecisionEnabled:()=>S,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 D(e||2),vec3:e=>new D(e||3),vec4:e=>new D(e||4),mat3:e=>new D(e||9),mat3ToMat4:(e,t=new D(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 D(e||16),mat4ToMat3:(e,t=new D(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 D(2);for(let r=0,n=e.length;r<n;r++)V.splitDouble(e[r],s),t[r]=s[0],i[r]=s[1]},splitDouble(e,t){const i=D.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 D(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],n=t[0],A=t[1],o=t[2];return[s*o-r*A,r*n-i*o,i*A-s*n,0]},cross3Vec3(e,t,i){i||(i=e);const s=e[0],r=e[1],n=e[2],A=t[0],o=t[1],a=t[2];return i[0]=r*a-n*o,i[1]=n*A-s*a,i[2]=s*o-r*A,i},sqLenVec4:e=>V.dotVec4(e,e),lenVec4:e=>Math.sqrt(V.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=>V.dotVec3(e,e),sqLenVec2:e=>V.dotVec2(e,e),lenVec3:e=>Math.sqrt(V.sqLenVec3(e)),distVec3:(()=>{const e=new D(3);return(t,i)=>V.lenVec3(V.subVec3(t,i,e))})(),lenVec2:e=>Math.sqrt(V.sqLenVec2(e)),distVec2:(()=>{const e=new D(2);return(t,i)=>V.lenVec2(V.subVec2(t,i,e))})(),rcpVec3:(e,t)=>V.divScalarVec3(1,e,t),normalizeVec4(e,t){const i=1/V.lenVec4(e);return V.mulVec4Scalar(e,i,t)},normalizeVec3(e,t){const i=1/V.lenVec3(e);return V.mulVec3Scalar(e,i,t)},normalizeVec2(e,t){const i=1/V.lenVec2(e);return V.mulVec2Scalar(e,i,t)},angleVec3(e,t){let i=V.dotVec3(e,t)/Math.sqrt(V.sqLenVec3(e)*V.sqLenVec3(t));return i=i<-1?-1:i>1?1:i,Math.acos(i)},vec3FromMat4Scale:(()=>{const e=new D(3);return(t,i)=>(e[0]=t[0],e[1]=t[1],e[2]=t[2],i[0]=V.lenVec3(e),e[0]=t[4],e[1]=t[5],e[2]=t[6],i[1]=V.lenVec3(e),e[0]=t[8],e[1]=t[9],e[2]=t[10],i[2]=V.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||V.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:()=>V.m4s(0),setMat4ToOnes:()=>V.m4s(1),diagonalMat4v:e=>new D([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)=>V.diagonalMat4v([e,t,i,s]),diagonalMat4s:e=>V.diagonalMat4c(e,e,e,e),identityMat4:(e=new D(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 D(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)=>V.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],n=e[2],A=e[3],o=e[4],a=e[5],l=e[6],c=e[7],h=e[8],u=e[9],d=e[10],f=e[11],p=e[12],g=e[13],m=e[14],_=e[15],b=t[0],B=t[1],y=t[2],w=t[3],v=t[4],C=t[5],M=t[6],E=t[7],F=t[8],U=t[9],x=t[10],I=t[11],T=t[12],P=t[13],S=t[14],D=t[15];return i[0]=b*s+B*o+y*h+w*p,i[1]=b*r+B*a+y*u+w*g,i[2]=b*n+B*l+y*d+w*m,i[3]=b*A+B*c+y*f+w*_,i[4]=v*s+C*o+M*h+E*p,i[5]=v*r+C*a+M*u+E*g,i[6]=v*n+C*l+M*d+E*m,i[7]=v*A+C*c+M*f+E*_,i[8]=F*s+U*o+x*h+I*p,i[9]=F*r+U*a+x*u+I*g,i[10]=F*n+U*l+x*d+I*m,i[11]=F*A+U*c+x*f+I*_,i[12]=T*s+P*o+S*h+D*p,i[13]=T*r+P*a+S*u+D*g,i[14]=T*n+P*l+S*d+D*m,i[15]=T*A+P*c+S*f+D*_,i},mulMat3(e,t,i){i||(i=new D(9));const s=e[0],r=e[3],n=e[6],A=e[1],o=e[4],a=e[7],l=e[2],c=e[5],h=e[8],u=t[0],d=t[3],f=t[6],p=t[1],g=t[4],m=t[7],_=t[2],b=t[5],B=t[8];return i[0]=s*u+r*p+n*_,i[3]=s*d+r*g+n*b,i[6]=s*f+r*m+n*B,i[1]=A*u+o*p+a*_,i[4]=A*d+o*g+a*b,i[7]=A*f+o*m+a*B,i[2]=l*u+c*p+h*_,i[5]=l*d+c*g+h*b,i[8]=l*f+c*m+h*B,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=V.vec4()){const s=t[0],r=t[1],n=t[2],A=t[3];return i[0]=e[0]*s+e[4]*r+e[8]*n+e[12]*A,i[1]=e[1]*s+e[5]*r+e[9]*n+e[13]*A,i[2]=e[2]*s+e[6]*r+e[10]*n+e[14]*A,i[3]=e[3]*s+e[7]*r+e[11]*n+e[15]*A,i},transposeMat4(e,t){const i=e[4],s=e[14],r=e[8],n=e[13],A=e[12],o=e[9];if(!t||e===t){const t=e[1],a=e[2],l=e[3],c=e[6],h=e[7],u=e[11];return e[1]=i,e[2]=r,e[3]=A,e[4]=t,e[6]=o,e[7]=n,e[8]=a,e[9]=c,e[11]=s,e[12]=l,e[13]=h,e[14]=u,e}return t[0]=e[0],t[1]=i,t[2]=r,t[3]=A,t[4]=e[1],t[5]=e[5],t[6]=o,t[7]=n,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],n=e[4],A=e[5],o=e[6],a=e[7],l=e[8],c=e[9],h=e[10],u=e[11],d=e[12],f=e[13],p=e[14],g=e[15];return d*c*o*r-l*f*o*r-d*A*h*r+n*f*h*r+l*A*p*r-n*c*p*r-d*c*s*a+l*f*s*a+d*i*h*a-t*f*h*a-l*i*p*a+t*c*p*a+d*A*s*u-n*f*s*u-d*i*o*u+t*f*o*u+n*i*p*u-t*A*p*u-l*A*s*g+n*c*s*g+l*i*o*g-t*c*o*g-n*i*h*g+t*A*h*g},inverseMat4(e,t){t||(t=e);const i=e[0],s=e[1],r=e[2],n=e[3],A=e[4],o=e[5],a=e[6],l=e[7],c=e[8],h=e[9],u=e[10],d=e[11],f=e[12],p=e[13],g=e[14],m=e[15],_=i*o-s*A,b=i*a-r*A,B=i*l-n*A,y=s*a-r*o,w=s*l-n*o,v=r*l-n*a,C=c*p-h*f,M=c*g-u*f,E=c*m-d*f,F=h*g-u*p,U=h*m-d*p,x=u*m-d*g,I=1/(_*x-b*U+B*F+y*E-w*M+v*C);return t[0]=(o*x-a*U+l*F)*I,t[1]=(-s*x+r*U-n*F)*I,t[2]=(p*v-g*w+m*y)*I,t[3]=(-h*v+u*w-d*y)*I,t[4]=(-A*x+a*E-l*M)*I,t[5]=(i*x-r*E+n*M)*I,t[6]=(-f*v+g*B-m*b)*I,t[7]=(c*v-u*B+d*b)*I,t[8]=(A*U-o*E+l*C)*I,t[9]=(-i*U+s*E-n*C)*I,t[10]=(f*w-p*B+m*_)*I,t[11]=(-c*w+h*B-d*_)*I,t[12]=(-A*F+o*M-a*C)*I,t[13]=(i*F-s*M+r*C)*I,t[14]=(-f*y+p*b-g*_)*I,t[15]=(c*y-h*b+u*_)*I,t},traceMat4:e=>e[0]+e[5]+e[10]+e[15],translationMat4v(e,t){const i=t||V.identityMat4();return i[12]=e[0],i[13]=e[1],i[14]=e[2],i},translationMat3v(e,t){const i=t||V.identityMat3();return i[6]=e[0],i[7]=e[1],i},translationMat4c:(()=>{const e=new D(3);return(t,i,s,r)=>(e[0]=t,e[1]=i,e[2]=s,V.translationMat4v(e,r))})(),translationMat4s:(e,t)=>V.translationMat4c(e,e,e,t),translateMat4v:(e,t)=>V.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 n=s[7];s[4]+=n*e,s[5]+=n*t,s[6]+=n*i;const A=s[11];s[8]+=A*e,s[9]+=A*t,s[10]+=A*i;const o=s[15];return s[12]+=o*e,s[13]+=o*t,s[14]+=o*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=V.normalizeVec4([t[0],t[1],t[2],0],[]),r=Math.sin(e),n=Math.cos(e),A=1-n,o=s[0],a=s[1],l=s[2];let c,h,u,d,f,p;return c=o*a,h=a*l,u=l*o,d=o*r,f=a*r,p=l*r,(i=i||V.mat4())[0]=A*o*o+n,i[1]=A*c+p,i[2]=A*u-f,i[3]=0,i[4]=A*c-p,i[5]=A*a*a+n,i[6]=A*h+d,i[7]=0,i[8]=A*u+f,i[9]=A*h-d,i[10]=A*l*l+n,i[11]=0,i[12]=0,i[13]=0,i[14]=0,i[15]=1,i},rotationMat4c:(e,t,i,s,r)=>V.rotationMat4v(e,[t,i,s],r),scalingMat4v:(e,t=V.identityMat4())=>(t[0]=e[0],t[5]=e[1],t[10]=e[2],t),scalingMat3v:(e,t=V.identityMat3())=>(t[0]=e[0],t[4]=e[1],t),scalingMat4c:(()=>{const e=new D(3);return(t,i,s,r)=>(e[0]=t,e[1]=i,e[2]=s,V.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=>V.scalingMat4c(e,e,e),rotationTranslationMat4(e,t,i=V.mat4()){const s=e[0],r=e[1],n=e[2],A=e[3],o=s+s,a=r+r,l=n+n,c=s*o,h=s*a,u=s*l,d=r*a,f=r*l,p=n*l,g=A*o,m=A*a,_=A*l;return i[0]=1-(d+p),i[1]=h+_,i[2]=u-m,i[3]=0,i[4]=h-_,i[5]=1-(c+p),i[6]=f+g,i[7]=0,i[8]=u+m,i[9]=f-g,i[10]=1-(c+d),i[11]=0,i[12]=t[0],i[13]=t[1],i[14]=t[2],i[15]=1,i},mat4ToEuler(e,t,i=V.vec4()){const s=V.clamp,r=e[0],n=e[4],A=e[8],o=e[1],a=e[5],l=e[9],c=e[2],h=e[6],u=e[10];return"XYZ"===t?(i[1]=Math.asin(s(A,-1,1)),Math.abs(A)<.99999?(i[0]=Math.atan2(-l,u),i[2]=Math.atan2(-n,r)):(i[0]=Math.atan2(h,a),i[2]=0)):"YXZ"===t?(i[0]=Math.asin(-s(l,-1,1)),Math.abs(l)<.99999?(i[1]=Math.atan2(A,u),i[2]=Math.atan2(o,a)):(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(-n,a)):(i[1]=0,i[2]=Math.atan2(o,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(o,r)):(i[0]=0,i[2]=Math.atan2(-n,a))):"YZX"===t?(i[2]=Math.asin(s(o,-1,1)),Math.abs(o)<.99999?(i[0]=Math.atan2(-l,a),i[1]=Math.atan2(-c,r)):(i[0]=0,i[1]=Math.atan2(A,u))):"XZY"===t&&(i[2]=Math.asin(-s(n,-1,1)),Math.abs(n)<.99999?(i[0]=Math.atan2(h,a),i[1]=Math.atan2(A,r)):(i[0]=Math.atan2(-l,u),i[1]=0)),i[0]*=V.RADTODEG,i[1]*=V.RADTODEG,i[2]*=V.RADTODEG,i},composeMat4:(e,t,i,s=V.mat4())=>(V.quaternionToRotationMat4(t,s),V.scaleMat4v(i,s),V.translateMat4v(e,s),s),decomposeMat4:(()=>{const e=new D(3),t=new D(16);return function(i,s,r,n){e[0]=i[0],e[1]=i[1],e[2]=i[2];let A=V.lenVec3(e);e[0]=i[4],e[1]=i[5],e[2]=i[6];const o=V.lenVec3(e);e[0]=i[8],e[1]=i[9],e[2]=i[10];const a=V.lenVec3(e);V.determinantMat4(i)<0&&(A=-A),s[0]=i[12],s[1]=i[13],s[2]=i[14],t.set(i);const l=1/A,c=1/o,h=1/a;return t[0]*=l,t[1]*=l,t[2]*=l,t[4]*=c,t[5]*=c,t[6]*=c,t[8]*=h,t[9]*=h,t[10]*=h,V.mat4ToQuaternion(t,r),n[0]=A,n[1]=o,n[2]=a,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=V.mat4());const r=e[0],n=e[1],A=e[2],o=i[0],a=i[1],l=i[2],c=t[0],h=t[1],u=t[2];if(r===c&&n===h&&A===u)return V.identityMat4();let d,f,p,g,m,_,b,B,y,w;return d=r-c,f=n-h,p=A-u,w=1/Math.sqrt(d*d+f*f+p*p),d*=w,f*=w,p*=w,g=a*p-l*f,m=l*d-o*p,_=o*f-a*d,w=Math.sqrt(g*g+m*m+_*_),w?(w=1/w,g*=w,m*=w,_*=w):(g=0,m=0,_=0),b=f*_-p*m,B=p*g-d*_,y=d*m-f*g,w=Math.sqrt(b*b+B*B+y*y),w?(w=1/w,b*=w,B*=w,y*=w):(b=0,B=0,y=0),s[0]=g,s[1]=b,s[2]=d,s[3]=0,s[4]=m,s[5]=B,s[6]=f,s[7]=0,s[8]=_,s[9]=y,s[10]=p,s[11]=0,s[12]=-(g*r+m*n+_*A),s[13]=-(b*r+B*n+y*A),s[14]=-(d*r+f*n+p*A),s[15]=1,s},lookAtMat4c:(e,t,i,s,r,n,A,o,a)=>V.lookAtMat4v([e,t,i],[s,r,n],[A,o,a],[]),orthoMat4c(e,t,i,s,r,n,A){A||(A=V.mat4());const o=t-e,a=s-i,l=n-r;return A[0]=2/o,A[1]=0,A[2]=0,A[3]=0,A[4]=0,A[5]=2/a,A[6]=0,A[7]=0,A[8]=0,A[9]=0,A[10]=-2/l,A[11]=0,A[12]=-(e+t)/o,A[13]=-(s+i)/a,A[14]=-(n+r)/l,A[15]=1,A},frustumMat4v(e,t,i){i||(i=V.mat4());const s=[e[0],e[1],e[2],0],r=[t[0],t[1],t[2],0];V.addVec4(r,s,Q),V.subVec4(r,s,R);const n=2*s[2],A=R[0],o=R[1],a=R[2];return i[0]=n/A,i[1]=0,i[2]=0,i[3]=0,i[4]=0,i[5]=n/o,i[6]=0,i[7]=0,i[8]=Q[0]/A,i[9]=Q[1]/o,i[10]=-Q[2]/a,i[11]=-1,i[12]=0,i[13]=0,i[14]=-n*r[2]/a,i[15]=0,i},frustumMat4(e,t,i,s,r,n,A){A||(A=V.mat4());const o=t-e,a=s-i,l=n-r;return A[0]=2*r/o,A[1]=0,A[2]=0,A[3]=0,A[4]=0,A[5]=2*r/a,A[6]=0,A[7]=0,A[8]=(t+e)/o,A[9]=(s+i)/a,A[10]=-(n+r)/l,A[11]=-1,A[12]=0,A[13]=0,A[14]=-n*r*2/l,A[15]=0,A},perspectiveMat4(e,t,i,s,r){const n=[],A=[];return n[2]=i,A[2]=s,A[1]=n[2]*Math.tan(e/2),n[1]=-A[1],A[0]=A[1]*t,n[0]=-A[0],V.frustumMat4v(n,A,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=V.vec3()){const s=t[0],r=t[1],n=t[2];return i[0]=e[0]*s+e[4]*r+e[8]*n+e[12],i[1]=e[1]*s+e[5]*r+e[9]*n+e[13],i[2]=e[2]*s+e[6]*r+e[10]*n+e[14],i},transformPoint4:(e,t,i=V.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 n,A,o,a;const l=e[0],c=e[1],h=e[2],u=e[3],d=e[4],f=e[5],p=e[6],g=e[7],m=e[8],_=e[9],b=e[10],B=e[11],y=e[12],w=e[13],v=e[14],C=e[15];let M;for(let e=0;e<r;++e)a=t[e],n=a[0],A=a[1],o=a[2],M=s[e]||(s[e]=[0,0,0]),M[0]=l*n+d*A+m*o+y,M[1]=c*n+f*A+_*o+w,M[2]=h*n+p*A+b*o+v,M[3]=u*n+g*A+B*o+C;return s.length=r,s},transformPositions3(e,t,i=t){let s;const r=t.length;let n,A,o;const a=e[0],l=e[1],c=e[2];e[3];const h=e[4],u=e[5],d=e[6];e[7];const f=e[8],p=e[9],g=e[10];e[11];const m=e[12],_=e[13],b=e[14];for(e[15],s=0;s<r;s+=3)n=t[s+0],A=t[s+1],o=t[s+2],i[s+0]=a*n+h*A+f*o+m,i[s+1]=l*n+u*A+p*o+_,i[s+2]=c*n+d*A+g*o+b;return i},transformPositions4(e,t,i=t){let s;const r=t.length;let n,A,o;const a=e[0],l=e[1],c=e[2],h=e[3],u=e[4],d=e[5],f=e[6],p=e[7],g=e[8],m=e[9],_=e[10],b=e[11],B=e[12],y=e[13],w=e[14],v=e[15];for(s=0;s<r;s+=4)n=t[s+0],A=t[s+1],o=t[s+2],i[s+0]=a*n+u*A+g*o+B,i[s+1]=l*n+d*A+m*o+y,i[s+2]=c*n+f*A+_*o+w,i[s+3]=h*n+p*A+b*o+v;return i},transformVec3(e,t,i){const s=t[0],r=t[1],n=t[2];return(i=i||this.vec3())[0]=e[0]*s+e[4]*r+e[8]*n,i[1]=e[1]*s+e[5]*r+e[9]*n,i[2]=e[2]*s+e[6]*r+e[10]*n,i},transformVec4(e,t,i){const s=t[0],r=t[1],n=t[2],A=t[3];return(i=i||V.vec4())[0]=e[0]*s+e[4]*r+e[8]*n+e[12]*A,i[1]=e[1]*s+e[5]*r+e[9]*n+e[13]*A,i[2]=e[2]*s+e[6]*r+e[10]*n+e[14]*A,i[3]=e[3]*s+e[7]*r+e[11]*n+e[15]*A,i},rotateVec2(e,t,i,s=e){const r=Math.cos(i),n=Math.sin(i),A=e[0]-t[0],o=e[1]-t[1];return s[0]=A*r-o*n+t[0],s[1]=A*n+o*r+t[1],e},rotateVec3X(e,t,i,s){const r=[],n=[];return r[0]=e[0]-t[0],r[1]=e[1]-t[1],r[2]=e[2]-t[2],n[0]=r[0],n[1]=r[1]*Math.cos(i)-r[2]*Math.sin(i),n[2]=r[1]*Math.sin(i)+r[2]*Math.cos(i),s[0]=n[0]+t[0],s[1]=n[1]+t[1],s[2]=n[2]+t[2],s},rotateVec3Y(e,t,i,s){const r=[],n=[];return r[0]=e[0]-t[0],r[1]=e[1]-t[1],r[2]=e[2]-t[2],n[0]=r[2]*Math.sin(i)+r[0]*Math.cos(i),n[1]=r[1],n[2]=r[2]*Math.cos(i)-r[0]*Math.sin(i),s[0]=n[0]+t[0],s[1]=n[1]+t[1],s[2]=n[2]+t[2],s},rotateVec3Z(e,t,i,s){const r=[],n=[];return r[0]=e[0]-t[0],r[1]=e[1]-t[1],r[2]=e[2]-t[2],n[0]=r[0]*Math.cos(i)-r[1]*Math.sin(i),n[1]=r[0]*Math.sin(i)+r[1]*Math.cos(i),n[2]=r[2],s[0]=n[0]+t[0],s[1]=n[1]+t[1],s[2]=n[2]+t[2],s},projectVec4(e,t){const i=1/e[3];return(t=t||V.vec2())[0]=e[0]*i,t[1]=e[1]*i,t},unprojectVec3:(()=>{const e=new D(16),t=new D(16),i=new D(16);return function(s,r,n,A){return this.transformVec3(this.mulMat4(this.inverseMat4(r,e),this.inverseMat4(n,t),i),s,A)}})(),lerpVec3(e,t,i,s,r,n){const A=n||V.vec3(),o=(e-t)/(i-t);return A[0]=s[0]+o*(r[0]-s[0]),A[1]=s[1]+o*(r[1]-s[1]),A[2]=s[2]+o*(r[2]-s[2]),A},lerpMat4(e,t,i,s,r,n){const A=n||V.mat4(),o=(e-t)/(i-t);return A[0]=s[0]+o*(r[0]-s[0]),A[1]=s[1]+o*(r[1]-s[1]),A[2]=s[2]+o*(r[2]-s[2]),A[3]=s[3]+o*(r[3]-s[3]),A[4]=s[4]+o*(r[4]-s[4]),A[5]=s[5]+o*(r[5]-s[5]),A[6]=s[6]+o*(r[6]-s[6]),A[7]=s[7]+o*(r[7]-s[7]),A[8]=s[8]+o*(r[8]-s[8]),A[9]=s[9]+o*(r[9]-s[9]),A[10]=s[10]+o*(r[10]-s[10]),A[11]=s[11]+o*(r[11]-s[11]),A[12]=s[12]+o*(r[12]-s[12]),A[13]=s[13]+o*(r[13]-s[13]),A[14]=s[14]+o*(r[14]-s[14]),A[15]=s[15]+o*(r[15]-s[15]),A},flatten(e){const t=[];let i,s,r,n,A;for(i=0,s=e.length;i<s;i++)for(A=e[i],r=0,n=A.length;r<n;r++)t.push(A[r]);return t},identityQuaternion:(e=V.vec4())=>(e[0]=0,e[1]=0,e[2]=0,e[3]=1,e),eulerToQuaternion(e,t,i=V.vec4()){const s=e[0]*V.DEGTORAD/2,r=e[1]*V.DEGTORAD/2,n=e[2]*V.DEGTORAD/2,A=Math.cos(s),o=Math.cos(r),a=Math.cos(n),l=Math.sin(s),c=Math.sin(r),h=Math.sin(n);return"XYZ"===t?(i[0]=l*o*a+A*c*h,i[1]=A*c*a-l*o*h,i[2]=A*o*h+l*c*a,i[3]=A*o*a-l*c*h):"YXZ"===t?(i[0]=l*o*a+A*c*h,i[1]=A*c*a-l*o*h,i[2]=A*o*h-l*c*a,i[3]=A*o*a+l*c*h):"ZXY"===t?(i[0]=l*o*a-A*c*h,i[1]=A*c*a+l*o*h,i[2]=A*o*h+l*c*a,i[3]=A*o*a-l*c*h):"ZYX"===t?(i[0]=l*o*a-A*c*h,i[1]=A*c*a+l*o*h,i[2]=A*o*h-l*c*a,i[3]=A*o*a+l*c*h):"YZX"===t?(i[0]=l*o*a+A*c*h,i[1]=A*c*a+l*o*h,i[2]=A*o*h-l*c*a,i[3]=A*o*a-l*c*h):"XZY"===t&&(i[0]=l*o*a-A*c*h,i[1]=A*c*a-l*o*h,i[2]=A*o*h+l*c*a,i[3]=A*o*a+l*c*h),i},mat4ToQuaternion(e,t=V.vec4()){const i=e[0],s=e[4],r=e[8],n=e[1],A=e[5],o=e[9],a=e[2],l=e[6],c=e[10];let h;const u=i+A+c;return u>0?(h=.5/Math.sqrt(u+1),t[3]=.25/h,t[0]=(l-o)*h,t[1]=(r-a)*h,t[2]=(n-s)*h):i>A&&i>c?(h=2*Math.sqrt(1+i-A-c),t[3]=(l-o)/h,t[0]=.25*h,t[1]=(s+n)/h,t[2]=(r+a)/h):A>c?(h=2*Math.sqrt(1+A-i-c),t[3]=(r-a)/h,t[0]=(s+n)/h,t[1]=.25*h,t[2]=(o+l)/h):(h=2*Math.sqrt(1+c-i-A),t[3]=(n-s)/h,t[0]=(r+a)/h,t[1]=(o+l)/h,t[2]=.25*h),t},vec3PairToQuaternion(e,t,i=V.vec4()){const s=Math.sqrt(V.dotVec3(e,e)*V.dotVec3(t,t));let r=s+V.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])):V.cross3Vec3(e,t,i),i[3]=r,V.normalizeQuaternion(i)},angleAxisToQuaternion(e,t=V.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 D(16);return(t,i,s)=>(s=s||V.vec3(),V.quaternionToRotationMat4(t,e),V.mat4ToEuler(e,i,s),s)})(),mulQuaternions(e,t,i=V.vec4()){const s=e[0],r=e[1],n=e[2],A=e[3],o=t[0],a=t[1],l=t[2],c=t[3];return i[0]=A*o+s*c+r*l-n*a,i[1]=A*a+r*c+n*o-s*l,i[2]=A*l+n*c+s*a-r*o,i[3]=A*c-s*o-r*a-n*l,i},vec3ApplyQuaternion(e,t,i=V.vec3()){const s=t[0],r=t[1],n=t[2],A=e[0],o=e[1],a=e[2],l=e[3],c=l*s+o*n-a*r,h=l*r+a*s-A*n,u=l*n+A*r-o*s,d=-A*s-o*r-a*n;return i[0]=c*l+d*-A+h*-a-u*-o,i[1]=h*l+d*-o+u*-A-c*-a,i[2]=u*l+d*-a+c*-o-h*-A,i},quaternionToMat4(e,t){t=V.identityMat4(t);const i=e[0],s=e[1],r=e[2],n=e[3],A=2*i,o=2*s,a=2*r,l=A*n,c=o*n,h=a*n,u=A*i,d=o*i,f=a*i,p=o*s,g=a*s,m=a*r;return t[0]=1-(p+m),t[1]=d+h,t[2]=f-c,t[4]=d-h,t[5]=1-(u+m),t[6]=g+l,t[8]=f+c,t[9]=g-l,t[10]=1-(u+p),t},quaternionToRotationMat4(e,t){const i=e[0],s=e[1],r=e[2],n=e[3],A=i+i,o=s+s,a=r+r,l=i*A,c=i*o,h=i*a,u=s*o,d=s*a,f=r*a,p=n*A,g=n*o,m=n*a;return t[0]=1-(u+f),t[4]=c-m,t[8]=h+g,t[1]=c+m,t[5]=1-(l+f),t[9]=d-p,t[2]=h-g,t[6]=d+p,t[10]=1-(l+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=V.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)=>V.normalizeQuaternion(V.conjugateQuaternion(e,t)),quaternionToAngleAxis(e,t=V.vec4()){const i=(e=V.normalizeQuaternion(e,O))[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 D(e||6),AABB2:e=>new D(e||4),OBB3:e=>new D(e||32),OBB2:e=>new D(e||16),Sphere3:(e,t,i,s)=>new D([e,t,i,s]),transformOBB3(e,t,i=t){let s;const r=t.length;let n,A,o;const a=e[0],l=e[1],c=e[2],h=e[3],u=e[4],d=e[5],f=e[6],p=e[7],g=e[8],m=e[9],_=e[10],b=e[11],B=e[12],y=e[13],w=e[14],v=e[15];for(s=0;s<r;s+=4)n=t[s+0],A=t[s+1],o=t[s+2],i[s+0]=a*n+u*A+g*o+B,i[s+1]=l*n+d*A+m*o+y,i[s+2]=c*n+f*A+_*o+w,i[s+3]=h*n+p*A+b*o+v;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 D(3),t=new D(3),i=new D(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],V.subVec3(t,e,i),Math.abs(V.lenVec3(i)))})(),getAABB3DiagPoint:(()=>{const e=new D(3),t=new D(3),i=new D(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 n=V.subVec3(t,e,i),A=r[0]-s[0],o=s[3]-r[0],a=r[1]-s[1],l=s[4]-r[1],c=r[2]-s[2],h=s[5]-r[2];return n[0]+=A>o?A:o,n[1]+=a>l?a:l,n[2]+=c>h?c:h,Math.abs(V.lenVec3(n))}})(),getAABB3Area:e=>(e[3]-e[0])*(e[4]-e[1])*(e[5]-e[2]),getAABB3Center(e,t){const i=t||V.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||V.vec2();return i[0]=(e[2]+e[0])/2,i[1]=(e[3]+e[1])/2,i},collapseAABB3:(e=V.AABB3())=>(e[0]=V.MAX_DOUBLE,e[1]=V.MAX_DOUBLE,e[2]=V.MAX_DOUBLE,e[3]=V.MIN_DOUBLE,e[4]=V.MIN_DOUBLE,e[5]=V.MIN_DOUBLE,e),AABB3ToOBB3:(e,t=V.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 D(3);return(t,i,s)=>{i=i||V.AABB3();let r,n,A,o=V.MAX_DOUBLE,a=V.MAX_DOUBLE,l=V.MAX_DOUBLE,c=V.MIN_DOUBLE,h=V.MIN_DOUBLE,u=V.MIN_DOUBLE;for(let i=0,d=t.length;i<d;i+=3)s?(e[0]=t[i+0],e[1]=t[i+1],e[2]=t[i+2],V.decompressPosition(e,s,e),r=e[0],n=e[1],A=e[2]):(r=t[i+0],n=t[i+1],A=t[i+2]),r<o&&(o=r),n<a&&(a=n),A<l&&(l=A),r>c&&(c=r),n>h&&(h=n),A>u&&(u=A);return i[0]=o,i[1]=a,i[2]=l,i[3]=c,i[4]=h,i[5]=u,i}})(),OBB3ToAABB3(e,t=V.AABB3()){let i,s,r,n=V.MAX_DOUBLE,A=V.MAX_DOUBLE,o=V.MAX_DOUBLE,a=V.MIN_DOUBLE,l=V.MIN_DOUBLE,c=V.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<n&&(n=i),s<A&&(A=s),r<o&&(o=r),i>a&&(a=i),s>l&&(l=s),r>c&&(c=r);return t[0]=n,t[1]=A,t[2]=o,t[3]=a,t[4]=l,t[5]=c,t},points3ToAABB3(e,t=V.AABB3()){let i,s,r,n=V.MAX_DOUBLE,A=V.MAX_DOUBLE,o=V.MAX_DOUBLE,a=V.MIN_DOUBLE,l=V.MIN_DOUBLE,c=V.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<n&&(n=i),s<A&&(A=s),r<o&&(o=r),i>a&&(a=i),s>l&&(l=s),r>c&&(c=r);return t[0]=n,t[1]=A,t[2]=o,t[3]=a,t[4]=l,t[5]=c,t},points3ToSphere3:(()=>{const e=new D(3);return(t,i)=>{i=i||V.vec4();let s,r=0,n=0,A=0;const o=t.length;for(s=0;s<o;s++)r+=t[s][0],n+=t[s][1],A+=t[s][2];i[0]=r/o,i[1]=n/o,i[2]=A/o;let a,l=0;for(s=0;s<o;s++)a=Math.abs(V.lenVec3(V.subVec3(t[s],i,e))),a>l&&(l=a);return i[3]=l,i}})(),positions3ToSphere3:(()=>{const e=new D(3),t=new D(3);return(i,s)=>{s=s||V.vec4();let r,n=0,A=0,o=0;const a=i.length;let l=0;for(r=0;r<a;r+=3)n+=i[r],A+=i[r+1],o+=i[r+2];const c=a/3;let h;for(s[0]=n/c,s[1]=A/c,s[2]=o/c,r=0;r<a;r+=3)e[0]=i[r],e[1]=i[r+1],e[2]=i[r+2],h=Math.abs(V.lenVec3(V.subVec3(e,s,t))),h>l&&(l=h);return s[3]=l,s}})(),OBB3ToSphere3:(()=>{const e=new D(3),t=new D(3);return(i,s)=>{s=s||V.vec4();let r,n=0,A=0,o=0;const a=i.length,l=a/4;for(r=0;r<a;r+=4)n+=i[r+0],A+=i[r+1],o+=i[r+2];s[0]=n/l,s[1]=A/l,s[2]=o/l;let c,h=0;for(r=0;r<a;r+=4)e[0]=i[r+0],e[1]=i[r+1],e[2]=i[r+2],c=Math.abs(V.lenVec3(V.subVec3(e,s,t))),c>h&&(h=c);return s[3]=h,s}})(),getSphere3Center:(e,t=V.vec3())=>(t[0]=e[0],t[1]=e[1],t[2]=e[2],t),getPositionsCenter(e,t=V.vec3()){let i=0,s=0,r=0;for(var n=0,A=e.length;n<A;n+=3)i+=e[n+0],s+=e[n+1],r+=e[n+2];const o=e.length/3;return t[0]=i/o,t[1]=s/o,t[2]=r/o,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,n=0,A=t.length;n<A;n+=3)i=t[n],s=t[n+1],r=t[n+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=V.AABB2())=>(e[0]=V.MAX_DOUBLE,e[1]=V.MAX_DOUBLE,e[2]=V.MIN_DOUBLE,e[3]=V.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=V.AABB2()){let i,s,r,n,A=V.MAX_DOUBLE,o=V.MAX_DOUBLE,a=V.MIN_DOUBLE,l=V.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,n=1/r,i*=n,s*=n,i<A&&(A=i),s<o&&(o=s),i>a&&(a=i),s>l&&(l=s);return t[0]=A,t[1]=o,t[2]=a,t[3]=l,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),n=.5*(e[1]+1),A=.5*(e[2]+1),o=.5*(e[3]+1);return s[0]=Math.floor(r*t),s[1]=i-Math.floor(o*i),s[2]=Math.floor(A*t),s[3]=i-Math.floor(n*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 n=.5*(i-e),A=.5*(s-t),o=r*r;return(2*t-2*i+n+A)*(r*o)+(-3*t+3*i-2*n-A)*o+n*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=V.vec3()){const r=t[0]-e[0],n=t[1]-e[1],A=t[2]-e[2],o=i[0]-e[0],a=i[1]-e[1],l=i[2]-e[2],c=n*l-A*a,h=A*o-r*l,u=r*a-n*o,d=Math.sqrt(c*c+h*h+u*u);return 0===d?(s[0]=0,s[1]=0,s[2]=0):(s[0]=c/d,s[1]=h/d,s[2]=u/d),s},rayTriangleIntersect:(()=>{const e=new D(3),t=new D(3),i=new D(3),s=new D(3),r=new D(3);return(n,A,o,a,l,c)=>{c=c||V.vec3();const h=V.subVec3(a,o,e),u=V.subVec3(l,o,t),d=V.cross3Vec3(A,u,i),f=V.dotVec3(h,d);if(f<1e-6)return null;const p=V.subVec3(n,o,s),g=V.dotVec3(p,d);if(g<0||g>f)return null;const m=V.cross3Vec3(p,h,r),_=V.dotVec3(A,m);if(_<0||g+_>f)return null;const b=V.dotVec3(u,m)/f;return c[0]=n[0]+b*A[0],c[1]=n[1]+b*A[1],c[2]=n[2]+b*A[2],c}})(),rayPlaneIntersect:(()=>{const e=new D(3),t=new D(3),i=new D(3),s=new D(3);return(r,n,A,o,a,l)=>{l=l||V.vec3(),n=V.normalizeVec3(n,e);const c=V.subVec3(o,A,t),h=V.subVec3(a,A,i),u=V.cross3Vec3(c,h,s);V.normalizeVec3(u,u);const d=-V.dotVec3(A,u),f=-(V.dotVec3(r,u)+d)/V.dotVec3(n,u);return l[0]=r[0]+f*n[0],l[1]=r[1]+f*n[1],l[2]=r[2]+f*n[2],l}})(),cartesianToBarycentric:(()=>{const e=new D(3),t=new D(3),i=new D(3);return(s,r,n,A,o)=>{const a=V.subVec3(A,r,e),l=V.subVec3(n,r,t),c=V.subVec3(s,r,i),h=V.dotVec3(a,a),u=V.dotVec3(a,l),d=V.dotVec3(a,c),f=V.dotVec3(l,l),p=V.dotVec3(l,c),g=h*f-u*u;if(0===g)return null;const m=1/g,_=(f*d-u*p)*m,b=(h*p-u*d)*m;return o[0]=1-_-b,o[1]=b,o[2]=_,o}})(),barycentricInsideTriangle(e){const t=e[1],i=e[2];return i>=0&&t>=0&&i+t<1},barycentricToCartesian(e,t,i,s,r=V.vec3()){const n=e[0],A=e[1],o=e[2];return r[0]=t[0]*n+i[0]*A+s[0]*o,r[1]=t[1]*n+i[1]*A+s[1]*o,r[2]=t[2]*n+i[2]*A+s[2]*o,r},mergeVertices(e,t,i,s){const r={},n=[],A=[],o=t?[]:null,a=i?[]:null,l=[];let c,h,u,d;const f=1e4;let p,g,m=0;for(p=0,g=e.length;p<g;p+=3)c=e[p],h=e[p+1],u=e[p+2],d=`${Math.round(c*f)}_${Math.round(h*f)}_${Math.round(u*f)}`,void 0===r[d]&&(r[d]=A.length/3,A.push(c),A.push(h),A.push(u),t&&(o.push(t[p]),o.push(t[p+1]),o.push(t[p+2])),i&&(a.push(i[m]),a.push(i[m+1]))),n[p/3]=r[d],m+=2;for(p=0,g=s.length;p<g;p++)l[p]=n[s[p]];const _={positions:A,indices:l};return o&&(_.normals=o),a&&(_.uv=a),_},buildNormals:(()=>{const e=new D(3),t=new D(3),i=new D(3),s=new D(3),r=new D(3),n=new D(3);return(A,o,a)=>{let l,c;const h=new Array(A.length/3);let u,d,f,p,g,m,_;for(l=0,c=o.length;l<c;l+=3){u=o[l],d=o[l+1],f=o[l+2],e[0]=A[3*u],e[1]=A[3*u+1],e[2]=A[3*u+2],t[0]=A[3*d],t[1]=A[3*d+1],t[2]=A[3*d+2],i[0]=A[3*f],i[1]=A[3*f+1],i[2]=A[3*f+2],V.subVec3(t,e,s),V.subVec3(i,e,r);const a=V.vec3();V.normalizeVec3(V.cross3Vec3(s,r,n),a),h[u]||(h[u]=[]),h[d]||(h[d]=[]),h[f]||(h[f]=[]),h[u].push(a),h[d].push(a),h[f].push(a)}for(a=a&&a.length===A.length?a:new Float32Array(A.length),l=0,c=h.length;l<c;l++){p=h[l].length,g=0,m=0,_=0;for(let e=0;e<p;e++)g+=h[l][e][0],m+=h[l][e][1],_+=h[l][e][2];a[3*l]=g/p,a[3*l+1]=m/p,a[3*l+2]=_/p}return a}})(),buildTangents:(()=>{const e=new D(3),t=new D(3),i=new D(3),s=new D(3),r=new D(3),n=new D(3),A=new D(3);return(o,a,l)=>{const c=new Float32Array(o.length);for(let h=0;h<a.length;h+=3){let u=a[h];const d=o.subarray(3*u,3*u+3),f=l.subarray(2*u,2*u+2);u=a[h+1];const p=o.subarray(3*u,3*u+3),g=l.subarray(2*u,2*u+2);u=a[h+2];const m=o.subarray(3*u,3*u+3),_=l.subarray(2*u,2*u+2),b=V.subVec3(p,d,e),B=V.subVec3(m,d,t),y=V.subVec2(g,f,i),w=V.subVec2(_,f,s),v=1/(y[0]*w[1]-y[1]*w[0]),C=V.mulVec3Scalar(V.subVec3(V.mulVec3Scalar(b,w[1],r),V.mulVec3Scalar(B,y[1],n),A),v,n);let M;for(let e=0;e<3;e++)M=3*a[h+e],c[M]+=C[0],c[M+1]+=C[1],c[M+2]+=C[2]}return c}})(),buildPickTriangles(e,t,i){const s=t.length,r=i?new Uint16Array(9*s):new Float32Array(9*s),n=new Uint8Array(12*s);let A,o,a,l,c,h,u=0,d=0,f=0;for(let i=0;i<s;i+=3)h=u>>24&255,c=u>>16&255,l=u>>8&255,a=255&u,o=t[i],A=3*o,r[d++]=e[A],r[d++]=e[A+1],r[d++]=e[A+2],n[f++]=a,n[f++]=l,n[f++]=c,n[f++]=h,o=t[i+1],A=3*o,r[d++]=e[A],r[d++]=e[A+1],r[d++]=e[A+2],n[f++]=a,n[f++]=l,n[f++]=c,n[f++]=h,o=t[i+2],A=3*o,r[d++]=e[A],r[d++]=e[A+1],r[d++]=e[A+2],n[f++]=a,n[f++]=l,n[f++]=c,n[f++]=h,u++;return{positions:r,colors:n}},faceToVertexNormals(e,t,i={}){const s=i.smoothNormalsAngleThreshold||20,r={},n=[],A={};let o,a,l,c,h;const u=1e4;let d,f,p,g,m,_;for(f=0,g=e.length;f<g;f+=3){d=f/3,a=e[f],l=e[f+1],c=e[f+2],h=`${Math.round(a*u)}_${Math.round(l*u)}_${Math.round(c*u)}`,void 0===r[h]?r[h]=[d]:r[h].push(d);const i=V.normalizeVec3([t[f],t[f+1],t[f+2]]);n[d]=i,o=V.vec4([i[0],i[1],i[2],1]),A[d]=o}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(o=A[i],p=0;p<t;p++){if(f===p)continue;const t=e[p];m=n[i],_=n[t];Math.abs(V.angleVec3(m,_)/V.DEGTORAD)<s&&(o[0]+=_[0],o[1]+=_[1],o[2]+=_[2],o[3]+=1)}}}for(f=0,g=t.length;f<g;f+=3)o=A[f/3],t[f+0]=o[0]/o[3],t[f+1]=o[1]/o[3],t[f+2]=o[2]/o[3]},transformRay:(()=>{const e=new D(4),t=new D(4);return(i,s,r,n,A)=>{e[0]=s[0],e[1]=s[1],e[2]=s[2],e[3]=1,V.transformVec4(i,e,t),n[0]=t[0],n[1]=t[1],n[2]=t[2],e[0]=r[0],e[1]=r[1],e[2]=r[2],V.transformVec3(i,e,t),V.normalizeVec3(t),A[0]=t[0],A[1]=t[1],A[2]=t[2]}})(),canvasPosToWorldRay:(()=>{const e=new D(16),t=new D(4),i=new D(4),s=(t,i,s,r,n)=>{n[0]=t,n[1]=i,n[2]=s,n[3]=1,V.transformVec4(e,n,n),r||V.mulVec4Scalar(n,1/n[3])};return(r,n,A,o,a,l,c)=>{const h="ortho"===o;V.mulMat4(A,n,e),V.inverseMat4(e,e);const u=2*a[0]/r.clientWidth-1,d=1-2*a[1]/r.clientHeight;s(u,d,-1,h,t),s(u,d,1,h,i),l[0]=t[0],l[1]=t[1],l[2]=t[2],V.subVec3(i,t,c),V.normalizeVec3(c)}})(),canvasPosToLocalRay:(()=>{const e=new D(3),t=new D(3);return(i,s,r,n,A,o,a,l)=>{V.canvasPosToWorldRay(i,s,r,n,o,e,t),V.worldRayToLocalRay(A,e,t,a,l)}})(),worldRayToLocalRay:(()=>{const e=new D(16),t=new D(4),i=new D(4);return(s,r,n,A,o)=>{const a=V.inverseMat4(s,e);t[0]=r[0],t[1]=r[1],t[2]=r[2],t[3]=1,V.transformVec4(a,t,i),A[0]=i[0],A[1]=i[1],A[2]=i[2],V.transformVec3(a,n,o)}})(),buildKDTree:(()=>{const e=new Float32Array;function t(i,s,r,n){const A=new D(6),o={triangles:null,left:null,right:null,leaf:!1,splitDim:0,aabb:A};let a,l;for(A[0]=A[1]=A[2]=Number.POSITIVE_INFINITY,A[3]=A[4]=A[5]=Number.NEGATIVE_INFINITY,a=0,l=i.length;a<l;++a){var c=3*i[a];for(let e=0;e<3;++e){const t=3*s[c+e];r[t]<A[0]&&(A[0]=r[t]),r[t]>A[3]&&(A[3]=r[t]),r[t+1]<A[1]&&(A[1]=r[t+1]),r[t+1]>A[4]&&(A[4]=r[t+1]),r[t+2]<A[2]&&(A[2]=r[t+2]),r[t+2]>A[5]&&(A[5]=r[t+2])}}if(i.length<20||n>10)return o.triangles=i,o.leaf=!0,o;e[0]=A[3]-A[0],e[1]=A[4]-A[1],e[2]=A[5]-A[2];let h=0;e[1]>e[h]&&(h=1),e[2]>e[h]&&(h=2),o.splitDim=h;const u=(A[h]+A[h+3])/2,d=new Array(i.length);let f=0;const p=new Array(i.length);let g=0;for(a=0,l=i.length;a<l;++a){const e=s[c=3*i[a]],t=3*s[c+1],n=3*s[c+2];r[3*e+h]<=u||r[t+h]<=u||r[n+h]<=u?d[f++]=i[a]:p[g++]=i[a]}return d.length=f,p.length=g,o.left=t(d,s,r,n+1),o.right=t(p,s,r,n+1),o}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 n=Math.sqrt(i*i+s*s+r*r);return t[0]=i/n,t[1]=s/n,t[2]=r/n,t},octDecodeVec2s(e,t){for(let i=0,s=0,r=e.length;i<r;i+=2){let r=e[i+0],n=e[i+1];r=(2*r+1)/255,n=(2*n+1)/255;const A=1-Math.abs(r)-Math.abs(n);A<0&&(r=(1-Math.abs(n))*(r>=0?1:-1),n=(1-Math.abs(r))*(n>=0?1:-1));const o=Math.sqrt(r*r+n*n+A*A);t[s+0]=r/o,t[s+1]=n/o,t[s+2]=A/o,s+=3}return t}};V.buildEdgeIndices=function(){const e=[],t=[],i=[],s=[],r=[];let n=0;const A=new Uint16Array(3),o=new Uint16Array(3),a=new Uint16Array(3),l=V.vec3(),c=V.vec3(),h=V.vec3(),u=V.vec3(),d=V.vec3(),f=V.vec3(),p=V.vec3();return function(g,m,_,b){!function(r,n){const A={};let o,a,l,c;const h=Math.pow(10,4);let u,d,f=0;for(u=0,d=r.length;u<d;u+=3)o=r[u],a=r[u+1],l=r[u+2],c=Math.round(o*h)+"_"+Math.round(a*h)+"_"+Math.round(l*h),void 0===A[c]&&(A[c]=f/3,e[f++]=o,e[f++]=a,e[f++]=l),t[u/3]=A[c];for(u=0,d=n.length;u<d;u++)s[u]=t[n[u]],i[s[u]]=n[u]}(g,m),function(t,i){n=0;for(let g=0,m=t;g<m;g+=3){const t=3*s[g],m=3*s[g+1],_=3*s[g+2];i?(A[0]=e[t],A[1]=e[t+1],A[2]=e[t+2],o[0]=e[m],o[1]=e[m+1],o[2]=e[m+2],a[0]=e[_],a[1]=e[_+1],a[2]=e[_+2],V.decompressPosition(A,i,l),V.decompressPosition(o,i,c),V.decompressPosition(a,i,h)):(l[0]=e[t],l[1]=e[t+1],l[2]=e[t+2],c[0]=e[m],c[1]=e[m+1],c[2]=e[m+2],h[0]=e[_],h[1]=e[_+1],h[2]=e[_+2]),V.subVec3(h,c,u),V.subVec3(l,c,d),V.cross3Vec3(u,d,f),V.normalizeVec3(f,p);const b=r[n]||(r[n]={normal:V.vec3()});b.normal[0]=p[0],b.normal[1]=p[1],b.normal[2]=p[2],n++}}(m.length,_);const B=[],y=Math.cos(V.DEGTORAD*b),w={};let v,C,M,E,F,U,x,I,T,P,S,D=!1;for(let e=0,t=m.length;e<t;e+=3){const t=e/3;for(let i=0;i<3;i++)v=s[e+i],C=s[e+(i+1)%3],M=Math.min(v,C),E=Math.max(v,C),F=M+","+E,void 0===w[F]?w[F]={index1:M,index2:E,face1:t,face2:void 0}:w[F].face2=t}for(F in w)U=w[F],void 0!==U.face2&&(x=r[U.face1].normal,I=r[U.face2].normal,T=V.dotVec3(x,I),T>y)||(P=i[U.index1],S=i[U.index2],(!D&&P>65535||S>65535)&&(D=!0),B.push(P),B.push(S));return D?new Uint32Array(B):new Uint16Array(B)}}(),V.planeClipsPositions3=function(e,t,i,s=3){for(let r=0,n=i.length;r<n;r+=s){if(k[0]=i[r+0]-e[0],k[1]=i[r+1]-e[1],k[2]=i[r+2]-e[2],k[0]*t[0]+k[1]*t[1]+k[2]*t[2]<0)return!0}return!1},V.planeIntersectsAABB3=(e,t)=>{const i=[t[0],t[1],t[2]],s=[t[3],t[4],t[5]],r=[[i[0],i[1],i[2]],[s[0],i[1],i[2]],[i[0],s[1],i[2]],[s[0],s[1],i[2]],[i[0],i[1],s[2]],[s[0],i[1],s[2]],[i[0],s[1],s[2]],[s[0],s[1],s[2]]];let n=!1,A=!1;for(const t of r){const i=e.dist+V.dotVec3(e.dir,t);if(i>0&&(n=!0),i<0&&(A=!0),n&&A)return!0}return!1},V.makeSectionPlaneSlicer=function(){const e=V.vec2(),t=V.vec2(),i=V.vec2(),s=V.vec2(),r=V.vec3(),n=V.vec3(),A=V.vec3();V.vec3();const a=[V.vec3(),V.vec3(),V.vec3()],l=[null,null,null],c=[null,null,null],h=[null,null,null],u=[1,0,0],d=[0,1,0],f=[0,0,1],p=function(){const e=V.vec3();return(t,i)=>V.sqLenVec3(V.subVec3(t,i,e))}(),g=e=>{const t=[];for(let i=0;i<e;++i)t.push(i);return t},m=(e,t,i)=>(i[1]-e[1])*(t[0]-e[0])>(t[1]-e[1])*(i[0]-e[0]);return function(_){const b=V.vec3ApplyQuaternion(_.quaternion,u,V.vec3()),B=V.vec3ApplyQuaternion(_.quaternion,d,V.vec3()),y=V.vec3ApplyQuaternion(_.quaternion,f,V.vec3());return function(u,d={}){const f=V.subVec3(u.origin,_.pos,V.vec3()),w=V.dotVec3(y,f),v=[],C=[null],M=(e,t)=>{const i=C.length,s=new Float64Array(5);return s.set(e),t&&(V.addVec3(f,e,r),s[3]=-V.dotVec3(b,r),s[4]=V.dotVec3(B,r)),C.push(s),i},E=(e,t)=>{const i=C[e];return t[0]=i[3],t[1]=i[4],t},F=(r,n)=>{const A=r.boundingBox,o=n.boundingBox;if(A[0]<o[0]||A[1]<o[1]||A[2]>o[2]||A[3]>o[3])return!1;const a=r.endPoints,l=n.endPoints;for(let r=0,n=a.length-1;r<a.length;n=r++){const A=E(a[r],e),[o,c]=A,h=E(a[n],t);let u=!1;for(let e=0,t=l.length-1;e<l.length;t=e++){const r=E(l[e],i),n=E(l[t],s);if(m(A,r,n)!==m(h,r,n)&&m(A,h,r)!==m(A,h,n))return!1;const[a,d]=r,[f,p]=n,g=o-a,_=c-d,b=f-a,B=p-d,y=(0!==b||0!==B)&&Math.abs(b*_-B*g)<1e-10?g*b+_*B:-1;if(y>=0&&y<=Math.pow(b,2)+Math.pow(B,2))return!1;d>c!=p>c&&g<_*b/B&&(u=!u)}if(!u)return!1}return!0},U={indices:[],normals:[]},x=!d.onlyPosSliceWithUV&&{indices:[],normals:[]},I=(e,t,i)=>{if(e){const s=C[t[0]];i||=V.normalizeVec3(V.cross3Vec3(V.subVec3(C[t[1]],s,r),V.subVec3(C[t[2]],s,n),r),r);for(let s=0;s<3;++s)e.indices.push(t[s]),e.normals.push(i[0],i[1],i[2])}},T=(e,t)=>{const i=3*u.indices[e];return t[0]=u.positions[i+0],t[1]=u.positions[i+1],t[2]=u.positions[i+2],t};for(let e=0;e<u.indices.length;e+=3){const t=T(e+0,a[0]),i=T(e+1,a[1]),s=T(e+2,a[2]);if(V.compareVec3(t,i)||V.compareVec3(i,s)||V.compareVec3(s,t))continue;const n=w+V.dotVec3(y,t),A=w+V.dotVec3(y,i),o=w+V.dotVec3(y,s);if(0!==n||0!==A||0!==o){const e=n*A<=0&&M(V.lerpVec3(n/(n-A),0,1,t,i,r),!0),a=A*o<=0&&M(V.lerpVec3(A/(A-o),0,1,i,s,r),!0),u=o*n<=0&&M(V.lerpVec3(o/(o-n),0,1,s,t,r),!0),f=!d.onlyPosSliceWithUV&&c;if(f&&(f[0]=M(t),f[1]=M(i),f[2]=M(s)),e?a||u:a&&u){if(v.push(e?[e,a||u]:[a,u]),f)if(0===n&&0===A)I(o>0?U:x,f);else if(0===n&&0===o)I(A>0?U:x,f);else if(0===A&&0===o)I(n>0?U:x,f);else{const t=(e?n:A)>0,i=t?U:x,s=t?x:U,r=l;r[0]=e,r[1]=a,r[2]=u;const o=h;e?(o[0]=0,o[1]=1,o[2]=2):(o[0]=1,o[1]=2,o[2]=0),r[o[1]]?(I(i,[f[o[0]],r[o[0]],f[o[2]]]),I(i,[r[o[0]],r[o[1]],f[o[2]]]),I(s,[r[o[0]],f[o[1]],r[o[1]]])):(I(i,[f[o[0]],r[o[0]],r[o[2]]]),I(s,[r[o[0]],f[o[1]],f[o[2]]]),I(s,[r[o[0]],f[o[2]],r[o[2]]]))}}else f&&(n>=0&&A>=0&&o>=0?I(U,f):n<=0&&A<=0&&o<=0&&I(x,f))}}const P=[];for(;v.length>0;){P.push([v[0][0],v[0][1]]);const e=P[P.length-1];for(v.splice(0,1);v.length>0;){const t=C[e[e.length-1]],i={distSq:p(C[e[0]],t),idx:-1,side:-1};if(v.forEach(((e,s)=>{const r=p(C[e[0]],t),n=p(C[e[1]],t),A=Math.min(r,n);i.distSq>A&&(i.distSq=A,i.idx=s,i.side=n<r?1:0)})),!(i.distSq<1e-20)){P.pop();break}{const s=i.idx>=0&&v[i.idx];if(C[s?s[i.side]:e[0]]=t,!s)break;{v.splice(i.idx,1);const t=s[1-i.side];if(!(p(C[t],C[e[0]])>1e-20))break;e.push(t)}}}}const S=P.filter((e=>e.length>2)).map(((i,s)=>{let r=0;const n=V.collapseAABB2(V.AABB2());for(let s=0;s<i.length;s++)E(i[s],e),V.expandAABB2Point2(n,e),E(i[(s+1)%i.length],t),r+=e[0]*t[1]-t[0]*e[1];return{boundingBox:n,doubleArea:Math.abs(r),endPoints:i}})).sort(((e,t)=>t.doubleArea-e.doubleArea));for(;S.length>0;){const t=[],i=[],s=s=>s.endPoints.forEach((s=>{E(s,e),t.push(e[0],e[1]),i.push(s)})),r=S.shift();s(r);const a=[];let c=0;for(;c<S.length;){const e=S[c];F(e,r)&&a.every((t=>!F(e,t)))?(e.index=t.length/2,s(e),a.push(e),S.splice(c,1)):++c}const h=o(t,a.map((e=>e.index)));for(let e=0;e<h.length;e+=3){const t=l;t[0]=i[h[e+0]],t[1]=i[h[e+1]],t[2]=i[h[e+2]];const s=C[t[0]];V.subVec3(C[t[1]],s,n),V.subVec3(C[t[2]],s,A),V.normalizeVec3(V.cross3Vec3(n,A,A),A);const r=V.dotVec3(A,y)<=0;I(r?U:x,t,A);const o=t[0];t[0]=t[2],t[2]=o,I(r?x:U,t,V.negateVec3(A,A))}}const D=e=>e&&e.indices.length>0&&function(){const t=[],i=d.onlyPosSliceWithUV&&[];return e.indices.forEach((e=>{const s=C[e];t.push(s[0],s[1],s[2]),i&&i.push(s[3],s[4])})),{indices:g(e.indices.length),positions:t,normals:e.normals,uv:i}}();return{pos:D(U),neg:D(x)}}}}();const L=new Float32Array(3);class H{constructor(e){if(!e)throw"Parameter expected: cfg";if(!e.viewer)throw"Parameter expected: cfg.viewer";this.viewer=e.viewer,this._maxTreeDepth=e.maxTreeDepth||15,this._root=null,this._needsRebuild=!0,this._onModelLoaded=this.viewer.scene.on("modelLoaded",(e=>{this._needsRebuild=!0})),this._onModelUnloaded=this.viewer.scene.on("modelUnloaded",(e=>{this._needsRebuild=!0}))}get root(){return this._needsRebuild&&this._rebuild(),this._root}_rebuild(){const e=this.viewer.scene;this._root={aabb:e.getAABB()};for(let t in e.objects){const i=e.objects[t];this._insertEntity(this._root,i,1)}this._needsRebuild=!1}_insertEntity(e,t,i){const s=t.aabb;if(i>=this._maxTreeDepth)return e.entities=e.entities||[],void e.entities.push(t);if(e.left&&V.containsAABB3(e.left.aabb,s))return void this._insertEntity(e.left,t,i+1);if(e.right&&V.containsAABB3(e.right.aabb,s))return void this._insertEntity(e.right,t,i+1);const r=e.aabb;L[0]=r[3]-r[0],L[1]=r[4]-r[1],L[2]=r[5]-r[2];let n=0;if(L[1]>L[n]&&(n=1),L[2]>L[n]&&(n=2),!e.left){const A=r.slice();if(A[n+3]=(r[n]+r[n+3])/2,e.left={aabb:A},V.containsAABB3(A,s))return void this._insertEntity(e.left,t,i+1)}if(!e.right){const A=r.slice();if(A[n]=(r[n]+r[n+3])/2,e.right={aabb:A},V.containsAABB3(A,s))return void this._insertEntity(e.right,t,i+1)}e.entities=e.entities||[],e.entities.push(t)}destroy(){const e=this.viewer.scene;e.off(this._onModelLoaded),e.off(this._onModelUnloaded),this._root=null,this._needsRebuild=!0}}class N{constructor(){this._head=[],this._headLength=0,this._tail=[],this._index=0,this._length=0}get length(){return this._length}shift(){if(this._index>=this._headLength){const e=this._head;if(e.length=0,this._head=this._tail,this._tail=e,this._index=0,this._headLength=this._head.length,!this._headLength)return}const e=this._head[this._index];return this._index<0?delete this._head[this._index++]:this._head[this._index++]=void 0,this._length--,e}push(e){return this._length++,this._tail.push(e),this}unshift(e){return this._head[--this._index]=e,this._length++,this}}const G={build:{version:"0.8"},client:{browser:navigator&&navigator.userAgent?navigator.userAgent:"n/a"},components:{scenes:0,models:0,meshes:0,objects:0},memory:{meshes:0,positions:0,colors:0,normals:0,uvs:0,indices:0,textures:0,transforms: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 j=[["0",10],["A",26],["a",26],["_",1],["$",1]].map((function(e){for(var t=[],i=e[0].charCodeAt(0),s=i+e[1],r=i;r<s;++r)t.push(r);return String.fromCharCode.apply(null,t)})).join("");function W(e,t){return(t&&4!==t?[0,6]:[0,6,12,18]).map((function(t){return j.substr(parseInt(e/(1<<t))%64,1)})).reverse().join("")}const z=function(){for(var e={},t=window.location.search.substring(1).split("&"),i=0;i<t.length;i++){var s=t[i].split("=");if(void 0===e[s[0]])e[s[0]]=decodeURIComponent(s[1]);else if("string"==typeof e[s[0]]){var r=[e[s[0]],decodeURIComponent(s[1])];e[s[0]]=r}else e[s[0]].push(decodeURIComponent(s[1]))}return e}();const X={xmlToJson:function e(t,i){if(t.nodeType===t.TEXT_NODE){var s=t.nodeValue;if(null===s.match(/^\s+$/))return s}else if(t.nodeType===t.ELEMENT_NODE||t.nodeType===t.DOCUMENT_NODE){var r={type:t.nodeName,children:[]};if(t.nodeType===t.ELEMENT_NODE)for(var n=0;n<t.attributes.length;n++){var A=t.attributes[n];r[i[A.nodeName]||A.nodeName]=A.nodeValue}for(var o=0;o<t.childNodes.length;o++){(n=e(t.childNodes[o],i))&&r.children.push(n)}return r}},clone:function(e){return JSON.parse(JSON.stringify(e))},compressGuid:function(e){var t=[0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30].map((function(t){return parseInt(e.substr(t,2),16)}));return W(t[0],2)+[1,4,7,10,13].map((function(e){return W((t[e]<<16)+(t[e+1]<<8)+t[e+2])})).join("")},findNodeOfType:function(e,t){var i=[],s=function(e){e.type===t&&i.push(e),(e.children||[]).forEach((function(e){s(e)}))};return s(e),i},timeout:function(e){return new Promise((function(t,i){setTimeout(t,e)}))},httpRequest:function(e){return new Promise((function(t,i){var s=new XMLHttpRequest;s.open(e.method||"GET",e.url,!0),s.onload=function(e){4===s.readyState&&(200===s.status?t(s.responseXML):i(s.statusText))},s.send(null)}))},loadJSON:function(e,t,i){var s=e=>{};t=t||s,i=i||s;var r=new XMLHttpRequest;r.overrideMimeType("application/json"),r.open("GET",e,!0),r.addEventListener("load",(function(e){var s=e.target.response;if(200===this.status){var r;try{r=JSON.parse(s)}catch(e){i(`utils.loadJSON(): Failed to parse JSON response - ${e}`)}t(r)}else if(0===this.status){console.warn("loadFile: HTTP Status 0 received.");try{t(JSON.parse(s))}catch(e){i(`utils.loadJSON(): Failed to parse JSON response - ${e}`)}}else i(e)}),!1),r.addEventListener("error",(function(e){i(e)}),!1),r.send(null)},loadArraybuffer:function(e,t,i){var s=e=>{};t=t||s,i=i||s;const r=e.match(/^data:(.*?)(;base64)?,(.*)$/);if(r){const e=!!r[2];var n=r[3];n=window.decodeURIComponent(n),e&&(n=window.atob(n));try{const e=new ArrayBuffer(n.length),i=new Uint8Array(e);for(var A=0;A<n.length;A++)i[A]=n.charCodeAt(A);ie.scheduleTask((()=>{t(e)}))}catch(e){ie.scheduleTask((()=>{i(e)}))}}else{const s=new XMLHttpRequest;s.open("GET",e,!0),s.responseType="arraybuffer",s.onreadystatechange=function(){4===s.readyState&&(200===s.status?t(s.response):i("loadArrayBuffer error : "+s.response))},s.send(null)}},queryString:z,isArray:function(e){return e&&!e.propertyIsEnumerable("length")&&"object"==typeof e&&"number"==typeof e.length},isString:function(e){return"string"==typeof e||e instanceof String},isNumeric:function(e){return!isNaN(parseFloat(e))&&isFinite(e)},isID:function(e){return X.isString(e)||X.isNumeric(e)},isSameComponent:function(e,t){return!(!e||!t)&&(X.isNumeric(e)||X.isString(e)?`${e}`:e.id)===(X.isNumeric(t)||X.isString(t)?`${t}`:t.id)},isFunction:function(e){return"function"==typeof e},isObject:function(e){const t={}.constructor;return!!e&&e.constructor===t},copy:function(e){return X.apply(e,{})},apply:function(e,t){for(const i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t},apply2:function(e,t){for(const i in e)e.hasOwnProperty(i)&&void 0!==e[i]&&null!==e[i]&&(t[i]=e[i]);return t},applyIf:function(e,t){for(const i in e)e.hasOwnProperty(i)&&(void 0!==t[i]&&null!==t[i]||(t[i]=e[i]));return t},isEmptyObject:function(e){for(const t in e)if(e.hasOwnProperty(t))return!1;return!0},inQuotes:function(e){return X.isNumeric(e)?`${e}`:`'${e}'`},concat:function(e,t){const i=new e.constructor(e.length+t.length);return i.set(e),i.set(t,e.length),i},flattenParentChildHierarchy:function(e){var t=[];return function e(i){i.id=i.uuid,delete i.oid,t.push(i);var s=i.children;if(s)for(var r=0,n=s.length;r<n;r++){s[r].parent=i.id,e(s[r])}i.children=[]}(e),t}},K={},Z=new e,J=new N,Y={sceneId:null,time:null,startTime:null,prevTime:null,deltaTime:null},$=[];let q,ee=0,te=0;const ie=new function(){this.version="1.0.0",this.scenes={},this._superTypes={},this._addScene=function(e){if(e.id){if(ie.scenes[e.id])return void console.error(`[ERROR] Scene ${X.inQuotes(e.id)} already exists`)}else e.id=Z.addItem({});ie.scenes[e.id]=e;const t=e.ticksPerOcclusionTest,i=e.ticksPerRender;K[e.id]={ticksPerOcclusionTest:t,ticksPerRender:i,renderCountdown:i},G.components.scenes++,e.once("destroyed",(()=>{Z.removeItem(e.id),delete ie.scenes[e.id],delete K[e.id],G.components.scenes--}))},this.clear=function(){let e;for(const t in ie.scenes)ie.scenes.hasOwnProperty(t)&&(e=ie.scenes[t],"default.scene"===t?e.clear():(e.destroy(),delete ie.scenes[e.id]))},this.scheduleTask=function(e,t=null){J.push(e),J.push(t)},this.runTasks=function(e=-1){let t,i,s=(new Date).getTime(),r=0;for(;J.length>0&&(e<0||s<e);)t=J.shift(),i=J.shift(),i?t.call(i):t(),s=(new Date).getTime(),r++;return r},this.getNumTasks=function(){return J.length}},se=function(){let e=Date.now();if(q=e-ee,ee>0&&q>0){var t=1e3/q;te+=t,$.push(t),$.length>=30&&(te-=$.shift()),G.frame.fps=Math.round(te/$.length)}for(let e in ie.scenes)ie.scenes[e].compile();ne(e),ee=e};!function(e,t){let i=Date.now()+t;(function s(){const r=Date.now()-i;e(),i+=t,setTimeout(s,Math.max(0,t-r))})()}((()=>{se()}),100);const re=function(){let e=Date.now();if(q=e-ee,ee>0&&q>0){var t=1e3/q;te+=t,$.push(t),$.length>=30&&(te-=$.shift()),G.frame.fps=Math.round(te/$.length)}ne(e),function(e){for(var t in Y.time=e,ie.scenes)if(ie.scenes.hasOwnProperty(t)){var i=ie.scenes[t];Y.sceneId=t,Y.startTime=i.startTime,Y.deltaTime=null!=Y.prevTime?Y.time-Y.prevTime:0,i.fire("tick",Y,!0)}Y.prevTime=e}(e),function(){const e=ie.scenes,t=!1;let i,s,r,n,A;for(A in e)e.hasOwnProperty(A)&&(i=e[A],s=K[A],s||(s=K[A]={}),r=i.ticksPerOcclusionTest,s.ticksPerOcclusionTest!==r&&(s.ticksPerOcclusionTest=r,s.renderCountdown=r),--i.occlusionTestCountdown<=0&&(i.doOcclusionTest(),i.occlusionTestCountdown=r),n=i.ticksPerRender,s.ticksPerRender!==n&&(s.ticksPerRender=n,s.renderCountdown=n),0==--s.renderCountdown&&(i.render(t),s.renderCountdown=n))}(),void 0!==window.requestPostAnimationFrame?window.requestPostAnimationFrame(se):requestAnimationFrame(re)};function ne(e){const t=ie.runTasks(e+10),i=ie.getNumTasks();G.frame.tasksRun=t,G.frame.tasksScheduled=i,G.frame.tasksBudget=10}re();class Ae{get type(){return"Component"}get isComponent(){return!0}constructor(e=null,t={}){if(this.scene=null,"Scene"===this.type)this.scene=this,this.viewer=t.viewer;else{if("Scene"===e.type)this.scene=e;else{if(!(e instanceof Ae))throw"Invalid param: owner must be a Component";this.scene=e.scene}this._owner=e}this._dontClear=!!t.dontClear,this._renderer=this.scene._renderer,this.meta=t.meta||{},this.id=t.id,this.destroyed=!1,this._attached={},this._attachments=null,this._subIdMap=null,this._subIdEvents=null,this._eventSubs=null,this._eventSubsNum=null,this._events=null,this._eventCallDepth=0,this._ownedComponents=null,this!==this.scene&&this.scene._addComponent(this),this._updateScheduled=!1,e&&e._own(this)}glRedraw(){this._renderer&&(this._renderer.imageDirty(),this.castsShadow&&this._renderer.shadowsDirty())}glResort(){this._renderer&&this._renderer.needStateSort()}get owner(){return this._owner}isType(e){return this.type===e}fire(e,t,i){this._events||(this._events={}),this._eventSubs||(this._eventSubs={},this._eventSubsNum={}),!0!==i&&(this._events[e]=t||!0);const s=this._eventSubs[e];let r;if(s)for(const i in s)s.hasOwnProperty(i)&&(r=s[i],this._eventCallDepth++,this._eventCallDepth<300?r.callback.call(r.scope,t):this.error("fire: potential stack overflow from recursive event '"+e+"' - dropping this event"),this._eventCallDepth--)}on(t,i,s){this._events||(this._events={}),this._subIdMap||(this._subIdMap=new e),this._subIdEvents||(this._subIdEvents={}),this._eventSubs||(this._eventSubs={}),this._eventSubsNum||(this._eventSubsNum={});let r=this._eventSubs[t];r?this._eventSubsNum[t]++:(r={},this._eventSubs[t]=r,this._eventSubsNum[t]=1);const n=this._subIdMap.addItem();r[n]={callback:i,scope:s||this},this._subIdEvents[n]=t;const A=this._events[t];return void 0!==A&&i.call(s||this,A),n}off(e){if(null==e)return;if(!this._subIdEvents)return;const t=this._subIdEvents[e];if(t){delete this._subIdEvents[e];const i=this._eventSubs[t];i&&(delete i[e],this._eventSubsNum[t]--),this._subIdMap.removeItem(e)}}once(e,t,i){const s=this,r=this.on(e,(function(e){s.off(r),t.call(i||this,e)}),i)}hasSubs(e){return this._eventSubsNum&&this._eventSubsNum[e]>0}log(e){e="[LOG]"+this._message(e),window.console.log(e),this.scene.fire("log",e)}_message(e){return" ["+this.type+" "+X.inQuotes(this.id)+"]: "+e}warn(e){e="[WARN]"+this._message(e),window.console.warn(e),this.scene.fire("warn",e)}error(e){e="[ERROR]"+this._message(e),window.console.error(e),this.scene.fire("error",e)}_attach(e){const t=e.name;if(!t)return void this.error("Component 'name' expected");let i=e.component;const s=e.sceneDefault,r=e.sceneSingleton,n=e.type,A=e.on,o=!1!==e.recompiles;if(i&&(X.isNumeric(i)||X.isString(i))){const e=i;if(i=this.scene.components[e],!i)return void this.error("Component not found: "+X.inQuotes(e))}if(!i)if(!0===r){const e=this.scene.types[n];for(const t in e)if(e.hasOwnProperty){i=e[t];break}if(!i)return this.error("Scene has no default component for '"+t+"'"),null}else if(!0===s&&(i=this.scene[t],!i))return this.error("Scene has no default component for '"+t+"'"),null;if(i){if(i.scene.id!==this.scene.id)return void this.error("Not in same scene: "+i.type+" "+X.inQuotes(i.id));if(n&&!i.isType(n))return void this.error("Expected a "+n+" type or subtype: "+i.type+" "+X.inQuotes(i.id))}this._attachments||(this._attachments={});const a=this._attached[t];let l,c,h;if(a){if(i&&a.id===i.id)return;const e=this._attachments[a.id];for(l=e.subs,c=0,h=l.length;c<h;c++)a.off(l[c]);delete this._attached[t],delete this._attachments[a.id];const s=e.params.onDetached;s&&(X.isFunction(s)?s(a):s.scope?s.callback.call(s.scope,a):s.callback(a)),e.managingLifecycle&&a.destroy()}if(i){const s={params:e,component:i,subs:[],managingLifecycle:false};s.subs.push(i.once("destroyed",(function(){s.params.component=null,this._attach(s.params)}),this)),o&&s.subs.push(i.on("dirty",(function(){this.fire("dirty",this)}),this)),this._attached[t]=i,this._attachments[i.id]=s;const r=e.onAttached;if(r&&(X.isFunction(r)?r(i):r.scope?r.callback.call(r.scope,i):r.callback(i)),A){let e,t,r,n;for(e in A)if(A.hasOwnProperty(e)){if(t=A[e],X.isFunction(t)?(r=t,n=null):(r=t.callback,n=t.scope),!r)continue;s.subs.push(i.on(e,r,n))}}}return o&&this.fire("dirty",this),this.fire(t,i),i}_checkComponent(e,t){if(!t.isComponent){if(!X.isID(t))return void this.error("Expected a Component or ID");{const e=t;if(!(t=this.scene.components[e]))return void this.error("Component not found: "+e)}}if(e===t.type){if(t.scene.id===this.scene.id)return t;this.error("Not in same scene: "+t.type)}else this.error("Expected a "+e+" Component")}_checkComponent2(e,t){if(!t.isComponent){if(!X.isID(t))return void this.error("Expected a Component or ID");{const e=t;if(!(t=this.scene.components[e]))return void this.error("Component not found: "+e)}}if(t.scene.id===this.scene.id){for(var i=0,s=e.length;i<s;i++)if(e[i]===t.type)return t;return this.error("Expected component types: "+e),null}this.error("Not in same scene: "+t.type)}_own(e){this._ownedComponents||(this._ownedComponents={}),this._ownedComponents[e.id]||(this._ownedComponents[e.id]=e),e.once("destroyed",(()=>{delete this._ownedComponents[e.id]}),this)}_needUpdate(e){this._updateScheduled||(this._updateScheduled=!0,0===e?this._doUpdate():ie.scheduleTask(this._doUpdate,this))}_doUpdate(){this._updateScheduled&&(this._updateScheduled=!1,this._update&&this._update())}scheduleTask(e){ie.scheduleTask(e,null)}_update(){}clear(){if(this._ownedComponents)for(var e in this._ownedComponents)if(this._ownedComponents.hasOwnProperty(e)){this._ownedComponents[e].destroy(),delete this._ownedComponents[e]}}destroy(){if(this.destroyed)return;let e,t,i,s,r,n;if(this.fire("destroyed",this.destroyed=!0),this._attachments)for(e in this._attachments)if(this._attachments.hasOwnProperty(e)){for(t=this._attachments[e],i=t.component,s=t.subs,r=0,n=s.length;r<n;r++)i.off(s[r]);t.managingLifecycle&&i.destroy()}if(this._ownedComponents)for(e in this._ownedComponents)this._ownedComponents.hasOwnProperty(e)&&(i=this._ownedComponents[e],i.destroy(),delete this._ownedComponents[e]);this.scene._removeComponent(this),this._attached={},this._attachments=null,this._subIdMap=null,this._subIdEvents=null,this._eventSubs=null,this._events=null,this._eventCallDepth=0,this._ownedComponents=null,this._updateScheduled=!1,this._renderer=null}}const oe=V.vec3(),ae=V.vec3(),le=V.mat4();class ce{constructor(){this.normal=V.vec3(),this.offset=0,this.testVertex=V.vec3()}set(e,t,i,s){const r=1/Math.sqrt(e*e+t*t+i*i);this.normal[0]=e*r,this.normal[1]=t*r,this.normal[2]=i*r,this.offset=s*r,this.testVertex[0]=this.normal[0]>=0?1:0,this.testVertex[1]=this.normal[1]>=0?1:0,this.testVertex[2]=this.normal[2]>=0?1:0}}class he{constructor(){this.planes=[new ce,new ce,new ce,new ce,new ce,new ce]}}function ue(e,t,i){const s=V.mulMat4(i,t,le),r=s[0],n=s[1],A=s[2],o=s[3],a=s[4],l=s[5],c=s[6],h=s[7],u=s[8],d=s[9],f=s[10],p=s[11],g=s[12],m=s[13],_=s[14],b=s[15];e.planes[0].set(o-r,h-a,p-u,b-g),e.planes[1].set(o+r,h+a,p+u,b+g),e.planes[2].set(o-n,h-l,p-d,b-m),e.planes[3].set(o+n,h+l,p+d,b+m),e.planes[4].set(o-A,h-c,p-f,b-_),e.planes[5].set(o+A,h+c,p+f,b+_)}function de(e,t){let i=he.INSIDE;const s=oe,r=ae;s[0]=t[0],s[1]=t[1],s[2]=t[2],r[0]=t[3],r[1]=t[4],r[2]=t[5];const n=[s,r];for(let t=0;t<6;++t){const s=e.planes[t];if(s.normal[0]*n[s.testVertex[0]][0]+s.normal[1]*n[s.testVertex[1]][1]+s.normal[2]*n[s.testVertex[2]][2]+s.offset<0)return he.OUTSIDE;s.normal[0]*n[1-s.testVertex[0]][0]+s.normal[1]*n[1-s.testVertex[1]][1]+s.normal[2]*n[1-s.testVertex[2]][2]+s.offset<0&&(i=he.INTERSECT)}return i}he.INSIDE=0,he.INTERSECT=1,he.OUTSIDE=2;class fe extends Ae{constructor(e={}){if(!e.viewer)throw"[MarqueePicker] Missing config: viewer";if(!e.objectsKdTree3)throw"[MarqueePicker] Missing config: objectsKdTree3";super(e.viewer.scene,e),this.viewer=e.viewer,this._objectsKdTree3=e.objectsKdTree3,this._canvasMarqueeCorner1=V.vec2(),this._canvasMarqueeCorner2=V.vec2(),this._canvasMarquee=V.AABB2(),this._marqueeFrustum=new he,this._marqueeFrustumProjMat=V.mat4(),this._pickMode=!1,this._marqueeElement=document.createElement("div"),document.body.appendChild(this._marqueeElement),this._marqueeElement.style.position="absolute",this._marqueeElement.style["z-index"]="40000005",this._marqueeElement.style.width="8px",this._marqueeElement.style.height="8px",this._marqueeElement.style.visibility="hidden",this._marqueeElement.style.top="0px",this._marqueeElement.style.left="0px",this._marqueeElement.style["box-shadow"]="0 2px 5px 0 #182A3D;",this._marqueeElement.style.opacity=1,this._marqueeElement.style["pointer-events"]="none"}setMarqueeCorner1(e){this._canvasMarqueeCorner1.set(e),this._canvasMarqueeCorner2.set(e),this._updateMarquee()}setMarqueeCorner2(e){this._canvasMarqueeCorner2.set(e),this._updateMarquee()}setMarquee(e,t){this._canvasMarqueeCorner1.set(e),this._canvasMarqueeCorner2.set(t),this._updateMarquee()}setMarqueeVisible(e){this._marqueVisible=e,this._marqueeElement.style.visibility=e?"visible":"hidden"}getMarqueeVisible(){return this._marqueVisible}setPickMode(e){if(e!==fe.PICK_MODE_INSIDE&&e!==fe.PICK_MODE_INTERSECTS)throw"Illegal MarqueePicker pickMode: must be MarqueePicker.PICK_MODE_INSIDE or MarqueePicker.PICK_MODE_INTERSECTS";e!==this._pickMode&&(this._marqueeElement.style["background-image"]=e===fe.PICK_MODE_INSIDE?"url(\"data:image/svg+xml,%3csvg width='100%25' height='100%25' xmlns='http://www.w3.org/2000/svg'%3e%3crect width='100%25' height='100%25' fill='none' rx='6' ry='6' stroke='%23333' stroke-width='4'/%3e%3c/svg%3e\")":"url(\"data:image/svg+xml,%3csvg width='100%25' height='100%25' xmlns='http://www.w3.org/2000/svg'%3e%3crect width='100%25' height='100%25' fill='none' rx='6' ry='6' stroke='%23333' stroke-width='4' stroke-dasharray='6%2c 14' stroke-dashoffset='0' stroke-linecap='square'/%3e%3c/svg%3e\")",this._pickMode=e)}getPickMode(){return this._pickMode}clear(){this.fire("clear",{})}pick(){this._updateMarquee(),this._buildMarqueeFrustum();const e=[],t=(i,s=he.INTERSECT)=>{if(s===he.INTERSECT&&(s=de(this._marqueeFrustum,i.aabb)),s!==he.OUTSIDE){if(i.entities){const t=i.entities;for(let i=0,s=t.length;i<s;i++){const s=t[i];if(!s.visible)continue;const r=s.aabb;if(this._pickMode===fe.PICK_MODE_INSIDE){de(this._marqueeFrustum,r)===he.INSIDE&&e.push(s.id)}else{de(this._marqueeFrustum,r)!==he.OUTSIDE&&e.push(s.id)}}}i.left&&t(i.left,s),i.right&&t(i.right,s)}};return(this._canvasMarquee[2]-this._canvasMarquee[0]>3||this._canvasMarquee[3]-this._canvasMarquee[1]>3)&&t(this._objectsKdTree3.root),this.fire("picked",e),e}_updateMarquee(){this._canvasMarquee[0]=Math.min(this._canvasMarqueeCorner1[0],this._canvasMarqueeCorner2[0]),this._canvasMarquee[1]=Math.min(this._canvasMarqueeCorner1[1],this._canvasMarqueeCorner2[1]),this._canvasMarquee[2]=Math.max(this._canvasMarqueeCorner1[0],this._canvasMarqueeCorner2[0]),this._canvasMarquee[3]=Math.max(this._canvasMarqueeCorner1[1],this._canvasMarqueeCorner2[1]),this._marqueeElement.style.width=this._canvasMarquee[2]-this._canvasMarquee[0]+"px",this._marqueeElement.style.height=this._canvasMarquee[3]-this._canvasMarquee[1]+"px",this._marqueeElement.style.left=`${this._canvasMarquee[0]}px`,this._marqueeElement.style.top=`${this._canvasMarquee[1]}px`}_buildMarqueeFrustum(){const e=this.viewer.scene.canvas.canvas,t=e.clientWidth,i=e.clientHeight,s=e.clientLeft,r=e.clientTop,n=2/t,A=2/i,o=e.clientHeight/e.clientWidth,a=(this._canvasMarquee[0]-s)*n-1,l=(this._canvasMarquee[2]-s)*n-1,c=-(this._canvasMarquee[3]-r)*A+1,h=-(this._canvasMarquee[1]-r)*A+1,u=this.viewer.scene.camera.frustum.near*(17*o);V.frustumMat4(a,l,c*o,h*o,u,1e4,this._marqueeFrustumProjMat),ue(this._marqueeFrustum,this.viewer.scene.camera.viewMatrix,this._marqueeFrustumProjMat)}destroy(){super.destroy(),this._marqueeElement.parentElement&&(this._marqueeElement.parentElement.removeChild(this._marqueeElement),this._marqueeElement=null,this._objectsKdTree3=null)}}fe.PICK_MODE_INTERSECTS=0,fe.PICK_MODE_INSIDE=1;class pe extends Ae{constructor(e){super(e.marqueePicker,e);const t=e.marqueePicker,i=t.viewer.scene.canvas.canvas;let s,r,n,A,o,a,l,c=!1,h=!1,u=!1;i.addEventListener("mousedown",(e=>{this.getActive()&&0===e.button&&(l=setTimeout((function(){const n=t.viewer.scene.input;n.keyDown[n.KEY_CTRL]||t.clear(),s=e.pageX,r=e.pageY,o=e.offsetX,t.setMarqueeCorner1([s,r]),c=!0,t.viewer.cameraControl.pointerEnabled=!1,t.setMarqueeVisible(!0),i.style.cursor="crosshair"}),400),h=!0)})),i.addEventListener("mouseup",(e=>{if(!this.getActive())return;if(!c&&!u)return;if(0!==e.button)return;clearTimeout(l),n=e.pageX,A=e.pageY;const i=Math.abs(n-s),o=Math.abs(A-r);c=!1,t.viewer.cameraControl.pointerEnabled=!0,u&&(u=!1),(i>3||o>3)&&t.pick()})),document.addEventListener("mouseup",(e=>{this.getActive()&&0===e.button&&(clearTimeout(l),c&&(t.setMarqueeVisible(!1),c=!1,h=!1,u=!0,t.viewer.cameraControl.pointerEnabled=!0))}),!0),i.addEventListener("mousemove",(e=>{this.getActive()&&0===e.button&&h&&(clearTimeout(l),c&&(n=e.pageX,A=e.pageY,a=e.offsetX,t.setMarqueeVisible(!0),t.setMarqueeCorner2([n,A]),t.setPickMode(o<a?fe.PICK_MODE_INSIDE:fe.PICK_MODE_INTERSECTS)))}))}setActive(e){this._active!==e&&(this._active=e,this.fire("active",this._active))}getActive(){return this._active}destroy(){}}class ge{constructor(e,t={}){this.viewer=e,this.scene=this.viewer.scene,this._circleDiv=document.createElement("div"),this.viewer.scene.canvas.canvas.parentNode.insertBefore(this._circleDiv,this.viewer.scene.canvas.canvas),this._circleDiv.style.backgroundColor="transparent",this._circleDiv.style.border="2px solid green",this._circleDiv.style.borderRadius="50px",this._circleDiv.style.width="50px",this._circleDiv.style.height="50px",this._circleDiv.style.margin="-200px -200px",this._circleDiv.style.zIndex="100000",this._circleDiv.style.position="absolute",this._circleDiv.style.pointerEvents="none",this._circlePos=null,this._circleMaxRadius=200,this._circleMinRadius=2,this._active=!1!==t.active,this._visible=!1,this._running=!1,this._destroyed=!1}start(e){if(this._destroyed)return;this._circlePos=e,this._running=!1,this._circleRadius=this._circleMaxRadius,this._circleDiv.style.borderRadius=`${this._circleRadius}px`,this._circleDiv.style.marginLeft=this._circlePos[0]-this._circleRadius+"px",this._circleDiv.style.marginTop=this._circlePos[1]-this._circleRadius+"px";const t=this._circleMaxRadius;let i;const s=e=>{if(!this._running)return;i||(i=e);const r=e-i,n=Math.min(r/300,1),A=t+(2-t)*n;this._circleRadius=A,this._circleDiv.style.width=`${this._circleRadius}px`,this._circleDiv.style.height=`${this._circleRadius}px`,this._circleDiv.style.marginLeft=this._circlePos[0]-this._circleRadius/2+"px",this._circleDiv.style.marginTop=this._circlePos[1]-this._circleRadius/2+"px",n<1&&requestAnimationFrame(s)};this._running=!0,requestAnimationFrame(s),this._circleDiv.style.visibility="visible"}stop(){this._destroyed||(this._running=!1,this._circleRadius=this._circleMaxRadius,this._circleDiv.style.borderRadius=`${this._circleRadius}px`,this._circleDiv.style.visibility="hidden")}set durationMs(e){this.stop(),this._durationMs=e}get durationMs(){return this._durationMs}destroy(){this._destroyed||(this.stop(),this._circleDiv.parentElement.removeChild(this._circleDiv),this._destroyed=!0)}}class me{constructor(e={}){this._eventSubIDMap=null,this._eventSubEvents=null,this._eventSubs=null,this._events=null,this._locale="en",this._messages={},this._locales=[],this._locale="en",this.messages=e.messages,this.locale=e.locale}set messages(e){this._messages=e||{},this._locales=Object.keys(this._messages),this.fire("updated",this)}loadMessages(e={}){for(let t in e)this._messages[t]=e[t];this.messages=this._messages}clearMessages(){this.messages={}}get locales(){return this._locales}set locale(e){e=e||"de",this._locale!==e&&(this._locale=e,this.fire("updated",e))}get locale(){return this._locale}translate(e,t){const i=this._messages[this._locale];if(!i)return null;const s=_e(e,i);return s?t?be(s,t):s:null}translatePlurals(e,t,i){const s=this._messages[this._locale];if(!s)return null;let r=_e(e,s);return r=0===(t=parseInt(""+t,10))?r.zero:t>1?r.other:r.one,r?(r=be(r,[t]),i&&(r=be(r,i)),r):null}fire(e,t,i){this._events||(this._events={}),this._eventSubs||(this._eventSubs={}),!0!==i&&(this._events[e]=t||!0);const s=this._eventSubs[e];if(s)for(const e in s)if(s.hasOwnProperty(e)){s[e].callback(t)}}on(t,i){this._events||(this._events={}),this._eventSubIDMap||(this._eventSubIDMap=new e),this._eventSubEvents||(this._eventSubEvents={}),this._eventSubs||(this._eventSubs={});let s=this._eventSubs[t];s||(s={},this._eventSubs[t]=s);const r=this._eventSubIDMap.addItem();s[r]={callback:i},this._eventSubEvents[r]=t;const n=this._events[t];return void 0!==n&&i(n),r}off(e){if(null==e)return;if(!this._eventSubEvents)return;const t=this._eventSubEvents[e];if(t){delete this._eventSubEvents[e];const i=this._eventSubs[t];i&&delete i[e],this._eventSubIDMap.removeItem(e)}}}function _e(e,t){if(t[e])return t[e];const i=e.split(".");let s=t;for(let e=0,t=i.length;s&&e<t;e++){s=s[i[e]]}return s}function be(e,t=[]){return e.replace(/\{\{|\}\}|\{(\d+)\}/g,(function(e,i){return"{{"===e?"{":"}}"===e?"}":t[i]}))}class Be extends Ae{constructor(e,t={}){super(e,t),this.t=t.t}set t(e){e=e||0,this._t=e<0?0:e>1?1:e}get t(){return this._t}get tangent(){return this.getTangent(this._t)}get length(){var e=this._getLengths();return e[e.length-1]}getTangent(e){var t=1e-4;void 0===e&&(e=this._t);var i=e-t,s=e+t;i<0&&(i=0),s>1&&(s=1);var r=this.getPoint(i),n=this.getPoint(s),A=V.subVec3(n,r,[]);return V.normalizeVec3(A,[])}getPointAt(e){var t=this.getUToTMapping(e);return this.getPoint(t)}getPoints(e){e||(e=5);var t,i=[];for(t=0;t<=e;t++)i.push(this.getPoint(t/e));return i}_getLengths(e){if(e||(e=this.__arcLengthDivisions?this.__arcLengthDivisions:200),this.cacheArcLengths&&this.cacheArcLengths.length===e+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=!1;var t,i,s=[],r=this.getPoint(0),n=0;for(s.push(0),i=1;i<=e;i++)t=this.getPoint(i/e),n+=V.lenVec3(V.subVec3(t,r,[])),s.push(n),r=t;return this.cacheArcLengths=s,s}_updateArcLengths(){this.needsUpdate=!0,this._getLengths()}getUToTMapping(e,t){var i,s=this._getLengths(),r=0,n=s.length;i=t||e*s[n-1];for(var A,o=0,a=n-1;o<=a;)if((A=s[r=Math.floor(o+(a-o)/2)]-i)<0)o=r+1;else{if(!(A>0)){a=r;break}a=r-1}if(s[r=a]===i)return r/(n-1);var l=s[r];return(r+(i-l)/(s[r+1]-l))/(n-1)}}class ye extends Be{constructor(e,t={}){super(e,t),this.points=t.points,this.t=t.t}set points(e){this._points=e||[]}get points(){return this._points}set t(e){e=e||0,this._t=e<0?0:e>1?1:e}get t(){return this._t}get point(){return this.getPoint(this._t)}getPoint(e){var t=this.points;if(!(t.length<3)){var i=(t.length-1)*e,s=Math.floor(i),r=i-s,n=t[0===s?s:s-1],A=t[s],o=t[s>t.length-2?t.length-1:s+1],a=t[s>t.length-3?t.length-1:s+2],l=V.vec3();return l[0]=V.catmullRomInterpolate(n[0],A[0],o[0],a[0],r),l[1]=V.catmullRomInterpolate(n[1],A[1],o[1],a[1],r),l[2]=V.catmullRomInterpolate(n[2],A[2],o[2],a[2],r),l}this.error("Can't sample point from SplineCurve - not enough points on curve - returning [0,0,0].")}getJSON(){return{points:points,t:this._t}}}const we=V.vec3();class ve extends Ae{get type(){return"CameraPath"}constructor(e,t={}){super(e,t),this._frames=[],this._eyeCurve=new ye(this),this._lookCurve=new ye(this),this._upCurve=new ye(this),t.frames&&(this.addFrames(t.frames),this.smoothFrameTimes(1))}get frames(){return this._frames}get eyeCurve(){return this._eyeCurve}get lookCurve(){return this._lookCurve}get upCurve(){return this._upCurve}saveFrame(e){const t=this.scene.camera;this.addFrame(e,t.eye,t.look,t.up)}addFrame(e,t,i,s){const r={t:e,eye:t.slice(0),look:i.slice(0),up:s.slice(0)};this._frames.push(r),this._eyeCurve.points.push(r.eye),this._lookCurve.points.push(r.look),this._upCurve.points.push(r.up)}addFrames(e){let t;for(let i=0,s=e.length;i<s;i++)t=e[i],this.addFrame(t.t||0,t.eye,t.look,t.up)}loadFrame(e){const t=this.scene.camera;e=(e/=this._frames[this._frames.length-1].t-this._frames[0].t)<0?0:e>1?1:e,t.eye=this._eyeCurve.getPoint(e,we),t.look=this._lookCurve.getPoint(e,we),t.up=this._upCurve.getPoint(e,we)}sampleFrame(e,t,i,s){e=e<0?0:e>1?1:e,this._eyeCurve.getPoint(e,t),this._lookCurve.getPoint(e,i),this._upCurve.getPoint(e,s)}smoothFrameTimes(e){if(0===this._frames.length)return;const t=V.vec3();var i=0;this._frames[0].t=0;const s=[];for(let e=1,n=this._frames.length;e<n;e++){var r=V.lenVec3(V.subVec3(this._frames[e].eye,this._frames[e-1].eye,t));s[e]=r,i+=r}for(let t=1,r=this._frames.length;t<r;t++){const r=s[t]/i*e;this._frames[t].t=this._frames[t-1].t+r}}clearFrames(){this._frames=[],this._eyeCurve.points=[],this._lookCurve.points=[],this._upCurve.points=[]}}const Ce=V.vec3(),Me=V.vec3(),Ee=V.vec3(),Fe=V.vec3(),Ue=V.vec3();class xe extends Ae{get type(){return"CameraFlightAnimation"}constructor(e,t={}){super(e,t),this._look1=V.vec3(),this._eye1=V.vec3(),this._up1=V.vec3(),this._look2=V.vec3(),this._eye2=V.vec3(),this._up2=V.vec3(),this._orthoScale1=1,this._orthoScale2=1,this._flying=!1,this._flyEyeLookUp=!1,this._flyingEye=!1,this._flyingLook=!1,this._callback=null,this._callbackScope=null,this._time1=null,this._time2=null,this.easing=!1!==t.easing,this.duration=t.duration,this.fit=t.fit,this.fitFOV=t.fitFOV,this.trail=t.trail}flyTo(e,t,i){e=e||this.scene,this._flying&&this.stop(),this._flying=!1,this._flyingEye=!1,this._flyingLook=!1,this._flyingEyeLookUp=!1,this._callback=t,this._callbackScope=i;const s=this.scene.camera,r=!!e.projection&&e.projection!==s.projection;let n,A,o,a,l;if(this._eye1[0]=s.eye[0],this._eye1[1]=s.eye[1],this._eye1[2]=s.eye[2],this._look1[0]=s.look[0],this._look1[1]=s.look[1],this._look1[2]=s.look[2],this._up1[0]=s.up[0],this._up1[1]=s.up[1],this._up1[2]=s.up[2],this._orthoScale1=s.ortho.scale,this._orthoScale2=e.orthoScale||this._orthoScale1,e.aabb)n=e.aabb;else if(6===e.length)n=e;else if(e.eye&&e.look||e.up)A=e.eye,o=e.look,a=e.up;else if(e.eye)A=e.eye;else if(e.look)o=e.look;else{let s=e;if((X.isNumeric(s)||X.isString(s))&&(l=s,s=this.scene.components[l],!s))return this.error("Component not found: "+X.inQuotes(l)),void(t&&(i?t.call(i):t()));r||(n=s.aabb||this.scene.aabb)}const c=e.poi;if(n){if(n[3]<n[0]||n[4]<n[1]||n[5]<n[2])return;if(n[3]===n[0]&&n[4]===n[1]&&n[5]===n[2])return;n=n.slice();const t=V.getAABB3Center(n);this._look2=c||t;const i=V.subVec3(this._eye1,this._look1,Ce),s=V.normalizeVec3(i),r=c?V.getAABB3DiagPoint(n,c):V.getAABB3Diag(n),A=e.fitFOV||this._fitFOV,o=Math.abs(r/Math.tan(A*V.DEGTORAD));this._orthoScale2=1.1*r,this._eye2[0]=this._look2[0]+s[0]*o,this._eye2[1]=this._look2[1]+s[1]*o,this._eye2[2]=this._look2[2]+s[2]*o,this._up2[0]=this._up1[0],this._up2[1]=this._up1[1],this._up2[2]=this._up1[2],this._flyingEyeLookUp=!0}else(A||o||a)&&(this._flyingEyeLookUp=!!A&&!!o&&!!a,this._flyingEye=!!A&&!o,this._flyingLook=!!o&&!A,A&&(this._eye2[0]=A[0],this._eye2[1]=A[1],this._eye2[2]=A[2]),o&&(this._look2[0]=o[0],this._look2[1]=o[1],this._look2[2]=o[2]),a&&(this._up2[0]=a[0],this._up2[1]=a[1],this._up2[2]=a[2]));r?("ortho"===e.projection&&"ortho"!==s.projection&&(this._projection2="ortho",this._projMatrix1=s.projMatrix.slice(),this._projMatrix2=s.ortho.matrix.slice(),s.projection="customProjection"),"perspective"===e.projection&&"perspective"!==s.projection&&(this._projection2="perspective",this._projMatrix1=s.projMatrix.slice(),this._projMatrix2=s.perspective.matrix.slice(),s.projection="customProjection")):this._projection2=null,this.fire("started",e,!0),this._time1=Date.now(),this._time2=this._time1+(Number.isFinite(e.duration)?1e3*e.duration:this._duration),this._flying=!0,ie.scheduleTask(this._update,this)}jumpTo(e){this._jumpTo(e)}_jumpTo(e){this._flying&&this.stop();const t=this.scene.camera;var i,s,r,n,A;if(e.aabb)i=e.aabb;else if(6===e.length)i=e;else if(e.eye||e.look||e.up)r=e.eye,n=e.look,A=e.up;else{let t=e;if((X.isNumeric(t)||X.isString(t))&&(s=t,t=this.scene.components[s],!t))return void this.error("Component not found: "+X.inQuotes(s));i=t.aabb||this.scene.aabb}const o=e.poi;if(i){if(i[3]<=i[0]||i[4]<=i[1]||i[5]<=i[2])return;var a=o?V.getAABB3DiagPoint(i,o):V.getAABB3Diag(i);let s;n=o||V.getAABB3Center(i,n),this._trail?V.subVec3(t.look,n,Ue):V.subVec3(t.eye,t.look,Ue),V.normalizeVec3(Ue);s=(void 0!==e.fit?e.fit:this._fit)?Math.abs(a/Math.tan((e.fitFOV||this._fitFOV)*V.DEGTORAD)):V.lenVec3(V.subVec3(t.eye,t.look,Ce)),V.mulVec3Scalar(Ue,s),t.eye=V.addVec3(n,Ue,Ce),t.look=n,this.scene.camera.ortho.scale=1.1*a}else(r||n||A)&&(r&&(t.eye=r),n&&(t.look=n),A&&(t.up=A));e.projection&&(t.projection=e.projection)}_update(){if(!this._flying)return;let e=(Date.now()-this._time1)/(this._time2-this._time1);const t=e>=1;e>1&&(e=1);const i=this.easing?xe._ease(e,0,1,1):e,s=this.scene.camera;if(this._flyingEye||this._flyingLook?this._flyingEye?(V.subVec3(s.eye,s.look,Ue),s.eye=V.lerpVec3(i,0,1,this._eye1,this._eye2,Ee),s.look=V.subVec3(Ee,Ue,Me)):this._flyingLook&&(s.look=V.lerpVec3(i,0,1,this._look1,this._look2,Me),s.up=V.lerpVec3(i,0,1,this._up1,this._up2,Fe)):this._flyingEyeLookUp&&(s.eye=V.lerpVec3(i,0,1,this._eye1,this._eye2,Ee),s.look=V.lerpVec3(i,0,1,this._look1,this._look2,Me),s.up=V.lerpVec3(i,0,1,this._up1,this._up2,Fe)),this._projection2){const t="ortho"===this._projection2?xe._easeOutExpo(e,0,1,1):xe._easeInCubic(e,0,1,1);s.customProjection.matrix=V.lerpMat4(t,0,1,this._projMatrix1,this._projMatrix2)}else s.ortho.scale=this._orthoScale1+e*(this._orthoScale2-this._orthoScale1);if(t)return s.ortho.scale=this._orthoScale2,void this.stop();ie.scheduleTask(this._update,this)}static _ease(e,t,i,s){return-i*(e/=s)*(e-2)+t}static _easeInCubic(e,t,i,s){return i*(e/=s)*e*e+t}static _easeOutExpo(e,t,i,s){return i*(1-Math.pow(2,-10*e/s))+t}stop(){if(!this._flying)return;this._flying=!1,this._time1=null,this._time2=null,this._projection2&&(this.scene.camera.projection=this._projection2);const e=this._callback;e&&(this._callback=null,this._callbackScope?e.call(this._callbackScope):e()),this.fire("stopped",!0,!0)}cancel(){this._flying&&(this._flying=!1,this._time1=null,this._time2=null,this._callback&&(this._callback=null),this.fire("canceled",!0,!0))}set duration(e){this._duration=Number.isFinite(e)?1e3*e:500,this.stop()}get duration(){return this._duration/1e3}set fit(e){this._fit=!1!==e}get fit(){return this._fit}set fitFOV(e){this._fitFOV=e||45}get fitFOV(){return this._fitFOV}set trail(e){this._trail=!!e}get trail(){return this._trail}destroy(){this.stop(),super.destroy()}}class Ie extends Ae{get type(){return"CameraPathAnimation"}constructor(e,t={}){super(e,t),this._cameraFlightAnimation=new xe(this),this._t=0,this.state=Ie.SCRUBBING,this._playingFromT=0,this._playingToT=0,this._playingRate=t.playingRate||1,this._playingDir=1,this._lastTime=null,this.cameraPath=t.cameraPath,this._tick=this.scene.on("tick",this._updateT,this)}_updateT(){const e=this._cameraPath;if(!e)return;let t,i;const s=performance.now(),r=this._lastTime?.001*(s-this._lastTime):0;if(this._lastTime=s,0!==r)switch(this.state){case Ie.SCRUBBING:return;case Ie.PLAYING:if(this._t+=this._playingRate*r,t=this._cameraPath.frames.length,0===t||this._playingDir<0&&this._t<=0||this._playingDir>0&&this._t>=this._cameraPath.frames[t-1].t)return this.state=Ie.SCRUBBING,this._t=this._cameraPath.frames[t-1].t,void this.fire("stopped");e.loadFrame(this._t);break;case Ie.PLAYING_TO:i=this._t+this._playingRate*r*this._playingDir,(this._playingDir<0&&i<=this._playingToT||this._playingDir>0&&i>=this._playingToT)&&(i=this._playingToT,this.state=Ie.SCRUBBING,this.fire("stopped")),this._t=i,e.loadFrame(this._t)}}_ease(e,t,i,s){return-i*(e/=s)*(e-2)+t}set cameraPath(e){this._cameraPath=e}get cameraPath(){return this._cameraPath}set rate(e){this._playingRate=e}get rate(){return this._playingRate}play(){this._cameraPath&&(this._lastTime=null,this.state=Ie.PLAYING)}playToT(e){this._cameraPath&&(this._playingFromT=this._t,this._playingToT=e,this._playingDir=this._playingToT-this._playingFromT<0?-1:1,this._lastTime=null,this.state=Ie.PLAYING_TO)}playToFrame(e){const t=this._cameraPath;if(!t)return;const i=t.frames[e];i?this.playToT(i.t):this.error("playToFrame - frame index out of range: "+e)}flyToFrame(e,t){const i=this._cameraPath;if(!i)return;const s=i.frames[e];s?(this.state=Ie.SCRUBBING,this._cameraFlightAnimation.flyTo(s,t)):this.error("flyToFrame - frame index out of range: "+e)}scrubToT(e){const t=this._cameraPath;if(!t)return;this.scene.camera&&(this._t=e,t.loadFrame(this._t),this.state=Ie.SCRUBBING)}scrubToFrame(e){const t=this._cameraPath;if(!t)return;if(!this.scene.camera)return;t.frames[e]?(t.loadFrame(this._t),this.state=Ie.SCRUBBING):this.error("playToFrame - frame index out of range: "+e)}stop(){this.state=Ie.SCRUBBING,this.fire("stopped")}destroy(){super.destroy(),this.scene.off(this._tick)}}Ie.STOPPED=0,Ie.SCRUBBING=1,Ie.PLAYING=2,Ie.PLAYING_TO=3;class Te extends Ae{get type(){return"Geometry"}get isGeometry(){return!0}constructor(e,t={}){super(e,t),G.memory.meshes++}destroy(){super.destroy(),G.memory.meshes--}}const Pe=new e({});class Se{constructor(e){this.id=Pe.addItem({});for(const t in e)e.hasOwnProperty(t)&&(this[t]=e[t])}destroy(){Pe.removeItem(this.id)}}class De{constructor(e,t,i,s,r,n,A,o,a){switch(this._gl=e,this.type=t,this.allocated=!1,i.constructor){case Uint8Array:this.itemType=e.UNSIGNED_BYTE,this.itemByteSize=1;break;case Int8Array:this.itemType=e.BYTE,this.itemByteSize=1;break;case Uint16Array:this.itemType=e.UNSIGNED_SHORT,this.itemByteSize=2;break;case Int16Array:this.itemType=e.SHORT,this.itemByteSize=2;break;case Uint32Array:this.itemType=e.UNSIGNED_INT,this.itemByteSize=4;break;case Int32Array:this.itemType=e.INT,this.itemByteSize=4;break;default:this.itemType=e.FLOAT,this.itemByteSize=4}this.usage=n,this.length=0,this.dataLength=s,this.numItems=0,this.itemSize=r,this.normalized=!!A,this.stride=o||0,this.offset=a||0,this._allocate(i)}_allocate(e){if(this.allocated=!1,this._handle=this._gl.createBuffer(),!this._handle)throw"Failed to allocate WebGL ArrayBuffer";this._handle&&(this._gl.bindBuffer(this.type,this._handle),this._gl.bufferData(this.type,e.length>this.dataLength?e.slice(0,this.dataLength):e,this.usage),this._gl.bindBuffer(this.type,null),this.length=e.length,this.numItems=this.length/this.itemSize,this.allocated=!0)}setData(e,t){this.allocated&&(e.length+(t||0)>this.length?(this.destroy(),this._allocate(e)):(this._gl.bindBuffer(this.type,this._handle),t||0===t?this._gl.bufferSubData(this.type,t*this.itemByteSize,e):this._gl.bufferData(this.type,e,this.usage),this._gl.bindBuffer(this.type,null)))}bind(){this.allocated&&this._gl.bindBuffer(this.type,this._handle)}unbind(){this.allocated&&this._gl.bindBuffer(this.type,null)}bindAtLocation(e){this.bind(),this._gl.vertexAttribPointer(e,this.itemSize,this.itemType,this.normalized,0,0)}destroy(){this.allocated&&(this._gl.deleteBuffer(this._handle),this._handle=null,this.allocated=!1)}}var ke=function(){const e=[],t=[],i=[],s=[],r=[];let n=0;const A=new Uint16Array(3),o=new Uint16Array(3),a=new Uint16Array(3),l=V.vec3(),c=V.vec3(),h=V.vec3(),u=V.vec3(),d=V.vec3(),f=V.vec3(),p=V.vec3();return function(g,m,_,b){!function(r,n){const A={};let o,a,l,c;const h=Math.pow(10,4);let u,d,f=0;for(u=0,d=r.length;u<d;u+=3)o=r[u],a=r[u+1],l=r[u+2],c=Math.round(o*h)+"_"+Math.round(a*h)+"_"+Math.round(l*h),void 0===A[c]&&(A[c]=f/3,e[f++]=o,e[f++]=a,e[f++]=l),t[u/3]=A[c];for(u=0,d=n.length;u<d;u++)s[u]=t[n[u]],i[s[u]]=n[u]}(g,m),function(t,i){n=0;for(let g=0,m=t;g<m;g+=3){const t=3*s[g],m=3*s[g+1],_=3*s[g+2];i?(A[0]=e[t],A[1]=e[t+1],A[2]=e[t+2],o[0]=e[m],o[1]=e[m+1],o[2]=e[m+2],a[0]=e[_],a[1]=e[_+1],a[2]=e[_+2],V.decompressPosition(A,i,l),V.decompressPosition(o,i,c),V.decompressPosition(a,i,h)):(l[0]=e[t],l[1]=e[t+1],l[2]=e[t+2],c[0]=e[m],c[1]=e[m+1],c[2]=e[m+2],h[0]=e[_],h[1]=e[_+1],h[2]=e[_+2]),V.subVec3(h,c,u),V.subVec3(l,c,d),V.cross3Vec3(u,d,f),V.normalizeVec3(f,p);const b=r[n]||(r[n]={normal:V.vec3()});b.normal[0]=p[0],b.normal[1]=p[1],b.normal[2]=p[2],n++}}(m.length,_);const B=[],y=Math.cos(V.DEGTORAD*b),w={};let v,C,M,E,F,U,x,I,T,P,S,D=!1;for(let e=0,t=m.length;e<t;e+=3){const t=e/3;for(let i=0;i<3;i++)v=s[e+i],C=s[e+(i+1)%3],M=Math.min(v,C),E=Math.max(v,C),F=M+","+E,void 0===w[F]?w[F]={index1:M,index2:E,face1:t,face2:void 0}:w[F].face2=t}for(F in w)U=w[F],void 0!==U.face2&&(x=r[U.face1].normal,I=r[U.face2].normal,T=V.dotVec3(x,I),T>y)||(P=i[U.index1],S=i[U.index2],(!D&&P>65535||S>65535)&&(D=!0),B.push(P),B.push(S));return D?new Uint32Array(B):new Uint16Array(B)}}();const Qe=function(){const e=V.mat4(),t=V.mat4();return function(i,s){s=s||V.mat4();const r=i[0],n=i[1],A=i[2],o=i[3]-r,a=i[4]-n,l=i[5]-A,c=65535;return V.identityMat4(e),V.translationMat4v(i,e),V.identityMat4(t),V.scalingMat4v([o/c,a/c,l/c],t),V.mulMat4(e,t,s),s}}();var Re=function(){const e=V.mat4(),t=V.mat4();return function(i,s,r){const n=new Uint16Array(i.length),A=new Float32Array([r[0]!==s[0]?65535/(r[0]-s[0]):0,r[1]!==s[1]?65535/(r[1]-s[1]):0,r[2]!==s[2]?65535/(r[2]-s[2]):0]);let o;for(o=0;o<i.length;o+=3)n[o+0]=Math.max(0,Math.min(65535,Math.floor((i[o+0]-s[0])*A[0]))),n[o+1]=Math.max(0,Math.min(65535,Math.floor((i[o+1]-s[1])*A[1]))),n[o+2]=Math.max(0,Math.min(65535,Math.floor((i[o+2]-s[2])*A[2])));V.identityMat4(e),V.translationMat4v(s,e),V.identityMat4(t),V.scalingMat4v([(r[0]-s[0])/65535,(r[1]-s[1])/65535,(r[2]-s[2])/65535],t);return{quantized:n,decodeMatrix:V.mulMat4(e,t,V.identityMat4())}}}();var Oe=function(){const e=V.mat3(),t=V.mat3();return function(i,s,r){const n=new Uint16Array(i.length),A=new Float32Array([65535/(r[0]-s[0]),65535/(r[1]-s[1])]);let o;for(o=0;o<i.length;o+=2)n[o+0]=Math.max(0,Math.min(65535,Math.floor((i[o+0]-s[0])*A[0]))),n[o+1]=Math.max(0,Math.min(65535,Math.floor((i[o+1]-s[1])*A[1])));V.identityMat3(e),V.translationMat3v(s,e),V.identityMat3(t),V.scalingMat3v([(r[0]-s[0])/65535,(r[1]-s[1])/65535],t);return{quantized:n,decodeMatrix:V.mulMat3(e,t,V.identityMat3())}}}();function Ve(e,t,i,s){let r=e[t]/(Math.abs(e[t])+Math.abs(e[t+1])+Math.abs(e[t+2])),n=e[t+1]/(Math.abs(e[t])+Math.abs(e[t+1])+Math.abs(e[t+2]));if(e[t+2]<0){let e=(1-Math.abs(n))*(r>=0?1:-1),t=(1-Math.abs(r))*(n>=0?1:-1);r=e,n=t}return new Int8Array([Math[i](127.5*r+(r<0?-1:0)),Math[s](127.5*n+(n<0?-1:0))])}function Le(e){let t=e[0],i=e[1];t/=t<0?127:128,i/=i<0?127:128;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 r=Math.sqrt(t*t+i*i+s*s);return[t/r,i/r,s/r]}function He(e,t,i){return e[t]*i[0]+e[t+1]*i[1]+e[t+2]*i[2]}const Ne={getPositionsBounds:function(e){const t=new Float32Array(3),i=new Float32Array(3);let s,r;for(s=0;s<3;s++)t[s]=Number.MAX_VALUE,i[s]=-Number.MAX_VALUE;for(s=0;s<e.length;s+=3)for(r=0;r<3;r++)t[r]=Math.min(t[r],e[s+r]),i[r]=Math.max(i[r],e[s+r]);return{min:t,max:i}},createPositionsDecodeMatrix:Qe,compressPositions:Re,compressPosition:function(e,t,i){const s=new Float32Array([t[3]!==t[0]?65535/(t[3]-t[0]):0,t[4]!==t[1]?65535/(t[4]-t[1]):0,t[5]!==t[2]?65535/(t[5]-t[2]):0]);i[0]=Math.max(0,Math.min(65535,Math.floor((e[0]-t[0])*s[0]))),i[1]=Math.max(0,Math.min(65535,Math.floor((e[1]-t[1])*s[1]))),i[2]=Math.max(0,Math.min(65535,Math.floor((e[2]-t[2])*s[2])))},decompressPositions:function(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},decompressPosition:function(e,t,i){return i[0]=e[0]*t[0]+t[12],i[1]=e[1]*t[5]+t[13],i[2]=e[2]*t[10]+t[14],i},decompressAABB:function(e,t,i=e){return i[0]=e[0]*t[0]+t[12],i[1]=e[1]*t[5]+t[13],i[2]=e[2]*t[10]+t[14],i[3]=e[3]*t[0]+t[12],i[4]=e[4]*t[5]+t[13],i[5]=e[5]*t[10]+t[14],i},getUVBounds:function(e){const t=new Float32Array(2),i=new Float32Array(2);let s,r;for(s=0;s<2;s++)t[s]=Number.MAX_VALUE,i[s]=-Number.MAX_VALUE;for(s=0;s<e.length;s+=2)for(r=0;r<2;r++)t[r]=Math.min(t[r],e[s+r]),i[r]=Math.max(i[r],e[s+r]);return{min:t,max:i}},compressUVs:Oe,decompressUVs:function(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},decompressUV:function(e,t,i){i[0]=e[0]*t[0]+t[6],i[1]=e[1]*t[4]+t[7]},compressNormals:function(e){const t=new Int8Array(e.length);let i,s,r,n,A;for(let o=0;o<e.length;o+=3)r=i=Ve(e,o,"floor","floor"),s=Le(i),n=A=He(e,o,s),i=Ve(e,o,"ceil","floor"),s=Le(i),n=He(e,o,s),n>A&&(r=i,A=n),i=Ve(e,o,"floor","ceil"),s=Le(i),n=He(e,o,s),n>A&&(r=i,A=n),i=Ve(e,o,"ceil","ceil"),s=Le(i),n=He(e,o,s),n>A&&(r=i,A=n),t[o]=r[0],t[o+1]=r[1];return t},decompressNormals:function(e,t){for(let i=0,s=0,r=e.length;i<r;i+=2){let r=e[i+0],n=e[i+1];r=(2*r+1)/255,n=(2*n+1)/255;const A=1-Math.abs(r)-Math.abs(n);A<0&&(r=(1-Math.abs(n))*(r>=0?1:-1),n=(1-Math.abs(r))*(n>=0?1:-1));const o=Math.sqrt(r*r+n*n+A*A);t[s+0]=r/o,t[s+1]=n/o,t[s+2]=A/o,s+=3}return t},decompressNormal:function(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 n=Math.sqrt(i*i+s*s+r*r);return t[0]=i/n,t[1]=s/n,t[2]=r/n,t}},Ge=G.memory,je=V.AABB3();class We extends Te{get type(){return"ReadableGeometry"}get isReadableGeometry(){return!0}constructor(e,t={}){super(e,t),this._state=new Se({compressGeometry:!!t.compressGeometry,primitive:null,primitiveName:null,positions:null,normals:null,colors:null,uv:null,indices:null,positionsDecodeMatrix:null,uvDecodeMatrix:null,positionsBuf:null,normalsBuf:null,colorsbuf:null,uvBuf:null,indicesBuf:null,hash:""}),this._numTriangles=0,this._edgeThreshold=t.edgeThreshold||10,this._edgeIndicesBuf=null,this._pickTrianglePositionsBuf=null,this._pickTriangleColorsBuf=null,this._aabbDirty=!0,this._boundingSphere=!0,this._aabb=null,this._aabbDirty=!0,this._obb=null,this._obbDirty=!0;const i=this._state,s=this.scene.canvas.gl;switch(t.primitive=t.primitive||"triangles",t.primitive){case"points":i.primitive=s.POINTS,i.primitiveName=t.primitive;break;case"lines":i.primitive=s.LINES,i.primitiveName=t.primitive;break;case"line-loop":i.primitive=s.LINE_LOOP,i.primitiveName=t.primitive;break;case"line-strip":i.primitive=s.LINE_STRIP,i.primitiveName=t.primitive;break;case"triangles":i.primitive=s.TRIANGLES,i.primitiveName=t.primitive;break;case"triangle-strip":i.primitive=s.TRIANGLE_STRIP,i.primitiveName=t.primitive;break;case"triangle-fan":i.primitive=s.TRIANGLE_FAN,i.primitiveName=t.primitive;break;default:this.error("Unsupported value for 'primitive': '"+t.primitive+"' - supported values are 'points', 'lines', 'line-loop', 'line-strip', 'triangles', 'triangle-strip' and 'triangle-fan'. Defaulting to 'triangles'."),i.primitive=s.TRIANGLES,i.primitiveName=t.primitive}if(t.positions)if(this._state.compressGeometry){const e=Ne.getPositionsBounds(t.positions),s=Ne.compressPositions(t.positions,e.min,e.max);i.positions=s.quantized,i.positionsDecodeMatrix=s.decodeMatrix}else i.positions=t.positions.constructor===Float32Array?t.positions:new Float32Array(t.positions);if(t.colors&&(i.colors=t.colors.constructor===Float32Array?t.colors:new Float32Array(t.colors)),t.uv)if(this._state.compressGeometry){const e=Ne.getUVBounds(t.uv),s=Ne.compressUVs(t.uv,e.min,e.max);i.uv=s.quantized,i.uvDecodeMatrix=s.decodeMatrix}else i.uv=t.uv.constructor===Float32Array?t.uv:new Float32Array(t.uv);if(t.normals&&(this._state.compressGeometry?i.normals=Ne.compressNormals(t.normals):i.normals=t.normals.constructor===Float32Array?t.normals:new Float32Array(t.normals)),t.indices&&(i.indices=t.indices.constructor===Uint32Array||t.indices.constructor===Uint16Array?t.indices:new Uint32Array(t.indices),"triangles"===this._state.primitiveName&&(this._numTriangles=t.indices.length/3)),this._buildHash(),Ge.meshes++,i.indices&&(i.indicesBuf=new De(s,s.ELEMENT_ARRAY_BUFFER,i.indices,i.indices.length,1,s.STATIC_DRAW),Ge.indices+=i.indicesBuf.numItems),i.positions&&(i.positionsBuf=new De(s,s.ARRAY_BUFFER,i.positions,i.positions.length,3,s.STATIC_DRAW),Ge.positions+=i.positionsBuf.numItems),i.normals){let e=i.compressGeometry;i.normalsBuf=new De(s,s.ARRAY_BUFFER,i.normals,i.normals.length,3,s.STATIC_DRAW,e),Ge.normals+=i.normalsBuf.numItems}i.colors&&(i.colorsBuf=new De(s,s.ARRAY_BUFFER,i.colors,i.colors.length,4,s.STATIC_DRAW),Ge.colors+=i.colorsBuf.numItems),i.uv&&(i.uvBuf=new De(s,s.ARRAY_BUFFER,i.uv,i.uv.length,2,s.STATIC_DRAW),Ge.uvs+=i.uvBuf.numItems)}_buildHash(){const e=this._state,t=["/g"];t.push("/"+e.primitive+";"),e.positions&&t.push("p"),e.colors&&t.push("c"),(e.normals||e.autoVertexNormals)&&t.push("n"),e.uv&&t.push("u"),e.compressGeometry&&t.push("cp"),t.push(";"),e.hash=t.join("")}_getEdgeIndices(){return this._edgeIndicesBuf||this._buildEdgeIndices(),this._edgeIndicesBuf}_getPickTrianglePositions(){return this._pickTrianglePositionsBuf||this._buildPickTriangleVBOs(),this._pickTrianglePositionsBuf}_getPickTriangleColors(){return this._pickTriangleColorsBuf||this._buildPickTriangleVBOs(),this._pickTriangleColorsBuf}_buildEdgeIndices(){const e=this._state;if(!e.positions||!e.indices)return;const t=this.scene.canvas.gl,i=ke(e.positions,e.indices,e.positionsDecodeMatrix,this._edgeThreshold);this._edgeIndicesBuf=new De(t,t.ELEMENT_ARRAY_BUFFER,i,i.length,1,t.STATIC_DRAW),Ge.indices+=this._edgeIndicesBuf.numItems}_buildPickTriangleVBOs(){const e=this._state;if(!e.positions||!e.indices)return;const t=this.scene.canvas.gl,i=V.buildPickTriangles(e.positions,e.indices,e.compressGeometry),s=i.positions,r=i.colors;this._pickTrianglePositionsBuf=new De(t,t.ARRAY_BUFFER,s,s.length,3,t.STATIC_DRAW),this._pickTriangleColorsBuf=new De(t,t.ARRAY_BUFFER,r,r.length,4,t.STATIC_DRAW,!0),Ge.positions+=this._pickTrianglePositionsBuf.numItems,Ge.colors+=this._pickTriangleColorsBuf.numItems}_buildPickVertexVBOs(){}get primitive(){return this._state.primitiveName}get compressGeometry(){return this._state.compressGeometry}get positions(){return this._state.positions?this._state.compressGeometry?(this._decompressedPositions||(this._decompressedPositions=new Float32Array(this._state.positions.length),Ne.decompressPositions(this._state.positions,this._state.positionsDecodeMatrix,this._decompressedPositions)),this._decompressedPositions):this._state.positions:null}set positions(e){const t=this._state,i=t.positions;if(i)if(i.length===e.length){if(this._state.compressGeometry){const i=Ne.getPositionsBounds(e),s=Ne.compressPositions(e,i.min,i.max);e=s.quantized,t.positionsDecodeMatrix=s.decodeMatrix}i.set(e),t.positionsBuf&&t.positionsBuf.setData(i),this._setAABBDirty(),this.glRedraw()}else this.error("can't update geometry positions - new positions are wrong length");else this.error("can't update geometry positions - geometry has no positions")}get normals(){if(this._state.normals){if(!this._state.compressGeometry)return this._state.normals;if(!this._decompressedNormals){const e=this._state.normals.length,t=e+e/2;this._decompressedNormals=new Float32Array(t),Ne.decompressNormals(this._state.normals,this._decompressedNormals)}return this._decompressedNormals}}set normals(e){if(this._state.compressGeometry)return void this.error("can't update geometry normals - quantized geometry is immutable");const t=this._state,i=t.normals;i?i.length===e.length?(i.set(e),t.normalsBuf&&t.normalsBuf.setData(i),this.glRedraw()):this.error("can't update geometry normals - new normals are wrong length"):this.error("can't update geometry normals - geometry has no normals")}get uv(){return this._state.uv?this._state.compressGeometry?(this._decompressedUV||(this._decompressedUV=new Float32Array(this._state.uv.length),Ne.decompressUVs(this._state.uv,this._state.uvDecodeMatrix,this._decompressedUV)),this._decompressedUV):this._state.uv:null}set uv(e){if(this._state.compressGeometry)return void this.error("can't update geometry UVs - quantized geometry is immutable");const t=this._state,i=t.uv;i?i.length===e.length?(i.set(e),t.uvBuf&&t.uvBuf.setData(i),this.glRedraw()):this.error("can't update geometry UVs - new UVs are wrong length"):this.error("can't update geometry UVs - geometry has no UVs")}get colors(){return this._state.colors}set colors(e){if(this._state.compressGeometry)return void this.error("can't update geometry colors - quantized geometry is immutable");const t=this._state,i=t.colors;i?i.length===e.length?(i.set(e),t.colorsBuf&&t.colorsBuf.setData(i),this.glRedraw()):this.error("can't update geometry colors - new colors are wrong length"):this.error("can't update geometry colors - geometry has no colors")}get indices(){return this._state.indices}get aabb(){return this._aabbDirty&&(this._aabb||(this._aabb=V.AABB3()),V.positions3ToAABB3(this._state.positions,this._aabb,this._state.positionsDecodeMatrix),this._aabbDirty=!1),this._aabb}get obb(){return this._obbDirty&&(this._obb||(this._obb=V.OBB3()),V.positions3ToAABB3(this._state.positions,je,this._state.positionsDecodeMatrix),V.AABB3ToOBB3(je,this._obb),this._obbDirty=!1),this._obb}_getMetrics(){if(!("_metrics"in this))switch(this._state.primitiveName){case"solid":case"surface":case"triangles":{const e=this._state.indices,t=this._state.positions,i=(i,s)=>{const r=3*e[i];for(let e=0;e<3;++e)s[e]=t[r+e];return s},s=[V.vec3(),V.vec3(),V.vec3(),V.vec3()];let r=0;const n=V.vec3([0,0,0]);for(let t=0;t<e.length;t+=3){const e=i(t,s[0]),A=i(t+1,s[1]),o=i(t+2,s[2]);V.addVec3(e,A,s[3]),V.addVec3(o,s[3],s[3]);const a=V.lenVec3(V.cross3Vec3(V.subVec3(A,e,s[1]),V.subVec3(o,e,s[2]),s[0]))/2;r+=a,V.mulVec3Scalar(s[3],a,s[3]),V.addVec3(n,s[3],n)}this._metrics={surfaceArea:r,centroid:V.mulVec3Scalar(n,1/r/3,n)};break}default:this._metrics={surfaceArea:0}}return this._metrics}get surfaceArea(){return this._getMetrics().surfaceArea}get centroid(){return this._getMetrics().centroid}get numTriangles(){return this._numTriangles}_setAABBDirty(){this._aabbDirty||(this._aabbDirty=!0,this._aabbDirty=!0,this._obbDirty=!0)}_getState(){return this._state}destroy(){super.destroy();const e=this._state;e.indicesBuf&&e.indicesBuf.destroy(),e.positionsBuf&&e.positionsBuf.destroy(),e.normalsBuf&&e.normalsBuf.destroy(),e.uvBuf&&e.uvBuf.destroy(),e.colorsBuf&&e.colorsBuf.destroy(),this._edgeIndicesBuf&&this._edgeIndicesBuf.destroy(),this._pickTrianglePositionsBuf&&this._pickTrianglePositionsBuf.destroy(),this._pickTriangleColorsBuf&&this._pickTriangleColorsBuf.destroy(),this._pickVertexPositionsBuf&&this._pickVertexPositionsBuf.destroy(),this._pickVertexColorsBuf&&this._pickVertexColorsBuf.destroy(),e.destroy(),Ge.meshes--}}const ze=G.memory,Xe=V.AABB3();class Ke extends Te{get type(){return"VBOGeometry"}get isVBOGeometry(){return!0}constructor(e,t={}){super(e,t),this._state=new Se({compressGeometry:!0,primitive:null,primitiveName:null,positionsDecodeMatrix:null,uvDecodeMatrix:null,positionsBuf:null,normalsBuf:null,colorsbuf:null,uvBuf:null,indicesBuf:null,hash:""}),this._numTriangles=0,this._edgeThreshold=t.edgeThreshold||10,this._aabb=null,this._obb=V.OBB3();const i=this._state,s=this.scene.canvas.gl;switch(t.primitive=t.primitive||"triangles",t.primitive){case"points":i.primitive=s.POINTS,i.primitiveName=t.primitive;break;case"lines":i.primitive=s.LINES,i.primitiveName=t.primitive;break;case"line-loop":i.primitive=s.LINE_LOOP,i.primitiveName=t.primitive;break;case"line-strip":i.primitive=s.LINE_STRIP,i.primitiveName=t.primitive;break;case"triangles":i.primitive=s.TRIANGLES,i.primitiveName=t.primitive;break;case"triangle-strip":i.primitive=s.TRIANGLE_STRIP,i.primitiveName=t.primitive;break;case"triangle-fan":i.primitive=s.TRIANGLE_FAN,i.primitiveName=t.primitive;break;default:this.error("Unsupported value for 'primitive': '"+t.primitive+"' - supported values are 'points', 'lines', 'line-loop', 'line-strip', 'triangles', 'triangle-strip' and 'triangle-fan'. Defaulting to 'triangles'."),i.primitive=s.TRIANGLES,i.primitiveName=t.primitive}if(t.positions)if(t.indices){var r;if(t.positionsDecodeMatrix);else{const e=Ne.getPositionsBounds(t.positions),n=Ne.compressPositions(t.positions,e.min,e.max);r=n.quantized,i.positionsDecodeMatrix=n.decodeMatrix,i.positionsBuf=new De(s,s.ARRAY_BUFFER,r,r.length,3,s.STATIC_DRAW),ze.positions+=i.positionsBuf.numItems,V.positions3ToAABB3(t.positions,this._aabb),V.positions3ToAABB3(r,Xe,i.positionsDecodeMatrix),V.AABB3ToOBB3(Xe,this._obb)}if(t.colors){const e=t.colors.constructor===Float32Array?t.colors:new Float32Array(t.colors);i.colorsBuf=new De(s,s.ARRAY_BUFFER,e,e.length,4,s.STATIC_DRAW),ze.colors+=i.colorsBuf.numItems}if(t.uv){const e=Ne.getUVBounds(t.uv),r=Ne.compressUVs(t.uv,e.min,e.max),n=r.quantized;i.uvDecodeMatrix=r.decodeMatrix,i.uvBuf=new De(s,s.ARRAY_BUFFER,n,n.length,2,s.STATIC_DRAW),ze.uvs+=i.uvBuf.numItems}if(t.normals){const e=Ne.compressNormals(t.normals);let r=i.compressGeometry;i.normalsBuf=new De(s,s.ARRAY_BUFFER,e,e.length,3,s.STATIC_DRAW,r),ze.normals+=i.normalsBuf.numItems}{const e=t.indices.constructor===Uint32Array||t.indices.constructor===Uint16Array?t.indices:new Uint32Array(t.indices);i.indicesBuf=new De(s,s.ELEMENT_ARRAY_BUFFER,e,e.length,1,s.STATIC_DRAW),ze.indices+=i.indicesBuf.numItems;const n=ke(r,e,i.positionsDecodeMatrix,this._edgeThreshold);this._edgeIndicesBuf=new De(s,s.ELEMENT_ARRAY_BUFFER,n,n.length,1,s.STATIC_DRAW),"triangles"===this._state.primitiveName&&(this._numTriangles=t.indices.length/3)}this._buildHash(),ze.meshes++}else this.error("Config expected: indices");else this.error("Config expected: positions")}_buildHash(){const e=this._state,t=["/g"];t.push("/"+e.primitive+";"),e.positionsBuf&&t.push("p"),e.colorsBuf&&t.push("c"),(e.normalsBuf||e.autoVertexNormals)&&t.push("n"),e.uvBuf&&t.push("u"),t.push("cp"),t.push(";"),e.hash=t.join("")}_getEdgeIndices(){return this._edgeIndicesBuf}get primitive(){return this._state.primitiveName}get aabb(){return this._aabb}get obb(){return this._obb}get numTriangles(){return this._numTriangles}_getState(){return this._state}destroy(){super.destroy();const e=this._state;e.indicesBuf&&e.indicesBuf.destroy(),e.positionsBuf&&e.positionsBuf.destroy(),e.normalsBuf&&e.normalsBuf.destroy(),e.uvBuf&&e.uvBuf.destroy(),e.colorsBuf&&e.colorsBuf.destroy(),this._edgeIndicesBuf&&this._edgeIndicesBuf.destroy(),e.destroy(),ze.meshes--}}var Ze={};function Je(e,t={}){return new Promise((function(i,s){t.src||(console.error("load3DSGeometry: Parameter expected: src"),s());var r=e.canvas.spinner;r.processes++,X.loadArraybuffer(t.src,(function(e){e.byteLength||(console.error("load3DSGeometry: no data loaded"),r.processes--,s());var n=Ze.parse.from3DS(e).edit.objects[0].mesh,A=n.vertices,o=n.uvt,a=n.indices;r.processes--,i(X.apply(t,{primitive:"triangles",positions:A,normals:null,uv:o,indices:a}))}),(function(e){console.error("load3DSGeometry: "+e),r.processes--,s()}))}))}function Ye(e,t={}){return new Promise((function(i,s){t.src||(console.error("loadOBJGeometry: Parameter expected: src"),s());var r=e.canvas.spinner;r.processes++,X.loadArraybuffer(t.src,(function(e){e.byteLength||(console.error("loadOBJGeometry: no data loaded"),r.processes--,s());for(var n=Ze.parse.fromOBJ(e),A=Ze.edit.unwrap(n.i_verts,n.c_verts,3),o=Ze.edit.unwrap(n.i_norms,n.c_norms,3),a=Ze.edit.unwrap(n.i_uvt,n.c_uvt,2),l=new Int32Array(n.i_verts.length),c=0;c<n.i_verts.length;c++)l[c]=c;r.processes--,i(X.apply(t,{primitive:"triangles",positions:A,normals:o.length>0?o:null,autoNormals:0===o.length,uv:a,indices:l}))}),(function(e){console.error("loadOBJGeometry: "+e),r.processes--,s()}))}))}function $e(e={}){let t=e.xSize||1;t<0&&(console.error("negative xSize not allowed - will invert"),t*=-1);let i=e.ySize||1;i<0&&(console.error("negative ySize not allowed - will invert"),i*=-1);let s=e.zSize||1;s<0&&(console.error("negative zSize not allowed - will invert"),s*=-1);const r=e.center,n=r?r[0]:0,A=r?r[1]:0,o=r?r[2]:0,a=-t+n,l=-i+A,c=-s+o,h=t+n,u=i+A,d=s+o;return X.apply(e,{positions:[h,u,d,a,u,d,a,l,d,h,l,d,h,u,d,h,l,d,h,l,c,h,u,c,h,u,d,h,u,c,a,u,c,a,u,d,a,u,d,a,u,c,a,l,c,a,l,d,a,l,c,h,l,c,h,l,d,a,l,d,h,l,c,a,l,c,a,u,c,h,u,c],normals:[0,0,1,0,0,1,0,0,1,0,0,1,1,0,0,1,0,0,1,0,0,1,0,0,0,1,0,0,1,0,0,1,0,0,1,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,0,-1,0,0,-1,0,0,-1,0,0,-1],uv:[1,0,0,0,0,1,1,1,0,0,0,1,1,1,1,0,1,1,1,0,0,0,0,1,1,0,0,0,0,1,1,1,0,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0],indices:[0,1,2,0,2,3,4,5,6,4,6,7,8,9,10,8,10,11,12,13,14,12,14,15,16,17,18,16,18,19,20,21,22,20,22,23]})}function qe(e={}){let t=e.xSize||1;t<0&&(console.error("negative xSize not allowed - will invert"),t*=-1);let i=e.ySize||1;i<0&&(console.error("negative ySize not allowed - will invert"),i*=-1);let s=e.zSize||1;s<0&&(console.error("negative zSize not allowed - will invert"),s*=-1);const r=e.center,n=r?r[0]:0,A=r?r[1]:0,o=r?r[2]:0,a=-t+n,l=-i+A,c=-s+o,h=t+n,u=i+A,d=s+o;return X.apply(e,{primitive:"lines",positions:[a,l,c,a,l,d,a,u,c,a,u,d,h,l,c,h,l,d,h,u,c,h,u,d],indices:[0,1,1,3,3,2,2,0,4,5,5,7,7,6,6,4,0,4,1,5,2,6,3,7]})}function et(e={}){return qe({id:e.id,center:[(e.aabb[0]+e.aabb[3])/2,(e.aabb[1]+e.aabb[4])/2,(e.aabb[2]+e.aabb[5])/2],xSize:Math.abs(e.aabb[3]-e.aabb[0])/2,ySize:Math.abs(e.aabb[4]-e.aabb[1])/2,zSize:Math.abs(e.aabb[5]-e.aabb[2])/2})}function tt(e={}){let t=e.radiusTop||1;t<0&&(console.error("negative radiusTop not allowed - will invert"),t*=-1);let i=e.radiusBottom||1;i<0&&(console.error("negative radiusBottom not allowed - will invert"),i*=-1);let s=e.height||1;s<0&&(console.error("negative height not allowed - will invert"),s*=-1);let r=e.radialSegments||32;r<0&&(console.error("negative radialSegments not allowed - will invert"),r*=-1),r<3&&(r=3);let n=e.heightSegments||1;n<0&&(console.error("negative heightSegments not allowed - will invert"),n*=-1),n<1&&(n=1);const A=!!e.openEnded;let o=e.center;const a=o?o[0]:0,l=o?o[1]:0,c=o?o[2]:0,h=s/2,u=s/n,d=2*Math.PI/r,f=1/r,p=(t-i)/n,g=[],m=[],_=[],b=[];let B,y,w,v,C,M,E,F,U,x,I;const T=(90-180*Math.atan(s/(i-t))/Math.PI)/90;for(B=0;B<=n;B++)for(C=t-B*p,M=h-B*u,y=0;y<=r;y++)w=Math.sin(y*d),v=Math.cos(y*d),m.push(C*w),m.push(T),m.push(C*v),_.push(y*f),_.push(1*B/n),g.push(C*w+a),g.push(M+l),g.push(C*v+c);for(B=0;B<n;B++)for(y=0;y<=r;y++)E=B*(r+1)+y,F=E+r,b.push(E),b.push(F),b.push(F+1),b.push(E),b.push(F+1),b.push(E+1);if(!A&&t>0){for(U=g.length/3,m.push(0),m.push(1),m.push(0),_.push(.5),_.push(.5),g.push(0+a),g.push(h+l),g.push(0+c),y=0;y<=r;y++)w=Math.sin(y*d),v=Math.cos(y*d),x=.5*Math.sin(y*d)+.5,I=.5*Math.cos(y*d)+.5,m.push(t*w),m.push(1),m.push(t*v),_.push(x),_.push(I),g.push(t*w+a),g.push(h+l),g.push(t*v+c);for(y=0;y<r;y++)o=U,E=U+1+y,b.push(E),b.push(E+1),b.push(o)}if(!A&&i>0){for(U=g.length/3,m.push(0),m.push(-1),m.push(0),_.push(.5),_.push(.5),g.push(0+a),g.push(0-h+l),g.push(0+c),y=0;y<=r;y++)w=Math.sin(y*d),v=Math.cos(y*d),x=.5*Math.sin(y*d)+.5,I=.5*Math.cos(y*d)+.5,m.push(i*w),m.push(-1),m.push(i*v),_.push(x),_.push(I),g.push(i*w+a),g.push(0-h+l),g.push(i*v+c);for(y=0;y<r;y++)o=U,E=U+1+y,b.push(o),b.push(E+1),b.push(E)}return X.apply(e,{positions:g,normals:m,uv:_,indices:b})}function it(e={}){let t=e.size||1;t<0&&(console.error("negative size not allowed - will invert"),t*=-1);let i=e.divisions||1;i<0&&(console.error("negative divisions not allowed - will invert"),i*=-1),i<1&&(i=1),t=t||10,i=i||10;const s=t/i,r=t/2,n=[],A=[];let o=0;for(let e=0,t=-r;e<=i;e++,t+=s)n.push(-r),n.push(0),n.push(t),n.push(r),n.push(0),n.push(t),n.push(t),n.push(0),n.push(-r),n.push(t),n.push(0),n.push(r),A.push(o++),A.push(o++),A.push(o++),A.push(o++);return X.apply(e,{primitive:"lines",positions:n,indices:A})}function st(e={}){let t=e.xSize||1;t<0&&(console.error("negative xSize not allowed - will invert"),t*=-1);let i=e.zSize||1;i<0&&(console.error("negative zSize not allowed - will invert"),i*=-1);let s=e.xSegments||1;s<0&&(console.error("negative xSegments not allowed - will invert"),s*=-1),s<1&&(s=1);let r=e.xSegments||1;r<0&&(console.error("negative zSegments not allowed - will invert"),r*=-1),r<1&&(r=1);const n=e.center,A=n?n[0]:0,o=n?n[1]:0,a=n?n[2]:0,l=t/2,c=i/2,h=Math.floor(s)||1,u=Math.floor(r)||1,d=h+1,f=u+1,p=t/h,g=i/u,m=new Float32Array(d*f*3),_=new Float32Array(d*f*3),b=new Float32Array(d*f*2);let B,y,w,v,C,M,E,F=0,U=0;for(B=0;B<f;B++){const e=B*g-c;for(y=0;y<d;y++)w=y*p-l,m[F]=w+A,m[F+1]=o,m[F+2]=-e+a,_[F+1]=1,b[U]=y/h,b[U+1]=(u-B)/u,F+=3,U+=2}F=0;const x=new(m.length/3>65535?Uint32Array:Uint16Array)(h*u*6);for(B=0;B<u;B++)for(y=0;y<h;y++)v=y+d*B,C=y+d*(B+1),M=y+1+d*(B+1),E=y+1+d*B,x[F]=E,x[F+1]=C,x[F+2]=v,x[F+3]=E,x[F+4]=M,x[F+5]=C,F+=6;return X.apply(e,{positions:m,normals:_,uv:b,indices:x})}function rt(e={}){const t=e.lod||1,i=e.center?e.center[0]:0,s=e.center?e.center[1]:0,r=e.center?e.center[2]:0;let n=e.radius||1;n<0&&(console.error("negative radius not allowed - will invert"),n*=-1);let A=e.heightSegments||18;A<0&&(console.error("negative heightSegments not allowed - will invert"),A*=-1),A=Math.floor(t*A),A<18&&(A=18);let o=e.widthSegments||18;o<0&&(console.error("negative widthSegments not allowed - will invert"),o*=-1),o=Math.floor(t*o),o<18&&(o=18);const a=[],l=[],c=[],h=[];let u,d,f,p,g,m,_,b,B,y,w,v,C,M,E;for(u=0;u<=A;u++)for(f=u*Math.PI/A,p=Math.sin(f),g=Math.cos(f),d=0;d<=o;d++)m=2*d*Math.PI/o,_=Math.sin(m),b=Math.cos(m),B=b*p,y=g,w=_*p,v=1-d/o,C=u/A,l.push(B),l.push(y),l.push(w),c.push(v),c.push(C),a.push(i+n*B),a.push(s+n*y),a.push(r+n*w);for(u=0;u<A;u++)for(d=0;d<o;d++)M=u*(o+1)+d,E=M+o+1,h.push(M+1),h.push(E+1),h.push(E),h.push(M+1),h.push(E),h.push(M);return X.apply(e,{positions:a,normals:l,uv:c,indices:h})}function nt(e={}){let t=e.radius||1;t<0&&(console.error("negative radius not allowed - will invert"),t*=-1),t*=.5;let i=e.tube||.3;i<0&&(console.error("negative tube not allowed - will invert"),i*=-1);let s=e.radialSegments||32;s<0&&(console.error("negative radialSegments not allowed - will invert"),s*=-1),s<4&&(s=4);let r=e.tubeSegments||24;r<0&&(console.error("negative tubeSegments not allowed - will invert"),r*=-1),r<4&&(r=4);let n=e.arc||2*Math.PI;n<0&&(console.warn("negative arc not allowed - will invert"),n*=-1),n>360&&(n=360);const A=e.center;let o=A?A[0]:0,a=A?A[1]:0;const l=A?A[2]:0,c=[],h=[],u=[],d=[];let f,p,g,m,_,b,B,y,w,v,C,M;for(y=0;y<=r;y++)for(B=0;B<=s;B++)f=B/s*n,p=.785398+y/r*Math.PI*2,o=t*Math.cos(f),a=t*Math.sin(f),g=(t+i*Math.cos(p))*Math.cos(f),m=(t+i*Math.cos(p))*Math.sin(f),_=i*Math.sin(p),c.push(g+o),c.push(m+a),c.push(_+l),u.push(1-B/s),u.push(y/r),b=V.normalizeVec3(V.subVec3([g,m,_],[o,a,l],[]),[]),h.push(b[0]),h.push(b[1]),h.push(b[2]);for(y=1;y<=r;y++)for(B=1;B<=s;B++)w=(s+1)*y+B-1,v=(s+1)*(y-1)+B-1,C=(s+1)*(y-1)+B,M=(s+1)*y+B,d.push(w),d.push(v),d.push(C),d.push(C),d.push(M),d.push(w);return X.apply(e,{positions:c,normals:h,uv:u,indices:d})}Ze.load=function(e,t){var i=new XMLHttpRequest;i.open("GET",e,!0),i.responseType="arraybuffer",i.onload=function(e){t(e.target.response)},i.send()},Ze.save=function(e,t){var i="data:application/octet-stream;base64,"+btoa(Ze.parse._buffToStr(e));window.location.href=i},Ze.clone=function(e){return JSON.parse(JSON.stringify(e))},Ze.bin={},Ze.bin.f=new Float32Array(1),Ze.bin.fb=new Uint8Array(Ze.bin.f.buffer),Ze.bin.rf=function(e,t){for(var i=Ze.bin.f,s=Ze.bin.fb,r=0;r<4;r++)s[r]=e[t+r];return i[0]},Ze.bin.rsl=function(e,t){return e[t]|e[t+1]<<8},Ze.bin.ril=function(e,t){return e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24},Ze.bin.rASCII0=function(e,t){for(var i="";0!=e[t];)i+=String.fromCharCode(e[t++]);return i},Ze.bin.wf=function(e,t,i){new Float32Array(e.buffer,t,1)[0]=i},Ze.bin.wsl=function(e,t,i){e[t]=i,e[t+1]=i>>8},Ze.bin.wil=function(e,t,i){e[t]=i,e[t+1]=i>>8,e[t+2]=i>>16,e[t+3]},Ze.parse={},Ze.parse._buffToStr=function(e){for(var t=new Uint8Array(e),i="",s=0;s<t.length;s++)i=i.concat(String.fromCharCode(t[s]));return i},Ze.parse._strToBuff=function(e){for(var t=new ArrayBuffer(e.length),i=new Uint8Array(t),s=0;s<e.length;s++)i[s]=e.charCodeAt(s);return t},Ze.parse._readLine=function(e,t){for(var i="";10!=e[t];)i+=String.fromCharCode(e[t++]);return i},Ze.parse.fromJSON=function(e){return JSON.parse(Ze.parse._buffToStr(e))},Ze.parse.toJSON=function(e){var t=JSON.stringify(e);return Ze.parse._strToBuff(t)},Ze.parse.fromOBJ=function(e){for(var t={groups:{},c_verts:[],c_uvt:[],c_norms:[],i_verts:[],i_uvt:[],i_norms:[]},i={from:0,to:0},s=0,r=new Uint8Array(e);s<r.length;){var n=Ze.parse._readLine(r,s);s+=n.length+1;var A=(n=(n=n.replace(/ +(?= )/g,"")).replace(/(^\s+|\s+$)/g,"")).split(" ");if("g"==A[0]&&(i.to=t.i_verts.length,null==t.groups[A[1]]&&(t.groups[A[1]]={from:t.i_verts.length,to:0}),i=t.groups[A[1]]),"v"==A[0]){var o=parseFloat(A[1]),a=parseFloat(A[2]),l=parseFloat(A[3]);t.c_verts.push(o,a,l)}if("vt"==A[0]){o=parseFloat(A[1]),a=1-parseFloat(A[2]);t.c_uvt.push(o,a)}if("vn"==A[0]){o=parseFloat(A[1]),a=parseFloat(A[2]),l=parseFloat(A[3]);t.c_norms.push(o,a,l)}if("f"==A[0]){var c=A[1].split("/"),h=A[2].split("/"),u=A[3].split("/"),d=parseInt(c[0])-1,f=parseInt(h[0])-1,p=parseInt(u[0])-1,g=parseInt(c[1])-1,m=parseInt(h[1])-1,_=parseInt(u[1])-1,b=parseInt(c[2])-1,B=parseInt(h[2])-1,y=parseInt(u[2])-1,w=t.c_verts.length/3,v=t.c_uvt.length/2,C=t.c_norms.length/3;if(d<0&&(d=w+d+1),f<0&&(f=w+f+1),p<0&&(p=w+p+1),g<0&&(g=v+g+1),m<0&&(m=v+m+1),_<0&&(_=v+_+1),b<0&&(b=C+b+1),B<0&&(B=C+B+1),y<0&&(y=C+y+1),t.i_verts.push(d,f,p),t.i_uvt.push(g,m,_),t.i_norms.push(b,B,y),5==A.length){var M=A[4].split("/"),E=parseInt(M[0])-1,F=parseInt(M[1])-1,U=parseInt(M[2])-1;E<0&&(E=w+E+1),F<0&&(F=v+F+1),U<0&&(U=C+U+1),t.i_verts.push(d,p,E),t.i_uvt.push(g,_,F),t.i_norms.push(b,y,U)}}}return i.to=t.i_verts.length,t},Ze.parse.fromMD2=function(e){e=new Uint8Array(e);var t={},i={};i.ident=Ze.bin.ril(e,0),i.version=Ze.bin.ril(e,4),i.skinwidth=Ze.bin.ril(e,8),i.skinheight=Ze.bin.ril(e,12),i.framesize=Ze.bin.ril(e,16),i.num_skins=Ze.bin.ril(e,20),i.num_vertices=Ze.bin.ril(e,24),i.num_st=Ze.bin.ril(e,28),i.num_tris=Ze.bin.ril(e,32),i.num_glcmds=Ze.bin.ril(e,36),i.num_frames=Ze.bin.ril(e,40),i.offset_skins=Ze.bin.ril(e,44),i.offset_st=Ze.bin.ril(e,48),i.offset_tris=Ze.bin.ril(e,52),i.offset_frames=Ze.bin.ril(e,56),i.offset_glcmds=Ze.bin.ril(e,60),i.offset_end=Ze.bin.ril(e,64);var s=i.offset_st;t.c_uvt=[];for(var r=0;r<i.num_st;r++){var n=Ze.bin.rsl(e,s)/i.skinwidth,A=Ze.bin.rsl(e,s+2)/i.skinheight;t.c_uvt.push(n,A),s+=4}s=i.offset_tris;var o=[],a=[];t.i_verts=o,t.i_uvt=a;for(r=0;r<i.num_tris;r++)o.push(Ze.bin.rsl(e,s),Ze.bin.rsl(e,s+2),Ze.bin.rsl(e,s+4)),a.push(Ze.bin.rsl(e,s+6),Ze.bin.rsl(e,s+8),Ze.bin.rsl(e,s+10)),s+=12;s=i.offset_skins;t.skins=[];for(r=0;r<i.num_skins;r++)t.skins.push(Ze.bin.rASCII0(e,s)),s+=64;s=i.offset_frames;t.frames=[];var l=Ze.parse.fromMD2._normals;for(r=0;r<i.num_frames;r++){var c={},h=Ze.bin.rf(e,s),u=Ze.bin.rf(e,s+4),d=Ze.bin.rf(e,s+8);s+=12;var f=Ze.bin.rf(e,s),p=Ze.bin.rf(e,s+4),g=Ze.bin.rf(e,s+8);s+=12,c.name=Ze.bin.rASCII0(e,s),s+=16,c.verts=[],c.norms=[];for(var m=0;m<i.num_vertices;m++)c.verts.push(e[s]*h+f,e[s+1]*u+p,e[s+2]*d+g),c.norms.push(l[3*e[s+3]],l[3*e[s+3]+1],l[3*e[s+3]+2]),s+=4;t.frames.push(c)}return t},Ze.parse.fromMD2._normals=[-.525731,0,.850651,-.442863,.238856,.864188,-.295242,0,.955423,-.309017,.5,.809017,-.16246,.262866,.951056,0,0,1,0,.850651,.525731,-.147621,.716567,.681718,.147621,.716567,.681718,0,.525731,.850651,.309017,.5,.809017,.525731,0,.850651,.295242,0,.955423,.442863,.238856,.864188,.16246,.262866,.951056,-.681718,.147621,.716567,-.809017,.309017,.5,-.587785,.425325,.688191,-.850651,.525731,0,-.864188,.442863,.238856,-.716567,.681718,.147621,-.688191,.587785,.425325,-.5,.809017,.309017,-.238856,.864188,.442863,-.425325,.688191,.587785,-.716567,.681718,-.147621,-.5,.809017,-.309017,-.525731,.850651,0,0,.850651,-.525731,-.238856,.864188,-.442863,0,.955423,-.295242,-.262866,.951056,-.16246,0,1,0,0,.955423,.295242,-.262866,.951056,.16246,.238856,.864188,.442863,.262866,.951056,.16246,.5,.809017,.309017,.238856,.864188,-.442863,.262866,.951056,-.16246,.5,.809017,-.309017,.850651,.525731,0,.716567,.681718,.147621,.716567,.681718,-.147621,.525731,.850651,0,.425325,.688191,.587785,.864188,.442863,.238856,.688191,.587785,.425325,.809017,.309017,.5,.681718,.147621,.716567,.587785,.425325,.688191,.955423,.295242,0,1,0,0,.951056,.16246,.262866,.850651,-.525731,0,.955423,-.295242,0,.864188,-.442863,.238856,.951056,-.16246,.262866,.809017,-.309017,.5,.681718,-.147621,.716567,.850651,0,.525731,.864188,.442863,-.238856,.809017,.309017,-.5,.951056,.16246,-.262866,.525731,0,-.850651,.681718,.147621,-.716567,.681718,-.147621,-.716567,.850651,0,-.525731,.809017,-.309017,-.5,.864188,-.442863,-.238856,.951056,-.16246,-.262866,.147621,.716567,-.681718,.309017,.5,-.809017,.425325,.688191,-.587785,.442863,.238856,-.864188,.587785,.425325,-.688191,.688191,.587785,-.425325,-.147621,.716567,-.681718,-.309017,.5,-.809017,0,.525731,-.850651,-.525731,0,-.850651,-.442863,.238856,-.864188,-.295242,0,-.955423,-.16246,.262866,-.951056,0,0,-1,.295242,0,-.955423,.16246,.262866,-.951056,-.442863,-.238856,-.864188,-.309017,-.5,-.809017,-.16246,-.262866,-.951056,0,-.850651,-.525731,-.147621,-.716567,-.681718,.147621,-.716567,-.681718,0,-.525731,-.850651,.309017,-.5,-.809017,.442863,-.238856,-.864188,.16246,-.262866,-.951056,.238856,-.864188,-.442863,.5,-.809017,-.309017,.425325,-.688191,-.587785,.716567,-.681718,-.147621,.688191,-.587785,-.425325,.587785,-.425325,-.688191,0,-.955423,-.295242,0,-1,0,.262866,-.951056,-.16246,0,-.850651,.525731,0,-.955423,.295242,.238856,-.864188,.442863,.262866,-.951056,.16246,.5,-.809017,.309017,.716567,-.681718,.147621,.525731,-.850651,0,-.238856,-.864188,-.442863,-.5,-.809017,-.309017,-.262866,-.951056,-.16246,-.850651,-.525731,0,-.716567,-.681718,-.147621,-.716567,-.681718,.147621,-.525731,-.850651,0,-.5,-.809017,.309017,-.238856,-.864188,.442863,-.262866,-.951056,.16246,-.864188,-.442863,.238856,-.809017,-.309017,.5,-.688191,-.587785,.425325,-.681718,-.147621,.716567,-.442863,-.238856,.864188,-.587785,-.425325,.688191,-.309017,-.5,.809017,-.147621,-.716567,.681718,-.425325,-.688191,.587785,-.16246,-.262866,.951056,.442863,-.238856,.864188,.16246,-.262866,.951056,.309017,-.5,.809017,.147621,-.716567,.681718,0,-.525731,.850651,.425325,-.688191,.587785,.587785,-.425325,.688191,.688191,-.587785,.425325,-.955423,.295242,0,-.951056,.16246,.262866,-1,0,0,-.850651,0,.525731,-.955423,-.295242,0,-.951056,-.16246,.262866,-.864188,.442863,-.238856,-.951056,.16246,-.262866,-.809017,.309017,-.5,-.864188,-.442863,-.238856,-.951056,-.16246,-.262866,-.809017,-.309017,-.5,-.681718,.147621,-.716567,-.681718,-.147621,-.716567,-.850651,0,-.525731,-.688191,.587785,-.425325,-.587785,.425325,-.688191,-.425325,.688191,-.587785,-.425325,-.688191,-.587785,-.587785,-.425325,-.688191,-.688191,-.587785,-.425325],Ze.parse.fromCollada=function(e){var t=Ze.parse._buffToStr(e),i=(new DOMParser).parseFromString(t,"text/xml"),s={},r=(i=i.childNodes[0]).getElementsByTagName("asset")[0],n=i.getElementsByTagName("library_geometries")[0],A=i.getElementsByTagName("library_images")[0],o=i.getElementsByTagName("library_materials")[0],a=i.getElementsByTagName("library_effects")[0];return r&&(s.asset=Ze.parse.fromCollada._asset(r)),n&&(s.geometries=Ze.parse.fromCollada._libGeometries(n)),A&&(s.images=Ze.parse.fromCollada._libImages(A)),o&&(s.materials=Ze.parse.fromCollada._libMaterials(o)),a&&(s.effects=Ze.parse.fromCollada._libEffects(a)),s},Ze.parse.fromCollada._asset=function(e){return{created:e.getElementsByTagName("created")[0].textContent,modified:e.getElementsByTagName("modified")[0].textContent,up_axis:e.getElementsByTagName("up_axis")[0].textContent}},Ze.parse.fromCollada._libGeometries=function(e){e=e.getElementsByTagName("geometry");for(var t=[],i=0;i<e.length;i++){var s=e[i],r=Ze.parse.fromCollada._getMesh(s.getElementsByTagName("mesh")[0]);t.push(r)}return t},Ze.parse.fromCollada._getMesh=function(e){for(var t={},i=e.getElementsByTagName("source"),s=t.sources={},r=0;r<i.length;r++){for(var n=i[r].getElementsByTagName("float_array")[0].textContent.split(" "),A=n.length-(""==n[n.length-1]?1:0),o=new Array(A),a=0;a<A;a++)o[a]=parseFloat(n[a]);s[i[r].getAttribute("id")]=o}t.triangles=[];var l=e.getElementsByTagName("triangles");if(null==l)return t;for(r=0;r<l.length;r++){var c={},h=l[r];c.material=h.getAttribute("material");var u=h.getElementsByTagName("input"),d=[];for(a=0;a<u.length;a++){var f=u[a];o=[];d[parseInt(f.getAttribute("offset"))]=o;var p=f.getAttribute("semantic");c["s_"+p]="VERTEX"==p?e.getElementsByTagName("vertices")[0].getElementsByTagName("input")[0].getAttribute("source").substring(1):f.getAttribute("source").substring(1),c["i_"+p]=o,s[c["s_"+p]]}var g=h.getElementsByTagName("p")[0].textContent.split(" "),m=3*Math.floor(g.length/3);for(a=0;a<m;a++)d[a%u.length].push(parseInt(g[a]));t.triangles.push(c)}return t},Ze.parse.fromCollada._libImages=function(e){e=e.getElementsByTagName("image");for(var t={},i=0;i<e.length;i++)t[e[i].getAttribute("id")]=e[i].getElementsByTagName("init_from")[0].textContent;return t},Ze.parse.fromCollada._libMaterials=function(e){e=e.getElementsByTagName("material");for(var t={},i=0;i<e.length;i++)t[e[i].getAttribute("name")]=e[i].getElementsByTagName("instance_effect")[0].getAttribute("url").substring(1);return t},Ze.parse.fromCollada._libEffects=function(e){e=e.getElementsByTagName("effect");for(var t={},i=0;i<e.length;i++){for(var s={},r=e[i].getElementsByTagName("newparam"),n=0;n<r.length;n++){var A=r[n].getElementsByTagName("surface")[0];A&&(s.surface=A.getElementsByTagName("init_from")[0].textContent)}t[e[i].getAttribute("id")]=s}return t},Ze.parse.from3DS=function(e){e=new Uint8Array(e);var t={};if(19789!=Ze.bin.rsl(e,0))return null;for(var i=Ze.bin.ril(e,2),s=6;s<i;){var r=Ze.bin.rsl(e,s),n=Ze.bin.ril(e,s+2);15677==r&&(t.edit=Ze.parse.from3DS._edit3ds(e,s,n)),45056==r&&(t.keyf=Ze.parse.from3DS._keyf3ds(e,s,n)),s+=n}return t},Ze.parse.from3DS._edit3ds=function(e,t,i){for(var s={},r=t+6;r<t+i;){var n=Ze.bin.rsl(e,r),A=Ze.bin.ril(e,r+2);16384==n&&(null==s.objects&&(s.objects=[]),s.objects.push(Ze.parse.from3DS._edit_object(e,r,A))),r+=A}return s},Ze.parse.from3DS._keyf3ds=function(e,t,i){for(var s={},r=t+6;r<t+i;){var n=Ze.bin.rsl(e,r),A=Ze.bin.ril(e,r+2);45058==n&&(null==s.desc&&(s.desc=[]),s.desc.push(Ze.parse.from3DS._keyf_objdes(e,r,A))),r+=A}return s},Ze.parse.from3DS._keyf_objdes=function(e,t,i){for(var s={},r=t+6;r<t+i;){var n=Ze.bin.rsl(e,r),A=Ze.bin.ril(e,r+2);45072==n&&(s.hierarchy=Ze.parse.from3DS._keyf_objhierarch(e,r,A)),45073==n&&(s.dummy_name=Ze.bin.rASCII0(e,r+6)),r+=A}return s},Ze.parse.from3DS._keyf_objhierarch=function(e,t,i){var s={},r=t+6;return s.name=Ze.bin.rASCII0(e,r),r+=s.name.length+1,s.hierarchy=Ze.bin.rsl(e,r+4),s},Ze.parse.from3DS._edit_object=function(e,t,i){var s={},r=t+6;for(s.name=Ze.bin.rASCII0(e,r),r+=s.name.length+1;r<t+i;){var n=Ze.bin.rsl(e,r),A=Ze.bin.ril(e,r+2);16640==n&&(s.mesh=Ze.parse.from3DS._obj_trimesh(e,r,A)),r+=A}return s},Ze.parse.from3DS._obj_trimesh=function(e,t,i){for(var s={},r=t+6;r<t+i;){var n=Ze.bin.rsl(e,r),A=Ze.bin.ril(e,r+2);16656==n&&(s.vertices=Ze.parse.from3DS._tri_vertexl(e,r,A)),16672==n&&(s.indices=Ze.parse.from3DS._tri_facel1(e,r,A)),16704==n&&(s.uvt=Ze.parse.from3DS._tri_mappingcoors(e,r,A)),16736==n&&(s.local=Ze.parse.from3DS._tri_local(e,r,A)),r+=A}return s},Ze.parse.from3DS._tri_vertexl=function(e,t,i){var s=[],r=t+6,n=Ze.bin.rsl(e,r);r+=2;for(var A=0;A<n;A++)s.push(Ze.bin.rf(e,r)),s.push(Ze.bin.rf(e,r+4)),s.push(Ze.bin.rf(e,r+8)),r+=12;return s},Ze.parse.from3DS._tri_facel1=function(e,t,i){var s=[],r=t+6,n=Ze.bin.rsl(e,r);r+=2;for(var A=0;A<n;A++)s.push(Ze.bin.rsl(e,r)),s.push(Ze.bin.rsl(e,r+2)),s.push(Ze.bin.rsl(e,r+4)),r+=8;return s},Ze.parse.from3DS._tri_mappingcoors=function(e,t,i){var s=[],r=t+6,n=Ze.bin.rsl(e,r);r+=2;for(var A=0;A<n;A++)s.push(Ze.bin.rf(e,r)),s.push(1-Ze.bin.rf(e,r+4)),r+=8;return s},Ze.parse.from3DS._tri_local=function(e,t,i){var s={},r=t+6;return s.X=[Ze.bin.rf(e,r),Ze.bin.rf(e,r+4),Ze.bin.rf(e,r+8)],r+=12,s.Y=[Ze.bin.rf(e,r),Ze.bin.rf(e,r+4),Ze.bin.rf(e,r+8)],r+=12,s.Z=[Ze.bin.rf(e,r),Ze.bin.rf(e,r+4),Ze.bin.rf(e,r+8)],r+=12,s.C=[Ze.bin.rf(e,r),Ze.bin.rf(e,r+4),Ze.bin.rf(e,r+8)],r+=12,s},Ze.parse.fromBIV=function(e){e=new Uint8Array(e);var t={},i={};return i.id=Ze.bin.ril(e,0),i.verS=Ze.bin.ril(e,4),i.texS=Ze.bin.ril(e,8),i.indS=Ze.bin.ril(e,12),i.verO=Ze.bin.ril(e,16),i.verL=Ze.bin.ril(e,20),i.texO=Ze.bin.ril(e,24),i.texL=Ze.bin.ril(e,28),i.indO=Ze.bin.ril(e,32),i.indL=Ze.bin.ril(e,36),0!=i.verO&&(t.vertices=Ze.parse.fromBIV._readFloats(e,i.verO,i.verL)),0!=i.texO&&(t.uvt=Ze.parse.fromBIV._readFloats(e,i.texO,i.texL)),0!=i.indO&&(t.indices=Ze.parse.fromBIV._readInts(e,i.indO,i.indL,i.indS)),t},Ze.parse.toBIV=function(e){for(var t=0,i=0;i<e.indices.length;i++)t=Math.max(t,e.indices[i]);var s=32;t<=65535&&(s=16);var r=40;e.vertices&&(r+=4*e.vertices.length),e.uvt&&(r+=4*e.uvt.length),e.indices&&(r+=e.indices.length*s/8);var n=new Uint8Array(r);Ze.bin.wil(n,0,1769365870),Ze.bin.wil(n,4,32),Ze.bin.wil(n,8,32),Ze.bin.wil(n,12,s);var A=40;return e.vertices&&(Ze.bin.wil(n,16,A),Ze.bin.wil(n,20,4*e.vertices.length),Ze.parse.fromBIV._writeFloats(n,A,e.vertices),A+=4*e.vertices.length),e.uvt&&(Ze.bin.wil(n,24,A),Ze.bin.wil(n,28,4*e.uvt.length),Ze.parse.fromBIV._writeFloats(n,A,e.uvt),A+=4*e.uvt.length),e.indices&&(Ze.bin.wil(n,32,A),Ze.bin.wil(n,36,4*e.indices.length),Ze.parse.fromBIV._writeInts(n,A,e.indices,s)),n.buffer},Ze.parse.fromBIV._readFloats=function(e,t,i){for(var s=[],r=0;r<i/4;r++)s.push(Ze.bin.rf(e,t+4*r));return s},Ze.parse.fromBIV._writeFloats=function(e,t,i){for(var s=0;s<i.length;s++)Ze.bin.wf(e,t+4*s,i[s])},Ze.parse.fromBIV._readInts=function(e,t,i,s){for(var r=[],n=0;n<i/4;n++)16==s&&r.push(Ze.bin.rsl(e,t+2*n)),32==s&&r.push(Ze.bin.ril(e,t+4*n));return r},Ze.parse.fromBIV._writeInts=function(e,t,i,s){for(var r=0;r<i.length;r++)16==s&&Ze.bin.wsl(e,t+2*r,i[r]),32==s&&Ze.bin.wil(e,t+4*r,i[r])},Ze.gen={},Ze.gen.Plane=function(e,t,i,s){i||(i=1),s||(s=1);for(var r={verts:[],inds:[],uvt:[]},n=e+1,A=t+1,o=0;o<A;o++)for(var a=0;a<n;a++){var l=a*(2/e)-1,c=o*(2/t)-1;r.verts.push(l,c,0),r.uvt.push(i*a/e,s*o/t),o<t&&a<e&&r.inds.push(o*n+a,o*n+a+1,(o+1)*n+a,o*n+a+1,(o+1)*n+a,(o+1)*n+a+1)}return r},Ze.gen.Cube=function(){return{verts:[-1,1,-1,1,1,-1,-1,-1,-1,1,-1,-1,-1,1,1,1,1,1,-1,-1,1,1,-1,1,-1,1,1,-1,1,-1,-1,-1,1,-1,-1,-1,1,1,1,1,1,-1,1,-1,1,1,-1,-1,-1,1,-1,1,1,-1,-1,1,1,1,1,1,-1,-1,-1,1,-1,-1,-1,-1,1,1,-1,1],inds:[0,1,2,1,2,3,4,5,6,5,6,7,8,9,10,9,10,11,12,13,14,13,14,15,16,17,18,17,18,19,20,21,22,21,22,23],uvt:[1/4,1/4,.5,1/4,1/4,.5,.5,.5,1,1/4,3/4,1/4,1,.5,3/4,.5,0,1/4,1/4,1/4,0,.5,1/4,.5,3/4,1/4,.5,1/4,3/4,.5,.5,.5,1/4,1/4,.5,1/4,1/4,0,.5,0,1/4,.5,.5,.5,1/4,3/4,.5,3/4]}},Ze.gen.Sphere=function(e,t){for(var i={verts:[],inds:[],uvt:[]},s=e+1,r=t+1,n=0;n<r;n++)for(var A=0;A<s;A++){var o=-Math.PI/2+n*Math.PI/t,a=2*A*Math.PI/e,l=Math.cos(o)*Math.cos(a),c=Math.sin(o),h=Math.cos(o)*Math.sin(a);i.verts.push(l,c,h),i.uvt.push(A/e,n/t),n<t&&A<e&&i.inds.push(s*n+A,s*n+A+1,s*(n+1)+A,s*n+A+1,s*(n+1)+A,s*(n+1)+A+1)}return i},Ze.mat={},Ze.mat.scale=function(e,t,i){return[e,0,0,0,0,t,0,0,0,0,i,0,0,0,0,1]},Ze.mat.translate=function(e,t,i){return[1,0,0,0,0,1,0,0,0,0,1,0,e,t,i,1]},Ze.mat.rotateDeg=function(e,t,i){var s=Math.PI/180;return Ze.mat.rotate(e*s,t*s,i*s)},Ze.mat.rotate=function(e,t,i){var s=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],r=e,n=t,A=i,o=Math.cos(r),a=Math.cos(n),l=Math.cos(A),c=Math.sin(r),h=Math.sin(n),u=Math.sin(A);return s[0]=a*l,s[1]=-a*u,s[2]=h,s[4]=o*u+c*h*l,s[5]=o*l-c*h*u,s[6]=-c*a,s[8]=c*u-o*h*l,s[9]=c*l+o*h*u,s[10]=o*a,s},Ze.edit={},Ze.edit.interpolate=function(e,t,i,s){for(var r=0;r<e.length;r++)i[r]=e[r]+s*(t[r]-e[r])},Ze.edit.transform=function(e,t){for(var i=0;i<e.length;i+=3){var s=e[i],r=e[i+1],n=e[i+2];e[i+0]=t[0]*s+t[4]*r+t[8]*n+t[12],e[i+1]=t[1]*s+t[5]*r+t[9]*n+t[13],e[i+2]=t[2]*s+t[6]*r+t[10]*n+t[14]}},Ze.edit.unwrap=function(e,t,i){for(var s=new Array(Math.floor(e.length/3)*i),r=0;r<e.length;r++)for(var n=0;n<i;n++)s[r*i+n]=t[e[r]*i+n];return s},Ze.edit.remap=function(e,t,i,s){for(var r=new Array(i.length),n=0;n<e.length;n++)for(var A=0;A<s;A++)r[t[n]*s+A]=i[e[n]*s+A];return r},Ze.utils={},Ze.utils.getAABB=function(e){var t,i,s,r,n,A;r=n=A=-(t=i=s=999999999);for(var o=0;o<e.length;o+=3){var a=e[o+0],l=e[o+1],c=e[o+2];a<t&&(t=a),a>r&&(r=a),l<i&&(i=l),l>n&&(n=l),c<s&&(s=c),l>A&&(A=c)}return{min:{x:t,y:i,z:s},max:{x:r,y:n,z:A}}};const At={" ":{width:16,points:[]},"!":{width:10,points:[[5,21],[5,7],[-1,-1],[5,2],[4,1],[5,0],[6,1],[5,2]]},'"':{width:16,points:[[4,21],[4,14],[-1,-1],[12,21],[12,14]]},"#":{width:21,points:[[11,25],[4,-7],[-1,-1],[17,25],[10,-7],[-1,-1],[4,12],[18,12],[-1,-1],[3,6],[17,6]]},$:{width:20,points:[[8,25],[8,-4],[-1,-1],[12,25],[12,-4],[-1,-1],[17,18],[15,20],[12,21],[8,21],[5,20],[3,18],[3,16],[4,14],[5,13],[7,12],[13,10],[15,9],[16,8],[17,6],[17,3],[15,1],[12,0],[8,0],[5,1],[3,3]]},"%":{width:24,points:[[21,21],[3,0],[-1,-1],[8,21],[10,19],[10,17],[9,15],[7,14],[5,14],[3,16],[3,18],[4,20],[6,21],[8,21],[10,20],[13,19],[16,19],[19,20],[21,21],[-1,-1],[17,7],[15,6],[14,4],[14,2],[16,0],[18,0],[20,1],[21,3],[21,5],[19,7],[17,7]]},"&":{width:26,points:[[23,12],[23,13],[22,14],[21,14],[20,13],[19,11],[17,6],[15,3],[13,1],[11,0],[7,0],[5,1],[4,2],[3,4],[3,6],[4,8],[5,9],[12,13],[13,14],[14,16],[14,18],[13,20],[11,21],[9,20],[8,18],[8,16],[9,13],[11,10],[16,3],[18,1],[20,0],[22,0],[23,1],[23,2]]},"'":{width:10,points:[[5,19],[4,20],[5,21],[6,20],[6,18],[5,16],[4,15]]},"(":{width:14,points:[[11,25],[9,23],[7,20],[5,16],[4,11],[4,7],[5,2],[7,-2],[9,-5],[11,-7]]},")":{width:14,points:[[3,25],[5,23],[7,20],[9,16],[10,11],[10,7],[9,2],[7,-2],[5,-5],[3,-7]]},"*":{width:16,points:[[8,21],[8,9],[-1,-1],[3,18],[13,12],[-1,-1],[13,18],[3,12]]},"+":{width:26,points:[[13,18],[13,0],[-1,-1],[4,9],[22,9]]},",":{width:10,points:[[6,1],[5,0],[4,1],[5,2],[6,1],[6,-1],[5,-3],[4,-4]]},"-":{width:26,points:[[4,9],[22,9]]},".":{width:10,points:[[5,2],[4,1],[5,0],[6,1],[5,2]]},"/":{width:22,points:[[20,25],[2,-7]]},0:{width:20,points:[[9,21],[6,20],[4,17],[3,12],[3,9],[4,4],[6,1],[9,0],[11,0],[14,1],[16,4],[17,9],[17,12],[16,17],[14,20],[11,21],[9,21]]},1:{width:20,points:[[6,17],[8,18],[11,21],[11,0]]},2:{width:20,points:[[4,16],[4,17],[5,19],[6,20],[8,21],[12,21],[14,20],[15,19],[16,17],[16,15],[15,13],[13,10],[3,0],[17,0]]},3:{width:20,points:[[5,21],[16,21],[10,13],[13,13],[15,12],[16,11],[17,8],[17,6],[16,3],[14,1],[11,0],[8,0],[5,1],[4,2],[3,4]]},4:{width:20,points:[[13,21],[3,7],[18,7],[-1,-1],[13,21],[13,0]]},5:{width:20,points:[[15,21],[5,21],[4,12],[5,13],[8,14],[11,14],[14,13],[16,11],[17,8],[17,6],[16,3],[14,1],[11,0],[8,0],[5,1],[4,2],[3,4]]},6:{width:20,points:[[16,18],[15,20],[12,21],[10,21],[7,20],[5,17],[4,12],[4,7],[5,3],[7,1],[10,0],[11,0],[14,1],[16,3],[17,6],[17,7],[16,10],[14,12],[11,13],[10,13],[7,12],[5,10],[4,7]]},7:{width:20,points:[[17,21],[7,0],[-1,-1],[3,21],[17,21]]},8:{width:20,points:[[8,21],[5,20],[4,18],[4,16],[5,14],[7,13],[11,12],[14,11],[16,9],[17,7],[17,4],[16,2],[15,1],[12,0],[8,0],[5,1],[4,2],[3,4],[3,7],[4,9],[6,11],[9,12],[13,13],[15,14],[16,16],[16,18],[15,20],[12,21],[8,21]]},9:{width:20,points:[[16,14],[15,11],[13,9],[10,8],[9,8],[6,9],[4,11],[3,14],[3,15],[4,18],[6,20],[9,21],[10,21],[13,20],[15,18],[16,14],[16,9],[15,4],[13,1],[10,0],[8,0],[5,1],[4,3]]},":":{width:10,points:[[5,14],[4,13],[5,12],[6,13],[5,14],[-1,-1],[5,2],[4,1],[5,0],[6,1],[5,2]]},";":{width:10,points:[[5,14],[4,13],[5,12],[6,13],[5,14],[-1,-1],[6,1],[5,0],[4,1],[5,2],[6,1],[6,-1],[5,-3],[4,-4]]},"<":{width:24,points:[[20,18],[4,9],[20,0]]},"=":{width:26,points:[[4,12],[22,12],[-1,-1],[4,6],[22,6]]},">":{width:24,points:[[4,18],[20,9],[4,0]]},"?":{width:18,points:[[3,16],[3,17],[4,19],[5,20],[7,21],[11,21],[13,20],[14,19],[15,17],[15,15],[14,13],[13,12],[9,10],[9,7],[-1,-1],[9,2],[8,1],[9,0],[10,1],[9,2]]},"@":{width:27,points:[[18,13],[17,15],[15,16],[12,16],[10,15],[9,14],[8,11],[8,8],[9,6],[11,5],[14,5],[16,6],[17,8],[-1,-1],[12,16],[10,14],[9,11],[9,8],[10,6],[11,5],[-1,-1],[18,16],[17,8],[17,6],[19,5],[21,5],[23,7],[24,10],[24,12],[23,15],[22,17],[20,19],[18,20],[15,21],[12,21],[9,20],[7,19],[5,17],[4,15],[3,12],[3,9],[4,6],[5,4],[7,2],[9,1],[12,0],[15,0],[18,1],[20,2],[21,3],[-1,-1],[19,16],[18,8],[18,6],[19,5]]},A:{width:18,points:[[9,21],[1,0],[-1,-1],[9,21],[17,0],[-1,-1],[4,7],[14,7]]},B:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[13,21],[16,20],[17,19],[18,17],[18,15],[17,13],[16,12],[13,11],[-1,-1],[4,11],[13,11],[16,10],[17,9],[18,7],[18,4],[17,2],[16,1],[13,0],[4,0]]},C:{width:21,points:[[18,16],[17,18],[15,20],[13,21],[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5]]},D:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[11,21],[14,20],[16,18],[17,16],[18,13],[18,8],[17,5],[16,3],[14,1],[11,0],[4,0]]},E:{width:19,points:[[4,21],[4,0],[-1,-1],[4,21],[17,21],[-1,-1],[4,11],[12,11],[-1,-1],[4,0],[17,0]]},F:{width:18,points:[[4,21],[4,0],[-1,-1],[4,21],[17,21],[-1,-1],[4,11],[12,11]]},G:{width:21,points:[[18,16],[17,18],[15,20],[13,21],[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5],[18,8],[-1,-1],[13,8],[18,8]]},H:{width:22,points:[[4,21],[4,0],[-1,-1],[18,21],[18,0],[-1,-1],[4,11],[18,11]]},I:{width:8,points:[[4,21],[4,0]]},J:{width:16,points:[[12,21],[12,5],[11,2],[10,1],[8,0],[6,0],[4,1],[3,2],[2,5],[2,7]]},K:{width:21,points:[[4,21],[4,0],[-1,-1],[18,21],[4,7],[-1,-1],[9,12],[18,0]]},L:{width:17,points:[[4,21],[4,0],[-1,-1],[4,0],[16,0]]},M:{width:24,points:[[4,21],[4,0],[-1,-1],[4,21],[12,0],[-1,-1],[20,21],[12,0],[-1,-1],[20,21],[20,0]]},N:{width:22,points:[[4,21],[4,0],[-1,-1],[4,21],[18,0],[-1,-1],[18,21],[18,0]]},O:{width:22,points:[[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5],[19,8],[19,13],[18,16],[17,18],[15,20],[13,21],[9,21]]},P:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[13,21],[16,20],[17,19],[18,17],[18,14],[17,12],[16,11],[13,10],[4,10]]},Q:{width:22,points:[[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5],[19,8],[19,13],[18,16],[17,18],[15,20],[13,21],[9,21],[-1,-1],[12,4],[18,-2]]},R:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[13,21],[16,20],[17,19],[18,17],[18,15],[17,13],[16,12],[13,11],[4,11],[-1,-1],[11,11],[18,0]]},S:{width:20,points:[[17,18],[15,20],[12,21],[8,21],[5,20],[3,18],[3,16],[4,14],[5,13],[7,12],[13,10],[15,9],[16,8],[17,6],[17,3],[15,1],[12,0],[8,0],[5,1],[3,3]]},T:{width:16,points:[[8,21],[8,0],[-1,-1],[1,21],[15,21]]},U:{width:22,points:[[4,21],[4,6],[5,3],[7,1],[10,0],[12,0],[15,1],[17,3],[18,6],[18,21]]},V:{width:18,points:[[1,21],[9,0],[-1,-1],[17,21],[9,0]]},W:{width:24,points:[[2,21],[7,0],[-1,-1],[12,21],[7,0],[-1,-1],[12,21],[17,0],[-1,-1],[22,21],[17,0]]},X:{width:20,points:[[3,21],[17,0],[-1,-1],[17,21],[3,0]]},Y:{width:18,points:[[1,21],[9,11],[9,0],[-1,-1],[17,21],[9,11]]},Z:{width:20,points:[[17,21],[3,0],[-1,-1],[3,21],[17,21],[-1,-1],[3,0],[17,0]]},"[":{width:14,points:[[4,25],[4,-7],[-1,-1],[5,25],[5,-7],[-1,-1],[4,25],[11,25],[-1,-1],[4,-7],[11,-7]]},"\\":{width:14,points:[[0,21],[14,-3]]},"]":{width:14,points:[[9,25],[9,-7],[-1,-1],[10,25],[10,-7],[-1,-1],[3,25],[10,25],[-1,-1],[3,-7],[10,-7]]},"^":{width:16,points:[[6,15],[8,18],[10,15],[-1,-1],[3,12],[8,17],[13,12],[-1,-1],[8,17],[8,0]]},_:{width:16,points:[[0,-2],[16,-2]]},"`":{width:10,points:[[6,21],[5,20],[4,18],[4,16],[5,15],[6,16],[5,17]]},a:{width:19,points:[[15,14],[15,0],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},b:{width:19,points:[[4,21],[4,0],[-1,-1],[4,11],[6,13],[8,14],[11,14],[13,13],[15,11],[16,8],[16,6],[15,3],[13,1],[11,0],[8,0],[6,1],[4,3]]},c:{width:18,points:[[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},d:{width:19,points:[[15,21],[15,0],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},e:{width:18,points:[[3,8],[15,8],[15,10],[14,12],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},f:{width:12,points:[[10,21],[8,21],[6,20],[5,17],[5,0],[-1,-1],[2,14],[9,14]]},g:{width:19,points:[[15,14],[15,-2],[14,-5],[13,-6],[11,-7],[8,-7],[6,-6],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},h:{width:19,points:[[4,21],[4,0],[-1,-1],[4,10],[7,13],[9,14],[12,14],[14,13],[15,10],[15,0]]},i:{width:8,points:[[3,21],[4,20],[5,21],[4,22],[3,21],[-1,-1],[4,14],[4,0]]},j:{width:10,points:[[5,21],[6,20],[7,21],[6,22],[5,21],[-1,-1],[6,14],[6,-3],[5,-6],[3,-7],[1,-7]]},k:{width:17,points:[[4,21],[4,0],[-1,-1],[14,14],[4,4],[-1,-1],[8,8],[15,0]]},l:{width:8,points:[[4,21],[4,0]]},m:{width:30,points:[[4,14],[4,0],[-1,-1],[4,10],[7,13],[9,14],[12,14],[14,13],[15,10],[15,0],[-1,-1],[15,10],[18,13],[20,14],[23,14],[25,13],[26,10],[26,0]]},n:{width:19,points:[[4,14],[4,0],[-1,-1],[4,10],[7,13],[9,14],[12,14],[14,13],[15,10],[15,0]]},o:{width:19,points:[[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3],[16,6],[16,8],[15,11],[13,13],[11,14],[8,14]]},p:{width:19,points:[[4,14],[4,-7],[-1,-1],[4,11],[6,13],[8,14],[11,14],[13,13],[15,11],[16,8],[16,6],[15,3],[13,1],[11,0],[8,0],[6,1],[4,3]]},q:{width:19,points:[[15,14],[15,-7],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},r:{width:13,points:[[4,14],[4,0],[-1,-1],[4,8],[5,11],[7,13],[9,14],[12,14]]},s:{width:17,points:[[14,11],[13,13],[10,14],[7,14],[4,13],[3,11],[4,9],[6,8],[11,7],[13,6],[14,4],[14,3],[13,1],[10,0],[7,0],[4,1],[3,3]]},t:{width:12,points:[[5,21],[5,4],[6,1],[8,0],[10,0],[-1,-1],[2,14],[9,14]]},u:{width:19,points:[[4,14],[4,4],[5,1],[7,0],[10,0],[12,1],[15,4],[-1,-1],[15,14],[15,0]]},v:{width:16,points:[[2,14],[8,0],[-1,-1],[14,14],[8,0]]},w:{width:22,points:[[3,14],[7,0],[-1,-1],[11,14],[7,0],[-1,-1],[11,14],[15,0],[-1,-1],[19,14],[15,0]]},x:{width:17,points:[[3,14],[14,0],[-1,-1],[14,14],[3,0]]},y:{width:16,points:[[2,14],[8,0],[-1,-1],[14,14],[8,0],[6,-4],[4,-6],[2,-7],[1,-7]]},z:{width:17,points:[[14,14],[3,0],[-1,-1],[3,14],[14,14],[-1,-1],[3,0],[14,0]]},"{":{width:14,points:[[9,25],[7,24],[6,23],[5,21],[5,19],[6,17],[7,16],[8,14],[8,12],[6,10],[-1,-1],[7,24],[6,22],[6,20],[7,18],[8,17],[9,15],[9,13],[8,11],[4,9],[8,7],[9,5],[9,3],[8,1],[7,0],[6,-2],[6,-4],[7,-6],[-1,-1],[6,8],[8,6],[8,4],[7,2],[6,1],[5,-1],[5,-3],[6,-5],[7,-6],[9,-7]]},"|":{width:8,points:[[4,25],[4,-7]]},"}":{width:14,points:[[5,25],[7,24],[8,23],[9,21],[9,19],[8,17],[7,16],[6,14],[6,12],[8,10],[-1,-1],[7,24],[8,22],[8,20],[7,18],[6,17],[5,15],[5,13],[6,11],[10,9],[6,7],[5,5],[5,3],[6,1],[7,0],[8,-2],[8,-4],[7,-6],[-1,-1],[8,8],[6,6],[6,4],[7,2],[8,1],[9,-1],[9,-3],[8,-5],[7,-6],[5,-7]]},"~":{width:24,points:[[3,6],[3,8],[4,11],[6,12],[8,12],[10,11],[14,8],[16,7],[18,7],[20,8],[21,10],[-1,-1],[3,8],[4,10],[6,11],[8,11],[10,10],[14,7],[16,6],[18,6],[20,7],[21,10],[21,12]]}};function ot(e={}){var t=e.origin||[0,0,0],i=t[0],s=t[1],r=t[2],n=e.size||1,A=[],o=[],a=e.text;X.isNumeric(a)&&(a=""+a);for(var l,c,h,u,d,f,p,g,m,_=(a||"").split("\n"),b=0,B=0,y=.04,w=0;w<_.length;w++){l=0,h=(c=_[w]).length;for(var v=0;v<h;v++)if(u=At[c.charAt(v)]){d=1,f=-1,p=-1,g=u.points.length;for(var C=0;C<g;C++)-1!==(m=u.points[C])[0]||-1!==m[1]?(A.push(l+m[0]*n*y+i),A.push(B+m[1]*n*y+s),A.push(0+r),-1===f?f=b:(-1===p||(f=p),p=b),b++,d?d=!1:(o.push(f),o.push(p))):d=1;l+=u.width*y*n}B-=35*y*n}return X.apply(e,{primitive:"lines",positions:A,indices:o})}function at(e={}){if(e.points.length%3!=0)throw"Size of points array for given polyline should be divisible by 3";let t=e.points.length/3;if(t<2)throw"There should be at least 2 points to create a polyline";let i=[];for(let e=0;e<t-1;e++)i.push(e),i.push(e+1);return X.apply(e,{primitive:"lines",positions:e.points,indices:i})}function lt(e={}){let t=e.curve.getPoints(e.divisions).map((e=>[...e])).flat();return at({id:e.id,points:t})}function ct(e={}){if(3!==e.startPoint.length)throw"Start point should contain 3 elements in array: x, y and z";if(3!==e.endPoint.length)throw"End point should contain 3 elements in array: x, y and z";let t=[],i=[],s=e.startPoint[0],r=e.startPoint[1],n=e.startPoint[2],A=e.endPoint[0],o=e.endPoint[1],a=e.endPoint[2],l=Math.sqrt((A-s)**2+(o-r)**2+(a-n)**2),c=[(A-s)/l,(o-r)/l,(a-n)/l];if(e.pattern){let h=e.pattern.length,u=!1,d=0,f=0,p=0,g=[s,r,n],m=e.pattern[f];for(i.push(g[0],g[1],g[2]);m<=l-d;){let s=[c[0]*m,c[1]*m,c[2]*m],r=[g[0]+s[0],g[1]+s[1],g[2]+s[2]];i.push(r[0],r[1],r[2]),u||(t.push(p),t.push(p+1)),u=!u,p+=1,g=r,f+=1,f>=h&&(f=0),d+=m,m=e.pattern[f]}e.extendToEnd&&(i.push(A,o,a),t.push(t.length-2),t.push(t.length-1))}else t.push(0),t.push(1),i.push(s,r,n,A,o,a);return X.apply(e,{primitive:"lines",positions:i,indices:t})}const ht=V.vec4(4),ut=V.vec4(),dt=V.vec4(),ft=V.vec3([1,0,0]),pt=V.vec3([0,1,0]),gt=V.vec3([0,0,1]),mt=V.vec3(3),_t=V.vec3(3),bt=V.identityMat4();class Bt extends Ae{constructor(e,t={}){if(super(e,t),this._parentNode=null,this._children=[],this._aabb=null,this._aabbDirty=!0,this.scene._aabbDirty=!0,this._numTriangles=0,this._scale=V.vec3(),this._quaternion=V.identityQuaternion(),this._rotation=V.vec3(),this._position=V.vec3(),this._offset=V.vec3(),this._localMatrix=V.identityMat4(),this._worldMatrix=V.identityMat4(),this._localMatrixDirty=!0,this._worldMatrixDirty=!0,t.matrix?this.matrix=t.matrix:(this.scale=t.scale,this.position=t.position,t.quaternion||(this.rotation=t.rotation)),this._isModel=t.isModel,this._isModel&&this.scene._registerModel(this),this._isObject=t.isObject,this._isObject&&this.scene._registerObject(this),this.origin=t.origin,this.visible=t.visible,this.culled=t.culled,this.pickable=t.pickable,this.clippable=t.clippable,this.collidable=t.collidable,this.castsShadow=t.castsShadow,this.receivesShadow=t.receivesShadow,this.xrayed=t.xrayed,this.highlighted=t.highlighted,this.selected=t.selected,this.edges=t.edges,this.colorize=t.colorize,this.opacity=t.opacity,this.offset=t.offset,t.children){const e=t.children;for(let i=0,s=e.length;i<s;i++)this.addChild(e[i],t.inheritStates)}if(t.parentId){const e=this.scene.components[t.parentId];e?e.isNode?e.addChild(this):this.error("Parent is not a Node: '"+t.parentId+"'"):this.error("Parent not found: '"+t.parentId+"'")}else t.parent&&(t.parent.isNode||this.error("Parent is not a Node"),t.parent.addChild(this))}get isEntity(){return!0}get isModel(){return this._isModel}get isObject(){return this._isObject}get aabb(){return this._aabbDirty&&this._updateAABB(),this._aabb}set origin(e){e?(this._origin||(this._origin=V.vec3()),this._origin.set(e)):this._origin&&(this._origin=null);for(let t=0,i=this._children.length;t<i;t++)this._children[t].origin=e;this.glRedraw()}get origin(){return this._origin}set rtcCenter(e){this.origin=e}get rtcCenter(){return this.origin}get numTriangles(){return this._numTriangles}set visible(e){e=!1!==e,this._visible=e;for(let t=0,i=this._children.length;t<i;t++)this._children[t].visible=e;this._isObject&&this.scene._objectVisibilityUpdated(this,e)}get visible(){return this._visible}set xrayed(e){e=!!e,this._xrayed=e;for(let t=0,i=this._children.length;t<i;t++)this._children[t].xrayed=e;this._isObject&&this.scene._objectXRayedUpdated(this,e)}get xrayed(){return this._xrayed}set highlighted(e){e=!!e,this._highlighted=e;for(let t=0,i=this._children.length;t<i;t++)this._children[t].highlighted=e;this._isObject&&this.scene._objectHighlightedUpdated(this,e)}get highlighted(){return this._highlighted}set selected(e){e=!!e,this._selected=e;for(let t=0,i=this._children.length;t<i;t++)this._children[t].selected=e;this._isObject&&this.scene._objectSelectedUpdated(this,e)}get selected(){return this._selected}set edges(e){e=!!e,this._edges=e;for(let t=0,i=this._children.length;t<i;t++)this._children[t].edges=e}get edges(){return this._edges}set culled(e){e=!!e,this._culled=e;for(let t=0,i=this._children.length;t<i;t++)this._children[t].culled=e}get culled(){return this._culled}set clippable(e){e=!1!==e,this._clippable=e;for(let t=0,i=this._children.length;t<i;t++)this._children[t].clippable=e}get clippable(){return this._clippable}set collidable(e){e=!1!==e,this._collidable=e;for(let t=0,i=this._children.length;t<i;t++)this._children[t].collidable=e}get collidable(){return this._collidable}set pickable(e){e=!1!==e,this._pickable=e;for(let t=0,i=this._children.length;t<i;t++)this._children[t].pickable=e}get pickable(){return this._pickable}set colorize(e){let t=this._colorize;t||(t=this._colorize=new Float32Array(4),t[3]=1),e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1);for(let e=0,i=this._children.length;e<i;e++)this._children[e].colorize=t;if(this._isObject){const t=!!e;this.scene._objectColorizeUpdated(this,t)}}get colorize(){return this._colorize.slice(0,3)}set opacity(e){let t=this._colorize;t||(t=this._colorize=new Float32Array(4),t[0]=1,t[1]=1,t[2]=1),t[3]=null!=e?e:1;for(let t=0,i=this._children.length;t<i;t++)this._children[t].opacity=e;if(this._isObject){const t=null!=e;this.scene._objectOpacityUpdated(this,t)}}get opacity(){return this._colorize[3]}set castsShadow(e){e=!!e,this._castsShadow=e;for(let t=0,i=this._children.length;t<i;t++)this._children[t].castsShadow=e}get castsShadow(){return this._castsShadow}set receivesShadow(e){e=!!e,this._receivesShadow=e;for(let t=0,i=this._children.length;t<i;t++)this._children[t].receivesShadow=e}get receivesShadow(){return this._receivesShadow}get saoEnabled(){return!1}set offset(e){e?(this._offset[0]=e[0],this._offset[1]=e[1],this._offset[2]=e[2]):(this._offset[0]=0,this._offset[1]=0,this._offset[2]=0);for(let e=0,t=this._children.length;e<t;e++)this._children[e].offset=this._offset;this._isObject&&this.scene._objectOffsetUpdated(this,e)}get offset(){return this._offset}get isNode(){return!0}_setLocalMatrixDirty(){this._localMatrixDirty=!0,this._setWorldMatrixDirty()}_setWorldMatrixDirty(){this._worldMatrixDirty=!0;for(let e=0,t=this._children.length;e<t;e++)this._children[e]._setWorldMatrixDirty()}_buildWorldMatrix(){const e=this.matrix;if(this._parentNode)V.mulMat4(this._parentNode.worldMatrix,e,this._worldMatrix);else for(let t=0,i=e.length;t<i;t++)this._worldMatrix[t]=e[t];this._worldMatrixDirty=!1}_setSubtreeAABBsDirty(e){if(e._aabbDirty=!0,e._children)for(let t=0,i=e._children.length;t<i;t++)this._setSubtreeAABBsDirty(e._children[t])}_setAABBDirty(){if(this._setSubtreeAABBsDirty(this),this.collidable)for(let e=this;e;e=e._parentNode)e._aabbDirty=!0}_updateAABB(){if(this.scene._aabbDirty=!0,this._aabb||(this._aabb=V.AABB3()),this._buildAABB)this._buildAABB(this.worldMatrix,this._aabb);else{let e;V.collapseAABB3(this._aabb);for(let t=0,i=this._children.length;t<i;t++)e=this._children[t],e.collidable&&V.expandAABB3(this._aabb,e.aabb)}this._aabbDirty=!1}addChild(e,t){if(X.isNumeric(e)||X.isString(e)){const t=e;if(!(e=this.scene.component[t]))return void this.warn("Component not found: "+X.inQuotes(t));if(!e.isNode&&!e.isMesh)return void this.error("Not a Node or Mesh: "+t)}else{if(!e.isNode&&!e.isMesh)return void this.error("Not a Node or Mesh: "+e.id);if(e._parentNode){if(e._parentNode.id===this.id)return void this.warn("Already a child: "+e.id);e._parentNode.removeChild(e)}}if(e.id,e.scene.id===this.scene.id)return this._children.push(e),e._parentNode=this,t&&(e.visible=this.visible,e.culled=this.culled,e.xrayed=this.xrayed,e.highlited=this.highlighted,e.selected=this.selected,e.edges=this.edges,e.clippable=this.clippable,e.pickable=this.pickable,e.collidable=this.collidable,e.castsShadow=this.castsShadow,e.receivesShadow=this.receivesShadow,e.colorize=this.colorize,e.opacity=this.opacity,e.offset=this.offset),e._setWorldMatrixDirty(),e._setAABBDirty(),this._numTriangles+=e.numTriangles,e;this.error("Child not in same Scene: "+e.id)}removeChild(e){for(let t=0,i=this._children.length;t<i;t++)if(this._children[t].id===e.id)return e._parentNode=null,this._children=this._children.splice(t,1),e._setWorldMatrixDirty(),e._setAABBDirty(),this._setAABBDirty(),void(this._numTriangles-=e.numTriangles)}removeChildren(){let e;for(let t=0,i=this._children.length;t<i;t++)e=this._children[t],e._parentNode=null,e._setWorldMatrixDirty(),e._setAABBDirty(),this._numTriangles-=e.numTriangles;this._children=[],this._setAABBDirty()}get numChildren(){return this._children.length}get children(){return this._children}set parent(e){if(X.isNumeric(e)||X.isString(e)){const t=e;if(!(e=this.scene.components[t]))return void this.warn("Node not found: "+X.inQuotes(t));if(!e.isNode)return void this.error("Not a Node: "+e.id)}e.scene.id===this.scene.id?this._parentNode&&this._parentNode.id===e.id?this.warn("Already a child of Node: "+e.id):e.addChild(this):this.error("Node not in same Scene: "+e.id)}get parent(){return this._parentNode}set position(e){this._position.set(e||[0,0,0]),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw()}get position(){return this._position}set rotation(e){this._rotation.set(e||[0,0,0]),V.eulerToQuaternion(this._rotation,"XYZ",this._quaternion),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw()}get rotation(){return this._rotation}set quaternion(e){this._quaternion.set(e||[0,0,0,1]),V.quaternionToEuler(this._quaternion,"XYZ",this._rotation),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw()}get quaternion(){return this._quaternion}set scale(e){this._scale.set(e||[1,1,1]),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw()}get scale(){return this._scale}set matrix(e){this._localMatrix||(this._localMatrix=V.identityMat4()),this._localMatrix.set(e||bt),V.decomposeMat4(this._localMatrix,this._position,this._quaternion,this._scale),this._localMatrixDirty=!1,this._setWorldMatrixDirty(),this._setAABBDirty(),this.glRedraw()}get matrix(){return this._localMatrixDirty&&(this._localMatrix||(this._localMatrix=V.identityMat4()),V.composeMat4(this._position,this._quaternion,this._scale,this._localMatrix),this._localMatrixDirty=!1),this._localMatrix}get worldMatrix(){return this._worldMatrixDirty&&this._buildWorldMatrix(),this._worldMatrix}rotate(e,t){return ht[0]=e[0],ht[1]=e[1],ht[2]=e[2],ht[3]=t*V.DEGTORAD,V.angleAxisToQuaternion(ht,ut),V.mulQuaternions(this.quaternion,ut,dt),this.quaternion=dt,this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw(),this}rotateOnWorldAxis(e,t){return ht[0]=e[0],ht[1]=e[1],ht[2]=e[2],ht[3]=t*V.DEGTORAD,V.angleAxisToQuaternion(ht,ut),V.mulQuaternions(ut,this.quaternion,ut),this}rotateX(e){return this.rotate(ft,e)}rotateY(e){return this.rotate(pt,e)}rotateZ(e){return this.rotate(gt,e)}translate(e,t){return V.vec3ApplyQuaternion(this.quaternion,e,mt),V.mulVec3Scalar(mt,t,_t),V.addVec3(this.position,_t,this.position),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw(),this}translateX(e){return this.translate(ft,e)}translateY(e){return this.translate(pt,e)}translateZ(e){return this.translate(gt,e)}get type(){return"Node"}destroy(){if(super.destroy(),this._parentNode&&this._parentNode.removeChild(this),this._isObject&&(this.scene._deregisterObject(this),this._visible&&this.scene._objectVisibilityUpdated(this,!1,!1),this._xrayed&&this.scene._objectXRayedUpdated(this,!1,!1),this._selected&&this.scene._objectSelectedUpdated(this,!1,!1),this._highlighted&&this.scene._objectHighlightedUpdated(this,!1,!1),this.scene._objectColorizeUpdated(this,!1),this.scene._objectOpacityUpdated(this,!1),this.offset.some((e=>0!==e))&&this.scene._objectOffsetUpdated(this,!1)),this._isModel&&this.scene._deregisterModel(this),this._children.length){const e=this._children.splice(0);let t;for(let i=0,s=e.length;i<s;i++)t=e[i],t.destroy()}this._children=[],this._setAABBDirty(),this.scene._aabbDirty=!0}}const yt=V.vec3(),wt=function(){const e=new Float64Array(16),t=new Float64Array(4),i=new Float64Array(4);return function(s,r,n){return n=n||e,t[0]=r[0],t[1]=r[1],t[2]=r[2],t[3]=1,V.transformVec4(s,t,i),V.setMat4Translation(s,i,n),n.slice()}}();function vt(e,t,i){const s=Float32Array.from([e[0]])[0],r=e[0]-s,n=Float32Array.from([e[1]])[0],A=e[1]-n,o=Float32Array.from([e[2]])[0],a=e[2]-o;t[0]=s,t[1]=n,t[2]=o,i[0]=r,i[1]=A,i[2]=a}function Ct(e,t,i,s=1e3){const r=V.getPositionsCenter(e,yt),n=Math.round(r[0]/s)*s,A=Math.round(r[1]/s)*s,o=Math.round(r[2]/s)*s;i[0]=n,i[1]=A,i[2]=o;const a=0!==i[0]||0!==i[1]||0!==i[2];if(a)for(let i=0,s=e.length;i<s;i+=3)t[i+0]=e[i+0]-n,t[i+1]=e[i+1]-A,t[i+2]=e[i+2]-o;return a}const Mt=1e3,Et=1001,Ft=1002,Ut=1003,xt=1004,It=1004,Tt=1005,Pt=1005,St=1006,Dt=1007,kt=1007,Qt=1008,Rt=1008,Ot=1009,Vt=1010,Lt=1011,Ht=1012,Nt=1013,Gt=1014,jt=1015,Wt=1016,zt=1017,Xt=1018,Kt=1020,Zt=1021,Jt=1022,Yt=1023,$t=1024,qt=1025,ei=1026,ti=1027,ii=1028,si=1029,ri=1030,ni=1031,Ai=1033,oi=33776,ai=33777,li=33778,ci=33779,hi=35840,ui=35841,di=35842,fi=35843,pi=36196,gi=37492,mi=37496,_i=37808,bi=37809,Bi=37810,yi=37811,wi=37812,vi=37813,Ci=37814,Mi=37815,Ei=37816,Fi=37817,Ui=37818,xi=37819,Ii=37820,Ti=37821,Pi=36492,Si=3e3,Di=3001,ki=1e4,Qi=10001,Ri=10002,Oi=10003,Vi=new e({}),Li=V.vec3(),Hi=V.vec4(),Ni={3001:"sRGBToLinear"},Gi=function(){const e=[],t=[],i=[],s=[],r=[],n=[],A=[],o=(t,i)=>{let s=!1;return e.push((e=>s&&i(t,e))),{toString:()=>(s=!0,t)}},a={createAttribute:function(t,i){let s=!1;e.push((e=>s&&e.push(`in ${t} ${i};`)));const A={toString:()=>(s=!0,i)};return r.push((e=>{const t=s&&e(i);return t&&n.push(t.attributeHash),A.setInputValue=t,null})),A},createFragmentDefinition:(e,t)=>{let i=!1;return s.push((s=>i&&t(e,s))),{toString:()=>(i=!0,e)}},createOutput:(e,t,s)=>{let r=!1;return i.push((i=>r&&i.push(`layout(location = ${s||0}) out ${e} ${t};`))),{toString:()=>(r=!0,t)}},createUniform:(t,s,r)=>{let n=!1;const o=e=>n&&e.push(`uniform ${t} ${s};`);e.push(o),i.push(o);const a={toString:()=>(n=!0,s)};return A.push((e=>{const t=n&&e(s);return r?t&&(e=>r(t,e)):(a.setInputValue=t,null)})),a},createUniformArray:(t,s,r)=>{let n=!1;const o=e=>n&&e.push(`uniform ${t} ${s}[${r}];`);e.push(o),i.push(o);const a={toString:()=>(n=!0,s)};return A.push((e=>(a.setInputValue=n&&e(s),null))),a},createUniformBlock:(t,s,r)=>{let n=!1;const o=Object.keys(s),a=e=>{n&&(e.push(`uniform ${t} {`),o.forEach((t=>e.push(` ${s[t]} ${t};`))),e.push("};"))};e.push(a),i.push(a);const l={};return o.forEach((e=>l[e]={toString:()=>(n=!0,e)})),A.push((e=>{const i=n&&e(t);return r?i&&(e=>r(i,e)):(l.setInputValue=i,null)})),l},createVarying:(s,r,n,A)=>{let o=!1;const a=A?A+" ":"";return e.push((e=>o&&e.push(`${a}out ${s} ${r};`))),t.push((e=>o&&e.push(`${r} = ${n()};`))),i.push((e=>o&&e.push(`${a}in ${s} ${r};`))),{toString:()=>(o=!0,r)}},createVertexDefinition:o,commonLibrary:{octDecode:o("octDecode",((e,t)=>{t.push(`vec3 ${e}(vec2 oct) {`),t.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),t.push(" if (v.z < 0.0) {"),t.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),t.push(" }"),t.push(" return normalize(v);"),t.push("}")}))}};return{programVariables:a,buildProgram:(o,l,c)=>{const h=c.getLogDepth,u=c.clipPos,d=c.usePickClipPos&&function(){const e=a.createUniform("vec2","pickClipPos"),t=a.createUniform("vec2","pickClipPosInv");return{setClipPosInputValue:i=>{e.setInputValue(i.pickClipPos),t.setInputValue(i.pickClipPosInv)},transformedClipPos:()=>`vec4((${u}.xy / ${u}.w - ${e}) * ${t} * ${u}.w, ${u}.zw)`}}(),f=d?d.transformedClipPos():u,p=[],g=a.createVarying("float","isPerspective",(()=>`(${c.projMatrix}[2][3] == -1.0) ? 1.0 : 0.0`)),m=a.createUniform("float","logDepthBufFC",((e,t)=>e(2/(Math.log(t.view.far+1)/Math.LN2)))),_=a.createVarying("float","vFragDepth",(()=>"1.0 + clipPos.w"));h?p.push(`gl_FragDepth = ${c.testPerspectiveForGl_FragDepth?`${g} == 0.0 ? gl_FragCoord.z : `:""}log2(${h(_)}) * ${m} * 0.5;`):c.cleanerEdges&&p.push("gl_FragDepth = gl_FragCoord.z + length(vec2(dFdx(gl_FragCoord.z), dFdy(gl_FragCoord.z)));");const b=a.createFragmentDefinition("linearToGamma",((e,t)=>{t.push(`vec4 ${e}(in vec4 value, in float gammaFactor) {`),t.push(" return vec4(pow(value.xyz, vec3(1.0 / gammaFactor)), value.w);"),t.push("}")})),B=c.sectionPlanesState,y=B&&function(){const e=function(e){const t=[];for(let i=0;i<e;++i)t.push(i);return t}(B.getNumAllocatedSectionPlanes()).map((e=>{const t=(t,i,s)=>a.createUniform(t,`sectionPlane${i}${e}`,((t,i)=>{const r=B.sectionPlanes,n=r.length,A=(i.mesh.layerIndex||0)*n,o=e<n&&i.mesh.renderFlags.sectionPlanesActivePerLayer[A+e];return s(t,o,r[e],i.mesh.origin)}));return{act:t("bool","Active",((e,t)=>e(t?1:0))),dir:t("vec3","Dir",((e,t,i)=>t&&e(i.dir))),pos:t("vec3","Pos",((e,t,i,s)=>t&&e(s?V.mulVec3Scalar(V.normalizeVec3(i.dir,Li),-(V.dotVec3(i.dir,s)+i.dist),Li):i.pos)))}}));return e.length>0&&(t=>e.map((e=>`(${e.act} ? clamp(dot(-${e.dir}, ${t} - ${e.pos}), 0.0, 1000.0) : 0.0)`)).join(" + "))}(),w=c.crossSections,v=y?function(){const e=a.createUniform("vec4","sliceColor",(e=>e(w.sliceColor))),t=i=>(t.needed=!0,`(sliced ? ${e} : ${i})`);return t}():e=>e,C=c.getGammaFactor,M=a.createUniform("float","gammaFactor",(e=>e(C())));c.appendFragmentOutputs(p,C&&(e=>`${b}(${e}, ${M})`),"gl_FragCoord",v);const E=function(){const e=[],t=a.createUniform("float","sliceThickness",(e=>e(w.sliceThickness)));if(y){v.needed&&e.push(" bool sliced = false;"),e.push(` if (${c.clippableTest()}) {`);const i=a.createVarying("highp vec3","vHighpWorldPosition",(()=>`${c.worldPositionAttribute}.xyz`));if(e.push(` float dist = ${y(i)};`),c.clippingCaps){const t=a.createVarying("float","vClipPositionW",(()=>"gl_Position.w"));e.push(` if (dist > (0.002 * ${t})) { discard; }`),e.push(" if (dist > 0.0) { "),e.push(` ${c.clippingCaps} = vec4(1.0, 0.0, 0.0, 1.0);`),h&&e.push(` gl_FragDepth = log2(${h(_)}) * ${m} * 0.5;`),e.push(" return;"),e.push(" }")}else e.push(` if (dist > ${v.needed?t:"0.0"}) { discard; }`);v.needed&&e.push(" sliced = dist > 0.0;"),e.push(" }")}return e}(),F=function(){const e=[];return s.forEach((t=>t(e))),e}(),U=[...function(){const e=[];return i.forEach((t=>t(e))),e}(),...F,"void main(void) {",...c.discardPoints?[" vec2 cxy = 2.0 * gl_PointCoord - 1.0;"," if (dot(cxy, cxy) > 1.0) { discard; }"]:[],...E,...p,"}"],x=[`gl_Position = ${f};`,...c.getPointSize?[`gl_PointSize = ${c.getPointSize()};`]:[],...function(){const e=[];return t.forEach((t=>t(e))),e}()],I=c.getVertexData?c.getVertexData():[],T=[...function(){const t=[];return e.forEach((e=>e(t))),t}(),"void main(void) {",...I,...x,"}"],P=e=>["#version 300 es","// "+l+" "+e+" shader","#ifdef GL_FRAGMENT_PRECISION_HIGH","precision highp float;","precision highp int;","precision highp usampler2D;","precision highp isampler2D;","precision highp sampler2D;","#else","precision mediump float;","precision mediump int;","precision mediump usampler2D;","precision mediump isampler2D;","precision mediump sampler2D;","#endif"],S=P("vertex").concat(T),D=P("fragment").concat(["vec4 sRGBToLinear(in vec4 value) {"," return vec4(mix(pow(value.rgb * 0.9478672986 + 0.0521327014, vec3(2.4)), value.rgb * 0.0773993808, vec3(lessThanEqual(value.rgb, vec3(0.04045)))), value.w);","}"]).concat(U),k=(e,t)=>{const i=t.join("\n"),s=o.createShader(e);return o.shaderSource(s,i),o.compileShader(s),o.getShaderParameter(s,o.COMPILE_STATUS)?[s]:[null,["Failed to compile",o.getShaderInfoLog(s),i.split("\n").map(((e,t)=>t+1+": "+e+"\n")).join("")]]},[Q,R]=k(o.VERTEX_SHADER,S),[O,L]=k(o.FRAGMENT_SHADER,D),H=e=>(console.error(e.join("\n")),[null,e]);if(R)return H(["Vertex shader error"].concat(R));if(L)return H(["Fragment shader error"].concat(L));{const e=o.createProgram();if(e){if(o.attachShader(e,Q),o.attachShader(e,O),o.linkProgram(e),o.getProgramParameter(e,o.LINK_STATUS)){const t=zi(o,e);r.forEach((e=>e(t)));const i=A.map((e=>e(t))).filter((e=>e)),s=Vi.addItem({});return[{id:s,bind:()=>o.useProgram(e),inputSetters:{attributesHash:n.sort().join(", "),setUniforms:(e,t)=>{d&&d.setClipPosInputValue(e),i.forEach((e=>e(t)))}},destroy:()=>{Vi.removeItem(s),o.deleteProgram(e),o.deleteShader(Q),o.deleteShader(O)}}]}return H(["",o.getProgramInfoLog(this.program),"","Vertex shader:","",...S,"","Fragment shader:","",...D])}return H(["Failed to allocate program"])}}}},ji=function(e,t){const i=e.createUniform("vec4","lightAmbient",(e=>e(t.getAmbientColorAndIntensity()))),s=t.lights,r=s.map(((t,i)=>{const r={color:e.createUniform("vec4",`lightColor${i}`,(e=>{const t=s[i];Hi[0]=t.color[0],Hi[1]=t.color[1],Hi[2]=t.color[2],Hi[3]=t.intensity,e(Hi)})),position:e.createUniform("vec3",`lightPos${i}`,(e=>e(s[i].pos))),direction:e.createUniform("vec3",`lightDir${i}`,(e=>e(s[i].dir))),shadowProjMatrix:e.createUniform("mat4",`shadowProjMatrix${i}`,(e=>e(s[i].getShadowViewMatrix()))),shadowViewMatrix:e.createUniform("mat4",`shadowViewMatrix${i}`,(e=>e(s[i].getShadowViewMatrix()))),shadowMap:e.createUniform("sampler2D",`shadowMap${i}`,(e=>e(s[i].getShadowRenderBuf().colorTextures[0])))},n=e=>({glslLight:{isViewSpace:"view"===t.space,getColor:()=>`${r.color}.rgb * ${r.color}.a`,getDirection:(t,i)=>`normalize(${e(t,i)})`,shadowParameters:t.castsShadow&&{getShadowProjMatrix:()=>r.shadowProjMatrix,getShadowViewMatrix:()=>r.shadowViewMatrix,getShadowMap:()=>r.shadowMap}},setupLightsInputs:()=>{const e=Object.values(r).map((e=>e.setupLightsInputs())).filter((e=>e));return()=>e.forEach((e=>e()))}});return"dir"===t.type?"view"===t.space?n(((e,t)=>`-${r.direction}`)):n(((e,t)=>`-(${e} * vec4(${r.direction}, 0.0)).xyz`)):"point"===t.type?"view"===t.space?n(((e,t)=>`${r.position} - ${t}`)):n(((e,t)=>`(${e} * vec4(${r.position}, 1.0)).xyz - ${t}`)):null})).filter((e=>e)),n=(t,i)=>{const s=()=>{const e=i();return e.length>0&&e[0]},r=s();return r&&Wi(e,"samplerCube",t,r.encoding,(e=>{const t=s();t&&e(t.texture)}))},A=n("light",(()=>t.lightMaps)),o=n("reflection",(()=>t.reflectionMaps));return{getHash:()=>t.getHash(),getAmbientColor:()=>`${i}.rgb * ${i}.a`,directionalLights:r.map((e=>e.glslLight)),getIrradiance:A&&(e=>`${A(e)}.rgb`),getReflection:o&&((e,t)=>`${o(e,t)}.rgb`)}},Wi=(e,t,i,s,r)=>{const n=e.createUniform(t,i+"Map",r);return(e,t)=>{const i=t?`texture(${n}, ${e}, ${t})`:`texture(${n}, ${e})`;return 3e3!==s?`${Ni[s]}(${i})`:i}},zi=function(e,t){const i={},s=e.getProgramParameter(t,e.ACTIVE_ATTRIBUTES);for(let r=0;r<s;++r){const n=e.getActiveAttrib(t,r),A=e.getAttribLocation(t,n.name);i[n.name]=function(t){t.bindAtLocation(A),e.enableVertexAttribArray(A);const i=t.attributeDivisor;i&&e.vertexAttribDivisor(A,i)},i[n.name].attributeHash=`${A.toString().padStart(1+Math.floor(Math.log10(s)),"0")}:${n.name}`}const r=e.getProgramParameter(t,e.ACTIVE_UNIFORM_BLOCKS);for(let s=0;s<r;++s){const r=e.getActiveUniformBlockName(t,s),n=e.getUniformBlockIndex(t,r),A=s;e.uniformBlockBinding(t,n,A);const o=e.createBuffer();i[r]=function(t){e.bindBuffer(e.UNIFORM_BUFFER,o),e.bufferData(e.UNIFORM_BUFFER,t,e.DYNAMIC_DRAW),e.bindBufferBase(e.UNIFORM_BUFFER,A,o)}}const n=e.getProgramParameter(t,e.ACTIVE_UNIFORMS);let A=0;for(let s=0;s<n;++s){const r=e.getActiveUniform(t,s);let n=r.name;n.endsWith("[0]")&&(n=n.substr(0,n.length-3)),"\0"===n[n.length-1]&&(n=n.substr(0,n.length-1));const o=e.getUniformLocation(t,n);if(function(){for(let t in e)if(r.type===e[t])return t}(),r.type===e.SAMPLER_2D||r.type===e.SAMPLER_CUBE||r.type===e.SAMPLER_2D_SHADOW||e instanceof window.WebGL2RenderingContext&&(r.type===e.UNSIGNED_INT_SAMPLER_2D||r.type===e.INT_SAMPLER_2D)){const t=A++;i[n]=function(i){const s=i.bind(t);return s&&e.uniform1i(o,t),s}}else i[n]=function(){if(1===r.size)switch(r.type){case e.BOOL:case e.INT:return t=>e.uniform1i(o,t);case e.FLOAT:return t=>e.uniform1f(o,t);case e.FLOAT_VEC2:return t=>e.uniform2fv(o,t);case e.FLOAT_VEC3:return t=>e.uniform3fv(o,t);case e.FLOAT_VEC4:return t=>e.uniform4fv(o,t);case e.FLOAT_MAT3:return t=>e.uniformMatrix3fv(o,!1,t);case e.FLOAT_MAT4:return t=>e.uniformMatrix4fv(o,!1,t)}else if(r.size>1)switch(r.type){case e.FLOAT:return t=>e.uniform1fv(o,t);case e.FLOAT_VEC2:return t=>e.uniform2fv(o,t);case e.FLOAT_VEC3:return t=>e.uniform3fv(o,t);case e.FLOAT_VEC4:return t=>e.uniform4fv(o,t)}throw`Unhandled uniform ${n}`}()}return function(e){const t=i[e];if(!t)throw`Missing input "${e}"`;return t}},Xi=V.vec4(),Ki=V.vec4();class Zi{constructor(){this.visibleLayers=[],this.sectionPlanesActivePerLayer=[],this.reset()}reset(){this.culled=!1,this.sectioned=!1,this.numLayers=0,this.numVisibleLayers=0,this.colorOpaque=!1,this.colorTransparent=!1,this.edgesOpaque=!1,this.edgesTransparent=!1,this.xrayedSilhouetteOpaque=!1,this.xrayedEdgesOpaque=!1,this.xrayedSilhouetteTransparent=!1,this.xrayedEdgesTransparent=!1,this.highlightedSilhouetteOpaque=!1,this.highlightedEdgesOpaque=!1,this.highlightedSilhouetteTransparent=!1,this.highlightedEdgesTransparent=!1,this.selectedSilhouetteOpaque=!1,this.selectedEdgesOpaque=!1,this.selectedSilhouetteTransparent=!1,this.selectedEdgesTransparent=!1}}const Ji=V.OBB3(),Yi=V.vec4(),$i=V.vec4(),qi=V.vec4(),es=V.vec3([1,0,0]),ts=V.vec3([0,1,0]),is=V.vec3([0,0,1]),ss=V.vec3(3),rs=V.vec3(3),ns=V.identityMat4(),As=new e({}),os={};class as extends Ae{constructor(e,t={}){super(e,t),this.renderOrder=t.renderOrder||0,this.originalSystemId=t.originalSystemId||this.id,this.renderFlags=new Zi,this._state=new Se({visible:!0,culled:!1,pickable:null,clippable:null,collidable:null,occluder:!1!==t.occluder,castsShadow:null,receivesShadow:null,xrayed:!1,highlighted:!1,selected:!1,edges:!1,stationary:!!t.stationary,background:!!t.background,billboard:this._checkBillboard(t.billboard),layer:null,colorize:null,pickID:this.scene._renderer.getPickID(this),drawHash:"",pickOcclusionHash:"",offset:V.vec3(),origin:null,originHash:null,isUI:t.isUI});const i=t.material?this._checkComponent2(["PhongMaterial","MetallicMaterial","SpecularMaterial","LambertMaterial"],t.material):this.scene.material,s=this,r=e=>{let t=null;const i=()=>{if(!t){const i=Gi(),r=i.programVariables.createAttribute,n=s._geometry._state,A={position:r("vec3","position"),color:n.colorsBuf&&r("vec4","color"),pickColor:r("vec4","pickColor"),uv:n.uvBuf&&r("vec2","uv"),normal:(n.autoVertexNormals||n.normalsBuf)&&["triangles","triangle-strip","triangle-fan"].includes(n.primitiveName)&&r("vec3","normal")},o=function(e){const t={toString:()=>(t.needed=!0,e)};return t},a=A.normal&&o("worldNormal"),l=a&&o("viewNormal"),c=A.uv&&o("decodedUv"),h=e(i.programVariables,{attributes:{position:{world:"worldPosition",view:"viewPosition"},color:A.color,pickColor:A.pickColor,uv:c,normal:A.normal&&{world:a,view:l}},viewMatrix:"viewMatrix2"}),u=[h.programName,s.scene.canvas.canvas.id,s.scene._sectionPlanesState.getHash(),s._geometry._state.hash].concat(h.getHash()).join(";");if(!(u in os)){const e=cs(s,A,{decodedUv:c,worldNormal:a,viewNormal:l},h,i);if(e.errors)return void console.log(e.errors.join("\n"));const t=As.addItem({});os[u]={drawMesh:e.drawMesh,id:t,useCount:0,delete:()=>{As.removeItem(t),e.destroy(),delete os[u],G.memory.programs--}},G.memory.programs++}t=os[u],t.useCount++}};return{get:i,getId:()=>t.id,put:()=>{t&&(0==--t.useCount&&t.delete(),t=null)},drawMesh:(e,s,r)=>{i(),t&&t.drawMesh(e,s,r)}}},n=s.scene,A=e=>(t,i)=>function(e,t,i,s,r){const n=r&&ji(t,s._lightsState),A=t.createUniform("vec3","uColor",((e,t)=>e(r?t.material.fillColor:t.material.edgeColor))),o=t.createUniform("float","uAlpha",((e,t)=>e(r?t.material.fillAlpha:t.material.edgeAlpha))),a=t.createVarying("vec4","vColor",(()=>{const e=i.attributes,t=r&&[n.getAmbientColor()].concat(e.normal?n.directionalLights.map((t=>`(max(dot(${e.normal.view}, ${t.getDirection(i.viewMatrix,e.position.view)}), 0.0) * ${t.getColor()})`)):[]);return`vec4(${A}${t?` * (${t.join(" + ")})`:""}, ${o})`})),l=t.createOutput("vec4","outColor");return{getHash:()=>[e,s.gammaOutput?"go":"",n&&n.getHash()],programName:r?"EmphasisFill":"EmphasisEdges",dontSetFrontFace:!0,discardPoints:r,drawEdges:!r,appendFragmentOutputs:(e,t)=>e.push(`${l} = ${t?t(a):a};`)}}(s._state.hash,t,i,n,e);this._renderers={_drawRenderer:r(((e,t)=>"LambertMaterial"===i.type?function(e,t,i,s,r){const n=ji(t,r._lightsState),A=t.createUniform("vec4","colorize",((e,t)=>e(t.meshColorize))),o=t.createUniform("float","materialAlpha",((e,t)=>e(t.material.alpha))),a=t.createUniform("vec3","materialColor",((e,t)=>e(t.material.color))),l=t.createUniform("vec3","materialEmissive",((e,t)=>e(t.material.emissive))),c=t.createVarying("vec4","vColor",(()=>{const e=i.attributes,t=[n.getAmbientColor()].concat(e.normal?n.directionalLights.map((t=>`(max(dot(${e.normal.view}, ${t.getDirection(i.viewMatrix,e.position.view)}), 0.0) * ${t.getColor()})`)):[]);return`${A} * vec4((${t.join(" + ")}) * ${a} + ${l}, ${o});`})),h=t.createOutput("vec4","outColor");return{getHash:()=>[e,r.gammaOutput?"go":"",n.getHash(),s._state.hash],programName:"Lambert",canActAsBackground:!0,discardPoints:!0,setupPointSize:!0,setsLineWidth:!0,appendFragmentOutputs:(e,t)=>e.push(`${h} = ${t?t(c):c};`)}}(s._state.drawHash,e,t,i,n):function(e,t,i,s,r){const n=s._state,A="PhongMaterial"===n.type,o="MetallicMaterial"===n.type,a="SpecularMaterial"===n.type,l=i.attributes,c=ji(t,r._lightsState),h=t.createUniform("vec4","colorize",((e,t)=>e(t.meshColorize))),u=t.createFragmentDefinition("fresnel",((e,t)=>{t.push(`float ${e}(vec3 eyeDir, vec3 normal, float edgeBias, float centerBias, float power) {`),t.push(" float fr = abs(dot(eyeDir, normal));"),t.push(" float finalFr = clamp((fr - edgeBias) / (centerBias - edgeBias), 0.0, 1.0);"),t.push(" return pow(finalFr, power);"),t.push("}")})),d=(e,i,r)=>{const n=(i,s,n)=>t.createUniform(i,e+"Fresnel"+s,((e,t)=>e(n(r(t.material))))),A=n("float","EdgeBias",(e=>e.edgeBias)),o=n("float","CenterBias",(e=>e.centerBias)),a=n("float","Power",(e=>e.power)),l=n("vec3","EdgeColor",(e=>e.edgeColor)),c=n("vec3","CenterColor",(e=>e.centerColor));return r(s)&&((e,t)=>`mix(${l+i}, ${c+i}, ${u}(${e}, ${t}, ${A}, ${o}, ${a}))`)},f=d("diffuse","",(e=>e._diffuseFresnel)),p=d("specular","",(e=>e._specularFresnel)),g=d("emissive","",(e=>e._emissiveFresnel)),m=d("alpha",".r",(e=>e._alphaFresnel)),_=(e,i)=>{const r=l.uv&&i(s),n=r&&Wi(t,"sampler2D",e,r.encoding,((e,t)=>e(i(t.material)._state.texture)));return n&&function(){const s=r._state.matrix&&t.createUniform("mat4",e+"MapMatrix",((e,t)=>e(i(t.material)._state.matrix))),A=s?e=>`(${s} * ${e}).st`:e=>`${e}.st`,o=(e,t)=>n(A(e));return o.getTexCoordExpression=A,o}()},b=_("ambient",(e=>e._ambientMap)),B=_("baseColor",(e=>e._baseColorMap)),y=_("diffuse",(e=>e._diffuseMap)),w=_("emissive",(e=>e._emissiveMap)),v=_("occlusion",(e=>e._occlusionMap)),C=_("alpha",(e=>e._alphaMap)),M=_("metallic",(e=>e._metallicMap)),E=_("roughness",(e=>e._roughnessMap)),F=_("metallicRoughness",(e=>e._metallicRoughnessMap)),U=_("specular",(e=>e._specularMap)),x=_("glossiness",(e=>e._glossinessMap)),I=_("specularGlossiness",(e=>e._specularGlossinessMap)),T=_("normal",(e=>e._normalMap)),P=(e,i,r)=>{const n=r(s);return("float"===i?null!=n:n)&&t.createUniform(i,e,((e,t)=>e(r(t.material))))},S=P("materialAmbient","vec3",(e=>e.ambient)),D=P("materialDiffuse","vec3",(e=>e.diffuse)),k=P("materialBaseColor","vec3",(e=>e.baseColor)),Q=P("materialEmissive","vec3",(e=>e.emissive)),R=P("materialSpecular","vec3",(e=>e.specular)),O=P("materialGlossiness","float",(e=>e.glossiness)),V=P("materialMetallic","float",(e=>e.metallic)),L=P("materialRoughness","float",(e=>e.roughness)),H=P("materialShininess","float",(e=>e.shininess)),N=P("materialSpecularF0","float",(e=>e.specularF0)),G=P("materialAlphaModeCutoff","vec4",(e=>{const t=e.alpha;return null!=t?(Xi[0]=t,Xi[1]=1===e.alphaMode?1:0,Xi[2]=e.alphaCutoff,Xi):null})),j=t.createVarying("vec3","vViewPosition",(()=>`${l.position.view}.xyz`)),W=t.createVarying("vec4","texturePos",(()=>`vec4(${l.uv}, 1.0, 1.0)`)),z=l.color&&t.createVarying("vec4","vColor",(()=>l.color)),X=t.createVarying("vec3","vViewNormal",(()=>l.normal.view)),K=c.directionalLights.map(((e,s)=>({vViewLightReverseDir:t.createVarying("vec3",`vViewLightReverseDir${s}`,(()=>e.getDirection(i.viewMatrix,null))),vShadowPosFromLight:t.createVarying("vec3",`vShadowPosFromLight${s}`,(()=>`(mat4(0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.5, 0.5, 0.5, 1.0) * ${e.shadowParameters.getShadowProjMatrix()} * (${e.shadowParameters.getShadowViewMatrix()} * ${l.position.world})).xyz`))}))),Z=t.createVarying("vec3","vWorldNormal",(()=>l.normal.world)),J=t.createOutput("vec4","outColor"),Y=t.createFragmentDefinition("saturate",((e,t)=>t.push(`float ${e}(const in float a) { return clamp(a, 0.0, 1.0); }`))),$=t.createFragmentDefinition("BRDF_Specular_GGX",((e,t)=>{t.push("vec3 F_Schlick(const in vec3 specularColor, const in float dotLH) {"),t.push(" float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );"),t.push(" return ( 1.0 - specularColor ) * fresnel + specularColor;"),t.push("}"),t.push("float G_GGX_Smith(const in float alpha, const in float dotNL, const in float dotNV) {"),t.push(" float a2 = ( alpha * alpha );"),t.push(" float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),t.push(" float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),t.push(" return 1.0 / ( gl * gv );"),t.push("}"),t.push("float G_GGX_SmithCorrelated(const in float alpha, const in float dotNL, const in float dotNV) {"),t.push(" float a2 = ( alpha * alpha );"),t.push(" float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),t.push(" float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),t.push(" return 0.5 / max( gv + gl, 1e-6 );"),t.push("}"),t.push("float D_GGX(const in float alpha, const in float dotNH) {"),t.push(" float a2 = ( alpha * alpha );"),t.push(" float denom = ( dotNH * dotNH) * ( a2 - 1.0 ) + 1.0;"),t.push(" return 0.31830988618 * a2 / ( denom * denom);"),t.push("}"),t.push(`vec3 ${e}(const in vec3 incidentLightDirection, const in vec3 viewNormal, const in vec3 viewEyeDir, const in vec3 specularColor, const in float roughness) {`),t.push(" float alpha = ( roughness * roughness );"),t.push(" vec3 halfDir = normalize( incidentLightDirection + viewEyeDir );"),t.push(` float dotNL = ${Y}( dot( viewNormal, incidentLightDirection ) );`),t.push(` float dotNV = ${Y}( dot( viewNormal, viewEyeDir ) );`),t.push(` float dotNH = ${Y}( dot( viewNormal, halfDir ) );`),t.push(` float dotLH = ${Y}( dot( incidentLightDirection, halfDir ) );`),t.push(" vec3 F = F_Schlick( specularColor, dotLH );"),t.push(" float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );"),t.push(" float D = D_GGX( alpha, dotNH );"),t.push(" return F * (G * D);"),t.push("}")})),q=t.createFragmentDefinition("BRDF_Specular_GGX_Environment",((e,t)=>{t.push(`vec3 ${e}(const in vec3 viewNormal, const in vec3 viewEyeDir, const in vec3 specularColor, const in float roughness) {`),t.push(` float dotNV = ${Y}(dot(viewNormal, viewEyeDir));`),t.push(" const vec4 c0 = vec4( -1, -0.0275, -0.572, 0.022);"),t.push(" const vec4 c1 = vec4( 1, 0.0425, 1.04, -0.04);"),t.push(" vec4 r = roughness * c0 + c1;"),t.push(" float a004 = min(r.x * r.x, exp2(-9.28 * dotNV)) * r.x + r.y;"),t.push(" vec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;"),t.push(" return specularColor * AB.x + AB.y;"),t.push("}")})),ee=t.createFragmentDefinition("perturbNormal2Arb",((e,t)=>{t.push(`vec3 ${e}( vec3 eye_pos, vec3 surf_norm, vec2 uv, vec4 texel ) {`),t.push(" vec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );"),t.push(" vec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );"),t.push(" vec2 st0 = dFdx( uv.st );"),t.push(" vec2 st1 = dFdy( uv.st );"),t.push(" vec3 S = normalize( q0 * st1.t - q1 * st0.t );"),t.push(" vec3 T = normalize( -q0 * st1.s + q1 * st0.s );"),t.push(" vec3 N = normalize( surf_norm );"),t.push(" vec3 mapN = texel.xyz * 2.0 - 1.0;"),t.push(" mat3 tsn = mat3( S, T, N );"),t.push(" return normalize( tsn * mapN );"),t.push("}")}));return{getHash:()=>[e,r.gammaOutput?"go":"",c.getHash(),s._state.hash],programName:"Draw",canActAsBackground:!0,discardPoints:!0,setupPointSize:!0,setsLineWidth:!0,appendFragmentOutputs:(e,t,s)=>{const r=l.normal&&(c.directionalLights.length>0||c.getIrradiance||c.getReflection);if(e.push(`vec3 diffuseColor = ${r&&(A||a)&&D||o&&k||"vec3(1.0)"};`),e.push(`vec4 alphaModeCutoff = ${(A||o||a)&&G||"vec4(1.0, 0.0, 0.0, 0.0)"};`),e.push("float alpha = alphaModeCutoff[0];"),(A||o||a)&&C&&e.push(`alpha *= ${C(W)}.r;`),z&&(e.push(`diffuseColor *= ${z}.rgb;`),e.push(`alpha *= ${z}.a;`)),o&&B&&(e.push("vec4 baseColorTexel = "+B(W)+";"),e.push("diffuseColor *= baseColorTexel.rgb;"),e.push("alpha *= baseColorTexel.a;")),(A||a)&&y&&(e.push("vec4 diffuseTexel = "+y(W)+";"),e.push("diffuseColor *= diffuseTexel.rgb;"),e.push("alpha *= diffuseTexel.a;")),e.push(`vec3 emissiveColor = ${(A||o||a)&&Q||"vec3(0.0)"};`),(A||o||a)&&w&&e.push(`emissiveColor = ${w(W)}.rgb;`),r){e.push(`vec3 specular = ${(A||a)&&R||"vec3(1.0)"};`),e.push(`float glossiness = ${a&&O||"1.0"};`),e.push(`float metallic = ${o&&V||"1.0"};`),e.push(`float roughness = ${(o||a)&&L||"1.0"};`),e.push(`float shininess = ${A&&H||"1.0"};`),e.push(`float specularF0 = ${o&&N||"1.0"};`),e.push(`float occlusion = ${(A||o||a)&&v?`${v(W)}.r`:"1.0"};`),o&&M&&e.push(`metallic *= ${M(W)}.r;`),o&&E&&e.push(`roughness *= ${E(W)}.r;`),o&&F&&(e.push("vec4 metalRoughTexel = "+F(W)+";"),e.push("metallic *= metalRoughTexel.b;"),e.push("roughness *= metalRoughTexel.g;")),(A||a)&&U&&e.push(`specular *= ${U(W)}.rgb;`),a&&x&&e.push(`glossiness *= ${x(W)}.r;`),a&&I&&(e.push("vec4 specGlossTexel = "+I(W)+";"),e.push("specular *= specGlossTexel.rgb;"),e.push("glossiness *= specGlossTexel.a;"));const t=`normalize(${X})`,s=(A||o||a)&&T?`${ee}(${j}, ${t}, ${T.getTexCoordExpression(W)}, ${T(W)})`:t;if(e.push(`vec3 viewNormal = ${s};`),e.push(`vec3 viewEyeDir = normalize(-${j});`),f&&e.push(`diffuseColor *= ${f("viewEyeDir","viewNormal")};`),p&&e.push(`specular *= ${p("viewEyeDir","viewNormal")};`),g&&e.push(`emissiveColor *= ${g("viewEyeDir","viewNormal")};`),m&&e.push(`alpha *= ${m("viewEyeDir","viewNormal")};`),e.push("if (alphaModeCutoff[1] == 1.0 && alpha < alphaModeCutoff[2]) {"),e.push(" discard;"),e.push("}"),e.push("vec3 material_diffuseColor;"),A&&(e.push("material_diffuseColor = diffuseColor;"),e.push("roughness = 0.0;")),a&&(e.push("float oneMinusSpecularStrength = 1.0 - max(max(specular.r, specular.g ),specular.b);"),e.push("material_diffuseColor = diffuseColor * oneMinusSpecularStrength;"),e.push("roughness = clamp(1.0 - glossiness, 0.04, 1.0);")),o&&(e.push("float dielectricSpecular = 0.16 * specularF0 * specularF0;"),e.push("material_diffuseColor = diffuseColor * (1.0 - dielectricSpecular) * (1.0 - metallic);"),e.push("roughness = clamp(roughness, 0.04, 1.0);"),e.push("specular = mix(vec3(dielectricSpecular), diffuseColor, metallic);")),A||o||a){if(e.push("const float PI = 3.14159265359;"),e.push("vec3 reflDiff = vec3(0.0);"),e.push("vec3 reflSpec = vec3(0.0);"),c.getIrradiance&&e.push(`reflDiff += ${c.getIrradiance(`normalize(${Z})`)};`),c.getReflection){const t="reflect(-viewEyeDir, viewNormal)",s=A?`0.2 * PI * ${c.getReflection(t)}`:function(){const e=`${q}(viewNormal, viewEyeDir, specular, roughness)`,s=`normalize((vec4(${t}, 0.0) * ${i.viewMatrix}).xyz)`;return`${e} * ${c.getReflection(s,"clamp(4.0 - 0.39624 - 0.25 * log2(pow(2.0 / pow(roughness + 0.0001, 2.0) - 2.0, 2.0) + 1.0), 0.0, 4.0)")}`}();e.push(`reflSpec += ${s};`)}c.directionalLights.some((e=>e.shadowParameters))&&(e.push("const vec4 bitShift = vec4(1.0, 1.0/256.0, 1.0/(256.0 * 256.0), 1.0/(256.0*256.0*256.0));"),e.push("const float texelSize = 1.0 / 1024.0;"),e.push("float shadow;"),e.push("float fragmentDepth;")),c.directionalLights.forEach(((t,i)=>{if(t.shadowParameters){const s="0.007";e.push(`fragmentDepth = ${K[i].vShadowPosFromLight}.z - ${s};`),e.push("shadow = 0.0;"),e.push("for (int x = -3; x <= 3; x++) {"),e.push(" for (int y = -3; y <= 3; y++) {"),e.push(` float texelDepth = dot(texture(${t.getShadowMap()}, ${K[i].vShadowPosFromLight}.xy + vec2(x, y) * texelSize), bitShift);`),e.push(" if (fragmentDepth < texelDepth) {"),e.push(" shadow += 1.0;"),e.push(" }"),e.push(" }"),e.push("}"),e.push("shadow /= 9.0;")}e.push(`vec3 lightColor${i} = ${t.getColor()}${t.shadowParameters?" * shadow":""};`),e.push(`vec3 lightDirection${i} = ${t.isViewSpace?t.getDirection(null,j):K[i].vViewLightReverseDir};`);const s=`${Y}(dot(viewNormal, lightDirection${i}))`;e.push(`vec3 irradiance${i} = ${s} * lightColor${i};`),e.push(`reflDiff += irradiance${i};`);const r=A?`lightColor${i} * specular * pow(max(dot(reflect(-lightDirection${i}, -viewNormal), viewEyeDir), 0.0), shininess)`:`irradiance${i} * PI * ${$}(lightDirection${i}, viewNormal, viewEyeDir, specular, roughness)`;e.push(`reflSpec += ${r};`)}))}const r=A&&`${c.getAmbientColor()} * diffuseColor`;e.push("vec3 outgoingLight = emissiveColor + occlusion * (reflDiff * material_diffuseColor + reflSpec)"+(r?" + "+r:"")+";")}else e.push(`vec3 ambientColor = ${A&&S||"vec3(1.0)"};`),A&&b&&e.push(`ambientColor *= ${b(W)}.rgb;`),e.push(`ambientColor *= ${c.getAmbientColor()};`),e.push("vec3 outgoingLight = emissiveColor + ambientColor;");e.push(`vec4 fragColor = ${h} * vec4(outgoingLight, alpha);`),e.push(`${J} = ${t?t("fragColor"):"fragColor"};`)}}}(s._state.drawHash,e,t,i,n))),_shadowRenderer:r((e=>function(e,t){const i=t.createFragmentDefinition("encodeFloat",((e,t)=>{t.push(`vec4 ${e}( const in float depth ) {`),t.push(" const vec4 bitShift = vec4(256 * 256 * 256, 256 * 256, 256, 1.0);"),t.push(" const vec4 bitMask = vec4(0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0);"),t.push(" vec4 comp = fract(depth * bitShift);"),t.push(" comp -= comp.xxyz * bitMask;"),t.push(" return comp;"),t.push("}")})),s=t.createOutput("vec4","outColor");return{getHash:()=>[e],programName:"Shadow",setsLineWidth:!0,useShadowView:!0,dontBillboardAnything:!0,dontGetLogDepth:!0,appendFragmentOutputs:(e,t,r)=>e.push(`${s} = ${i}(${r}.z);`)}}(s._state.hash,e))),_emphasisEdgesRenderer:r(A(!1)),_emphasisFillRenderer:r(A(!0)),_pickMeshRenderer:r((e=>function(e,t){const i=t.createUniform("vec4","pickColor",((e,t)=>{var i=t.meshPickID;Ki[0]=255&i,Ki[1]=i>>8&255,Ki[2]=i>>16&255,Ki[3]=i>>24&255,V.mulVec4Scalar(Ki,1/255,Ki),e(Ki)})),s=t.createOutput("vec4","outColor");return{getHash:()=>[e],programName:"PickMesh",isPick:!0,dontBillboardAnything:!0,appendFragmentOutputs:e=>e.push(`${s} = ${i};`)}}(s._state.hash,e))),_pickTriangleRenderer:r(((e,t)=>function(e,t,i){const s=t.createVarying("vec4","vColor",(()=>i.attributes.pickColor)),r=t.createOutput("vec4","outColor");return{getHash:()=>[e],programName:"PickTriangle",isPick:!0,trianglePick:!0,dontBillboardAnything:!0,appendFragmentOutputs:e=>e.push(`${r} = ${s};`)}}(s._state.hash,e,t))),_occlusionRenderer:r((e=>function(e,t){const i=t.createOutput("vec4","outColor");return{getHash:()=>[e],programName:"Occlusion",skipIfTransparent:!0,appendFragmentOutputs:e=>e.push(`${i} = vec4(0.0, 0.0, 1.0, 1.0);`)}}(s._state.pickOcclusionHash,e)))},this._geometry=t.geometry?this._checkComponent2(["ReadableGeometry","VBOGeometry"],t.geometry):this.scene.geometry,this._material=i,this._xrayMaterial=t.xrayMaterial?this._checkComponent("EmphasisMaterial",t.xrayMaterial):this.scene.xrayMaterial,this._highlightMaterial=t.highlightMaterial?this._checkComponent("EmphasisMaterial",t.highlightMaterial):this.scene.highlightMaterial,this._selectedMaterial=t.selectedMaterial?this._checkComponent("EmphasisMaterial",t.selectedMaterial):this.scene.selectedMaterial,this._edgeMaterial=t.edgeMaterial?this._checkComponent("EdgeMaterial",t.edgeMaterial):this.scene.edgeMaterial,this._parentNode=null,this._aabb=null,this._aabbDirty=!0,this._numTriangles=this._geometry?this._geometry.numTriangles:0,this.scene._aabbDirty=!0,this._scale=V.vec3(),this._quaternion=V.identityQuaternion(),this._rotation=V.vec3(),this._position=V.vec3(),this._worldMatrix=V.identityMat4(),this._worldNormalMatrix=V.identityMat4(),this._localMatrixDirty=!0,this._worldMatrixDirty=!0,this._worldNormalMatrixDirty=!0;const o=t.origin||t.rtcCenter;if(o&&(this._state.origin=V.vec3(o),this._state.originHash=o.join()),t.matrix?this.matrix=t.matrix:(this.scale=t.scale,this.position=t.position,t.quaternion||(this.rotation=t.rotation)),this._isObject=t.isObject,this._isObject&&this.scene._registerObject(this),this._isModel=t.isModel,this._isModel&&this.scene._registerModel(this),this.visible=t.visible,this.culled=t.culled,this.pickable=t.pickable,this.clippable=t.clippable,this.collidable=t.collidable,this.castsShadow=t.castsShadow,this.receivesShadow=t.receivesShadow,this.xrayed=t.xrayed,this.highlighted=t.highlighted,this.selected=t.selected,this.edges=t.edges,this.layer=t.layer,this.colorize=t.colorize,this.opacity=t.opacity,this.offset=t.offset,t.parentId){const e=this.scene.components[t.parentId];e?e.isNode?e.addChild(this):this.error("Parent is not a Node: '"+t.parentId+"'"):this.error("Parent not found: '"+t.parentId+"'"),this._parentNode=e}else t.parent&&(t.parent.isNode||this.error("Parent is not a Node"),t.parent.addChild(this),this._parentNode=t.parent);this.compile()}get type(){return"Mesh"}get isMesh(){return!0}get parent(){return this._parentNode}get geometry(){return this._geometry}get material(){return this._material}get position(){return this._position}set position(e){this._position.set(e||[0,0,0]),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw()}get rotation(){return this._rotation}set rotation(e){this._rotation.set(e||[0,0,0]),V.eulerToQuaternion(this._rotation,"XYZ",this._quaternion),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw()}get quaternion(){return this._quaternion}set quaternion(e){this._quaternion.set(e||[0,0,0,1]),V.quaternionToEuler(this._quaternion,"XYZ",this._rotation),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw()}get scale(){return this._scale}set scale(e){this._scale.set(e||[1,1,1]),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw()}get matrix(){return this._localMatrixDirty&&(this.__localMatrix||(this.__localMatrix=V.identityMat4()),V.composeMat4(this._position,this._quaternion,this._scale,this.__localMatrix),this._localMatrixDirty=!1),this.__localMatrix}set matrix(e){this.__localMatrix||(this.__localMatrix=V.identityMat4()),this.__localMatrix.set(e||ns),V.decomposeMat4(this.__localMatrix,this._position,this._quaternion,this._scale),this._localMatrixDirty=!1,this._setWorldMatrixDirty(),this._setAABBDirty(),this.glRedraw()}get worldMatrix(){return this._worldMatrixDirty&&this._buildWorldMatrix(),this._worldMatrix}get worldNormalMatrix(){return this._worldNormalMatrixDirty&&this._buildWorldNormalMatrix(),this._worldNormalMatrix}get isEntity(){return!0}get isModel(){return this._isModel}get isObject(){return this._isObject}get isUI(){return this._state.isUI}get aabb(){return this._aabbDirty&&this._updateAABB(),this._aabb}get origin(){return this._state.origin}set origin(e){e?(this._state.origin||(this._state.origin=V.vec3()),this._state.origin.set(e),this._state.originHash=e.join(),this._setAABBDirty(),this.scene._aabbDirty=!0):this._state.origin&&(this._state.origin=null,this._state.originHash=null,this._setAABBDirty(),this.scene._aabbDirty=!0)}get rtcCenter(){return this.origin}set rtcCenter(e){this.origin=e}get numTriangles(){return this._numTriangles}get visible(){return this._state.visible}set visible(e){e=!1!==e,this._state.visible=e,this._isObject&&this.scene._objectVisibilityUpdated(this,e),this.glRedraw()}get xrayed(){return this._state.xrayed}set xrayed(e){e=!!e,this._state.xrayed!==e&&(this._state.xrayed=e,this._isObject&&this.scene._objectXRayedUpdated(this,e),this.glRedraw())}get highlighted(){return this._state.highlighted}set highlighted(e){(e=!!e)!==this._state.highlighted&&(this._state.highlighted=e,this._isObject&&this.scene._objectHighlightedUpdated(this,e),this.glRedraw())}get selected(){return this._state.selected}set selected(e){(e=!!e)!==this._state.selected&&(this._state.selected=e,this._isObject&&this.scene._objectSelectedUpdated(this,e),this.glRedraw())}get edges(){return this._state.edges}set edges(e){(e=!!e)!==this._state.edges&&(this._state.edges=e,this.glRedraw())}get culled(){return this._state.culled}set culled(e){this._state.culled=!!e,this.glRedraw()}get clippable(){return this._state.clippable}set clippable(e){e=!1!==e,this._state.clippable!==e&&(this._state.clippable=e,this.glRedraw())}get collidable(){return this._state.collidable}set collidable(e){(e=!1!==e)!==this._state.collidable&&(this._state.collidable=e,this._setAABBDirty(),this.scene._aabbDirty=!0)}get pickable(){return this._state.pickable}set pickable(e){e=!1!==e,this._state.pickable!==e&&(this._state.pickable=e)}get castsShadow(){return this._state.castsShadow}set castsShadow(e){(e=!1!==e)!==this._state.castsShadow&&(this._state.castsShadow=e,this.glRedraw())}get receivesShadow(){return this._state.receivesShadow}set receivesShadow(e){(e=!1!==e)!==this._state.receivesShadow&&(this._state.receivesShadow=e,this._state.hash=e?"/mod/rs;":"/mod;",this.fire("dirty",this))}get saoEnabled(){return!1}get colorize(){return this._state.colorize}set colorize(e){let t=this._state.colorize;t||(t=this._state.colorize=new Float32Array(4),t[3]=1),e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1);const i=!!e;this.scene._objectColorizeUpdated(this,i),this.glRedraw()}get opacity(){return this._state.colorize[3]}set opacity(e){let t=this._state.colorize;t||(t=this._state.colorize=new Float32Array(4),t[0]=1,t[1]=1,t[2]=1);const i=null!=e;t[3]=i?e:1,this.scene._objectOpacityUpdated(this,i),this.glRedraw()}get transparent(){return 2===this._material.alphaMode||this._state.colorize[3]<1}get layer(){return this._state.layer}set layer(e){e=e||0,(e=Math.round(e))!==this._state.layer&&(this._state.layer=e,this._renderer.needStateSort())}get stationary(){return this._state.stationary}get billboard(){return this._state.billboard}get offset(){return this._state.offset}set offset(e){this._state.offset.set(e||[0,0,0]),this._setAABBDirty(),this.glRedraw()}get isDrawable(){return!0}get isStateSortable(){return!0}get xrayMaterial(){return this._xrayMaterial}get highlightMaterial(){return this._highlightMaterial}get selectedMaterial(){return this._selectedMaterial}get edgeMaterial(){return this._edgeMaterial}_checkBillboard(e){return"spherical"!==(e=e||"none")&&"cylindrical"!==e&&"none"!==e&&(this.error("Unsupported value for 'billboard': "+e+" - accepted values are 'spherical', 'cylindrical' and 'none' - defaulting to 'none'."),e="none"),e}compile(){const e=this.scene,t=this._state,i=[e.canvas.canvas.id,e._sectionPlanesState.getHash()];t.stationary&&i.push("/s"),"none"===t.billboard?i.push("/n"):"spherical"===t.billboard?i.push("/s"):"cylindrical"===t.billboard&&i.push("/c"),i.push(";");const s=i.concat([e.gammaOutput?"go":"",e._lightsState.getHash(),t.receivesShadow?"/rs":""]).join("");this._state.drawHash!==s&&(this._state.drawHash=s,this._renderers._drawRenderer.put(),this._renderers._shadowRenderer.put(),this._renderers._emphasisFillRenderer.put(),this._renderers._emphasisEdgesRenderer.put(),this._renderers._drawRenderer.get(),this._renderers._emphasisFillRenderer.get(),this._renderers._emphasisEdgesRenderer.get());const r=i.join("");this._state.pickOcclusionHash!==r&&(this._state.pickOcclusionHash=r,this._renderers._pickMeshRenderer.put(),this._renderers._pickTriangleRenderer.put(),this._renderers._pickMeshRenderer.get(),this._state.occluder&&(this._renderers._occlusionRenderer.put(),this._renderers._occlusionRenderer.get()))}_setLocalMatrixDirty(){this._localMatrixDirty=!0,this._setWorldMatrixDirty()}_setWorldMatrixDirty(){this._worldMatrixDirty=!0,this._worldNormalMatrixDirty=!0}_buildWorldMatrix(){const e=this.matrix;if(this._parentNode)V.mulMat4(this._parentNode.worldMatrix,e,this._worldMatrix);else for(let t=0,i=e.length;t<i;t++)this._worldMatrix[t]=e[t];this._worldMatrixDirty=!1}_buildWorldNormalMatrix(){this._worldMatrixDirty&&this._buildWorldMatrix(),this._worldNormalMatrix||(this._worldNormalMatrix=V.mat4()),V.transposeMat4(this._worldMatrix,this._worldNormalMatrix),V.inverseMat4(this._worldNormalMatrix),this._worldNormalMatrixDirty=!1}_setAABBDirty(){if(this.collidable)for(let e=this;e;e=e._parentNode)e._aabbDirty=!0}_updateAABB(){this.scene._aabbDirty=!0,this._aabb||(this._aabb=V.AABB3()),this._buildAABB(this.worldMatrix,this._aabb),this._aabbDirty=!1}_buildAABB(e,t){V.transformOBB3(e,this._geometry.obb,Ji),V.OBB3ToAABB3(Ji,t);const i=this._state.offset;if(t[0]+=i[0],t[1]+=i[1],t[2]+=i[2],t[3]+=i[0],t[4]+=i[1],t[5]+=i[2],this._state.origin){const e=this._state.origin;t[0]+=e[0],t[1]+=e[1],t[2]+=e[2],t[3]+=e[0],t[4]+=e[1],t[5]+=e[2]}}rotate(e,t){return Yi[0]=e[0],Yi[1]=e[1],Yi[2]=e[2],Yi[3]=t*V.DEGTORAD,V.angleAxisToQuaternion(Yi,$i),V.mulQuaternions(this.quaternion,$i,qi),this.quaternion=qi,this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw(),this}rotateOnWorldAxis(e,t){return Yi[0]=e[0],Yi[1]=e[1],Yi[2]=e[2],Yi[3]=t*V.DEGTORAD,V.angleAxisToQuaternion(Yi,$i),V.mulQuaternions($i,this.quaternion,$i),this}rotateX(e){return this.rotate(es,e)}rotateY(e){return this.rotate(ts,e)}rotateZ(e){return this.rotate(is,e)}translate(e,t){return V.vec3ApplyQuaternion(this.quaternion,e,ss),V.mulVec3Scalar(ss,t,rs),V.addVec3(this.position,rs,this.position),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw(),this}translateX(e){return this.translate(es,e)}translateY(e){return this.translate(ts,e)}translateZ(e){return this.translate(is,e)}stateSortCompare(e,t){return e._state.layer-t._state.layer||e._renderers._drawRenderer.getId()-t._renderers._drawRenderer.getId()||e._material._state.id-t._material._state.id||e._geometry._state.id-t._geometry._state.id}rebuildRenderFlags(){this.renderFlags.reset(),this._getActiveSectionPlanes()?(this.renderFlags.numLayers=1,this.renderFlags.numVisibleLayers=1,this.renderFlags.visibleLayers[0]=0,this._updateRenderFlags()):this.renderFlags.culled=!0}_updateRenderFlags(){const e=this.renderFlags,t=this._state;if(t.xrayed){const t=this._xrayMaterial._state;t.fill&&(t.fillAlpha<1?e.xrayedSilhouetteTransparent=!0:e.xrayedSilhouetteOpaque=!0),t.edges&&(t.edgeAlpha<1?e.xrayedEdgesTransparent=!0:e.xrayedEdgesOpaque=!0)}else{if(this._material._state.alpha<1||t.colorize[3]<1?e.colorTransparent=!0:e.colorOpaque=!0,t.edges){this._edgeMaterial._state.alpha<1?e.edgesTransparent=!0:e.edgesOpaque=!0}if(t.selected){const t=this._selectedMaterial._state;t.fill&&(t.fillAlpha<1?e.selectedSilhouetteTransparent=!0:e.selectedSilhouetteOpaque=!0),t.edges&&(t.edgeAlpha<1?e.selectedEdgesTransparent=!0:e.selectedEdgesOpaque=!0)}else if(t.highlighted){const t=this._highlightMaterial._state;t.fill&&(t.fillAlpha<1?e.highlightedSilhouetteTransparent=!0:e.highlightedSilhouetteOpaque=!0),t.edges&&(t.edgeAlpha<1?e.highlightedEdgesTransparent=!0:e.highlightedEdgesOpaque=!0)}}}_getActiveSectionPlanes(){if(this._state.clippable){const e=this.scene._sectionPlanesState.sectionPlanes,t=e.length;if(t>0)for(let i=0;i<t;i++){const t=e[i],s=this.renderFlags;if(t.active)if(this._state.origin){const e=V.planeAABB3Intersect(t.dir,t.dist,this.aabb);if(-1===e)return!1;const r=0===e;s.sectionPlanesActivePerLayer[i]=r}else s.sectionPlanesActivePerLayer[i]=!0;else s.sectionPlanesActivePerLayer[i]=!1}}return!0}drawColorOpaque(e){this._renderers._drawRenderer.drawMesh(e,this,this._material)}drawColorTransparent(e){this._renderers._drawRenderer.drawMesh(e,this,this._material)}drawSilhouetteXRayed(e){this._renderers._emphasisFillRenderer.drawMesh(e,this,this._xrayMaterial)}drawSilhouetteHighlighted(e){this._renderers._emphasisFillRenderer.drawMesh(e,this,this._highlightMaterial)}drawSilhouetteSelected(e){this._renderers._emphasisFillRenderer.drawMesh(e,this,this._selectedMaterial)}drawEdgesColorOpaque(e){this._renderers._emphasisEdgesRenderer.drawMesh(e,this,this._edgeMaterial)}drawEdgesColorTransparent(e){this._renderers._emphasisEdgesRenderer.drawMesh(e,this,this._edgeMaterial)}drawEdgesXRayed(e){this._renderers._emphasisEdgesRenderer.drawMesh(e,this,this._xrayMaterial)}drawEdgesHighlighted(e){this._renderers._emphasisEdgesRenderer.drawMesh(e,this,this._highlightMaterial)}drawEdgesSelected(e){this._renderers._emphasisEdgesRenderer.drawMesh(e,this,this._selectedMaterial)}drawOcclusion(e){this._renderers._occlusionRenderer.drawMesh(e,this,this._material)}drawShadow(e){this._renderers._shadowRenderer.drawMesh(e,this,this._material)}drawPickMesh(e){this._renderers._pickMeshRenderer.drawMesh(e,this,this._material)}canPickTriangle(){return this._geometry.isReadableGeometry}drawPickTriangles(e){this._renderers._pickTriangleRenderer.drawMesh(e,this,this._material)}pickTriangleSurface(e,t,i,s){ls(this,e,t,i,s)}drawPickVertices(e){}delegatePickedEntity(){return this}destroy(){super.destroy(),Object.values(this._renderers).forEach((e=>e.put())),this.scene._renderer.putPickID(this._state.pickID),this._isObject&&(this.scene._deregisterObject(this),this._visible&&this.scene._objectVisibilityUpdated(this,!1,!1),this._xrayed&&this.scene._objectXRayedUpdated(this,!1,!1),this._selected&&this.scene._objectSelectedUpdated(this,!1,!1),this._highlighted&&this.scene._objectHighlightedUpdated(this,!1,!1),this.scene._objectColorizeUpdated(this,!1),this.scene._objectOpacityUpdated(this,!1),this.offset.some((e=>0!==e))&&this.scene._objectOffsetUpdated(this,!1)),this._isModel&&this.scene._deregisterModel(this),this.glRedraw()}}const ls=function(){const e=V.vec3(),t=V.vec3(),i=V.vec3(),s=V.vec3(),r=V.vec3(),n=V.vec3(),A=V.vec4(),o=V.vec3(),a=V.vec3(),l=V.vec3(),c=V.vec3(),h=V.vec3(),u=V.vec3(),d=V.vec3(),f=V.vec3(),p=V.vec3(),g=V.vec4(),m=V.vec4(),_=V.vec4(),b=V.vec3(),B=V.vec3(),y=V.vec3(),w=V.vec3(),v=V.vec3(),C=V.vec3(),M=V.vec3(),E=V.vec3(),F=V.vec3(),U=V.vec3(),x=V.vec3();return function(I,T,P,S,D){var k=D.primIndex;if(null!=k&&k>-1){const L=I.geometry._state,H=I.scene,N=H.camera,G=H.canvas;if("triangles"===L.primitiveName){D.primitive="triangle";const H=k,j=L.indices,W=L.positions;let z,X,K;if(j){var Q=j[H+0],R=j[H+1],O=j[H+2];n[0]=Q,n[1]=R,n[2]=O,D.indices=n,z=3*Q,X=3*R,K=3*O}else z=3*H,X=z+3,K=X+3;if(i[0]=W[z+0],i[1]=W[z+1],i[2]=W[z+2],s[0]=W[X+0],s[1]=W[X+1],s[2]=W[X+2],r[0]=W[K+0],r[1]=W[K+1],r[2]=W[K+2],L.compressGeometry){const e=L.positionsDecodeMatrix;e&&(Ne.decompressPosition(i,e,i),Ne.decompressPosition(s,e,s),Ne.decompressPosition(r,e,r))}D.canvasPos?V.canvasPosToLocalRay(G.canvas,I.origin?wt(T,I.origin):T,P,S,I.worldMatrix,D.canvasPos,e,t):D.origin&&D.direction&&V.worldRayToLocalRay(I.worldMatrix,D.origin,D.direction,e,t),V.normalizeVec3(t),V.rayPlaneIntersect(e,t,i,s,r,A),D.localPos=A,D.position=A,g[0]=A[0],g[1]=A[1],g[2]=A[2],g[3]=1,V.transformVec4(I.worldMatrix,g,m),o[0]=m[0],o[1]=m[1],o[2]=m[2],D.canvasPos&&I.origin&&(o[0]+=I.origin[0],o[1]+=I.origin[1],o[2]+=I.origin[2]),D.worldPos=o,V.transformVec4(N.matrix,m,_),a[0]=_[0],a[1]=_[1],a[2]=_[2],D.viewPos=a,V.cartesianToBarycentric(A,i,s,r,l),D.bary=l;const Z=L.normals;if(Z){if(L.compressGeometry){const e=3*Q,t=3*R,i=3*O;Ne.decompressNormal(Z.subarray(e,e+2),c),Ne.decompressNormal(Z.subarray(t,t+2),h),Ne.decompressNormal(Z.subarray(i,i+2),u)}else c[0]=Z[z],c[1]=Z[z+1],c[2]=Z[z+2],h[0]=Z[X],h[1]=Z[X+1],h[2]=Z[X+2],u[0]=Z[K],u[1]=Z[K+1],u[2]=Z[K+2];const e=V.addVec3(V.addVec3(V.mulVec3Scalar(c,l[0],b),V.mulVec3Scalar(h,l[1],B),y),V.mulVec3Scalar(u,l[2],w),v);D.worldNormal=V.normalizeVec3(V.transformVec3(I.worldNormalMatrix,e,C))}const J=L.uv;if(J){if(d[0]=J[2*Q],d[1]=J[2*Q+1],f[0]=J[2*R],f[1]=J[2*R+1],p[0]=J[2*O],p[1]=J[2*O+1],L.compressGeometry){const e=L.uvDecodeMatrix;e&&(Ne.decompressUV(d,e,d),Ne.decompressUV(f,e,f),Ne.decompressUV(p,e,p))}D.uv=V.addVec3(V.addVec3(V.mulVec2Scalar(d,l[0],M),V.mulVec2Scalar(f,l[1],E),F),V.mulVec2Scalar(p,l[2],U),x)}}}}}(),cs=(e,t,i,s,r)=>{const n=r.programVariables,A=i.decodedUv,o=i.worldNormal,a=i.viewNormal,l=e.scene,c=l.canvas.gl,h=e._state.background,u=e._geometry._state,d=u.compressGeometry,f="points"===u.primitiveName,p=n.createUniform("float","pointSize"),g=n.createUniform("mat4","modelMatrix"),m=n.createUniform("mat4","modelNormalMatrix"),_=n.createUniform("vec3","offset"),b=n.createUniform("vec3","scale"),B=n.createUniform("mat4","positionsDecodeMatrix"),y=n.createUniform("mat3","uvDecodeMatrix"),w=n.createUniform("mat4","viewMatrix"),v=n.createUniform("mat4","viewNormalMatrix"),C=n.createUniform("mat4","projMatrix"),M=e.billboard,E=!s.dontBillboardAnything&&("spherical"===M||"cylindrical"===M),F=e.stationary,U=E&&((e,t)=>[`mat4 ${e}(in mat4 matIn) {`," mat4 mat = matIn;",` mat[0].xyz = vec3(${b}[0], 0.0, 0.0);`,..."spherical"===M?[` mat[1].xyz = vec3(0.0, ${b}[1], 0.0);`]:[]," mat[2].xyz = vec3(0.0, 0.0, 1.0);"," return mat;","}"].forEach((e=>t.push(e)))),x=function(){const e=U&&n.createVertexDefinition("billboard",U);return t=>e?`${e}(${t})`:t}(),I=function(){const e=U&&n.createFragmentDefinition("billboard",U);return t=>e?`${e}(${t})`:t}(),T=[];s.dontBillboardAnything?T.push(`mat4 viewMatrix2 = ${w};`):(T.push(`mat4 viewMatrix1 = ${w};`),F?T.push("viewMatrix1[3].xyz = vec3(0.0, 0.0, 0.0);"):h&&T.push("viewMatrix1[3] = vec4(0.0, 0.0, 0.0, 1.0);"),T.push(`mat4 viewMatrix2 = ${I("viewMatrix1")};`));const P="clipPos",S=n.createUniform("bool","clippable"),[D,k]=r.buildProgram(c,s.programName,{appendFragmentOutputs:(e,t,i,r)=>{T.forEach((t=>e.push(t))),s.appendFragmentOutputs(e,t,i,r)},clippableTest:()=>S,clippingCaps:s.clippingCaps,clipPos:h?"clipPos.xyww":P,crossSections:l.crossSections,discardPoints:f&&s.discardPoints,getGammaFactor:l.gammaOutput&&(()=>l.gammaFactor),getLogDepth:!s.dontGetLogDepth&&l.logarithmicDepthBufferEnabled&&(e=>e),getPointSize:s.setupPointSize&&f&&(()=>p),getVertexData:function(){const e=a&&a.needed&&`vec3 ${a} = normalize((${x(v)} * vec4(${o}, 0.0)).xyz);`,i=[];if(i.push(`vec4 localPosition = vec4(${t.position}, 1.0);`),d&&i.push(`localPosition = ${B} * localPosition;`),i.push(`vec4 worldPosition = ${x(g)} * localPosition;`),i.push(`worldPosition.xyz = worldPosition.xyz + ${_};`),s.dontBillboardAnything?i.push(`vec4 viewPosition = ${w} * worldPosition;`):(i.push(`mat4 viewMatrix1 = ${w};`),F?i.push("viewMatrix1[3].xyz = vec3(0.0, 0.0, 0.0);"):h&&i.push("viewMatrix1[3] = vec4(0.0, 0.0, 0.0, 1.0);"),i.push(`mat4 viewMatrix2 = ${x("viewMatrix1")};`),i.push(`vec4 viewPosition = ${E?`${x(`viewMatrix1 * ${g}`)} * localPosition`:"viewMatrix2 * worldPosition"};`)),A&&A.needed&&i.push(`vec2 ${A} = ${d?`(${y} * vec3(${t.uv}, 1.0)).xy`:t.uv};`),o&&o.needed){const e=d?`${n.commonLibrary.octDecode}(${t.normal}.xy)`:t.normal;i.push(`vec3 ${o} = (${x(m)} * vec4(${e}, 0.0)).xyz;`)}return e&&i.push(e),i.push(`vec4 clipPos = ${C} * viewPosition;`),i},projMatrix:C,sectionPlanesState:l._sectionPlanesState,testPerspectiveForGl_FragDepth:!0,usePickClipPos:s.isPick,worldPositionAttribute:"worldPosition"});if(k)return{errors:k};{const e=D.inputSetters;let i=null,r=null;return{destroy:()=>D.destroy(),drawMesh:(n,A,o)=>{if(s.skipIfTransparent&&o.alpha<1)return;const a=o._state,l=A._state,u=A._geometry,d=u._state,f=n.viewParams,M=s.canActAsBackground&&h;n.lastProgramId!==D.id&&(n.lastProgramId=D.id,D.bind(),n.useProgram++,i=null,r=null,M&&c.depthFunc(c.LEQUAL)),a.id!==i&&(n.backfaces!==a.backfaces&&(a.backfaces?c.disable(c.CULL_FACE):c.enable(c.CULL_FACE),n.backfaces=a.backfaces),s.dontSetFrontFace||n.frontface===a.frontface||(c.frontFace(a.frontface?c.CCW:c.CW),n.frontface=a.frontface),s.drawEdges&&n.lineWidth!==a.edgeWidth&&(c.lineWidth(a.edgeWidth),n.lineWidth=a.edgeWidth),s.setsLineWidth&&n.lineWidth!==a.lineWidth&&(c.lineWidth(a.lineWidth),n.lineWidth=a.lineWidth),i=a.id);const E=!s.useShadowView&&A.origin;((t,i)=>{const s=(e,t)=>e.setInputValue&&e.setInputValue(t);s(p,o.pointSize),s(g,A.worldMatrix),s(m,A.worldNormalMatrix),s(_,A.offset),s(b,A.scale),s(B,d.positionsDecodeMatrix),s(y,d.uvDecodeMatrix),s(w,i),s(v,f.viewNormalMatrix),s(C,t),s(S,A.clippable),e.setUniforms(n,{material:o,meshColorize:A.colorize,meshPickID:A._state.pickID,mesh:{origin:A.origin,renderFlags:{sectionPlanesActivePerLayer:A.renderFlags.sectionPlanesActivePerLayer}},view:{far:f.far}})})(f.projMatrix,E?n.getRTCViewMatrix(l.originHash,E):f.viewMatrix);const F=e=>{const i=(e,t)=>{e&&e.setInputValue&&t&&(e.setInputValue(t),n.bindArray++)};i(t.position,(e||d).positionsBuf),i(t.color,d.colorsBuf),i(t.pickColor,e&&e.pickColorsBuf),i(t.uv,d.uvBuf),i(t.normal,d.normalsBuf)};if(s.trianglePick){const e=u._getPickTrianglePositions();d.id!==r&&(F({positionsBuf:e,pickColorsBuf:u._getPickTriangleColors()}),r=d.id),c.drawArrays(d.primitive,0,e.numItems/3)}else if(s.drawEdges){const e=d.primitive===c.TRIANGLES?u._getEdgeIndices():d.primitive===c.LINES&&d.indicesBuf;e&&(d.id!==r&&(F(),e.bind(),n.bindArray++,r=d.id),c.drawElements(c.LINES,e.numItems,e.itemType,0),n.drawElements++)}else d.id!==r&&(F(),d.indicesBuf&&(d.indicesBuf.bind(),n.bindArray++),r=d.id),d.indicesBuf?(c.drawElements(d.primitive,d.indicesBuf.numItems,d.indicesBuf.itemType,0),n.drawElements++):d.positionsBuf&&(c.drawArrays(c.TRIANGLES,0,d.positionsBuf.numItems),n.drawArrays++);M&&c.depthFunc(c.LESS)}}}};class hs extends Ae{get type(){return"Material"}constructor(e,t={}){super(e,t),G.memory.materials++}destroy(){super.destroy(),G.memory.materials--}}const us={opaque:0,mask:1,blend:2},ds=["opaque","mask","blend"];class fs extends hs{get type(){return"PhongMaterial"}constructor(e,t={}){super(e,t),this._state=new Se({type:"PhongMaterial",ambient:V.vec3([1,1,1]),diffuse:V.vec3([1,1,1]),specular:V.vec3([1,1,1]),emissive:V.vec3([0,0,0]),alpha:null,shininess:null,reflectivity:null,alphaMode:null,alphaCutoff:null,lineWidth:null,pointSize:null,backfaces:null,frontface:null,hash:null}),this.ambient=t.ambient,this.diffuse=t.diffuse,this.specular=t.specular,this.emissive=t.emissive,this.alpha=t.alpha,this.shininess=t.shininess,this.reflectivity=t.reflectivity,this.lineWidth=t.lineWidth,this.pointSize=t.pointSize,t.ambientMap&&(this._ambientMap=this._checkComponent("Texture",t.ambientMap)),t.diffuseMap&&(this._diffuseMap=this._checkComponent("Texture",t.diffuseMap)),t.specularMap&&(this._specularMap=this._checkComponent("Texture",t.specularMap)),t.emissiveMap&&(this._emissiveMap=this._checkComponent("Texture",t.emissiveMap)),t.alphaMap&&(this._alphaMap=this._checkComponent("Texture",t.alphaMap)),t.reflectivityMap&&(this._reflectivityMap=this._checkComponent("Texture",t.reflectivityMap)),t.normalMap&&(this._normalMap=this._checkComponent("Texture",t.normalMap)),t.occlusionMap&&(this._occlusionMap=this._checkComponent("Texture",t.occlusionMap)),t.diffuseFresnel&&(this._diffuseFresnel=this._checkComponent("Fresnel",t.diffuseFresnel)),t.specularFresnel&&(this._specularFresnel=this._checkComponent("Fresnel",t.specularFresnel)),t.emissiveFresnel&&(this._emissiveFresnel=this._checkComponent("Fresnel",t.emissiveFresnel)),t.alphaFresnel&&(this._alphaFresnel=this._checkComponent("Fresnel",t.alphaFresnel)),t.reflectivityFresnel&&(this._reflectivityFresnel=this._checkComponent("Fresnel",t.reflectivityFresnel)),this.alphaMode=t.alphaMode,this.alphaCutoff=t.alphaCutoff,this.backfaces=t.backfaces,this.frontface=t.frontface,this._makeHash()}_makeHash(){const e=this._state,t=["/p"];this._normalMap&&(t.push("/nm"),this._normalMap.hasMatrix&&t.push("/mat")),this._ambientMap&&(t.push("/am"),this._ambientMap.hasMatrix&&t.push("/mat"),t.push("/"+this._ambientMap.encoding)),this._diffuseMap&&(t.push("/dm"),this._diffuseMap.hasMatrix&&t.push("/mat"),t.push("/"+this._diffuseMap.encoding)),this._specularMap&&(t.push("/sm"),this._specularMap.hasMatrix&&t.push("/mat")),this._emissiveMap&&(t.push("/em"),this._emissiveMap.hasMatrix&&t.push("/mat"),t.push("/"+this._emissiveMap.encoding)),this._alphaMap&&(t.push("/opm"),this._alphaMap.hasMatrix&&t.push("/mat")),this._reflectivityMap&&(t.push("/rm"),this._reflectivityMap.hasMatrix&&t.push("/mat")),this._occlusionMap&&(t.push("/ocm"),this._occlusionMap.hasMatrix&&t.push("/mat")),this._diffuseFresnel&&t.push("/df"),this._specularFresnel&&t.push("/sf"),this._emissiveFresnel&&t.push("/ef"),this._alphaFresnel&&t.push("/of"),this._reflectivityFresnel&&t.push("/rf"),t.push(";"),e.hash=t.join("")}set ambient(e){let t=this._state.ambient;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.ambient=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}get ambient(){return this._state.ambient}set diffuse(e){let t=this._state.diffuse;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.diffuse=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}get diffuse(){return this._state.diffuse}set specular(e){let t=this._state.specular;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.specular=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}get specular(){return this._state.specular}set emissive(e){let t=this._state.emissive;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.emissive=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=0,t[1]=0,t[2]=0),this.glRedraw()}get emissive(){return this._state.emissive}set alpha(e){e=null!=e?e:1,this._state.alpha!==e&&(this._state.alpha=e,this.glRedraw())}get alpha(){return this._state.alpha}set shininess(e){this._state.shininess=void 0!==e?e:80,this.glRedraw()}get shininess(){return this._state.shininess}set lineWidth(e){this._state.lineWidth=e||1,this.glRedraw()}get lineWidth(){return this._state.lineWidth}set pointSize(e){this._state.pointSize=e||1,this.glRedraw()}get pointSize(){return this._state.pointSize}set reflectivity(e){this._state.reflectivity=void 0!==e?e:1,this.glRedraw()}get reflectivity(){return this._state.reflectivity}get normalMap(){return this._normalMap}get ambientMap(){return this._ambientMap}get diffuseMap(){return this._diffuseMap}get specularMap(){return this._specularMap}get emissiveMap(){return this._emissiveMap}get alphaMap(){return this._alphaMap}get reflectivityMap(){return this._reflectivityMap}get occlusionMap(){return this._occlusionMap}get diffuseFresnel(){return this._diffuseFresnel}get specularFresnel(){return this._specularFresnel}get emissiveFresnel(){return this._emissiveFresnel}get alphaFresnel(){return this._alphaFresnel}get reflectivityFresnel(){return this._reflectivityFresnel}set alphaMode(e){let t=us[e=e||"opaque"];void 0===t&&(this.error("Unsupported value for 'alphaMode': "+e+" - defaulting to 'opaque'"),t="opaque"),this._state.alphaMode!==t&&(this._state.alphaMode=t,this.glRedraw())}get alphaMode(){return ds[this._state.alphaMode]}set alphaCutoff(e){null==e&&(e=.5),this._state.alphaCutoff!==e&&(this._state.alphaCutoff=e)}get alphaCutoff(){return this._state.alphaCutoff}set backfaces(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}get backfaces(){return this._state.backfaces}set frontface(e){e="cw"!==e,this._state.frontface!==e&&(this._state.frontface=e,this.glRedraw())}get frontface(){return this._state.frontface?"ccw":"cw"}destroy(){super.destroy(),this._state.destroy()}}function ps(e,t){if(void 0===e._cachedExtensions&&(e._cachedExtensions={}),void 0!==e._cachedExtensions[t])return e._cachedExtensions[t];let i;switch(t){case"WEBGL_depth_texture":i=e.getExtension("WEBGL_depth_texture")||e.getExtension("MOZ_WEBGL_depth_texture")||e.getExtension("WEBKIT_WEBGL_depth_texture");break;case"EXT_texture_filter_anisotropic":i=e.getExtension("EXT_texture_filter_anisotropic")||e.getExtension("MOZ_EXT_texture_filter_anisotropic")||e.getExtension("WEBKIT_EXT_texture_filter_anisotropic");break;case"WEBGL_compressed_texture_s3tc":i=e.getExtension("WEBGL_compressed_texture_s3tc")||e.getExtension("MOZ_WEBGL_compressed_texture_s3tc")||e.getExtension("WEBKIT_WEBGL_compressed_texture_s3tc");break;case"WEBGL_compressed_texture_pvrtc":i=e.getExtension("WEBGL_compressed_texture_pvrtc")||e.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc");break;default:i=e.getExtension(t)}return e._cachedExtensions[t]=i,i}function gs(e,t,i=null){let s;const r=t;if(1009===r)return e.UNSIGNED_BYTE;if(1017===r)return e.UNSIGNED_SHORT_4_4_4_4;if(1018===r)return e.UNSIGNED_SHORT_5_5_5_1;if(1010===r)return e.BYTE;if(1011===r)return e.SHORT;if(1012===r)return e.UNSIGNED_SHORT;if(1013===r)return e.INT;if(1014===r)return e.UNSIGNED_INT;if(1015===r)return e.FLOAT;if(1016===r)return e.HALF_FLOAT;if(1021===r)return e.ALPHA;if(1023===r)return e.RGBA;if(1024===r)return e.LUMINANCE;if(1025===r)return e.LUMINANCE_ALPHA;if(1026===r)return e.DEPTH_COMPONENT;if(1027===r)return e.DEPTH_STENCIL;if(1028===r)return e.RED;if(1022===r)return e.RGBA;if(1029===r)return e.RED_INTEGER;if(1030===r)return e.RG;if(1031===r)return e.RG_INTEGER;if(1033===r)return e.RGBA_INTEGER;if(33776===r||33777===r||33778===r||33779===r)if(3001===i){const t=ps(e,"WEBGL_compressed_texture_s3tc_srgb");if(null===t)return null;if(33776===r)return t.COMPRESSED_SRGB_S3TC_DXT1_EXT;if(33777===r)return t.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;if(33778===r)return t.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;if(33779===r)return t.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}else{if(s=ps(e,"WEBGL_compressed_texture_s3tc"),null===s)return null;if(33776===r)return s.COMPRESSED_RGB_S3TC_DXT1_EXT;if(33777===r)return s.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(33778===r)return s.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(33779===r)return s.COMPRESSED_RGBA_S3TC_DXT5_EXT}if(35840===r||35841===r||35842===r||35843===r){const t=ps(e,"WEBGL_compressed_texture_pvrtc");if(null===t)return null;if(35840===r)return t.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(35841===r)return t.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(35842===r)return t.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(35843===r)return t.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}if(36196===r){const t=ps(e,"WEBGL_compressed_texture_etc1");return null!==t?t.COMPRESSED_RGB_ETC1_WEBGL:null}if(37492===r||37496===r){const t=ps(e,"WEBGL_compressed_texture_etc");if(null===t)return null;if(37492===r)return 3001===i?t.COMPRESSED_SRGB8_ETC2:t.COMPRESSED_RGB8_ETC2;if(37496===r)return 3001===i?t.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:t.COMPRESSED_RGBA8_ETC2_EAC}if(37808===r||37809===r||37810===r||37811===r||37812===r||37813===r||37814===r||37815===r||37816===r||37817===r||37818===r||37819===r||37820===r||37821===r){const t=ps(e,"WEBGL_compressed_texture_astc");if(null===t)return null;if(37808===r)return 3001===i?t.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:t.COMPRESSED_RGBA_ASTC_4x4_KHR;if(37809===r)return 3001===i?t.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:t.COMPRESSED_RGBA_ASTC_5x4_KHR;if(37810===r)return 3001===i?t.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:t.COMPRESSED_RGBA_ASTC_5x5_KHR;if(37811===r)return 3001===i?t.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:t.COMPRESSED_RGBA_ASTC_6x5_KHR;if(37812===r)return 3001===i?t.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:t.COMPRESSED_RGBA_ASTC_6x6_KHR;if(37813===r)return 3001===i?t.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:t.COMPRESSED_RGBA_ASTC_8x5_KHR;if(37814===r)return 3001===i?t.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:t.COMPRESSED_RGBA_ASTC_8x6_KHR;if(37815===r)return 3001===i?t.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:t.COMPRESSED_RGBA_ASTC_8x8_KHR;if(37816===r)return 3001===i?t.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:t.COMPRESSED_RGBA_ASTC_10x5_KHR;if(37817===r)return 3001===i?t.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:t.COMPRESSED_RGBA_ASTC_10x6_KHR;if(37818===r)return 3001===i?t.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:t.COMPRESSED_RGBA_ASTC_10x8_KHR;if(37819===r)return 3001===i?t.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:t.COMPRESSED_RGBA_ASTC_10x10_KHR;if(37820===r)return 3001===i?t.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:t.COMPRESSED_RGBA_ASTC_12x10_KHR;if(37821===r)return 3001===i?t.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:t.COMPRESSED_RGBA_ASTC_12x12_KHR}if(36492===r){const t=ps(e,"EXT_texture_compression_bptc");if(null===t)return null;if(36492===r)return 3001===i?t.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:t.COMPRESSED_RGBA_BPTC_UNORM_EXT}return 1020===r?e.UNSIGNED_INT_24_8:1e3===r?e.REPEAT:1001===r?e.CLAMP_TO_EDGE:1004===r||1005===r?e.NEAREST_MIPMAP_LINEAR:1007===r?e.LINEAR_MIPMAP_NEAREST:1008===r?e.LINEAR_MIPMAP_LINEAR:1003===r?e.NEAREST:1006===r?e.LINEAR:null}const ms=new Uint8Array([0,0,0,1]);class _s{constructor({gl:e,target:t,format:i,type:s,wrapS:r,wrapT:n,wrapR:A,encoding:o,preloadColor:a,premultiplyAlpha:l,flipY:c}){this.gl=e,this.target=t||e.TEXTURE_2D,this.format=i||1023,this.type=s||1009,this.internalFormat=null,this.premultiplyAlpha=!!l,this.flipY=!!c,this.unpackAlignment=4,this.wrapS=r||1e3,this.wrapT=n||1e3,this.wrapR=A||1e3,this.encoding=o||3001,this.texture=e.createTexture(),a&&this.setPreloadColor(a),this.allocated=!0}setPreloadColor(e){e?(ms[0]=Math.floor(255*e[0]),ms[1]=Math.floor(255*e[1]),ms[2]=Math.floor(255*e[2]),ms[3]=Math.floor(255*(void 0!==e[3]?e[3]:1))):(ms[0]=0,ms[1]=0,ms[2]=0,ms[3]=255);const t=this.gl;if(t.bindTexture(this.target,this.texture),this.target===t.TEXTURE_CUBE_MAP){const e=[t.TEXTURE_CUBE_MAP_POSITIVE_X,t.TEXTURE_CUBE_MAP_NEGATIVE_X,t.TEXTURE_CUBE_MAP_POSITIVE_Y,t.TEXTURE_CUBE_MAP_NEGATIVE_Y,t.TEXTURE_CUBE_MAP_POSITIVE_Z,t.TEXTURE_CUBE_MAP_NEGATIVE_Z];for(let i=0,s=e.length;i<s;i++)t.texImage2D(e[i],0,t.RGBA,1,1,0,t.RGBA,t.UNSIGNED_BYTE,ms)}else t.texImage2D(this.target,0,t.RGBA,1,1,0,t.RGBA,t.UNSIGNED_BYTE,ms);t.bindTexture(this.target,null)}setTarget(e){this.target=e||this.gl.TEXTURE_2D}setImage(e,t={}){const i=this.gl;void 0!==t.format&&(this.format=t.format),void 0!==t.internalFormat&&(this.internalFormat=t.internalFormat),void 0!==t.encoding&&(this.encoding=t.encoding),void 0!==t.type&&(this.type=t.type),void 0!==t.flipY&&(this.flipY=t.flipY),void 0!==t.premultiplyAlpha&&(this.premultiplyAlpha=t.premultiplyAlpha),void 0!==t.unpackAlignment&&(this.unpackAlignment=t.unpackAlignment),void 0!==t.minFilter&&(this.minFilter=t.minFilter),void 0!==t.magFilter&&(this.magFilter=t.magFilter),void 0!==t.wrapS&&(this.wrapS=t.wrapS),void 0!==t.wrapT&&(this.wrapT=t.wrapT),void 0!==t.wrapR&&(this.wrapR=t.wrapR);let s=!1;i.bindTexture(this.target,this.texture);const r=i.getParameter(i.UNPACK_FLIP_Y_WEBGL);i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL,this.flipY);const n=i.getParameter(i.UNPACK_PREMULTIPLY_ALPHA_WEBGL);i.pixelStorei(i.UNPACK_PREMULTIPLY_ALPHA_WEBGL,this.premultiplyAlpha);const A=i.getParameter(i.UNPACK_ALIGNMENT);i.pixelStorei(i.UNPACK_ALIGNMENT,this.unpackAlignment);const o=i.getParameter(i.UNPACK_COLORSPACE_CONVERSION_WEBGL);i.pixelStorei(i.UNPACK_COLORSPACE_CONVERSION_WEBGL,i.NONE);const a=gs(i,this.minFilter);i.texParameteri(this.target,i.TEXTURE_MIN_FILTER,a),a!==i.NEAREST_MIPMAP_NEAREST&&a!==i.LINEAR_MIPMAP_NEAREST&&a!==i.NEAREST_MIPMAP_LINEAR&&a!==i.LINEAR_MIPMAP_LINEAR||(s=!0);const l=gs(i,this.magFilter);l&&i.texParameteri(this.target,i.TEXTURE_MAG_FILTER,l);const c=gs(i,this.wrapS);c&&i.texParameteri(this.target,i.TEXTURE_WRAP_S,c);const h=gs(i,this.wrapT);h&&i.texParameteri(this.target,i.TEXTURE_WRAP_T,h);const u=gs(i,this.format,this.encoding),d=gs(i,this.type),f=bs(i,this.internalFormat,u,d,this.encoding,!1);if(this.target===i.TEXTURE_CUBE_MAP){if(X.isArray(e)){const t=e,s=[i.TEXTURE_CUBE_MAP_POSITIVE_X,i.TEXTURE_CUBE_MAP_NEGATIVE_X,i.TEXTURE_CUBE_MAP_POSITIVE_Y,i.TEXTURE_CUBE_MAP_NEGATIVE_Y,i.TEXTURE_CUBE_MAP_POSITIVE_Z,i.TEXTURE_CUBE_MAP_NEGATIVE_Z];for(let e=0,r=s.length;e<r;e++)i.texImage2D(s[e],0,f,u,d,t[e])}}else i.texImage2D(i.TEXTURE_2D,0,f,u,d,e);s&&i.generateMipmap(this.target),i.bindTexture(this.target,null),i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL,r),i.pixelStorei(i.UNPACK_PREMULTIPLY_ALPHA_WEBGL,n),i.pixelStorei(i.UNPACK_ALIGNMENT,A),i.pixelStorei(i.UNPACK_COLORSPACE_CONVERSION_WEBGL,o)}setCompressedData({mipmaps:e,props:t={}}){const i=this.gl,s=e.length;void 0!==t.format&&(this.format=t.format),void 0!==t.internalFormat&&(this.internalFormat=t.internalFormat),void 0!==t.encoding&&(this.encoding=t.encoding),void 0!==t.type&&(this.type=t.type),void 0!==t.flipY&&(this.flipY=t.flipY),void 0!==t.premultiplyAlpha&&(this.premultiplyAlpha=t.premultiplyAlpha),void 0!==t.unpackAlignment&&(this.unpackAlignment=t.unpackAlignment),void 0!==t.minFilter&&(this.minFilter=t.minFilter),void 0!==t.magFilter&&(this.magFilter=t.magFilter),void 0!==t.wrapS&&(this.wrapS=t.wrapS),void 0!==t.wrapT&&(this.wrapT=t.wrapT),void 0!==t.wrapR&&(this.wrapR=t.wrapR),i.activeTexture(i.TEXTURE0+0),i.bindTexture(this.target,this.texture);let r=e.length>1;i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL,this.flipY),i.pixelStorei(i.UNPACK_PREMULTIPLY_ALPHA_WEBGL,this.premultiplyAlpha),i.pixelStorei(i.UNPACK_ALIGNMENT,this.unpackAlignment),i.pixelStorei(i.UNPACK_COLORSPACE_CONVERSION_WEBGL,i.NONE);const n=gs(i,this.wrapS);n&&i.texParameteri(this.target,i.TEXTURE_WRAP_S,n);const A=gs(i,this.wrapT);if(A&&i.texParameteri(this.target,i.TEXTURE_WRAP_T,A),this.type===i.TEXTURE_3D||this.type===i.TEXTURE_2D_ARRAY){const e=gs(i,this.wrapR);e&&i.texParameteri(this.target,i.TEXTURE_WRAP_R,e),i.texParameteri(this.type,i.TEXTURE_WRAP_R,e)}r?(i.texParameteri(this.target,i.TEXTURE_MIN_FILTER,Bs(i,this.minFilter)),i.texParameteri(this.target,i.TEXTURE_MAG_FILTER,Bs(i,this.magFilter))):(i.texParameteri(this.target,i.TEXTURE_MIN_FILTER,gs(i,this.minFilter)),i.texParameteri(this.target,i.TEXTURE_MAG_FILTER,gs(i,this.magFilter)));const o=gs(i,this.format,this.encoding),a=gs(i,this.type),l=bs(i,this.internalFormat,o,a,this.encoding,!1);i.texStorage2D(i.TEXTURE_2D,s,l,e[0].width,e[0].height);for(let t=0,s=e.length;t<s;t++){const s=e[t];1023!==this.format?null!==o?i.compressedTexSubImage2D(i.TEXTURE_2D,t,0,0,s.width,s.height,o,s.data):console.warn("Attempt to load unsupported compressed texture format in .setCompressedData()"):i.texSubImage2D(i.TEXTURE_2D,t,0,0,s.width,s.height,o,a,s.data)}i.bindTexture(this.target,null)}setProps(e){const t=this.gl;t.bindTexture(this.target,this.texture),this._uploadProps(e),t.bindTexture(this.target,null)}_uploadProps(e){const t=this.gl;if(void 0!==e.format&&(this.format=e.format),void 0!==e.internalFormat&&(this.internalFormat=e.internalFormat),void 0!==e.encoding&&(this.encoding=e.encoding),void 0!==e.type&&(this.type=e.type),void 0!==e.minFilter){const i=gs(t,e.minFilter);i&&(this.minFilter=e.minFilter,t.texParameteri(this.target,t.TEXTURE_MIN_FILTER,i),i!==t.NEAREST_MIPMAP_NEAREST&&i!==t.LINEAR_MIPMAP_NEAREST&&i!==t.NEAREST_MIPMAP_LINEAR&&i!==t.LINEAR_MIPMAP_LINEAR||t.generateMipmap(this.target))}if(void 0!==e.magFilter){const i=gs(t,e.magFilter);i&&(this.magFilter=e.magFilter,t.texParameteri(this.target,t.TEXTURE_MAG_FILTER,i))}if(void 0!==e.wrapS){const i=gs(t,e.wrapS);i&&(this.wrapS=e.wrapS,t.texParameteri(this.target,t.TEXTURE_WRAP_S,i))}if(void 0!==e.wrapT){const i=gs(t,e.wrapT);i&&(this.wrapT=e.wrapT,t.texParameteri(this.target,t.TEXTURE_WRAP_T,i))}}bind(e){if(this.allocated){if(this.texture){const t=this.gl;return t.activeTexture(t["TEXTURE"+e]),t.bindTexture(this.target,this.texture),!0}return!1}}unbind(e){if(this.allocated&&this.texture){const t=this.gl;t.activeTexture(t["TEXTURE"+e]),t.bindTexture(this.target,null)}}destroy(){this.allocated&&this.texture&&(this.gl.deleteTexture(this.texture),this.texture=null)}}function bs(e,t,i,s,r,n=!1){if(null!==t){if(void 0!==e[t])return e[t];console.warn("Attempt to use non-existing WebGL internal format '"+t+"'")}let A=i;return i===e.RED&&(s===e.FLOAT&&(A=e.R32F),s===e.HALF_FLOAT&&(A=e.R16F),s===e.UNSIGNED_BYTE&&(A=e.R8)),i===e.RG&&(s===e.FLOAT&&(A=e.RG32F),s===e.HALF_FLOAT&&(A=e.RG16F),s===e.UNSIGNED_BYTE&&(A=e.RG8)),i===e.RGBA&&(s===e.FLOAT&&(A=e.RGBA32F),s===e.HALF_FLOAT&&(A=e.RGBA16F),s===e.UNSIGNED_BYTE&&(A=3001===r&&!1===n?e.SRGB8_ALPHA8:e.RGBA8),s===e.UNSIGNED_SHORT_4_4_4_4&&(A=e.RGBA4),s===e.UNSIGNED_SHORT_5_5_5_1&&(A=e.RGB5_A1)),A!==e.R16F&&A!==e.R32F&&A!==e.RG16F&&A!==e.RG32F&&A!==e.RGBA16F&&A!==e.RGBA32F||ps(e,"EXT_color_buffer_float"),A}function Bs(e,t){return 1003===t||1004===t||1005===t?e.NEAREST:e.LINEAR}function ys(e){if(!ws(e.width)||!ws(e.height)){const t=document.createElement("canvas");t.width=vs(e.width),t.height=vs(e.height);t.getContext("2d").drawImage(e,0,0,e.width,e.height,0,0,t.width,t.height),e=t}return e}function ws(e){return 0==(e&e-1)}function vs(e){--e;for(let t=1;t<32;t<<=1)e|=e>>t;return e+1}class Cs extends Ae{get type(){return"Texture"}constructor(e,t={}){super(e,t),this._state=new Se({texture:new _s({gl:this.scene.canvas.gl}),matrix:V.identityMat4(),hasMatrix:t.translate&&(0!==t.translate[0]||0!==t.translate[1])||!!t.rotate||t.scale&&(0!==t.scale[0]||0!==t.scale[1]),minFilter:this._checkMinFilter(t.minFilter),magFilter:this._checkMagFilter(t.magFilter),wrapS:this._checkWrapS(t.wrapS),wrapT:this._checkWrapT(t.wrapT),flipY:this._checkFlipY(t.flipY),encoding:this._checkEncoding(t.encoding)}),this._src=null,this._image=null,this._translate=V.vec2([0,0]),this._scale=V.vec2([1,1]),this._rotate=V.vec2([0,0]),this._matrixDirty=!1,this.translate=t.translate,this.scale=t.scale,this.rotate=t.rotate,t.src?this.src=t.src:t.image&&(this.image=t.image),G.memory.textures++}_checkMinFilter(e){return 1006!==(e=e||1008)&&1007!==e&&1008!==e&&1005!==e&&1004!==e&&(this.error("Unsupported value for 'minFilter' - supported values are LinearFilter, LinearMipMapNearestFilter, NearestMipMapNearestFilter, NearestMipMapLinearFilter and LinearMipMapLinearFilter. Defaulting to LinearMipMapLinearFilter."),e=1008),e}_checkMagFilter(e){return 1006!==(e=e||1006)&&1003!==e&&(this.error("Unsupported value for 'magFilter' - supported values are LinearFilter and NearestFilter. Defaulting to LinearFilter."),e=1006),e}_checkWrapS(e){return 1001!==(e=e||1e3)&&1002!==e&&1e3!==e&&(this.error("Unsupported value for 'wrapS' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),e=1e3),e}_checkWrapT(e){return 1001!==(e=e||1e3)&&1002!==e&&1e3!==e&&(this.error("Unsupported value for 'wrapT' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),e=1e3),e}_checkFlipY(e){return!!e}_checkEncoding(e){return 3e3!==(e=e||3e3)&&3001!==e&&(this.error("Unsupported value for 'encoding' - supported values are LinearEncoding and sRGBEncoding. Defaulting to LinearEncoding."),e=3e3),e}_update(){const e=this._state;if(this._matrixDirty){let t,i;0===this._translate[0]&&0===this._translate[1]||(t=V.translationMat4v([this._translate[0],this._translate[1],0],this._state.matrix)),1===this._scale[0]&&1===this._scale[1]||(i=V.scalingMat4v([this._scale[0],this._scale[1],1]),t=t?V.mulMat4(t,i):i),0!==this._rotate&&(i=V.rotationMat4v(.0174532925*this._rotate,[0,0,1]),t=t?V.mulMat4(t,i):i),t&&(e.matrix=t),this._matrixDirty=!1}this.glRedraw()}set image(e){this._image=ys(e),this._image.crossOrigin="Anonymous",this._state.texture.setImage(this._image,this._state),this._src=null,this.glRedraw()}get image(){return this._image}set src(e){this.scene.loading++,this.scene.canvas.spinner.processes++;const t=this;let i=new Image;i.onload=function(){i=ys(i),t._state.texture.setImage(i,t._state),t.scene.loading--,t.glRedraw(),t.scene.canvas.spinner.processes--},i.src=e,this._src=e,this._image=null}get src(){return this._src}set translate(e){this._translate.set(e||[0,0]),this._matrixDirty=!0,this._needUpdate()}get translate(){return this._translate}set scale(e){this._scale.set(e||[1,1]),this._matrixDirty=!0,this._needUpdate()}get scale(){return this._scale}set rotate(e){e=e||0,this._rotate!==e&&(this._rotate=e,this._matrixDirty=!0,this._needUpdate())}get rotate(){return this._rotate}get minFilter(){return this._state.minFilter}get magFilter(){return this._state.magFilter}get wrapS(){return this._state.wrapS}get wrapT(){return this._state.wrapT}get flipY(){return this._state.flipY}get encoding(){return this._state.encoding}destroy(){super.destroy(),this._state.texture&&this._state.texture.destroy(),this._state.destroy(),G.memory.textures--}}const Ms=V.vec3(),Es=V.vec3();V.vec3();const Fs=V.vec3([0,-1,0]),Us=V.vec4([0,0,0,1]);class xs extends Ae{constructor(e,t={}){super(e,t),this._src=null,this._image=null,this._pos=V.vec3(),this._origin=V.vec3(),this._rtcPos=V.vec3(),this._dir=V.vec3(),this._size=1,this._imageSize=V.vec2(),this._texture=new Cs(this),this._plane=new as(this,{geometry:new We(this,st({center:[0,0,0],xSize:1,zSize:1,xSegments:10,zSegments:10})),material:new fs(this,{diffuse:[0,0,0],ambient:[0,0,0],specular:[0,0,0],diffuseMap:this._texture,emissiveMap:this._texture,backfaces:!0}),clippable:t.clippable}),this._grid=new as(this,{geometry:new We(this,it({size:1,divisions:10})),material:new fs(this,{diffuse:[0,0,0],ambient:[0,0,0],emissive:[.2,.8,.2]}),position:[0,.001,0],clippable:t.clippable}),this._node=new Bt(this,{rotation:[0,0,0],position:[0,0,0],scale:[1,1,1],clippable:!1,children:[this._plane,this._grid]}),this._gridVisible=!1,this.visible=!0,this.gridVisible=t.gridVisible,this.position=t.position,this.rotation=t.rotation,this.dir=t.dir,this.size=t.size,this.collidable=t.collidable,this.clippable=t.clippable,this.pickable=t.pickable,this.opacity=t.opacity,t.image?this.image=t.image:this.src=t.src}set visible(e){this._plane.visible=e,this._grid.visible=this._gridVisible&&e}get visible(){return this._plane.visible}set gridVisible(e){e=!1!==e,this._gridVisible=e,this._grid.visible=this._gridVisible&&this.visible}get gridVisible(){return this._gridVisible}set image(e){this._image=e,this._image&&(this._imageSize[0]=e.width,this._imageSize[1]=e.height,this._updatePlaneSizeFromImage(),this._src=null,this._texture.image=this._image)}get image(){return this._image}set src(e){if(this._src=e,this._src){this._image=null;const e=new Image;e.onload=()=>{this._texture.image=e,this._imageSize[0]=e.width,this._imageSize[1]=e.height,this._updatePlaneSizeFromImage()},e.src=this._src}}get src(){return this._src}set position(e){this._pos.set(e||[0,0,0]),vt(this._pos,this._origin,this._rtcPos),this._node.origin=this._origin,this._node.position=this._rtcPos}get position(){return this._pos}set rotation(e){this._node.rotation=e}get rotation(){return this._node.rotation}set size(e){this._size=null==e?1:e,this._image&&this._updatePlaneSizeFromImage()}get size(){return this._size}set dir(e){if(this._dir.set(e||[0,0,-1]),e){const t=this.scene.center,i=[-this._dir[0],-this._dir[1],-this._dir[2]];V.subVec3(t,this.position,Ms);const s=-V.dotVec3(i,Ms);V.normalizeVec3(i),V.mulVec3Scalar(i,s,Es),V.vec3PairToQuaternion(Fs,e,Us),this._node.quaternion=Us}}get dir(){return this._dir}set collidable(e){this._node.collidable=!1!==e}get collidable(){return this._node.collidable}set clippable(e){this._node.clippable=!1!==e}get clippable(){return this._node.clippable}set pickable(e){this._node.pickable=!1!==e}get pickable(){return this._node.pickable}set opacity(e){this._node.opacity=e}get opacity(){return this._node.opacity}destroy(){super.destroy()}_updatePlaneSizeFromImage(){const e=this._size,t=this._imageSize[0],i=this._imageSize[1];if(t>i){const s=i/t;this._node.scale=[e,1,e*s]}else{const s=t/i;this._node.scale=[e*s,1,e]}}}class Is extends hs{get type(){return"LambertMaterial"}constructor(e,t={}){super(e,t),this._state=new Se({type:"LambertMaterial",ambient:V.vec3([1,1,1]),color:V.vec3([1,1,1]),emissive:V.vec3([0,0,0]),alpha:null,alphaMode:0,lineWidth:null,pointSize:null,backfaces:null,frontface:null,hash:"/lam;"}),this.ambient=t.ambient,this.color=t.color,this.emissive=t.emissive,this.alpha=t.alpha,this.lineWidth=t.lineWidth,this.pointSize=t.pointSize,this.backfaces=t.backfaces,this.frontface=t.frontface}set ambient(e){let t=this._state.ambient;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.ambient=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}get ambient(){return this._state.ambient}set color(e){let t=this._state.color;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.color=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}get color(){return this._state.color}set emissive(e){let t=this._state.emissive;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.emissive=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=0,t[1]=0,t[2]=0),this.glRedraw()}get emissive(){return this._state.emissive}set alpha(e){e=null!=e?e:1,this._state.alpha!==e&&(this._state.alpha=e,this._state.alphaMode=e<1?2:0,this.glRedraw())}get alpha(){return this._state.alpha}set lineWidth(e){this._state.lineWidth=e||1,this.glRedraw()}get lineWidth(){return this._state.lineWidth}set pointSize(e){this._state.pointSize=e||1,this.glRedraw()}get pointSize(){return this._state.pointSize}set backfaces(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}get backfaces(){return this._state.backfaces}set frontface(e){e="cw"!==e,this._state.frontface!==e&&(this._state.frontface=e,this.glRedraw())}get frontface(){return this._state.frontface?"ccw":"cw"}_getState(){return this._state}destroy(){super.destroy(),this._state.destroy()}}const Ts={opaque:0,mask:1,blend:2},Ps=["opaque","mask","blend"];class Ss extends hs{get type(){return"MetallicMaterial"}constructor(e,t={}){super(e,t),this._state=new Se({type:"MetallicMaterial",baseColor:V.vec4([1,1,1]),emissive:V.vec4([0,0,0]),metallic:null,roughness:null,specularF0:null,alpha:null,alphaMode:null,alphaCutoff:null,lineWidth:null,pointSize:null,backfaces:null,frontface:null,hash:null}),this.baseColor=t.baseColor,this.metallic=t.metallic,this.roughness=t.roughness,this.specularF0=t.specularF0,this.emissive=t.emissive,this.alpha=t.alpha,t.baseColorMap&&(this._baseColorMap=this._checkComponent("Texture",t.baseColorMap)),t.metallicMap&&(this._metallicMap=this._checkComponent("Texture",t.metallicMap)),t.roughnessMap&&(this._roughnessMap=this._checkComponent("Texture",t.roughnessMap)),t.metallicRoughnessMap&&(this._metallicRoughnessMap=this._checkComponent("Texture",t.metallicRoughnessMap)),t.emissiveMap&&(this._emissiveMap=this._checkComponent("Texture",t.emissiveMap)),t.occlusionMap&&(this._occlusionMap=this._checkComponent("Texture",t.occlusionMap)),t.alphaMap&&(this._alphaMap=this._checkComponent("Texture",t.alphaMap)),t.normalMap&&(this._normalMap=this._checkComponent("Texture",t.normalMap)),this.alphaMode=t.alphaMode,this.alphaCutoff=t.alphaCutoff,this.backfaces=t.backfaces,this.frontface=t.frontface,this.lineWidth=t.lineWidth,this.pointSize=t.pointSize,this._makeHash()}_makeHash(){const e=this._state,t=["/met"];this._baseColorMap&&(t.push("/bm"),this._baseColorMap._state.hasMatrix&&t.push("/mat"),t.push("/"+this._baseColorMap._state.encoding)),this._metallicMap&&(t.push("/mm"),this._metallicMap._state.hasMatrix&&t.push("/mat")),this._roughnessMap&&(t.push("/rm"),this._roughnessMap._state.hasMatrix&&t.push("/mat")),this._metallicRoughnessMap&&(t.push("/mrm"),this._metallicRoughnessMap._state.hasMatrix&&t.push("/mat")),this._emissiveMap&&(t.push("/em"),this._emissiveMap._state.hasMatrix&&t.push("/mat")),this._occlusionMap&&(t.push("/ocm"),this._occlusionMap._state.hasMatrix&&t.push("/mat")),this._alphaMap&&(t.push("/am"),this._alphaMap._state.hasMatrix&&t.push("/mat")),this._normalMap&&(t.push("/nm"),this._normalMap._state.hasMatrix&&t.push("/mat")),t.push(";"),e.hash=t.join("")}set baseColor(e){let t=this._state.baseColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.baseColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}get baseColor(){return this._state.baseColor}get baseColorMap(){return this._baseColorMap}set metallic(e){e=null!=e?e:1,this._state.metallic!==e&&(this._state.metallic=e,this.glRedraw())}get metallic(){return this._state.metallic}get metallicMap(){return this._attached.metallicMap}set roughness(e){e=null!=e?e:1,this._state.roughness!==e&&(this._state.roughness=e,this.glRedraw())}get roughness(){return this._state.roughness}get roughnessMap(){return this._attached.roughnessMap}get metallicRoughnessMap(){return this._attached.metallicRoughnessMap}set specularF0(e){e=null!=e?e:0,this._state.specularF0!==e&&(this._state.specularF0=e,this.glRedraw())}get specularF0(){return this._state.specularF0}set emissive(e){let t=this._state.emissive;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.emissive=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=0,t[1]=0,t[2]=0),this.glRedraw()}get emissive(){return this._state.emissive}get emissiveMap(){return this._attached.emissiveMap}get occlusionMap(){return this._attached.occlusionMap}set alpha(e){e=null!=e?e:1,this._state.alpha!==e&&(this._state.alpha=e,this.glRedraw())}get alpha(){return this._state.alpha}get alphaMap(){return this._attached.alphaMap}get normalMap(){return this._attached.normalMap}set alphaMode(e){let t=Ts[e=e||"opaque"];void 0===t&&(this.error("Unsupported value for 'alphaMode': "+e+" defaulting to 'opaque'"),t="opaque"),this._state.alphaMode!==t&&(this._state.alphaMode=t,this.glRedraw())}get alphaMode(){return Ps[this._state.alphaMode]}set alphaCutoff(e){null==e&&(e=.5),this._state.alphaCutoff!==e&&(this._state.alphaCutoff=e)}get alphaCutoff(){return this._state.alphaCutoff}set backfaces(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}get backfaces(){return this._state.backfaces}set frontface(e){e="cw"!==e,this._state.frontface!==e&&(this._state.frontface=e,this.glRedraw())}get frontface(){return this._state.frontface?"ccw":"cw"}set lineWidth(e){this._state.lineWidth=e||1,this.glRedraw()}get lineWidth(){return this._state.lineWidth}set pointSize(e){this._state.pointSize=e||1,this.glRedraw()}get pointSize(){return this._state.pointSize}destroy(){super.destroy(),this._state.destroy()}}const Ds={opaque:0,mask:1,blend:2},ks=["opaque","mask","blend"];class Qs extends hs{get type(){return"SpecularMaterial"}constructor(e,t={}){super(e,t),this._state=new Se({type:"SpecularMaterial",diffuse:V.vec3([1,1,1]),emissive:V.vec3([0,0,0]),specular:V.vec3([1,1,1]),glossiness:null,specularF0:null,alpha:null,alphaMode:null,alphaCutoff:null,lineWidth:null,pointSize:null,backfaces:null,frontface:null,hash:null}),this.diffuse=t.diffuse,this.specular=t.specular,this.glossiness=t.glossiness,this.specularF0=t.specularF0,this.emissive=t.emissive,this.alpha=t.alpha,t.diffuseMap&&(this._diffuseMap=this._checkComponent("Texture",t.diffuseMap)),t.emissiveMap&&(this._emissiveMap=this._checkComponent("Texture",t.emissiveMap)),t.specularMap&&(this._specularMap=this._checkComponent("Texture",t.specularMap)),t.glossinessMap&&(this._glossinessMap=this._checkComponent("Texture",t.glossinessMap)),t.specularGlossinessMap&&(this._specularGlossinessMap=this._checkComponent("Texture",t.specularGlossinessMap)),t.occlusionMap&&(this._occlusionMap=this._checkComponent("Texture",t.occlusionMap)),t.alphaMap&&(this._alphaMap=this._checkComponent("Texture",t.alphaMap)),t.normalMap&&(this._normalMap=this._checkComponent("Texture",t.normalMap)),this.alphaMode=t.alphaMode,this.alphaCutoff=t.alphaCutoff,this.backfaces=t.backfaces,this.frontface=t.frontface,this.lineWidth=t.lineWidth,this.pointSize=t.pointSize,this._makeHash()}_makeHash(){const e=this._state,t=["/spe"];this._diffuseMap&&(t.push("/dm"),this._diffuseMap.hasMatrix&&t.push("/mat"),t.push("/"+this._diffuseMap.encoding)),this._emissiveMap&&(t.push("/em"),this._emissiveMap.hasMatrix&&t.push("/mat")),this._glossinessMap&&(t.push("/gm"),this._glossinessMap.hasMatrix&&t.push("/mat")),this._specularMap&&(t.push("/sm"),this._specularMap.hasMatrix&&t.push("/mat")),this._specularGlossinessMap&&(t.push("/sgm"),this._specularGlossinessMap.hasMatrix&&t.push("/mat")),this._occlusionMap&&(t.push("/ocm"),this._occlusionMap.hasMatrix&&t.push("/mat")),this._normalMap&&(t.push("/nm"),this._normalMap.hasMatrix&&t.push("/mat")),this._alphaMap&&(t.push("/opm"),this._alphaMap.hasMatrix&&t.push("/mat")),t.push(";"),e.hash=t.join("")}set diffuse(e){let t=this._state.diffuse;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.diffuse=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}get diffuse(){return this._state.diffuse}get diffuseMap(){return this._diffuseMap}set specular(e){let t=this._state.specular;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.specular=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}get specular(){return this._state.specular}get specularMap(){return this._specularMap}get specularGlossinessMap(){return this._specularGlossinessMap}set glossiness(e){e=null!=e?e:1,this._state.glossiness!==e&&(this._state.glossiness=e,this.glRedraw())}get glossiness(){return this._state.glossiness}get glossinessMap(){return this._glossinessMap}set specularF0(e){e=null!=e?e:0,this._state.specularF0!==e&&(this._state.specularF0=e,this.glRedraw())}get specularF0(){return this._state.specularF0}set emissive(e){let t=this._state.emissive;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.emissive=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=0,t[1]=0,t[2]=0),this.glRedraw()}get emissive(){return this._state.emissive}get emissiveMap(){return this._emissiveMap}set alpha(e){e=null!=e?e:1,this._state.alpha!==e&&(this._state.alpha=e,this.glRedraw())}get alpha(){return this._state.alpha}get alphaMap(){return this._alphaMap}get normalMap(){return this._normalMap}get occlusionMap(){return this._occlusionMap}set alphaMode(e){let t=Ds[e=e||"opaque"];void 0===t&&(this.error("Unsupported value for 'alphaMode': "+e+" defaulting to 'opaque'"),t="opaque"),this._state.alphaMode!==t&&(this._state.alphaMode=t,this.glRedraw())}get alphaMode(){return ks[this._state.alphaMode]}set alphaCutoff(e){null==e&&(e=.5),this._state.alphaCutoff!==e&&(this._state.alphaCutoff=e)}get alphaCutoff(){return this._state.alphaCutoff}set backfaces(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}get backfaces(){return this._state.backfaces}set frontface(e){e="cw"!==e,this._state.frontface!==e&&(this._state.frontface=e,this.glRedraw())}get frontface(){return this._state.frontface?"ccw":"cw"}set lineWidth(e){this._state.lineWidth=e||1,this.glRedraw()}get lineWidth(){return this._state.lineWidth}set pointSize(e){this._state.pointSize=e||1,this.glRedraw()}get pointSize(){return this._state.pointSize}destroy(){super.destroy(),this._state.destroy()}}const Rs={default:{fill:!0,fillColor:[.4,.4,.4],fillAlpha:.2,edges:!0,edgeColor:[.2,.2,.2],edgeAlpha:.5,edgeWidth:1},defaultWhiteBG:{fill:!0,fillColor:[1,1,1],fillAlpha:.6,edgeColor:[.2,.2,.2],edgeAlpha:1,edgeWidth:1},defaultLightBG:{fill:!0,fillColor:[.4,.4,.4],fillAlpha:.2,edges:!0,edgeColor:[.2,.2,.2],edgeAlpha:.5,edgeWidth:1},defaultDarkBG:{fill:!0,fillColor:[.4,.4,.4],fillAlpha:.2,edges:!0,edgeColor:[.5,.5,.5],edgeAlpha:.5,edgeWidth:1},phosphorous:{fill:!0,fillColor:[0,0,0],fillAlpha:.4,edges:!0,edgeColor:[.9,.9,.9],edgeAlpha:.5,edgeWidth:2},sunset:{fill:!0,fillColor:[.9,.9,.6],fillAlpha:.2,edges:!0,edgeColor:[.9,.9,.9],edgeAlpha:.5,edgeWidth:1},vectorscope:{fill:!0,fillColor:[0,0,0],fillAlpha:.7,edges:!0,edgeColor:[.2,1,.2],edgeAlpha:1,edgeWidth:2},battlezone:{fill:!0,fillColor:[0,0,0],fillAlpha:1,edges:!0,edgeColor:[.2,1,.2],edgeAlpha:1,edgeWidth:3},sepia:{fill:!0,fillColor:[.970588207244873,.7965892553329468,.6660899519920349],fillAlpha:.4,edges:!0,edgeColor:[.529411792755127,.4577854573726654,.4100345969200134],edgeAlpha:1,edgeWidth:1},yellowHighlight:{fill:!0,fillColor:[1,1,0],fillAlpha:.5,edges:!0,edgeColor:[1,1,1],edgeAlpha:1,edgeWidth:1},greenSelected:{fill:!0,fillColor:[0,1,0],fillAlpha:.5,edges:!0,edgeColor:[1,1,1],edgeAlpha:1,edgeWidth:1},gamegrid:{fill:!0,fillColor:[.2,.2,.7],fillAlpha:.9,edges:!0,edgeColor:[.4,.4,1.6],edgeAlpha:.8,edgeWidth:3}};class Os extends hs{get type(){return"EmphasisMaterial"}get presets(){return Rs}constructor(e,t={}){super(e,t),this._state=new Se({type:"EmphasisMaterial",fill:null,fillColor:null,fillAlpha:null,edges:null,edgeColor:null,edgeAlpha:null,edgeWidth:null,backfaces:!0,glowThrough:!0}),this._preset="default",t.preset?(this.preset=t.preset,void 0!==t.fill&&(this.fill=t.fill),t.fillColor&&(this.fillColor=t.fillColor),void 0!==t.fillAlpha&&(this.fillAlpha=t.fillAlpha),void 0!==t.edges&&(this.edges=t.edges),t.edgeColor&&(this.edgeColor=t.edgeColor),void 0!==t.edgeAlpha&&(this.edgeAlpha=t.edgeAlpha),void 0!==t.edgeWidth&&(this.edgeWidth=t.edgeWidth),void 0!==t.backfaces&&(this.backfaces=t.backfaces),void 0!==t.glowThrough&&(this.glowThrough=t.glowThrough)):(this.fill=t.fill,this.fillColor=t.fillColor,this.fillAlpha=t.fillAlpha,this.edges=t.edges,this.edgeColor=t.edgeColor,this.edgeAlpha=t.edgeAlpha,this.edgeWidth=t.edgeWidth,this.backfaces=t.backfaces,this.glowThrough=t.glowThrough)}set fill(e){e=!1!==e,this._state.fill!==e&&(this._state.fill=e,this.glRedraw())}get fill(){return this._state.fill}set fillColor(e){let t=this._state.fillColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.fillColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.4,t[1]=.4,t[2]=.4),this.glRedraw()}get fillColor(){return this._state.fillColor}set fillAlpha(e){e=null!=e?e:.2,this._state.fillAlpha!==e&&(this._state.fillAlpha=e,this.glRedraw())}get fillAlpha(){return this._state.fillAlpha}set edges(e){e=!1!==e,this._state.edges!==e&&(this._state.edges=e,this.glRedraw())}get edges(){return this._state.edges}set edgeColor(e){let t=this._state.edgeColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.edgeColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}get edgeColor(){return this._state.edgeColor}set edgeAlpha(e){e=null!=e?e:.5,this._state.edgeAlpha!==e&&(this._state.edgeAlpha=e,this.glRedraw())}get edgeAlpha(){return this._state.edgeAlpha}set edgeWidth(e){this._state.edgeWidth=e||1,this.glRedraw()}get edgeWidth(){return this._state.edgeWidth}set backfaces(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}get backfaces(){return this._state.backfaces}set glowThrough(e){e=!1!==e,this._state.glowThrough!==e&&(this._state.glowThrough=e,this.glRedraw())}get glowThrough(){return this._state.glowThrough}set preset(e){if(console.warn("EmphasisMaterial.preset is deprecated and will be removed in future versions."),e=e||"default",this._preset===e)return;const t=Rs[e];t?(this.fill=t.fill,this.fillColor=t.fillColor,this.fillAlpha=t.fillAlpha,this.edges=t.edges,this.edgeColor=t.edgeColor,this.edgeAlpha=t.edgeAlpha,this.edgeWidth=t.edgeWidth,this.glowThrough=t.glowThrough,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(Rs).join(", "))}get preset(){return console.warn("EmphasisMaterial.preset is deprecated and will be removed in future versions."),this._preset}destroy(){super.destroy(),this._state.destroy()}}const Vs={default:{edgeColor:[0,0,0],edgeAlpha:1,edgeWidth:1},defaultWhiteBG:{edgeColor:[.2,.2,.2],edgeAlpha:1,edgeWidth:1},defaultLightBG:{edgeColor:[.2,.2,.2],edgeAlpha:1,edgeWidth:1},defaultDarkBG:{edgeColor:[.5,.5,.5],edgeAlpha:1,edgeWidth:1}};class Ls extends hs{get type(){return"EdgeMaterial"}get presets(){return Vs}constructor(e,t={}){super(e,t),this._state=new Se({type:"EdgeMaterial",edges:null,edgeColor:null,edgeAlpha:null,edgeWidth:null}),this._preset="default",t.preset?(this.preset=t.preset,t.edgeColor&&(this.edgeColor=t.edgeColor),void 0!==t.edgeAlpha&&(this.edgeAlpha=t.edgeAlpha),void 0!==t.edgeWidth&&(this.edgeWidth=t.edgeWidth)):(this.edgeColor=t.edgeColor,this.edgeAlpha=t.edgeAlpha,this.edgeWidth=t.edgeWidth),this.edges=!1!==t.edges}set edges(e){e=!1!==e,this._state.edges!==e&&(this._state.edges=e,this.glRedraw())}get edges(){return this._state.edges}set edgeColor(e){let t=this._state.edgeColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.edgeColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}get edgeColor(){return this._state.edgeColor}set edgeAlpha(e){e=null!=e?e:1,this._state.edgeAlpha!==e&&(this._state.edgeAlpha=e,this.glRedraw())}get edgeAlpha(){return this._state.edgeAlpha}set edgeWidth(e){this._state.edgeWidth=e||1,this.glRedraw()}get edgeWidth(){return this._state.edgeWidth}set preset(e){if(e=e||"default",this._preset===e)return;const t=Vs[e];t?(this.edgeColor=t.edgeColor,this.edgeAlpha=t.edgeAlpha,this.edgeWidth=t.edgeWidth,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(Vs).join(", "))}get preset(){return this._preset}destroy(){super.destroy(),this._state.destroy()}}class Hs extends Ae{get type(){return"Fresnel"}constructor(e,t={}){super(e,t),this._state=new Se({edgeColor:V.vec3([0,0,0]),centerColor:V.vec3([1,1,1]),edgeBias:0,centerBias:1,power:1}),this.edgeColor=t.edgeColor,this.centerColor=t.centerColor,this.edgeBias=t.edgeBias,this.centerBias=t.centerBias,this.power=t.power}set edgeColor(e){this._state.edgeColor.set(e||[0,0,0]),this.glRedraw()}get edgeColor(){return this._state.edgeColor}set centerColor(e){this._state.centerColor.set(e||[1,1,1]),this.glRedraw()}get centerColor(){return this._state.centerColor}set edgeBias(e){this._state.edgeBias=e||0,this.glRedraw()}get edgeBias(){return this._state.edgeBias}set centerBias(e){this._state.centerBias=null!=e?e:1,this.glRedraw()}get centerBias(){return this._state.centerBias}set power(e){this._state.power=null!=e?e:1,this.glRedraw()}get power(){return this._state.power}destroy(){super.destroy(),this._state.destroy()}}class Ns extends Ae{constructor(e,t={}){super(e,t),this._type=t.type||(t.src?t.src.split(".").pop():null)||"jpg",this._pos=V.vec3(t.pos||[0,0,0]),this._up=V.vec3(t.up||[0,1,0]),this._normal=V.vec3(t.normal||[0,0,1]),this._height=t.height||1,this._origin=V.vec3(),this._rtcPos=V.vec3(),this._imageSize=V.vec2(),this._texture=new Cs(this,{flipY:!0}),this._image=new Image,"jpg"!==this._type&&"png"!==this._type&&(this.error('Unsupported type - defaulting to "jpg"'),this._type="jpg"),this._node=new Bt(this,{matrix:V.inverseMat4(V.lookAtMat4v(this._pos,V.subVec3(this._pos,this._normal,V.mat4()),this._up,V.mat4())),children:[this._bitmapMesh=new as(this,{scale:[1,1,1],rotation:[-90,0,0],collidable:t.collidable,pickable:t.pickable,opacity:t.opacity,clippable:t.clippable,geometry:new We(this,st({center:[0,0,0],xSize:1,zSize:1,xSegments:2,zSegments:2})),material:new fs(this,{diffuse:[0,0,0],ambient:[0,0,0],specular:[0,0,0],diffuseMap:this._texture,emissiveMap:this._texture,backfaces:!0})})]}),t.image?this.image=t.image:t.src?this.src=t.src:t.imageData&&(this.imageData=t.imageData),this.scene._bitmapCreated(this)}set visible(e){this._bitmapMesh.visible=e}get visible(){return this._bitmapMesh.visible}set image(e){this._image=e,this._image&&(this._texture.image=this._image,this._imageSize[0]=this._image.width,this._imageSize[1]=this._image.height,this._updateBitmapMeshScale())}get image(){return this._image}set src(e){if(e){this._image.onload=()=>{this._texture.image=this._image,this._imageSize[0]=this._image.width,this._imageSize[1]=this._image.height,this._updateBitmapMeshScale()},this._image.src=e;switch(e.split(".").pop()){case"jpeg":case"jpg":this._type="jpg";break;case"png":this._type="png"}}}get src(){return this._image.src}set imageData(e){this._image.onload=()=>{this._texture.image=image,this._imageSize[0]=image.width,this._imageSize[1]=image.height,this._updateBitmapMeshScale()},this._image.src=e}get imageData(){const e=document.createElement("canvas"),t=e.getContext("2d");return e.width=this._image.width,e.height=this._image.height,t.drawImage(this._image,0,0),e.toDataURL("jpg"===this._type?"image/jpeg":"image/png")}set type(e){"png"===(e=e||"jpg")&&"jpg"===e||(this.error("Unsupported value for `type` - supported types are `jpg` and `png` - defaulting to `jpg`"),e="jpg"),this._type=e}get type(){return this._type}get pos(){return this._pos}get normal(){return this._normal}get up(){return this._up}set height(e){this._height=null==e?1:e,this._image&&this._updateBitmapMeshScale()}get height(){return this._height}set collidable(e){this._bitmapMesh.collidable=!1!==e}get collidable(){return this._bitmapMesh.collidable}set clippable(e){this._bitmapMesh.clippable=!1!==e}get clippable(){return this._bitmapMesh.clippable}set pickable(e){this._bitmapMesh.pickable=!1!==e}get pickable(){return this._bitmapMesh.pickable}set opacity(e){this._bitmapMesh.opacity=e}get opacity(){return this._bitmapMesh.opacity}destroy(){super.destroy(),this.scene._bitmapDestroyed(this)}_updateBitmapMeshScale(){const e=this._imageSize[1]/this._imageSize[0];this._bitmapMesh.scale=[this._height/e,1,this._height]}}const Gs=(e,t)=>{const i=[];let s=[];function r(e,i){let s,r;for(let n=0;n<3;n++)if(s=t[3*e+n],r=t[3*i+n],s!==r)return r-s;return 0}let n=e.slice().sort(r),A=null;for(let e=0,t=n.length;e<t;e++)0!==e&&0===r(n[e],n[e-1])||(A=n[e]),i[n[e]]=A;for(let t=0,r=e.length;t<r;t+=3){const r=i[e[t]],n=i[e[t+1]],A=i[e[t+2]];let o=r,a=n,l=A;if(r>n&&r>A?n>A?(o=r,a=n,l=A):(o=r,a=A,l=n):n>r&&n>A?r>A?(o=n,a=r,l=A):(o=n,a=A,l=r):A>r&&A>n&&(r>n?(o=A,a=r,l=n):(o=A,a=n,l=r)),s[t+0]=[o,a],s[t+1]=[a,l],o>l){const e=l;l=o,o=e}s[t+2]=[l,o]}function o(e,t){let i,s;for(let r=0;r<2;r++)if(i=e[r],s=t[r],s!==i)return s-i;return 0}s=s.slice(0,e.length),s.sort(o);let a=0;for(let e=0;e<s.length;e++)if(0===e||0!==o(s[e],s[e-1])){if(0!==e&&2!==a)return!1;a=1}else a++;return!(s.length>0&&2!==a)},js=V.vec3(),Ws=V.vec3(),zs=V.vec3();class Xs{constructor(){this.vertices=[],this.indices=[],this.reset()}reset(){this.lenVertices=0,this.lenIndices=0,this.primitive=null}setPrimitive(e){this.primitive=e}addVertex(e){this.vertices[this.lenVertices++]=e[0],this.vertices[this.lenVertices++]=e[1],this.vertices[this.lenVertices++]=e[2]}addIndex(e){this.indices[this.lenIndices++]=e}get volume(){const e=this.vertices,t=this.indices;if("solid"!==this.primitive&&"surface"!==this.primitive&&"triangles"!==this.primitive)return-1;if("solid"!==this.primitive&&!Gs(t,e))return-1;let i=0;for(let s=0;s<this.lenIndices;s+=3){const r=3*t[s],n=3*t[s+1],A=3*t[s+2];js[0]=e[r],js[1]=e[r+1],js[2]=e[r+2],Ws[0]=e[n],Ws[1]=e[n+1],Ws[2]=e[n+2],zs[0]=e[A],zs[1]=e[A+1],zs[2]=e[A+2],V.cross3Vec3(js,Ws,js),i+=V.dotVec3(js,zs)}return i/6}}const Ks=new Xs,Zs=V.vec3(),Js=V.vec3(),Ys=V.vec3(),$s=V.vec3(),qs=V.vec3(),er=V.vec3();class tr{constructor(){this.vertices=[],this.indices=[],this.reset()}reset(){this.lenVertices=0,this.lenIndices=0}addVertex(e){this.vertices[this.lenVertices++]=e[0],this.vertices[this.lenVertices++]=e[1],this.vertices[this.lenVertices++]=e[2]}addIndex(e){this.indices[this.lenIndices++]=e}get surfaceArea(){const e=this.vertices,t=this.indices;let i=0;for(let s=0;s<this.lenIndices;s+=3){const r=3*t[s],n=3*t[s+1],A=3*t[s+2];Zs[0]=e[r],Zs[1]=e[r+1],Zs[2]=e[r+2],Js[0]=e[n],Js[1]=e[n+1],Js[2]=e[n+2],Ys[0]=e[A],Ys[1]=e[A+1],Ys[2]=e[A+2],V.subVec3(Zs,Js,$s),V.subVec3(Ys,Js,qs),i+=.5*V.lenVec3(V.cross3Vec3($s,qs,er))}return i}}const ir=new tr,sr=V.OBB3(),rr=V.OBB3(),nr=V.OBB3();class Ar{constructor(e,t,i,s,r,n,A=null,o=0){this.model=e,this.object=null,this.parent=null,this.transform=r,this.textureSet=n,this._matrixDirty=!1,this._matrixUpdateScheduled=!1,this.id=t,this.obb=null,this._aabbLocal=null,this._aabbWorld=V.AABB3(),this._aabbWorldDirty=!1,this.layer=A,this.portionId=o,this._color=new Uint8Array([i[0],i[1],i[2],s]),this._colorize=new Uint8Array([i[0],i[1],i[2],s]),this._colorizing=!1,this._transparent=s<255,this.numTriangles=0,this.origin=null,this.entity=null,r&&r._addMesh(this),this._volume=null,this._surfaceArea=null}_sceneModelDirty(){this._aabbWorldDirty=!0,this.layer.aabbChanged()}_transformDirty(){this._matrixDirty||this._matrixUpdateScheduled||(this.model._meshMatrixDirty(this),this._matrixDirty=!0,this._matrixUpdateScheduled=!0),this._aabbWorldDirty=!0,this.layer.aabbChanged(),this.entity&&this.entity._transformDirty()}_updateMatrix(){this.transform&&this._matrixDirty&&this.layer.setMatrix(this.portionId,this.transform.worldMatrix),this._matrixDirty=!1,this._matrixUpdateScheduled=!1}_finalize(e){this.layer.initFlags(this.portionId,e,this._transparent)}_finalize2(){this.layer.flushInitFlags&&this.layer.flushInitFlags()}_setVisible(e){this.layer.setVisible(this.portionId,e,this._transparent)}_setColor(e){this._color[0]=e[0],this._color[1]=e[1],this._color[2]=e[2],this._colorizing||this.layer.setColor(this.portionId,this._color,!1)}_setColorize(e){e?(this._colorize[0]=e[0],this._colorize[1]=e[1],this._colorize[2]=e[2],this.layer.setColor(this.portionId,this._colorize,false),this._colorizing=!0):(this.layer.setColor(this.portionId,this._color,false),this._colorizing=!1)}_setOpacity(e,t){const i=e<255,s=this._transparent!==i;this._color[3]=e,this._colorize[3]=e,this._transparent=i,this._colorizing?this.layer.setColor(this.portionId,this._colorize):this.layer.setColor(this.portionId,this._color),s&&this.layer.setTransparent(this.portionId,t,i)}_setOffset(e){this.layer.setOffset(this.portionId,e)}_setHighlighted(e){this.layer.setHighlighted(this.portionId,e,this._transparent)}_setXRayed(e){this.layer.setXRayed(this.portionId,e,this._transparent)}_setSelected(e){this.layer.setSelected(this.portionId,e,this._transparent)}_setEdges(e){this.layer.setEdges(this.portionId,e,this._transparent)}_setClippable(e){this.layer.setClippable(this.portionId,e,this._transparent)}_setCollidable(e){this.layer.setCollidable(this.portionId,e)}_setPickable(e){this.layer.setPickable(this.portionId,e,this._transparent)}_setCulled(e){this.layer.setCulled(this.portionId,e,this._transparent)}canPickTriangle(){return!1}drawPickTriangles(e,t){}pickTriangleSurface(e){}precisionRayPickSurface(e,t,i,s){return this.layer.precisionRayPickSurface(this.portionId,e,t,i,s)}canPickWorldPos(){return!0}drawPickDepths(e){this.model.drawPickDepths(e)}drawPickNormals(e){this.model.drawPickNormals(e)}delegatePickedEntity(){return this.parent}getEachVertex(e){this.layer.getEachVertex&&this.layer.getEachVertex(this.portionId,e)}getEachIndex(e){this.layer.getEachIndex&&this.layer.getEachIndex(this.portionId,e)}isSolid(){return this.layer.solid}get volume(){if(null!==this._volume)return this._volume;switch(this.layer.primitive){case"solid":case"surface":case"triangles":Ks.reset(),Ks.setPrimitive(this.layer.primitive),this.getEachVertex((e=>{Ks.addVertex(e)})),this.getEachIndex((e=>{Ks.addIndex(e)})),this._volume=Ks.volume;break;default:this._volume=0}return this._volume}get surfaceArea(){if(null!==this._surfaceArea)return this._surfaceArea;switch(this.layer.primitive){case"solid":case"surface":case"triangles":ir.reset(),this.getEachVertex((e=>{ir.addVertex(e)})),this.getEachIndex((e=>{ir.addIndex(e)})),this._surfaceArea=ir.surfaceArea;break;default:this._surfaceArea=0}return this._surfaceArea}set aabb(e){if(this._aabbLocal=e,this.origin){this._aabbLocal=e.slice(0);const t=this.origin;this._aabbLocal[0]+=t[0],this._aabbLocal[1]+=t[1],this._aabbLocal[2]+=t[2],this._aabbLocal[3]+=t[0],this._aabbLocal[4]+=t[1],this._aabbLocal[5]+=t[2]}}get aabb(){return this._aabbWorldDirty&&(V.AABB3ToOBB3(this._aabbLocal,sr),this.transform?(V.transformOBB3(this.transform.worldMatrix,sr,rr),V.transformOBB3(this.model.worldMatrix,rr,nr),V.OBB3ToAABB3(nr,this._aabbWorld)):(V.transformOBB3(this.model.worldMatrix,sr,rr),V.OBB3ToAABB3(rr,this._aabbWorld)),this._aabbWorldDirty=!1),this._aabbWorld}_destroy(){this.model.scene._renderer.putPickID(this.pickId),this.layer=null}}const or=1,ar=4,lr=8,cr=16,hr=32,ur=256,dr=512,fr=1024,pr=2048,gr=function(e,t,i,s){const r=s&&e.createUniform("vec4","edgeColor",((e,t)=>e(t.legacyFrameCtx.programColor))),n=t.attributes.color,A=!s&&e.createVarying("vec4","vColor",(()=>`vec4(${n}.rgb * 0.5, ${n}.a)`)),o=e.createOutput("vec4","outColor");return{programName:s?"Edges":"EdgesColor",getLogDepth:i&&(e=>e),renderPassFlag:2,appendFragmentOutputs:e=>e.push(`${o} = ${r||A};`)}},mr=function(e,t){const i=e.createOutput("vec4","outColor");return{programName:"Occlusion",getLogDepth:!1,renderPassFlag:0,appendFragmentOutputs:e=>e.push(`${i} = vec4(0.0, 0.0, 1.0, 1.0);`)}},_r=function(e,t,i,s){const r=e.createUniform("vec4","silhouetteColor",((e,t)=>e(t.legacyFrameCtx.programColor))),n=e.createVarying("float","vAlpha",(()=>`${t.attributes.color}.a`)),A=e.createOutput("vec4","outColor");return{programName:"Silhouette",getLogDepth:i&&(e=>e),renderPassFlag:1,appendFragmentOutputs:(e,t,i,o)=>{e.push(`${A} = ${s?r:o(`vec4(${r}.rgb, min(${r}.a, ${n}))`)};`)}}},br=V.vec2(),Br=V.vec3(),yr=V.vec4(),wr=V.mat4(),vr=V.vec3([0,0,0]),Cr=0,Mr=1,Er=2,Fr=3,Ur=4,xr=5,Ir=6,Tr=7,Pr=8,Sr=9,Dr=10,kr=11,Qr=e=>[V.safeInv(e[0]),V.safeInv(e[1]),V.safeInv(e[2])],Rr=(e,t,i,s,r)=>{const n=!!(e&or),A=!!(e&ur),o=!!(e&dr),a=!!(e&fr),l=!!(e&pr),c=!!(e&lr),h=!!(e&ar);let u,d;u=!n||h||A||o&&!s.highlightMaterial.glowThrough||a&&!s.selectedMaterial.glowThrough?Cr:t?Er:Mr,d=!n||h?Cr:a?Ur:o?Fr:A?xr:Cr;let f=0;f=i&&n&&!h?a?Sr:o?Pr:A?Dr:l?t?Tr:Ir:Cr:Cr;const p=n&&!h&&c?kr:Cr;r[0]=u,r[1]=d,r[2]=f,r[3]=p},Or=function(){const e={};return function(t,i,s,r,n,A,o,a){const l=[i,"points"===s||"lines"===s?s:"triangles",!!r,!!n,!!A,!!o].join(":");l in e||(e[l]={});const c=e[l],h=t.id;if(!(h in c)){const e=t.canvas.gl,l=function(r,n,A){const o=function(){const A=Gi(),o=A.programVariables,l=a(o,n);return r(o,l.geometryParameters,(function(r,a){const c=t.pointsMaterial,h="points"===s&&!n,u=()=>[t._sectionPlanesState.getHash()].concat(h?[c.hash]:[]).concat(r.getHash?r.getHash():[]).join(";"),d=u(),f=()=>d===u(),p=l.geometryParameters,g=r.incrementDrawState,m=r.isShadowProgram,_=p.attributes,b=_.position.world,B="clipPos",[y,w]=A.buildProgram(e,i+" "+s+" "+r.programName,{appendFragmentOutputs:r.appendFragmentOutputs,cleanerEdges:r.cleanerEdges,clipPos:B,clippableTest:l.clippableTest,clippingCaps:r.clippingCaps,crossSections:t.crossSections,discardPoints:h&&c.roundPoints,getGammaFactor:t.gammaOutput&&(()=>t.gammaFactor),getLogDepth:r.getLogDepth,getPointSize:function(){const e=[];if(h){const t=o.createUniform("float","pointSize",(e=>e(c.pointSize)));if(c.perspectivePoints){const i=o.createUniform("float","nearPlaneHeight",((e,t)=>e(t.legacyFrameCtx.nearPlaneHeight))),s=`${Math.floor(c.minPerspectivePointSize)}.0`,r=`${Math.floor(c.maxPerspectivePointSize)}.0`;e.push(`clamp((${i} * ${t}) / gl_Position.w, ${s}, ${r})`)}else e.push(t)}else n&&n.vertices&&e.push("1.0");return r.incPointSizeBy10&&"points"===s&&e.push("10.0"),e.length>0&&(()=>e.join(" + "))}(),getVertexData:()=>{const e=_.color,t=_.flags[r.renderPassFlag],i=o.createUniform("int","renderPass",((e,t)=>e(t.renderPass))),n=[`if (${m?`(${t} <= 0) || (${e}.a < 1.0)`:`${t} != ${i}`}) {`,` gl_Position = vec4(${r.vertexCullX||0}, 0.0, 0.0, 0.0);`," return;","}"].concat(l.dontCullOnAlphaZero||r.dontCullOnAlphaZero?[]:[`if (${e}.a == 0.0) {`," gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"," return;","}"]).concat(r.filterIntensityRange&&"points"===s&&c.filterIntensity?function(){const t=o.createUniform("vec2","intensityRange",(e=>{br[0]=c.minIntensity,br[1]=c.maxIntensity,e(br)}));return[`if ((${e}.a < ${t}[0]) || (${e}.a > ${t}[1])) {`," gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"," return;","}"]}():[]),A=[];l.ensureColorAndFlagAvailable&&l.ensureColorAndFlagAvailable(A),n.forEach((e=>A.push(e))),l.appendVertexData(A);const a=p.attributes.position.view;return A.push(`vec4 ${a} = ${p.viewMatrix} * ${b};`),A.push(`vec4 clipPos = ${p.projMatrix} * ${a};`),A},projMatrix:p.projMatrix,sectionPlanesState:t._sectionPlanesState,testPerspectiveForGl_FragDepth:"points"!==s&&"lines"!==s||n,usePickClipPos:a,worldPositionAttribute:b});return w?(console.error(w),{getValid:f,destroy:()=>{},drawLayer:(e,t,i)=>{}}):{getValid:f,destroy:()=>y.destroy(),drawLayer:(e,t,i)=>{e.lastProgramId!==y.id&&(e.lastProgramId=y.id,y.bind());const s=t.origin,r=t.model,A=e.viewParams,o=Br;V.transformPoint3(r.matrix,s,o);const a=A.viewMatrix,c=A.projMatrix;e.snapPickOrigin&&(e.snapPickOrigin[0]=o[0],e.snapPickOrigin[1]=o[1],e.snapPickOrigin[2]=o[2]);const h={legacyFrameCtx:e,layerTextureSet:t.layerTextureSet,mesh:{layerIndex:t.layerIndex,origin:o,renderFlags:{sectionPlanesActivePerLayer:r.renderFlags.sectionPlanesActivePerLayer}},renderPass:i,view:{eye:A.eye,far:A.far,projMatrix:c,viewMatrix:V.compareVec3(o,vr)?a:wt(a,o,wr),viewNormalMatrix:A.viewNormalMatrix}};y.inputSetters.setUniforms(e,h),t.drawCalls[n?n.vertices?"drawVertices":"drawEdges":"drawSurface"](y.inputSetters.attributesHash,l.layerTypeInputs,{projMatrix:c,viewMatrix:V.compareVec3(o,vr)?a:wt(a,o,wr),viewNormalMatrix:A.viewNormalMatrix,eye:A.eye}),g&&e.drawElements++}}}))};let l=A&&o();return{drawLayer:(e,t,i)=>{l||(l=o()),l.drawLayer(e,t,i)},revalidate:e=>{!l||!e&&l.getValid()||(l.destroy(),l=A&&o())}}},u=(e,t)=>l(e,t,!0),d=(e,t)=>l(e,t,!1),f=(e,i,r,n)=>function(e,t,i,s,r,n){const A=e.createVarying("vec4","vColor",(()=>{const e=t.attributes,i="points"===n?`vec4(${e.color}.rgb, 1.0)`:`${e.color}`;return s?`vec4(${[s.getAmbientColor()].concat(s.directionalLights.map((i=>`max(dot(${e.normal.view}, ${i.getDirection(t.viewMatrix,e.position.view)}), 0.0) * ${i.getColor()}`))).join(" + ")}, 1) * ${i}`:i})),o=e.createOutput("vec4","outColor");return{programName:"Color",getHash:()=>[s?s.getHash():"-",r?"sao":"nosao"],cleanerEdges:!0,getLogDepth:i&&(e=>"points"!==n&&"lines"!==n?`${e} + length(vec2(dFdx(${e}), dFdy(${e})))`:e),renderPassFlag:0,appendFragmentOutputs:(e,t,i,s)=>{"points"===n||"lines"===n?e.push(`${o} = ${A};`):(e.push(`vec4 fragColor = ${s(A)};`),e.push(`${o} = ${r?`vec4(fragColor.rgb * ${r.getAmbient(i)}, fragColor.a)`:"fragColor"};`))},filterIntensityRange:!0,incrementDrawState:!0}}(e,i,t.logarithmicDepthBufferEnabled,r,n,s),p=(e,i,s)=>s(function(e,t,i){const s=e.createUniform("float","far",((e,t)=>e(t.legacyFrameCtx.viewParams.far))),r=e.createUniform("float","near",((e,t)=>e(t.legacyFrameCtx.viewParams.near))),n=e.createVarying("vec3","vViewPosition",(()=>`${t.attributes.position.view}.xyz`)),A=e.createOutput("vec4","outPackedDepth"),o=e.createFragmentDefinition("packDepth",((e,t)=>{t.push(`vec4 ${e}(const in float depth) {`),t.push(" const vec4 bitShift = vec4(256.0*256.0*256.0, 256.0*256.0, 256.0, 1.0);"),t.push(" const vec4 bitMask = vec4(0.0, 1.0/256.0, 1.0/256.0, 1.0/256.0);"),t.push(" vec4 res = fract(depth * bitShift);"),t.push(" res -= res.xxyz * bitMask;"),t.push(" return res;"),t.push("}")}));return{programName:"PickDepth",getLogDepth:i&&(e=>e),renderPassFlag:3,incPointSizeBy10:!0,appendFragmentOutputs:e=>{e.push(`float zNormalizedDepth = abs((${r} + ${n}.z) / (${s} - ${r}));`),e.push(`${A} = ${o}(zNormalizedDepth);`)}}}(e,i,t.logarithmicDepthBufferEnabled),!0),g=(e,i,s)=>s(function(e,t,i){const s=e.createVarying("vec4","vPickColor",(()=>`${t.attributes.pickColor} / 255.0`)),r=e.createOutput("vec4","outPickColor");return{programName:"PickMesh",getLogDepth:i&&(e=>e),renderPassFlag:3,incPointSizeBy10:!0,dontCullOnAlphaZero:!0,appendFragmentOutputs:e=>e.push(`${r} = ${s};`)}}(e,i,t.logarithmicDepthBufferEnabled),!0),m=(e,i,s,r)=>s(function(e,t,i,s){const r=e.createVarying("vec3","vWorldPosition",(()=>`${t.attributes.position.world}.xyz`)),n=e.createVarying("vec3","vWorldNormal",(()=>t.attributes.normal.world)),A=e.createOutput("highp ivec4","outNormal");return{programName:s?"PickNormalsFlat":"PickNormals",getLogDepth:i&&(e=>e),renderPassFlag:3,appendFragmentOutputs:e=>{const t=s?`normalize(cross(dFdx(${r}), dFdy(${r})))`:n;e.push(`${A} = ivec4(${t} * float(${V.MAX_INT}), 1.0);`)}}}(e,i,t.logarithmicDepthBufferEnabled,r),!0),_=(e,t,i,s,r)=>i(function(e,t,i,s){const r=e.createUniform("int","layerNumber",((e,t)=>e(t.legacyFrameCtx.snapPickLayerParams.length))),n=e.createUniform("vec3","coordinateScaler",((e,t)=>e(t.legacyFrameCtx.snapPickCoordinateScale))),A=e.createVarying("vec3","vWorldPosition",(()=>`${t.attributes.position.world}.xyz`)),o=e.createVarying("vec4","vPickColor",(()=>t.attributes.pickColor)),a=e.createOutput("highp ivec4","outCoords",0),l=e.createOutput("highp ivec4","outNormal",1),c=e.createOutput("lowp uvec4","outPickColor",2);return{programName:i?"SnapInit":"Snap",getLogDepth:e=>i?`${e} + length(vec2(dFdx(${e}), dFdy(${e})))`:e,renderPassFlag:3,vertexCullX:!i&&"2.0",dontCullOnAlphaZero:!i,appendFragmentOutputs:e=>{e.push(`${a} = ivec4(${A} * ${n}.xyz, ${i?"-":""}${r});`),i&&(e.push(`${l} = ${s?"ivec4(1.0)":`ivec4(normalize(cross(dFdx(${A}), dFdy(${A}))) * float(${V.MAX_INT}), 1.0)`};`),e.push(`${c} = uvec4(${o});`))}}}(e,t,s,r),!0);c[h]="points"===s?{colorRenderers:{"sao-":{vertex:d(((e,t,i)=>i(f(e,t,null,null))))}},occlusionRenderer:d(((e,i,s)=>s(mr(e,t.logarithmicDepthBufferEnabled)))),pickDepthRenderer:d(p),pickMeshRenderer:d(g),silhouetteRenderer:d(((e,i,s)=>s(_r(e,i,t.logarithmicDepthBufferEnabled,!0)))),snapInitRenderer:d(((e,t,i)=>_(e,t,i,!0,!0))),snapVertexRenderer:d(((e,t,i)=>_(e,t,i,!1,!0)),{vertices:!0})}:"lines"===s?{colorRenderers:{"sao-":{vertex:d(((e,t,i)=>i(f(e,t,null,null))))}},silhouetteRenderer:d(((e,i,s)=>s(_r(e,i,t.logarithmicDepthBufferEnabled,!0)))),snapInitRenderer:d(((e,t,i)=>_(e,t,i,!0,!1))),snapEdgeRenderer:d(((e,t,i)=>_(e,t,i,!1,!1)),{vertices:!1}),snapVertexRenderer:d(((e,t,i)=>_(e,t,i,!1,!1)),{vertices:!0})}:{colorRenderers:function(){const e=e=>ji(e,t._lightsState),i=e=>{const t=e.createUniform("vec4","uSAOParams",((e,t)=>e(t.legacyFrameCtx.saoParams))),i=Wi(e,"sampler2D","uOcclusionTexture",3e3,((e,t)=>e(t.legacyFrameCtx.occlusionTexture)));return{getAmbient:e=>{const s=`${t}.w`;return`(smoothstep(${`${t}.z`}, 1.0, dot(${i(`${e}.xy / ${t}.xy`)}, (255. / 256.) / vec4(256. * 256. * 256., 256. * 256., 256., 1.))) * ${s})`}}},s=function(s){const r=(r,n,A)=>function(e,t,i,s,r,n,A){const o=Wi(e,"sampler2D","uColorMap",3001,((e,t)=>{const i=t.layerTextureSet.colorTexture;i&&e(i.texture)})),a=n&&e.createUniform("float","materialAlphaCutoff",((e,t)=>e(t.layerTextureSet.alphaCutoff))),l=t.attributes,c=e.createVarying("vec3","vViewPosition",(()=>`${l.position.view}.xyz`)),h=e.createVarying("vec2","vUV",(()=>l.uv)),u=e.createVarying("vec4","vColor",(()=>l.color)),d=e.createOutput("vec4","outColor");return{programName:"ColorTexture",getHash:()=>[s.getHash(),r?"sao":"nosao",!!A,n?"alphaCutoffYes":"alphaCutoffNo"],getLogDepth:i.logarithmicDepthBufferEnabled&&(e=>e),renderPassFlag:0,appendFragmentOutputs:(e,i,n,A)=>{e.push(`vec3 viewNormal = normalize(cross(dFdx(${c}), dFdy(${c})));`),e.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),s.directionalLights.forEach((i=>{e.push(`reflectedColor += max(dot(viewNormal, ${i.getDirection(t.viewMatrix,c)}), 0.0) * ${i.getColor()};`)})),e.push(`vec4 color = vec4(${s.getAmbientColor()} + reflectedColor, 1) * ${A(u)};`),e.push(`vec4 sampleColor = ${o(h)};`),a&&e.push(`if (sampleColor.a < ${a}) { discard; }`),e.push("vec4 colorTexel = color * sampleColor;"),e.push(`${d} = vec4(colorTexel.rgb${r?" * "+r.getAmbient(n):""}, color.a);`),i&&e.push(`${d} = ${i(d)};`)},incrementDrawState:!0}}(r,n,t,e(r),s&&i(r),A,t.gammaOutput);return{PBR:n&&d(((r,n,A)=>A(function(e,t,i,s,r){const n=(t,i,s)=>Wi(e,"sampler2D",t,i?3001:3e3,((e,t)=>{const i=s(t.layerTextureSet);i&&e(i.texture)})),A=t.attributes,o=s.getIrradiance,a=n("uColorMap",!0,(e=>e.colorTexture)),l=n("uMetallicRoughMap",!1,(e=>e.metallicRoughnessTexture)),c=n("uEmissiveMap",!0,(e=>e.emissiveTexture)),h=n("uNormalMap",!1,(e=>e.normalsTexture)),u=n("uAOMap",!1,(e=>e.occlusionTexture)),d=e.createVarying("vec3","vViewPosition",(()=>`${A.position.view}.xyz`)),f=e.createVarying("vec3","vViewNormal",(()=>A.normal.view)),p=e.createVarying("vec4","vColor",(()=>A.color)),g=e.createVarying("vec2","vUV",(()=>A.uv)),m=e.createVarying("vec2","vMetallicRoughness",(()=>A.metallicRoughness)),_=e.createVarying("vec3","vWorldNormal",(()=>`${A.normal.world}.xyz`)),b=e.createOutput("vec4","outColor"),B=e.createFragmentDefinition("saturate",((e,t)=>t.push(`float ${e}(const in float a) { return clamp(a, 0.0, 1.0); }`))),y=e.createFragmentDefinition("BRDF_Specular_GGX",((e,t)=>{t.push("vec3 F_Schlick(const in vec3 specularColor, const in float dotLH) {"),t.push(" float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );"),t.push(" return ( 1.0 - specularColor ) * fresnel + specularColor;"),t.push("}"),t.push("float G_GGX_Smith(const in float alpha, const in float dotNL, const in float dotNV) {"),t.push(" float a2 = ( alpha * alpha );"),t.push(" float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),t.push(" float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),t.push(" return 1.0 / ( gl * gv );"),t.push("}"),t.push("float G_GGX_SmithCorrelated(const in float alpha, const in float dotNL, const in float dotNV) {"),t.push(" float a2 = ( alpha * alpha );"),t.push(" float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),t.push(" float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),t.push(" return 0.5 / max( gv + gl, 1e-6 );"),t.push("}"),t.push("float D_GGX(const in float alpha, const in float dotNH) {"),t.push(" float a2 = ( alpha * alpha );"),t.push(" float denom = ( dotNH * dotNH) * ( a2 - 1.0 ) + 1.0;"),t.push(" return 0.31830988618 * a2 / ( denom * denom);"),t.push("}"),t.push(`vec3 ${e}(const in vec3 incidentLightDirection, const in vec3 viewNormal, const in vec3 viewEyeDir, const in vec3 specularColor, const in float roughness) {`),t.push(" float alpha = ( roughness * roughness );"),t.push(" vec3 halfDir = normalize( incidentLightDirection + viewEyeDir );"),t.push(` float dotNL = ${B}( dot( viewNormal, incidentLightDirection ) );`),t.push(` float dotNV = ${B}( dot( viewNormal, viewEyeDir ) );`),t.push(` float dotNH = ${B}( dot( viewNormal, halfDir ) );`),t.push(` float dotLH = ${B}( dot( incidentLightDirection, halfDir ) );`),t.push(" vec3 F = F_Schlick( specularColor, dotLH );"),t.push(" float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );"),t.push(" float D = D_GGX( alpha, dotNH );"),t.push(" return F * (G * D);"),t.push("}")})),w=e.createFragmentDefinition("BRDF_Specular_GGX_Environment",((e,t)=>{t.push(`vec3 ${e}(const in vec3 viewNormal, const in vec3 viewEyeDir, const in vec3 specularColor, const in float roughness) {`),t.push(` float dotNV = ${B}(dot(viewNormal, viewEyeDir));`),t.push(" const vec4 c0 = vec4( -1, -0.0275, -0.572, 0.022);"),t.push(" const vec4 c1 = vec4( 1, 0.0425, 1.04, -0.04);"),t.push(" vec4 r = roughness * c0 + c1;"),t.push(" float a004 = min(r.x * r.x, exp2(-9.28 * dotNV)) * r.x + r.y;"),t.push(" vec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;"),t.push(" return specularColor * AB.x + AB.y;"),t.push("}")})),v=e.createFragmentDefinition("perturbNormal2Arb",((e,t)=>{t.push(`vec3 ${e}( vec3 eye_pos, vec3 surf_norm, vec2 uv, vec4 texel ) {`),t.push(" if (texel.r == 0.0 && texel.g == 0.0 && texel.b == 0.0) {"),t.push(" return surf_norm;"),t.push(" }"),t.push(" vec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );"),t.push(" vec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );"),t.push(" vec2 st0 = dFdx( uv.st );"),t.push(" vec2 st1 = dFdy( uv.st );"),t.push(" vec3 S = normalize( q0 * st1.t - q1 * st0.t );"),t.push(" vec3 T = normalize( -q0 * st1.s + q1 * st0.s );"),t.push(" vec3 N = normalize( surf_norm );"),t.push(" vec3 mapN = texel.xyz * 2.0 - 1.0;"),t.push(" mat3 tsn = mat3( S, T, N );"),t.push(" return normalize( tsn * mapN );"),t.push("}")}));return{programName:"PBR",getHash:()=>[s.getHash(),r?"sao":"nosao",!!i.gammaOutput],getLogDepth:i.logarithmicDepthBufferEnabled&&(e=>e),renderPassFlag:0,clippingCaps:i._sectionPlanesState.clippingCaps&&b,incrementDrawState:!0,appendFragmentOutputs:(e,i,n)=>{if(e.push("const float PI = 3.14159265359;"),e.push("vec3 reflDiff = vec3(0.0);"),e.push("vec3 reflSpec = vec3(0.0);"),e.push(`vec3 rgb = ${p}.rgb;`),e.push(`float opacity = ${p}.a;`),e.push("vec3 baseColor = rgb;"),e.push("float specularF0 = 1.0;"),e.push(`float metallic = float(${m}.r) / 255.0;`),e.push(`float roughness = float(${m}.g) / 255.0;`),e.push("float dielectricSpecular = 0.16 * specularF0 * specularF0;"),e.push(`vec4 colorTexel = ${a(g)};`),e.push("baseColor *= colorTexel.rgb;"),e.push(`vec3 metalRoughTexel = ${l(g)}.rgb;`),e.push("metallic *= metalRoughTexel.b;"),e.push("roughness *= metalRoughTexel.g;"),e.push("vec3 diffuseColor = baseColor * (1.0 - dielectricSpecular) * (1.0 - metallic);"),e.push("float specularRoughness = clamp(roughness, 0.04, 1.0);"),e.push("vec3 specularColor = mix(vec3(dielectricSpecular), baseColor, metallic);"),e.push(`vec3 viewNormal = -${v}(${d}, normalize(${f}), ${g}, ${h(g)});`),e.push(`vec3 viewEyeDir = normalize(${d});`),o&&e.push(`reflDiff += ${o(`normalize(${_})`)};`),s.getReflection){const i=`normalize((vec4(reflect(viewEyeDir, viewNormal), 0.0) * ${t.viewMatrix}).xyz)`,r="8.0",n=`0.5 * clamp(${r} - 0.79248 - 0.5 * log2(pow((2.0 / pow(specularRoughness + 0.0001, 2.0) - 2.0), 2.0) + 1.0), 0.0, ${r})`,A=s.getReflection(i,n),o=`${w}(viewNormal, viewEyeDir, specularColor, specularRoughness)`;e.push(`reflSpec += ${A} * ${o};`)}s.directionalLights.forEach(((i,s)=>{e.push(`vec3 lightDirection${s} = -${i.getDirection(t.viewMatrix,d)};`);const r=`${B}(dot(viewNormal, lightDirection${s}))`;e.push(`vec3 irradiance${s} = ${r} * ${i.getColor()};`),e.push(`reflDiff += irradiance${s};`),e.push(`reflSpec += irradiance${s} * PI * ${y}(lightDirection${s}, viewNormal, viewEyeDir, specularColor, specularRoughness);`)})),e.push(`vec3 emissiveColor = ${c(g)}.rgb;`),e.push(`float aoFactor = ${u(g)}.r;`);const A=`${s.getAmbientColor()} * baseColor * opacity * rgb`;e.push(`vec3 outgoingLight = emissiveColor + reflDiff * diffuseColor + reflSpec + ${A};`),e.push(`${b} = vec4(outgoingLight * aoFactor${r?` * ${r.getAmbient(n)}`:""}, opacity);`),i&&e.push(`${b} = ${i(b)};`)}}}(r,n,t,e(r),s&&i(r))))),texture:A&&{"alphaCutoff-":d(((e,t,i)=>i(r(e,t,!1)))),"alphaCutoff+":d(((e,t,i)=>i(r(e,t,!0))))},vertex:d(o?(t,r,n)=>n(f(t,r,e(t),s&&i(t))):(r,n,A)=>A(function(e,t,i,s,r){const n=t.attributes,A=e.createVarying("vec3","vViewPosition",(()=>`${n.position.view}.xyz`)),o=e.createVarying("vec4","vColor",(()=>n.color)),a=e.createOutput("vec4","outColor");return{programName:"FlatColor",getHash:()=>[s.getHash(),r?"sao":"nosao"],cleanerEdges:!0,getLogDepth:i&&(e=>e),renderPassFlag:0,appendFragmentOutputs:(e,i,n,l)=>{e.push(`vec3 viewNormal = normalize(cross(dFdx(${A}), dFdy(${A})));`);const c=[s.getAmbientColor()].concat(s.directionalLights.map((e=>`max(dot(viewNormal, ${e.getDirection(t.viewMatrix,A)}), 0.0) * ${e.getColor()}`)));e.push(`vec4 fragColor = vec4(${c.join(" + ")}, 1) * ${l(o)};`),e.push(`${a} = ${r?`vec4(fragColor.rgb * ${r.getAmbient(n)}, fragColor.a)`:"fragColor"};`)}}}(r,n,t.logarithmicDepthBufferEnabled,e(r),s&&i(r))))}};return{"sao-":s(!1),"sao+":r&&s(!0)}}(),depthRenderer:d(((e,i,s)=>s(function(e,t,i){const s=e.createVarying("highp vec2","vHighPrecisionZW",(()=>`${t.attributes.position.clip}.zw`)),r=e.createOutput("vec4","outColor");return{programName:"Depth",getLogDepth:i&&(e=>e),renderPassFlag:0,appendFragmentOutputs:e=>e.push(`${r} = vec4(vec3((1.0 - ${s}[0] / ${s}[1]) / 2.0), 1.0);`)}}(e,i,t.logarithmicDepthBufferEnabled)))),edgesRenderers:{uniform:d(((e,i,s)=>s(gr(e,i,t.logarithmicDepthBufferEnabled,!0))),{vertices:!1}),vertex:d(((e,i,s)=>s(gr(e,i,t.logarithmicDepthBufferEnabled,!1))),{vertices:!1})},occlusionRenderer:d(((e,i,s)=>s(mr(e,t.logarithmicDepthBufferEnabled)))),pickDepthRenderer:u(p),pickMeshRenderer:u(g),pickNormalsFlatRenderer:u(((e,t,i)=>m(e,t,i,!0))),pickNormalsRenderer:u(((e,t,i)=>m(e,t,i,!1))),shadowRenderer:d(((e,i,s)=>s(function(e,t){const i=e.createOutput("vec4","outColor"),s=e.createFragmentDefinition("encodeFloat",((e,t)=>{t.push(`vec4 ${e}(const in float v) {`),t.push(" const vec4 bitShift = vec4(256 * 256 * 256, 256 * 256, 256, 1.0);"),t.push(" const vec4 bitMask = vec4(0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0);"),t.push(" vec4 comp = fract(v * bitShift);"),t.push(" comp -= comp.xxyz * bitMask;"),t.push(" return comp;"),t.push("}")}));return{programName:"Shadow",getLogDepth:t&&(e=>e),renderPassFlag:0,isShadowProgram:!0,appendFragmentOutputs:(e,t,r)=>e.push(`${i} = ${s}(${r}.z);`)}}(e,t)))),silhouetteRenderer:u(((e,i,s)=>s(_r(e,i,t.logarithmicDepthBufferEnabled,!1)))),snapInitRenderer:u(((e,t,i)=>_(e,t,i,!0,!1))),snapEdgeRenderer:u(((e,t,i)=>_(e,t,i,!1,!1)),{vertices:!1}),snapVertexRenderer:u(((e,t,i)=>_(e,t,i,!1,!1)),{vertices:!0})};const b=e=>{!function t(i){i.revalidate?i.revalidate(e):Object.values(i).forEach((e=>e&&t(e)))}(c[h])},B=()=>b(!1);B(),t.on("compile",B),t.on("destroyed",(()=>{delete c[h]}))}return c[h]}}();class Vr{constructor(e,t,i){this.model=e,this.primitive=t,this.origin=i,this._meshes=[],this._aabb=V.collapseAABB3(),this._aabbDirty=!0}finalize(){if(!this._compiledPortions){this._compiledPortions=this.compilePortions(),this.solid=this._compiledPortions.solid,this.sortId=this._compiledPortions.sortId,this.layerTextureSet=this._compiledPortions.layerTextureSet,this.drawCalls=this._compiledPortions.drawCalls,this._renderers=this._compiledPortions.renderers,this._setFlags=this._compiledPortions.setFlags,this.setColor=this._compiledPortions.setColor,this.setMatrix=this._compiledPortions.setMatrix,this.setOffset=this._compiledPortions.setOffset,this.getEachIndex=this._compiledPortions.getEachIndex,this.getEachVertex=this._compiledPortions.getEachVertex,this.readGeometryData=this._compiledPortions.readGeometryData,this.precisionRayPickSurface=this._compiledPortions.precisionRayPickSurface,this._countsByFlag={};const e=(e,t)=>{const i={count:0,fromFlags:(s,r)=>{s&e?(i.count++,this.model[t]++):r||(i.count--,this.model[t]--)}};this._countsByFlag[e]=i};e(or,"numVisibleLayerPortions"),e(ar,"numCulledLayerPortions"),e(lr,"numPickableLayerPortions"),e(cr,"numClippableLayerPortions"),e(ur,"numXRayedLayerPortions"),e(dr,"numHighlightedLayerPortions"),e(fr,"numSelectedLayerPortions"),this._renderers.edgesRenderers&&e(pr,"numEdgesLayerPortions"),this._countsByFlagArr=Object.values(this._countsByFlag),this._numTransparentLayerPortions=0}}aabbChanged(){this._aabbDirty=!0}getAABB(){return this._aabbDirty&&(V.collapseAABB3(this._aabb),this._meshes.forEach((e=>V.expandAABB3(this._aabb,e.aabb))),this._aabbDirty=!1),this._aabb}__drawLayer(e,t,i,s){if(this._countsByFlag[ar].count<this._portions.length&&this._countsByFlag[or].count>0){const e="points"!==this.primitive&&"lines"!==this.primitive&&[Mr,Er,kr,Fr,Ur,xr];if(e&&e.includes(s)){const e=!0;if(t.backfaces!==e){const i=this.model.scene.canvas.gl;i.disable(i.CULL_FACE),t.backfaces=e}}t.textureUnit=0,i.drawLayer(t,this,s)}}__setVec4FromMaterialColorAlpha(e,t,i){return i[0]=e[0],i[1]=e[1],i[2]=e[2],i[3]=t,i}__drawColor(e,t,i){if((i?this._numTransparentLayerPortions<this._portions.length:this._numTransparentLayerPortions>0)&&this._countsByFlag[ur].count<this._portions.length){const s=i&&t.withSAO&&this._renderers.colorRenderers["sao+"]||this._renderers.colorRenderers["sao-"],r=t.pbrEnabled&&s.PBR?s.PBR:t.colorTextureEnabled&&s.texture?s.texture[this.layerTextureSet&&"number"==typeof this.layerTextureSet.alphaCutoff?"alphaCutoff+":"alphaCutoff-"]:s.vertex,n=i?Mr:Er;this.__drawLayer(e,t,r,n)}}drawColorOpaque(e,t){this.__drawColor(e,t,!0)}drawColorTransparent(e,t){this.__drawColor(e,t,!1)}drawDepth(e,t){const i=this._renderers.depthRenderer;i&&this._numTransparentLayerPortions<this._portions.length&&this._countsByFlag[ur].count<this._portions.length&&this.__drawLayer(e,t,i,Mr)}__drawSilhouette(e,t,i,s){t.programColor=this.__setVec4FromMaterialColorAlpha(i.fillColor,i.fillAlpha,yr),this.__drawLayer(e,t,this._renderers.silhouetteRenderer,s)}drawSilhouetteXRayed(e,t){this._countsByFlag[ur].count>0&&this.__drawSilhouette(e,t,this.model.scene.xrayMaterial,xr)}drawSilhouetteHighlighted(e,t){this._countsByFlag[dr].count>0&&this.__drawSilhouette(e,t,this.model.scene.highlightMaterial,Fr)}drawSilhouetteSelected(e,t){this._countsByFlag[fr].count>0&&this.__drawSilhouette(e,t,this.model.scene.selectedMaterial,Ur)}__drawVertexEdges(e,t,i){const s=this._renderers.edgesRenderers&&this._renderers.edgesRenderers.vertex;s&&this._countsByFlag[pr].count>0&&this.__drawLayer(e,t,s,i)}drawEdgesColorOpaque(e,t){this._compiledPortions.edgesColorOpaqueAllowed()&&this.__drawVertexEdges(e,t,Ir)}drawEdgesColorTransparent(e,t){this._numTransparentLayerPortions>0&&this.__drawVertexEdges(e,t,Tr)}__drawUniformEdges(e,t,i,s){const r=this._renderers.edgesRenderers&&this._renderers.edgesRenderers.uniform;r&&(t.programColor=this.__setVec4FromMaterialColorAlpha(i.edgeColor,i.edgeAlpha,yr),this.__drawLayer(e,t,r,s))}drawEdgesHighlighted(e,t){this._countsByFlag[dr].count>0&&this.__drawUniformEdges(e,t,this.model.scene.highlightMaterial,Pr)}drawEdgesSelected(e,t){this._countsByFlag[fr].count>0&&this.__drawUniformEdges(e,t,this.model.scene.selectedMaterial,Sr)}drawEdgesXRayed(e,t){this._countsByFlag[ur].count>0&&this.__drawUniformEdges(e,t,this.model.scene.xrayMaterial,Dr)}__drawPick(e,t,i){i&&this.__drawLayer(e,t,i,kr)}drawPickMesh(e,t){this.__drawPick(e,t,this._renderers.pickMeshRenderer)}drawPickDepths(e,t){this.__drawPick(e,t,this._renderers.pickDepthRenderer)}drawPickNormals(e,t){const i=this._renderers.pickNormalsFlatRenderer;this.__drawPick(e,t,i)}drawSnap(e,t,i){t.snapPickOrigin=[0,0,0];const s=this.getAABB();t.snapPickCoordinateScale=V.mulVec3Scalar(Qr([s[3]-s[0],s[4]-s[1],s[5]-s[2]]),V.MAX_INT);const r=i?this._renderers.snapInitRenderer:"edge"===t.snapMode?this._renderers.snapEdgeRenderer:this._renderers.snapVertexRenderer;this.__drawPick(e,t,r),t.snapPickLayerParams.push({origin:t.snapPickOrigin.slice(),coordinateScale:Qr(t.snapPickCoordinateScale)})}drawOcclusion(e,t){const i=this._renderers.occlusionRenderer;i&&this.__drawLayer(e,t,i,Mr)}drawShadow(e,t){const i=this._renderers.shadowRenderer;i&&this.__drawLayer(e,t,i,Mr)}initFlags(e,t,i){this._countsByFlagArr.forEach((e=>e.fromFlags(t,!0))),i&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++);const s="points"!==this.primitive;this._setFlags(e,t,i,s),this._compiledPortions.setFlags2(e,t,s)}flushInitFlags(){this._compiledPortions.setDeferredFlags()}setVisible(e,t,i){this._countsByFlag[or].fromFlags(t),this._setFlags(e,t,i)}setCulled(e,t,i){this._countsByFlag[ar].fromFlags(t),this._setFlags(e,t,i)}setPickable(e,t,i){this._countsByFlag[lr].fromFlags(t),this._setFlags(e,t,i)}setClippable(e,t){this._countsByFlag[cr].fromFlags(t),this._compiledPortions.setClippableFlags(e,t)}setCollidable(e,t){}setXRayed(e,t,i){this._countsByFlag[ur].fromFlags(t),this._setFlags(e,t,i)}setHighlighted(e,t,i){this._countsByFlag[dr].fromFlags(t),this._setFlags(e,t,i)}setSelected(e,t,i){this._countsByFlag[fr].fromFlags(t),this._setFlags(e,t,i)}setEdges(e,t,i){this._countsByFlag[pr]&&(this._countsByFlag[pr].fromFlags(t),this._setFlags(e,t,i))}setTransparent(e,t,i){i?(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++):(this._numTransparentLayerPortions--,this.model.numTransparentLayerPortions--),this._setFlags(e,t,i)}destroy(){this._compiledPortions&&this._compiledPortions.destroy()}}let Lr=65536,Hr=5e6;class Nr{constructor(){}set doublePrecisionEnabled(e){V.setDoublePrecisionEnabled(e)}get doublePrecisionEnabled(){return V.getDoublePrecisionEnabled()}set maxDataTextureHeight(e){(e=1024*Math.ceil(e/1024))>4096?e=4096:e<1024&&(e=1024),Lr=e}get maxDataTextureHeight(){return Lr}set maxGeometryBatchSize(e){e<1e5?e=1e5:e>5e6&&(e=5e6),Hr=e}get maxGeometryBatchSize(){return Hr}}const Gr=e=>{const t=[];for(let i=0;i<e;++i)t.push(i);return t},jr={sizeDataColorsAndFlags:0,sizeDataInstancesMatrices:0,sizeDataPositionDecodeMatrices:0,sizeDataTextureOffsets:0,sizeDataTexturePositions:0,sizeDataTextureIndices:0,sizeDataTextureEdgeIndices:0,sizeDataTexturePortionIds:0,numberOfGeometries:0,numberOfPortions:0,numberOfLayers:0,numberOfTextures:0,totalPolygons:0,totalPolygons8Bits:0,totalPolygons16Bits:0,totalPolygons32Bits:0,totalEdges:0,totalEdges8Bits:0,totalEdges16Bits:0,totalEdges32Bits:0,cannotCreatePortion:{because10BitsObjectId:0,becauseTextureSize:0},overheadSizeAlignementIndices:0,overheadSizeAlignementEdgeIndices:0};window.printDataTextureRamStats=function(){console.log(JSON.stringify(jr,null,4));let e=0;Object.keys(jr).forEach((t=>{t.startsWith("size")&&(e+=jr[t])})),console.log(`Total size ${e} bytes (${(e/1e3/1e3).toFixed(2)} MB)`),console.log(`Avg bytes / triangle: ${(e/jr.totalPolygons).toFixed(2)}`);let t={};Object.keys(jr).forEach((i=>{i.startsWith("size")&&(t[i]=`${(jr[i]/e*100).toFixed(2)} % of total`)})),console.log(JSON.stringify({percentualRamUsage:t},null,4))};const Wr=new Nr,zr=Wr.maxDataTextureHeight,Xr=V.vec3(),Kr=V.vec3(),Zr=V.vec4();V.vec4();const Jr=new Float32Array(16),Yr=new Uint8Array(4),$r=V.identityMat4();class qr extends Vr{constructor(e,t,i){super(e,t,i),jr.numberOfLayers++,this._sortId=`TriDTX-${jr.numberOfLayers}`;const s=e.scene.canvas.gl,r=(e,t)=>{const i=[];let r=0;const A=[];let o=0;const a=[];let l=0;const c=[];let h=0;return{len:()=>o,accumulateIndices:(s,u)=>{const d=s&&s.length>0&&function(){const t=r/3;r+=s.length,i.push(s);const a=s.length/3;return i=>{const s=o;o+=3*a,n.perObjectIndexBaseOffsets.push(s/3-t);for(let e=0;e<a;e+=8)A.push(i);jr[e]+=a,jr.totalPolygons+=a}}(),f=u&&function(){const e=l/2;l+=u.length,a.push(u);const i=u.length/2;return s=>{const r=h;h+=2*i,n.perObjectEdgeIndexBaseOffsets.push(r/2-e);for(let e=0;e<i;e+=8)c.push(s);jr[t]+=i,jr.totalEdges+=i}}();return jr.numberOfGeometries++,{numTriangles:s?s.length/3:0,accumulateSubPortionId:e=>{d&&d(e),f&&f(e)}}},createDrawers:(e,t)=>{const n=function(t,i){return t.length>0?e([t],t.length,1,s.UNSIGNED_SHORT,"sizeDataTexturePortionIds"):i},u=n(A,{texture:null}),d=r>0&&e(i,r,3,t,"sizeDataTextureIndices"),f=n(c),p=l>0&&e(a,l,2,t,"sizeDataTextureEdgeIndices");return{indices:function(e,t){o>0&&(e.perPrimIndices.setInputValue(d),e.perPrimIdPorIds.setInputValue(u),s.drawArrays(t,0,o))},edges:function(e,t){h>0&&(e.perPrimIndices.setInputValue(p),e.perPrimIdPorIds.setInputValue(f),s.drawArrays(t,0,h))}}}}},n=this._buffer={positionsCompressed:[],lenPositionsCompressed:0,geometry8Bits:r("totalPolygons8Bits","totalEdges8Bits"),geometry16Bits:r("totalPolygons16Bits","totalEdges16Bits"),geometry32Bits:r("totalPolygons32Bits","totalEdges32Bits"),perObjectColors:[],perObjectPickColors:[],perObjectSolid:[],perObjectPositionsDecodeMatrices:[],perObjectInstancePositioningMatrices:[],perObjectVertexBases:[],perObjectIndexBaseOffsets:[],perObjectEdgeIndexBaseOffsets:[]};this._numVertices=0,this._portions=[],this._subPortionReadableGeometries=this.model.scene.readableGeometryEnabled&&{},this._portionToSubPortionsMap=[],this._bucketGeometries={},this._primitive=t}canCreatePortion(e){const t=e.buckets.length;this._portions.length+t>65536&&jr.cannotCreatePortion.because10BitsObjectId++;let i=this._portions.length+t<=65536;const s=void 0!==e.geometryId&&null!==e.geometryId?`${e.geometryId}#0`:`${e.id}#0`;if(!this._bucketGeometries[s]){const t=this._buffer,s=Math.max(t.geometry8Bits.len(),t.geometry16Bits.len(),t.geometry32Bits.len());let r=0,n=0;e.buckets.forEach((e=>{r+=e.positionsCompressed.length/3,n+=e.indices.length/3})),(this._numVertices+r>4096*zr||s+n>4096*zr)&&jr.cannotCreatePortion.becauseTextureSize++,i&&=this._numVertices+r<=4096*zr&&s+n<=4096*zr}return i}createPortion(e,t){const i=this._buffer,s=t.buckets.map(((e,s)=>{const r=(t.geometryId??t.id)+"#"+s;if(!(r in this._bucketGeometries)){const t=(e,t,i)=>{if(e){const s=8*Math.ceil(e.length/t/8)*t,r=new Uint32Array(s);return r.set(e),jr[i]+=2*(r.length-e.length),r}return e};e.indices=t(e.indices,3,"overheadSizeAlignementIndices"),e.edgeIndices=t(e.edgeIndices,2,"overheadSizeAlignementEdgeIndices");const s=e.positionsCompressed;i.positionsCompressed.push(s);const n=s.length/3;this._numVertices+=n;const A=i.lenPositionsCompressed/3;i.lenPositionsCompressed+=s.length,this._bucketGeometries[r]={vertexBase:A,geometryData:function(){const t=e.indices,s=e.edgeIndices;return n<=256?i.geometry8Bits.accumulateIndices(t,s):n<=65536?i.geometry16Bits.accumulateIndices(t,s):i.geometry32Bits.accumulateIndices(t,s)}()}}const n=this._bucketGeometries[r];i.perObjectPositionsDecodeMatrices.push(t.positionsDecodeMatrix),i.perObjectInstancePositioningMatrices.push(t.meshMatrix||$r),i.perObjectSolid.push(!!t.solid),i.perObjectPickColors.push(t.pickColor),i.perObjectVertexBases.push(n.vertexBase);const A=t.colors,o=t.color;i.perObjectColors.push(A?[255*A[0],255*A[1],255*A[2],255]:[o[0],o[1],o[2],t.opacity]);const a=this._portions.length;return this._portions.push({}),n.geometryData.accumulateSubPortionId(a),this._subPortionReadableGeometries&&(this._subPortionReadableGeometries[a]={indices:e.indices,positionsCompressed:e.positionsCompressed,positionsDecodeMatrix:t.positionsDecodeMatrix}),jr.numberOfPortions++,a})),r=this._portionToSubPortionsMap.length;return this._portionToSubPortionsMap.push(s),this.model.numPortions++,this._meshes.push(e),r}compilePortions(){const e=this._buffer,t=this.model,i=this._portions.length,s=this.origin,r=this._portionToSubPortionsMap,n=this._primitive,A=this._sortId,o=this._subPortionReadableGeometries,a=t.scene,l=a.canvas.gl,c=en(l,i,32,l.UNSIGNED_BYTE,512,(t=>{const s=e=>[e>>24&255,e>>16&255,e>>8&255,255&e];for(let r=0;r<i;r++)t.set(e.perObjectColors[r],32*r+0),t.set(e.perObjectPickColors[r],32*r+4),t.set([0,0,0,0],32*r+8),t.set([0,0,0,0],32*r+12),t.set(s(e.perObjectVertexBases[r]),32*r+16),t.set(s(e.perObjectIndexBaseOffsets[r]),32*r+20),t.set(s(e.perObjectEdgeIndexBaseOffsets[r]),32*r+24),t.set([e.perObjectSolid[r]?1:0,0,0,0],32*r+28)}),"sizeDataColorsAndFlags",!0),h=c.textureData,u=function(e,t,i,s,r,n,A){return en(l,t,i,s,r,(t=>{for(let i=0,s=0,r=e.length;i<r;i++){const r=e[i];t.set(r,s),s+=r.length}}),n,A)},d=function(e,t,i){const s=e.length;if(0===s)throw"num "+t+" matrices===0";return u(e,s,16,l.FLOAT,512,t,i)},f=d(e.perObjectInstancePositioningMatrices,"sizeDataInstancesMatrices",!0),p=f.textureData,g=d(e.perObjectPositionsDecodeMatrices,"sizeDataPositionDecodeMatrices",!1),m=function(e,t,i,s,r){return u(e,t/i,i,s,4096,r,!1)},_=m(e.positionsCompressed,e.lenPositionsCompressed,3,l.UNSIGNED_SHORT,"sizeDataTexturePositions"),b=e.geometry8Bits.createDrawers(m,l.UNSIGNED_BYTE),B=e.geometry16Bits.createDrawers(m,l.UNSIGNED_SHORT),y=e.geometry32Bits.createDrawers(m,l.UNSIGNED_INT);this._buffer=null;let w=!1,v=!1,C=!1,M=0;const E=()=>{w=!0},F=a.on("rendering",(()=>{v&&(w=!1,v=!1,h.reloadData()),M=0})),U=(e,i)=>{const s=r[e];if(s)for(let e=0,t=s.length;e<t;e++)i(s[e]);else t.error("portion not found: "+e)},x=(e,t,i,s)=>{const r=w||s;r?v=!0:++M>=10&&E(),h.setData(i,e,t,!r)},I=(e,t,i=!1)=>{Yr.set([t&cr?255:0,0,1,2]),U(e,(e=>x(e,3,Yr,i)))};return{edgesColorOpaqueAllowed:()=>!a.logarithmicDepthBufferEnabled||(a._loggedWarning||(console.log("Edge enhancement for SceneModel data texture layers currently disabled with logarithmic depth buffer"),a._loggedWarning=!0),!1),sortId:A,setClippableFlags:I,setFlags:(e,t,i,s=!1)=>{Rr(t,i,!0,a,Yr),U(e,(e=>x(e,2,Yr,s)))},setFlags2:I,setDeferredFlags:()=>{},setColor:(e,t)=>{Yr.set(t),U(e,(e=>x(e,0,Yr,!1)))},setMatrix:(e,t)=>{U(e,(e=>{const i=w;i?v=!0:++M>=10&&E(),Jr.set(t),p.setData(Jr,e,0,!i)}))},setOffset:(e,t)=>{},getEachIndex:(e,t)=>{o&&U(e,(e=>o[e].indices.forEach((e=>t(e)))))},getEachVertex:(e,i)=>{o&&U(e,(e=>{const r=o[e],n=r.positionsCompressed,A=r.positionsDecodeMatrix,a=Zr;for(let e=0,r=n.length;e<r;e+=3)a[0]=n[e],a[1]=n[e+1],a[2]=n[e+2],a[3]=1,V.decompressPosition(a,A),V.mulMat4v4(t.worldMatrix,a,a),V.addVec3(s,a,a),i(a)}))},precisionRayPickSurface:(e,t,i,s,r)=>!1,renderers:Or(a,"dtx",n,t.saoEnabled,!1,!1,!0,((e,t)=>tn(e,!t))),drawCalls:function(){const e=function(e){const i=(e,t)=>e.setInputValue&&e.setInputValue(t);return(r,n,A)=>{i(n.worldMatrix,t.rotationMatrix),i(n.viewMatrix,A.viewMatrix),i(n.projMatrix,A.projMatrix);const o=V.transformPoint3(t.matrix,s,Xr);i(n.uCameraEyeRtc,V.subVec3(A.eye,o,Kr)),i(n.perObjPosDecode,g),i(n.perVertIdCoords,_),i(n.perObjColsFlags,c),i(n.perObjectMatrix,f),e(n)}},i=function(t){return e((e=>{b.edges(e,t),B.edges(e,t),y.edges(e,t)}))};return{drawVertices:i(l.POINTS),drawEdges:i(l.LINES),drawSurface:e((e=>{const t=l.TRIANGLES;b.indices(e,t),B.indices(e,t),y.indices(e,t)}))}}(),destroy:()=>{C||(a.off(F),C=!0)}}}}const en=function(e,t,i,s,r,n,A,o){if(i>4&&i%4>0)throw"Unhandled data size "+i;const a=Math.ceil(i/4),l=i/a,[c,h,u]=function(){switch(s){case e.UNSIGNED_BYTE:return[Uint8Array,...1===l?[e.R8UI,e.RED_INTEGER]:2===l?[e.RG8UI,e.RG_INTEGER]:3===l?[e.RGB8UI,e.RGB_INTEGER]:[e.RGBA8UI,e.RGBA_INTEGER]];case e.UNSIGNED_SHORT:return[Uint16Array,...1===l?[e.R16UI,e.RED_INTEGER]:2===l?[e.RG16UI,e.RG_INTEGER]:3===l?[e.RGB16UI,e.RGB_INTEGER]:[e.RGBA16UI,e.RGBA_INTEGER]];case e.UNSIGNED_INT:return[Uint32Array,...1===l?[e.R32UI,e.RED_INTEGER]:2===l?[e.RG32UI,e.RG_INTEGER]:3===l?[e.RGB32UI,e.RGB_INTEGER]:[e.RGBA32UI,e.RGBA_INTEGER]];case e.FLOAT:return[Float32Array,...1===l?[e.R32F,e.RED]:2===l?[e.RG32F,e.RG]:3===l?[e.RGB32F,e.RGB]:[e.RGBA32F,e.RGBA]];default:throw"Unhandled data type "+s}}(),d=r*a,f=Math.ceil(t/r);if(0===f)throw"texture height===0";const p=new c(d*f*l);jr[A]+=p.byteLength,jr.numberOfTextures++,n(p);const g=e.createTexture();return e.bindTexture(e.TEXTURE_2D,g),e.texStorage2D(e.TEXTURE_2D,1,h,d,f),e.texSubImage2D(e.TEXTURE_2D,0,0,0,d,f,u,s,p),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.bindTexture(e.TEXTURE_2D,null),{bind:t=>(e.activeTexture(e["TEXTURE"+t]),e.bindTexture(e.TEXTURE_2D,g),!0),unbind(e){},textureData:o&&{setData(t,n,A=0,o=!1){if(p.set(t,n*i+A*l),o){e.bindTexture(e.TEXTURE_2D,g);const i=n%r*a+A,o=Math.floor(n/r),c=t.length/l;e.texSubImage2D(e.TEXTURE_2D,0,i,o,c,1,u,s,t)}},reloadData(){e.bindTexture(e.TEXTURE_2D,g),e.texSubImage2D(e.TEXTURE_2D,0,0,0,d,f,u,s,p)}}}},tn=function(e,t){const i=(t,i)=>{const s=e.createUniform(t,i),r=e=>`texelFetch(${s}, ${e}, 0)`;return r.map=s,r},s=i("highp usampler2D","perPrimIndices"),r=i("mediump usampler2D","perPrimIdPorIds"),n=i("highp sampler2D","perObjPosDecode"),A=i("mediump usampler2D","perVertIdCoords"),o=i("lowp usampler2D","perObjColsFlags"),a=i("highp sampler2D","perObjectMatrix"),l=e.createUniform("mat4","worldMatrix"),c=e.createUniform("mat4","viewMatrix"),h=e.createUniform("mat4","projMatrix"),u=e.createUniform("vec3","uCameraEyeRtc"),d=function(e){const t={toString:()=>(t.needed=!0,e)};return t},f=d("colorA"),p=d("pickColor"),g=d("worldNormal"),m=d("viewNormal"),_=e=>o(`ivec2(objectIndexCoords.x*8+${e}, objectIndexCoords.y)`);return{clippableTest:function(){const t=e.createVarying("uint","vClippable",(()=>"flags2.r"),"flat");return()=>`${t} > 0u`}(),geometryParameters:{attributes:{color:f,flags:Gr(4).map((e=>`int(flags[${e}])`)),metallicRoughness:null,normal:{view:m,world:g},pickColor:p,position:{clip:"gl_Position",view:"viewPosition",world:"worldPosition"},uv:null},projMatrix:h,viewMatrix:c},ensureColorAndFlagAvailable:e=>{e.push("int primitiveIndex = gl_VertexID / "+(t?3:2)+";"),e.push("int h_packed_object_id_index = (primitiveIndex >> 3) & 4095;"),e.push("int v_packed_object_id_index = (primitiveIndex >> 3) >> 12;"),e.push(`int objectIndex = int(${r("ivec2(h_packed_object_id_index, v_packed_object_id_index)")}.r);`),e.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),e.push(`uvec4 flags = ${_(2)};`),e.push(`uvec4 flags2 = ${_(3)};`),f.needed&&e.push(`vec4 ${f} = vec4(${_(0)}) / 255.0;`)},appendVertexData:e=>{const i=e=>a(`ivec2(objectIndexCoords.x*4+${e}, objectIndexCoords.y)`);e.push(`mat4 objectInstanceMatrix = mat4(${i(0)}, ${i(1)}, ${i(2)}, ${i(3)});`);const r=e=>n(`ivec2(objectIndexCoords.x*4+${e}, objectIndexCoords.y)`);if(e.push(`mat4 objectDecodeAndInstanceMatrix = objectInstanceMatrix * mat4(${r(0)}, ${r(1)}, ${r(2)}, ${r(3)});`),e.push(`ivec4 packedVertexBase = ivec4(${_(4)});`),e.push(`ivec4 packedIndexBaseOffset = ivec4(${_(t?5:6)});`),e.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),e.push("int h_index = (primitiveIndex - indexBaseOffset) & 4095;"),e.push("int v_index = (primitiveIndex - indexBaseOffset) >> 12;"),e.push(`ivec3 vertexIndices = ivec3(${s("ivec2(h_index, v_index)")});`),e.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),t){e.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),e.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),e.push(`uint solid = ${_(7)}.r;`);const t=e=>`vec3(${A(`ivec2(indexPositionH[${e}], indexPositionV[${e}])`)})`;e.push(`vec3 positions[] = vec3[](${t(0)}, ${t(1)}, ${t(2)});`),e.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),e.push("vec3 position = positions[gl_VertexID % 3];"),g.needed&&e.push(`vec3 worldNormal = -normalize((transpose(inverse(${l} * objectDecodeAndInstanceMatrix)) * vec4(normal,1)).xyz);`),m.needed&&e.push(`vec3 viewNormal = -normalize((transpose(inverse(${c} * objectDecodeAndInstanceMatrix)) * vec4(normal,1)).xyz);`),e.push("if (solid != 1u) {"),e.push(` if (${o=h,`(${o}[2][3] == - 1.0)`}) {`),e.push(` vec3 uCameraEyeRtcInQuantizedSpace = (inverse(${l} * objectDecodeAndInstanceMatrix) * vec4(${u}, 1)).xyz;`),e.push(" if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),e.push(" position = positions[2 - (gl_VertexID % 3)];"),g.needed&&e.push(" worldNormal = -worldNormal;"),m.needed&&e.push(" viewNormal = -viewNormal;"),e.push(" }"),e.push(" } else {"),m.needed||e.push(` vec3 viewNormal = -normalize((transpose(inverse(${c} * objectDecodeAndInstanceMatrix)) * vec4(normal,1)).xyz);`),e.push(" if (viewNormal.z < 0.0) {"),e.push(" position = positions[2 - (gl_VertexID % 3)];"),g.needed&&e.push(" worldNormal = -worldNormal;"),m.needed&&e.push(" viewNormal = -viewNormal;"),e.push(" }"),e.push(" }"),e.push("}")}else e.push("int indexPositionH = uniqueVertexIndexes[gl_VertexID % 2] & 4095;"),e.push("int indexPositionV = uniqueVertexIndexes[gl_VertexID % 2] >> 12;"),e.push(`vec3 position = vec3(${A("ivec2(indexPositionH, indexPositionV)")});`);var o;p.needed&&e.push(`vec4 pickColor = vec4(${_(1)});`),e.push(`vec4 worldPosition = ${l} * (objectDecodeAndInstanceMatrix * vec4(position, 1.0));`)},layerTypeInputs:{perPrimIndices:s.map,perPrimIdPorIds:r.map,perObjPosDecode:n.map,perVertIdCoords:A.map,perObjColsFlags:o.map,perObjectMatrix:a.map,worldMatrix:l,viewMatrix:c,projMatrix:h,uCameraEyeRtc:u}}},sn=V.mat4(),rn=V.mat4();function nn(e,t,i){const s=e.length,r=new Uint16Array(s),n=t[0],A=t[1],o=t[2],a=t[3]-n||1,l=t[4]-A||1,c=t[5]-o||1,h=65525,u=h/a,d=h/l,f=h/c,p=e=>e>=0?e:0;for(let t=0;t<s;t+=3)r[t+0]=Math.floor(p(e[t+0]-n)*u),r[t+1]=Math.floor(p(e[t+1]-A)*d),r[t+2]=Math.floor(p(e[t+2]-o)*f);return V.identityMat4(sn),V.translationMat4v(t,sn),V.identityMat4(rn),V.scalingMat4v([a/h,l/h,c/h],rn),V.mulMat4(sn,rn,i),r}function An(e,t){const i=e[0],s=e[1],r=e[2],n=e[3]-i||1,A=e[4]-s||1,o=e[5]-r||1,a=65525;return V.identityMat4(sn),V.translationMat4v(e,sn),V.identityMat4(rn),V.scalingMat4v([n/a,A/a,o/a],rn),V.mulMat4(sn,rn,t),t}function on(e,t,i){let s=e[0]/(Math.abs(e[0])+Math.abs(e[1])+Math.abs(e[2])),r=e[1]/(Math.abs(e[0])+Math.abs(e[1])+Math.abs(e[2]));if(e[2]<0){let e=s,t=r;e=(1-Math.abs(r))*(s>=0?1:-1),t=(1-Math.abs(s))*(r>=0?1:-1),s=e,r=t}return new Int8Array([Math[t](127.5*s+(s<0?-1:0)),Math[i](127.5*r+(r<0?-1:0))])}function an(e){let t=e[0],i=e[1];t/=t<0?127:128,i/=i<0?127:128;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 r=Math.sqrt(t*t+i*i+s*s);return[t/r,i/r,s/r]}const ln=new Float32Array(1),cn=new Float32Array(4),hn=new Float32Array(3),un=V.mat4(),dn=V.vec4([0,0,0,1]),fn=V.vec4(),pn=V.vec3(),gn=V.vec3(),mn=V.vec3(),_n=V.vec3(),bn=V.vec3(),Bn=V.vec3(),yn=V.vec3(),wn=new Uint8Array(4),vn=new Float32Array(96),Cn=function(e){const t=[];for(let i=0;i<e;++i)t.push(i);return t},Mn=function(e,t){e.set(t);let i=t.length;const s=e.length;for(;i<s;){const t=Math.min(i,s-i);e.set(e.subarray(0,t),i),i+=t}},En=function(){let e=0;const t=new Map;return{acquire:()=>e++,release:()=>{e--,0===e&&t.clear()},getTypeArray:function(e,i){t.has(e)||t.set(e,{});const s=t.get(e);return i in s||(s[i]=new e(i)),s[i]}}}();class Fn extends Vr{constructor(e,t,i,s){super(e,t,i);const r=!!s.geometry;this._maxVerts=s.maxGeometryBatchSize;const n=r?s.geometry.positionsDecodeMatrix:s.positionsDecodeMatrix;this._positionsDecodeMatrix=n&&V.mat4(n),this._cfgUvDecodeMatrix=s.uvDecodeMatrix&&V.mat3(s.uvDecodeMatrix),this._instancedGeometry=s.geometry,this._textureSet=s.textureSet,this._modelAABB=!r&&V.collapseAABB3(),this._portions=[];const A=function(){let e=0;const t=[];return{length:()=>e,append:function(i,s=1,r=1,n=0){e+=s*i.length,t.push({data:i,times:s,denormalizeScale:r,increment:n})},compileBuffer:function(e){let i=0;t.forEach((e=>{i+=e.times*e.data.length}));const s=new e(i);let r=0;return t.forEach((e=>{const t=e.data,i=e.denormalizeScale,n=e.increment,A=s.subarray(r);if(1===i&&0===n)A.set(t);else for(let e=0;e<t.length;++e)A[e]=n+t[e]*i;let o=t.length;const a=e.times*t.length;for(;o<a;){const e=Math.min(o,a-o);A.set(A.subarray(0,e),o),o+=e}r+=o})),s}}};this._buffer={colors:A(),metallicRoughness:A(),pickColors:A(),...r?{modelMatrixCol:[A(),A(),A()],modelNormalMatrixCol:[A(),A(),A()]}:{positions:A(),indices:A(),uv:A(),normals:A(),edgeIndices:A()}}}canCreatePortion(e,t){return this._instancedGeometry||this._buffer.positions.length()+e<=3*this._maxVerts&&this._buffer.indices.length()+t<=3*this._maxVerts}createPortion(e,t){const i=this._buffer,s=this._instancedGeometry,r=this.model,n=this._portions.length,A=this.primitive,o=!!this._positionsDecodeMatrix,a=r.scene,l=t.meshMatrix,c=(s,o,l,c,h)=>{const u=this._portions.length>0&&this._portions[this._portions.length-1],d={indicesBaseIndex:u?u.indicesBaseIndex+u.numIndices:0,numIndices:l?l.length:0,portionBase:s,portionSize:o,retainedGeometry:a.readableGeometryEnabled&&"points"!==A&&"lines"!==A&&{indices:l,quantizedPositions:c,offset:a.entityOffsetsEnabled&&V.vec3(),matrix:h&&h.slice(),inverseMatrix:null,normalMatrix:null}};return"points"!==A&&"lines"!==A&&i.metallicRoughness.append([t.metallic??0,t.roughness??255],o),"lines"!==A&&i.pickColors.append(t.pickColor.slice(0,4),o),this._portions.push(d),r.numPortions++,this._meshes.push(e),n};if(s){if(i.modelMatrixCol.forEach(((e,t)=>e.append([l[t+0],l[t+4],l[t+8],l[t+12]]))),"points"!==A){const e=t.color;i.colors.append([e[0],e[1],e[2],t.opacity??255])}if("points"!==A&&"lines"!==A&&s.normals){const e=V.inverseMat4(V.transposeMat4(l,V.mat4()));i.modelNormalMatrixCol.forEach(((t,i)=>t.append([e[i+0],e[i+4],e[i+8],e[i+12]])))}return c(n,1,s.indices,s.positionsCompressed,l)}{const e=i.positions.length()/3,s=o?t.positionsCompressed:t.positions;if(!s)throw(o?"positionsCompressed":"positions")+" expected";i.positions.append(s);const r=s.length/3,n=t.indices;n&&i.indices.append(n,1,1,e);const a=t.normalsCompressed,h=t.normals;if(a&&a.length>0)i.normals.append(a);else if(h&&h.length>0){const e=un;l?(V.transposeMat4(l,e),V.inverseMat4(e,e)):V.identityMat4(e);const t=[];!function(e,t,i,s,r){function n(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}let A,o,a,l,c,h,u=new Float32Array([0,0,0,0]),d=new Float32Array([0,0,0,0]);for(h=0;h<i;h+=3)u[0]=t[h],u[1]=t[h+1],u[2]=t[h+2],V.transformVec3(e,u,d),V.normalizeVec3(d,d),a=A=on(d,"floor","floor"),o=an(A),l=c=n(d,o),A=on(d,"ceil","floor"),o=an(A),l=n(d,o),l>c&&(a=A,c=l),A=on(d,"floor","ceil"),o=an(A),l=n(d,o),l>c&&(a=A,c=l),A=on(d,"ceil","ceil"),o=an(A),l=n(d,o),l>c&&(a=A,c=l),s[r+h+0]=a[0],s[r+h+1]=a[1],s[r+h+2]=0}(e,h,h.length,t,0),i.normals.append(t)}const u=t.colors,d=t.colorsCompressed,f=t.color;if(u)if("points"===A)i.colors.append(u,1,255);else{const e=[];for(let t=0,i=u.length;t<i;t+=3)e.push(255*u[t]),e.push(255*u[t+1]),e.push(255*u[t+2]),e.push(255);i.colors.append(e)}else if(d)if("points"===A)i.colors.append(d);else{const e=[];for(let t=0,i=d.length;t<i;t+=3)e.push(d[t]),e.push(d[t+1]),e.push(d[t+2]),e.push(255);i.colors.append(e)}else f&&i.colors.append([f[0],f[1],f[2],"points"===A?1:t.opacity],r);const p=e=>e&&e.length>0&&e,g=p(t.uv)||p(t.uvCompressed);g&&i.uv.append(g);const m=t.edgeIndices;return m&&i.edgeIndices.append(m,1,1,e),V.expandAABB3(this._modelAABB,t.aabb),c(e,r,n)}}compilePortions(){const e=this._buffer,t=this._instancedGeometry,i=this.model,s=this._modelAABB,r=this.origin,n=this._portions,A=this.primitive,o=this._textureSet;let a=this._positionsDecodeMatrix;const l=this._cfgUvDecodeMatrix,c=i.scene,h=c.canvas.gl,u=!!t,d=[],f=(e,t,i,s)=>{if(t.length>0){const r=t.constructor,[n,A]={[Uint8Array]:[1,h.UNSIGNED_BYTE],[Int8Array]:[1,h.BYTE],[Uint16Array]:[2,h.UNSIGNED_SHORT],[Int16Array]:[2,h.SHORT],[Uint32Array]:[4,h.UNSIGNED_INT],[Int32Array]:[4,h.INT],[Float32Array]:[4,h.FLOAT]}[r],o=h.createBuffer();d.push((()=>h.deleteBuffer(o)));const a=()=>h.bindBuffer(e,o),l=t=>{a(),h.bufferData(e,t,s)};l(t);const c=t.BYTES_PER_ELEMENT,u=t.length/i;return{bindBuffer:a,getData:(t=0,s=u-t)=>{a();const A=new r(s*i);return h.getBufferSubData(e,t*n*i,A,0,s*i),A},numItems:u,setData:l,setSubData:(t,i)=>{a(),h.bufferSubData(e,i*c,t)},type:A}}return null},p=(e,t,i,s=!1,r=!1)=>{const n=f(h.ARRAY_BUFFER,e,t,i);return n&&{getData:n.getData,numItems:n.numItems,setData:n.setData,setSubData:n.setSubData,attributeDivisor:s&&1,bindAtLocation:e=>{n.bindBuffer(),h.vertexAttribPointer(e,t,n.type,!!r,0,0)}}},g=e=>{const t=f(h.ELEMENT_ARRAY_BUFFER,e,1,h.STATIC_DRAW);return t&&{getData:t.getData,bindIndicesBuffer:t.bindBuffer,indicesCount:e.length,indicesType:t.type}},m=n.reduce(((e,t)=>e+t.portionSize),0),_=p(new Float32Array(m),1,h.DYNAMIC_DRAW,u),b=(e,t)=>p(e,4,t,u&&"points"!==A,!0),B=u&&t.colorsCompressed?b(new Uint8Array(t.colorsCompressed),h.STATIC_DRAW):b(e.colors.compileBuffer(Uint8Array),h.DYNAMIC_DRAW),y=c.entityOffsetsEnabled&&p(new Float32Array(3*m),3,h.DYNAMIC_DRAW,u),w=p(e.metallicRoughness.compileBuffer(Uint8Array),2,h.STATIC_DRAW,u),v=p(e.pickColors.compileBuffer(Uint8Array),4,h.STATIC_DRAW,u),C=g(u?new Uint32Array(t.edgeIndices):e.edgeIndices.compileBuffer(Uint32Array)),M=u?"points"!==A&&t.indices&&new Uint32Array(t.indices):e.indices.compileBuffer(Uint32Array),E=M&&g(M),F=u?t.positionsCompressed:a?e.positions.compileBuffer(Uint16Array):nn(e.positions.compileBuffer(Float64Array),s,a=V.mat4()),U=F&&p(F,3,h.STATIC_DRAW);u||n.forEach((e=>{if(e.retainedGeometry){const t=3*e.portionBase;e.retainedGeometry.quantizedPositions=F.subarray(t,t+3*e.portionSize)}}));const x=u&&e.modelMatrixCol.map((e=>p(e.compileBuffer(Float32Array),4,h.STATIC_DRAW,!0))),I=!u&&e.normals.compileBuffer(Int8Array),T=I&&p(I,3,h.STATIC_DRAW,!1,!0),P=x&&T&&e.modelNormalMatrixCol.map((e=>p(e.compileBuffer(Float32Array),4,h.STATIC_DRAW,!0))),S=u?"points"!==A&&"lines"!==A&&t.uvCompressed&&{buf:p(t.uvCompressed,2,h.STATIC_DRAW),mat:t.uvDecodeMatrix}:function(){const t=e.uv.compileBuffer(Float32Array);if(0===t.length)return null;if(l)return{buf:p(t,2,h.STATIC_DRAW),mat:l};{const e=Ne.getUVBounds(t),i=Ne.compressUVs(t,e.min,e.max);return{buf:p(i.quantized,2,h.STATIC_DRAW),mat:V.mat3(i.decodeMatrix)}}}();this._buffer=null,En.acquire(),d.push((()=>En.release()));let D=null;const k=(e,i,s,r=!1)=>{Rr(i,s,"points"!==A&&"lines"!==A,c,wn);const o=i&cr?1:0;let a=0;a|=wn[0],a|=wn[1]<<4,a|=wn[2]<<8,a|=wn[3]<<12,a|=o<<16,ln[0]=a;const l=n[e],h=l.portionBase,u=l.portionSize;if(r&&!t)D||(D=new Float32Array(m)),Mn(D.subarray(h,h+u),ln);else if(_){const e=En.getTypeArray(Float32Array,u);Mn(e,ln),_.setSubData(e,h)}},Q="solid"===A;return{edgesColorOpaqueAllowed:()=>!0,solid:Q,sortId:("points"===A?"Points":"lines"===A?"Lines":"Triangles")+(u?"Instancing":"Batching")+"Layer"+("points"!==A&&"lines"!==A?(Q?"-solid":"-surface")+"-autoNormals"+(u?"":(o&&o.colorTexture?"-colorTexture":"")+(o&&o.metallicRoughnessTexture?"-metallicRoughnessTexture":"")):""),setClippableFlags:k,setFlags:k,setFlags2:(e,t,i)=>{},setDeferredFlags:()=>{D&&(_.setData(D),D=null)},setColor:(e,t)=>{if(B){const i=n[e],s=En.getTypeArray(Uint8Array,4*i.portionSize);Mn(s,t.slice(0,4)),B.setSubData(s,4*i.portionBase)}},setMatrix:(e,t)=>{x&&x.forEach(((i,s)=>{cn[0]=t[s+0],cn[1]=t[s+4],cn[2]=t[s+8],cn[3]=t[s+12],i.setSubData(cn,4*e)}))},setOffset:(e,t)=>{if(c.entityOffsetsEnabled){const i=n[e];if(y){hn.set(t);const e=En.getTypeArray(Float32Array,3*i.portionSize);Mn(e,hn),y.setSubData(e,3*i.portionBase)}i.retainedGeometry&&i.retainedGeometry.offset.set(t)}else i.error("Entity#offset not enabled for this Viewer")},getEachIndex:(e,t)=>{const i=n[e].retainedGeometry;i&&i.indices.forEach((e=>t(e)))},getEachVertex:(e,t)=>{const s=n[e].retainedGeometry;if(s){const e=fn;r?e.set(r,0):e[0]=e[1]=e[2]=0,e[3]=1;const n=i.matrix;V.mulMat4v4(n,e,e);const A=s.quantizedPositions,o=dn;for(let i=0,r=A.length;i<r;i+=3)o[0]=A[i],o[1]=A[i+1],o[2]=A[i+2],V.decompressPosition(o,a),s.matrix&&V.transformPoint3(s.matrix,o,o),o[3]=1,V.mulMat4v4(n,o,o),V.addVec3(e,o,o),t(o)}},readGeometryData:"points"!==A&&"lines"!==A&&(e=>{const t=!u&&n[e],s=t?E.getData(t.indicesBaseIndex,t.numIndices).map((e=>e-t.portionBase)):E.getData(),A=i.matrix,o=V.vec4();o.set(r,0),o[3]=1,V.mulMat4v4(A,o,o);const l=x&&V.mat4();if(l){const t=x[0].getData(e,1),i=x[1].getData(e,1),s=x[2].getData(e,1);l.set([t[0],i[0],s[0],0,t[1],i[1],s[1],0,t[2],i[2],s[2],0,t[3],i[3],s[3],1])}const c=V.mat4();V.mulMat4(A,l?V.mulMat4(l,a,c):a,c),c[12]+=o[0],c[13]+=o[1],c[14]+=o[2];const h=t?U.getData(t.portionBase,t.portionSize):U.getData();return{indices:s,positions:V.transformPositions3(c,h,new Float64Array(h.length))}}),precisionRayPickSurface:(e,t,s,A,o)=>{const l=n[e].retainedGeometry;if(l){l.matrix&&!l.inverseMatrix&&(l.inverseMatrix=V.inverseMat4(l.matrix,V.mat4())),o&&l.inverseMatrix&&!l.normalMatrix&&(l.normalMatrix=V.transposeMat4(l.inverseMatrix,V.mat4()));const e=l.quantizedPositions,n=l.indices,c=l.offset,h=pn,u=gn;h.set(r?V.subVec3(t,r,mn):t),u.set(s),c&&V.subVec3(h,c),V.transformRay(i.worldNormalMatrix,h,u,h,u),l.inverseMatrix&&V.transformRay(l.inverseMatrix,h,u,h,u);const d=_n,f=bn,p=Bn;let g=!1,m=0;const _=yn;for(let s=0,b=n.length;s<b;s+=3){const b=3*n[s],B=3*n[s+1],y=3*n[s+2];if(d[0]=e[b],d[1]=e[b+1],d[2]=e[b+2],f[0]=e[B],f[1]=e[B+1],f[2]=e[B+2],p[0]=e[y],p[1]=e[y+1],p[2]=e[y+2],V.decompressPosition(d,a),V.decompressPosition(f,a),V.decompressPosition(p,a),V.rayTriangleIntersect(h,u,d,f,p,_)){l.matrix&&V.transformPoint3(l.matrix,_,_),V.transformPoint3(i.worldMatrix,_,_),c&&V.addVec3(_,c),r&&V.addVec3(_,r);const e=Math.abs(V.lenVec3(V.subVec3(_,t,[])));(!g||e>m)&&(m=e,A.set(_),o&&V.triangleNormal(d,f,p,o),g=!0)}}return g&&o&&(l.normalMatrix&&V.transformVec3(l.normalMatrix,o,o),V.transformVec3(i.worldNormalMatrix,o,o),V.normalizeVec3(o)),g}return!1},layerTextureSet:o,renderers:Or(c,u?"instancing":"batching",A,i.saoEnabled,i.pbrEnabled&&S&&o&&o.colorTexture&&T&&w&&o.metallicRoughnessTexture,i.colorTextureEnabled&&S&&o&&o.colorTexture,!!T,(e=>xn(e,u&&{hasModelNormalMat:!!P},c.entityOffsetsEnabled))),drawCalls:function(){const e={},t=t=>(s,r,o)=>{let l=0;vn.set(i.rotationMatrix,0),vn.set(o.viewMatrix,l+=16),vn.set(o.projMatrix,l+=16),vn.set(a,l+=16),r.needNormal()&&(vn.set(i.worldNormalMatrix,l+=16),vn.set(o.viewNormalMatrix,l+=16)),r.matrices.setInputValue(vn),r.uvDecodeMatrix.setInputValue&&r.uvDecodeMatrix.setInputValue(S.mat),s in e||(e[s]=[null,null,null]);const c=e[s],f=t?t.vertices?0:1:2;if(!c[f]){const e=h.createVertexArray();h.bindVertexArray(e);const i=(e,t)=>{e&&e.setInputValue&&t&&e.setInputValue(t)},s=r.attributes;i(s.position,U),i(s.normal,T),i(s.color,B),i(s.pickColor,v),i(s.uV,S&&S.buf),i(s.metallicRoughness,w),i(s.flags,_),i(s.offset,y),s.modelMatrixCol&&s.modelMatrixCol.forEach(((e,t)=>i(e,x[t]))),s.modelNormalMatrixCol&&s.modelNormalMatrixCol.forEach(((e,t)=>i(e,P[t])));const o=function(){const e=()=>{u?h.drawArraysInstanced(h.POINTS,0,U.numItems,n.length):h.drawArrays(h.POINTS,0,U.numItems)},i=(e,t)=>{t.bindIndicesBuffer();const i=t.indicesCount,s=t.indicesType;return()=>{u?h.drawElementsInstanced(e,i,s,0,n.length):h.drawElements(e,i,s,0)}};return"points"===A?e:"lines"===A?t&&t.vertices?e:i(h.LINES,E):t&&t.vertices?e:t?C?i(h.LINES,C):()=>{}:i(h.TRIANGLES,E)}();h.bindVertexArray(null),d.push((()=>h.deleteVertexArray(e))),c[f]=()=>{h.bindVertexArray(e),o(),h.bindVertexArray(null)}}c[f]()};return{drawVertices:t({vertices:!0}),drawEdges:t({}),drawSurface:t(null)}}(),destroy:()=>{d.forEach((e=>e())),d.length=0}}}}const Un=function(e){const t={toString:()=>(t.needed=!0,e)};return t},xn=function(e,t,i){const s=e.createAttribute,r={position:s("vec3","positionA"),normal:s("vec3","normalA"),color:s("vec4","colorA"),pickColor:s("vec4","pickColor"),uV:s("vec2","uvApremul"),metallicRoughness:s("vec2","metallicRoughness"),flags:s("float","flagsA"),offset:i&&s("vec3","offset"),modelMatrixCol:t&&Cn(3).map((e=>s("vec4","modelMatrixCol"+e))),modelNormalMatrixCol:t&&t.hasModelNormalMat&&Cn(3).map((e=>s("vec4","modelNormalMatrixCol"+e)))},n=Un("aUv"),A=Un("viewNormal"),o=Un("worldNormal"),a=e.createUniform("mat3","uvDecodeMatrix"),l=()=>A.needed||o.needed,c=e.createUniformBlock("Matrices",{worldMatrix:"mat4",viewMatrix:"mat4",projMatrix:"mat4",positionsDecodeMatrix:"mat4",worldNormalMatrix:"mat4",viewNormalMatrix:"mat4"});return{dontCullOnAlphaZero:!0,clippableTest:function(){const t=e.createVarying("float","vClippable",(()=>`((int(${r.flags}) >> 16 & 0xF) == 1) ? 1.0 : 0.0`));return()=>`${t} != 0.0`}(),geometryParameters:{attributes:{color:r.color,flags:Cn(4).map((e=>({toString:()=>`(int(${r.flags}) >> ${4*e} & 0xF)`}))),metallicRoughness:r.metallicRoughness,normal:{view:A,world:o},pickColor:r.pickColor,position:{clip:"gl_Position",view:"viewPosition",world:"worldPosition"},uv:n},projMatrix:c.projMatrix,viewMatrix:c.viewMatrix},appendVertexData:t=>{n.needed&&t.push(`vec2 ${n} = (${a} * vec3(${r.uV}, 1.0)).xy;`);const i=r.modelMatrixCol&&`mat4(${r.modelMatrixCol[0]}, ${r.modelMatrixCol[1]}, ${r.modelMatrixCol[2]}, vec4(0.0,0.0,0.0,1.0))`;if(t.push(`vec4 worldPosition = ${c.worldMatrix} * (${c.positionsDecodeMatrix} * vec4(${r.position}, 1.0)${i?" * "+i:""});`),r.offset&&t.push(`worldPosition.xyz = worldPosition.xyz + ${r.offset};`),l()){const i=r.modelNormalMatrixCol&&`* mat4(${r.modelNormalMatrixCol[0]}, ${r.modelNormalMatrixCol[1]}, ${r.modelNormalMatrixCol[2]}, vec4(0.0,0.0,0.0,1.0))`;t.push(`vec4 modelNormal = vec4(${e.commonLibrary.octDecode}(${r.normal}.xy), 0.0)${i||""};`),t.push(`vec3 ${o} = (${c.worldNormalMatrix} * modelNormal).xyz;`),A.needed&&t.push(`vec3 ${A} = normalize((${c.viewNormalMatrix} * vec4(${o}, 0.0)).xyz);`)}},layerTypeInputs:{attributes:r,matrices:c,uvDecodeMatrix:a,needNormal:l}}};class In{constructor(e){this.id=e.id,this.colorTexture=e.colorTexture,this.alphaCutoff=e.alphaCutoff,this.metallicRoughnessTexture=e.metallicRoughnessTexture,this.normalsTexture=e.normalsTexture,this.emissiveTexture=e.emissiveTexture,this.occlusionTexture=e.occlusionTexture}destroy(){}}class Tn{constructor(e){this.id=e.id,this.texture=e.texture}destroy(){this.texture&&(this.texture.destroy(),this.texture=null)}}const Pn={enabled:!1,files:{},add:function(e,t){!1!==this.enabled&&(this.files[e]=t)},get:function(e){if(!1!==this.enabled)return this.files[e]},remove:function(e){delete this.files[e]},clear:function(){this.files={}}};class Sn{constructor(e,t,i){this.isLoading=!1,this.itemsLoaded=0,this.itemsTotal=0,this.urlModifier=void 0,this.handlers=[],this.onStart=void 0,this.onLoad=e,this.onProgress=t,this.onError=i}itemStart(e){this.itemsTotal++,!1===this.isLoading&&void 0!==this.onStart&&this.onStart(e,this.itemsLoaded,this.itemsTotal),this.isLoading=!0}itemEnd(e){this.itemsLoaded++,void 0!==this.onProgress&&this.onProgress(e,this.itemsLoaded,this.itemsTotal),this.itemsLoaded===this.itemsTotal&&(this.isLoading=!1,void 0!==this.onLoad&&this.onLoad())}itemError(e){void 0!==this.onError&&this.onError(e)}resolveURL(e){return this.urlModifier?this.urlModifier(e):e}setURLModifier(e){return this.urlModifier=e,this}addHandler(e,t){return this.handlers.push(e,t),this}removeHandler(e){const t=this.handlers.indexOf(e);return-1!==t&&this.handlers.splice(t,2),this}getHandler(e){for(let t=0,i=this.handlers.length;t<i;t+=2){const i=this.handlers[t],s=this.handlers[t+1];if(i.global&&(i.lastIndex=0),i.test(e))return s}return null}}const Dn=new Sn;class kn{constructor(e){this.manager=void 0!==e?e:Dn,this.crossOrigin="anonymous",this.withCredentials=!1,this.path="",this.resourcePath="",this.requestHeader={}}load(){}loadAsync(e,t){const i=this;return new Promise((function(s,r){i.load(e,s,t,r)}))}parse(){}setCrossOrigin(e){return this.crossOrigin=e,this}setWithCredentials(e){return this.withCredentials=e,this}setPath(e){return this.path=e,this}setResourcePath(e){return this.resourcePath=e,this}setRequestHeader(e){return this.requestHeader=e,this}}const Qn={};class Rn extends kn{constructor(e){super(e)}load(e,t,i,s){void 0===e&&(e=""),void 0!==this.path&&(e=this.path+e),e=this.manager.resolveURL(e);const r=Pn.get(e);if(void 0!==r)return this.manager.itemStart(e),ie.scheduleTask((()=>{t&&t(r),this.manager.itemEnd(e)}),0),r;if(void 0!==Qn[e])return void Qn[e].push({onLoad:t,onProgress:i,onError:s});Qn[e]=[],Qn[e].push({onLoad:t,onProgress:i,onError:s});const n=new Request(e,{headers:new Headers(this.requestHeader),credentials:this.withCredentials?"include":"same-origin"}),A=this.mimeType,o=this.responseType;fetch(n).then((t=>{if(200===t.status||0===t.status){if(0===t.status&&console.warn("FileLoader: HTTP Status 0 received."),"undefined"==typeof ReadableStream||void 0===t.body.getReader)return t;const i=Qn[e],s=t.body.getReader(),r=t.headers.get("Content-Length"),n=r?parseInt(r):0,A=0!==n;let o=0;const a=new ReadableStream({start(e){!function t(){s.read().then((({done:s,value:r})=>{if(s)e.close();else{o+=r.byteLength;const s=new ProgressEvent("progress",{lengthComputable:A,loaded:o,total:n});for(let e=0,t=i.length;e<t;e++){const t=i[e];t.onProgress&&t.onProgress(s)}e.enqueue(r),t()}}))}()}});return new Response(a)}throw Error(`fetch for "${t.url}" responded with ${t.status}: ${t.statusText}`)})).then((e=>{switch(o){case"arraybuffer":return e.arrayBuffer();case"blob":return e.blob();case"document":return e.text().then((e=>(new DOMParser).parseFromString(e,A)));case"json":return e.json();default:if(void 0===A)return e.text();{const t=/charset="?([^;"\s]*)"?/i.exec(A),i=t&&t[1]?t[1].toLowerCase():void 0,s=new TextDecoder(i);return e.arrayBuffer().then((e=>s.decode(e)))}}})).then((t=>{Pn.add(e,t);const i=Qn[e];delete Qn[e];for(let e=0,s=i.length;e<s;e++){const s=i[e];s.onLoad&&s.onLoad(t)}})).catch((t=>{const i=Qn[e];if(void 0===i)throw this.manager.itemError(e),t;delete Qn[e];for(let e=0,s=i.length;e<s;e++){const s=i[e];s.onError&&s.onError(t)}this.manager.itemError(e)})).finally((()=>{this.manager.itemEnd(e)})),this.manager.itemStart(e)}setResponseType(e){return this.responseType=e,this}setMimeType(e){return this.mimeType=e,this}}class On{constructor(e=4){this.pool=e,this.queue=[],this.workers=[],this.workersResolve=[],this.workerStatus=0}_initWorker(e){if(!this.workers[e]){const t=this.workerCreator();t.addEventListener("message",this._onMessage.bind(this,e)),this.workers[e]=t}}_getIdleWorker(){for(let e=0;e<this.pool;e++)if(!(this.workerStatus&1<<e))return e;return-1}_onMessage(e,t){const i=this.workersResolve[e];if(i&&i(t),this.queue.length){const{resolve:t,msg:i,transfer:s}=this.queue.shift();this.workersResolve[e]=t,this.workers[e].postMessage(i,s)}else this.workerStatus^=1<<e}setWorkerCreator(e){this.workerCreator=e}setWorkerLimit(e){this.pool=e}postMessage(e,t){return new Promise((i=>{const s=this._getIdleWorker();-1!==s?(this._initWorker(s),this.workerStatus|=1<<s,this.workersResolve[s]=i,this.workers[s].postMessage(e,t)):this.queue.push({resolve:i,msg:e,transfer:t})}))}destroy(){this.workers.forEach((e=>e.terminate())),this.workersResolve.length=0,this.workers.length=0,this.queue.length=0,this.workerStatus=0}}let Vn=0;class Ln{constructor({viewer:e,transcoderPath:t,workerLimit:i}){this._transcoderPath=t||"https://cdn.jsdelivr.net/npm/@xeokit/xeokit-sdk/dist/basis/",this._transcoderBinary=null,this._transcoderPending=null,this._workerPool=new On,this._workerSourceURL="",i&&this._workerPool.setWorkerLimit(i);const s=e.capabilities;this._workerConfig={astcSupported:s.astcSupported,etc1Supported:s.etc1Supported,etc2Supported:s.etc2Supported,dxtSupported:s.dxtSupported,bptcSupported:s.bptcSupported,pvrtcSupported:s.pvrtcSupported},this._supportedFileTypes=["xkt2"]}_init(){if(!this._transcoderPending){const e=new Rn;e.setPath(this._transcoderPath),e.setWithCredentials(this.withCredentials);const t=e.loadAsync("basis_transcoder.js"),i=new Rn;i.setPath(this._transcoderPath),i.setResponseType("arraybuffer"),i.setWithCredentials(this.withCredentials);const s=i.loadAsync("basis_transcoder.wasm");this._transcoderPending=Promise.all([t,s]).then((([e,t])=>{const i=Ln.BasisWorker.toString(),s=["/* constants */","let _EngineFormat = "+JSON.stringify(Ln.EngineFormat),"let _TranscoderFormat = "+JSON.stringify(Ln.TranscoderFormat),"let _BasisFormat = "+JSON.stringify(Ln.BasisFormat),"/* basis_transcoder.js */",e,"/* worker */",i.substring(i.indexOf("{")+1,i.lastIndexOf("}"))].join("\n");this._workerSourceURL=URL.createObjectURL(new Blob([s])),this._transcoderBinary=t,this._workerPool.setWorkerCreator((()=>{const e=new Worker(this._workerSourceURL),t=this._transcoderBinary.slice(0);return e.postMessage({type:"init",config:this._workerConfig,transcoderBinary:t},[t]),e}))})),Vn>0&&console.warn("KTX2TextureTranscoder: Multiple active KTX2TextureTranscoder may cause performance issues. Use a single KTX2TextureTranscoder instance, or call .dispose() on old instances."),Vn++}return this._transcoderPending}transcode(e,t,i={}){return new Promise(((s,r)=>{const n=i;this._init().then((()=>this._workerPool.postMessage({type:"transcode",buffers:e,taskConfig:n},e))).then((e=>{const i=e.data,{mipmaps:n,width:A,height:o,format:a,type:l,error:c,dfdTransferFn:h,dfdFlags:u}=i;if("error"===l)return r(c);t.setCompressedData({mipmaps:n,props:{format:a,minFilter:1===n.length?1006:1008,magFilter:1===n.length?1006:1008,encoding:2===h?3001:3e3,premultiplyAlpha:!!(1&u)}}),s()}))}))}destroy(){URL.revokeObjectURL(this._workerSourceURL),this._workerPool.destroy(),Vn--}}Ln.BasisFormat={ETC1S:0,UASTC_4x4:1},Ln.TranscoderFormat={ETC1:0,ETC2:1,BC1:2,BC3:3,BC4:4,BC5:5,BC7_M6_OPAQUE_ONLY:6,BC7_M5:7,PVRTC1_4_RGB:8,PVRTC1_4_RGBA:9,ASTC_4x4:10,ATC_RGB:11,ATC_RGBA_INTERPOLATED_ALPHA:12,RGBA32:13,RGB565:14,BGR565:15,RGBA4444:16},Ln.EngineFormat={RGBAFormat:1023,RGBA_ASTC_4x4_Format:37808,RGBA_BPTC_Format:36492,RGBA_ETC2_EAC_Format:37496,RGBA_PVRTC_4BPPV1_Format:35842,RGBA_S3TC_DXT5_Format:33779,RGB_ETC1_Format:36196,RGB_ETC2_Format:37492,RGB_PVRTC_4BPPV1_Format:35840,RGB_S3TC_DXT1_Format:33776},Ln.BasisWorker=function(){let e,t,i;const s=_EngineFormat,r=_TranscoderFormat,n=_BasisFormat;self.addEventListener("message",(function(A){const c=A.data;switch(c.type){case"init":e=c.config,h=c.transcoderBinary,t=new Promise((e=>{i={wasmBinary:h,onRuntimeInitialized:e},BASIS(i)})).then((()=>{i.initializeBasis(),void 0===i.KTX2File&&console.warn("KTX2TextureTranscoder: Please update Basis Universal transcoder.")}));break;case"transcode":t.then((()=>{try{const{width:t,height:A,hasAlpha:h,mipmaps:u,format:d,dfdTransferFn:f,dfdFlags:p}=function(t){const A=new i.KTX2File(new Uint8Array(t));function c(){A.close(),A.delete()}if(!A.isValid())throw c(),new Error("KTX2TextureTranscoder: Invalid or unsupported .ktx2 file");const h=A.isUASTC()?n.UASTC_4x4:n.ETC1S,u=A.getWidth(),d=A.getHeight(),f=A.getLevels(),p=A.getHasAlpha(),g=A.getDFDTransferFunc(),m=A.getDFDFlags(),{transcoderFormat:_,engineFormat:b}=function(t,i,A,c){let h,u;const d=t===n.ETC1S?o:a;for(let s=0;s<d.length;s++){const r=d[s];if(e[r.if]&&(r.basisFormat.includes(t)&&!(c&&r.transcoderFormat.length<2)&&(!r.needsPowerOfTwo||l(i)&&l(A))))return h=r.transcoderFormat[c?1:0],u=r.engineFormat[c?1:0],{transcoderFormat:h,engineFormat:u}}return console.warn("KTX2TextureTranscoder: No suitable compressed texture format found. Decoding to RGBA32."),h=r.RGBA32,u=s.RGBAFormat,{transcoderFormat:h,engineFormat:u}}(h,u,d,p);if(!u||!d||!f)throw c(),new Error("KTX2TextureTranscoder: Invalid texture");if(!A.startTranscoding())throw c(),new Error("KTX2TextureTranscoder: .startTranscoding failed");const B=[];for(let e=0;e<f;e++){const t=A.getImageLevelInfo(e,0,0),i=t.origWidth,s=t.origHeight,r=new Uint8Array(A.getImageTranscodedSizeInBytes(e,0,0,_));if(!A.transcodeImage(r,e,0,0,_,0,-1,-1))throw c(),new Error("KTX2TextureTranscoder: .transcodeImage failed.");B.push({data:r,width:i,height:s})}return c(),{width:u,height:d,hasAlpha:p,mipmaps:B,format:b,dfdTransferFn:g,dfdFlags:m}}(c.buffers[0]),g=[];for(let e=0;e<u.length;++e)g.push(u[e].data.buffer);self.postMessage({type:"transcode",id:c.id,width:t,height:A,hasAlpha:h,mipmaps:u,format:d,dfdTransferFn:f,dfdFlags:p},g)}catch(e){console.error(`[KTX2TextureTranscoder.BasisWorker]: ${e}`),self.postMessage({type:"error",id:c.id,error:e.message})}}))}var h}));const A=[{if:"astcSupported",basisFormat:[n.UASTC_4x4],transcoderFormat:[r.ASTC_4x4,r.ASTC_4x4],engineFormat:[s.RGBA_ASTC_4x4_Format,s.RGBA_ASTC_4x4_Format],priorityETC1S:1/0,priorityUASTC:1,needsPowerOfTwo:!1},{if:"bptcSupported",basisFormat:[n.ETC1S,n.UASTC_4x4],transcoderFormat:[r.BC7_M5,r.BC7_M5],engineFormat:[s.RGBA_BPTC_Format,s.RGBA_BPTC_Format],priorityETC1S:3,priorityUASTC:2,needsPowerOfTwo:!1},{if:"dxtSupported",basisFormat:[n.ETC1S,n.UASTC_4x4],transcoderFormat:[r.BC1,r.BC3],engineFormat:[s.RGB_S3TC_DXT1_Format,s.RGBA_S3TC_DXT5_Format],priorityETC1S:4,priorityUASTC:5,needsPowerOfTwo:!1},{if:"etc2Supported",basisFormat:[n.ETC1S,n.UASTC_4x4],transcoderFormat:[r.ETC1,r.ETC2],engineFormat:[s.RGB_ETC2_Format,s.RGBA_ETC2_EAC_Format],priorityETC1S:1,priorityUASTC:3,needsPowerOfTwo:!1},{if:"etc1Supported",basisFormat:[n.ETC1S,n.UASTC_4x4],transcoderFormat:[r.ETC1],engineFormat:[s.RGB_ETC1_Format],priorityETC1S:2,priorityUASTC:4,needsPowerOfTwo:!1},{if:"pvrtcSupported",basisFormat:[n.ETC1S,n.UASTC_4x4],transcoderFormat:[r.PVRTC1_4_RGB,r.PVRTC1_4_RGBA],engineFormat:[s.RGB_PVRTC_4BPPV1_Format,s.RGBA_PVRTC_4BPPV1_Format],priorityETC1S:5,priorityUASTC:6,needsPowerOfTwo:!0}],o=A.sort((function(e,t){return e.priorityETC1S-t.priorityETC1S})),a=A.sort((function(e,t){return e.priorityUASTC-t.priorityUASTC}));function l(e){return e<=2||0==(e&e-1)&&0!==e}};const Hn={};function Nn(e){const t=e.scene.id;let i=Hn[t];return i||(i=new Ln({viewer:e}),Hn[t]=i,e.scene.on("destroyed",(()=>{delete Hn[t],i.destroy()}))),i}
8
8
  /**
9
9
  * @author https://github.com/tmarti, with support from https://tribia.com/
10
10
  * @license MIT